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>
32 #include <linux/module.h>
34 #include <drm/radeon_drm.h>
36 #include "radeon_asic.h"
37 #include "radeon_mode.h"
42 #define PFP_UCODE_SIZE 576
43 #define PM4_UCODE_SIZE 1792
44 #define RLC_UCODE_SIZE 768
45 #define R700_PFP_UCODE_SIZE 848
46 #define R700_PM4_UCODE_SIZE 1360
47 #define R700_RLC_UCODE_SIZE 1024
48 #define EVERGREEN_PFP_UCODE_SIZE 1120
49 #define EVERGREEN_PM4_UCODE_SIZE 1376
50 #define EVERGREEN_RLC_UCODE_SIZE 768
51 #define CAYMAN_RLC_UCODE_SIZE 1024
52 #define ARUBA_RLC_UCODE_SIZE 1536
55 MODULE_FIRMWARE("radeon/R600_pfp.bin");
56 MODULE_FIRMWARE("radeon/R600_me.bin");
57 MODULE_FIRMWARE("radeon/RV610_pfp.bin");
58 MODULE_FIRMWARE("radeon/RV610_me.bin");
59 MODULE_FIRMWARE("radeon/RV630_pfp.bin");
60 MODULE_FIRMWARE("radeon/RV630_me.bin");
61 MODULE_FIRMWARE("radeon/RV620_pfp.bin");
62 MODULE_FIRMWARE("radeon/RV620_me.bin");
63 MODULE_FIRMWARE("radeon/RV635_pfp.bin");
64 MODULE_FIRMWARE("radeon/RV635_me.bin");
65 MODULE_FIRMWARE("radeon/RV670_pfp.bin");
66 MODULE_FIRMWARE("radeon/RV670_me.bin");
67 MODULE_FIRMWARE("radeon/RS780_pfp.bin");
68 MODULE_FIRMWARE("radeon/RS780_me.bin");
69 MODULE_FIRMWARE("radeon/RV770_pfp.bin");
70 MODULE_FIRMWARE("radeon/RV770_me.bin");
71 MODULE_FIRMWARE("radeon/RV730_pfp.bin");
72 MODULE_FIRMWARE("radeon/RV730_me.bin");
73 MODULE_FIRMWARE("radeon/RV710_pfp.bin");
74 MODULE_FIRMWARE("radeon/RV710_me.bin");
75 MODULE_FIRMWARE("radeon/R600_rlc.bin");
76 MODULE_FIRMWARE("radeon/R700_rlc.bin");
77 MODULE_FIRMWARE("radeon/CEDAR_pfp.bin");
78 MODULE_FIRMWARE("radeon/CEDAR_me.bin");
79 MODULE_FIRMWARE("radeon/CEDAR_rlc.bin");
80 MODULE_FIRMWARE("radeon/REDWOOD_pfp.bin");
81 MODULE_FIRMWARE("radeon/REDWOOD_me.bin");
82 MODULE_FIRMWARE("radeon/REDWOOD_rlc.bin");
83 MODULE_FIRMWARE("radeon/JUNIPER_pfp.bin");
84 MODULE_FIRMWARE("radeon/JUNIPER_me.bin");
85 MODULE_FIRMWARE("radeon/JUNIPER_rlc.bin");
86 MODULE_FIRMWARE("radeon/CYPRESS_pfp.bin");
87 MODULE_FIRMWARE("radeon/CYPRESS_me.bin");
88 MODULE_FIRMWARE("radeon/CYPRESS_rlc.bin");
89 MODULE_FIRMWARE("radeon/PALM_pfp.bin");
90 MODULE_FIRMWARE("radeon/PALM_me.bin");
91 MODULE_FIRMWARE("radeon/SUMO_rlc.bin");
92 MODULE_FIRMWARE("radeon/SUMO_pfp.bin");
93 MODULE_FIRMWARE("radeon/SUMO_me.bin");
94 MODULE_FIRMWARE("radeon/SUMO2_pfp.bin");
95 MODULE_FIRMWARE("radeon/SUMO2_me.bin");
97 int r600_debugfs_mc_info_init(struct radeon_device *rdev);
99 /* r600,rv610,rv630,rv620,rv635,rv670 */
100 int r600_mc_wait_for_idle(struct radeon_device *rdev);
101 static void r600_gpu_init(struct radeon_device *rdev);
102 void r600_fini(struct radeon_device *rdev);
103 void r600_irq_disable(struct radeon_device *rdev);
104 static void r600_pcie_gen2_enable(struct radeon_device *rdev);
106 /* get temperature in millidegrees */
107 int rv6xx_get_temp(struct radeon_device *rdev)
109 u32 temp = (RREG32(CG_THERMAL_STATUS) & ASIC_T_MASK) >>
111 int actual_temp = temp & 0xff;
116 return actual_temp * 1000;
119 void r600_pm_get_dynpm_state(struct radeon_device *rdev)
123 rdev->pm.dynpm_can_upclock = true;
124 rdev->pm.dynpm_can_downclock = true;
126 /* power state array is low to high, default is first */
127 if ((rdev->flags & RADEON_IS_IGP) || (rdev->family == CHIP_R600)) {
128 int min_power_state_index = 0;
130 if (rdev->pm.num_power_states > 2)
131 min_power_state_index = 1;
133 switch (rdev->pm.dynpm_planned_action) {
134 case DYNPM_ACTION_MINIMUM:
135 rdev->pm.requested_power_state_index = min_power_state_index;
136 rdev->pm.requested_clock_mode_index = 0;
137 rdev->pm.dynpm_can_downclock = false;
139 case DYNPM_ACTION_DOWNCLOCK:
140 if (rdev->pm.current_power_state_index == min_power_state_index) {
141 rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
142 rdev->pm.dynpm_can_downclock = false;
144 if (rdev->pm.active_crtc_count > 1) {
145 for (i = 0; i < rdev->pm.num_power_states; i++) {
146 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
148 else if (i >= rdev->pm.current_power_state_index) {
149 rdev->pm.requested_power_state_index =
150 rdev->pm.current_power_state_index;
153 rdev->pm.requested_power_state_index = i;
158 if (rdev->pm.current_power_state_index == 0)
159 rdev->pm.requested_power_state_index =
160 rdev->pm.num_power_states - 1;
162 rdev->pm.requested_power_state_index =
163 rdev->pm.current_power_state_index - 1;
166 rdev->pm.requested_clock_mode_index = 0;
167 /* don't use the power state if crtcs are active and no display flag is set */
168 if ((rdev->pm.active_crtc_count > 0) &&
169 (rdev->pm.power_state[rdev->pm.requested_power_state_index].
170 clock_info[rdev->pm.requested_clock_mode_index].flags &
171 RADEON_PM_MODE_NO_DISPLAY)) {
172 rdev->pm.requested_power_state_index++;
175 case DYNPM_ACTION_UPCLOCK:
176 if (rdev->pm.current_power_state_index == (rdev->pm.num_power_states - 1)) {
177 rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
178 rdev->pm.dynpm_can_upclock = false;
180 if (rdev->pm.active_crtc_count > 1) {
181 for (i = (rdev->pm.num_power_states - 1); i >= 0; i--) {
182 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
184 else if (i <= rdev->pm.current_power_state_index) {
185 rdev->pm.requested_power_state_index =
186 rdev->pm.current_power_state_index;
189 rdev->pm.requested_power_state_index = i;
194 rdev->pm.requested_power_state_index =
195 rdev->pm.current_power_state_index + 1;
197 rdev->pm.requested_clock_mode_index = 0;
199 case DYNPM_ACTION_DEFAULT:
200 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
201 rdev->pm.requested_clock_mode_index = 0;
202 rdev->pm.dynpm_can_upclock = false;
204 case DYNPM_ACTION_NONE:
206 DRM_ERROR("Requested mode for not defined action\n");
210 /* XXX select a power state based on AC/DC, single/dualhead, etc. */
211 /* for now just select the first power state and switch between clock modes */
212 /* power state array is low to high, default is first (0) */
213 if (rdev->pm.active_crtc_count > 1) {
214 rdev->pm.requested_power_state_index = -1;
215 /* start at 1 as we don't want the default mode */
216 for (i = 1; i < rdev->pm.num_power_states; i++) {
217 if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
219 else if ((rdev->pm.power_state[i].type == POWER_STATE_TYPE_PERFORMANCE) ||
220 (rdev->pm.power_state[i].type == POWER_STATE_TYPE_BATTERY)) {
221 rdev->pm.requested_power_state_index = i;
225 /* if nothing selected, grab the default state. */
226 if (rdev->pm.requested_power_state_index == -1)
227 rdev->pm.requested_power_state_index = 0;
229 rdev->pm.requested_power_state_index = 1;
231 switch (rdev->pm.dynpm_planned_action) {
232 case DYNPM_ACTION_MINIMUM:
233 rdev->pm.requested_clock_mode_index = 0;
234 rdev->pm.dynpm_can_downclock = false;
236 case DYNPM_ACTION_DOWNCLOCK:
237 if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
238 if (rdev->pm.current_clock_mode_index == 0) {
239 rdev->pm.requested_clock_mode_index = 0;
240 rdev->pm.dynpm_can_downclock = false;
242 rdev->pm.requested_clock_mode_index =
243 rdev->pm.current_clock_mode_index - 1;
245 rdev->pm.requested_clock_mode_index = 0;
246 rdev->pm.dynpm_can_downclock = false;
248 /* don't use the power state if crtcs are active and no display flag is set */
249 if ((rdev->pm.active_crtc_count > 0) &&
250 (rdev->pm.power_state[rdev->pm.requested_power_state_index].
251 clock_info[rdev->pm.requested_clock_mode_index].flags &
252 RADEON_PM_MODE_NO_DISPLAY)) {
253 rdev->pm.requested_clock_mode_index++;
256 case DYNPM_ACTION_UPCLOCK:
257 if (rdev->pm.requested_power_state_index == rdev->pm.current_power_state_index) {
258 if (rdev->pm.current_clock_mode_index ==
259 (rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1)) {
260 rdev->pm.requested_clock_mode_index = rdev->pm.current_clock_mode_index;
261 rdev->pm.dynpm_can_upclock = false;
263 rdev->pm.requested_clock_mode_index =
264 rdev->pm.current_clock_mode_index + 1;
266 rdev->pm.requested_clock_mode_index =
267 rdev->pm.power_state[rdev->pm.requested_power_state_index].num_clock_modes - 1;
268 rdev->pm.dynpm_can_upclock = false;
271 case DYNPM_ACTION_DEFAULT:
272 rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
273 rdev->pm.requested_clock_mode_index = 0;
274 rdev->pm.dynpm_can_upclock = false;
276 case DYNPM_ACTION_NONE:
278 DRM_ERROR("Requested mode for not defined action\n");
283 DRM_DEBUG_DRIVER("Requested: e: %d m: %d p: %d\n",
284 rdev->pm.power_state[rdev->pm.requested_power_state_index].
285 clock_info[rdev->pm.requested_clock_mode_index].sclk,
286 rdev->pm.power_state[rdev->pm.requested_power_state_index].
287 clock_info[rdev->pm.requested_clock_mode_index].mclk,
288 rdev->pm.power_state[rdev->pm.requested_power_state_index].
292 void rs780_pm_init_profile(struct radeon_device *rdev)
294 if (rdev->pm.num_power_states == 2) {
296 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
297 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
298 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
299 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
301 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0;
302 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0;
303 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
304 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
306 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0;
307 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 0;
308 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
309 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
311 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0;
312 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
313 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
314 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
316 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0;
317 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
318 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
319 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
321 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0;
322 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
323 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
324 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
326 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0;
327 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 1;
328 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
329 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
330 } else if (rdev->pm.num_power_states == 3) {
332 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
333 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
334 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
335 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
337 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
338 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
339 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
340 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
342 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
343 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
344 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
345 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
347 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
348 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 2;
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 = 1;
353 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 1;
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_MID_MH_IDX].dpms_off_ps_idx = 1;
358 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 1;
359 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
360 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
362 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 1;
363 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
364 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
365 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
368 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
369 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
370 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
371 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
373 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 2;
374 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 2;
375 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
376 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
378 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 2;
379 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 2;
380 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
381 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
383 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 2;
384 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 3;
385 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
386 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
388 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
389 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 0;
390 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
391 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
393 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
394 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 0;
395 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
396 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
398 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
399 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 3;
400 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
401 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
405 void r600_pm_init_profile(struct radeon_device *rdev)
409 if (rdev->family == CHIP_R600) {
412 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
413 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
414 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
415 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
417 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
418 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
419 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
420 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
422 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
423 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
424 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
425 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
427 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
428 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
429 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
430 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
432 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
433 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
434 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
435 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
437 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
438 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
439 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
440 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
442 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
443 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
444 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
445 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
447 if (rdev->pm.num_power_states < 4) {
449 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
450 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
451 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
452 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
454 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 1;
455 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 1;
456 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
457 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
459 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 1;
460 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
461 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
462 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
464 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 1;
465 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 1;
466 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
467 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
469 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 2;
470 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 2;
471 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
472 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
474 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 2;
475 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 2;
476 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
477 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
479 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 2;
480 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 2;
481 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
482 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
485 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
486 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
487 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
488 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
490 if (rdev->flags & RADEON_IS_MOBILITY)
491 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
493 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
494 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
495 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
496 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
497 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
499 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
500 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
501 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
502 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
504 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
505 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
506 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
507 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
508 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
510 if (rdev->flags & RADEON_IS_MOBILITY)
511 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
513 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
514 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
515 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
516 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
517 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
519 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
520 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
521 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
522 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
524 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
525 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
526 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
527 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
528 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
533 void r600_pm_misc(struct radeon_device *rdev)
535 int req_ps_idx = rdev->pm.requested_power_state_index;
536 int req_cm_idx = rdev->pm.requested_clock_mode_index;
537 struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
538 struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
540 if ((voltage->type == VOLTAGE_SW) && voltage->voltage) {
541 /* 0xff01 is a flag rather then an actual voltage */
542 if (voltage->voltage == 0xff01)
544 if (voltage->voltage != rdev->pm.current_vddc) {
545 radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
546 rdev->pm.current_vddc = voltage->voltage;
547 DRM_DEBUG_DRIVER("Setting: v: %d\n", voltage->voltage);
552 bool r600_gui_idle(struct radeon_device *rdev)
554 if (RREG32(GRBM_STATUS) & GUI_ACTIVE)
560 /* hpd for digital panel detect/disconnect */
561 bool r600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
563 bool connected = false;
565 if (ASIC_IS_DCE3(rdev)) {
568 if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
572 if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
576 if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
580 if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
585 if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
589 if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
598 if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
602 if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
606 if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
616 void r600_hpd_set_polarity(struct radeon_device *rdev,
617 enum radeon_hpd_id hpd)
620 bool connected = r600_hpd_sense(rdev, hpd);
622 if (ASIC_IS_DCE3(rdev)) {
625 tmp = RREG32(DC_HPD1_INT_CONTROL);
627 tmp &= ~DC_HPDx_INT_POLARITY;
629 tmp |= DC_HPDx_INT_POLARITY;
630 WREG32(DC_HPD1_INT_CONTROL, tmp);
633 tmp = RREG32(DC_HPD2_INT_CONTROL);
635 tmp &= ~DC_HPDx_INT_POLARITY;
637 tmp |= DC_HPDx_INT_POLARITY;
638 WREG32(DC_HPD2_INT_CONTROL, tmp);
641 tmp = RREG32(DC_HPD3_INT_CONTROL);
643 tmp &= ~DC_HPDx_INT_POLARITY;
645 tmp |= DC_HPDx_INT_POLARITY;
646 WREG32(DC_HPD3_INT_CONTROL, tmp);
649 tmp = RREG32(DC_HPD4_INT_CONTROL);
651 tmp &= ~DC_HPDx_INT_POLARITY;
653 tmp |= DC_HPDx_INT_POLARITY;
654 WREG32(DC_HPD4_INT_CONTROL, tmp);
657 tmp = RREG32(DC_HPD5_INT_CONTROL);
659 tmp &= ~DC_HPDx_INT_POLARITY;
661 tmp |= DC_HPDx_INT_POLARITY;
662 WREG32(DC_HPD5_INT_CONTROL, tmp);
666 tmp = RREG32(DC_HPD6_INT_CONTROL);
668 tmp &= ~DC_HPDx_INT_POLARITY;
670 tmp |= DC_HPDx_INT_POLARITY;
671 WREG32(DC_HPD6_INT_CONTROL, tmp);
679 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
681 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
683 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
684 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
687 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
689 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
691 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
692 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
695 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
697 tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
699 tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
700 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
708 void r600_hpd_init(struct radeon_device *rdev)
710 struct drm_device *dev = rdev->ddev;
711 struct drm_connector *connector;
714 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
715 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
717 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
718 connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
719 /* don't try to enable hpd on eDP or LVDS avoid breaking the
720 * aux dp channel on imac and help (but not completely fix)
721 * https://bugzilla.redhat.com/show_bug.cgi?id=726143
725 if (ASIC_IS_DCE3(rdev)) {
726 u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
727 if (ASIC_IS_DCE32(rdev))
730 switch (radeon_connector->hpd.hpd) {
732 WREG32(DC_HPD1_CONTROL, tmp);
735 WREG32(DC_HPD2_CONTROL, tmp);
738 WREG32(DC_HPD3_CONTROL, tmp);
741 WREG32(DC_HPD4_CONTROL, tmp);
745 WREG32(DC_HPD5_CONTROL, tmp);
748 WREG32(DC_HPD6_CONTROL, tmp);
754 switch (radeon_connector->hpd.hpd) {
756 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN);
759 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, DC_HOT_PLUG_DETECTx_EN);
762 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, DC_HOT_PLUG_DETECTx_EN);
768 enable |= 1 << radeon_connector->hpd.hpd;
769 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
771 radeon_irq_kms_enable_hpd(rdev, enable);
774 void r600_hpd_fini(struct radeon_device *rdev)
776 struct drm_device *dev = rdev->ddev;
777 struct drm_connector *connector;
778 unsigned disable = 0;
780 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
781 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
782 if (ASIC_IS_DCE3(rdev)) {
783 switch (radeon_connector->hpd.hpd) {
785 WREG32(DC_HPD1_CONTROL, 0);
788 WREG32(DC_HPD2_CONTROL, 0);
791 WREG32(DC_HPD3_CONTROL, 0);
794 WREG32(DC_HPD4_CONTROL, 0);
798 WREG32(DC_HPD5_CONTROL, 0);
801 WREG32(DC_HPD6_CONTROL, 0);
807 switch (radeon_connector->hpd.hpd) {
809 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, 0);
812 WREG32(DC_HOT_PLUG_DETECT2_CONTROL, 0);
815 WREG32(DC_HOT_PLUG_DETECT3_CONTROL, 0);
821 disable |= 1 << radeon_connector->hpd.hpd;
823 radeon_irq_kms_disable_hpd(rdev, disable);
829 void r600_pcie_gart_tlb_flush(struct radeon_device *rdev)
834 /* flush hdp cache so updates hit vram */
835 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
836 !(rdev->flags & RADEON_IS_AGP)) {
837 void __iomem *ptr = (void *)rdev->gart.ptr;
840 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
841 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL
842 * This seems to cause problems on some AGP cards. Just use the old
845 WREG32(HDP_DEBUG1, 0);
846 tmp = readl((void __iomem *)ptr);
848 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
850 WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR, rdev->mc.gtt_start >> 12);
851 WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR, (rdev->mc.gtt_end - 1) >> 12);
852 WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
853 for (i = 0; i < rdev->usec_timeout; i++) {
855 tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
856 tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
858 printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
868 int r600_pcie_gart_init(struct radeon_device *rdev)
872 if (rdev->gart.robj) {
873 WARN(1, "R600 PCIE GART already initialized\n");
876 /* Initialize common gart structure */
877 r = radeon_gart_init(rdev);
880 rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
881 return radeon_gart_table_vram_alloc(rdev);
884 static int r600_pcie_gart_enable(struct radeon_device *rdev)
889 if (rdev->gart.robj == NULL) {
890 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
893 r = radeon_gart_table_vram_pin(rdev);
896 radeon_gart_restore(rdev);
899 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
900 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
901 EFFECTIVE_L2_QUEUE_SIZE(7));
902 WREG32(VM_L2_CNTL2, 0);
903 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
904 /* Setup TLB control */
905 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
906 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
907 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
908 ENABLE_WAIT_L2_QUERY;
909 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
910 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
911 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
912 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
913 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
914 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
915 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
916 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
917 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
918 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
919 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
920 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
921 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
922 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
923 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
924 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
925 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
926 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
927 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
928 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
929 (u32)(rdev->dummy_page.addr >> 12));
930 for (i = 1; i < 7; i++)
931 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
933 r600_pcie_gart_tlb_flush(rdev);
934 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
935 (unsigned)(rdev->mc.gtt_size >> 20),
936 (unsigned long long)rdev->gart.table_addr);
937 rdev->gart.ready = true;
941 static void r600_pcie_gart_disable(struct radeon_device *rdev)
946 /* Disable all tables */
947 for (i = 0; i < 7; i++)
948 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
950 /* Disable L2 cache */
951 WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
952 EFFECTIVE_L2_QUEUE_SIZE(7));
953 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
954 /* Setup L1 TLB control */
955 tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
956 ENABLE_WAIT_L2_QUERY;
957 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
958 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
959 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
960 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
961 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
962 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
963 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
964 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
965 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp);
966 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp);
967 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
968 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
969 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp);
970 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
971 radeon_gart_table_vram_unpin(rdev);
974 static void r600_pcie_gart_fini(struct radeon_device *rdev)
976 radeon_gart_fini(rdev);
977 r600_pcie_gart_disable(rdev);
978 radeon_gart_table_vram_free(rdev);
981 static void r600_agp_enable(struct radeon_device *rdev)
987 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
988 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
989 EFFECTIVE_L2_QUEUE_SIZE(7));
990 WREG32(VM_L2_CNTL2, 0);
991 WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
992 /* Setup TLB control */
993 tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
994 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
995 EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
996 ENABLE_WAIT_L2_QUERY;
997 WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
998 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
999 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
1000 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
1001 WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
1002 WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
1003 WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
1004 WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
1005 WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
1006 WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
1007 WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
1008 WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
1009 WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
1010 WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
1011 for (i = 0; i < 7; i++)
1012 WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
1015 int r600_mc_wait_for_idle(struct radeon_device *rdev)
1020 for (i = 0; i < rdev->usec_timeout; i++) {
1021 /* read MC_STATUS */
1022 tmp = RREG32(R_000E50_SRBM_STATUS) & 0x3F00;
1030 static void r600_mc_program(struct radeon_device *rdev)
1032 struct rv515_mc_save save;
1036 /* Initialize HDP */
1037 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1038 WREG32((0x2c14 + j), 0x00000000);
1039 WREG32((0x2c18 + j), 0x00000000);
1040 WREG32((0x2c1c + j), 0x00000000);
1041 WREG32((0x2c20 + j), 0x00000000);
1042 WREG32((0x2c24 + j), 0x00000000);
1044 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
1046 rv515_mc_stop(rdev, &save);
1047 if (r600_mc_wait_for_idle(rdev)) {
1048 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
1050 /* Lockout access through VGA aperture (doesn't exist before R600) */
1051 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
1052 /* Update configuration */
1053 if (rdev->flags & RADEON_IS_AGP) {
1054 if (rdev->mc.vram_start < rdev->mc.gtt_start) {
1055 /* VRAM before AGP */
1056 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1057 rdev->mc.vram_start >> 12);
1058 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1059 rdev->mc.gtt_end >> 12);
1061 /* VRAM after AGP */
1062 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
1063 rdev->mc.gtt_start >> 12);
1064 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1065 rdev->mc.vram_end >> 12);
1068 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12);
1069 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12);
1071 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
1072 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
1073 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
1074 WREG32(MC_VM_FB_LOCATION, tmp);
1075 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
1076 WREG32(HDP_NONSURFACE_INFO, (2 << 7));
1077 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
1078 if (rdev->flags & RADEON_IS_AGP) {
1079 WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 22);
1080 WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 22);
1081 WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
1083 WREG32(MC_VM_AGP_BASE, 0);
1084 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
1085 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
1087 if (r600_mc_wait_for_idle(rdev)) {
1088 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
1090 rv515_mc_resume(rdev, &save);
1091 /* we need to own VRAM, so turn off the VGA renderer here
1092 * to stop it overwriting our objects */
1093 rv515_vga_render_disable(rdev);
1097 * r600_vram_gtt_location - try to find VRAM & GTT location
1098 * @rdev: radeon device structure holding all necessary informations
1099 * @mc: memory controller structure holding memory informations
1101 * Function will place try to place VRAM at same place as in CPU (PCI)
1102 * address space as some GPU seems to have issue when we reprogram at
1103 * different address space.
1105 * If there is not enough space to fit the unvisible VRAM after the
1106 * aperture then we limit the VRAM size to the aperture.
1108 * If we are using AGP then place VRAM adjacent to AGP aperture are we need
1109 * them to be in one from GPU point of view so that we can program GPU to
1110 * catch access outside them (weird GPU policy see ??).
1112 * This function will never fails, worst case are limiting VRAM or GTT.
1114 * Note: GTT start, end, size should be initialized before calling this
1115 * function on AGP platform.
1117 static void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
1119 u64 size_bf, size_af;
1121 if (mc->mc_vram_size > 0xE0000000) {
1122 /* leave room for at least 512M GTT */
1123 dev_warn(rdev->dev, "limiting VRAM\n");
1124 mc->real_vram_size = 0xE0000000;
1125 mc->mc_vram_size = 0xE0000000;
1127 if (rdev->flags & RADEON_IS_AGP) {
1128 size_bf = mc->gtt_start;
1129 size_af = 0xFFFFFFFF - mc->gtt_end;
1130 if (size_bf > size_af) {
1131 if (mc->mc_vram_size > size_bf) {
1132 dev_warn(rdev->dev, "limiting VRAM\n");
1133 mc->real_vram_size = size_bf;
1134 mc->mc_vram_size = size_bf;
1136 mc->vram_start = mc->gtt_start - mc->mc_vram_size;
1138 if (mc->mc_vram_size > size_af) {
1139 dev_warn(rdev->dev, "limiting VRAM\n");
1140 mc->real_vram_size = size_af;
1141 mc->mc_vram_size = size_af;
1143 mc->vram_start = mc->gtt_end + 1;
1145 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
1146 dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
1147 mc->mc_vram_size >> 20, mc->vram_start,
1148 mc->vram_end, mc->real_vram_size >> 20);
1151 if (rdev->flags & RADEON_IS_IGP) {
1152 base = RREG32(MC_VM_FB_LOCATION) & 0xFFFF;
1155 radeon_vram_location(rdev, &rdev->mc, base);
1156 rdev->mc.gtt_base_align = 0;
1157 radeon_gtt_location(rdev, mc);
1161 static int r600_mc_init(struct radeon_device *rdev)
1164 int chansize, numchan;
1166 /* Get VRAM informations */
1167 rdev->mc.vram_is_ddr = true;
1168 tmp = RREG32(RAMCFG);
1169 if (tmp & CHANSIZE_OVERRIDE) {
1171 } else if (tmp & CHANSIZE_MASK) {
1176 tmp = RREG32(CHMAP);
1177 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
1192 rdev->mc.vram_width = numchan * chansize;
1193 /* Could aper size report 0 ? */
1194 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
1195 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
1196 /* Setup GPU memory space */
1197 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
1198 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
1199 rdev->mc.visible_vram_size = rdev->mc.aper_size;
1200 r600_vram_gtt_location(rdev, &rdev->mc);
1202 if (rdev->flags & RADEON_IS_IGP) {
1203 rs690_pm_info(rdev);
1204 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
1206 radeon_update_bandwidth_info(rdev);
1210 int r600_vram_scratch_init(struct radeon_device *rdev)
1214 if (rdev->vram_scratch.robj == NULL) {
1215 r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE,
1216 PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
1217 NULL, &rdev->vram_scratch.robj);
1223 r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
1224 if (unlikely(r != 0))
1226 r = radeon_bo_pin(rdev->vram_scratch.robj,
1227 RADEON_GEM_DOMAIN_VRAM, &rdev->vram_scratch.gpu_addr);
1229 radeon_bo_unreserve(rdev->vram_scratch.robj);
1232 r = radeon_bo_kmap(rdev->vram_scratch.robj,
1233 (void **)&rdev->vram_scratch.ptr);
1235 radeon_bo_unpin(rdev->vram_scratch.robj);
1236 radeon_bo_unreserve(rdev->vram_scratch.robj);
1241 void r600_vram_scratch_fini(struct radeon_device *rdev)
1245 if (rdev->vram_scratch.robj == NULL) {
1248 r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
1249 if (likely(r == 0)) {
1250 radeon_bo_kunmap(rdev->vram_scratch.robj);
1251 radeon_bo_unpin(rdev->vram_scratch.robj);
1252 radeon_bo_unreserve(rdev->vram_scratch.robj);
1254 radeon_bo_unref(&rdev->vram_scratch.robj);
1257 /* We doesn't check that the GPU really needs a reset we simply do the
1258 * reset, it's up to the caller to determine if the GPU needs one. We
1259 * might add an helper function to check that.
1261 static int r600_gpu_soft_reset(struct radeon_device *rdev)
1263 struct rv515_mc_save save;
1264 u32 grbm_busy_mask = S_008010_VC_BUSY(1) | S_008010_VGT_BUSY_NO_DMA(1) |
1265 S_008010_VGT_BUSY(1) | S_008010_TA03_BUSY(1) |
1266 S_008010_TC_BUSY(1) | S_008010_SX_BUSY(1) |
1267 S_008010_SH_BUSY(1) | S_008010_SPI03_BUSY(1) |
1268 S_008010_SMX_BUSY(1) | S_008010_SC_BUSY(1) |
1269 S_008010_PA_BUSY(1) | S_008010_DB03_BUSY(1) |
1270 S_008010_CR_BUSY(1) | S_008010_CB03_BUSY(1) |
1271 S_008010_GUI_ACTIVE(1);
1272 u32 grbm2_busy_mask = S_008014_SPI0_BUSY(1) | S_008014_SPI1_BUSY(1) |
1273 S_008014_SPI2_BUSY(1) | S_008014_SPI3_BUSY(1) |
1274 S_008014_TA0_BUSY(1) | S_008014_TA1_BUSY(1) |
1275 S_008014_TA2_BUSY(1) | S_008014_TA3_BUSY(1) |
1276 S_008014_DB0_BUSY(1) | S_008014_DB1_BUSY(1) |
1277 S_008014_DB2_BUSY(1) | S_008014_DB3_BUSY(1) |
1278 S_008014_CB0_BUSY(1) | S_008014_CB1_BUSY(1) |
1279 S_008014_CB2_BUSY(1) | S_008014_CB3_BUSY(1);
1282 if (!(RREG32(GRBM_STATUS) & GUI_ACTIVE))
1285 dev_info(rdev->dev, "GPU softreset \n");
1286 dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
1287 RREG32(R_008010_GRBM_STATUS));
1288 dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
1289 RREG32(R_008014_GRBM_STATUS2));
1290 dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
1291 RREG32(R_000E50_SRBM_STATUS));
1292 dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n",
1293 RREG32(CP_STALLED_STAT1));
1294 dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n",
1295 RREG32(CP_STALLED_STAT2));
1296 dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n",
1297 RREG32(CP_BUSY_STAT));
1298 dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n",
1300 rv515_mc_stop(rdev, &save);
1301 if (r600_mc_wait_for_idle(rdev)) {
1302 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
1304 /* Disable CP parsing/prefetching */
1305 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
1306 /* Check if any of the rendering block is busy and reset it */
1307 if ((RREG32(R_008010_GRBM_STATUS) & grbm_busy_mask) ||
1308 (RREG32(R_008014_GRBM_STATUS2) & grbm2_busy_mask)) {
1309 tmp = S_008020_SOFT_RESET_CR(1) |
1310 S_008020_SOFT_RESET_DB(1) |
1311 S_008020_SOFT_RESET_CB(1) |
1312 S_008020_SOFT_RESET_PA(1) |
1313 S_008020_SOFT_RESET_SC(1) |
1314 S_008020_SOFT_RESET_SMX(1) |
1315 S_008020_SOFT_RESET_SPI(1) |
1316 S_008020_SOFT_RESET_SX(1) |
1317 S_008020_SOFT_RESET_SH(1) |
1318 S_008020_SOFT_RESET_TC(1) |
1319 S_008020_SOFT_RESET_TA(1) |
1320 S_008020_SOFT_RESET_VC(1) |
1321 S_008020_SOFT_RESET_VGT(1);
1322 dev_info(rdev->dev, " R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
1323 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
1324 RREG32(R_008020_GRBM_SOFT_RESET);
1326 WREG32(R_008020_GRBM_SOFT_RESET, 0);
1328 /* Reset CP (we always reset CP) */
1329 tmp = S_008020_SOFT_RESET_CP(1);
1330 dev_info(rdev->dev, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
1331 WREG32(R_008020_GRBM_SOFT_RESET, tmp);
1332 RREG32(R_008020_GRBM_SOFT_RESET);
1334 WREG32(R_008020_GRBM_SOFT_RESET, 0);
1335 /* Wait a little for things to settle down */
1337 dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
1338 RREG32(R_008010_GRBM_STATUS));
1339 dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
1340 RREG32(R_008014_GRBM_STATUS2));
1341 dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
1342 RREG32(R_000E50_SRBM_STATUS));
1343 dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n",
1344 RREG32(CP_STALLED_STAT1));
1345 dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n",
1346 RREG32(CP_STALLED_STAT2));
1347 dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n",
1348 RREG32(CP_BUSY_STAT));
1349 dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n",
1351 rv515_mc_resume(rdev, &save);
1355 bool r600_gpu_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
1361 srbm_status = RREG32(R_000E50_SRBM_STATUS);
1362 grbm_status = RREG32(R_008010_GRBM_STATUS);
1363 grbm_status2 = RREG32(R_008014_GRBM_STATUS2);
1364 if (!G_008010_GUI_ACTIVE(grbm_status)) {
1365 radeon_ring_lockup_update(ring);
1368 /* force CP activities */
1369 radeon_ring_force_activity(rdev, ring);
1370 return radeon_ring_test_lockup(rdev, ring);
1374 * r600_dma_is_lockup - Check if the DMA engine is locked up
1376 * @rdev: radeon_device pointer
1377 * @ring: radeon_ring structure holding ring information
1379 * Check if the async DMA engine is locked up (r6xx-evergreen).
1380 * Returns true if the engine appears to be locked up, false if not.
1382 bool r600_dma_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
1386 dma_status_reg = RREG32(DMA_STATUS_REG);
1387 if (dma_status_reg & DMA_IDLE) {
1388 radeon_ring_lockup_update(ring);
1391 /* force ring activities */
1392 radeon_ring_force_activity(rdev, ring);
1393 return radeon_ring_test_lockup(rdev, ring);
1396 int r600_asic_reset(struct radeon_device *rdev)
1398 return r600_gpu_soft_reset(rdev);
1401 u32 r6xx_remap_render_backend(struct radeon_device *rdev,
1402 u32 tiling_pipe_num,
1404 u32 total_max_rb_num,
1405 u32 disabled_rb_mask)
1407 u32 rendering_pipe_num, rb_num_width, req_rb_num;
1408 u32 pipe_rb_ratio, pipe_rb_remain;
1409 u32 data = 0, mask = 1 << (max_rb_num - 1);
1412 /* mask out the RBs that don't exist on that asic */
1413 disabled_rb_mask |= (0xff << max_rb_num) & 0xff;
1415 rendering_pipe_num = 1 << tiling_pipe_num;
1416 req_rb_num = total_max_rb_num - r600_count_pipe_bits(disabled_rb_mask);
1417 BUG_ON(rendering_pipe_num < req_rb_num);
1419 pipe_rb_ratio = rendering_pipe_num / req_rb_num;
1420 pipe_rb_remain = rendering_pipe_num - pipe_rb_ratio * req_rb_num;
1422 if (rdev->family <= CHIP_RV740) {
1430 for (i = 0; i < max_rb_num; i++) {
1431 if (!(mask & disabled_rb_mask)) {
1432 for (j = 0; j < pipe_rb_ratio; j++) {
1433 data <<= rb_num_width;
1434 data |= max_rb_num - i - 1;
1436 if (pipe_rb_remain) {
1437 data <<= rb_num_width;
1438 data |= max_rb_num - i - 1;
1448 int r600_count_pipe_bits(uint32_t val)
1450 return hweight32(val);
1453 static void r600_gpu_init(struct radeon_device *rdev)
1457 u32 cc_rb_backend_disable;
1458 u32 cc_gc_shader_pipe_config;
1462 u32 sq_gpr_resource_mgmt_1 = 0;
1463 u32 sq_gpr_resource_mgmt_2 = 0;
1464 u32 sq_thread_resource_mgmt = 0;
1465 u32 sq_stack_resource_mgmt_1 = 0;
1466 u32 sq_stack_resource_mgmt_2 = 0;
1467 u32 disabled_rb_mask;
1469 rdev->config.r600.tiling_group_size = 256;
1470 switch (rdev->family) {
1472 rdev->config.r600.max_pipes = 4;
1473 rdev->config.r600.max_tile_pipes = 8;
1474 rdev->config.r600.max_simds = 4;
1475 rdev->config.r600.max_backends = 4;
1476 rdev->config.r600.max_gprs = 256;
1477 rdev->config.r600.max_threads = 192;
1478 rdev->config.r600.max_stack_entries = 256;
1479 rdev->config.r600.max_hw_contexts = 8;
1480 rdev->config.r600.max_gs_threads = 16;
1481 rdev->config.r600.sx_max_export_size = 128;
1482 rdev->config.r600.sx_max_export_pos_size = 16;
1483 rdev->config.r600.sx_max_export_smx_size = 128;
1484 rdev->config.r600.sq_num_cf_insts = 2;
1488 rdev->config.r600.max_pipes = 2;
1489 rdev->config.r600.max_tile_pipes = 2;
1490 rdev->config.r600.max_simds = 3;
1491 rdev->config.r600.max_backends = 1;
1492 rdev->config.r600.max_gprs = 128;
1493 rdev->config.r600.max_threads = 192;
1494 rdev->config.r600.max_stack_entries = 128;
1495 rdev->config.r600.max_hw_contexts = 8;
1496 rdev->config.r600.max_gs_threads = 4;
1497 rdev->config.r600.sx_max_export_size = 128;
1498 rdev->config.r600.sx_max_export_pos_size = 16;
1499 rdev->config.r600.sx_max_export_smx_size = 128;
1500 rdev->config.r600.sq_num_cf_insts = 2;
1506 rdev->config.r600.max_pipes = 1;
1507 rdev->config.r600.max_tile_pipes = 1;
1508 rdev->config.r600.max_simds = 2;
1509 rdev->config.r600.max_backends = 1;
1510 rdev->config.r600.max_gprs = 128;
1511 rdev->config.r600.max_threads = 192;
1512 rdev->config.r600.max_stack_entries = 128;
1513 rdev->config.r600.max_hw_contexts = 4;
1514 rdev->config.r600.max_gs_threads = 4;
1515 rdev->config.r600.sx_max_export_size = 128;
1516 rdev->config.r600.sx_max_export_pos_size = 16;
1517 rdev->config.r600.sx_max_export_smx_size = 128;
1518 rdev->config.r600.sq_num_cf_insts = 1;
1521 rdev->config.r600.max_pipes = 4;
1522 rdev->config.r600.max_tile_pipes = 4;
1523 rdev->config.r600.max_simds = 4;
1524 rdev->config.r600.max_backends = 4;
1525 rdev->config.r600.max_gprs = 192;
1526 rdev->config.r600.max_threads = 192;
1527 rdev->config.r600.max_stack_entries = 256;
1528 rdev->config.r600.max_hw_contexts = 8;
1529 rdev->config.r600.max_gs_threads = 16;
1530 rdev->config.r600.sx_max_export_size = 128;
1531 rdev->config.r600.sx_max_export_pos_size = 16;
1532 rdev->config.r600.sx_max_export_smx_size = 128;
1533 rdev->config.r600.sq_num_cf_insts = 2;
1539 /* Initialize HDP */
1540 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
1541 WREG32((0x2c14 + j), 0x00000000);
1542 WREG32((0x2c18 + j), 0x00000000);
1543 WREG32((0x2c1c + j), 0x00000000);
1544 WREG32((0x2c20 + j), 0x00000000);
1545 WREG32((0x2c24 + j), 0x00000000);
1548 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
1552 ramcfg = RREG32(RAMCFG);
1553 switch (rdev->config.r600.max_tile_pipes) {
1555 tiling_config |= PIPE_TILING(0);
1558 tiling_config |= PIPE_TILING(1);
1561 tiling_config |= PIPE_TILING(2);
1564 tiling_config |= PIPE_TILING(3);
1569 rdev->config.r600.tiling_npipes = rdev->config.r600.max_tile_pipes;
1570 rdev->config.r600.tiling_nbanks = 4 << ((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
1571 tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
1572 tiling_config |= GROUP_SIZE((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
1574 tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
1576 tiling_config |= ROW_TILING(3);
1577 tiling_config |= SAMPLE_SPLIT(3);
1579 tiling_config |= ROW_TILING(tmp);
1580 tiling_config |= SAMPLE_SPLIT(tmp);
1582 tiling_config |= BANK_SWAPS(1);
1584 cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
1585 tmp = R6XX_MAX_BACKENDS -
1586 r600_count_pipe_bits((cc_rb_backend_disable >> 16) & R6XX_MAX_BACKENDS_MASK);
1587 if (tmp < rdev->config.r600.max_backends) {
1588 rdev->config.r600.max_backends = tmp;
1591 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0x00ffff00;
1592 tmp = R6XX_MAX_PIPES -
1593 r600_count_pipe_bits((cc_gc_shader_pipe_config >> 8) & R6XX_MAX_PIPES_MASK);
1594 if (tmp < rdev->config.r600.max_pipes) {
1595 rdev->config.r600.max_pipes = tmp;
1597 tmp = R6XX_MAX_SIMDS -
1598 r600_count_pipe_bits((cc_gc_shader_pipe_config >> 16) & R6XX_MAX_SIMDS_MASK);
1599 if (tmp < rdev->config.r600.max_simds) {
1600 rdev->config.r600.max_simds = tmp;
1603 disabled_rb_mask = (RREG32(CC_RB_BACKEND_DISABLE) >> 16) & R6XX_MAX_BACKENDS_MASK;
1604 tmp = (tiling_config & PIPE_TILING__MASK) >> PIPE_TILING__SHIFT;
1605 tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.r600.max_backends,
1606 R6XX_MAX_BACKENDS, disabled_rb_mask);
1607 tiling_config |= tmp << 16;
1608 rdev->config.r600.backend_map = tmp;
1610 rdev->config.r600.tile_config = tiling_config;
1611 WREG32(GB_TILING_CONFIG, tiling_config);
1612 WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff);
1613 WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff);
1614 WREG32(DMA_TILING_CONFIG, tiling_config & 0xffff);
1616 tmp = R6XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8);
1617 WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK);
1618 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK);
1620 /* Setup some CP states */
1621 WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
1622 WREG32(CP_MEQ_THRESHOLDS, (MEQ_END(0x40) | ROQ_END(0x40)));
1624 WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO | SYNC_GRADIENT |
1625 SYNC_WALKER | SYNC_ALIGNER));
1626 /* Setup various GPU states */
1627 if (rdev->family == CHIP_RV670)
1628 WREG32(ARB_GDEC_RD_CNTL, 0x00000021);
1630 tmp = RREG32(SX_DEBUG_1);
1631 tmp |= SMX_EVENT_RELEASE;
1632 if ((rdev->family > CHIP_R600))
1633 tmp |= ENABLE_NEW_SMX_ADDRESS;
1634 WREG32(SX_DEBUG_1, tmp);
1636 if (((rdev->family) == CHIP_R600) ||
1637 ((rdev->family) == CHIP_RV630) ||
1638 ((rdev->family) == CHIP_RV610) ||
1639 ((rdev->family) == CHIP_RV620) ||
1640 ((rdev->family) == CHIP_RS780) ||
1641 ((rdev->family) == CHIP_RS880)) {
1642 WREG32(DB_DEBUG, PREZ_MUST_WAIT_FOR_POSTZ_DONE);
1644 WREG32(DB_DEBUG, 0);
1646 WREG32(DB_WATERMARKS, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
1647 DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
1649 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
1650 WREG32(VGT_NUM_INSTANCES, 0);
1652 WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
1653 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(0));
1655 tmp = RREG32(SQ_MS_FIFO_SIZES);
1656 if (((rdev->family) == CHIP_RV610) ||
1657 ((rdev->family) == CHIP_RV620) ||
1658 ((rdev->family) == CHIP_RS780) ||
1659 ((rdev->family) == CHIP_RS880)) {
1660 tmp = (CACHE_FIFO_SIZE(0xa) |
1661 FETCH_FIFO_HIWATER(0xa) |
1662 DONE_FIFO_HIWATER(0xe0) |
1663 ALU_UPDATE_FIFO_HIWATER(0x8));
1664 } else if (((rdev->family) == CHIP_R600) ||
1665 ((rdev->family) == CHIP_RV630)) {
1666 tmp &= ~DONE_FIFO_HIWATER(0xff);
1667 tmp |= DONE_FIFO_HIWATER(0x4);
1669 WREG32(SQ_MS_FIFO_SIZES, tmp);
1671 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
1672 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
1674 sq_config = RREG32(SQ_CONFIG);
1675 sq_config &= ~(PS_PRIO(3) |
1679 sq_config |= (DX9_CONSTS |
1686 if ((rdev->family) == CHIP_R600) {
1687 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(124) |
1689 NUM_CLAUSE_TEMP_GPRS(4));
1690 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(0) |
1692 sq_thread_resource_mgmt = (NUM_PS_THREADS(136) |
1693 NUM_VS_THREADS(48) |
1696 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(128) |
1697 NUM_VS_STACK_ENTRIES(128));
1698 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(0) |
1699 NUM_ES_STACK_ENTRIES(0));
1700 } else if (((rdev->family) == CHIP_RV610) ||
1701 ((rdev->family) == CHIP_RV620) ||
1702 ((rdev->family) == CHIP_RS780) ||
1703 ((rdev->family) == CHIP_RS880)) {
1704 /* no vertex cache */
1705 sq_config &= ~VC_ENABLE;
1707 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1709 NUM_CLAUSE_TEMP_GPRS(2));
1710 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1712 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1713 NUM_VS_THREADS(78) |
1715 NUM_ES_THREADS(31));
1716 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1717 NUM_VS_STACK_ENTRIES(40));
1718 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1719 NUM_ES_STACK_ENTRIES(16));
1720 } else if (((rdev->family) == CHIP_RV630) ||
1721 ((rdev->family) == CHIP_RV635)) {
1722 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1724 NUM_CLAUSE_TEMP_GPRS(2));
1725 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(18) |
1727 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1728 NUM_VS_THREADS(78) |
1730 NUM_ES_THREADS(31));
1731 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
1732 NUM_VS_STACK_ENTRIES(40));
1733 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
1734 NUM_ES_STACK_ENTRIES(16));
1735 } else if ((rdev->family) == CHIP_RV670) {
1736 sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
1738 NUM_CLAUSE_TEMP_GPRS(2));
1739 sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
1741 sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
1742 NUM_VS_THREADS(78) |
1744 NUM_ES_THREADS(31));
1745 sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(64) |
1746 NUM_VS_STACK_ENTRIES(64));
1747 sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(64) |
1748 NUM_ES_STACK_ENTRIES(64));
1751 WREG32(SQ_CONFIG, sq_config);
1752 WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
1753 WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
1754 WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
1755 WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
1756 WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
1758 if (((rdev->family) == CHIP_RV610) ||
1759 ((rdev->family) == CHIP_RV620) ||
1760 ((rdev->family) == CHIP_RS780) ||
1761 ((rdev->family) == CHIP_RS880)) {
1762 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(TC_ONLY));
1764 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC));
1767 /* More default values. 2D/3D driver should adjust as needed */
1768 WREG32(PA_SC_AA_SAMPLE_LOCS_2S, (S0_X(0xc) | S0_Y(0x4) |
1769 S1_X(0x4) | S1_Y(0xc)));
1770 WREG32(PA_SC_AA_SAMPLE_LOCS_4S, (S0_X(0xe) | S0_Y(0xe) |
1771 S1_X(0x2) | S1_Y(0x2) |
1772 S2_X(0xa) | S2_Y(0x6) |
1773 S3_X(0x6) | S3_Y(0xa)));
1774 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0, (S0_X(0xe) | S0_Y(0xb) |
1775 S1_X(0x4) | S1_Y(0xc) |
1776 S2_X(0x1) | S2_Y(0x6) |
1777 S3_X(0xa) | S3_Y(0xe)));
1778 WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1, (S4_X(0x6) | S4_Y(0x1) |
1779 S5_X(0x0) | S5_Y(0x0) |
1780 S6_X(0xb) | S6_Y(0x4) |
1781 S7_X(0x7) | S7_Y(0x8)));
1783 WREG32(VGT_STRMOUT_EN, 0);
1784 tmp = rdev->config.r600.max_pipes * 16;
1785 switch (rdev->family) {
1801 WREG32(VGT_ES_PER_GS, 128);
1802 WREG32(VGT_GS_PER_ES, tmp);
1803 WREG32(VGT_GS_PER_VS, 2);
1804 WREG32(VGT_GS_VERTEX_REUSE, 16);
1806 /* more default values. 2D/3D driver should adjust as needed */
1807 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
1808 WREG32(VGT_STRMOUT_EN, 0);
1810 WREG32(PA_SC_MODE_CNTL, 0);
1811 WREG32(PA_SC_AA_CONFIG, 0);
1812 WREG32(PA_SC_LINE_STIPPLE, 0);
1813 WREG32(SPI_INPUT_Z, 0);
1814 WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
1815 WREG32(CB_COLOR7_FRAG, 0);
1817 /* Clear render buffer base addresses */
1818 WREG32(CB_COLOR0_BASE, 0);
1819 WREG32(CB_COLOR1_BASE, 0);
1820 WREG32(CB_COLOR2_BASE, 0);
1821 WREG32(CB_COLOR3_BASE, 0);
1822 WREG32(CB_COLOR4_BASE, 0);
1823 WREG32(CB_COLOR5_BASE, 0);
1824 WREG32(CB_COLOR6_BASE, 0);
1825 WREG32(CB_COLOR7_BASE, 0);
1826 WREG32(CB_COLOR7_FRAG, 0);
1828 switch (rdev->family) {
1833 tmp = TC_L2_SIZE(8);
1837 tmp = TC_L2_SIZE(4);
1840 tmp = TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT;
1843 tmp = TC_L2_SIZE(0);
1846 WREG32(TC_CNTL, tmp);
1848 tmp = RREG32(HDP_HOST_PATH_CNTL);
1849 WREG32(HDP_HOST_PATH_CNTL, tmp);
1851 tmp = RREG32(ARB_POP);
1852 tmp |= ENABLE_TC128;
1853 WREG32(ARB_POP, tmp);
1855 WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
1856 WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
1858 WREG32(PA_SC_ENHANCE, FORCE_EOV_MAX_CLK_CNT(4095));
1859 WREG32(VC_ENHANCE, 0);
1864 * Indirect registers accessor
1866 u32 r600_pciep_rreg(struct radeon_device *rdev, u32 reg)
1870 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
1871 (void)RREG32(PCIE_PORT_INDEX);
1872 r = RREG32(PCIE_PORT_DATA);
1876 void r600_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
1878 WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
1879 (void)RREG32(PCIE_PORT_INDEX);
1880 WREG32(PCIE_PORT_DATA, (v));
1881 (void)RREG32(PCIE_PORT_DATA);
1887 void r600_cp_stop(struct radeon_device *rdev)
1889 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
1890 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
1891 WREG32(SCRATCH_UMSK, 0);
1892 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
1895 int r600_init_microcode(struct radeon_device *rdev)
1897 struct platform_device *pdev;
1898 const char *chip_name;
1899 const char *rlc_chip_name;
1900 size_t pfp_req_size, me_req_size, rlc_req_size;
1906 pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
1909 printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
1913 switch (rdev->family) {
1916 rlc_chip_name = "R600";
1919 chip_name = "RV610";
1920 rlc_chip_name = "R600";
1923 chip_name = "RV630";
1924 rlc_chip_name = "R600";
1927 chip_name = "RV620";
1928 rlc_chip_name = "R600";
1931 chip_name = "RV635";
1932 rlc_chip_name = "R600";
1935 chip_name = "RV670";
1936 rlc_chip_name = "R600";
1940 chip_name = "RS780";
1941 rlc_chip_name = "R600";
1944 chip_name = "RV770";
1945 rlc_chip_name = "R700";
1949 chip_name = "RV730";
1950 rlc_chip_name = "R700";
1953 chip_name = "RV710";
1954 rlc_chip_name = "R700";
1957 chip_name = "CEDAR";
1958 rlc_chip_name = "CEDAR";
1961 chip_name = "REDWOOD";
1962 rlc_chip_name = "REDWOOD";
1965 chip_name = "JUNIPER";
1966 rlc_chip_name = "JUNIPER";
1970 chip_name = "CYPRESS";
1971 rlc_chip_name = "CYPRESS";
1975 rlc_chip_name = "SUMO";
1979 rlc_chip_name = "SUMO";
1982 chip_name = "SUMO2";
1983 rlc_chip_name = "SUMO";
1988 if (rdev->family >= CHIP_CEDAR) {
1989 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
1990 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
1991 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
1992 } else if (rdev->family >= CHIP_RV770) {
1993 pfp_req_size = R700_PFP_UCODE_SIZE * 4;
1994 me_req_size = R700_PM4_UCODE_SIZE * 4;
1995 rlc_req_size = R700_RLC_UCODE_SIZE * 4;
1997 pfp_req_size = PFP_UCODE_SIZE * 4;
1998 me_req_size = PM4_UCODE_SIZE * 12;
1999 rlc_req_size = RLC_UCODE_SIZE * 4;
2002 DRM_INFO("Loading %s Microcode\n", chip_name);
2004 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
2005 err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
2008 if (rdev->pfp_fw->size != pfp_req_size) {
2010 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2011 rdev->pfp_fw->size, fw_name);
2016 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
2017 err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
2020 if (rdev->me_fw->size != me_req_size) {
2022 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
2023 rdev->me_fw->size, fw_name);
2027 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
2028 err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
2031 if (rdev->rlc_fw->size != rlc_req_size) {
2033 "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
2034 rdev->rlc_fw->size, fw_name);
2039 platform_device_unregister(pdev);
2044 "r600_cp: Failed to load firmware \"%s\"\n",
2046 release_firmware(rdev->pfp_fw);
2047 rdev->pfp_fw = NULL;
2048 release_firmware(rdev->me_fw);
2050 release_firmware(rdev->rlc_fw);
2051 rdev->rlc_fw = NULL;
2056 static int r600_cp_load_microcode(struct radeon_device *rdev)
2058 const __be32 *fw_data;
2061 if (!rdev->me_fw || !rdev->pfp_fw)
2070 RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
2073 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
2074 RREG32(GRBM_SOFT_RESET);
2076 WREG32(GRBM_SOFT_RESET, 0);
2078 WREG32(CP_ME_RAM_WADDR, 0);
2080 fw_data = (const __be32 *)rdev->me_fw->data;
2081 WREG32(CP_ME_RAM_WADDR, 0);
2082 for (i = 0; i < PM4_UCODE_SIZE * 3; i++)
2083 WREG32(CP_ME_RAM_DATA,
2084 be32_to_cpup(fw_data++));
2086 fw_data = (const __be32 *)rdev->pfp_fw->data;
2087 WREG32(CP_PFP_UCODE_ADDR, 0);
2088 for (i = 0; i < PFP_UCODE_SIZE; i++)
2089 WREG32(CP_PFP_UCODE_DATA,
2090 be32_to_cpup(fw_data++));
2092 WREG32(CP_PFP_UCODE_ADDR, 0);
2093 WREG32(CP_ME_RAM_WADDR, 0);
2094 WREG32(CP_ME_RAM_RADDR, 0);
2098 int r600_cp_start(struct radeon_device *rdev)
2100 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
2104 r = radeon_ring_lock(rdev, ring, 7);
2106 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
2109 radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
2110 radeon_ring_write(ring, 0x1);
2111 if (rdev->family >= CHIP_RV770) {
2112 radeon_ring_write(ring, 0x0);
2113 radeon_ring_write(ring, rdev->config.rv770.max_hw_contexts - 1);
2115 radeon_ring_write(ring, 0x3);
2116 radeon_ring_write(ring, rdev->config.r600.max_hw_contexts - 1);
2118 radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
2119 radeon_ring_write(ring, 0);
2120 radeon_ring_write(ring, 0);
2121 radeon_ring_unlock_commit(rdev, ring);
2124 WREG32(R_0086D8_CP_ME_CNTL, cp_me);
2128 int r600_cp_resume(struct radeon_device *rdev)
2130 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
2136 WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
2137 RREG32(GRBM_SOFT_RESET);
2139 WREG32(GRBM_SOFT_RESET, 0);
2141 /* Set ring buffer size */
2142 rb_bufsz = drm_order(ring->ring_size / 8);
2143 tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
2145 tmp |= BUF_SWAP_32BIT;
2147 WREG32(CP_RB_CNTL, tmp);
2148 WREG32(CP_SEM_WAIT_TIMER, 0x0);
2150 /* Set the write pointer delay */
2151 WREG32(CP_RB_WPTR_DELAY, 0);
2153 /* Initialize the ring buffer's read and write pointers */
2154 WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
2155 WREG32(CP_RB_RPTR_WR, 0);
2157 WREG32(CP_RB_WPTR, ring->wptr);
2159 /* set the wb address whether it's enabled or not */
2160 WREG32(CP_RB_RPTR_ADDR,
2161 ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC));
2162 WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
2163 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
2165 if (rdev->wb.enabled)
2166 WREG32(SCRATCH_UMSK, 0xff);
2168 tmp |= RB_NO_UPDATE;
2169 WREG32(SCRATCH_UMSK, 0);
2173 WREG32(CP_RB_CNTL, tmp);
2175 WREG32(CP_RB_BASE, ring->gpu_addr >> 8);
2176 WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
2178 ring->rptr = RREG32(CP_RB_RPTR);
2180 r600_cp_start(rdev);
2182 r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring);
2184 ring->ready = false;
2190 void r600_ring_init(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ring_size)
2195 /* Align ring size */
2196 rb_bufsz = drm_order(ring_size / 8);
2197 ring_size = (1 << (rb_bufsz + 1)) * 4;
2198 ring->ring_size = ring_size;
2199 ring->align_mask = 16 - 1;
2201 if (radeon_ring_supports_scratch_reg(rdev, ring)) {
2202 r = radeon_scratch_get(rdev, &ring->rptr_save_reg);
2204 DRM_ERROR("failed to get scratch reg for rptr save (%d).\n", r);
2205 ring->rptr_save_reg = 0;
2210 void r600_cp_fini(struct radeon_device *rdev)
2212 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
2214 radeon_ring_fini(rdev, ring);
2215 radeon_scratch_free(rdev, ring->rptr_save_reg);
2220 * Starting with R600, the GPU has an asynchronous
2221 * DMA engine. The programming model is very similar
2222 * to the 3D engine (ring buffer, IBs, etc.), but the
2223 * DMA controller has it's own packet format that is
2224 * different form the PM4 format used by the 3D engine.
2225 * It supports copying data, writing embedded data,
2226 * solid fills, and a number of other things. It also
2227 * has support for tiling/detiling of buffers.
2230 * r600_dma_stop - stop the async dma engine
2232 * @rdev: radeon_device pointer
2234 * Stop the async dma engine (r6xx-evergreen).
2236 void r600_dma_stop(struct radeon_device *rdev)
2238 u32 rb_cntl = RREG32(DMA_RB_CNTL);
2240 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
2242 rb_cntl &= ~DMA_RB_ENABLE;
2243 WREG32(DMA_RB_CNTL, rb_cntl);
2245 rdev->ring[R600_RING_TYPE_DMA_INDEX].ready = false;
2249 * r600_dma_resume - setup and start the async dma engine
2251 * @rdev: radeon_device pointer
2253 * Set up the DMA ring buffer and enable it. (r6xx-evergreen).
2254 * Returns 0 for success, error for failure.
2256 int r600_dma_resume(struct radeon_device *rdev)
2258 struct radeon_ring *ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
2259 u32 rb_cntl, dma_cntl;
2264 if (rdev->family >= CHIP_RV770)
2265 WREG32(SRBM_SOFT_RESET, RV770_SOFT_RESET_DMA);
2267 WREG32(SRBM_SOFT_RESET, SOFT_RESET_DMA);
2268 RREG32(SRBM_SOFT_RESET);
2270 WREG32(SRBM_SOFT_RESET, 0);
2272 WREG32(DMA_SEM_INCOMPLETE_TIMER_CNTL, 0);
2273 WREG32(DMA_SEM_WAIT_FAIL_TIMER_CNTL, 0);
2275 /* Set ring buffer size in dwords */
2276 rb_bufsz = drm_order(ring->ring_size / 4);
2277 rb_cntl = rb_bufsz << 1;
2279 rb_cntl |= DMA_RB_SWAP_ENABLE | DMA_RPTR_WRITEBACK_SWAP_ENABLE;
2281 WREG32(DMA_RB_CNTL, rb_cntl);
2283 /* Initialize the ring buffer's read and write pointers */
2284 WREG32(DMA_RB_RPTR, 0);
2285 WREG32(DMA_RB_WPTR, 0);
2287 /* set the wb address whether it's enabled or not */
2288 WREG32(DMA_RB_RPTR_ADDR_HI,
2289 upper_32_bits(rdev->wb.gpu_addr + R600_WB_DMA_RPTR_OFFSET) & 0xFF);
2290 WREG32(DMA_RB_RPTR_ADDR_LO,
2291 ((rdev->wb.gpu_addr + R600_WB_DMA_RPTR_OFFSET) & 0xFFFFFFFC));
2293 if (rdev->wb.enabled)
2294 rb_cntl |= DMA_RPTR_WRITEBACK_ENABLE;
2296 WREG32(DMA_RB_BASE, ring->gpu_addr >> 8);
2298 /* enable DMA IBs */
2299 WREG32(DMA_IB_CNTL, DMA_IB_ENABLE);
2301 dma_cntl = RREG32(DMA_CNTL);
2302 dma_cntl &= ~CTXEMPTY_INT_ENABLE;
2303 WREG32(DMA_CNTL, dma_cntl);
2305 if (rdev->family >= CHIP_RV770)
2306 WREG32(DMA_MODE, 1);
2309 WREG32(DMA_RB_WPTR, ring->wptr << 2);
2311 ring->rptr = RREG32(DMA_RB_RPTR) >> 2;
2313 WREG32(DMA_RB_CNTL, rb_cntl | DMA_RB_ENABLE);
2317 r = radeon_ring_test(rdev, R600_RING_TYPE_DMA_INDEX, ring);
2319 ring->ready = false;
2323 radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
2329 * r600_dma_fini - tear down the async dma engine
2331 * @rdev: radeon_device pointer
2333 * Stop the async dma engine and free the ring (r6xx-evergreen).
2335 void r600_dma_fini(struct radeon_device *rdev)
2337 r600_dma_stop(rdev);
2338 radeon_ring_fini(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX]);
2342 * GPU scratch registers helpers function.
2344 void r600_scratch_init(struct radeon_device *rdev)
2348 rdev->scratch.num_reg = 7;
2349 rdev->scratch.reg_base = SCRATCH_REG0;
2350 for (i = 0; i < rdev->scratch.num_reg; i++) {
2351 rdev->scratch.free[i] = true;
2352 rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
2356 int r600_ring_test(struct radeon_device *rdev, struct radeon_ring *ring)
2363 r = radeon_scratch_get(rdev, &scratch);
2365 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
2368 WREG32(scratch, 0xCAFEDEAD);
2369 r = radeon_ring_lock(rdev, ring, 3);
2371 DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ring->idx, r);
2372 radeon_scratch_free(rdev, scratch);
2375 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2376 radeon_ring_write(ring, ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2377 radeon_ring_write(ring, 0xDEADBEEF);
2378 radeon_ring_unlock_commit(rdev, ring);
2379 for (i = 0; i < rdev->usec_timeout; i++) {
2380 tmp = RREG32(scratch);
2381 if (tmp == 0xDEADBEEF)
2385 if (i < rdev->usec_timeout) {
2386 DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
2388 DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
2389 ring->idx, scratch, tmp);
2392 radeon_scratch_free(rdev, scratch);
2397 * r600_dma_ring_test - simple async dma engine test
2399 * @rdev: radeon_device pointer
2400 * @ring: radeon_ring structure holding ring information
2402 * Test the DMA engine by writing using it to write an
2403 * value to memory. (r6xx-SI).
2404 * Returns 0 for success, error for failure.
2406 int r600_dma_ring_test(struct radeon_device *rdev,
2407 struct radeon_ring *ring)
2411 void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
2415 DRM_ERROR("invalid vram scratch pointer\n");
2422 r = radeon_ring_lock(rdev, ring, 4);
2424 DRM_ERROR("radeon: dma failed to lock ring %d (%d).\n", ring->idx, r);
2427 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 1));
2428 radeon_ring_write(ring, rdev->vram_scratch.gpu_addr & 0xfffffffc);
2429 radeon_ring_write(ring, upper_32_bits(rdev->vram_scratch.gpu_addr) & 0xff);
2430 radeon_ring_write(ring, 0xDEADBEEF);
2431 radeon_ring_unlock_commit(rdev, ring);
2433 for (i = 0; i < rdev->usec_timeout; i++) {
2435 if (tmp == 0xDEADBEEF)
2440 if (i < rdev->usec_timeout) {
2441 DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
2443 DRM_ERROR("radeon: ring %d test failed (0x%08X)\n",
2451 * CP fences/semaphores
2454 void r600_fence_ring_emit(struct radeon_device *rdev,
2455 struct radeon_fence *fence)
2457 struct radeon_ring *ring = &rdev->ring[fence->ring];
2459 if (rdev->wb.use_event) {
2460 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
2461 /* flush read cache over gart */
2462 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
2463 radeon_ring_write(ring, PACKET3_TC_ACTION_ENA |
2464 PACKET3_VC_ACTION_ENA |
2465 PACKET3_SH_ACTION_ENA);
2466 radeon_ring_write(ring, 0xFFFFFFFF);
2467 radeon_ring_write(ring, 0);
2468 radeon_ring_write(ring, 10); /* poll interval */
2469 /* EVENT_WRITE_EOP - flush caches, send int */
2470 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
2471 radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5));
2472 radeon_ring_write(ring, addr & 0xffffffff);
2473 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
2474 radeon_ring_write(ring, fence->seq);
2475 radeon_ring_write(ring, 0);
2477 /* flush read cache over gart */
2478 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
2479 radeon_ring_write(ring, PACKET3_TC_ACTION_ENA |
2480 PACKET3_VC_ACTION_ENA |
2481 PACKET3_SH_ACTION_ENA);
2482 radeon_ring_write(ring, 0xFFFFFFFF);
2483 radeon_ring_write(ring, 0);
2484 radeon_ring_write(ring, 10); /* poll interval */
2485 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
2486 radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT) | EVENT_INDEX(0));
2487 /* wait for 3D idle clean */
2488 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2489 radeon_ring_write(ring, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2490 radeon_ring_write(ring, WAIT_3D_IDLE_bit | WAIT_3D_IDLECLEAN_bit);
2491 /* Emit fence sequence & fire IRQ */
2492 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2493 radeon_ring_write(ring, ((rdev->fence_drv[fence->ring].scratch_reg - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2494 radeon_ring_write(ring, fence->seq);
2495 /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
2496 radeon_ring_write(ring, PACKET0(CP_INT_STATUS, 0));
2497 radeon_ring_write(ring, RB_INT_STAT);
2501 void r600_semaphore_ring_emit(struct radeon_device *rdev,
2502 struct radeon_ring *ring,
2503 struct radeon_semaphore *semaphore,
2506 uint64_t addr = semaphore->gpu_addr;
2507 unsigned sel = emit_wait ? PACKET3_SEM_SEL_WAIT : PACKET3_SEM_SEL_SIGNAL;
2509 if (rdev->family < CHIP_CAYMAN)
2510 sel |= PACKET3_SEM_WAIT_ON_SIGNAL;
2512 radeon_ring_write(ring, PACKET3(PACKET3_MEM_SEMAPHORE, 1));
2513 radeon_ring_write(ring, addr & 0xffffffff);
2514 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | sel);
2518 * DMA fences/semaphores
2522 * r600_dma_fence_ring_emit - emit a fence on the DMA ring
2524 * @rdev: radeon_device pointer
2525 * @fence: radeon fence object
2527 * Add a DMA fence packet to the ring to write
2528 * the fence seq number and DMA trap packet to generate
2529 * an interrupt if needed (r6xx-r7xx).
2531 void r600_dma_fence_ring_emit(struct radeon_device *rdev,
2532 struct radeon_fence *fence)
2534 struct radeon_ring *ring = &rdev->ring[fence->ring];
2535 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
2537 /* write the fence */
2538 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_FENCE, 0, 0, 0));
2539 radeon_ring_write(ring, addr & 0xfffffffc);
2540 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff));
2541 radeon_ring_write(ring, lower_32_bits(fence->seq));
2542 /* generate an interrupt */
2543 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_TRAP, 0, 0, 0));
2547 * r600_dma_semaphore_ring_emit - emit a semaphore on the dma ring
2549 * @rdev: radeon_device pointer
2550 * @ring: radeon_ring structure holding ring information
2551 * @semaphore: radeon semaphore object
2552 * @emit_wait: wait or signal semaphore
2554 * Add a DMA semaphore packet to the ring wait on or signal
2555 * other rings (r6xx-SI).
2557 void r600_dma_semaphore_ring_emit(struct radeon_device *rdev,
2558 struct radeon_ring *ring,
2559 struct radeon_semaphore *semaphore,
2562 u64 addr = semaphore->gpu_addr;
2563 u32 s = emit_wait ? 0 : 1;
2565 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SEMAPHORE, 0, s, 0));
2566 radeon_ring_write(ring, addr & 0xfffffffc);
2567 radeon_ring_write(ring, upper_32_bits(addr) & 0xff);
2570 int r600_copy_blit(struct radeon_device *rdev,
2571 uint64_t src_offset,
2572 uint64_t dst_offset,
2573 unsigned num_gpu_pages,
2574 struct radeon_fence **fence)
2576 struct radeon_semaphore *sem = NULL;
2577 struct radeon_sa_bo *vb = NULL;
2580 r = r600_blit_prepare_copy(rdev, num_gpu_pages, fence, &vb, &sem);
2584 r600_kms_blit_copy(rdev, src_offset, dst_offset, num_gpu_pages, vb);
2585 r600_blit_done_copy(rdev, fence, vb, sem);
2590 * r600_copy_dma - copy pages using the DMA engine
2592 * @rdev: radeon_device pointer
2593 * @src_offset: src GPU address
2594 * @dst_offset: dst GPU address
2595 * @num_gpu_pages: number of GPU pages to xfer
2596 * @fence: radeon fence object
2598 * Copy GPU paging using the DMA engine (r6xx-r7xx).
2599 * Used by the radeon ttm implementation to move pages if
2600 * registered as the asic copy callback.
2602 int r600_copy_dma(struct radeon_device *rdev,
2603 uint64_t src_offset, uint64_t dst_offset,
2604 unsigned num_gpu_pages,
2605 struct radeon_fence **fence)
2607 struct radeon_semaphore *sem = NULL;
2608 int ring_index = rdev->asic->copy.dma_ring_index;
2609 struct radeon_ring *ring = &rdev->ring[ring_index];
2610 u32 size_in_dw, cur_size_in_dw;
2614 r = radeon_semaphore_create(rdev, &sem);
2616 DRM_ERROR("radeon: moving bo (%d).\n", r);
2620 size_in_dw = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT) / 4;
2621 num_loops = DIV_ROUND_UP(size_in_dw, 0xffff);
2622 r = radeon_ring_lock(rdev, ring, num_loops * 5 + 8);
2624 DRM_ERROR("radeon: moving bo (%d).\n", r);
2625 radeon_semaphore_free(rdev, &sem, NULL);
2629 if (radeon_fence_need_sync(*fence, ring->idx)) {
2630 radeon_semaphore_sync_rings(rdev, sem, (*fence)->ring,
2632 radeon_fence_note_sync(*fence, ring->idx);
2634 radeon_semaphore_free(rdev, &sem, NULL);
2637 for (i = 0; i < num_loops; i++) {
2638 cur_size_in_dw = size_in_dw;
2639 if (cur_size_in_dw > 0xFFFE)
2640 cur_size_in_dw = 0xFFFE;
2641 size_in_dw -= cur_size_in_dw;
2642 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_COPY, 0, 0, cur_size_in_dw));
2643 radeon_ring_write(ring, dst_offset & 0xfffffffc);
2644 radeon_ring_write(ring, src_offset & 0xfffffffc);
2645 radeon_ring_write(ring, upper_32_bits(dst_offset) & 0xff);
2646 radeon_ring_write(ring, upper_32_bits(src_offset) & 0xff);
2647 src_offset += cur_size_in_dw * 4;
2648 dst_offset += cur_size_in_dw * 4;
2651 r = radeon_fence_emit(rdev, fence, ring->idx);
2653 radeon_ring_unlock_undo(rdev, ring);
2657 radeon_ring_unlock_commit(rdev, ring);
2658 radeon_semaphore_free(rdev, &sem, *fence);
2663 int r600_set_surface_reg(struct radeon_device *rdev, int reg,
2664 uint32_t tiling_flags, uint32_t pitch,
2665 uint32_t offset, uint32_t obj_size)
2667 /* FIXME: implement */
2671 void r600_clear_surface_reg(struct radeon_device *rdev, int reg)
2673 /* FIXME: implement */
2676 static int r600_startup(struct radeon_device *rdev)
2678 struct radeon_ring *ring;
2681 /* enable pcie gen2 link */
2682 r600_pcie_gen2_enable(rdev);
2684 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
2685 r = r600_init_microcode(rdev);
2687 DRM_ERROR("Failed to load firmware!\n");
2692 r = r600_vram_scratch_init(rdev);
2696 r600_mc_program(rdev);
2697 if (rdev->flags & RADEON_IS_AGP) {
2698 r600_agp_enable(rdev);
2700 r = r600_pcie_gart_enable(rdev);
2704 r600_gpu_init(rdev);
2705 r = r600_blit_init(rdev);
2707 r600_blit_fini(rdev);
2708 rdev->asic->copy.copy = NULL;
2709 dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
2712 /* allocate wb buffer */
2713 r = radeon_wb_init(rdev);
2717 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
2719 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
2723 r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
2725 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
2730 r = r600_irq_init(rdev);
2732 DRM_ERROR("radeon: IH init failed (%d).\n", r);
2733 radeon_irq_kms_fini(rdev);
2738 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
2739 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
2740 R600_CP_RB_RPTR, R600_CP_RB_WPTR,
2741 0, 0xfffff, RADEON_CP_PACKET2);
2745 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
2746 r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
2747 DMA_RB_RPTR, DMA_RB_WPTR,
2748 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
2752 r = r600_cp_load_microcode(rdev);
2755 r = r600_cp_resume(rdev);
2759 r = r600_dma_resume(rdev);
2763 r = radeon_ib_pool_init(rdev);
2765 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
2769 r = r600_audio_init(rdev);
2771 DRM_ERROR("radeon: audio init failed\n");
2778 void r600_vga_set_state(struct radeon_device *rdev, bool state)
2782 temp = RREG32(CONFIG_CNTL);
2783 if (state == false) {
2789 WREG32(CONFIG_CNTL, temp);
2792 int r600_resume(struct radeon_device *rdev)
2796 /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
2797 * posting will perform necessary task to bring back GPU into good
2801 atom_asic_init(rdev->mode_info.atom_context);
2803 rdev->accel_working = true;
2804 r = r600_startup(rdev);
2806 DRM_ERROR("r600 startup failed on resume\n");
2807 rdev->accel_working = false;
2814 int r600_suspend(struct radeon_device *rdev)
2816 r600_audio_fini(rdev);
2818 r600_dma_stop(rdev);
2819 r600_irq_suspend(rdev);
2820 radeon_wb_disable(rdev);
2821 r600_pcie_gart_disable(rdev);
2826 /* Plan is to move initialization in that function and use
2827 * helper function so that radeon_device_init pretty much
2828 * do nothing more than calling asic specific function. This
2829 * should also allow to remove a bunch of callback function
2832 int r600_init(struct radeon_device *rdev)
2836 if (r600_debugfs_mc_info_init(rdev)) {
2837 DRM_ERROR("Failed to register debugfs file for mc !\n");
2840 if (!radeon_get_bios(rdev)) {
2841 if (ASIC_IS_AVIVO(rdev))
2844 /* Must be an ATOMBIOS */
2845 if (!rdev->is_atom_bios) {
2846 dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
2849 r = radeon_atombios_init(rdev);
2852 /* Post card if necessary */
2853 if (!radeon_card_posted(rdev)) {
2855 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
2858 DRM_INFO("GPU not posted. posting now...\n");
2859 atom_asic_init(rdev->mode_info.atom_context);
2861 /* Initialize scratch registers */
2862 r600_scratch_init(rdev);
2863 /* Initialize surface registers */
2864 radeon_surface_init(rdev);
2865 /* Initialize clocks */
2866 radeon_get_clock_info(rdev->ddev);
2868 r = radeon_fence_driver_init(rdev);
2871 if (rdev->flags & RADEON_IS_AGP) {
2872 r = radeon_agp_init(rdev);
2874 radeon_agp_disable(rdev);
2876 r = r600_mc_init(rdev);
2879 /* Memory manager */
2880 r = radeon_bo_init(rdev);
2884 r = radeon_irq_kms_init(rdev);
2888 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL;
2889 r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024);
2891 rdev->ring[R600_RING_TYPE_DMA_INDEX].ring_obj = NULL;
2892 r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX], 64 * 1024);
2894 rdev->ih.ring_obj = NULL;
2895 r600_ih_ring_init(rdev, 64 * 1024);
2897 r = r600_pcie_gart_init(rdev);
2901 rdev->accel_working = true;
2902 r = r600_startup(rdev);
2904 dev_err(rdev->dev, "disabling GPU acceleration\n");
2906 r600_dma_fini(rdev);
2907 r600_irq_fini(rdev);
2908 radeon_wb_fini(rdev);
2909 radeon_ib_pool_fini(rdev);
2910 radeon_irq_kms_fini(rdev);
2911 r600_pcie_gart_fini(rdev);
2912 rdev->accel_working = false;
2918 void r600_fini(struct radeon_device *rdev)
2920 r600_audio_fini(rdev);
2921 r600_blit_fini(rdev);
2923 r600_dma_fini(rdev);
2924 r600_irq_fini(rdev);
2925 radeon_wb_fini(rdev);
2926 radeon_ib_pool_fini(rdev);
2927 radeon_irq_kms_fini(rdev);
2928 r600_pcie_gart_fini(rdev);
2929 r600_vram_scratch_fini(rdev);
2930 radeon_agp_fini(rdev);
2931 radeon_gem_fini(rdev);
2932 radeon_fence_driver_fini(rdev);
2933 radeon_bo_fini(rdev);
2934 radeon_atombios_fini(rdev);
2943 void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
2945 struct radeon_ring *ring = &rdev->ring[ib->ring];
2948 if (ring->rptr_save_reg) {
2949 next_rptr = ring->wptr + 3 + 4;
2950 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
2951 radeon_ring_write(ring, ((ring->rptr_save_reg -
2952 PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
2953 radeon_ring_write(ring, next_rptr);
2954 } else if (rdev->wb.enabled) {
2955 next_rptr = ring->wptr + 5 + 4;
2956 radeon_ring_write(ring, PACKET3(PACKET3_MEM_WRITE, 3));
2957 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
2958 radeon_ring_write(ring, (upper_32_bits(ring->next_rptr_gpu_addr) & 0xff) | (1 << 18));
2959 radeon_ring_write(ring, next_rptr);
2960 radeon_ring_write(ring, 0);
2963 radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
2964 radeon_ring_write(ring,
2968 (ib->gpu_addr & 0xFFFFFFFC));
2969 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
2970 radeon_ring_write(ring, ib->length_dw);
2973 int r600_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
2975 struct radeon_ib ib;
2981 r = radeon_scratch_get(rdev, &scratch);
2983 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
2986 WREG32(scratch, 0xCAFEDEAD);
2987 r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
2989 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
2992 ib.ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1);
2993 ib.ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
2994 ib.ptr[2] = 0xDEADBEEF;
2996 r = radeon_ib_schedule(rdev, &ib, NULL);
2998 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
3001 r = radeon_fence_wait(ib.fence, false);
3003 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
3006 for (i = 0; i < rdev->usec_timeout; i++) {
3007 tmp = RREG32(scratch);
3008 if (tmp == 0xDEADBEEF)
3012 if (i < rdev->usec_timeout) {
3013 DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
3015 DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
3020 radeon_ib_free(rdev, &ib);
3022 radeon_scratch_free(rdev, scratch);
3027 * r600_dma_ib_test - test an IB on the DMA engine
3029 * @rdev: radeon_device pointer
3030 * @ring: radeon_ring structure holding ring information
3032 * Test a simple IB in the DMA ring (r6xx-SI).
3033 * Returns 0 on success, error on failure.
3035 int r600_dma_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
3037 struct radeon_ib ib;
3040 void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
3044 DRM_ERROR("invalid vram scratch pointer\n");
3051 r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
3053 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
3057 ib.ptr[0] = DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 1);
3058 ib.ptr[1] = rdev->vram_scratch.gpu_addr & 0xfffffffc;
3059 ib.ptr[2] = upper_32_bits(rdev->vram_scratch.gpu_addr) & 0xff;
3060 ib.ptr[3] = 0xDEADBEEF;
3063 r = radeon_ib_schedule(rdev, &ib, NULL);
3065 radeon_ib_free(rdev, &ib);
3066 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
3069 r = radeon_fence_wait(ib.fence, false);
3071 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
3074 for (i = 0; i < rdev->usec_timeout; i++) {
3076 if (tmp == 0xDEADBEEF)
3080 if (i < rdev->usec_timeout) {
3081 DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
3083 DRM_ERROR("radeon: ib test failed (0x%08X)\n", tmp);
3086 radeon_ib_free(rdev, &ib);
3091 * r600_dma_ring_ib_execute - Schedule an IB on the DMA engine
3093 * @rdev: radeon_device pointer
3094 * @ib: IB object to schedule
3096 * Schedule an IB in the DMA ring (r6xx-r7xx).
3098 void r600_dma_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
3100 struct radeon_ring *ring = &rdev->ring[ib->ring];
3102 if (rdev->wb.enabled) {
3103 u32 next_rptr = ring->wptr + 4;
3104 while ((next_rptr & 7) != 5)
3107 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 1));
3108 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
3109 radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xff);
3110 radeon_ring_write(ring, next_rptr);
3113 /* The indirect buffer packet must end on an 8 DW boundary in the DMA ring.
3114 * Pad as necessary with NOPs.
3116 while ((ring->wptr & 7) != 5)
3117 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
3118 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_INDIRECT_BUFFER, 0, 0, 0));
3119 radeon_ring_write(ring, (ib->gpu_addr & 0xFFFFFFE0));
3120 radeon_ring_write(ring, (ib->length_dw << 16) | (upper_32_bits(ib->gpu_addr) & 0xFF));
3127 * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
3128 * the same as the CP ring buffer, but in reverse. Rather than the CPU
3129 * writing to the ring and the GPU consuming, the GPU writes to the ring
3130 * and host consumes. As the host irq handler processes interrupts, it
3131 * increments the rptr. When the rptr catches up with the wptr, all the
3132 * current interrupts have been processed.
3135 void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size)
3139 /* Align ring size */
3140 rb_bufsz = drm_order(ring_size / 4);
3141 ring_size = (1 << rb_bufsz) * 4;
3142 rdev->ih.ring_size = ring_size;
3143 rdev->ih.ptr_mask = rdev->ih.ring_size - 1;
3147 int r600_ih_ring_alloc(struct radeon_device *rdev)
3151 /* Allocate ring buffer */
3152 if (rdev->ih.ring_obj == NULL) {
3153 r = radeon_bo_create(rdev, rdev->ih.ring_size,
3155 RADEON_GEM_DOMAIN_GTT,
3156 NULL, &rdev->ih.ring_obj);
3158 DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r);
3161 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
3162 if (unlikely(r != 0))
3164 r = radeon_bo_pin(rdev->ih.ring_obj,
3165 RADEON_GEM_DOMAIN_GTT,
3166 &rdev->ih.gpu_addr);
3168 radeon_bo_unreserve(rdev->ih.ring_obj);
3169 DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r);
3172 r = radeon_bo_kmap(rdev->ih.ring_obj,
3173 (void **)&rdev->ih.ring);
3174 radeon_bo_unreserve(rdev->ih.ring_obj);
3176 DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r);
3183 void r600_ih_ring_fini(struct radeon_device *rdev)
3186 if (rdev->ih.ring_obj) {
3187 r = radeon_bo_reserve(rdev->ih.ring_obj, false);
3188 if (likely(r == 0)) {
3189 radeon_bo_kunmap(rdev->ih.ring_obj);
3190 radeon_bo_unpin(rdev->ih.ring_obj);
3191 radeon_bo_unreserve(rdev->ih.ring_obj);
3193 radeon_bo_unref(&rdev->ih.ring_obj);
3194 rdev->ih.ring = NULL;
3195 rdev->ih.ring_obj = NULL;
3199 void r600_rlc_stop(struct radeon_device *rdev)
3202 if ((rdev->family >= CHIP_RV770) &&
3203 (rdev->family <= CHIP_RV740)) {
3204 /* r7xx asics need to soft reset RLC before halting */
3205 WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC);
3206 RREG32(SRBM_SOFT_RESET);
3208 WREG32(SRBM_SOFT_RESET, 0);
3209 RREG32(SRBM_SOFT_RESET);
3212 WREG32(RLC_CNTL, 0);
3215 static void r600_rlc_start(struct radeon_device *rdev)
3217 WREG32(RLC_CNTL, RLC_ENABLE);
3220 static int r600_rlc_init(struct radeon_device *rdev)
3223 const __be32 *fw_data;
3228 r600_rlc_stop(rdev);
3230 WREG32(RLC_HB_CNTL, 0);
3232 if (rdev->family == CHIP_ARUBA) {
3233 WREG32(TN_RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
3234 WREG32(TN_RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
3236 if (rdev->family <= CHIP_CAYMAN) {
3237 WREG32(RLC_HB_BASE, 0);
3238 WREG32(RLC_HB_RPTR, 0);
3239 WREG32(RLC_HB_WPTR, 0);
3241 if (rdev->family <= CHIP_CAICOS) {
3242 WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
3243 WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
3245 WREG32(RLC_MC_CNTL, 0);
3246 WREG32(RLC_UCODE_CNTL, 0);
3248 fw_data = (const __be32 *)rdev->rlc_fw->data;
3249 if (rdev->family >= CHIP_ARUBA) {
3250 for (i = 0; i < ARUBA_RLC_UCODE_SIZE; i++) {
3251 WREG32(RLC_UCODE_ADDR, i);
3252 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
3254 } else if (rdev->family >= CHIP_CAYMAN) {
3255 for (i = 0; i < CAYMAN_RLC_UCODE_SIZE; i++) {
3256 WREG32(RLC_UCODE_ADDR, i);
3257 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
3259 } else if (rdev->family >= CHIP_CEDAR) {
3260 for (i = 0; i < EVERGREEN_RLC_UCODE_SIZE; i++) {
3261 WREG32(RLC_UCODE_ADDR, i);
3262 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
3264 } else if (rdev->family >= CHIP_RV770) {
3265 for (i = 0; i < R700_RLC_UCODE_SIZE; i++) {
3266 WREG32(RLC_UCODE_ADDR, i);
3267 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
3270 for (i = 0; i < RLC_UCODE_SIZE; i++) {
3271 WREG32(RLC_UCODE_ADDR, i);
3272 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
3275 WREG32(RLC_UCODE_ADDR, 0);
3277 r600_rlc_start(rdev);
3282 static void r600_enable_interrupts(struct radeon_device *rdev)
3284 u32 ih_cntl = RREG32(IH_CNTL);
3285 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
3287 ih_cntl |= ENABLE_INTR;
3288 ih_rb_cntl |= IH_RB_ENABLE;
3289 WREG32(IH_CNTL, ih_cntl);
3290 WREG32(IH_RB_CNTL, ih_rb_cntl);
3291 rdev->ih.enabled = true;
3294 void r600_disable_interrupts(struct radeon_device *rdev)
3296 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
3297 u32 ih_cntl = RREG32(IH_CNTL);
3299 ih_rb_cntl &= ~IH_RB_ENABLE;
3300 ih_cntl &= ~ENABLE_INTR;
3301 WREG32(IH_RB_CNTL, ih_rb_cntl);
3302 WREG32(IH_CNTL, ih_cntl);
3303 /* set rptr, wptr to 0 */
3304 WREG32(IH_RB_RPTR, 0);
3305 WREG32(IH_RB_WPTR, 0);
3306 rdev->ih.enabled = false;
3310 static void r600_disable_interrupt_state(struct radeon_device *rdev)
3314 WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
3315 tmp = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
3316 WREG32(DMA_CNTL, tmp);
3317 WREG32(GRBM_INT_CNTL, 0);
3318 WREG32(DxMODE_INT_MASK, 0);
3319 WREG32(D1GRPH_INTERRUPT_CONTROL, 0);
3320 WREG32(D2GRPH_INTERRUPT_CONTROL, 0);
3321 if (ASIC_IS_DCE3(rdev)) {
3322 WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL, 0);
3323 WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL, 0);
3324 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3325 WREG32(DC_HPD1_INT_CONTROL, tmp);
3326 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3327 WREG32(DC_HPD2_INT_CONTROL, tmp);
3328 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3329 WREG32(DC_HPD3_INT_CONTROL, tmp);
3330 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3331 WREG32(DC_HPD4_INT_CONTROL, tmp);
3332 if (ASIC_IS_DCE32(rdev)) {
3333 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3334 WREG32(DC_HPD5_INT_CONTROL, tmp);
3335 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
3336 WREG32(DC_HPD6_INT_CONTROL, tmp);
3337 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3338 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, tmp);
3339 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3340 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, tmp);
3342 tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3343 WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
3344 tmp = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3345 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, tmp);
3348 WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
3349 WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
3350 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
3351 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
3352 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
3353 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
3354 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
3355 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
3356 tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3357 WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
3358 tmp = RREG32(HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3359 WREG32(HDMI1_AUDIO_PACKET_CONTROL, tmp);
3363 int r600_irq_init(struct radeon_device *rdev)
3367 u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
3370 ret = r600_ih_ring_alloc(rdev);
3375 r600_disable_interrupts(rdev);
3378 ret = r600_rlc_init(rdev);
3380 r600_ih_ring_fini(rdev);
3384 /* setup interrupt control */
3385 /* set dummy read address to ring address */
3386 WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
3387 interrupt_cntl = RREG32(INTERRUPT_CNTL);
3388 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
3389 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
3391 interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
3392 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
3393 interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
3394 WREG32(INTERRUPT_CNTL, interrupt_cntl);
3396 WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
3397 rb_bufsz = drm_order(rdev->ih.ring_size / 4);
3399 ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
3400 IH_WPTR_OVERFLOW_CLEAR |
3403 if (rdev->wb.enabled)
3404 ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
3406 /* set the writeback address whether it's enabled or not */
3407 WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
3408 WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
3410 WREG32(IH_RB_CNTL, ih_rb_cntl);
3412 /* set rptr, wptr to 0 */
3413 WREG32(IH_RB_RPTR, 0);
3414 WREG32(IH_RB_WPTR, 0);
3416 /* Default settings for IH_CNTL (disabled at first) */
3417 ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
3418 /* RPTR_REARM only works if msi's are enabled */
3419 if (rdev->msi_enabled)
3420 ih_cntl |= RPTR_REARM;
3421 WREG32(IH_CNTL, ih_cntl);
3423 /* force the active interrupt state to all disabled */
3424 if (rdev->family >= CHIP_CEDAR)
3425 evergreen_disable_interrupt_state(rdev);
3427 r600_disable_interrupt_state(rdev);
3429 /* at this point everything should be setup correctly to enable master */
3430 pci_set_master(rdev->pdev);
3433 r600_enable_interrupts(rdev);
3438 void r600_irq_suspend(struct radeon_device *rdev)
3440 r600_irq_disable(rdev);
3441 r600_rlc_stop(rdev);
3444 void r600_irq_fini(struct radeon_device *rdev)
3446 r600_irq_suspend(rdev);
3447 r600_ih_ring_fini(rdev);
3450 int r600_irq_set(struct radeon_device *rdev)
3452 u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
3454 u32 hpd1, hpd2, hpd3, hpd4 = 0, hpd5 = 0, hpd6 = 0;
3455 u32 grbm_int_cntl = 0;
3457 u32 d1grph = 0, d2grph = 0;
3460 if (!rdev->irq.installed) {
3461 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
3464 /* don't enable anything if the ih is disabled */
3465 if (!rdev->ih.enabled) {
3466 r600_disable_interrupts(rdev);
3467 /* force the active interrupt state to all disabled */
3468 r600_disable_interrupt_state(rdev);
3472 if (ASIC_IS_DCE3(rdev)) {
3473 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
3474 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
3475 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
3476 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
3477 if (ASIC_IS_DCE32(rdev)) {
3478 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
3479 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
3480 hdmi0 = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
3481 hdmi1 = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
3483 hdmi0 = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3484 hdmi1 = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3487 hpd1 = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & ~DC_HPDx_INT_EN;
3488 hpd2 = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & ~DC_HPDx_INT_EN;
3489 hpd3 = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & ~DC_HPDx_INT_EN;
3490 hdmi0 = RREG32(HDMI0_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3491 hdmi1 = RREG32(HDMI1_AUDIO_PACKET_CONTROL) & ~HDMI0_AZ_FORMAT_WTRIG_MASK;
3493 dma_cntl = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
3495 if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
3496 DRM_DEBUG("r600_irq_set: sw int\n");
3497 cp_int_cntl |= RB_INT_ENABLE;
3498 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
3501 if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
3502 DRM_DEBUG("r600_irq_set: sw int dma\n");
3503 dma_cntl |= TRAP_ENABLE;
3506 if (rdev->irq.crtc_vblank_int[0] ||
3507 atomic_read(&rdev->irq.pflip[0])) {
3508 DRM_DEBUG("r600_irq_set: vblank 0\n");
3509 mode_int |= D1MODE_VBLANK_INT_MASK;
3511 if (rdev->irq.crtc_vblank_int[1] ||
3512 atomic_read(&rdev->irq.pflip[1])) {
3513 DRM_DEBUG("r600_irq_set: vblank 1\n");
3514 mode_int |= D2MODE_VBLANK_INT_MASK;
3516 if (rdev->irq.hpd[0]) {
3517 DRM_DEBUG("r600_irq_set: hpd 1\n");
3518 hpd1 |= DC_HPDx_INT_EN;
3520 if (rdev->irq.hpd[1]) {
3521 DRM_DEBUG("r600_irq_set: hpd 2\n");
3522 hpd2 |= DC_HPDx_INT_EN;
3524 if (rdev->irq.hpd[2]) {
3525 DRM_DEBUG("r600_irq_set: hpd 3\n");
3526 hpd3 |= DC_HPDx_INT_EN;
3528 if (rdev->irq.hpd[3]) {
3529 DRM_DEBUG("r600_irq_set: hpd 4\n");
3530 hpd4 |= DC_HPDx_INT_EN;
3532 if (rdev->irq.hpd[4]) {
3533 DRM_DEBUG("r600_irq_set: hpd 5\n");
3534 hpd5 |= DC_HPDx_INT_EN;
3536 if (rdev->irq.hpd[5]) {
3537 DRM_DEBUG("r600_irq_set: hpd 6\n");
3538 hpd6 |= DC_HPDx_INT_EN;
3540 if (rdev->irq.afmt[0]) {
3541 DRM_DEBUG("r600_irq_set: hdmi 0\n");
3542 hdmi0 |= HDMI0_AZ_FORMAT_WTRIG_MASK;
3544 if (rdev->irq.afmt[1]) {
3545 DRM_DEBUG("r600_irq_set: hdmi 0\n");
3546 hdmi1 |= HDMI0_AZ_FORMAT_WTRIG_MASK;
3549 WREG32(CP_INT_CNTL, cp_int_cntl);
3550 WREG32(DMA_CNTL, dma_cntl);
3551 WREG32(DxMODE_INT_MASK, mode_int);
3552 WREG32(D1GRPH_INTERRUPT_CONTROL, d1grph);
3553 WREG32(D2GRPH_INTERRUPT_CONTROL, d2grph);
3554 WREG32(GRBM_INT_CNTL, grbm_int_cntl);
3555 if (ASIC_IS_DCE3(rdev)) {
3556 WREG32(DC_HPD1_INT_CONTROL, hpd1);
3557 WREG32(DC_HPD2_INT_CONTROL, hpd2);
3558 WREG32(DC_HPD3_INT_CONTROL, hpd3);
3559 WREG32(DC_HPD4_INT_CONTROL, hpd4);
3560 if (ASIC_IS_DCE32(rdev)) {
3561 WREG32(DC_HPD5_INT_CONTROL, hpd5);
3562 WREG32(DC_HPD6_INT_CONTROL, hpd6);
3563 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, hdmi0);
3564 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, hdmi1);
3566 WREG32(HDMI0_AUDIO_PACKET_CONTROL, hdmi0);
3567 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, hdmi1);
3570 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
3571 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
3572 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, hpd3);
3573 WREG32(HDMI0_AUDIO_PACKET_CONTROL, hdmi0);
3574 WREG32(HDMI1_AUDIO_PACKET_CONTROL, hdmi1);
3580 static void r600_irq_ack(struct radeon_device *rdev)
3584 if (ASIC_IS_DCE3(rdev)) {
3585 rdev->irq.stat_regs.r600.disp_int = RREG32(DCE3_DISP_INTERRUPT_STATUS);
3586 rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE);
3587 rdev->irq.stat_regs.r600.disp_int_cont2 = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2);
3588 if (ASIC_IS_DCE32(rdev)) {
3589 rdev->irq.stat_regs.r600.hdmi0_status = RREG32(AFMT_STATUS + DCE3_HDMI_OFFSET0);
3590 rdev->irq.stat_regs.r600.hdmi1_status = RREG32(AFMT_STATUS + DCE3_HDMI_OFFSET1);
3592 rdev->irq.stat_regs.r600.hdmi0_status = RREG32(HDMI0_STATUS);
3593 rdev->irq.stat_regs.r600.hdmi1_status = RREG32(DCE3_HDMI1_STATUS);
3596 rdev->irq.stat_regs.r600.disp_int = RREG32(DISP_INTERRUPT_STATUS);
3597 rdev->irq.stat_regs.r600.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
3598 rdev->irq.stat_regs.r600.disp_int_cont2 = 0;
3599 rdev->irq.stat_regs.r600.hdmi0_status = RREG32(HDMI0_STATUS);
3600 rdev->irq.stat_regs.r600.hdmi1_status = RREG32(HDMI1_STATUS);
3602 rdev->irq.stat_regs.r600.d1grph_int = RREG32(D1GRPH_INTERRUPT_STATUS);
3603 rdev->irq.stat_regs.r600.d2grph_int = RREG32(D2GRPH_INTERRUPT_STATUS);
3605 if (rdev->irq.stat_regs.r600.d1grph_int & DxGRPH_PFLIP_INT_OCCURRED)
3606 WREG32(D1GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR);
3607 if (rdev->irq.stat_regs.r600.d2grph_int & DxGRPH_PFLIP_INT_OCCURRED)
3608 WREG32(D2GRPH_INTERRUPT_STATUS, DxGRPH_PFLIP_INT_CLEAR);
3609 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT)
3610 WREG32(D1MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
3611 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT)
3612 WREG32(D1MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
3613 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT)
3614 WREG32(D2MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
3615 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT)
3616 WREG32(D2MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
3617 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT) {
3618 if (ASIC_IS_DCE3(rdev)) {
3619 tmp = RREG32(DC_HPD1_INT_CONTROL);
3620 tmp |= DC_HPDx_INT_ACK;
3621 WREG32(DC_HPD1_INT_CONTROL, tmp);
3623 tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
3624 tmp |= DC_HPDx_INT_ACK;
3625 WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
3628 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT) {
3629 if (ASIC_IS_DCE3(rdev)) {
3630 tmp = RREG32(DC_HPD2_INT_CONTROL);
3631 tmp |= DC_HPDx_INT_ACK;
3632 WREG32(DC_HPD2_INT_CONTROL, tmp);
3634 tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
3635 tmp |= DC_HPDx_INT_ACK;
3636 WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
3639 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT) {
3640 if (ASIC_IS_DCE3(rdev)) {
3641 tmp = RREG32(DC_HPD3_INT_CONTROL);
3642 tmp |= DC_HPDx_INT_ACK;
3643 WREG32(DC_HPD3_INT_CONTROL, tmp);
3645 tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
3646 tmp |= DC_HPDx_INT_ACK;
3647 WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
3650 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT) {
3651 tmp = RREG32(DC_HPD4_INT_CONTROL);
3652 tmp |= DC_HPDx_INT_ACK;
3653 WREG32(DC_HPD4_INT_CONTROL, tmp);
3655 if (ASIC_IS_DCE32(rdev)) {
3656 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT) {
3657 tmp = RREG32(DC_HPD5_INT_CONTROL);
3658 tmp |= DC_HPDx_INT_ACK;
3659 WREG32(DC_HPD5_INT_CONTROL, tmp);
3661 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT) {
3662 tmp = RREG32(DC_HPD5_INT_CONTROL);
3663 tmp |= DC_HPDx_INT_ACK;
3664 WREG32(DC_HPD6_INT_CONTROL, tmp);
3666 if (rdev->irq.stat_regs.r600.hdmi0_status & AFMT_AZ_FORMAT_WTRIG) {
3667 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0);
3668 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
3669 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET0, tmp);
3671 if (rdev->irq.stat_regs.r600.hdmi1_status & AFMT_AZ_FORMAT_WTRIG) {
3672 tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1);
3673 tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
3674 WREG32(AFMT_AUDIO_PACKET_CONTROL + DCE3_HDMI_OFFSET1, tmp);
3677 if (rdev->irq.stat_regs.r600.hdmi0_status & HDMI0_AZ_FORMAT_WTRIG) {
3678 tmp = RREG32(HDMI0_AUDIO_PACKET_CONTROL);
3679 tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
3680 WREG32(HDMI0_AUDIO_PACKET_CONTROL, tmp);
3682 if (rdev->irq.stat_regs.r600.hdmi1_status & HDMI0_AZ_FORMAT_WTRIG) {
3683 if (ASIC_IS_DCE3(rdev)) {
3684 tmp = RREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL);
3685 tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
3686 WREG32(DCE3_HDMI1_AUDIO_PACKET_CONTROL, tmp);
3688 tmp = RREG32(HDMI1_AUDIO_PACKET_CONTROL);
3689 tmp |= HDMI0_AZ_FORMAT_WTRIG_ACK;
3690 WREG32(HDMI1_AUDIO_PACKET_CONTROL, tmp);
3696 void r600_irq_disable(struct radeon_device *rdev)
3698 r600_disable_interrupts(rdev);
3699 /* Wait and acknowledge irq */
3702 r600_disable_interrupt_state(rdev);
3705 static u32 r600_get_ih_wptr(struct radeon_device *rdev)
3709 if (rdev->wb.enabled)
3710 wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
3712 wptr = RREG32(IH_RB_WPTR);
3714 if (wptr & RB_OVERFLOW) {
3715 /* When a ring buffer overflow happen start parsing interrupt
3716 * from the last not overwritten vector (wptr + 16). Hopefully
3717 * this should allow us to catchup.
3719 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
3720 wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
3721 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
3722 tmp = RREG32(IH_RB_CNTL);
3723 tmp |= IH_WPTR_OVERFLOW_CLEAR;
3724 WREG32(IH_RB_CNTL, tmp);
3726 return (wptr & rdev->ih.ptr_mask);
3730 * Each IV ring entry is 128 bits:
3731 * [7:0] - interrupt source id
3733 * [59:32] - interrupt source data
3734 * [127:60] - reserved
3736 * The basic interrupt vector entries
3737 * are decoded as follows:
3738 * src_id src_data description
3743 * 19 0 FP Hot plug detection A
3744 * 19 1 FP Hot plug detection B
3745 * 19 2 DAC A auto-detection
3746 * 19 3 DAC B auto-detection
3752 * 181 - EOP Interrupt
3755 * Note, these are based on r600 and may need to be
3756 * adjusted or added to on newer asics
3759 int r600_irq_process(struct radeon_device *rdev)
3763 u32 src_id, src_data;
3765 bool queue_hotplug = false;
3766 bool queue_hdmi = false;
3768 if (!rdev->ih.enabled || rdev->shutdown)
3771 /* No MSIs, need a dummy read to flush PCI DMAs */
3772 if (!rdev->msi_enabled)
3775 wptr = r600_get_ih_wptr(rdev);
3778 /* is somebody else already processing irqs? */
3779 if (atomic_xchg(&rdev->ih.lock, 1))
3782 rptr = rdev->ih.rptr;
3783 DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
3785 /* Order reading of wptr vs. reading of IH ring data */
3788 /* display interrupts */
3791 while (rptr != wptr) {
3792 /* wptr/rptr are in bytes! */
3793 ring_index = rptr / 4;
3794 src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
3795 src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
3798 case 1: /* D1 vblank/vline */
3800 case 0: /* D1 vblank */
3801 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VBLANK_INTERRUPT) {
3802 if (rdev->irq.crtc_vblank_int[0]) {
3803 drm_handle_vblank(rdev->ddev, 0);
3804 rdev->pm.vblank_sync = true;
3805 wake_up(&rdev->irq.vblank_queue);
3807 if (atomic_read(&rdev->irq.pflip[0]))
3808 radeon_crtc_handle_flip(rdev, 0);
3809 rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
3810 DRM_DEBUG("IH: D1 vblank\n");
3813 case 1: /* D1 vline */
3814 if (rdev->irq.stat_regs.r600.disp_int & LB_D1_VLINE_INTERRUPT) {
3815 rdev->irq.stat_regs.r600.disp_int &= ~LB_D1_VLINE_INTERRUPT;
3816 DRM_DEBUG("IH: D1 vline\n");
3820 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
3824 case 5: /* D2 vblank/vline */
3826 case 0: /* D2 vblank */
3827 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VBLANK_INTERRUPT) {
3828 if (rdev->irq.crtc_vblank_int[1]) {
3829 drm_handle_vblank(rdev->ddev, 1);
3830 rdev->pm.vblank_sync = true;
3831 wake_up(&rdev->irq.vblank_queue);
3833 if (atomic_read(&rdev->irq.pflip[1]))
3834 radeon_crtc_handle_flip(rdev, 1);
3835 rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VBLANK_INTERRUPT;
3836 DRM_DEBUG("IH: D2 vblank\n");
3839 case 1: /* D1 vline */
3840 if (rdev->irq.stat_regs.r600.disp_int & LB_D2_VLINE_INTERRUPT) {
3841 rdev->irq.stat_regs.r600.disp_int &= ~LB_D2_VLINE_INTERRUPT;
3842 DRM_DEBUG("IH: D2 vline\n");
3846 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
3850 case 19: /* HPD/DAC hotplug */
3853 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD1_INTERRUPT) {
3854 rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD1_INTERRUPT;
3855 queue_hotplug = true;
3856 DRM_DEBUG("IH: HPD1\n");
3860 if (rdev->irq.stat_regs.r600.disp_int & DC_HPD2_INTERRUPT) {
3861 rdev->irq.stat_regs.r600.disp_int &= ~DC_HPD2_INTERRUPT;
3862 queue_hotplug = true;
3863 DRM_DEBUG("IH: HPD2\n");
3867 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD3_INTERRUPT) {
3868 rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD3_INTERRUPT;
3869 queue_hotplug = true;
3870 DRM_DEBUG("IH: HPD3\n");
3874 if (rdev->irq.stat_regs.r600.disp_int_cont & DC_HPD4_INTERRUPT) {
3875 rdev->irq.stat_regs.r600.disp_int_cont &= ~DC_HPD4_INTERRUPT;
3876 queue_hotplug = true;
3877 DRM_DEBUG("IH: HPD4\n");
3881 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD5_INTERRUPT) {
3882 rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD5_INTERRUPT;
3883 queue_hotplug = true;
3884 DRM_DEBUG("IH: HPD5\n");
3888 if (rdev->irq.stat_regs.r600.disp_int_cont2 & DC_HPD6_INTERRUPT) {
3889 rdev->irq.stat_regs.r600.disp_int_cont2 &= ~DC_HPD6_INTERRUPT;
3890 queue_hotplug = true;
3891 DRM_DEBUG("IH: HPD6\n");
3895 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
3902 if (rdev->irq.stat_regs.r600.hdmi0_status & HDMI0_AZ_FORMAT_WTRIG) {
3903 rdev->irq.stat_regs.r600.hdmi0_status &= ~HDMI0_AZ_FORMAT_WTRIG;
3905 DRM_DEBUG("IH: HDMI0\n");
3909 if (rdev->irq.stat_regs.r600.hdmi1_status & HDMI0_AZ_FORMAT_WTRIG) {
3910 rdev->irq.stat_regs.r600.hdmi1_status &= ~HDMI0_AZ_FORMAT_WTRIG;
3912 DRM_DEBUG("IH: HDMI1\n");
3916 DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
3920 case 176: /* CP_INT in ring buffer */
3921 case 177: /* CP_INT in IB1 */
3922 case 178: /* CP_INT in IB2 */
3923 DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
3924 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
3926 case 181: /* CP EOP event */
3927 DRM_DEBUG("IH: CP EOP\n");
3928 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
3930 case 224: /* DMA trap event */
3931 DRM_DEBUG("IH: DMA trap\n");
3932 radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
3934 case 233: /* GUI IDLE */
3935 DRM_DEBUG("IH: GUI idle\n");
3938 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
3942 /* wptr/rptr are in bytes! */
3944 rptr &= rdev->ih.ptr_mask;
3947 schedule_work(&rdev->hotplug_work);
3949 schedule_work(&rdev->audio_work);
3950 rdev->ih.rptr = rptr;
3951 WREG32(IH_RB_RPTR, rdev->ih.rptr);
3952 atomic_set(&rdev->ih.lock, 0);
3954 /* make sure wptr hasn't changed while processing */
3955 wptr = r600_get_ih_wptr(rdev);
3965 #if defined(CONFIG_DEBUG_FS)
3967 static int r600_debugfs_mc_info(struct seq_file *m, void *data)
3969 struct drm_info_node *node = (struct drm_info_node *) m->private;
3970 struct drm_device *dev = node->minor->dev;
3971 struct radeon_device *rdev = dev->dev_private;
3973 DREG32_SYS(m, rdev, R_000E50_SRBM_STATUS);
3974 DREG32_SYS(m, rdev, VM_L2_STATUS);
3978 static struct drm_info_list r600_mc_info_list[] = {
3979 {"r600_mc_info", r600_debugfs_mc_info, 0, NULL},
3983 int r600_debugfs_mc_info_init(struct radeon_device *rdev)
3985 #if defined(CONFIG_DEBUG_FS)
3986 return radeon_debugfs_add_files(rdev, r600_mc_info_list, ARRAY_SIZE(r600_mc_info_list));
3993 * r600_ioctl_wait_idle - flush host path cache on wait idle ioctl
3994 * rdev: radeon device structure
3995 * bo: buffer object struct which userspace is waiting for idle
3997 * Some R6XX/R7XX doesn't seems to take into account HDP flush performed
3998 * through ring buffer, this leads to corruption in rendering, see
3999 * http://bugzilla.kernel.org/show_bug.cgi?id=15186 to avoid this we
4000 * directly perform HDP flush by writing register through MMIO.
4002 void r600_ioctl_wait_idle(struct radeon_device *rdev, struct radeon_bo *bo)
4004 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
4005 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL.
4006 * This seems to cause problems on some AGP cards. Just use the old
4009 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
4010 rdev->vram_scratch.ptr && !(rdev->flags & RADEON_IS_AGP)) {
4011 void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
4014 WREG32(HDP_DEBUG1, 0);
4015 tmp = readl((void __iomem *)ptr);
4017 WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
4020 void r600_set_pcie_lanes(struct radeon_device *rdev, int lanes)
4022 u32 link_width_cntl, mask, target_reg;
4024 if (rdev->flags & RADEON_IS_IGP)
4027 if (!(rdev->flags & RADEON_IS_PCIE))
4030 /* x2 cards have a special sequence */
4031 if (ASIC_IS_X2(rdev))
4034 /* FIXME wait for idle */
4038 mask = RADEON_PCIE_LC_LINK_WIDTH_X0;
4041 mask = RADEON_PCIE_LC_LINK_WIDTH_X1;
4044 mask = RADEON_PCIE_LC_LINK_WIDTH_X2;
4047 mask = RADEON_PCIE_LC_LINK_WIDTH_X4;
4050 mask = RADEON_PCIE_LC_LINK_WIDTH_X8;
4053 mask = RADEON_PCIE_LC_LINK_WIDTH_X12;
4057 mask = RADEON_PCIE_LC_LINK_WIDTH_X16;
4061 link_width_cntl = RREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
4063 if ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) ==
4064 (mask << RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT))
4067 if (link_width_cntl & R600_PCIE_LC_UPCONFIGURE_DIS)
4070 link_width_cntl &= ~(RADEON_PCIE_LC_LINK_WIDTH_MASK |
4071 RADEON_PCIE_LC_RECONFIG_NOW |
4072 R600_PCIE_LC_RENEGOTIATE_EN |
4073 R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE);
4074 link_width_cntl |= mask;
4076 WREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
4078 /* some northbridges can renegotiate the link rather than requiring
4079 * a complete re-config.
4080 * e.g., AMD 780/790 northbridges (pci ids: 0x5956, 0x5957, 0x5958, etc.)
4082 if (link_width_cntl & R600_PCIE_LC_RENEGOTIATION_SUPPORT)
4083 link_width_cntl |= R600_PCIE_LC_RENEGOTIATE_EN | R600_PCIE_LC_UPCONFIGURE_SUPPORT;
4085 link_width_cntl |= R600_PCIE_LC_RECONFIG_ARC_MISSING_ESCAPE;
4087 WREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL, (link_width_cntl |
4088 RADEON_PCIE_LC_RECONFIG_NOW));
4090 if (rdev->family >= CHIP_RV770)
4091 target_reg = R700_TARGET_AND_CURRENT_PROFILE_INDEX;
4093 target_reg = R600_TARGET_AND_CURRENT_PROFILE_INDEX;
4095 /* wait for lane set to complete */
4096 link_width_cntl = RREG32(target_reg);
4097 while (link_width_cntl == 0xffffffff)
4098 link_width_cntl = RREG32(target_reg);
4102 int r600_get_pcie_lanes(struct radeon_device *rdev)
4104 u32 link_width_cntl;
4106 if (rdev->flags & RADEON_IS_IGP)
4109 if (!(rdev->flags & RADEON_IS_PCIE))
4112 /* x2 cards have a special sequence */
4113 if (ASIC_IS_X2(rdev))
4116 /* FIXME wait for idle */
4118 link_width_cntl = RREG32_PCIE_P(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
4120 switch ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) >> RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT) {
4121 case RADEON_PCIE_LC_LINK_WIDTH_X0:
4123 case RADEON_PCIE_LC_LINK_WIDTH_X1:
4125 case RADEON_PCIE_LC_LINK_WIDTH_X2:
4127 case RADEON_PCIE_LC_LINK_WIDTH_X4:
4129 case RADEON_PCIE_LC_LINK_WIDTH_X8:
4131 case RADEON_PCIE_LC_LINK_WIDTH_X16:
4137 static void r600_pcie_gen2_enable(struct radeon_device *rdev)
4139 u32 link_width_cntl, lanes, speed_cntl, training_cntl, tmp;
4144 if (radeon_pcie_gen2 == 0)
4147 if (rdev->flags & RADEON_IS_IGP)
4150 if (!(rdev->flags & RADEON_IS_PCIE))
4153 /* x2 cards have a special sequence */
4154 if (ASIC_IS_X2(rdev))
4157 /* only RV6xx+ chips are supported */
4158 if (rdev->family <= CHIP_R600)
4161 ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask);
4165 if (!(mask & DRM_PCIE_SPEED_50))
4168 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
4169 if (speed_cntl & LC_CURRENT_DATA_RATE) {
4170 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
4174 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
4176 /* 55 nm r6xx asics */
4177 if ((rdev->family == CHIP_RV670) ||
4178 (rdev->family == CHIP_RV620) ||
4179 (rdev->family == CHIP_RV635)) {
4180 /* advertise upconfig capability */
4181 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
4182 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
4183 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
4184 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
4185 if (link_width_cntl & LC_RENEGOTIATION_SUPPORT) {
4186 lanes = (link_width_cntl & LC_LINK_WIDTH_RD_MASK) >> LC_LINK_WIDTH_RD_SHIFT;
4187 link_width_cntl &= ~(LC_LINK_WIDTH_MASK |
4188 LC_RECONFIG_ARC_MISSING_ESCAPE);
4189 link_width_cntl |= lanes | LC_RECONFIG_NOW | LC_RENEGOTIATE_EN;
4190 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
4192 link_width_cntl |= LC_UPCONFIGURE_DIS;
4193 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
4197 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
4198 if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
4199 (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
4201 /* 55 nm r6xx asics */
4202 if ((rdev->family == CHIP_RV670) ||
4203 (rdev->family == CHIP_RV620) ||
4204 (rdev->family == CHIP_RV635)) {
4205 WREG32(MM_CFGREGS_CNTL, 0x8);
4206 link_cntl2 = RREG32(0x4088);
4207 WREG32(MM_CFGREGS_CNTL, 0);
4208 /* not supported yet */
4209 if (link_cntl2 & SELECTABLE_DEEMPHASIS)
4213 speed_cntl &= ~LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_MASK;
4214 speed_cntl |= (0x3 << LC_SPEED_CHANGE_ATTEMPTS_ALLOWED_SHIFT);
4215 speed_cntl &= ~LC_VOLTAGE_TIMER_SEL_MASK;
4216 speed_cntl &= ~LC_FORCE_DIS_HW_SPEED_CHANGE;
4217 speed_cntl |= LC_FORCE_EN_HW_SPEED_CHANGE;
4218 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
4220 tmp = RREG32(0x541c);
4221 WREG32(0x541c, tmp | 0x8);
4222 WREG32(MM_CFGREGS_CNTL, MM_WR_TO_CFG_EN);
4223 link_cntl2 = RREG16(0x4088);
4224 link_cntl2 &= ~TARGET_LINK_SPEED_MASK;
4226 WREG16(0x4088, link_cntl2);
4227 WREG32(MM_CFGREGS_CNTL, 0);
4229 if ((rdev->family == CHIP_RV670) ||
4230 (rdev->family == CHIP_RV620) ||
4231 (rdev->family == CHIP_RV635)) {
4232 training_cntl = RREG32_PCIE_P(PCIE_LC_TRAINING_CNTL);
4233 training_cntl &= ~LC_POINT_7_PLUS_EN;
4234 WREG32_PCIE_P(PCIE_LC_TRAINING_CNTL, training_cntl);
4236 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
4237 speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
4238 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
4241 speed_cntl = RREG32_PCIE_P(PCIE_LC_SPEED_CNTL);
4242 speed_cntl |= LC_GEN2_EN_STRAP;
4243 WREG32_PCIE_P(PCIE_LC_SPEED_CNTL, speed_cntl);
4246 link_width_cntl = RREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL);
4247 /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
4249 link_width_cntl |= LC_UPCONFIGURE_DIS;
4251 link_width_cntl &= ~LC_UPCONFIGURE_DIS;
4252 WREG32_PCIE_P(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
4257 * r600_get_gpu_clock - return GPU clock counter snapshot
4259 * @rdev: radeon_device pointer
4261 * Fetches a GPU clock counter snapshot (R6xx-cayman).
4262 * Returns the 64 bit clock counter snapshot.
4264 uint64_t r600_get_gpu_clock(struct radeon_device *rdev)
4268 mutex_lock(&rdev->gpu_clock_mutex);
4269 WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
4270 clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
4271 ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
4272 mutex_unlock(&rdev->gpu_clock_mutex);