blob: d7896bb553a9c0eb123b9f507a56dc7d9da9804c [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Dave Airlie
25 * Alex Deucher
26 * Jerome Glisse
27 */
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Jerome Glisse3ce0a232009-09-08 10:10:24 +100029#include <linux/seq_file.h>
30#include <linux/firmware.h>
Paul Gortmakere0cd3602011-08-30 11:04:30 -040031#include <linux/module.h>
David Howells760285e2012-10-02 18:01:07 +010032#include <drm/drmP.h>
33#include <drm/radeon_drm.h>
Jerome Glisse771fe6b2009-06-05 14:42:42 +020034#include "radeon.h"
Daniel Vettere6990372010-03-11 21:19:17 +000035#include "radeon_asic.h"
Slava Grigorevbfc1f972014-12-22 17:26:51 -050036#include "radeon_audio.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100037#include "radeon_mode.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100038#include "r600d.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100039#include "atom.h"
Jerome Glissed39c3b82009-09-28 18:34:43 +020040#include "avivod.h"
Alex Deucher138e4e12013-01-11 15:33:13 -050041#include "radeon_ucode.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100042
43/* Firmware Names */
44MODULE_FIRMWARE("radeon/R600_pfp.bin");
45MODULE_FIRMWARE("radeon/R600_me.bin");
46MODULE_FIRMWARE("radeon/RV610_pfp.bin");
47MODULE_FIRMWARE("radeon/RV610_me.bin");
48MODULE_FIRMWARE("radeon/RV630_pfp.bin");
49MODULE_FIRMWARE("radeon/RV630_me.bin");
50MODULE_FIRMWARE("radeon/RV620_pfp.bin");
51MODULE_FIRMWARE("radeon/RV620_me.bin");
52MODULE_FIRMWARE("radeon/RV635_pfp.bin");
53MODULE_FIRMWARE("radeon/RV635_me.bin");
54MODULE_FIRMWARE("radeon/RV670_pfp.bin");
55MODULE_FIRMWARE("radeon/RV670_me.bin");
56MODULE_FIRMWARE("radeon/RS780_pfp.bin");
57MODULE_FIRMWARE("radeon/RS780_me.bin");
58MODULE_FIRMWARE("radeon/RV770_pfp.bin");
59MODULE_FIRMWARE("radeon/RV770_me.bin");
Alex Deucher66229b22013-06-26 00:11:19 -040060MODULE_FIRMWARE("radeon/RV770_smc.bin");
Jerome Glisse3ce0a232009-09-08 10:10:24 +100061MODULE_FIRMWARE("radeon/RV730_pfp.bin");
62MODULE_FIRMWARE("radeon/RV730_me.bin");
Alex Deucher66229b22013-06-26 00:11:19 -040063MODULE_FIRMWARE("radeon/RV730_smc.bin");
64MODULE_FIRMWARE("radeon/RV740_smc.bin");
Jerome Glisse3ce0a232009-09-08 10:10:24 +100065MODULE_FIRMWARE("radeon/RV710_pfp.bin");
66MODULE_FIRMWARE("radeon/RV710_me.bin");
Alex Deucher66229b22013-06-26 00:11:19 -040067MODULE_FIRMWARE("radeon/RV710_smc.bin");
Alex Deucherd8f60cf2009-12-01 13:43:46 -050068MODULE_FIRMWARE("radeon/R600_rlc.bin");
69MODULE_FIRMWARE("radeon/R700_rlc.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040070MODULE_FIRMWARE("radeon/CEDAR_pfp.bin");
71MODULE_FIRMWARE("radeon/CEDAR_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040072MODULE_FIRMWARE("radeon/CEDAR_rlc.bin");
Alex Deucherdc50ba72013-06-26 00:33:35 -040073MODULE_FIRMWARE("radeon/CEDAR_smc.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040074MODULE_FIRMWARE("radeon/REDWOOD_pfp.bin");
75MODULE_FIRMWARE("radeon/REDWOOD_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040076MODULE_FIRMWARE("radeon/REDWOOD_rlc.bin");
Alex Deucherdc50ba72013-06-26 00:33:35 -040077MODULE_FIRMWARE("radeon/REDWOOD_smc.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040078MODULE_FIRMWARE("radeon/JUNIPER_pfp.bin");
79MODULE_FIRMWARE("radeon/JUNIPER_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040080MODULE_FIRMWARE("radeon/JUNIPER_rlc.bin");
Alex Deucherdc50ba72013-06-26 00:33:35 -040081MODULE_FIRMWARE("radeon/JUNIPER_smc.bin");
Dave Airliea7433742010-04-09 15:31:09 +100082MODULE_FIRMWARE("radeon/CYPRESS_pfp.bin");
Alex Deucherfe251e22010-03-24 13:36:43 -040083MODULE_FIRMWARE("radeon/CYPRESS_me.bin");
Alex Deucher45f9a392010-03-24 13:55:51 -040084MODULE_FIRMWARE("radeon/CYPRESS_rlc.bin");
Alex Deucherdc50ba72013-06-26 00:33:35 -040085MODULE_FIRMWARE("radeon/CYPRESS_smc.bin");
Alex Deucher439bd6c2010-11-22 17:56:31 -050086MODULE_FIRMWARE("radeon/PALM_pfp.bin");
87MODULE_FIRMWARE("radeon/PALM_me.bin");
88MODULE_FIRMWARE("radeon/SUMO_rlc.bin");
Alex Deucherd5c5a722011-05-31 15:42:48 -040089MODULE_FIRMWARE("radeon/SUMO_pfp.bin");
90MODULE_FIRMWARE("radeon/SUMO_me.bin");
91MODULE_FIRMWARE("radeon/SUMO2_pfp.bin");
92MODULE_FIRMWARE("radeon/SUMO2_me.bin");
Jerome Glisse3ce0a232009-09-08 10:10:24 +100093
Alex Deucherf13f7732013-01-18 18:12:22 -050094static const u32 crtc_offsets[2] =
95{
96 0,
97 AVIVO_D2CRTC_H_TOTAL - AVIVO_D1CRTC_H_TOTAL
98};
99
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000100int r600_debugfs_mc_info_init(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200101
Jerome Glisse1a029b72009-10-06 19:04:30 +0200102/* r600,rv610,rv630,rv620,rv635,rv670 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200103int r600_mc_wait_for_idle(struct radeon_device *rdev);
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400104static void r600_gpu_init(struct radeon_device *rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000105void r600_fini(struct radeon_device *rdev);
Alex Deucher45f9a392010-03-24 13:55:51 -0400106void r600_irq_disable(struct radeon_device *rdev);
Alex Deucher9e46a482011-01-06 18:49:35 -0500107static void r600_pcie_gen2_enable(struct radeon_device *rdev);
Alex Deucher2948f5e2013-04-12 13:52:52 -0400108extern int evergreen_rlc_resume(struct radeon_device *rdev);
Alex Deucherde9ae742013-11-01 19:01:36 -0400109extern void rv770_set_clk_bypass_mode(struct radeon_device *rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200110
Denys Vlasenko9e5acbc2015-05-20 13:02:37 +0200111/*
112 * Indirect registers accessor
113 */
114u32 r600_rcu_rreg(struct radeon_device *rdev, u32 reg)
115{
116 unsigned long flags;
117 u32 r;
118
119 spin_lock_irqsave(&rdev->rcu_idx_lock, flags);
120 WREG32(R600_RCU_INDEX, ((reg) & 0x1fff));
121 r = RREG32(R600_RCU_DATA);
122 spin_unlock_irqrestore(&rdev->rcu_idx_lock, flags);
123 return r;
124}
125
126void r600_rcu_wreg(struct radeon_device *rdev, u32 reg, u32 v)
127{
128 unsigned long flags;
129
130 spin_lock_irqsave(&rdev->rcu_idx_lock, flags);
131 WREG32(R600_RCU_INDEX, ((reg) & 0x1fff));
132 WREG32(R600_RCU_DATA, (v));
133 spin_unlock_irqrestore(&rdev->rcu_idx_lock, flags);
134}
135
136u32 r600_uvd_ctx_rreg(struct radeon_device *rdev, u32 reg)
137{
138 unsigned long flags;
139 u32 r;
140
141 spin_lock_irqsave(&rdev->uvd_idx_lock, flags);
142 WREG32(R600_UVD_CTX_INDEX, ((reg) & 0x1ff));
143 r = RREG32(R600_UVD_CTX_DATA);
144 spin_unlock_irqrestore(&rdev->uvd_idx_lock, flags);
145 return r;
146}
147
148void r600_uvd_ctx_wreg(struct radeon_device *rdev, u32 reg, u32 v)
149{
150 unsigned long flags;
151
152 spin_lock_irqsave(&rdev->uvd_idx_lock, flags);
153 WREG32(R600_UVD_CTX_INDEX, ((reg) & 0x1ff));
154 WREG32(R600_UVD_CTX_DATA, (v));
155 spin_unlock_irqrestore(&rdev->uvd_idx_lock, flags);
156}
157
Alex Deucher454d2e22013-02-14 10:04:02 -0500158/**
Alex Deucherc6d2ac22014-10-01 09:36:57 -0400159 * r600_get_allowed_info_register - fetch the register for the info ioctl
160 *
161 * @rdev: radeon_device pointer
162 * @reg: register offset in bytes
163 * @val: register value
164 *
165 * Returns 0 for success or -EINVAL for an invalid register
166 *
167 */
168int r600_get_allowed_info_register(struct radeon_device *rdev,
169 u32 reg, u32 *val)
170{
171 switch (reg) {
172 case GRBM_STATUS:
173 case GRBM_STATUS2:
174 case R_000E50_SRBM_STATUS:
175 case DMA_STATUS_REG:
176 case UVD_STATUS:
177 *val = RREG32(reg);
178 return 0;
179 default:
180 return -EINVAL;
181 }
182}
183
184/**
Alex Deucher454d2e22013-02-14 10:04:02 -0500185 * r600_get_xclk - get the xclk
186 *
187 * @rdev: radeon_device pointer
188 *
189 * Returns the reference clock used by the gfx engine
190 * (r6xx, IGPs, APUs).
191 */
192u32 r600_get_xclk(struct radeon_device *rdev)
193{
194 return rdev->clock.spll.reference_freq;
195}
196
Alex Deucher1b9ba702013-09-05 09:52:37 -0400197int r600_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
198{
Alex Deucher4a956a72012-11-28 16:55:21 -0500199 unsigned fb_div = 0, ref_div, vclk_div = 0, dclk_div = 0;
200 int r;
201
202 /* bypass vclk and dclk with bclk */
203 WREG32_P(CG_UPLL_FUNC_CNTL_2,
204 VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
205 ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
206
207 /* assert BYPASS_EN, deassert UPLL_RESET, UPLL_SLEEP and UPLL_CTLREQ */
208 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~(
209 UPLL_RESET_MASK | UPLL_SLEEP_MASK | UPLL_CTLREQ_MASK));
210
211 if (rdev->family >= CHIP_RS780)
212 WREG32_P(GFX_MACRO_BYPASS_CNTL, UPLL_BYPASS_CNTL,
213 ~UPLL_BYPASS_CNTL);
214
215 if (!vclk || !dclk) {
216 /* keep the Bypass mode, put PLL to sleep */
217 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
218 return 0;
219 }
220
221 if (rdev->clock.spll.reference_freq == 10000)
222 ref_div = 34;
223 else
224 ref_div = 4;
225
226 r = radeon_uvd_calc_upll_dividers(rdev, vclk, dclk, 50000, 160000,
227 ref_div + 1, 0xFFF, 2, 30, ~0,
228 &fb_div, &vclk_div, &dclk_div);
229 if (r)
230 return r;
231
232 if (rdev->family >= CHIP_RV670 && rdev->family < CHIP_RS780)
233 fb_div >>= 1;
234 else
235 fb_div |= 1;
236
237 r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
Jérome Glisse3cf8bb12016-03-16 12:56:45 +0100238 if (r)
239 return r;
Alex Deucher4a956a72012-11-28 16:55:21 -0500240
241 /* assert PLL_RESET */
242 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
243
244 /* For RS780 we have to choose ref clk */
245 if (rdev->family >= CHIP_RS780)
246 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_REFCLK_SRC_SEL_MASK,
247 ~UPLL_REFCLK_SRC_SEL_MASK);
248
249 /* set the required fb, ref and post divder values */
250 WREG32_P(CG_UPLL_FUNC_CNTL,
251 UPLL_FB_DIV(fb_div) |
252 UPLL_REF_DIV(ref_div),
253 ~(UPLL_FB_DIV_MASK | UPLL_REF_DIV_MASK));
254 WREG32_P(CG_UPLL_FUNC_CNTL_2,
255 UPLL_SW_HILEN(vclk_div >> 1) |
256 UPLL_SW_LOLEN((vclk_div >> 1) + (vclk_div & 1)) |
257 UPLL_SW_HILEN2(dclk_div >> 1) |
258 UPLL_SW_LOLEN2((dclk_div >> 1) + (dclk_div & 1)) |
259 UPLL_DIVEN_MASK | UPLL_DIVEN2_MASK,
260 ~UPLL_SW_MASK);
261
262 /* give the PLL some time to settle */
263 mdelay(15);
264
265 /* deassert PLL_RESET */
266 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
267
268 mdelay(15);
269
270 /* deassert BYPASS EN */
271 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
272
273 if (rdev->family >= CHIP_RS780)
274 WREG32_P(GFX_MACRO_BYPASS_CNTL, 0, ~UPLL_BYPASS_CNTL);
275
276 r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
277 if (r)
278 return r;
279
280 /* switch VCLK and DCLK selection */
281 WREG32_P(CG_UPLL_FUNC_CNTL_2,
282 VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
283 ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
284
285 mdelay(100);
286
Alex Deucher1b9ba702013-09-05 09:52:37 -0400287 return 0;
288}
289
Alex Deucher134b4802013-09-23 12:22:11 -0400290void dce3_program_fmt(struct drm_encoder *encoder)
291{
292 struct drm_device *dev = encoder->dev;
293 struct radeon_device *rdev = dev->dev_private;
294 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
295 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
296 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
297 int bpc = 0;
298 u32 tmp = 0;
Alex Deucher6214bb72013-09-24 17:26:26 -0400299 enum radeon_connector_dither dither = RADEON_FMT_DITHER_DISABLE;
Alex Deucher134b4802013-09-23 12:22:11 -0400300
Alex Deucher6214bb72013-09-24 17:26:26 -0400301 if (connector) {
302 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deucher134b4802013-09-23 12:22:11 -0400303 bpc = radeon_get_monitor_bpc(connector);
Alex Deucher6214bb72013-09-24 17:26:26 -0400304 dither = radeon_connector->dither;
305 }
Alex Deucher134b4802013-09-23 12:22:11 -0400306
307 /* LVDS FMT is set up by atom */
308 if (radeon_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
309 return;
310
311 /* not needed for analog */
312 if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1) ||
313 (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2))
314 return;
315
316 if (bpc == 0)
317 return;
318
319 switch (bpc) {
320 case 6:
Alex Deucher6214bb72013-09-24 17:26:26 -0400321 if (dither == RADEON_FMT_DITHER_ENABLE)
Alex Deucher134b4802013-09-23 12:22:11 -0400322 /* XXX sort out optimal dither settings */
323 tmp |= FMT_SPATIAL_DITHER_EN;
324 else
325 tmp |= FMT_TRUNCATE_EN;
326 break;
327 case 8:
Alex Deucher6214bb72013-09-24 17:26:26 -0400328 if (dither == RADEON_FMT_DITHER_ENABLE)
Alex Deucher134b4802013-09-23 12:22:11 -0400329 /* XXX sort out optimal dither settings */
330 tmp |= (FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH);
331 else
332 tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH);
333 break;
334 case 10:
335 default:
336 /* not needed */
337 break;
338 }
339
340 WREG32(FMT_BIT_DEPTH_CONTROL + radeon_crtc->crtc_offset, tmp);
341}
342
Alex Deucher21a81222010-07-02 12:58:16 -0400343/* get temperature in millidegrees */
Alex Deucher20d391d2011-02-01 16:12:34 -0500344int rv6xx_get_temp(struct radeon_device *rdev)
Alex Deucher21a81222010-07-02 12:58:16 -0400345{
346 u32 temp = (RREG32(CG_THERMAL_STATUS) & ASIC_T_MASK) >>
347 ASIC_T_SHIFT;
Alex Deucher20d391d2011-02-01 16:12:34 -0500348 int actual_temp = temp & 0xff;
Alex Deucher21a81222010-07-02 12:58:16 -0400349
Alex Deucher20d391d2011-02-01 16:12:34 -0500350 if (temp & 0x100)
351 actual_temp -= 256;
352
353 return actual_temp * 1000;
Alex Deucher21a81222010-07-02 12:58:16 -0400354}
355
Alex Deucherce8f5372010-05-07 15:10:16 -0400356void r600_pm_get_dynpm_state(struct radeon_device *rdev)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400357{
358 int i;
359
Alex Deucherce8f5372010-05-07 15:10:16 -0400360 rdev->pm.dynpm_can_upclock = true;
361 rdev->pm.dynpm_can_downclock = true;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400362
363 /* power state array is low to high, default is first */
364 if ((rdev->flags & RADEON_IS_IGP) || (rdev->family == CHIP_R600)) {
365 int min_power_state_index = 0;
366
367 if (rdev->pm.num_power_states > 2)
368 min_power_state_index = 1;
369
Alex Deucherce8f5372010-05-07 15:10:16 -0400370 switch (rdev->pm.dynpm_planned_action) {
371 case DYNPM_ACTION_MINIMUM:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400372 rdev->pm.requested_power_state_index = min_power_state_index;
373 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400374 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400375 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400376 case DYNPM_ACTION_DOWNCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400377 if (rdev->pm.current_power_state_index == min_power_state_index) {
378 rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400379 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400380 } else {
381 if (rdev->pm.active_crtc_count > 1) {
382 for (i = 0; i < rdev->pm.num_power_states; i++) {
Alex Deucherd7311172010-05-03 01:13:14 -0400383 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400384 continue;
385 else if (i >= rdev->pm.current_power_state_index) {
386 rdev->pm.requested_power_state_index =
387 rdev->pm.current_power_state_index;
388 break;
389 } else {
390 rdev->pm.requested_power_state_index = i;
391 break;
392 }
393 }
Alex Deucher773c3fa2010-06-25 16:21:27 -0400394 } else {
395 if (rdev->pm.current_power_state_index == 0)
396 rdev->pm.requested_power_state_index =
397 rdev->pm.num_power_states - 1;
398 else
399 rdev->pm.requested_power_state_index =
400 rdev->pm.current_power_state_index - 1;
401 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400402 }
403 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherd7311172010-05-03 01:13:14 -0400404 /* don't use the power state if crtcs are active and no display flag is set */
405 if ((rdev->pm.active_crtc_count > 0) &&
406 (rdev->pm.power_state[rdev->pm.requested_power_state_index].
407 clock_info[rdev->pm.requested_clock_mode_index].flags &
408 RADEON_PM_MODE_NO_DISPLAY)) {
409 rdev->pm.requested_power_state_index++;
410 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400411 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400412 case DYNPM_ACTION_UPCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400413 if (rdev->pm.current_power_state_index == (rdev->pm.num_power_states - 1)) {
414 rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400415 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400416 } else {
417 if (rdev->pm.active_crtc_count > 1) {
418 for (i = (rdev->pm.num_power_states - 1); i >= 0; i--) {
Alex Deucherd7311172010-05-03 01:13:14 -0400419 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400420 continue;
421 else if (i <= rdev->pm.current_power_state_index) {
422 rdev->pm.requested_power_state_index =
423 rdev->pm.current_power_state_index;
424 break;
425 } else {
426 rdev->pm.requested_power_state_index = i;
427 break;
428 }
429 }
430 } else
431 rdev->pm.requested_power_state_index =
432 rdev->pm.current_power_state_index + 1;
433 }
434 rdev->pm.requested_clock_mode_index = 0;
435 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400436 case DYNPM_ACTION_DEFAULT:
Alex Deucher58e21df2010-03-22 13:31:08 -0400437 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
438 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400439 rdev->pm.dynpm_can_upclock = false;
Alex Deucher58e21df2010-03-22 13:31:08 -0400440 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400441 case DYNPM_ACTION_NONE:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400442 default:
443 DRM_ERROR("Requested mode for not defined action\n");
444 return;
445 }
446 } else {
447 /* XXX select a power state based on AC/DC, single/dualhead, etc. */
448 /* for now just select the first power state and switch between clock modes */
449 /* power state array is low to high, default is first (0) */
450 if (rdev->pm.active_crtc_count > 1) {
451 rdev->pm.requested_power_state_index = -1;
452 /* start at 1 as we don't want the default mode */
453 for (i = 1; i < rdev->pm.num_power_states; i++) {
Alex Deucherd7311172010-05-03 01:13:14 -0400454 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
Alex Deuchera48b9b42010-04-22 14:03:55 -0400455 continue;
456 else if ((rdev->pm.power_state[i].type == POWER_STATE_TYPE_PERFORMANCE) ||
457 (rdev->pm.power_state[i].type == POWER_STATE_TYPE_BATTERY)) {
458 rdev->pm.requested_power_state_index = i;
459 break;
460 }
461 }
462 /* if nothing selected, grab the default state. */
463 if (rdev->pm.requested_power_state_index == -1)
464 rdev->pm.requested_power_state_index = 0;
465 } else
466 rdev->pm.requested_power_state_index = 1;
467
Alex Deucherce8f5372010-05-07 15:10:16 -0400468 switch (rdev->pm.dynpm_planned_action) {
469 case DYNPM_ACTION_MINIMUM:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400470 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400471 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400472 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400473 case DYNPM_ACTION_DOWNCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400474 if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
475 if (rdev->pm.current_clock_mode_index == 0) {
476 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400477 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400478 } else
479 rdev->pm.requested_clock_mode_index =
480 rdev->pm.current_clock_mode_index - 1;
481 } else {
482 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400483 rdev->pm.dynpm_can_downclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400484 }
Alex Deucherd7311172010-05-03 01:13:14 -0400485 /* don't use the power state if crtcs are active and no display flag is set */
486 if ((rdev->pm.active_crtc_count > 0) &&
487 (rdev->pm.power_state[rdev->pm.requested_power_state_index].
488 clock_info[rdev->pm.requested_clock_mode_index].flags &
489 RADEON_PM_MODE_NO_DISPLAY)) {
490 rdev->pm.requested_clock_mode_index++;
491 }
Alex Deuchera48b9b42010-04-22 14:03:55 -0400492 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400493 case DYNPM_ACTION_UPCLOCK:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400494 if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
495 if (rdev->pm.current_clock_mode_index ==
496 (rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1)) {
497 rdev->pm.requested_clock_mode_index = rdev->pm.current_clock_mode_index;
Alex Deucherce8f5372010-05-07 15:10:16 -0400498 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400499 } else
500 rdev->pm.requested_clock_mode_index =
501 rdev->pm.current_clock_mode_index + 1;
502 } else {
503 rdev->pm.requested_clock_mode_index =
504 rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400505 rdev->pm.dynpm_can_upclock = false;
Alex Deuchera48b9b42010-04-22 14:03:55 -0400506 }
507 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400508 case DYNPM_ACTION_DEFAULT:
Alex Deucher58e21df2010-03-22 13:31:08 -0400509 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
510 rdev->pm.requested_clock_mode_index = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400511 rdev->pm.dynpm_can_upclock = false;
Alex Deucher58e21df2010-03-22 13:31:08 -0400512 break;
Alex Deucherce8f5372010-05-07 15:10:16 -0400513 case DYNPM_ACTION_NONE:
Alex Deuchera48b9b42010-04-22 14:03:55 -0400514 default:
515 DRM_ERROR("Requested mode for not defined action\n");
516 return;
517 }
518 }
519
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000520 DRM_DEBUG_DRIVER("Requested: e: %d m: %d p: %d\n",
Alex Deucherce8a3eb2010-05-07 16:58:27 -0400521 rdev->pm.power_state[rdev->pm.requested_power_state_index].
522 clock_info[rdev->pm.requested_clock_mode_index].sclk,
523 rdev->pm.power_state[rdev->pm.requested_power_state_index].
524 clock_info[rdev->pm.requested_clock_mode_index].mclk,
525 rdev->pm.power_state[rdev->pm.requested_power_state_index].
526 pcie_lanes);
Alex Deuchera48b9b42010-04-22 14:03:55 -0400527}
528
Alex Deucherce8f5372010-05-07 15:10:16 -0400529void rs780_pm_init_profile(struct radeon_device *rdev)
530{
531 if (rdev->pm.num_power_states == 2) {
532 /* default */
533 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
534 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
535 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
536 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
537 /* low sh */
538 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0;
539 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0;
540 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
541 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400542 /* mid sh */
543 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0;
544 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 0;
545 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
546 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400547 /* high sh */
548 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0;
549 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
550 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
551 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
552 /* low mh */
553 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0;
554 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
555 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
556 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400557 /* mid mh */
558 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0;
559 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
560 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
561 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400562 /* high mh */
563 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0;
564 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 1;
565 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
566 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
567 } else if (rdev->pm.num_power_states == 3) {
568 /* default */
569 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
570 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
571 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
572 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
573 /* low sh */
574 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
575 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
576 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
577 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400578 /* mid sh */
579 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
580 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
581 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
582 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400583 /* high sh */
584 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
585 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 2;
586 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
587 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
588 /* low mh */
589 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 1;
590 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 1;
591 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
592 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400593 /* mid mh */
594 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 1;
595 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 1;
596 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
597 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400598 /* high mh */
599 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 1;
600 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
601 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
602 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
603 } else {
604 /* default */
605 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
606 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
607 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
608 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
609 /* low sh */
610 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 2;
611 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 2;
612 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
613 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400614 /* mid sh */
615 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 2;
616 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 2;
617 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
618 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400619 /* high sh */
620 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 2;
621 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 3;
622 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
623 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
624 /* low mh */
625 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
626 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
627 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
628 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400629 /* mid mh */
630 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
631 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
632 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
633 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400634 /* high mh */
635 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
636 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 3;
637 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
638 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
639 }
640}
641
642void r600_pm_init_profile(struct radeon_device *rdev)
643{
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400644 int idx;
645
Alex Deucherce8f5372010-05-07 15:10:16 -0400646 if (rdev->family == CHIP_R600) {
647 /* XXX */
648 /* default */
649 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
650 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
651 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400652 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400653 /* low sh */
654 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
655 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
656 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400657 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400658 /* mid sh */
659 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
660 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
661 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
662 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400663 /* high sh */
664 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
665 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
666 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400667 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400668 /* low mh */
669 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
670 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
671 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400672 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400673 /* mid mh */
674 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
675 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
676 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
677 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400678 /* high mh */
679 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
680 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
681 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucher4bff5172010-05-17 19:41:26 -0400682 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherce8f5372010-05-07 15:10:16 -0400683 } else {
684 if (rdev->pm.num_power_states < 4) {
685 /* default */
686 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
687 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
688 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
689 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
690 /* low sh */
Alex Deucherce8f5372010-05-07 15:10:16 -0400691 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
692 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
693 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400694 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
695 /* mid sh */
696 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
697 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
698 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
699 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400700 /* high sh */
701 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
702 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
703 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
704 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
705 /* low mh */
Alex Deucher4bff5172010-05-17 19:41:26 -0400706 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
707 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 2;
Alex Deucherce8f5372010-05-07 15:10:16 -0400708 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400709 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
710 /* low mh */
711 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
712 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 2;
713 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
714 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
Alex Deucherce8f5372010-05-07 15:10:16 -0400715 /* high mh */
Alex Deucher4bff5172010-05-17 19:41:26 -0400716 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
717 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
718 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
719 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
720 } else {
721 /* default */
722 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
723 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
724 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
725 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
726 /* low sh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400727 if (rdev->flags & RADEON_IS_MOBILITY)
728 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
729 else
730 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
731 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
732 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
733 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
734 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400735 /* mid sh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400736 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
737 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
738 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
739 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
Alex Deucher4bff5172010-05-17 19:41:26 -0400740 /* high sh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400741 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
742 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
743 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
Alex Deucher4bff5172010-05-17 19:41:26 -0400744 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
745 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
746 /* low mh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400747 if (rdev->flags & RADEON_IS_MOBILITY)
748 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
749 else
750 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
751 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
752 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
753 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
754 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
Alex Deucherc9e75b22010-06-02 17:56:01 -0400755 /* mid mh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400756 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
757 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
758 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
759 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
Alex Deucher4bff5172010-05-17 19:41:26 -0400760 /* high mh */
Alex Deucherbbe26ff2011-11-04 10:09:42 -0400761 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
762 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
763 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
Alex Deucherce8f5372010-05-07 15:10:16 -0400764 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
765 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
766 }
767 }
Alex Deucherbae6b5622010-04-22 13:38:05 -0400768}
769
Alex Deucher49e02b72010-04-23 17:57:27 -0400770void r600_pm_misc(struct radeon_device *rdev)
771{
Rafał Miłeckia081a9d2010-06-07 18:20:25 -0400772 int req_ps_idx = rdev->pm.requested_power_state_index;
773 int req_cm_idx = rdev->pm.requested_clock_mode_index;
774 struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
775 struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
Alex Deucher7ac9aa52010-05-27 19:25:54 -0400776
Alex Deucher4d601732010-06-07 18:15:18 -0400777 if ((voltage->type == VOLTAGE_SW) && voltage->voltage) {
Alex Deuchera377e182011-06-20 13:00:31 -0400778 /* 0xff01 is a flag rather then an actual voltage */
779 if (voltage->voltage == 0xff01)
780 return;
Alex Deucher4d601732010-06-07 18:15:18 -0400781 if (voltage->voltage != rdev->pm.current_vddc) {
Alex Deucher8a83ec52011-04-12 14:49:23 -0400782 radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
Alex Deucher4d601732010-06-07 18:15:18 -0400783 rdev->pm.current_vddc = voltage->voltage;
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000784 DRM_DEBUG_DRIVER("Setting: v: %d\n", voltage->voltage);
Alex Deucher4d601732010-06-07 18:15:18 -0400785 }
786 }
Alex Deucher49e02b72010-04-23 17:57:27 -0400787}
788
Alex Deucherdef9ba92010-04-22 12:39:58 -0400789bool r600_gui_idle(struct radeon_device *rdev)
790{
791 if (RREG32(GRBM_STATUS) & GUI_ACTIVE)
792 return false;
793 else
794 return true;
795}
796
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500797/* hpd for digital panel detect/disconnect */
798bool r600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
799{
800 bool connected = false;
801
802 if (ASIC_IS_DCE3(rdev)) {
803 switch (hpd) {
804 case RADEON_HPD_1:
805 if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
806 connected = true;
807 break;
808 case RADEON_HPD_2:
809 if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
810 connected = true;
811 break;
812 case RADEON_HPD_3:
813 if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
814 connected = true;
815 break;
816 case RADEON_HPD_4:
817 if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
818 connected = true;
819 break;
820 /* DCE 3.2 */
821 case RADEON_HPD_5:
822 if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
823 connected = true;
824 break;
825 case RADEON_HPD_6:
826 if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
827 connected = true;
828 break;
829 default:
830 break;
831 }
832 } else {
833 switch (hpd) {
834 case RADEON_HPD_1:
835 if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
836 connected = true;
837 break;
838 case RADEON_HPD_2:
839 if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
840 connected = true;
841 break;
842 case RADEON_HPD_3:
843 if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
844 connected = true;
845 break;
846 default:
847 break;
848 }
849 }
850 return connected;
851}
852
853void r600_hpd_set_polarity(struct radeon_device *rdev,
Alex Deucher429770b2009-12-04 15:26:55 -0500854 enum radeon_hpd_id hpd)
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500855{
856 u32 tmp;
857 bool connected = r600_hpd_sense(rdev, hpd);
858
859 if (ASIC_IS_DCE3(rdev)) {
860 switch (hpd) {
861 case RADEON_HPD_1:
862 tmp = RREG32(DC_HPD1_INT_CONTROL);
863 if (connected)
864 tmp &= ~DC_HPDx_INT_POLARITY;
865 else
866 tmp |= DC_HPDx_INT_POLARITY;
867 WREG32(DC_HPD1_INT_CONTROL, tmp);
868 break;
869 case RADEON_HPD_2:
870 tmp = RREG32(DC_HPD2_INT_CONTROL);
871 if (connected)
872 tmp &= ~DC_HPDx_INT_POLARITY;
873 else
874 tmp |= DC_HPDx_INT_POLARITY;
875 WREG32(DC_HPD2_INT_CONTROL, tmp);
876 break;
877 case RADEON_HPD_3:
878 tmp = RREG32(DC_HPD3_INT_CONTROL);
879 if (connected)
880 tmp &= ~DC_HPDx_INT_POLARITY;
881 else
882 tmp |= DC_HPDx_INT_POLARITY;
883 WREG32(DC_HPD3_INT_CONTROL, tmp);
884 break;
885 case RADEON_HPD_4:
886 tmp = RREG32(DC_HPD4_INT_CONTROL);
887 if (connected)
888 tmp &= ~DC_HPDx_INT_POLARITY;
889 else
890 tmp |= DC_HPDx_INT_POLARITY;
891 WREG32(DC_HPD4_INT_CONTROL, tmp);
892 break;
893 case RADEON_HPD_5:
894 tmp = RREG32(DC_HPD5_INT_CONTROL);
895 if (connected)
896 tmp &= ~DC_HPDx_INT_POLARITY;
897 else
898 tmp |= DC_HPDx_INT_POLARITY;
899 WREG32(DC_HPD5_INT_CONTROL, tmp);
900 break;
901 /* DCE 3.2 */
902 case RADEON_HPD_6:
903 tmp = RREG32(DC_HPD6_INT_CONTROL);
904 if (connected)
905 tmp &= ~DC_HPDx_INT_POLARITY;
906 else
907 tmp |= DC_HPDx_INT_POLARITY;
908 WREG32(DC_HPD6_INT_CONTROL, tmp);
909 break;
910 default:
911 break;
912 }
913 } else {
914 switch (hpd) {
915 case RADEON_HPD_1:
916 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
917 if (connected)
918 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
919 else
920 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
921 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
922 break;
923 case RADEON_HPD_2:
924 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
925 if (connected)
926 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
927 else
928 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
929 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
930 break;
931 case RADEON_HPD_3:
932 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
933 if (connected)
934 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
935 else
936 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
937 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
938 break;
939 default:
940 break;
941 }
942 }
943}
944
945void r600_hpd_init(struct radeon_device *rdev)
946{
947 struct drm_device *dev = rdev->ddev;
948 struct drm_connector *connector;
Christian Koenigfb982572012-05-17 01:33:30 +0200949 unsigned enable = 0;
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500950
Alex Deucher64912e92011-11-03 11:21:39 -0400951 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
952 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500953
Jerome Glisse455c89b2012-05-04 11:06:22 -0400954 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
955 connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
956 /* don't try to enable hpd on eDP or LVDS avoid breaking the
957 * aux dp channel on imac and help (but not completely fix)
958 * https://bugzilla.redhat.com/show_bug.cgi?id=726143
959 */
960 continue;
961 }
Alex Deucher64912e92011-11-03 11:21:39 -0400962 if (ASIC_IS_DCE3(rdev)) {
963 u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
964 if (ASIC_IS_DCE32(rdev))
965 tmp |= DC_HPDx_EN;
966
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500967 switch (radeon_connector->hpd.hpd) {
968 case RADEON_HPD_1:
969 WREG32(DC_HPD1_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500970 break;
971 case RADEON_HPD_2:
972 WREG32(DC_HPD2_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500973 break;
974 case RADEON_HPD_3:
975 WREG32(DC_HPD3_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500976 break;
977 case RADEON_HPD_4:
978 WREG32(DC_HPD4_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500979 break;
980 /* DCE 3.2 */
981 case RADEON_HPD_5:
982 WREG32(DC_HPD5_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500983 break;
984 case RADEON_HPD_6:
985 WREG32(DC_HPD6_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500986 break;
987 default:
988 break;
989 }
Alex Deucher64912e92011-11-03 11:21:39 -0400990 } else {
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500991 switch (radeon_connector->hpd.hpd) {
992 case RADEON_HPD_1:
993 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500994 break;
995 case RADEON_HPD_2:
996 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, DC_HOT_PLUG_DETECTx_EN);
Alex Deuchere0df1ac2009-12-04 15:12:21 -0500997 break;
998 case RADEON_HPD_3:
999 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, DC_HOT_PLUG_DETECTx_EN);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001000 break;
1001 default:
1002 break;
1003 }
1004 }
Christian Koenigfb982572012-05-17 01:33:30 +02001005 enable |= 1 << radeon_connector->hpd.hpd;
Alex Deucher64912e92011-11-03 11:21:39 -04001006 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001007 }
Christian Koenigfb982572012-05-17 01:33:30 +02001008 radeon_irq_kms_enable_hpd(rdev, enable);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001009}
1010
1011void r600_hpd_fini(struct radeon_device *rdev)
1012{
1013 struct drm_device *dev = rdev->ddev;
1014 struct drm_connector *connector;
Christian Koenigfb982572012-05-17 01:33:30 +02001015 unsigned disable = 0;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001016
Christian Koenigfb982572012-05-17 01:33:30 +02001017 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1018 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1019 if (ASIC_IS_DCE3(rdev)) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001020 switch (radeon_connector->hpd.hpd) {
1021 case RADEON_HPD_1:
1022 WREG32(DC_HPD1_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001023 break;
1024 case RADEON_HPD_2:
1025 WREG32(DC_HPD2_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001026 break;
1027 case RADEON_HPD_3:
1028 WREG32(DC_HPD3_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001029 break;
1030 case RADEON_HPD_4:
1031 WREG32(DC_HPD4_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001032 break;
1033 /* DCE 3.2 */
1034 case RADEON_HPD_5:
1035 WREG32(DC_HPD5_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001036 break;
1037 case RADEON_HPD_6:
1038 WREG32(DC_HPD6_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001039 break;
1040 default:
1041 break;
1042 }
Christian Koenigfb982572012-05-17 01:33:30 +02001043 } else {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001044 switch (radeon_connector->hpd.hpd) {
1045 case RADEON_HPD_1:
1046 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001047 break;
1048 case RADEON_HPD_2:
1049 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001050 break;
1051 case RADEON_HPD_3:
1052 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001053 break;
1054 default:
1055 break;
1056 }
1057 }
Christian Koenigfb982572012-05-17 01:33:30 +02001058 disable |= 1 << radeon_connector->hpd.hpd;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001059 }
Christian Koenigfb982572012-05-17 01:33:30 +02001060 radeon_irq_kms_disable_hpd(rdev, disable);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05001061}
1062
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001063/*
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001064 * R600 PCIE GART
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001065 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001066void r600_pcie_gart_tlb_flush(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001067{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001068 unsigned i;
1069 u32 tmp;
1070
Dave Airlie2e98f102010-02-15 15:54:45 +10001071 /* flush hdp cache so updates hit vram */
Alex Deucherf3886f82010-12-08 10:05:34 -05001072 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
1073 !(rdev->flags & RADEON_IS_AGP)) {
Jerome Glissec9a1be92011-11-03 11:16:49 -04001074 void __iomem *ptr = (void *)rdev->gart.ptr;
Alex Deucher812d0462010-07-26 18:51:53 -04001075 u32 tmp;
1076
1077 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
1078 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL
Alex Deucherf3886f82010-12-08 10:05:34 -05001079 * This seems to cause problems on some AGP cards. Just use the old
1080 * method for them.
Alex Deucher812d0462010-07-26 18:51:53 -04001081 */
1082 WREG32(HDP_DEBUG1, 0);
1083 tmp = readl((void __iomem *)ptr);
1084 } else
1085 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
Dave Airlie2e98f102010-02-15 15:54:45 +10001086
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001087 WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR, rdev->mc.gtt_start >> 12);
1088 WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR, (rdev->mc.gtt_end - 1) >> 12);
1089 WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
1090 for (i = 0; i < rdev->usec_timeout; i++) {
1091 /* read MC_STATUS */
1092 tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
1093 tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
1094 if (tmp == 2) {
1095 printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
1096 return;
1097 }
1098 if (tmp) {
1099 return;
1100 }
1101 udelay(1);
1102 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001103}
1104
Jerome Glisse4aac0472009-09-14 18:29:49 +02001105int r600_pcie_gart_init(struct radeon_device *rdev)
1106{
1107 int r;
1108
Jerome Glissec9a1be92011-11-03 11:16:49 -04001109 if (rdev->gart.robj) {
Joe Perchesfce7d612010-10-30 21:08:30 +00001110 WARN(1, "R600 PCIE GART already initialized\n");
Jerome Glisse4aac0472009-09-14 18:29:49 +02001111 return 0;
1112 }
1113 /* Initialize common gart structure */
1114 r = radeon_gart_init(rdev);
1115 if (r)
1116 return r;
1117 rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
1118 return radeon_gart_table_vram_alloc(rdev);
1119}
1120
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001121static int r600_pcie_gart_enable(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001122{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001123 u32 tmp;
1124 int r, i;
1125
Jerome Glissec9a1be92011-11-03 11:16:49 -04001126 if (rdev->gart.robj == NULL) {
Jerome Glisse4aac0472009-09-14 18:29:49 +02001127 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
1128 return -EINVAL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001129 }
Jerome Glisse4aac0472009-09-14 18:29:49 +02001130 r = radeon_gart_table_vram_pin(rdev);
1131 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001132 return r;
Dave Airliebc1a6312009-09-15 11:07:52 +10001133
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001134 /* Setup L2 cache */
1135 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
1136 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
1137 EFFECTIVE_L2_QUEUE_SIZE(7));
1138 WREG32(VM_L2_CNTL2, 0);
1139 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
1140 /* Setup TLB control */
1141 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
1142 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
1143 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
1144 ENABLE_WAIT_L2_QUERY;
1145 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
1146 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
1147 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
1148 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
1149 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
1150 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
1151 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
1152 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
1153 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
1154 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
1155 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
1156 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
Christian Königa8fba642013-04-25 18:54:07 +02001157 WREG32(MC_VM_L1_TLB_MCB_RD_UVD_CNTL, tmp);
1158 WREG32(MC_VM_L1_TLB_MCB_WR_UVD_CNTL, tmp);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001159 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
1160 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
1161 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
Christian König7c0411d2015-05-28 15:51:59 +02001162 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001163 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
1164 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
1165 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
1166 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
1167 (u32)(rdev->dummy_page.addr >> 12));
1168 for (i = 1; i < 7; i++)
1169 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
1170
1171 r600_pcie_gart_tlb_flush(rdev);
Tormod Voldenfcf4de52011-08-31 21:54:07 +00001172 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
1173 (unsigned)(rdev->mc.gtt_size >> 20),
1174 (unsigned long long)rdev->gart.table_addr);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001175 rdev->gart.ready = true;
1176 return 0;
1177}
1178
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001179static void r600_pcie_gart_disable(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001180{
1181 u32 tmp;
Jerome Glissec9a1be92011-11-03 11:16:49 -04001182 int i;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001183
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001184 /* Disable all tables */
1185 for (i = 0; i < 7; i++)
1186 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
1187
1188 /* Disable L2 cache */
1189 WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
1190 EFFECTIVE_L2_QUEUE_SIZE(7));
1191 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
1192 /* Setup L1 TLB control */
1193 tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
1194 ENABLE_WAIT_L2_QUERY;
1195 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
1196 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
1197 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
1198 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
1199 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
1200 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
1201 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
1202 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
1203 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp);
1204 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp);
1205 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
1206 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
1207 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp);
1208 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
Christian Königa8fba642013-04-25 18:54:07 +02001209 WREG32(MC_VM_L1_TLB_MCB_RD_UVD_CNTL, tmp);
1210 WREG32(MC_VM_L1_TLB_MCB_WR_UVD_CNTL, tmp);
Jerome Glissec9a1be92011-11-03 11:16:49 -04001211 radeon_gart_table_vram_unpin(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001212}
1213
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001214static void r600_pcie_gart_fini(struct radeon_device *rdev)
Jerome Glisse4aac0472009-09-14 18:29:49 +02001215{
Jerome Glissef9274562010-03-17 14:44:29 +00001216 radeon_gart_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02001217 r600_pcie_gart_disable(rdev);
1218 radeon_gart_table_vram_free(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001219}
1220
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001221static void r600_agp_enable(struct radeon_device *rdev)
Jerome Glisse1a029b72009-10-06 19:04:30 +02001222{
1223 u32 tmp;
1224 int i;
1225
1226 /* Setup L2 cache */
1227 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
1228 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
1229 EFFECTIVE_L2_QUEUE_SIZE(7));
1230 WREG32(VM_L2_CNTL2, 0);
1231 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
1232 /* Setup TLB control */
1233 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
1234 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
1235 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
1236 ENABLE_WAIT_L2_QUERY;
1237 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
1238 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
1239 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
1240 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
1241 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
1242 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
1243 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
1244 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
1245 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
1246 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
1247 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
1248 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
1249 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
1250 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
1251 for (i = 0; i < 7; i++)
1252 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
1253}
1254
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001255int r600_mc_wait_for_idle(struct radeon_device *rdev)
1256{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001257 unsigned i;
1258 u32 tmp;
1259
1260 for (i = 0; i < rdev->usec_timeout; i++) {
1261 /* read MC_STATUS */
1262 tmp = RREG32(R_000E50_SRBM_STATUS) & 0x3F00;
1263 if (!tmp)
1264 return 0;
1265 udelay(1);
1266 }
1267 return -1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001268}
1269
Samuel Li65337e62013-04-05 17:50:53 -04001270uint32_t rs780_mc_rreg(struct radeon_device *rdev, uint32_t reg)
1271{
Alex Deucher0a5b7b02013-09-03 19:00:09 -04001272 unsigned long flags;
Samuel Li65337e62013-04-05 17:50:53 -04001273 uint32_t r;
1274
Alex Deucher0a5b7b02013-09-03 19:00:09 -04001275 spin_lock_irqsave(&rdev->mc_idx_lock, flags);
Samuel Li65337e62013-04-05 17:50:53 -04001276 WREG32(R_0028F8_MC_INDEX, S_0028F8_MC_IND_ADDR(reg));
1277 r = RREG32(R_0028FC_MC_DATA);
1278 WREG32(R_0028F8_MC_INDEX, ~C_0028F8_MC_IND_ADDR);
Alex Deucher0a5b7b02013-09-03 19:00:09 -04001279 spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
Samuel Li65337e62013-04-05 17:50:53 -04001280 return r;
1281}
1282
1283void rs780_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
1284{
Alex Deucher0a5b7b02013-09-03 19:00:09 -04001285 unsigned long flags;
1286
1287 spin_lock_irqsave(&rdev->mc_idx_lock, flags);
Samuel Li65337e62013-04-05 17:50:53 -04001288 WREG32(R_0028F8_MC_INDEX, S_0028F8_MC_IND_ADDR(reg) |
1289 S_0028F8_MC_IND_WR_EN(1));
1290 WREG32(R_0028FC_MC_DATA, v);
1291 WREG32(R_0028F8_MC_INDEX, 0x7F);
Alex Deucher0a5b7b02013-09-03 19:00:09 -04001292 spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
Samuel Li65337e62013-04-05 17:50:53 -04001293}
1294
Jerome Glissea3c19452009-10-01 18:02:13 +02001295static void r600_mc_program(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001296{
Jerome Glissea3c19452009-10-01 18:02:13 +02001297 struct rv515_mc_save save;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001298 u32 tmp;
1299 int i, j;
1300
1301 /* Initialize HDP */
1302 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1303 WREG32((0x2c14 + j), 0x00000000);
1304 WREG32((0x2c18 + j), 0x00000000);
1305 WREG32((0x2c1c + j), 0x00000000);
1306 WREG32((0x2c20 + j), 0x00000000);
1307 WREG32((0x2c24 + j), 0x00000000);
1308 }
1309 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
1310
Jerome Glissea3c19452009-10-01 18:02:13 +02001311 rv515_mc_stop(rdev, &save);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001312 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +02001313 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001314 }
Jerome Glissea3c19452009-10-01 18:02:13 +02001315 /* Lockout access through VGA aperture (doesn't exist before R600) */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001316 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001317 /* Update configuration */
Jerome Glisse1a029b72009-10-06 19:04:30 +02001318 if (rdev->flags & RADEON_IS_AGP) {
1319 if (rdev->mc.vram_start < rdev->mc.gtt_start) {
1320 /* VRAM before AGP */
1321 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1322 rdev->mc.vram_start >> 12);
1323 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1324 rdev->mc.gtt_end >> 12);
1325 } else {
1326 /* VRAM after AGP */
1327 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1328 rdev->mc.gtt_start >> 12);
1329 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1330 rdev->mc.vram_end >> 12);
1331 }
1332 } else {
1333 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12);
1334 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12);
1335 }
Alex Deucher16cdf042011-10-28 10:30:02 -04001336 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
Jerome Glisse1a029b72009-10-06 19:04:30 +02001337 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001338 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
1339 WREG32(MC_VM_FB_LOCATION, tmp);
1340 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
1341 WREG32(HDP_NONSURFACE_INFO, (2 << 7));
Jerome Glisse46fcd2b2010-06-03 19:34:48 +02001342 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001343 if (rdev->flags & RADEON_IS_AGP) {
Jerome Glisse1a029b72009-10-06 19:04:30 +02001344 WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 22);
1345 WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 22);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001346 WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
1347 } else {
1348 WREG32(MC_VM_AGP_BASE, 0);
1349 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
1350 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
1351 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001352 if (r600_mc_wait_for_idle(rdev)) {
Jerome Glissea3c19452009-10-01 18:02:13 +02001353 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001354 }
Jerome Glissea3c19452009-10-01 18:02:13 +02001355 rv515_mc_resume(rdev, &save);
Dave Airlie698443d2009-09-18 14:16:38 +10001356 /* we need to own VRAM, so turn off the VGA renderer here
1357 * to stop it overwriting our objects */
Jerome Glissed39c3b82009-09-28 18:34:43 +02001358 rv515_vga_render_disable(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001359}
1360
Jerome Glissed594e462010-02-17 21:54:29 +00001361/**
1362 * r600_vram_gtt_location - try to find VRAM & GTT location
1363 * @rdev: radeon device structure holding all necessary informations
1364 * @mc: memory controller structure holding memory informations
1365 *
1366 * Function will place try to place VRAM at same place as in CPU (PCI)
1367 * address space as some GPU seems to have issue when we reprogram at
1368 * different address space.
1369 *
1370 * If there is not enough space to fit the unvisible VRAM after the
1371 * aperture then we limit the VRAM size to the aperture.
1372 *
1373 * If we are using AGP then place VRAM adjacent to AGP aperture are we need
1374 * them to be in one from GPU point of view so that we can program GPU to
1375 * catch access outside them (weird GPU policy see ??).
1376 *
1377 * This function will never fails, worst case are limiting VRAM or GTT.
1378 *
1379 * Note: GTT start, end, size should be initialized before calling this
1380 * function on AGP platform.
1381 */
Alex Deucher0ef0c1f2010-11-22 17:56:26 -05001382static void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
Jerome Glissed594e462010-02-17 21:54:29 +00001383{
1384 u64 size_bf, size_af;
1385
1386 if (mc->mc_vram_size > 0xE0000000) {
1387 /* leave room for at least 512M GTT */
1388 dev_warn(rdev->dev, "limiting VRAM\n");
1389 mc->real_vram_size = 0xE0000000;
1390 mc->mc_vram_size = 0xE0000000;
1391 }
1392 if (rdev->flags & RADEON_IS_AGP) {
1393 size_bf = mc->gtt_start;
Alex Deucher9ed8b1f2013-04-08 11:13:01 -04001394 size_af = mc->mc_mask - mc->gtt_end;
Jerome Glissed594e462010-02-17 21:54:29 +00001395 if (size_bf > size_af) {
1396 if (mc->mc_vram_size > size_bf) {
1397 dev_warn(rdev->dev, "limiting VRAM\n");
1398 mc->real_vram_size = size_bf;
1399 mc->mc_vram_size = size_bf;
1400 }
1401 mc->vram_start = mc->gtt_start - mc->mc_vram_size;
1402 } else {
1403 if (mc->mc_vram_size > size_af) {
1404 dev_warn(rdev->dev, "limiting VRAM\n");
1405 mc->real_vram_size = size_af;
1406 mc->mc_vram_size = size_af;
1407 }
Jerome Glissedfc6ae52012-04-17 16:51:38 -04001408 mc->vram_start = mc->gtt_end + 1;
Jerome Glissed594e462010-02-17 21:54:29 +00001409 }
1410 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
1411 dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
1412 mc->mc_vram_size >> 20, mc->vram_start,
1413 mc->vram_end, mc->real_vram_size >> 20);
1414 } else {
1415 u64 base = 0;
Alex Deucher8961d522010-12-03 14:37:22 -05001416 if (rdev->flags & RADEON_IS_IGP) {
1417 base = RREG32(MC_VM_FB_LOCATION) & 0xFFFF;
1418 base <<= 24;
1419 }
Jerome Glissed594e462010-02-17 21:54:29 +00001420 radeon_vram_location(rdev, &rdev->mc, base);
Alex Deucher8d369bb2010-07-15 10:51:10 -04001421 rdev->mc.gtt_base_align = 0;
Jerome Glissed594e462010-02-17 21:54:29 +00001422 radeon_gtt_location(rdev, mc);
1423 }
1424}
1425
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001426static int r600_mc_init(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001427{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001428 u32 tmp;
Alex Deucher5885b7a2009-10-19 17:23:33 -04001429 int chansize, numchan;
Samuel Li65337e62013-04-05 17:50:53 -04001430 uint32_t h_addr, l_addr;
1431 unsigned long long k8_addr;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001432
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001433 /* Get VRAM informations */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001434 rdev->mc.vram_is_ddr = true;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001435 tmp = RREG32(RAMCFG);
1436 if (tmp & CHANSIZE_OVERRIDE) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001437 chansize = 16;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001438 } else if (tmp & CHANSIZE_MASK) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001439 chansize = 64;
1440 } else {
1441 chansize = 32;
1442 }
Alex Deucher5885b7a2009-10-19 17:23:33 -04001443 tmp = RREG32(CHMAP);
1444 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
1445 case 0:
1446 default:
1447 numchan = 1;
1448 break;
1449 case 1:
1450 numchan = 2;
1451 break;
1452 case 2:
1453 numchan = 4;
1454 break;
1455 case 3:
1456 numchan = 8;
1457 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001458 }
Alex Deucher5885b7a2009-10-19 17:23:33 -04001459 rdev->mc.vram_width = numchan * chansize;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001460 /* Could aper size report 0 ? */
Jordan Crouse01d73a62010-05-27 13:40:24 -06001461 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
1462 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001463 /* Setup GPU memory space */
1464 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
1465 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
Jerome Glisse51e5fcd2010-02-19 14:33:54 +00001466 rdev->mc.visible_vram_size = rdev->mc.aper_size;
Jerome Glissed594e462010-02-17 21:54:29 +00001467 r600_vram_gtt_location(rdev, &rdev->mc);
Alex Deucherf47299c2010-03-16 20:54:38 -04001468
Alex Deucherf8920342010-06-30 12:02:03 -04001469 if (rdev->flags & RADEON_IS_IGP) {
1470 rs690_pm_info(rdev);
Alex Deucher06b64762010-01-05 11:27:29 -05001471 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
Samuel Li65337e62013-04-05 17:50:53 -04001472
1473 if (rdev->family == CHIP_RS780 || rdev->family == CHIP_RS880) {
1474 /* Use K8 direct mapping for fast fb access. */
1475 rdev->fastfb_working = false;
1476 h_addr = G_000012_K8_ADDR_EXT(RREG32_MC(R_000012_MC_MISC_UMA_CNTL));
1477 l_addr = RREG32_MC(R_000011_K8_FB_LOCATION);
1478 k8_addr = ((unsigned long long)h_addr) << 32 | l_addr;
1479#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
1480 if (k8_addr + rdev->mc.visible_vram_size < 0x100000000ULL)
1481#endif
1482 {
1483 /* FastFB shall be used with UMA memory. Here it is simply disabled when sideport
1484 * memory is present.
1485 */
1486 if (rdev->mc.igp_sideport_enabled == false && radeon_fastfb == 1) {
1487 DRM_INFO("Direct mapping: aper base at 0x%llx, replaced by direct mapping base 0x%llx.\n",
1488 (unsigned long long)rdev->mc.aper_base, k8_addr);
1489 rdev->mc.aper_base = (resource_size_t)k8_addr;
1490 rdev->fastfb_working = true;
1491 }
1492 }
Jérome Glisse3cf8bb12016-03-16 12:56:45 +01001493 }
Alex Deucherf8920342010-06-30 12:02:03 -04001494 }
Samuel Li65337e62013-04-05 17:50:53 -04001495
Alex Deucherf47299c2010-03-16 20:54:38 -04001496 radeon_update_bandwidth_info(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001497 return 0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001498}
1499
Alex Deucher16cdf042011-10-28 10:30:02 -04001500int r600_vram_scratch_init(struct radeon_device *rdev)
1501{
1502 int r;
1503
1504 if (rdev->vram_scratch.robj == NULL) {
1505 r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE,
1506 PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
Maarten Lankhorst831b6962014-09-18 14:11:56 +02001507 0, NULL, NULL, &rdev->vram_scratch.robj);
Alex Deucher16cdf042011-10-28 10:30:02 -04001508 if (r) {
1509 return r;
1510 }
1511 }
1512
1513 r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
1514 if (unlikely(r != 0))
1515 return r;
1516 r = radeon_bo_pin(rdev->vram_scratch.robj,
1517 RADEON_GEM_DOMAIN_VRAM, &rdev->vram_scratch.gpu_addr);
1518 if (r) {
1519 radeon_bo_unreserve(rdev->vram_scratch.robj);
1520 return r;
1521 }
1522 r = radeon_bo_kmap(rdev->vram_scratch.robj,
1523 (void **)&rdev->vram_scratch.ptr);
1524 if (r)
1525 radeon_bo_unpin(rdev->vram_scratch.robj);
1526 radeon_bo_unreserve(rdev->vram_scratch.robj);
1527
1528 return r;
1529}
1530
1531void r600_vram_scratch_fini(struct radeon_device *rdev)
1532{
1533 int r;
1534
1535 if (rdev->vram_scratch.robj == NULL) {
1536 return;
1537 }
1538 r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
1539 if (likely(r == 0)) {
1540 radeon_bo_kunmap(rdev->vram_scratch.robj);
1541 radeon_bo_unpin(rdev->vram_scratch.robj);
1542 radeon_bo_unreserve(rdev->vram_scratch.robj);
1543 }
1544 radeon_bo_unref(&rdev->vram_scratch.robj);
1545}
1546
Alex Deucher410a3412013-01-18 13:05:39 -05001547void r600_set_bios_scratch_engine_hung(struct radeon_device *rdev, bool hung)
1548{
1549 u32 tmp = RREG32(R600_BIOS_3_SCRATCH);
1550
1551 if (hung)
1552 tmp |= ATOM_S3_ASIC_GUI_ENGINE_HUNG;
1553 else
1554 tmp &= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG;
1555
1556 WREG32(R600_BIOS_3_SCRATCH, tmp);
1557}
1558
Alex Deucherd3cb7812013-01-18 13:53:37 -05001559static void r600_print_gpu_status_regs(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001560{
Jerome Glisse64c56e82013-01-02 17:30:35 -05001561 dev_info(rdev->dev, " R_008010_GRBM_STATUS = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001562 RREG32(R_008010_GRBM_STATUS));
Jerome Glisse64c56e82013-01-02 17:30:35 -05001563 dev_info(rdev->dev, " R_008014_GRBM_STATUS2 = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001564 RREG32(R_008014_GRBM_STATUS2));
Jerome Glisse64c56e82013-01-02 17:30:35 -05001565 dev_info(rdev->dev, " R_000E50_SRBM_STATUS = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001566 RREG32(R_000E50_SRBM_STATUS));
Jerome Glisse440a7cd2012-06-27 12:25:01 -04001567 dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001568 RREG32(CP_STALLED_STAT1));
Jerome Glisse440a7cd2012-06-27 12:25:01 -04001569 dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001570 RREG32(CP_STALLED_STAT2));
Jerome Glisse440a7cd2012-06-27 12:25:01 -04001571 dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001572 RREG32(CP_BUSY_STAT));
Jerome Glisse440a7cd2012-06-27 12:25:01 -04001573 dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n",
Alex Deucherd3cb7812013-01-18 13:53:37 -05001574 RREG32(CP_STAT));
Alex Deucher71e3d152013-01-03 12:20:35 -05001575 dev_info(rdev->dev, " R_00D034_DMA_STATUS_REG = 0x%08X\n",
1576 RREG32(DMA_STATUS_REG));
1577}
1578
Alex Deucherf13f7732013-01-18 18:12:22 -05001579static bool r600_is_display_hung(struct radeon_device *rdev)
1580{
1581 u32 crtc_hung = 0;
1582 u32 crtc_status[2];
1583 u32 i, j, tmp;
1584
1585 for (i = 0; i < rdev->num_crtc; i++) {
1586 if (RREG32(AVIVO_D1CRTC_CONTROL + crtc_offsets[i]) & AVIVO_CRTC_EN) {
1587 crtc_status[i] = RREG32(AVIVO_D1CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
1588 crtc_hung |= (1 << i);
1589 }
1590 }
1591
1592 for (j = 0; j < 10; j++) {
1593 for (i = 0; i < rdev->num_crtc; i++) {
1594 if (crtc_hung & (1 << i)) {
1595 tmp = RREG32(AVIVO_D1CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
1596 if (tmp != crtc_status[i])
1597 crtc_hung &= ~(1 << i);
1598 }
1599 }
1600 if (crtc_hung == 0)
1601 return false;
1602 udelay(100);
1603 }
1604
1605 return true;
1606}
1607
Christian König2483b4e2013-08-13 11:56:54 +02001608u32 r600_gpu_check_soft_reset(struct radeon_device *rdev)
Alex Deucherf13f7732013-01-18 18:12:22 -05001609{
1610 u32 reset_mask = 0;
1611 u32 tmp;
1612
1613 /* GRBM_STATUS */
1614 tmp = RREG32(R_008010_GRBM_STATUS);
1615 if (rdev->family >= CHIP_RV770) {
1616 if (G_008010_PA_BUSY(tmp) | G_008010_SC_BUSY(tmp) |
1617 G_008010_SH_BUSY(tmp) | G_008010_SX_BUSY(tmp) |
1618 G_008010_TA_BUSY(tmp) | G_008010_VGT_BUSY(tmp) |
1619 G_008010_DB03_BUSY(tmp) | G_008010_CB03_BUSY(tmp) |
1620 G_008010_SPI03_BUSY(tmp) | G_008010_VGT_BUSY_NO_DMA(tmp))
1621 reset_mask |= RADEON_RESET_GFX;
1622 } else {
1623 if (G_008010_PA_BUSY(tmp) | G_008010_SC_BUSY(tmp) |
1624 G_008010_SH_BUSY(tmp) | G_008010_SX_BUSY(tmp) |
1625 G_008010_TA03_BUSY(tmp) | G_008010_VGT_BUSY(tmp) |
1626 G_008010_DB03_BUSY(tmp) | G_008010_CB03_BUSY(tmp) |
1627 G_008010_SPI03_BUSY(tmp) | G_008010_VGT_BUSY_NO_DMA(tmp))
1628 reset_mask |= RADEON_RESET_GFX;
1629 }
1630
1631 if (G_008010_CF_RQ_PENDING(tmp) | G_008010_PF_RQ_PENDING(tmp) |
1632 G_008010_CP_BUSY(tmp) | G_008010_CP_COHERENCY_BUSY(tmp))
1633 reset_mask |= RADEON_RESET_CP;
1634
1635 if (G_008010_GRBM_EE_BUSY(tmp))
1636 reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
1637
1638 /* DMA_STATUS_REG */
1639 tmp = RREG32(DMA_STATUS_REG);
1640 if (!(tmp & DMA_IDLE))
1641 reset_mask |= RADEON_RESET_DMA;
1642
1643 /* SRBM_STATUS */
1644 tmp = RREG32(R_000E50_SRBM_STATUS);
1645 if (G_000E50_RLC_RQ_PENDING(tmp) | G_000E50_RLC_BUSY(tmp))
1646 reset_mask |= RADEON_RESET_RLC;
1647
1648 if (G_000E50_IH_BUSY(tmp))
1649 reset_mask |= RADEON_RESET_IH;
1650
1651 if (G_000E50_SEM_BUSY(tmp))
1652 reset_mask |= RADEON_RESET_SEM;
1653
1654 if (G_000E50_GRBM_RQ_PENDING(tmp))
1655 reset_mask |= RADEON_RESET_GRBM;
1656
1657 if (G_000E50_VMC_BUSY(tmp))
1658 reset_mask |= RADEON_RESET_VMC;
1659
1660 if (G_000E50_MCB_BUSY(tmp) | G_000E50_MCDZ_BUSY(tmp) |
1661 G_000E50_MCDY_BUSY(tmp) | G_000E50_MCDX_BUSY(tmp) |
1662 G_000E50_MCDW_BUSY(tmp))
1663 reset_mask |= RADEON_RESET_MC;
1664
1665 if (r600_is_display_hung(rdev))
1666 reset_mask |= RADEON_RESET_DISPLAY;
1667
Alex Deucherd808fc82013-02-28 10:03:08 -05001668 /* Skip MC reset as it's mostly likely not hung, just busy */
1669 if (reset_mask & RADEON_RESET_MC) {
1670 DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
1671 reset_mask &= ~RADEON_RESET_MC;
1672 }
1673
Alex Deucherf13f7732013-01-18 18:12:22 -05001674 return reset_mask;
1675}
1676
1677static void r600_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
Alex Deucher71e3d152013-01-03 12:20:35 -05001678{
1679 struct rv515_mc_save save;
Alex Deucherd3cb7812013-01-18 13:53:37 -05001680 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
1681 u32 tmp;
Alex Deucher19fc42e2013-01-14 11:04:39 -05001682
Alex Deucher71e3d152013-01-03 12:20:35 -05001683 if (reset_mask == 0)
Alex Deucherf13f7732013-01-18 18:12:22 -05001684 return;
Alex Deucher71e3d152013-01-03 12:20:35 -05001685
1686 dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
1687
Alex Deucherd3cb7812013-01-18 13:53:37 -05001688 r600_print_gpu_status_regs(rdev);
1689
Alex Deucherd3cb7812013-01-18 13:53:37 -05001690 /* Disable CP parsing/prefetching */
1691 if (rdev->family >= CHIP_RV770)
1692 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1) | S_0086D8_CP_PFP_HALT(1));
1693 else
1694 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
Alex Deucher71e3d152013-01-03 12:20:35 -05001695
Alex Deucherd3cb7812013-01-18 13:53:37 -05001696 /* disable the RLC */
1697 WREG32(RLC_CNTL, 0);
1698
1699 if (reset_mask & RADEON_RESET_DMA) {
1700 /* Disable DMA */
1701 tmp = RREG32(DMA_RB_CNTL);
1702 tmp &= ~DMA_RB_ENABLE;
1703 WREG32(DMA_RB_CNTL, tmp);
1704 }
1705
1706 mdelay(50);
1707
Alex Deucherca578022013-01-23 18:56:08 -05001708 rv515_mc_stop(rdev, &save);
1709 if (r600_mc_wait_for_idle(rdev)) {
1710 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
1711 }
1712
Alex Deucherd3cb7812013-01-18 13:53:37 -05001713 if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE)) {
1714 if (rdev->family >= CHIP_RV770)
1715 grbm_soft_reset |= S_008020_SOFT_RESET_DB(1) |
1716 S_008020_SOFT_RESET_CB(1) |
1717 S_008020_SOFT_RESET_PA(1) |
1718 S_008020_SOFT_RESET_SC(1) |
1719 S_008020_SOFT_RESET_SPI(1) |
1720 S_008020_SOFT_RESET_SX(1) |
1721 S_008020_SOFT_RESET_SH(1) |
1722 S_008020_SOFT_RESET_TC(1) |
1723 S_008020_SOFT_RESET_TA(1) |
1724 S_008020_SOFT_RESET_VC(1) |
1725 S_008020_SOFT_RESET_VGT(1);
1726 else
1727 grbm_soft_reset |= S_008020_SOFT_RESET_CR(1) |
1728 S_008020_SOFT_RESET_DB(1) |
1729 S_008020_SOFT_RESET_CB(1) |
1730 S_008020_SOFT_RESET_PA(1) |
1731 S_008020_SOFT_RESET_SC(1) |
1732 S_008020_SOFT_RESET_SMX(1) |
1733 S_008020_SOFT_RESET_SPI(1) |
1734 S_008020_SOFT_RESET_SX(1) |
1735 S_008020_SOFT_RESET_SH(1) |
1736 S_008020_SOFT_RESET_TC(1) |
1737 S_008020_SOFT_RESET_TA(1) |
1738 S_008020_SOFT_RESET_VC(1) |
1739 S_008020_SOFT_RESET_VGT(1);
1740 }
1741
1742 if (reset_mask & RADEON_RESET_CP) {
1743 grbm_soft_reset |= S_008020_SOFT_RESET_CP(1) |
1744 S_008020_SOFT_RESET_VGT(1);
1745
1746 srbm_soft_reset |= S_000E60_SOFT_RESET_GRBM(1);
1747 }
1748
1749 if (reset_mask & RADEON_RESET_DMA) {
1750 if (rdev->family >= CHIP_RV770)
1751 srbm_soft_reset |= RV770_SOFT_RESET_DMA;
1752 else
1753 srbm_soft_reset |= SOFT_RESET_DMA;
1754 }
1755
Alex Deucherf13f7732013-01-18 18:12:22 -05001756 if (reset_mask & RADEON_RESET_RLC)
1757 srbm_soft_reset |= S_000E60_SOFT_RESET_RLC(1);
1758
1759 if (reset_mask & RADEON_RESET_SEM)
1760 srbm_soft_reset |= S_000E60_SOFT_RESET_SEM(1);
1761
1762 if (reset_mask & RADEON_RESET_IH)
1763 srbm_soft_reset |= S_000E60_SOFT_RESET_IH(1);
1764
1765 if (reset_mask & RADEON_RESET_GRBM)
1766 srbm_soft_reset |= S_000E60_SOFT_RESET_GRBM(1);
1767
Alex Deucher24178ec2013-01-24 15:00:17 -05001768 if (!(rdev->flags & RADEON_IS_IGP)) {
1769 if (reset_mask & RADEON_RESET_MC)
1770 srbm_soft_reset |= S_000E60_SOFT_RESET_MC(1);
1771 }
Alex Deucherf13f7732013-01-18 18:12:22 -05001772
1773 if (reset_mask & RADEON_RESET_VMC)
1774 srbm_soft_reset |= S_000E60_SOFT_RESET_VMC(1);
1775
Alex Deucherd3cb7812013-01-18 13:53:37 -05001776 if (grbm_soft_reset) {
1777 tmp = RREG32(R_008020_GRBM_SOFT_RESET);
1778 tmp |= grbm_soft_reset;
1779 dev_info(rdev->dev, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
1780 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
1781 tmp = RREG32(R_008020_GRBM_SOFT_RESET);
1782
1783 udelay(50);
1784
1785 tmp &= ~grbm_soft_reset;
1786 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
1787 tmp = RREG32(R_008020_GRBM_SOFT_RESET);
1788 }
1789
1790 if (srbm_soft_reset) {
1791 tmp = RREG32(SRBM_SOFT_RESET);
1792 tmp |= srbm_soft_reset;
1793 dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
1794 WREG32(SRBM_SOFT_RESET, tmp);
1795 tmp = RREG32(SRBM_SOFT_RESET);
1796
1797 udelay(50);
1798
1799 tmp &= ~srbm_soft_reset;
1800 WREG32(SRBM_SOFT_RESET, tmp);
1801 tmp = RREG32(SRBM_SOFT_RESET);
1802 }
Alex Deucher71e3d152013-01-03 12:20:35 -05001803
1804 /* Wait a little for things to settle down */
1805 mdelay(1);
1806
Jerome Glissea3c19452009-10-01 18:02:13 +02001807 rv515_mc_resume(rdev, &save);
Alex Deucherd3cb7812013-01-18 13:53:37 -05001808 udelay(50);
Alex Deucher410a3412013-01-18 13:05:39 -05001809
Alex Deucherd3cb7812013-01-18 13:53:37 -05001810 r600_print_gpu_status_regs(rdev);
Alex Deucherd3cb7812013-01-18 13:53:37 -05001811}
1812
Alex Deucherde9ae742013-11-01 19:01:36 -04001813static void r600_gpu_pci_config_reset(struct radeon_device *rdev)
1814{
1815 struct rv515_mc_save save;
1816 u32 tmp, i;
1817
1818 dev_info(rdev->dev, "GPU pci config reset\n");
1819
1820 /* disable dpm? */
1821
1822 /* Disable CP parsing/prefetching */
1823 if (rdev->family >= CHIP_RV770)
1824 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1) | S_0086D8_CP_PFP_HALT(1));
1825 else
1826 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
1827
1828 /* disable the RLC */
1829 WREG32(RLC_CNTL, 0);
1830
1831 /* Disable DMA */
1832 tmp = RREG32(DMA_RB_CNTL);
1833 tmp &= ~DMA_RB_ENABLE;
1834 WREG32(DMA_RB_CNTL, tmp);
1835
1836 mdelay(50);
1837
1838 /* set mclk/sclk to bypass */
1839 if (rdev->family >= CHIP_RV770)
1840 rv770_set_clk_bypass_mode(rdev);
1841 /* disable BM */
1842 pci_clear_master(rdev->pdev);
1843 /* disable mem access */
1844 rv515_mc_stop(rdev, &save);
1845 if (r600_mc_wait_for_idle(rdev)) {
1846 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
1847 }
1848
1849 /* BIF reset workaround. Not sure if this is needed on 6xx */
1850 tmp = RREG32(BUS_CNTL);
1851 tmp |= VGA_COHE_SPEC_TIMER_DIS;
1852 WREG32(BUS_CNTL, tmp);
1853
1854 tmp = RREG32(BIF_SCRATCH0);
1855
1856 /* reset */
1857 radeon_pci_config_reset(rdev);
1858 mdelay(1);
1859
1860 /* BIF reset workaround. Not sure if this is needed on 6xx */
1861 tmp = SOFT_RESET_BIF;
1862 WREG32(SRBM_SOFT_RESET, tmp);
1863 mdelay(1);
1864 WREG32(SRBM_SOFT_RESET, 0);
1865
1866 /* wait for asic to come out of reset */
1867 for (i = 0; i < rdev->usec_timeout; i++) {
1868 if (RREG32(CONFIG_MEMSIZE) != 0xffffffff)
1869 break;
1870 udelay(1);
1871 }
1872}
1873
Jérome Glisse71fe2892016-03-18 16:58:38 +01001874int r600_asic_reset(struct radeon_device *rdev, bool hard)
Alex Deucherd3cb7812013-01-18 13:53:37 -05001875{
Alex Deucherf13f7732013-01-18 18:12:22 -05001876 u32 reset_mask;
1877
Jérome Glisse71fe2892016-03-18 16:58:38 +01001878 if (hard) {
1879 r600_gpu_pci_config_reset(rdev);
1880 return 0;
1881 }
1882
Alex Deucherf13f7732013-01-18 18:12:22 -05001883 reset_mask = r600_gpu_check_soft_reset(rdev);
1884
1885 if (reset_mask)
1886 r600_set_bios_scratch_engine_hung(rdev, true);
1887
Alex Deucherde9ae742013-11-01 19:01:36 -04001888 /* try soft reset */
Alex Deucherf13f7732013-01-18 18:12:22 -05001889 r600_gpu_soft_reset(rdev, reset_mask);
1890
1891 reset_mask = r600_gpu_check_soft_reset(rdev);
1892
Alex Deucherde9ae742013-11-01 19:01:36 -04001893 /* try pci config reset */
1894 if (reset_mask && radeon_hard_reset)
1895 r600_gpu_pci_config_reset(rdev);
1896
1897 reset_mask = r600_gpu_check_soft_reset(rdev);
1898
Alex Deucherf13f7732013-01-18 18:12:22 -05001899 if (!reset_mask)
1900 r600_set_bios_scratch_engine_hung(rdev, false);
1901
1902 return 0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001903}
1904
Alex Deucher123bc182013-01-24 11:37:19 -05001905/**
1906 * r600_gfx_is_lockup - Check if the GFX engine is locked up
1907 *
1908 * @rdev: radeon_device pointer
1909 * @ring: radeon_ring structure holding ring information
1910 *
1911 * Check if the GFX engine is locked up.
1912 * Returns true if the engine appears to be locked up, false if not.
1913 */
1914bool r600_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
Jerome Glisse225758d2010-03-09 14:45:10 +00001915{
Alex Deucher123bc182013-01-24 11:37:19 -05001916 u32 reset_mask = r600_gpu_check_soft_reset(rdev);
Jerome Glisse225758d2010-03-09 14:45:10 +00001917
Alex Deucher123bc182013-01-24 11:37:19 -05001918 if (!(reset_mask & (RADEON_RESET_GFX |
1919 RADEON_RESET_COMPUTE |
1920 RADEON_RESET_CP))) {
Christian Königff212f22014-02-18 14:52:33 +01001921 radeon_ring_lockup_update(rdev, ring);
Jerome Glisse225758d2010-03-09 14:45:10 +00001922 return false;
1923 }
Christian König069211e2012-05-02 15:11:20 +02001924 return radeon_ring_test_lockup(rdev, ring);
Jerome Glisse225758d2010-03-09 14:45:10 +00001925}
1926
Alex Deucher416a2bd2012-05-31 19:00:25 -04001927u32 r6xx_remap_render_backend(struct radeon_device *rdev,
1928 u32 tiling_pipe_num,
1929 u32 max_rb_num,
1930 u32 total_max_rb_num,
1931 u32 disabled_rb_mask)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001932{
Alex Deucher416a2bd2012-05-31 19:00:25 -04001933 u32 rendering_pipe_num, rb_num_width, req_rb_num;
Mikko Tiihonenf689e3a2013-01-30 14:10:04 -05001934 u32 pipe_rb_ratio, pipe_rb_remain, tmp;
Alex Deucher416a2bd2012-05-31 19:00:25 -04001935 u32 data = 0, mask = 1 << (max_rb_num - 1);
1936 unsigned i, j;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001937
Alex Deucher416a2bd2012-05-31 19:00:25 -04001938 /* mask out the RBs that don't exist on that asic */
Mikko Tiihonenf689e3a2013-01-30 14:10:04 -05001939 tmp = disabled_rb_mask | ((0xff << max_rb_num) & 0xff);
1940 /* make sure at least one RB is available */
1941 if ((tmp & 0xff) != 0xff)
1942 disabled_rb_mask = tmp;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001943
Alex Deucher416a2bd2012-05-31 19:00:25 -04001944 rendering_pipe_num = 1 << tiling_pipe_num;
1945 req_rb_num = total_max_rb_num - r600_count_pipe_bits(disabled_rb_mask);
1946 BUG_ON(rendering_pipe_num < req_rb_num);
1947
1948 pipe_rb_ratio = rendering_pipe_num / req_rb_num;
1949 pipe_rb_remain = rendering_pipe_num - pipe_rb_ratio * req_rb_num;
1950
1951 if (rdev->family <= CHIP_RV740) {
1952 /* r6xx/r7xx */
1953 rb_num_width = 2;
1954 } else {
1955 /* eg+ */
1956 rb_num_width = 4;
1957 }
1958
1959 for (i = 0; i < max_rb_num; i++) {
1960 if (!(mask & disabled_rb_mask)) {
1961 for (j = 0; j < pipe_rb_ratio; j++) {
1962 data <<= rb_num_width;
1963 data |= max_rb_num - i - 1;
1964 }
1965 if (pipe_rb_remain) {
1966 data <<= rb_num_width;
1967 data |= max_rb_num - i - 1;
1968 pipe_rb_remain--;
1969 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001970 }
Alex Deucher416a2bd2012-05-31 19:00:25 -04001971 mask >>= 1;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001972 }
1973
Alex Deucher416a2bd2012-05-31 19:00:25 -04001974 return data;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001975}
1976
1977int r600_count_pipe_bits(uint32_t val)
1978{
Akinobu Mitaef8cf3a2012-11-09 12:10:41 +00001979 return hweight32(val);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001980}
1981
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001982static void r600_gpu_init(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001983{
1984 u32 tiling_config;
1985 u32 ramcfg;
Alex Deucherd03f5d52010-02-19 16:22:31 -05001986 u32 cc_gc_shader_pipe_config;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001987 u32 tmp;
1988 int i, j;
1989 u32 sq_config;
1990 u32 sq_gpr_resource_mgmt_1 = 0;
1991 u32 sq_gpr_resource_mgmt_2 = 0;
1992 u32 sq_thread_resource_mgmt = 0;
1993 u32 sq_stack_resource_mgmt_1 = 0;
1994 u32 sq_stack_resource_mgmt_2 = 0;
Alex Deucher416a2bd2012-05-31 19:00:25 -04001995 u32 disabled_rb_mask;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001996
Alex Deucher416a2bd2012-05-31 19:00:25 -04001997 rdev->config.r600.tiling_group_size = 256;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10001998 switch (rdev->family) {
1999 case CHIP_R600:
2000 rdev->config.r600.max_pipes = 4;
2001 rdev->config.r600.max_tile_pipes = 8;
2002 rdev->config.r600.max_simds = 4;
2003 rdev->config.r600.max_backends = 4;
2004 rdev->config.r600.max_gprs = 256;
2005 rdev->config.r600.max_threads = 192;
2006 rdev->config.r600.max_stack_entries = 256;
2007 rdev->config.r600.max_hw_contexts = 8;
2008 rdev->config.r600.max_gs_threads = 16;
2009 rdev->config.r600.sx_max_export_size = 128;
2010 rdev->config.r600.sx_max_export_pos_size = 16;
2011 rdev->config.r600.sx_max_export_smx_size = 128;
2012 rdev->config.r600.sq_num_cf_insts = 2;
2013 break;
2014 case CHIP_RV630:
2015 case CHIP_RV635:
2016 rdev->config.r600.max_pipes = 2;
2017 rdev->config.r600.max_tile_pipes = 2;
2018 rdev->config.r600.max_simds = 3;
2019 rdev->config.r600.max_backends = 1;
2020 rdev->config.r600.max_gprs = 128;
2021 rdev->config.r600.max_threads = 192;
2022 rdev->config.r600.max_stack_entries = 128;
2023 rdev->config.r600.max_hw_contexts = 8;
2024 rdev->config.r600.max_gs_threads = 4;
2025 rdev->config.r600.sx_max_export_size = 128;
2026 rdev->config.r600.sx_max_export_pos_size = 16;
2027 rdev->config.r600.sx_max_export_smx_size = 128;
2028 rdev->config.r600.sq_num_cf_insts = 2;
2029 break;
2030 case CHIP_RV610:
2031 case CHIP_RV620:
2032 case CHIP_RS780:
2033 case CHIP_RS880:
2034 rdev->config.r600.max_pipes = 1;
2035 rdev->config.r600.max_tile_pipes = 1;
2036 rdev->config.r600.max_simds = 2;
2037 rdev->config.r600.max_backends = 1;
2038 rdev->config.r600.max_gprs = 128;
2039 rdev->config.r600.max_threads = 192;
2040 rdev->config.r600.max_stack_entries = 128;
2041 rdev->config.r600.max_hw_contexts = 4;
2042 rdev->config.r600.max_gs_threads = 4;
2043 rdev->config.r600.sx_max_export_size = 128;
2044 rdev->config.r600.sx_max_export_pos_size = 16;
2045 rdev->config.r600.sx_max_export_smx_size = 128;
2046 rdev->config.r600.sq_num_cf_insts = 1;
2047 break;
2048 case CHIP_RV670:
2049 rdev->config.r600.max_pipes = 4;
2050 rdev->config.r600.max_tile_pipes = 4;
2051 rdev->config.r600.max_simds = 4;
2052 rdev->config.r600.max_backends = 4;
2053 rdev->config.r600.max_gprs = 192;
2054 rdev->config.r600.max_threads = 192;
2055 rdev->config.r600.max_stack_entries = 256;
2056 rdev->config.r600.max_hw_contexts = 8;
2057 rdev->config.r600.max_gs_threads = 16;
2058 rdev->config.r600.sx_max_export_size = 128;
2059 rdev->config.r600.sx_max_export_pos_size = 16;
2060 rdev->config.r600.sx_max_export_smx_size = 128;
2061 rdev->config.r600.sq_num_cf_insts = 2;
2062 break;
2063 default:
2064 break;
2065 }
2066
2067 /* Initialize HDP */
2068 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
2069 WREG32((0x2c14 + j), 0x00000000);
2070 WREG32((0x2c18 + j), 0x00000000);
2071 WREG32((0x2c1c + j), 0x00000000);
2072 WREG32((0x2c20 + j), 0x00000000);
2073 WREG32((0x2c24 + j), 0x00000000);
2074 }
2075
2076 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
2077
2078 /* Setup tiling */
2079 tiling_config = 0;
2080 ramcfg = RREG32(RAMCFG);
2081 switch (rdev->config.r600.max_tile_pipes) {
2082 case 1:
2083 tiling_config |= PIPE_TILING(0);
2084 break;
2085 case 2:
2086 tiling_config |= PIPE_TILING(1);
2087 break;
2088 case 4:
2089 tiling_config |= PIPE_TILING(2);
2090 break;
2091 case 8:
2092 tiling_config |= PIPE_TILING(3);
2093 break;
2094 default:
2095 break;
2096 }
Alex Deucherd03f5d52010-02-19 16:22:31 -05002097 rdev->config.r600.tiling_npipes = rdev->config.r600.max_tile_pipes;
Jerome Glisse961fb592010-02-10 22:30:05 +00002098 rdev->config.r600.tiling_nbanks = 4 << ((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002099 tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
Alex Deucher881fe6c2010-10-18 23:54:56 -04002100 tiling_config |= GROUP_SIZE((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
Alex Deucher416a2bd2012-05-31 19:00:25 -04002101
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002102 tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
2103 if (tmp > 3) {
2104 tiling_config |= ROW_TILING(3);
2105 tiling_config |= SAMPLE_SPLIT(3);
2106 } else {
2107 tiling_config |= ROW_TILING(tmp);
2108 tiling_config |= SAMPLE_SPLIT(tmp);
2109 }
2110 tiling_config |= BANK_SWAPS(1);
Alex Deucherd03f5d52010-02-19 16:22:31 -05002111
Alex Deucher416a2bd2012-05-31 19:00:25 -04002112 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0x00ffff00;
Alex Deucher65fcf662014-06-02 16:13:21 -04002113 tmp = rdev->config.r600.max_simds -
2114 r600_count_pipe_bits((cc_gc_shader_pipe_config >> 16) & R6XX_MAX_SIMDS_MASK);
2115 rdev->config.r600.active_simds = tmp;
Alex Deucherd03f5d52010-02-19 16:22:31 -05002116
Alex Deucher416a2bd2012-05-31 19:00:25 -04002117 disabled_rb_mask = (RREG32(CC_RB_BACKEND_DISABLE) >> 16) & R6XX_MAX_BACKENDS_MASK;
Alex Deucher0a5f6e92014-08-25 14:52:15 -04002118 tmp = 0;
2119 for (i = 0; i < rdev->config.r600.max_backends; i++)
2120 tmp |= (1 << i);
2121 /* if all the backends are disabled, fix it up here */
2122 if ((disabled_rb_mask & tmp) == tmp) {
2123 for (i = 0; i < rdev->config.r600.max_backends; i++)
2124 disabled_rb_mask &= ~(1 << i);
2125 }
Alex Deucher416a2bd2012-05-31 19:00:25 -04002126 tmp = (tiling_config & PIPE_TILING__MASK) >> PIPE_TILING__SHIFT;
2127 tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.r600.max_backends,
2128 R6XX_MAX_BACKENDS, disabled_rb_mask);
2129 tiling_config |= tmp << 16;
2130 rdev->config.r600.backend_map = tmp;
2131
Alex Deuchere7aeeba62010-06-04 13:10:12 -04002132 rdev->config.r600.tile_config = tiling_config;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002133 WREG32(GB_TILING_CONFIG, tiling_config);
2134 WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff);
2135 WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff);
Alex Deucher4d756582012-09-27 15:08:35 -04002136 WREG32(DMA_TILING_CONFIG, tiling_config & 0xffff);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002137
Alex Deucherd03f5d52010-02-19 16:22:31 -05002138 tmp = R6XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002139 WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK);
2140 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK);
2141
2142 /* Setup some CP states */
2143 WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
2144 WREG32(CP_MEQ_THRESHOLDS, (MEQ_END(0x40) | ROQ_END(0x40)));
2145
2146 WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO | SYNC_GRADIENT |
2147 SYNC_WALKER | SYNC_ALIGNER));
2148 /* Setup various GPU states */
2149 if (rdev->family == CHIP_RV670)
2150 WREG32(ARB_GDEC_RD_CNTL, 0x00000021);
2151
2152 tmp = RREG32(SX_DEBUG_1);
2153 tmp |= SMX_EVENT_RELEASE;
2154 if ((rdev->family > CHIP_R600))
2155 tmp |= ENABLE_NEW_SMX_ADDRESS;
2156 WREG32(SX_DEBUG_1, tmp);
2157
2158 if (((rdev->family) == CHIP_R600) ||
2159 ((rdev->family) == CHIP_RV630) ||
2160 ((rdev->family) == CHIP_RV610) ||
2161 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05002162 ((rdev->family) == CHIP_RS780) ||
2163 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002164 WREG32(DB_DEBUG, PREZ_MUST_WAIT_FOR_POSTZ_DONE);
2165 } else {
2166 WREG32(DB_DEBUG, 0);
2167 }
2168 WREG32(DB_WATERMARKS, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
2169 DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
2170
2171 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
2172 WREG32(VGT_NUM_INSTANCES, 0);
2173
2174 WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
2175 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(0));
2176
2177 tmp = RREG32(SQ_MS_FIFO_SIZES);
2178 if (((rdev->family) == CHIP_RV610) ||
2179 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05002180 ((rdev->family) == CHIP_RS780) ||
2181 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002182 tmp = (CACHE_FIFO_SIZE(0xa) |
2183 FETCH_FIFO_HIWATER(0xa) |
2184 DONE_FIFO_HIWATER(0xe0) |
2185 ALU_UPDATE_FIFO_HIWATER(0x8));
2186 } else if (((rdev->family) == CHIP_R600) ||
2187 ((rdev->family) == CHIP_RV630)) {
2188 tmp &= ~DONE_FIFO_HIWATER(0xff);
2189 tmp |= DONE_FIFO_HIWATER(0x4);
2190 }
2191 WREG32(SQ_MS_FIFO_SIZES, tmp);
2192
2193 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
2194 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
2195 */
2196 sq_config = RREG32(SQ_CONFIG);
2197 sq_config &= ~(PS_PRIO(3) |
2198 VS_PRIO(3) |
2199 GS_PRIO(3) |
2200 ES_PRIO(3));
2201 sq_config |= (DX9_CONSTS |
2202 VC_ENABLE |
2203 PS_PRIO(0) |
2204 VS_PRIO(1) |
2205 GS_PRIO(2) |
2206 ES_PRIO(3));
2207
2208 if ((rdev->family) == CHIP_R600) {
2209 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(124) |
2210 NUM_VS_GPRS(124) |
2211 NUM_CLAUSE_TEMP_GPRS(4));
2212 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(0) |
2213 NUM_ES_GPRS(0));
2214 sq_thread_resource_mgmt = (NUM_PS_THREADS(136) |
2215 NUM_VS_THREADS(48) |
2216 NUM_GS_THREADS(4) |
2217 NUM_ES_THREADS(4));
2218 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(128) |
2219 NUM_VS_STACK_ENTRIES(128));
2220 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(0) |
2221 NUM_ES_STACK_ENTRIES(0));
2222 } else if (((rdev->family) == CHIP_RV610) ||
2223 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05002224 ((rdev->family) == CHIP_RS780) ||
2225 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002226 /* no vertex cache */
2227 sq_config &= ~VC_ENABLE;
2228
2229 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
2230 NUM_VS_GPRS(44) |
2231 NUM_CLAUSE_TEMP_GPRS(2));
2232 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
2233 NUM_ES_GPRS(17));
2234 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
2235 NUM_VS_THREADS(78) |
2236 NUM_GS_THREADS(4) |
2237 NUM_ES_THREADS(31));
2238 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
2239 NUM_VS_STACK_ENTRIES(40));
2240 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
2241 NUM_ES_STACK_ENTRIES(16));
2242 } else if (((rdev->family) == CHIP_RV630) ||
2243 ((rdev->family) == CHIP_RV635)) {
2244 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
2245 NUM_VS_GPRS(44) |
2246 NUM_CLAUSE_TEMP_GPRS(2));
2247 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(18) |
2248 NUM_ES_GPRS(18));
2249 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
2250 NUM_VS_THREADS(78) |
2251 NUM_GS_THREADS(4) |
2252 NUM_ES_THREADS(31));
2253 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
2254 NUM_VS_STACK_ENTRIES(40));
2255 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
2256 NUM_ES_STACK_ENTRIES(16));
2257 } else if ((rdev->family) == CHIP_RV670) {
2258 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
2259 NUM_VS_GPRS(44) |
2260 NUM_CLAUSE_TEMP_GPRS(2));
2261 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
2262 NUM_ES_GPRS(17));
2263 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
2264 NUM_VS_THREADS(78) |
2265 NUM_GS_THREADS(4) |
2266 NUM_ES_THREADS(31));
2267 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(64) |
2268 NUM_VS_STACK_ENTRIES(64));
2269 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(64) |
2270 NUM_ES_STACK_ENTRIES(64));
2271 }
2272
2273 WREG32(SQ_CONFIG, sq_config);
2274 WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
2275 WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
2276 WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
2277 WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
2278 WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
2279
2280 if (((rdev->family) == CHIP_RV610) ||
2281 ((rdev->family) == CHIP_RV620) ||
Alex Deucheree59f2b2009-11-05 13:11:46 -05002282 ((rdev->family) == CHIP_RS780) ||
2283 ((rdev->family) == CHIP_RS880)) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002284 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(TC_ONLY));
2285 } else {
2286 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC));
2287 }
2288
2289 /* More default values. 2D/3D driver should adjust as needed */
2290 WREG32(PA_SC_AA_SAMPLE_LOCS_2S, (S0_X(0xc) | S0_Y(0x4) |
2291 S1_X(0x4) | S1_Y(0xc)));
2292 WREG32(PA_SC_AA_SAMPLE_LOCS_4S, (S0_X(0xe) | S0_Y(0xe) |
2293 S1_X(0x2) | S1_Y(0x2) |
2294 S2_X(0xa) | S2_Y(0x6) |
2295 S3_X(0x6) | S3_Y(0xa)));
2296 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0, (S0_X(0xe) | S0_Y(0xb) |
2297 S1_X(0x4) | S1_Y(0xc) |
2298 S2_X(0x1) | S2_Y(0x6) |
2299 S3_X(0xa) | S3_Y(0xe)));
2300 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1, (S4_X(0x6) | S4_Y(0x1) |
2301 S5_X(0x0) | S5_Y(0x0) |
2302 S6_X(0xb) | S6_Y(0x4) |
2303 S7_X(0x7) | S7_Y(0x8)));
2304
2305 WREG32(VGT_STRMOUT_EN, 0);
2306 tmp = rdev->config.r600.max_pipes * 16;
2307 switch (rdev->family) {
2308 case CHIP_RV610:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002309 case CHIP_RV620:
Alex Deucheree59f2b2009-11-05 13:11:46 -05002310 case CHIP_RS780:
2311 case CHIP_RS880:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002312 tmp += 32;
2313 break;
2314 case CHIP_RV670:
2315 tmp += 128;
2316 break;
2317 default:
2318 break;
2319 }
2320 if (tmp > 256) {
2321 tmp = 256;
2322 }
2323 WREG32(VGT_ES_PER_GS, 128);
2324 WREG32(VGT_GS_PER_ES, tmp);
2325 WREG32(VGT_GS_PER_VS, 2);
2326 WREG32(VGT_GS_VERTEX_REUSE, 16);
2327
2328 /* more default values. 2D/3D driver should adjust as needed */
2329 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
2330 WREG32(VGT_STRMOUT_EN, 0);
2331 WREG32(SX_MISC, 0);
2332 WREG32(PA_SC_MODE_CNTL, 0);
2333 WREG32(PA_SC_AA_CONFIG, 0);
2334 WREG32(PA_SC_LINE_STIPPLE, 0);
2335 WREG32(SPI_INPUT_Z, 0);
2336 WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
2337 WREG32(CB_COLOR7_FRAG, 0);
2338
2339 /* Clear render buffer base addresses */
2340 WREG32(CB_COLOR0_BASE, 0);
2341 WREG32(CB_COLOR1_BASE, 0);
2342 WREG32(CB_COLOR2_BASE, 0);
2343 WREG32(CB_COLOR3_BASE, 0);
2344 WREG32(CB_COLOR4_BASE, 0);
2345 WREG32(CB_COLOR5_BASE, 0);
2346 WREG32(CB_COLOR6_BASE, 0);
2347 WREG32(CB_COLOR7_BASE, 0);
2348 WREG32(CB_COLOR7_FRAG, 0);
2349
2350 switch (rdev->family) {
2351 case CHIP_RV610:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002352 case CHIP_RV620:
Alex Deucheree59f2b2009-11-05 13:11:46 -05002353 case CHIP_RS780:
2354 case CHIP_RS880:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002355 tmp = TC_L2_SIZE(8);
2356 break;
2357 case CHIP_RV630:
2358 case CHIP_RV635:
2359 tmp = TC_L2_SIZE(4);
2360 break;
2361 case CHIP_R600:
2362 tmp = TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT;
2363 break;
2364 default:
2365 tmp = TC_L2_SIZE(0);
2366 break;
2367 }
2368 WREG32(TC_CNTL, tmp);
2369
2370 tmp = RREG32(HDP_HOST_PATH_CNTL);
2371 WREG32(HDP_HOST_PATH_CNTL, tmp);
2372
2373 tmp = RREG32(ARB_POP);
2374 tmp |= ENABLE_TC128;
2375 WREG32(ARB_POP, tmp);
2376
2377 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
2378 WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
2379 NUM_CLIP_SEQ(3)));
2380 WREG32(PA_SC_ENHANCE, FORCE_EOV_MAX_CLK_CNT(4095));
Alex Deucherb866d132012-06-14 22:06:36 +02002381 WREG32(VC_ENHANCE, 0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002382}
2383
2384
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002385/*
2386 * Indirect registers accessor
2387 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002388u32 r600_pciep_rreg(struct radeon_device *rdev, u32 reg)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002389{
Alex Deucher0a5b7b02013-09-03 19:00:09 -04002390 unsigned long flags;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002391 u32 r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002392
Alex Deucher0a5b7b02013-09-03 19:00:09 -04002393 spin_lock_irqsave(&rdev->pciep_idx_lock, flags);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002394 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
2395 (void)RREG32(PCIE_PORT_INDEX);
2396 r = RREG32(PCIE_PORT_DATA);
Alex Deucher0a5b7b02013-09-03 19:00:09 -04002397 spin_unlock_irqrestore(&rdev->pciep_idx_lock, flags);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002398 return r;
2399}
2400
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002401void r600_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02002402{
Alex Deucher0a5b7b02013-09-03 19:00:09 -04002403 unsigned long flags;
2404
2405 spin_lock_irqsave(&rdev->pciep_idx_lock, flags);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002406 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
2407 (void)RREG32(PCIE_PORT_INDEX);
2408 WREG32(PCIE_PORT_DATA, (v));
2409 (void)RREG32(PCIE_PORT_DATA);
Alex Deucher0a5b7b02013-09-03 19:00:09 -04002410 spin_unlock_irqrestore(&rdev->pciep_idx_lock, flags);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002411}
2412
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002413/*
2414 * CP & Ring
2415 */
2416void r600_cp_stop(struct radeon_device *rdev)
2417{
Alex Deucher50efa512014-01-27 11:26:33 -05002418 if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
2419 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002420 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
Alex Deucher724c80e2010-08-27 18:25:25 -04002421 WREG32(SCRATCH_UMSK, 0);
Alex Deucher4d756582012-09-27 15:08:35 -04002422 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002423}
2424
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002425int r600_init_microcode(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002426{
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002427 const char *chip_name;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002428 const char *rlc_chip_name;
Alex Deucher66229b22013-06-26 00:11:19 -04002429 const char *smc_chip_name = "RV770";
2430 size_t pfp_req_size, me_req_size, rlc_req_size, smc_req_size = 0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002431 char fw_name[30];
2432 int err;
2433
2434 DRM_DEBUG("\n");
2435
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002436 switch (rdev->family) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002437 case CHIP_R600:
2438 chip_name = "R600";
2439 rlc_chip_name = "R600";
2440 break;
2441 case CHIP_RV610:
2442 chip_name = "RV610";
2443 rlc_chip_name = "R600";
2444 break;
2445 case CHIP_RV630:
2446 chip_name = "RV630";
2447 rlc_chip_name = "R600";
2448 break;
2449 case CHIP_RV620:
2450 chip_name = "RV620";
2451 rlc_chip_name = "R600";
2452 break;
2453 case CHIP_RV635:
2454 chip_name = "RV635";
2455 rlc_chip_name = "R600";
2456 break;
2457 case CHIP_RV670:
2458 chip_name = "RV670";
2459 rlc_chip_name = "R600";
2460 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002461 case CHIP_RS780:
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002462 case CHIP_RS880:
2463 chip_name = "RS780";
2464 rlc_chip_name = "R600";
2465 break;
2466 case CHIP_RV770:
2467 chip_name = "RV770";
2468 rlc_chip_name = "R700";
Alex Deucher66229b22013-06-26 00:11:19 -04002469 smc_chip_name = "RV770";
2470 smc_req_size = ALIGN(RV770_SMC_UCODE_SIZE, 4);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002471 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002472 case CHIP_RV730:
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002473 chip_name = "RV730";
2474 rlc_chip_name = "R700";
Alex Deucher66229b22013-06-26 00:11:19 -04002475 smc_chip_name = "RV730";
2476 smc_req_size = ALIGN(RV730_SMC_UCODE_SIZE, 4);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002477 break;
2478 case CHIP_RV710:
2479 chip_name = "RV710";
2480 rlc_chip_name = "R700";
Alex Deucher66229b22013-06-26 00:11:19 -04002481 smc_chip_name = "RV710";
2482 smc_req_size = ALIGN(RV710_SMC_UCODE_SIZE, 4);
2483 break;
2484 case CHIP_RV740:
2485 chip_name = "RV730";
2486 rlc_chip_name = "R700";
2487 smc_chip_name = "RV740";
2488 smc_req_size = ALIGN(RV740_SMC_UCODE_SIZE, 4);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002489 break;
Alex Deucherfe251e22010-03-24 13:36:43 -04002490 case CHIP_CEDAR:
2491 chip_name = "CEDAR";
Alex Deucher45f9a392010-03-24 13:55:51 -04002492 rlc_chip_name = "CEDAR";
Alex Deucherdc50ba72013-06-26 00:33:35 -04002493 smc_chip_name = "CEDAR";
2494 smc_req_size = ALIGN(CEDAR_SMC_UCODE_SIZE, 4);
Alex Deucherfe251e22010-03-24 13:36:43 -04002495 break;
2496 case CHIP_REDWOOD:
2497 chip_name = "REDWOOD";
Alex Deucher45f9a392010-03-24 13:55:51 -04002498 rlc_chip_name = "REDWOOD";
Alex Deucherdc50ba72013-06-26 00:33:35 -04002499 smc_chip_name = "REDWOOD";
2500 smc_req_size = ALIGN(REDWOOD_SMC_UCODE_SIZE, 4);
Alex Deucherfe251e22010-03-24 13:36:43 -04002501 break;
2502 case CHIP_JUNIPER:
2503 chip_name = "JUNIPER";
Alex Deucher45f9a392010-03-24 13:55:51 -04002504 rlc_chip_name = "JUNIPER";
Alex Deucherdc50ba72013-06-26 00:33:35 -04002505 smc_chip_name = "JUNIPER";
2506 smc_req_size = ALIGN(JUNIPER_SMC_UCODE_SIZE, 4);
Alex Deucherfe251e22010-03-24 13:36:43 -04002507 break;
2508 case CHIP_CYPRESS:
2509 case CHIP_HEMLOCK:
2510 chip_name = "CYPRESS";
Alex Deucher45f9a392010-03-24 13:55:51 -04002511 rlc_chip_name = "CYPRESS";
Alex Deucherdc50ba72013-06-26 00:33:35 -04002512 smc_chip_name = "CYPRESS";
2513 smc_req_size = ALIGN(CYPRESS_SMC_UCODE_SIZE, 4);
Alex Deucherfe251e22010-03-24 13:36:43 -04002514 break;
Alex Deucher439bd6c2010-11-22 17:56:31 -05002515 case CHIP_PALM:
2516 chip_name = "PALM";
2517 rlc_chip_name = "SUMO";
2518 break;
Alex Deucherd5c5a722011-05-31 15:42:48 -04002519 case CHIP_SUMO:
2520 chip_name = "SUMO";
2521 rlc_chip_name = "SUMO";
2522 break;
2523 case CHIP_SUMO2:
2524 chip_name = "SUMO2";
2525 rlc_chip_name = "SUMO";
2526 break;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002527 default: BUG();
2528 }
2529
Alex Deucherfe251e22010-03-24 13:36:43 -04002530 if (rdev->family >= CHIP_CEDAR) {
2531 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
2532 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
Alex Deucher45f9a392010-03-24 13:55:51 -04002533 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
Alex Deucherfe251e22010-03-24 13:36:43 -04002534 } else if (rdev->family >= CHIP_RV770) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002535 pfp_req_size = R700_PFP_UCODE_SIZE * 4;
2536 me_req_size = R700_PM4_UCODE_SIZE * 4;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002537 rlc_req_size = R700_RLC_UCODE_SIZE * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002538 } else {
Alex Deucher138e4e12013-01-11 15:33:13 -05002539 pfp_req_size = R600_PFP_UCODE_SIZE * 4;
2540 me_req_size = R600_PM4_UCODE_SIZE * 12;
2541 rlc_req_size = R600_RLC_UCODE_SIZE * 4;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002542 }
2543
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002544 DRM_INFO("Loading %s Microcode\n", chip_name);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002545
2546 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04002547 err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002548 if (err)
2549 goto out;
2550 if (rdev->pfp_fw->size != pfp_req_size) {
2551 printk(KERN_ERR
2552 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2553 rdev->pfp_fw->size, fw_name);
2554 err = -EINVAL;
2555 goto out;
2556 }
2557
2558 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04002559 err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002560 if (err)
2561 goto out;
2562 if (rdev->me_fw->size != me_req_size) {
2563 printk(KERN_ERR
2564 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2565 rdev->me_fw->size, fw_name);
2566 err = -EINVAL;
2567 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002568
2569 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04002570 err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002571 if (err)
2572 goto out;
2573 if (rdev->rlc_fw->size != rlc_req_size) {
2574 printk(KERN_ERR
2575 "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
2576 rdev->rlc_fw->size, fw_name);
2577 err = -EINVAL;
2578 }
2579
Alex Deucherdc50ba72013-06-26 00:33:35 -04002580 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_HEMLOCK)) {
Alex Deucher66229b22013-06-26 00:11:19 -04002581 snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", smc_chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04002582 err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
Alex Deucher8a53fa22013-08-07 16:09:08 -04002583 if (err) {
2584 printk(KERN_ERR
2585 "smc: error loading firmware \"%s\"\n",
2586 fw_name);
2587 release_firmware(rdev->smc_fw);
2588 rdev->smc_fw = NULL;
Alex Deucherd8367112013-10-16 11:36:30 -04002589 err = 0;
Alex Deucher8a53fa22013-08-07 16:09:08 -04002590 } else if (rdev->smc_fw->size != smc_req_size) {
Alex Deucher66229b22013-06-26 00:11:19 -04002591 printk(KERN_ERR
2592 "smc: Bogus length %zu in firmware \"%s\"\n",
2593 rdev->smc_fw->size, fw_name);
2594 err = -EINVAL;
2595 }
2596 }
2597
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002598out:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002599 if (err) {
2600 if (err != -EINVAL)
2601 printk(KERN_ERR
2602 "r600_cp: Failed to load firmware \"%s\"\n",
2603 fw_name);
2604 release_firmware(rdev->pfp_fw);
2605 rdev->pfp_fw = NULL;
2606 release_firmware(rdev->me_fw);
2607 rdev->me_fw = NULL;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05002608 release_firmware(rdev->rlc_fw);
2609 rdev->rlc_fw = NULL;
Alex Deucher66229b22013-06-26 00:11:19 -04002610 release_firmware(rdev->smc_fw);
2611 rdev->smc_fw = NULL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002612 }
2613 return err;
2614}
2615
Alex Deucherea31bf62013-12-09 19:44:30 -05002616u32 r600_gfx_get_rptr(struct radeon_device *rdev,
2617 struct radeon_ring *ring)
2618{
2619 u32 rptr;
2620
2621 if (rdev->wb.enabled)
2622 rptr = rdev->wb.wb[ring->rptr_offs/4];
2623 else
2624 rptr = RREG32(R600_CP_RB_RPTR);
2625
2626 return rptr;
2627}
2628
2629u32 r600_gfx_get_wptr(struct radeon_device *rdev,
2630 struct radeon_ring *ring)
2631{
2632 u32 wptr;
2633
2634 wptr = RREG32(R600_CP_RB_WPTR);
2635
2636 return wptr;
2637}
2638
2639void r600_gfx_set_wptr(struct radeon_device *rdev,
2640 struct radeon_ring *ring)
2641{
2642 WREG32(R600_CP_RB_WPTR, ring->wptr);
2643 (void)RREG32(R600_CP_RB_WPTR);
2644}
2645
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002646static int r600_cp_load_microcode(struct radeon_device *rdev)
2647{
2648 const __be32 *fw_data;
2649 int i;
2650
2651 if (!rdev->me_fw || !rdev->pfp_fw)
2652 return -EINVAL;
2653
2654 r600_cp_stop(rdev);
2655
Cédric Cano4eace7f2011-02-11 19:45:38 -05002656 WREG32(CP_RB_CNTL,
2657#ifdef __BIG_ENDIAN
2658 BUF_SWAP_32BIT |
2659#endif
2660 RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002661
2662 /* Reset cp */
2663 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
2664 RREG32(GRBM_SOFT_RESET);
2665 mdelay(15);
2666 WREG32(GRBM_SOFT_RESET, 0);
2667
2668 WREG32(CP_ME_RAM_WADDR, 0);
2669
2670 fw_data = (const __be32 *)rdev->me_fw->data;
2671 WREG32(CP_ME_RAM_WADDR, 0);
Alex Deucher138e4e12013-01-11 15:33:13 -05002672 for (i = 0; i < R600_PM4_UCODE_SIZE * 3; i++)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002673 WREG32(CP_ME_RAM_DATA,
2674 be32_to_cpup(fw_data++));
2675
2676 fw_data = (const __be32 *)rdev->pfp_fw->data;
2677 WREG32(CP_PFP_UCODE_ADDR, 0);
Alex Deucher138e4e12013-01-11 15:33:13 -05002678 for (i = 0; i < R600_PFP_UCODE_SIZE; i++)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002679 WREG32(CP_PFP_UCODE_DATA,
2680 be32_to_cpup(fw_data++));
2681
2682 WREG32(CP_PFP_UCODE_ADDR, 0);
2683 WREG32(CP_ME_RAM_WADDR, 0);
2684 WREG32(CP_ME_RAM_RADDR, 0);
2685 return 0;
2686}
2687
2688int r600_cp_start(struct radeon_device *rdev)
2689{
Christian Könige32eb502011-10-23 12:56:27 +02002690 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002691 int r;
2692 uint32_t cp_me;
2693
Christian Könige32eb502011-10-23 12:56:27 +02002694 r = radeon_ring_lock(rdev, ring, 7);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002695 if (r) {
2696 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
2697 return r;
2698 }
Christian Könige32eb502011-10-23 12:56:27 +02002699 radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
2700 radeon_ring_write(ring, 0x1);
Alex Deucher7e7b41d2010-09-02 21:32:32 -04002701 if (rdev->family >= CHIP_RV770) {
Christian Könige32eb502011-10-23 12:56:27 +02002702 radeon_ring_write(ring, 0x0);
2703 radeon_ring_write(ring, rdev->config.rv770.max_hw_contexts - 1);
Alex Deucherfe251e22010-03-24 13:36:43 -04002704 } else {
Christian Könige32eb502011-10-23 12:56:27 +02002705 radeon_ring_write(ring, 0x3);
2706 radeon_ring_write(ring, rdev->config.r600.max_hw_contexts - 1);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002707 }
Christian Könige32eb502011-10-23 12:56:27 +02002708 radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
2709 radeon_ring_write(ring, 0);
2710 radeon_ring_write(ring, 0);
Michel Dänzer1538a9e2014-08-18 17:34:55 +09002711 radeon_ring_unlock_commit(rdev, ring, false);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002712
2713 cp_me = 0xff;
2714 WREG32(R_0086D8_CP_ME_CNTL, cp_me);
2715 return 0;
2716}
2717
2718int r600_cp_resume(struct radeon_device *rdev)
2719{
Christian Könige32eb502011-10-23 12:56:27 +02002720 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002721 u32 tmp;
2722 u32 rb_bufsz;
2723 int r;
2724
2725 /* Reset cp */
2726 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
2727 RREG32(GRBM_SOFT_RESET);
2728 mdelay(15);
2729 WREG32(GRBM_SOFT_RESET, 0);
2730
2731 /* Set ring buffer size */
Daniel Vetterb72a8922013-07-10 14:11:59 +02002732 rb_bufsz = order_base_2(ring->ring_size / 8);
2733 tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002734#ifdef __BIG_ENDIAN
Alex Deucherd6f28932009-11-02 16:01:27 -05002735 tmp |= BUF_SWAP_32BIT;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002736#endif
Alex Deucherd6f28932009-11-02 16:01:27 -05002737 WREG32(CP_RB_CNTL, tmp);
Christian König15d33322011-09-15 19:02:22 +02002738 WREG32(CP_SEM_WAIT_TIMER, 0x0);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002739
2740 /* Set the write pointer delay */
2741 WREG32(CP_RB_WPTR_DELAY, 0);
2742
2743 /* Initialize the ring buffer's read and write pointers */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002744 WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
2745 WREG32(CP_RB_RPTR_WR, 0);
Christian Könige32eb502011-10-23 12:56:27 +02002746 ring->wptr = 0;
2747 WREG32(CP_RB_WPTR, ring->wptr);
Alex Deucher724c80e2010-08-27 18:25:25 -04002748
2749 /* set the wb address whether it's enabled or not */
Cédric Cano4eace7f2011-02-11 19:45:38 -05002750 WREG32(CP_RB_RPTR_ADDR,
Cédric Cano4eace7f2011-02-11 19:45:38 -05002751 ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC));
Alex Deucher724c80e2010-08-27 18:25:25 -04002752 WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
2753 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
2754
2755 if (rdev->wb.enabled)
2756 WREG32(SCRATCH_UMSK, 0xff);
2757 else {
2758 tmp |= RB_NO_UPDATE;
2759 WREG32(SCRATCH_UMSK, 0);
2760 }
2761
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002762 mdelay(1);
2763 WREG32(CP_RB_CNTL, tmp);
2764
Christian Könige32eb502011-10-23 12:56:27 +02002765 WREG32(CP_RB_BASE, ring->gpu_addr >> 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002766 WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
2767
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002768 r600_cp_start(rdev);
Christian Könige32eb502011-10-23 12:56:27 +02002769 ring->ready = true;
Alex Deucherf7128122012-02-23 17:53:45 -05002770 r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002771 if (r) {
Christian Könige32eb502011-10-23 12:56:27 +02002772 ring->ready = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002773 return r;
2774 }
Alex Deucherb9ace362014-01-27 10:59:51 -05002775
Alex Deucher50efa512014-01-27 11:26:33 -05002776 if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
Alex Deucherb9ace362014-01-27 10:59:51 -05002777 radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
2778
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002779 return 0;
2780}
2781
Christian Könige32eb502011-10-23 12:56:27 +02002782void r600_ring_init(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ring_size)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002783{
2784 u32 rb_bufsz;
Christian König45df6802012-07-06 16:22:55 +02002785 int r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002786
2787 /* Align ring size */
Daniel Vetterb72a8922013-07-10 14:11:59 +02002788 rb_bufsz = order_base_2(ring_size / 8);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002789 ring_size = (1 << (rb_bufsz + 1)) * 4;
Christian Könige32eb502011-10-23 12:56:27 +02002790 ring->ring_size = ring_size;
2791 ring->align_mask = 16 - 1;
Christian König45df6802012-07-06 16:22:55 +02002792
Alex Deucher89d35802012-07-17 14:02:31 -04002793 if (radeon_ring_supports_scratch_reg(rdev, ring)) {
2794 r = radeon_scratch_get(rdev, &ring->rptr_save_reg);
2795 if (r) {
2796 DRM_ERROR("failed to get scratch reg for rptr save (%d).\n", r);
2797 ring->rptr_save_reg = 0;
2798 }
Christian König45df6802012-07-06 16:22:55 +02002799 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002800}
2801
Jerome Glisse655efd32010-02-02 11:51:45 +01002802void r600_cp_fini(struct radeon_device *rdev)
2803{
Christian König45df6802012-07-06 16:22:55 +02002804 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Jerome Glisse655efd32010-02-02 11:51:45 +01002805 r600_cp_stop(rdev);
Christian König45df6802012-07-06 16:22:55 +02002806 radeon_ring_fini(rdev, ring);
2807 radeon_scratch_free(rdev, ring->rptr_save_reg);
Jerome Glisse655efd32010-02-02 11:51:45 +01002808}
2809
Alex Deucher4d756582012-09-27 15:08:35 -04002810/*
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002811 * GPU scratch registers helpers function.
2812 */
2813void r600_scratch_init(struct radeon_device *rdev)
2814{
2815 int i;
2816
2817 rdev->scratch.num_reg = 7;
Alex Deucher724c80e2010-08-27 18:25:25 -04002818 rdev->scratch.reg_base = SCRATCH_REG0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002819 for (i = 0; i < rdev->scratch.num_reg; i++) {
2820 rdev->scratch.free[i] = true;
Alex Deucher724c80e2010-08-27 18:25:25 -04002821 rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002822 }
2823}
2824
Christian Könige32eb502011-10-23 12:56:27 +02002825int r600_ring_test(struct radeon_device *rdev, struct radeon_ring *ring)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002826{
2827 uint32_t scratch;
2828 uint32_t tmp = 0;
Alex Deucher8b25ed32012-07-17 14:02:30 -04002829 unsigned i;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002830 int r;
2831
2832 r = radeon_scratch_get(rdev, &scratch);
2833 if (r) {
2834 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
2835 return r;
2836 }
2837 WREG32(scratch, 0xCAFEDEAD);
Christian Könige32eb502011-10-23 12:56:27 +02002838 r = radeon_ring_lock(rdev, ring, 3);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002839 if (r) {
Alex Deucher8b25ed32012-07-17 14:02:30 -04002840 DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ring->idx, r);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002841 radeon_scratch_free(rdev, scratch);
2842 return r;
2843 }
Christian Könige32eb502011-10-23 12:56:27 +02002844 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2845 radeon_ring_write(ring, ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2846 radeon_ring_write(ring, 0xDEADBEEF);
Michel Dänzer1538a9e2014-08-18 17:34:55 +09002847 radeon_ring_unlock_commit(rdev, ring, false);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002848 for (i = 0; i < rdev->usec_timeout; i++) {
2849 tmp = RREG32(scratch);
2850 if (tmp == 0xDEADBEEF)
2851 break;
2852 DRM_UDELAY(1);
2853 }
2854 if (i < rdev->usec_timeout) {
Alex Deucher8b25ed32012-07-17 14:02:30 -04002855 DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002856 } else {
Christian Königbf852792011-10-13 13:19:22 +02002857 DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
Alex Deucher8b25ed32012-07-17 14:02:30 -04002858 ring->idx, scratch, tmp);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002859 r = -EINVAL;
2860 }
2861 radeon_scratch_free(rdev, scratch);
2862 return r;
2863}
2864
Alex Deucher4d756582012-09-27 15:08:35 -04002865/*
2866 * CP fences/semaphores
2867 */
2868
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002869void r600_fence_ring_emit(struct radeon_device *rdev,
2870 struct radeon_fence *fence)
2871{
Christian Könige32eb502011-10-23 12:56:27 +02002872 struct radeon_ring *ring = &rdev->ring[fence->ring];
Alex Deucherd45b9642014-01-16 18:11:47 -05002873 u32 cp_coher_cntl = PACKET3_TC_ACTION_ENA | PACKET3_VC_ACTION_ENA |
2874 PACKET3_SH_ACTION_ENA;
2875
2876 if (rdev->family >= CHIP_RV770)
2877 cp_coher_cntl |= PACKET3_FULL_CACHE_ENA;
Christian König7b1f2482011-09-23 15:11:23 +02002878
Alex Deucherd0f8a852010-09-04 05:04:34 -04002879 if (rdev->wb.use_event) {
Jerome Glisse30eb77f2011-11-20 20:45:34 +00002880 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
Jerome Glisse77b1bad2011-10-26 11:41:22 -04002881 /* flush read cache over gart */
Christian Könige32eb502011-10-23 12:56:27 +02002882 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
Alex Deucherd45b9642014-01-16 18:11:47 -05002883 radeon_ring_write(ring, cp_coher_cntl);
Christian Könige32eb502011-10-23 12:56:27 +02002884 radeon_ring_write(ring, 0xFFFFFFFF);
2885 radeon_ring_write(ring, 0);
2886 radeon_ring_write(ring, 10); /* poll interval */
Alex Deucherd0f8a852010-09-04 05:04:34 -04002887 /* EVENT_WRITE_EOP - flush caches, send int */
Christian Könige32eb502011-10-23 12:56:27 +02002888 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
2889 radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5));
Christian König5e167cd2014-06-03 20:51:46 +02002890 radeon_ring_write(ring, lower_32_bits(addr));
Christian Könige32eb502011-10-23 12:56:27 +02002891 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
2892 radeon_ring_write(ring, fence->seq);
2893 radeon_ring_write(ring, 0);
Alex Deucherd0f8a852010-09-04 05:04:34 -04002894 } else {
Jerome Glisse77b1bad2011-10-26 11:41:22 -04002895 /* flush read cache over gart */
Christian Könige32eb502011-10-23 12:56:27 +02002896 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
Alex Deucherd45b9642014-01-16 18:11:47 -05002897 radeon_ring_write(ring, cp_coher_cntl);
Christian Könige32eb502011-10-23 12:56:27 +02002898 radeon_ring_write(ring, 0xFFFFFFFF);
2899 radeon_ring_write(ring, 0);
2900 radeon_ring_write(ring, 10); /* poll interval */
2901 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
2902 radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT) | EVENT_INDEX(0));
Alex Deucherd0f8a852010-09-04 05:04:34 -04002903 /* wait for 3D idle clean */
Christian Könige32eb502011-10-23 12:56:27 +02002904 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2905 radeon_ring_write(ring, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2906 radeon_ring_write(ring, WAIT_3D_IDLE_bit | WAIT_3D_IDLECLEAN_bit);
Alex Deucherd0f8a852010-09-04 05:04:34 -04002907 /* Emit fence sequence & fire IRQ */
Christian Könige32eb502011-10-23 12:56:27 +02002908 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2909 radeon_ring_write(ring, ((rdev->fence_drv[fence->ring].scratch_reg - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2910 radeon_ring_write(ring, fence->seq);
Alex Deucherd0f8a852010-09-04 05:04:34 -04002911 /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
Christian Könige32eb502011-10-23 12:56:27 +02002912 radeon_ring_write(ring, PACKET0(CP_INT_STATUS, 0));
2913 radeon_ring_write(ring, RB_INT_STAT);
Alex Deucherd0f8a852010-09-04 05:04:34 -04002914 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10002915}
2916
Christian König86302ee2014-08-18 16:30:12 +02002917/**
2918 * r600_semaphore_ring_emit - emit a semaphore on the CP ring
2919 *
2920 * @rdev: radeon_device pointer
2921 * @ring: radeon ring buffer object
2922 * @semaphore: radeon semaphore object
2923 * @emit_wait: Is this a sempahore wait?
2924 *
2925 * Emits a semaphore signal/wait packet to the CP ring and prevents the PFP
2926 * from running ahead of semaphore waits.
2927 */
Christian König1654b812013-11-12 12:58:05 +01002928bool r600_semaphore_ring_emit(struct radeon_device *rdev,
Christian Könige32eb502011-10-23 12:56:27 +02002929 struct radeon_ring *ring,
Christian König15d33322011-09-15 19:02:22 +02002930 struct radeon_semaphore *semaphore,
Christian König7b1f2482011-09-23 15:11:23 +02002931 bool emit_wait)
Christian König15d33322011-09-15 19:02:22 +02002932{
2933 uint64_t addr = semaphore->gpu_addr;
2934 unsigned sel = emit_wait ? PACKET3_SEM_SEL_WAIT : PACKET3_SEM_SEL_SIGNAL;
2935
Christian König0be70432012-03-07 11:28:57 +01002936 if (rdev->family < CHIP_CAYMAN)
2937 sel |= PACKET3_SEM_WAIT_ON_SIGNAL;
2938
Christian Könige32eb502011-10-23 12:56:27 +02002939 radeon_ring_write(ring, PACKET3(PACKET3_MEM_SEMAPHORE, 1));
Christian König5e167cd2014-06-03 20:51:46 +02002940 radeon_ring_write(ring, lower_32_bits(addr));
Christian Könige32eb502011-10-23 12:56:27 +02002941 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | sel);
Christian König1654b812013-11-12 12:58:05 +01002942
Alex Deucherb6c2b4f2014-09-08 13:16:39 -04002943 /* PFP_SYNC_ME packet only exists on 7xx+, only enable it on eg+ */
2944 if (emit_wait && (rdev->family >= CHIP_CEDAR)) {
Christian König86302ee2014-08-18 16:30:12 +02002945 /* Prevent the PFP from running ahead of the semaphore wait */
2946 radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
2947 radeon_ring_write(ring, 0x0);
2948 }
2949
Christian König1654b812013-11-12 12:58:05 +01002950 return true;
Christian König15d33322011-09-15 19:02:22 +02002951}
2952
Alex Deucher4d756582012-09-27 15:08:35 -04002953/**
Alex Deucher072b5ac2013-07-11 14:48:05 -04002954 * r600_copy_cpdma - copy pages using the CP DMA engine
2955 *
2956 * @rdev: radeon_device pointer
2957 * @src_offset: src GPU address
2958 * @dst_offset: dst GPU address
2959 * @num_gpu_pages: number of GPU pages to xfer
2960 * @fence: radeon fence object
2961 *
2962 * Copy GPU paging using the CP DMA engine (r6xx+).
2963 * Used by the radeon ttm implementation to move pages if
2964 * registered as the asic copy callback.
2965 */
Christian König57d20a42014-09-04 20:01:53 +02002966struct radeon_fence *r600_copy_cpdma(struct radeon_device *rdev,
2967 uint64_t src_offset, uint64_t dst_offset,
2968 unsigned num_gpu_pages,
2969 struct reservation_object *resv)
Alex Deucher072b5ac2013-07-11 14:48:05 -04002970{
Christian König57d20a42014-09-04 20:01:53 +02002971 struct radeon_fence *fence;
Christian König975700d22014-11-19 14:01:22 +01002972 struct radeon_sync sync;
Alex Deucher072b5ac2013-07-11 14:48:05 -04002973 int ring_index = rdev->asic->copy.blit_ring_index;
2974 struct radeon_ring *ring = &rdev->ring[ring_index];
2975 u32 size_in_bytes, cur_size_in_bytes, tmp;
2976 int i, num_loops;
2977 int r = 0;
2978
Christian König975700d22014-11-19 14:01:22 +01002979 radeon_sync_create(&sync);
Alex Deucher072b5ac2013-07-11 14:48:05 -04002980
2981 size_in_bytes = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT);
2982 num_loops = DIV_ROUND_UP(size_in_bytes, 0x1fffff);
Alex Deucher745a39a2013-07-18 09:24:37 -04002983 r = radeon_ring_lock(rdev, ring, num_loops * 6 + 24);
Alex Deucher072b5ac2013-07-11 14:48:05 -04002984 if (r) {
2985 DRM_ERROR("radeon: moving bo (%d).\n", r);
Christian König975700d22014-11-19 14:01:22 +01002986 radeon_sync_free(rdev, &sync, NULL);
Christian König57d20a42014-09-04 20:01:53 +02002987 return ERR_PTR(r);
Alex Deucher072b5ac2013-07-11 14:48:05 -04002988 }
2989
Christian König975700d22014-11-19 14:01:22 +01002990 radeon_sync_resv(rdev, &sync, resv, false);
2991 radeon_sync_rings(rdev, &sync, ring->idx);
Alex Deucher072b5ac2013-07-11 14:48:05 -04002992
Alex Deucher745a39a2013-07-18 09:24:37 -04002993 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2994 radeon_ring_write(ring, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2995 radeon_ring_write(ring, WAIT_3D_IDLE_bit);
Alex Deucher072b5ac2013-07-11 14:48:05 -04002996 for (i = 0; i < num_loops; i++) {
2997 cur_size_in_bytes = size_in_bytes;
2998 if (cur_size_in_bytes > 0x1fffff)
2999 cur_size_in_bytes = 0x1fffff;
3000 size_in_bytes -= cur_size_in_bytes;
3001 tmp = upper_32_bits(src_offset) & 0xff;
3002 if (size_in_bytes == 0)
3003 tmp |= PACKET3_CP_DMA_CP_SYNC;
3004 radeon_ring_write(ring, PACKET3(PACKET3_CP_DMA, 4));
Christian König5e167cd2014-06-03 20:51:46 +02003005 radeon_ring_write(ring, lower_32_bits(src_offset));
Alex Deucher072b5ac2013-07-11 14:48:05 -04003006 radeon_ring_write(ring, tmp);
Christian König5e167cd2014-06-03 20:51:46 +02003007 radeon_ring_write(ring, lower_32_bits(dst_offset));
Alex Deucher072b5ac2013-07-11 14:48:05 -04003008 radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff);
3009 radeon_ring_write(ring, cur_size_in_bytes);
3010 src_offset += cur_size_in_bytes;
3011 dst_offset += cur_size_in_bytes;
3012 }
3013 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
3014 radeon_ring_write(ring, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
3015 radeon_ring_write(ring, WAIT_CP_DMA_IDLE_bit);
3016
Christian König57d20a42014-09-04 20:01:53 +02003017 r = radeon_fence_emit(rdev, &fence, ring->idx);
Alex Deucher072b5ac2013-07-11 14:48:05 -04003018 if (r) {
3019 radeon_ring_unlock_undo(rdev, ring);
Christian König975700d22014-11-19 14:01:22 +01003020 radeon_sync_free(rdev, &sync, NULL);
Christian König57d20a42014-09-04 20:01:53 +02003021 return ERR_PTR(r);
Alex Deucher072b5ac2013-07-11 14:48:05 -04003022 }
3023
Michel Dänzer1538a9e2014-08-18 17:34:55 +09003024 radeon_ring_unlock_commit(rdev, ring, false);
Christian König975700d22014-11-19 14:01:22 +01003025 radeon_sync_free(rdev, &sync, fence);
Alex Deucher072b5ac2013-07-11 14:48:05 -04003026
Christian König57d20a42014-09-04 20:01:53 +02003027 return fence;
Alex Deucher072b5ac2013-07-11 14:48:05 -04003028}
3029
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003030int r600_set_surface_reg(struct radeon_device *rdev, int reg,
3031 uint32_t tiling_flags, uint32_t pitch,
3032 uint32_t offset, uint32_t obj_size)
3033{
3034 /* FIXME: implement */
3035 return 0;
3036}
3037
3038void r600_clear_surface_reg(struct radeon_device *rdev, int reg)
3039{
3040 /* FIXME: implement */
3041}
3042
Jérome Glissec91f9362016-03-18 16:58:26 +01003043static void r600_uvd_init(struct radeon_device *rdev)
3044{
3045 int r;
3046
3047 if (!rdev->has_uvd)
3048 return;
3049
3050 r = radeon_uvd_init(rdev);
3051 if (r) {
3052 dev_err(rdev->dev, "failed UVD (%d) init.\n", r);
3053 /*
3054 * At this point rdev->uvd.vcpu_bo is NULL which trickles down
3055 * to early fails uvd_v1_0_resume() and thus nothing happens
3056 * there. So it is pointless to try to go through that code
3057 * hence why we disable uvd here.
3058 */
3059 rdev->has_uvd = 0;
3060 return;
3061 }
3062 rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_obj = NULL;
3063 r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_UVD_INDEX], 4096);
3064}
3065
3066static void r600_uvd_start(struct radeon_device *rdev)
3067{
3068 int r;
3069
3070 if (!rdev->has_uvd)
3071 return;
3072
3073 r = uvd_v1_0_resume(rdev);
3074 if (r) {
3075 dev_err(rdev->dev, "failed UVD resume (%d).\n", r);
3076 goto error;
3077 }
3078 r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_UVD_INDEX);
3079 if (r) {
3080 dev_err(rdev->dev, "failed initializing UVD fences (%d).\n", r);
3081 goto error;
3082 }
3083 return;
3084
3085error:
3086 rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
3087}
3088
3089static void r600_uvd_resume(struct radeon_device *rdev)
3090{
3091 struct radeon_ring *ring;
3092 int r;
3093
3094 if (!rdev->has_uvd || !rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size)
3095 return;
3096
3097 ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
3098 r = radeon_ring_init(rdev, ring, ring->ring_size, 0, RADEON_CP_PACKET2);
3099 if (r) {
3100 dev_err(rdev->dev, "failed initializing UVD ring (%d).\n", r);
3101 return;
3102 }
3103 r = uvd_v1_0_init(rdev);
3104 if (r) {
3105 dev_err(rdev->dev, "failed initializing UVD (%d).\n", r);
3106 return;
3107 }
3108}
3109
Lauri Kasanen1109ca02012-08-31 13:43:50 -04003110static int r600_startup(struct radeon_device *rdev)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003111{
Alex Deucher4d756582012-09-27 15:08:35 -04003112 struct radeon_ring *ring;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003113 int r;
3114
Alex Deucher9e46a482011-01-06 18:49:35 -05003115 /* enable pcie gen2 link */
3116 r600_pcie_gen2_enable(rdev);
3117
Alex Deuchere5903d32013-08-30 08:58:20 -04003118 /* scratch needs to be initialized before MC */
3119 r = r600_vram_scratch_init(rdev);
3120 if (r)
3121 return r;
3122
Alex Deucher6fab3feb2013-08-04 12:13:17 -04003123 r600_mc_program(rdev);
3124
Jerome Glisse1a029b72009-10-06 19:04:30 +02003125 if (rdev->flags & RADEON_IS_AGP) {
3126 r600_agp_enable(rdev);
3127 } else {
3128 r = r600_pcie_gart_enable(rdev);
3129 if (r)
3130 return r;
3131 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003132 r600_gpu_init(rdev);
Alex Deucherb70d6bb2010-08-06 21:36:58 -04003133
Alex Deucher724c80e2010-08-27 18:25:25 -04003134 /* allocate wb buffer */
3135 r = radeon_wb_init(rdev);
3136 if (r)
3137 return r;
3138
Jerome Glisse30eb77f2011-11-20 20:45:34 +00003139 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
3140 if (r) {
3141 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
3142 return r;
3143 }
3144
Jérome Glissec91f9362016-03-18 16:58:26 +01003145 r600_uvd_start(rdev);
Christian König856754c2013-04-16 22:11:22 +02003146
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003147 /* Enable IRQ */
Adis Hamziće49f3952013-06-02 16:47:54 +02003148 if (!rdev->irq.installed) {
3149 r = radeon_irq_kms_init(rdev);
3150 if (r)
3151 return r;
3152 }
3153
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003154 r = r600_irq_init(rdev);
3155 if (r) {
3156 DRM_ERROR("radeon: IH init failed (%d).\n", r);
3157 radeon_irq_kms_fini(rdev);
3158 return r;
3159 }
3160 r600_irq_set(rdev);
3161
Alex Deucher4d756582012-09-27 15:08:35 -04003162 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Christian Könige32eb502011-10-23 12:56:27 +02003163 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
Christian König2e1e6da2013-08-13 11:56:52 +02003164 RADEON_CP_PACKET2);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003165 if (r)
3166 return r;
Alex Deucher4d756582012-09-27 15:08:35 -04003167
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003168 r = r600_cp_load_microcode(rdev);
3169 if (r)
3170 return r;
3171 r = r600_cp_resume(rdev);
3172 if (r)
3173 return r;
Alex Deucher724c80e2010-08-27 18:25:25 -04003174
Jérome Glissec91f9362016-03-18 16:58:26 +01003175 r600_uvd_resume(rdev);
Christian König856754c2013-04-16 22:11:22 +02003176
Christian König2898c342012-07-05 11:55:34 +02003177 r = radeon_ib_pool_init(rdev);
3178 if (r) {
3179 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
Jerome Glisseb15ba512011-11-15 11:48:34 -05003180 return r;
Christian König2898c342012-07-05 11:55:34 +02003181 }
Jerome Glisseb15ba512011-11-15 11:48:34 -05003182
Slava Grigorevbfc1f972014-12-22 17:26:51 -05003183 r = radeon_audio_init(rdev);
Alex Deucherd4e30ef2012-06-04 17:18:51 -04003184 if (r) {
3185 DRM_ERROR("radeon: audio init failed\n");
3186 return r;
3187 }
3188
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003189 return 0;
3190}
3191
Dave Airlie28d52042009-09-21 14:33:58 +10003192void r600_vga_set_state(struct radeon_device *rdev, bool state)
3193{
3194 uint32_t temp;
3195
3196 temp = RREG32(CONFIG_CNTL);
3197 if (state == false) {
3198 temp &= ~(1<<0);
3199 temp |= (1<<1);
3200 } else {
3201 temp &= ~(1<<1);
3202 }
3203 WREG32(CONFIG_CNTL, temp);
3204}
3205
Dave Airliefc30b8e2009-09-18 15:19:37 +10003206int r600_resume(struct radeon_device *rdev)
3207{
3208 int r;
3209
Jerome Glisse1a029b72009-10-06 19:04:30 +02003210 /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
3211 * posting will perform necessary task to bring back GPU into good
3212 * shape.
3213 */
Dave Airliefc30b8e2009-09-18 15:19:37 +10003214 /* post card */
Jerome Glissee7d40b92009-10-01 18:02:15 +02003215 atom_asic_init(rdev->mode_info.atom_context);
Dave Airliefc30b8e2009-09-18 15:19:37 +10003216
Alex Deucherbc6a6292014-02-25 12:01:28 -05003217 if (rdev->pm.pm_method == PM_METHOD_DPM)
3218 radeon_pm_resume(rdev);
Alex Deucher6c7bcce2013-12-18 14:07:14 -05003219
Jerome Glisseb15ba512011-11-15 11:48:34 -05003220 rdev->accel_working = true;
Dave Airliefc30b8e2009-09-18 15:19:37 +10003221 r = r600_startup(rdev);
3222 if (r) {
3223 DRM_ERROR("r600 startup failed on resume\n");
Jerome Glisse6b7746e2012-02-20 17:57:20 -05003224 rdev->accel_working = false;
Dave Airliefc30b8e2009-09-18 15:19:37 +10003225 return r;
3226 }
3227
Dave Airliefc30b8e2009-09-18 15:19:37 +10003228 return r;
3229}
3230
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003231int r600_suspend(struct radeon_device *rdev)
3232{
Alex Deucher6c7bcce2013-12-18 14:07:14 -05003233 radeon_pm_suspend(rdev);
Slava Grigorev7991d662014-12-03 17:07:01 -05003234 radeon_audio_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003235 r600_cp_stop(rdev);
Alex Deucherbdc99722014-08-26 13:11:36 -04003236 if (rdev->has_uvd) {
3237 uvd_v1_0_fini(rdev);
3238 radeon_uvd_suspend(rdev);
3239 }
Jerome Glisse0c452492010-01-15 14:44:37 +01003240 r600_irq_suspend(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04003241 radeon_wb_disable(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02003242 r600_pcie_gart_disable(rdev);
Alex Deucher6ddddfe2011-10-14 10:51:22 -04003243
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003244 return 0;
3245}
3246
3247/* Plan is to move initialization in that function and use
3248 * helper function so that radeon_device_init pretty much
3249 * do nothing more than calling asic specific function. This
3250 * should also allow to remove a bunch of callback function
3251 * like vram_info.
3252 */
3253int r600_init(struct radeon_device *rdev)
3254{
3255 int r;
3256
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003257 if (r600_debugfs_mc_info_init(rdev)) {
3258 DRM_ERROR("Failed to register debugfs file for mc !\n");
3259 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003260 /* Read BIOS */
3261 if (!radeon_get_bios(rdev)) {
3262 if (ASIC_IS_AVIVO(rdev))
3263 return -EINVAL;
3264 }
3265 /* Must be an ATOMBIOS */
Jerome Glissee7d40b92009-10-01 18:02:15 +02003266 if (!rdev->is_atom_bios) {
3267 dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003268 return -EINVAL;
Jerome Glissee7d40b92009-10-01 18:02:15 +02003269 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003270 r = radeon_atombios_init(rdev);
3271 if (r)
3272 return r;
3273 /* Post card if necessary */
Alex Deucherfd909c32011-01-11 18:08:59 -05003274 if (!radeon_card_posted(rdev)) {
Dave Airlie72542d72009-12-01 14:06:31 +10003275 if (!rdev->bios) {
3276 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
3277 return -EINVAL;
3278 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003279 DRM_INFO("GPU not posted. posting now...\n");
3280 atom_asic_init(rdev->mode_info.atom_context);
3281 }
3282 /* Initialize scratch registers */
3283 r600_scratch_init(rdev);
3284 /* Initialize surface registers */
3285 radeon_surface_init(rdev);
Rafał Miłecki74338742009-11-03 00:53:02 +01003286 /* Initialize clocks */
Michel Dänzer5e6dde72009-09-17 09:42:28 +02003287 radeon_get_clock_info(rdev->ddev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003288 /* Fence driver */
Jerome Glisse30eb77f2011-11-20 20:45:34 +00003289 r = radeon_fence_driver_init(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003290 if (r)
3291 return r;
Jerome Glisse700a0cc2010-01-13 15:16:38 +01003292 if (rdev->flags & RADEON_IS_AGP) {
3293 r = radeon_agp_init(rdev);
3294 if (r)
3295 radeon_agp_disable(rdev);
3296 }
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003297 r = r600_mc_init(rdev);
Jerome Glisseb574f252009-10-06 19:04:29 +02003298 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003299 return r;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003300 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +01003301 r = radeon_bo_init(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003302 if (r)
3303 return r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003304
Alex Deucher01ac8792013-12-18 19:11:27 -05003305 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
3306 r = r600_init_microcode(rdev);
3307 if (r) {
3308 DRM_ERROR("Failed to load firmware!\n");
3309 return r;
3310 }
3311 }
3312
Alex Deucher6c7bcce2013-12-18 14:07:14 -05003313 /* Initialize power management */
3314 radeon_pm_init(rdev);
3315
Christian Könige32eb502011-10-23 12:56:27 +02003316 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL;
3317 r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003318
Jérome Glissec91f9362016-03-18 16:58:26 +01003319 r600_uvd_init(rdev);
Christian König856754c2013-04-16 22:11:22 +02003320
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003321 rdev->ih.ring_obj = NULL;
3322 r600_ih_ring_init(rdev, 64 * 1024);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003323
Jerome Glisse4aac0472009-09-14 18:29:49 +02003324 r = r600_pcie_gart_init(rdev);
3325 if (r)
3326 return r;
3327
Alex Deucher779720a2009-12-09 19:31:44 -05003328 rdev->accel_working = true;
Dave Airliefc30b8e2009-09-18 15:19:37 +10003329 r = r600_startup(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003330 if (r) {
Jerome Glisse655efd32010-02-02 11:51:45 +01003331 dev_err(rdev->dev, "disabling GPU acceleration\n");
3332 r600_cp_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01003333 r600_irq_fini(rdev);
Alex Deucher724c80e2010-08-27 18:25:25 -04003334 radeon_wb_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02003335 radeon_ib_pool_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01003336 radeon_irq_kms_fini(rdev);
Jerome Glisse75c81292009-10-01 18:02:14 +02003337 r600_pcie_gart_fini(rdev);
Jerome Glisse733289c2009-09-16 15:24:21 +02003338 rdev->accel_working = false;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003339 }
Christian Koenigdafc3bd2009-10-11 23:49:13 +02003340
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003341 return 0;
3342}
3343
3344void r600_fini(struct radeon_device *rdev)
3345{
Alex Deucher6c7bcce2013-12-18 14:07:14 -05003346 radeon_pm_fini(rdev);
Slava Grigorev7991d662014-12-03 17:07:01 -05003347 radeon_audio_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01003348 r600_cp_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003349 r600_irq_fini(rdev);
Alex Deucherbdc99722014-08-26 13:11:36 -04003350 if (rdev->has_uvd) {
3351 uvd_v1_0_fini(rdev);
3352 radeon_uvd_fini(rdev);
3353 }
Alex Deucher724c80e2010-08-27 18:25:25 -04003354 radeon_wb_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02003355 radeon_ib_pool_fini(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003356 radeon_irq_kms_fini(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +02003357 r600_pcie_gart_fini(rdev);
Alex Deucher16cdf042011-10-28 10:30:02 -04003358 r600_vram_scratch_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01003359 radeon_agp_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003360 radeon_gem_fini(rdev);
3361 radeon_fence_driver_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +01003362 radeon_bo_fini(rdev);
Jerome Glissee7d40b92009-10-01 18:02:15 +02003363 radeon_atombios_fini(rdev);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003364 kfree(rdev->bios);
3365 rdev->bios = NULL;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003366}
3367
3368
3369/*
3370 * CS stuff
3371 */
3372void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
3373{
Christian König876dc9f2012-05-08 14:24:01 +02003374 struct radeon_ring *ring = &rdev->ring[ib->ring];
Alex Deucher89d35802012-07-17 14:02:31 -04003375 u32 next_rptr;
Christian König7b1f2482011-09-23 15:11:23 +02003376
Christian König45df6802012-07-06 16:22:55 +02003377 if (ring->rptr_save_reg) {
Alex Deucher89d35802012-07-17 14:02:31 -04003378 next_rptr = ring->wptr + 3 + 4;
Christian König45df6802012-07-06 16:22:55 +02003379 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
3380 radeon_ring_write(ring, ((ring->rptr_save_reg -
3381 PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
3382 radeon_ring_write(ring, next_rptr);
Alex Deucher89d35802012-07-17 14:02:31 -04003383 } else if (rdev->wb.enabled) {
3384 next_rptr = ring->wptr + 5 + 4;
3385 radeon_ring_write(ring, PACKET3(PACKET3_MEM_WRITE, 3));
3386 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
3387 radeon_ring_write(ring, (upper_32_bits(ring->next_rptr_gpu_addr) & 0xff) | (1 << 18));
3388 radeon_ring_write(ring, next_rptr);
3389 radeon_ring_write(ring, 0);
Christian König45df6802012-07-06 16:22:55 +02003390 }
3391
Christian Könige32eb502011-10-23 12:56:27 +02003392 radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
3393 radeon_ring_write(ring,
Cédric Cano4eace7f2011-02-11 19:45:38 -05003394#ifdef __BIG_ENDIAN
3395 (2 << 0) |
3396#endif
3397 (ib->gpu_addr & 0xFFFFFFFC));
Christian Könige32eb502011-10-23 12:56:27 +02003398 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
3399 radeon_ring_write(ring, ib->length_dw);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003400}
3401
Alex Deucherf7128122012-02-23 17:53:45 -05003402int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003403{
Jerome Glissef2e39222012-05-09 15:35:02 +02003404 struct radeon_ib ib;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003405 uint32_t scratch;
3406 uint32_t tmp = 0;
3407 unsigned i;
3408 int r;
3409
3410 r = radeon_scratch_get(rdev, &scratch);
3411 if (r) {
3412 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
3413 return r;
3414 }
3415 WREG32(scratch, 0xCAFEDEAD);
Christian König4bf3dd92012-08-06 18:57:44 +02003416 r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003417 if (r) {
3418 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
Michel Dänzeraf026c52012-09-20 10:31:10 +02003419 goto free_scratch;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003420 }
Jerome Glissef2e39222012-05-09 15:35:02 +02003421 ib.ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1);
3422 ib.ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
3423 ib.ptr[2] = 0xDEADBEEF;
3424 ib.length_dw = 3;
Michel Dänzer1538a9e2014-08-18 17:34:55 +09003425 r = radeon_ib_schedule(rdev, &ib, NULL, false);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003426 if (r) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003427 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
Michel Dänzeraf026c52012-09-20 10:31:10 +02003428 goto free_ib;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003429 }
Matthew Dawson04db4ca2016-02-07 16:51:12 -05003430 r = radeon_fence_wait_timeout(ib.fence, false, usecs_to_jiffies(
3431 RADEON_USEC_IB_TEST_TIMEOUT));
3432 if (r < 0) {
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003433 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
Michel Dänzeraf026c52012-09-20 10:31:10 +02003434 goto free_ib;
Matthew Dawson04db4ca2016-02-07 16:51:12 -05003435 } else if (r == 0) {
3436 DRM_ERROR("radeon: fence wait timed out.\n");
3437 r = -ETIMEDOUT;
3438 goto free_ib;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003439 }
Matthew Dawson04db4ca2016-02-07 16:51:12 -05003440 r = 0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003441 for (i = 0; i < rdev->usec_timeout; i++) {
3442 tmp = RREG32(scratch);
3443 if (tmp == 0xDEADBEEF)
3444 break;
3445 DRM_UDELAY(1);
3446 }
3447 if (i < rdev->usec_timeout) {
Jerome Glissef2e39222012-05-09 15:35:02 +02003448 DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003449 } else {
Daniel J Blueman4417d7f2010-09-22 17:57:19 +01003450 DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003451 scratch, tmp);
3452 r = -EINVAL;
3453 }
Michel Dänzeraf026c52012-09-20 10:31:10 +02003454free_ib:
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003455 radeon_ib_free(rdev, &ib);
Michel Dänzeraf026c52012-09-20 10:31:10 +02003456free_scratch:
3457 radeon_scratch_free(rdev, scratch);
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003458 return r;
3459}
3460
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003461/*
3462 * Interrupts
3463 *
3464 * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
3465 * the same as the CP ring buffer, but in reverse. Rather than the CPU
3466 * writing to the ring and the GPU consuming, the GPU writes to the ring
3467 * and host consumes. As the host irq handler processes interrupts, it
3468 * increments the rptr. When the rptr catches up with the wptr, all the
3469 * current interrupts have been processed.
3470 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003471
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003472void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size)
3473{
3474 u32 rb_bufsz;
Jerome Glisse3ce0a232009-09-08 10:10:24 +10003475
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003476 /* Align ring size */
Daniel Vetterb72a8922013-07-10 14:11:59 +02003477 rb_bufsz = order_base_2(ring_size / 4);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003478 ring_size = (1 << rb_bufsz) * 4;
3479 rdev->ih.ring_size = ring_size;
Jerome Glisse0c452492010-01-15 14:44:37 +01003480 rdev->ih.ptr_mask = rdev->ih.ring_size - 1;
3481 rdev->ih.rptr = 0;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003482}
3483
Alex Deucher25a857f2012-03-20 17:18:22 -04003484int r600_ih_ring_alloc(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003485{
3486 int r;
3487
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003488 /* Allocate ring buffer */
3489 if (rdev->ih.ring_obj == NULL) {
Daniel Vetter441921d2011-02-18 17:59:16 +01003490 r = radeon_bo_create(rdev, rdev->ih.ring_size,
Alex Deucher268b2512010-11-17 19:00:26 -05003491 PAGE_SIZE, true,
Michel Dänzer02376d82014-07-17 19:01:08 +09003492 RADEON_GEM_DOMAIN_GTT, 0,
Maarten Lankhorst831b6962014-09-18 14:11:56 +02003493 NULL, NULL, &rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003494 if (r) {
3495 DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r);
3496 return r;
3497 }
Jerome Glisse4c788672009-11-20 14:29:23 +01003498 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
3499 if (unlikely(r != 0))
3500 return r;
3501 r = radeon_bo_pin(rdev->ih.ring_obj,
3502 RADEON_GEM_DOMAIN_GTT,
3503 &rdev->ih.gpu_addr);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003504 if (r) {
Jerome Glisse4c788672009-11-20 14:29:23 +01003505 radeon_bo_unreserve(rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003506 DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r);
3507 return r;
3508 }
Jerome Glisse4c788672009-11-20 14:29:23 +01003509 r = radeon_bo_kmap(rdev->ih.ring_obj,
3510 (void **)&rdev->ih.ring);
3511 radeon_bo_unreserve(rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003512 if (r) {
3513 DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r);
3514 return r;
3515 }
3516 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003517 return 0;
3518}
3519
Alex Deucher25a857f2012-03-20 17:18:22 -04003520void r600_ih_ring_fini(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003521{
Jerome Glisse4c788672009-11-20 14:29:23 +01003522 int r;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003523 if (rdev->ih.ring_obj) {
Jerome Glisse4c788672009-11-20 14:29:23 +01003524 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
3525 if (likely(r == 0)) {
3526 radeon_bo_kunmap(rdev->ih.ring_obj);
3527 radeon_bo_unpin(rdev->ih.ring_obj);
3528 radeon_bo_unreserve(rdev->ih.ring_obj);
3529 }
3530 radeon_bo_unref(&rdev->ih.ring_obj);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003531 rdev->ih.ring = NULL;
3532 rdev->ih.ring_obj = NULL;
3533 }
3534}
3535
Alex Deucher45f9a392010-03-24 13:55:51 -04003536void r600_rlc_stop(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003537{
3538
Alex Deucher45f9a392010-03-24 13:55:51 -04003539 if ((rdev->family >= CHIP_RV770) &&
3540 (rdev->family <= CHIP_RV740)) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003541 /* r7xx asics need to soft reset RLC before halting */
3542 WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC);
3543 RREG32(SRBM_SOFT_RESET);
Arnd Bergmann4de833c2012-04-05 12:58:22 -06003544 mdelay(15);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003545 WREG32(SRBM_SOFT_RESET, 0);
3546 RREG32(SRBM_SOFT_RESET);
3547 }
3548
3549 WREG32(RLC_CNTL, 0);
3550}
3551
3552static void r600_rlc_start(struct radeon_device *rdev)
3553{
3554 WREG32(RLC_CNTL, RLC_ENABLE);
3555}
3556
Alex Deucher2948f5e2013-04-12 13:52:52 -04003557static int r600_rlc_resume(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003558{
3559 u32 i;
3560 const __be32 *fw_data;
3561
3562 if (!rdev->rlc_fw)
3563 return -EINVAL;
3564
3565 r600_rlc_stop(rdev);
3566
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003567 WREG32(RLC_HB_CNTL, 0);
Alex Deucherc420c742012-03-20 17:18:39 -04003568
Alex Deucher2948f5e2013-04-12 13:52:52 -04003569 WREG32(RLC_HB_BASE, 0);
3570 WREG32(RLC_HB_RPTR, 0);
3571 WREG32(RLC_HB_WPTR, 0);
3572 WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
3573 WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003574 WREG32(RLC_MC_CNTL, 0);
3575 WREG32(RLC_UCODE_CNTL, 0);
3576
3577 fw_data = (const __be32 *)rdev->rlc_fw->data;
Alex Deucher2948f5e2013-04-12 13:52:52 -04003578 if (rdev->family >= CHIP_RV770) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003579 for (i = 0; i < R700_RLC_UCODE_SIZE; i++) {
3580 WREG32(RLC_UCODE_ADDR, i);
3581 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
3582 }
3583 } else {
Alex Deucher138e4e12013-01-11 15:33:13 -05003584 for (i = 0; i < R600_RLC_UCODE_SIZE; i++) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003585 WREG32(RLC_UCODE_ADDR, i);
3586 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
3587 }
3588 }
3589 WREG32(RLC_UCODE_ADDR, 0);
3590
3591 r600_rlc_start(rdev);
3592
3593 return 0;
3594}
3595
3596static void r600_enable_interrupts(struct radeon_device *rdev)
3597{
3598 u32 ih_cntl = RREG32(IH_CNTL);
3599 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
3600
3601 ih_cntl |= ENABLE_INTR;
3602 ih_rb_cntl |= IH_RB_ENABLE;
3603 WREG32(IH_CNTL, ih_cntl);
3604 WREG32(IH_RB_CNTL, ih_rb_cntl);
3605 rdev->ih.enabled = true;
3606}
3607
Alex Deucher45f9a392010-03-24 13:55:51 -04003608void r600_disable_interrupts(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003609{
3610 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
3611 u32 ih_cntl = RREG32(IH_CNTL);
3612
3613 ih_rb_cntl &= ~IH_RB_ENABLE;
3614 ih_cntl &= ~ENABLE_INTR;
3615 WREG32(IH_RB_CNTL, ih_rb_cntl);
3616 WREG32(IH_CNTL, ih_cntl);
3617 /* set rptr, wptr to 0 */
3618 WREG32(IH_RB_RPTR, 0);
3619 WREG32(IH_RB_WPTR, 0);
3620 rdev->ih.enabled = false;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003621 rdev->ih.rptr = 0;
3622}
3623
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003624static void r600_disable_interrupt_state(struct radeon_device *rdev)
3625{
3626 u32 tmp;
3627
Alex Deucher3555e532010-10-08 12:09:12 -04003628 WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
Alex Deucher4d756582012-09-27 15:08:35 -04003629 tmp = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
3630 WREG32(DMA_CNTL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003631 WREG32(GRBM_INT_CNTL, 0);
3632 WREG32(DxMODE_INT_MASK, 0);
Alex Deucher6f34be52010-11-21 10:59:01 -05003633 WREG32(D1GRPH_INTERRUPT_CONTROL, 0);
3634 WREG32(D2GRPH_INTERRUPT_CONTROL, 0);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003635 if (ASIC_IS_DCE3(rdev)) {
3636 WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL, 0);
3637 WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL, 0);
3638 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3639 WREG32(DC_HPD1_INT_CONTROL, tmp);
3640 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3641 WREG32(DC_HPD2_INT_CONTROL, tmp);
3642 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3643 WREG32(DC_HPD3_INT_CONTROL, tmp);
3644 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3645 WREG32(DC_HPD4_INT_CONTROL, tmp);
3646 if (ASIC_IS_DCE32(rdev)) {
3647 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04003648 WREG32(DC_HPD5_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003649 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04003650 WREG32(DC_HPD6_INT_CONTROL, tmp);
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003651 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3652 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, tmp);
3653 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3654 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, tmp);
Alex Deucherf122c612012-03-30 08:59:57 -04003655 } else {
3656 tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3657 WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
3658 tmp = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3659 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003660 }
3661 } else {
3662 WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
3663 WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
3664 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04003665 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003666 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04003667 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003668 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
Alex Deucher5898b1f2010-03-24 13:57:29 -04003669 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
Alex Deucherf122c612012-03-30 08:59:57 -04003670 tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3671 WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
3672 tmp = RREG32(HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3673 WREG32(HDMI1_AUDIO_PACKET_CONTROL, tmp);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003674 }
3675}
3676
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003677int r600_irq_init(struct radeon_device *rdev)
3678{
3679 int ret = 0;
3680 int rb_bufsz;
3681 u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
3682
3683 /* allocate ring */
Jerome Glisse0c452492010-01-15 14:44:37 +01003684 ret = r600_ih_ring_alloc(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003685 if (ret)
3686 return ret;
3687
3688 /* disable irqs */
3689 r600_disable_interrupts(rdev);
3690
3691 /* init rlc */
Alex Deucher2948f5e2013-04-12 13:52:52 -04003692 if (rdev->family >= CHIP_CEDAR)
3693 ret = evergreen_rlc_resume(rdev);
3694 else
3695 ret = r600_rlc_resume(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003696 if (ret) {
3697 r600_ih_ring_fini(rdev);
3698 return ret;
3699 }
3700
3701 /* setup interrupt control */
3702 /* set dummy read address to ring address */
3703 WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
3704 interrupt_cntl = RREG32(INTERRUPT_CNTL);
3705 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
3706 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
3707 */
3708 interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
3709 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
3710 interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
3711 WREG32(INTERRUPT_CNTL, interrupt_cntl);
3712
3713 WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
Daniel Vetterb72a8922013-07-10 14:11:59 +02003714 rb_bufsz = order_base_2(rdev->ih.ring_size / 4);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003715
3716 ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
3717 IH_WPTR_OVERFLOW_CLEAR |
3718 (rb_bufsz << 1));
Alex Deucher724c80e2010-08-27 18:25:25 -04003719
3720 if (rdev->wb.enabled)
3721 ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
3722
3723 /* set the writeback address whether it's enabled or not */
3724 WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
3725 WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003726
3727 WREG32(IH_RB_CNTL, ih_rb_cntl);
3728
3729 /* set rptr, wptr to 0 */
3730 WREG32(IH_RB_RPTR, 0);
3731 WREG32(IH_RB_WPTR, 0);
3732
3733 /* Default settings for IH_CNTL (disabled at first) */
3734 ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
3735 /* RPTR_REARM only works if msi's are enabled */
3736 if (rdev->msi_enabled)
3737 ih_cntl |= RPTR_REARM;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003738 WREG32(IH_CNTL, ih_cntl);
3739
3740 /* force the active interrupt state to all disabled */
Alex Deucher45f9a392010-03-24 13:55:51 -04003741 if (rdev->family >= CHIP_CEDAR)
3742 evergreen_disable_interrupt_state(rdev);
3743 else
3744 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003745
Dave Airlie20998102012-04-03 11:53:05 +01003746 /* at this point everything should be setup correctly to enable master */
3747 pci_set_master(rdev->pdev);
3748
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003749 /* enable irqs */
3750 r600_enable_interrupts(rdev);
3751
3752 return ret;
3753}
3754
Jerome Glisse0c452492010-01-15 14:44:37 +01003755void r600_irq_suspend(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003756{
Alex Deucher45f9a392010-03-24 13:55:51 -04003757 r600_irq_disable(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003758 r600_rlc_stop(rdev);
Jerome Glisse0c452492010-01-15 14:44:37 +01003759}
3760
3761void r600_irq_fini(struct radeon_device *rdev)
3762{
3763 r600_irq_suspend(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003764 r600_ih_ring_fini(rdev);
3765}
3766
3767int r600_irq_set(struct radeon_device *rdev)
3768{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003769 u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
3770 u32 mode_int = 0;
3771 u32 hpd1, hpd2, hpd3, hpd4 = 0, hpd5 = 0, hpd6 = 0;
Alex Deucher2031f772010-04-22 12:52:11 -04003772 u32 grbm_int_cntl = 0;
Alex Deucherf122c612012-03-30 08:59:57 -04003773 u32 hdmi0, hdmi1;
Alex Deucher4d756582012-09-27 15:08:35 -04003774 u32 dma_cntl;
Alex Deucher4a6369e2013-04-12 14:04:10 -04003775 u32 thermal_int = 0;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003776
Jerome Glisse003e69f2010-01-07 15:39:14 +01003777 if (!rdev->irq.installed) {
Joe Perchesfce7d612010-10-30 21:08:30 +00003778 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
Jerome Glisse003e69f2010-01-07 15:39:14 +01003779 return -EINVAL;
3780 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003781 /* don't enable anything if the ih is disabled */
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003782 if (!rdev->ih.enabled) {
3783 r600_disable_interrupts(rdev);
3784 /* force the active interrupt state to all disabled */
3785 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003786 return 0;
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01003787 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003788
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003789 if (ASIC_IS_DCE3(rdev)) {
3790 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
3791 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
3792 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
3793 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
3794 if (ASIC_IS_DCE32(rdev)) {
3795 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
3796 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003797 hdmi0 = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
3798 hdmi1 = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
Alex Deucherf122c612012-03-30 08:59:57 -04003799 } else {
3800 hdmi0 = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3801 hdmi1 = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003802 }
3803 } else {
3804 hpd1 = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & ~DC_HPDx_INT_EN;
3805 hpd2 = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & ~DC_HPDx_INT_EN;
3806 hpd3 = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & ~DC_HPDx_INT_EN;
Alex Deucherf122c612012-03-30 08:59:57 -04003807 hdmi0 = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3808 hdmi1 = RREG32(HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003809 }
Alex Deucher4a6369e2013-04-12 14:04:10 -04003810
Alex Deucher4d756582012-09-27 15:08:35 -04003811 dma_cntl = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003812
Alex Deucher4a6369e2013-04-12 14:04:10 -04003813 if ((rdev->family > CHIP_R600) && (rdev->family < CHIP_RV770)) {
3814 thermal_int = RREG32(CG_THERMAL_INT) &
3815 ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
Alex Deucher66229b22013-06-26 00:11:19 -04003816 } else if (rdev->family >= CHIP_RV770) {
3817 thermal_int = RREG32(RV770_CG_THERMAL_INT) &
3818 ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
3819 }
3820 if (rdev->irq.dpm_thermal) {
3821 DRM_DEBUG("dpm thermal\n");
3822 thermal_int |= THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW;
Alex Deucher4a6369e2013-04-12 14:04:10 -04003823 }
3824
Christian Koenig736fc372012-05-17 19:52:00 +02003825 if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003826 DRM_DEBUG("r600_irq_set: sw int\n");
3827 cp_int_cntl |= RB_INT_ENABLE;
Alex Deucherd0f8a852010-09-04 05:04:34 -04003828 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003829 }
Alex Deucher4d756582012-09-27 15:08:35 -04003830
3831 if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
3832 DRM_DEBUG("r600_irq_set: sw int dma\n");
3833 dma_cntl |= TRAP_ENABLE;
3834 }
3835
Alex Deucher6f34be52010-11-21 10:59:01 -05003836 if (rdev->irq.crtc_vblank_int[0] ||
Christian Koenig736fc372012-05-17 19:52:00 +02003837 atomic_read(&rdev->irq.pflip[0])) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003838 DRM_DEBUG("r600_irq_set: vblank 0\n");
3839 mode_int |= D1MODE_VBLANK_INT_MASK;
3840 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003841 if (rdev->irq.crtc_vblank_int[1] ||
Christian Koenig736fc372012-05-17 19:52:00 +02003842 atomic_read(&rdev->irq.pflip[1])) {
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003843 DRM_DEBUG("r600_irq_set: vblank 1\n");
3844 mode_int |= D2MODE_VBLANK_INT_MASK;
3845 }
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003846 if (rdev->irq.hpd[0]) {
3847 DRM_DEBUG("r600_irq_set: hpd 1\n");
3848 hpd1 |= DC_HPDx_INT_EN;
3849 }
3850 if (rdev->irq.hpd[1]) {
3851 DRM_DEBUG("r600_irq_set: hpd 2\n");
3852 hpd2 |= DC_HPDx_INT_EN;
3853 }
3854 if (rdev->irq.hpd[2]) {
3855 DRM_DEBUG("r600_irq_set: hpd 3\n");
3856 hpd3 |= DC_HPDx_INT_EN;
3857 }
3858 if (rdev->irq.hpd[3]) {
3859 DRM_DEBUG("r600_irq_set: hpd 4\n");
3860 hpd4 |= DC_HPDx_INT_EN;
3861 }
3862 if (rdev->irq.hpd[4]) {
3863 DRM_DEBUG("r600_irq_set: hpd 5\n");
3864 hpd5 |= DC_HPDx_INT_EN;
3865 }
3866 if (rdev->irq.hpd[5]) {
3867 DRM_DEBUG("r600_irq_set: hpd 6\n");
3868 hpd6 |= DC_HPDx_INT_EN;
3869 }
Alex Deucherf122c612012-03-30 08:59:57 -04003870 if (rdev->irq.afmt[0]) {
3871 DRM_DEBUG("r600_irq_set: hdmi 0\n");
3872 hdmi0 |= HDMI0_AZ_FORMAT_WTRIG_MASK;
Christian Koenigf2594932010-04-10 03:13:16 +02003873 }
Alex Deucherf122c612012-03-30 08:59:57 -04003874 if (rdev->irq.afmt[1]) {
3875 DRM_DEBUG("r600_irq_set: hdmi 0\n");
3876 hdmi1 |= HDMI0_AZ_FORMAT_WTRIG_MASK;
Christian Koenigf2594932010-04-10 03:13:16 +02003877 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003878
3879 WREG32(CP_INT_CNTL, cp_int_cntl);
Alex Deucher4d756582012-09-27 15:08:35 -04003880 WREG32(DMA_CNTL, dma_cntl);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003881 WREG32(DxMODE_INT_MASK, mode_int);
Christian Königf5d636d2014-04-23 20:46:06 +02003882 WREG32(D1GRPH_INTERRUPT_CONTROL, DxGRPH_PFLIP_INT_MASK);
3883 WREG32(D2GRPH_INTERRUPT_CONTROL, DxGRPH_PFLIP_INT_MASK);
Alex Deucher2031f772010-04-22 12:52:11 -04003884 WREG32(GRBM_INT_CNTL, grbm_int_cntl);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003885 if (ASIC_IS_DCE3(rdev)) {
3886 WREG32(DC_HPD1_INT_CONTROL, hpd1);
3887 WREG32(DC_HPD2_INT_CONTROL, hpd2);
3888 WREG32(DC_HPD3_INT_CONTROL, hpd3);
3889 WREG32(DC_HPD4_INT_CONTROL, hpd4);
3890 if (ASIC_IS_DCE32(rdev)) {
3891 WREG32(DC_HPD5_INT_CONTROL, hpd5);
3892 WREG32(DC_HPD6_INT_CONTROL, hpd6);
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003893 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, hdmi0);
3894 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, hdmi1);
Alex Deucherf122c612012-03-30 08:59:57 -04003895 } else {
3896 WREG32(HDMI0_AUDIO_PACKET_CONTROL, hdmi0);
3897 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, hdmi1);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003898 }
3899 } else {
3900 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
3901 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
3902 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, hpd3);
Alex Deucherf122c612012-03-30 08:59:57 -04003903 WREG32(HDMI0_AUDIO_PACKET_CONTROL, hdmi0);
3904 WREG32(HDMI1_AUDIO_PACKET_CONTROL, hdmi1);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003905 }
Alex Deucher4a6369e2013-04-12 14:04:10 -04003906 if ((rdev->family > CHIP_R600) && (rdev->family < CHIP_RV770)) {
3907 WREG32(CG_THERMAL_INT, thermal_int);
Alex Deucher66229b22013-06-26 00:11:19 -04003908 } else if (rdev->family >= CHIP_RV770) {
3909 WREG32(RV770_CG_THERMAL_INT, thermal_int);
Alex Deucher4a6369e2013-04-12 14:04:10 -04003910 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003911
Alex Deucher9d1393f2015-03-02 20:41:31 -05003912 /* posting read */
3913 RREG32(R_000E50_SRBM_STATUS);
3914
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003915 return 0;
3916}
3917
Andi Kleence580fa2011-10-13 16:08:47 -07003918static void r600_irq_ack(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003919{
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003920 u32 tmp;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003921
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003922 if (ASIC_IS_DCE3(rdev)) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003923 rdev->irq.stat_regs.r600.disp_int = RREG32(DCE3_DISP_INTERRUPT_STATUS);
3924 rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE);
3925 rdev->irq.stat_regs.r600.disp_int_cont2 = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2);
Alex Deucherf122c612012-03-30 08:59:57 -04003926 if (ASIC_IS_DCE32(rdev)) {
Rafał Miłeckic6543a62012-04-28 23:35:24 +02003927 rdev->irq.stat_regs.r600.hdmi0_status = RREG32(AFMT_STATUS + DCE3_HDMI_OFFSET0);
3928 rdev->irq.stat_regs.r600.hdmi1_status = RREG32(AFMT_STATUS + DCE3_HDMI_OFFSET1);
Alex Deucherf122c612012-03-30 08:59:57 -04003929 } else {
3930 rdev->irq.stat_regs.r600.hdmi0_status = RREG32(HDMI0_STATUS);
3931 rdev->irq.stat_regs.r600.hdmi1_status = RREG32(DCE3_HDMI1_STATUS);
3932 }
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003933 } else {
Alex Deucher6f34be52010-11-21 10:59:01 -05003934 rdev->irq.stat_regs.r600.disp_int = RREG32(DISP_INTERRUPT_STATUS);
3935 rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
3936 rdev->irq.stat_regs.r600.disp_int_cont2 = 0;
Alex Deucherf122c612012-03-30 08:59:57 -04003937 rdev->irq.stat_regs.r600.hdmi0_status = RREG32(HDMI0_STATUS);
3938 rdev->irq.stat_regs.r600.hdmi1_status = RREG32(HDMI1_STATUS);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003939 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003940 rdev->irq.stat_regs.r600.d1grph_int = RREG32(D1GRPH_INTERRUPT_STATUS);
3941 rdev->irq.stat_regs.r600.d2grph_int = RREG32(D2GRPH_INTERRUPT_STATUS);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003942
Alex Deucher6f34be52010-11-21 10:59:01 -05003943 if (rdev->irq.stat_regs.r600.d1grph_int & DxGRPH_PFLIP_INT_OCCURRED)
3944 WREG32(D1GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR);
3945 if (rdev->irq.stat_regs.r600.d2grph_int & DxGRPH_PFLIP_INT_OCCURRED)
3946 WREG32(D2GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR);
3947 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003948 WREG32(D1MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003949 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003950 WREG32(D1MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003951 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003952 WREG32(D2MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003953 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05003954 WREG32(D2MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
Alex Deucher6f34be52010-11-21 10:59:01 -05003955 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003956 if (ASIC_IS_DCE3(rdev)) {
3957 tmp = RREG32(DC_HPD1_INT_CONTROL);
3958 tmp |= DC_HPDx_INT_ACK;
3959 WREG32(DC_HPD1_INT_CONTROL, tmp);
3960 } else {
3961 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
3962 tmp |= DC_HPDx_INT_ACK;
3963 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
3964 }
3965 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003966 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003967 if (ASIC_IS_DCE3(rdev)) {
3968 tmp = RREG32(DC_HPD2_INT_CONTROL);
3969 tmp |= DC_HPDx_INT_ACK;
3970 WREG32(DC_HPD2_INT_CONTROL, tmp);
3971 } else {
3972 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
3973 tmp |= DC_HPDx_INT_ACK;
3974 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
3975 }
3976 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003977 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003978 if (ASIC_IS_DCE3(rdev)) {
3979 tmp = RREG32(DC_HPD3_INT_CONTROL);
3980 tmp |= DC_HPDx_INT_ACK;
3981 WREG32(DC_HPD3_INT_CONTROL, tmp);
3982 } else {
3983 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
3984 tmp |= DC_HPDx_INT_ACK;
3985 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
3986 }
3987 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003988 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003989 tmp = RREG32(DC_HPD4_INT_CONTROL);
3990 tmp |= DC_HPDx_INT_ACK;
3991 WREG32(DC_HPD4_INT_CONTROL, tmp);
3992 }
3993 if (ASIC_IS_DCE32(rdev)) {
Alex Deucher6f34be52010-11-21 10:59:01 -05003994 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05003995 tmp = RREG32(DC_HPD5_INT_CONTROL);
3996 tmp |= DC_HPDx_INT_ACK;
3997 WREG32(DC_HPD5_INT_CONTROL, tmp);
3998 }
Alex Deucher6f34be52010-11-21 10:59:01 -05003999 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT) {
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004000 tmp = RREG32(DC_HPD5_INT_CONTROL);
4001 tmp |= DC_HPDx_INT_ACK;
4002 WREG32(DC_HPD6_INT_CONTROL, tmp);
4003 }
Alex Deucherf122c612012-03-30 08:59:57 -04004004 if (rdev->irq.stat_regs.r600.hdmi0_status & AFMT_AZ_FORMAT_WTRIG) {
Rafał Miłeckic6543a62012-04-28 23:35:24 +02004005 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0);
Alex Deucherf122c612012-03-30 08:59:57 -04004006 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
Rafał Miłeckic6543a62012-04-28 23:35:24 +02004007 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, tmp);
Alex Deucherf122c612012-03-30 08:59:57 -04004008 }
4009 if (rdev->irq.stat_regs.r600.hdmi1_status & AFMT_AZ_FORMAT_WTRIG) {
Rafał Miłeckic6543a62012-04-28 23:35:24 +02004010 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1);
Alex Deucherf122c612012-03-30 08:59:57 -04004011 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
Rafał Miłeckic6543a62012-04-28 23:35:24 +02004012 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, tmp);
Christian Koenigf2594932010-04-10 03:13:16 +02004013 }
4014 } else {
Alex Deucherf122c612012-03-30 08:59:57 -04004015 if (rdev->irq.stat_regs.r600.hdmi0_status & HDMI0_AZ_FORMAT_WTRIG) {
4016 tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL);
4017 tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
4018 WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
4019 }
4020 if (rdev->irq.stat_regs.r600.hdmi1_status & HDMI0_AZ_FORMAT_WTRIG) {
4021 if (ASIC_IS_DCE3(rdev)) {
4022 tmp = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL);
4023 tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
4024 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, tmp);
4025 } else {
4026 tmp = RREG32(HDMI1_AUDIO_PACKET_CONTROL);
4027 tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
4028 WREG32(HDMI1_AUDIO_PACKET_CONTROL, tmp);
4029 }
Christian Koenigf2594932010-04-10 03:13:16 +02004030 }
4031 }
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004032}
4033
4034void r600_irq_disable(struct radeon_device *rdev)
4035{
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004036 r600_disable_interrupts(rdev);
4037 /* Wait and acknowledge irq */
4038 mdelay(1);
Alex Deucher6f34be52010-11-21 10:59:01 -05004039 r600_irq_ack(rdev);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004040 r600_disable_interrupt_state(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004041}
4042
Andi Kleence580fa2011-10-13 16:08:47 -07004043static u32 r600_get_ih_wptr(struct radeon_device *rdev)
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004044{
4045 u32 wptr, tmp;
4046
Alex Deucher724c80e2010-08-27 18:25:25 -04004047 if (rdev->wb.enabled)
Cédric Cano204ae242011-04-19 11:07:13 -04004048 wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
Alex Deucher724c80e2010-08-27 18:25:25 -04004049 else
4050 wptr = RREG32(IH_RB_WPTR);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004051
4052 if (wptr & RB_OVERFLOW) {
Michel Dänzer11bab0a2014-09-19 12:07:11 +09004053 wptr &= ~RB_OVERFLOW;
Jerome Glisse7924e5e2010-01-15 14:44:39 +01004054 /* When a ring buffer overflow happen start parsing interrupt
4055 * from the last not overwritten vector (wptr + 16). Hopefully
4056 * this should allow us to catchup.
4057 */
Michel Dänzer6cc2fda2014-09-19 12:22:07 +09004058 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n",
4059 wptr, rdev->ih.rptr, (wptr + 16) & rdev->ih.ptr_mask);
Jerome Glisse7924e5e2010-01-15 14:44:39 +01004060 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004061 tmp = RREG32(IH_RB_CNTL);
4062 tmp |= IH_WPTR_OVERFLOW_CLEAR;
4063 WREG32(IH_RB_CNTL, tmp);
4064 }
Jerome Glisse0c452492010-01-15 14:44:37 +01004065 return (wptr & rdev->ih.ptr_mask);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004066}
4067
4068/* r600 IV Ring
4069 * Each IV ring entry is 128 bits:
4070 * [7:0] - interrupt source id
4071 * [31:8] - reserved
4072 * [59:32] - interrupt source data
4073 * [127:60] - reserved
4074 *
4075 * The basic interrupt vector entries
4076 * are decoded as follows:
4077 * src_id src_data description
4078 * 1 0 D1 Vblank
4079 * 1 1 D1 Vline
4080 * 5 0 D2 Vblank
4081 * 5 1 D2 Vline
4082 * 19 0 FP Hot plug detection A
4083 * 19 1 FP Hot plug detection B
4084 * 19 2 DAC A auto-detection
4085 * 19 3 DAC B auto-detection
Christian Koenigf2594932010-04-10 03:13:16 +02004086 * 21 4 HDMI block A
4087 * 21 5 HDMI block B
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004088 * 176 - CP_INT RB
4089 * 177 - CP_INT IB1
4090 * 178 - CP_INT IB2
4091 * 181 - EOP Interrupt
4092 * 233 - GUI Idle
4093 *
4094 * Note, these are based on r600 and may need to be
4095 * adjusted or added to on newer asics
4096 */
4097
4098int r600_irq_process(struct radeon_device *rdev)
4099{
Dave Airlie682f1a52011-06-18 03:59:51 +00004100 u32 wptr;
4101 u32 rptr;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004102 u32 src_id, src_data;
Alex Deucher6f34be52010-11-21 10:59:01 -05004103 u32 ring_index;
Alex Deucherd4877cf2009-12-04 16:56:37 -05004104 bool queue_hotplug = false;
Alex Deucherf122c612012-03-30 08:59:57 -04004105 bool queue_hdmi = false;
Alex Deucher4a6369e2013-04-12 14:04:10 -04004106 bool queue_thermal = false;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004107
Dave Airlie682f1a52011-06-18 03:59:51 +00004108 if (!rdev->ih.enabled || rdev->shutdown)
Jerome Glisse79c2bbc2010-01-15 14:44:38 +01004109 return IRQ_NONE;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004110
Benjamin Herrenschmidtf6a56932011-07-13 06:28:22 +00004111 /* No MSIs, need a dummy read to flush PCI DMAs */
4112 if (!rdev->msi_enabled)
4113 RREG32(IH_RB_WPTR);
4114
Dave Airlie682f1a52011-06-18 03:59:51 +00004115 wptr = r600_get_ih_wptr(rdev);
Christian Koenigc20dc362012-05-16 21:45:24 +02004116
4117restart_ih:
4118 /* is somebody else already processing irqs? */
4119 if (atomic_xchg(&rdev->ih.lock, 1))
4120 return IRQ_NONE;
4121
Dave Airlie682f1a52011-06-18 03:59:51 +00004122 rptr = rdev->ih.rptr;
4123 DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
4124
Benjamin Herrenschmidt964f6642011-07-13 16:28:19 +10004125 /* Order reading of wptr vs. reading of IH ring data */
4126 rmb();
4127
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004128 /* display interrupts */
Alex Deucher6f34be52010-11-21 10:59:01 -05004129 r600_irq_ack(rdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004130
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004131 while (rptr != wptr) {
4132 /* wptr/rptr are in bytes! */
4133 ring_index = rptr / 4;
Cédric Cano4eace7f2011-02-11 19:45:38 -05004134 src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
4135 src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004136
4137 switch (src_id) {
4138 case 1: /* D1 vblank/vline */
4139 switch (src_data) {
4140 case 0: /* D1 vblank */
Mario Kleiner07f18f02015-07-03 06:03:06 +02004141 if (!(rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT))
4142 DRM_DEBUG("IH: D1 vblank - IH event w/o asserted irq bit?\n");
4143
4144 if (rdev->irq.crtc_vblank_int[0]) {
4145 drm_handle_vblank(rdev->ddev, 0);
4146 rdev->pm.vblank_sync = true;
4147 wake_up(&rdev->irq.vblank_queue);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004148 }
Mario Kleiner07f18f02015-07-03 06:03:06 +02004149 if (atomic_read(&rdev->irq.pflip[0]))
4150 radeon_crtc_handle_vblank(rdev, 0);
4151 rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
4152 DRM_DEBUG("IH: D1 vblank\n");
4153
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004154 break;
4155 case 1: /* D1 vline */
Mario Kleiner07f18f02015-07-03 06:03:06 +02004156 if (!(rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT))
4157 DRM_DEBUG("IH: D1 vline - IH event w/o asserted irq bit?\n");
4158
4159 rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VLINE_INTERRUPT;
4160 DRM_DEBUG("IH: D1 vline\n");
4161
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004162 break;
4163 default:
Alex Deucherb0425892010-01-11 19:47:38 -05004164 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004165 break;
4166 }
4167 break;
4168 case 5: /* D2 vblank/vline */
4169 switch (src_data) {
4170 case 0: /* D2 vblank */
Mario Kleiner07f18f02015-07-03 06:03:06 +02004171 if (!(rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT))
4172 DRM_DEBUG("IH: D2 vblank - IH event w/o asserted irq bit?\n");
4173
4174 if (rdev->irq.crtc_vblank_int[1]) {
4175 drm_handle_vblank(rdev->ddev, 1);
4176 rdev->pm.vblank_sync = true;
4177 wake_up(&rdev->irq.vblank_queue);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004178 }
Mario Kleiner07f18f02015-07-03 06:03:06 +02004179 if (atomic_read(&rdev->irq.pflip[1]))
4180 radeon_crtc_handle_vblank(rdev, 1);
4181 rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VBLANK_INTERRUPT;
4182 DRM_DEBUG("IH: D2 vblank\n");
4183
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004184 break;
4185 case 1: /* D1 vline */
Mario Kleiner07f18f02015-07-03 06:03:06 +02004186 if (!(rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT))
4187 DRM_DEBUG("IH: D2 vline - IH event w/o asserted irq bit?\n");
4188
4189 rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VLINE_INTERRUPT;
4190 DRM_DEBUG("IH: D2 vline\n");
4191
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004192 break;
4193 default:
Alex Deucherb0425892010-01-11 19:47:38 -05004194 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004195 break;
4196 }
4197 break;
Christian Königf5d636d2014-04-23 20:46:06 +02004198 case 9: /* D1 pflip */
4199 DRM_DEBUG("IH: D1 flip\n");
Mario Kleiner39dc5452014-07-29 06:21:44 +02004200 if (radeon_use_pflipirq > 0)
4201 radeon_crtc_handle_flip(rdev, 0);
Christian Königf5d636d2014-04-23 20:46:06 +02004202 break;
4203 case 11: /* D2 pflip */
4204 DRM_DEBUG("IH: D2 flip\n");
Mario Kleiner39dc5452014-07-29 06:21:44 +02004205 if (radeon_use_pflipirq > 0)
4206 radeon_crtc_handle_flip(rdev, 1);
Christian Königf5d636d2014-04-23 20:46:06 +02004207 break;
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004208 case 19: /* HPD/DAC hotplug */
4209 switch (src_data) {
4210 case 0:
Mario Kleiner07f18f02015-07-03 06:03:06 +02004211 if (!(rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT))
4212 DRM_DEBUG("IH: HPD1 - IH event w/o asserted irq bit?\n");
4213
4214 rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD1_INTERRUPT;
4215 queue_hotplug = true;
4216 DRM_DEBUG("IH: HPD1\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004217 break;
4218 case 1:
Mario Kleiner07f18f02015-07-03 06:03:06 +02004219 if (!(rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT))
4220 DRM_DEBUG("IH: HPD2 - IH event w/o asserted irq bit?\n");
4221
4222 rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD2_INTERRUPT;
4223 queue_hotplug = true;
4224 DRM_DEBUG("IH: HPD2\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004225 break;
4226 case 4:
Mario Kleiner07f18f02015-07-03 06:03:06 +02004227 if (!(rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT))
4228 DRM_DEBUG("IH: HPD3 - IH event w/o asserted irq bit?\n");
4229
4230 rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD3_INTERRUPT;
4231 queue_hotplug = true;
4232 DRM_DEBUG("IH: HPD3\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004233 break;
4234 case 5:
Mario Kleiner07f18f02015-07-03 06:03:06 +02004235 if (!(rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT))
4236 DRM_DEBUG("IH: HPD4 - IH event w/o asserted irq bit?\n");
4237
4238 rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD4_INTERRUPT;
4239 queue_hotplug = true;
4240 DRM_DEBUG("IH: HPD4\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004241 break;
4242 case 10:
Mario Kleiner07f18f02015-07-03 06:03:06 +02004243 if (!(rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT))
4244 DRM_DEBUG("IH: HPD5 - IH event w/o asserted irq bit?\n");
4245
4246 rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD5_INTERRUPT;
4247 queue_hotplug = true;
4248 DRM_DEBUG("IH: HPD5\n");
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004249 break;
4250 case 12:
Mario Kleiner07f18f02015-07-03 06:03:06 +02004251 if (!(rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT))
4252 DRM_DEBUG("IH: HPD6 - IH event w/o asserted irq bit?\n");
4253
4254 rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD6_INTERRUPT;
4255 queue_hotplug = true;
4256 DRM_DEBUG("IH: HPD6\n");
4257
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004258 break;
4259 default:
Alex Deucherb0425892010-01-11 19:47:38 -05004260 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deuchere0df1ac2009-12-04 15:12:21 -05004261 break;
4262 }
4263 break;
Alex Deucherf122c612012-03-30 08:59:57 -04004264 case 21: /* hdmi */
4265 switch (src_data) {
4266 case 4:
Mario Kleiner07f18f02015-07-03 06:03:06 +02004267 if (!(rdev->irq.stat_regs.r600.hdmi0_status & HDMI0_AZ_FORMAT_WTRIG))
4268 DRM_DEBUG("IH: HDMI0 - IH event w/o asserted irq bit?\n");
4269
4270 rdev->irq.stat_regs.r600.hdmi0_status &= ~HDMI0_AZ_FORMAT_WTRIG;
4271 queue_hdmi = true;
4272 DRM_DEBUG("IH: HDMI0\n");
4273
Alex Deucherf122c612012-03-30 08:59:57 -04004274 break;
4275 case 5:
Mario Kleiner07f18f02015-07-03 06:03:06 +02004276 if (!(rdev->irq.stat_regs.r600.hdmi1_status & HDMI0_AZ_FORMAT_WTRIG))
4277 DRM_DEBUG("IH: HDMI1 - IH event w/o asserted irq bit?\n");
4278
4279 rdev->irq.stat_regs.r600.hdmi1_status &= ~HDMI0_AZ_FORMAT_WTRIG;
4280 queue_hdmi = true;
4281 DRM_DEBUG("IH: HDMI1\n");
4282
Alex Deucherf122c612012-03-30 08:59:57 -04004283 break;
4284 default:
4285 DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
4286 break;
4287 }
Christian Koenigf2594932010-04-10 03:13:16 +02004288 break;
Alex Deucher858a41c82014-01-30 14:35:04 -05004289 case 124: /* UVD */
4290 DRM_DEBUG("IH: UVD int: 0x%08x\n", src_data);
4291 radeon_fence_process(rdev, R600_RING_TYPE_UVD_INDEX);
4292 break;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004293 case 176: /* CP_INT in ring buffer */
4294 case 177: /* CP_INT in IB1 */
4295 case 178: /* CP_INT in IB2 */
4296 DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
Alex Deucher74652802011-08-25 13:39:48 -04004297 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004298 break;
4299 case 181: /* CP EOP event */
4300 DRM_DEBUG("IH: CP EOP\n");
Alex Deucher74652802011-08-25 13:39:48 -04004301 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004302 break;
Alex Deucher4d756582012-09-27 15:08:35 -04004303 case 224: /* DMA trap event */
4304 DRM_DEBUG("IH: DMA trap\n");
4305 radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
4306 break;
Alex Deucher4a6369e2013-04-12 14:04:10 -04004307 case 230: /* thermal low to high */
4308 DRM_DEBUG("IH: thermal low to high\n");
4309 rdev->pm.dpm.thermal.high_to_low = false;
4310 queue_thermal = true;
4311 break;
4312 case 231: /* thermal high to low */
4313 DRM_DEBUG("IH: thermal high to low\n");
4314 rdev->pm.dpm.thermal.high_to_low = true;
4315 queue_thermal = true;
4316 break;
Alex Deucher2031f772010-04-22 12:52:11 -04004317 case 233: /* GUI IDLE */
Ilija Hadzic303c8052011-06-07 14:54:48 -04004318 DRM_DEBUG("IH: GUI idle\n");
Alex Deucher2031f772010-04-22 12:52:11 -04004319 break;
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004320 default:
Alex Deucherb0425892010-01-11 19:47:38 -05004321 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004322 break;
4323 }
4324
4325 /* wptr/rptr are in bytes! */
Jerome Glisse0c452492010-01-15 14:44:37 +01004326 rptr += 16;
4327 rptr &= rdev->ih.ptr_mask;
Michel Dänzerf55e03b2014-09-19 12:22:10 +09004328 WREG32(IH_RB_RPTR, rptr);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004329 }
Alex Deucherd4877cf2009-12-04 16:56:37 -05004330 if (queue_hotplug)
Lyudecb5d4162015-12-03 18:26:07 -05004331 schedule_delayed_work(&rdev->hotplug_work, 0);
Alex Deucherf122c612012-03-30 08:59:57 -04004332 if (queue_hdmi)
4333 schedule_work(&rdev->audio_work);
Alex Deucher4a6369e2013-04-12 14:04:10 -04004334 if (queue_thermal && rdev->pm.dpm_enabled)
4335 schedule_work(&rdev->pm.dpm.thermal.work);
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004336 rdev->ih.rptr = rptr;
Christian Koenigc20dc362012-05-16 21:45:24 +02004337 atomic_set(&rdev->ih.lock, 0);
4338
4339 /* make sure wptr hasn't changed while processing */
4340 wptr = r600_get_ih_wptr(rdev);
4341 if (wptr != rptr)
4342 goto restart_ih;
4343
Alex Deucherd8f60cf2009-12-01 13:43:46 -05004344 return IRQ_HANDLED;
4345}
Jerome Glisse3ce0a232009-09-08 10:10:24 +10004346
4347/*
4348 * Debugfs info
4349 */
4350#if defined(CONFIG_DEBUG_FS)
4351
Jerome Glisse3ce0a232009-09-08 10:10:24 +10004352static int r600_debugfs_mc_info(struct seq_file *m, void *data)
4353{
4354 struct drm_info_node *node = (struct drm_info_node *) m->private;
4355 struct drm_device *dev = node->minor->dev;
4356 struct radeon_device *rdev = dev->dev_private;
4357
4358 DREG32_SYS(m, rdev, R_000E50_SRBM_STATUS);
4359 DREG32_SYS(m, rdev, VM_L2_STATUS);
4360 return 0;
4361}
4362
4363static struct drm_info_list r600_mc_info_list[] = {
4364 {"r600_mc_info", r600_debugfs_mc_info, 0, NULL},
Jerome Glisse3ce0a232009-09-08 10:10:24 +10004365};
4366#endif
4367
4368int r600_debugfs_mc_info_init(struct radeon_device *rdev)
4369{
4370#if defined(CONFIG_DEBUG_FS)
4371 return radeon_debugfs_add_files(rdev, r600_mc_info_list, ARRAY_SIZE(r600_mc_info_list));
4372#else
4373 return 0;
4374#endif
Jerome Glisse771fe6b2009-06-05 14:42:42 +02004375}
Jerome Glisse062b3892010-02-04 20:36:39 +01004376
4377/**
Michel Dänzer124764f2014-07-31 18:43:48 +09004378 * r600_mmio_hdp_flush - flush Host Data Path cache via MMIO
Jerome Glisse062b3892010-02-04 20:36:39 +01004379 * rdev: radeon device structure
Jerome Glisse062b3892010-02-04 20:36:39 +01004380 *
Michel Dänzer124764f2014-07-31 18:43:48 +09004381 * Some R6XX/R7XX don't seem to take into account HDP flushes performed
4382 * through the ring buffer. This leads to corruption in rendering, see
4383 * http://bugzilla.kernel.org/show_bug.cgi?id=15186 . To avoid this, we
4384 * directly perform the HDP flush by writing the register through MMIO.
Jerome Glisse062b3892010-02-04 20:36:39 +01004385 */
Michel Dänzer124764f2014-07-31 18:43:48 +09004386void r600_mmio_hdp_flush(struct radeon_device *rdev)
Jerome Glisse062b3892010-02-04 20:36:39 +01004387{
Alex Deucher812d0462010-07-26 18:51:53 -04004388 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
Alex Deucherf3886f82010-12-08 10:05:34 -05004389 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL.
4390 * This seems to cause problems on some AGP cards. Just use the old
4391 * method for them.
Alex Deucher812d0462010-07-26 18:51:53 -04004392 */
Alex Deuchere4884592010-09-27 10:57:10 -04004393 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
Alex Deucherf3886f82010-12-08 10:05:34 -05004394 rdev->vram_scratch.ptr && !(rdev->flags & RADEON_IS_AGP)) {
Alex Deucher87cbf8f2010-08-27 13:59:54 -04004395 void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
Alex Deucher812d0462010-07-26 18:51:53 -04004396 u32 tmp;
4397
4398 WREG32(HDP_DEBUG1, 0);
4399 tmp = readl((void __iomem *)ptr);
4400 } else
4401 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
Jerome Glisse062b3892010-02-04 20:36:39 +01004402}
Alex Deucher3313e3d2011-01-06 18:49:34 -05004403
4404void r600_set_pcie_lanes(struct radeon_device *rdev, int lanes)
4405{
Alex Deucherd5445a12013-03-18 18:52:13 -04004406 u32 link_width_cntl, mask;
Alex Deucher3313e3d2011-01-06 18:49:34 -05004407
4408 if (rdev->flags & RADEON_IS_IGP)
4409 return;
4410
4411 if (!(rdev->flags & RADEON_IS_PCIE))
4412 return;
4413
4414 /* x2 cards have a special sequence */
4415 if (ASIC_IS_X2(rdev))
4416 return;
4417
Alex Deucherd5445a12013-03-18 18:52:13 -04004418 radeon_gui_idle(rdev);
Alex Deucher3313e3d2011-01-06 18:49:34 -05004419
4420 switch (lanes) {
4421 case 0:
4422 mask = RADEON_PCIE_LC_LINK_WIDTH_X0;
4423 break;
4424 case 1:
4425 mask = RADEON_PCIE_LC_LINK_WIDTH_X1;
4426 break;
4427 case 2:
4428 mask = RADEON_PCIE_LC_LINK_WIDTH_X2;
4429 break;
4430 case 4:
4431 mask = RADEON_PCIE_LC_LINK_WIDTH_X4;
4432 break;
4433 case 8:
4434 mask = RADEON_PCIE_LC_LINK_WIDTH_X8;
4435 break;
4436 case 12:
Alex Deucherd5445a12013-03-18 18:52:13 -04004437 /* not actually supported */
Alex Deucher3313e3d2011-01-06 18:49:34 -05004438 mask = RADEON_PCIE_LC_LINK_WIDTH_X12;
4439 break;
4440 case 16:
Alex Deucher3313e3d2011-01-06 18:49:34 -05004441 mask = RADEON_PCIE_LC_LINK_WIDTH_X16;
4442 break;
Alex Deucherd5445a12013-03-18 18:52:13 -04004443 default:
4444 DRM_ERROR("invalid pcie lane request: %d\n", lanes);
4445 return;
Alex Deucher3313e3d2011-01-06 18:49:34 -05004446 }
4447
Alex Deucher492d2b62012-10-25 16:06:59 -04004448 link_width_cntl = RREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
Alex Deucherd5445a12013-03-18 18:52:13 -04004449 link_width_cntl &= ~RADEON_PCIE_LC_LINK_WIDTH_MASK;
4450 link_width_cntl |= mask << RADEON_PCIE_LC_LINK_WIDTH_SHIFT;
4451 link_width_cntl |= (RADEON_PCIE_LC_RECONFIG_NOW |
4452 R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE);
Alex Deucher3313e3d2011-01-06 18:49:34 -05004453
Alex Deucher492d2b62012-10-25 16:06:59 -04004454 WREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
Alex Deucher3313e3d2011-01-06 18:49:34 -05004455}
4456
4457int r600_get_pcie_lanes(struct radeon_device *rdev)
4458{
4459 u32 link_width_cntl;
4460
4461 if (rdev->flags & RADEON_IS_IGP)
4462 return 0;
4463
4464 if (!(rdev->flags & RADEON_IS_PCIE))
4465 return 0;
4466
4467 /* x2 cards have a special sequence */
4468 if (ASIC_IS_X2(rdev))
4469 return 0;
4470
Alex Deucherd5445a12013-03-18 18:52:13 -04004471 radeon_gui_idle(rdev);
Alex Deucher3313e3d2011-01-06 18:49:34 -05004472
Alex Deucher492d2b62012-10-25 16:06:59 -04004473 link_width_cntl = RREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
Alex Deucher3313e3d2011-01-06 18:49:34 -05004474
4475 switch ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) >> RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT) {
Alex Deucher3313e3d2011-01-06 18:49:34 -05004476 case RADEON_PCIE_LC_LINK_WIDTH_X1:
4477 return 1;
4478 case RADEON_PCIE_LC_LINK_WIDTH_X2:
4479 return 2;
4480 case RADEON_PCIE_LC_LINK_WIDTH_X4:
4481 return 4;
4482 case RADEON_PCIE_LC_LINK_WIDTH_X8:
4483 return 8;
Alex Deucherd5445a12013-03-18 18:52:13 -04004484 case RADEON_PCIE_LC_LINK_WIDTH_X12:
4485 /* not actually supported */
4486 return 12;
4487 case RADEON_PCIE_LC_LINK_WIDTH_X0:
Alex Deucher3313e3d2011-01-06 18:49:34 -05004488 case RADEON_PCIE_LC_LINK_WIDTH_X16:
4489 default:
4490 return 16;
4491 }
4492}
4493
Alex Deucher9e46a482011-01-06 18:49:35 -05004494static void r600_pcie_gen2_enable(struct radeon_device *rdev)
4495{
4496 u32 link_width_cntl, lanes, speed_cntl, training_cntl, tmp;
4497 u16 link_cntl2;
4498
Alex Deucherd42dd572011-01-12 20:05:11 -05004499 if (radeon_pcie_gen2 == 0)
4500 return;
4501
Alex Deucher9e46a482011-01-06 18:49:35 -05004502 if (rdev->flags & RADEON_IS_IGP)
4503 return;
4504
4505 if (!(rdev->flags & RADEON_IS_PCIE))
4506 return;
4507
4508 /* x2 cards have a special sequence */
4509 if (ASIC_IS_X2(rdev))
4510 return;
4511
4512 /* only RV6xx+ chips are supported */
4513 if (rdev->family <= CHIP_R600)
4514 return;
4515
Kleber Sacilotto de Souza7e0e4192013-05-03 19:43:13 -03004516 if ((rdev->pdev->bus->max_bus_speed != PCIE_SPEED_5_0GT) &&
4517 (rdev->pdev->bus->max_bus_speed != PCIE_SPEED_8_0GT))
Dave Airlie197bbb32012-06-27 08:35:54 +01004518 return;
4519
Alex Deucher492d2b62012-10-25 16:06:59 -04004520 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
Alex Deucher3691fee2012-10-08 17:46:27 -04004521 if (speed_cntl & LC_CURRENT_DATA_RATE) {
4522 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
4523 return;
4524 }
4525
Dave Airlie197bbb32012-06-27 08:35:54 +01004526 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
4527
Alex Deucher9e46a482011-01-06 18:49:35 -05004528 /* 55 nm r6xx asics */
4529 if ((rdev->family == CHIP_RV670) ||
4530 (rdev->family == CHIP_RV620) ||
4531 (rdev->family == CHIP_RV635)) {
4532 /* advertise upconfig capability */
Alex Deucher492d2b62012-10-25 16:06:59 -04004533 link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05004534 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
Alex Deucher492d2b62012-10-25 16:06:59 -04004535 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
4536 link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05004537 if (link_width_cntl & LC_RENEGOTIATION_SUPPORT) {
4538 lanes = (link_width_cntl & LC_LINK_WIDTH_RD_MASK) >> LC_LINK_WIDTH_RD_SHIFT;
4539 link_width_cntl &= ~(LC_LINK_WIDTH_MASK |
4540 LC_RECONFIG_ARC_MISSING_ESCAPE);
4541 link_width_cntl |= lanes | LC_RECONFIG_NOW | LC_RENEGOTIATE_EN;
Alex Deucher492d2b62012-10-25 16:06:59 -04004542 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05004543 } else {
4544 link_width_cntl |= LC_UPCONFIGURE_DIS;
Alex Deucher492d2b62012-10-25 16:06:59 -04004545 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05004546 }
4547 }
4548
Alex Deucher492d2b62012-10-25 16:06:59 -04004549 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05004550 if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
4551 (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
4552
4553 /* 55 nm r6xx asics */
4554 if ((rdev->family == CHIP_RV670) ||
4555 (rdev->family == CHIP_RV620) ||
4556 (rdev->family == CHIP_RV635)) {
4557 WREG32(MM_CFGREGS_CNTL, 0x8);
4558 link_cntl2 = RREG32(0x4088);
4559 WREG32(MM_CFGREGS_CNTL, 0);
4560 /* not supported yet */
4561 if (link_cntl2 & SELECTABLE_DEEMPHASIS)
4562 return;
4563 }
4564
4565 speed_cntl &= ~LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_MASK;
4566 speed_cntl |= (0x3 << LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_SHIFT);
4567 speed_cntl &= ~LC_VOLTAGE_TIMER_SEL_MASK;
4568 speed_cntl &= ~LC_FORCE_DIS_HW_SPEED_CHANGE;
4569 speed_cntl |= LC_FORCE_EN_HW_SPEED_CHANGE;
Alex Deucher492d2b62012-10-25 16:06:59 -04004570 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05004571
4572 tmp = RREG32(0x541c);
4573 WREG32(0x541c, tmp | 0x8);
4574 WREG32(MM_CFGREGS_CNTL, MM_WR_TO_CFG_EN);
4575 link_cntl2 = RREG16(0x4088);
4576 link_cntl2 &= ~TARGET_LINK_SPEED_MASK;
4577 link_cntl2 |= 0x2;
4578 WREG16(0x4088, link_cntl2);
4579 WREG32(MM_CFGREGS_CNTL, 0);
4580
4581 if ((rdev->family == CHIP_RV670) ||
4582 (rdev->family == CHIP_RV620) ||
4583 (rdev->family == CHIP_RV635)) {
Alex Deucher492d2b62012-10-25 16:06:59 -04004584 training_cntl = RREG32_PCIE_PORT(PCIE_LC_TRAINING_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05004585 training_cntl &= ~LC_POINT_7_PLUS_EN;
Alex Deucher492d2b62012-10-25 16:06:59 -04004586 WREG32_PCIE_PORT(PCIE_LC_TRAINING_CNTL, training_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05004587 } else {
Alex Deucher492d2b62012-10-25 16:06:59 -04004588 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05004589 speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
Alex Deucher492d2b62012-10-25 16:06:59 -04004590 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05004591 }
4592
Alex Deucher492d2b62012-10-25 16:06:59 -04004593 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05004594 speed_cntl |= LC_GEN2_EN_STRAP;
Alex Deucher492d2b62012-10-25 16:06:59 -04004595 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05004596
4597 } else {
Alex Deucher492d2b62012-10-25 16:06:59 -04004598 link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
Alex Deucher9e46a482011-01-06 18:49:35 -05004599 /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
4600 if (1)
4601 link_width_cntl |= LC_UPCONFIGURE_DIS;
4602 else
4603 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
Alex Deucher492d2b62012-10-25 16:06:59 -04004604 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
Alex Deucher9e46a482011-01-06 18:49:35 -05004605 }
4606}
Marek Olšák6759a0a2012-08-09 16:34:17 +02004607
4608/**
Alex Deucherd0418892013-01-24 10:35:23 -05004609 * r600_get_gpu_clock_counter - return GPU clock counter snapshot
Marek Olšák6759a0a2012-08-09 16:34:17 +02004610 *
4611 * @rdev: radeon_device pointer
4612 *
4613 * Fetches a GPU clock counter snapshot (R6xx-cayman).
4614 * Returns the 64 bit clock counter snapshot.
4615 */
Alex Deucherd0418892013-01-24 10:35:23 -05004616uint64_t r600_get_gpu_clock_counter(struct radeon_device *rdev)
Marek Olšák6759a0a2012-08-09 16:34:17 +02004617{
4618 uint64_t clock;
4619
4620 mutex_lock(&rdev->gpu_clock_mutex);
4621 WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
4622 clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
Jérome Glisse3cf8bb12016-03-16 12:56:45 +01004623 ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
Marek Olšák6759a0a2012-08-09 16:34:17 +02004624 mutex_unlock(&rdev->gpu_clock_mutex);
4625 return clock;
4626}