2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
24 * Authors: Dave Airlie
28 #include <linux/slab.h>
29 #include <linux/seq_file.h>
30 #include <linux/firmware.h>
31 #include <linux/platform_device.h>
33 #include "radeon_drm.h"
35 #include "radeon_asic.h"
36 #include "radeon_mode.h"
41 #define PFP_UCODE_SIZE 576
42 #define PM4_UCODE_SIZE 1792
43 #define RLC_UCODE_SIZE 768
44 #define R700_PFP_UCODE_SIZE 848
45 #define R700_PM4_UCODE_SIZE 1360
46 #define R700_RLC_UCODE_SIZE 1024
47 #define EVERGREEN_PFP_UCODE_SIZE 1120
48 #define EVERGREEN_PM4_UCODE_SIZE 1376
49 #define EVERGREEN_RLC_UCODE_SIZE 768
52 MODULE_FIRMWARE("radeon/R600_pfp.bin");
53 MODULE_FIRMWARE("radeon/R600_me.bin");
54 MODULE_FIRMWARE("radeon/RV610_pfp.bin");
55 MODULE_FIRMWARE("radeon/RV610_me.bin");
56 MODULE_FIRMWARE("radeon/RV630_pfp.bin");
57 MODULE_FIRMWARE("radeon/RV630_me.bin");
58 MODULE_FIRMWARE("radeon/RV620_pfp.bin");
59 MODULE_FIRMWARE("radeon/RV620_me.bin");
60 MODULE_FIRMWARE("radeon/RV635_pfp.bin");
61 MODULE_FIRMWARE("radeon/RV635_me.bin");
62 MODULE_FIRMWARE("radeon/RV670_pfp.bin");
63 MODULE_FIRMWARE("radeon/RV670_me.bin");
64 MODULE_FIRMWARE("radeon/RS780_pfp.bin");
65 MODULE_FIRMWARE("radeon/RS780_me.bin");
66 MODULE_FIRMWARE("radeon/RV770_pfp.bin");
67 MODULE_FIRMWARE("radeon/RV770_me.bin");
68 MODULE_FIRMWARE("radeon/RV730_pfp.bin");
69 MODULE_FIRMWARE("radeon/RV730_me.bin");
70 MODULE_FIRMWARE("radeon/RV710_pfp.bin");
71 MODULE_FIRMWARE("radeon/RV710_me.bin");
72 MODULE_FIRMWARE("radeon/R600_rlc.bin");
73 MODULE_FIRMWARE("radeon/R700_rlc.bin");
74 MODULE_FIRMWARE("radeon/CEDAR_pfp.bin");
75 MODULE_FIRMWARE("radeon/CEDAR_me.bin");
76 MODULE_FIRMWARE("radeon/CEDAR_rlc.bin");
77 MODULE_FIRMWARE("radeon/REDWOOD_pfp.bin");
78 MODULE_FIRMWARE("radeon/REDWOOD_me.bin");
79 MODULE_FIRMWARE("radeon/REDWOOD_rlc.bin");
80 MODULE_FIRMWARE("radeon/JUNIPER_pfp.bin");
81 MODULE_FIRMWARE("radeon/JUNIPER_me.bin");
82 MODULE_FIRMWARE("radeon/JUNIPER_rlc.bin");
83 MODULE_FIRMWARE("radeon/CYPRESS_pfp.bin");
84 MODULE_FIRMWARE("radeon/CYPRESS_me.bin");
85 MODULE_FIRMWARE("radeon/CYPRESS_rlc.bin");
87 int r600_debugfs_mc_info_init(struct radeon_device
*rdev
);
89 /* r600,rv610,rv630,rv620,rv635,rv670 */
90 int r600_mc_wait_for_idle(struct radeon_device
*rdev
);
91 void r600_gpu_init(struct radeon_device
*rdev
);
92 void r600_fini(struct radeon_device
*rdev
);
93 void r600_irq_disable(struct radeon_device
*rdev
);
95 void r600_pm_get_dynpm_state(struct radeon_device
*rdev
)
99 rdev
->pm
.dynpm_can_upclock
= true;
100 rdev
->pm
.dynpm_can_downclock
= true;
102 /* power state array is low to high, default is first */
103 if ((rdev
->flags
& RADEON_IS_IGP
) || (rdev
->family
== CHIP_R600
)) {
104 int min_power_state_index
= 0;
106 if (rdev
->pm
.num_power_states
> 2)
107 min_power_state_index
= 1;
109 switch (rdev
->pm
.dynpm_planned_action
) {
110 case DYNPM_ACTION_MINIMUM
:
111 rdev
->pm
.requested_power_state_index
= min_power_state_index
;
112 rdev
->pm
.requested_clock_mode_index
= 0;
113 rdev
->pm
.dynpm_can_downclock
= false;
115 case DYNPM_ACTION_DOWNCLOCK
:
116 if (rdev
->pm
.current_power_state_index
== min_power_state_index
) {
117 rdev
->pm
.requested_power_state_index
= rdev
->pm
.current_power_state_index
;
118 rdev
->pm
.dynpm_can_downclock
= false;
120 if (rdev
->pm
.active_crtc_count
> 1) {
121 for (i
= 0; i
< rdev
->pm
.num_power_states
; i
++) {
122 if (rdev
->pm
.power_state
[i
].flags
& RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
)
124 else if (i
>= rdev
->pm
.current_power_state_index
) {
125 rdev
->pm
.requested_power_state_index
=
126 rdev
->pm
.current_power_state_index
;
129 rdev
->pm
.requested_power_state_index
= i
;
134 rdev
->pm
.requested_power_state_index
=
135 rdev
->pm
.current_power_state_index
- 1;
137 rdev
->pm
.requested_clock_mode_index
= 0;
138 /* don't use the power state if crtcs are active and no display flag is set */
139 if ((rdev
->pm
.active_crtc_count
> 0) &&
140 (rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].
141 clock_info
[rdev
->pm
.requested_clock_mode_index
].flags
&
142 RADEON_PM_MODE_NO_DISPLAY
)) {
143 rdev
->pm
.requested_power_state_index
++;
146 case DYNPM_ACTION_UPCLOCK
:
147 if (rdev
->pm
.current_power_state_index
== (rdev
->pm
.num_power_states
- 1)) {
148 rdev
->pm
.requested_power_state_index
= rdev
->pm
.current_power_state_index
;
149 rdev
->pm
.dynpm_can_upclock
= false;
151 if (rdev
->pm
.active_crtc_count
> 1) {
152 for (i
= (rdev
->pm
.num_power_states
- 1); i
>= 0; i
--) {
153 if (rdev
->pm
.power_state
[i
].flags
& RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
)
155 else if (i
<= rdev
->pm
.current_power_state_index
) {
156 rdev
->pm
.requested_power_state_index
=
157 rdev
->pm
.current_power_state_index
;
160 rdev
->pm
.requested_power_state_index
= i
;
165 rdev
->pm
.requested_power_state_index
=
166 rdev
->pm
.current_power_state_index
+ 1;
168 rdev
->pm
.requested_clock_mode_index
= 0;
170 case DYNPM_ACTION_DEFAULT
:
171 rdev
->pm
.requested_power_state_index
= rdev
->pm
.default_power_state_index
;
172 rdev
->pm
.requested_clock_mode_index
= 0;
173 rdev
->pm
.dynpm_can_upclock
= false;
175 case DYNPM_ACTION_NONE
:
177 DRM_ERROR("Requested mode for not defined action\n");
181 /* XXX select a power state based on AC/DC, single/dualhead, etc. */
182 /* for now just select the first power state and switch between clock modes */
183 /* power state array is low to high, default is first (0) */
184 if (rdev
->pm
.active_crtc_count
> 1) {
185 rdev
->pm
.requested_power_state_index
= -1;
186 /* start at 1 as we don't want the default mode */
187 for (i
= 1; i
< rdev
->pm
.num_power_states
; i
++) {
188 if (rdev
->pm
.power_state
[i
].flags
& RADEON_PM_STATE_SINGLE_DISPLAY_ONLY
)
190 else if ((rdev
->pm
.power_state
[i
].type
== POWER_STATE_TYPE_PERFORMANCE
) ||
191 (rdev
->pm
.power_state
[i
].type
== POWER_STATE_TYPE_BATTERY
)) {
192 rdev
->pm
.requested_power_state_index
= i
;
196 /* if nothing selected, grab the default state. */
197 if (rdev
->pm
.requested_power_state_index
== -1)
198 rdev
->pm
.requested_power_state_index
= 0;
200 rdev
->pm
.requested_power_state_index
= 1;
202 switch (rdev
->pm
.dynpm_planned_action
) {
203 case DYNPM_ACTION_MINIMUM
:
204 rdev
->pm
.requested_clock_mode_index
= 0;
205 rdev
->pm
.dynpm_can_downclock
= false;
207 case DYNPM_ACTION_DOWNCLOCK
:
208 if (rdev
->pm
.requested_power_state_index
== rdev
->pm
.current_power_state_index
) {
209 if (rdev
->pm
.current_clock_mode_index
== 0) {
210 rdev
->pm
.requested_clock_mode_index
= 0;
211 rdev
->pm
.dynpm_can_downclock
= false;
213 rdev
->pm
.requested_clock_mode_index
=
214 rdev
->pm
.current_clock_mode_index
- 1;
216 rdev
->pm
.requested_clock_mode_index
= 0;
217 rdev
->pm
.dynpm_can_downclock
= false;
219 /* don't use the power state if crtcs are active and no display flag is set */
220 if ((rdev
->pm
.active_crtc_count
> 0) &&
221 (rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].
222 clock_info
[rdev
->pm
.requested_clock_mode_index
].flags
&
223 RADEON_PM_MODE_NO_DISPLAY
)) {
224 rdev
->pm
.requested_clock_mode_index
++;
227 case DYNPM_ACTION_UPCLOCK
:
228 if (rdev
->pm
.requested_power_state_index
== rdev
->pm
.current_power_state_index
) {
229 if (rdev
->pm
.current_clock_mode_index
==
230 (rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].num_clock_modes
- 1)) {
231 rdev
->pm
.requested_clock_mode_index
= rdev
->pm
.current_clock_mode_index
;
232 rdev
->pm
.dynpm_can_upclock
= false;
234 rdev
->pm
.requested_clock_mode_index
=
235 rdev
->pm
.current_clock_mode_index
+ 1;
237 rdev
->pm
.requested_clock_mode_index
=
238 rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].num_clock_modes
- 1;
239 rdev
->pm
.dynpm_can_upclock
= false;
242 case DYNPM_ACTION_DEFAULT
:
243 rdev
->pm
.requested_power_state_index
= rdev
->pm
.default_power_state_index
;
244 rdev
->pm
.requested_clock_mode_index
= 0;
245 rdev
->pm
.dynpm_can_upclock
= false;
247 case DYNPM_ACTION_NONE
:
249 DRM_ERROR("Requested mode for not defined action\n");
254 DRM_DEBUG("Requested: e: %d m: %d p: %d\n",
255 rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].
256 clock_info
[rdev
->pm
.requested_clock_mode_index
].sclk
,
257 rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].
258 clock_info
[rdev
->pm
.requested_clock_mode_index
].mclk
,
259 rdev
->pm
.power_state
[rdev
->pm
.requested_power_state_index
].
263 static int r600_pm_get_type_index(struct radeon_device
*rdev
,
264 enum radeon_pm_state_type ps_type
,
268 int found_instance
= -1;
270 for (i
= 0; i
< rdev
->pm
.num_power_states
; i
++) {
271 if (rdev
->pm
.power_state
[i
].type
== ps_type
) {
273 if (found_instance
== instance
)
277 /* return default if no match */
278 return rdev
->pm
.default_power_state_index
;
281 void rs780_pm_init_profile(struct radeon_device
*rdev
)
283 if (rdev
->pm
.num_power_states
== 2) {
285 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
286 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
287 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_cm_idx
= 0;
288 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_cm_idx
= 0;
290 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_ps_idx
= 0;
291 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_ps_idx
= 0;
292 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_cm_idx
= 0;
293 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_cm_idx
= 0;
295 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_ps_idx
= 0;
296 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_ps_idx
= 1;
297 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_cm_idx
= 0;
298 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_cm_idx
= 0;
300 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_ps_idx
= 0;
301 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_ps_idx
= 0;
302 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_cm_idx
= 0;
303 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_cm_idx
= 0;
305 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_ps_idx
= 0;
306 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_ps_idx
= 1;
307 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_cm_idx
= 0;
308 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_cm_idx
= 0;
309 } else if (rdev
->pm
.num_power_states
== 3) {
311 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
312 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
313 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_cm_idx
= 0;
314 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_cm_idx
= 0;
316 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_ps_idx
= 1;
317 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_ps_idx
= 1;
318 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_cm_idx
= 0;
319 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_cm_idx
= 0;
321 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_ps_idx
= 1;
322 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_ps_idx
= 2;
323 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_cm_idx
= 0;
324 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_cm_idx
= 0;
326 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_ps_idx
= 1;
327 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_ps_idx
= 1;
328 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_cm_idx
= 0;
329 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_cm_idx
= 0;
331 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_ps_idx
= 1;
332 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_ps_idx
= 2;
333 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_cm_idx
= 0;
334 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_cm_idx
= 0;
337 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
338 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
339 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_cm_idx
= 0;
340 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_cm_idx
= 0;
342 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_ps_idx
= 2;
343 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_ps_idx
= 2;
344 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_cm_idx
= 0;
345 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_cm_idx
= 0;
347 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_ps_idx
= 2;
348 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_ps_idx
= 3;
349 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_cm_idx
= 0;
350 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_cm_idx
= 0;
352 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_ps_idx
= 2;
353 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_ps_idx
= 0;
354 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_cm_idx
= 0;
355 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_cm_idx
= 0;
357 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_ps_idx
= 2;
358 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_ps_idx
= 3;
359 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_cm_idx
= 0;
360 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_cm_idx
= 0;
364 void r600_pm_init_profile(struct radeon_device
*rdev
)
366 if (rdev
->family
== CHIP_R600
) {
369 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
370 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
371 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_cm_idx
= 0;
372 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_cm_idx
= 0;
374 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
375 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
376 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_cm_idx
= 0;
377 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_cm_idx
= 0;
379 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
380 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
381 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_cm_idx
= 0;
382 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_cm_idx
= 0;
384 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
385 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
386 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_cm_idx
= 0;
387 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_cm_idx
= 0;
389 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
390 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
391 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_cm_idx
= 0;
392 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_cm_idx
= 0;
394 if (rdev
->pm
.num_power_states
< 4) {
396 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
397 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
398 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_cm_idx
= 0;
399 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_cm_idx
= 2;
401 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_ps_idx
= 1;
402 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_ps_idx
= 1;
403 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_cm_idx
= 0;
404 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_cm_idx
= 1;
406 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_ps_idx
= 1;
407 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_ps_idx
= 1;
408 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_cm_idx
= 0;
409 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_cm_idx
= 2;
411 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_ps_idx
= 2;
412 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_ps_idx
= 2;
413 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_cm_idx
= 0;
414 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_cm_idx
= 1;
416 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_ps_idx
= 2;
417 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_ps_idx
= 2;
418 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_cm_idx
= 0;
419 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_cm_idx
= 2;
422 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_ps_idx
= rdev
->pm
.default_power_state_index
;
423 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_ps_idx
= rdev
->pm
.default_power_state_index
;
424 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_off_cm_idx
= 0;
425 rdev
->pm
.profiles
[PM_PROFILE_DEFAULT_IDX
].dpms_on_cm_idx
= 2;
427 if (rdev
->flags
& RADEON_IS_MOBILITY
) {
428 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_ps_idx
=
429 r600_pm_get_type_index(rdev
, POWER_STATE_TYPE_BATTERY
, 0);
430 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_ps_idx
=
431 r600_pm_get_type_index(rdev
, POWER_STATE_TYPE_BATTERY
, 0);
432 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_cm_idx
= 0;
433 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_cm_idx
= 1;
435 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_ps_idx
=
436 r600_pm_get_type_index(rdev
, POWER_STATE_TYPE_PERFORMANCE
, 0);
437 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_ps_idx
=
438 r600_pm_get_type_index(rdev
, POWER_STATE_TYPE_PERFORMANCE
, 0);
439 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_off_cm_idx
= 0;
440 rdev
->pm
.profiles
[PM_PROFILE_LOW_SH_IDX
].dpms_on_cm_idx
= 1;
443 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_ps_idx
=
444 r600_pm_get_type_index(rdev
, POWER_STATE_TYPE_PERFORMANCE
, 0);
445 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_ps_idx
=
446 r600_pm_get_type_index(rdev
, POWER_STATE_TYPE_PERFORMANCE
, 0);
447 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_off_cm_idx
= 0;
448 rdev
->pm
.profiles
[PM_PROFILE_HIGH_SH_IDX
].dpms_on_cm_idx
= 2;
450 if (rdev
->flags
& RADEON_IS_MOBILITY
) {
451 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_ps_idx
=
452 r600_pm_get_type_index(rdev
, POWER_STATE_TYPE_BATTERY
, 1);
453 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_ps_idx
=
454 r600_pm_get_type_index(rdev
, POWER_STATE_TYPE_BATTERY
, 1);
455 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_cm_idx
= 0;
456 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_cm_idx
= 2;
458 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_ps_idx
=
459 r600_pm_get_type_index(rdev
, POWER_STATE_TYPE_PERFORMANCE
, 1);
460 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_ps_idx
=
461 r600_pm_get_type_index(rdev
, POWER_STATE_TYPE_PERFORMANCE
, 1);
462 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_off_cm_idx
= 0;
463 rdev
->pm
.profiles
[PM_PROFILE_LOW_MH_IDX
].dpms_on_cm_idx
= 1;
466 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_ps_idx
=
467 r600_pm_get_type_index(rdev
, POWER_STATE_TYPE_PERFORMANCE
, 1);
468 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_ps_idx
=
469 r600_pm_get_type_index(rdev
, POWER_STATE_TYPE_PERFORMANCE
, 1);
470 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_off_cm_idx
= 0;
471 rdev
->pm
.profiles
[PM_PROFILE_HIGH_MH_IDX
].dpms_on_cm_idx
= 2;
476 void r600_pm_misc(struct radeon_device
*rdev
)
481 bool r600_gui_idle(struct radeon_device
*rdev
)
483 if (RREG32(GRBM_STATUS
) & GUI_ACTIVE
)
489 /* hpd for digital panel detect/disconnect */
490 bool r600_hpd_sense(struct radeon_device
*rdev
, enum radeon_hpd_id hpd
)
492 bool connected
= false;
494 if (ASIC_IS_DCE3(rdev
)) {
497 if (RREG32(DC_HPD1_INT_STATUS
) & DC_HPDx_SENSE
)
501 if (RREG32(DC_HPD2_INT_STATUS
) & DC_HPDx_SENSE
)
505 if (RREG32(DC_HPD3_INT_STATUS
) & DC_HPDx_SENSE
)
509 if (RREG32(DC_HPD4_INT_STATUS
) & DC_HPDx_SENSE
)
514 if (RREG32(DC_HPD5_INT_STATUS
) & DC_HPDx_SENSE
)
518 if (RREG32(DC_HPD6_INT_STATUS
) & DC_HPDx_SENSE
)
527 if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS
) & DC_HOT_PLUG_DETECTx_SENSE
)
531 if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS
) & DC_HOT_PLUG_DETECTx_SENSE
)
535 if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS
) & DC_HOT_PLUG_DETECTx_SENSE
)
545 void r600_hpd_set_polarity(struct radeon_device
*rdev
,
546 enum radeon_hpd_id hpd
)
549 bool connected
= r600_hpd_sense(rdev
, hpd
);
551 if (ASIC_IS_DCE3(rdev
)) {
554 tmp
= RREG32(DC_HPD1_INT_CONTROL
);
556 tmp
&= ~DC_HPDx_INT_POLARITY
;
558 tmp
|= DC_HPDx_INT_POLARITY
;
559 WREG32(DC_HPD1_INT_CONTROL
, tmp
);
562 tmp
= RREG32(DC_HPD2_INT_CONTROL
);
564 tmp
&= ~DC_HPDx_INT_POLARITY
;
566 tmp
|= DC_HPDx_INT_POLARITY
;
567 WREG32(DC_HPD2_INT_CONTROL
, tmp
);
570 tmp
= RREG32(DC_HPD3_INT_CONTROL
);
572 tmp
&= ~DC_HPDx_INT_POLARITY
;
574 tmp
|= DC_HPDx_INT_POLARITY
;
575 WREG32(DC_HPD3_INT_CONTROL
, tmp
);
578 tmp
= RREG32(DC_HPD4_INT_CONTROL
);
580 tmp
&= ~DC_HPDx_INT_POLARITY
;
582 tmp
|= DC_HPDx_INT_POLARITY
;
583 WREG32(DC_HPD4_INT_CONTROL
, tmp
);
586 tmp
= RREG32(DC_HPD5_INT_CONTROL
);
588 tmp
&= ~DC_HPDx_INT_POLARITY
;
590 tmp
|= DC_HPDx_INT_POLARITY
;
591 WREG32(DC_HPD5_INT_CONTROL
, tmp
);
595 tmp
= RREG32(DC_HPD6_INT_CONTROL
);
597 tmp
&= ~DC_HPDx_INT_POLARITY
;
599 tmp
|= DC_HPDx_INT_POLARITY
;
600 WREG32(DC_HPD6_INT_CONTROL
, tmp
);
608 tmp
= RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
);
610 tmp
&= ~DC_HOT_PLUG_DETECTx_INT_POLARITY
;
612 tmp
|= DC_HOT_PLUG_DETECTx_INT_POLARITY
;
613 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
, tmp
);
616 tmp
= RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
);
618 tmp
&= ~DC_HOT_PLUG_DETECTx_INT_POLARITY
;
620 tmp
|= DC_HOT_PLUG_DETECTx_INT_POLARITY
;
621 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
, tmp
);
624 tmp
= RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
);
626 tmp
&= ~DC_HOT_PLUG_DETECTx_INT_POLARITY
;
628 tmp
|= DC_HOT_PLUG_DETECTx_INT_POLARITY
;
629 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
, tmp
);
637 void r600_hpd_init(struct radeon_device
*rdev
)
639 struct drm_device
*dev
= rdev
->ddev
;
640 struct drm_connector
*connector
;
642 if (ASIC_IS_DCE3(rdev
)) {
643 u32 tmp
= DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
644 if (ASIC_IS_DCE32(rdev
))
647 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
648 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
649 switch (radeon_connector
->hpd
.hpd
) {
651 WREG32(DC_HPD1_CONTROL
, tmp
);
652 rdev
->irq
.hpd
[0] = true;
655 WREG32(DC_HPD2_CONTROL
, tmp
);
656 rdev
->irq
.hpd
[1] = true;
659 WREG32(DC_HPD3_CONTROL
, tmp
);
660 rdev
->irq
.hpd
[2] = true;
663 WREG32(DC_HPD4_CONTROL
, tmp
);
664 rdev
->irq
.hpd
[3] = true;
668 WREG32(DC_HPD5_CONTROL
, tmp
);
669 rdev
->irq
.hpd
[4] = true;
672 WREG32(DC_HPD6_CONTROL
, tmp
);
673 rdev
->irq
.hpd
[5] = true;
680 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
681 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
682 switch (radeon_connector
->hpd
.hpd
) {
684 WREG32(DC_HOT_PLUG_DETECT1_CONTROL
, DC_HOT_PLUG_DETECTx_EN
);
685 rdev
->irq
.hpd
[0] = true;
688 WREG32(DC_HOT_PLUG_DETECT2_CONTROL
, DC_HOT_PLUG_DETECTx_EN
);
689 rdev
->irq
.hpd
[1] = true;
692 WREG32(DC_HOT_PLUG_DETECT3_CONTROL
, DC_HOT_PLUG_DETECTx_EN
);
693 rdev
->irq
.hpd
[2] = true;
700 if (rdev
->irq
.installed
)
704 void r600_hpd_fini(struct radeon_device
*rdev
)
706 struct drm_device
*dev
= rdev
->ddev
;
707 struct drm_connector
*connector
;
709 if (ASIC_IS_DCE3(rdev
)) {
710 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
711 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
712 switch (radeon_connector
->hpd
.hpd
) {
714 WREG32(DC_HPD1_CONTROL
, 0);
715 rdev
->irq
.hpd
[0] = false;
718 WREG32(DC_HPD2_CONTROL
, 0);
719 rdev
->irq
.hpd
[1] = false;
722 WREG32(DC_HPD3_CONTROL
, 0);
723 rdev
->irq
.hpd
[2] = false;
726 WREG32(DC_HPD4_CONTROL
, 0);
727 rdev
->irq
.hpd
[3] = false;
731 WREG32(DC_HPD5_CONTROL
, 0);
732 rdev
->irq
.hpd
[4] = false;
735 WREG32(DC_HPD6_CONTROL
, 0);
736 rdev
->irq
.hpd
[5] = false;
743 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
744 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
745 switch (radeon_connector
->hpd
.hpd
) {
747 WREG32(DC_HOT_PLUG_DETECT1_CONTROL
, 0);
748 rdev
->irq
.hpd
[0] = false;
751 WREG32(DC_HOT_PLUG_DETECT2_CONTROL
, 0);
752 rdev
->irq
.hpd
[1] = false;
755 WREG32(DC_HOT_PLUG_DETECT3_CONTROL
, 0);
756 rdev
->irq
.hpd
[2] = false;
768 void r600_pcie_gart_tlb_flush(struct radeon_device
*rdev
)
773 /* flush hdp cache so updates hit vram */
774 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL
, 0x1);
776 WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR
, rdev
->mc
.gtt_start
>> 12);
777 WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR
, (rdev
->mc
.gtt_end
- 1) >> 12);
778 WREG32(VM_CONTEXT0_REQUEST_RESPONSE
, REQUEST_TYPE(1));
779 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
781 tmp
= RREG32(VM_CONTEXT0_REQUEST_RESPONSE
);
782 tmp
= (tmp
& RESPONSE_TYPE_MASK
) >> RESPONSE_TYPE_SHIFT
;
784 printk(KERN_WARNING
"[drm] r600 flush TLB failed\n");
794 int r600_pcie_gart_init(struct radeon_device
*rdev
)
798 if (rdev
->gart
.table
.vram
.robj
) {
799 WARN(1, "R600 PCIE GART already initialized.\n");
802 /* Initialize common gart structure */
803 r
= radeon_gart_init(rdev
);
806 rdev
->gart
.table_size
= rdev
->gart
.num_gpu_pages
* 8;
807 return radeon_gart_table_vram_alloc(rdev
);
810 int r600_pcie_gart_enable(struct radeon_device
*rdev
)
815 if (rdev
->gart
.table
.vram
.robj
== NULL
) {
816 dev_err(rdev
->dev
, "No VRAM object for PCIE GART.\n");
819 r
= radeon_gart_table_vram_pin(rdev
);
822 radeon_gart_restore(rdev
);
825 WREG32(VM_L2_CNTL
, ENABLE_L2_CACHE
| ENABLE_L2_FRAGMENT_PROCESSING
|
826 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE
|
827 EFFECTIVE_L2_QUEUE_SIZE(7));
828 WREG32(VM_L2_CNTL2
, 0);
829 WREG32(VM_L2_CNTL3
, BANK_SELECT_0(0) | BANK_SELECT_1(1));
830 /* Setup TLB control */
831 tmp
= ENABLE_L1_TLB
| ENABLE_L1_FRAGMENT_PROCESSING
|
832 SYSTEM_ACCESS_MODE_NOT_IN_SYS
|
833 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
834 ENABLE_WAIT_L2_QUERY
;
835 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL
, tmp
);
836 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL
, tmp
);
837 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL
, tmp
| ENABLE_L1_STRICT_ORDERING
);
838 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL
, tmp
);
839 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL
, tmp
);
840 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL
, tmp
);
841 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL
, tmp
);
842 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL
, tmp
);
843 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL
, tmp
);
844 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL
, tmp
);
845 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL
, tmp
);
846 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL
, tmp
);
847 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL
, tmp
| ENABLE_SEMAPHORE_MODE
);
848 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL
, tmp
| ENABLE_SEMAPHORE_MODE
);
849 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR
, rdev
->mc
.gtt_start
>> 12);
850 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR
, rdev
->mc
.gtt_end
>> 12);
851 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR
, rdev
->gart
.table_addr
>> 12);
852 WREG32(VM_CONTEXT0_CNTL
, ENABLE_CONTEXT
| PAGE_TABLE_DEPTH(0) |
853 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT
);
854 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR
,
855 (u32
)(rdev
->dummy_page
.addr
>> 12));
856 for (i
= 1; i
< 7; i
++)
857 WREG32(VM_CONTEXT0_CNTL
+ (i
* 4), 0);
859 r600_pcie_gart_tlb_flush(rdev
);
860 rdev
->gart
.ready
= true;
864 void r600_pcie_gart_disable(struct radeon_device
*rdev
)
869 /* Disable all tables */
870 for (i
= 0; i
< 7; i
++)
871 WREG32(VM_CONTEXT0_CNTL
+ (i
* 4), 0);
873 /* Disable L2 cache */
874 WREG32(VM_L2_CNTL
, ENABLE_L2_FRAGMENT_PROCESSING
|
875 EFFECTIVE_L2_QUEUE_SIZE(7));
876 WREG32(VM_L2_CNTL3
, BANK_SELECT_0(0) | BANK_SELECT_1(1));
877 /* Setup L1 TLB control */
878 tmp
= EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
879 ENABLE_WAIT_L2_QUERY
;
880 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL
, tmp
);
881 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL
, tmp
);
882 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL
, tmp
);
883 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL
, tmp
);
884 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL
, tmp
);
885 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL
, tmp
);
886 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL
, tmp
);
887 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL
, tmp
);
888 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL
, tmp
);
889 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL
, tmp
);
890 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL
, tmp
);
891 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL
, tmp
);
892 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL
, tmp
);
893 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL
, tmp
);
894 if (rdev
->gart
.table
.vram
.robj
) {
895 r
= radeon_bo_reserve(rdev
->gart
.table
.vram
.robj
, false);
896 if (likely(r
== 0)) {
897 radeon_bo_kunmap(rdev
->gart
.table
.vram
.robj
);
898 radeon_bo_unpin(rdev
->gart
.table
.vram
.robj
);
899 radeon_bo_unreserve(rdev
->gart
.table
.vram
.robj
);
904 void r600_pcie_gart_fini(struct radeon_device
*rdev
)
906 radeon_gart_fini(rdev
);
907 r600_pcie_gart_disable(rdev
);
908 radeon_gart_table_vram_free(rdev
);
911 void r600_agp_enable(struct radeon_device
*rdev
)
917 WREG32(VM_L2_CNTL
, ENABLE_L2_CACHE
| ENABLE_L2_FRAGMENT_PROCESSING
|
918 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE
|
919 EFFECTIVE_L2_QUEUE_SIZE(7));
920 WREG32(VM_L2_CNTL2
, 0);
921 WREG32(VM_L2_CNTL3
, BANK_SELECT_0(0) | BANK_SELECT_1(1));
922 /* Setup TLB control */
923 tmp
= ENABLE_L1_TLB
| ENABLE_L1_FRAGMENT_PROCESSING
|
924 SYSTEM_ACCESS_MODE_NOT_IN_SYS
|
925 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
926 ENABLE_WAIT_L2_QUERY
;
927 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL
, tmp
);
928 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL
, tmp
);
929 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL
, tmp
| ENABLE_L1_STRICT_ORDERING
);
930 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL
, tmp
);
931 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL
, tmp
);
932 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL
, tmp
);
933 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL
, tmp
);
934 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL
, tmp
);
935 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL
, tmp
);
936 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL
, tmp
);
937 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL
, tmp
);
938 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL
, tmp
);
939 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL
, tmp
| ENABLE_SEMAPHORE_MODE
);
940 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL
, tmp
| ENABLE_SEMAPHORE_MODE
);
941 for (i
= 0; i
< 7; i
++)
942 WREG32(VM_CONTEXT0_CNTL
+ (i
* 4), 0);
945 int r600_mc_wait_for_idle(struct radeon_device
*rdev
)
950 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
952 tmp
= RREG32(R_000E50_SRBM_STATUS
) & 0x3F00;
960 static void r600_mc_program(struct radeon_device
*rdev
)
962 struct rv515_mc_save save
;
967 for (i
= 0, j
= 0; i
< 32; i
++, j
+= 0x18) {
968 WREG32((0x2c14 + j
), 0x00000000);
969 WREG32((0x2c18 + j
), 0x00000000);
970 WREG32((0x2c1c + j
), 0x00000000);
971 WREG32((0x2c20 + j
), 0x00000000);
972 WREG32((0x2c24 + j
), 0x00000000);
974 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL
, 0);
976 rv515_mc_stop(rdev
, &save
);
977 if (r600_mc_wait_for_idle(rdev
)) {
978 dev_warn(rdev
->dev
, "Wait for MC idle timedout !\n");
980 /* Lockout access through VGA aperture (doesn't exist before R600) */
981 WREG32(VGA_HDP_CONTROL
, VGA_MEMORY_DISABLE
);
982 /* Update configuration */
983 if (rdev
->flags
& RADEON_IS_AGP
) {
984 if (rdev
->mc
.vram_start
< rdev
->mc
.gtt_start
) {
985 /* VRAM before AGP */
986 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR
,
987 rdev
->mc
.vram_start
>> 12);
988 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR
,
989 rdev
->mc
.gtt_end
>> 12);
992 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR
,
993 rdev
->mc
.gtt_start
>> 12);
994 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR
,
995 rdev
->mc
.vram_end
>> 12);
998 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR
, rdev
->mc
.vram_start
>> 12);
999 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR
, rdev
->mc
.vram_end
>> 12);
1001 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR
, 0);
1002 tmp
= ((rdev
->mc
.vram_end
>> 24) & 0xFFFF) << 16;
1003 tmp
|= ((rdev
->mc
.vram_start
>> 24) & 0xFFFF);
1004 WREG32(MC_VM_FB_LOCATION
, tmp
);
1005 WREG32(HDP_NONSURFACE_BASE
, (rdev
->mc
.vram_start
>> 8));
1006 WREG32(HDP_NONSURFACE_INFO
, (2 << 7));
1007 WREG32(HDP_NONSURFACE_SIZE
, rdev
->mc
.mc_vram_size
| 0x3FF);
1008 if (rdev
->flags
& RADEON_IS_AGP
) {
1009 WREG32(MC_VM_AGP_TOP
, rdev
->mc
.gtt_end
>> 22);
1010 WREG32(MC_VM_AGP_BOT
, rdev
->mc
.gtt_start
>> 22);
1011 WREG32(MC_VM_AGP_BASE
, rdev
->mc
.agp_base
>> 22);
1013 WREG32(MC_VM_AGP_BASE
, 0);
1014 WREG32(MC_VM_AGP_TOP
, 0x0FFFFFFF);
1015 WREG32(MC_VM_AGP_BOT
, 0x0FFFFFFF);
1017 if (r600_mc_wait_for_idle(rdev
)) {
1018 dev_warn(rdev
->dev
, "Wait for MC idle timedout !\n");
1020 rv515_mc_resume(rdev
, &save
);
1021 /* we need to own VRAM, so turn off the VGA renderer here
1022 * to stop it overwriting our objects */
1023 rv515_vga_render_disable(rdev
);
1027 * r600_vram_gtt_location - try to find VRAM & GTT location
1028 * @rdev: radeon device structure holding all necessary informations
1029 * @mc: memory controller structure holding memory informations
1031 * Function will place try to place VRAM at same place as in CPU (PCI)
1032 * address space as some GPU seems to have issue when we reprogram at
1033 * different address space.
1035 * If there is not enough space to fit the unvisible VRAM after the
1036 * aperture then we limit the VRAM size to the aperture.
1038 * If we are using AGP then place VRAM adjacent to AGP aperture are we need
1039 * them to be in one from GPU point of view so that we can program GPU to
1040 * catch access outside them (weird GPU policy see ??).
1042 * This function will never fails, worst case are limiting VRAM or GTT.
1044 * Note: GTT start, end, size should be initialized before calling this
1045 * function on AGP platform.
1047 void r600_vram_gtt_location(struct radeon_device
*rdev
, struct radeon_mc
*mc
)
1049 u64 size_bf
, size_af
;
1051 if (mc
->mc_vram_size
> 0xE0000000) {
1052 /* leave room for at least 512M GTT */
1053 dev_warn(rdev
->dev
, "limiting VRAM\n");
1054 mc
->real_vram_size
= 0xE0000000;
1055 mc
->mc_vram_size
= 0xE0000000;
1057 if (rdev
->flags
& RADEON_IS_AGP
) {
1058 size_bf
= mc
->gtt_start
;
1059 size_af
= 0xFFFFFFFF - mc
->gtt_end
+ 1;
1060 if (size_bf
> size_af
) {
1061 if (mc
->mc_vram_size
> size_bf
) {
1062 dev_warn(rdev
->dev
, "limiting VRAM\n");
1063 mc
->real_vram_size
= size_bf
;
1064 mc
->mc_vram_size
= size_bf
;
1066 mc
->vram_start
= mc
->gtt_start
- mc
->mc_vram_size
;
1068 if (mc
->mc_vram_size
> size_af
) {
1069 dev_warn(rdev
->dev
, "limiting VRAM\n");
1070 mc
->real_vram_size
= size_af
;
1071 mc
->mc_vram_size
= size_af
;
1073 mc
->vram_start
= mc
->gtt_end
;
1075 mc
->vram_end
= mc
->vram_start
+ mc
->mc_vram_size
- 1;
1076 dev_info(rdev
->dev
, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
1077 mc
->mc_vram_size
>> 20, mc
->vram_start
,
1078 mc
->vram_end
, mc
->real_vram_size
>> 20);
1081 if (rdev
->flags
& RADEON_IS_IGP
)
1082 base
= (RREG32(MC_VM_FB_LOCATION
) & 0xFFFF) << 24;
1083 radeon_vram_location(rdev
, &rdev
->mc
, base
);
1084 radeon_gtt_location(rdev
, mc
);
1088 int r600_mc_init(struct radeon_device
*rdev
)
1091 int chansize
, numchan
;
1093 /* Get VRAM informations */
1094 rdev
->mc
.vram_is_ddr
= true;
1095 tmp
= RREG32(RAMCFG
);
1096 if (tmp
& CHANSIZE_OVERRIDE
) {
1098 } else if (tmp
& CHANSIZE_MASK
) {
1103 tmp
= RREG32(CHMAP
);
1104 switch ((tmp
& NOOFCHAN_MASK
) >> NOOFCHAN_SHIFT
) {
1119 rdev
->mc
.vram_width
= numchan
* chansize
;
1120 /* Could aper size report 0 ? */
1121 rdev
->mc
.aper_base
= drm_get_resource_start(rdev
->ddev
, 0);
1122 rdev
->mc
.aper_size
= drm_get_resource_len(rdev
->ddev
, 0);
1123 /* Setup GPU memory space */
1124 rdev
->mc
.mc_vram_size
= RREG32(CONFIG_MEMSIZE
);
1125 rdev
->mc
.real_vram_size
= RREG32(CONFIG_MEMSIZE
);
1126 rdev
->mc
.visible_vram_size
= rdev
->mc
.aper_size
;
1127 r600_vram_gtt_location(rdev
, &rdev
->mc
);
1129 if (rdev
->flags
& RADEON_IS_IGP
)
1130 rdev
->mc
.igp_sideport_enabled
= radeon_atombios_sideport_present(rdev
);
1131 radeon_update_bandwidth_info(rdev
);
1135 /* We doesn't check that the GPU really needs a reset we simply do the
1136 * reset, it's up to the caller to determine if the GPU needs one. We
1137 * might add an helper function to check that.
1139 int r600_gpu_soft_reset(struct radeon_device
*rdev
)
1141 struct rv515_mc_save save
;
1142 u32 grbm_busy_mask
= S_008010_VC_BUSY(1) | S_008010_VGT_BUSY_NO_DMA(1) |
1143 S_008010_VGT_BUSY(1) | S_008010_TA03_BUSY(1) |
1144 S_008010_TC_BUSY(1) | S_008010_SX_BUSY(1) |
1145 S_008010_SH_BUSY(1) | S_008010_SPI03_BUSY(1) |
1146 S_008010_SMX_BUSY(1) | S_008010_SC_BUSY(1) |
1147 S_008010_PA_BUSY(1) | S_008010_DB03_BUSY(1) |
1148 S_008010_CR_BUSY(1) | S_008010_CB03_BUSY(1) |
1149 S_008010_GUI_ACTIVE(1);
1150 u32 grbm2_busy_mask
= S_008014_SPI0_BUSY(1) | S_008014_SPI1_BUSY(1) |
1151 S_008014_SPI2_BUSY(1) | S_008014_SPI3_BUSY(1) |
1152 S_008014_TA0_BUSY(1) | S_008014_TA1_BUSY(1) |
1153 S_008014_TA2_BUSY(1) | S_008014_TA3_BUSY(1) |
1154 S_008014_DB0_BUSY(1) | S_008014_DB1_BUSY(1) |
1155 S_008014_DB2_BUSY(1) | S_008014_DB3_BUSY(1) |
1156 S_008014_CB0_BUSY(1) | S_008014_CB1_BUSY(1) |
1157 S_008014_CB2_BUSY(1) | S_008014_CB3_BUSY(1);
1160 dev_info(rdev
->dev
, "GPU softreset \n");
1161 dev_info(rdev
->dev
, " R_008010_GRBM_STATUS=0x%08X\n",
1162 RREG32(R_008010_GRBM_STATUS
));
1163 dev_info(rdev
->dev
, " R_008014_GRBM_STATUS2=0x%08X\n",
1164 RREG32(R_008014_GRBM_STATUS2
));
1165 dev_info(rdev
->dev
, " R_000E50_SRBM_STATUS=0x%08X\n",
1166 RREG32(R_000E50_SRBM_STATUS
));
1167 rv515_mc_stop(rdev
, &save
);
1168 if (r600_mc_wait_for_idle(rdev
)) {
1169 dev_warn(rdev
->dev
, "Wait for MC idle timedout !\n");
1171 /* Disable CP parsing/prefetching */
1172 WREG32(R_0086D8_CP_ME_CNTL
, S_0086D8_CP_ME_HALT(1));
1173 /* Check if any of the rendering block is busy and reset it */
1174 if ((RREG32(R_008010_GRBM_STATUS
) & grbm_busy_mask
) ||
1175 (RREG32(R_008014_GRBM_STATUS2
) & grbm2_busy_mask
)) {
1176 tmp
= S_008020_SOFT_RESET_CR(1) |
1177 S_008020_SOFT_RESET_DB(1) |
1178 S_008020_SOFT_RESET_CB(1) |
1179 S_008020_SOFT_RESET_PA(1) |
1180 S_008020_SOFT_RESET_SC(1) |
1181 S_008020_SOFT_RESET_SMX(1) |
1182 S_008020_SOFT_RESET_SPI(1) |
1183 S_008020_SOFT_RESET_SX(1) |
1184 S_008020_SOFT_RESET_SH(1) |
1185 S_008020_SOFT_RESET_TC(1) |
1186 S_008020_SOFT_RESET_TA(1) |
1187 S_008020_SOFT_RESET_VC(1) |
1188 S_008020_SOFT_RESET_VGT(1);
1189 dev_info(rdev
->dev
, " R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp
);
1190 WREG32(R_008020_GRBM_SOFT_RESET
, tmp
);
1191 RREG32(R_008020_GRBM_SOFT_RESET
);
1193 WREG32(R_008020_GRBM_SOFT_RESET
, 0);
1195 /* Reset CP (we always reset CP) */
1196 tmp
= S_008020_SOFT_RESET_CP(1);
1197 dev_info(rdev
->dev
, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp
);
1198 WREG32(R_008020_GRBM_SOFT_RESET
, tmp
);
1199 RREG32(R_008020_GRBM_SOFT_RESET
);
1201 WREG32(R_008020_GRBM_SOFT_RESET
, 0);
1202 /* Wait a little for things to settle down */
1204 dev_info(rdev
->dev
, " R_008010_GRBM_STATUS=0x%08X\n",
1205 RREG32(R_008010_GRBM_STATUS
));
1206 dev_info(rdev
->dev
, " R_008014_GRBM_STATUS2=0x%08X\n",
1207 RREG32(R_008014_GRBM_STATUS2
));
1208 dev_info(rdev
->dev
, " R_000E50_SRBM_STATUS=0x%08X\n",
1209 RREG32(R_000E50_SRBM_STATUS
));
1210 rv515_mc_resume(rdev
, &save
);
1214 bool r600_gpu_is_lockup(struct radeon_device
*rdev
)
1221 srbm_status
= RREG32(R_000E50_SRBM_STATUS
);
1222 grbm_status
= RREG32(R_008010_GRBM_STATUS
);
1223 grbm_status2
= RREG32(R_008014_GRBM_STATUS2
);
1224 if (!G_008010_GUI_ACTIVE(grbm_status
)) {
1225 r100_gpu_lockup_update(&rdev
->config
.r300
.lockup
, &rdev
->cp
);
1228 /* force CP activities */
1229 r
= radeon_ring_lock(rdev
, 2);
1232 radeon_ring_write(rdev
, 0x80000000);
1233 radeon_ring_write(rdev
, 0x80000000);
1234 radeon_ring_unlock_commit(rdev
);
1236 rdev
->cp
.rptr
= RREG32(R600_CP_RB_RPTR
);
1237 return r100_gpu_cp_is_lockup(rdev
, &rdev
->config
.r300
.lockup
, &rdev
->cp
);
1240 int r600_asic_reset(struct radeon_device
*rdev
)
1242 return r600_gpu_soft_reset(rdev
);
1245 static u32
r600_get_tile_pipe_to_backend_map(u32 num_tile_pipes
,
1247 u32 backend_disable_mask
)
1249 u32 backend_map
= 0;
1250 u32 enabled_backends_mask
;
1251 u32 enabled_backends_count
;
1253 u32 swizzle_pipe
[R6XX_MAX_PIPES
];
1257 if (num_tile_pipes
> R6XX_MAX_PIPES
)
1258 num_tile_pipes
= R6XX_MAX_PIPES
;
1259 if (num_tile_pipes
< 1)
1261 if (num_backends
> R6XX_MAX_BACKENDS
)
1262 num_backends
= R6XX_MAX_BACKENDS
;
1263 if (num_backends
< 1)
1266 enabled_backends_mask
= 0;
1267 enabled_backends_count
= 0;
1268 for (i
= 0; i
< R6XX_MAX_BACKENDS
; ++i
) {
1269 if (((backend_disable_mask
>> i
) & 1) == 0) {
1270 enabled_backends_mask
|= (1 << i
);
1271 ++enabled_backends_count
;
1273 if (enabled_backends_count
== num_backends
)
1277 if (enabled_backends_count
== 0) {
1278 enabled_backends_mask
= 1;
1279 enabled_backends_count
= 1;
1282 if (enabled_backends_count
!= num_backends
)
1283 num_backends
= enabled_backends_count
;
1285 memset((uint8_t *)&swizzle_pipe
[0], 0, sizeof(u32
) * R6XX_MAX_PIPES
);
1286 switch (num_tile_pipes
) {
1288 swizzle_pipe
[0] = 0;
1291 swizzle_pipe
[0] = 0;
1292 swizzle_pipe
[1] = 1;
1295 swizzle_pipe
[0] = 0;
1296 swizzle_pipe
[1] = 1;
1297 swizzle_pipe
[2] = 2;
1300 swizzle_pipe
[0] = 0;
1301 swizzle_pipe
[1] = 1;
1302 swizzle_pipe
[2] = 2;
1303 swizzle_pipe
[3] = 3;
1306 swizzle_pipe
[0] = 0;
1307 swizzle_pipe
[1] = 1;
1308 swizzle_pipe
[2] = 2;
1309 swizzle_pipe
[3] = 3;
1310 swizzle_pipe
[4] = 4;
1313 swizzle_pipe
[0] = 0;
1314 swizzle_pipe
[1] = 2;
1315 swizzle_pipe
[2] = 4;
1316 swizzle_pipe
[3] = 5;
1317 swizzle_pipe
[4] = 1;
1318 swizzle_pipe
[5] = 3;
1321 swizzle_pipe
[0] = 0;
1322 swizzle_pipe
[1] = 2;
1323 swizzle_pipe
[2] = 4;
1324 swizzle_pipe
[3] = 6;
1325 swizzle_pipe
[4] = 1;
1326 swizzle_pipe
[5] = 3;
1327 swizzle_pipe
[6] = 5;
1330 swizzle_pipe
[0] = 0;
1331 swizzle_pipe
[1] = 2;
1332 swizzle_pipe
[2] = 4;
1333 swizzle_pipe
[3] = 6;
1334 swizzle_pipe
[4] = 1;
1335 swizzle_pipe
[5] = 3;
1336 swizzle_pipe
[6] = 5;
1337 swizzle_pipe
[7] = 7;
1342 for (cur_pipe
= 0; cur_pipe
< num_tile_pipes
; ++cur_pipe
) {
1343 while (((1 << cur_backend
) & enabled_backends_mask
) == 0)
1344 cur_backend
= (cur_backend
+ 1) % R6XX_MAX_BACKENDS
;
1346 backend_map
|= (u32
)(((cur_backend
& 3) << (swizzle_pipe
[cur_pipe
] * 2)));
1348 cur_backend
= (cur_backend
+ 1) % R6XX_MAX_BACKENDS
;
1354 int r600_count_pipe_bits(uint32_t val
)
1358 for (i
= 0; i
< 32; i
++) {
1365 void r600_gpu_init(struct radeon_device
*rdev
)
1370 u32 cc_rb_backend_disable
;
1371 u32 cc_gc_shader_pipe_config
;
1375 u32 sq_gpr_resource_mgmt_1
= 0;
1376 u32 sq_gpr_resource_mgmt_2
= 0;
1377 u32 sq_thread_resource_mgmt
= 0;
1378 u32 sq_stack_resource_mgmt_1
= 0;
1379 u32 sq_stack_resource_mgmt_2
= 0;
1381 /* FIXME: implement */
1382 switch (rdev
->family
) {
1384 rdev
->config
.r600
.max_pipes
= 4;
1385 rdev
->config
.r600
.max_tile_pipes
= 8;
1386 rdev
->config
.r600
.max_simds
= 4;
1387 rdev
->config
.r600
.max_backends
= 4;
1388 rdev
->config
.r600
.max_gprs
= 256;
1389 rdev
->config
.r600
.max_threads
= 192;
1390 rdev
->config
.r600
.max_stack_entries
= 256;
1391 rdev
->config
.r600
.max_hw_contexts
= 8;
1392 rdev
->config
.r600
.max_gs_threads
= 16;
1393 rdev
->config
.r600
.sx_max_export_size
= 128;
1394 rdev
->config
.r600
.sx_max_export_pos_size
= 16;
1395 rdev
->config
.r600
.sx_max_export_smx_size
= 128;
1396 rdev
->config
.r600
.sq_num_cf_insts
= 2;
1400 rdev
->config
.r600
.max_pipes
= 2;
1401 rdev
->config
.r600
.max_tile_pipes
= 2;
1402 rdev
->config
.r600
.max_simds
= 3;
1403 rdev
->config
.r600
.max_backends
= 1;
1404 rdev
->config
.r600
.max_gprs
= 128;
1405 rdev
->config
.r600
.max_threads
= 192;
1406 rdev
->config
.r600
.max_stack_entries
= 128;
1407 rdev
->config
.r600
.max_hw_contexts
= 8;
1408 rdev
->config
.r600
.max_gs_threads
= 4;
1409 rdev
->config
.r600
.sx_max_export_size
= 128;
1410 rdev
->config
.r600
.sx_max_export_pos_size
= 16;
1411 rdev
->config
.r600
.sx_max_export_smx_size
= 128;
1412 rdev
->config
.r600
.sq_num_cf_insts
= 2;
1418 rdev
->config
.r600
.max_pipes
= 1;
1419 rdev
->config
.r600
.max_tile_pipes
= 1;
1420 rdev
->config
.r600
.max_simds
= 2;
1421 rdev
->config
.r600
.max_backends
= 1;
1422 rdev
->config
.r600
.max_gprs
= 128;
1423 rdev
->config
.r600
.max_threads
= 192;
1424 rdev
->config
.r600
.max_stack_entries
= 128;
1425 rdev
->config
.r600
.max_hw_contexts
= 4;
1426 rdev
->config
.r600
.max_gs_threads
= 4;
1427 rdev
->config
.r600
.sx_max_export_size
= 128;
1428 rdev
->config
.r600
.sx_max_export_pos_size
= 16;
1429 rdev
->config
.r600
.sx_max_export_smx_size
= 128;
1430 rdev
->config
.r600
.sq_num_cf_insts
= 1;
1433 rdev
->config
.r600
.max_pipes
= 4;
1434 rdev
->config
.r600
.max_tile_pipes
= 4;
1435 rdev
->config
.r600
.max_simds
= 4;
1436 rdev
->config
.r600
.max_backends
= 4;
1437 rdev
->config
.r600
.max_gprs
= 192;
1438 rdev
->config
.r600
.max_threads
= 192;
1439 rdev
->config
.r600
.max_stack_entries
= 256;
1440 rdev
->config
.r600
.max_hw_contexts
= 8;
1441 rdev
->config
.r600
.max_gs_threads
= 16;
1442 rdev
->config
.r600
.sx_max_export_size
= 128;
1443 rdev
->config
.r600
.sx_max_export_pos_size
= 16;
1444 rdev
->config
.r600
.sx_max_export_smx_size
= 128;
1445 rdev
->config
.r600
.sq_num_cf_insts
= 2;
1451 /* Initialize HDP */
1452 for (i
= 0, j
= 0; i
< 32; i
++, j
+= 0x18) {
1453 WREG32((0x2c14 + j
), 0x00000000);
1454 WREG32((0x2c18 + j
), 0x00000000);
1455 WREG32((0x2c1c + j
), 0x00000000);
1456 WREG32((0x2c20 + j
), 0x00000000);
1457 WREG32((0x2c24 + j
), 0x00000000);
1460 WREG32(GRBM_CNTL
, GRBM_READ_TIMEOUT(0xff));
1464 ramcfg
= RREG32(RAMCFG
);
1465 switch (rdev
->config
.r600
.max_tile_pipes
) {
1467 tiling_config
|= PIPE_TILING(0);
1470 tiling_config
|= PIPE_TILING(1);
1473 tiling_config
|= PIPE_TILING(2);
1476 tiling_config
|= PIPE_TILING(3);
1481 rdev
->config
.r600
.tiling_npipes
= rdev
->config
.r600
.max_tile_pipes
;
1482 rdev
->config
.r600
.tiling_nbanks
= 4 << ((ramcfg
& NOOFBANK_MASK
) >> NOOFBANK_SHIFT
);
1483 tiling_config
|= BANK_TILING((ramcfg
& NOOFBANK_MASK
) >> NOOFBANK_SHIFT
);
1484 tiling_config
|= GROUP_SIZE(0);
1485 rdev
->config
.r600
.tiling_group_size
= 256;
1486 tmp
= (ramcfg
& NOOFROWS_MASK
) >> NOOFROWS_SHIFT
;
1488 tiling_config
|= ROW_TILING(3);
1489 tiling_config
|= SAMPLE_SPLIT(3);
1491 tiling_config
|= ROW_TILING(tmp
);
1492 tiling_config
|= SAMPLE_SPLIT(tmp
);
1494 tiling_config
|= BANK_SWAPS(1);
1496 cc_rb_backend_disable
= RREG32(CC_RB_BACKEND_DISABLE
) & 0x00ff0000;
1497 cc_rb_backend_disable
|=
1498 BACKEND_DISABLE((R6XX_MAX_BACKENDS_MASK
<< rdev
->config
.r600
.max_backends
) & R6XX_MAX_BACKENDS_MASK
);
1500 cc_gc_shader_pipe_config
= RREG32(CC_GC_SHADER_PIPE_CONFIG
) & 0xffffff00;
1501 cc_gc_shader_pipe_config
|=
1502 INACTIVE_QD_PIPES((R6XX_MAX_PIPES_MASK
<< rdev
->config
.r600
.max_pipes
) & R6XX_MAX_PIPES_MASK
);
1503 cc_gc_shader_pipe_config
|=
1504 INACTIVE_SIMDS((R6XX_MAX_SIMDS_MASK
<< rdev
->config
.r600
.max_simds
) & R6XX_MAX_SIMDS_MASK
);
1506 backend_map
= r600_get_tile_pipe_to_backend_map(rdev
->config
.r600
.max_tile_pipes
,
1507 (R6XX_MAX_BACKENDS
-
1508 r600_count_pipe_bits((cc_rb_backend_disable
&
1509 R6XX_MAX_BACKENDS_MASK
) >> 16)),
1510 (cc_rb_backend_disable
>> 16));
1512 tiling_config
|= BACKEND_MAP(backend_map
);
1513 WREG32(GB_TILING_CONFIG
, tiling_config
);
1514 WREG32(DCP_TILING_CONFIG
, tiling_config
& 0xffff);
1515 WREG32(HDP_TILING_CONFIG
, tiling_config
& 0xffff);
1518 WREG32(CC_RB_BACKEND_DISABLE
, cc_rb_backend_disable
);
1519 WREG32(CC_GC_SHADER_PIPE_CONFIG
, cc_gc_shader_pipe_config
);
1520 WREG32(GC_USER_SHADER_PIPE_CONFIG
, cc_gc_shader_pipe_config
);
1522 tmp
= R6XX_MAX_PIPES
- r600_count_pipe_bits((cc_gc_shader_pipe_config
& INACTIVE_QD_PIPES_MASK
) >> 8);
1523 WREG32(VGT_OUT_DEALLOC_CNTL
, (tmp
* 4) & DEALLOC_DIST_MASK
);
1524 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL
, ((tmp
* 4) - 2) & VTX_REUSE_DEPTH_MASK
);
1526 /* Setup some CP states */
1527 WREG32(CP_QUEUE_THRESHOLDS
, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
1528 WREG32(CP_MEQ_THRESHOLDS
, (MEQ_END(0x40) | ROQ_END(0x40)));
1530 WREG32(TA_CNTL_AUX
, (DISABLE_CUBE_ANISO
| SYNC_GRADIENT
|
1531 SYNC_WALKER
| SYNC_ALIGNER
));
1532 /* Setup various GPU states */
1533 if (rdev
->family
== CHIP_RV670
)
1534 WREG32(ARB_GDEC_RD_CNTL
, 0x00000021);
1536 tmp
= RREG32(SX_DEBUG_1
);
1537 tmp
|= SMX_EVENT_RELEASE
;
1538 if ((rdev
->family
> CHIP_R600
))
1539 tmp
|= ENABLE_NEW_SMX_ADDRESS
;
1540 WREG32(SX_DEBUG_1
, tmp
);
1542 if (((rdev
->family
) == CHIP_R600
) ||
1543 ((rdev
->family
) == CHIP_RV630
) ||
1544 ((rdev
->family
) == CHIP_RV610
) ||
1545 ((rdev
->family
) == CHIP_RV620
) ||
1546 ((rdev
->family
) == CHIP_RS780
) ||
1547 ((rdev
->family
) == CHIP_RS880
)) {
1548 WREG32(DB_DEBUG
, PREZ_MUST_WAIT_FOR_POSTZ_DONE
);
1550 WREG32(DB_DEBUG
, 0);
1552 WREG32(DB_WATERMARKS
, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
1553 DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
1555 WREG32(PA_SC_MULTI_CHIP_CNTL
, 0);
1556 WREG32(VGT_NUM_INSTANCES
, 0);
1558 WREG32(SPI_CONFIG_CNTL
, GPR_WRITE_PRIORITY(0));
1559 WREG32(SPI_CONFIG_CNTL_1
, VTX_DONE_DELAY(0));
1561 tmp
= RREG32(SQ_MS_FIFO_SIZES
);
1562 if (((rdev
->family
) == CHIP_RV610
) ||
1563 ((rdev
->family
) == CHIP_RV620
) ||
1564 ((rdev
->family
) == CHIP_RS780
) ||
1565 ((rdev
->family
) == CHIP_RS880
)) {
1566 tmp
= (CACHE_FIFO_SIZE(0xa) |
1567 FETCH_FIFO_HIWATER(0xa) |
1568 DONE_FIFO_HIWATER(0xe0) |
1569 ALU_UPDATE_FIFO_HIWATER(0x8));
1570 } else if (((rdev
->family
) == CHIP_R600
) ||
1571 ((rdev
->family
) == CHIP_RV630
)) {
1572 tmp
&= ~DONE_FIFO_HIWATER(0xff);
1573 tmp
|= DONE_FIFO_HIWATER(0x4);
1575 WREG32(SQ_MS_FIFO_SIZES
, tmp
);
1577 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
1578 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
1580 sq_config
= RREG32(SQ_CONFIG
);
1581 sq_config
&= ~(PS_PRIO(3) |
1585 sq_config
|= (DX9_CONSTS
|
1592 if ((rdev
->family
) == CHIP_R600
) {
1593 sq_gpr_resource_mgmt_1
= (NUM_PS_GPRS(124) |
1595 NUM_CLAUSE_TEMP_GPRS(4));
1596 sq_gpr_resource_mgmt_2
= (NUM_GS_GPRS(0) |
1598 sq_thread_resource_mgmt
= (NUM_PS_THREADS(136) |
1599 NUM_VS_THREADS(48) |
1602 sq_stack_resource_mgmt_1
= (NUM_PS_STACK_ENTRIES(128) |
1603 NUM_VS_STACK_ENTRIES(128));
1604 sq_stack_resource_mgmt_2
= (NUM_GS_STACK_ENTRIES(0) |
1605 NUM_ES_STACK_ENTRIES(0));
1606 } else if (((rdev
->family
) == CHIP_RV610
) ||
1607 ((rdev
->family
) == CHIP_RV620
) ||
1608 ((rdev
->family
) == CHIP_RS780
) ||
1609 ((rdev
->family
) == CHIP_RS880
)) {
1610 /* no vertex cache */
1611 sq_config
&= ~VC_ENABLE
;
1613 sq_gpr_resource_mgmt_1
= (NUM_PS_GPRS(44) |
1615 NUM_CLAUSE_TEMP_GPRS(2));
1616 sq_gpr_resource_mgmt_2
= (NUM_GS_GPRS(17) |
1618 sq_thread_resource_mgmt
= (NUM_PS_THREADS(79) |
1619 NUM_VS_THREADS(78) |
1621 NUM_ES_THREADS(31));
1622 sq_stack_resource_mgmt_1
= (NUM_PS_STACK_ENTRIES(40) |
1623 NUM_VS_STACK_ENTRIES(40));
1624 sq_stack_resource_mgmt_2
= (NUM_GS_STACK_ENTRIES(32) |
1625 NUM_ES_STACK_ENTRIES(16));
1626 } else if (((rdev
->family
) == CHIP_RV630
) ||
1627 ((rdev
->family
) == CHIP_RV635
)) {
1628 sq_gpr_resource_mgmt_1
= (NUM_PS_GPRS(44) |
1630 NUM_CLAUSE_TEMP_GPRS(2));
1631 sq_gpr_resource_mgmt_2
= (NUM_GS_GPRS(18) |
1633 sq_thread_resource_mgmt
= (NUM_PS_THREADS(79) |
1634 NUM_VS_THREADS(78) |
1636 NUM_ES_THREADS(31));
1637 sq_stack_resource_mgmt_1
= (NUM_PS_STACK_ENTRIES(40) |
1638 NUM_VS_STACK_ENTRIES(40));
1639 sq_stack_resource_mgmt_2
= (NUM_GS_STACK_ENTRIES(32) |
1640 NUM_ES_STACK_ENTRIES(16));
1641 } else if ((rdev
->family
) == CHIP_RV670
) {
1642 sq_gpr_resource_mgmt_1
= (NUM_PS_GPRS(44) |
1644 NUM_CLAUSE_TEMP_GPRS(2));
1645 sq_gpr_resource_mgmt_2
= (NUM_GS_GPRS(17) |
1647 sq_thread_resource_mgmt
= (NUM_PS_THREADS(79) |
1648 NUM_VS_THREADS(78) |
1650 NUM_ES_THREADS(31));
1651 sq_stack_resource_mgmt_1
= (NUM_PS_STACK_ENTRIES(64) |
1652 NUM_VS_STACK_ENTRIES(64));
1653 sq_stack_resource_mgmt_2
= (NUM_GS_STACK_ENTRIES(64) |
1654 NUM_ES_STACK_ENTRIES(64));
1657 WREG32(SQ_CONFIG
, sq_config
);
1658 WREG32(SQ_GPR_RESOURCE_MGMT_1
, sq_gpr_resource_mgmt_1
);
1659 WREG32(SQ_GPR_RESOURCE_MGMT_2
, sq_gpr_resource_mgmt_2
);
1660 WREG32(SQ_THREAD_RESOURCE_MGMT
, sq_thread_resource_mgmt
);
1661 WREG32(SQ_STACK_RESOURCE_MGMT_1
, sq_stack_resource_mgmt_1
);
1662 WREG32(SQ_STACK_RESOURCE_MGMT_2
, sq_stack_resource_mgmt_2
);
1664 if (((rdev
->family
) == CHIP_RV610
) ||
1665 ((rdev
->family
) == CHIP_RV620
) ||
1666 ((rdev
->family
) == CHIP_RS780
) ||
1667 ((rdev
->family
) == CHIP_RS880
)) {
1668 WREG32(VGT_CACHE_INVALIDATION
, CACHE_INVALIDATION(TC_ONLY
));
1670 WREG32(VGT_CACHE_INVALIDATION
, CACHE_INVALIDATION(VC_AND_TC
));
1673 /* More default values. 2D/3D driver should adjust as needed */
1674 WREG32(PA_SC_AA_SAMPLE_LOCS_2S
, (S0_X(0xc) | S0_Y(0x4) |
1675 S1_X(0x4) | S1_Y(0xc)));
1676 WREG32(PA_SC_AA_SAMPLE_LOCS_4S
, (S0_X(0xe) | S0_Y(0xe) |
1677 S1_X(0x2) | S1_Y(0x2) |
1678 S2_X(0xa) | S2_Y(0x6) |
1679 S3_X(0x6) | S3_Y(0xa)));
1680 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0
, (S0_X(0xe) | S0_Y(0xb) |
1681 S1_X(0x4) | S1_Y(0xc) |
1682 S2_X(0x1) | S2_Y(0x6) |
1683 S3_X(0xa) | S3_Y(0xe)));
1684 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1
, (S4_X(0x6) | S4_Y(0x1) |
1685 S5_X(0x0) | S5_Y(0x0) |
1686 S6_X(0xb) | S6_Y(0x4) |
1687 S7_X(0x7) | S7_Y(0x8)));
1689 WREG32(VGT_STRMOUT_EN
, 0);
1690 tmp
= rdev
->config
.r600
.max_pipes
* 16;
1691 switch (rdev
->family
) {
1707 WREG32(VGT_ES_PER_GS
, 128);
1708 WREG32(VGT_GS_PER_ES
, tmp
);
1709 WREG32(VGT_GS_PER_VS
, 2);
1710 WREG32(VGT_GS_VERTEX_REUSE
, 16);
1712 /* more default values. 2D/3D driver should adjust as needed */
1713 WREG32(PA_SC_LINE_STIPPLE_STATE
, 0);
1714 WREG32(VGT_STRMOUT_EN
, 0);
1716 WREG32(PA_SC_MODE_CNTL
, 0);
1717 WREG32(PA_SC_AA_CONFIG
, 0);
1718 WREG32(PA_SC_LINE_STIPPLE
, 0);
1719 WREG32(SPI_INPUT_Z
, 0);
1720 WREG32(SPI_PS_IN_CONTROL_0
, NUM_INTERP(2));
1721 WREG32(CB_COLOR7_FRAG
, 0);
1723 /* Clear render buffer base addresses */
1724 WREG32(CB_COLOR0_BASE
, 0);
1725 WREG32(CB_COLOR1_BASE
, 0);
1726 WREG32(CB_COLOR2_BASE
, 0);
1727 WREG32(CB_COLOR3_BASE
, 0);
1728 WREG32(CB_COLOR4_BASE
, 0);
1729 WREG32(CB_COLOR5_BASE
, 0);
1730 WREG32(CB_COLOR6_BASE
, 0);
1731 WREG32(CB_COLOR7_BASE
, 0);
1732 WREG32(CB_COLOR7_FRAG
, 0);
1734 switch (rdev
->family
) {
1739 tmp
= TC_L2_SIZE(8);
1743 tmp
= TC_L2_SIZE(4);
1746 tmp
= TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT
;
1749 tmp
= TC_L2_SIZE(0);
1752 WREG32(TC_CNTL
, tmp
);
1754 tmp
= RREG32(HDP_HOST_PATH_CNTL
);
1755 WREG32(HDP_HOST_PATH_CNTL
, tmp
);
1757 tmp
= RREG32(ARB_POP
);
1758 tmp
|= ENABLE_TC128
;
1759 WREG32(ARB_POP
, tmp
);
1761 WREG32(PA_SC_MULTI_CHIP_CNTL
, 0);
1762 WREG32(PA_CL_ENHANCE
, (CLIP_VTX_REORDER_ENA
|
1764 WREG32(PA_SC_ENHANCE
, FORCE_EOV_MAX_CLK_CNT(4095));
1769 * Indirect registers accessor
1771 u32
r600_pciep_rreg(struct radeon_device
*rdev
, u32 reg
)
1775 WREG32(PCIE_PORT_INDEX
, ((reg
) & 0xff));
1776 (void)RREG32(PCIE_PORT_INDEX
);
1777 r
= RREG32(PCIE_PORT_DATA
);
1781 void r600_pciep_wreg(struct radeon_device
*rdev
, u32 reg
, u32 v
)
1783 WREG32(PCIE_PORT_INDEX
, ((reg
) & 0xff));
1784 (void)RREG32(PCIE_PORT_INDEX
);
1785 WREG32(PCIE_PORT_DATA
, (v
));
1786 (void)RREG32(PCIE_PORT_DATA
);
1792 void r600_cp_stop(struct radeon_device
*rdev
)
1794 WREG32(R_0086D8_CP_ME_CNTL
, S_0086D8_CP_ME_HALT(1));
1797 int r600_init_microcode(struct radeon_device
*rdev
)
1799 struct platform_device
*pdev
;
1800 const char *chip_name
;
1801 const char *rlc_chip_name
;
1802 size_t pfp_req_size
, me_req_size
, rlc_req_size
;
1808 pdev
= platform_device_register_simple("radeon_cp", 0, NULL
, 0);
1811 printk(KERN_ERR
"radeon_cp: Failed to register firmware\n");
1815 switch (rdev
->family
) {
1818 rlc_chip_name
= "R600";
1821 chip_name
= "RV610";
1822 rlc_chip_name
= "R600";
1825 chip_name
= "RV630";
1826 rlc_chip_name
= "R600";
1829 chip_name
= "RV620";
1830 rlc_chip_name
= "R600";
1833 chip_name
= "RV635";
1834 rlc_chip_name
= "R600";
1837 chip_name
= "RV670";
1838 rlc_chip_name
= "R600";
1842 chip_name
= "RS780";
1843 rlc_chip_name
= "R600";
1846 chip_name
= "RV770";
1847 rlc_chip_name
= "R700";
1851 chip_name
= "RV730";
1852 rlc_chip_name
= "R700";
1855 chip_name
= "RV710";
1856 rlc_chip_name
= "R700";
1859 chip_name
= "CEDAR";
1860 rlc_chip_name
= "CEDAR";
1863 chip_name
= "REDWOOD";
1864 rlc_chip_name
= "REDWOOD";
1867 chip_name
= "JUNIPER";
1868 rlc_chip_name
= "JUNIPER";
1872 chip_name
= "CYPRESS";
1873 rlc_chip_name
= "CYPRESS";
1878 if (rdev
->family
>= CHIP_CEDAR
) {
1879 pfp_req_size
= EVERGREEN_PFP_UCODE_SIZE
* 4;
1880 me_req_size
= EVERGREEN_PM4_UCODE_SIZE
* 4;
1881 rlc_req_size
= EVERGREEN_RLC_UCODE_SIZE
* 4;
1882 } else if (rdev
->family
>= CHIP_RV770
) {
1883 pfp_req_size
= R700_PFP_UCODE_SIZE
* 4;
1884 me_req_size
= R700_PM4_UCODE_SIZE
* 4;
1885 rlc_req_size
= R700_RLC_UCODE_SIZE
* 4;
1887 pfp_req_size
= PFP_UCODE_SIZE
* 4;
1888 me_req_size
= PM4_UCODE_SIZE
* 12;
1889 rlc_req_size
= RLC_UCODE_SIZE
* 4;
1892 DRM_INFO("Loading %s Microcode\n", chip_name
);
1894 snprintf(fw_name
, sizeof(fw_name
), "radeon/%s_pfp.bin", chip_name
);
1895 err
= request_firmware(&rdev
->pfp_fw
, fw_name
, &pdev
->dev
);
1898 if (rdev
->pfp_fw
->size
!= pfp_req_size
) {
1900 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
1901 rdev
->pfp_fw
->size
, fw_name
);
1906 snprintf(fw_name
, sizeof(fw_name
), "radeon/%s_me.bin", chip_name
);
1907 err
= request_firmware(&rdev
->me_fw
, fw_name
, &pdev
->dev
);
1910 if (rdev
->me_fw
->size
!= me_req_size
) {
1912 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
1913 rdev
->me_fw
->size
, fw_name
);
1917 snprintf(fw_name
, sizeof(fw_name
), "radeon/%s_rlc.bin", rlc_chip_name
);
1918 err
= request_firmware(&rdev
->rlc_fw
, fw_name
, &pdev
->dev
);
1921 if (rdev
->rlc_fw
->size
!= rlc_req_size
) {
1923 "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
1924 rdev
->rlc_fw
->size
, fw_name
);
1929 platform_device_unregister(pdev
);
1934 "r600_cp: Failed to load firmware \"%s\"\n",
1936 release_firmware(rdev
->pfp_fw
);
1937 rdev
->pfp_fw
= NULL
;
1938 release_firmware(rdev
->me_fw
);
1940 release_firmware(rdev
->rlc_fw
);
1941 rdev
->rlc_fw
= NULL
;
1946 static int r600_cp_load_microcode(struct radeon_device
*rdev
)
1948 const __be32
*fw_data
;
1951 if (!rdev
->me_fw
|| !rdev
->pfp_fw
)
1956 WREG32(CP_RB_CNTL
, RB_NO_UPDATE
| RB_BLKSZ(15) | RB_BUFSZ(3));
1959 WREG32(GRBM_SOFT_RESET
, SOFT_RESET_CP
);
1960 RREG32(GRBM_SOFT_RESET
);
1962 WREG32(GRBM_SOFT_RESET
, 0);
1964 WREG32(CP_ME_RAM_WADDR
, 0);
1966 fw_data
= (const __be32
*)rdev
->me_fw
->data
;
1967 WREG32(CP_ME_RAM_WADDR
, 0);
1968 for (i
= 0; i
< PM4_UCODE_SIZE
* 3; i
++)
1969 WREG32(CP_ME_RAM_DATA
,
1970 be32_to_cpup(fw_data
++));
1972 fw_data
= (const __be32
*)rdev
->pfp_fw
->data
;
1973 WREG32(CP_PFP_UCODE_ADDR
, 0);
1974 for (i
= 0; i
< PFP_UCODE_SIZE
; i
++)
1975 WREG32(CP_PFP_UCODE_DATA
,
1976 be32_to_cpup(fw_data
++));
1978 WREG32(CP_PFP_UCODE_ADDR
, 0);
1979 WREG32(CP_ME_RAM_WADDR
, 0);
1980 WREG32(CP_ME_RAM_RADDR
, 0);
1984 int r600_cp_start(struct radeon_device
*rdev
)
1989 r
= radeon_ring_lock(rdev
, 7);
1991 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r
);
1994 radeon_ring_write(rdev
, PACKET3(PACKET3_ME_INITIALIZE
, 5));
1995 radeon_ring_write(rdev
, 0x1);
1996 if (rdev
->family
>= CHIP_CEDAR
) {
1997 radeon_ring_write(rdev
, 0x0);
1998 radeon_ring_write(rdev
, rdev
->config
.evergreen
.max_hw_contexts
- 1);
1999 } else if (rdev
->family
>= CHIP_RV770
) {
2000 radeon_ring_write(rdev
, 0x0);
2001 radeon_ring_write(rdev
, rdev
->config
.rv770
.max_hw_contexts
- 1);
2003 radeon_ring_write(rdev
, 0x3);
2004 radeon_ring_write(rdev
, rdev
->config
.r600
.max_hw_contexts
- 1);
2006 radeon_ring_write(rdev
, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
2007 radeon_ring_write(rdev
, 0);
2008 radeon_ring_write(rdev
, 0);
2009 radeon_ring_unlock_commit(rdev
);
2012 WREG32(R_0086D8_CP_ME_CNTL
, cp_me
);
2016 int r600_cp_resume(struct radeon_device
*rdev
)
2023 WREG32(GRBM_SOFT_RESET
, SOFT_RESET_CP
);
2024 RREG32(GRBM_SOFT_RESET
);
2026 WREG32(GRBM_SOFT_RESET
, 0);
2028 /* Set ring buffer size */
2029 rb_bufsz
= drm_order(rdev
->cp
.ring_size
/ 8);
2030 tmp
= RB_NO_UPDATE
| (drm_order(RADEON_GPU_PAGE_SIZE
/8) << 8) | rb_bufsz
;
2032 tmp
|= BUF_SWAP_32BIT
;
2034 WREG32(CP_RB_CNTL
, tmp
);
2035 WREG32(CP_SEM_WAIT_TIMER
, 0x4);
2037 /* Set the write pointer delay */
2038 WREG32(CP_RB_WPTR_DELAY
, 0);
2040 /* Initialize the ring buffer's read and write pointers */
2041 WREG32(CP_RB_CNTL
, tmp
| RB_RPTR_WR_ENA
);
2042 WREG32(CP_RB_RPTR_WR
, 0);
2043 WREG32(CP_RB_WPTR
, 0);
2044 WREG32(CP_RB_RPTR_ADDR
, rdev
->cp
.gpu_addr
& 0xFFFFFFFF);
2045 WREG32(CP_RB_RPTR_ADDR_HI
, upper_32_bits(rdev
->cp
.gpu_addr
));
2047 WREG32(CP_RB_CNTL
, tmp
);
2049 WREG32(CP_RB_BASE
, rdev
->cp
.gpu_addr
>> 8);
2050 WREG32(CP_DEBUG
, (1 << 27) | (1 << 28));
2052 rdev
->cp
.rptr
= RREG32(CP_RB_RPTR
);
2053 rdev
->cp
.wptr
= RREG32(CP_RB_WPTR
);
2055 r600_cp_start(rdev
);
2056 rdev
->cp
.ready
= true;
2057 r
= radeon_ring_test(rdev
);
2059 rdev
->cp
.ready
= false;
2065 void r600_cp_commit(struct radeon_device
*rdev
)
2067 WREG32(CP_RB_WPTR
, rdev
->cp
.wptr
);
2068 (void)RREG32(CP_RB_WPTR
);
2071 void r600_ring_init(struct radeon_device
*rdev
, unsigned ring_size
)
2075 /* Align ring size */
2076 rb_bufsz
= drm_order(ring_size
/ 8);
2077 ring_size
= (1 << (rb_bufsz
+ 1)) * 4;
2078 rdev
->cp
.ring_size
= ring_size
;
2079 rdev
->cp
.align_mask
= 16 - 1;
2082 void r600_cp_fini(struct radeon_device
*rdev
)
2085 radeon_ring_fini(rdev
);
2090 * GPU scratch registers helpers function.
2092 void r600_scratch_init(struct radeon_device
*rdev
)
2096 rdev
->scratch
.num_reg
= 7;
2097 for (i
= 0; i
< rdev
->scratch
.num_reg
; i
++) {
2098 rdev
->scratch
.free
[i
] = true;
2099 rdev
->scratch
.reg
[i
] = SCRATCH_REG0
+ (i
* 4);
2103 int r600_ring_test(struct radeon_device
*rdev
)
2110 r
= radeon_scratch_get(rdev
, &scratch
);
2112 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r
);
2115 WREG32(scratch
, 0xCAFEDEAD);
2116 r
= radeon_ring_lock(rdev
, 3);
2118 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r
);
2119 radeon_scratch_free(rdev
, scratch
);
2122 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONFIG_REG
, 1));
2123 radeon_ring_write(rdev
, ((scratch
- PACKET3_SET_CONFIG_REG_OFFSET
) >> 2));
2124 radeon_ring_write(rdev
, 0xDEADBEEF);
2125 radeon_ring_unlock_commit(rdev
);
2126 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
2127 tmp
= RREG32(scratch
);
2128 if (tmp
== 0xDEADBEEF)
2132 if (i
< rdev
->usec_timeout
) {
2133 DRM_INFO("ring test succeeded in %d usecs\n", i
);
2135 DRM_ERROR("radeon: ring test failed (scratch(0x%04X)=0x%08X)\n",
2139 radeon_scratch_free(rdev
, scratch
);
2143 void r600_wb_disable(struct radeon_device
*rdev
)
2147 WREG32(SCRATCH_UMSK
, 0);
2148 if (rdev
->wb
.wb_obj
) {
2149 r
= radeon_bo_reserve(rdev
->wb
.wb_obj
, false);
2150 if (unlikely(r
!= 0))
2152 radeon_bo_kunmap(rdev
->wb
.wb_obj
);
2153 radeon_bo_unpin(rdev
->wb
.wb_obj
);
2154 radeon_bo_unreserve(rdev
->wb
.wb_obj
);
2158 void r600_wb_fini(struct radeon_device
*rdev
)
2160 r600_wb_disable(rdev
);
2161 if (rdev
->wb
.wb_obj
) {
2162 radeon_bo_unref(&rdev
->wb
.wb_obj
);
2164 rdev
->wb
.wb_obj
= NULL
;
2168 int r600_wb_enable(struct radeon_device
*rdev
)
2172 if (rdev
->wb
.wb_obj
== NULL
) {
2173 r
= radeon_bo_create(rdev
, NULL
, RADEON_GPU_PAGE_SIZE
, true,
2174 RADEON_GEM_DOMAIN_GTT
, &rdev
->wb
.wb_obj
);
2176 dev_warn(rdev
->dev
, "(%d) create WB bo failed\n", r
);
2179 r
= radeon_bo_reserve(rdev
->wb
.wb_obj
, false);
2180 if (unlikely(r
!= 0)) {
2184 r
= radeon_bo_pin(rdev
->wb
.wb_obj
, RADEON_GEM_DOMAIN_GTT
,
2185 &rdev
->wb
.gpu_addr
);
2187 radeon_bo_unreserve(rdev
->wb
.wb_obj
);
2188 dev_warn(rdev
->dev
, "(%d) pin WB bo failed\n", r
);
2192 r
= radeon_bo_kmap(rdev
->wb
.wb_obj
, (void **)&rdev
->wb
.wb
);
2193 radeon_bo_unreserve(rdev
->wb
.wb_obj
);
2195 dev_warn(rdev
->dev
, "(%d) map WB bo failed\n", r
);
2200 WREG32(SCRATCH_ADDR
, (rdev
->wb
.gpu_addr
>> 8) & 0xFFFFFFFF);
2201 WREG32(CP_RB_RPTR_ADDR
, (rdev
->wb
.gpu_addr
+ 1024) & 0xFFFFFFFC);
2202 WREG32(CP_RB_RPTR_ADDR_HI
, upper_32_bits(rdev
->wb
.gpu_addr
+ 1024) & 0xFF);
2203 WREG32(SCRATCH_UMSK
, 0xff);
2207 void r600_fence_ring_emit(struct radeon_device
*rdev
,
2208 struct radeon_fence
*fence
)
2210 /* Also consider EVENT_WRITE_EOP. it handles the interrupts + timestamps + events */
2212 radeon_ring_write(rdev
, PACKET3(PACKET3_EVENT_WRITE
, 0));
2213 radeon_ring_write(rdev
, CACHE_FLUSH_AND_INV_EVENT
);
2214 /* wait for 3D idle clean */
2215 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONFIG_REG
, 1));
2216 radeon_ring_write(rdev
, (WAIT_UNTIL
- PACKET3_SET_CONFIG_REG_OFFSET
) >> 2);
2217 radeon_ring_write(rdev
, WAIT_3D_IDLE_bit
| WAIT_3D_IDLECLEAN_bit
);
2218 /* Emit fence sequence & fire IRQ */
2219 radeon_ring_write(rdev
, PACKET3(PACKET3_SET_CONFIG_REG
, 1));
2220 radeon_ring_write(rdev
, ((rdev
->fence_drv
.scratch_reg
- PACKET3_SET_CONFIG_REG_OFFSET
) >> 2));
2221 radeon_ring_write(rdev
, fence
->seq
);
2222 /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
2223 radeon_ring_write(rdev
, PACKET0(CP_INT_STATUS
, 0));
2224 radeon_ring_write(rdev
, RB_INT_STAT
);
2227 int r600_copy_blit(struct radeon_device
*rdev
,
2228 uint64_t src_offset
, uint64_t dst_offset
,
2229 unsigned num_pages
, struct radeon_fence
*fence
)
2233 mutex_lock(&rdev
->r600_blit
.mutex
);
2234 rdev
->r600_blit
.vb_ib
= NULL
;
2235 r
= r600_blit_prepare_copy(rdev
, num_pages
* RADEON_GPU_PAGE_SIZE
);
2237 if (rdev
->r600_blit
.vb_ib
)
2238 radeon_ib_free(rdev
, &rdev
->r600_blit
.vb_ib
);
2239 mutex_unlock(&rdev
->r600_blit
.mutex
);
2242 r600_kms_blit_copy(rdev
, src_offset
, dst_offset
, num_pages
* RADEON_GPU_PAGE_SIZE
);
2243 r600_blit_done_copy(rdev
, fence
);
2244 mutex_unlock(&rdev
->r600_blit
.mutex
);
2248 int r600_set_surface_reg(struct radeon_device
*rdev
, int reg
,
2249 uint32_t tiling_flags
, uint32_t pitch
,
2250 uint32_t offset
, uint32_t obj_size
)
2252 /* FIXME: implement */
2256 void r600_clear_surface_reg(struct radeon_device
*rdev
, int reg
)
2258 /* FIXME: implement */
2262 bool r600_card_posted(struct radeon_device
*rdev
)
2266 /* first check CRTCs */
2267 reg
= RREG32(D1CRTC_CONTROL
) |
2268 RREG32(D2CRTC_CONTROL
);
2272 /* then check MEM_SIZE, in case the crtcs are off */
2273 if (RREG32(CONFIG_MEMSIZE
))
2279 int r600_startup(struct radeon_device
*rdev
)
2283 if (!rdev
->me_fw
|| !rdev
->pfp_fw
|| !rdev
->rlc_fw
) {
2284 r
= r600_init_microcode(rdev
);
2286 DRM_ERROR("Failed to load firmware!\n");
2291 r600_mc_program(rdev
);
2292 if (rdev
->flags
& RADEON_IS_AGP
) {
2293 r600_agp_enable(rdev
);
2295 r
= r600_pcie_gart_enable(rdev
);
2299 r600_gpu_init(rdev
);
2300 r
= r600_blit_init(rdev
);
2302 r600_blit_fini(rdev
);
2303 rdev
->asic
->copy
= NULL
;
2304 dev_warn(rdev
->dev
, "failed blitter (%d) falling back to memcpy\n", r
);
2306 /* pin copy shader into vram */
2307 if (rdev
->r600_blit
.shader_obj
) {
2308 r
= radeon_bo_reserve(rdev
->r600_blit
.shader_obj
, false);
2309 if (unlikely(r
!= 0))
2311 r
= radeon_bo_pin(rdev
->r600_blit
.shader_obj
, RADEON_GEM_DOMAIN_VRAM
,
2312 &rdev
->r600_blit
.shader_gpu_addr
);
2313 radeon_bo_unreserve(rdev
->r600_blit
.shader_obj
);
2315 dev_err(rdev
->dev
, "(%d) pin blit object failed\n", r
);
2320 r
= r600_irq_init(rdev
);
2322 DRM_ERROR("radeon: IH init failed (%d).\n", r
);
2323 radeon_irq_kms_fini(rdev
);
2328 r
= radeon_ring_init(rdev
, rdev
->cp
.ring_size
);
2331 r
= r600_cp_load_microcode(rdev
);
2334 r
= r600_cp_resume(rdev
);
2337 /* write back buffer are not vital so don't worry about failure */
2338 r600_wb_enable(rdev
);
2342 void r600_vga_set_state(struct radeon_device
*rdev
, bool state
)
2346 temp
= RREG32(CONFIG_CNTL
);
2347 if (state
== false) {
2353 WREG32(CONFIG_CNTL
, temp
);
2356 int r600_resume(struct radeon_device
*rdev
)
2360 /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
2361 * posting will perform necessary task to bring back GPU into good
2365 atom_asic_init(rdev
->mode_info
.atom_context
);
2366 /* Initialize clocks */
2367 r
= radeon_clocks_init(rdev
);
2372 r
= r600_startup(rdev
);
2374 DRM_ERROR("r600 startup failed on resume\n");
2378 r
= r600_ib_test(rdev
);
2380 DRM_ERROR("radeon: failled testing IB (%d).\n", r
);
2384 r
= r600_audio_init(rdev
);
2386 DRM_ERROR("radeon: audio resume failed\n");
2393 int r600_suspend(struct radeon_device
*rdev
)
2397 r600_audio_fini(rdev
);
2398 /* FIXME: we should wait for ring to be empty */
2400 rdev
->cp
.ready
= false;
2401 r600_irq_suspend(rdev
);
2402 r600_wb_disable(rdev
);
2403 r600_pcie_gart_disable(rdev
);
2404 /* unpin shaders bo */
2405 if (rdev
->r600_blit
.shader_obj
) {
2406 r
= radeon_bo_reserve(rdev
->r600_blit
.shader_obj
, false);
2408 radeon_bo_unpin(rdev
->r600_blit
.shader_obj
);
2409 radeon_bo_unreserve(rdev
->r600_blit
.shader_obj
);
2415 /* Plan is to move initialization in that function and use
2416 * helper function so that radeon_device_init pretty much
2417 * do nothing more than calling asic specific function. This
2418 * should also allow to remove a bunch of callback function
2421 int r600_init(struct radeon_device
*rdev
)
2425 r
= radeon_dummy_page_init(rdev
);
2428 if (r600_debugfs_mc_info_init(rdev
)) {
2429 DRM_ERROR("Failed to register debugfs file for mc !\n");
2431 /* This don't do much */
2432 r
= radeon_gem_init(rdev
);
2436 if (!radeon_get_bios(rdev
)) {
2437 if (ASIC_IS_AVIVO(rdev
))
2440 /* Must be an ATOMBIOS */
2441 if (!rdev
->is_atom_bios
) {
2442 dev_err(rdev
->dev
, "Expecting atombios for R600 GPU\n");
2445 r
= radeon_atombios_init(rdev
);
2448 /* Post card if necessary */
2449 if (!r600_card_posted(rdev
)) {
2451 dev_err(rdev
->dev
, "Card not posted and no BIOS - ignoring\n");
2454 DRM_INFO("GPU not posted. posting now...\n");
2455 atom_asic_init(rdev
->mode_info
.atom_context
);
2457 /* Initialize scratch registers */
2458 r600_scratch_init(rdev
);
2459 /* Initialize surface registers */
2460 radeon_surface_init(rdev
);
2461 /* Initialize clocks */
2462 radeon_get_clock_info(rdev
->ddev
);
2463 r
= radeon_clocks_init(rdev
);
2467 r
= radeon_fence_driver_init(rdev
);
2470 if (rdev
->flags
& RADEON_IS_AGP
) {
2471 r
= radeon_agp_init(rdev
);
2473 radeon_agp_disable(rdev
);
2475 r
= r600_mc_init(rdev
);
2478 /* Memory manager */
2479 r
= radeon_bo_init(rdev
);
2483 r
= radeon_irq_kms_init(rdev
);
2487 rdev
->cp
.ring_obj
= NULL
;
2488 r600_ring_init(rdev
, 1024 * 1024);
2490 rdev
->ih
.ring_obj
= NULL
;
2491 r600_ih_ring_init(rdev
, 64 * 1024);
2493 r
= r600_pcie_gart_init(rdev
);
2497 rdev
->accel_working
= true;
2498 r
= r600_startup(rdev
);
2500 dev_err(rdev
->dev
, "disabling GPU acceleration\n");
2503 r600_irq_fini(rdev
);
2504 radeon_irq_kms_fini(rdev
);
2505 r600_pcie_gart_fini(rdev
);
2506 rdev
->accel_working
= false;
2508 if (rdev
->accel_working
) {
2509 r
= radeon_ib_pool_init(rdev
);
2511 dev_err(rdev
->dev
, "IB initialization failed (%d).\n", r
);
2512 rdev
->accel_working
= false;
2514 r
= r600_ib_test(rdev
);
2516 dev_err(rdev
->dev
, "IB test failed (%d).\n", r
);
2517 rdev
->accel_working
= false;
2522 r
= r600_audio_init(rdev
);
2524 return r
; /* TODO error handling */
2528 void r600_fini(struct radeon_device
*rdev
)
2530 r600_audio_fini(rdev
);
2531 r600_blit_fini(rdev
);
2534 r600_irq_fini(rdev
);
2535 radeon_irq_kms_fini(rdev
);
2536 r600_pcie_gart_fini(rdev
);
2537 radeon_agp_fini(rdev
);
2538 radeon_gem_fini(rdev
);
2539 radeon_fence_driver_fini(rdev
);
2540 radeon_clocks_fini(rdev
);
2541 radeon_bo_fini(rdev
);
2542 radeon_atombios_fini(rdev
);
2545 radeon_dummy_page_fini(rdev
);
2552 void r600_ring_ib_execute(struct radeon_device
*rdev
, struct radeon_ib
*ib
)
2554 /* FIXME: implement */
2555 radeon_ring_write(rdev
, PACKET3(PACKET3_INDIRECT_BUFFER
, 2));
2556 radeon_ring_write(rdev
, ib
->gpu_addr
& 0xFFFFFFFC);
2557 radeon_ring_write(rdev
, upper_32_bits(ib
->gpu_addr
) & 0xFF);
2558 radeon_ring_write(rdev
, ib
->length_dw
);
2561 int r600_ib_test(struct radeon_device
*rdev
)
2563 struct radeon_ib
*ib
;
2569 r
= radeon_scratch_get(rdev
, &scratch
);
2571 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r
);
2574 WREG32(scratch
, 0xCAFEDEAD);
2575 r
= radeon_ib_get(rdev
, &ib
);
2577 DRM_ERROR("radeon: failed to get ib (%d).\n", r
);
2580 ib
->ptr
[0] = PACKET3(PACKET3_SET_CONFIG_REG
, 1);
2581 ib
->ptr
[1] = ((scratch
- PACKET3_SET_CONFIG_REG_OFFSET
) >> 2);
2582 ib
->ptr
[2] = 0xDEADBEEF;
2583 ib
->ptr
[3] = PACKET2(0);
2584 ib
->ptr
[4] = PACKET2(0);
2585 ib
->ptr
[5] = PACKET2(0);
2586 ib
->ptr
[6] = PACKET2(0);
2587 ib
->ptr
[7] = PACKET2(0);
2588 ib
->ptr
[8] = PACKET2(0);
2589 ib
->ptr
[9] = PACKET2(0);
2590 ib
->ptr
[10] = PACKET2(0);
2591 ib
->ptr
[11] = PACKET2(0);
2592 ib
->ptr
[12] = PACKET2(0);
2593 ib
->ptr
[13] = PACKET2(0);
2594 ib
->ptr
[14] = PACKET2(0);
2595 ib
->ptr
[15] = PACKET2(0);
2597 r
= radeon_ib_schedule(rdev
, ib
);
2599 radeon_scratch_free(rdev
, scratch
);
2600 radeon_ib_free(rdev
, &ib
);
2601 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r
);
2604 r
= radeon_fence_wait(ib
->fence
, false);
2606 DRM_ERROR("radeon: fence wait failed (%d).\n", r
);
2609 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
2610 tmp
= RREG32(scratch
);
2611 if (tmp
== 0xDEADBEEF)
2615 if (i
< rdev
->usec_timeout
) {
2616 DRM_INFO("ib test succeeded in %u usecs\n", i
);
2618 DRM_ERROR("radeon: ib test failed (sracth(0x%04X)=0x%08X)\n",
2622 radeon_scratch_free(rdev
, scratch
);
2623 radeon_ib_free(rdev
, &ib
);
2630 * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
2631 * the same as the CP ring buffer, but in reverse. Rather than the CPU
2632 * writing to the ring and the GPU consuming, the GPU writes to the ring
2633 * and host consumes. As the host irq handler processes interrupts, it
2634 * increments the rptr. When the rptr catches up with the wptr, all the
2635 * current interrupts have been processed.
2638 void r600_ih_ring_init(struct radeon_device
*rdev
, unsigned ring_size
)
2642 /* Align ring size */
2643 rb_bufsz
= drm_order(ring_size
/ 4);
2644 ring_size
= (1 << rb_bufsz
) * 4;
2645 rdev
->ih
.ring_size
= ring_size
;
2646 rdev
->ih
.ptr_mask
= rdev
->ih
.ring_size
- 1;
2650 static int r600_ih_ring_alloc(struct radeon_device
*rdev
)
2654 /* Allocate ring buffer */
2655 if (rdev
->ih
.ring_obj
== NULL
) {
2656 r
= radeon_bo_create(rdev
, NULL
, rdev
->ih
.ring_size
,
2658 RADEON_GEM_DOMAIN_GTT
,
2659 &rdev
->ih
.ring_obj
);
2661 DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r
);
2664 r
= radeon_bo_reserve(rdev
->ih
.ring_obj
, false);
2665 if (unlikely(r
!= 0))
2667 r
= radeon_bo_pin(rdev
->ih
.ring_obj
,
2668 RADEON_GEM_DOMAIN_GTT
,
2669 &rdev
->ih
.gpu_addr
);
2671 radeon_bo_unreserve(rdev
->ih
.ring_obj
);
2672 DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r
);
2675 r
= radeon_bo_kmap(rdev
->ih
.ring_obj
,
2676 (void **)&rdev
->ih
.ring
);
2677 radeon_bo_unreserve(rdev
->ih
.ring_obj
);
2679 DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r
);
2686 static void r600_ih_ring_fini(struct radeon_device
*rdev
)
2689 if (rdev
->ih
.ring_obj
) {
2690 r
= radeon_bo_reserve(rdev
->ih
.ring_obj
, false);
2691 if (likely(r
== 0)) {
2692 radeon_bo_kunmap(rdev
->ih
.ring_obj
);
2693 radeon_bo_unpin(rdev
->ih
.ring_obj
);
2694 radeon_bo_unreserve(rdev
->ih
.ring_obj
);
2696 radeon_bo_unref(&rdev
->ih
.ring_obj
);
2697 rdev
->ih
.ring
= NULL
;
2698 rdev
->ih
.ring_obj
= NULL
;
2702 void r600_rlc_stop(struct radeon_device
*rdev
)
2705 if ((rdev
->family
>= CHIP_RV770
) &&
2706 (rdev
->family
<= CHIP_RV740
)) {
2707 /* r7xx asics need to soft reset RLC before halting */
2708 WREG32(SRBM_SOFT_RESET
, SOFT_RESET_RLC
);
2709 RREG32(SRBM_SOFT_RESET
);
2711 WREG32(SRBM_SOFT_RESET
, 0);
2712 RREG32(SRBM_SOFT_RESET
);
2715 WREG32(RLC_CNTL
, 0);
2718 static void r600_rlc_start(struct radeon_device
*rdev
)
2720 WREG32(RLC_CNTL
, RLC_ENABLE
);
2723 static int r600_rlc_init(struct radeon_device
*rdev
)
2726 const __be32
*fw_data
;
2731 r600_rlc_stop(rdev
);
2733 WREG32(RLC_HB_BASE
, 0);
2734 WREG32(RLC_HB_CNTL
, 0);
2735 WREG32(RLC_HB_RPTR
, 0);
2736 WREG32(RLC_HB_WPTR
, 0);
2737 WREG32(RLC_HB_WPTR_LSB_ADDR
, 0);
2738 WREG32(RLC_HB_WPTR_MSB_ADDR
, 0);
2739 WREG32(RLC_MC_CNTL
, 0);
2740 WREG32(RLC_UCODE_CNTL
, 0);
2742 fw_data
= (const __be32
*)rdev
->rlc_fw
->data
;
2743 if (rdev
->family
>= CHIP_CEDAR
) {
2744 for (i
= 0; i
< EVERGREEN_RLC_UCODE_SIZE
; i
++) {
2745 WREG32(RLC_UCODE_ADDR
, i
);
2746 WREG32(RLC_UCODE_DATA
, be32_to_cpup(fw_data
++));
2748 } else if (rdev
->family
>= CHIP_RV770
) {
2749 for (i
= 0; i
< R700_RLC_UCODE_SIZE
; i
++) {
2750 WREG32(RLC_UCODE_ADDR
, i
);
2751 WREG32(RLC_UCODE_DATA
, be32_to_cpup(fw_data
++));
2754 for (i
= 0; i
< RLC_UCODE_SIZE
; i
++) {
2755 WREG32(RLC_UCODE_ADDR
, i
);
2756 WREG32(RLC_UCODE_DATA
, be32_to_cpup(fw_data
++));
2759 WREG32(RLC_UCODE_ADDR
, 0);
2761 r600_rlc_start(rdev
);
2766 static void r600_enable_interrupts(struct radeon_device
*rdev
)
2768 u32 ih_cntl
= RREG32(IH_CNTL
);
2769 u32 ih_rb_cntl
= RREG32(IH_RB_CNTL
);
2771 ih_cntl
|= ENABLE_INTR
;
2772 ih_rb_cntl
|= IH_RB_ENABLE
;
2773 WREG32(IH_CNTL
, ih_cntl
);
2774 WREG32(IH_RB_CNTL
, ih_rb_cntl
);
2775 rdev
->ih
.enabled
= true;
2778 void r600_disable_interrupts(struct radeon_device
*rdev
)
2780 u32 ih_rb_cntl
= RREG32(IH_RB_CNTL
);
2781 u32 ih_cntl
= RREG32(IH_CNTL
);
2783 ih_rb_cntl
&= ~IH_RB_ENABLE
;
2784 ih_cntl
&= ~ENABLE_INTR
;
2785 WREG32(IH_RB_CNTL
, ih_rb_cntl
);
2786 WREG32(IH_CNTL
, ih_cntl
);
2787 /* set rptr, wptr to 0 */
2788 WREG32(IH_RB_RPTR
, 0);
2789 WREG32(IH_RB_WPTR
, 0);
2790 rdev
->ih
.enabled
= false;
2795 static void r600_disable_interrupt_state(struct radeon_device
*rdev
)
2799 WREG32(CP_INT_CNTL
, 0);
2800 WREG32(GRBM_INT_CNTL
, 0);
2801 WREG32(DxMODE_INT_MASK
, 0);
2802 if (ASIC_IS_DCE3(rdev
)) {
2803 WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL
, 0);
2804 WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL
, 0);
2805 tmp
= RREG32(DC_HPD1_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
2806 WREG32(DC_HPD1_INT_CONTROL
, tmp
);
2807 tmp
= RREG32(DC_HPD2_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
2808 WREG32(DC_HPD2_INT_CONTROL
, tmp
);
2809 tmp
= RREG32(DC_HPD3_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
2810 WREG32(DC_HPD3_INT_CONTROL
, tmp
);
2811 tmp
= RREG32(DC_HPD4_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
2812 WREG32(DC_HPD4_INT_CONTROL
, tmp
);
2813 if (ASIC_IS_DCE32(rdev
)) {
2814 tmp
= RREG32(DC_HPD5_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
2815 WREG32(DC_HPD5_INT_CONTROL
, tmp
);
2816 tmp
= RREG32(DC_HPD6_INT_CONTROL
) & DC_HPDx_INT_POLARITY
;
2817 WREG32(DC_HPD6_INT_CONTROL
, tmp
);
2820 WREG32(DACA_AUTODETECT_INT_CONTROL
, 0);
2821 WREG32(DACB_AUTODETECT_INT_CONTROL
, 0);
2822 tmp
= RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
) & DC_HOT_PLUG_DETECTx_INT_POLARITY
;
2823 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
, tmp
);
2824 tmp
= RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
) & DC_HOT_PLUG_DETECTx_INT_POLARITY
;
2825 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
, tmp
);
2826 tmp
= RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
) & DC_HOT_PLUG_DETECTx_INT_POLARITY
;
2827 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
, tmp
);
2831 int r600_irq_init(struct radeon_device
*rdev
)
2835 u32 interrupt_cntl
, ih_cntl
, ih_rb_cntl
;
2838 ret
= r600_ih_ring_alloc(rdev
);
2843 r600_disable_interrupts(rdev
);
2846 ret
= r600_rlc_init(rdev
);
2848 r600_ih_ring_fini(rdev
);
2852 /* setup interrupt control */
2853 /* set dummy read address to ring address */
2854 WREG32(INTERRUPT_CNTL2
, rdev
->ih
.gpu_addr
>> 8);
2855 interrupt_cntl
= RREG32(INTERRUPT_CNTL
);
2856 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
2857 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
2859 interrupt_cntl
&= ~IH_DUMMY_RD_OVERRIDE
;
2860 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
2861 interrupt_cntl
&= ~IH_REQ_NONSNOOP_EN
;
2862 WREG32(INTERRUPT_CNTL
, interrupt_cntl
);
2864 WREG32(IH_RB_BASE
, rdev
->ih
.gpu_addr
>> 8);
2865 rb_bufsz
= drm_order(rdev
->ih
.ring_size
/ 4);
2867 ih_rb_cntl
= (IH_WPTR_OVERFLOW_ENABLE
|
2868 IH_WPTR_OVERFLOW_CLEAR
|
2870 /* WPTR writeback, not yet */
2871 /*ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;*/
2872 WREG32(IH_RB_WPTR_ADDR_LO
, 0);
2873 WREG32(IH_RB_WPTR_ADDR_HI
, 0);
2875 WREG32(IH_RB_CNTL
, ih_rb_cntl
);
2877 /* set rptr, wptr to 0 */
2878 WREG32(IH_RB_RPTR
, 0);
2879 WREG32(IH_RB_WPTR
, 0);
2881 /* Default settings for IH_CNTL (disabled at first) */
2882 ih_cntl
= MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
2883 /* RPTR_REARM only works if msi's are enabled */
2884 if (rdev
->msi_enabled
)
2885 ih_cntl
|= RPTR_REARM
;
2888 ih_cntl
|= IH_MC_SWAP(IH_MC_SWAP_32BIT
);
2890 WREG32(IH_CNTL
, ih_cntl
);
2892 /* force the active interrupt state to all disabled */
2893 if (rdev
->family
>= CHIP_CEDAR
)
2894 evergreen_disable_interrupt_state(rdev
);
2896 r600_disable_interrupt_state(rdev
);
2899 r600_enable_interrupts(rdev
);
2904 void r600_irq_suspend(struct radeon_device
*rdev
)
2906 r600_irq_disable(rdev
);
2907 r600_rlc_stop(rdev
);
2910 void r600_irq_fini(struct radeon_device
*rdev
)
2912 r600_irq_suspend(rdev
);
2913 r600_ih_ring_fini(rdev
);
2916 int r600_irq_set(struct radeon_device
*rdev
)
2918 u32 cp_int_cntl
= CNTX_BUSY_INT_ENABLE
| CNTX_EMPTY_INT_ENABLE
;
2920 u32 hpd1
, hpd2
, hpd3
, hpd4
= 0, hpd5
= 0, hpd6
= 0;
2921 u32 grbm_int_cntl
= 0;
2924 if (!rdev
->irq
.installed
) {
2925 WARN(1, "Can't enable IRQ/MSI because no handler is installed.\n");
2928 /* don't enable anything if the ih is disabled */
2929 if (!rdev
->ih
.enabled
) {
2930 r600_disable_interrupts(rdev
);
2931 /* force the active interrupt state to all disabled */
2932 r600_disable_interrupt_state(rdev
);
2936 hdmi1
= RREG32(R600_HDMI_BLOCK1
+ R600_HDMI_CNTL
) & ~R600_HDMI_INT_EN
;
2937 if (ASIC_IS_DCE3(rdev
)) {
2938 hdmi2
= RREG32(R600_HDMI_BLOCK3
+ R600_HDMI_CNTL
) & ~R600_HDMI_INT_EN
;
2939 hpd1
= RREG32(DC_HPD1_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
2940 hpd2
= RREG32(DC_HPD2_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
2941 hpd3
= RREG32(DC_HPD3_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
2942 hpd4
= RREG32(DC_HPD4_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
2943 if (ASIC_IS_DCE32(rdev
)) {
2944 hpd5
= RREG32(DC_HPD5_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
2945 hpd6
= RREG32(DC_HPD6_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
2948 hdmi2
= RREG32(R600_HDMI_BLOCK2
+ R600_HDMI_CNTL
) & ~R600_HDMI_INT_EN
;
2949 hpd1
= RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
2950 hpd2
= RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
2951 hpd3
= RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
) & ~DC_HPDx_INT_EN
;
2954 if (rdev
->irq
.sw_int
) {
2955 DRM_DEBUG("r600_irq_set: sw int\n");
2956 cp_int_cntl
|= RB_INT_ENABLE
;
2958 if (rdev
->irq
.crtc_vblank_int
[0]) {
2959 DRM_DEBUG("r600_irq_set: vblank 0\n");
2960 mode_int
|= D1MODE_VBLANK_INT_MASK
;
2962 if (rdev
->irq
.crtc_vblank_int
[1]) {
2963 DRM_DEBUG("r600_irq_set: vblank 1\n");
2964 mode_int
|= D2MODE_VBLANK_INT_MASK
;
2966 if (rdev
->irq
.hpd
[0]) {
2967 DRM_DEBUG("r600_irq_set: hpd 1\n");
2968 hpd1
|= DC_HPDx_INT_EN
;
2970 if (rdev
->irq
.hpd
[1]) {
2971 DRM_DEBUG("r600_irq_set: hpd 2\n");
2972 hpd2
|= DC_HPDx_INT_EN
;
2974 if (rdev
->irq
.hpd
[2]) {
2975 DRM_DEBUG("r600_irq_set: hpd 3\n");
2976 hpd3
|= DC_HPDx_INT_EN
;
2978 if (rdev
->irq
.hpd
[3]) {
2979 DRM_DEBUG("r600_irq_set: hpd 4\n");
2980 hpd4
|= DC_HPDx_INT_EN
;
2982 if (rdev
->irq
.hpd
[4]) {
2983 DRM_DEBUG("r600_irq_set: hpd 5\n");
2984 hpd5
|= DC_HPDx_INT_EN
;
2986 if (rdev
->irq
.hpd
[5]) {
2987 DRM_DEBUG("r600_irq_set: hpd 6\n");
2988 hpd6
|= DC_HPDx_INT_EN
;
2990 if (rdev
->irq
.hdmi
[0]) {
2991 DRM_DEBUG("r600_irq_set: hdmi 1\n");
2992 hdmi1
|= R600_HDMI_INT_EN
;
2994 if (rdev
->irq
.hdmi
[1]) {
2995 DRM_DEBUG("r600_irq_set: hdmi 2\n");
2996 hdmi2
|= R600_HDMI_INT_EN
;
2998 if (rdev
->irq
.gui_idle
) {
2999 DRM_DEBUG("gui idle\n");
3000 grbm_int_cntl
|= GUI_IDLE_INT_ENABLE
;
3003 WREG32(CP_INT_CNTL
, cp_int_cntl
);
3004 WREG32(DxMODE_INT_MASK
, mode_int
);
3005 WREG32(GRBM_INT_CNTL
, grbm_int_cntl
);
3006 WREG32(R600_HDMI_BLOCK1
+ R600_HDMI_CNTL
, hdmi1
);
3007 if (ASIC_IS_DCE3(rdev
)) {
3008 WREG32(R600_HDMI_BLOCK3
+ R600_HDMI_CNTL
, hdmi2
);
3009 WREG32(DC_HPD1_INT_CONTROL
, hpd1
);
3010 WREG32(DC_HPD2_INT_CONTROL
, hpd2
);
3011 WREG32(DC_HPD3_INT_CONTROL
, hpd3
);
3012 WREG32(DC_HPD4_INT_CONTROL
, hpd4
);
3013 if (ASIC_IS_DCE32(rdev
)) {
3014 WREG32(DC_HPD5_INT_CONTROL
, hpd5
);
3015 WREG32(DC_HPD6_INT_CONTROL
, hpd6
);
3018 WREG32(R600_HDMI_BLOCK2
+ R600_HDMI_CNTL
, hdmi2
);
3019 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
, hpd1
);
3020 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
, hpd2
);
3021 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
, hpd3
);
3027 static inline void r600_irq_ack(struct radeon_device
*rdev
,
3030 u32
*disp_int_cont2
)
3034 if (ASIC_IS_DCE3(rdev
)) {
3035 *disp_int
= RREG32(DCE3_DISP_INTERRUPT_STATUS
);
3036 *disp_int_cont
= RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE
);
3037 *disp_int_cont2
= RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2
);
3039 *disp_int
= RREG32(DISP_INTERRUPT_STATUS
);
3040 *disp_int_cont
= RREG32(DISP_INTERRUPT_STATUS_CONTINUE
);
3041 *disp_int_cont2
= 0;
3044 if (*disp_int
& LB_D1_VBLANK_INTERRUPT
)
3045 WREG32(D1MODE_VBLANK_STATUS
, DxMODE_VBLANK_ACK
);
3046 if (*disp_int
& LB_D1_VLINE_INTERRUPT
)
3047 WREG32(D1MODE_VLINE_STATUS
, DxMODE_VLINE_ACK
);
3048 if (*disp_int
& LB_D2_VBLANK_INTERRUPT
)
3049 WREG32(D2MODE_VBLANK_STATUS
, DxMODE_VBLANK_ACK
);
3050 if (*disp_int
& LB_D2_VLINE_INTERRUPT
)
3051 WREG32(D2MODE_VLINE_STATUS
, DxMODE_VLINE_ACK
);
3052 if (*disp_int
& DC_HPD1_INTERRUPT
) {
3053 if (ASIC_IS_DCE3(rdev
)) {
3054 tmp
= RREG32(DC_HPD1_INT_CONTROL
);
3055 tmp
|= DC_HPDx_INT_ACK
;
3056 WREG32(DC_HPD1_INT_CONTROL
, tmp
);
3058 tmp
= RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
);
3059 tmp
|= DC_HPDx_INT_ACK
;
3060 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL
, tmp
);
3063 if (*disp_int
& DC_HPD2_INTERRUPT
) {
3064 if (ASIC_IS_DCE3(rdev
)) {
3065 tmp
= RREG32(DC_HPD2_INT_CONTROL
);
3066 tmp
|= DC_HPDx_INT_ACK
;
3067 WREG32(DC_HPD2_INT_CONTROL
, tmp
);
3069 tmp
= RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
);
3070 tmp
|= DC_HPDx_INT_ACK
;
3071 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL
, tmp
);
3074 if (*disp_int_cont
& DC_HPD3_INTERRUPT
) {
3075 if (ASIC_IS_DCE3(rdev
)) {
3076 tmp
= RREG32(DC_HPD3_INT_CONTROL
);
3077 tmp
|= DC_HPDx_INT_ACK
;
3078 WREG32(DC_HPD3_INT_CONTROL
, tmp
);
3080 tmp
= RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
);
3081 tmp
|= DC_HPDx_INT_ACK
;
3082 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL
, tmp
);
3085 if (*disp_int_cont
& DC_HPD4_INTERRUPT
) {
3086 tmp
= RREG32(DC_HPD4_INT_CONTROL
);
3087 tmp
|= DC_HPDx_INT_ACK
;
3088 WREG32(DC_HPD4_INT_CONTROL
, tmp
);
3090 if (ASIC_IS_DCE32(rdev
)) {
3091 if (*disp_int_cont2
& DC_HPD5_INTERRUPT
) {
3092 tmp
= RREG32(DC_HPD5_INT_CONTROL
);
3093 tmp
|= DC_HPDx_INT_ACK
;
3094 WREG32(DC_HPD5_INT_CONTROL
, tmp
);
3096 if (*disp_int_cont2
& DC_HPD6_INTERRUPT
) {
3097 tmp
= RREG32(DC_HPD5_INT_CONTROL
);
3098 tmp
|= DC_HPDx_INT_ACK
;
3099 WREG32(DC_HPD6_INT_CONTROL
, tmp
);
3102 if (RREG32(R600_HDMI_BLOCK1
+ R600_HDMI_STATUS
) & R600_HDMI_INT_PENDING
) {
3103 WREG32_P(R600_HDMI_BLOCK1
+ R600_HDMI_CNTL
, R600_HDMI_INT_ACK
, ~R600_HDMI_INT_ACK
);
3105 if (ASIC_IS_DCE3(rdev
)) {
3106 if (RREG32(R600_HDMI_BLOCK3
+ R600_HDMI_STATUS
) & R600_HDMI_INT_PENDING
) {
3107 WREG32_P(R600_HDMI_BLOCK3
+ R600_HDMI_CNTL
, R600_HDMI_INT_ACK
, ~R600_HDMI_INT_ACK
);
3110 if (RREG32(R600_HDMI_BLOCK2
+ R600_HDMI_STATUS
) & R600_HDMI_INT_PENDING
) {
3111 WREG32_P(R600_HDMI_BLOCK2
+ R600_HDMI_CNTL
, R600_HDMI_INT_ACK
, ~R600_HDMI_INT_ACK
);
3116 void r600_irq_disable(struct radeon_device
*rdev
)
3118 u32 disp_int
, disp_int_cont
, disp_int_cont2
;
3120 r600_disable_interrupts(rdev
);
3121 /* Wait and acknowledge irq */
3123 r600_irq_ack(rdev
, &disp_int
, &disp_int_cont
, &disp_int_cont2
);
3124 r600_disable_interrupt_state(rdev
);
3127 static inline u32
r600_get_ih_wptr(struct radeon_device
*rdev
)
3131 /* XXX use writeback */
3132 wptr
= RREG32(IH_RB_WPTR
);
3134 if (wptr
& RB_OVERFLOW
) {
3135 /* When a ring buffer overflow happen start parsing interrupt
3136 * from the last not overwritten vector (wptr + 16). Hopefully
3137 * this should allow us to catchup.
3139 dev_warn(rdev
->dev
, "IH ring buffer overflow (0x%08X, %d, %d)\n",
3140 wptr
, rdev
->ih
.rptr
, (wptr
+ 16) + rdev
->ih
.ptr_mask
);
3141 rdev
->ih
.rptr
= (wptr
+ 16) & rdev
->ih
.ptr_mask
;
3142 tmp
= RREG32(IH_RB_CNTL
);
3143 tmp
|= IH_WPTR_OVERFLOW_CLEAR
;
3144 WREG32(IH_RB_CNTL
, tmp
);
3146 return (wptr
& rdev
->ih
.ptr_mask
);
3150 * Each IV ring entry is 128 bits:
3151 * [7:0] - interrupt source id
3153 * [59:32] - interrupt source data
3154 * [127:60] - reserved
3156 * The basic interrupt vector entries
3157 * are decoded as follows:
3158 * src_id src_data description
3163 * 19 0 FP Hot plug detection A
3164 * 19 1 FP Hot plug detection B
3165 * 19 2 DAC A auto-detection
3166 * 19 3 DAC B auto-detection
3172 * 181 - EOP Interrupt
3175 * Note, these are based on r600 and may need to be
3176 * adjusted or added to on newer asics
3179 int r600_irq_process(struct radeon_device
*rdev
)
3181 u32 wptr
= r600_get_ih_wptr(rdev
);
3182 u32 rptr
= rdev
->ih
.rptr
;
3183 u32 src_id
, src_data
;
3184 u32 ring_index
, disp_int
, disp_int_cont
, disp_int_cont2
;
3185 unsigned long flags
;
3186 bool queue_hotplug
= false;
3188 DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr
, wptr
);
3189 if (!rdev
->ih
.enabled
)
3192 spin_lock_irqsave(&rdev
->ih
.lock
, flags
);
3195 spin_unlock_irqrestore(&rdev
->ih
.lock
, flags
);
3198 if (rdev
->shutdown
) {
3199 spin_unlock_irqrestore(&rdev
->ih
.lock
, flags
);
3204 /* display interrupts */
3205 r600_irq_ack(rdev
, &disp_int
, &disp_int_cont
, &disp_int_cont2
);
3207 rdev
->ih
.wptr
= wptr
;
3208 while (rptr
!= wptr
) {
3209 /* wptr/rptr are in bytes! */
3210 ring_index
= rptr
/ 4;
3211 src_id
= rdev
->ih
.ring
[ring_index
] & 0xff;
3212 src_data
= rdev
->ih
.ring
[ring_index
+ 1] & 0xfffffff;
3215 case 1: /* D1 vblank/vline */
3217 case 0: /* D1 vblank */
3218 if (disp_int
& LB_D1_VBLANK_INTERRUPT
) {
3219 drm_handle_vblank(rdev
->ddev
, 0);
3220 rdev
->pm
.vblank_sync
= true;
3221 wake_up(&rdev
->irq
.vblank_queue
);
3222 disp_int
&= ~LB_D1_VBLANK_INTERRUPT
;
3223 DRM_DEBUG("IH: D1 vblank\n");
3226 case 1: /* D1 vline */
3227 if (disp_int
& LB_D1_VLINE_INTERRUPT
) {
3228 disp_int
&= ~LB_D1_VLINE_INTERRUPT
;
3229 DRM_DEBUG("IH: D1 vline\n");
3233 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id
, src_data
);
3237 case 5: /* D2 vblank/vline */
3239 case 0: /* D2 vblank */
3240 if (disp_int
& LB_D2_VBLANK_INTERRUPT
) {
3241 drm_handle_vblank(rdev
->ddev
, 1);
3242 rdev
->pm
.vblank_sync
= true;
3243 wake_up(&rdev
->irq
.vblank_queue
);
3244 disp_int
&= ~LB_D2_VBLANK_INTERRUPT
;
3245 DRM_DEBUG("IH: D2 vblank\n");
3248 case 1: /* D1 vline */
3249 if (disp_int
& LB_D2_VLINE_INTERRUPT
) {
3250 disp_int
&= ~LB_D2_VLINE_INTERRUPT
;
3251 DRM_DEBUG("IH: D2 vline\n");
3255 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id
, src_data
);
3259 case 19: /* HPD/DAC hotplug */
3262 if (disp_int
& DC_HPD1_INTERRUPT
) {
3263 disp_int
&= ~DC_HPD1_INTERRUPT
;
3264 queue_hotplug
= true;
3265 DRM_DEBUG("IH: HPD1\n");
3269 if (disp_int
& DC_HPD2_INTERRUPT
) {
3270 disp_int
&= ~DC_HPD2_INTERRUPT
;
3271 queue_hotplug
= true;
3272 DRM_DEBUG("IH: HPD2\n");
3276 if (disp_int_cont
& DC_HPD3_INTERRUPT
) {
3277 disp_int_cont
&= ~DC_HPD3_INTERRUPT
;
3278 queue_hotplug
= true;
3279 DRM_DEBUG("IH: HPD3\n");
3283 if (disp_int_cont
& DC_HPD4_INTERRUPT
) {
3284 disp_int_cont
&= ~DC_HPD4_INTERRUPT
;
3285 queue_hotplug
= true;
3286 DRM_DEBUG("IH: HPD4\n");
3290 if (disp_int_cont2
& DC_HPD5_INTERRUPT
) {
3291 disp_int_cont2
&= ~DC_HPD5_INTERRUPT
;
3292 queue_hotplug
= true;
3293 DRM_DEBUG("IH: HPD5\n");
3297 if (disp_int_cont2
& DC_HPD6_INTERRUPT
) {
3298 disp_int_cont2
&= ~DC_HPD6_INTERRUPT
;
3299 queue_hotplug
= true;
3300 DRM_DEBUG("IH: HPD6\n");
3304 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id
, src_data
);
3309 DRM_DEBUG("IH: HDMI: 0x%x\n", src_data
);
3310 r600_audio_schedule_polling(rdev
);
3312 case 176: /* CP_INT in ring buffer */
3313 case 177: /* CP_INT in IB1 */
3314 case 178: /* CP_INT in IB2 */
3315 DRM_DEBUG("IH: CP int: 0x%08x\n", src_data
);
3316 radeon_fence_process(rdev
);
3318 case 181: /* CP EOP event */
3319 DRM_DEBUG("IH: CP EOP\n");
3321 case 233: /* GUI IDLE */
3322 DRM_DEBUG("IH: CP EOP\n");
3323 rdev
->pm
.gui_idle
= true;
3324 wake_up(&rdev
->irq
.idle_queue
);
3327 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id
, src_data
);
3331 /* wptr/rptr are in bytes! */
3333 rptr
&= rdev
->ih
.ptr_mask
;
3335 /* make sure wptr hasn't changed while processing */
3336 wptr
= r600_get_ih_wptr(rdev
);
3337 if (wptr
!= rdev
->ih
.wptr
)
3340 queue_work(rdev
->wq
, &rdev
->hotplug_work
);
3341 rdev
->ih
.rptr
= rptr
;
3342 WREG32(IH_RB_RPTR
, rdev
->ih
.rptr
);
3343 spin_unlock_irqrestore(&rdev
->ih
.lock
, flags
);
3350 #if defined(CONFIG_DEBUG_FS)
3352 static int r600_debugfs_cp_ring_info(struct seq_file
*m
, void *data
)
3354 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
3355 struct drm_device
*dev
= node
->minor
->dev
;
3356 struct radeon_device
*rdev
= dev
->dev_private
;
3357 unsigned count
, i
, j
;
3359 radeon_ring_free_size(rdev
);
3360 count
= (rdev
->cp
.ring_size
/ 4) - rdev
->cp
.ring_free_dw
;
3361 seq_printf(m
, "CP_STAT 0x%08x\n", RREG32(CP_STAT
));
3362 seq_printf(m
, "CP_RB_WPTR 0x%08x\n", RREG32(CP_RB_WPTR
));
3363 seq_printf(m
, "CP_RB_RPTR 0x%08x\n", RREG32(CP_RB_RPTR
));
3364 seq_printf(m
, "driver's copy of the CP_RB_WPTR 0x%08x\n", rdev
->cp
.wptr
);
3365 seq_printf(m
, "driver's copy of the CP_RB_RPTR 0x%08x\n", rdev
->cp
.rptr
);
3366 seq_printf(m
, "%u free dwords in ring\n", rdev
->cp
.ring_free_dw
);
3367 seq_printf(m
, "%u dwords in ring\n", count
);
3369 for (j
= 0; j
<= count
; j
++) {
3370 seq_printf(m
, "r[%04d]=0x%08x\n", i
, rdev
->cp
.ring
[i
]);
3371 i
= (i
+ 1) & rdev
->cp
.ptr_mask
;
3376 static int r600_debugfs_mc_info(struct seq_file
*m
, void *data
)
3378 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
3379 struct drm_device
*dev
= node
->minor
->dev
;
3380 struct radeon_device
*rdev
= dev
->dev_private
;
3382 DREG32_SYS(m
, rdev
, R_000E50_SRBM_STATUS
);
3383 DREG32_SYS(m
, rdev
, VM_L2_STATUS
);
3387 static struct drm_info_list r600_mc_info_list
[] = {
3388 {"r600_mc_info", r600_debugfs_mc_info
, 0, NULL
},
3389 {"r600_ring_info", r600_debugfs_cp_ring_info
, 0, NULL
},
3393 int r600_debugfs_mc_info_init(struct radeon_device
*rdev
)
3395 #if defined(CONFIG_DEBUG_FS)
3396 return radeon_debugfs_add_files(rdev
, r600_mc_info_list
, ARRAY_SIZE(r600_mc_info_list
));
3403 * r600_ioctl_wait_idle - flush host path cache on wait idle ioctl
3404 * rdev: radeon device structure
3405 * bo: buffer object struct which userspace is waiting for idle
3407 * Some R6XX/R7XX doesn't seems to take into account HDP flush performed
3408 * through ring buffer, this leads to corruption in rendering, see
3409 * http://bugzilla.kernel.org/show_bug.cgi?id=15186 to avoid this we
3410 * directly perform HDP flush by writing register through MMIO.
3412 void r600_ioctl_wait_idle(struct radeon_device
*rdev
, struct radeon_bo
*bo
)
3414 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL
, 0x1);