2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
24 * Authors: Dave Airlie
28 #include <linux/slab.h>
29 #include <linux/seq_file.h>
30 #include <linux/firmware.h>
31 #include <linux/module.h>
33 #include <drm/radeon_drm.h>
35 #include "radeon_asic.h"
36 #include "radeon_audio.h"
37 #include "radeon_mode.h"
41 #include "radeon_ucode.h"
44 MODULE_FIRMWARE("radeon/R600_pfp.bin");
45 MODULE_FIRMWARE("radeon/R600_me.bin");
46 MODULE_FIRMWARE("radeon/RV610_pfp.bin");
47 MODULE_FIRMWARE("radeon/RV610_me.bin");
48 MODULE_FIRMWARE("radeon/RV630_pfp.bin");
49 MODULE_FIRMWARE("radeon/RV630_me.bin");
50 MODULE_FIRMWARE("radeon/RV620_pfp.bin");
51 MODULE_FIRMWARE("radeon/RV620_me.bin");
52 MODULE_FIRMWARE("radeon/RV635_pfp.bin");
53 MODULE_FIRMWARE("radeon/RV635_me.bin");
54 MODULE_FIRMWARE("radeon/RV670_pfp.bin");
55 MODULE_FIRMWARE("radeon/RV670_me.bin");
56 MODULE_FIRMWARE("radeon/RS780_pfp.bin");
57 MODULE_FIRMWARE("radeon/RS780_me.bin");
58 MODULE_FIRMWARE("radeon/RV770_pfp.bin");
59 MODULE_FIRMWARE("radeon/RV770_me.bin");
60 MODULE_FIRMWARE("radeon/RV770_smc.bin");
61 MODULE_FIRMWARE("radeon/RV730_pfp.bin");
62 MODULE_FIRMWARE("radeon/RV730_me.bin");
63 MODULE_FIRMWARE("radeon/RV730_smc.bin");
64 MODULE_FIRMWARE("radeon/RV740_smc.bin");
65 MODULE_FIRMWARE("radeon/RV710_pfp.bin");
66 MODULE_FIRMWARE("radeon/RV710_me.bin");
67 MODULE_FIRMWARE("radeon/RV710_smc.bin");
68 MODULE_FIRMWARE("radeon/R600_rlc.bin");
69 MODULE_FIRMWARE("radeon/R700_rlc.bin");
70 MODULE_FIRMWARE("radeon/CEDAR_pfp.bin");
71 MODULE_FIRMWARE("radeon/CEDAR_me.bin");
72 MODULE_FIRMWARE("radeon/CEDAR_rlc.bin");
73 MODULE_FIRMWARE("radeon/CEDAR_smc.bin");
74 MODULE_FIRMWARE("radeon/REDWOOD_pfp.bin");
75 MODULE_FIRMWARE("radeon/REDWOOD_me.bin");
76 MODULE_FIRMWARE("radeon/REDWOOD_rlc.bin");
77 MODULE_FIRMWARE("radeon/REDWOOD_smc.bin");
78 MODULE_FIRMWARE("radeon/JUNIPER_pfp.bin");
79 MODULE_FIRMWARE("radeon/JUNIPER_me.bin");
80 MODULE_FIRMWARE("radeon/JUNIPER_rlc.bin");
81 MODULE_FIRMWARE("radeon/JUNIPER_smc.bin");
82 MODULE_FIRMWARE("radeon/CYPRESS_pfp.bin");
83 MODULE_FIRMWARE("radeon/CYPRESS_me.bin");
84 MODULE_FIRMWARE("radeon/CYPRESS_rlc.bin");
85 MODULE_FIRMWARE("radeon/CYPRESS_smc.bin");
86 MODULE_FIRMWARE("radeon/PALM_pfp.bin");
87 MODULE_FIRMWARE("radeon/PALM_me.bin");
88 MODULE_FIRMWARE("radeon/SUMO_rlc.bin");
89 MODULE_FIRMWARE("radeon/SUMO_pfp.bin");
90 MODULE_FIRMWARE("radeon/SUMO_me.bin");
91 MODULE_FIRMWARE("radeon/SUMO2_pfp.bin");
92 MODULE_FIRMWARE("radeon/SUMO2_me.bin");
94 static const u32 crtc_offsets
[2] =
97 AVIVO_D2CRTC_H_TOTAL
- AVIVO_D1CRTC_H_TOTAL
100 int r600_debugfs_mc_info_init(struct radeon_device
*rdev
);
102 /* r600,rv610,rv630,rv620,rv635,rv670 */
103 int r600_mc_wait_for_idle(struct radeon_device
*rdev
);
104 static void r600_gpu_init(struct radeon_device
*rdev
);
105 void r600_fini(struct radeon_device
*rdev
);
106 void r600_irq_disable(struct radeon_device
*rdev
);
107 static void r600_pcie_gen2_enable(struct radeon_device
*rdev
);
108 extern int evergreen_rlc_resume(struct radeon_device
*rdev
);
109 extern void rv770_set_clk_bypass_mode(struct radeon_device
*rdev
);
112 * Indirect registers accessor
114 u32
r600_rcu_rreg(struct radeon_device
*rdev
, u32 reg
)
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
);
126 void r600_rcu_wreg(struct radeon_device
*rdev
, u32 reg
, u32 v
)
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
);
136 u32
r600_uvd_ctx_rreg(struct radeon_device
*rdev
, u32 reg
)
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
);
148 void r600_uvd_ctx_wreg(struct radeon_device
*rdev
, u32 reg
, u32 v
)
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
);
159 * r600_get_allowed_info_register - fetch the register for the info ioctl
161 * @rdev: radeon_device pointer
162 * @reg: register offset in bytes
163 * @val: register value
165 * Returns 0 for success or -EINVAL for an invalid register
168 int r600_get_allowed_info_register(struct radeon_device
*rdev
,
174 case R_000E50_SRBM_STATUS
:
185 * r600_get_xclk - get the xclk
187 * @rdev: radeon_device pointer
189 * Returns the reference clock used by the gfx engine
190 * (r6xx, IGPs, APUs).
192 u32
r600_get_xclk(struct radeon_device
*rdev
)
194 return rdev
->clock
.spll
.reference_freq
;
197 int r600_set_uvd_clocks(struct radeon_device
*rdev
, u32 vclk
, u32 dclk
)
199 unsigned fb_div
= 0, ref_div
, vclk_div
= 0, dclk_div
= 0;
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
));
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
));
211 if (rdev
->family
>= CHIP_RS780
)
212 WREG32_P(GFX_MACRO_BYPASS_CNTL
, UPLL_BYPASS_CNTL
,
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
);
221 if (rdev
->clock
.spll
.reference_freq
== 10000)
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
);
232 if (rdev
->family
>= CHIP_RV670
&& rdev
->family
< CHIP_RS780
)
237 r
= radeon_uvd_send_upll_ctlreq(rdev
, CG_UPLL_FUNC_CNTL
);
241 /* assert PLL_RESET */
242 WREG32_P(CG_UPLL_FUNC_CNTL
, UPLL_RESET_MASK
, ~UPLL_RESET_MASK
);
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
);
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
,
262 /* give the PLL some time to settle */
265 /* deassert PLL_RESET */
266 WREG32_P(CG_UPLL_FUNC_CNTL
, 0, ~UPLL_RESET_MASK
);
270 /* deassert BYPASS EN */
271 WREG32_P(CG_UPLL_FUNC_CNTL
, 0, ~UPLL_BYPASS_EN_MASK
);
273 if (rdev
->family
>= CHIP_RS780
)
274 WREG32_P(GFX_MACRO_BYPASS_CNTL
, 0, ~UPLL_BYPASS_CNTL
);
276 r
= radeon_uvd_send_upll_ctlreq(rdev
, CG_UPLL_FUNC_CNTL
);
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
));
290 void dce3_program_fmt(struct drm_encoder
*encoder
)
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
);
299 enum radeon_connector_dither dither
= RADEON_FMT_DITHER_DISABLE
;
302 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
303 bpc
= radeon_get_monitor_bpc(connector
);
304 dither
= radeon_connector
->dither
;
307 /* LVDS FMT is set up by atom */
308 if (radeon_encoder
->devices
& ATOM_DEVICE_LCD_SUPPORT
)
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
))
321 if (dither
== RADEON_FMT_DITHER_ENABLE
)
322 /* XXX sort out optimal dither settings */
323 tmp
|= FMT_SPATIAL_DITHER_EN
;
325 tmp
|= FMT_TRUNCATE_EN
;
328 if (dither
== RADEON_FMT_DITHER_ENABLE
)
329 /* XXX sort out optimal dither settings */
330 tmp
|= (FMT_SPATIAL_DITHER_EN
| FMT_SPATIAL_DITHER_DEPTH
);
332 tmp
|= (FMT_TRUNCATE_EN
| FMT_TRUNCATE_DEPTH
);
340 WREG32(FMT_BIT_DEPTH_CONTROL
+ radeon_crtc
->crtc_offset
, tmp
);
343 /* get temperature in millidegrees */
344 int rv6xx_get_temp(struct radeon_device
*rdev
)
346 u32 temp
= (RREG32(CG_THERMAL_STATUS
) & ASIC_T_MASK
) >>
348 int actual_temp
= temp
& 0xff;
353 return actual_temp
* 1000;
356 void r600_pm_get_dynpm_state(struct radeon_device
*rdev
)
360 rdev
->pm
.dynpm_can_upclock
= true;
361 rdev
->pm
.dynpm_can_downclock
= true;
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;
367 if (rdev
->pm
.num_power_states
> 2)
368 min_power_state_index
= 1;
370 switch (rdev
->pm
.dynpm_planned_action
) {
371 case DYNPM_ACTION_MINIMUM
:
372 rdev
->pm
.requested_power_state_index
= min_power_state_index
;
373 rdev
->pm
.requested_clock_mode_index
= 0;
374 rdev
->pm
.dynpm_can_downclock
= false;
376 case DYNPM_ACTION_DOWNCLOCK
:
377 if (rdev
->pm
.current_power_state_index
== min_power_state_index
) {
378 rdev
->pm
.requested_power_state_index
= rdev
->pm
.current_power_state_index
;
379 rdev
->pm
.dynpm_can_downclock
= false;
381 if (rdev
->pm
.active_crtc_count
> 1) {
382 for (i
= 0; i
< rdev
->pm
.num_power_states
; i
++) {
383 if (rdev
->pm
.power_state
[i
].flags
& RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
)
385 else if (i
>= rdev
->pm
.current_power_state_index
) {
386 rdev
->pm
.requested_power_state_index
=
387 rdev
->pm
.current_power_state_index
;
390 rdev
->pm
.requested_power_state_index
= i
;
395 if (rdev
->pm
.current_power_state_index
== 0)
396 rdev
->pm
.requested_power_state_index
=
397 rdev
->pm
.num_power_states
- 1;
399 rdev
->pm
.requested_power_state_index
=
400 rdev
->pm
.current_power_state_index
- 1;
403 rdev
->pm
.requested_clock_mode_index
= 0;
404 /* 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
++;
412 case DYNPM_ACTION_UPCLOCK
:
413 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
;
415 rdev
->pm
.dynpm_can_upclock
= false;
417 if (rdev
->pm
.active_crtc_count
> 1) {
418 for (i
= (rdev
->pm
.num_power_states
- 1); i
>= 0; i
--) {
419 if (rdev
->pm
.power_state
[i
].flags
& RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
)
421 else if (i
<= rdev
->pm
.current_power_state_index
) {
422 rdev
->pm
.requested_power_state_index
=
423 rdev
->pm
.current_power_state_index
;
426 rdev
->pm
.requested_power_state_index
= i
;
431 rdev
->pm
.requested_power_state_index
=
432 rdev
->pm
.current_power_state_index
+ 1;
434 rdev
->pm
.requested_clock_mode_index
= 0;
436 case DYNPM_ACTION_DEFAULT
:
437 rdev
->pm
.requested_power_state_index
= rdev
->pm
.default_power_state_index
;
438 rdev
->pm
.requested_clock_mode_index
= 0;
439 rdev
->pm
.dynpm_can_upclock
= false;
441 case DYNPM_ACTION_NONE
:
443 DRM_ERROR("Requested mode for not defined action\n");
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
++) {
454 if (rdev
->pm
.power_state
[i
].flags
& RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
)
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
;
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;
466 rdev
->pm
.requested_power_state_index
= 1;
468 switch (rdev
->pm
.dynpm_planned_action
) {
469 case DYNPM_ACTION_MINIMUM
:
470 rdev
->pm
.requested_clock_mode_index
= 0;
471 rdev
->pm
.dynpm_can_downclock
= false;
473 case DYNPM_ACTION_DOWNCLOCK
:
474 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;
477 rdev
->pm
.dynpm_can_downclock
= false;
479 rdev
->pm
.requested_clock_mode_index
=
480 rdev
->pm
.current_clock_mode_index
- 1;
482 rdev
->pm
.requested_clock_mode_index
= 0;
483 rdev
->pm
.dynpm_can_downclock
= false;
485 /* 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
++;
493 case DYNPM_ACTION_UPCLOCK
:
494 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
;
498 rdev
->pm
.dynpm_can_upclock
= false;
500 rdev
->pm
.requested_clock_mode_index
=
501 rdev
->pm
.current_clock_mode_index
+ 1;
503 rdev
->pm
.requested_clock_mode_index
=
504 rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].num_clock_modes
- 1;
505 rdev
->pm
.dynpm_can_upclock
= false;
508 case DYNPM_ACTION_DEFAULT
:
509 rdev
->pm
.requested_power_state_index
= rdev
->pm
.default_power_state_index
;
510 rdev
->pm
.requested_clock_mode_index
= 0;
511 rdev
->pm
.dynpm_can_upclock
= false;
513 case DYNPM_ACTION_NONE
:
515 DRM_ERROR("Requested mode for not defined action\n");
520 DRM_DEBUG_DRIVER("Requested: e: %d m: %d p: %d\n",
521 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
].
529 void rs780_pm_init_profile(struct radeon_device
*rdev
)
531 if (rdev
->pm
.num_power_states
== 2) {
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;
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;
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;
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;
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;
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;
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) {
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
642 void r600_pm_init_profile(struct radeon_device
*rdev
)
646 if (rdev
->family
== CHIP_R600
) {
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;
652 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_cm_idx
= 0;
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;
657 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_cm_idx
= 0;
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;
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;
667 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_cm_idx
= 0;
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;
672 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_cm_idx
= 0;
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;
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;
682 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_cm_idx
= 0;
684 if (rdev
->pm
.num_power_states
< 4) {
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;
691 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;
694 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_cm_idx
= 0;
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;
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;
706 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;
708 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_cm_idx
= 0;
709 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_cm_idx
= 0;
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;
716 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;
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;
727 if (rdev
->flags
& RADEON_IS_MOBILITY
)
728 idx
= radeon_pm_get_type_index(rdev
, POWER_STATE_TYPE_BATTERY
, 0);
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;
736 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;
741 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
;
744 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;
747 if (rdev
->flags
& RADEON_IS_MOBILITY
)
748 idx
= radeon_pm_get_type_index(rdev
, POWER_STATE_TYPE_BATTERY
, 1);
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;
756 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;
761 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
;
764 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;
770 void r600_pm_misc(struct radeon_device
*rdev
)
772 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
;
777 if ((voltage
->type
== VOLTAGE_SW
) && voltage
->voltage
) {
778 /* 0xff01 is a flag rather then an actual voltage */
779 if (voltage
->voltage
== 0xff01)
781 if (voltage
->voltage
!= rdev
->pm
.current_vddc
) {
782 radeon_atom_set_voltage(rdev
, voltage
->voltage
, SET_VOLTAGE_TYPE_ASIC_VDDC
);
783 rdev
->pm
.current_vddc
= voltage
->voltage
;
784 DRM_DEBUG_DRIVER("Setting: v: %d\n", voltage
->voltage
);
789 bool r600_gui_idle(struct radeon_device
*rdev
)
791 if (RREG32(GRBM_STATUS
) & GUI_ACTIVE
)
797 /* hpd for digital panel detect/disconnect */
798 bool r600_hpd_sense(struct radeon_device
*rdev
, enum radeon_hpd_id hpd
)
800 bool connected
= false;
802 if (ASIC_IS_DCE3(rdev
)) {
805 if (RREG32(DC_HPD1_INT_STATUS
) & DC_HPDx_SENSE
)
809 if (RREG32(DC_HPD2_INT_STATUS
) & DC_HPDx_SENSE
)
813 if (RREG32(DC_HPD3_INT_STATUS
) & DC_HPDx_SENSE
)
817 if (RREG32(DC_HPD4_INT_STATUS
) & DC_HPDx_SENSE
)
822 if (RREG32(DC_HPD5_INT_STATUS
) & DC_HPDx_SENSE
)
826 if (RREG32(DC_HPD6_INT_STATUS
) & DC_HPDx_SENSE
)
835 if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS
) & DC_HOT_PLUG_DETECTx_SENSE
)
839 if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS
) & DC_HOT_PLUG_DETECTx_SENSE
)
843 if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS
) & DC_HOT_PLUG_DETECTx_SENSE
)
853 void r600_hpd_set_polarity(struct radeon_device
*rdev
,
854 enum radeon_hpd_id hpd
)
857 bool connected
= r600_hpd_sense(rdev
, hpd
);
859 if (ASIC_IS_DCE3(rdev
)) {
862 tmp
= RREG32(DC_HPD1_INT_CONTROL
);
864 tmp
&= ~DC_HPDx_INT_POLARITY
;
866 tmp
|= DC_HPDx_INT_POLARITY
;
867 WREG32(DC_HPD1_INT_CONTROL
, tmp
);
870 tmp
= RREG32(DC_HPD2_INT_CONTROL
);
872 tmp
&= ~DC_HPDx_INT_POLARITY
;
874 tmp
|= DC_HPDx_INT_POLARITY
;
875 WREG32(DC_HPD2_INT_CONTROL
, tmp
);
878 tmp
= RREG32(DC_HPD3_INT_CONTROL
);
880 tmp
&= ~DC_HPDx_INT_POLARITY
;
882 tmp
|= DC_HPDx_INT_POLARITY
;
883 WREG32(DC_HPD3_INT_CONTROL
, tmp
);
886 tmp
= RREG32(DC_HPD4_INT_CONTROL
);
888 tmp
&= ~DC_HPDx_INT_POLARITY
;
890 tmp
|= DC_HPDx_INT_POLARITY
;
891 WREG32(DC_HPD4_INT_CONTROL
, tmp
);
894 tmp
= RREG32(DC_HPD5_INT_CONTROL
);
896 tmp
&= ~DC_HPDx_INT_POLARITY
;
898 tmp
|= DC_HPDx_INT_POLARITY
;
899 WREG32(DC_HPD5_INT_CONTROL
, tmp
);
903 tmp
= RREG32(DC_HPD6_INT_CONTROL
);
905 tmp
&= ~DC_HPDx_INT_POLARITY
;
907 tmp
|= DC_HPDx_INT_POLARITY
;
908 WREG32(DC_HPD6_INT_CONTROL
, tmp
);
916 tmp
= RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
);
918 tmp
&= ~DC_HOT_PLUG_DETECTx_INT_POLARITY
;
920 tmp
|= DC_HOT_PLUG_DETECTx_INT_POLARITY
;
921 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
, tmp
);
924 tmp
= RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
);
926 tmp
&= ~DC_HOT_PLUG_DETECTx_INT_POLARITY
;
928 tmp
|= DC_HOT_PLUG_DETECTx_INT_POLARITY
;
929 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
, tmp
);
932 tmp
= RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
);
934 tmp
&= ~DC_HOT_PLUG_DETECTx_INT_POLARITY
;
936 tmp
|= DC_HOT_PLUG_DETECTx_INT_POLARITY
;
937 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
, tmp
);
945 void r600_hpd_init(struct radeon_device
*rdev
)
947 struct drm_device
*dev
= rdev
->ddev
;
948 struct drm_connector
*connector
;
951 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
952 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
954 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
962 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
))
967 switch (radeon_connector
->hpd
.hpd
) {
969 WREG32(DC_HPD1_CONTROL
, tmp
);
972 WREG32(DC_HPD2_CONTROL
, tmp
);
975 WREG32(DC_HPD3_CONTROL
, tmp
);
978 WREG32(DC_HPD4_CONTROL
, tmp
);
982 WREG32(DC_HPD5_CONTROL
, tmp
);
985 WREG32(DC_HPD6_CONTROL
, tmp
);
991 switch (radeon_connector
->hpd
.hpd
) {
993 WREG32(DC_HOT_PLUG_DETECT1_CONTROL
, DC_HOT_PLUG_DETECTx_EN
);
996 WREG32(DC_HOT_PLUG_DETECT2_CONTROL
, DC_HOT_PLUG_DETECTx_EN
);
999 WREG32(DC_HOT_PLUG_DETECT3_CONTROL
, DC_HOT_PLUG_DETECTx_EN
);
1005 enable
|= 1 << radeon_connector
->hpd
.hpd
;
1006 radeon_hpd_set_polarity(rdev
, radeon_connector
->hpd
.hpd
);
1008 radeon_irq_kms_enable_hpd(rdev
, enable
);
1011 void r600_hpd_fini(struct radeon_device
*rdev
)
1013 struct drm_device
*dev
= rdev
->ddev
;
1014 struct drm_connector
*connector
;
1015 unsigned disable
= 0;
1017 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
)) {
1020 switch (radeon_connector
->hpd
.hpd
) {
1022 WREG32(DC_HPD1_CONTROL
, 0);
1025 WREG32(DC_HPD2_CONTROL
, 0);
1028 WREG32(DC_HPD3_CONTROL
, 0);
1031 WREG32(DC_HPD4_CONTROL
, 0);
1035 WREG32(DC_HPD5_CONTROL
, 0);
1038 WREG32(DC_HPD6_CONTROL
, 0);
1044 switch (radeon_connector
->hpd
.hpd
) {
1046 WREG32(DC_HOT_PLUG_DETECT1_CONTROL
, 0);
1049 WREG32(DC_HOT_PLUG_DETECT2_CONTROL
, 0);
1052 WREG32(DC_HOT_PLUG_DETECT3_CONTROL
, 0);
1058 disable
|= 1 << radeon_connector
->hpd
.hpd
;
1060 radeon_irq_kms_disable_hpd(rdev
, disable
);
1066 void r600_pcie_gart_tlb_flush(struct radeon_device
*rdev
)
1071 /* flush hdp cache so updates hit vram */
1072 if ((rdev
->family
>= CHIP_RV770
) && (rdev
->family
<= CHIP_RV740
) &&
1073 !(rdev
->flags
& RADEON_IS_AGP
)) {
1074 void __iomem
*ptr
= (void *)rdev
->gart
.ptr
;
1077 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
1078 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL
1079 * This seems to cause problems on some AGP cards. Just use the old
1082 WREG32(HDP_DEBUG1
, 0);
1083 tmp
= readl((void __iomem
*)ptr
);
1085 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL
, 0x1);
1087 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
;
1095 printk(KERN_WARNING
"[drm] r600 flush TLB failed\n");
1105 int r600_pcie_gart_init(struct radeon_device
*rdev
)
1109 if (rdev
->gart
.robj
) {
1110 WARN(1, "R600 PCIE GART already initialized\n");
1113 /* Initialize common gart structure */
1114 r
= radeon_gart_init(rdev
);
1117 rdev
->gart
.table_size
= rdev
->gart
.num_gpu_pages
* 8;
1118 return radeon_gart_table_vram_alloc(rdev
);
1121 static int r600_pcie_gart_enable(struct radeon_device
*rdev
)
1126 if (rdev
->gart
.robj
== NULL
) {
1127 dev_err(rdev
->dev
, "No VRAM object for PCIE GART.\n");
1130 r
= radeon_gart_table_vram_pin(rdev
);
1134 /* 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
);
1157 WREG32(MC_VM_L1_TLB_MCB_RD_UVD_CNTL
, tmp
);
1158 WREG32(MC_VM_L1_TLB_MCB_WR_UVD_CNTL
, tmp
);
1159 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);
1162 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR
, rdev
->mc
.gtt_end
>> 12);
1163 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);
1171 r600_pcie_gart_tlb_flush(rdev
);
1172 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
);
1175 rdev
->gart
.ready
= true;
1179 static void r600_pcie_gart_disable(struct radeon_device
*rdev
)
1184 /* Disable all tables */
1185 for (i
= 0; i
< 7; i
++)
1186 WREG32(VM_CONTEXT0_CNTL
+ (i
* 4), 0);
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
);
1209 WREG32(MC_VM_L1_TLB_MCB_RD_UVD_CNTL
, tmp
);
1210 WREG32(MC_VM_L1_TLB_MCB_WR_UVD_CNTL
, tmp
);
1211 radeon_gart_table_vram_unpin(rdev
);
1214 static void r600_pcie_gart_fini(struct radeon_device
*rdev
)
1216 radeon_gart_fini(rdev
);
1217 r600_pcie_gart_disable(rdev
);
1218 radeon_gart_table_vram_free(rdev
);
1221 static void r600_agp_enable(struct radeon_device
*rdev
)
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);
1255 int r600_mc_wait_for_idle(struct radeon_device
*rdev
)
1260 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
1261 /* read MC_STATUS */
1262 tmp
= RREG32(R_000E50_SRBM_STATUS
) & 0x3F00;
1270 uint32_t rs780_mc_rreg(struct radeon_device
*rdev
, uint32_t reg
)
1272 unsigned long flags
;
1275 spin_lock_irqsave(&rdev
->mc_idx_lock
, flags
);
1276 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
);
1279 spin_unlock_irqrestore(&rdev
->mc_idx_lock
, flags
);
1283 void rs780_mc_wreg(struct radeon_device
*rdev
, uint32_t reg
, uint32_t v
)
1285 unsigned long flags
;
1287 spin_lock_irqsave(&rdev
->mc_idx_lock
, flags
);
1288 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);
1292 spin_unlock_irqrestore(&rdev
->mc_idx_lock
, flags
);
1295 static void r600_mc_program(struct radeon_device
*rdev
)
1297 struct rv515_mc_save save
;
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);
1309 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL
, 0);
1311 rv515_mc_stop(rdev
, &save
);
1312 if (r600_mc_wait_for_idle(rdev
)) {
1313 dev_warn(rdev
->dev
, "Wait for MC idle timedout !\n");
1315 /* Lockout access through VGA aperture (doesn't exist before R600) */
1316 WREG32(VGA_HDP_CONTROL
, VGA_MEMORY_DISABLE
);
1317 /* Update configuration */
1318 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);
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);
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);
1336 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR
, rdev
->vram_scratch
.gpu_addr
>> 12);
1337 tmp
= ((rdev
->mc
.vram_end
>> 24) & 0xFFFF) << 16;
1338 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));
1342 WREG32(HDP_NONSURFACE_SIZE
, 0x3FFFFFFF);
1343 if (rdev
->flags
& RADEON_IS_AGP
) {
1344 WREG32(MC_VM_AGP_TOP
, rdev
->mc
.gtt_end
>> 22);
1345 WREG32(MC_VM_AGP_BOT
, rdev
->mc
.gtt_start
>> 22);
1346 WREG32(MC_VM_AGP_BASE
, rdev
->mc
.agp_base
>> 22);
1348 WREG32(MC_VM_AGP_BASE
, 0);
1349 WREG32(MC_VM_AGP_TOP
, 0x0FFFFFFF);
1350 WREG32(MC_VM_AGP_BOT
, 0x0FFFFFFF);
1352 if (r600_mc_wait_for_idle(rdev
)) {
1353 dev_warn(rdev
->dev
, "Wait for MC idle timedout !\n");
1355 rv515_mc_resume(rdev
, &save
);
1356 /* we need to own VRAM, so turn off the VGA renderer here
1357 * to stop it overwriting our objects */
1358 rv515_vga_render_disable(rdev
);
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
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.
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.
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 ??).
1377 * This function will never fails, worst case are limiting VRAM or GTT.
1379 * Note: GTT start, end, size should be initialized before calling this
1380 * function on AGP platform.
1382 static void r600_vram_gtt_location(struct radeon_device
*rdev
, struct radeon_mc
*mc
)
1384 u64 size_bf
, size_af
;
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;
1392 if (rdev
->flags
& RADEON_IS_AGP
) {
1393 size_bf
= mc
->gtt_start
;
1394 size_af
= mc
->mc_mask
- mc
->gtt_end
;
1395 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
;
1401 mc
->vram_start
= mc
->gtt_start
- mc
->mc_vram_size
;
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
;
1408 mc
->vram_start
= mc
->gtt_end
+ 1;
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);
1416 if (rdev
->flags
& RADEON_IS_IGP
) {
1417 base
= RREG32(MC_VM_FB_LOCATION
) & 0xFFFF;
1420 radeon_vram_location(rdev
, &rdev
->mc
, base
);
1421 rdev
->mc
.gtt_base_align
= 0;
1422 radeon_gtt_location(rdev
, mc
);
1426 static int r600_mc_init(struct radeon_device
*rdev
)
1429 int chansize
, numchan
;
1430 uint32_t h_addr
, l_addr
;
1431 unsigned long long k8_addr
;
1433 /* Get VRAM informations */
1434 rdev
->mc
.vram_is_ddr
= true;
1435 tmp
= RREG32(RAMCFG
);
1436 if (tmp
& CHANSIZE_OVERRIDE
) {
1438 } else if (tmp
& CHANSIZE_MASK
) {
1443 tmp
= RREG32(CHMAP
);
1444 switch ((tmp
& NOOFCHAN_MASK
) >> NOOFCHAN_SHIFT
) {
1459 rdev
->mc
.vram_width
= numchan
* chansize
;
1460 /* Could aper size report 0 ? */
1461 rdev
->mc
.aper_base
= pci_resource_start(rdev
->pdev
, 0);
1462 rdev
->mc
.aper_size
= pci_resource_len(rdev
->pdev
, 0);
1463 /* Setup GPU memory space */
1464 rdev
->mc
.mc_vram_size
= RREG32(CONFIG_MEMSIZE
);
1465 rdev
->mc
.real_vram_size
= RREG32(CONFIG_MEMSIZE
);
1466 rdev
->mc
.visible_vram_size
= rdev
->mc
.aper_size
;
1467 r600_vram_gtt_location(rdev
, &rdev
->mc
);
1469 if (rdev
->flags
& RADEON_IS_IGP
) {
1470 rs690_pm_info(rdev
);
1471 rdev
->mc
.igp_sideport_enabled
= radeon_atombios_sideport_present(rdev
);
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
)
1483 /* FastFB shall be used with UMA memory. Here it is simply disabled when sideport
1484 * memory is present.
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;
1496 radeon_update_bandwidth_info(rdev
);
1500 int r600_vram_scratch_init(struct radeon_device
*rdev
)
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
,
1507 0, NULL
, NULL
, &rdev
->vram_scratch
.robj
);
1513 r
= radeon_bo_reserve(rdev
->vram_scratch
.robj
, false);
1514 if (unlikely(r
!= 0))
1516 r
= radeon_bo_pin(rdev
->vram_scratch
.robj
,
1517 RADEON_GEM_DOMAIN_VRAM
, &rdev
->vram_scratch
.gpu_addr
);
1519 radeon_bo_unreserve(rdev
->vram_scratch
.robj
);
1522 r
= radeon_bo_kmap(rdev
->vram_scratch
.robj
,
1523 (void **)&rdev
->vram_scratch
.ptr
);
1525 radeon_bo_unpin(rdev
->vram_scratch
.robj
);
1526 radeon_bo_unreserve(rdev
->vram_scratch
.robj
);
1531 void r600_vram_scratch_fini(struct radeon_device
*rdev
)
1535 if (rdev
->vram_scratch
.robj
== NULL
) {
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
);
1544 radeon_bo_unref(&rdev
->vram_scratch
.robj
);
1547 void r600_set_bios_scratch_engine_hung(struct radeon_device
*rdev
, bool hung
)
1549 u32 tmp
= RREG32(R600_BIOS_3_SCRATCH
);
1552 tmp
|= ATOM_S3_ASIC_GUI_ENGINE_HUNG
;
1554 tmp
&= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG
;
1556 WREG32(R600_BIOS_3_SCRATCH
, tmp
);
1559 static void r600_print_gpu_status_regs(struct radeon_device
*rdev
)
1561 dev_info(rdev
->dev
, " R_008010_GRBM_STATUS = 0x%08X\n",
1562 RREG32(R_008010_GRBM_STATUS
));
1563 dev_info(rdev
->dev
, " R_008014_GRBM_STATUS2 = 0x%08X\n",
1564 RREG32(R_008014_GRBM_STATUS2
));
1565 dev_info(rdev
->dev
, " R_000E50_SRBM_STATUS = 0x%08X\n",
1566 RREG32(R_000E50_SRBM_STATUS
));
1567 dev_info(rdev
->dev
, " R_008674_CP_STALLED_STAT1 = 0x%08X\n",
1568 RREG32(CP_STALLED_STAT1
));
1569 dev_info(rdev
->dev
, " R_008678_CP_STALLED_STAT2 = 0x%08X\n",
1570 RREG32(CP_STALLED_STAT2
));
1571 dev_info(rdev
->dev
, " R_00867C_CP_BUSY_STAT = 0x%08X\n",
1572 RREG32(CP_BUSY_STAT
));
1573 dev_info(rdev
->dev
, " R_008680_CP_STAT = 0x%08X\n",
1575 dev_info(rdev
->dev
, " R_00D034_DMA_STATUS_REG = 0x%08X\n",
1576 RREG32(DMA_STATUS_REG
));
1579 static bool r600_is_display_hung(struct radeon_device
*rdev
)
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
);
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
);
1608 u32
r600_gpu_check_soft_reset(struct radeon_device
*rdev
)
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
;
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
;
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
;
1635 if (G_008010_GRBM_EE_BUSY(tmp
))
1636 reset_mask
|= RADEON_RESET_GRBM
| RADEON_RESET_GFX
| RADEON_RESET_CP
;
1638 /* DMA_STATUS_REG */
1639 tmp
= RREG32(DMA_STATUS_REG
);
1640 if (!(tmp
& DMA_IDLE
))
1641 reset_mask
|= RADEON_RESET_DMA
;
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
;
1648 if (G_000E50_IH_BUSY(tmp
))
1649 reset_mask
|= RADEON_RESET_IH
;
1651 if (G_000E50_SEM_BUSY(tmp
))
1652 reset_mask
|= RADEON_RESET_SEM
;
1654 if (G_000E50_GRBM_RQ_PENDING(tmp
))
1655 reset_mask
|= RADEON_RESET_GRBM
;
1657 if (G_000E50_VMC_BUSY(tmp
))
1658 reset_mask
|= RADEON_RESET_VMC
;
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
;
1665 if (r600_is_display_hung(rdev
))
1666 reset_mask
|= RADEON_RESET_DISPLAY
;
1668 /* 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
;
1677 static void r600_gpu_soft_reset(struct radeon_device
*rdev
, u32 reset_mask
)
1679 struct rv515_mc_save save
;
1680 u32 grbm_soft_reset
= 0, srbm_soft_reset
= 0;
1683 if (reset_mask
== 0)
1686 dev_info(rdev
->dev
, "GPU softreset: 0x%08X\n", reset_mask
);
1688 r600_print_gpu_status_regs(rdev
);
1690 /* 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));
1694 WREG32(R_0086D8_CP_ME_CNTL
, S_0086D8_CP_ME_HALT(1));
1696 /* disable the RLC */
1697 WREG32(RLC_CNTL
, 0);
1699 if (reset_mask
& RADEON_RESET_DMA
) {
1701 tmp
= RREG32(DMA_RB_CNTL
);
1702 tmp
&= ~DMA_RB_ENABLE
;
1703 WREG32(DMA_RB_CNTL
, tmp
);
1708 rv515_mc_stop(rdev
, &save
);
1709 if (r600_mc_wait_for_idle(rdev
)) {
1710 dev_warn(rdev
->dev
, "Wait for MC idle timedout !\n");
1713 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);
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);
1742 if (reset_mask
& RADEON_RESET_CP
) {
1743 grbm_soft_reset
|= S_008020_SOFT_RESET_CP(1) |
1744 S_008020_SOFT_RESET_VGT(1);
1746 srbm_soft_reset
|= S_000E60_SOFT_RESET_GRBM(1);
1749 if (reset_mask
& RADEON_RESET_DMA
) {
1750 if (rdev
->family
>= CHIP_RV770
)
1751 srbm_soft_reset
|= RV770_SOFT_RESET_DMA
;
1753 srbm_soft_reset
|= SOFT_RESET_DMA
;
1756 if (reset_mask
& RADEON_RESET_RLC
)
1757 srbm_soft_reset
|= S_000E60_SOFT_RESET_RLC(1);
1759 if (reset_mask
& RADEON_RESET_SEM
)
1760 srbm_soft_reset
|= S_000E60_SOFT_RESET_SEM(1);
1762 if (reset_mask
& RADEON_RESET_IH
)
1763 srbm_soft_reset
|= S_000E60_SOFT_RESET_IH(1);
1765 if (reset_mask
& RADEON_RESET_GRBM
)
1766 srbm_soft_reset
|= S_000E60_SOFT_RESET_GRBM(1);
1768 if (!(rdev
->flags
& RADEON_IS_IGP
)) {
1769 if (reset_mask
& RADEON_RESET_MC
)
1770 srbm_soft_reset
|= S_000E60_SOFT_RESET_MC(1);
1773 if (reset_mask
& RADEON_RESET_VMC
)
1774 srbm_soft_reset
|= S_000E60_SOFT_RESET_VMC(1);
1776 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
);
1785 tmp
&= ~grbm_soft_reset
;
1786 WREG32(R_008020_GRBM_SOFT_RESET
, tmp
);
1787 tmp
= RREG32(R_008020_GRBM_SOFT_RESET
);
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
);
1799 tmp
&= ~srbm_soft_reset
;
1800 WREG32(SRBM_SOFT_RESET
, tmp
);
1801 tmp
= RREG32(SRBM_SOFT_RESET
);
1804 /* Wait a little for things to settle down */
1807 rv515_mc_resume(rdev
, &save
);
1810 r600_print_gpu_status_regs(rdev
);
1813 static void r600_gpu_pci_config_reset(struct radeon_device
*rdev
)
1815 struct rv515_mc_save save
;
1818 dev_info(rdev
->dev
, "GPU pci config reset\n");
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));
1826 WREG32(R_0086D8_CP_ME_CNTL
, S_0086D8_CP_ME_HALT(1));
1828 /* disable the RLC */
1829 WREG32(RLC_CNTL
, 0);
1832 tmp
= RREG32(DMA_RB_CNTL
);
1833 tmp
&= ~DMA_RB_ENABLE
;
1834 WREG32(DMA_RB_CNTL
, tmp
);
1838 /* set mclk/sclk to bypass */
1839 if (rdev
->family
>= CHIP_RV770
)
1840 rv770_set_clk_bypass_mode(rdev
);
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");
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
);
1854 tmp
= RREG32(BIF_SCRATCH0
);
1857 radeon_pci_config_reset(rdev
);
1860 /* BIF reset workaround. Not sure if this is needed on 6xx */
1861 tmp
= SOFT_RESET_BIF
;
1862 WREG32(SRBM_SOFT_RESET
, tmp
);
1864 WREG32(SRBM_SOFT_RESET
, 0);
1866 /* wait for asic to come out of reset */
1867 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
1868 if (RREG32(CONFIG_MEMSIZE
) != 0xffffffff)
1874 int r600_asic_reset(struct radeon_device
*rdev
)
1878 reset_mask
= r600_gpu_check_soft_reset(rdev
);
1881 r600_set_bios_scratch_engine_hung(rdev
, true);
1883 /* try soft reset */
1884 r600_gpu_soft_reset(rdev
, reset_mask
);
1886 reset_mask
= r600_gpu_check_soft_reset(rdev
);
1888 /* try pci config reset */
1889 if (reset_mask
&& radeon_hard_reset
)
1890 r600_gpu_pci_config_reset(rdev
);
1892 reset_mask
= r600_gpu_check_soft_reset(rdev
);
1895 r600_set_bios_scratch_engine_hung(rdev
, false);
1901 * r600_gfx_is_lockup - Check if the GFX engine is locked up
1903 * @rdev: radeon_device pointer
1904 * @ring: radeon_ring structure holding ring information
1906 * Check if the GFX engine is locked up.
1907 * Returns true if the engine appears to be locked up, false if not.
1909 bool r600_gfx_is_lockup(struct radeon_device
*rdev
, struct radeon_ring
*ring
)
1911 u32 reset_mask
= r600_gpu_check_soft_reset(rdev
);
1913 if (!(reset_mask
& (RADEON_RESET_GFX
|
1914 RADEON_RESET_COMPUTE
|
1915 RADEON_RESET_CP
))) {
1916 radeon_ring_lockup_update(rdev
, ring
);
1919 return radeon_ring_test_lockup(rdev
, ring
);
1922 u32
r6xx_remap_render_backend(struct radeon_device
*rdev
,
1923 u32 tiling_pipe_num
,
1925 u32 total_max_rb_num
,
1926 u32 disabled_rb_mask
)
1928 u32 rendering_pipe_num
, rb_num_width
, req_rb_num
;
1929 u32 pipe_rb_ratio
, pipe_rb_remain
, tmp
;
1930 u32 data
= 0, mask
= 1 << (max_rb_num
- 1);
1933 /* mask out the RBs that don't exist on that asic */
1934 tmp
= disabled_rb_mask
| ((0xff << max_rb_num
) & 0xff);
1935 /* make sure at least one RB is available */
1936 if ((tmp
& 0xff) != 0xff)
1937 disabled_rb_mask
= tmp
;
1939 rendering_pipe_num
= 1 << tiling_pipe_num
;
1940 req_rb_num
= total_max_rb_num
- r600_count_pipe_bits(disabled_rb_mask
);
1941 BUG_ON(rendering_pipe_num
< req_rb_num
);
1943 pipe_rb_ratio
= rendering_pipe_num
/ req_rb_num
;
1944 pipe_rb_remain
= rendering_pipe_num
- pipe_rb_ratio
* req_rb_num
;
1946 if (rdev
->family
<= CHIP_RV740
) {
1954 for (i
= 0; i
< max_rb_num
; i
++) {
1955 if (!(mask
& disabled_rb_mask
)) {
1956 for (j
= 0; j
< pipe_rb_ratio
; j
++) {
1957 data
<<= rb_num_width
;
1958 data
|= max_rb_num
- i
- 1;
1960 if (pipe_rb_remain
) {
1961 data
<<= rb_num_width
;
1962 data
|= max_rb_num
- i
- 1;
1972 int r600_count_pipe_bits(uint32_t val
)
1974 return hweight32(val
);
1977 static void r600_gpu_init(struct radeon_device
*rdev
)
1981 u32 cc_gc_shader_pipe_config
;
1985 u32 sq_gpr_resource_mgmt_1
= 0;
1986 u32 sq_gpr_resource_mgmt_2
= 0;
1987 u32 sq_thread_resource_mgmt
= 0;
1988 u32 sq_stack_resource_mgmt_1
= 0;
1989 u32 sq_stack_resource_mgmt_2
= 0;
1990 u32 disabled_rb_mask
;
1992 rdev
->config
.r600
.tiling_group_size
= 256;
1993 switch (rdev
->family
) {
1995 rdev
->config
.r600
.max_pipes
= 4;
1996 rdev
->config
.r600
.max_tile_pipes
= 8;
1997 rdev
->config
.r600
.max_simds
= 4;
1998 rdev
->config
.r600
.max_backends
= 4;
1999 rdev
->config
.r600
.max_gprs
= 256;
2000 rdev
->config
.r600
.max_threads
= 192;
2001 rdev
->config
.r600
.max_stack_entries
= 256;
2002 rdev
->config
.r600
.max_hw_contexts
= 8;
2003 rdev
->config
.r600
.max_gs_threads
= 16;
2004 rdev
->config
.r600
.sx_max_export_size
= 128;
2005 rdev
->config
.r600
.sx_max_export_pos_size
= 16;
2006 rdev
->config
.r600
.sx_max_export_smx_size
= 128;
2007 rdev
->config
.r600
.sq_num_cf_insts
= 2;
2011 rdev
->config
.r600
.max_pipes
= 2;
2012 rdev
->config
.r600
.max_tile_pipes
= 2;
2013 rdev
->config
.r600
.max_simds
= 3;
2014 rdev
->config
.r600
.max_backends
= 1;
2015 rdev
->config
.r600
.max_gprs
= 128;
2016 rdev
->config
.r600
.max_threads
= 192;
2017 rdev
->config
.r600
.max_stack_entries
= 128;
2018 rdev
->config
.r600
.max_hw_contexts
= 8;
2019 rdev
->config
.r600
.max_gs_threads
= 4;
2020 rdev
->config
.r600
.sx_max_export_size
= 128;
2021 rdev
->config
.r600
.sx_max_export_pos_size
= 16;
2022 rdev
->config
.r600
.sx_max_export_smx_size
= 128;
2023 rdev
->config
.r600
.sq_num_cf_insts
= 2;
2029 rdev
->config
.r600
.max_pipes
= 1;
2030 rdev
->config
.r600
.max_tile_pipes
= 1;
2031 rdev
->config
.r600
.max_simds
= 2;
2032 rdev
->config
.r600
.max_backends
= 1;
2033 rdev
->config
.r600
.max_gprs
= 128;
2034 rdev
->config
.r600
.max_threads
= 192;
2035 rdev
->config
.r600
.max_stack_entries
= 128;
2036 rdev
->config
.r600
.max_hw_contexts
= 4;
2037 rdev
->config
.r600
.max_gs_threads
= 4;
2038 rdev
->config
.r600
.sx_max_export_size
= 128;
2039 rdev
->config
.r600
.sx_max_export_pos_size
= 16;
2040 rdev
->config
.r600
.sx_max_export_smx_size
= 128;
2041 rdev
->config
.r600
.sq_num_cf_insts
= 1;
2044 rdev
->config
.r600
.max_pipes
= 4;
2045 rdev
->config
.r600
.max_tile_pipes
= 4;
2046 rdev
->config
.r600
.max_simds
= 4;
2047 rdev
->config
.r600
.max_backends
= 4;
2048 rdev
->config
.r600
.max_gprs
= 192;
2049 rdev
->config
.r600
.max_threads
= 192;
2050 rdev
->config
.r600
.max_stack_entries
= 256;
2051 rdev
->config
.r600
.max_hw_contexts
= 8;
2052 rdev
->config
.r600
.max_gs_threads
= 16;
2053 rdev
->config
.r600
.sx_max_export_size
= 128;
2054 rdev
->config
.r600
.sx_max_export_pos_size
= 16;
2055 rdev
->config
.r600
.sx_max_export_smx_size
= 128;
2056 rdev
->config
.r600
.sq_num_cf_insts
= 2;
2062 /* Initialize HDP */
2063 for (i
= 0, j
= 0; i
< 32; i
++, j
+= 0x18) {
2064 WREG32((0x2c14 + j
), 0x00000000);
2065 WREG32((0x2c18 + j
), 0x00000000);
2066 WREG32((0x2c1c + j
), 0x00000000);
2067 WREG32((0x2c20 + j
), 0x00000000);
2068 WREG32((0x2c24 + j
), 0x00000000);
2071 WREG32(GRBM_CNTL
, GRBM_READ_TIMEOUT(0xff));
2075 ramcfg
= RREG32(RAMCFG
);
2076 switch (rdev
->config
.r600
.max_tile_pipes
) {
2078 tiling_config
|= PIPE_TILING(0);
2081 tiling_config
|= PIPE_TILING(1);
2084 tiling_config
|= PIPE_TILING(2);
2087 tiling_config
|= PIPE_TILING(3);
2092 rdev
->config
.r600
.tiling_npipes
= rdev
->config
.r600
.max_tile_pipes
;
2093 rdev
->config
.r600
.tiling_nbanks
= 4 << ((ramcfg
& NOOFBANK_MASK
) >> NOOFBANK_SHIFT
);
2094 tiling_config
|= BANK_TILING((ramcfg
& NOOFBANK_MASK
) >> NOOFBANK_SHIFT
);
2095 tiling_config
|= GROUP_SIZE((ramcfg
& BURSTLENGTH_MASK
) >> BURSTLENGTH_SHIFT
);
2097 tmp
= (ramcfg
& NOOFROWS_MASK
) >> NOOFROWS_SHIFT
;
2099 tiling_config
|= ROW_TILING(3);
2100 tiling_config
|= SAMPLE_SPLIT(3);
2102 tiling_config
|= ROW_TILING(tmp
);
2103 tiling_config
|= SAMPLE_SPLIT(tmp
);
2105 tiling_config
|= BANK_SWAPS(1);
2107 cc_gc_shader_pipe_config
= RREG32(CC_GC_SHADER_PIPE_CONFIG
) & 0x00ffff00;
2108 tmp
= rdev
->config
.r600
.max_simds
-
2109 r600_count_pipe_bits((cc_gc_shader_pipe_config
>> 16) & R6XX_MAX_SIMDS_MASK
);
2110 rdev
->config
.r600
.active_simds
= tmp
;
2112 disabled_rb_mask
= (RREG32(CC_RB_BACKEND_DISABLE
) >> 16) & R6XX_MAX_BACKENDS_MASK
;
2114 for (i
= 0; i
< rdev
->config
.r600
.max_backends
; i
++)
2116 /* if all the backends are disabled, fix it up here */
2117 if ((disabled_rb_mask
& tmp
) == tmp
) {
2118 for (i
= 0; i
< rdev
->config
.r600
.max_backends
; i
++)
2119 disabled_rb_mask
&= ~(1 << i
);
2121 tmp
= (tiling_config
& PIPE_TILING__MASK
) >> PIPE_TILING__SHIFT
;
2122 tmp
= r6xx_remap_render_backend(rdev
, tmp
, rdev
->config
.r600
.max_backends
,
2123 R6XX_MAX_BACKENDS
, disabled_rb_mask
);
2124 tiling_config
|= tmp
<< 16;
2125 rdev
->config
.r600
.backend_map
= tmp
;
2127 rdev
->config
.r600
.tile_config
= tiling_config
;
2128 WREG32(GB_TILING_CONFIG
, tiling_config
);
2129 WREG32(DCP_TILING_CONFIG
, tiling_config
& 0xffff);
2130 WREG32(HDP_TILING_CONFIG
, tiling_config
& 0xffff);
2131 WREG32(DMA_TILING_CONFIG
, tiling_config
& 0xffff);
2133 tmp
= R6XX_MAX_PIPES
- r600_count_pipe_bits((cc_gc_shader_pipe_config
& INACTIVE_QD_PIPES_MASK
) >> 8);
2134 WREG32(VGT_OUT_DEALLOC_CNTL
, (tmp
* 4) & DEALLOC_DIST_MASK
);
2135 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL
, ((tmp
* 4) - 2) & VTX_REUSE_DEPTH_MASK
);
2137 /* Setup some CP states */
2138 WREG32(CP_QUEUE_THRESHOLDS
, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
2139 WREG32(CP_MEQ_THRESHOLDS
, (MEQ_END(0x40) | ROQ_END(0x40)));
2141 WREG32(TA_CNTL_AUX
, (DISABLE_CUBE_ANISO
| SYNC_GRADIENT
|
2142 SYNC_WALKER
| SYNC_ALIGNER
));
2143 /* Setup various GPU states */
2144 if (rdev
->family
== CHIP_RV670
)
2145 WREG32(ARB_GDEC_RD_CNTL
, 0x00000021);
2147 tmp
= RREG32(SX_DEBUG_1
);
2148 tmp
|= SMX_EVENT_RELEASE
;
2149 if ((rdev
->family
> CHIP_R600
))
2150 tmp
|= ENABLE_NEW_SMX_ADDRESS
;
2151 WREG32(SX_DEBUG_1
, tmp
);
2153 if (((rdev
->family
) == CHIP_R600
) ||
2154 ((rdev
->family
) == CHIP_RV630
) ||
2155 ((rdev
->family
) == CHIP_RV610
) ||
2156 ((rdev
->family
) == CHIP_RV620
) ||
2157 ((rdev
->family
) == CHIP_RS780
) ||
2158 ((rdev
->family
) == CHIP_RS880
)) {
2159 WREG32(DB_DEBUG
, PREZ_MUST_WAIT_FOR_POSTZ_DONE
);
2161 WREG32(DB_DEBUG
, 0);
2163 WREG32(DB_WATERMARKS
, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
2164 DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
2166 WREG32(PA_SC_MULTI_CHIP_CNTL
, 0);
2167 WREG32(VGT_NUM_INSTANCES
, 0);
2169 WREG32(SPI_CONFIG_CNTL
, GPR_WRITE_PRIORITY(0));
2170 WREG32(SPI_CONFIG_CNTL_1
, VTX_DONE_DELAY(0));
2172 tmp
= RREG32(SQ_MS_FIFO_SIZES
);
2173 if (((rdev
->family
) == CHIP_RV610
) ||
2174 ((rdev
->family
) == CHIP_RV620
) ||
2175 ((rdev
->family
) == CHIP_RS780
) ||
2176 ((rdev
->family
) == CHIP_RS880
)) {
2177 tmp
= (CACHE_FIFO_SIZE(0xa) |
2178 FETCH_FIFO_HIWATER(0xa) |
2179 DONE_FIFO_HIWATER(0xe0) |
2180 ALU_UPDATE_FIFO_HIWATER(0x8));
2181 } else if (((rdev
->family
) == CHIP_R600
) ||
2182 ((rdev
->family
) == CHIP_RV630
)) {
2183 tmp
&= ~DONE_FIFO_HIWATER(0xff);
2184 tmp
|= DONE_FIFO_HIWATER(0x4);
2186 WREG32(SQ_MS_FIFO_SIZES
, tmp
);
2188 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
2189 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
2191 sq_config
= RREG32(SQ_CONFIG
);
2192 sq_config
&= ~(PS_PRIO(3) |
2196 sq_config
|= (DX9_CONSTS
|
2203 if ((rdev
->family
) == CHIP_R600
) {
2204 sq_gpr_resource_mgmt_1
= (NUM_PS_GPRS(124) |
2206 NUM_CLAUSE_TEMP_GPRS(4));
2207 sq_gpr_resource_mgmt_2
= (NUM_GS_GPRS(0) |
2209 sq_thread_resource_mgmt
= (NUM_PS_THREADS(136) |
2210 NUM_VS_THREADS(48) |
2213 sq_stack_resource_mgmt_1
= (NUM_PS_STACK_ENTRIES(128) |
2214 NUM_VS_STACK_ENTRIES(128));
2215 sq_stack_resource_mgmt_2
= (NUM_GS_STACK_ENTRIES(0) |
2216 NUM_ES_STACK_ENTRIES(0));
2217 } else if (((rdev
->family
) == CHIP_RV610
) ||
2218 ((rdev
->family
) == CHIP_RV620
) ||
2219 ((rdev
->family
) == CHIP_RS780
) ||
2220 ((rdev
->family
) == CHIP_RS880
)) {
2221 /* no vertex cache */
2222 sq_config
&= ~VC_ENABLE
;
2224 sq_gpr_resource_mgmt_1
= (NUM_PS_GPRS(44) |
2226 NUM_CLAUSE_TEMP_GPRS(2));
2227 sq_gpr_resource_mgmt_2
= (NUM_GS_GPRS(17) |
2229 sq_thread_resource_mgmt
= (NUM_PS_THREADS(79) |
2230 NUM_VS_THREADS(78) |
2232 NUM_ES_THREADS(31));
2233 sq_stack_resource_mgmt_1
= (NUM_PS_STACK_ENTRIES(40) |
2234 NUM_VS_STACK_ENTRIES(40));
2235 sq_stack_resource_mgmt_2
= (NUM_GS_STACK_ENTRIES(32) |
2236 NUM_ES_STACK_ENTRIES(16));
2237 } else if (((rdev
->family
) == CHIP_RV630
) ||
2238 ((rdev
->family
) == CHIP_RV635
)) {
2239 sq_gpr_resource_mgmt_1
= (NUM_PS_GPRS(44) |
2241 NUM_CLAUSE_TEMP_GPRS(2));
2242 sq_gpr_resource_mgmt_2
= (NUM_GS_GPRS(18) |
2244 sq_thread_resource_mgmt
= (NUM_PS_THREADS(79) |
2245 NUM_VS_THREADS(78) |
2247 NUM_ES_THREADS(31));
2248 sq_stack_resource_mgmt_1
= (NUM_PS_STACK_ENTRIES(40) |
2249 NUM_VS_STACK_ENTRIES(40));
2250 sq_stack_resource_mgmt_2
= (NUM_GS_STACK_ENTRIES(32) |
2251 NUM_ES_STACK_ENTRIES(16));
2252 } else if ((rdev
->family
) == CHIP_RV670
) {
2253 sq_gpr_resource_mgmt_1
= (NUM_PS_GPRS(44) |
2255 NUM_CLAUSE_TEMP_GPRS(2));
2256 sq_gpr_resource_mgmt_2
= (NUM_GS_GPRS(17) |
2258 sq_thread_resource_mgmt
= (NUM_PS_THREADS(79) |
2259 NUM_VS_THREADS(78) |
2261 NUM_ES_THREADS(31));
2262 sq_stack_resource_mgmt_1
= (NUM_PS_STACK_ENTRIES(64) |
2263 NUM_VS_STACK_ENTRIES(64));
2264 sq_stack_resource_mgmt_2
= (NUM_GS_STACK_ENTRIES(64) |
2265 NUM_ES_STACK_ENTRIES(64));
2268 WREG32(SQ_CONFIG
, sq_config
);
2269 WREG32(SQ_GPR_RESOURCE_MGMT_1
, sq_gpr_resource_mgmt_1
);
2270 WREG32(SQ_GPR_RESOURCE_MGMT_2
, sq_gpr_resource_mgmt_2
);
2271 WREG32(SQ_THREAD_RESOURCE_MGMT
, sq_thread_resource_mgmt
);
2272 WREG32(SQ_STACK_RESOURCE_MGMT_1
, sq_stack_resource_mgmt_1
);
2273 WREG32(SQ_STACK_RESOURCE_MGMT_2
, sq_stack_resource_mgmt_2
);
2275 if (((rdev
->family
) == CHIP_RV610
) ||
2276 ((rdev
->family
) == CHIP_RV620
) ||
2277 ((rdev
->family
) == CHIP_RS780
) ||
2278 ((rdev
->family
) == CHIP_RS880
)) {
2279 WREG32(VGT_CACHE_INVALIDATION
, CACHE_INVALIDATION(TC_ONLY
));
2281 WREG32(VGT_CACHE_INVALIDATION
, CACHE_INVALIDATION(VC_AND_TC
));
2284 /* More default values. 2D/3D driver should adjust as needed */
2285 WREG32(PA_SC_AA_SAMPLE_LOCS_2S
, (S0_X(0xc) | S0_Y(0x4) |
2286 S1_X(0x4) | S1_Y(0xc)));
2287 WREG32(PA_SC_AA_SAMPLE_LOCS_4S
, (S0_X(0xe) | S0_Y(0xe) |
2288 S1_X(0x2) | S1_Y(0x2) |
2289 S2_X(0xa) | S2_Y(0x6) |
2290 S3_X(0x6) | S3_Y(0xa)));
2291 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0
, (S0_X(0xe) | S0_Y(0xb) |
2292 S1_X(0x4) | S1_Y(0xc) |
2293 S2_X(0x1) | S2_Y(0x6) |
2294 S3_X(0xa) | S3_Y(0xe)));
2295 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1
, (S4_X(0x6) | S4_Y(0x1) |
2296 S5_X(0x0) | S5_Y(0x0) |
2297 S6_X(0xb) | S6_Y(0x4) |
2298 S7_X(0x7) | S7_Y(0x8)));
2300 WREG32(VGT_STRMOUT_EN
, 0);
2301 tmp
= rdev
->config
.r600
.max_pipes
* 16;
2302 switch (rdev
->family
) {
2318 WREG32(VGT_ES_PER_GS
, 128);
2319 WREG32(VGT_GS_PER_ES
, tmp
);
2320 WREG32(VGT_GS_PER_VS
, 2);
2321 WREG32(VGT_GS_VERTEX_REUSE
, 16);
2323 /* more default values. 2D/3D driver should adjust as needed */
2324 WREG32(PA_SC_LINE_STIPPLE_STATE
, 0);
2325 WREG32(VGT_STRMOUT_EN
, 0);
2327 WREG32(PA_SC_MODE_CNTL
, 0);
2328 WREG32(PA_SC_AA_CONFIG
, 0);
2329 WREG32(PA_SC_LINE_STIPPLE
, 0);
2330 WREG32(SPI_INPUT_Z
, 0);
2331 WREG32(SPI_PS_IN_CONTROL_0
, NUM_INTERP(2));
2332 WREG32(CB_COLOR7_FRAG
, 0);
2334 /* Clear render buffer base addresses */
2335 WREG32(CB_COLOR0_BASE
, 0);
2336 WREG32(CB_COLOR1_BASE
, 0);
2337 WREG32(CB_COLOR2_BASE
, 0);
2338 WREG32(CB_COLOR3_BASE
, 0);
2339 WREG32(CB_COLOR4_BASE
, 0);
2340 WREG32(CB_COLOR5_BASE
, 0);
2341 WREG32(CB_COLOR6_BASE
, 0);
2342 WREG32(CB_COLOR7_BASE
, 0);
2343 WREG32(CB_COLOR7_FRAG
, 0);
2345 switch (rdev
->family
) {
2350 tmp
= TC_L2_SIZE(8);
2354 tmp
= TC_L2_SIZE(4);
2357 tmp
= TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT
;
2360 tmp
= TC_L2_SIZE(0);
2363 WREG32(TC_CNTL
, tmp
);
2365 tmp
= RREG32(HDP_HOST_PATH_CNTL
);
2366 WREG32(HDP_HOST_PATH_CNTL
, tmp
);
2368 tmp
= RREG32(ARB_POP
);
2369 tmp
|= ENABLE_TC128
;
2370 WREG32(ARB_POP
, tmp
);
2372 WREG32(PA_SC_MULTI_CHIP_CNTL
, 0);
2373 WREG32(PA_CL_ENHANCE
, (CLIP_VTX_REORDER_ENA
|
2375 WREG32(PA_SC_ENHANCE
, FORCE_EOV_MAX_CLK_CNT(4095));
2376 WREG32(VC_ENHANCE
, 0);
2381 * Indirect registers accessor
2383 u32
r600_pciep_rreg(struct radeon_device
*rdev
, u32 reg
)
2385 unsigned long flags
;
2388 spin_lock_irqsave(&rdev
->pciep_idx_lock
, flags
);
2389 WREG32(PCIE_PORT_INDEX
, ((reg
) & 0xff));
2390 (void)RREG32(PCIE_PORT_INDEX
);
2391 r
= RREG32(PCIE_PORT_DATA
);
2392 spin_unlock_irqrestore(&rdev
->pciep_idx_lock
, flags
);
2396 void r600_pciep_wreg(struct radeon_device
*rdev
, u32 reg
, u32 v
)
2398 unsigned long flags
;
2400 spin_lock_irqsave(&rdev
->pciep_idx_lock
, flags
);
2401 WREG32(PCIE_PORT_INDEX
, ((reg
) & 0xff));
2402 (void)RREG32(PCIE_PORT_INDEX
);
2403 WREG32(PCIE_PORT_DATA
, (v
));
2404 (void)RREG32(PCIE_PORT_DATA
);
2405 spin_unlock_irqrestore(&rdev
->pciep_idx_lock
, flags
);
2411 void r600_cp_stop(struct radeon_device
*rdev
)
2413 if (rdev
->asic
->copy
.copy_ring_index
== RADEON_RING_TYPE_GFX_INDEX
)
2414 radeon_ttm_set_active_vram_size(rdev
, rdev
->mc
.visible_vram_size
);
2415 WREG32(R_0086D8_CP_ME_CNTL
, S_0086D8_CP_ME_HALT(1));
2416 WREG32(SCRATCH_UMSK
, 0);
2417 rdev
->ring
[RADEON_RING_TYPE_GFX_INDEX
].ready
= false;
2420 int r600_init_microcode(struct radeon_device
*rdev
)
2422 const char *chip_name
;
2423 const char *rlc_chip_name
;
2424 const char *smc_chip_name
= "RV770";
2425 size_t pfp_req_size
, me_req_size
, rlc_req_size
, smc_req_size
= 0;
2431 switch (rdev
->family
) {
2434 rlc_chip_name
= "R600";
2437 chip_name
= "RV610";
2438 rlc_chip_name
= "R600";
2441 chip_name
= "RV630";
2442 rlc_chip_name
= "R600";
2445 chip_name
= "RV620";
2446 rlc_chip_name
= "R600";
2449 chip_name
= "RV635";
2450 rlc_chip_name
= "R600";
2453 chip_name
= "RV670";
2454 rlc_chip_name
= "R600";
2458 chip_name
= "RS780";
2459 rlc_chip_name
= "R600";
2462 chip_name
= "RV770";
2463 rlc_chip_name
= "R700";
2464 smc_chip_name
= "RV770";
2465 smc_req_size
= ALIGN(RV770_SMC_UCODE_SIZE
, 4);
2468 chip_name
= "RV730";
2469 rlc_chip_name
= "R700";
2470 smc_chip_name
= "RV730";
2471 smc_req_size
= ALIGN(RV730_SMC_UCODE_SIZE
, 4);
2474 chip_name
= "RV710";
2475 rlc_chip_name
= "R700";
2476 smc_chip_name
= "RV710";
2477 smc_req_size
= ALIGN(RV710_SMC_UCODE_SIZE
, 4);
2480 chip_name
= "RV730";
2481 rlc_chip_name
= "R700";
2482 smc_chip_name
= "RV740";
2483 smc_req_size
= ALIGN(RV740_SMC_UCODE_SIZE
, 4);
2486 chip_name
= "CEDAR";
2487 rlc_chip_name
= "CEDAR";
2488 smc_chip_name
= "CEDAR";
2489 smc_req_size
= ALIGN(CEDAR_SMC_UCODE_SIZE
, 4);
2492 chip_name
= "REDWOOD";
2493 rlc_chip_name
= "REDWOOD";
2494 smc_chip_name
= "REDWOOD";
2495 smc_req_size
= ALIGN(REDWOOD_SMC_UCODE_SIZE
, 4);
2498 chip_name
= "JUNIPER";
2499 rlc_chip_name
= "JUNIPER";
2500 smc_chip_name
= "JUNIPER";
2501 smc_req_size
= ALIGN(JUNIPER_SMC_UCODE_SIZE
, 4);
2505 chip_name
= "CYPRESS";
2506 rlc_chip_name
= "CYPRESS";
2507 smc_chip_name
= "CYPRESS";
2508 smc_req_size
= ALIGN(CYPRESS_SMC_UCODE_SIZE
, 4);
2512 rlc_chip_name
= "SUMO";
2516 rlc_chip_name
= "SUMO";
2519 chip_name
= "SUMO2";
2520 rlc_chip_name
= "SUMO";
2525 if (rdev
->family
>= CHIP_CEDAR
) {
2526 pfp_req_size
= EVERGREEN_PFP_UCODE_SIZE
* 4;
2527 me_req_size
= EVERGREEN_PM4_UCODE_SIZE
* 4;
2528 rlc_req_size
= EVERGREEN_RLC_UCODE_SIZE
* 4;
2529 } else if (rdev
->family
>= CHIP_RV770
) {
2530 pfp_req_size
= R700_PFP_UCODE_SIZE
* 4;
2531 me_req_size
= R700_PM4_UCODE_SIZE
* 4;
2532 rlc_req_size
= R700_RLC_UCODE_SIZE
* 4;
2534 pfp_req_size
= R600_PFP_UCODE_SIZE
* 4;
2535 me_req_size
= R600_PM4_UCODE_SIZE
* 12;
2536 rlc_req_size
= R600_RLC_UCODE_SIZE
* 4;
2539 DRM_INFO("Loading %s Microcode\n", chip_name
);
2541 snprintf(fw_name
, sizeof(fw_name
), "radeon/%s_pfp.bin", chip_name
);
2542 err
= request_firmware(&rdev
->pfp_fw
, fw_name
, rdev
->dev
);
2545 if (rdev
->pfp_fw
->size
!= pfp_req_size
) {
2547 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2548 rdev
->pfp_fw
->size
, fw_name
);
2553 snprintf(fw_name
, sizeof(fw_name
), "radeon/%s_me.bin", chip_name
);
2554 err
= request_firmware(&rdev
->me_fw
, fw_name
, rdev
->dev
);
2557 if (rdev
->me_fw
->size
!= me_req_size
) {
2559 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2560 rdev
->me_fw
->size
, fw_name
);
2564 snprintf(fw_name
, sizeof(fw_name
), "radeon/%s_rlc.bin", rlc_chip_name
);
2565 err
= request_firmware(&rdev
->rlc_fw
, fw_name
, rdev
->dev
);
2568 if (rdev
->rlc_fw
->size
!= rlc_req_size
) {
2570 "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
2571 rdev
->rlc_fw
->size
, fw_name
);
2575 if ((rdev
->family
>= CHIP_RV770
) && (rdev
->family
<= CHIP_HEMLOCK
)) {
2576 snprintf(fw_name
, sizeof(fw_name
), "radeon/%s_smc.bin", smc_chip_name
);
2577 err
= request_firmware(&rdev
->smc_fw
, fw_name
, rdev
->dev
);
2580 "smc: error loading firmware \"%s\"\n",
2582 release_firmware(rdev
->smc_fw
);
2583 rdev
->smc_fw
= NULL
;
2585 } else if (rdev
->smc_fw
->size
!= smc_req_size
) {
2587 "smc: Bogus length %zu in firmware \"%s\"\n",
2588 rdev
->smc_fw
->size
, fw_name
);
2597 "r600_cp: Failed to load firmware \"%s\"\n",
2599 release_firmware(rdev
->pfp_fw
);
2600 rdev
->pfp_fw
= NULL
;
2601 release_firmware(rdev
->me_fw
);
2603 release_firmware(rdev
->rlc_fw
);
2604 rdev
->rlc_fw
= NULL
;
2605 release_firmware(rdev
->smc_fw
);
2606 rdev
->smc_fw
= NULL
;
2611 u32
r600_gfx_get_rptr(struct radeon_device
*rdev
,
2612 struct radeon_ring
*ring
)
2616 if (rdev
->wb
.enabled
)
2617 rptr
= rdev
->wb
.wb
[ring
->rptr_offs
/4];
2619 rptr
= RREG32(R600_CP_RB_RPTR
);
2624 u32
r600_gfx_get_wptr(struct radeon_device
*rdev
,
2625 struct radeon_ring
*ring
)
2629 wptr
= RREG32(R600_CP_RB_WPTR
);
2634 void r600_gfx_set_wptr(struct radeon_device
*rdev
,
2635 struct radeon_ring
*ring
)
2637 WREG32(R600_CP_RB_WPTR
, ring
->wptr
);
2638 (void)RREG32(R600_CP_RB_WPTR
);
2641 static int r600_cp_load_microcode(struct radeon_device
*rdev
)
2643 const __be32
*fw_data
;
2646 if (!rdev
->me_fw
|| !rdev
->pfp_fw
)
2655 RB_NO_UPDATE
| RB_BLKSZ(15) | RB_BUFSZ(3));
2658 WREG32(GRBM_SOFT_RESET
, SOFT_RESET_CP
);
2659 RREG32(GRBM_SOFT_RESET
);
2661 WREG32(GRBM_SOFT_RESET
, 0);
2663 WREG32(CP_ME_RAM_WADDR
, 0);
2665 fw_data
= (const __be32
*)rdev
->me_fw
->data
;
2666 WREG32(CP_ME_RAM_WADDR
, 0);
2667 for (i
= 0; i
< R600_PM4_UCODE_SIZE
* 3; i
++)
2668 WREG32(CP_ME_RAM_DATA
,
2669 be32_to_cpup(fw_data
++));
2671 fw_data
= (const __be32
*)rdev
->pfp_fw
->data
;
2672 WREG32(CP_PFP_UCODE_ADDR
, 0);
2673 for (i
= 0; i
< R600_PFP_UCODE_SIZE
; i
++)
2674 WREG32(CP_PFP_UCODE_DATA
,
2675 be32_to_cpup(fw_data
++));
2677 WREG32(CP_PFP_UCODE_ADDR
, 0);
2678 WREG32(CP_ME_RAM_WADDR
, 0);
2679 WREG32(CP_ME_RAM_RADDR
, 0);
2683 int r600_cp_start(struct radeon_device
*rdev
)
2685 struct radeon_ring
*ring
= &rdev
->ring
[RADEON_RING_TYPE_GFX_INDEX
];
2689 r
= radeon_ring_lock(rdev
, ring
, 7);
2691 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r
);
2694 radeon_ring_write(ring
, PACKET3(PACKET3_ME_INITIALIZE
, 5));
2695 radeon_ring_write(ring
, 0x1);
2696 if (rdev
->family
>= CHIP_RV770
) {
2697 radeon_ring_write(ring
, 0x0);
2698 radeon_ring_write(ring
, rdev
->config
.rv770
.max_hw_contexts
- 1);
2700 radeon_ring_write(ring
, 0x3);
2701 radeon_ring_write(ring
, rdev
->config
.r600
.max_hw_contexts
- 1);
2703 radeon_ring_write(ring
, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
2704 radeon_ring_write(ring
, 0);
2705 radeon_ring_write(ring
, 0);
2706 radeon_ring_unlock_commit(rdev
, ring
, false);
2709 WREG32(R_0086D8_CP_ME_CNTL
, cp_me
);
2713 int r600_cp_resume(struct radeon_device
*rdev
)
2715 struct radeon_ring
*ring
= &rdev
->ring
[RADEON_RING_TYPE_GFX_INDEX
];
2721 WREG32(GRBM_SOFT_RESET
, SOFT_RESET_CP
);
2722 RREG32(GRBM_SOFT_RESET
);
2724 WREG32(GRBM_SOFT_RESET
, 0);
2726 /* Set ring buffer size */
2727 rb_bufsz
= order_base_2(ring
->ring_size
/ 8);
2728 tmp
= (order_base_2(RADEON_GPU_PAGE_SIZE
/8) << 8) | rb_bufsz
;
2730 tmp
|= BUF_SWAP_32BIT
;
2732 WREG32(CP_RB_CNTL
, tmp
);
2733 WREG32(CP_SEM_WAIT_TIMER
, 0x0);
2735 /* Set the write pointer delay */
2736 WREG32(CP_RB_WPTR_DELAY
, 0);
2738 /* Initialize the ring buffer's read and write pointers */
2739 WREG32(CP_RB_CNTL
, tmp
| RB_RPTR_WR_ENA
);
2740 WREG32(CP_RB_RPTR_WR
, 0);
2742 WREG32(CP_RB_WPTR
, ring
->wptr
);
2744 /* set the wb address whether it's enabled or not */
2745 WREG32(CP_RB_RPTR_ADDR
,
2746 ((rdev
->wb
.gpu_addr
+ RADEON_WB_CP_RPTR_OFFSET
) & 0xFFFFFFFC));
2747 WREG32(CP_RB_RPTR_ADDR_HI
, upper_32_bits(rdev
->wb
.gpu_addr
+ RADEON_WB_CP_RPTR_OFFSET
) & 0xFF);
2748 WREG32(SCRATCH_ADDR
, ((rdev
->wb
.gpu_addr
+ RADEON_WB_SCRATCH_OFFSET
) >> 8) & 0xFFFFFFFF);
2750 if (rdev
->wb
.enabled
)
2751 WREG32(SCRATCH_UMSK
, 0xff);
2753 tmp
|= RB_NO_UPDATE
;
2754 WREG32(SCRATCH_UMSK
, 0);
2758 WREG32(CP_RB_CNTL
, tmp
);
2760 WREG32(CP_RB_BASE
, ring
->gpu_addr
>> 8);
2761 WREG32(CP_DEBUG
, (1 << 27) | (1 << 28));
2763 r600_cp_start(rdev
);
2765 r
= radeon_ring_test(rdev
, RADEON_RING_TYPE_GFX_INDEX
, ring
);
2767 ring
->ready
= false;
2771 if (rdev
->asic
->copy
.copy_ring_index
== RADEON_RING_TYPE_GFX_INDEX
)
2772 radeon_ttm_set_active_vram_size(rdev
, rdev
->mc
.real_vram_size
);
2777 void r600_ring_init(struct radeon_device
*rdev
, struct radeon_ring
*ring
, unsigned ring_size
)
2782 /* Align ring size */
2783 rb_bufsz
= order_base_2(ring_size
/ 8);
2784 ring_size
= (1 << (rb_bufsz
+ 1)) * 4;
2785 ring
->ring_size
= ring_size
;
2786 ring
->align_mask
= 16 - 1;
2788 if (radeon_ring_supports_scratch_reg(rdev
, ring
)) {
2789 r
= radeon_scratch_get(rdev
, &ring
->rptr_save_reg
);
2791 DRM_ERROR("failed to get scratch reg for rptr save (%d).\n", r
);
2792 ring
->rptr_save_reg
= 0;
2797 void r600_cp_fini(struct radeon_device
*rdev
)
2799 struct radeon_ring
*ring
= &rdev
->ring
[RADEON_RING_TYPE_GFX_INDEX
];
2801 radeon_ring_fini(rdev
, ring
);
2802 radeon_scratch_free(rdev
, ring
->rptr_save_reg
);
2806 * GPU scratch registers helpers function.
2808 void r600_scratch_init(struct radeon_device
*rdev
)
2812 rdev
->scratch
.num_reg
= 7;
2813 rdev
->scratch
.reg_base
= SCRATCH_REG0
;
2814 for (i
= 0; i
< rdev
->scratch
.num_reg
; i
++) {
2815 rdev
->scratch
.free
[i
] = true;
2816 rdev
->scratch
.reg
[i
] = rdev
->scratch
.reg_base
+ (i
* 4);
2820 int r600_ring_test(struct radeon_device
*rdev
, struct radeon_ring
*ring
)
2827 r
= radeon_scratch_get(rdev
, &scratch
);
2829 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r
);
2832 WREG32(scratch
, 0xCAFEDEAD);
2833 r
= radeon_ring_lock(rdev
, ring
, 3);
2835 DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ring
->idx
, r
);
2836 radeon_scratch_free(rdev
, scratch
);
2839 radeon_ring_write(ring
, PACKET3(PACKET3_SET_CONFIG_REG
, 1));
2840 radeon_ring_write(ring
, ((scratch
- PACKET3_SET_CONFIG_REG_OFFSET
) >> 2));
2841 radeon_ring_write(ring
, 0xDEADBEEF);
2842 radeon_ring_unlock_commit(rdev
, ring
, false);
2843 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
2844 tmp
= RREG32(scratch
);
2845 if (tmp
== 0xDEADBEEF)
2849 if (i
< rdev
->usec_timeout
) {
2850 DRM_INFO("ring test on %d succeeded in %d usecs\n", ring
->idx
, i
);
2852 DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
2853 ring
->idx
, scratch
, tmp
);
2856 radeon_scratch_free(rdev
, scratch
);
2861 * CP fences/semaphores
2864 void r600_fence_ring_emit(struct radeon_device
*rdev
,
2865 struct radeon_fence
*fence
)
2867 struct radeon_ring
*ring
= &rdev
->ring
[fence
->ring
];
2868 u32 cp_coher_cntl
= PACKET3_TC_ACTION_ENA
| PACKET3_VC_ACTION_ENA
|
2869 PACKET3_SH_ACTION_ENA
;
2871 if (rdev
->family
>= CHIP_RV770
)
2872 cp_coher_cntl
|= PACKET3_FULL_CACHE_ENA
;
2874 if (rdev
->wb
.use_event
) {
2875 u64 addr
= rdev
->fence_drv
[fence
->ring
].gpu_addr
;
2876 /* flush read cache over gart */
2877 radeon_ring_write(ring
, PACKET3(PACKET3_SURFACE_SYNC
, 3));
2878 radeon_ring_write(ring
, cp_coher_cntl
);
2879 radeon_ring_write(ring
, 0xFFFFFFFF);
2880 radeon_ring_write(ring
, 0);
2881 radeon_ring_write(ring
, 10); /* poll interval */
2882 /* EVENT_WRITE_EOP - flush caches, send int */
2883 radeon_ring_write(ring
, PACKET3(PACKET3_EVENT_WRITE_EOP
, 4));
2884 radeon_ring_write(ring
, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS
) | EVENT_INDEX(5));
2885 radeon_ring_write(ring
, lower_32_bits(addr
));
2886 radeon_ring_write(ring
, (upper_32_bits(addr
) & 0xff) | DATA_SEL(1) | INT_SEL(2));
2887 radeon_ring_write(ring
, fence
->seq
);
2888 radeon_ring_write(ring
, 0);
2890 /* flush read cache over gart */
2891 radeon_ring_write(ring
, PACKET3(PACKET3_SURFACE_SYNC
, 3));
2892 radeon_ring_write(ring
, cp_coher_cntl
);
2893 radeon_ring_write(ring
, 0xFFFFFFFF);
2894 radeon_ring_write(ring
, 0);
2895 radeon_ring_write(ring
, 10); /* poll interval */
2896 radeon_ring_write(ring
, PACKET3(PACKET3_EVENT_WRITE
, 0));
2897 radeon_ring_write(ring
, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT
) | EVENT_INDEX(0));
2898 /* wait for 3D idle clean */
2899 radeon_ring_write(ring
, PACKET3(PACKET3_SET_CONFIG_REG
, 1));
2900 radeon_ring_write(ring
, (WAIT_UNTIL
- PACKET3_SET_CONFIG_REG_OFFSET
) >> 2);
2901 radeon_ring_write(ring
, WAIT_3D_IDLE_bit
| WAIT_3D_IDLECLEAN_bit
);
2902 /* Emit fence sequence & fire IRQ */
2903 radeon_ring_write(ring
, PACKET3(PACKET3_SET_CONFIG_REG
, 1));
2904 radeon_ring_write(ring
, ((rdev
->fence_drv
[fence
->ring
].scratch_reg
- PACKET3_SET_CONFIG_REG_OFFSET
) >> 2));
2905 radeon_ring_write(ring
, fence
->seq
);
2906 /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
2907 radeon_ring_write(ring
, PACKET0(CP_INT_STATUS
, 0));
2908 radeon_ring_write(ring
, RB_INT_STAT
);
2913 * r600_semaphore_ring_emit - emit a semaphore on the CP ring
2915 * @rdev: radeon_device pointer
2916 * @ring: radeon ring buffer object
2917 * @semaphore: radeon semaphore object
2918 * @emit_wait: Is this a sempahore wait?
2920 * Emits a semaphore signal/wait packet to the CP ring and prevents the PFP
2921 * from running ahead of semaphore waits.
2923 bool r600_semaphore_ring_emit(struct radeon_device
*rdev
,
2924 struct radeon_ring
*ring
,
2925 struct radeon_semaphore
*semaphore
,
2928 uint64_t addr
= semaphore
->gpu_addr
;
2929 unsigned sel
= emit_wait
? PACKET3_SEM_SEL_WAIT
: PACKET3_SEM_SEL_SIGNAL
;
2931 if (rdev
->family
< CHIP_CAYMAN
)
2932 sel
|= PACKET3_SEM_WAIT_ON_SIGNAL
;
2934 radeon_ring_write(ring
, PACKET3(PACKET3_MEM_SEMAPHORE
, 1));
2935 radeon_ring_write(ring
, lower_32_bits(addr
));
2936 radeon_ring_write(ring
, (upper_32_bits(addr
) & 0xff) | sel
);
2938 /* PFP_SYNC_ME packet only exists on 7xx+, only enable it on eg+ */
2939 if (emit_wait
&& (rdev
->family
>= CHIP_CEDAR
)) {
2940 /* Prevent the PFP from running ahead of the semaphore wait */
2941 radeon_ring_write(ring
, PACKET3(PACKET3_PFP_SYNC_ME
, 0));
2942 radeon_ring_write(ring
, 0x0);
2949 * r600_copy_cpdma - copy pages using the CP DMA engine
2951 * @rdev: radeon_device pointer
2952 * @src_offset: src GPU address
2953 * @dst_offset: dst GPU address
2954 * @num_gpu_pages: number of GPU pages to xfer
2955 * @fence: radeon fence object
2957 * Copy GPU paging using the CP DMA engine (r6xx+).
2958 * Used by the radeon ttm implementation to move pages if
2959 * registered as the asic copy callback.
2961 struct radeon_fence
*r600_copy_cpdma(struct radeon_device
*rdev
,
2962 uint64_t src_offset
, uint64_t dst_offset
,
2963 unsigned num_gpu_pages
,
2964 struct reservation_object
*resv
)
2966 struct radeon_fence
*fence
;
2967 struct radeon_sync sync
;
2968 int ring_index
= rdev
->asic
->copy
.blit_ring_index
;
2969 struct radeon_ring
*ring
= &rdev
->ring
[ring_index
];
2970 u32 size_in_bytes
, cur_size_in_bytes
, tmp
;
2974 radeon_sync_create(&sync
);
2976 size_in_bytes
= (num_gpu_pages
<< RADEON_GPU_PAGE_SHIFT
);
2977 num_loops
= DIV_ROUND_UP(size_in_bytes
, 0x1fffff);
2978 r
= radeon_ring_lock(rdev
, ring
, num_loops
* 6 + 24);
2980 DRM_ERROR("radeon: moving bo (%d).\n", r
);
2981 radeon_sync_free(rdev
, &sync
, NULL
);
2985 radeon_sync_resv(rdev
, &sync
, resv
, false);
2986 radeon_sync_rings(rdev
, &sync
, ring
->idx
);
2988 radeon_ring_write(ring
, PACKET3(PACKET3_SET_CONFIG_REG
, 1));
2989 radeon_ring_write(ring
, (WAIT_UNTIL
- PACKET3_SET_CONFIG_REG_OFFSET
) >> 2);
2990 radeon_ring_write(ring
, WAIT_3D_IDLE_bit
);
2991 for (i
= 0; i
< num_loops
; i
++) {
2992 cur_size_in_bytes
= size_in_bytes
;
2993 if (cur_size_in_bytes
> 0x1fffff)
2994 cur_size_in_bytes
= 0x1fffff;
2995 size_in_bytes
-= cur_size_in_bytes
;
2996 tmp
= upper_32_bits(src_offset
) & 0xff;
2997 if (size_in_bytes
== 0)
2998 tmp
|= PACKET3_CP_DMA_CP_SYNC
;
2999 radeon_ring_write(ring
, PACKET3(PACKET3_CP_DMA
, 4));
3000 radeon_ring_write(ring
, lower_32_bits(src_offset
));
3001 radeon_ring_write(ring
, tmp
);
3002 radeon_ring_write(ring
, lower_32_bits(dst_offset
));
3003 radeon_ring_write(ring
, upper_32_bits(dst_offset
) & 0xff);
3004 radeon_ring_write(ring
, cur_size_in_bytes
);
3005 src_offset
+= cur_size_in_bytes
;
3006 dst_offset
+= cur_size_in_bytes
;
3008 radeon_ring_write(ring
, PACKET3(PACKET3_SET_CONFIG_REG
, 1));
3009 radeon_ring_write(ring
, (WAIT_UNTIL
- PACKET3_SET_CONFIG_REG_OFFSET
) >> 2);
3010 radeon_ring_write(ring
, WAIT_CP_DMA_IDLE_bit
);
3012 r
= radeon_fence_emit(rdev
, &fence
, ring
->idx
);
3014 radeon_ring_unlock_undo(rdev
, ring
);
3015 radeon_sync_free(rdev
, &sync
, NULL
);
3019 radeon_ring_unlock_commit(rdev
, ring
, false);
3020 radeon_sync_free(rdev
, &sync
, fence
);
3025 int r600_set_surface_reg(struct radeon_device
*rdev
, int reg
,
3026 uint32_t tiling_flags
, uint32_t pitch
,
3027 uint32_t offset
, uint32_t obj_size
)
3029 /* FIXME: implement */
3033 void r600_clear_surface_reg(struct radeon_device
*rdev
, int reg
)
3035 /* FIXME: implement */
3038 static int r600_startup(struct radeon_device
*rdev
)
3040 struct radeon_ring
*ring
;
3043 /* enable pcie gen2 link */
3044 r600_pcie_gen2_enable(rdev
);
3046 /* scratch needs to be initialized before MC */
3047 r
= r600_vram_scratch_init(rdev
);
3051 r600_mc_program(rdev
);
3053 if (rdev
->flags
& RADEON_IS_AGP
) {
3054 r600_agp_enable(rdev
);
3056 r
= r600_pcie_gart_enable(rdev
);
3060 r600_gpu_init(rdev
);
3062 /* allocate wb buffer */
3063 r
= radeon_wb_init(rdev
);
3067 r
= radeon_fence_driver_start_ring(rdev
, RADEON_RING_TYPE_GFX_INDEX
);
3069 dev_err(rdev
->dev
, "failed initializing CP fences (%d).\n", r
);
3073 if (rdev
->has_uvd
) {
3074 r
= uvd_v1_0_resume(rdev
);
3076 r
= radeon_fence_driver_start_ring(rdev
, R600_RING_TYPE_UVD_INDEX
);
3078 dev_err(rdev
->dev
, "failed initializing UVD fences (%d).\n", r
);
3082 rdev
->ring
[R600_RING_TYPE_UVD_INDEX
].ring_size
= 0;
3086 if (!rdev
->irq
.installed
) {
3087 r
= radeon_irq_kms_init(rdev
);
3092 r
= r600_irq_init(rdev
);
3094 DRM_ERROR("radeon: IH init failed (%d).\n", r
);
3095 radeon_irq_kms_fini(rdev
);
3100 ring
= &rdev
->ring
[RADEON_RING_TYPE_GFX_INDEX
];
3101 r
= radeon_ring_init(rdev
, ring
, ring
->ring_size
, RADEON_WB_CP_RPTR_OFFSET
,
3106 r
= r600_cp_load_microcode(rdev
);
3109 r
= r600_cp_resume(rdev
);
3113 if (rdev
->has_uvd
) {
3114 ring
= &rdev
->ring
[R600_RING_TYPE_UVD_INDEX
];
3115 if (ring
->ring_size
) {
3116 r
= radeon_ring_init(rdev
, ring
, ring
->ring_size
, 0,
3119 r
= uvd_v1_0_init(rdev
);
3121 DRM_ERROR("radeon: failed initializing UVD (%d).\n", r
);
3125 r
= radeon_ib_pool_init(rdev
);
3127 dev_err(rdev
->dev
, "IB initialization failed (%d).\n", r
);
3131 r
= radeon_audio_init(rdev
);
3133 DRM_ERROR("radeon: audio init failed\n");
3140 void r600_vga_set_state(struct radeon_device
*rdev
, bool state
)
3144 temp
= RREG32(CONFIG_CNTL
);
3145 if (state
== false) {
3151 WREG32(CONFIG_CNTL
, temp
);
3154 int r600_resume(struct radeon_device
*rdev
)
3158 /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
3159 * posting will perform necessary task to bring back GPU into good
3163 atom_asic_init(rdev
->mode_info
.atom_context
);
3165 if (rdev
->pm
.pm_method
== PM_METHOD_DPM
)
3166 radeon_pm_resume(rdev
);
3168 rdev
->accel_working
= true;
3169 r
= r600_startup(rdev
);
3171 DRM_ERROR("r600 startup failed on resume\n");
3172 rdev
->accel_working
= false;
3179 int r600_suspend(struct radeon_device
*rdev
)
3181 radeon_pm_suspend(rdev
);
3182 radeon_audio_fini(rdev
);
3184 if (rdev
->has_uvd
) {
3185 uvd_v1_0_fini(rdev
);
3186 radeon_uvd_suspend(rdev
);
3188 r600_irq_suspend(rdev
);
3189 radeon_wb_disable(rdev
);
3190 r600_pcie_gart_disable(rdev
);
3195 /* Plan is to move initialization in that function and use
3196 * helper function so that radeon_device_init pretty much
3197 * do nothing more than calling asic specific function. This
3198 * should also allow to remove a bunch of callback function
3201 int r600_init(struct radeon_device
*rdev
)
3205 if (r600_debugfs_mc_info_init(rdev
)) {
3206 DRM_ERROR("Failed to register debugfs file for mc !\n");
3209 if (!radeon_get_bios(rdev
)) {
3210 if (ASIC_IS_AVIVO(rdev
))
3213 /* Must be an ATOMBIOS */
3214 if (!rdev
->is_atom_bios
) {
3215 dev_err(rdev
->dev
, "Expecting atombios for R600 GPU\n");
3218 r
= radeon_atombios_init(rdev
);
3221 /* Post card if necessary */
3222 if (!radeon_card_posted(rdev
)) {
3224 dev_err(rdev
->dev
, "Card not posted and no BIOS - ignoring\n");
3227 DRM_INFO("GPU not posted. posting now...\n");
3228 atom_asic_init(rdev
->mode_info
.atom_context
);
3230 /* Initialize scratch registers */
3231 r600_scratch_init(rdev
);
3232 /* Initialize surface registers */
3233 radeon_surface_init(rdev
);
3234 /* Initialize clocks */
3235 radeon_get_clock_info(rdev
->ddev
);
3237 r
= radeon_fence_driver_init(rdev
);
3240 if (rdev
->flags
& RADEON_IS_AGP
) {
3241 r
= radeon_agp_init(rdev
);
3243 radeon_agp_disable(rdev
);
3245 r
= r600_mc_init(rdev
);
3248 /* Memory manager */
3249 r
= radeon_bo_init(rdev
);
3253 if (!rdev
->me_fw
|| !rdev
->pfp_fw
|| !rdev
->rlc_fw
) {
3254 r
= r600_init_microcode(rdev
);
3256 DRM_ERROR("Failed to load firmware!\n");
3261 /* Initialize power management */
3262 radeon_pm_init(rdev
);
3264 rdev
->ring
[RADEON_RING_TYPE_GFX_INDEX
].ring_obj
= NULL
;
3265 r600_ring_init(rdev
, &rdev
->ring
[RADEON_RING_TYPE_GFX_INDEX
], 1024 * 1024);
3267 if (rdev
->has_uvd
) {
3268 r
= radeon_uvd_init(rdev
);
3270 rdev
->ring
[R600_RING_TYPE_UVD_INDEX
].ring_obj
= NULL
;
3271 r600_ring_init(rdev
, &rdev
->ring
[R600_RING_TYPE_UVD_INDEX
], 4096);
3275 rdev
->ih
.ring_obj
= NULL
;
3276 r600_ih_ring_init(rdev
, 64 * 1024);
3278 r
= r600_pcie_gart_init(rdev
);
3282 rdev
->accel_working
= true;
3283 r
= r600_startup(rdev
);
3285 dev_err(rdev
->dev
, "disabling GPU acceleration\n");
3287 r600_irq_fini(rdev
);
3288 radeon_wb_fini(rdev
);
3289 radeon_ib_pool_fini(rdev
);
3290 radeon_irq_kms_fini(rdev
);
3291 r600_pcie_gart_fini(rdev
);
3292 rdev
->accel_working
= false;
3298 void r600_fini(struct radeon_device
*rdev
)
3300 radeon_pm_fini(rdev
);
3301 radeon_audio_fini(rdev
);
3303 r600_irq_fini(rdev
);
3304 if (rdev
->has_uvd
) {
3305 uvd_v1_0_fini(rdev
);
3306 radeon_uvd_fini(rdev
);
3308 radeon_wb_fini(rdev
);
3309 radeon_ib_pool_fini(rdev
);
3310 radeon_irq_kms_fini(rdev
);
3311 r600_pcie_gart_fini(rdev
);
3312 r600_vram_scratch_fini(rdev
);
3313 radeon_agp_fini(rdev
);
3314 radeon_gem_fini(rdev
);
3315 radeon_fence_driver_fini(rdev
);
3316 radeon_bo_fini(rdev
);
3317 radeon_atombios_fini(rdev
);
3326 void r600_ring_ib_execute(struct radeon_device
*rdev
, struct radeon_ib
*ib
)
3328 struct radeon_ring
*ring
= &rdev
->ring
[ib
->ring
];
3331 if (ring
->rptr_save_reg
) {
3332 next_rptr
= ring
->wptr
+ 3 + 4;
3333 radeon_ring_write(ring
, PACKET3(PACKET3_SET_CONFIG_REG
, 1));
3334 radeon_ring_write(ring
, ((ring
->rptr_save_reg
-
3335 PACKET3_SET_CONFIG_REG_OFFSET
) >> 2));
3336 radeon_ring_write(ring
, next_rptr
);
3337 } else if (rdev
->wb
.enabled
) {
3338 next_rptr
= ring
->wptr
+ 5 + 4;
3339 radeon_ring_write(ring
, PACKET3(PACKET3_MEM_WRITE
, 3));
3340 radeon_ring_write(ring
, ring
->next_rptr_gpu_addr
& 0xfffffffc);
3341 radeon_ring_write(ring
, (upper_32_bits(ring
->next_rptr_gpu_addr
) & 0xff) | (1 << 18));
3342 radeon_ring_write(ring
, next_rptr
);
3343 radeon_ring_write(ring
, 0);
3346 radeon_ring_write(ring
, PACKET3(PACKET3_INDIRECT_BUFFER
, 2));
3347 radeon_ring_write(ring
,
3351 (ib
->gpu_addr
& 0xFFFFFFFC));
3352 radeon_ring_write(ring
, upper_32_bits(ib
->gpu_addr
) & 0xFF);
3353 radeon_ring_write(ring
, ib
->length_dw
);
3356 int r600_ib_test(struct radeon_device
*rdev
, struct radeon_ring
*ring
)
3358 struct radeon_ib ib
;
3364 r
= radeon_scratch_get(rdev
, &scratch
);
3366 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r
);
3369 WREG32(scratch
, 0xCAFEDEAD);
3370 r
= radeon_ib_get(rdev
, ring
->idx
, &ib
, NULL
, 256);
3372 DRM_ERROR("radeon: failed to get ib (%d).\n", r
);
3375 ib
.ptr
[0] = PACKET3(PACKET3_SET_CONFIG_REG
, 1);
3376 ib
.ptr
[1] = ((scratch
- PACKET3_SET_CONFIG_REG_OFFSET
) >> 2);
3377 ib
.ptr
[2] = 0xDEADBEEF;
3379 r
= radeon_ib_schedule(rdev
, &ib
, NULL
, false);
3381 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r
);
3384 r
= radeon_fence_wait(ib
.fence
, false);
3386 DRM_ERROR("radeon: fence wait failed (%d).\n", r
);
3389 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
3390 tmp
= RREG32(scratch
);
3391 if (tmp
== 0xDEADBEEF)
3395 if (i
< rdev
->usec_timeout
) {
3396 DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib
.fence
->ring
, i
);
3398 DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
3403 radeon_ib_free(rdev
, &ib
);
3405 radeon_scratch_free(rdev
, scratch
);
3412 * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
3413 * the same as the CP ring buffer, but in reverse. Rather than the CPU
3414 * writing to the ring and the GPU consuming, the GPU writes to the ring
3415 * and host consumes. As the host irq handler processes interrupts, it
3416 * increments the rptr. When the rptr catches up with the wptr, all the
3417 * current interrupts have been processed.
3420 void r600_ih_ring_init(struct radeon_device
*rdev
, unsigned ring_size
)
3424 /* Align ring size */
3425 rb_bufsz
= order_base_2(ring_size
/ 4);
3426 ring_size
= (1 << rb_bufsz
) * 4;
3427 rdev
->ih
.ring_size
= ring_size
;
3428 rdev
->ih
.ptr_mask
= rdev
->ih
.ring_size
- 1;
3432 int r600_ih_ring_alloc(struct radeon_device
*rdev
)
3436 /* Allocate ring buffer */
3437 if (rdev
->ih
.ring_obj
== NULL
) {
3438 r
= radeon_bo_create(rdev
, rdev
->ih
.ring_size
,
3440 RADEON_GEM_DOMAIN_GTT
, 0,
3441 NULL
, NULL
, &rdev
->ih
.ring_obj
);
3443 DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r
);
3446 r
= radeon_bo_reserve(rdev
->ih
.ring_obj
, false);
3447 if (unlikely(r
!= 0))
3449 r
= radeon_bo_pin(rdev
->ih
.ring_obj
,
3450 RADEON_GEM_DOMAIN_GTT
,
3451 &rdev
->ih
.gpu_addr
);
3453 radeon_bo_unreserve(rdev
->ih
.ring_obj
);
3454 DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r
);
3457 r
= radeon_bo_kmap(rdev
->ih
.ring_obj
,
3458 (void **)&rdev
->ih
.ring
);
3459 radeon_bo_unreserve(rdev
->ih
.ring_obj
);
3461 DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r
);
3468 void r600_ih_ring_fini(struct radeon_device
*rdev
)
3471 if (rdev
->ih
.ring_obj
) {
3472 r
= radeon_bo_reserve(rdev
->ih
.ring_obj
, false);
3473 if (likely(r
== 0)) {
3474 radeon_bo_kunmap(rdev
->ih
.ring_obj
);
3475 radeon_bo_unpin(rdev
->ih
.ring_obj
);
3476 radeon_bo_unreserve(rdev
->ih
.ring_obj
);
3478 radeon_bo_unref(&rdev
->ih
.ring_obj
);
3479 rdev
->ih
.ring
= NULL
;
3480 rdev
->ih
.ring_obj
= NULL
;
3484 void r600_rlc_stop(struct radeon_device
*rdev
)
3487 if ((rdev
->family
>= CHIP_RV770
) &&
3488 (rdev
->family
<= CHIP_RV740
)) {
3489 /* r7xx asics need to soft reset RLC before halting */
3490 WREG32(SRBM_SOFT_RESET
, SOFT_RESET_RLC
);
3491 RREG32(SRBM_SOFT_RESET
);
3493 WREG32(SRBM_SOFT_RESET
, 0);
3494 RREG32(SRBM_SOFT_RESET
);
3497 WREG32(RLC_CNTL
, 0);
3500 static void r600_rlc_start(struct radeon_device
*rdev
)
3502 WREG32(RLC_CNTL
, RLC_ENABLE
);
3505 static int r600_rlc_resume(struct radeon_device
*rdev
)
3508 const __be32
*fw_data
;
3513 r600_rlc_stop(rdev
);
3515 WREG32(RLC_HB_CNTL
, 0);
3517 WREG32(RLC_HB_BASE
, 0);
3518 WREG32(RLC_HB_RPTR
, 0);
3519 WREG32(RLC_HB_WPTR
, 0);
3520 WREG32(RLC_HB_WPTR_LSB_ADDR
, 0);
3521 WREG32(RLC_HB_WPTR_MSB_ADDR
, 0);
3522 WREG32(RLC_MC_CNTL
, 0);
3523 WREG32(RLC_UCODE_CNTL
, 0);
3525 fw_data
= (const __be32
*)rdev
->rlc_fw
->data
;
3526 if (rdev
->family
>= CHIP_RV770
) {
3527 for (i
= 0; i
< R700_RLC_UCODE_SIZE
; i
++) {
3528 WREG32(RLC_UCODE_ADDR
, i
);
3529 WREG32(RLC_UCODE_DATA
, be32_to_cpup(fw_data
++));
3532 for (i
= 0; i
< R600_RLC_UCODE_SIZE
; i
++) {
3533 WREG32(RLC_UCODE_ADDR
, i
);
3534 WREG32(RLC_UCODE_DATA
, be32_to_cpup(fw_data
++));
3537 WREG32(RLC_UCODE_ADDR
, 0);
3539 r600_rlc_start(rdev
);
3544 static void r600_enable_interrupts(struct radeon_device
*rdev
)
3546 u32 ih_cntl
= RREG32(IH_CNTL
);
3547 u32 ih_rb_cntl
= RREG32(IH_RB_CNTL
);
3549 ih_cntl
|= ENABLE_INTR
;
3550 ih_rb_cntl
|= IH_RB_ENABLE
;
3551 WREG32(IH_CNTL
, ih_cntl
);
3552 WREG32(IH_RB_CNTL
, ih_rb_cntl
);
3553 rdev
->ih
.enabled
= true;
3556 void r600_disable_interrupts(struct radeon_device
*rdev
)
3558 u32 ih_rb_cntl
= RREG32(IH_RB_CNTL
);
3559 u32 ih_cntl
= RREG32(IH_CNTL
);
3561 ih_rb_cntl
&= ~IH_RB_ENABLE
;
3562 ih_cntl
&= ~ENABLE_INTR
;
3563 WREG32(IH_RB_CNTL
, ih_rb_cntl
);
3564 WREG32(IH_CNTL
, ih_cntl
);
3565 /* set rptr, wptr to 0 */
3566 WREG32(IH_RB_RPTR
, 0);
3567 WREG32(IH_RB_WPTR
, 0);
3568 rdev
->ih
.enabled
= false;
3572 static void r600_disable_interrupt_state(struct radeon_device
*rdev
)
3576 WREG32(CP_INT_CNTL
, CNTX_BUSY_INT_ENABLE
| CNTX_EMPTY_INT_ENABLE
);
3577 tmp
= RREG32(DMA_CNTL
) & ~TRAP_ENABLE
;
3578 WREG32(DMA_CNTL
, tmp
);
3579 WREG32(GRBM_INT_CNTL
, 0);
3580 WREG32(DxMODE_INT_MASK
, 0);
3581 WREG32(D1GRPH_INTERRUPT_CONTROL
, 0);
3582 WREG32(D2GRPH_INTERRUPT_CONTROL
, 0);
3583 if (ASIC_IS_DCE3(rdev
)) {
3584 WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL
, 0);
3585 WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL
, 0);
3586 tmp
= RREG32(DC_HPD1_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
3587 WREG32(DC_HPD1_INT_CONTROL
, tmp
);
3588 tmp
= RREG32(DC_HPD2_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
3589 WREG32(DC_HPD2_INT_CONTROL
, tmp
);
3590 tmp
= RREG32(DC_HPD3_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
3591 WREG32(DC_HPD3_INT_CONTROL
, tmp
);
3592 tmp
= RREG32(DC_HPD4_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
3593 WREG32(DC_HPD4_INT_CONTROL
, tmp
);
3594 if (ASIC_IS_DCE32(rdev
)) {
3595 tmp
= RREG32(DC_HPD5_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
3596 WREG32(DC_HPD5_INT_CONTROL
, tmp
);
3597 tmp
= RREG32(DC_HPD6_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
3598 WREG32(DC_HPD6_INT_CONTROL
, tmp
);
3599 tmp
= RREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET0
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
3600 WREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET0
, tmp
);
3601 tmp
= RREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET1
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
3602 WREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET1
, tmp
);
3604 tmp
= RREG32(HDMI0_AUDIO_PACKET_CONTROL
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
3605 WREG32(HDMI0_AUDIO_PACKET_CONTROL
, tmp
);
3606 tmp
= RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
3607 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL
, tmp
);
3610 WREG32(DACA_AUTODETECT_INT_CONTROL
, 0);
3611 WREG32(DACB_AUTODETECT_INT_CONTROL
, 0);
3612 tmp
= RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
) & DC_HOT_PLUG_DETECTx_INT_POLARITY
;
3613 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
, tmp
);
3614 tmp
= RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
) & DC_HOT_PLUG_DETECTx_INT_POLARITY
;
3615 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
, tmp
);
3616 tmp
= RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
) & DC_HOT_PLUG_DETECTx_INT_POLARITY
;
3617 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
, tmp
);
3618 tmp
= RREG32(HDMI0_AUDIO_PACKET_CONTROL
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
3619 WREG32(HDMI0_AUDIO_PACKET_CONTROL
, tmp
);
3620 tmp
= RREG32(HDMI1_AUDIO_PACKET_CONTROL
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
3621 WREG32(HDMI1_AUDIO_PACKET_CONTROL
, tmp
);
3625 int r600_irq_init(struct radeon_device
*rdev
)
3629 u32 interrupt_cntl
, ih_cntl
, ih_rb_cntl
;
3632 ret
= r600_ih_ring_alloc(rdev
);
3637 r600_disable_interrupts(rdev
);
3640 if (rdev
->family
>= CHIP_CEDAR
)
3641 ret
= evergreen_rlc_resume(rdev
);
3643 ret
= r600_rlc_resume(rdev
);
3645 r600_ih_ring_fini(rdev
);
3649 /* setup interrupt control */
3650 /* set dummy read address to ring address */
3651 WREG32(INTERRUPT_CNTL2
, rdev
->ih
.gpu_addr
>> 8);
3652 interrupt_cntl
= RREG32(INTERRUPT_CNTL
);
3653 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
3654 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
3656 interrupt_cntl
&= ~IH_DUMMY_RD_OVERRIDE
;
3657 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
3658 interrupt_cntl
&= ~IH_REQ_NONSNOOP_EN
;
3659 WREG32(INTERRUPT_CNTL
, interrupt_cntl
);
3661 WREG32(IH_RB_BASE
, rdev
->ih
.gpu_addr
>> 8);
3662 rb_bufsz
= order_base_2(rdev
->ih
.ring_size
/ 4);
3664 ih_rb_cntl
= (IH_WPTR_OVERFLOW_ENABLE
|
3665 IH_WPTR_OVERFLOW_CLEAR
|
3668 if (rdev
->wb
.enabled
)
3669 ih_rb_cntl
|= IH_WPTR_WRITEBACK_ENABLE
;
3671 /* set the writeback address whether it's enabled or not */
3672 WREG32(IH_RB_WPTR_ADDR_LO
, (rdev
->wb
.gpu_addr
+ R600_WB_IH_WPTR_OFFSET
) & 0xFFFFFFFC);
3673 WREG32(IH_RB_WPTR_ADDR_HI
, upper_32_bits(rdev
->wb
.gpu_addr
+ R600_WB_IH_WPTR_OFFSET
) & 0xFF);
3675 WREG32(IH_RB_CNTL
, ih_rb_cntl
);
3677 /* set rptr, wptr to 0 */
3678 WREG32(IH_RB_RPTR
, 0);
3679 WREG32(IH_RB_WPTR
, 0);
3681 /* Default settings for IH_CNTL (disabled at first) */
3682 ih_cntl
= MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
3683 /* RPTR_REARM only works if msi's are enabled */
3684 if (rdev
->msi_enabled
)
3685 ih_cntl
|= RPTR_REARM
;
3686 WREG32(IH_CNTL
, ih_cntl
);
3688 /* force the active interrupt state to all disabled */
3689 if (rdev
->family
>= CHIP_CEDAR
)
3690 evergreen_disable_interrupt_state(rdev
);
3692 r600_disable_interrupt_state(rdev
);
3694 /* at this point everything should be setup correctly to enable master */
3695 pci_set_master(rdev
->pdev
);
3698 r600_enable_interrupts(rdev
);
3703 void r600_irq_suspend(struct radeon_device
*rdev
)
3705 r600_irq_disable(rdev
);
3706 r600_rlc_stop(rdev
);
3709 void r600_irq_fini(struct radeon_device
*rdev
)
3711 r600_irq_suspend(rdev
);
3712 r600_ih_ring_fini(rdev
);
3715 int r600_irq_set(struct radeon_device
*rdev
)
3717 u32 cp_int_cntl
= CNTX_BUSY_INT_ENABLE
| CNTX_EMPTY_INT_ENABLE
;
3719 u32 hpd1
, hpd2
, hpd3
, hpd4
= 0, hpd5
= 0, hpd6
= 0;
3720 u32 grbm_int_cntl
= 0;
3723 u32 thermal_int
= 0;
3725 if (!rdev
->irq
.installed
) {
3726 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
3729 /* don't enable anything if the ih is disabled */
3730 if (!rdev
->ih
.enabled
) {
3731 r600_disable_interrupts(rdev
);
3732 /* force the active interrupt state to all disabled */
3733 r600_disable_interrupt_state(rdev
);
3737 if (ASIC_IS_DCE3(rdev
)) {
3738 hpd1
= RREG32(DC_HPD1_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
3739 hpd2
= RREG32(DC_HPD2_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
3740 hpd3
= RREG32(DC_HPD3_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
3741 hpd4
= RREG32(DC_HPD4_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
3742 if (ASIC_IS_DCE32(rdev
)) {
3743 hpd5
= RREG32(DC_HPD5_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
3744 hpd6
= RREG32(DC_HPD6_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
3745 hdmi0
= RREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET0
) & ~AFMT_AZ_FORMAT_WTRIG_MASK
;
3746 hdmi1
= RREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET1
) & ~AFMT_AZ_FORMAT_WTRIG_MASK
;
3748 hdmi0
= RREG32(HDMI0_AUDIO_PACKET_CONTROL
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
3749 hdmi1
= RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
3752 hpd1
= RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
3753 hpd2
= RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
3754 hpd3
= RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
3755 hdmi0
= RREG32(HDMI0_AUDIO_PACKET_CONTROL
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
3756 hdmi1
= RREG32(HDMI1_AUDIO_PACKET_CONTROL
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
3759 dma_cntl
= RREG32(DMA_CNTL
) & ~TRAP_ENABLE
;
3761 if ((rdev
->family
> CHIP_R600
) && (rdev
->family
< CHIP_RV770
)) {
3762 thermal_int
= RREG32(CG_THERMAL_INT
) &
3763 ~(THERM_INT_MASK_HIGH
| THERM_INT_MASK_LOW
);
3764 } else if (rdev
->family
>= CHIP_RV770
) {
3765 thermal_int
= RREG32(RV770_CG_THERMAL_INT
) &
3766 ~(THERM_INT_MASK_HIGH
| THERM_INT_MASK_LOW
);
3768 if (rdev
->irq
.dpm_thermal
) {
3769 DRM_DEBUG("dpm thermal\n");
3770 thermal_int
|= THERM_INT_MASK_HIGH
| THERM_INT_MASK_LOW
;
3773 if (atomic_read(&rdev
->irq
.ring_int
[RADEON_RING_TYPE_GFX_INDEX
])) {
3774 DRM_DEBUG("r600_irq_set: sw int\n");
3775 cp_int_cntl
|= RB_INT_ENABLE
;
3776 cp_int_cntl
|= TIME_STAMP_INT_ENABLE
;
3779 if (atomic_read(&rdev
->irq
.ring_int
[R600_RING_TYPE_DMA_INDEX
])) {
3780 DRM_DEBUG("r600_irq_set: sw int dma\n");
3781 dma_cntl
|= TRAP_ENABLE
;
3784 if (rdev
->irq
.crtc_vblank_int
[0] ||
3785 atomic_read(&rdev
->irq
.pflip
[0])) {
3786 DRM_DEBUG("r600_irq_set: vblank 0\n");
3787 mode_int
|= D1MODE_VBLANK_INT_MASK
;
3789 if (rdev
->irq
.crtc_vblank_int
[1] ||
3790 atomic_read(&rdev
->irq
.pflip
[1])) {
3791 DRM_DEBUG("r600_irq_set: vblank 1\n");
3792 mode_int
|= D2MODE_VBLANK_INT_MASK
;
3794 if (rdev
->irq
.hpd
[0]) {
3795 DRM_DEBUG("r600_irq_set: hpd 1\n");
3796 hpd1
|= DC_HPDx_INT_EN
;
3798 if (rdev
->irq
.hpd
[1]) {
3799 DRM_DEBUG("r600_irq_set: hpd 2\n");
3800 hpd2
|= DC_HPDx_INT_EN
;
3802 if (rdev
->irq
.hpd
[2]) {
3803 DRM_DEBUG("r600_irq_set: hpd 3\n");
3804 hpd3
|= DC_HPDx_INT_EN
;
3806 if (rdev
->irq
.hpd
[3]) {
3807 DRM_DEBUG("r600_irq_set: hpd 4\n");
3808 hpd4
|= DC_HPDx_INT_EN
;
3810 if (rdev
->irq
.hpd
[4]) {
3811 DRM_DEBUG("r600_irq_set: hpd 5\n");
3812 hpd5
|= DC_HPDx_INT_EN
;
3814 if (rdev
->irq
.hpd
[5]) {
3815 DRM_DEBUG("r600_irq_set: hpd 6\n");
3816 hpd6
|= DC_HPDx_INT_EN
;
3818 if (rdev
->irq
.afmt
[0]) {
3819 DRM_DEBUG("r600_irq_set: hdmi 0\n");
3820 hdmi0
|= HDMI0_AZ_FORMAT_WTRIG_MASK
;
3822 if (rdev
->irq
.afmt
[1]) {
3823 DRM_DEBUG("r600_irq_set: hdmi 0\n");
3824 hdmi1
|= HDMI0_AZ_FORMAT_WTRIG_MASK
;
3827 WREG32(CP_INT_CNTL
, cp_int_cntl
);
3828 WREG32(DMA_CNTL
, dma_cntl
);
3829 WREG32(DxMODE_INT_MASK
, mode_int
);
3830 WREG32(D1GRPH_INTERRUPT_CONTROL
, DxGRPH_PFLIP_INT_MASK
);
3831 WREG32(D2GRPH_INTERRUPT_CONTROL
, DxGRPH_PFLIP_INT_MASK
);
3832 WREG32(GRBM_INT_CNTL
, grbm_int_cntl
);
3833 if (ASIC_IS_DCE3(rdev
)) {
3834 WREG32(DC_HPD1_INT_CONTROL
, hpd1
);
3835 WREG32(DC_HPD2_INT_CONTROL
, hpd2
);
3836 WREG32(DC_HPD3_INT_CONTROL
, hpd3
);
3837 WREG32(DC_HPD4_INT_CONTROL
, hpd4
);
3838 if (ASIC_IS_DCE32(rdev
)) {
3839 WREG32(DC_HPD5_INT_CONTROL
, hpd5
);
3840 WREG32(DC_HPD6_INT_CONTROL
, hpd6
);
3841 WREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET0
, hdmi0
);
3842 WREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET1
, hdmi1
);
3844 WREG32(HDMI0_AUDIO_PACKET_CONTROL
, hdmi0
);
3845 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL
, hdmi1
);
3848 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
, hpd1
);
3849 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
, hpd2
);
3850 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
, hpd3
);
3851 WREG32(HDMI0_AUDIO_PACKET_CONTROL
, hdmi0
);
3852 WREG32(HDMI1_AUDIO_PACKET_CONTROL
, hdmi1
);
3854 if ((rdev
->family
> CHIP_R600
) && (rdev
->family
< CHIP_RV770
)) {
3855 WREG32(CG_THERMAL_INT
, thermal_int
);
3856 } else if (rdev
->family
>= CHIP_RV770
) {
3857 WREG32(RV770_CG_THERMAL_INT
, thermal_int
);
3861 RREG32(R_000E50_SRBM_STATUS
);
3866 static void r600_irq_ack(struct radeon_device
*rdev
)
3870 if (ASIC_IS_DCE3(rdev
)) {
3871 rdev
->irq
.stat_regs
.r600
.disp_int
= RREG32(DCE3_DISP_INTERRUPT_STATUS
);
3872 rdev
->irq
.stat_regs
.r600
.disp_int_cont
= RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE
);
3873 rdev
->irq
.stat_regs
.r600
.disp_int_cont2
= RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2
);
3874 if (ASIC_IS_DCE32(rdev
)) {
3875 rdev
->irq
.stat_regs
.r600
.hdmi0_status
= RREG32(AFMT_STATUS
+ DCE3_HDMI_OFFSET0
);
3876 rdev
->irq
.stat_regs
.r600
.hdmi1_status
= RREG32(AFMT_STATUS
+ DCE3_HDMI_OFFSET1
);
3878 rdev
->irq
.stat_regs
.r600
.hdmi0_status
= RREG32(HDMI0_STATUS
);
3879 rdev
->irq
.stat_regs
.r600
.hdmi1_status
= RREG32(DCE3_HDMI1_STATUS
);
3882 rdev
->irq
.stat_regs
.r600
.disp_int
= RREG32(DISP_INTERRUPT_STATUS
);
3883 rdev
->irq
.stat_regs
.r600
.disp_int_cont
= RREG32(DISP_INTERRUPT_STATUS_CONTINUE
);
3884 rdev
->irq
.stat_regs
.r600
.disp_int_cont2
= 0;
3885 rdev
->irq
.stat_regs
.r600
.hdmi0_status
= RREG32(HDMI0_STATUS
);
3886 rdev
->irq
.stat_regs
.r600
.hdmi1_status
= RREG32(HDMI1_STATUS
);
3888 rdev
->irq
.stat_regs
.r600
.d1grph_int
= RREG32(D1GRPH_INTERRUPT_STATUS
);
3889 rdev
->irq
.stat_regs
.r600
.d2grph_int
= RREG32(D2GRPH_INTERRUPT_STATUS
);
3891 if (rdev
->irq
.stat_regs
.r600
.d1grph_int
& DxGRPH_PFLIP_INT_OCCURRED
)
3892 WREG32(D1GRPH_INTERRUPT_STATUS
, DxGRPH_PFLIP_INT_CLEAR
);
3893 if (rdev
->irq
.stat_regs
.r600
.d2grph_int
& DxGRPH_PFLIP_INT_OCCURRED
)
3894 WREG32(D2GRPH_INTERRUPT_STATUS
, DxGRPH_PFLIP_INT_CLEAR
);
3895 if (rdev
->irq
.stat_regs
.r600
.disp_int
& LB_D1_VBLANK_INTERRUPT
)
3896 WREG32(D1MODE_VBLANK_STATUS
, DxMODE_VBLANK_ACK
);
3897 if (rdev
->irq
.stat_regs
.r600
.disp_int
& LB_D1_VLINE_INTERRUPT
)
3898 WREG32(D1MODE_VLINE_STATUS
, DxMODE_VLINE_ACK
);
3899 if (rdev
->irq
.stat_regs
.r600
.disp_int
& LB_D2_VBLANK_INTERRUPT
)
3900 WREG32(D2MODE_VBLANK_STATUS
, DxMODE_VBLANK_ACK
);
3901 if (rdev
->irq
.stat_regs
.r600
.disp_int
& LB_D2_VLINE_INTERRUPT
)
3902 WREG32(D2MODE_VLINE_STATUS
, DxMODE_VLINE_ACK
);
3903 if (rdev
->irq
.stat_regs
.r600
.disp_int
& DC_HPD1_INTERRUPT
) {
3904 if (ASIC_IS_DCE3(rdev
)) {
3905 tmp
= RREG32(DC_HPD1_INT_CONTROL
);
3906 tmp
|= DC_HPDx_INT_ACK
;
3907 WREG32(DC_HPD1_INT_CONTROL
, tmp
);
3909 tmp
= RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
);
3910 tmp
|= DC_HPDx_INT_ACK
;
3911 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
, tmp
);
3914 if (rdev
->irq
.stat_regs
.r600
.disp_int
& DC_HPD2_INTERRUPT
) {
3915 if (ASIC_IS_DCE3(rdev
)) {
3916 tmp
= RREG32(DC_HPD2_INT_CONTROL
);
3917 tmp
|= DC_HPDx_INT_ACK
;
3918 WREG32(DC_HPD2_INT_CONTROL
, tmp
);
3920 tmp
= RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
);
3921 tmp
|= DC_HPDx_INT_ACK
;
3922 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
, tmp
);
3925 if (rdev
->irq
.stat_regs
.r600
.disp_int_cont
& DC_HPD3_INTERRUPT
) {
3926 if (ASIC_IS_DCE3(rdev
)) {
3927 tmp
= RREG32(DC_HPD3_INT_CONTROL
);
3928 tmp
|= DC_HPDx_INT_ACK
;
3929 WREG32(DC_HPD3_INT_CONTROL
, tmp
);
3931 tmp
= RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
);
3932 tmp
|= DC_HPDx_INT_ACK
;
3933 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
, tmp
);
3936 if (rdev
->irq
.stat_regs
.r600
.disp_int_cont
& DC_HPD4_INTERRUPT
) {
3937 tmp
= RREG32(DC_HPD4_INT_CONTROL
);
3938 tmp
|= DC_HPDx_INT_ACK
;
3939 WREG32(DC_HPD4_INT_CONTROL
, tmp
);
3941 if (ASIC_IS_DCE32(rdev
)) {
3942 if (rdev
->irq
.stat_regs
.r600
.disp_int_cont2
& DC_HPD5_INTERRUPT
) {
3943 tmp
= RREG32(DC_HPD5_INT_CONTROL
);
3944 tmp
|= DC_HPDx_INT_ACK
;
3945 WREG32(DC_HPD5_INT_CONTROL
, tmp
);
3947 if (rdev
->irq
.stat_regs
.r600
.disp_int_cont2
& DC_HPD6_INTERRUPT
) {
3948 tmp
= RREG32(DC_HPD5_INT_CONTROL
);
3949 tmp
|= DC_HPDx_INT_ACK
;
3950 WREG32(DC_HPD6_INT_CONTROL
, tmp
);
3952 if (rdev
->irq
.stat_regs
.r600
.hdmi0_status
& AFMT_AZ_FORMAT_WTRIG
) {
3953 tmp
= RREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET0
);
3954 tmp
|= AFMT_AZ_FORMAT_WTRIG_ACK
;
3955 WREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET0
, tmp
);
3957 if (rdev
->irq
.stat_regs
.r600
.hdmi1_status
& AFMT_AZ_FORMAT_WTRIG
) {
3958 tmp
= RREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET1
);
3959 tmp
|= AFMT_AZ_FORMAT_WTRIG_ACK
;
3960 WREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET1
, tmp
);
3963 if (rdev
->irq
.stat_regs
.r600
.hdmi0_status
& HDMI0_AZ_FORMAT_WTRIG
) {
3964 tmp
= RREG32(HDMI0_AUDIO_PACKET_CONTROL
);
3965 tmp
|= HDMI0_AZ_FORMAT_WTRIG_ACK
;
3966 WREG32(HDMI0_AUDIO_PACKET_CONTROL
, tmp
);
3968 if (rdev
->irq
.stat_regs
.r600
.hdmi1_status
& HDMI0_AZ_FORMAT_WTRIG
) {
3969 if (ASIC_IS_DCE3(rdev
)) {
3970 tmp
= RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL
);
3971 tmp
|= HDMI0_AZ_FORMAT_WTRIG_ACK
;
3972 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL
, tmp
);
3974 tmp
= RREG32(HDMI1_AUDIO_PACKET_CONTROL
);
3975 tmp
|= HDMI0_AZ_FORMAT_WTRIG_ACK
;
3976 WREG32(HDMI1_AUDIO_PACKET_CONTROL
, tmp
);
3982 void r600_irq_disable(struct radeon_device
*rdev
)
3984 r600_disable_interrupts(rdev
);
3985 /* Wait and acknowledge irq */
3988 r600_disable_interrupt_state(rdev
);
3991 static u32
r600_get_ih_wptr(struct radeon_device
*rdev
)
3995 if (rdev
->wb
.enabled
)
3996 wptr
= le32_to_cpu(rdev
->wb
.wb
[R600_WB_IH_WPTR_OFFSET
/4]);
3998 wptr
= RREG32(IH_RB_WPTR
);
4000 if (wptr
& RB_OVERFLOW
) {
4001 wptr
&= ~RB_OVERFLOW
;
4002 /* When a ring buffer overflow happen start parsing interrupt
4003 * from the last not overwritten vector (wptr + 16). Hopefully
4004 * this should allow us to catchup.
4006 dev_warn(rdev
->dev
, "IH ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n",
4007 wptr
, rdev
->ih
.rptr
, (wptr
+ 16) & rdev
->ih
.ptr_mask
);
4008 rdev
->ih
.rptr
= (wptr
+ 16) & rdev
->ih
.ptr_mask
;
4009 tmp
= RREG32(IH_RB_CNTL
);
4010 tmp
|= IH_WPTR_OVERFLOW_CLEAR
;
4011 WREG32(IH_RB_CNTL
, tmp
);
4013 return (wptr
& rdev
->ih
.ptr_mask
);
4017 * Each IV ring entry is 128 bits:
4018 * [7:0] - interrupt source id
4020 * [59:32] - interrupt source data
4021 * [127:60] - reserved
4023 * The basic interrupt vector entries
4024 * are decoded as follows:
4025 * src_id src_data description
4030 * 19 0 FP Hot plug detection A
4031 * 19 1 FP Hot plug detection B
4032 * 19 2 DAC A auto-detection
4033 * 19 3 DAC B auto-detection
4039 * 181 - EOP Interrupt
4042 * Note, these are based on r600 and may need to be
4043 * adjusted or added to on newer asics
4046 int r600_irq_process(struct radeon_device
*rdev
)
4050 u32 src_id
, src_data
;
4052 bool queue_hotplug
= false;
4053 bool queue_hdmi
= false;
4054 bool queue_thermal
= false;
4056 if (!rdev
->ih
.enabled
|| rdev
->shutdown
)
4059 /* No MSIs, need a dummy read to flush PCI DMAs */
4060 if (!rdev
->msi_enabled
)
4063 wptr
= r600_get_ih_wptr(rdev
);
4066 /* is somebody else already processing irqs? */
4067 if (atomic_xchg(&rdev
->ih
.lock
, 1))
4070 rptr
= rdev
->ih
.rptr
;
4071 DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr
, wptr
);
4073 /* Order reading of wptr vs. reading of IH ring data */
4076 /* display interrupts */
4079 while (rptr
!= wptr
) {
4080 /* wptr/rptr are in bytes! */
4081 ring_index
= rptr
/ 4;
4082 src_id
= le32_to_cpu(rdev
->ih
.ring
[ring_index
]) & 0xff;
4083 src_data
= le32_to_cpu(rdev
->ih
.ring
[ring_index
+ 1]) & 0xfffffff;
4086 case 1: /* D1 vblank/vline */
4088 case 0: /* D1 vblank */
4089 if (!(rdev
->irq
.stat_regs
.r600
.disp_int
& LB_D1_VBLANK_INTERRUPT
))
4090 DRM_DEBUG("IH: D1 vblank - IH event w/o asserted irq bit?\n");
4092 if (rdev
->irq
.crtc_vblank_int
[0]) {
4093 drm_handle_vblank(rdev
->ddev
, 0);
4094 rdev
->pm
.vblank_sync
= true;
4095 wake_up(&rdev
->irq
.vblank_queue
);
4097 if (atomic_read(&rdev
->irq
.pflip
[0]))
4098 radeon_crtc_handle_vblank(rdev
, 0);
4099 rdev
->irq
.stat_regs
.r600
.disp_int
&= ~LB_D1_VBLANK_INTERRUPT
;
4100 DRM_DEBUG("IH: D1 vblank\n");
4103 case 1: /* D1 vline */
4104 if (!(rdev
->irq
.stat_regs
.r600
.disp_int
& LB_D1_VLINE_INTERRUPT
))
4105 DRM_DEBUG("IH: D1 vline - IH event w/o asserted irq bit?\n");
4107 rdev
->irq
.stat_regs
.r600
.disp_int
&= ~LB_D1_VLINE_INTERRUPT
;
4108 DRM_DEBUG("IH: D1 vline\n");
4112 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id
, src_data
);
4116 case 5: /* D2 vblank/vline */
4118 case 0: /* D2 vblank */
4119 if (!(rdev
->irq
.stat_regs
.r600
.disp_int
& LB_D2_VBLANK_INTERRUPT
))
4120 DRM_DEBUG("IH: D2 vblank - IH event w/o asserted irq bit?\n");
4122 if (rdev
->irq
.crtc_vblank_int
[1]) {
4123 drm_handle_vblank(rdev
->ddev
, 1);
4124 rdev
->pm
.vblank_sync
= true;
4125 wake_up(&rdev
->irq
.vblank_queue
);
4127 if (atomic_read(&rdev
->irq
.pflip
[1]))
4128 radeon_crtc_handle_vblank(rdev
, 1);
4129 rdev
->irq
.stat_regs
.r600
.disp_int
&= ~LB_D2_VBLANK_INTERRUPT
;
4130 DRM_DEBUG("IH: D2 vblank\n");
4133 case 1: /* D1 vline */
4134 if (!(rdev
->irq
.stat_regs
.r600
.disp_int
& LB_D2_VLINE_INTERRUPT
))
4135 DRM_DEBUG("IH: D2 vline - IH event w/o asserted irq bit?\n");
4137 rdev
->irq
.stat_regs
.r600
.disp_int
&= ~LB_D2_VLINE_INTERRUPT
;
4138 DRM_DEBUG("IH: D2 vline\n");
4142 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id
, src_data
);
4146 case 9: /* D1 pflip */
4147 DRM_DEBUG("IH: D1 flip\n");
4148 if (radeon_use_pflipirq
> 0)
4149 radeon_crtc_handle_flip(rdev
, 0);
4151 case 11: /* D2 pflip */
4152 DRM_DEBUG("IH: D2 flip\n");
4153 if (radeon_use_pflipirq
> 0)
4154 radeon_crtc_handle_flip(rdev
, 1);
4156 case 19: /* HPD/DAC hotplug */
4159 if (!(rdev
->irq
.stat_regs
.r600
.disp_int
& DC_HPD1_INTERRUPT
))
4160 DRM_DEBUG("IH: HPD1 - IH event w/o asserted irq bit?\n");
4162 rdev
->irq
.stat_regs
.r600
.disp_int
&= ~DC_HPD1_INTERRUPT
;
4163 queue_hotplug
= true;
4164 DRM_DEBUG("IH: HPD1\n");
4167 if (!(rdev
->irq
.stat_regs
.r600
.disp_int
& DC_HPD2_INTERRUPT
))
4168 DRM_DEBUG("IH: HPD2 - IH event w/o asserted irq bit?\n");
4170 rdev
->irq
.stat_regs
.r600
.disp_int
&= ~DC_HPD2_INTERRUPT
;
4171 queue_hotplug
= true;
4172 DRM_DEBUG("IH: HPD2\n");
4175 if (!(rdev
->irq
.stat_regs
.r600
.disp_int_cont
& DC_HPD3_INTERRUPT
))
4176 DRM_DEBUG("IH: HPD3 - IH event w/o asserted irq bit?\n");
4178 rdev
->irq
.stat_regs
.r600
.disp_int_cont
&= ~DC_HPD3_INTERRUPT
;
4179 queue_hotplug
= true;
4180 DRM_DEBUG("IH: HPD3\n");
4183 if (!(rdev
->irq
.stat_regs
.r600
.disp_int_cont
& DC_HPD4_INTERRUPT
))
4184 DRM_DEBUG("IH: HPD4 - IH event w/o asserted irq bit?\n");
4186 rdev
->irq
.stat_regs
.r600
.disp_int_cont
&= ~DC_HPD4_INTERRUPT
;
4187 queue_hotplug
= true;
4188 DRM_DEBUG("IH: HPD4\n");
4191 if (!(rdev
->irq
.stat_regs
.r600
.disp_int_cont2
& DC_HPD5_INTERRUPT
))
4192 DRM_DEBUG("IH: HPD5 - IH event w/o asserted irq bit?\n");
4194 rdev
->irq
.stat_regs
.r600
.disp_int_cont2
&= ~DC_HPD5_INTERRUPT
;
4195 queue_hotplug
= true;
4196 DRM_DEBUG("IH: HPD5\n");
4199 if (!(rdev
->irq
.stat_regs
.r600
.disp_int_cont2
& DC_HPD6_INTERRUPT
))
4200 DRM_DEBUG("IH: HPD6 - IH event w/o asserted irq bit?\n");
4202 rdev
->irq
.stat_regs
.r600
.disp_int_cont2
&= ~DC_HPD6_INTERRUPT
;
4203 queue_hotplug
= true;
4204 DRM_DEBUG("IH: HPD6\n");
4208 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id
, src_data
);
4215 if (!(rdev
->irq
.stat_regs
.r600
.hdmi0_status
& HDMI0_AZ_FORMAT_WTRIG
))
4216 DRM_DEBUG("IH: HDMI0 - IH event w/o asserted irq bit?\n");
4218 rdev
->irq
.stat_regs
.r600
.hdmi0_status
&= ~HDMI0_AZ_FORMAT_WTRIG
;
4220 DRM_DEBUG("IH: HDMI0\n");
4224 if (!(rdev
->irq
.stat_regs
.r600
.hdmi1_status
& HDMI0_AZ_FORMAT_WTRIG
))
4225 DRM_DEBUG("IH: HDMI1 - IH event w/o asserted irq bit?\n");
4227 rdev
->irq
.stat_regs
.r600
.hdmi1_status
&= ~HDMI0_AZ_FORMAT_WTRIG
;
4229 DRM_DEBUG("IH: HDMI1\n");
4233 DRM_ERROR("Unhandled interrupt: %d %d\n", src_id
, src_data
);
4238 DRM_DEBUG("IH: UVD int: 0x%08x\n", src_data
);
4239 radeon_fence_process(rdev
, R600_RING_TYPE_UVD_INDEX
);
4241 case 176: /* CP_INT in ring buffer */
4242 case 177: /* CP_INT in IB1 */
4243 case 178: /* CP_INT in IB2 */
4244 DRM_DEBUG("IH: CP int: 0x%08x\n", src_data
);
4245 radeon_fence_process(rdev
, RADEON_RING_TYPE_GFX_INDEX
);
4247 case 181: /* CP EOP event */
4248 DRM_DEBUG("IH: CP EOP\n");
4249 radeon_fence_process(rdev
, RADEON_RING_TYPE_GFX_INDEX
);
4251 case 224: /* DMA trap event */
4252 DRM_DEBUG("IH: DMA trap\n");
4253 radeon_fence_process(rdev
, R600_RING_TYPE_DMA_INDEX
);
4255 case 230: /* thermal low to high */
4256 DRM_DEBUG("IH: thermal low to high\n");
4257 rdev
->pm
.dpm
.thermal
.high_to_low
= false;
4258 queue_thermal
= true;
4260 case 231: /* thermal high to low */
4261 DRM_DEBUG("IH: thermal high to low\n");
4262 rdev
->pm
.dpm
.thermal
.high_to_low
= true;
4263 queue_thermal
= true;
4265 case 233: /* GUI IDLE */
4266 DRM_DEBUG("IH: GUI idle\n");
4269 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id
, src_data
);
4273 /* wptr/rptr are in bytes! */
4275 rptr
&= rdev
->ih
.ptr_mask
;
4276 WREG32(IH_RB_RPTR
, rptr
);
4279 schedule_work(&rdev
->hotplug_work
);
4281 schedule_work(&rdev
->audio_work
);
4282 if (queue_thermal
&& rdev
->pm
.dpm_enabled
)
4283 schedule_work(&rdev
->pm
.dpm
.thermal
.work
);
4284 rdev
->ih
.rptr
= rptr
;
4285 atomic_set(&rdev
->ih
.lock
, 0);
4287 /* make sure wptr hasn't changed while processing */
4288 wptr
= r600_get_ih_wptr(rdev
);
4298 #if defined(CONFIG_DEBUG_FS)
4300 static int r600_debugfs_mc_info(struct seq_file
*m
, void *data
)
4302 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
4303 struct drm_device
*dev
= node
->minor
->dev
;
4304 struct radeon_device
*rdev
= dev
->dev_private
;
4306 DREG32_SYS(m
, rdev
, R_000E50_SRBM_STATUS
);
4307 DREG32_SYS(m
, rdev
, VM_L2_STATUS
);
4311 static struct drm_info_list r600_mc_info_list
[] = {
4312 {"r600_mc_info", r600_debugfs_mc_info
, 0, NULL
},
4316 int r600_debugfs_mc_info_init(struct radeon_device
*rdev
)
4318 #if defined(CONFIG_DEBUG_FS)
4319 return radeon_debugfs_add_files(rdev
, r600_mc_info_list
, ARRAY_SIZE(r600_mc_info_list
));
4326 * r600_mmio_hdp_flush - flush Host Data Path cache via MMIO
4327 * rdev: radeon device structure
4329 * Some R6XX/R7XX don't seem to take into account HDP flushes performed
4330 * through the ring buffer. This leads to corruption in rendering, see
4331 * http://bugzilla.kernel.org/show_bug.cgi?id=15186 . To avoid this, we
4332 * directly perform the HDP flush by writing the register through MMIO.
4334 void r600_mmio_hdp_flush(struct radeon_device
*rdev
)
4336 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
4337 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL.
4338 * This seems to cause problems on some AGP cards. Just use the old
4341 if ((rdev
->family
>= CHIP_RV770
) && (rdev
->family
<= CHIP_RV740
) &&
4342 rdev
->vram_scratch
.ptr
&& !(rdev
->flags
& RADEON_IS_AGP
)) {
4343 void __iomem
*ptr
= (void *)rdev
->vram_scratch
.ptr
;
4346 WREG32(HDP_DEBUG1
, 0);
4347 tmp
= readl((void __iomem
*)ptr
);
4349 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL
, 0x1);
4352 void r600_set_pcie_lanes(struct radeon_device
*rdev
, int lanes
)
4354 u32 link_width_cntl
, mask
;
4356 if (rdev
->flags
& RADEON_IS_IGP
)
4359 if (!(rdev
->flags
& RADEON_IS_PCIE
))
4362 /* x2 cards have a special sequence */
4363 if (ASIC_IS_X2(rdev
))
4366 radeon_gui_idle(rdev
);
4370 mask
= RADEON_PCIE_LC_LINK_WIDTH_X0
;
4373 mask
= RADEON_PCIE_LC_LINK_WIDTH_X1
;
4376 mask
= RADEON_PCIE_LC_LINK_WIDTH_X2
;
4379 mask
= RADEON_PCIE_LC_LINK_WIDTH_X4
;
4382 mask
= RADEON_PCIE_LC_LINK_WIDTH_X8
;
4385 /* not actually supported */
4386 mask
= RADEON_PCIE_LC_LINK_WIDTH_X12
;
4389 mask
= RADEON_PCIE_LC_LINK_WIDTH_X16
;
4392 DRM_ERROR("invalid pcie lane request: %d\n", lanes
);
4396 link_width_cntl
= RREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL
);
4397 link_width_cntl
&= ~RADEON_PCIE_LC_LINK_WIDTH_MASK
;
4398 link_width_cntl
|= mask
<< RADEON_PCIE_LC_LINK_WIDTH_SHIFT
;
4399 link_width_cntl
|= (RADEON_PCIE_LC_RECONFIG_NOW
|
4400 R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE
);
4402 WREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL
, link_width_cntl
);
4405 int r600_get_pcie_lanes(struct radeon_device
*rdev
)
4407 u32 link_width_cntl
;
4409 if (rdev
->flags
& RADEON_IS_IGP
)
4412 if (!(rdev
->flags
& RADEON_IS_PCIE
))
4415 /* x2 cards have a special sequence */
4416 if (ASIC_IS_X2(rdev
))
4419 radeon_gui_idle(rdev
);
4421 link_width_cntl
= RREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL
);
4423 switch ((link_width_cntl
& RADEON_PCIE_LC_LINK_WIDTH_RD_MASK
) >> RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT
) {
4424 case RADEON_PCIE_LC_LINK_WIDTH_X1
:
4426 case RADEON_PCIE_LC_LINK_WIDTH_X2
:
4428 case RADEON_PCIE_LC_LINK_WIDTH_X4
:
4430 case RADEON_PCIE_LC_LINK_WIDTH_X8
:
4432 case RADEON_PCIE_LC_LINK_WIDTH_X12
:
4433 /* not actually supported */
4435 case RADEON_PCIE_LC_LINK_WIDTH_X0
:
4436 case RADEON_PCIE_LC_LINK_WIDTH_X16
:
4442 static void r600_pcie_gen2_enable(struct radeon_device
*rdev
)
4444 u32 link_width_cntl
, lanes
, speed_cntl
, training_cntl
, tmp
;
4447 if (radeon_pcie_gen2
== 0)
4450 if (rdev
->flags
& RADEON_IS_IGP
)
4453 if (!(rdev
->flags
& RADEON_IS_PCIE
))
4456 /* x2 cards have a special sequence */
4457 if (ASIC_IS_X2(rdev
))
4460 /* only RV6xx+ chips are supported */
4461 if (rdev
->family
<= CHIP_R600
)
4464 if ((rdev
->pdev
->bus
->max_bus_speed
!= PCIE_SPEED_5_0GT
) &&
4465 (rdev
->pdev
->bus
->max_bus_speed
!= PCIE_SPEED_8_0GT
))
4468 speed_cntl
= RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
);
4469 if (speed_cntl
& LC_CURRENT_DATA_RATE
) {
4470 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
4474 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
4476 /* 55 nm r6xx asics */
4477 if ((rdev
->family
== CHIP_RV670
) ||
4478 (rdev
->family
== CHIP_RV620
) ||
4479 (rdev
->family
== CHIP_RV635
)) {
4480 /* advertise upconfig capability */
4481 link_width_cntl
= RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL
);
4482 link_width_cntl
&= ~LC_UPCONFIGURE_DIS
;
4483 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL
, link_width_cntl
);
4484 link_width_cntl
= RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL
);
4485 if (link_width_cntl
& LC_RENEGOTIATION_SUPPORT
) {
4486 lanes
= (link_width_cntl
& LC_LINK_WIDTH_RD_MASK
) >> LC_LINK_WIDTH_RD_SHIFT
;
4487 link_width_cntl
&= ~(LC_LINK_WIDTH_MASK
|
4488 LC_RECONFIG_ARC_MISSING_ESCAPE
);
4489 link_width_cntl
|= lanes
| LC_RECONFIG_NOW
| LC_RENEGOTIATE_EN
;
4490 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL
, link_width_cntl
);
4492 link_width_cntl
|= LC_UPCONFIGURE_DIS
;
4493 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL
, link_width_cntl
);
4497 speed_cntl
= RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
);
4498 if ((speed_cntl
& LC_OTHER_SIDE_EVER_SENT_GEN2
) &&
4499 (speed_cntl
& LC_OTHER_SIDE_SUPPORTS_GEN2
)) {
4501 /* 55 nm r6xx asics */
4502 if ((rdev
->family
== CHIP_RV670
) ||
4503 (rdev
->family
== CHIP_RV620
) ||
4504 (rdev
->family
== CHIP_RV635
)) {
4505 WREG32(MM_CFGREGS_CNTL
, 0x8);
4506 link_cntl2
= RREG32(0x4088);
4507 WREG32(MM_CFGREGS_CNTL
, 0);
4508 /* not supported yet */
4509 if (link_cntl2
& SELECTABLE_DEEMPHASIS
)
4513 speed_cntl
&= ~LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_MASK
;
4514 speed_cntl
|= (0x3 << LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_SHIFT
);
4515 speed_cntl
&= ~LC_VOLTAGE_TIMER_SEL_MASK
;
4516 speed_cntl
&= ~LC_FORCE_DIS_HW_SPEED_CHANGE
;
4517 speed_cntl
|= LC_FORCE_EN_HW_SPEED_CHANGE
;
4518 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
, speed_cntl
);
4520 tmp
= RREG32(0x541c);
4521 WREG32(0x541c, tmp
| 0x8);
4522 WREG32(MM_CFGREGS_CNTL
, MM_WR_TO_CFG_EN
);
4523 link_cntl2
= RREG16(0x4088);
4524 link_cntl2
&= ~TARGET_LINK_SPEED_MASK
;
4526 WREG16(0x4088, link_cntl2
);
4527 WREG32(MM_CFGREGS_CNTL
, 0);
4529 if ((rdev
->family
== CHIP_RV670
) ||
4530 (rdev
->family
== CHIP_RV620
) ||
4531 (rdev
->family
== CHIP_RV635
)) {
4532 training_cntl
= RREG32_PCIE_PORT(PCIE_LC_TRAINING_CNTL
);
4533 training_cntl
&= ~LC_POINT_7_PLUS_EN
;
4534 WREG32_PCIE_PORT(PCIE_LC_TRAINING_CNTL
, training_cntl
);
4536 speed_cntl
= RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
);
4537 speed_cntl
&= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN
;
4538 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
, speed_cntl
);
4541 speed_cntl
= RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
);
4542 speed_cntl
|= LC_GEN2_EN_STRAP
;
4543 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
, speed_cntl
);
4546 link_width_cntl
= RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL
);
4547 /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
4549 link_width_cntl
|= LC_UPCONFIGURE_DIS
;
4551 link_width_cntl
&= ~LC_UPCONFIGURE_DIS
;
4552 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL
, link_width_cntl
);
4557 * r600_get_gpu_clock_counter - return GPU clock counter snapshot
4559 * @rdev: radeon_device pointer
4561 * Fetches a GPU clock counter snapshot (R6xx-cayman).
4562 * Returns the 64 bit clock counter snapshot.
4564 uint64_t r600_get_gpu_clock_counter(struct radeon_device
*rdev
)
4568 mutex_lock(&rdev
->gpu_clock_mutex
);
4569 WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT
, 1);
4570 clock
= (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB
) |
4571 ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB
) << 32ULL);
4572 mutex_unlock(&rdev
->gpu_clock_mutex
);