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 * $FreeBSD: head/sys/dev/drm2/radeon/r600.c 254885 2013-08-25 19:37:15Z dumbbell $
32 #include <uapi_drm/radeon_drm.h>
34 #include "radeon_asic.h"
35 #include "radeon_mode.h"
40 #define PFP_UCODE_SIZE 576
41 #define PM4_UCODE_SIZE 1792
42 #define RLC_UCODE_SIZE 768
43 #define R700_PFP_UCODE_SIZE 848
44 #define R700_PM4_UCODE_SIZE 1360
45 #define R700_RLC_UCODE_SIZE 1024
46 #define EVERGREEN_PFP_UCODE_SIZE 1120
47 #define EVERGREEN_PM4_UCODE_SIZE 1376
48 #define EVERGREEN_RLC_UCODE_SIZE 768
49 #define CAYMAN_RLC_UCODE_SIZE 1024
50 #define ARUBA_RLC_UCODE_SIZE 1536
54 MODULE_FIRMWARE("radeon/R600_pfp.bin");
55 MODULE_FIRMWARE("radeon/R600_me.bin");
56 MODULE_FIRMWARE("radeon/RV610_pfp.bin");
57 MODULE_FIRMWARE("radeon/RV610_me.bin");
58 MODULE_FIRMWARE("radeon/RV630_pfp.bin");
59 MODULE_FIRMWARE("radeon/RV630_me.bin");
60 MODULE_FIRMWARE("radeon/RV620_pfp.bin");
61 MODULE_FIRMWARE("radeon/RV620_me.bin");
62 MODULE_FIRMWARE("radeon/RV635_pfp.bin");
63 MODULE_FIRMWARE("radeon/RV635_me.bin");
64 MODULE_FIRMWARE("radeon/RV670_pfp.bin");
65 MODULE_FIRMWARE("radeon/RV670_me.bin");
66 MODULE_FIRMWARE("radeon/RS780_pfp.bin");
67 MODULE_FIRMWARE("radeon/RS780_me.bin");
68 MODULE_FIRMWARE("radeon/RV770_pfp.bin");
69 MODULE_FIRMWARE("radeon/RV770_me.bin");
70 MODULE_FIRMWARE("radeon/RV730_pfp.bin");
71 MODULE_FIRMWARE("radeon/RV730_me.bin");
72 MODULE_FIRMWARE("radeon/RV710_pfp.bin");
73 MODULE_FIRMWARE("radeon/RV710_me.bin");
74 MODULE_FIRMWARE("radeon/R600_rlc.bin");
75 MODULE_FIRMWARE("radeon/R700_rlc.bin");
76 MODULE_FIRMWARE("radeon/CEDAR_pfp.bin");
77 MODULE_FIRMWARE("radeon/CEDAR_me.bin");
78 MODULE_FIRMWARE("radeon/CEDAR_rlc.bin");
79 MODULE_FIRMWARE("radeon/REDWOOD_pfp.bin");
80 MODULE_FIRMWARE("radeon/REDWOOD_me.bin");
81 MODULE_FIRMWARE("radeon/REDWOOD_rlc.bin");
82 MODULE_FIRMWARE("radeon/JUNIPER_pfp.bin");
83 MODULE_FIRMWARE("radeon/JUNIPER_me.bin");
84 MODULE_FIRMWARE("radeon/JUNIPER_rlc.bin");
85 MODULE_FIRMWARE("radeon/CYPRESS_pfp.bin");
86 MODULE_FIRMWARE("radeon/CYPRESS_me.bin");
87 MODULE_FIRMWARE("radeon/CYPRESS_rlc.bin");
88 MODULE_FIRMWARE("radeon/PALM_pfp.bin");
89 MODULE_FIRMWARE("radeon/PALM_me.bin");
90 MODULE_FIRMWARE("radeon/SUMO_rlc.bin");
91 MODULE_FIRMWARE("radeon/SUMO_pfp.bin");
92 MODULE_FIRMWARE("radeon/SUMO_me.bin");
93 MODULE_FIRMWARE("radeon/SUMO2_pfp.bin");
94 MODULE_FIRMWARE("radeon/SUMO2_me.bin");
95 MODULE_FIRMWARE("radeon/OLAND_pfp.bin");
96 MODULE_FIRMWARE("radeon/OLAND_me.bin");
97 MODULE_FIRMWARE("radeon/OLAND_ce.bin");
98 MODULE_FIRMWARE("radeon/OLAND_mc.bin");
99 MODULE_FIRMWARE("radeon/OLAND_rlc.bin");
100 #endif /* DUMBBELL_WIP */
102 static const u32 crtc_offsets
[2] =
105 AVIVO_D2CRTC_H_TOTAL
- AVIVO_D1CRTC_H_TOTAL
108 int r600_debugfs_mc_info_init(struct radeon_device
*rdev
);
110 /* r600,rv610,rv630,rv620,rv635,rv670 */
111 static void r600_gpu_init(struct radeon_device
*rdev
);
112 void r600_irq_disable(struct radeon_device
*rdev
);
113 static void r600_pcie_gen2_enable(struct radeon_device
*rdev
);
116 * r600_get_xclk - get the xclk
118 * @rdev: radeon_device pointer
120 * Returns the reference clock used by the gfx engine
121 * (r6xx, IGPs, APUs).
123 u32
r600_get_xclk(struct radeon_device
*rdev
)
125 return rdev
->clock
.spll
.reference_freq
;
128 /* get temperature in millidegrees */
129 int rv6xx_get_temp(struct radeon_device
*rdev
)
131 u32 temp
= (RREG32(CG_THERMAL_STATUS
) & ASIC_T_MASK
) >>
133 int actual_temp
= temp
& 0xff;
138 return actual_temp
* 1000;
141 void r600_pm_get_dynpm_state(struct radeon_device
*rdev
)
145 rdev
->pm
.dynpm_can_upclock
= true;
146 rdev
->pm
.dynpm_can_downclock
= true;
148 /* power state array is low to high, default is first */
149 if ((rdev
->flags
& RADEON_IS_IGP
) || (rdev
->family
== CHIP_R600
)) {
150 int min_power_state_index
= 0;
152 if (rdev
->pm
.num_power_states
> 2)
153 min_power_state_index
= 1;
155 switch (rdev
->pm
.dynpm_planned_action
) {
156 case DYNPM_ACTION_MINIMUM
:
157 rdev
->pm
.requested_power_state_index
= min_power_state_index
;
158 rdev
->pm
.requested_clock_mode_index
= 0;
159 rdev
->pm
.dynpm_can_downclock
= false;
161 case DYNPM_ACTION_DOWNCLOCK
:
162 if (rdev
->pm
.current_power_state_index
== min_power_state_index
) {
163 rdev
->pm
.requested_power_state_index
= rdev
->pm
.current_power_state_index
;
164 rdev
->pm
.dynpm_can_downclock
= false;
166 if (rdev
->pm
.active_crtc_count
> 1) {
167 for (i
= 0; i
< rdev
->pm
.num_power_states
; i
++) {
168 if (rdev
->pm
.power_state
[i
].flags
& RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
)
170 else if (i
>= rdev
->pm
.current_power_state_index
) {
171 rdev
->pm
.requested_power_state_index
=
172 rdev
->pm
.current_power_state_index
;
175 rdev
->pm
.requested_power_state_index
= i
;
180 if (rdev
->pm
.current_power_state_index
== 0)
181 rdev
->pm
.requested_power_state_index
=
182 rdev
->pm
.num_power_states
- 1;
184 rdev
->pm
.requested_power_state_index
=
185 rdev
->pm
.current_power_state_index
- 1;
188 rdev
->pm
.requested_clock_mode_index
= 0;
189 /* don't use the power state if crtcs are active and no display flag is set */
190 if ((rdev
->pm
.active_crtc_count
> 0) &&
191 (rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].
192 clock_info
[rdev
->pm
.requested_clock_mode_index
].flags
&
193 RADEON_PM_MODE_NO_DISPLAY
)) {
194 rdev
->pm
.requested_power_state_index
++;
197 case DYNPM_ACTION_UPCLOCK
:
198 if (rdev
->pm
.current_power_state_index
== (rdev
->pm
.num_power_states
- 1)) {
199 rdev
->pm
.requested_power_state_index
= rdev
->pm
.current_power_state_index
;
200 rdev
->pm
.dynpm_can_upclock
= false;
202 if (rdev
->pm
.active_crtc_count
> 1) {
203 for (i
= (rdev
->pm
.num_power_states
- 1); i
>= 0; i
--) {
204 if (rdev
->pm
.power_state
[i
].flags
& RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
)
206 else if (i
<= rdev
->pm
.current_power_state_index
) {
207 rdev
->pm
.requested_power_state_index
=
208 rdev
->pm
.current_power_state_index
;
211 rdev
->pm
.requested_power_state_index
= i
;
216 rdev
->pm
.requested_power_state_index
=
217 rdev
->pm
.current_power_state_index
+ 1;
219 rdev
->pm
.requested_clock_mode_index
= 0;
221 case DYNPM_ACTION_DEFAULT
:
222 rdev
->pm
.requested_power_state_index
= rdev
->pm
.default_power_state_index
;
223 rdev
->pm
.requested_clock_mode_index
= 0;
224 rdev
->pm
.dynpm_can_upclock
= false;
226 case DYNPM_ACTION_NONE
:
228 DRM_ERROR("Requested mode for not defined action\n");
232 /* XXX select a power state based on AC/DC, single/dualhead, etc. */
233 /* for now just select the first power state and switch between clock modes */
234 /* power state array is low to high, default is first (0) */
235 if (rdev
->pm
.active_crtc_count
> 1) {
236 rdev
->pm
.requested_power_state_index
= -1;
237 /* start at 1 as we don't want the default mode */
238 for (i
= 1; i
< rdev
->pm
.num_power_states
; i
++) {
239 if (rdev
->pm
.power_state
[i
].flags
& RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
)
241 else if ((rdev
->pm
.power_state
[i
].type
== POWER_STATE_TYPE_PERFORMANCE
) ||
242 (rdev
->pm
.power_state
[i
].type
== POWER_STATE_TYPE_BATTERY
)) {
243 rdev
->pm
.requested_power_state_index
= i
;
247 /* if nothing selected, grab the default state. */
248 if (rdev
->pm
.requested_power_state_index
== -1)
249 rdev
->pm
.requested_power_state_index
= 0;
251 rdev
->pm
.requested_power_state_index
= 1;
253 switch (rdev
->pm
.dynpm_planned_action
) {
254 case DYNPM_ACTION_MINIMUM
:
255 rdev
->pm
.requested_clock_mode_index
= 0;
256 rdev
->pm
.dynpm_can_downclock
= false;
258 case DYNPM_ACTION_DOWNCLOCK
:
259 if (rdev
->pm
.requested_power_state_index
== rdev
->pm
.current_power_state_index
) {
260 if (rdev
->pm
.current_clock_mode_index
== 0) {
261 rdev
->pm
.requested_clock_mode_index
= 0;
262 rdev
->pm
.dynpm_can_downclock
= false;
264 rdev
->pm
.requested_clock_mode_index
=
265 rdev
->pm
.current_clock_mode_index
- 1;
267 rdev
->pm
.requested_clock_mode_index
= 0;
268 rdev
->pm
.dynpm_can_downclock
= false;
270 /* don't use the power state if crtcs are active and no display flag is set */
271 if ((rdev
->pm
.active_crtc_count
> 0) &&
272 (rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].
273 clock_info
[rdev
->pm
.requested_clock_mode_index
].flags
&
274 RADEON_PM_MODE_NO_DISPLAY
)) {
275 rdev
->pm
.requested_clock_mode_index
++;
278 case DYNPM_ACTION_UPCLOCK
:
279 if (rdev
->pm
.requested_power_state_index
== rdev
->pm
.current_power_state_index
) {
280 if (rdev
->pm
.current_clock_mode_index
==
281 (rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].num_clock_modes
- 1)) {
282 rdev
->pm
.requested_clock_mode_index
= rdev
->pm
.current_clock_mode_index
;
283 rdev
->pm
.dynpm_can_upclock
= false;
285 rdev
->pm
.requested_clock_mode_index
=
286 rdev
->pm
.current_clock_mode_index
+ 1;
288 rdev
->pm
.requested_clock_mode_index
=
289 rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].num_clock_modes
- 1;
290 rdev
->pm
.dynpm_can_upclock
= false;
293 case DYNPM_ACTION_DEFAULT
:
294 rdev
->pm
.requested_power_state_index
= rdev
->pm
.default_power_state_index
;
295 rdev
->pm
.requested_clock_mode_index
= 0;
296 rdev
->pm
.dynpm_can_upclock
= false;
298 case DYNPM_ACTION_NONE
:
300 DRM_ERROR("Requested mode for not defined action\n");
305 DRM_DEBUG_DRIVER("Requested: e: %d m: %d p: %d\n",
306 rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].
307 clock_info
[rdev
->pm
.requested_clock_mode_index
].sclk
,
308 rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].
309 clock_info
[rdev
->pm
.requested_clock_mode_index
].mclk
,
310 rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].
314 void rs780_pm_init_profile(struct radeon_device
*rdev
)
316 if (rdev
->pm
.num_power_states
== 2) {
318 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
319 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
320 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_cm_idx
= 0;
321 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_cm_idx
= 0;
323 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_ps_idx
= 0;
324 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_ps_idx
= 0;
325 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_cm_idx
= 0;
326 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_cm_idx
= 0;
328 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_off_ps_idx
= 0;
329 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_on_ps_idx
= 0;
330 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_off_cm_idx
= 0;
331 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_on_cm_idx
= 0;
333 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_ps_idx
= 0;
334 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_ps_idx
= 1;
335 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_cm_idx
= 0;
336 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_cm_idx
= 0;
338 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_ps_idx
= 0;
339 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_ps_idx
= 0;
340 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_cm_idx
= 0;
341 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_cm_idx
= 0;
343 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_off_ps_idx
= 0;
344 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_on_ps_idx
= 0;
345 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_off_cm_idx
= 0;
346 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_on_cm_idx
= 0;
348 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_ps_idx
= 0;
349 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_ps_idx
= 1;
350 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_cm_idx
= 0;
351 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_cm_idx
= 0;
352 } else if (rdev
->pm
.num_power_states
== 3) {
354 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
355 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
356 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_cm_idx
= 0;
357 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_cm_idx
= 0;
359 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_ps_idx
= 1;
360 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_ps_idx
= 1;
361 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_cm_idx
= 0;
362 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_cm_idx
= 0;
364 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_off_ps_idx
= 1;
365 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_on_ps_idx
= 1;
366 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_off_cm_idx
= 0;
367 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_on_cm_idx
= 0;
369 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_ps_idx
= 1;
370 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_ps_idx
= 2;
371 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_cm_idx
= 0;
372 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_cm_idx
= 0;
374 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_ps_idx
= 1;
375 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_ps_idx
= 1;
376 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_cm_idx
= 0;
377 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_cm_idx
= 0;
379 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_off_ps_idx
= 1;
380 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_on_ps_idx
= 1;
381 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_off_cm_idx
= 0;
382 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_on_cm_idx
= 0;
384 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_ps_idx
= 1;
385 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_ps_idx
= 2;
386 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_cm_idx
= 0;
387 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_cm_idx
= 0;
390 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
391 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
392 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_cm_idx
= 0;
393 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_cm_idx
= 0;
395 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_ps_idx
= 2;
396 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_ps_idx
= 2;
397 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_cm_idx
= 0;
398 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_cm_idx
= 0;
400 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_off_ps_idx
= 2;
401 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_on_ps_idx
= 2;
402 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_off_cm_idx
= 0;
403 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_on_cm_idx
= 0;
405 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_ps_idx
= 2;
406 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_ps_idx
= 3;
407 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_cm_idx
= 0;
408 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_cm_idx
= 0;
410 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_ps_idx
= 2;
411 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_ps_idx
= 0;
412 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_cm_idx
= 0;
413 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_cm_idx
= 0;
415 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_off_ps_idx
= 2;
416 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_on_ps_idx
= 0;
417 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_off_cm_idx
= 0;
418 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_on_cm_idx
= 0;
420 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_ps_idx
= 2;
421 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_ps_idx
= 3;
422 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_cm_idx
= 0;
423 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_cm_idx
= 0;
427 void r600_pm_init_profile(struct radeon_device
*rdev
)
431 if (rdev
->family
== CHIP_R600
) {
434 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
435 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
436 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_cm_idx
= 0;
437 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_cm_idx
= 0;
439 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
440 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
441 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_cm_idx
= 0;
442 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_cm_idx
= 0;
444 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
445 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
446 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_off_cm_idx
= 0;
447 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_on_cm_idx
= 0;
449 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
450 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
451 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_cm_idx
= 0;
452 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_cm_idx
= 0;
454 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
455 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
456 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_cm_idx
= 0;
457 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_cm_idx
= 0;
459 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
460 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
461 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_off_cm_idx
= 0;
462 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_on_cm_idx
= 0;
464 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
465 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
466 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_cm_idx
= 0;
467 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_cm_idx
= 0;
469 if (rdev
->pm
.num_power_states
< 4) {
471 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
472 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
473 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_cm_idx
= 0;
474 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_cm_idx
= 2;
476 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_ps_idx
= 1;
477 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_ps_idx
= 1;
478 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_cm_idx
= 0;
479 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_cm_idx
= 0;
481 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_off_ps_idx
= 1;
482 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_on_ps_idx
= 1;
483 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_off_cm_idx
= 0;
484 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_on_cm_idx
= 1;
486 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_ps_idx
= 1;
487 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_ps_idx
= 1;
488 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_cm_idx
= 0;
489 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_cm_idx
= 2;
491 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_ps_idx
= 2;
492 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_ps_idx
= 2;
493 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_cm_idx
= 0;
494 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_cm_idx
= 0;
496 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_off_ps_idx
= 2;
497 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_on_ps_idx
= 2;
498 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_off_cm_idx
= 0;
499 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_on_cm_idx
= 1;
501 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_ps_idx
= 2;
502 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_ps_idx
= 2;
503 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_cm_idx
= 0;
504 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_cm_idx
= 2;
507 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
508 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
509 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_cm_idx
= 0;
510 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_cm_idx
= 2;
512 if (rdev
->flags
& RADEON_IS_MOBILITY
)
513 idx
= radeon_pm_get_type_index(rdev
, POWER_STATE_TYPE_BATTERY
, 0);
515 idx
= radeon_pm_get_type_index(rdev
, POWER_STATE_TYPE_PERFORMANCE
, 0);
516 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_ps_idx
= idx
;
517 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_ps_idx
= idx
;
518 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_cm_idx
= 0;
519 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_cm_idx
= 0;
521 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_off_ps_idx
= idx
;
522 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_on_ps_idx
= idx
;
523 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_off_cm_idx
= 0;
524 rdev
->pm
.profiles
[PM_PROFILE_MID_SH_IDX
].dpms_on_cm_idx
= 1;
526 idx
= radeon_pm_get_type_index(rdev
, POWER_STATE_TYPE_PERFORMANCE
, 0);
527 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_ps_idx
= idx
;
528 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_ps_idx
= idx
;
529 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_cm_idx
= 0;
530 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_cm_idx
= 2;
532 if (rdev
->flags
& RADEON_IS_MOBILITY
)
533 idx
= radeon_pm_get_type_index(rdev
, POWER_STATE_TYPE_BATTERY
, 1);
535 idx
= radeon_pm_get_type_index(rdev
, POWER_STATE_TYPE_PERFORMANCE
, 1);
536 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_ps_idx
= idx
;
537 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_ps_idx
= idx
;
538 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_cm_idx
= 0;
539 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_cm_idx
= 0;
541 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_off_ps_idx
= idx
;
542 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_on_ps_idx
= idx
;
543 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_off_cm_idx
= 0;
544 rdev
->pm
.profiles
[PM_PROFILE_MID_MH_IDX
].dpms_on_cm_idx
= 1;
546 idx
= radeon_pm_get_type_index(rdev
, POWER_STATE_TYPE_PERFORMANCE
, 1);
547 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_ps_idx
= idx
;
548 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_ps_idx
= idx
;
549 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_cm_idx
= 0;
550 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_cm_idx
= 2;
555 void r600_pm_misc(struct radeon_device
*rdev
)
557 int req_ps_idx
= rdev
->pm
.requested_power_state_index
;
558 int req_cm_idx
= rdev
->pm
.requested_clock_mode_index
;
559 struct radeon_power_state
*ps
= &rdev
->pm
.power_state
[req_ps_idx
];
560 struct radeon_voltage
*voltage
= &ps
->clock_info
[req_cm_idx
].voltage
;
562 if ((voltage
->type
== VOLTAGE_SW
) && voltage
->voltage
) {
563 /* 0xff01 is a flag rather then an actual voltage */
564 if (voltage
->voltage
== 0xff01)
566 if (voltage
->voltage
!= rdev
->pm
.current_vddc
) {
567 radeon_atom_set_voltage(rdev
, voltage
->voltage
, SET_VOLTAGE_TYPE_ASIC_VDDC
);
568 rdev
->pm
.current_vddc
= voltage
->voltage
;
569 DRM_DEBUG_DRIVER("Setting: v: %d\n", voltage
->voltage
);
574 bool r600_gui_idle(struct radeon_device
*rdev
)
576 if (RREG32(GRBM_STATUS
) & GUI_ACTIVE
)
582 /* hpd for digital panel detect/disconnect */
583 bool r600_hpd_sense(struct radeon_device
*rdev
, enum radeon_hpd_id hpd
)
585 bool connected
= false;
587 if (ASIC_IS_DCE3(rdev
)) {
590 if (RREG32(DC_HPD1_INT_STATUS
) & DC_HPDx_SENSE
)
594 if (RREG32(DC_HPD2_INT_STATUS
) & DC_HPDx_SENSE
)
598 if (RREG32(DC_HPD3_INT_STATUS
) & DC_HPDx_SENSE
)
602 if (RREG32(DC_HPD4_INT_STATUS
) & DC_HPDx_SENSE
)
607 if (RREG32(DC_HPD5_INT_STATUS
) & DC_HPDx_SENSE
)
611 if (RREG32(DC_HPD6_INT_STATUS
) & DC_HPDx_SENSE
)
620 if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS
) & DC_HOT_PLUG_DETECTx_SENSE
)
624 if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS
) & DC_HOT_PLUG_DETECTx_SENSE
)
628 if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS
) & DC_HOT_PLUG_DETECTx_SENSE
)
638 void r600_hpd_set_polarity(struct radeon_device
*rdev
,
639 enum radeon_hpd_id hpd
)
642 bool connected
= r600_hpd_sense(rdev
, hpd
);
644 if (ASIC_IS_DCE3(rdev
)) {
647 tmp
= RREG32(DC_HPD1_INT_CONTROL
);
649 tmp
&= ~DC_HPDx_INT_POLARITY
;
651 tmp
|= DC_HPDx_INT_POLARITY
;
652 WREG32(DC_HPD1_INT_CONTROL
, tmp
);
655 tmp
= RREG32(DC_HPD2_INT_CONTROL
);
657 tmp
&= ~DC_HPDx_INT_POLARITY
;
659 tmp
|= DC_HPDx_INT_POLARITY
;
660 WREG32(DC_HPD2_INT_CONTROL
, tmp
);
663 tmp
= RREG32(DC_HPD3_INT_CONTROL
);
665 tmp
&= ~DC_HPDx_INT_POLARITY
;
667 tmp
|= DC_HPDx_INT_POLARITY
;
668 WREG32(DC_HPD3_INT_CONTROL
, tmp
);
671 tmp
= RREG32(DC_HPD4_INT_CONTROL
);
673 tmp
&= ~DC_HPDx_INT_POLARITY
;
675 tmp
|= DC_HPDx_INT_POLARITY
;
676 WREG32(DC_HPD4_INT_CONTROL
, tmp
);
679 tmp
= RREG32(DC_HPD5_INT_CONTROL
);
681 tmp
&= ~DC_HPDx_INT_POLARITY
;
683 tmp
|= DC_HPDx_INT_POLARITY
;
684 WREG32(DC_HPD5_INT_CONTROL
, tmp
);
688 tmp
= RREG32(DC_HPD6_INT_CONTROL
);
690 tmp
&= ~DC_HPDx_INT_POLARITY
;
692 tmp
|= DC_HPDx_INT_POLARITY
;
693 WREG32(DC_HPD6_INT_CONTROL
, tmp
);
701 tmp
= RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
);
703 tmp
&= ~DC_HOT_PLUG_DETECTx_INT_POLARITY
;
705 tmp
|= DC_HOT_PLUG_DETECTx_INT_POLARITY
;
706 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
, tmp
);
709 tmp
= RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
);
711 tmp
&= ~DC_HOT_PLUG_DETECTx_INT_POLARITY
;
713 tmp
|= DC_HOT_PLUG_DETECTx_INT_POLARITY
;
714 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
, tmp
);
717 tmp
= RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
);
719 tmp
&= ~DC_HOT_PLUG_DETECTx_INT_POLARITY
;
721 tmp
|= DC_HOT_PLUG_DETECTx_INT_POLARITY
;
722 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
, tmp
);
730 void r600_hpd_init(struct radeon_device
*rdev
)
732 struct drm_device
*dev
= rdev
->ddev
;
733 struct drm_connector
*connector
;
736 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
737 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
739 if (connector
->connector_type
== DRM_MODE_CONNECTOR_eDP
||
740 connector
->connector_type
== DRM_MODE_CONNECTOR_LVDS
) {
741 /* don't try to enable hpd on eDP or LVDS avoid breaking the
742 * aux dp channel on imac and help (but not completely fix)
743 * https://bugzilla.redhat.com/show_bug.cgi?id=726143
747 if (ASIC_IS_DCE3(rdev
)) {
748 u32 tmp
= DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
749 if (ASIC_IS_DCE32(rdev
))
752 switch (radeon_connector
->hpd
.hpd
) {
754 WREG32(DC_HPD1_CONTROL
, tmp
);
757 WREG32(DC_HPD2_CONTROL
, tmp
);
760 WREG32(DC_HPD3_CONTROL
, tmp
);
763 WREG32(DC_HPD4_CONTROL
, tmp
);
767 WREG32(DC_HPD5_CONTROL
, tmp
);
770 WREG32(DC_HPD6_CONTROL
, tmp
);
776 switch (radeon_connector
->hpd
.hpd
) {
778 WREG32(DC_HOT_PLUG_DETECT1_CONTROL
, DC_HOT_PLUG_DETECTx_EN
);
781 WREG32(DC_HOT_PLUG_DETECT2_CONTROL
, DC_HOT_PLUG_DETECTx_EN
);
784 WREG32(DC_HOT_PLUG_DETECT3_CONTROL
, DC_HOT_PLUG_DETECTx_EN
);
790 enable
|= 1 << radeon_connector
->hpd
.hpd
;
791 radeon_hpd_set_polarity(rdev
, radeon_connector
->hpd
.hpd
);
793 radeon_irq_kms_enable_hpd(rdev
, enable
);
796 void r600_hpd_fini(struct radeon_device
*rdev
)
798 struct drm_device
*dev
= rdev
->ddev
;
799 struct drm_connector
*connector
;
800 unsigned disable
= 0;
802 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
803 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
804 if (ASIC_IS_DCE3(rdev
)) {
805 switch (radeon_connector
->hpd
.hpd
) {
807 WREG32(DC_HPD1_CONTROL
, 0);
810 WREG32(DC_HPD2_CONTROL
, 0);
813 WREG32(DC_HPD3_CONTROL
, 0);
816 WREG32(DC_HPD4_CONTROL
, 0);
820 WREG32(DC_HPD5_CONTROL
, 0);
823 WREG32(DC_HPD6_CONTROL
, 0);
829 switch (radeon_connector
->hpd
.hpd
) {
831 WREG32(DC_HOT_PLUG_DETECT1_CONTROL
, 0);
834 WREG32(DC_HOT_PLUG_DETECT2_CONTROL
, 0);
837 WREG32(DC_HOT_PLUG_DETECT3_CONTROL
, 0);
843 disable
|= 1 << radeon_connector
->hpd
.hpd
;
845 radeon_irq_kms_disable_hpd(rdev
, disable
);
851 void r600_pcie_gart_tlb_flush(struct radeon_device
*rdev
)
856 /* flush hdp cache so updates hit vram */
857 if ((rdev
->family
>= CHIP_RV770
) && (rdev
->family
<= CHIP_RV740
) &&
858 !(rdev
->flags
& RADEON_IS_AGP
)) {
859 volatile uint32_t *ptr
= rdev
->gart
.ptr
;
862 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
863 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL
864 * This seems to cause problems on some AGP cards. Just use the old
867 WREG32(HDP_DEBUG1
, 0);
870 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL
, 0x1);
872 WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR
, rdev
->mc
.gtt_start
>> 12);
873 WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR
, (rdev
->mc
.gtt_end
- 1) >> 12);
874 WREG32(VM_CONTEXT0_REQUEST_RESPONSE
, REQUEST_TYPE(1));
875 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
877 tmp
= RREG32(VM_CONTEXT0_REQUEST_RESPONSE
);
878 tmp
= (tmp
& RESPONSE_TYPE_MASK
) >> RESPONSE_TYPE_SHIFT
;
880 DRM_ERROR("[drm] r600 flush TLB failed\n");
890 int r600_pcie_gart_init(struct radeon_device
*rdev
)
894 if (rdev
->gart
.robj
) {
895 DRM_ERROR("R600 PCIE GART already initialized\n");
898 /* Initialize common gart structure */
899 r
= radeon_gart_init(rdev
);
902 rdev
->gart
.table_size
= rdev
->gart
.num_gpu_pages
* 8;
903 return radeon_gart_table_vram_alloc(rdev
);
906 static int r600_pcie_gart_enable(struct radeon_device
*rdev
)
911 if (rdev
->gart
.robj
== NULL
) {
912 dev_err(rdev
->dev
, "No VRAM object for PCIE GART.\n");
915 r
= radeon_gart_table_vram_pin(rdev
);
918 radeon_gart_restore(rdev
);
921 WREG32(VM_L2_CNTL
, ENABLE_L2_CACHE
| ENABLE_L2_FRAGMENT_PROCESSING
|
922 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE
|
923 EFFECTIVE_L2_QUEUE_SIZE(7));
924 WREG32(VM_L2_CNTL2
, 0);
925 WREG32(VM_L2_CNTL3
, BANK_SELECT_0(0) | BANK_SELECT_1(1));
926 /* Setup TLB control */
927 tmp
= ENABLE_L1_TLB
| ENABLE_L1_FRAGMENT_PROCESSING
|
928 SYSTEM_ACCESS_MODE_NOT_IN_SYS
|
929 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
930 ENABLE_WAIT_L2_QUERY
;
931 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL
, tmp
);
932 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL
, tmp
);
933 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL
, tmp
| ENABLE_L1_STRICT_ORDERING
);
934 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL
, tmp
);
935 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL
, tmp
);
936 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL
, tmp
);
937 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL
, tmp
);
938 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL
, tmp
);
939 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL
, tmp
);
940 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL
, tmp
);
941 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL
, tmp
);
942 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL
, tmp
);
943 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL
, tmp
| ENABLE_SEMAPHORE_MODE
);
944 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL
, tmp
| ENABLE_SEMAPHORE_MODE
);
945 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR
, rdev
->mc
.gtt_start
>> 12);
946 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR
, rdev
->mc
.gtt_end
>> 12);
947 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR
, rdev
->gart
.table_addr
>> 12);
948 WREG32(VM_CONTEXT0_CNTL
, ENABLE_CONTEXT
| PAGE_TABLE_DEPTH(0) |
949 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT
);
950 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR
,
951 (u32
)(rdev
->dummy_page
.addr
>> 12));
952 for (i
= 1; i
< 7; i
++)
953 WREG32(VM_CONTEXT0_CNTL
+ (i
* 4), 0);
955 r600_pcie_gart_tlb_flush(rdev
);
956 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
957 (unsigned)(rdev
->mc
.gtt_size
>> 20),
958 (unsigned long long)rdev
->gart
.table_addr
);
959 rdev
->gart
.ready
= true;
963 static void r600_pcie_gart_disable(struct radeon_device
*rdev
)
968 /* Disable all tables */
969 for (i
= 0; i
< 7; i
++)
970 WREG32(VM_CONTEXT0_CNTL
+ (i
* 4), 0);
972 /* Disable L2 cache */
973 WREG32(VM_L2_CNTL
, ENABLE_L2_FRAGMENT_PROCESSING
|
974 EFFECTIVE_L2_QUEUE_SIZE(7));
975 WREG32(VM_L2_CNTL3
, BANK_SELECT_0(0) | BANK_SELECT_1(1));
976 /* Setup L1 TLB control */
977 tmp
= EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
978 ENABLE_WAIT_L2_QUERY
;
979 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL
, tmp
);
980 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL
, tmp
);
981 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL
, tmp
);
982 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL
, tmp
);
983 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL
, tmp
);
984 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL
, tmp
);
985 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL
, tmp
);
986 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL
, tmp
);
987 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL
, tmp
);
988 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL
, tmp
);
989 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL
, tmp
);
990 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL
, tmp
);
991 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL
, tmp
);
992 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL
, tmp
);
993 radeon_gart_table_vram_unpin(rdev
);
996 static void r600_pcie_gart_fini(struct radeon_device
*rdev
)
998 radeon_gart_fini(rdev
);
999 r600_pcie_gart_disable(rdev
);
1000 radeon_gart_table_vram_free(rdev
);
1003 static void r600_agp_enable(struct radeon_device
*rdev
)
1008 /* Setup L2 cache */
1009 WREG32(VM_L2_CNTL
, ENABLE_L2_CACHE
| ENABLE_L2_FRAGMENT_PROCESSING
|
1010 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE
|
1011 EFFECTIVE_L2_QUEUE_SIZE(7));
1012 WREG32(VM_L2_CNTL2
, 0);
1013 WREG32(VM_L2_CNTL3
, BANK_SELECT_0(0) | BANK_SELECT_1(1));
1014 /* Setup TLB control */
1015 tmp
= ENABLE_L1_TLB
| ENABLE_L1_FRAGMENT_PROCESSING
|
1016 SYSTEM_ACCESS_MODE_NOT_IN_SYS
|
1017 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
1018 ENABLE_WAIT_L2_QUERY
;
1019 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL
, tmp
);
1020 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL
, tmp
);
1021 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL
, tmp
| ENABLE_L1_STRICT_ORDERING
);
1022 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL
, tmp
);
1023 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL
, tmp
);
1024 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL
, tmp
);
1025 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL
, tmp
);
1026 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL
, tmp
);
1027 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL
, tmp
);
1028 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL
, tmp
);
1029 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL
, tmp
);
1030 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL
, tmp
);
1031 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL
, tmp
| ENABLE_SEMAPHORE_MODE
);
1032 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL
, tmp
| ENABLE_SEMAPHORE_MODE
);
1033 for (i
= 0; i
< 7; i
++)
1034 WREG32(VM_CONTEXT0_CNTL
+ (i
* 4), 0);
1037 int r600_mc_wait_for_idle(struct radeon_device
*rdev
)
1042 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
1043 /* read MC_STATUS */
1044 tmp
= RREG32(R_000E50_SRBM_STATUS
) & 0x3F00;
1052 uint32_t rs780_mc_rreg(struct radeon_device
*rdev
, uint32_t reg
)
1056 WREG32(R_0028F8_MC_INDEX
, S_0028F8_MC_IND_ADDR(reg
));
1057 r
= RREG32(R_0028FC_MC_DATA
);
1058 WREG32(R_0028F8_MC_INDEX
, ~C_0028F8_MC_IND_ADDR
);
1062 void rs780_mc_wreg(struct radeon_device
*rdev
, uint32_t reg
, uint32_t v
)
1064 WREG32(R_0028F8_MC_INDEX
, S_0028F8_MC_IND_ADDR(reg
) |
1065 S_0028F8_MC_IND_WR_EN(1));
1066 WREG32(R_0028FC_MC_DATA
, v
);
1067 WREG32(R_0028F8_MC_INDEX
, 0x7F);
1070 static void r600_mc_program(struct radeon_device
*rdev
)
1072 struct rv515_mc_save save
;
1076 /* Initialize HDP */
1077 for (i
= 0, j
= 0; i
< 32; i
++, j
+= 0x18) {
1078 WREG32((0x2c14 + j
), 0x00000000);
1079 WREG32((0x2c18 + j
), 0x00000000);
1080 WREG32((0x2c1c + j
), 0x00000000);
1081 WREG32((0x2c20 + j
), 0x00000000);
1082 WREG32((0x2c24 + j
), 0x00000000);
1084 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL
, 0);
1086 rv515_mc_stop(rdev
, &save
);
1087 if (r600_mc_wait_for_idle(rdev
)) {
1088 dev_warn(rdev
->dev
, "Wait for MC idle timedout !\n");
1090 /* Lockout access through VGA aperture (doesn't exist before R600) */
1091 WREG32(VGA_HDP_CONTROL
, VGA_MEMORY_DISABLE
);
1092 /* Update configuration */
1093 if (rdev
->flags
& RADEON_IS_AGP
) {
1094 if (rdev
->mc
.vram_start
< rdev
->mc
.gtt_start
) {
1095 /* VRAM before AGP */
1096 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR
,
1097 rdev
->mc
.vram_start
>> 12);
1098 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR
,
1099 rdev
->mc
.gtt_end
>> 12);
1101 /* VRAM after AGP */
1102 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR
,
1103 rdev
->mc
.gtt_start
>> 12);
1104 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR
,
1105 rdev
->mc
.vram_end
>> 12);
1108 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR
, rdev
->mc
.vram_start
>> 12);
1109 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR
, rdev
->mc
.vram_end
>> 12);
1111 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR
, rdev
->vram_scratch
.gpu_addr
>> 12);
1112 tmp
= ((rdev
->mc
.vram_end
>> 24) & 0xFFFF) << 16;
1113 tmp
|= ((rdev
->mc
.vram_start
>> 24) & 0xFFFF);
1114 WREG32(MC_VM_FB_LOCATION
, tmp
);
1115 WREG32(HDP_NONSURFACE_BASE
, (rdev
->mc
.vram_start
>> 8));
1116 WREG32(HDP_NONSURFACE_INFO
, (2 << 7));
1117 WREG32(HDP_NONSURFACE_SIZE
, 0x3FFFFFFF);
1118 if (rdev
->flags
& RADEON_IS_AGP
) {
1119 WREG32(MC_VM_AGP_TOP
, rdev
->mc
.gtt_end
>> 22);
1120 WREG32(MC_VM_AGP_BOT
, rdev
->mc
.gtt_start
>> 22);
1121 WREG32(MC_VM_AGP_BASE
, rdev
->mc
.agp_base
>> 22);
1123 WREG32(MC_VM_AGP_BASE
, 0);
1124 WREG32(MC_VM_AGP_TOP
, 0x0FFFFFFF);
1125 WREG32(MC_VM_AGP_BOT
, 0x0FFFFFFF);
1127 if (r600_mc_wait_for_idle(rdev
)) {
1128 dev_warn(rdev
->dev
, "Wait for MC idle timedout !\n");
1130 rv515_mc_resume(rdev
, &save
);
1131 /* we need to own VRAM, so turn off the VGA renderer here
1132 * to stop it overwriting our objects */
1133 rv515_vga_render_disable(rdev
);
1137 * r600_vram_gtt_location - try to find VRAM & GTT location
1138 * @rdev: radeon device structure holding all necessary informations
1139 * @mc: memory controller structure holding memory informations
1141 * Function will place try to place VRAM at same place as in CPU (PCI)
1142 * address space as some GPU seems to have issue when we reprogram at
1143 * different address space.
1145 * If there is not enough space to fit the unvisible VRAM after the
1146 * aperture then we limit the VRAM size to the aperture.
1148 * If we are using AGP then place VRAM adjacent to AGP aperture are we need
1149 * them to be in one from GPU point of view so that we can program GPU to
1150 * catch access outside them (weird GPU policy see ??).
1152 * This function will never fails, worst case are limiting VRAM or GTT.
1154 * Note: GTT start, end, size should be initialized before calling this
1155 * function on AGP platform.
1157 static void r600_vram_gtt_location(struct radeon_device
*rdev
, struct radeon_mc
*mc
)
1159 u64 size_bf
, size_af
;
1161 if (mc
->mc_vram_size
> 0xE0000000) {
1162 /* leave room for at least 512M GTT */
1163 dev_warn(rdev
->dev
, "limiting VRAM\n");
1164 mc
->real_vram_size
= 0xE0000000;
1165 mc
->mc_vram_size
= 0xE0000000;
1167 if (rdev
->flags
& RADEON_IS_AGP
) {
1168 size_bf
= mc
->gtt_start
;
1169 size_af
= mc
->mc_mask
- mc
->gtt_end
;
1170 if (size_bf
> size_af
) {
1171 if (mc
->mc_vram_size
> size_bf
) {
1172 dev_warn(rdev
->dev
, "limiting VRAM\n");
1173 mc
->real_vram_size
= size_bf
;
1174 mc
->mc_vram_size
= size_bf
;
1176 mc
->vram_start
= mc
->gtt_start
- mc
->mc_vram_size
;
1178 if (mc
->mc_vram_size
> size_af
) {
1179 dev_warn(rdev
->dev
, "limiting VRAM\n");
1180 mc
->real_vram_size
= size_af
;
1181 mc
->mc_vram_size
= size_af
;
1183 mc
->vram_start
= mc
->gtt_end
+ 1;
1185 mc
->vram_end
= mc
->vram_start
+ mc
->mc_vram_size
- 1;
1186 dev_info(rdev
->dev
, "VRAM: %juM 0x%08jX - 0x%08jX (%juM used)\n",
1187 (uintmax_t)mc
->mc_vram_size
>> 20, (uintmax_t)mc
->vram_start
,
1188 (uintmax_t)mc
->vram_end
, (uintmax_t)mc
->real_vram_size
>> 20);
1191 if (rdev
->flags
& RADEON_IS_IGP
) {
1192 base
= RREG32(MC_VM_FB_LOCATION
) & 0xFFFF;
1195 radeon_vram_location(rdev
, &rdev
->mc
, base
);
1196 rdev
->mc
.gtt_base_align
= 0;
1197 radeon_gtt_location(rdev
, mc
);
1201 static int r600_mc_init(struct radeon_device
*rdev
)
1204 int chansize
, numchan
;
1205 uint32_t h_addr
, l_addr
;
1206 unsigned long long k8_addr
;
1208 /* Get VRAM informations */
1209 rdev
->mc
.vram_is_ddr
= true;
1210 tmp
= RREG32(RAMCFG
);
1211 if (tmp
& CHANSIZE_OVERRIDE
) {
1213 } else if (tmp
& CHANSIZE_MASK
) {
1218 tmp
= RREG32(CHMAP
);
1219 switch ((tmp
& NOOFCHAN_MASK
) >> NOOFCHAN_SHIFT
) {
1234 rdev
->mc
.vram_width
= numchan
* chansize
;
1235 /* Could aper size report 0 ? */
1236 rdev
->mc
.aper_base
= drm_get_resource_start(rdev
->ddev
, 0);
1237 rdev
->mc
.aper_size
= drm_get_resource_len(rdev
->ddev
, 0);
1238 /* Setup GPU memory space */
1239 rdev
->mc
.mc_vram_size
= RREG32(CONFIG_MEMSIZE
);
1240 rdev
->mc
.real_vram_size
= RREG32(CONFIG_MEMSIZE
);
1241 rdev
->mc
.visible_vram_size
= rdev
->mc
.aper_size
;
1242 r600_vram_gtt_location(rdev
, &rdev
->mc
);
1244 if (rdev
->flags
& RADEON_IS_IGP
) {
1245 rs690_pm_info(rdev
);
1246 rdev
->mc
.igp_sideport_enabled
= radeon_atombios_sideport_present(rdev
);
1248 if (rdev
->family
== CHIP_RS780
|| rdev
->family
== CHIP_RS880
) {
1249 /* Use K8 direct mapping for fast fb access. */
1250 rdev
->fastfb_working
= false;
1251 h_addr
= G_000012_K8_ADDR_EXT(RREG32_MC(R_000012_MC_MISC_UMA_CNTL
));
1252 l_addr
= RREG32_MC(R_000011_K8_FB_LOCATION
);
1253 k8_addr
= ((unsigned long long)h_addr
) << 32 | l_addr
;
1254 #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
1255 if (k8_addr
+ rdev
->mc
.visible_vram_size
< 0x100000000ULL
)
1258 /* FastFB shall be used with UMA memory. Here it is simply disabled when sideport
1259 * memory is present.
1261 if (rdev
->mc
.igp_sideport_enabled
== false && radeon_fastfb
== 1) {
1262 DRM_INFO("Direct mapping: aper base at 0x%llx, replaced by direct mapping base 0x%llx.\n",
1263 (unsigned long long)rdev
->mc
.aper_base
, k8_addr
);
1264 rdev
->mc
.aper_base
= (resource_size_t
)k8_addr
;
1265 rdev
->fastfb_working
= true;
1271 radeon_update_bandwidth_info(rdev
);
1275 int r600_vram_scratch_init(struct radeon_device
*rdev
)
1278 void *vram_scratch_ptr_ptr
;
1280 if (rdev
->vram_scratch
.robj
== NULL
) {
1281 r
= radeon_bo_create(rdev
, RADEON_GPU_PAGE_SIZE
,
1282 PAGE_SIZE
, true, RADEON_GEM_DOMAIN_VRAM
,
1283 NULL
, &rdev
->vram_scratch
.robj
);
1289 r
= radeon_bo_reserve(rdev
->vram_scratch
.robj
, false);
1290 if (unlikely(r
!= 0)) {
1291 radeon_bo_unref(&rdev
->vram_scratch
.robj
);
1294 r
= radeon_bo_pin(rdev
->vram_scratch
.robj
,
1295 RADEON_GEM_DOMAIN_VRAM
, &rdev
->vram_scratch
.gpu_addr
);
1297 radeon_bo_unreserve(rdev
->vram_scratch
.robj
);
1298 radeon_bo_unref(&rdev
->vram_scratch
.robj
);
1301 vram_scratch_ptr_ptr
= &rdev
->vram_scratch
.ptr
;
1302 r
= radeon_bo_kmap(rdev
->vram_scratch
.robj
,
1303 vram_scratch_ptr_ptr
);
1305 radeon_bo_unpin(rdev
->vram_scratch
.robj
);
1306 radeon_bo_unreserve(rdev
->vram_scratch
.robj
);
1308 radeon_bo_unref(&rdev
->vram_scratch
.robj
);
1313 void r600_vram_scratch_fini(struct radeon_device
*rdev
)
1317 if (rdev
->vram_scratch
.robj
== NULL
) {
1320 r
= radeon_bo_reserve(rdev
->vram_scratch
.robj
, false);
1321 if (likely(r
== 0)) {
1322 radeon_bo_kunmap(rdev
->vram_scratch
.robj
);
1323 radeon_bo_unpin(rdev
->vram_scratch
.robj
);
1324 radeon_bo_unreserve(rdev
->vram_scratch
.robj
);
1326 radeon_bo_unref(&rdev
->vram_scratch
.robj
);
1329 void r600_set_bios_scratch_engine_hung(struct radeon_device
*rdev
, bool hung
)
1331 u32 tmp
= RREG32(R600_BIOS_3_SCRATCH
);
1334 tmp
|= ATOM_S3_ASIC_GUI_ENGINE_HUNG
;
1336 tmp
&= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG
;
1338 WREG32(R600_BIOS_3_SCRATCH
, tmp
);
1341 static void r600_print_gpu_status_regs(struct radeon_device
*rdev
)
1343 dev_info(rdev
->dev
, " R_008010_GRBM_STATUS = 0x%08X\n",
1344 RREG32(R_008010_GRBM_STATUS
));
1345 dev_info(rdev
->dev
, " R_008014_GRBM_STATUS2 = 0x%08X\n",
1346 RREG32(R_008014_GRBM_STATUS2
));
1347 dev_info(rdev
->dev
, " R_000E50_SRBM_STATUS = 0x%08X\n",
1348 RREG32(R_000E50_SRBM_STATUS
));
1349 dev_info(rdev
->dev
, " R_008674_CP_STALLED_STAT1 = 0x%08X\n",
1350 RREG32(CP_STALLED_STAT1
));
1351 dev_info(rdev
->dev
, " R_008678_CP_STALLED_STAT2 = 0x%08X\n",
1352 RREG32(CP_STALLED_STAT2
));
1353 dev_info(rdev
->dev
, " R_00867C_CP_BUSY_STAT = 0x%08X\n",
1354 RREG32(CP_BUSY_STAT
));
1355 dev_info(rdev
->dev
, " R_008680_CP_STAT = 0x%08X\n",
1357 dev_info(rdev
->dev
, " R_00D034_DMA_STATUS_REG = 0x%08X\n",
1358 RREG32(DMA_STATUS_REG
));
1361 static bool r600_is_display_hung(struct radeon_device
*rdev
)
1367 for (i
= 0; i
< rdev
->num_crtc
; i
++) {
1368 if (RREG32(AVIVO_D1CRTC_CONTROL
+ crtc_offsets
[i
]) & AVIVO_CRTC_EN
) {
1369 crtc_status
[i
] = RREG32(AVIVO_D1CRTC_STATUS_HV_COUNT
+ crtc_offsets
[i
]);
1370 crtc_hung
|= (1 << i
);
1374 for (j
= 0; j
< 10; j
++) {
1375 for (i
= 0; i
< rdev
->num_crtc
; i
++) {
1376 if (crtc_hung
& (1 << i
)) {
1377 tmp
= RREG32(AVIVO_D1CRTC_STATUS_HV_COUNT
+ crtc_offsets
[i
]);
1378 if (tmp
!= crtc_status
[i
])
1379 crtc_hung
&= ~(1 << i
);
1390 static u32
r600_gpu_check_soft_reset(struct radeon_device
*rdev
)
1396 tmp
= RREG32(R_008010_GRBM_STATUS
);
1397 if (rdev
->family
>= CHIP_RV770
) {
1398 if (G_008010_PA_BUSY(tmp
) | G_008010_SC_BUSY(tmp
) |
1399 G_008010_SH_BUSY(tmp
) | G_008010_SX_BUSY(tmp
) |
1400 G_008010_TA_BUSY(tmp
) | G_008010_VGT_BUSY(tmp
) |
1401 G_008010_DB03_BUSY(tmp
) | G_008010_CB03_BUSY(tmp
) |
1402 G_008010_SPI03_BUSY(tmp
) | G_008010_VGT_BUSY_NO_DMA(tmp
))
1403 reset_mask
|= RADEON_RESET_GFX
;
1405 if (G_008010_PA_BUSY(tmp
) | G_008010_SC_BUSY(tmp
) |
1406 G_008010_SH_BUSY(tmp
) | G_008010_SX_BUSY(tmp
) |
1407 G_008010_TA03_BUSY(tmp
) | G_008010_VGT_BUSY(tmp
) |
1408 G_008010_DB03_BUSY(tmp
) | G_008010_CB03_BUSY(tmp
) |
1409 G_008010_SPI03_BUSY(tmp
) | G_008010_VGT_BUSY_NO_DMA(tmp
))
1410 reset_mask
|= RADEON_RESET_GFX
;
1413 if (G_008010_CF_RQ_PENDING(tmp
) | G_008010_PF_RQ_PENDING(tmp
) |
1414 G_008010_CP_BUSY(tmp
) | G_008010_CP_COHERENCY_BUSY(tmp
))
1415 reset_mask
|= RADEON_RESET_CP
;
1417 if (G_008010_GRBM_EE_BUSY(tmp
))
1418 reset_mask
|= RADEON_RESET_GRBM
| RADEON_RESET_GFX
| RADEON_RESET_CP
;
1420 /* DMA_STATUS_REG */
1421 tmp
= RREG32(DMA_STATUS_REG
);
1422 if (!(tmp
& DMA_IDLE
))
1423 reset_mask
|= RADEON_RESET_DMA
;
1426 tmp
= RREG32(R_000E50_SRBM_STATUS
);
1427 if (G_000E50_RLC_RQ_PENDING(tmp
) | G_000E50_RLC_BUSY(tmp
))
1428 reset_mask
|= RADEON_RESET_RLC
;
1430 if (G_000E50_IH_BUSY(tmp
))
1431 reset_mask
|= RADEON_RESET_IH
;
1433 if (G_000E50_SEM_BUSY(tmp
))
1434 reset_mask
|= RADEON_RESET_SEM
;
1436 if (G_000E50_GRBM_RQ_PENDING(tmp
))
1437 reset_mask
|= RADEON_RESET_GRBM
;
1439 if (G_000E50_VMC_BUSY(tmp
))
1440 reset_mask
|= RADEON_RESET_VMC
;
1442 if (G_000E50_MCB_BUSY(tmp
) | G_000E50_MCDZ_BUSY(tmp
) |
1443 G_000E50_MCDY_BUSY(tmp
) | G_000E50_MCDX_BUSY(tmp
) |
1444 G_000E50_MCDW_BUSY(tmp
))
1445 reset_mask
|= RADEON_RESET_MC
;
1447 if (r600_is_display_hung(rdev
))
1448 reset_mask
|= RADEON_RESET_DISPLAY
;
1450 /* Skip MC reset as it's mostly likely not hung, just busy */
1451 if (reset_mask
& RADEON_RESET_MC
) {
1452 DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask
);
1453 reset_mask
&= ~RADEON_RESET_MC
;
1459 static void r600_gpu_soft_reset(struct radeon_device
*rdev
, u32 reset_mask
)
1461 struct rv515_mc_save save
;
1462 u32 grbm_soft_reset
= 0, srbm_soft_reset
= 0;
1465 if (reset_mask
== 0)
1468 dev_info(rdev
->dev
, "GPU softreset: 0x%08X\n", reset_mask
);
1470 r600_print_gpu_status_regs(rdev
);
1472 /* Disable CP parsing/prefetching */
1473 if (rdev
->family
>= CHIP_RV770
)
1474 WREG32(R_0086D8_CP_ME_CNTL
, S_0086D8_CP_ME_HALT(1) | S_0086D8_CP_PFP_HALT(1));
1476 WREG32(R_0086D8_CP_ME_CNTL
, S_0086D8_CP_ME_HALT(1));
1478 /* disable the RLC */
1479 WREG32(RLC_CNTL
, 0);
1481 if (reset_mask
& RADEON_RESET_DMA
) {
1483 tmp
= RREG32(DMA_RB_CNTL
);
1484 tmp
&= ~DMA_RB_ENABLE
;
1485 WREG32(DMA_RB_CNTL
, tmp
);
1490 rv515_mc_stop(rdev
, &save
);
1491 if (r600_mc_wait_for_idle(rdev
)) {
1492 dev_warn(rdev
->dev
, "Wait for MC idle timedout !\n");
1495 if (reset_mask
& (RADEON_RESET_GFX
| RADEON_RESET_COMPUTE
)) {
1496 if (rdev
->family
>= CHIP_RV770
)
1497 grbm_soft_reset
|= S_008020_SOFT_RESET_DB(1) |
1498 S_008020_SOFT_RESET_CB(1) |
1499 S_008020_SOFT_RESET_PA(1) |
1500 S_008020_SOFT_RESET_SC(1) |
1501 S_008020_SOFT_RESET_SPI(1) |
1502 S_008020_SOFT_RESET_SX(1) |
1503 S_008020_SOFT_RESET_SH(1) |
1504 S_008020_SOFT_RESET_TC(1) |
1505 S_008020_SOFT_RESET_TA(1) |
1506 S_008020_SOFT_RESET_VC(1) |
1507 S_008020_SOFT_RESET_VGT(1);
1509 grbm_soft_reset
|= S_008020_SOFT_RESET_CR(1) |
1510 S_008020_SOFT_RESET_DB(1) |
1511 S_008020_SOFT_RESET_CB(1) |
1512 S_008020_SOFT_RESET_PA(1) |
1513 S_008020_SOFT_RESET_SC(1) |
1514 S_008020_SOFT_RESET_SMX(1) |
1515 S_008020_SOFT_RESET_SPI(1) |
1516 S_008020_SOFT_RESET_SX(1) |
1517 S_008020_SOFT_RESET_SH(1) |
1518 S_008020_SOFT_RESET_TC(1) |
1519 S_008020_SOFT_RESET_TA(1) |
1520 S_008020_SOFT_RESET_VC(1) |
1521 S_008020_SOFT_RESET_VGT(1);
1524 if (reset_mask
& RADEON_RESET_CP
) {
1525 grbm_soft_reset
|= S_008020_SOFT_RESET_CP(1) |
1526 S_008020_SOFT_RESET_VGT(1);
1528 srbm_soft_reset
|= S_000E60_SOFT_RESET_GRBM(1);
1531 if (reset_mask
& RADEON_RESET_DMA
) {
1532 if (rdev
->family
>= CHIP_RV770
)
1533 srbm_soft_reset
|= RV770_SOFT_RESET_DMA
;
1535 srbm_soft_reset
|= SOFT_RESET_DMA
;
1538 if (reset_mask
& RADEON_RESET_RLC
)
1539 srbm_soft_reset
|= S_000E60_SOFT_RESET_RLC(1);
1541 if (reset_mask
& RADEON_RESET_SEM
)
1542 srbm_soft_reset
|= S_000E60_SOFT_RESET_SEM(1);
1544 if (reset_mask
& RADEON_RESET_IH
)
1545 srbm_soft_reset
|= S_000E60_SOFT_RESET_IH(1);
1547 if (reset_mask
& RADEON_RESET_GRBM
)
1548 srbm_soft_reset
|= S_000E60_SOFT_RESET_GRBM(1);
1550 if (!(rdev
->flags
& RADEON_IS_IGP
)) {
1551 if (reset_mask
& RADEON_RESET_MC
)
1552 srbm_soft_reset
|= S_000E60_SOFT_RESET_MC(1);
1555 if (reset_mask
& RADEON_RESET_VMC
)
1556 srbm_soft_reset
|= S_000E60_SOFT_RESET_VMC(1);
1558 if (grbm_soft_reset
) {
1559 tmp
= RREG32(R_008020_GRBM_SOFT_RESET
);
1560 tmp
|= grbm_soft_reset
;
1561 dev_info(rdev
->dev
, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp
);
1562 WREG32(R_008020_GRBM_SOFT_RESET
, tmp
);
1563 tmp
= RREG32(R_008020_GRBM_SOFT_RESET
);
1567 tmp
&= ~grbm_soft_reset
;
1568 WREG32(R_008020_GRBM_SOFT_RESET
, tmp
);
1569 tmp
= RREG32(R_008020_GRBM_SOFT_RESET
);
1572 if (srbm_soft_reset
) {
1573 tmp
= RREG32(SRBM_SOFT_RESET
);
1574 tmp
|= srbm_soft_reset
;
1575 dev_info(rdev
->dev
, "SRBM_SOFT_RESET=0x%08X\n", tmp
);
1576 WREG32(SRBM_SOFT_RESET
, tmp
);
1577 tmp
= RREG32(SRBM_SOFT_RESET
);
1581 tmp
&= ~srbm_soft_reset
;
1582 WREG32(SRBM_SOFT_RESET
, tmp
);
1583 tmp
= RREG32(SRBM_SOFT_RESET
);
1586 /* Wait a little for things to settle down */
1589 rv515_mc_resume(rdev
, &save
);
1592 r600_print_gpu_status_regs(rdev
);
1595 int r600_asic_reset(struct radeon_device
*rdev
)
1599 reset_mask
= r600_gpu_check_soft_reset(rdev
);
1602 r600_set_bios_scratch_engine_hung(rdev
, true);
1604 r600_gpu_soft_reset(rdev
, reset_mask
);
1606 reset_mask
= r600_gpu_check_soft_reset(rdev
);
1609 r600_set_bios_scratch_engine_hung(rdev
, false);
1615 * r600_gfx_is_lockup - Check if the GFX engine is locked up
1617 * @rdev: radeon_device pointer
1618 * @ring: radeon_ring structure holding ring information
1620 * Check if the GFX engine is locked up.
1621 * Returns true if the engine appears to be locked up, false if not.
1623 bool r600_gfx_is_lockup(struct radeon_device
*rdev
, struct radeon_ring
*ring
)
1625 u32 reset_mask
= r600_gpu_check_soft_reset(rdev
);
1627 if (!(reset_mask
& (RADEON_RESET_GFX
|
1628 RADEON_RESET_COMPUTE
|
1629 RADEON_RESET_CP
))) {
1630 radeon_ring_lockup_update(ring
);
1633 /* force CP activities */
1634 radeon_ring_force_activity(rdev
, ring
);
1635 return radeon_ring_test_lockup(rdev
, ring
);
1639 * r600_dma_is_lockup - Check if the DMA engine is locked up
1641 * @rdev: radeon_device pointer
1642 * @ring: radeon_ring structure holding ring information
1644 * Check if the async DMA engine is locked up.
1645 * Returns true if the engine appears to be locked up, false if not.
1647 bool r600_dma_is_lockup(struct radeon_device
*rdev
, struct radeon_ring
*ring
)
1649 u32 reset_mask
= r600_gpu_check_soft_reset(rdev
);
1651 if (!(reset_mask
& RADEON_RESET_DMA
)) {
1652 radeon_ring_lockup_update(ring
);
1655 /* force ring activities */
1656 radeon_ring_force_activity(rdev
, ring
);
1657 return radeon_ring_test_lockup(rdev
, ring
);
1660 u32
r6xx_remap_render_backend(struct radeon_device
*rdev
,
1661 u32 tiling_pipe_num
,
1663 u32 total_max_rb_num
,
1664 u32 disabled_rb_mask
)
1666 u32 rendering_pipe_num
, rb_num_width
, req_rb_num
;
1667 u32 pipe_rb_ratio
, pipe_rb_remain
, tmp
;
1668 u32 data
= 0, mask
= 1 << (max_rb_num
- 1);
1671 /* mask out the RBs that don't exist on that asic */
1672 tmp
= disabled_rb_mask
| ((0xff << max_rb_num
) & 0xff);
1673 /* make sure at least one RB is available */
1674 if ((tmp
& 0xff) != 0xff)
1675 disabled_rb_mask
= tmp
;
1677 rendering_pipe_num
= 1 << tiling_pipe_num
;
1678 req_rb_num
= total_max_rb_num
- r600_count_pipe_bits(disabled_rb_mask
);
1679 KASSERT(rendering_pipe_num
>= req_rb_num
, ("rendering_pipe_num < req_rb_num"));
1681 pipe_rb_ratio
= rendering_pipe_num
/ req_rb_num
;
1682 pipe_rb_remain
= rendering_pipe_num
- pipe_rb_ratio
* req_rb_num
;
1684 if (rdev
->family
<= CHIP_RV740
) {
1692 for (i
= 0; i
< max_rb_num
; i
++) {
1693 if (!(mask
& disabled_rb_mask
)) {
1694 for (j
= 0; j
< pipe_rb_ratio
; j
++) {
1695 data
<<= rb_num_width
;
1696 data
|= max_rb_num
- i
- 1;
1698 if (pipe_rb_remain
) {
1699 data
<<= rb_num_width
;
1700 data
|= max_rb_num
- i
- 1;
1710 int r600_count_pipe_bits(uint32_t val
)
1712 return hweight32(val
);
1715 static void r600_gpu_init(struct radeon_device
*rdev
)
1719 u32 cc_rb_backend_disable
;
1720 u32 cc_gc_shader_pipe_config
;
1724 u32 sq_gpr_resource_mgmt_1
= 0;
1725 u32 sq_gpr_resource_mgmt_2
= 0;
1726 u32 sq_thread_resource_mgmt
= 0;
1727 u32 sq_stack_resource_mgmt_1
= 0;
1728 u32 sq_stack_resource_mgmt_2
= 0;
1729 u32 disabled_rb_mask
;
1731 rdev
->config
.r600
.tiling_group_size
= 256;
1732 switch (rdev
->family
) {
1734 rdev
->config
.r600
.max_pipes
= 4;
1735 rdev
->config
.r600
.max_tile_pipes
= 8;
1736 rdev
->config
.r600
.max_simds
= 4;
1737 rdev
->config
.r600
.max_backends
= 4;
1738 rdev
->config
.r600
.max_gprs
= 256;
1739 rdev
->config
.r600
.max_threads
= 192;
1740 rdev
->config
.r600
.max_stack_entries
= 256;
1741 rdev
->config
.r600
.max_hw_contexts
= 8;
1742 rdev
->config
.r600
.max_gs_threads
= 16;
1743 rdev
->config
.r600
.sx_max_export_size
= 128;
1744 rdev
->config
.r600
.sx_max_export_pos_size
= 16;
1745 rdev
->config
.r600
.sx_max_export_smx_size
= 128;
1746 rdev
->config
.r600
.sq_num_cf_insts
= 2;
1750 rdev
->config
.r600
.max_pipes
= 2;
1751 rdev
->config
.r600
.max_tile_pipes
= 2;
1752 rdev
->config
.r600
.max_simds
= 3;
1753 rdev
->config
.r600
.max_backends
= 1;
1754 rdev
->config
.r600
.max_gprs
= 128;
1755 rdev
->config
.r600
.max_threads
= 192;
1756 rdev
->config
.r600
.max_stack_entries
= 128;
1757 rdev
->config
.r600
.max_hw_contexts
= 8;
1758 rdev
->config
.r600
.max_gs_threads
= 4;
1759 rdev
->config
.r600
.sx_max_export_size
= 128;
1760 rdev
->config
.r600
.sx_max_export_pos_size
= 16;
1761 rdev
->config
.r600
.sx_max_export_smx_size
= 128;
1762 rdev
->config
.r600
.sq_num_cf_insts
= 2;
1768 rdev
->config
.r600
.max_pipes
= 1;
1769 rdev
->config
.r600
.max_tile_pipes
= 1;
1770 rdev
->config
.r600
.max_simds
= 2;
1771 rdev
->config
.r600
.max_backends
= 1;
1772 rdev
->config
.r600
.max_gprs
= 128;
1773 rdev
->config
.r600
.max_threads
= 192;
1774 rdev
->config
.r600
.max_stack_entries
= 128;
1775 rdev
->config
.r600
.max_hw_contexts
= 4;
1776 rdev
->config
.r600
.max_gs_threads
= 4;
1777 rdev
->config
.r600
.sx_max_export_size
= 128;
1778 rdev
->config
.r600
.sx_max_export_pos_size
= 16;
1779 rdev
->config
.r600
.sx_max_export_smx_size
= 128;
1780 rdev
->config
.r600
.sq_num_cf_insts
= 1;
1783 rdev
->config
.r600
.max_pipes
= 4;
1784 rdev
->config
.r600
.max_tile_pipes
= 4;
1785 rdev
->config
.r600
.max_simds
= 4;
1786 rdev
->config
.r600
.max_backends
= 4;
1787 rdev
->config
.r600
.max_gprs
= 192;
1788 rdev
->config
.r600
.max_threads
= 192;
1789 rdev
->config
.r600
.max_stack_entries
= 256;
1790 rdev
->config
.r600
.max_hw_contexts
= 8;
1791 rdev
->config
.r600
.max_gs_threads
= 16;
1792 rdev
->config
.r600
.sx_max_export_size
= 128;
1793 rdev
->config
.r600
.sx_max_export_pos_size
= 16;
1794 rdev
->config
.r600
.sx_max_export_smx_size
= 128;
1795 rdev
->config
.r600
.sq_num_cf_insts
= 2;
1801 /* Initialize HDP */
1802 for (i
= 0, j
= 0; i
< 32; i
++, j
+= 0x18) {
1803 WREG32((0x2c14 + j
), 0x00000000);
1804 WREG32((0x2c18 + j
), 0x00000000);
1805 WREG32((0x2c1c + j
), 0x00000000);
1806 WREG32((0x2c20 + j
), 0x00000000);
1807 WREG32((0x2c24 + j
), 0x00000000);
1810 WREG32(GRBM_CNTL
, GRBM_READ_TIMEOUT(0xff));
1814 ramcfg
= RREG32(RAMCFG
);
1815 switch (rdev
->config
.r600
.max_tile_pipes
) {
1817 tiling_config
|= PIPE_TILING(0);
1820 tiling_config
|= PIPE_TILING(1);
1823 tiling_config
|= PIPE_TILING(2);
1826 tiling_config
|= PIPE_TILING(3);
1831 rdev
->config
.r600
.tiling_npipes
= rdev
->config
.r600
.max_tile_pipes
;
1832 rdev
->config
.r600
.tiling_nbanks
= 4 << ((ramcfg
& NOOFBANK_MASK
) >> NOOFBANK_SHIFT
);
1833 tiling_config
|= BANK_TILING((ramcfg
& NOOFBANK_MASK
) >> NOOFBANK_SHIFT
);
1834 tiling_config
|= GROUP_SIZE((ramcfg
& BURSTLENGTH_MASK
) >> BURSTLENGTH_SHIFT
);
1836 tmp
= (ramcfg
& NOOFROWS_MASK
) >> NOOFROWS_SHIFT
;
1838 tiling_config
|= ROW_TILING(3);
1839 tiling_config
|= SAMPLE_SPLIT(3);
1841 tiling_config
|= ROW_TILING(tmp
);
1842 tiling_config
|= SAMPLE_SPLIT(tmp
);
1844 tiling_config
|= BANK_SWAPS(1);
1846 cc_rb_backend_disable
= RREG32(CC_RB_BACKEND_DISABLE
) & 0x00ff0000;
1847 tmp
= R6XX_MAX_BACKENDS
-
1848 r600_count_pipe_bits((cc_rb_backend_disable
>> 16) & R6XX_MAX_BACKENDS_MASK
);
1849 if (tmp
< rdev
->config
.r600
.max_backends
) {
1850 rdev
->config
.r600
.max_backends
= tmp
;
1853 cc_gc_shader_pipe_config
= RREG32(CC_GC_SHADER_PIPE_CONFIG
) & 0x00ffff00;
1854 tmp
= R6XX_MAX_PIPES
-
1855 r600_count_pipe_bits((cc_gc_shader_pipe_config
>> 8) & R6XX_MAX_PIPES_MASK
);
1856 if (tmp
< rdev
->config
.r600
.max_pipes
) {
1857 rdev
->config
.r600
.max_pipes
= tmp
;
1859 tmp
= R6XX_MAX_SIMDS
-
1860 r600_count_pipe_bits((cc_gc_shader_pipe_config
>> 16) & R6XX_MAX_SIMDS_MASK
);
1861 if (tmp
< rdev
->config
.r600
.max_simds
) {
1862 rdev
->config
.r600
.max_simds
= tmp
;
1865 disabled_rb_mask
= (RREG32(CC_RB_BACKEND_DISABLE
) >> 16) & R6XX_MAX_BACKENDS_MASK
;
1866 tmp
= (tiling_config
& PIPE_TILING__MASK
) >> PIPE_TILING__SHIFT
;
1867 tmp
= r6xx_remap_render_backend(rdev
, tmp
, rdev
->config
.r600
.max_backends
,
1868 R6XX_MAX_BACKENDS
, disabled_rb_mask
);
1869 tiling_config
|= tmp
<< 16;
1870 rdev
->config
.r600
.backend_map
= tmp
;
1872 rdev
->config
.r600
.tile_config
= tiling_config
;
1873 WREG32(GB_TILING_CONFIG
, tiling_config
);
1874 WREG32(DCP_TILING_CONFIG
, tiling_config
& 0xffff);
1875 WREG32(HDP_TILING_CONFIG
, tiling_config
& 0xffff);
1876 WREG32(DMA_TILING_CONFIG
, tiling_config
& 0xffff);
1878 tmp
= R6XX_MAX_PIPES
- r600_count_pipe_bits((cc_gc_shader_pipe_config
& INACTIVE_QD_PIPES_MASK
) >> 8);
1879 WREG32(VGT_OUT_DEALLOC_CNTL
, (tmp
* 4) & DEALLOC_DIST_MASK
);
1880 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL
, ((tmp
* 4) - 2) & VTX_REUSE_DEPTH_MASK
);
1882 /* Setup some CP states */
1883 WREG32(CP_QUEUE_THRESHOLDS
, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
1884 WREG32(CP_MEQ_THRESHOLDS
, (MEQ_END(0x40) | ROQ_END(0x40)));
1886 WREG32(TA_CNTL_AUX
, (DISABLE_CUBE_ANISO
| SYNC_GRADIENT
|
1887 SYNC_WALKER
| SYNC_ALIGNER
));
1888 /* Setup various GPU states */
1889 if (rdev
->family
== CHIP_RV670
)
1890 WREG32(ARB_GDEC_RD_CNTL
, 0x00000021);
1892 tmp
= RREG32(SX_DEBUG_1
);
1893 tmp
|= SMX_EVENT_RELEASE
;
1894 if ((rdev
->family
> CHIP_R600
))
1895 tmp
|= ENABLE_NEW_SMX_ADDRESS
;
1896 WREG32(SX_DEBUG_1
, tmp
);
1898 if (((rdev
->family
) == CHIP_R600
) ||
1899 ((rdev
->family
) == CHIP_RV630
) ||
1900 ((rdev
->family
) == CHIP_RV610
) ||
1901 ((rdev
->family
) == CHIP_RV620
) ||
1902 ((rdev
->family
) == CHIP_RS780
) ||
1903 ((rdev
->family
) == CHIP_RS880
)) {
1904 WREG32(DB_DEBUG
, PREZ_MUST_WAIT_FOR_POSTZ_DONE
);
1906 WREG32(DB_DEBUG
, 0);
1908 WREG32(DB_WATERMARKS
, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
1909 DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
1911 WREG32(PA_SC_MULTI_CHIP_CNTL
, 0);
1912 WREG32(VGT_NUM_INSTANCES
, 0);
1914 WREG32(SPI_CONFIG_CNTL
, GPR_WRITE_PRIORITY(0));
1915 WREG32(SPI_CONFIG_CNTL_1
, VTX_DONE_DELAY(0));
1917 tmp
= RREG32(SQ_MS_FIFO_SIZES
);
1918 if (((rdev
->family
) == CHIP_RV610
) ||
1919 ((rdev
->family
) == CHIP_RV620
) ||
1920 ((rdev
->family
) == CHIP_RS780
) ||
1921 ((rdev
->family
) == CHIP_RS880
)) {
1922 tmp
= (CACHE_FIFO_SIZE(0xa) |
1923 FETCH_FIFO_HIWATER(0xa) |
1924 DONE_FIFO_HIWATER(0xe0) |
1925 ALU_UPDATE_FIFO_HIWATER(0x8));
1926 } else if (((rdev
->family
) == CHIP_R600
) ||
1927 ((rdev
->family
) == CHIP_RV630
)) {
1928 tmp
&= ~DONE_FIFO_HIWATER(0xff);
1929 tmp
|= DONE_FIFO_HIWATER(0x4);
1931 WREG32(SQ_MS_FIFO_SIZES
, tmp
);
1933 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
1934 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
1936 sq_config
= RREG32(SQ_CONFIG
);
1937 sq_config
&= ~(PS_PRIO(3) |
1941 sq_config
|= (DX9_CONSTS
|
1948 if ((rdev
->family
) == CHIP_R600
) {
1949 sq_gpr_resource_mgmt_1
= (NUM_PS_GPRS(124) |
1951 NUM_CLAUSE_TEMP_GPRS(4));
1952 sq_gpr_resource_mgmt_2
= (NUM_GS_GPRS(0) |
1954 sq_thread_resource_mgmt
= (NUM_PS_THREADS(136) |
1955 NUM_VS_THREADS(48) |
1958 sq_stack_resource_mgmt_1
= (NUM_PS_STACK_ENTRIES(128) |
1959 NUM_VS_STACK_ENTRIES(128));
1960 sq_stack_resource_mgmt_2
= (NUM_GS_STACK_ENTRIES(0) |
1961 NUM_ES_STACK_ENTRIES(0));
1962 } else if (((rdev
->family
) == CHIP_RV610
) ||
1963 ((rdev
->family
) == CHIP_RV620
) ||
1964 ((rdev
->family
) == CHIP_RS780
) ||
1965 ((rdev
->family
) == CHIP_RS880
)) {
1966 /* no vertex cache */
1967 sq_config
&= ~VC_ENABLE
;
1969 sq_gpr_resource_mgmt_1
= (NUM_PS_GPRS(44) |
1971 NUM_CLAUSE_TEMP_GPRS(2));
1972 sq_gpr_resource_mgmt_2
= (NUM_GS_GPRS(17) |
1974 sq_thread_resource_mgmt
= (NUM_PS_THREADS(79) |
1975 NUM_VS_THREADS(78) |
1977 NUM_ES_THREADS(31));
1978 sq_stack_resource_mgmt_1
= (NUM_PS_STACK_ENTRIES(40) |
1979 NUM_VS_STACK_ENTRIES(40));
1980 sq_stack_resource_mgmt_2
= (NUM_GS_STACK_ENTRIES(32) |
1981 NUM_ES_STACK_ENTRIES(16));
1982 } else if (((rdev
->family
) == CHIP_RV630
) ||
1983 ((rdev
->family
) == CHIP_RV635
)) {
1984 sq_gpr_resource_mgmt_1
= (NUM_PS_GPRS(44) |
1986 NUM_CLAUSE_TEMP_GPRS(2));
1987 sq_gpr_resource_mgmt_2
= (NUM_GS_GPRS(18) |
1989 sq_thread_resource_mgmt
= (NUM_PS_THREADS(79) |
1990 NUM_VS_THREADS(78) |
1992 NUM_ES_THREADS(31));
1993 sq_stack_resource_mgmt_1
= (NUM_PS_STACK_ENTRIES(40) |
1994 NUM_VS_STACK_ENTRIES(40));
1995 sq_stack_resource_mgmt_2
= (NUM_GS_STACK_ENTRIES(32) |
1996 NUM_ES_STACK_ENTRIES(16));
1997 } else if ((rdev
->family
) == CHIP_RV670
) {
1998 sq_gpr_resource_mgmt_1
= (NUM_PS_GPRS(44) |
2000 NUM_CLAUSE_TEMP_GPRS(2));
2001 sq_gpr_resource_mgmt_2
= (NUM_GS_GPRS(17) |
2003 sq_thread_resource_mgmt
= (NUM_PS_THREADS(79) |
2004 NUM_VS_THREADS(78) |
2006 NUM_ES_THREADS(31));
2007 sq_stack_resource_mgmt_1
= (NUM_PS_STACK_ENTRIES(64) |
2008 NUM_VS_STACK_ENTRIES(64));
2009 sq_stack_resource_mgmt_2
= (NUM_GS_STACK_ENTRIES(64) |
2010 NUM_ES_STACK_ENTRIES(64));
2013 WREG32(SQ_CONFIG
, sq_config
);
2014 WREG32(SQ_GPR_RESOURCE_MGMT_1
, sq_gpr_resource_mgmt_1
);
2015 WREG32(SQ_GPR_RESOURCE_MGMT_2
, sq_gpr_resource_mgmt_2
);
2016 WREG32(SQ_THREAD_RESOURCE_MGMT
, sq_thread_resource_mgmt
);
2017 WREG32(SQ_STACK_RESOURCE_MGMT_1
, sq_stack_resource_mgmt_1
);
2018 WREG32(SQ_STACK_RESOURCE_MGMT_2
, sq_stack_resource_mgmt_2
);
2020 if (((rdev
->family
) == CHIP_RV610
) ||
2021 ((rdev
->family
) == CHIP_RV620
) ||
2022 ((rdev
->family
) == CHIP_RS780
) ||
2023 ((rdev
->family
) == CHIP_RS880
)) {
2024 WREG32(VGT_CACHE_INVALIDATION
, CACHE_INVALIDATION(TC_ONLY
));
2026 WREG32(VGT_CACHE_INVALIDATION
, CACHE_INVALIDATION(VC_AND_TC
));
2029 /* More default values. 2D/3D driver should adjust as needed */
2030 WREG32(PA_SC_AA_SAMPLE_LOCS_2S
, (S0_X(0xc) | S0_Y(0x4) |
2031 S1_X(0x4) | S1_Y(0xc)));
2032 WREG32(PA_SC_AA_SAMPLE_LOCS_4S
, (S0_X(0xe) | S0_Y(0xe) |
2033 S1_X(0x2) | S1_Y(0x2) |
2034 S2_X(0xa) | S2_Y(0x6) |
2035 S3_X(0x6) | S3_Y(0xa)));
2036 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0
, (S0_X(0xe) | S0_Y(0xb) |
2037 S1_X(0x4) | S1_Y(0xc) |
2038 S2_X(0x1) | S2_Y(0x6) |
2039 S3_X(0xa) | S3_Y(0xe)));
2040 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1
, (S4_X(0x6) | S4_Y(0x1) |
2041 S5_X(0x0) | S5_Y(0x0) |
2042 S6_X(0xb) | S6_Y(0x4) |
2043 S7_X(0x7) | S7_Y(0x8)));
2045 WREG32(VGT_STRMOUT_EN
, 0);
2046 tmp
= rdev
->config
.r600
.max_pipes
* 16;
2047 switch (rdev
->family
) {
2063 WREG32(VGT_ES_PER_GS
, 128);
2064 WREG32(VGT_GS_PER_ES
, tmp
);
2065 WREG32(VGT_GS_PER_VS
, 2);
2066 WREG32(VGT_GS_VERTEX_REUSE
, 16);
2068 /* more default values. 2D/3D driver should adjust as needed */
2069 WREG32(PA_SC_LINE_STIPPLE_STATE
, 0);
2070 WREG32(VGT_STRMOUT_EN
, 0);
2072 WREG32(PA_SC_MODE_CNTL
, 0);
2073 WREG32(PA_SC_AA_CONFIG
, 0);
2074 WREG32(PA_SC_LINE_STIPPLE
, 0);
2075 WREG32(SPI_INPUT_Z
, 0);
2076 WREG32(SPI_PS_IN_CONTROL_0
, NUM_INTERP(2));
2077 WREG32(CB_COLOR7_FRAG
, 0);
2079 /* Clear render buffer base addresses */
2080 WREG32(CB_COLOR0_BASE
, 0);
2081 WREG32(CB_COLOR1_BASE
, 0);
2082 WREG32(CB_COLOR2_BASE
, 0);
2083 WREG32(CB_COLOR3_BASE
, 0);
2084 WREG32(CB_COLOR4_BASE
, 0);
2085 WREG32(CB_COLOR5_BASE
, 0);
2086 WREG32(CB_COLOR6_BASE
, 0);
2087 WREG32(CB_COLOR7_BASE
, 0);
2088 WREG32(CB_COLOR7_FRAG
, 0);
2090 switch (rdev
->family
) {
2095 tmp
= TC_L2_SIZE(8);
2099 tmp
= TC_L2_SIZE(4);
2102 tmp
= TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT
;
2105 tmp
= TC_L2_SIZE(0);
2108 WREG32(TC_CNTL
, tmp
);
2110 tmp
= RREG32(HDP_HOST_PATH_CNTL
);
2111 WREG32(HDP_HOST_PATH_CNTL
, tmp
);
2113 tmp
= RREG32(ARB_POP
);
2114 tmp
|= ENABLE_TC128
;
2115 WREG32(ARB_POP
, tmp
);
2117 WREG32(PA_SC_MULTI_CHIP_CNTL
, 0);
2118 WREG32(PA_CL_ENHANCE
, (CLIP_VTX_REORDER_ENA
|
2120 WREG32(PA_SC_ENHANCE
, FORCE_EOV_MAX_CLK_CNT(4095));
2121 WREG32(VC_ENHANCE
, 0);
2126 * Indirect registers accessor
2128 u32
r600_pciep_rreg(struct radeon_device
*rdev
, u32 reg
)
2132 WREG32(PCIE_PORT_INDEX
, ((reg
) & 0xff));
2133 (void)RREG32(PCIE_PORT_INDEX
);
2134 r
= RREG32(PCIE_PORT_DATA
);
2138 void r600_pciep_wreg(struct radeon_device
*rdev
, u32 reg
, u32 v
)
2140 WREG32(PCIE_PORT_INDEX
, ((reg
) & 0xff));
2141 (void)RREG32(PCIE_PORT_INDEX
);
2142 WREG32(PCIE_PORT_DATA
, (v
));
2143 (void)RREG32(PCIE_PORT_DATA
);
2149 void r600_cp_stop(struct radeon_device
*rdev
)
2151 radeon_ttm_set_active_vram_size(rdev
, rdev
->mc
.visible_vram_size
);
2152 WREG32(R_0086D8_CP_ME_CNTL
, S_0086D8_CP_ME_HALT(1));
2153 WREG32(SCRATCH_UMSK
, 0);
2154 rdev
->ring
[RADEON_RING_TYPE_GFX_INDEX
].ready
= false;
2157 int r600_init_microcode(struct radeon_device
*rdev
)
2159 const char *chip_name
;
2160 const char *rlc_chip_name
;
2161 size_t pfp_req_size
, me_req_size
, rlc_req_size
;
2167 switch (rdev
->family
) {
2170 rlc_chip_name
= "R600";
2173 chip_name
= "RV610";
2174 rlc_chip_name
= "R600";
2177 chip_name
= "RV630";
2178 rlc_chip_name
= "R600";
2181 chip_name
= "RV620";
2182 rlc_chip_name
= "R600";
2185 chip_name
= "RV635";
2186 rlc_chip_name
= "R600";
2189 chip_name
= "RV670";
2190 rlc_chip_name
= "R600";
2194 chip_name
= "RS780";
2195 rlc_chip_name
= "R600";
2198 chip_name
= "RV770";
2199 rlc_chip_name
= "R700";
2203 chip_name
= "RV730";
2204 rlc_chip_name
= "R700";
2207 chip_name
= "RV710";
2208 rlc_chip_name
= "R700";
2211 chip_name
= "CEDAR";
2212 rlc_chip_name
= "CEDAR";
2215 chip_name
= "REDWOOD";
2216 rlc_chip_name
= "REDWOOD";
2219 chip_name
= "JUNIPER";
2220 rlc_chip_name
= "JUNIPER";
2224 chip_name
= "CYPRESS";
2225 rlc_chip_name
= "CYPRESS";
2229 rlc_chip_name
= "SUMO";
2233 rlc_chip_name
= "SUMO";
2236 chip_name
= "SUMO2";
2237 rlc_chip_name
= "SUMO";
2239 default: panic("%s: Unsupported family %d", __func__
, rdev
->family
);
2242 if (rdev
->family
>= CHIP_CEDAR
) {
2243 pfp_req_size
= EVERGREEN_PFP_UCODE_SIZE
* 4;
2244 me_req_size
= EVERGREEN_PM4_UCODE_SIZE
* 4;
2245 rlc_req_size
= EVERGREEN_RLC_UCODE_SIZE
* 4;
2246 } else if (rdev
->family
>= CHIP_RV770
) {
2247 pfp_req_size
= R700_PFP_UCODE_SIZE
* 4;
2248 me_req_size
= R700_PM4_UCODE_SIZE
* 4;
2249 rlc_req_size
= R700_RLC_UCODE_SIZE
* 4;
2251 pfp_req_size
= PFP_UCODE_SIZE
* 4;
2252 me_req_size
= PM4_UCODE_SIZE
* 12;
2253 rlc_req_size
= RLC_UCODE_SIZE
* 4;
2256 DRM_INFO("Loading %s Microcode\n", chip_name
);
2259 ksnprintf(fw_name
, sizeof(fw_name
), "radeonkmsfw_%s_pfp", chip_name
);
2260 rdev
->pfp_fw
= firmware_get(fw_name
);
2261 if (rdev
->pfp_fw
== NULL
) {
2265 if (rdev
->pfp_fw
->datasize
!= pfp_req_size
) {
2267 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2268 rdev
->pfp_fw
->datasize
, fw_name
);
2273 ksnprintf(fw_name
, sizeof(fw_name
), "radeonkmsfw_%s_me", chip_name
);
2274 rdev
->me_fw
= firmware_get(fw_name
);
2275 if (rdev
->me_fw
== NULL
) {
2279 if (rdev
->me_fw
->datasize
!= me_req_size
) {
2281 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2282 rdev
->me_fw
->datasize
, fw_name
);
2286 ksnprintf(fw_name
, sizeof(fw_name
), "radeonkmsfw_%s_rlc",
2288 rdev
->rlc_fw
= firmware_get(fw_name
);
2289 if (rdev
->rlc_fw
== NULL
) {
2293 if (rdev
->rlc_fw
->datasize
!= rlc_req_size
) {
2295 "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
2296 rdev
->rlc_fw
->datasize
, fw_name
);
2304 "r600_cp: Failed to load firmware \"%s\"\n",
2306 if (rdev
->pfp_fw
!= NULL
) {
2307 firmware_put(rdev
->pfp_fw
, FIRMWARE_UNLOAD
);
2308 rdev
->pfp_fw
= NULL
;
2310 if (rdev
->me_fw
!= NULL
) {
2311 firmware_put(rdev
->me_fw
, FIRMWARE_UNLOAD
);
2314 if (rdev
->rlc_fw
!= NULL
) {
2315 firmware_put(rdev
->rlc_fw
, FIRMWARE_UNLOAD
);
2316 rdev
->rlc_fw
= NULL
;
2323 * r600_fini_microcode - drop the firmwares image references
2325 * @rdev: radeon_device pointer
2327 * Drop the pfp, me and rlc firmwares image references.
2328 * Called at driver shutdown.
2330 void r600_fini_microcode(struct radeon_device
*rdev
)
2333 if (rdev
->pfp_fw
!= NULL
) {
2334 firmware_put(rdev
->pfp_fw
, FIRMWARE_UNLOAD
);
2335 rdev
->pfp_fw
= NULL
;
2338 if (rdev
->me_fw
!= NULL
) {
2339 firmware_put(rdev
->me_fw
, FIRMWARE_UNLOAD
);
2343 if (rdev
->rlc_fw
!= NULL
) {
2344 firmware_put(rdev
->rlc_fw
, FIRMWARE_UNLOAD
);
2345 rdev
->rlc_fw
= NULL
;
2349 static int r600_cp_load_microcode(struct radeon_device
*rdev
)
2351 const __be32
*fw_data
;
2354 if (!rdev
->me_fw
|| !rdev
->pfp_fw
)
2363 RB_NO_UPDATE
| RB_BLKSZ(15) | RB_BUFSZ(3));
2366 WREG32(GRBM_SOFT_RESET
, SOFT_RESET_CP
);
2367 RREG32(GRBM_SOFT_RESET
);
2369 WREG32(GRBM_SOFT_RESET
, 0);
2371 WREG32(CP_ME_RAM_WADDR
, 0);
2373 fw_data
= (const __be32
*)rdev
->me_fw
->data
;
2374 WREG32(CP_ME_RAM_WADDR
, 0);
2375 for (i
= 0; i
< PM4_UCODE_SIZE
* 3; i
++)
2376 WREG32(CP_ME_RAM_DATA
,
2377 be32_to_cpup(fw_data
++));
2379 fw_data
= (const __be32
*)rdev
->pfp_fw
->data
;
2380 WREG32(CP_PFP_UCODE_ADDR
, 0);
2381 for (i
= 0; i
< PFP_UCODE_SIZE
; i
++)
2382 WREG32(CP_PFP_UCODE_DATA
,
2383 be32_to_cpup(fw_data
++));
2385 WREG32(CP_PFP_UCODE_ADDR
, 0);
2386 WREG32(CP_ME_RAM_WADDR
, 0);
2387 WREG32(CP_ME_RAM_RADDR
, 0);
2391 int r600_cp_start(struct radeon_device
*rdev
)
2393 struct radeon_ring
*ring
= &rdev
->ring
[RADEON_RING_TYPE_GFX_INDEX
];
2397 r
= radeon_ring_lock(rdev
, ring
, 7);
2399 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r
);
2402 radeon_ring_write(ring
, PACKET3(PACKET3_ME_INITIALIZE
, 5));
2403 radeon_ring_write(ring
, 0x1);
2404 if (rdev
->family
>= CHIP_RV770
) {
2405 radeon_ring_write(ring
, 0x0);
2406 radeon_ring_write(ring
, rdev
->config
.rv770
.max_hw_contexts
- 1);
2408 radeon_ring_write(ring
, 0x3);
2409 radeon_ring_write(ring
, rdev
->config
.r600
.max_hw_contexts
- 1);
2411 radeon_ring_write(ring
, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
2412 radeon_ring_write(ring
, 0);
2413 radeon_ring_write(ring
, 0);
2414 radeon_ring_unlock_commit(rdev
, ring
);
2417 WREG32(R_0086D8_CP_ME_CNTL
, cp_me
);
2421 int r600_cp_resume(struct radeon_device
*rdev
)
2423 struct radeon_ring
*ring
= &rdev
->ring
[RADEON_RING_TYPE_GFX_INDEX
];
2429 WREG32(GRBM_SOFT_RESET
, SOFT_RESET_CP
);
2430 RREG32(GRBM_SOFT_RESET
);
2432 WREG32(GRBM_SOFT_RESET
, 0);
2434 /* Set ring buffer size */
2435 rb_bufsz
= drm_order(ring
->ring_size
/ 8);
2436 tmp
= (drm_order(RADEON_GPU_PAGE_SIZE
/8) << 8) | rb_bufsz
;
2438 tmp
|= BUF_SWAP_32BIT
;
2440 WREG32(CP_RB_CNTL
, tmp
);
2441 WREG32(CP_SEM_WAIT_TIMER
, 0x0);
2443 /* Set the write pointer delay */
2444 WREG32(CP_RB_WPTR_DELAY
, 0);
2446 /* Initialize the ring buffer's read and write pointers */
2447 WREG32(CP_RB_CNTL
, tmp
| RB_RPTR_WR_ENA
);
2448 WREG32(CP_RB_RPTR_WR
, 0);
2450 WREG32(CP_RB_WPTR
, ring
->wptr
);
2452 /* set the wb address whether it's enabled or not */
2453 WREG32(CP_RB_RPTR_ADDR
,
2454 ((rdev
->wb
.gpu_addr
+ RADEON_WB_CP_RPTR_OFFSET
) & 0xFFFFFFFC));
2455 WREG32(CP_RB_RPTR_ADDR_HI
, upper_32_bits(rdev
->wb
.gpu_addr
+ RADEON_WB_CP_RPTR_OFFSET
) & 0xFF);
2456 WREG32(SCRATCH_ADDR
, ((rdev
->wb
.gpu_addr
+ RADEON_WB_SCRATCH_OFFSET
) >> 8) & 0xFFFFFFFF);
2458 if (rdev
->wb
.enabled
)
2459 WREG32(SCRATCH_UMSK
, 0xff);
2461 tmp
|= RB_NO_UPDATE
;
2462 WREG32(SCRATCH_UMSK
, 0);
2466 WREG32(CP_RB_CNTL
, tmp
);
2468 WREG32(CP_RB_BASE
, ring
->gpu_addr
>> 8);
2469 WREG32(CP_DEBUG
, (1 << 27) | (1 << 28));
2471 ring
->rptr
= RREG32(CP_RB_RPTR
);
2473 r600_cp_start(rdev
);
2475 r
= radeon_ring_test(rdev
, RADEON_RING_TYPE_GFX_INDEX
, ring
);
2477 ring
->ready
= false;
2483 void r600_ring_init(struct radeon_device
*rdev
, struct radeon_ring
*ring
, unsigned ring_size
)
2488 /* Align ring size */
2489 rb_bufsz
= drm_order(ring_size
/ 8);
2490 ring_size
= (1 << (rb_bufsz
+ 1)) * 4;
2491 ring
->ring_size
= ring_size
;
2492 ring
->align_mask
= 16 - 1;
2494 if (radeon_ring_supports_scratch_reg(rdev
, ring
)) {
2495 r
= radeon_scratch_get(rdev
, &ring
->rptr_save_reg
);
2497 DRM_ERROR("failed to get scratch reg for rptr save (%d).\n", r
);
2498 ring
->rptr_save_reg
= 0;
2503 void r600_cp_fini(struct radeon_device
*rdev
)
2505 struct radeon_ring
*ring
= &rdev
->ring
[RADEON_RING_TYPE_GFX_INDEX
];
2507 radeon_ring_fini(rdev
, ring
);
2508 radeon_scratch_free(rdev
, ring
->rptr_save_reg
);
2513 * Starting with R600, the GPU has an asynchronous
2514 * DMA engine. The programming model is very similar
2515 * to the 3D engine (ring buffer, IBs, etc.), but the
2516 * DMA controller has it's own packet format that is
2517 * different form the PM4 format used by the 3D engine.
2518 * It supports copying data, writing embedded data,
2519 * solid fills, and a number of other things. It also
2520 * has support for tiling/detiling of buffers.
2523 * r600_dma_stop - stop the async dma engine
2525 * @rdev: radeon_device pointer
2527 * Stop the async dma engine (r6xx-evergreen).
2529 void r600_dma_stop(struct radeon_device
*rdev
)
2531 u32 rb_cntl
= RREG32(DMA_RB_CNTL
);
2533 radeon_ttm_set_active_vram_size(rdev
, rdev
->mc
.visible_vram_size
);
2535 rb_cntl
&= ~DMA_RB_ENABLE
;
2536 WREG32(DMA_RB_CNTL
, rb_cntl
);
2538 rdev
->ring
[R600_RING_TYPE_DMA_INDEX
].ready
= false;
2542 * r600_dma_resume - setup and start the async dma engine
2544 * @rdev: radeon_device pointer
2546 * Set up the DMA ring buffer and enable it. (r6xx-evergreen).
2547 * Returns 0 for success, error for failure.
2549 int r600_dma_resume(struct radeon_device
*rdev
)
2551 struct radeon_ring
*ring
= &rdev
->ring
[R600_RING_TYPE_DMA_INDEX
];
2552 u32 rb_cntl
, dma_cntl
, ib_cntl
;
2557 if (rdev
->family
>= CHIP_RV770
)
2558 WREG32(SRBM_SOFT_RESET
, RV770_SOFT_RESET_DMA
);
2560 WREG32(SRBM_SOFT_RESET
, SOFT_RESET_DMA
);
2561 RREG32(SRBM_SOFT_RESET
);
2563 WREG32(SRBM_SOFT_RESET
, 0);
2565 WREG32(DMA_SEM_INCOMPLETE_TIMER_CNTL
, 0);
2566 WREG32(DMA_SEM_WAIT_FAIL_TIMER_CNTL
, 0);
2568 /* Set ring buffer size in dwords */
2569 rb_bufsz
= drm_order(ring
->ring_size
/ 4);
2570 rb_cntl
= rb_bufsz
<< 1;
2572 rb_cntl
|= DMA_RB_SWAP_ENABLE
| DMA_RPTR_WRITEBACK_SWAP_ENABLE
;
2574 WREG32(DMA_RB_CNTL
, rb_cntl
);
2576 /* Initialize the ring buffer's read and write pointers */
2577 WREG32(DMA_RB_RPTR
, 0);
2578 WREG32(DMA_RB_WPTR
, 0);
2580 /* set the wb address whether it's enabled or not */
2581 WREG32(DMA_RB_RPTR_ADDR_HI
,
2582 upper_32_bits(rdev
->wb
.gpu_addr
+ R600_WB_DMA_RPTR_OFFSET
) & 0xFF);
2583 WREG32(DMA_RB_RPTR_ADDR_LO
,
2584 ((rdev
->wb
.gpu_addr
+ R600_WB_DMA_RPTR_OFFSET
) & 0xFFFFFFFC));
2586 if (rdev
->wb
.enabled
)
2587 rb_cntl
|= DMA_RPTR_WRITEBACK_ENABLE
;
2589 WREG32(DMA_RB_BASE
, ring
->gpu_addr
>> 8);
2591 /* enable DMA IBs */
2592 ib_cntl
= DMA_IB_ENABLE
;
2594 ib_cntl
|= DMA_IB_SWAP_ENABLE
;
2596 WREG32(DMA_IB_CNTL
, ib_cntl
);
2598 dma_cntl
= RREG32(DMA_CNTL
);
2599 dma_cntl
&= ~CTXEMPTY_INT_ENABLE
;
2600 WREG32(DMA_CNTL
, dma_cntl
);
2602 if (rdev
->family
>= CHIP_RV770
)
2603 WREG32(DMA_MODE
, 1);
2606 WREG32(DMA_RB_WPTR
, ring
->wptr
<< 2);
2608 ring
->rptr
= RREG32(DMA_RB_RPTR
) >> 2;
2610 WREG32(DMA_RB_CNTL
, rb_cntl
| DMA_RB_ENABLE
);
2614 r
= radeon_ring_test(rdev
, R600_RING_TYPE_DMA_INDEX
, ring
);
2616 ring
->ready
= false;
2620 radeon_ttm_set_active_vram_size(rdev
, rdev
->mc
.real_vram_size
);
2626 * r600_dma_fini - tear down the async dma engine
2628 * @rdev: radeon_device pointer
2630 * Stop the async dma engine and free the ring (r6xx-evergreen).
2632 void r600_dma_fini(struct radeon_device
*rdev
)
2634 r600_dma_stop(rdev
);
2635 radeon_ring_fini(rdev
, &rdev
->ring
[R600_RING_TYPE_DMA_INDEX
]);
2641 int r600_uvd_rbc_start(struct radeon_device
*rdev
)
2643 struct radeon_ring
*ring
= &rdev
->ring
[R600_RING_TYPE_UVD_INDEX
];
2645 uint32_t rb_bufsz
, tmp
;
2648 rptr_addr
= rdev
->wb
.gpu_addr
+ R600_WB_UVD_RPTR_OFFSET
;
2650 if (upper_32_bits(rptr_addr
) != upper_32_bits(ring
->gpu_addr
)) {
2651 DRM_ERROR("UVD ring and rptr not in the same 4GB segment!\n");
2655 /* force RBC into idle state */
2656 WREG32(UVD_RBC_RB_CNTL
, 0x11010101);
2658 /* Set the write pointer delay */
2659 WREG32(UVD_RBC_RB_WPTR_CNTL
, 0);
2661 /* set the wb address */
2662 WREG32(UVD_RBC_RB_RPTR_ADDR
, rptr_addr
>> 2);
2664 /* programm the 4GB memory segment for rptr and ring buffer */
2665 WREG32(UVD_LMI_EXT40_ADDR
, upper_32_bits(rptr_addr
) |
2666 (0x7 << 16) | (0x1 << 31));
2668 /* Initialize the ring buffer's read and write pointers */
2669 WREG32(UVD_RBC_RB_RPTR
, 0x0);
2671 ring
->wptr
= ring
->rptr
= RREG32(UVD_RBC_RB_RPTR
);
2672 WREG32(UVD_RBC_RB_WPTR
, ring
->wptr
);
2674 /* set the ring address */
2675 WREG32(UVD_RBC_RB_BASE
, ring
->gpu_addr
);
2677 /* Set ring buffer size */
2678 rb_bufsz
= drm_order(ring
->ring_size
);
2679 rb_bufsz
= (0x1 << 8) | rb_bufsz
;
2680 WREG32(UVD_RBC_RB_CNTL
, rb_bufsz
);
2683 r
= radeon_ring_test(rdev
, R600_RING_TYPE_UVD_INDEX
, ring
);
2685 ring
->ready
= false;
2689 r
= radeon_ring_lock(rdev
, ring
, 10);
2691 DRM_ERROR("radeon: ring failed to lock UVD ring (%d).\n", r
);
2695 tmp
= PACKET0(UVD_SEMA_WAIT_FAULT_TIMEOUT_CNTL
, 0);
2696 radeon_ring_write(ring
, tmp
);
2697 radeon_ring_write(ring
, 0xFFFFF);
2699 tmp
= PACKET0(UVD_SEMA_WAIT_INCOMPLETE_TIMEOUT_CNTL
, 0);
2700 radeon_ring_write(ring
, tmp
);
2701 radeon_ring_write(ring
, 0xFFFFF);
2703 tmp
= PACKET0(UVD_SEMA_SIGNAL_INCOMPLETE_TIMEOUT_CNTL
, 0);
2704 radeon_ring_write(ring
, tmp
);
2705 radeon_ring_write(ring
, 0xFFFFF);
2707 /* Clear timeout status bits */
2708 radeon_ring_write(ring
, PACKET0(UVD_SEMA_TIMEOUT_STATUS
, 0));
2709 radeon_ring_write(ring
, 0x8);
2711 radeon_ring_write(ring
, PACKET0(UVD_SEMA_CNTL
, 0));
2712 radeon_ring_write(ring
, 3);
2714 radeon_ring_unlock_commit(rdev
, ring
);
2719 void r600_uvd_rbc_stop(struct radeon_device
*rdev
)
2721 struct radeon_ring
*ring
= &rdev
->ring
[R600_RING_TYPE_UVD_INDEX
];
2723 /* force RBC into idle state */
2724 WREG32(UVD_RBC_RB_CNTL
, 0x11010101);
2725 ring
->ready
= false;
2728 int r600_uvd_init(struct radeon_device
*rdev
)
2731 /* disable byte swapping */
2732 u32 lmi_swap_cntl
= 0;
2733 u32 mp_swap_cntl
= 0;
2735 /* raise clocks while booting up the VCPU */
2736 radeon_set_uvd_clocks(rdev
, 53300, 40000);
2738 /* disable clock gating */
2739 WREG32(UVD_CGC_GATE
, 0);
2741 /* disable interupt */
2742 WREG32_P(UVD_MASTINT_EN
, 0, ~(1 << 1));
2744 /* put LMI, VCPU, RBC etc... into reset */
2745 WREG32(UVD_SOFT_RESET
, LMI_SOFT_RESET
| VCPU_SOFT_RESET
|
2746 LBSI_SOFT_RESET
| RBC_SOFT_RESET
| CSM_SOFT_RESET
|
2747 CXW_SOFT_RESET
| TAP_SOFT_RESET
| LMI_UMC_SOFT_RESET
);
2750 /* take UVD block out of reset */
2751 WREG32_P(SRBM_SOFT_RESET
, 0, ~SOFT_RESET_UVD
);
2754 /* initialize UVD memory controller */
2755 WREG32(UVD_LMI_CTRL
, 0x40 | (1 << 8) | (1 << 13) |
2756 (1 << 21) | (1 << 9) | (1 << 20));
2759 /* swap (8 in 32) RB and IB */
2760 lmi_swap_cntl
= 0xa;
2763 WREG32(UVD_LMI_SWAP_CNTL
, lmi_swap_cntl
);
2764 WREG32(UVD_MP_SWAP_CNTL
, mp_swap_cntl
);
2766 WREG32(UVD_MPC_SET_MUXA0
, 0x40c2040);
2767 WREG32(UVD_MPC_SET_MUXA1
, 0x0);
2768 WREG32(UVD_MPC_SET_MUXB0
, 0x40c2040);
2769 WREG32(UVD_MPC_SET_MUXB1
, 0x0);
2770 WREG32(UVD_MPC_SET_ALU
, 0);
2771 WREG32(UVD_MPC_SET_MUX
, 0x88);
2774 WREG32_P(UVD_LMI_CTRL2
, 1 << 8, ~(1 << 8));
2775 WREG32_P(UVD_RB_ARB_CTRL
, 1 << 3, ~(1 << 3));
2777 /* take all subblocks out of reset, except VCPU */
2778 WREG32(UVD_SOFT_RESET
, VCPU_SOFT_RESET
);
2781 /* enable VCPU clock */
2782 WREG32(UVD_VCPU_CNTL
, 1 << 9);
2785 WREG32_P(UVD_LMI_CTRL2
, 0, ~(1 << 8));
2787 /* boot up the VCPU */
2788 WREG32(UVD_SOFT_RESET
, 0);
2791 WREG32_P(UVD_RB_ARB_CTRL
, 0, ~(1 << 3));
2793 for (i
= 0; i
< 10; ++i
) {
2795 for (j
= 0; j
< 100; ++j
) {
2796 status
= RREG32(UVD_STATUS
);
2805 DRM_ERROR("UVD not responding, trying to reset the VCPU!!!\n");
2806 WREG32_P(UVD_SOFT_RESET
, VCPU_SOFT_RESET
, ~VCPU_SOFT_RESET
);
2808 WREG32_P(UVD_SOFT_RESET
, 0, ~VCPU_SOFT_RESET
);
2814 DRM_ERROR("UVD not responding, giving up!!!\n");
2815 radeon_set_uvd_clocks(rdev
, 0, 0);
2819 /* enable interupt */
2820 WREG32_P(UVD_MASTINT_EN
, 3<<1, ~(3 << 1));
2822 r
= r600_uvd_rbc_start(rdev
);
2824 DRM_INFO("UVD initialized successfully.\n");
2826 /* lower clocks again */
2827 radeon_set_uvd_clocks(rdev
, 0, 0);
2833 * GPU scratch registers helpers function.
2835 void r600_scratch_init(struct radeon_device
*rdev
)
2839 rdev
->scratch
.num_reg
= 7;
2840 rdev
->scratch
.reg_base
= SCRATCH_REG0
;
2841 for (i
= 0; i
< rdev
->scratch
.num_reg
; i
++) {
2842 rdev
->scratch
.free
[i
] = true;
2843 rdev
->scratch
.reg
[i
] = rdev
->scratch
.reg_base
+ (i
* 4);
2847 int r600_ring_test(struct radeon_device
*rdev
, struct radeon_ring
*ring
)
2854 r
= radeon_scratch_get(rdev
, &scratch
);
2856 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r
);
2859 WREG32(scratch
, 0xCAFEDEAD);
2860 r
= radeon_ring_lock(rdev
, ring
, 3);
2862 DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ring
->idx
, r
);
2863 radeon_scratch_free(rdev
, scratch
);
2866 radeon_ring_write(ring
, PACKET3(PACKET3_SET_CONFIG_REG
, 1));
2867 radeon_ring_write(ring
, ((scratch
- PACKET3_SET_CONFIG_REG_OFFSET
) >> 2));
2868 radeon_ring_write(ring
, 0xDEADBEEF);
2869 radeon_ring_unlock_commit(rdev
, ring
);
2870 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
2871 tmp
= RREG32(scratch
);
2872 if (tmp
== 0xDEADBEEF)
2876 if (i
< rdev
->usec_timeout
) {
2877 DRM_INFO("ring test on %d succeeded in %d usecs\n", ring
->idx
, i
);
2879 DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
2880 ring
->idx
, scratch
, tmp
);
2883 radeon_scratch_free(rdev
, scratch
);
2888 * r600_dma_ring_test - simple async dma engine test
2890 * @rdev: radeon_device pointer
2891 * @ring: radeon_ring structure holding ring information
2893 * Test the DMA engine by writing using it to write an
2894 * value to memory. (r6xx-SI).
2895 * Returns 0 for success, error for failure.
2897 int r600_dma_ring_test(struct radeon_device
*rdev
,
2898 struct radeon_ring
*ring
)
2902 volatile uint32_t *ptr
= rdev
->vram_scratch
.ptr
;
2906 DRM_ERROR("invalid vram scratch pointer\n");
2913 r
= radeon_ring_lock(rdev
, ring
, 4);
2915 DRM_ERROR("radeon: dma failed to lock ring %d (%d).\n", ring
->idx
, r
);
2918 radeon_ring_write(ring
, DMA_PACKET(DMA_PACKET_WRITE
, 0, 0, 1));
2919 radeon_ring_write(ring
, rdev
->vram_scratch
.gpu_addr
& 0xfffffffc);
2920 radeon_ring_write(ring
, upper_32_bits(rdev
->vram_scratch
.gpu_addr
) & 0xff);
2921 radeon_ring_write(ring
, 0xDEADBEEF);
2922 radeon_ring_unlock_commit(rdev
, ring
);
2924 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
2926 if (tmp
== 0xDEADBEEF)
2931 if (i
< rdev
->usec_timeout
) {
2932 DRM_INFO("ring test on %d succeeded in %d usecs\n", ring
->idx
, i
);
2934 DRM_ERROR("radeon: ring %d test failed (0x%08X)\n",
2941 int r600_uvd_ring_test(struct radeon_device
*rdev
, struct radeon_ring
*ring
)
2947 WREG32(UVD_CONTEXT_ID
, 0xCAFEDEAD);
2948 r
= radeon_ring_lock(rdev
, ring
, 3);
2950 DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n",
2954 radeon_ring_write(ring
, PACKET0(UVD_CONTEXT_ID
, 0));
2955 radeon_ring_write(ring
, 0xDEADBEEF);
2956 radeon_ring_unlock_commit(rdev
, ring
);
2957 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
2958 tmp
= RREG32(UVD_CONTEXT_ID
);
2959 if (tmp
== 0xDEADBEEF)
2964 if (i
< rdev
->usec_timeout
) {
2965 DRM_INFO("ring test on %d succeeded in %d usecs\n",
2968 DRM_ERROR("radeon: ring %d test failed (0x%08X)\n",
2976 * CP fences/semaphores
2979 void r600_fence_ring_emit(struct radeon_device
*rdev
,
2980 struct radeon_fence
*fence
)
2982 struct radeon_ring
*ring
= &rdev
->ring
[fence
->ring
];
2984 if (rdev
->wb
.use_event
) {
2985 u64 addr
= rdev
->fence_drv
[fence
->ring
].gpu_addr
;
2986 /* flush read cache over gart */
2987 radeon_ring_write(ring
, PACKET3(PACKET3_SURFACE_SYNC
, 3));
2988 radeon_ring_write(ring
, PACKET3_TC_ACTION_ENA
|
2989 PACKET3_VC_ACTION_ENA
|
2990 PACKET3_SH_ACTION_ENA
);
2991 radeon_ring_write(ring
, 0xFFFFFFFF);
2992 radeon_ring_write(ring
, 0);
2993 radeon_ring_write(ring
, 10); /* poll interval */
2994 /* EVENT_WRITE_EOP - flush caches, send int */
2995 radeon_ring_write(ring
, PACKET3(PACKET3_EVENT_WRITE_EOP
, 4));
2996 radeon_ring_write(ring
, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS
) | EVENT_INDEX(5));
2997 radeon_ring_write(ring
, addr
& 0xffffffff);
2998 radeon_ring_write(ring
, (upper_32_bits(addr
) & 0xff) | DATA_SEL(1) | INT_SEL(2));
2999 radeon_ring_write(ring
, fence
->seq
);
3000 radeon_ring_write(ring
, 0);
3002 /* flush read cache over gart */
3003 radeon_ring_write(ring
, PACKET3(PACKET3_SURFACE_SYNC
, 3));
3004 radeon_ring_write(ring
, PACKET3_TC_ACTION_ENA
|
3005 PACKET3_VC_ACTION_ENA
|
3006 PACKET3_SH_ACTION_ENA
);
3007 radeon_ring_write(ring
, 0xFFFFFFFF);
3008 radeon_ring_write(ring
, 0);
3009 radeon_ring_write(ring
, 10); /* poll interval */
3010 radeon_ring_write(ring
, PACKET3(PACKET3_EVENT_WRITE
, 0));
3011 radeon_ring_write(ring
, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT
) | EVENT_INDEX(0));
3012 /* wait for 3D idle clean */
3013 radeon_ring_write(ring
, PACKET3(PACKET3_SET_CONFIG_REG
, 1));
3014 radeon_ring_write(ring
, (WAIT_UNTIL
- PACKET3_SET_CONFIG_REG_OFFSET
) >> 2);
3015 radeon_ring_write(ring
, WAIT_3D_IDLE_bit
| WAIT_3D_IDLECLEAN_bit
);
3016 /* Emit fence sequence & fire IRQ */
3017 radeon_ring_write(ring
, PACKET3(PACKET3_SET_CONFIG_REG
, 1));
3018 radeon_ring_write(ring
, ((rdev
->fence_drv
[fence
->ring
].scratch_reg
- PACKET3_SET_CONFIG_REG_OFFSET
) >> 2));
3019 radeon_ring_write(ring
, fence
->seq
);
3020 /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
3021 radeon_ring_write(ring
, PACKET0(CP_INT_STATUS
, 0));
3022 radeon_ring_write(ring
, RB_INT_STAT
);
3026 void r600_uvd_fence_emit(struct radeon_device
*rdev
,
3027 struct radeon_fence
*fence
)
3029 struct radeon_ring
*ring
= &rdev
->ring
[fence
->ring
];
3030 uint32_t addr
= rdev
->fence_drv
[fence
->ring
].gpu_addr
;
3032 radeon_ring_write(ring
, PACKET0(UVD_CONTEXT_ID
, 0));
3033 radeon_ring_write(ring
, fence
->seq
);
3034 radeon_ring_write(ring
, PACKET0(UVD_GPCOM_VCPU_DATA0
, 0));
3035 radeon_ring_write(ring
, addr
& 0xffffffff);
3036 radeon_ring_write(ring
, PACKET0(UVD_GPCOM_VCPU_DATA1
, 0));
3037 radeon_ring_write(ring
, upper_32_bits(addr
) & 0xff);
3038 radeon_ring_write(ring
, PACKET0(UVD_GPCOM_VCPU_CMD
, 0));
3039 radeon_ring_write(ring
, 0);
3041 radeon_ring_write(ring
, PACKET0(UVD_GPCOM_VCPU_DATA0
, 0));
3042 radeon_ring_write(ring
, 0);
3043 radeon_ring_write(ring
, PACKET0(UVD_GPCOM_VCPU_DATA1
, 0));
3044 radeon_ring_write(ring
, 0);
3045 radeon_ring_write(ring
, PACKET0(UVD_GPCOM_VCPU_CMD
, 0));
3046 radeon_ring_write(ring
, 2);
3050 void r600_semaphore_ring_emit(struct radeon_device
*rdev
,
3051 struct radeon_ring
*ring
,
3052 struct radeon_semaphore
*semaphore
,
3055 uint64_t addr
= semaphore
->gpu_addr
;
3056 unsigned sel
= emit_wait
? PACKET3_SEM_SEL_WAIT
: PACKET3_SEM_SEL_SIGNAL
;
3058 if (rdev
->family
< CHIP_CAYMAN
)
3059 sel
|= PACKET3_SEM_WAIT_ON_SIGNAL
;
3061 radeon_ring_write(ring
, PACKET3(PACKET3_MEM_SEMAPHORE
, 1));
3062 radeon_ring_write(ring
, addr
& 0xffffffff);
3063 radeon_ring_write(ring
, (upper_32_bits(addr
) & 0xff) | sel
);
3067 * DMA fences/semaphores
3071 * r600_dma_fence_ring_emit - emit a fence on the DMA ring
3073 * @rdev: radeon_device pointer
3074 * @fence: radeon fence object
3076 * Add a DMA fence packet to the ring to write
3077 * the fence seq number and DMA trap packet to generate
3078 * an interrupt if needed (r6xx-r7xx).
3080 void r600_dma_fence_ring_emit(struct radeon_device
*rdev
,
3081 struct radeon_fence
*fence
)
3083 struct radeon_ring
*ring
= &rdev
->ring
[fence
->ring
];
3084 u64 addr
= rdev
->fence_drv
[fence
->ring
].gpu_addr
;
3086 /* write the fence */
3087 radeon_ring_write(ring
, DMA_PACKET(DMA_PACKET_FENCE
, 0, 0, 0));
3088 radeon_ring_write(ring
, addr
& 0xfffffffc);
3089 radeon_ring_write(ring
, (upper_32_bits(addr
) & 0xff));
3090 radeon_ring_write(ring
, lower_32_bits(fence
->seq
));
3091 /* generate an interrupt */
3092 radeon_ring_write(ring
, DMA_PACKET(DMA_PACKET_TRAP
, 0, 0, 0));
3096 * r600_dma_semaphore_ring_emit - emit a semaphore on the dma ring
3098 * @rdev: radeon_device pointer
3099 * @ring: radeon_ring structure holding ring information
3100 * @semaphore: radeon semaphore object
3101 * @emit_wait: wait or signal semaphore
3103 * Add a DMA semaphore packet to the ring wait on or signal
3104 * other rings (r6xx-SI).
3106 void r600_dma_semaphore_ring_emit(struct radeon_device
*rdev
,
3107 struct radeon_ring
*ring
,
3108 struct radeon_semaphore
*semaphore
,
3111 u64 addr
= semaphore
->gpu_addr
;
3112 u32 s
= emit_wait
? 0 : 1;
3114 radeon_ring_write(ring
, DMA_PACKET(DMA_PACKET_SEMAPHORE
, 0, s
, 0));
3115 radeon_ring_write(ring
, addr
& 0xfffffffc);
3116 radeon_ring_write(ring
, upper_32_bits(addr
) & 0xff);
3119 void r600_uvd_semaphore_emit(struct radeon_device
*rdev
,
3120 struct radeon_ring
*ring
,
3121 struct radeon_semaphore
*semaphore
,
3124 uint64_t addr
= semaphore
->gpu_addr
;
3126 radeon_ring_write(ring
, PACKET0(UVD_SEMA_ADDR_LOW
, 0));
3127 radeon_ring_write(ring
, (addr
>> 3) & 0x000FFFFF);
3129 radeon_ring_write(ring
, PACKET0(UVD_SEMA_ADDR_HIGH
, 0));
3130 radeon_ring_write(ring
, (addr
>> 23) & 0x000FFFFF);
3132 radeon_ring_write(ring
, PACKET0(UVD_SEMA_CMD
, 0));
3133 radeon_ring_write(ring
, emit_wait
? 1 : 0);
3136 int r600_copy_blit(struct radeon_device
*rdev
,
3137 uint64_t src_offset
,
3138 uint64_t dst_offset
,
3139 unsigned num_gpu_pages
,
3140 struct radeon_fence
**fence
)
3142 struct radeon_semaphore
*sem
= NULL
;
3143 struct radeon_sa_bo
*vb
= NULL
;
3146 r
= r600_blit_prepare_copy(rdev
, num_gpu_pages
, fence
, &vb
, &sem
);
3150 r600_kms_blit_copy(rdev
, src_offset
, dst_offset
, num_gpu_pages
, vb
);
3151 r600_blit_done_copy(rdev
, fence
, vb
, sem
);
3156 * r600_copy_dma - copy pages using the DMA engine
3158 * @rdev: radeon_device pointer
3159 * @src_offset: src GPU address
3160 * @dst_offset: dst GPU address
3161 * @num_gpu_pages: number of GPU pages to xfer
3162 * @fence: radeon fence object
3164 * Copy GPU paging using the DMA engine (r6xx).
3165 * Used by the radeon ttm implementation to move pages if
3166 * registered as the asic copy callback.
3168 int r600_copy_dma(struct radeon_device
*rdev
,
3169 uint64_t src_offset
, uint64_t dst_offset
,
3170 unsigned num_gpu_pages
,
3171 struct radeon_fence
**fence
)
3173 struct radeon_semaphore
*sem
= NULL
;
3174 int ring_index
= rdev
->asic
->copy
.dma_ring_index
;
3175 struct radeon_ring
*ring
= &rdev
->ring
[ring_index
];
3176 u32 size_in_dw
, cur_size_in_dw
;
3180 r
= radeon_semaphore_create(rdev
, &sem
);
3182 DRM_ERROR("radeon: moving bo (%d).\n", r
);
3186 size_in_dw
= (num_gpu_pages
<< RADEON_GPU_PAGE_SHIFT
) / 4;
3187 num_loops
= DIV_ROUND_UP(size_in_dw
, 0xFFFE);
3188 r
= radeon_ring_lock(rdev
, ring
, num_loops
* 4 + 8);
3190 DRM_ERROR("radeon: moving bo (%d).\n", r
);
3191 radeon_semaphore_free(rdev
, &sem
, NULL
);
3195 if (radeon_fence_need_sync(*fence
, ring
->idx
)) {
3196 radeon_semaphore_sync_rings(rdev
, sem
, (*fence
)->ring
,
3198 radeon_fence_note_sync(*fence
, ring
->idx
);
3200 radeon_semaphore_free(rdev
, &sem
, NULL
);
3203 for (i
= 0; i
< num_loops
; i
++) {
3204 cur_size_in_dw
= size_in_dw
;
3205 if (cur_size_in_dw
> 0xFFFE)
3206 cur_size_in_dw
= 0xFFFE;
3207 size_in_dw
-= cur_size_in_dw
;
3208 radeon_ring_write(ring
, DMA_PACKET(DMA_PACKET_COPY
, 0, 0, cur_size_in_dw
));
3209 radeon_ring_write(ring
, dst_offset
& 0xfffffffc);
3210 radeon_ring_write(ring
, src_offset
& 0xfffffffc);
3211 radeon_ring_write(ring
, (((upper_32_bits(dst_offset
) & 0xff) << 16) |
3212 (upper_32_bits(src_offset
) & 0xff)));
3213 src_offset
+= cur_size_in_dw
* 4;
3214 dst_offset
+= cur_size_in_dw
* 4;
3217 r
= radeon_fence_emit(rdev
, fence
, ring
->idx
);
3219 radeon_ring_unlock_undo(rdev
, ring
);
3223 radeon_ring_unlock_commit(rdev
, ring
);
3224 radeon_semaphore_free(rdev
, &sem
, *fence
);
3229 int r600_set_surface_reg(struct radeon_device
*rdev
, int reg
,
3230 uint32_t tiling_flags
, uint32_t pitch
,
3231 uint32_t offset
, uint32_t obj_size
)
3233 /* FIXME: implement */
3237 void r600_clear_surface_reg(struct radeon_device
*rdev
, int reg
)
3239 /* FIXME: implement */
3242 static int r600_startup(struct radeon_device
*rdev
)
3244 struct radeon_ring
*ring
;
3247 /* enable pcie gen2 link */
3248 r600_pcie_gen2_enable(rdev
);
3250 if (!rdev
->me_fw
|| !rdev
->pfp_fw
|| !rdev
->rlc_fw
) {
3251 r
= r600_init_microcode(rdev
);
3253 DRM_ERROR("Failed to load firmware!\n");
3258 r
= r600_vram_scratch_init(rdev
);
3262 r600_mc_program(rdev
);
3263 if (rdev
->flags
& RADEON_IS_AGP
) {
3264 r600_agp_enable(rdev
);
3266 r
= r600_pcie_gart_enable(rdev
);
3270 r600_gpu_init(rdev
);
3271 r
= r600_blit_init(rdev
);
3273 r600_blit_fini(rdev
);
3274 rdev
->asic
->copy
.copy
= NULL
;
3275 dev_warn(rdev
->dev
, "failed blitter (%d) falling back to memcpy\n", r
);
3278 /* allocate wb buffer */
3279 r
= radeon_wb_init(rdev
);
3283 r
= radeon_fence_driver_start_ring(rdev
, RADEON_RING_TYPE_GFX_INDEX
);
3285 dev_err(rdev
->dev
, "failed initializing CP fences (%d).\n", r
);
3289 r
= radeon_fence_driver_start_ring(rdev
, R600_RING_TYPE_DMA_INDEX
);
3291 dev_err(rdev
->dev
, "failed initializing DMA fences (%d).\n", r
);
3296 if (!rdev
->irq
.installed
) {
3297 r
= radeon_irq_kms_init(rdev
);
3302 r
= r600_irq_init(rdev
);
3304 DRM_ERROR("radeon: IH init failed (%d).\n", r
);
3305 radeon_irq_kms_fini(rdev
);
3310 ring
= &rdev
->ring
[RADEON_RING_TYPE_GFX_INDEX
];
3311 r
= radeon_ring_init(rdev
, ring
, ring
->ring_size
, RADEON_WB_CP_RPTR_OFFSET
,
3312 R600_CP_RB_RPTR
, R600_CP_RB_WPTR
,
3313 0, 0xfffff, RADEON_CP_PACKET2
);
3317 ring
= &rdev
->ring
[R600_RING_TYPE_DMA_INDEX
];
3318 r
= radeon_ring_init(rdev
, ring
, ring
->ring_size
, R600_WB_DMA_RPTR_OFFSET
,
3319 DMA_RB_RPTR
, DMA_RB_WPTR
,
3320 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP
, 0, 0, 0));
3324 r
= r600_cp_load_microcode(rdev
);
3327 r
= r600_cp_resume(rdev
);
3331 r
= r600_dma_resume(rdev
);
3335 r
= radeon_ib_pool_init(rdev
);
3337 dev_err(rdev
->dev
, "IB initialization failed (%d).\n", r
);
3341 r
= r600_audio_init(rdev
);
3343 DRM_ERROR("radeon: audio init failed\n");
3350 void r600_vga_set_state(struct radeon_device
*rdev
, bool state
)
3354 temp
= RREG32(CONFIG_CNTL
);
3355 if (state
== false) {
3361 WREG32(CONFIG_CNTL
, temp
);
3364 int r600_resume(struct radeon_device
*rdev
)
3368 /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
3369 * posting will perform necessary task to bring back GPU into good
3373 atom_asic_init(rdev
->mode_info
.atom_context
);
3375 rdev
->accel_working
= true;
3376 r
= r600_startup(rdev
);
3378 DRM_ERROR("r600 startup failed on resume\n");
3379 rdev
->accel_working
= false;
3386 int r600_suspend(struct radeon_device
*rdev
)
3388 r600_audio_fini(rdev
);
3390 r600_dma_stop(rdev
);
3391 r600_irq_suspend(rdev
);
3392 radeon_wb_disable(rdev
);
3393 r600_pcie_gart_disable(rdev
);
3398 /* Plan is to move initialization in that function and use
3399 * helper function so that radeon_device_init pretty much
3400 * do nothing more than calling asic specific function. This
3401 * should also allow to remove a bunch of callback function
3404 int r600_init(struct radeon_device
*rdev
)
3408 if (r600_debugfs_mc_info_init(rdev
)) {
3409 DRM_ERROR("Failed to register debugfs file for mc !\n");
3412 if (!radeon_get_bios(rdev
)) {
3413 if (ASIC_IS_AVIVO(rdev
))
3416 /* Must be an ATOMBIOS */
3417 if (!rdev
->is_atom_bios
) {
3418 dev_err(rdev
->dev
, "Expecting atombios for R600 GPU\n");
3421 r
= radeon_atombios_init(rdev
);
3424 /* Post card if necessary */
3425 if (!radeon_card_posted(rdev
)) {
3427 dev_err(rdev
->dev
, "Card not posted and no BIOS - ignoring\n");
3430 DRM_INFO("GPU not posted. posting now...\n");
3431 atom_asic_init(rdev
->mode_info
.atom_context
);
3433 /* Initialize scratch registers */
3434 r600_scratch_init(rdev
);
3435 /* Initialize surface registers */
3436 radeon_surface_init(rdev
);
3437 /* Initialize clocks */
3438 radeon_get_clock_info(rdev
->ddev
);
3440 r
= radeon_fence_driver_init(rdev
);
3443 if (rdev
->flags
& RADEON_IS_AGP
) {
3444 r
= radeon_agp_init(rdev
);
3446 radeon_agp_disable(rdev
);
3448 r
= r600_mc_init(rdev
);
3451 /* Memory manager */
3452 r
= radeon_bo_init(rdev
);
3456 rdev
->ring
[RADEON_RING_TYPE_GFX_INDEX
].ring_obj
= NULL
;
3457 r600_ring_init(rdev
, &rdev
->ring
[RADEON_RING_TYPE_GFX_INDEX
], 1024 * 1024);
3459 rdev
->ring
[R600_RING_TYPE_DMA_INDEX
].ring_obj
= NULL
;
3460 r600_ring_init(rdev
, &rdev
->ring
[R600_RING_TYPE_DMA_INDEX
], 64 * 1024);
3462 rdev
->ih
.ring_obj
= NULL
;
3463 r600_ih_ring_init(rdev
, 64 * 1024);
3465 r
= r600_pcie_gart_init(rdev
);
3469 rdev
->accel_working
= true;
3470 r
= r600_startup(rdev
);
3472 dev_err(rdev
->dev
, "disabling GPU acceleration\n");
3474 r600_dma_fini(rdev
);
3475 r600_irq_fini(rdev
);
3476 radeon_wb_fini(rdev
);
3477 radeon_ib_pool_fini(rdev
);
3478 radeon_irq_kms_fini(rdev
);
3479 r600_pcie_gart_fini(rdev
);
3480 rdev
->accel_working
= false;
3486 void r600_fini(struct radeon_device
*rdev
)
3488 r600_audio_fini(rdev
);
3489 r600_blit_fini(rdev
);
3491 r600_dma_fini(rdev
);
3492 r600_irq_fini(rdev
);
3493 radeon_wb_fini(rdev
);
3494 radeon_ib_pool_fini(rdev
);
3495 radeon_irq_kms_fini(rdev
);
3496 r600_pcie_gart_fini(rdev
);
3497 r600_vram_scratch_fini(rdev
);
3498 radeon_agp_fini(rdev
);
3499 radeon_gem_fini(rdev
);
3500 radeon_fence_driver_fini(rdev
);
3501 radeon_bo_fini(rdev
);
3502 radeon_atombios_fini(rdev
);
3503 r600_fini_microcode(rdev
);
3504 drm_free(rdev
->bios
, M_DRM
);
3512 void r600_ring_ib_execute(struct radeon_device
*rdev
, struct radeon_ib
*ib
)
3514 struct radeon_ring
*ring
= &rdev
->ring
[ib
->ring
];
3517 if (ring
->rptr_save_reg
) {
3518 next_rptr
= ring
->wptr
+ 3 + 4;
3519 radeon_ring_write(ring
, PACKET3(PACKET3_SET_CONFIG_REG
, 1));
3520 radeon_ring_write(ring
, ((ring
->rptr_save_reg
-
3521 PACKET3_SET_CONFIG_REG_OFFSET
) >> 2));
3522 radeon_ring_write(ring
, next_rptr
);
3523 } else if (rdev
->wb
.enabled
) {
3524 next_rptr
= ring
->wptr
+ 5 + 4;
3525 radeon_ring_write(ring
, PACKET3(PACKET3_MEM_WRITE
, 3));
3526 radeon_ring_write(ring
, ring
->next_rptr_gpu_addr
& 0xfffffffc);
3527 radeon_ring_write(ring
, (upper_32_bits(ring
->next_rptr_gpu_addr
) & 0xff) | (1 << 18));
3528 radeon_ring_write(ring
, next_rptr
);
3529 radeon_ring_write(ring
, 0);
3532 radeon_ring_write(ring
, PACKET3(PACKET3_INDIRECT_BUFFER
, 2));
3533 radeon_ring_write(ring
,
3537 (ib
->gpu_addr
& 0xFFFFFFFC));
3538 radeon_ring_write(ring
, upper_32_bits(ib
->gpu_addr
) & 0xFF);
3539 radeon_ring_write(ring
, ib
->length_dw
);
3542 void r600_uvd_ib_execute(struct radeon_device
*rdev
, struct radeon_ib
*ib
)
3544 struct radeon_ring
*ring
= &rdev
->ring
[ib
->ring
];
3546 radeon_ring_write(ring
, PACKET0(UVD_RBC_IB_BASE
, 0));
3547 radeon_ring_write(ring
, ib
->gpu_addr
);
3548 radeon_ring_write(ring
, PACKET0(UVD_RBC_IB_SIZE
, 0));
3549 radeon_ring_write(ring
, ib
->length_dw
);
3552 int r600_ib_test(struct radeon_device
*rdev
, struct radeon_ring
*ring
)
3554 struct radeon_ib ib
;
3560 r
= radeon_scratch_get(rdev
, &scratch
);
3562 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r
);
3565 WREG32(scratch
, 0xCAFEDEAD);
3566 r
= radeon_ib_get(rdev
, ring
->idx
, &ib
, NULL
, 256);
3568 DRM_ERROR("radeon: failed to get ib (%d).\n", r
);
3571 ib
.ptr
[0] = PACKET3(PACKET3_SET_CONFIG_REG
, 1);
3572 ib
.ptr
[1] = ((scratch
- PACKET3_SET_CONFIG_REG_OFFSET
) >> 2);
3573 ib
.ptr
[2] = 0xDEADBEEF;
3575 r
= radeon_ib_schedule(rdev
, &ib
, NULL
);
3577 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r
);
3580 r
= radeon_fence_wait(ib
.fence
, false);
3582 DRM_ERROR("radeon: fence wait failed (%d).\n", r
);
3585 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
3586 tmp
= RREG32(scratch
);
3587 if (tmp
== 0xDEADBEEF)
3591 if (i
< rdev
->usec_timeout
) {
3592 DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib
.fence
->ring
, i
);
3594 DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
3599 radeon_ib_free(rdev
, &ib
);
3601 radeon_scratch_free(rdev
, scratch
);
3606 * r600_dma_ib_test - test an IB on the DMA engine
3608 * @rdev: radeon_device pointer
3609 * @ring: radeon_ring structure holding ring information
3611 * Test a simple IB in the DMA ring (r6xx-SI).
3612 * Returns 0 on success, error on failure.
3614 int r600_dma_ib_test(struct radeon_device
*rdev
, struct radeon_ring
*ring
)
3616 struct radeon_ib ib
;
3619 volatile uint32_t *ptr
= rdev
->vram_scratch
.ptr
;
3623 DRM_ERROR("invalid vram scratch pointer\n");
3630 r
= radeon_ib_get(rdev
, ring
->idx
, &ib
, NULL
, 256);
3632 DRM_ERROR("radeon: failed to get ib (%d).\n", r
);
3636 ib
.ptr
[0] = DMA_PACKET(DMA_PACKET_WRITE
, 0, 0, 1);
3637 ib
.ptr
[1] = rdev
->vram_scratch
.gpu_addr
& 0xfffffffc;
3638 ib
.ptr
[2] = upper_32_bits(rdev
->vram_scratch
.gpu_addr
) & 0xff;
3639 ib
.ptr
[3] = 0xDEADBEEF;
3642 r
= radeon_ib_schedule(rdev
, &ib
, NULL
);
3644 radeon_ib_free(rdev
, &ib
);
3645 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r
);
3648 r
= radeon_fence_wait(ib
.fence
, false);
3650 radeon_ib_free(rdev
, &ib
);
3651 DRM_ERROR("radeon: fence wait failed (%d).\n", r
);
3654 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
3656 if (tmp
== 0xDEADBEEF)
3660 if (i
< rdev
->usec_timeout
) {
3661 DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib
.fence
->ring
, i
);
3663 DRM_ERROR("radeon: ib test failed (0x%08X)\n", tmp
);
3666 radeon_ib_free(rdev
, &ib
);
3670 int r600_uvd_ib_test(struct radeon_device
*rdev
, struct radeon_ring
*ring
)
3672 struct radeon_fence
*fence
= NULL
;
3675 r
= radeon_set_uvd_clocks(rdev
, 53300, 40000);
3677 DRM_ERROR("radeon: failed to raise UVD clocks (%d).\n", r
);
3681 r
= radeon_uvd_get_create_msg(rdev
, ring
->idx
, 1, NULL
);
3683 DRM_ERROR("radeon: failed to get create msg (%d).\n", r
);
3687 r
= radeon_uvd_get_destroy_msg(rdev
, ring
->idx
, 1, &fence
);
3689 DRM_ERROR("radeon: failed to get destroy ib (%d).\n", r
);
3693 r
= radeon_fence_wait(fence
, false);
3695 DRM_ERROR("radeon: fence wait failed (%d).\n", r
);
3698 DRM_INFO("ib test on ring %d succeeded\n", ring
->idx
);
3700 radeon_fence_unref(&fence
);
3701 radeon_set_uvd_clocks(rdev
, 0, 0);
3706 * r600_dma_ring_ib_execute - Schedule an IB on the DMA engine
3708 * @rdev: radeon_device pointer
3709 * @ib: IB object to schedule
3711 * Schedule an IB in the DMA ring (r6xx-r7xx).
3713 void r600_dma_ring_ib_execute(struct radeon_device
*rdev
, struct radeon_ib
*ib
)
3715 struct radeon_ring
*ring
= &rdev
->ring
[ib
->ring
];
3717 if (rdev
->wb
.enabled
) {
3718 u32 next_rptr
= ring
->wptr
+ 4;
3719 while ((next_rptr
& 7) != 5)
3722 radeon_ring_write(ring
, DMA_PACKET(DMA_PACKET_WRITE
, 0, 0, 1));
3723 radeon_ring_write(ring
, ring
->next_rptr_gpu_addr
& 0xfffffffc);
3724 radeon_ring_write(ring
, upper_32_bits(ring
->next_rptr_gpu_addr
) & 0xff);
3725 radeon_ring_write(ring
, next_rptr
);
3728 /* The indirect buffer packet must end on an 8 DW boundary in the DMA ring.
3729 * Pad as necessary with NOPs.
3731 while ((ring
->wptr
& 7) != 5)
3732 radeon_ring_write(ring
, DMA_PACKET(DMA_PACKET_NOP
, 0, 0, 0));
3733 radeon_ring_write(ring
, DMA_PACKET(DMA_PACKET_INDIRECT_BUFFER
, 0, 0, 0));
3734 radeon_ring_write(ring
, (ib
->gpu_addr
& 0xFFFFFFE0));
3735 radeon_ring_write(ring
, (ib
->length_dw
<< 16) | (upper_32_bits(ib
->gpu_addr
) & 0xFF));
3742 * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
3743 * the same as the CP ring buffer, but in reverse. Rather than the CPU
3744 * writing to the ring and the GPU consuming, the GPU writes to the ring
3745 * and host consumes. As the host irq handler processes interrupts, it
3746 * increments the rptr. When the rptr catches up with the wptr, all the
3747 * current interrupts have been processed.
3750 void r600_ih_ring_init(struct radeon_device
*rdev
, unsigned ring_size
)
3754 /* Align ring size */
3755 rb_bufsz
= drm_order(ring_size
/ 4);
3756 ring_size
= (1 << rb_bufsz
) * 4;
3757 rdev
->ih
.ring_size
= ring_size
;
3758 rdev
->ih
.ptr_mask
= rdev
->ih
.ring_size
- 1;
3762 int r600_ih_ring_alloc(struct radeon_device
*rdev
)
3767 /* Allocate ring buffer */
3768 if (rdev
->ih
.ring_obj
== NULL
) {
3769 r
= radeon_bo_create(rdev
, rdev
->ih
.ring_size
,
3771 RADEON_GEM_DOMAIN_GTT
,
3772 NULL
, &rdev
->ih
.ring_obj
);
3774 DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r
);
3777 r
= radeon_bo_reserve(rdev
->ih
.ring_obj
, false);
3778 if (unlikely(r
!= 0)) {
3779 radeon_bo_unref(&rdev
->ih
.ring_obj
);
3782 r
= radeon_bo_pin(rdev
->ih
.ring_obj
,
3783 RADEON_GEM_DOMAIN_GTT
,
3784 &rdev
->ih
.gpu_addr
);
3786 radeon_bo_unreserve(rdev
->ih
.ring_obj
);
3787 radeon_bo_unref(&rdev
->ih
.ring_obj
);
3788 DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r
);
3791 ring_ptr
= &rdev
->ih
.ring
;
3792 r
= radeon_bo_kmap(rdev
->ih
.ring_obj
,
3795 radeon_bo_unpin(rdev
->ih
.ring_obj
);
3796 radeon_bo_unreserve(rdev
->ih
.ring_obj
);
3798 DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r
);
3799 radeon_bo_unref(&rdev
->ih
.ring_obj
);
3806 void r600_ih_ring_fini(struct radeon_device
*rdev
)
3809 if (rdev
->ih
.ring_obj
) {
3810 r
= radeon_bo_reserve(rdev
->ih
.ring_obj
, false);
3811 if (likely(r
== 0)) {
3812 radeon_bo_kunmap(rdev
->ih
.ring_obj
);
3813 radeon_bo_unpin(rdev
->ih
.ring_obj
);
3814 radeon_bo_unreserve(rdev
->ih
.ring_obj
);
3816 radeon_bo_unref(&rdev
->ih
.ring_obj
);
3817 rdev
->ih
.ring
= NULL
;
3818 rdev
->ih
.ring_obj
= NULL
;
3822 void r600_rlc_stop(struct radeon_device
*rdev
)
3825 if ((rdev
->family
>= CHIP_RV770
) &&
3826 (rdev
->family
<= CHIP_RV740
)) {
3827 /* r7xx asics need to soft reset RLC before halting */
3828 WREG32(SRBM_SOFT_RESET
, SOFT_RESET_RLC
);
3829 RREG32(SRBM_SOFT_RESET
);
3831 WREG32(SRBM_SOFT_RESET
, 0);
3832 RREG32(SRBM_SOFT_RESET
);
3835 WREG32(RLC_CNTL
, 0);
3838 static void r600_rlc_start(struct radeon_device
*rdev
)
3840 WREG32(RLC_CNTL
, RLC_ENABLE
);
3843 static int r600_rlc_init(struct radeon_device
*rdev
)
3846 const __be32
*fw_data
;
3851 r600_rlc_stop(rdev
);
3853 WREG32(RLC_HB_CNTL
, 0);
3855 if (rdev
->family
== CHIP_ARUBA
) {
3856 WREG32(TN_RLC_SAVE_AND_RESTORE_BASE
, rdev
->rlc
.save_restore_gpu_addr
>> 8);
3857 WREG32(TN_RLC_CLEAR_STATE_RESTORE_BASE
, rdev
->rlc
.clear_state_gpu_addr
>> 8);
3859 if (rdev
->family
<= CHIP_CAYMAN
) {
3860 WREG32(RLC_HB_BASE
, 0);
3861 WREG32(RLC_HB_RPTR
, 0);
3862 WREG32(RLC_HB_WPTR
, 0);
3864 if (rdev
->family
<= CHIP_CAICOS
) {
3865 WREG32(RLC_HB_WPTR_LSB_ADDR
, 0);
3866 WREG32(RLC_HB_WPTR_MSB_ADDR
, 0);
3868 WREG32(RLC_MC_CNTL
, 0);
3869 WREG32(RLC_UCODE_CNTL
, 0);
3871 fw_data
= (const __be32
*)rdev
->rlc_fw
->data
;
3872 if (rdev
->family
>= CHIP_ARUBA
) {
3873 for (i
= 0; i
< ARUBA_RLC_UCODE_SIZE
; i
++) {
3874 WREG32(RLC_UCODE_ADDR
, i
);
3875 WREG32(RLC_UCODE_DATA
, be32_to_cpup(fw_data
++));
3877 } else if (rdev
->family
>= CHIP_CAYMAN
) {
3878 for (i
= 0; i
< CAYMAN_RLC_UCODE_SIZE
; i
++) {
3879 WREG32(RLC_UCODE_ADDR
, i
);
3880 WREG32(RLC_UCODE_DATA
, be32_to_cpup(fw_data
++));
3882 } else if (rdev
->family
>= CHIP_CEDAR
) {
3883 for (i
= 0; i
< EVERGREEN_RLC_UCODE_SIZE
; i
++) {
3884 WREG32(RLC_UCODE_ADDR
, i
);
3885 WREG32(RLC_UCODE_DATA
, be32_to_cpup(fw_data
++));
3887 } else if (rdev
->family
>= CHIP_RV770
) {
3888 for (i
= 0; i
< R700_RLC_UCODE_SIZE
; i
++) {
3889 WREG32(RLC_UCODE_ADDR
, i
);
3890 WREG32(RLC_UCODE_DATA
, be32_to_cpup(fw_data
++));
3893 for (i
= 0; i
< RLC_UCODE_SIZE
; i
++) {
3894 WREG32(RLC_UCODE_ADDR
, i
);
3895 WREG32(RLC_UCODE_DATA
, be32_to_cpup(fw_data
++));
3898 WREG32(RLC_UCODE_ADDR
, 0);
3900 r600_rlc_start(rdev
);
3905 static void r600_enable_interrupts(struct radeon_device
*rdev
)
3907 u32 ih_cntl
= RREG32(IH_CNTL
);
3908 u32 ih_rb_cntl
= RREG32(IH_RB_CNTL
);
3910 ih_cntl
|= ENABLE_INTR
;
3911 ih_rb_cntl
|= IH_RB_ENABLE
;
3912 WREG32(IH_CNTL
, ih_cntl
);
3913 WREG32(IH_RB_CNTL
, ih_rb_cntl
);
3914 rdev
->ih
.enabled
= true;
3917 void r600_disable_interrupts(struct radeon_device
*rdev
)
3919 u32 ih_rb_cntl
= RREG32(IH_RB_CNTL
);
3920 u32 ih_cntl
= RREG32(IH_CNTL
);
3922 ih_rb_cntl
&= ~IH_RB_ENABLE
;
3923 ih_cntl
&= ~ENABLE_INTR
;
3924 WREG32(IH_RB_CNTL
, ih_rb_cntl
);
3925 WREG32(IH_CNTL
, ih_cntl
);
3926 /* set rptr, wptr to 0 */
3927 WREG32(IH_RB_RPTR
, 0);
3928 WREG32(IH_RB_WPTR
, 0);
3929 rdev
->ih
.enabled
= false;
3933 static void r600_disable_interrupt_state(struct radeon_device
*rdev
)
3937 WREG32(CP_INT_CNTL
, CNTX_BUSY_INT_ENABLE
| CNTX_EMPTY_INT_ENABLE
);
3938 tmp
= RREG32(DMA_CNTL
) & ~TRAP_ENABLE
;
3939 WREG32(DMA_CNTL
, tmp
);
3940 WREG32(GRBM_INT_CNTL
, 0);
3941 WREG32(DxMODE_INT_MASK
, 0);
3942 WREG32(D1GRPH_INTERRUPT_CONTROL
, 0);
3943 WREG32(D2GRPH_INTERRUPT_CONTROL
, 0);
3944 if (ASIC_IS_DCE3(rdev
)) {
3945 WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL
, 0);
3946 WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL
, 0);
3947 tmp
= RREG32(DC_HPD1_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
3948 WREG32(DC_HPD1_INT_CONTROL
, tmp
);
3949 tmp
= RREG32(DC_HPD2_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
3950 WREG32(DC_HPD2_INT_CONTROL
, tmp
);
3951 tmp
= RREG32(DC_HPD3_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
3952 WREG32(DC_HPD3_INT_CONTROL
, tmp
);
3953 tmp
= RREG32(DC_HPD4_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
3954 WREG32(DC_HPD4_INT_CONTROL
, tmp
);
3955 if (ASIC_IS_DCE32(rdev
)) {
3956 tmp
= RREG32(DC_HPD5_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
3957 WREG32(DC_HPD5_INT_CONTROL
, tmp
);
3958 tmp
= RREG32(DC_HPD6_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
3959 WREG32(DC_HPD6_INT_CONTROL
, tmp
);
3960 tmp
= RREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET0
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
3961 WREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET0
, tmp
);
3962 tmp
= RREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET1
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
3963 WREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET1
, tmp
);
3965 tmp
= RREG32(HDMI0_AUDIO_PACKET_CONTROL
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
3966 WREG32(HDMI0_AUDIO_PACKET_CONTROL
, tmp
);
3967 tmp
= RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
3968 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL
, tmp
);
3971 WREG32(DACA_AUTODETECT_INT_CONTROL
, 0);
3972 WREG32(DACB_AUTODETECT_INT_CONTROL
, 0);
3973 tmp
= RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
) & DC_HOT_PLUG_DETECTx_INT_POLARITY
;
3974 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
, tmp
);
3975 tmp
= RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
) & DC_HOT_PLUG_DETECTx_INT_POLARITY
;
3976 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
, tmp
);
3977 tmp
= RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
) & DC_HOT_PLUG_DETECTx_INT_POLARITY
;
3978 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
, tmp
);
3979 tmp
= RREG32(HDMI0_AUDIO_PACKET_CONTROL
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
3980 WREG32(HDMI0_AUDIO_PACKET_CONTROL
, tmp
);
3981 tmp
= RREG32(HDMI1_AUDIO_PACKET_CONTROL
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
3982 WREG32(HDMI1_AUDIO_PACKET_CONTROL
, tmp
);
3986 int r600_irq_init(struct radeon_device
*rdev
)
3990 u32 interrupt_cntl
, ih_cntl
, ih_rb_cntl
;
3993 ret
= r600_ih_ring_alloc(rdev
);
3998 r600_disable_interrupts(rdev
);
4001 ret
= r600_rlc_init(rdev
);
4003 r600_ih_ring_fini(rdev
);
4007 /* setup interrupt control */
4008 /* set dummy read address to ring address */
4009 WREG32(INTERRUPT_CNTL2
, rdev
->ih
.gpu_addr
>> 8);
4010 interrupt_cntl
= RREG32(INTERRUPT_CNTL
);
4011 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
4012 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
4014 interrupt_cntl
&= ~IH_DUMMY_RD_OVERRIDE
;
4015 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
4016 interrupt_cntl
&= ~IH_REQ_NONSNOOP_EN
;
4017 WREG32(INTERRUPT_CNTL
, interrupt_cntl
);
4019 WREG32(IH_RB_BASE
, rdev
->ih
.gpu_addr
>> 8);
4020 rb_bufsz
= drm_order(rdev
->ih
.ring_size
/ 4);
4022 ih_rb_cntl
= (IH_WPTR_OVERFLOW_ENABLE
|
4023 IH_WPTR_OVERFLOW_CLEAR
|
4026 if (rdev
->wb
.enabled
)
4027 ih_rb_cntl
|= IH_WPTR_WRITEBACK_ENABLE
;
4029 /* set the writeback address whether it's enabled or not */
4030 WREG32(IH_RB_WPTR_ADDR_LO
, (rdev
->wb
.gpu_addr
+ R600_WB_IH_WPTR_OFFSET
) & 0xFFFFFFFC);
4031 WREG32(IH_RB_WPTR_ADDR_HI
, upper_32_bits(rdev
->wb
.gpu_addr
+ R600_WB_IH_WPTR_OFFSET
) & 0xFF);
4033 WREG32(IH_RB_CNTL
, ih_rb_cntl
);
4035 /* set rptr, wptr to 0 */
4036 WREG32(IH_RB_RPTR
, 0);
4037 WREG32(IH_RB_WPTR
, 0);
4039 /* Default settings for IH_CNTL (disabled at first) */
4040 ih_cntl
= MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
4041 /* RPTR_REARM only works if msi's are enabled */
4042 if (rdev
->msi_enabled
)
4043 ih_cntl
|= RPTR_REARM
;
4044 WREG32(IH_CNTL
, ih_cntl
);
4046 /* force the active interrupt state to all disabled */
4047 if (rdev
->family
>= CHIP_CEDAR
)
4048 evergreen_disable_interrupt_state(rdev
);
4050 r600_disable_interrupt_state(rdev
);
4052 /* at this point everything should be setup correctly to enable master */
4053 pci_enable_busmaster(rdev
->dev
);
4056 r600_enable_interrupts(rdev
);
4061 void r600_irq_suspend(struct radeon_device
*rdev
)
4063 r600_irq_disable(rdev
);
4064 r600_rlc_stop(rdev
);
4067 void r600_irq_fini(struct radeon_device
*rdev
)
4069 r600_irq_suspend(rdev
);
4070 r600_ih_ring_fini(rdev
);
4073 int r600_irq_set(struct radeon_device
*rdev
)
4075 u32 cp_int_cntl
= CNTX_BUSY_INT_ENABLE
| CNTX_EMPTY_INT_ENABLE
;
4077 u32 hpd1
, hpd2
, hpd3
, hpd4
= 0, hpd5
= 0, hpd6
= 0;
4078 u32 grbm_int_cntl
= 0;
4080 u32 d1grph
= 0, d2grph
= 0;
4083 if (!rdev
->irq
.installed
) {
4084 DRM_ERROR("Can't enable IRQ/MSI because no handler is installed\n");
4087 /* don't enable anything if the ih is disabled */
4088 if (!rdev
->ih
.enabled
) {
4089 r600_disable_interrupts(rdev
);
4090 /* force the active interrupt state to all disabled */
4091 r600_disable_interrupt_state(rdev
);
4095 if (ASIC_IS_DCE3(rdev
)) {
4096 hpd1
= RREG32(DC_HPD1_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
4097 hpd2
= RREG32(DC_HPD2_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
4098 hpd3
= RREG32(DC_HPD3_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
4099 hpd4
= RREG32(DC_HPD4_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
4100 if (ASIC_IS_DCE32(rdev
)) {
4101 hpd5
= RREG32(DC_HPD5_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
4102 hpd6
= RREG32(DC_HPD6_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
4103 hdmi0
= RREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET0
) & ~AFMT_AZ_FORMAT_WTRIG_MASK
;
4104 hdmi1
= RREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET1
) & ~AFMT_AZ_FORMAT_WTRIG_MASK
;
4106 hdmi0
= RREG32(HDMI0_AUDIO_PACKET_CONTROL
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
4107 hdmi1
= RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
4110 hpd1
= RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
4111 hpd2
= RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
4112 hpd3
= RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
4113 hdmi0
= RREG32(HDMI0_AUDIO_PACKET_CONTROL
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
4114 hdmi1
= RREG32(HDMI1_AUDIO_PACKET_CONTROL
) & ~HDMI0_AZ_FORMAT_WTRIG_MASK
;
4116 dma_cntl
= RREG32(DMA_CNTL
) & ~TRAP_ENABLE
;
4118 if (atomic_read(&rdev
->irq
.ring_int
[RADEON_RING_TYPE_GFX_INDEX
])) {
4119 DRM_DEBUG("r600_irq_set: sw int\n");
4120 cp_int_cntl
|= RB_INT_ENABLE
;
4121 cp_int_cntl
|= TIME_STAMP_INT_ENABLE
;
4124 if (atomic_read(&rdev
->irq
.ring_int
[R600_RING_TYPE_DMA_INDEX
])) {
4125 DRM_DEBUG("r600_irq_set: sw int dma\n");
4126 dma_cntl
|= TRAP_ENABLE
;
4129 if (rdev
->irq
.crtc_vblank_int
[0] ||
4130 atomic_read(&rdev
->irq
.pflip
[0])) {
4131 DRM_DEBUG("r600_irq_set: vblank 0\n");
4132 mode_int
|= D1MODE_VBLANK_INT_MASK
;
4134 if (rdev
->irq
.crtc_vblank_int
[1] ||
4135 atomic_read(&rdev
->irq
.pflip
[1])) {
4136 DRM_DEBUG("r600_irq_set: vblank 1\n");
4137 mode_int
|= D2MODE_VBLANK_INT_MASK
;
4139 if (rdev
->irq
.hpd
[0]) {
4140 DRM_DEBUG("r600_irq_set: hpd 1\n");
4141 hpd1
|= DC_HPDx_INT_EN
;
4143 if (rdev
->irq
.hpd
[1]) {
4144 DRM_DEBUG("r600_irq_set: hpd 2\n");
4145 hpd2
|= DC_HPDx_INT_EN
;
4147 if (rdev
->irq
.hpd
[2]) {
4148 DRM_DEBUG("r600_irq_set: hpd 3\n");
4149 hpd3
|= DC_HPDx_INT_EN
;
4151 if (rdev
->irq
.hpd
[3]) {
4152 DRM_DEBUG("r600_irq_set: hpd 4\n");
4153 hpd4
|= DC_HPDx_INT_EN
;
4155 if (rdev
->irq
.hpd
[4]) {
4156 DRM_DEBUG("r600_irq_set: hpd 5\n");
4157 hpd5
|= DC_HPDx_INT_EN
;
4159 if (rdev
->irq
.hpd
[5]) {
4160 DRM_DEBUG("r600_irq_set: hpd 6\n");
4161 hpd6
|= DC_HPDx_INT_EN
;
4163 if (rdev
->irq
.afmt
[0]) {
4164 DRM_DEBUG("r600_irq_set: hdmi 0\n");
4165 hdmi0
|= HDMI0_AZ_FORMAT_WTRIG_MASK
;
4167 if (rdev
->irq
.afmt
[1]) {
4168 DRM_DEBUG("r600_irq_set: hdmi 0\n");
4169 hdmi1
|= HDMI0_AZ_FORMAT_WTRIG_MASK
;
4172 WREG32(CP_INT_CNTL
, cp_int_cntl
);
4173 WREG32(DMA_CNTL
, dma_cntl
);
4174 WREG32(DxMODE_INT_MASK
, mode_int
);
4175 WREG32(D1GRPH_INTERRUPT_CONTROL
, d1grph
);
4176 WREG32(D2GRPH_INTERRUPT_CONTROL
, d2grph
);
4177 WREG32(GRBM_INT_CNTL
, grbm_int_cntl
);
4178 if (ASIC_IS_DCE3(rdev
)) {
4179 WREG32(DC_HPD1_INT_CONTROL
, hpd1
);
4180 WREG32(DC_HPD2_INT_CONTROL
, hpd2
);
4181 WREG32(DC_HPD3_INT_CONTROL
, hpd3
);
4182 WREG32(DC_HPD4_INT_CONTROL
, hpd4
);
4183 if (ASIC_IS_DCE32(rdev
)) {
4184 WREG32(DC_HPD5_INT_CONTROL
, hpd5
);
4185 WREG32(DC_HPD6_INT_CONTROL
, hpd6
);
4186 WREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET0
, hdmi0
);
4187 WREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET1
, hdmi1
);
4189 WREG32(HDMI0_AUDIO_PACKET_CONTROL
, hdmi0
);
4190 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL
, hdmi1
);
4193 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
, hpd1
);
4194 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
, hpd2
);
4195 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
, hpd3
);
4196 WREG32(HDMI0_AUDIO_PACKET_CONTROL
, hdmi0
);
4197 WREG32(HDMI1_AUDIO_PACKET_CONTROL
, hdmi1
);
4203 static void r600_irq_ack(struct radeon_device
*rdev
)
4207 if (ASIC_IS_DCE3(rdev
)) {
4208 rdev
->irq
.stat_regs
.r600
.disp_int
= RREG32(DCE3_DISP_INTERRUPT_STATUS
);
4209 rdev
->irq
.stat_regs
.r600
.disp_int_cont
= RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE
);
4210 rdev
->irq
.stat_regs
.r600
.disp_int_cont2
= RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2
);
4211 if (ASIC_IS_DCE32(rdev
)) {
4212 rdev
->irq
.stat_regs
.r600
.hdmi0_status
= RREG32(AFMT_STATUS
+ DCE3_HDMI_OFFSET0
);
4213 rdev
->irq
.stat_regs
.r600
.hdmi1_status
= RREG32(AFMT_STATUS
+ DCE3_HDMI_OFFSET1
);
4215 rdev
->irq
.stat_regs
.r600
.hdmi0_status
= RREG32(HDMI0_STATUS
);
4216 rdev
->irq
.stat_regs
.r600
.hdmi1_status
= RREG32(DCE3_HDMI1_STATUS
);
4219 rdev
->irq
.stat_regs
.r600
.disp_int
= RREG32(DISP_INTERRUPT_STATUS
);
4220 rdev
->irq
.stat_regs
.r600
.disp_int_cont
= RREG32(DISP_INTERRUPT_STATUS_CONTINUE
);
4221 rdev
->irq
.stat_regs
.r600
.disp_int_cont2
= 0;
4222 rdev
->irq
.stat_regs
.r600
.hdmi0_status
= RREG32(HDMI0_STATUS
);
4223 rdev
->irq
.stat_regs
.r600
.hdmi1_status
= RREG32(HDMI1_STATUS
);
4225 rdev
->irq
.stat_regs
.r600
.d1grph_int
= RREG32(D1GRPH_INTERRUPT_STATUS
);
4226 rdev
->irq
.stat_regs
.r600
.d2grph_int
= RREG32(D2GRPH_INTERRUPT_STATUS
);
4228 if (rdev
->irq
.stat_regs
.r600
.d1grph_int
& DxGRPH_PFLIP_INT_OCCURRED
)
4229 WREG32(D1GRPH_INTERRUPT_STATUS
, DxGRPH_PFLIP_INT_CLEAR
);
4230 if (rdev
->irq
.stat_regs
.r600
.d2grph_int
& DxGRPH_PFLIP_INT_OCCURRED
)
4231 WREG32(D2GRPH_INTERRUPT_STATUS
, DxGRPH_PFLIP_INT_CLEAR
);
4232 if (rdev
->irq
.stat_regs
.r600
.disp_int
& LB_D1_VBLANK_INTERRUPT
)
4233 WREG32(D1MODE_VBLANK_STATUS
, DxMODE_VBLANK_ACK
);
4234 if (rdev
->irq
.stat_regs
.r600
.disp_int
& LB_D1_VLINE_INTERRUPT
)
4235 WREG32(D1MODE_VLINE_STATUS
, DxMODE_VLINE_ACK
);
4236 if (rdev
->irq
.stat_regs
.r600
.disp_int
& LB_D2_VBLANK_INTERRUPT
)
4237 WREG32(D2MODE_VBLANK_STATUS
, DxMODE_VBLANK_ACK
);
4238 if (rdev
->irq
.stat_regs
.r600
.disp_int
& LB_D2_VLINE_INTERRUPT
)
4239 WREG32(D2MODE_VLINE_STATUS
, DxMODE_VLINE_ACK
);
4240 if (rdev
->irq
.stat_regs
.r600
.disp_int
& DC_HPD1_INTERRUPT
) {
4241 if (ASIC_IS_DCE3(rdev
)) {
4242 tmp
= RREG32(DC_HPD1_INT_CONTROL
);
4243 tmp
|= DC_HPDx_INT_ACK
;
4244 WREG32(DC_HPD1_INT_CONTROL
, tmp
);
4246 tmp
= RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
);
4247 tmp
|= DC_HPDx_INT_ACK
;
4248 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
, tmp
);
4251 if (rdev
->irq
.stat_regs
.r600
.disp_int
& DC_HPD2_INTERRUPT
) {
4252 if (ASIC_IS_DCE3(rdev
)) {
4253 tmp
= RREG32(DC_HPD2_INT_CONTROL
);
4254 tmp
|= DC_HPDx_INT_ACK
;
4255 WREG32(DC_HPD2_INT_CONTROL
, tmp
);
4257 tmp
= RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
);
4258 tmp
|= DC_HPDx_INT_ACK
;
4259 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
, tmp
);
4262 if (rdev
->irq
.stat_regs
.r600
.disp_int_cont
& DC_HPD3_INTERRUPT
) {
4263 if (ASIC_IS_DCE3(rdev
)) {
4264 tmp
= RREG32(DC_HPD3_INT_CONTROL
);
4265 tmp
|= DC_HPDx_INT_ACK
;
4266 WREG32(DC_HPD3_INT_CONTROL
, tmp
);
4268 tmp
= RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
);
4269 tmp
|= DC_HPDx_INT_ACK
;
4270 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
, tmp
);
4273 if (rdev
->irq
.stat_regs
.r600
.disp_int_cont
& DC_HPD4_INTERRUPT
) {
4274 tmp
= RREG32(DC_HPD4_INT_CONTROL
);
4275 tmp
|= DC_HPDx_INT_ACK
;
4276 WREG32(DC_HPD4_INT_CONTROL
, tmp
);
4278 if (ASIC_IS_DCE32(rdev
)) {
4279 if (rdev
->irq
.stat_regs
.r600
.disp_int_cont2
& DC_HPD5_INTERRUPT
) {
4280 tmp
= RREG32(DC_HPD5_INT_CONTROL
);
4281 tmp
|= DC_HPDx_INT_ACK
;
4282 WREG32(DC_HPD5_INT_CONTROL
, tmp
);
4284 if (rdev
->irq
.stat_regs
.r600
.disp_int_cont2
& DC_HPD6_INTERRUPT
) {
4285 tmp
= RREG32(DC_HPD5_INT_CONTROL
);
4286 tmp
|= DC_HPDx_INT_ACK
;
4287 WREG32(DC_HPD6_INT_CONTROL
, tmp
);
4289 if (rdev
->irq
.stat_regs
.r600
.hdmi0_status
& AFMT_AZ_FORMAT_WTRIG
) {
4290 tmp
= RREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET0
);
4291 tmp
|= AFMT_AZ_FORMAT_WTRIG_ACK
;
4292 WREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET0
, tmp
);
4294 if (rdev
->irq
.stat_regs
.r600
.hdmi1_status
& AFMT_AZ_FORMAT_WTRIG
) {
4295 tmp
= RREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET1
);
4296 tmp
|= AFMT_AZ_FORMAT_WTRIG_ACK
;
4297 WREG32(AFMT_AUDIO_PACKET_CONTROL
+ DCE3_HDMI_OFFSET1
, tmp
);
4300 if (rdev
->irq
.stat_regs
.r600
.hdmi0_status
& HDMI0_AZ_FORMAT_WTRIG
) {
4301 tmp
= RREG32(HDMI0_AUDIO_PACKET_CONTROL
);
4302 tmp
|= HDMI0_AZ_FORMAT_WTRIG_ACK
;
4303 WREG32(HDMI0_AUDIO_PACKET_CONTROL
, tmp
);
4305 if (rdev
->irq
.stat_regs
.r600
.hdmi1_status
& HDMI0_AZ_FORMAT_WTRIG
) {
4306 if (ASIC_IS_DCE3(rdev
)) {
4307 tmp
= RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL
);
4308 tmp
|= HDMI0_AZ_FORMAT_WTRIG_ACK
;
4309 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL
, tmp
);
4311 tmp
= RREG32(HDMI1_AUDIO_PACKET_CONTROL
);
4312 tmp
|= HDMI0_AZ_FORMAT_WTRIG_ACK
;
4313 WREG32(HDMI1_AUDIO_PACKET_CONTROL
, tmp
);
4319 void r600_irq_disable(struct radeon_device
*rdev
)
4321 r600_disable_interrupts(rdev
);
4322 /* Wait and acknowledge irq */
4325 r600_disable_interrupt_state(rdev
);
4328 static u32
r600_get_ih_wptr(struct radeon_device
*rdev
)
4332 if (rdev
->wb
.enabled
)
4333 wptr
= le32_to_cpu(rdev
->wb
.wb
[R600_WB_IH_WPTR_OFFSET
/4]);
4335 wptr
= RREG32(IH_RB_WPTR
);
4337 if (wptr
& RB_OVERFLOW
) {
4338 /* When a ring buffer overflow happen start parsing interrupt
4339 * from the last not overwritten vector (wptr + 16). Hopefully
4340 * this should allow us to catchup.
4342 dev_warn(rdev
->dev
, "IH ring buffer overflow (0x%08X, %d, %d)\n",
4343 wptr
, rdev
->ih
.rptr
, (wptr
+ 16) + rdev
->ih
.ptr_mask
);
4344 rdev
->ih
.rptr
= (wptr
+ 16) & rdev
->ih
.ptr_mask
;
4345 tmp
= RREG32(IH_RB_CNTL
);
4346 tmp
|= IH_WPTR_OVERFLOW_CLEAR
;
4347 WREG32(IH_RB_CNTL
, tmp
);
4349 return (wptr
& rdev
->ih
.ptr_mask
);
4353 * Each IV ring entry is 128 bits:
4354 * [7:0] - interrupt source id
4356 * [59:32] - interrupt source data
4357 * [127:60] - reserved
4359 * The basic interrupt vector entries
4360 * are decoded as follows:
4361 * src_id src_data description
4366 * 19 0 FP Hot plug detection A
4367 * 19 1 FP Hot plug detection B
4368 * 19 2 DAC A auto-detection
4369 * 19 3 DAC B auto-detection
4375 * 181 - EOP Interrupt
4378 * Note, these are based on r600 and may need to be
4379 * adjusted or added to on newer asics
4382 irqreturn_t
r600_irq_process(struct radeon_device
*rdev
)
4386 u32 src_id
, src_data
;
4388 bool queue_hotplug
= false;
4389 bool queue_hdmi
= false;
4391 if (!rdev
->ih
.enabled
|| rdev
->shutdown
)
4394 /* No MSIs, need a dummy read to flush PCI DMAs */
4395 if (!rdev
->msi_enabled
)
4398 wptr
= r600_get_ih_wptr(rdev
);
4401 /* is somebody else already processing irqs? */
4402 if (atomic_xchg(&rdev
->ih
.lock
, 1))
4405 rptr
= rdev
->ih
.rptr
;
4406 DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr
, wptr
);
4408 /* Order reading of wptr vs. reading of IH ring data */
4411 /* display interrupts */
4414 while (rptr
!= wptr
) {
4415 /* wptr/rptr are in bytes! */
4416 ring_index
= rptr
/ 4;
4417 src_id
= le32_to_cpu(rdev
->ih
.ring
[ring_index
]) & 0xff;
4418 src_data
= le32_to_cpu(rdev
->ih
.ring
[ring_index
+ 1]) & 0xfffffff;
4421 case 1: /* D1 vblank/vline */
4423 case 0: /* D1 vblank */
4424 if (rdev
->irq
.stat_regs
.r600
.disp_int
& LB_D1_VBLANK_INTERRUPT
) {
4425 if (rdev
->irq
.crtc_vblank_int
[0]) {
4426 drm_handle_vblank(rdev
->ddev
, 0);
4427 rdev
->pm
.vblank_sync
= true;
4428 DRM_WAKEUP(&rdev
->irq
.vblank_queue
);
4430 if (atomic_read(&rdev
->irq
.pflip
[0]))
4431 radeon_crtc_handle_flip(rdev
, 0);
4432 rdev
->irq
.stat_regs
.r600
.disp_int
&= ~LB_D1_VBLANK_INTERRUPT
;
4433 DRM_DEBUG("IH: D1 vblank\n");
4436 case 1: /* D1 vline */
4437 if (rdev
->irq
.stat_regs
.r600
.disp_int
& LB_D1_VLINE_INTERRUPT
) {
4438 rdev
->irq
.stat_regs
.r600
.disp_int
&= ~LB_D1_VLINE_INTERRUPT
;
4439 DRM_DEBUG("IH: D1 vline\n");
4443 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id
, src_data
);
4447 case 5: /* D2 vblank/vline */
4449 case 0: /* D2 vblank */
4450 if (rdev
->irq
.stat_regs
.r600
.disp_int
& LB_D2_VBLANK_INTERRUPT
) {
4451 if (rdev
->irq
.crtc_vblank_int
[1]) {
4452 drm_handle_vblank(rdev
->ddev
, 1);
4453 rdev
->pm
.vblank_sync
= true;
4454 DRM_WAKEUP(&rdev
->irq
.vblank_queue
);
4456 if (atomic_read(&rdev
->irq
.pflip
[1]))
4457 radeon_crtc_handle_flip(rdev
, 1);
4458 rdev
->irq
.stat_regs
.r600
.disp_int
&= ~LB_D2_VBLANK_INTERRUPT
;
4459 DRM_DEBUG("IH: D2 vblank\n");
4462 case 1: /* D1 vline */
4463 if (rdev
->irq
.stat_regs
.r600
.disp_int
& LB_D2_VLINE_INTERRUPT
) {
4464 rdev
->irq
.stat_regs
.r600
.disp_int
&= ~LB_D2_VLINE_INTERRUPT
;
4465 DRM_DEBUG("IH: D2 vline\n");
4469 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id
, src_data
);
4473 case 19: /* HPD/DAC hotplug */
4476 if (rdev
->irq
.stat_regs
.r600
.disp_int
& DC_HPD1_INTERRUPT
) {
4477 rdev
->irq
.stat_regs
.r600
.disp_int
&= ~DC_HPD1_INTERRUPT
;
4478 queue_hotplug
= true;
4479 DRM_DEBUG("IH: HPD1\n");
4483 if (rdev
->irq
.stat_regs
.r600
.disp_int
& DC_HPD2_INTERRUPT
) {
4484 rdev
->irq
.stat_regs
.r600
.disp_int
&= ~DC_HPD2_INTERRUPT
;
4485 queue_hotplug
= true;
4486 DRM_DEBUG("IH: HPD2\n");
4490 if (rdev
->irq
.stat_regs
.r600
.disp_int_cont
& DC_HPD3_INTERRUPT
) {
4491 rdev
->irq
.stat_regs
.r600
.disp_int_cont
&= ~DC_HPD3_INTERRUPT
;
4492 queue_hotplug
= true;
4493 DRM_DEBUG("IH: HPD3\n");
4497 if (rdev
->irq
.stat_regs
.r600
.disp_int_cont
& DC_HPD4_INTERRUPT
) {
4498 rdev
->irq
.stat_regs
.r600
.disp_int_cont
&= ~DC_HPD4_INTERRUPT
;
4499 queue_hotplug
= true;
4500 DRM_DEBUG("IH: HPD4\n");
4504 if (rdev
->irq
.stat_regs
.r600
.disp_int_cont2
& DC_HPD5_INTERRUPT
) {
4505 rdev
->irq
.stat_regs
.r600
.disp_int_cont2
&= ~DC_HPD5_INTERRUPT
;
4506 queue_hotplug
= true;
4507 DRM_DEBUG("IH: HPD5\n");
4511 if (rdev
->irq
.stat_regs
.r600
.disp_int_cont2
& DC_HPD6_INTERRUPT
) {
4512 rdev
->irq
.stat_regs
.r600
.disp_int_cont2
&= ~DC_HPD6_INTERRUPT
;
4513 queue_hotplug
= true;
4514 DRM_DEBUG("IH: HPD6\n");
4518 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id
, src_data
);
4525 if (rdev
->irq
.stat_regs
.r600
.hdmi0_status
& HDMI0_AZ_FORMAT_WTRIG
) {
4526 rdev
->irq
.stat_regs
.r600
.hdmi0_status
&= ~HDMI0_AZ_FORMAT_WTRIG
;
4528 DRM_DEBUG("IH: HDMI0\n");
4532 if (rdev
->irq
.stat_regs
.r600
.hdmi1_status
& HDMI0_AZ_FORMAT_WTRIG
) {
4533 rdev
->irq
.stat_regs
.r600
.hdmi1_status
&= ~HDMI0_AZ_FORMAT_WTRIG
;
4535 DRM_DEBUG("IH: HDMI1\n");
4539 DRM_ERROR("Unhandled interrupt: %d %d\n", src_id
, src_data
);
4543 case 176: /* CP_INT in ring buffer */
4544 case 177: /* CP_INT in IB1 */
4545 case 178: /* CP_INT in IB2 */
4546 DRM_DEBUG("IH: CP int: 0x%08x\n", src_data
);
4547 radeon_fence_process(rdev
, RADEON_RING_TYPE_GFX_INDEX
);
4549 case 181: /* CP EOP event */
4550 DRM_DEBUG("IH: CP EOP\n");
4551 radeon_fence_process(rdev
, RADEON_RING_TYPE_GFX_INDEX
);
4553 case 224: /* DMA trap event */
4554 DRM_DEBUG("IH: DMA trap\n");
4555 radeon_fence_process(rdev
, R600_RING_TYPE_DMA_INDEX
);
4557 case 233: /* GUI IDLE */
4558 DRM_DEBUG("IH: GUI idle\n");
4561 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id
, src_data
);
4565 /* wptr/rptr are in bytes! */
4567 rptr
&= rdev
->ih
.ptr_mask
;
4570 taskqueue_enqueue(rdev
->tq
, &rdev
->hotplug_work
);
4572 taskqueue_enqueue(rdev
->tq
, &rdev
->audio_work
);
4573 rdev
->ih
.rptr
= rptr
;
4574 WREG32(IH_RB_RPTR
, rdev
->ih
.rptr
);
4575 atomic_set(&rdev
->ih
.lock
, 0);
4577 /* make sure wptr hasn't changed while processing */
4578 wptr
= r600_get_ih_wptr(rdev
);
4588 #if defined(CONFIG_DEBUG_FS)
4590 static int r600_debugfs_mc_info(struct seq_file
*m
, void *data
)
4592 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
4593 struct drm_device
*dev
= node
->minor
->dev
;
4594 struct radeon_device
*rdev
= dev
->dev_private
;
4596 DREG32_SYS(m
, rdev
, R_000E50_SRBM_STATUS
);
4597 DREG32_SYS(m
, rdev
, VM_L2_STATUS
);
4601 static struct drm_info_list r600_mc_info_list
[] = {
4602 {"r600_mc_info", r600_debugfs_mc_info
, 0, NULL
},
4606 int r600_debugfs_mc_info_init(struct radeon_device
*rdev
)
4608 #if defined(CONFIG_DEBUG_FS)
4609 return radeon_debugfs_add_files(rdev
, r600_mc_info_list
, ARRAY_SIZE(r600_mc_info_list
));
4616 * r600_ioctl_wait_idle - flush host path cache on wait idle ioctl
4617 * rdev: radeon device structure
4618 * bo: buffer object struct which userspace is waiting for idle
4620 * Some R6XX/R7XX doesn't seems to take into account HDP flush performed
4621 * through ring buffer, this leads to corruption in rendering, see
4622 * http://bugzilla.kernel.org/show_bug.cgi?id=15186 to avoid this we
4623 * directly perform HDP flush by writing register through MMIO.
4625 void r600_ioctl_wait_idle(struct radeon_device
*rdev
, struct radeon_bo
*bo
)
4627 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
4628 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL.
4629 * This seems to cause problems on some AGP cards. Just use the old
4632 if ((rdev
->family
>= CHIP_RV770
) && (rdev
->family
<= CHIP_RV740
) &&
4633 rdev
->vram_scratch
.ptr
&& !(rdev
->flags
& RADEON_IS_AGP
)) {
4634 volatile uint32_t *ptr
= rdev
->vram_scratch
.ptr
;
4637 WREG32(HDP_DEBUG1
, 0);
4640 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL
, 0x1);
4643 void r600_set_pcie_lanes(struct radeon_device
*rdev
, int lanes
)
4645 u32 link_width_cntl
, mask
;
4647 if (rdev
->flags
& RADEON_IS_IGP
)
4650 if (!(rdev
->flags
& RADEON_IS_PCIE
))
4653 /* x2 cards have a special sequence */
4654 if (ASIC_IS_X2(rdev
))
4657 radeon_gui_idle(rdev
);
4661 mask
= RADEON_PCIE_LC_LINK_WIDTH_X0
;
4664 mask
= RADEON_PCIE_LC_LINK_WIDTH_X1
;
4667 mask
= RADEON_PCIE_LC_LINK_WIDTH_X2
;
4670 mask
= RADEON_PCIE_LC_LINK_WIDTH_X4
;
4673 mask
= RADEON_PCIE_LC_LINK_WIDTH_X8
;
4676 /* not actually supported */
4677 mask
= RADEON_PCIE_LC_LINK_WIDTH_X12
;
4680 mask
= RADEON_PCIE_LC_LINK_WIDTH_X16
;
4683 DRM_ERROR("invalid pcie lane request: %d\n", lanes
);
4687 link_width_cntl
= RREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL
);
4688 link_width_cntl
&= ~RADEON_PCIE_LC_LINK_WIDTH_MASK
;
4689 link_width_cntl
|= mask
<< RADEON_PCIE_LC_LINK_WIDTH_SHIFT
;
4690 link_width_cntl
|= (RADEON_PCIE_LC_RECONFIG_NOW
|
4691 R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE
);
4693 WREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL
, link_width_cntl
);
4696 int r600_get_pcie_lanes(struct radeon_device
*rdev
)
4698 u32 link_width_cntl
;
4700 if (rdev
->flags
& RADEON_IS_IGP
)
4703 if (!(rdev
->flags
& RADEON_IS_PCIE
))
4706 /* x2 cards have a special sequence */
4707 if (ASIC_IS_X2(rdev
))
4710 radeon_gui_idle(rdev
);
4712 link_width_cntl
= RREG32_PCIE_PORT(RADEON_PCIE_LC_LINK_WIDTH_CNTL
);
4714 switch ((link_width_cntl
& RADEON_PCIE_LC_LINK_WIDTH_RD_MASK
) >> RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT
) {
4715 case RADEON_PCIE_LC_LINK_WIDTH_X1
:
4717 case RADEON_PCIE_LC_LINK_WIDTH_X2
:
4719 case RADEON_PCIE_LC_LINK_WIDTH_X4
:
4721 case RADEON_PCIE_LC_LINK_WIDTH_X8
:
4723 case RADEON_PCIE_LC_LINK_WIDTH_X12
:
4724 /* not actually supported */
4726 case RADEON_PCIE_LC_LINK_WIDTH_X0
:
4727 case RADEON_PCIE_LC_LINK_WIDTH_X16
:
4733 static void r600_pcie_gen2_enable(struct radeon_device
*rdev
)
4735 u32 link_width_cntl
, lanes
, speed_cntl
, training_cntl
, tmp
;
4740 if (radeon_pcie_gen2
== 0)
4743 if (rdev
->flags
& RADEON_IS_IGP
)
4746 if (!(rdev
->flags
& RADEON_IS_PCIE
))
4749 /* x2 cards have a special sequence */
4750 if (ASIC_IS_X2(rdev
))
4753 /* only RV6xx+ chips are supported */
4754 if (rdev
->family
<= CHIP_R600
)
4757 ret
= drm_pcie_get_speed_cap_mask(rdev
->ddev
, &mask
);
4761 if (!(mask
& DRM_PCIE_SPEED_50
))
4764 speed_cntl
= RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
);
4765 if (speed_cntl
& LC_CURRENT_DATA_RATE
) {
4766 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
4770 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
4772 /* 55 nm r6xx asics */
4773 if ((rdev
->family
== CHIP_RV670
) ||
4774 (rdev
->family
== CHIP_RV620
) ||
4775 (rdev
->family
== CHIP_RV635
)) {
4776 /* advertise upconfig capability */
4777 link_width_cntl
= RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL
);
4778 link_width_cntl
&= ~LC_UPCONFIGURE_DIS
;
4779 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL
, link_width_cntl
);
4780 link_width_cntl
= RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL
);
4781 if (link_width_cntl
& LC_RENEGOTIATION_SUPPORT
) {
4782 lanes
= (link_width_cntl
& LC_LINK_WIDTH_RD_MASK
) >> LC_LINK_WIDTH_RD_SHIFT
;
4783 link_width_cntl
&= ~(LC_LINK_WIDTH_MASK
|
4784 LC_RECONFIG_ARC_MISSING_ESCAPE
);
4785 link_width_cntl
|= lanes
| LC_RECONFIG_NOW
| LC_RENEGOTIATE_EN
;
4786 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL
, link_width_cntl
);
4788 link_width_cntl
|= LC_UPCONFIGURE_DIS
;
4789 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL
, link_width_cntl
);
4793 speed_cntl
= RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
);
4794 if ((speed_cntl
& LC_OTHER_SIDE_EVER_SENT_GEN2
) &&
4795 (speed_cntl
& LC_OTHER_SIDE_SUPPORTS_GEN2
)) {
4797 /* 55 nm r6xx asics */
4798 if ((rdev
->family
== CHIP_RV670
) ||
4799 (rdev
->family
== CHIP_RV620
) ||
4800 (rdev
->family
== CHIP_RV635
)) {
4801 WREG32(MM_CFGREGS_CNTL
, 0x8);
4802 link_cntl2
= RREG32(0x4088);
4803 WREG32(MM_CFGREGS_CNTL
, 0);
4804 /* not supported yet */
4805 if (link_cntl2
& SELECTABLE_DEEMPHASIS
)
4809 speed_cntl
&= ~LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_MASK
;
4810 speed_cntl
|= (0x3 << LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_SHIFT
);
4811 speed_cntl
&= ~LC_VOLTAGE_TIMER_SEL_MASK
;
4812 speed_cntl
&= ~LC_FORCE_DIS_HW_SPEED_CHANGE
;
4813 speed_cntl
|= LC_FORCE_EN_HW_SPEED_CHANGE
;
4814 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
, speed_cntl
);
4816 tmp
= RREG32(0x541c);
4817 WREG32(0x541c, tmp
| 0x8);
4818 WREG32(MM_CFGREGS_CNTL
, MM_WR_TO_CFG_EN
);
4819 link_cntl2
= RREG16(0x4088);
4820 link_cntl2
&= ~TARGET_LINK_SPEED_MASK
;
4822 WREG16(0x4088, link_cntl2
);
4823 WREG32(MM_CFGREGS_CNTL
, 0);
4825 if ((rdev
->family
== CHIP_RV670
) ||
4826 (rdev
->family
== CHIP_RV620
) ||
4827 (rdev
->family
== CHIP_RV635
)) {
4828 training_cntl
= RREG32_PCIE_PORT(PCIE_LC_TRAINING_CNTL
);
4829 training_cntl
&= ~LC_POINT_7_PLUS_EN
;
4830 WREG32_PCIE_PORT(PCIE_LC_TRAINING_CNTL
, training_cntl
);
4832 speed_cntl
= RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
);
4833 speed_cntl
&= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN
;
4834 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
, speed_cntl
);
4837 speed_cntl
= RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
);
4838 speed_cntl
|= LC_GEN2_EN_STRAP
;
4839 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL
, speed_cntl
);
4842 link_width_cntl
= RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL
);
4843 /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
4845 link_width_cntl
|= LC_UPCONFIGURE_DIS
;
4847 link_width_cntl
&= ~LC_UPCONFIGURE_DIS
;
4848 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL
, link_width_cntl
);
4853 * r600_get_gpu_clock_counter - return GPU clock counter snapshot
4855 * @rdev: radeon_device pointer
4857 * Fetches a GPU clock counter snapshot (R6xx-cayman).
4858 * Returns the 64 bit clock counter snapshot.
4860 uint64_t r600_get_gpu_clock_counter(struct radeon_device
*rdev
)
4864 spin_lock(&rdev
->gpu_clock_mutex
);
4865 WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT
, 1);
4866 clock
= (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB
) |
4867 ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB
) << 32ULL);
4868 spin_unlock(&rdev
->gpu_clock_mutex
);