2 * Copyright 2012 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 * Authors: Alex Deucher
24 #include <linux/firmware.h>
25 #include <linux/module.h>
28 #include "radeon_asic.h"
31 #include "cik_blit_shaders.h"
32 #include "radeon_ucode.h"
33 #include "clearstate_ci.h"
35 MODULE_FIRMWARE("radeon/BONAIRE_pfp.bin");
36 MODULE_FIRMWARE("radeon/BONAIRE_me.bin");
37 MODULE_FIRMWARE("radeon/BONAIRE_ce.bin");
38 MODULE_FIRMWARE("radeon/BONAIRE_mec.bin");
39 MODULE_FIRMWARE("radeon/BONAIRE_mc.bin");
40 MODULE_FIRMWARE("radeon/BONAIRE_mc2.bin");
41 MODULE_FIRMWARE("radeon/BONAIRE_rlc.bin");
42 MODULE_FIRMWARE("radeon/BONAIRE_sdma.bin");
43 MODULE_FIRMWARE("radeon/BONAIRE_smc.bin");
45 MODULE_FIRMWARE("radeon/bonaire_pfp.bin");
46 MODULE_FIRMWARE("radeon/bonaire_me.bin");
47 MODULE_FIRMWARE("radeon/bonaire_ce.bin");
48 MODULE_FIRMWARE("radeon/bonaire_mec.bin");
49 MODULE_FIRMWARE("radeon/bonaire_mc.bin");
50 MODULE_FIRMWARE("radeon/bonaire_rlc.bin");
51 MODULE_FIRMWARE("radeon/bonaire_sdma.bin");
52 MODULE_FIRMWARE("radeon/bonaire_smc.bin");
54 MODULE_FIRMWARE("radeon/HAWAII_pfp.bin");
55 MODULE_FIRMWARE("radeon/HAWAII_me.bin");
56 MODULE_FIRMWARE("radeon/HAWAII_ce.bin");
57 MODULE_FIRMWARE("radeon/HAWAII_mec.bin");
58 MODULE_FIRMWARE("radeon/HAWAII_mc.bin");
59 MODULE_FIRMWARE("radeon/HAWAII_mc2.bin");
60 MODULE_FIRMWARE("radeon/HAWAII_rlc.bin");
61 MODULE_FIRMWARE("radeon/HAWAII_sdma.bin");
62 MODULE_FIRMWARE("radeon/HAWAII_smc.bin");
64 MODULE_FIRMWARE("radeon/hawaii_pfp.bin");
65 MODULE_FIRMWARE("radeon/hawaii_me.bin");
66 MODULE_FIRMWARE("radeon/hawaii_ce.bin");
67 MODULE_FIRMWARE("radeon/hawaii_mec.bin");
68 MODULE_FIRMWARE("radeon/hawaii_mc.bin");
69 MODULE_FIRMWARE("radeon/hawaii_rlc.bin");
70 MODULE_FIRMWARE("radeon/hawaii_sdma.bin");
71 MODULE_FIRMWARE("radeon/hawaii_smc.bin");
73 MODULE_FIRMWARE("radeon/KAVERI_pfp.bin");
74 MODULE_FIRMWARE("radeon/KAVERI_me.bin");
75 MODULE_FIRMWARE("radeon/KAVERI_ce.bin");
76 MODULE_FIRMWARE("radeon/KAVERI_mec.bin");
77 MODULE_FIRMWARE("radeon/KAVERI_rlc.bin");
78 MODULE_FIRMWARE("radeon/KAVERI_sdma.bin");
80 MODULE_FIRMWARE("radeon/kaveri_pfp.bin");
81 MODULE_FIRMWARE("radeon/kaveri_me.bin");
82 MODULE_FIRMWARE("radeon/kaveri_ce.bin");
83 MODULE_FIRMWARE("radeon/kaveri_mec.bin");
84 MODULE_FIRMWARE("radeon/kaveri_mec2.bin");
85 MODULE_FIRMWARE("radeon/kaveri_rlc.bin");
86 MODULE_FIRMWARE("radeon/kaveri_sdma.bin");
88 MODULE_FIRMWARE("radeon/KABINI_pfp.bin");
89 MODULE_FIRMWARE("radeon/KABINI_me.bin");
90 MODULE_FIRMWARE("radeon/KABINI_ce.bin");
91 MODULE_FIRMWARE("radeon/KABINI_mec.bin");
92 MODULE_FIRMWARE("radeon/KABINI_rlc.bin");
93 MODULE_FIRMWARE("radeon/KABINI_sdma.bin");
95 MODULE_FIRMWARE("radeon/kabini_pfp.bin");
96 MODULE_FIRMWARE("radeon/kabini_me.bin");
97 MODULE_FIRMWARE("radeon/kabini_ce.bin");
98 MODULE_FIRMWARE("radeon/kabini_mec.bin");
99 MODULE_FIRMWARE("radeon/kabini_rlc.bin");
100 MODULE_FIRMWARE("radeon/kabini_sdma.bin");
102 MODULE_FIRMWARE("radeon/MULLINS_pfp.bin");
103 MODULE_FIRMWARE("radeon/MULLINS_me.bin");
104 MODULE_FIRMWARE("radeon/MULLINS_ce.bin");
105 MODULE_FIRMWARE("radeon/MULLINS_mec.bin");
106 MODULE_FIRMWARE("radeon/MULLINS_rlc.bin");
107 MODULE_FIRMWARE("radeon/MULLINS_sdma.bin");
109 MODULE_FIRMWARE("radeon/mullins_pfp.bin");
110 MODULE_FIRMWARE("radeon/mullins_me.bin");
111 MODULE_FIRMWARE("radeon/mullins_ce.bin");
112 MODULE_FIRMWARE("radeon/mullins_mec.bin");
113 MODULE_FIRMWARE("radeon/mullins_rlc.bin");
114 MODULE_FIRMWARE("radeon/mullins_sdma.bin");
116 static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh);
117 static void cik_rlc_stop(struct radeon_device *rdev);
118 static void cik_pcie_gen3_enable(struct radeon_device *rdev);
119 static void cik_program_aspm(struct radeon_device *rdev);
120 static void cik_init_pg(struct radeon_device *rdev);
121 static void cik_init_cg(struct radeon_device *rdev);
122 static void cik_fini_pg(struct radeon_device *rdev);
123 static void cik_fini_cg(struct radeon_device *rdev);
124 static void cik_enable_gui_idle_interrupt(struct radeon_device *rdev,
127 /* get temperature in millidegrees */
128 int ci_get_temp(struct radeon_device *rdev)
133 temp = (RREG32_SMC(CG_MULT_THERMAL_STATUS) & CTF_TEMP_MASK) >>
139 actual_temp = temp & 0x1ff;
141 actual_temp = actual_temp * 1000;
146 /* get temperature in millidegrees */
147 int kv_get_temp(struct radeon_device *rdev)
152 temp = RREG32_SMC(0xC0300E0C);
155 actual_temp = (temp / 8) - 49;
159 actual_temp = actual_temp * 1000;
165 * Indirect registers accessor
167 u32 cik_pciep_rreg(struct radeon_device *rdev, u32 reg)
171 spin_lock(&rdev->pciep_idx_lock);
172 WREG32(PCIE_INDEX, reg);
173 (void)RREG32(PCIE_INDEX);
174 r = RREG32(PCIE_DATA);
175 spin_unlock(&rdev->pciep_idx_lock);
179 void cik_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
181 spin_lock(&rdev->pciep_idx_lock);
182 WREG32(PCIE_INDEX, reg);
183 (void)RREG32(PCIE_INDEX);
184 WREG32(PCIE_DATA, v);
185 (void)RREG32(PCIE_DATA);
186 spin_unlock(&rdev->pciep_idx_lock);
189 static const u32 spectre_rlc_save_restore_register_list[] =
191 (0x0e00 << 16) | (0xc12c >> 2),
193 (0x0e00 << 16) | (0xc140 >> 2),
195 (0x0e00 << 16) | (0xc150 >> 2),
197 (0x0e00 << 16) | (0xc15c >> 2),
199 (0x0e00 << 16) | (0xc168 >> 2),
201 (0x0e00 << 16) | (0xc170 >> 2),
203 (0x0e00 << 16) | (0xc178 >> 2),
205 (0x0e00 << 16) | (0xc204 >> 2),
207 (0x0e00 << 16) | (0xc2b4 >> 2),
209 (0x0e00 << 16) | (0xc2b8 >> 2),
211 (0x0e00 << 16) | (0xc2bc >> 2),
213 (0x0e00 << 16) | (0xc2c0 >> 2),
215 (0x0e00 << 16) | (0x8228 >> 2),
217 (0x0e00 << 16) | (0x829c >> 2),
219 (0x0e00 << 16) | (0x869c >> 2),
221 (0x0600 << 16) | (0x98f4 >> 2),
223 (0x0e00 << 16) | (0x98f8 >> 2),
225 (0x0e00 << 16) | (0x9900 >> 2),
227 (0x0e00 << 16) | (0xc260 >> 2),
229 (0x0e00 << 16) | (0x90e8 >> 2),
231 (0x0e00 << 16) | (0x3c000 >> 2),
233 (0x0e00 << 16) | (0x3c00c >> 2),
235 (0x0e00 << 16) | (0x8c1c >> 2),
237 (0x0e00 << 16) | (0x9700 >> 2),
239 (0x0e00 << 16) | (0xcd20 >> 2),
241 (0x4e00 << 16) | (0xcd20 >> 2),
243 (0x5e00 << 16) | (0xcd20 >> 2),
245 (0x6e00 << 16) | (0xcd20 >> 2),
247 (0x7e00 << 16) | (0xcd20 >> 2),
249 (0x8e00 << 16) | (0xcd20 >> 2),
251 (0x9e00 << 16) | (0xcd20 >> 2),
253 (0xae00 << 16) | (0xcd20 >> 2),
255 (0xbe00 << 16) | (0xcd20 >> 2),
257 (0x0e00 << 16) | (0x89bc >> 2),
259 (0x0e00 << 16) | (0x8900 >> 2),
262 (0x0e00 << 16) | (0xc130 >> 2),
264 (0x0e00 << 16) | (0xc134 >> 2),
266 (0x0e00 << 16) | (0xc1fc >> 2),
268 (0x0e00 << 16) | (0xc208 >> 2),
270 (0x0e00 << 16) | (0xc264 >> 2),
272 (0x0e00 << 16) | (0xc268 >> 2),
274 (0x0e00 << 16) | (0xc26c >> 2),
276 (0x0e00 << 16) | (0xc270 >> 2),
278 (0x0e00 << 16) | (0xc274 >> 2),
280 (0x0e00 << 16) | (0xc278 >> 2),
282 (0x0e00 << 16) | (0xc27c >> 2),
284 (0x0e00 << 16) | (0xc280 >> 2),
286 (0x0e00 << 16) | (0xc284 >> 2),
288 (0x0e00 << 16) | (0xc288 >> 2),
290 (0x0e00 << 16) | (0xc28c >> 2),
292 (0x0e00 << 16) | (0xc290 >> 2),
294 (0x0e00 << 16) | (0xc294 >> 2),
296 (0x0e00 << 16) | (0xc298 >> 2),
298 (0x0e00 << 16) | (0xc29c >> 2),
300 (0x0e00 << 16) | (0xc2a0 >> 2),
302 (0x0e00 << 16) | (0xc2a4 >> 2),
304 (0x0e00 << 16) | (0xc2a8 >> 2),
306 (0x0e00 << 16) | (0xc2ac >> 2),
308 (0x0e00 << 16) | (0xc2b0 >> 2),
310 (0x0e00 << 16) | (0x301d0 >> 2),
312 (0x0e00 << 16) | (0x30238 >> 2),
314 (0x0e00 << 16) | (0x30250 >> 2),
316 (0x0e00 << 16) | (0x30254 >> 2),
318 (0x0e00 << 16) | (0x30258 >> 2),
320 (0x0e00 << 16) | (0x3025c >> 2),
322 (0x4e00 << 16) | (0xc900 >> 2),
324 (0x5e00 << 16) | (0xc900 >> 2),
326 (0x6e00 << 16) | (0xc900 >> 2),
328 (0x7e00 << 16) | (0xc900 >> 2),
330 (0x8e00 << 16) | (0xc900 >> 2),
332 (0x9e00 << 16) | (0xc900 >> 2),
334 (0xae00 << 16) | (0xc900 >> 2),
336 (0xbe00 << 16) | (0xc900 >> 2),
338 (0x4e00 << 16) | (0xc904 >> 2),
340 (0x5e00 << 16) | (0xc904 >> 2),
342 (0x6e00 << 16) | (0xc904 >> 2),
344 (0x7e00 << 16) | (0xc904 >> 2),
346 (0x8e00 << 16) | (0xc904 >> 2),
348 (0x9e00 << 16) | (0xc904 >> 2),
350 (0xae00 << 16) | (0xc904 >> 2),
352 (0xbe00 << 16) | (0xc904 >> 2),
354 (0x4e00 << 16) | (0xc908 >> 2),
356 (0x5e00 << 16) | (0xc908 >> 2),
358 (0x6e00 << 16) | (0xc908 >> 2),
360 (0x7e00 << 16) | (0xc908 >> 2),
362 (0x8e00 << 16) | (0xc908 >> 2),
364 (0x9e00 << 16) | (0xc908 >> 2),
366 (0xae00 << 16) | (0xc908 >> 2),
368 (0xbe00 << 16) | (0xc908 >> 2),
370 (0x4e00 << 16) | (0xc90c >> 2),
372 (0x5e00 << 16) | (0xc90c >> 2),
374 (0x6e00 << 16) | (0xc90c >> 2),
376 (0x7e00 << 16) | (0xc90c >> 2),
378 (0x8e00 << 16) | (0xc90c >> 2),
380 (0x9e00 << 16) | (0xc90c >> 2),
382 (0xae00 << 16) | (0xc90c >> 2),
384 (0xbe00 << 16) | (0xc90c >> 2),
386 (0x4e00 << 16) | (0xc910 >> 2),
388 (0x5e00 << 16) | (0xc910 >> 2),
390 (0x6e00 << 16) | (0xc910 >> 2),
392 (0x7e00 << 16) | (0xc910 >> 2),
394 (0x8e00 << 16) | (0xc910 >> 2),
396 (0x9e00 << 16) | (0xc910 >> 2),
398 (0xae00 << 16) | (0xc910 >> 2),
400 (0xbe00 << 16) | (0xc910 >> 2),
402 (0x0e00 << 16) | (0xc99c >> 2),
404 (0x0e00 << 16) | (0x9834 >> 2),
406 (0x0000 << 16) | (0x30f00 >> 2),
408 (0x0001 << 16) | (0x30f00 >> 2),
410 (0x0000 << 16) | (0x30f04 >> 2),
412 (0x0001 << 16) | (0x30f04 >> 2),
414 (0x0000 << 16) | (0x30f08 >> 2),
416 (0x0001 << 16) | (0x30f08 >> 2),
418 (0x0000 << 16) | (0x30f0c >> 2),
420 (0x0001 << 16) | (0x30f0c >> 2),
422 (0x0600 << 16) | (0x9b7c >> 2),
424 (0x0e00 << 16) | (0x8a14 >> 2),
426 (0x0e00 << 16) | (0x8a18 >> 2),
428 (0x0600 << 16) | (0x30a00 >> 2),
430 (0x0e00 << 16) | (0x8bf0 >> 2),
432 (0x0e00 << 16) | (0x8bcc >> 2),
434 (0x0e00 << 16) | (0x8b24 >> 2),
436 (0x0e00 << 16) | (0x30a04 >> 2),
438 (0x0600 << 16) | (0x30a10 >> 2),
440 (0x0600 << 16) | (0x30a14 >> 2),
442 (0x0600 << 16) | (0x30a18 >> 2),
444 (0x0600 << 16) | (0x30a2c >> 2),
446 (0x0e00 << 16) | (0xc700 >> 2),
448 (0x0e00 << 16) | (0xc704 >> 2),
450 (0x0e00 << 16) | (0xc708 >> 2),
452 (0x0e00 << 16) | (0xc768 >> 2),
454 (0x0400 << 16) | (0xc770 >> 2),
456 (0x0400 << 16) | (0xc774 >> 2),
458 (0x0400 << 16) | (0xc778 >> 2),
460 (0x0400 << 16) | (0xc77c >> 2),
462 (0x0400 << 16) | (0xc780 >> 2),
464 (0x0400 << 16) | (0xc784 >> 2),
466 (0x0400 << 16) | (0xc788 >> 2),
468 (0x0400 << 16) | (0xc78c >> 2),
470 (0x0400 << 16) | (0xc798 >> 2),
472 (0x0400 << 16) | (0xc79c >> 2),
474 (0x0400 << 16) | (0xc7a0 >> 2),
476 (0x0400 << 16) | (0xc7a4 >> 2),
478 (0x0400 << 16) | (0xc7a8 >> 2),
480 (0x0400 << 16) | (0xc7ac >> 2),
482 (0x0400 << 16) | (0xc7b0 >> 2),
484 (0x0400 << 16) | (0xc7b4 >> 2),
486 (0x0e00 << 16) | (0x9100 >> 2),
488 (0x0e00 << 16) | (0x3c010 >> 2),
490 (0x0e00 << 16) | (0x92a8 >> 2),
492 (0x0e00 << 16) | (0x92ac >> 2),
494 (0x0e00 << 16) | (0x92b4 >> 2),
496 (0x0e00 << 16) | (0x92b8 >> 2),
498 (0x0e00 << 16) | (0x92bc >> 2),
500 (0x0e00 << 16) | (0x92c0 >> 2),
502 (0x0e00 << 16) | (0x92c4 >> 2),
504 (0x0e00 << 16) | (0x92c8 >> 2),
506 (0x0e00 << 16) | (0x92cc >> 2),
508 (0x0e00 << 16) | (0x92d0 >> 2),
510 (0x0e00 << 16) | (0x8c00 >> 2),
512 (0x0e00 << 16) | (0x8c04 >> 2),
514 (0x0e00 << 16) | (0x8c20 >> 2),
516 (0x0e00 << 16) | (0x8c38 >> 2),
518 (0x0e00 << 16) | (0x8c3c >> 2),
520 (0x0e00 << 16) | (0xae00 >> 2),
522 (0x0e00 << 16) | (0x9604 >> 2),
524 (0x0e00 << 16) | (0xac08 >> 2),
526 (0x0e00 << 16) | (0xac0c >> 2),
528 (0x0e00 << 16) | (0xac10 >> 2),
530 (0x0e00 << 16) | (0xac14 >> 2),
532 (0x0e00 << 16) | (0xac58 >> 2),
534 (0x0e00 << 16) | (0xac68 >> 2),
536 (0x0e00 << 16) | (0xac6c >> 2),
538 (0x0e00 << 16) | (0xac70 >> 2),
540 (0x0e00 << 16) | (0xac74 >> 2),
542 (0x0e00 << 16) | (0xac78 >> 2),
544 (0x0e00 << 16) | (0xac7c >> 2),
546 (0x0e00 << 16) | (0xac80 >> 2),
548 (0x0e00 << 16) | (0xac84 >> 2),
550 (0x0e00 << 16) | (0xac88 >> 2),
552 (0x0e00 << 16) | (0xac8c >> 2),
554 (0x0e00 << 16) | (0x970c >> 2),
556 (0x0e00 << 16) | (0x9714 >> 2),
558 (0x0e00 << 16) | (0x9718 >> 2),
560 (0x0e00 << 16) | (0x971c >> 2),
562 (0x0e00 << 16) | (0x31068 >> 2),
564 (0x4e00 << 16) | (0x31068 >> 2),
566 (0x5e00 << 16) | (0x31068 >> 2),
568 (0x6e00 << 16) | (0x31068 >> 2),
570 (0x7e00 << 16) | (0x31068 >> 2),
572 (0x8e00 << 16) | (0x31068 >> 2),
574 (0x9e00 << 16) | (0x31068 >> 2),
576 (0xae00 << 16) | (0x31068 >> 2),
578 (0xbe00 << 16) | (0x31068 >> 2),
580 (0x0e00 << 16) | (0xcd10 >> 2),
582 (0x0e00 << 16) | (0xcd14 >> 2),
584 (0x0e00 << 16) | (0x88b0 >> 2),
586 (0x0e00 << 16) | (0x88b4 >> 2),
588 (0x0e00 << 16) | (0x88b8 >> 2),
590 (0x0e00 << 16) | (0x88bc >> 2),
592 (0x0400 << 16) | (0x89c0 >> 2),
594 (0x0e00 << 16) | (0x88c4 >> 2),
596 (0x0e00 << 16) | (0x88c8 >> 2),
598 (0x0e00 << 16) | (0x88d0 >> 2),
600 (0x0e00 << 16) | (0x88d4 >> 2),
602 (0x0e00 << 16) | (0x88d8 >> 2),
604 (0x0e00 << 16) | (0x8980 >> 2),
606 (0x0e00 << 16) | (0x30938 >> 2),
608 (0x0e00 << 16) | (0x3093c >> 2),
610 (0x0e00 << 16) | (0x30940 >> 2),
612 (0x0e00 << 16) | (0x89a0 >> 2),
614 (0x0e00 << 16) | (0x30900 >> 2),
616 (0x0e00 << 16) | (0x30904 >> 2),
618 (0x0e00 << 16) | (0x89b4 >> 2),
620 (0x0e00 << 16) | (0x3c210 >> 2),
622 (0x0e00 << 16) | (0x3c214 >> 2),
624 (0x0e00 << 16) | (0x3c218 >> 2),
626 (0x0e00 << 16) | (0x8904 >> 2),
629 (0x0e00 << 16) | (0x8c28 >> 2),
630 (0x0e00 << 16) | (0x8c2c >> 2),
631 (0x0e00 << 16) | (0x8c30 >> 2),
632 (0x0e00 << 16) | (0x8c34 >> 2),
633 (0x0e00 << 16) | (0x9600 >> 2),
636 static const u32 kalindi_rlc_save_restore_register_list[] =
638 (0x0e00 << 16) | (0xc12c >> 2),
640 (0x0e00 << 16) | (0xc140 >> 2),
642 (0x0e00 << 16) | (0xc150 >> 2),
644 (0x0e00 << 16) | (0xc15c >> 2),
646 (0x0e00 << 16) | (0xc168 >> 2),
648 (0x0e00 << 16) | (0xc170 >> 2),
650 (0x0e00 << 16) | (0xc204 >> 2),
652 (0x0e00 << 16) | (0xc2b4 >> 2),
654 (0x0e00 << 16) | (0xc2b8 >> 2),
656 (0x0e00 << 16) | (0xc2bc >> 2),
658 (0x0e00 << 16) | (0xc2c0 >> 2),
660 (0x0e00 << 16) | (0x8228 >> 2),
662 (0x0e00 << 16) | (0x829c >> 2),
664 (0x0e00 << 16) | (0x869c >> 2),
666 (0x0600 << 16) | (0x98f4 >> 2),
668 (0x0e00 << 16) | (0x98f8 >> 2),
670 (0x0e00 << 16) | (0x9900 >> 2),
672 (0x0e00 << 16) | (0xc260 >> 2),
674 (0x0e00 << 16) | (0x90e8 >> 2),
676 (0x0e00 << 16) | (0x3c000 >> 2),
678 (0x0e00 << 16) | (0x3c00c >> 2),
680 (0x0e00 << 16) | (0x8c1c >> 2),
682 (0x0e00 << 16) | (0x9700 >> 2),
684 (0x0e00 << 16) | (0xcd20 >> 2),
686 (0x4e00 << 16) | (0xcd20 >> 2),
688 (0x5e00 << 16) | (0xcd20 >> 2),
690 (0x6e00 << 16) | (0xcd20 >> 2),
692 (0x7e00 << 16) | (0xcd20 >> 2),
694 (0x0e00 << 16) | (0x89bc >> 2),
696 (0x0e00 << 16) | (0x8900 >> 2),
699 (0x0e00 << 16) | (0xc130 >> 2),
701 (0x0e00 << 16) | (0xc134 >> 2),
703 (0x0e00 << 16) | (0xc1fc >> 2),
705 (0x0e00 << 16) | (0xc208 >> 2),
707 (0x0e00 << 16) | (0xc264 >> 2),
709 (0x0e00 << 16) | (0xc268 >> 2),
711 (0x0e00 << 16) | (0xc26c >> 2),
713 (0x0e00 << 16) | (0xc270 >> 2),
715 (0x0e00 << 16) | (0xc274 >> 2),
717 (0x0e00 << 16) | (0xc28c >> 2),
719 (0x0e00 << 16) | (0xc290 >> 2),
721 (0x0e00 << 16) | (0xc294 >> 2),
723 (0x0e00 << 16) | (0xc298 >> 2),
725 (0x0e00 << 16) | (0xc2a0 >> 2),
727 (0x0e00 << 16) | (0xc2a4 >> 2),
729 (0x0e00 << 16) | (0xc2a8 >> 2),
731 (0x0e00 << 16) | (0xc2ac >> 2),
733 (0x0e00 << 16) | (0x301d0 >> 2),
735 (0x0e00 << 16) | (0x30238 >> 2),
737 (0x0e00 << 16) | (0x30250 >> 2),
739 (0x0e00 << 16) | (0x30254 >> 2),
741 (0x0e00 << 16) | (0x30258 >> 2),
743 (0x0e00 << 16) | (0x3025c >> 2),
745 (0x4e00 << 16) | (0xc900 >> 2),
747 (0x5e00 << 16) | (0xc900 >> 2),
749 (0x6e00 << 16) | (0xc900 >> 2),
751 (0x7e00 << 16) | (0xc900 >> 2),
753 (0x4e00 << 16) | (0xc904 >> 2),
755 (0x5e00 << 16) | (0xc904 >> 2),
757 (0x6e00 << 16) | (0xc904 >> 2),
759 (0x7e00 << 16) | (0xc904 >> 2),
761 (0x4e00 << 16) | (0xc908 >> 2),
763 (0x5e00 << 16) | (0xc908 >> 2),
765 (0x6e00 << 16) | (0xc908 >> 2),
767 (0x7e00 << 16) | (0xc908 >> 2),
769 (0x4e00 << 16) | (0xc90c >> 2),
771 (0x5e00 << 16) | (0xc90c >> 2),
773 (0x6e00 << 16) | (0xc90c >> 2),
775 (0x7e00 << 16) | (0xc90c >> 2),
777 (0x4e00 << 16) | (0xc910 >> 2),
779 (0x5e00 << 16) | (0xc910 >> 2),
781 (0x6e00 << 16) | (0xc910 >> 2),
783 (0x7e00 << 16) | (0xc910 >> 2),
785 (0x0e00 << 16) | (0xc99c >> 2),
787 (0x0e00 << 16) | (0x9834 >> 2),
789 (0x0000 << 16) | (0x30f00 >> 2),
791 (0x0000 << 16) | (0x30f04 >> 2),
793 (0x0000 << 16) | (0x30f08 >> 2),
795 (0x0000 << 16) | (0x30f0c >> 2),
797 (0x0600 << 16) | (0x9b7c >> 2),
799 (0x0e00 << 16) | (0x8a14 >> 2),
801 (0x0e00 << 16) | (0x8a18 >> 2),
803 (0x0600 << 16) | (0x30a00 >> 2),
805 (0x0e00 << 16) | (0x8bf0 >> 2),
807 (0x0e00 << 16) | (0x8bcc >> 2),
809 (0x0e00 << 16) | (0x8b24 >> 2),
811 (0x0e00 << 16) | (0x30a04 >> 2),
813 (0x0600 << 16) | (0x30a10 >> 2),
815 (0x0600 << 16) | (0x30a14 >> 2),
817 (0x0600 << 16) | (0x30a18 >> 2),
819 (0x0600 << 16) | (0x30a2c >> 2),
821 (0x0e00 << 16) | (0xc700 >> 2),
823 (0x0e00 << 16) | (0xc704 >> 2),
825 (0x0e00 << 16) | (0xc708 >> 2),
827 (0x0e00 << 16) | (0xc768 >> 2),
829 (0x0400 << 16) | (0xc770 >> 2),
831 (0x0400 << 16) | (0xc774 >> 2),
833 (0x0400 << 16) | (0xc798 >> 2),
835 (0x0400 << 16) | (0xc79c >> 2),
837 (0x0e00 << 16) | (0x9100 >> 2),
839 (0x0e00 << 16) | (0x3c010 >> 2),
841 (0x0e00 << 16) | (0x8c00 >> 2),
843 (0x0e00 << 16) | (0x8c04 >> 2),
845 (0x0e00 << 16) | (0x8c20 >> 2),
847 (0x0e00 << 16) | (0x8c38 >> 2),
849 (0x0e00 << 16) | (0x8c3c >> 2),
851 (0x0e00 << 16) | (0xae00 >> 2),
853 (0x0e00 << 16) | (0x9604 >> 2),
855 (0x0e00 << 16) | (0xac08 >> 2),
857 (0x0e00 << 16) | (0xac0c >> 2),
859 (0x0e00 << 16) | (0xac10 >> 2),
861 (0x0e00 << 16) | (0xac14 >> 2),
863 (0x0e00 << 16) | (0xac58 >> 2),
865 (0x0e00 << 16) | (0xac68 >> 2),
867 (0x0e00 << 16) | (0xac6c >> 2),
869 (0x0e00 << 16) | (0xac70 >> 2),
871 (0x0e00 << 16) | (0xac74 >> 2),
873 (0x0e00 << 16) | (0xac78 >> 2),
875 (0x0e00 << 16) | (0xac7c >> 2),
877 (0x0e00 << 16) | (0xac80 >> 2),
879 (0x0e00 << 16) | (0xac84 >> 2),
881 (0x0e00 << 16) | (0xac88 >> 2),
883 (0x0e00 << 16) | (0xac8c >> 2),
885 (0x0e00 << 16) | (0x970c >> 2),
887 (0x0e00 << 16) | (0x9714 >> 2),
889 (0x0e00 << 16) | (0x9718 >> 2),
891 (0x0e00 << 16) | (0x971c >> 2),
893 (0x0e00 << 16) | (0x31068 >> 2),
895 (0x4e00 << 16) | (0x31068 >> 2),
897 (0x5e00 << 16) | (0x31068 >> 2),
899 (0x6e00 << 16) | (0x31068 >> 2),
901 (0x7e00 << 16) | (0x31068 >> 2),
903 (0x0e00 << 16) | (0xcd10 >> 2),
905 (0x0e00 << 16) | (0xcd14 >> 2),
907 (0x0e00 << 16) | (0x88b0 >> 2),
909 (0x0e00 << 16) | (0x88b4 >> 2),
911 (0x0e00 << 16) | (0x88b8 >> 2),
913 (0x0e00 << 16) | (0x88bc >> 2),
915 (0x0400 << 16) | (0x89c0 >> 2),
917 (0x0e00 << 16) | (0x88c4 >> 2),
919 (0x0e00 << 16) | (0x88c8 >> 2),
921 (0x0e00 << 16) | (0x88d0 >> 2),
923 (0x0e00 << 16) | (0x88d4 >> 2),
925 (0x0e00 << 16) | (0x88d8 >> 2),
927 (0x0e00 << 16) | (0x8980 >> 2),
929 (0x0e00 << 16) | (0x30938 >> 2),
931 (0x0e00 << 16) | (0x3093c >> 2),
933 (0x0e00 << 16) | (0x30940 >> 2),
935 (0x0e00 << 16) | (0x89a0 >> 2),
937 (0x0e00 << 16) | (0x30900 >> 2),
939 (0x0e00 << 16) | (0x30904 >> 2),
941 (0x0e00 << 16) | (0x89b4 >> 2),
943 (0x0e00 << 16) | (0x3e1fc >> 2),
945 (0x0e00 << 16) | (0x3c210 >> 2),
947 (0x0e00 << 16) | (0x3c214 >> 2),
949 (0x0e00 << 16) | (0x3c218 >> 2),
951 (0x0e00 << 16) | (0x8904 >> 2),
954 (0x0e00 << 16) | (0x8c28 >> 2),
955 (0x0e00 << 16) | (0x8c2c >> 2),
956 (0x0e00 << 16) | (0x8c30 >> 2),
957 (0x0e00 << 16) | (0x8c34 >> 2),
958 (0x0e00 << 16) | (0x9600 >> 2),
961 static const u32 bonaire_golden_spm_registers[] =
963 0x30800, 0xe0ffffff, 0xe0000000
966 static const u32 bonaire_golden_common_registers[] =
968 0xc770, 0xffffffff, 0x00000800,
969 0xc774, 0xffffffff, 0x00000800,
970 0xc798, 0xffffffff, 0x00007fbf,
971 0xc79c, 0xffffffff, 0x00007faf
974 static const u32 bonaire_golden_registers[] =
976 0x3354, 0x00000333, 0x00000333,
977 0x3350, 0x000c0fc0, 0x00040200,
978 0x9a10, 0x00010000, 0x00058208,
979 0x3c000, 0xffff1fff, 0x00140000,
980 0x3c200, 0xfdfc0fff, 0x00000100,
981 0x3c234, 0x40000000, 0x40000200,
982 0x9830, 0xffffffff, 0x00000000,
983 0x9834, 0xf00fffff, 0x00000400,
984 0x9838, 0x0002021c, 0x00020200,
985 0xc78, 0x00000080, 0x00000000,
986 0x5bb0, 0x000000f0, 0x00000070,
987 0x5bc0, 0xf0311fff, 0x80300000,
988 0x98f8, 0x73773777, 0x12010001,
989 0x350c, 0x00810000, 0x408af000,
990 0x7030, 0x31000111, 0x00000011,
991 0x2f48, 0x73773777, 0x12010001,
992 0x220c, 0x00007fb6, 0x0021a1b1,
993 0x2210, 0x00007fb6, 0x002021b1,
994 0x2180, 0x00007fb6, 0x00002191,
995 0x2218, 0x00007fb6, 0x002121b1,
996 0x221c, 0x00007fb6, 0x002021b1,
997 0x21dc, 0x00007fb6, 0x00002191,
998 0x21e0, 0x00007fb6, 0x00002191,
999 0x3628, 0x0000003f, 0x0000000a,
1000 0x362c, 0x0000003f, 0x0000000a,
1001 0x2ae4, 0x00073ffe, 0x000022a2,
1002 0x240c, 0x000007ff, 0x00000000,
1003 0x8a14, 0xf000003f, 0x00000007,
1004 0x8bf0, 0x00002001, 0x00000001,
1005 0x8b24, 0xffffffff, 0x00ffffff,
1006 0x30a04, 0x0000ff0f, 0x00000000,
1007 0x28a4c, 0x07ffffff, 0x06000000,
1008 0x4d8, 0x00000fff, 0x00000100,
1009 0x3e78, 0x00000001, 0x00000002,
1010 0x9100, 0x03000000, 0x0362c688,
1011 0x8c00, 0x000000ff, 0x00000001,
1012 0xe40, 0x00001fff, 0x00001fff,
1013 0x9060, 0x0000007f, 0x00000020,
1014 0x9508, 0x00010000, 0x00010000,
1015 0xac14, 0x000003ff, 0x000000f3,
1016 0xac0c, 0xffffffff, 0x00001032
1019 static const u32 bonaire_mgcg_cgcg_init[] =
1021 0xc420, 0xffffffff, 0xfffffffc,
1022 0x30800, 0xffffffff, 0xe0000000,
1023 0x3c2a0, 0xffffffff, 0x00000100,
1024 0x3c208, 0xffffffff, 0x00000100,
1025 0x3c2c0, 0xffffffff, 0xc0000100,
1026 0x3c2c8, 0xffffffff, 0xc0000100,
1027 0x3c2c4, 0xffffffff, 0xc0000100,
1028 0x55e4, 0xffffffff, 0x00600100,
1029 0x3c280, 0xffffffff, 0x00000100,
1030 0x3c214, 0xffffffff, 0x06000100,
1031 0x3c220, 0xffffffff, 0x00000100,
1032 0x3c218, 0xffffffff, 0x06000100,
1033 0x3c204, 0xffffffff, 0x00000100,
1034 0x3c2e0, 0xffffffff, 0x00000100,
1035 0x3c224, 0xffffffff, 0x00000100,
1036 0x3c200, 0xffffffff, 0x00000100,
1037 0x3c230, 0xffffffff, 0x00000100,
1038 0x3c234, 0xffffffff, 0x00000100,
1039 0x3c250, 0xffffffff, 0x00000100,
1040 0x3c254, 0xffffffff, 0x00000100,
1041 0x3c258, 0xffffffff, 0x00000100,
1042 0x3c25c, 0xffffffff, 0x00000100,
1043 0x3c260, 0xffffffff, 0x00000100,
1044 0x3c27c, 0xffffffff, 0x00000100,
1045 0x3c278, 0xffffffff, 0x00000100,
1046 0x3c210, 0xffffffff, 0x06000100,
1047 0x3c290, 0xffffffff, 0x00000100,
1048 0x3c274, 0xffffffff, 0x00000100,
1049 0x3c2b4, 0xffffffff, 0x00000100,
1050 0x3c2b0, 0xffffffff, 0x00000100,
1051 0x3c270, 0xffffffff, 0x00000100,
1052 0x30800, 0xffffffff, 0xe0000000,
1053 0x3c020, 0xffffffff, 0x00010000,
1054 0x3c024, 0xffffffff, 0x00030002,
1055 0x3c028, 0xffffffff, 0x00040007,
1056 0x3c02c, 0xffffffff, 0x00060005,
1057 0x3c030, 0xffffffff, 0x00090008,
1058 0x3c034, 0xffffffff, 0x00010000,
1059 0x3c038, 0xffffffff, 0x00030002,
1060 0x3c03c, 0xffffffff, 0x00040007,
1061 0x3c040, 0xffffffff, 0x00060005,
1062 0x3c044, 0xffffffff, 0x00090008,
1063 0x3c048, 0xffffffff, 0x00010000,
1064 0x3c04c, 0xffffffff, 0x00030002,
1065 0x3c050, 0xffffffff, 0x00040007,
1066 0x3c054, 0xffffffff, 0x00060005,
1067 0x3c058, 0xffffffff, 0x00090008,
1068 0x3c05c, 0xffffffff, 0x00010000,
1069 0x3c060, 0xffffffff, 0x00030002,
1070 0x3c064, 0xffffffff, 0x00040007,
1071 0x3c068, 0xffffffff, 0x00060005,
1072 0x3c06c, 0xffffffff, 0x00090008,
1073 0x3c070, 0xffffffff, 0x00010000,
1074 0x3c074, 0xffffffff, 0x00030002,
1075 0x3c078, 0xffffffff, 0x00040007,
1076 0x3c07c, 0xffffffff, 0x00060005,
1077 0x3c080, 0xffffffff, 0x00090008,
1078 0x3c084, 0xffffffff, 0x00010000,
1079 0x3c088, 0xffffffff, 0x00030002,
1080 0x3c08c, 0xffffffff, 0x00040007,
1081 0x3c090, 0xffffffff, 0x00060005,
1082 0x3c094, 0xffffffff, 0x00090008,
1083 0x3c098, 0xffffffff, 0x00010000,
1084 0x3c09c, 0xffffffff, 0x00030002,
1085 0x3c0a0, 0xffffffff, 0x00040007,
1086 0x3c0a4, 0xffffffff, 0x00060005,
1087 0x3c0a8, 0xffffffff, 0x00090008,
1088 0x3c000, 0xffffffff, 0x96e00200,
1089 0x8708, 0xffffffff, 0x00900100,
1090 0xc424, 0xffffffff, 0x0020003f,
1091 0x38, 0xffffffff, 0x0140001c,
1092 0x3c, 0x000f0000, 0x000f0000,
1093 0x220, 0xffffffff, 0xC060000C,
1094 0x224, 0xc0000fff, 0x00000100,
1095 0xf90, 0xffffffff, 0x00000100,
1096 0xf98, 0x00000101, 0x00000000,
1097 0x20a8, 0xffffffff, 0x00000104,
1098 0x55e4, 0xff000fff, 0x00000100,
1099 0x30cc, 0xc0000fff, 0x00000104,
1100 0xc1e4, 0x00000001, 0x00000001,
1101 0xd00c, 0xff000ff0, 0x00000100,
1102 0xd80c, 0xff000ff0, 0x00000100
1105 static const u32 spectre_golden_spm_registers[] =
1107 0x30800, 0xe0ffffff, 0xe0000000
1110 static const u32 spectre_golden_common_registers[] =
1112 0xc770, 0xffffffff, 0x00000800,
1113 0xc774, 0xffffffff, 0x00000800,
1114 0xc798, 0xffffffff, 0x00007fbf,
1115 0xc79c, 0xffffffff, 0x00007faf
1118 static const u32 spectre_golden_registers[] =
1120 0x3c000, 0xffff1fff, 0x96940200,
1121 0x3c00c, 0xffff0001, 0xff000000,
1122 0x3c200, 0xfffc0fff, 0x00000100,
1123 0x6ed8, 0x00010101, 0x00010000,
1124 0x9834, 0xf00fffff, 0x00000400,
1125 0x9838, 0xfffffffc, 0x00020200,
1126 0x5bb0, 0x000000f0, 0x00000070,
1127 0x5bc0, 0xf0311fff, 0x80300000,
1128 0x98f8, 0x73773777, 0x12010001,
1129 0x9b7c, 0x00ff0000, 0x00fc0000,
1130 0x2f48, 0x73773777, 0x12010001,
1131 0x8a14, 0xf000003f, 0x00000007,
1132 0x8b24, 0xffffffff, 0x00ffffff,
1133 0x28350, 0x3f3f3fff, 0x00000082,
1134 0x28354, 0x0000003f, 0x00000000,
1135 0x3e78, 0x00000001, 0x00000002,
1136 0x913c, 0xffff03df, 0x00000004,
1137 0xc768, 0x00000008, 0x00000008,
1138 0x8c00, 0x000008ff, 0x00000800,
1139 0x9508, 0x00010000, 0x00010000,
1140 0xac0c, 0xffffffff, 0x54763210,
1141 0x214f8, 0x01ff01ff, 0x00000002,
1142 0x21498, 0x007ff800, 0x00200000,
1143 0x2015c, 0xffffffff, 0x00000f40,
1144 0x30934, 0xffffffff, 0x00000001
1147 static const u32 spectre_mgcg_cgcg_init[] =
1149 0xc420, 0xffffffff, 0xfffffffc,
1150 0x30800, 0xffffffff, 0xe0000000,
1151 0x3c2a0, 0xffffffff, 0x00000100,
1152 0x3c208, 0xffffffff, 0x00000100,
1153 0x3c2c0, 0xffffffff, 0x00000100,
1154 0x3c2c8, 0xffffffff, 0x00000100,
1155 0x3c2c4, 0xffffffff, 0x00000100,
1156 0x55e4, 0xffffffff, 0x00600100,
1157 0x3c280, 0xffffffff, 0x00000100,
1158 0x3c214, 0xffffffff, 0x06000100,
1159 0x3c220, 0xffffffff, 0x00000100,
1160 0x3c218, 0xffffffff, 0x06000100,
1161 0x3c204, 0xffffffff, 0x00000100,
1162 0x3c2e0, 0xffffffff, 0x00000100,
1163 0x3c224, 0xffffffff, 0x00000100,
1164 0x3c200, 0xffffffff, 0x00000100,
1165 0x3c230, 0xffffffff, 0x00000100,
1166 0x3c234, 0xffffffff, 0x00000100,
1167 0x3c250, 0xffffffff, 0x00000100,
1168 0x3c254, 0xffffffff, 0x00000100,
1169 0x3c258, 0xffffffff, 0x00000100,
1170 0x3c25c, 0xffffffff, 0x00000100,
1171 0x3c260, 0xffffffff, 0x00000100,
1172 0x3c27c, 0xffffffff, 0x00000100,
1173 0x3c278, 0xffffffff, 0x00000100,
1174 0x3c210, 0xffffffff, 0x06000100,
1175 0x3c290, 0xffffffff, 0x00000100,
1176 0x3c274, 0xffffffff, 0x00000100,
1177 0x3c2b4, 0xffffffff, 0x00000100,
1178 0x3c2b0, 0xffffffff, 0x00000100,
1179 0x3c270, 0xffffffff, 0x00000100,
1180 0x30800, 0xffffffff, 0xe0000000,
1181 0x3c020, 0xffffffff, 0x00010000,
1182 0x3c024, 0xffffffff, 0x00030002,
1183 0x3c028, 0xffffffff, 0x00040007,
1184 0x3c02c, 0xffffffff, 0x00060005,
1185 0x3c030, 0xffffffff, 0x00090008,
1186 0x3c034, 0xffffffff, 0x00010000,
1187 0x3c038, 0xffffffff, 0x00030002,
1188 0x3c03c, 0xffffffff, 0x00040007,
1189 0x3c040, 0xffffffff, 0x00060005,
1190 0x3c044, 0xffffffff, 0x00090008,
1191 0x3c048, 0xffffffff, 0x00010000,
1192 0x3c04c, 0xffffffff, 0x00030002,
1193 0x3c050, 0xffffffff, 0x00040007,
1194 0x3c054, 0xffffffff, 0x00060005,
1195 0x3c058, 0xffffffff, 0x00090008,
1196 0x3c05c, 0xffffffff, 0x00010000,
1197 0x3c060, 0xffffffff, 0x00030002,
1198 0x3c064, 0xffffffff, 0x00040007,
1199 0x3c068, 0xffffffff, 0x00060005,
1200 0x3c06c, 0xffffffff, 0x00090008,
1201 0x3c070, 0xffffffff, 0x00010000,
1202 0x3c074, 0xffffffff, 0x00030002,
1203 0x3c078, 0xffffffff, 0x00040007,
1204 0x3c07c, 0xffffffff, 0x00060005,
1205 0x3c080, 0xffffffff, 0x00090008,
1206 0x3c084, 0xffffffff, 0x00010000,
1207 0x3c088, 0xffffffff, 0x00030002,
1208 0x3c08c, 0xffffffff, 0x00040007,
1209 0x3c090, 0xffffffff, 0x00060005,
1210 0x3c094, 0xffffffff, 0x00090008,
1211 0x3c098, 0xffffffff, 0x00010000,
1212 0x3c09c, 0xffffffff, 0x00030002,
1213 0x3c0a0, 0xffffffff, 0x00040007,
1214 0x3c0a4, 0xffffffff, 0x00060005,
1215 0x3c0a8, 0xffffffff, 0x00090008,
1216 0x3c0ac, 0xffffffff, 0x00010000,
1217 0x3c0b0, 0xffffffff, 0x00030002,
1218 0x3c0b4, 0xffffffff, 0x00040007,
1219 0x3c0b8, 0xffffffff, 0x00060005,
1220 0x3c0bc, 0xffffffff, 0x00090008,
1221 0x3c000, 0xffffffff, 0x96e00200,
1222 0x8708, 0xffffffff, 0x00900100,
1223 0xc424, 0xffffffff, 0x0020003f,
1224 0x38, 0xffffffff, 0x0140001c,
1225 0x3c, 0x000f0000, 0x000f0000,
1226 0x220, 0xffffffff, 0xC060000C,
1227 0x224, 0xc0000fff, 0x00000100,
1228 0xf90, 0xffffffff, 0x00000100,
1229 0xf98, 0x00000101, 0x00000000,
1230 0x20a8, 0xffffffff, 0x00000104,
1231 0x55e4, 0xff000fff, 0x00000100,
1232 0x30cc, 0xc0000fff, 0x00000104,
1233 0xc1e4, 0x00000001, 0x00000001,
1234 0xd00c, 0xff000ff0, 0x00000100,
1235 0xd80c, 0xff000ff0, 0x00000100
1238 static const u32 kalindi_golden_spm_registers[] =
1240 0x30800, 0xe0ffffff, 0xe0000000
1243 static const u32 kalindi_golden_common_registers[] =
1245 0xc770, 0xffffffff, 0x00000800,
1246 0xc774, 0xffffffff, 0x00000800,
1247 0xc798, 0xffffffff, 0x00007fbf,
1248 0xc79c, 0xffffffff, 0x00007faf
1251 static const u32 kalindi_golden_registers[] =
1253 0x3c000, 0xffffdfff, 0x6e944040,
1254 0x55e4, 0xff607fff, 0xfc000100,
1255 0x3c220, 0xff000fff, 0x00000100,
1256 0x3c224, 0xff000fff, 0x00000100,
1257 0x3c200, 0xfffc0fff, 0x00000100,
1258 0x6ed8, 0x00010101, 0x00010000,
1259 0x9830, 0xffffffff, 0x00000000,
1260 0x9834, 0xf00fffff, 0x00000400,
1261 0x5bb0, 0x000000f0, 0x00000070,
1262 0x5bc0, 0xf0311fff, 0x80300000,
1263 0x98f8, 0x73773777, 0x12010001,
1264 0x98fc, 0xffffffff, 0x00000010,
1265 0x9b7c, 0x00ff0000, 0x00fc0000,
1266 0x8030, 0x00001f0f, 0x0000100a,
1267 0x2f48, 0x73773777, 0x12010001,
1268 0x2408, 0x000fffff, 0x000c007f,
1269 0x8a14, 0xf000003f, 0x00000007,
1270 0x8b24, 0x3fff3fff, 0x00ffcfff,
1271 0x30a04, 0x0000ff0f, 0x00000000,
1272 0x28a4c, 0x07ffffff, 0x06000000,
1273 0x4d8, 0x00000fff, 0x00000100,
1274 0x3e78, 0x00000001, 0x00000002,
1275 0xc768, 0x00000008, 0x00000008,
1276 0x8c00, 0x000000ff, 0x00000003,
1277 0x214f8, 0x01ff01ff, 0x00000002,
1278 0x21498, 0x007ff800, 0x00200000,
1279 0x2015c, 0xffffffff, 0x00000f40,
1280 0x88c4, 0x001f3ae3, 0x00000082,
1281 0x88d4, 0x0000001f, 0x00000010,
1282 0x30934, 0xffffffff, 0x00000000
1285 static const u32 kalindi_mgcg_cgcg_init[] =
1287 0xc420, 0xffffffff, 0xfffffffc,
1288 0x30800, 0xffffffff, 0xe0000000,
1289 0x3c2a0, 0xffffffff, 0x00000100,
1290 0x3c208, 0xffffffff, 0x00000100,
1291 0x3c2c0, 0xffffffff, 0x00000100,
1292 0x3c2c8, 0xffffffff, 0x00000100,
1293 0x3c2c4, 0xffffffff, 0x00000100,
1294 0x55e4, 0xffffffff, 0x00600100,
1295 0x3c280, 0xffffffff, 0x00000100,
1296 0x3c214, 0xffffffff, 0x06000100,
1297 0x3c220, 0xffffffff, 0x00000100,
1298 0x3c218, 0xffffffff, 0x06000100,
1299 0x3c204, 0xffffffff, 0x00000100,
1300 0x3c2e0, 0xffffffff, 0x00000100,
1301 0x3c224, 0xffffffff, 0x00000100,
1302 0x3c200, 0xffffffff, 0x00000100,
1303 0x3c230, 0xffffffff, 0x00000100,
1304 0x3c234, 0xffffffff, 0x00000100,
1305 0x3c250, 0xffffffff, 0x00000100,
1306 0x3c254, 0xffffffff, 0x00000100,
1307 0x3c258, 0xffffffff, 0x00000100,
1308 0x3c25c, 0xffffffff, 0x00000100,
1309 0x3c260, 0xffffffff, 0x00000100,
1310 0x3c27c, 0xffffffff, 0x00000100,
1311 0x3c278, 0xffffffff, 0x00000100,
1312 0x3c210, 0xffffffff, 0x06000100,
1313 0x3c290, 0xffffffff, 0x00000100,
1314 0x3c274, 0xffffffff, 0x00000100,
1315 0x3c2b4, 0xffffffff, 0x00000100,
1316 0x3c2b0, 0xffffffff, 0x00000100,
1317 0x3c270, 0xffffffff, 0x00000100,
1318 0x30800, 0xffffffff, 0xe0000000,
1319 0x3c020, 0xffffffff, 0x00010000,
1320 0x3c024, 0xffffffff, 0x00030002,
1321 0x3c028, 0xffffffff, 0x00040007,
1322 0x3c02c, 0xffffffff, 0x00060005,
1323 0x3c030, 0xffffffff, 0x00090008,
1324 0x3c034, 0xffffffff, 0x00010000,
1325 0x3c038, 0xffffffff, 0x00030002,
1326 0x3c03c, 0xffffffff, 0x00040007,
1327 0x3c040, 0xffffffff, 0x00060005,
1328 0x3c044, 0xffffffff, 0x00090008,
1329 0x3c000, 0xffffffff, 0x96e00200,
1330 0x8708, 0xffffffff, 0x00900100,
1331 0xc424, 0xffffffff, 0x0020003f,
1332 0x38, 0xffffffff, 0x0140001c,
1333 0x3c, 0x000f0000, 0x000f0000,
1334 0x220, 0xffffffff, 0xC060000C,
1335 0x224, 0xc0000fff, 0x00000100,
1336 0x20a8, 0xffffffff, 0x00000104,
1337 0x55e4, 0xff000fff, 0x00000100,
1338 0x30cc, 0xc0000fff, 0x00000104,
1339 0xc1e4, 0x00000001, 0x00000001,
1340 0xd00c, 0xff000ff0, 0x00000100,
1341 0xd80c, 0xff000ff0, 0x00000100
1344 static const u32 hawaii_golden_spm_registers[] =
1346 0x30800, 0xe0ffffff, 0xe0000000
1349 static const u32 hawaii_golden_common_registers[] =
1351 0x30800, 0xffffffff, 0xe0000000,
1352 0x28350, 0xffffffff, 0x3a00161a,
1353 0x28354, 0xffffffff, 0x0000002e,
1354 0x9a10, 0xffffffff, 0x00018208,
1355 0x98f8, 0xffffffff, 0x12011003
1358 static const u32 hawaii_golden_registers[] =
1360 0x3354, 0x00000333, 0x00000333,
1361 0x9a10, 0x00010000, 0x00058208,
1362 0x9830, 0xffffffff, 0x00000000,
1363 0x9834, 0xf00fffff, 0x00000400,
1364 0x9838, 0x0002021c, 0x00020200,
1365 0xc78, 0x00000080, 0x00000000,
1366 0x5bb0, 0x000000f0, 0x00000070,
1367 0x5bc0, 0xf0311fff, 0x80300000,
1368 0x350c, 0x00810000, 0x408af000,
1369 0x7030, 0x31000111, 0x00000011,
1370 0x2f48, 0x73773777, 0x12010001,
1371 0x2120, 0x0000007f, 0x0000001b,
1372 0x21dc, 0x00007fb6, 0x00002191,
1373 0x3628, 0x0000003f, 0x0000000a,
1374 0x362c, 0x0000003f, 0x0000000a,
1375 0x2ae4, 0x00073ffe, 0x000022a2,
1376 0x240c, 0x000007ff, 0x00000000,
1377 0x8bf0, 0x00002001, 0x00000001,
1378 0x8b24, 0xffffffff, 0x00ffffff,
1379 0x30a04, 0x0000ff0f, 0x00000000,
1380 0x28a4c, 0x07ffffff, 0x06000000,
1381 0x3e78, 0x00000001, 0x00000002,
1382 0xc768, 0x00000008, 0x00000008,
1383 0xc770, 0x00000f00, 0x00000800,
1384 0xc774, 0x00000f00, 0x00000800,
1385 0xc798, 0x00ffffff, 0x00ff7fbf,
1386 0xc79c, 0x00ffffff, 0x00ff7faf,
1387 0x8c00, 0x000000ff, 0x00000800,
1388 0xe40, 0x00001fff, 0x00001fff,
1389 0x9060, 0x0000007f, 0x00000020,
1390 0x9508, 0x00010000, 0x00010000,
1391 0xae00, 0x00100000, 0x000ff07c,
1392 0xac14, 0x000003ff, 0x0000000f,
1393 0xac10, 0xffffffff, 0x7564fdec,
1394 0xac0c, 0xffffffff, 0x3120b9a8,
1395 0xac08, 0x20000000, 0x0f9c0000
1398 static const u32 hawaii_mgcg_cgcg_init[] =
1400 0xc420, 0xffffffff, 0xfffffffd,
1401 0x30800, 0xffffffff, 0xe0000000,
1402 0x3c2a0, 0xffffffff, 0x00000100,
1403 0x3c208, 0xffffffff, 0x00000100,
1404 0x3c2c0, 0xffffffff, 0x00000100,
1405 0x3c2c8, 0xffffffff, 0x00000100,
1406 0x3c2c4, 0xffffffff, 0x00000100,
1407 0x55e4, 0xffffffff, 0x00200100,
1408 0x3c280, 0xffffffff, 0x00000100,
1409 0x3c214, 0xffffffff, 0x06000100,
1410 0x3c220, 0xffffffff, 0x00000100,
1411 0x3c218, 0xffffffff, 0x06000100,
1412 0x3c204, 0xffffffff, 0x00000100,
1413 0x3c2e0, 0xffffffff, 0x00000100,
1414 0x3c224, 0xffffffff, 0x00000100,
1415 0x3c200, 0xffffffff, 0x00000100,
1416 0x3c230, 0xffffffff, 0x00000100,
1417 0x3c234, 0xffffffff, 0x00000100,
1418 0x3c250, 0xffffffff, 0x00000100,
1419 0x3c254, 0xffffffff, 0x00000100,
1420 0x3c258, 0xffffffff, 0x00000100,
1421 0x3c25c, 0xffffffff, 0x00000100,
1422 0x3c260, 0xffffffff, 0x00000100,
1423 0x3c27c, 0xffffffff, 0x00000100,
1424 0x3c278, 0xffffffff, 0x00000100,
1425 0x3c210, 0xffffffff, 0x06000100,
1426 0x3c290, 0xffffffff, 0x00000100,
1427 0x3c274, 0xffffffff, 0x00000100,
1428 0x3c2b4, 0xffffffff, 0x00000100,
1429 0x3c2b0, 0xffffffff, 0x00000100,
1430 0x3c270, 0xffffffff, 0x00000100,
1431 0x30800, 0xffffffff, 0xe0000000,
1432 0x3c020, 0xffffffff, 0x00010000,
1433 0x3c024, 0xffffffff, 0x00030002,
1434 0x3c028, 0xffffffff, 0x00040007,
1435 0x3c02c, 0xffffffff, 0x00060005,
1436 0x3c030, 0xffffffff, 0x00090008,
1437 0x3c034, 0xffffffff, 0x00010000,
1438 0x3c038, 0xffffffff, 0x00030002,
1439 0x3c03c, 0xffffffff, 0x00040007,
1440 0x3c040, 0xffffffff, 0x00060005,
1441 0x3c044, 0xffffffff, 0x00090008,
1442 0x3c048, 0xffffffff, 0x00010000,
1443 0x3c04c, 0xffffffff, 0x00030002,
1444 0x3c050, 0xffffffff, 0x00040007,
1445 0x3c054, 0xffffffff, 0x00060005,
1446 0x3c058, 0xffffffff, 0x00090008,
1447 0x3c05c, 0xffffffff, 0x00010000,
1448 0x3c060, 0xffffffff, 0x00030002,
1449 0x3c064, 0xffffffff, 0x00040007,
1450 0x3c068, 0xffffffff, 0x00060005,
1451 0x3c06c, 0xffffffff, 0x00090008,
1452 0x3c070, 0xffffffff, 0x00010000,
1453 0x3c074, 0xffffffff, 0x00030002,
1454 0x3c078, 0xffffffff, 0x00040007,
1455 0x3c07c, 0xffffffff, 0x00060005,
1456 0x3c080, 0xffffffff, 0x00090008,
1457 0x3c084, 0xffffffff, 0x00010000,
1458 0x3c088, 0xffffffff, 0x00030002,
1459 0x3c08c, 0xffffffff, 0x00040007,
1460 0x3c090, 0xffffffff, 0x00060005,
1461 0x3c094, 0xffffffff, 0x00090008,
1462 0x3c098, 0xffffffff, 0x00010000,
1463 0x3c09c, 0xffffffff, 0x00030002,
1464 0x3c0a0, 0xffffffff, 0x00040007,
1465 0x3c0a4, 0xffffffff, 0x00060005,
1466 0x3c0a8, 0xffffffff, 0x00090008,
1467 0x3c0ac, 0xffffffff, 0x00010000,
1468 0x3c0b0, 0xffffffff, 0x00030002,
1469 0x3c0b4, 0xffffffff, 0x00040007,
1470 0x3c0b8, 0xffffffff, 0x00060005,
1471 0x3c0bc, 0xffffffff, 0x00090008,
1472 0x3c0c0, 0xffffffff, 0x00010000,
1473 0x3c0c4, 0xffffffff, 0x00030002,
1474 0x3c0c8, 0xffffffff, 0x00040007,
1475 0x3c0cc, 0xffffffff, 0x00060005,
1476 0x3c0d0, 0xffffffff, 0x00090008,
1477 0x3c0d4, 0xffffffff, 0x00010000,
1478 0x3c0d8, 0xffffffff, 0x00030002,
1479 0x3c0dc, 0xffffffff, 0x00040007,
1480 0x3c0e0, 0xffffffff, 0x00060005,
1481 0x3c0e4, 0xffffffff, 0x00090008,
1482 0x3c0e8, 0xffffffff, 0x00010000,
1483 0x3c0ec, 0xffffffff, 0x00030002,
1484 0x3c0f0, 0xffffffff, 0x00040007,
1485 0x3c0f4, 0xffffffff, 0x00060005,
1486 0x3c0f8, 0xffffffff, 0x00090008,
1487 0xc318, 0xffffffff, 0x00020200,
1488 0x3350, 0xffffffff, 0x00000200,
1489 0x15c0, 0xffffffff, 0x00000400,
1490 0x55e8, 0xffffffff, 0x00000000,
1491 0x2f50, 0xffffffff, 0x00000902,
1492 0x3c000, 0xffffffff, 0x96940200,
1493 0x8708, 0xffffffff, 0x00900100,
1494 0xc424, 0xffffffff, 0x0020003f,
1495 0x38, 0xffffffff, 0x0140001c,
1496 0x3c, 0x000f0000, 0x000f0000,
1497 0x220, 0xffffffff, 0xc060000c,
1498 0x224, 0xc0000fff, 0x00000100,
1499 0xf90, 0xffffffff, 0x00000100,
1500 0xf98, 0x00000101, 0x00000000,
1501 0x20a8, 0xffffffff, 0x00000104,
1502 0x55e4, 0xff000fff, 0x00000100,
1503 0x30cc, 0xc0000fff, 0x00000104,
1504 0xc1e4, 0x00000001, 0x00000001,
1505 0xd00c, 0xff000ff0, 0x00000100,
1506 0xd80c, 0xff000ff0, 0x00000100
1509 static const u32 godavari_golden_registers[] =
1511 0x55e4, 0xff607fff, 0xfc000100,
1512 0x6ed8, 0x00010101, 0x00010000,
1513 0x9830, 0xffffffff, 0x00000000,
1514 0x98302, 0xf00fffff, 0x00000400,
1515 0x6130, 0xffffffff, 0x00010000,
1516 0x5bb0, 0x000000f0, 0x00000070,
1517 0x5bc0, 0xf0311fff, 0x80300000,
1518 0x98f8, 0x73773777, 0x12010001,
1519 0x98fc, 0xffffffff, 0x00000010,
1520 0x8030, 0x00001f0f, 0x0000100a,
1521 0x2f48, 0x73773777, 0x12010001,
1522 0x2408, 0x000fffff, 0x000c007f,
1523 0x8a14, 0xf000003f, 0x00000007,
1524 0x8b24, 0xffffffff, 0x00ff0fff,
1525 0x30a04, 0x0000ff0f, 0x00000000,
1526 0x28a4c, 0x07ffffff, 0x06000000,
1527 0x4d8, 0x00000fff, 0x00000100,
1528 0xd014, 0x00010000, 0x00810001,
1529 0xd814, 0x00010000, 0x00810001,
1530 0x3e78, 0x00000001, 0x00000002,
1531 0xc768, 0x00000008, 0x00000008,
1532 0xc770, 0x00000f00, 0x00000800,
1533 0xc774, 0x00000f00, 0x00000800,
1534 0xc798, 0x00ffffff, 0x00ff7fbf,
1535 0xc79c, 0x00ffffff, 0x00ff7faf,
1536 0x8c00, 0x000000ff, 0x00000001,
1537 0x214f8, 0x01ff01ff, 0x00000002,
1538 0x21498, 0x007ff800, 0x00200000,
1539 0x2015c, 0xffffffff, 0x00000f40,
1540 0x88c4, 0x001f3ae3, 0x00000082,
1541 0x88d4, 0x0000001f, 0x00000010,
1542 0x30934, 0xffffffff, 0x00000000
1546 static void cik_init_golden_registers(struct radeon_device *rdev)
1548 switch (rdev->family) {
1550 radeon_program_register_sequence(rdev,
1551 bonaire_mgcg_cgcg_init,
1552 (const u32)ARRAY_SIZE(bonaire_mgcg_cgcg_init));
1553 radeon_program_register_sequence(rdev,
1554 bonaire_golden_registers,
1555 (const u32)ARRAY_SIZE(bonaire_golden_registers));
1556 radeon_program_register_sequence(rdev,
1557 bonaire_golden_common_registers,
1558 (const u32)ARRAY_SIZE(bonaire_golden_common_registers));
1559 radeon_program_register_sequence(rdev,
1560 bonaire_golden_spm_registers,
1561 (const u32)ARRAY_SIZE(bonaire_golden_spm_registers));
1564 radeon_program_register_sequence(rdev,
1565 kalindi_mgcg_cgcg_init,
1566 (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
1567 radeon_program_register_sequence(rdev,
1568 kalindi_golden_registers,
1569 (const u32)ARRAY_SIZE(kalindi_golden_registers));
1570 radeon_program_register_sequence(rdev,
1571 kalindi_golden_common_registers,
1572 (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
1573 radeon_program_register_sequence(rdev,
1574 kalindi_golden_spm_registers,
1575 (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
1578 radeon_program_register_sequence(rdev,
1579 kalindi_mgcg_cgcg_init,
1580 (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
1581 radeon_program_register_sequence(rdev,
1582 godavari_golden_registers,
1583 (const u32)ARRAY_SIZE(godavari_golden_registers));
1584 radeon_program_register_sequence(rdev,
1585 kalindi_golden_common_registers,
1586 (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
1587 radeon_program_register_sequence(rdev,
1588 kalindi_golden_spm_registers,
1589 (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
1592 radeon_program_register_sequence(rdev,
1593 spectre_mgcg_cgcg_init,
1594 (const u32)ARRAY_SIZE(spectre_mgcg_cgcg_init));
1595 radeon_program_register_sequence(rdev,
1596 spectre_golden_registers,
1597 (const u32)ARRAY_SIZE(spectre_golden_registers));
1598 radeon_program_register_sequence(rdev,
1599 spectre_golden_common_registers,
1600 (const u32)ARRAY_SIZE(spectre_golden_common_registers));
1601 radeon_program_register_sequence(rdev,
1602 spectre_golden_spm_registers,
1603 (const u32)ARRAY_SIZE(spectre_golden_spm_registers));
1606 radeon_program_register_sequence(rdev,
1607 hawaii_mgcg_cgcg_init,
1608 (const u32)ARRAY_SIZE(hawaii_mgcg_cgcg_init));
1609 radeon_program_register_sequence(rdev,
1610 hawaii_golden_registers,
1611 (const u32)ARRAY_SIZE(hawaii_golden_registers));
1612 radeon_program_register_sequence(rdev,
1613 hawaii_golden_common_registers,
1614 (const u32)ARRAY_SIZE(hawaii_golden_common_registers));
1615 radeon_program_register_sequence(rdev,
1616 hawaii_golden_spm_registers,
1617 (const u32)ARRAY_SIZE(hawaii_golden_spm_registers));
1625 * cik_get_xclk - get the xclk
1627 * @rdev: radeon_device pointer
1629 * Returns the reference clock used by the gfx engine
1632 u32 cik_get_xclk(struct radeon_device *rdev)
1634 u32 reference_clock = rdev->clock.spll.reference_freq;
1636 if (rdev->flags & RADEON_IS_IGP) {
1637 if (RREG32_SMC(GENERAL_PWRMGT) & GPU_COUNTER_CLK)
1638 return reference_clock / 2;
1640 if (RREG32_SMC(CG_CLKPIN_CNTL) & XTALIN_DIVIDE)
1641 return reference_clock / 4;
1643 return reference_clock;
1647 * cik_mm_rdoorbell - read a doorbell dword
1649 * @rdev: radeon_device pointer
1650 * @index: doorbell index
1652 * Returns the value in the doorbell aperture at the
1653 * requested doorbell index (CIK).
1655 u32 cik_mm_rdoorbell(struct radeon_device *rdev, u32 index)
1657 if (index < rdev->doorbell.num_doorbells) {
1658 return readl(rdev->doorbell.ptr + index);
1660 DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
1666 * cik_mm_wdoorbell - write a doorbell dword
1668 * @rdev: radeon_device pointer
1669 * @index: doorbell index
1670 * @v: value to write
1672 * Writes @v to the doorbell aperture at the
1673 * requested doorbell index (CIK).
1675 void cik_mm_wdoorbell(struct radeon_device *rdev, u32 index, u32 v)
1677 if (index < rdev->doorbell.num_doorbells) {
1678 writel(v, rdev->doorbell.ptr + index);
1680 DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
1684 #define BONAIRE_IO_MC_REGS_SIZE 36
1686 static const u32 bonaire_io_mc_regs[BONAIRE_IO_MC_REGS_SIZE][2] =
1688 {0x00000070, 0x04400000},
1689 {0x00000071, 0x80c01803},
1690 {0x00000072, 0x00004004},
1691 {0x00000073, 0x00000100},
1692 {0x00000074, 0x00ff0000},
1693 {0x00000075, 0x34000000},
1694 {0x00000076, 0x08000014},
1695 {0x00000077, 0x00cc08ec},
1696 {0x00000078, 0x00000400},
1697 {0x00000079, 0x00000000},
1698 {0x0000007a, 0x04090000},
1699 {0x0000007c, 0x00000000},
1700 {0x0000007e, 0x4408a8e8},
1701 {0x0000007f, 0x00000304},
1702 {0x00000080, 0x00000000},
1703 {0x00000082, 0x00000001},
1704 {0x00000083, 0x00000002},
1705 {0x00000084, 0xf3e4f400},
1706 {0x00000085, 0x052024e3},
1707 {0x00000087, 0x00000000},
1708 {0x00000088, 0x01000000},
1709 {0x0000008a, 0x1c0a0000},
1710 {0x0000008b, 0xff010000},
1711 {0x0000008d, 0xffffefff},
1712 {0x0000008e, 0xfff3efff},
1713 {0x0000008f, 0xfff3efbf},
1714 {0x00000092, 0xf7ffffff},
1715 {0x00000093, 0xffffff7f},
1716 {0x00000095, 0x00101101},
1717 {0x00000096, 0x00000fff},
1718 {0x00000097, 0x00116fff},
1719 {0x00000098, 0x60010000},
1720 {0x00000099, 0x10010000},
1721 {0x0000009a, 0x00006000},
1722 {0x0000009b, 0x00001000},
1723 {0x0000009f, 0x00b48000}
1726 #define HAWAII_IO_MC_REGS_SIZE 22
1728 static const u32 hawaii_io_mc_regs[HAWAII_IO_MC_REGS_SIZE][2] =
1730 {0x0000007d, 0x40000000},
1731 {0x0000007e, 0x40180304},
1732 {0x0000007f, 0x0000ff00},
1733 {0x00000081, 0x00000000},
1734 {0x00000083, 0x00000800},
1735 {0x00000086, 0x00000000},
1736 {0x00000087, 0x00000100},
1737 {0x00000088, 0x00020100},
1738 {0x00000089, 0x00000000},
1739 {0x0000008b, 0x00040000},
1740 {0x0000008c, 0x00000100},
1741 {0x0000008e, 0xff010000},
1742 {0x00000090, 0xffffefff},
1743 {0x00000091, 0xfff3efff},
1744 {0x00000092, 0xfff3efbf},
1745 {0x00000093, 0xf7ffffff},
1746 {0x00000094, 0xffffff7f},
1747 {0x00000095, 0x00000fff},
1748 {0x00000096, 0x00116fff},
1749 {0x00000097, 0x60010000},
1750 {0x00000098, 0x10010000},
1751 {0x0000009f, 0x00c79000}
1756 * cik_srbm_select - select specific register instances
1758 * @rdev: radeon_device pointer
1759 * @me: selected ME (micro engine)
1764 * Switches the currently active registers instances. Some
1765 * registers are instanced per VMID, others are instanced per
1766 * me/pipe/queue combination.
1768 static void cik_srbm_select(struct radeon_device *rdev,
1769 u32 me, u32 pipe, u32 queue, u32 vmid)
1771 u32 srbm_gfx_cntl = (PIPEID(pipe & 0x3) |
1774 QUEUEID(queue & 0x7));
1775 WREG32(SRBM_GFX_CNTL, srbm_gfx_cntl);
1780 * ci_mc_load_microcode - load MC ucode into the hw
1782 * @rdev: radeon_device pointer
1784 * Load the GDDR MC ucode into the hw (CIK).
1785 * Returns 0 on success, error on failure.
1787 int ci_mc_load_microcode(struct radeon_device *rdev)
1789 const __be32 *fw_data = NULL;
1790 const __le32 *new_fw_data = NULL;
1791 u32 running, blackout = 0;
1792 u32 *io_mc_regs = NULL;
1793 const __le32 *new_io_mc_regs = NULL;
1794 int i, regs_size, ucode_size;
1800 const struct mc_firmware_header_v1_0 *hdr =
1801 (const struct mc_firmware_header_v1_0 *)rdev->mc_fw->data;
1803 radeon_ucode_print_mc_hdr(&hdr->header);
1805 regs_size = le32_to_cpu(hdr->io_debug_size_bytes) / (4 * 2);
1806 new_io_mc_regs = (const __le32 *)
1807 ((const char *)rdev->mc_fw->data + le32_to_cpu(hdr->io_debug_array_offset_bytes));
1808 ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
1809 new_fw_data = (const __le32 *)
1810 ((const char *)rdev->mc_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
1812 ucode_size = rdev->mc_fw->datasize / 4;
1814 switch (rdev->family) {
1816 io_mc_regs = (u32 *)&bonaire_io_mc_regs;
1817 regs_size = BONAIRE_IO_MC_REGS_SIZE;
1820 io_mc_regs = (u32 *)&hawaii_io_mc_regs;
1821 regs_size = HAWAII_IO_MC_REGS_SIZE;
1826 fw_data = (const __be32 *)rdev->mc_fw->data;
1829 running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
1833 blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
1834 WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
1837 /* reset the engine and set to writable */
1838 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
1839 WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
1841 /* load mc io regs */
1842 for (i = 0; i < regs_size; i++) {
1844 WREG32(MC_SEQ_IO_DEBUG_INDEX, le32_to_cpup(new_io_mc_regs++));
1845 WREG32(MC_SEQ_IO_DEBUG_DATA, le32_to_cpup(new_io_mc_regs++));
1847 WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
1848 WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
1851 /* load the MC ucode */
1852 for (i = 0; i < ucode_size; i++) {
1854 WREG32(MC_SEQ_SUP_PGM, le32_to_cpup(new_fw_data++));
1856 WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
1859 /* put the engine back into the active state */
1860 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
1861 WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
1862 WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
1864 /* wait for training to complete */
1865 for (i = 0; i < rdev->usec_timeout; i++) {
1866 if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D0)
1870 for (i = 0; i < rdev->usec_timeout; i++) {
1871 if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D1)
1877 WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
1884 * cik_init_microcode - load ucode images from disk
1886 * @rdev: radeon_device pointer
1888 * Use the firmware interface to load the ucode images into
1889 * the driver (not loaded into hw).
1890 * Returns 0 on success, error on failure.
1892 static int cik_init_microcode(struct radeon_device *rdev)
1894 const char *chip_name;
1895 const char *new_chip_name;
1896 size_t pfp_req_size, me_req_size, ce_req_size,
1897 mec_req_size, rlc_req_size, mc_req_size = 0,
1898 sdma_req_size, smc_req_size = 0, mc2_req_size = 0;
1906 switch (rdev->family) {
1908 chip_name = "BONAIRE";
1909 new_chip_name = "bonaire";
1910 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
1911 me_req_size = CIK_ME_UCODE_SIZE * 4;
1912 ce_req_size = CIK_CE_UCODE_SIZE * 4;
1913 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
1914 rlc_req_size = BONAIRE_RLC_UCODE_SIZE * 4;
1915 mc_req_size = BONAIRE_MC_UCODE_SIZE * 4;
1916 mc2_req_size = BONAIRE_MC2_UCODE_SIZE * 4;
1917 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
1918 smc_req_size = ALIGN(BONAIRE_SMC_UCODE_SIZE, 4);
1922 chip_name = "HAWAII";
1923 new_chip_name = "hawaii";
1924 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
1925 me_req_size = CIK_ME_UCODE_SIZE * 4;
1926 ce_req_size = CIK_CE_UCODE_SIZE * 4;
1927 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
1928 rlc_req_size = BONAIRE_RLC_UCODE_SIZE * 4;
1929 mc_req_size = HAWAII_MC_UCODE_SIZE * 4;
1930 mc2_req_size = HAWAII_MC2_UCODE_SIZE * 4;
1931 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
1932 smc_req_size = ALIGN(HAWAII_SMC_UCODE_SIZE, 4);
1936 chip_name = "KAVERI";
1937 new_chip_name = "kaveri";
1938 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
1939 me_req_size = CIK_ME_UCODE_SIZE * 4;
1940 ce_req_size = CIK_CE_UCODE_SIZE * 4;
1941 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
1942 rlc_req_size = KV_RLC_UCODE_SIZE * 4;
1943 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
1947 chip_name = "KABINI";
1948 new_chip_name = "kabini";
1949 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
1950 me_req_size = CIK_ME_UCODE_SIZE * 4;
1951 ce_req_size = CIK_CE_UCODE_SIZE * 4;
1952 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
1953 rlc_req_size = KB_RLC_UCODE_SIZE * 4;
1954 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
1958 chip_name = "MULLINS";
1959 new_chip_name = "mullins";
1960 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
1961 me_req_size = CIK_ME_UCODE_SIZE * 4;
1962 ce_req_size = CIK_CE_UCODE_SIZE * 4;
1963 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
1964 rlc_req_size = ML_RLC_UCODE_SIZE * 4;
1965 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
1971 DRM_INFO("Loading %s Microcode\n", new_chip_name);
1973 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_pfp", new_chip_name);
1974 err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
1976 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_pfp", chip_name);
1977 err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
1980 if (rdev->pfp_fw->datasize != pfp_req_size) {
1982 "cik_cp: Bogus length %zu in firmware \"%s\"\n",
1983 rdev->pfp_fw->datasize, fw_name);
1988 err = radeon_ucode_validate(rdev->pfp_fw);
1991 "cik_fw: validation failed for firmware \"%s\"\n",
1999 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_me", new_chip_name);
2000 err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
2002 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_me", chip_name);
2003 err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
2006 if (rdev->me_fw->datasize != me_req_size) {
2008 "cik_cp: Bogus length %zu in firmware \"%s\"\n",
2009 rdev->me_fw->datasize, fw_name);
2013 err = radeon_ucode_validate(rdev->me_fw);
2016 "cik_fw: validation failed for firmware \"%s\"\n",
2024 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_ce", new_chip_name);
2025 err = request_firmware(&rdev->ce_fw, fw_name, rdev->dev);
2027 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_ce", chip_name);
2028 err = request_firmware(&rdev->ce_fw, fw_name, rdev->dev);
2031 if (rdev->ce_fw->datasize != ce_req_size) {
2033 "cik_cp: Bogus length %zu in firmware \"%s\"\n",
2034 rdev->ce_fw->datasize, fw_name);
2038 err = radeon_ucode_validate(rdev->ce_fw);
2041 "cik_fw: validation failed for firmware \"%s\"\n",
2049 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_mec", new_chip_name);
2050 err = request_firmware(&rdev->mec_fw, fw_name, rdev->dev);
2052 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_mec", chip_name);
2053 err = request_firmware(&rdev->mec_fw, fw_name, rdev->dev);
2056 if (rdev->mec_fw->datasize != mec_req_size) {
2058 "cik_cp: Bogus length %zu in firmware \"%s\"\n",
2059 rdev->mec_fw->datasize, fw_name);
2063 err = radeon_ucode_validate(rdev->mec_fw);
2066 "cik_fw: validation failed for firmware \"%s\"\n",
2074 if (rdev->family == CHIP_KAVERI) {
2075 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_mec2", new_chip_name);
2076 err = request_firmware(&rdev->mec2_fw, fw_name, rdev->dev);
2080 err = radeon_ucode_validate(rdev->mec2_fw);
2089 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_rlc", new_chip_name);
2090 err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
2092 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_rlc", chip_name);
2093 err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
2096 if (rdev->rlc_fw->datasize != rlc_req_size) {
2098 "cik_rlc: Bogus length %zu in firmware \"%s\"\n",
2099 rdev->rlc_fw->datasize, fw_name);
2103 err = radeon_ucode_validate(rdev->rlc_fw);
2106 "cik_fw: validation failed for firmware \"%s\"\n",
2114 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_sdma", new_chip_name);
2115 err = request_firmware(&rdev->sdma_fw, fw_name, rdev->dev);
2117 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_sdma", chip_name);
2118 err = request_firmware(&rdev->sdma_fw, fw_name, rdev->dev);
2121 if (rdev->sdma_fw->datasize != sdma_req_size) {
2123 "cik_sdma: Bogus length %zu in firmware \"%s\"\n",
2124 rdev->sdma_fw->datasize, fw_name);
2128 err = radeon_ucode_validate(rdev->sdma_fw);
2131 "cik_fw: validation failed for firmware \"%s\"\n",
2139 /* No SMC, MC ucode on APUs */
2140 if (!(rdev->flags & RADEON_IS_IGP)) {
2141 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_mc", new_chip_name);
2142 err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
2144 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_mc2", chip_name);
2145 err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
2147 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_mc", chip_name);
2148 err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
2152 if ((rdev->mc_fw->datasize != mc_req_size) &&
2153 (rdev->mc_fw->datasize != mc2_req_size)){
2155 "cik_mc: Bogus length %zu in firmware \"%s\"\n",
2156 rdev->mc_fw->datasize, fw_name);
2159 DRM_INFO("%s: %zu bytes\n", fw_name, rdev->mc_fw->datasize);
2161 err = radeon_ucode_validate(rdev->mc_fw);
2164 "cik_fw: validation failed for firmware \"%s\"\n",
2172 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_smc", new_chip_name);
2173 err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
2175 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_smc", chip_name);
2176 err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
2179 "smc: error loading firmware \"%s\"\n",
2181 release_firmware(rdev->smc_fw);
2182 rdev->smc_fw = NULL;
2184 } else if (rdev->smc_fw->datasize != smc_req_size) {
2186 "cik_smc: Bogus length %zu in firmware \"%s\"\n",
2187 rdev->smc_fw->datasize, fw_name);
2191 err = radeon_ucode_validate(rdev->smc_fw);
2194 "cik_fw: validation failed for firmware \"%s\"\n",
2204 rdev->new_fw = false;
2205 } else if (new_fw < num_fw) {
2206 printk(KERN_ERR "ci_fw: mixing new and old firmware!\n");
2209 rdev->new_fw = true;
2216 "cik_cp: Failed to load firmware \"%s\"\n",
2218 release_firmware(rdev->pfp_fw);
2219 rdev->pfp_fw = NULL;
2220 release_firmware(rdev->me_fw);
2222 release_firmware(rdev->ce_fw);
2224 release_firmware(rdev->mec_fw);
2225 rdev->mec_fw = NULL;
2226 release_firmware(rdev->mec2_fw);
2227 rdev->mec2_fw = NULL;
2228 release_firmware(rdev->rlc_fw);
2229 rdev->rlc_fw = NULL;
2230 release_firmware(rdev->sdma_fw);
2231 rdev->sdma_fw = NULL;
2232 release_firmware(rdev->mc_fw);
2234 release_firmware(rdev->smc_fw);
2235 rdev->smc_fw = NULL;
2244 * cik_tiling_mode_table_init - init the hw tiling table
2246 * @rdev: radeon_device pointer
2248 * Starting with SI, the tiling setup is done globally in a
2249 * set of 32 tiling modes. Rather than selecting each set of
2250 * parameters per surface as on older asics, we just select
2251 * which index in the tiling table we want to use, and the
2252 * surface uses those parameters (CIK).
2254 static void cik_tiling_mode_table_init(struct radeon_device *rdev)
2256 const u32 num_tile_mode_states = 32;
2257 const u32 num_secondary_tile_mode_states = 16;
2258 u32 reg_offset, gb_tile_moden, split_equal_to_row_size;
2259 u32 num_pipe_configs;
2260 u32 num_rbs = rdev->config.cik.max_backends_per_se *
2261 rdev->config.cik.max_shader_engines;
2263 switch (rdev->config.cik.mem_row_size_in_kb) {
2265 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_1KB;
2269 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_2KB;
2272 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_4KB;
2276 num_pipe_configs = rdev->config.cik.max_tile_pipes;
2277 if (num_pipe_configs > 8)
2278 num_pipe_configs = 16;
2280 if (num_pipe_configs == 16) {
2281 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
2282 switch (reg_offset) {
2284 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2285 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2286 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2287 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
2290 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2291 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2292 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2293 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
2296 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2297 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2298 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2299 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2302 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2303 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2304 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2305 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
2308 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2309 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2310 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2311 TILE_SPLIT(split_equal_to_row_size));
2314 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2315 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2316 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2319 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2320 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2321 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2322 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2325 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2326 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2327 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2328 TILE_SPLIT(split_equal_to_row_size));
2331 gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2332 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16));
2335 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2336 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2337 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
2340 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2341 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2342 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2343 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2346 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2347 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2348 PIPE_CONFIG(ADDR_SURF_P16_32x32_8x16) |
2349 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2352 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2353 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2354 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2355 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2358 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2359 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2360 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
2363 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2364 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2365 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2366 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2369 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2370 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2371 PIPE_CONFIG(ADDR_SURF_P16_32x32_8x16) |
2372 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2375 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2376 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2377 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2378 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2381 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2382 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2383 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
2386 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2387 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2388 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2389 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2392 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2393 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2394 PIPE_CONFIG(ADDR_SURF_P16_32x32_8x16) |
2395 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2398 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2399 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2400 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2401 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2407 rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
2408 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2410 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
2411 switch (reg_offset) {
2413 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2414 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2415 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2416 NUM_BANKS(ADDR_SURF_16_BANK));
2419 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2420 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2421 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2422 NUM_BANKS(ADDR_SURF_16_BANK));
2425 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2426 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2427 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2428 NUM_BANKS(ADDR_SURF_16_BANK));
2431 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2432 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2433 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2434 NUM_BANKS(ADDR_SURF_16_BANK));
2437 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2438 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2439 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2440 NUM_BANKS(ADDR_SURF_8_BANK));
2443 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2444 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2445 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2446 NUM_BANKS(ADDR_SURF_4_BANK));
2449 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2450 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2451 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2452 NUM_BANKS(ADDR_SURF_2_BANK));
2455 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2456 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2457 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2458 NUM_BANKS(ADDR_SURF_16_BANK));
2461 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2462 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2463 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2464 NUM_BANKS(ADDR_SURF_16_BANK));
2467 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2468 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2469 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2470 NUM_BANKS(ADDR_SURF_16_BANK));
2473 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2474 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2475 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2476 NUM_BANKS(ADDR_SURF_8_BANK));
2479 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2480 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2481 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2482 NUM_BANKS(ADDR_SURF_4_BANK));
2485 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2486 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2487 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2488 NUM_BANKS(ADDR_SURF_2_BANK));
2491 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2492 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2493 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2494 NUM_BANKS(ADDR_SURF_2_BANK));
2500 rdev->config.cik.macrotile_mode_array[reg_offset] = gb_tile_moden;
2501 WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2503 } else if (num_pipe_configs == 8) {
2504 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
2505 switch (reg_offset) {
2507 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2508 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2509 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2510 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
2513 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2514 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2515 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2516 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
2519 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2520 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2521 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2522 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2525 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2526 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2527 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2528 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
2531 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2532 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2533 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2534 TILE_SPLIT(split_equal_to_row_size));
2537 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2538 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2539 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2542 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2543 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2544 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2545 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2548 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2549 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2550 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2551 TILE_SPLIT(split_equal_to_row_size));
2554 gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2555 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16));
2558 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2559 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2560 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
2563 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2564 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2565 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2566 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2569 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2570 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2571 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2572 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2575 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2576 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2577 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2578 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2581 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2582 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2583 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
2586 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2587 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2588 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2589 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2592 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2593 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2594 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2595 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2598 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2599 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2600 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2601 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2604 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2605 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2606 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
2609 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2610 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2611 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2612 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2615 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2616 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2617 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2618 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2621 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2622 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2623 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2624 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2630 rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
2631 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2633 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
2634 switch (reg_offset) {
2636 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2637 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2638 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2639 NUM_BANKS(ADDR_SURF_16_BANK));
2642 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2643 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2644 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2645 NUM_BANKS(ADDR_SURF_16_BANK));
2648 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2649 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2650 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2651 NUM_BANKS(ADDR_SURF_16_BANK));
2654 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2655 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2656 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2657 NUM_BANKS(ADDR_SURF_16_BANK));
2660 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2661 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2662 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2663 NUM_BANKS(ADDR_SURF_8_BANK));
2666 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2667 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2668 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2669 NUM_BANKS(ADDR_SURF_4_BANK));
2672 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2673 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2674 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2675 NUM_BANKS(ADDR_SURF_2_BANK));
2678 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2679 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2680 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2681 NUM_BANKS(ADDR_SURF_16_BANK));
2684 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2685 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2686 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2687 NUM_BANKS(ADDR_SURF_16_BANK));
2690 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2691 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2692 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2693 NUM_BANKS(ADDR_SURF_16_BANK));
2696 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2697 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2698 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2699 NUM_BANKS(ADDR_SURF_16_BANK));
2702 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2703 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2704 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2705 NUM_BANKS(ADDR_SURF_8_BANK));
2708 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2709 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2710 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2711 NUM_BANKS(ADDR_SURF_4_BANK));
2714 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2715 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2716 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2717 NUM_BANKS(ADDR_SURF_2_BANK));
2723 rdev->config.cik.macrotile_mode_array[reg_offset] = gb_tile_moden;
2724 WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2726 } else if (num_pipe_configs == 4) {
2728 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
2729 switch (reg_offset) {
2731 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2732 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2733 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2734 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
2737 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2738 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2739 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2740 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
2743 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2744 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2745 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2746 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2749 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2750 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2751 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2752 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
2755 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2756 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2757 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2758 TILE_SPLIT(split_equal_to_row_size));
2761 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2762 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2763 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2766 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2767 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2768 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2769 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2772 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2773 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2774 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2775 TILE_SPLIT(split_equal_to_row_size));
2778 gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2779 PIPE_CONFIG(ADDR_SURF_P4_16x16));
2782 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2783 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2784 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
2787 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2788 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2789 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2790 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2793 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2794 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2795 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2796 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2799 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2800 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2801 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2802 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2805 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2806 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2807 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
2810 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2811 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2812 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2813 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2816 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2817 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2818 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2819 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2822 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2823 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2824 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2825 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2828 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2829 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2830 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
2833 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2834 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2835 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2836 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2839 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2840 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2841 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2842 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2845 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2846 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2847 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2848 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2854 rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
2855 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2857 } else if (num_rbs < 4) {
2858 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
2859 switch (reg_offset) {
2861 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2862 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2863 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2864 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
2867 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2868 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2869 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2870 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
2873 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2874 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2875 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2876 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2879 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2880 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2881 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2882 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
2885 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2886 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2887 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2888 TILE_SPLIT(split_equal_to_row_size));
2891 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2892 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2893 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2896 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2897 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2898 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2899 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2902 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2903 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2904 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2905 TILE_SPLIT(split_equal_to_row_size));
2908 gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2909 PIPE_CONFIG(ADDR_SURF_P4_8x16));
2912 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2913 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2914 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
2917 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2918 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2919 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2920 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2923 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2924 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2925 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2926 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2929 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2930 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2931 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2932 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2935 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2936 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2937 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
2940 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2941 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2942 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2943 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2946 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2947 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2948 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2949 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2952 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2953 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2954 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2955 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2958 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2959 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2960 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
2963 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2964 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2965 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2966 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2969 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2970 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2971 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2972 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2975 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2976 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2977 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2978 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2984 rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
2985 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2988 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
2989 switch (reg_offset) {
2991 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2992 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2993 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2994 NUM_BANKS(ADDR_SURF_16_BANK));
2997 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2998 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2999 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3000 NUM_BANKS(ADDR_SURF_16_BANK));
3003 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3004 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3005 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3006 NUM_BANKS(ADDR_SURF_16_BANK));
3009 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3010 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3011 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3012 NUM_BANKS(ADDR_SURF_16_BANK));
3015 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3016 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3017 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3018 NUM_BANKS(ADDR_SURF_16_BANK));
3021 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3022 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3023 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3024 NUM_BANKS(ADDR_SURF_8_BANK));
3027 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3028 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3029 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
3030 NUM_BANKS(ADDR_SURF_4_BANK));
3033 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3034 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
3035 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3036 NUM_BANKS(ADDR_SURF_16_BANK));
3039 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3040 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3041 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3042 NUM_BANKS(ADDR_SURF_16_BANK));
3045 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3046 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3047 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3048 NUM_BANKS(ADDR_SURF_16_BANK));
3051 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3052 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3053 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3054 NUM_BANKS(ADDR_SURF_16_BANK));
3057 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3058 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3059 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3060 NUM_BANKS(ADDR_SURF_16_BANK));
3063 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3064 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3065 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3066 NUM_BANKS(ADDR_SURF_8_BANK));
3069 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3070 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3071 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
3072 NUM_BANKS(ADDR_SURF_4_BANK));
3078 rdev->config.cik.macrotile_mode_array[reg_offset] = gb_tile_moden;
3079 WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
3081 } else if (num_pipe_configs == 2) {
3082 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
3083 switch (reg_offset) {
3085 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3086 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
3087 PIPE_CONFIG(ADDR_SURF_P2) |
3088 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
3091 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3092 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
3093 PIPE_CONFIG(ADDR_SURF_P2) |
3094 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
3097 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3098 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
3099 PIPE_CONFIG(ADDR_SURF_P2) |
3100 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
3103 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3104 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
3105 PIPE_CONFIG(ADDR_SURF_P2) |
3106 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
3109 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3110 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
3111 PIPE_CONFIG(ADDR_SURF_P2) |
3112 TILE_SPLIT(split_equal_to_row_size));
3115 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3116 PIPE_CONFIG(ADDR_SURF_P2) |
3117 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3120 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
3121 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
3122 PIPE_CONFIG(ADDR_SURF_P2) |
3123 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
3126 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
3127 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
3128 PIPE_CONFIG(ADDR_SURF_P2) |
3129 TILE_SPLIT(split_equal_to_row_size));
3132 gb_tile_moden = ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
3133 PIPE_CONFIG(ADDR_SURF_P2);
3136 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3137 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3138 PIPE_CONFIG(ADDR_SURF_P2));
3141 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3142 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3143 PIPE_CONFIG(ADDR_SURF_P2) |
3144 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3147 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3148 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3149 PIPE_CONFIG(ADDR_SURF_P2) |
3150 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3153 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
3154 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3155 PIPE_CONFIG(ADDR_SURF_P2) |
3156 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3159 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3160 PIPE_CONFIG(ADDR_SURF_P2) |
3161 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
3164 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3165 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3166 PIPE_CONFIG(ADDR_SURF_P2) |
3167 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3170 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3171 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3172 PIPE_CONFIG(ADDR_SURF_P2) |
3173 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3176 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
3177 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3178 PIPE_CONFIG(ADDR_SURF_P2) |
3179 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3182 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3183 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3184 PIPE_CONFIG(ADDR_SURF_P2));
3187 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
3188 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3189 PIPE_CONFIG(ADDR_SURF_P2) |
3190 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3193 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3194 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3195 PIPE_CONFIG(ADDR_SURF_P2) |
3196 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3199 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
3200 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3201 PIPE_CONFIG(ADDR_SURF_P2) |
3202 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3208 rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
3209 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
3211 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
3212 switch (reg_offset) {
3214 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3215 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3216 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3217 NUM_BANKS(ADDR_SURF_16_BANK));
3220 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3221 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3222 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3223 NUM_BANKS(ADDR_SURF_16_BANK));
3226 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3227 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3228 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3229 NUM_BANKS(ADDR_SURF_16_BANK));
3232 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3233 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3234 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3235 NUM_BANKS(ADDR_SURF_16_BANK));
3238 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3239 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3240 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3241 NUM_BANKS(ADDR_SURF_16_BANK));
3244 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3245 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3246 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3247 NUM_BANKS(ADDR_SURF_16_BANK));
3250 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3251 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3252 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3253 NUM_BANKS(ADDR_SURF_8_BANK));
3256 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3257 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
3258 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3259 NUM_BANKS(ADDR_SURF_16_BANK));
3262 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3263 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3264 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3265 NUM_BANKS(ADDR_SURF_16_BANK));
3268 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3269 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3270 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3271 NUM_BANKS(ADDR_SURF_16_BANK));
3274 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3275 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3276 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3277 NUM_BANKS(ADDR_SURF_16_BANK));
3280 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3281 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3282 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3283 NUM_BANKS(ADDR_SURF_16_BANK));
3286 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3287 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3288 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3289 NUM_BANKS(ADDR_SURF_16_BANK));
3292 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3293 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3294 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3295 NUM_BANKS(ADDR_SURF_8_BANK));
3301 rdev->config.cik.macrotile_mode_array[reg_offset] = gb_tile_moden;
3302 WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
3305 DRM_ERROR("unknown num pipe config: 0x%x\n", num_pipe_configs);
3309 * cik_select_se_sh - select which SE, SH to address
3311 * @rdev: radeon_device pointer
3312 * @se_num: shader engine to address
3313 * @sh_num: sh block to address
3315 * Select which SE, SH combinations to address. Certain
3316 * registers are instanced per SE or SH. 0xffffffff means
3317 * broadcast to all SEs or SHs (CIK).
3319 static void cik_select_se_sh(struct radeon_device *rdev,
3320 u32 se_num, u32 sh_num)
3322 u32 data = INSTANCE_BROADCAST_WRITES;
3324 if ((se_num == 0xffffffff) && (sh_num == 0xffffffff))
3325 data |= SH_BROADCAST_WRITES | SE_BROADCAST_WRITES;
3326 else if (se_num == 0xffffffff)
3327 data |= SE_BROADCAST_WRITES | SH_INDEX(sh_num);
3328 else if (sh_num == 0xffffffff)
3329 data |= SH_BROADCAST_WRITES | SE_INDEX(se_num);
3331 data |= SH_INDEX(sh_num) | SE_INDEX(se_num);
3332 WREG32(GRBM_GFX_INDEX, data);
3336 * cik_create_bitmask - create a bitmask
3338 * @bit_width: length of the mask
3340 * create a variable length bit mask (CIK).
3341 * Returns the bitmask.
3343 static u32 cik_create_bitmask(u32 bit_width)
3347 for (i = 0; i < bit_width; i++) {
3355 * cik_get_rb_disabled - computes the mask of disabled RBs
3357 * @rdev: radeon_device pointer
3358 * @max_rb_num: max RBs (render backends) for the asic
3359 * @se_num: number of SEs (shader engines) for the asic
3360 * @sh_per_se: number of SH blocks per SE for the asic
3362 * Calculates the bitmask of disabled RBs (CIK).
3363 * Returns the disabled RB bitmask.
3365 static u32 cik_get_rb_disabled(struct radeon_device *rdev,
3366 u32 max_rb_num_per_se,
3371 data = RREG32(CC_RB_BACKEND_DISABLE);
3373 data &= BACKEND_DISABLE_MASK;
3376 data |= RREG32(GC_USER_RB_BACKEND_DISABLE);
3378 data >>= BACKEND_DISABLE_SHIFT;
3380 mask = cik_create_bitmask(max_rb_num_per_se / sh_per_se);
3386 * cik_setup_rb - setup the RBs on the asic
3388 * @rdev: radeon_device pointer
3389 * @se_num: number of SEs (shader engines) for the asic
3390 * @sh_per_se: number of SH blocks per SE for the asic
3391 * @max_rb_num: max RBs (render backends) for the asic
3393 * Configures per-SE/SH RB registers (CIK).
3395 static void cik_setup_rb(struct radeon_device *rdev,
3396 u32 se_num, u32 sh_per_se,
3397 u32 max_rb_num_per_se)
3401 u32 disabled_rbs = 0;
3402 u32 enabled_rbs = 0;
3404 for (i = 0; i < se_num; i++) {
3405 for (j = 0; j < sh_per_se; j++) {
3406 cik_select_se_sh(rdev, i, j);
3407 data = cik_get_rb_disabled(rdev, max_rb_num_per_se, sh_per_se);
3408 if (rdev->family == CHIP_HAWAII)
3409 disabled_rbs |= data << ((i * sh_per_se + j) * HAWAII_RB_BITMAP_WIDTH_PER_SH);
3411 disabled_rbs |= data << ((i * sh_per_se + j) * CIK_RB_BITMAP_WIDTH_PER_SH);
3414 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
3417 for (i = 0; i < max_rb_num_per_se * se_num; i++) {
3418 if (!(disabled_rbs & mask))
3419 enabled_rbs |= mask;
3423 rdev->config.cik.backend_enable_mask = enabled_rbs;
3425 for (i = 0; i < se_num; i++) {
3426 cik_select_se_sh(rdev, i, 0xffffffff);
3428 for (j = 0; j < sh_per_se; j++) {
3429 switch (enabled_rbs & 3) {
3432 data |= PKR_MAP(RASTER_CONFIG_RB_MAP_3);
3434 data |= PKR_MAP(RASTER_CONFIG_RB_MAP_0);
3437 data |= (RASTER_CONFIG_RB_MAP_0 << (i * sh_per_se + j) * 2);
3440 data |= (RASTER_CONFIG_RB_MAP_3 << (i * sh_per_se + j) * 2);
3444 data |= (RASTER_CONFIG_RB_MAP_2 << (i * sh_per_se + j) * 2);
3449 WREG32(PA_SC_RASTER_CONFIG, data);
3451 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
3455 * cik_gpu_init - setup the 3D engine
3457 * @rdev: radeon_device pointer
3459 * Configures the 3D engine and tiling configuration
3460 * registers so that the 3D engine is usable.
3462 static void cik_gpu_init(struct radeon_device *rdev)
3464 u32 gb_addr_config = RREG32(GB_ADDR_CONFIG);
3465 u32 mc_shared_chmap, mc_arb_ramcfg;
3466 u32 hdp_host_path_cntl;
3470 switch (rdev->family) {
3472 rdev->config.cik.max_shader_engines = 2;
3473 rdev->config.cik.max_tile_pipes = 4;
3474 rdev->config.cik.max_cu_per_sh = 7;
3475 rdev->config.cik.max_sh_per_se = 1;
3476 rdev->config.cik.max_backends_per_se = 2;
3477 rdev->config.cik.max_texture_channel_caches = 4;
3478 rdev->config.cik.max_gprs = 256;
3479 rdev->config.cik.max_gs_threads = 32;
3480 rdev->config.cik.max_hw_contexts = 8;
3482 rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
3483 rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
3484 rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
3485 rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
3486 gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
3489 rdev->config.cik.max_shader_engines = 4;
3490 rdev->config.cik.max_tile_pipes = 16;
3491 rdev->config.cik.max_cu_per_sh = 11;
3492 rdev->config.cik.max_sh_per_se = 1;
3493 rdev->config.cik.max_backends_per_se = 4;
3494 rdev->config.cik.max_texture_channel_caches = 16;
3495 rdev->config.cik.max_gprs = 256;
3496 rdev->config.cik.max_gs_threads = 32;
3497 rdev->config.cik.max_hw_contexts = 8;
3499 rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
3500 rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
3501 rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
3502 rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
3503 gb_addr_config = HAWAII_GB_ADDR_CONFIG_GOLDEN;
3506 rdev->config.cik.max_shader_engines = 1;
3507 rdev->config.cik.max_tile_pipes = 4;
3508 if ((rdev->pdev->device == 0x1304) ||
3509 (rdev->pdev->device == 0x1305) ||
3510 (rdev->pdev->device == 0x130C) ||
3511 (rdev->pdev->device == 0x130F) ||
3512 (rdev->pdev->device == 0x1310) ||
3513 (rdev->pdev->device == 0x1311) ||
3514 (rdev->pdev->device == 0x131C)) {
3515 rdev->config.cik.max_cu_per_sh = 8;
3516 rdev->config.cik.max_backends_per_se = 2;
3517 } else if ((rdev->pdev->device == 0x1309) ||
3518 (rdev->pdev->device == 0x130A) ||
3519 (rdev->pdev->device == 0x130D) ||
3520 (rdev->pdev->device == 0x1313) ||
3521 (rdev->pdev->device == 0x131D)) {
3522 rdev->config.cik.max_cu_per_sh = 6;
3523 rdev->config.cik.max_backends_per_se = 2;
3524 } else if ((rdev->pdev->device == 0x1306) ||
3525 (rdev->pdev->device == 0x1307) ||
3526 (rdev->pdev->device == 0x130B) ||
3527 (rdev->pdev->device == 0x130E) ||
3528 (rdev->pdev->device == 0x1315) ||
3529 (rdev->pdev->device == 0x1318) ||
3530 (rdev->pdev->device == 0x131B)) {
3531 rdev->config.cik.max_cu_per_sh = 4;
3532 rdev->config.cik.max_backends_per_se = 1;
3534 rdev->config.cik.max_cu_per_sh = 3;
3535 rdev->config.cik.max_backends_per_se = 1;
3537 rdev->config.cik.max_sh_per_se = 1;
3538 rdev->config.cik.max_texture_channel_caches = 4;
3539 rdev->config.cik.max_gprs = 256;
3540 rdev->config.cik.max_gs_threads = 16;
3541 rdev->config.cik.max_hw_contexts = 8;
3543 rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
3544 rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
3545 rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
3546 rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
3547 gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
3552 rdev->config.cik.max_shader_engines = 1;
3553 rdev->config.cik.max_tile_pipes = 2;
3554 rdev->config.cik.max_cu_per_sh = 2;
3555 rdev->config.cik.max_sh_per_se = 1;
3556 rdev->config.cik.max_backends_per_se = 1;
3557 rdev->config.cik.max_texture_channel_caches = 2;
3558 rdev->config.cik.max_gprs = 256;
3559 rdev->config.cik.max_gs_threads = 16;
3560 rdev->config.cik.max_hw_contexts = 8;
3562 rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
3563 rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
3564 rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
3565 rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
3566 gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
3570 /* Initialize HDP */
3571 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
3572 WREG32((0x2c14 + j), 0x00000000);
3573 WREG32((0x2c18 + j), 0x00000000);
3574 WREG32((0x2c1c + j), 0x00000000);
3575 WREG32((0x2c20 + j), 0x00000000);
3576 WREG32((0x2c24 + j), 0x00000000);
3579 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
3581 WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
3583 mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
3584 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
3586 rdev->config.cik.num_tile_pipes = rdev->config.cik.max_tile_pipes;
3587 rdev->config.cik.mem_max_burst_length_bytes = 256;
3588 tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
3589 rdev->config.cik.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
3590 if (rdev->config.cik.mem_row_size_in_kb > 4)
3591 rdev->config.cik.mem_row_size_in_kb = 4;
3592 /* XXX use MC settings? */
3593 rdev->config.cik.shader_engine_tile_size = 32;
3594 rdev->config.cik.num_gpus = 1;
3595 rdev->config.cik.multi_gpu_tile_size = 64;
3597 /* fix up row size */
3598 gb_addr_config &= ~ROW_SIZE_MASK;
3599 switch (rdev->config.cik.mem_row_size_in_kb) {
3602 gb_addr_config |= ROW_SIZE(0);
3605 gb_addr_config |= ROW_SIZE(1);
3608 gb_addr_config |= ROW_SIZE(2);
3612 /* setup tiling info dword. gb_addr_config is not adequate since it does
3613 * not have bank info, so create a custom tiling dword.
3614 * bits 3:0 num_pipes
3615 * bits 7:4 num_banks
3616 * bits 11:8 group_size
3617 * bits 15:12 row_size
3619 rdev->config.cik.tile_config = 0;
3620 switch (rdev->config.cik.num_tile_pipes) {
3622 rdev->config.cik.tile_config |= (0 << 0);
3625 rdev->config.cik.tile_config |= (1 << 0);
3628 rdev->config.cik.tile_config |= (2 << 0);
3632 /* XXX what about 12? */
3633 rdev->config.cik.tile_config |= (3 << 0);
3636 rdev->config.cik.tile_config |=
3637 ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) << 4;
3638 rdev->config.cik.tile_config |=
3639 ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
3640 rdev->config.cik.tile_config |=
3641 ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
3643 WREG32(GB_ADDR_CONFIG, gb_addr_config);
3644 WREG32(HDP_ADDR_CONFIG, gb_addr_config);
3645 WREG32(DMIF_ADDR_CALC, gb_addr_config);
3646 WREG32(SDMA0_TILING_CONFIG + SDMA0_REGISTER_OFFSET, gb_addr_config & 0x70);
3647 WREG32(SDMA0_TILING_CONFIG + SDMA1_REGISTER_OFFSET, gb_addr_config & 0x70);
3648 WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
3649 WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
3650 WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
3652 cik_tiling_mode_table_init(rdev);
3654 cik_setup_rb(rdev, rdev->config.cik.max_shader_engines,
3655 rdev->config.cik.max_sh_per_se,
3656 rdev->config.cik.max_backends_per_se);
3658 rdev->config.cik.active_cus = 0;
3659 for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
3660 for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
3661 rdev->config.cik.active_cus +=
3662 hweight32(cik_get_cu_active_bitmap(rdev, i, j));
3666 /* set HW defaults for 3D engine */
3667 WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
3669 WREG32(SX_DEBUG_1, 0x20);
3671 WREG32(TA_CNTL_AUX, 0x00010000);
3673 tmp = RREG32(SPI_CONFIG_CNTL);
3675 WREG32(SPI_CONFIG_CNTL, tmp);
3677 WREG32(SQ_CONFIG, 1);
3679 WREG32(DB_DEBUG, 0);
3681 tmp = RREG32(DB_DEBUG2) & ~0xf00fffff;
3683 WREG32(DB_DEBUG2, tmp);
3685 tmp = RREG32(DB_DEBUG3) & ~0x0002021c;
3687 WREG32(DB_DEBUG3, tmp);
3689 tmp = RREG32(CB_HW_CONTROL) & ~0x00010000;
3691 WREG32(CB_HW_CONTROL, tmp);
3693 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
3695 WREG32(PA_SC_FIFO_SIZE, (SC_FRONTEND_PRIM_FIFO_SIZE(rdev->config.cik.sc_prim_fifo_size_frontend) |
3696 SC_BACKEND_PRIM_FIFO_SIZE(rdev->config.cik.sc_prim_fifo_size_backend) |
3697 SC_HIZ_TILE_FIFO_SIZE(rdev->config.cik.sc_hiz_tile_fifo_size) |
3698 SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.cik.sc_earlyz_tile_fifo_size)));
3700 WREG32(VGT_NUM_INSTANCES, 1);
3702 WREG32(CP_PERFMON_CNTL, 0);
3704 WREG32(SQ_CONFIG, 0);
3706 WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
3707 FORCE_EOV_MAX_REZ_CNT(255)));
3709 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
3710 AUTO_INVLD_EN(ES_AND_GS_AUTO));
3712 WREG32(VGT_GS_VERTEX_REUSE, 16);
3713 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
3715 tmp = RREG32(HDP_MISC_CNTL);
3716 tmp |= HDP_FLUSH_INVALIDATE_CACHE;
3717 WREG32(HDP_MISC_CNTL, tmp);
3719 hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
3720 WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
3722 WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
3723 WREG32(PA_SC_ENHANCE, ENABLE_PA_SC_OUT_OF_ORDER);
3729 * GPU scratch registers helpers function.
3732 * cik_scratch_init - setup driver info for CP scratch regs
3734 * @rdev: radeon_device pointer
3736 * Set up the number and offset of the CP scratch registers.
3737 * NOTE: use of CP scratch registers is a legacy inferface and
3738 * is not used by default on newer asics (r6xx+). On newer asics,
3739 * memory buffers are used for fences rather than scratch regs.
3741 static void cik_scratch_init(struct radeon_device *rdev)
3745 rdev->scratch.num_reg = 7;
3746 rdev->scratch.reg_base = SCRATCH_REG0;
3747 for (i = 0; i < rdev->scratch.num_reg; i++) {
3748 rdev->scratch.free[i] = true;
3749 rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
3754 * cik_ring_test - basic gfx ring test
3756 * @rdev: radeon_device pointer
3757 * @ring: radeon_ring structure holding ring information
3759 * Allocate a scratch register and write to it using the gfx ring (CIK).
3760 * Provides a basic gfx ring test to verify that the ring is working.
3761 * Used by cik_cp_gfx_resume();
3762 * Returns 0 on success, error on failure.
3764 int cik_ring_test(struct radeon_device *rdev, struct radeon_ring *ring)
3771 r = radeon_scratch_get(rdev, &scratch);
3773 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
3776 WREG32(scratch, 0xCAFEDEAD);
3777 r = radeon_ring_lock(rdev, ring, 3);
3779 DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ring->idx, r);
3780 radeon_scratch_free(rdev, scratch);
3783 radeon_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
3784 radeon_ring_write(ring, ((scratch - PACKET3_SET_UCONFIG_REG_START) >> 2));
3785 radeon_ring_write(ring, 0xDEADBEEF);
3786 radeon_ring_unlock_commit(rdev, ring, false);
3788 for (i = 0; i < rdev->usec_timeout; i++) {
3789 tmp = RREG32(scratch);
3790 if (tmp == 0xDEADBEEF)
3794 if (i < rdev->usec_timeout) {
3795 DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
3797 DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
3798 ring->idx, scratch, tmp);
3801 radeon_scratch_free(rdev, scratch);
3806 * cik_hdp_flush_cp_ring_emit - emit an hdp flush on the cp
3808 * @rdev: radeon_device pointer
3809 * @ridx: radeon ring index
3811 * Emits an hdp flush on the cp.
3813 static void cik_hdp_flush_cp_ring_emit(struct radeon_device *rdev,
3816 struct radeon_ring *ring = &rdev->ring[ridx];
3819 switch (ring->idx) {
3820 case CAYMAN_RING_TYPE_CP1_INDEX:
3821 case CAYMAN_RING_TYPE_CP2_INDEX:
3825 ref_and_mask = CP2 << ring->pipe;
3828 ref_and_mask = CP6 << ring->pipe;
3834 case RADEON_RING_TYPE_GFX_INDEX:
3839 radeon_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
3840 radeon_ring_write(ring, (WAIT_REG_MEM_OPERATION(1) | /* write, wait, write */
3841 WAIT_REG_MEM_FUNCTION(3) | /* == */
3842 WAIT_REG_MEM_ENGINE(1))); /* pfp */
3843 radeon_ring_write(ring, GPU_HDP_FLUSH_REQ >> 2);
3844 radeon_ring_write(ring, GPU_HDP_FLUSH_DONE >> 2);
3845 radeon_ring_write(ring, ref_and_mask);
3846 radeon_ring_write(ring, ref_and_mask);
3847 radeon_ring_write(ring, 0x20); /* poll interval */
3851 * cik_fence_gfx_ring_emit - emit a fence on the gfx ring
3853 * @rdev: radeon_device pointer
3854 * @fence: radeon fence object
3856 * Emits a fence sequnce number on the gfx ring and flushes
3859 void cik_fence_gfx_ring_emit(struct radeon_device *rdev,
3860 struct radeon_fence *fence)
3862 struct radeon_ring *ring = &rdev->ring[fence->ring];
3863 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
3865 /* EVENT_WRITE_EOP - flush caches, send int */
3866 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
3867 radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
3869 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
3871 radeon_ring_write(ring, addr & 0xfffffffc);
3872 radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) | DATA_SEL(1) | INT_SEL(2));
3873 radeon_ring_write(ring, fence->seq);
3874 radeon_ring_write(ring, 0);
3878 * cik_fence_compute_ring_emit - emit a fence on the compute ring
3880 * @rdev: radeon_device pointer
3881 * @fence: radeon fence object
3883 * Emits a fence sequnce number on the compute ring and flushes
3886 void cik_fence_compute_ring_emit(struct radeon_device *rdev,
3887 struct radeon_fence *fence)
3889 struct radeon_ring *ring = &rdev->ring[fence->ring];
3890 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
3892 /* RELEASE_MEM - flush caches, send int */
3893 radeon_ring_write(ring, PACKET3(PACKET3_RELEASE_MEM, 5));
3894 radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
3896 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
3898 radeon_ring_write(ring, DATA_SEL(1) | INT_SEL(2));
3899 radeon_ring_write(ring, addr & 0xfffffffc);
3900 radeon_ring_write(ring, upper_32_bits(addr));
3901 radeon_ring_write(ring, fence->seq);
3902 radeon_ring_write(ring, 0);
3906 * cik_semaphore_ring_emit - emit a semaphore on the CP ring
3908 * @rdev: radeon_device pointer
3909 * @ring: radeon ring buffer object
3910 * @semaphore: radeon semaphore object
3911 * @emit_wait: Is this a sempahore wait?
3913 * Emits a semaphore signal/wait packet to the CP ring and prevents the PFP
3914 * from running ahead of semaphore waits.
3916 bool cik_semaphore_ring_emit(struct radeon_device *rdev,
3917 struct radeon_ring *ring,
3918 struct radeon_semaphore *semaphore,
3921 uint64_t addr = semaphore->gpu_addr;
3922 unsigned sel = emit_wait ? PACKET3_SEM_SEL_WAIT : PACKET3_SEM_SEL_SIGNAL;
3924 radeon_ring_write(ring, PACKET3(PACKET3_MEM_SEMAPHORE, 1));
3925 radeon_ring_write(ring, lower_32_bits(addr));
3926 radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) | sel);
3928 if (emit_wait && ring->idx == RADEON_RING_TYPE_GFX_INDEX) {
3929 /* Prevent the PFP from running ahead of the semaphore wait */
3930 radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
3931 radeon_ring_write(ring, 0x0);
3938 * cik_copy_cpdma - copy pages using the CP DMA engine
3940 * @rdev: radeon_device pointer
3941 * @src_offset: src GPU address
3942 * @dst_offset: dst GPU address
3943 * @num_gpu_pages: number of GPU pages to xfer
3944 * @fence: radeon fence object
3946 * Copy GPU paging using the CP DMA engine (CIK+).
3947 * Used by the radeon ttm implementation to move pages if
3948 * registered as the asic copy callback.
3950 int cik_copy_cpdma(struct radeon_device *rdev,
3951 uint64_t src_offset, uint64_t dst_offset,
3952 unsigned num_gpu_pages,
3953 struct radeon_fence **fence)
3955 struct radeon_semaphore *sem = NULL;
3956 int ring_index = rdev->asic->copy.blit_ring_index;
3957 struct radeon_ring *ring = &rdev->ring[ring_index];
3958 u32 size_in_bytes, cur_size_in_bytes, control;
3962 r = radeon_semaphore_create(rdev, &sem);
3964 DRM_ERROR("radeon: moving bo (%d).\n", r);
3968 size_in_bytes = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT);
3969 num_loops = DIV_ROUND_UP(size_in_bytes, 0x1fffff);
3970 r = radeon_ring_lock(rdev, ring, num_loops * 7 + 18);
3972 DRM_ERROR("radeon: moving bo (%d).\n", r);
3973 radeon_semaphore_free(rdev, &sem, NULL);
3977 radeon_semaphore_sync_to(sem, *fence);
3978 radeon_semaphore_sync_rings(rdev, sem, ring->idx);
3980 for (i = 0; i < num_loops; i++) {
3981 cur_size_in_bytes = size_in_bytes;
3982 if (cur_size_in_bytes > 0x1fffff)
3983 cur_size_in_bytes = 0x1fffff;
3984 size_in_bytes -= cur_size_in_bytes;
3986 if (size_in_bytes == 0)
3987 control |= PACKET3_DMA_DATA_CP_SYNC;
3988 radeon_ring_write(ring, PACKET3(PACKET3_DMA_DATA, 5));
3989 radeon_ring_write(ring, control);
3990 radeon_ring_write(ring, lower_32_bits(src_offset));
3991 radeon_ring_write(ring, upper_32_bits(src_offset));
3992 radeon_ring_write(ring, lower_32_bits(dst_offset));
3993 radeon_ring_write(ring, upper_32_bits(dst_offset));
3994 radeon_ring_write(ring, cur_size_in_bytes);
3995 src_offset += cur_size_in_bytes;
3996 dst_offset += cur_size_in_bytes;
3999 r = radeon_fence_emit(rdev, fence, ring->idx);
4001 radeon_ring_unlock_undo(rdev, ring);
4002 radeon_semaphore_free(rdev, &sem, NULL);
4006 radeon_ring_unlock_commit(rdev, ring, false);
4007 radeon_semaphore_free(rdev, &sem, *fence);
4016 * cik_ring_ib_execute - emit an IB (Indirect Buffer) on the gfx ring
4018 * @rdev: radeon_device pointer
4019 * @ib: radeon indirect buffer object
4021 * Emits an DE (drawing engine) or CE (constant engine) IB
4022 * on the gfx ring. IBs are usually generated by userspace
4023 * acceleration drivers and submitted to the kernel for
4024 * sheduling on the ring. This function schedules the IB
4025 * on the gfx ring for execution by the GPU.
4027 void cik_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
4029 struct radeon_ring *ring = &rdev->ring[ib->ring];
4030 u32 header, control = INDIRECT_BUFFER_VALID;
4032 if (ib->is_const_ib) {
4033 /* set switch buffer packet before const IB */
4034 radeon_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
4035 radeon_ring_write(ring, 0);
4037 header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
4040 if (ring->rptr_save_reg) {
4041 next_rptr = ring->wptr + 3 + 4;
4042 radeon_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
4043 radeon_ring_write(ring, ((ring->rptr_save_reg -
4044 PACKET3_SET_UCONFIG_REG_START) >> 2));
4045 radeon_ring_write(ring, next_rptr);
4046 } else if (rdev->wb.enabled) {
4047 next_rptr = ring->wptr + 5 + 4;
4048 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
4049 radeon_ring_write(ring, WRITE_DATA_DST_SEL(1));
4050 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
4051 radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr));
4052 radeon_ring_write(ring, next_rptr);
4055 header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
4058 control |= ib->length_dw |
4059 (ib->vm ? (ib->vm->id << 24) : 0);
4061 radeon_ring_write(ring, header);
4062 radeon_ring_write(ring,
4066 (ib->gpu_addr & 0xFFFFFFFC));
4067 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
4068 radeon_ring_write(ring, control);
4072 * cik_ib_test - basic gfx ring IB test
4074 * @rdev: radeon_device pointer
4075 * @ring: radeon_ring structure holding ring information
4077 * Allocate an IB and execute it on the gfx ring (CIK).
4078 * Provides a basic gfx ring test to verify that IBs are working.
4079 * Returns 0 on success, error on failure.
4081 int cik_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
4083 struct radeon_ib ib;
4089 r = radeon_scratch_get(rdev, &scratch);
4091 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
4094 WREG32(scratch, 0xCAFEDEAD);
4095 r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
4097 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
4098 radeon_scratch_free(rdev, scratch);
4101 ib.ptr[0] = PACKET3(PACKET3_SET_UCONFIG_REG, 1);
4102 ib.ptr[1] = ((scratch - PACKET3_SET_UCONFIG_REG_START) >> 2);
4103 ib.ptr[2] = 0xDEADBEEF;
4105 r = radeon_ib_schedule(rdev, &ib, NULL, false);
4107 radeon_scratch_free(rdev, scratch);
4108 radeon_ib_free(rdev, &ib);
4109 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
4112 r = radeon_fence_wait(ib.fence, false);
4114 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
4115 radeon_scratch_free(rdev, scratch);
4116 radeon_ib_free(rdev, &ib);
4119 for (i = 0; i < rdev->usec_timeout; i++) {
4120 tmp = RREG32(scratch);
4121 if (tmp == 0xDEADBEEF)
4125 if (i < rdev->usec_timeout) {
4126 DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
4128 DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
4132 radeon_scratch_free(rdev, scratch);
4133 radeon_ib_free(rdev, &ib);
4139 * On CIK, gfx and compute now have independant command processors.
4142 * Gfx consists of a single ring and can process both gfx jobs and
4143 * compute jobs. The gfx CP consists of three microengines (ME):
4144 * PFP - Pre-Fetch Parser
4146 * CE - Constant Engine
4147 * The PFP and ME make up what is considered the Drawing Engine (DE).
4148 * The CE is an asynchronous engine used for updating buffer desciptors
4149 * used by the DE so that they can be loaded into cache in parallel
4150 * while the DE is processing state update packets.
4153 * The compute CP consists of two microengines (ME):
4154 * MEC1 - Compute MicroEngine 1
4155 * MEC2 - Compute MicroEngine 2
4156 * Each MEC supports 4 compute pipes and each pipe supports 8 queues.
4157 * The queues are exposed to userspace and are programmed directly
4158 * by the compute runtime.
4161 * cik_cp_gfx_enable - enable/disable the gfx CP MEs
4163 * @rdev: radeon_device pointer
4164 * @enable: enable or disable the MEs
4166 * Halts or unhalts the gfx MEs.
4168 static void cik_cp_gfx_enable(struct radeon_device *rdev, bool enable)
4171 WREG32(CP_ME_CNTL, 0);
4173 if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
4174 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
4175 WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT));
4176 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
4182 * cik_cp_gfx_load_microcode - load the gfx CP ME ucode
4184 * @rdev: radeon_device pointer
4186 * Loads the gfx PFP, ME, and CE ucode.
4187 * Returns 0 for success, -EINVAL if the ucode is not available.
4189 static int cik_cp_gfx_load_microcode(struct radeon_device *rdev)
4193 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw)
4196 cik_cp_gfx_enable(rdev, false);
4199 const struct gfx_firmware_header_v1_0 *pfp_hdr =
4200 (const struct gfx_firmware_header_v1_0 *)rdev->pfp_fw->data;
4201 const struct gfx_firmware_header_v1_0 *ce_hdr =
4202 (const struct gfx_firmware_header_v1_0 *)rdev->ce_fw->data;
4203 const struct gfx_firmware_header_v1_0 *me_hdr =
4204 (const struct gfx_firmware_header_v1_0 *)rdev->me_fw->data;
4205 const __le32 *fw_data;
4208 radeon_ucode_print_gfx_hdr(&pfp_hdr->header);
4209 radeon_ucode_print_gfx_hdr(&ce_hdr->header);
4210 radeon_ucode_print_gfx_hdr(&me_hdr->header);
4213 fw_data = (const __le32 *)
4214 ((const char *)rdev->pfp_fw->data + le32_to_cpu(pfp_hdr->header.ucode_array_offset_bytes));
4215 fw_size = le32_to_cpu(pfp_hdr->header.ucode_size_bytes) / 4;
4216 WREG32(CP_PFP_UCODE_ADDR, 0);
4217 for (i = 0; i < fw_size; i++)
4218 WREG32(CP_PFP_UCODE_DATA, le32_to_cpup(fw_data++));
4219 WREG32(CP_PFP_UCODE_ADDR, le32_to_cpu(pfp_hdr->header.ucode_version));
4222 fw_data = (const __le32 *)
4223 ((const char *)rdev->ce_fw->data + le32_to_cpu(ce_hdr->header.ucode_array_offset_bytes));
4224 fw_size = le32_to_cpu(ce_hdr->header.ucode_size_bytes) / 4;
4225 WREG32(CP_CE_UCODE_ADDR, 0);
4226 for (i = 0; i < fw_size; i++)
4227 WREG32(CP_CE_UCODE_DATA, le32_to_cpup(fw_data++));
4228 WREG32(CP_CE_UCODE_ADDR, le32_to_cpu(ce_hdr->header.ucode_version));
4231 fw_data = (const __be32 *)
4232 ((const char *)rdev->me_fw->data + le32_to_cpu(me_hdr->header.ucode_array_offset_bytes));
4233 fw_size = le32_to_cpu(me_hdr->header.ucode_size_bytes) / 4;
4234 WREG32(CP_ME_RAM_WADDR, 0);
4235 for (i = 0; i < fw_size; i++)
4236 WREG32(CP_ME_RAM_DATA, le32_to_cpup(fw_data++));
4237 WREG32(CP_ME_RAM_WADDR, le32_to_cpu(me_hdr->header.ucode_version));
4238 WREG32(CP_ME_RAM_RADDR, le32_to_cpu(me_hdr->header.ucode_version));
4240 const __be32 *fw_data;
4243 fw_data = (const __be32 *)rdev->pfp_fw->data;
4244 WREG32(CP_PFP_UCODE_ADDR, 0);
4245 for (i = 0; i < CIK_PFP_UCODE_SIZE; i++)
4246 WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
4247 WREG32(CP_PFP_UCODE_ADDR, 0);
4250 fw_data = (const __be32 *)rdev->ce_fw->data;
4251 WREG32(CP_CE_UCODE_ADDR, 0);
4252 for (i = 0; i < CIK_CE_UCODE_SIZE; i++)
4253 WREG32(CP_CE_UCODE_DATA, be32_to_cpup(fw_data++));
4254 WREG32(CP_CE_UCODE_ADDR, 0);
4257 fw_data = (const __be32 *)rdev->me_fw->data;
4258 WREG32(CP_ME_RAM_WADDR, 0);
4259 for (i = 0; i < CIK_ME_UCODE_SIZE; i++)
4260 WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
4261 WREG32(CP_ME_RAM_WADDR, 0);
4268 * cik_cp_gfx_start - start the gfx ring
4270 * @rdev: radeon_device pointer
4272 * Enables the ring and loads the clear state context and other
4273 * packets required to init the ring.
4274 * Returns 0 for success, error for failure.
4276 static int cik_cp_gfx_start(struct radeon_device *rdev)
4278 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
4282 WREG32(CP_MAX_CONTEXT, rdev->config.cik.max_hw_contexts - 1);
4283 WREG32(CP_ENDIAN_SWAP, 0);
4284 WREG32(CP_DEVICE_ID, 1);
4286 cik_cp_gfx_enable(rdev, true);
4288 r = radeon_ring_lock(rdev, ring, cik_default_size + 17);
4290 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
4294 /* init the CE partitions. CE only used for gfx on CIK */
4295 radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
4296 radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
4297 radeon_ring_write(ring, 0x8000);
4298 radeon_ring_write(ring, 0x8000);
4300 /* setup clear context state */
4301 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
4302 radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
4304 radeon_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
4305 radeon_ring_write(ring, 0x80000000);
4306 radeon_ring_write(ring, 0x80000000);
4308 for (i = 0; i < cik_default_size; i++)
4309 radeon_ring_write(ring, cik_default_state[i]);
4311 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
4312 radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
4314 /* set clear context state */
4315 radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
4316 radeon_ring_write(ring, 0);
4318 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
4319 radeon_ring_write(ring, 0x00000316);
4320 radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
4321 radeon_ring_write(ring, 0x00000010); /* VGT_OUT_DEALLOC_CNTL */
4323 radeon_ring_unlock_commit(rdev, ring, false);
4329 * cik_cp_gfx_fini - stop the gfx ring
4331 * @rdev: radeon_device pointer
4333 * Stop the gfx ring and tear down the driver ring
4336 static void cik_cp_gfx_fini(struct radeon_device *rdev)
4338 cik_cp_gfx_enable(rdev, false);
4339 radeon_ring_fini(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
4343 * cik_cp_gfx_resume - setup the gfx ring buffer registers
4345 * @rdev: radeon_device pointer
4347 * Program the location and size of the gfx ring buffer
4348 * and test it to make sure it's working.
4349 * Returns 0 for success, error for failure.
4351 static int cik_cp_gfx_resume(struct radeon_device *rdev)
4353 struct radeon_ring *ring;
4359 WREG32(CP_SEM_WAIT_TIMER, 0x0);
4360 if (rdev->family != CHIP_HAWAII)
4361 WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
4363 /* Set the write pointer delay */
4364 WREG32(CP_RB_WPTR_DELAY, 0);
4366 /* set the RB to use vmid 0 */
4367 WREG32(CP_RB_VMID, 0);
4369 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
4371 /* ring 0 - compute and gfx */
4372 /* Set ring buffer size */
4373 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
4374 rb_bufsz = order_base_2(ring->ring_size / 8);
4375 tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
4377 tmp |= BUF_SWAP_32BIT;
4379 WREG32(CP_RB0_CNTL, tmp);
4381 /* Initialize the ring buffer's read and write pointers */
4382 WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA);
4384 WREG32(CP_RB0_WPTR, ring->wptr);
4386 /* set the wb address wether it's enabled or not */
4387 WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
4388 WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
4390 /* scratch register shadowing is no longer supported */
4391 WREG32(SCRATCH_UMSK, 0);
4393 if (!rdev->wb.enabled)
4394 tmp |= RB_NO_UPDATE;
4397 WREG32(CP_RB0_CNTL, tmp);
4399 rb_addr = ring->gpu_addr >> 8;
4400 WREG32(CP_RB0_BASE, rb_addr);
4401 WREG32(CP_RB0_BASE_HI, upper_32_bits(rb_addr));
4403 /* start the ring */
4404 cik_cp_gfx_start(rdev);
4405 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
4406 r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
4408 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
4412 if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
4413 radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
4418 u32 cik_gfx_get_rptr(struct radeon_device *rdev,
4419 struct radeon_ring *ring)
4423 if (rdev->wb.enabled)
4424 rptr = rdev->wb.wb[ring->rptr_offs/4];
4426 rptr = RREG32(CP_RB0_RPTR);
4431 u32 cik_gfx_get_wptr(struct radeon_device *rdev,
4432 struct radeon_ring *ring)
4436 wptr = RREG32(CP_RB0_WPTR);
4441 void cik_gfx_set_wptr(struct radeon_device *rdev,
4442 struct radeon_ring *ring)
4444 WREG32(CP_RB0_WPTR, ring->wptr);
4445 (void)RREG32(CP_RB0_WPTR);
4448 u32 cik_compute_get_rptr(struct radeon_device *rdev,
4449 struct radeon_ring *ring)
4453 if (rdev->wb.enabled) {
4454 rptr = rdev->wb.wb[ring->rptr_offs/4];
4456 spin_lock(&rdev->srbm_mutex);
4457 cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
4458 rptr = RREG32(CP_HQD_PQ_RPTR);
4459 cik_srbm_select(rdev, 0, 0, 0, 0);
4460 spin_unlock(&rdev->srbm_mutex);
4466 u32 cik_compute_get_wptr(struct radeon_device *rdev,
4467 struct radeon_ring *ring)
4471 if (rdev->wb.enabled) {
4472 /* XXX check if swapping is necessary on BE */
4473 wptr = rdev->wb.wb[ring->wptr_offs/4];
4475 spin_lock(&rdev->srbm_mutex);
4476 cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
4477 wptr = RREG32(CP_HQD_PQ_WPTR);
4478 cik_srbm_select(rdev, 0, 0, 0, 0);
4479 spin_unlock(&rdev->srbm_mutex);
4485 void cik_compute_set_wptr(struct radeon_device *rdev,
4486 struct radeon_ring *ring)
4488 /* XXX check if swapping is necessary on BE */
4489 rdev->wb.wb[ring->wptr_offs/4] = ring->wptr;
4490 WDOORBELL32(ring->doorbell_index, ring->wptr);
4494 * cik_cp_compute_enable - enable/disable the compute CP MEs
4496 * @rdev: radeon_device pointer
4497 * @enable: enable or disable the MEs
4499 * Halts or unhalts the compute MEs.
4501 static void cik_cp_compute_enable(struct radeon_device *rdev, bool enable)
4504 WREG32(CP_MEC_CNTL, 0);
4506 WREG32(CP_MEC_CNTL, (MEC_ME1_HALT | MEC_ME2_HALT));
4507 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
4508 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
4514 * cik_cp_compute_load_microcode - load the compute CP ME ucode
4516 * @rdev: radeon_device pointer
4518 * Loads the compute MEC1&2 ucode.
4519 * Returns 0 for success, -EINVAL if the ucode is not available.
4521 static int cik_cp_compute_load_microcode(struct radeon_device *rdev)
4528 cik_cp_compute_enable(rdev, false);
4531 const struct gfx_firmware_header_v1_0 *mec_hdr =
4532 (const struct gfx_firmware_header_v1_0 *)rdev->mec_fw->data;
4533 const __le32 *fw_data;
4536 radeon_ucode_print_gfx_hdr(&mec_hdr->header);
4539 fw_data = (const __le32 *)
4540 ((const char *)rdev->mec_fw->data + le32_to_cpu(mec_hdr->header.ucode_array_offset_bytes));
4541 fw_size = le32_to_cpu(mec_hdr->header.ucode_size_bytes) / 4;
4542 WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
4543 for (i = 0; i < fw_size; i++)
4544 WREG32(CP_MEC_ME1_UCODE_DATA, le32_to_cpup(fw_data++));
4545 WREG32(CP_MEC_ME1_UCODE_ADDR, le32_to_cpu(mec_hdr->header.ucode_version));
4548 if (rdev->family == CHIP_KAVERI) {
4549 const struct gfx_firmware_header_v1_0 *mec2_hdr =
4550 (const struct gfx_firmware_header_v1_0 *)rdev->mec2_fw->data;
4552 fw_data = (const __le32 *)
4553 ((const char *)rdev->mec2_fw->data +
4554 le32_to_cpu(mec2_hdr->header.ucode_array_offset_bytes));
4555 fw_size = le32_to_cpu(mec2_hdr->header.ucode_size_bytes) / 4;
4556 WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
4557 for (i = 0; i < fw_size; i++)
4558 WREG32(CP_MEC_ME2_UCODE_DATA, le32_to_cpup(fw_data++));
4559 WREG32(CP_MEC_ME2_UCODE_ADDR, le32_to_cpu(mec2_hdr->header.ucode_version));
4562 const __be32 *fw_data;
4565 fw_data = (const __be32 *)rdev->mec_fw->data;
4566 WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
4567 for (i = 0; i < CIK_MEC_UCODE_SIZE; i++)
4568 WREG32(CP_MEC_ME1_UCODE_DATA, be32_to_cpup(fw_data++));
4569 WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
4571 if (rdev->family == CHIP_KAVERI) {
4573 fw_data = (const __be32 *)rdev->mec_fw->data;
4574 WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
4575 for (i = 0; i < CIK_MEC_UCODE_SIZE; i++)
4576 WREG32(CP_MEC_ME2_UCODE_DATA, be32_to_cpup(fw_data++));
4577 WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
4585 * cik_cp_compute_start - start the compute queues
4587 * @rdev: radeon_device pointer
4589 * Enable the compute queues.
4590 * Returns 0 for success, error for failure.
4592 static int cik_cp_compute_start(struct radeon_device *rdev)
4594 cik_cp_compute_enable(rdev, true);
4600 * cik_cp_compute_fini - stop the compute queues
4602 * @rdev: radeon_device pointer
4604 * Stop the compute queues and tear down the driver queue
4607 static void cik_cp_compute_fini(struct radeon_device *rdev)
4611 cik_cp_compute_enable(rdev, false);
4613 for (i = 0; i < 2; i++) {
4615 idx = CAYMAN_RING_TYPE_CP1_INDEX;
4617 idx = CAYMAN_RING_TYPE_CP2_INDEX;
4619 if (rdev->ring[idx].mqd_obj) {
4620 r = radeon_bo_reserve(rdev->ring[idx].mqd_obj, false);
4621 if (unlikely(r != 0))
4622 dev_warn(rdev->dev, "(%d) reserve MQD bo failed\n", r);
4624 radeon_bo_unpin(rdev->ring[idx].mqd_obj);
4625 radeon_bo_unreserve(rdev->ring[idx].mqd_obj);
4627 radeon_bo_unref(&rdev->ring[idx].mqd_obj);
4628 rdev->ring[idx].mqd_obj = NULL;
4633 static void cik_mec_fini(struct radeon_device *rdev)
4637 if (rdev->mec.hpd_eop_obj) {
4638 r = radeon_bo_reserve(rdev->mec.hpd_eop_obj, false);
4639 if (unlikely(r != 0))
4640 dev_warn(rdev->dev, "(%d) reserve HPD EOP bo failed\n", r);
4641 radeon_bo_unpin(rdev->mec.hpd_eop_obj);
4642 radeon_bo_unreserve(rdev->mec.hpd_eop_obj);
4644 radeon_bo_unref(&rdev->mec.hpd_eop_obj);
4645 rdev->mec.hpd_eop_obj = NULL;
4649 #define MEC_HPD_SIZE 2048
4651 static int cik_mec_init(struct radeon_device *rdev)
4657 * KV: 2 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 64 Queues total
4658 * CI/KB: 1 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 32 Queues total
4660 if (rdev->family == CHIP_KAVERI)
4661 rdev->mec.num_mec = 2;
4663 rdev->mec.num_mec = 1;
4664 rdev->mec.num_pipe = 4;
4665 rdev->mec.num_queue = rdev->mec.num_mec * rdev->mec.num_pipe * 8;
4667 if (rdev->mec.hpd_eop_obj == NULL) {
4668 r = radeon_bo_create(rdev,
4669 rdev->mec.num_mec *rdev->mec.num_pipe * MEC_HPD_SIZE * 2,
4671 RADEON_GEM_DOMAIN_GTT, 0, NULL,
4672 &rdev->mec.hpd_eop_obj);
4674 dev_warn(rdev->dev, "(%d) create HDP EOP bo failed\n", r);
4679 r = radeon_bo_reserve(rdev->mec.hpd_eop_obj, false);
4680 if (unlikely(r != 0)) {
4684 r = radeon_bo_pin(rdev->mec.hpd_eop_obj, RADEON_GEM_DOMAIN_GTT,
4685 &rdev->mec.hpd_eop_gpu_addr);
4687 dev_warn(rdev->dev, "(%d) pin HDP EOP bo failed\n", r);
4691 r = radeon_bo_kmap(rdev->mec.hpd_eop_obj, (void **)&hpd);
4693 dev_warn(rdev->dev, "(%d) map HDP EOP bo failed\n", r);
4698 /* clear memory. Not sure if this is required or not */
4699 memset(hpd, 0, rdev->mec.num_mec *rdev->mec.num_pipe * MEC_HPD_SIZE * 2);
4701 radeon_bo_kunmap(rdev->mec.hpd_eop_obj);
4702 radeon_bo_unreserve(rdev->mec.hpd_eop_obj);
4707 struct hqd_registers
4709 u32 cp_mqd_base_addr;
4710 u32 cp_mqd_base_addr_hi;
4713 u32 cp_hqd_persistent_state;
4714 u32 cp_hqd_pipe_priority;
4715 u32 cp_hqd_queue_priority;
4718 u32 cp_hqd_pq_base_hi;
4720 u32 cp_hqd_pq_rptr_report_addr;
4721 u32 cp_hqd_pq_rptr_report_addr_hi;
4722 u32 cp_hqd_pq_wptr_poll_addr;
4723 u32 cp_hqd_pq_wptr_poll_addr_hi;
4724 u32 cp_hqd_pq_doorbell_control;
4726 u32 cp_hqd_pq_control;
4727 u32 cp_hqd_ib_base_addr;
4728 u32 cp_hqd_ib_base_addr_hi;
4730 u32 cp_hqd_ib_control;
4731 u32 cp_hqd_iq_timer;
4733 u32 cp_hqd_dequeue_request;
4734 u32 cp_hqd_dma_offload;
4735 u32 cp_hqd_sema_cmd;
4736 u32 cp_hqd_msg_type;
4737 u32 cp_hqd_atomic0_preop_lo;
4738 u32 cp_hqd_atomic0_preop_hi;
4739 u32 cp_hqd_atomic1_preop_lo;
4740 u32 cp_hqd_atomic1_preop_hi;
4741 u32 cp_hqd_hq_scheduler0;
4742 u32 cp_hqd_hq_scheduler1;
4749 u32 dispatch_initiator;
4753 u32 pipeline_stat_enable;
4754 u32 perf_counter_enable;
4760 u32 resource_limits;
4761 u32 static_thread_mgmt01[2];
4763 u32 static_thread_mgmt23[2];
4765 u32 thread_trace_enable;
4768 u32 vgtcs_invoke_count[2];
4769 struct hqd_registers queue_state;
4771 u32 interrupt_queue[64];
4775 * cik_cp_compute_resume - setup the compute queue registers
4777 * @rdev: radeon_device pointer
4779 * Program the compute queues and test them to make sure they
4781 * Returns 0 for success, error for failure.
4783 static int cik_cp_compute_resume(struct radeon_device *rdev)
4787 bool use_doorbell = true;
4793 struct bonaire_mqd *mqd;
4795 r = cik_cp_compute_start(rdev);
4799 /* fix up chicken bits */
4800 tmp = RREG32(CP_CPF_DEBUG);
4802 WREG32(CP_CPF_DEBUG, tmp);
4804 /* init the pipes */
4805 spin_lock(&rdev->srbm_mutex);
4806 for (i = 0; i < (rdev->mec.num_pipe * rdev->mec.num_mec); i++) {
4807 int me = (i < 4) ? 1 : 2;
4808 int pipe = (i < 4) ? i : (i - 4);
4810 eop_gpu_addr = rdev->mec.hpd_eop_gpu_addr + (i * MEC_HPD_SIZE * 2);
4812 cik_srbm_select(rdev, me, pipe, 0, 0);
4814 /* write the EOP addr */
4815 WREG32(CP_HPD_EOP_BASE_ADDR, eop_gpu_addr >> 8);
4816 WREG32(CP_HPD_EOP_BASE_ADDR_HI, upper_32_bits(eop_gpu_addr) >> 8);
4818 /* set the VMID assigned */
4819 WREG32(CP_HPD_EOP_VMID, 0);
4821 /* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */
4822 tmp = RREG32(CP_HPD_EOP_CONTROL);
4823 tmp &= ~EOP_SIZE_MASK;
4824 tmp |= order_base_2(MEC_HPD_SIZE / 8);
4825 WREG32(CP_HPD_EOP_CONTROL, tmp);
4827 cik_srbm_select(rdev, 0, 0, 0, 0);
4828 spin_unlock(&rdev->srbm_mutex);
4830 /* init the queues. Just two for now. */
4831 for (i = 0; i < 2; i++) {
4833 idx = CAYMAN_RING_TYPE_CP1_INDEX;
4835 idx = CAYMAN_RING_TYPE_CP2_INDEX;
4837 if (rdev->ring[idx].mqd_obj == NULL) {
4838 r = radeon_bo_create(rdev,
4839 sizeof(struct bonaire_mqd),
4841 RADEON_GEM_DOMAIN_GTT, 0, NULL,
4842 &rdev->ring[idx].mqd_obj);
4844 dev_warn(rdev->dev, "(%d) create MQD bo failed\n", r);
4849 r = radeon_bo_reserve(rdev->ring[idx].mqd_obj, false);
4850 if (unlikely(r != 0)) {
4851 cik_cp_compute_fini(rdev);
4854 r = radeon_bo_pin(rdev->ring[idx].mqd_obj, RADEON_GEM_DOMAIN_GTT,
4857 dev_warn(rdev->dev, "(%d) pin MQD bo failed\n", r);
4858 cik_cp_compute_fini(rdev);
4861 r = radeon_bo_kmap(rdev->ring[idx].mqd_obj, (void **)&buf);
4863 dev_warn(rdev->dev, "(%d) map MQD bo failed\n", r);
4864 cik_cp_compute_fini(rdev);
4868 /* init the mqd struct */
4869 memset(buf, 0, sizeof(struct bonaire_mqd));
4871 mqd = (struct bonaire_mqd *)buf;
4872 mqd->header = 0xC0310800;
4873 mqd->static_thread_mgmt01[0] = 0xffffffff;
4874 mqd->static_thread_mgmt01[1] = 0xffffffff;
4875 mqd->static_thread_mgmt23[0] = 0xffffffff;
4876 mqd->static_thread_mgmt23[1] = 0xffffffff;
4878 spin_lock(&rdev->srbm_mutex);
4879 cik_srbm_select(rdev, rdev->ring[idx].me,
4880 rdev->ring[idx].pipe,
4881 rdev->ring[idx].queue, 0);
4883 /* disable wptr polling */
4884 tmp = RREG32(CP_PQ_WPTR_POLL_CNTL);
4885 tmp &= ~WPTR_POLL_EN;
4886 WREG32(CP_PQ_WPTR_POLL_CNTL, tmp);
4888 /* enable doorbell? */
4889 mqd->queue_state.cp_hqd_pq_doorbell_control =
4890 RREG32(CP_HQD_PQ_DOORBELL_CONTROL);
4892 mqd->queue_state.cp_hqd_pq_doorbell_control |= DOORBELL_EN;
4894 mqd->queue_state.cp_hqd_pq_doorbell_control &= ~DOORBELL_EN;
4895 WREG32(CP_HQD_PQ_DOORBELL_CONTROL,
4896 mqd->queue_state.cp_hqd_pq_doorbell_control);
4898 /* disable the queue if it's active */
4899 mqd->queue_state.cp_hqd_dequeue_request = 0;
4900 mqd->queue_state.cp_hqd_pq_rptr = 0;
4901 mqd->queue_state.cp_hqd_pq_wptr= 0;
4902 if (RREG32(CP_HQD_ACTIVE) & 1) {
4903 WREG32(CP_HQD_DEQUEUE_REQUEST, 1);
4904 for (j = 0; j < rdev->usec_timeout; j++) {
4905 if (!(RREG32(CP_HQD_ACTIVE) & 1))
4909 WREG32(CP_HQD_DEQUEUE_REQUEST, mqd->queue_state.cp_hqd_dequeue_request);
4910 WREG32(CP_HQD_PQ_RPTR, mqd->queue_state.cp_hqd_pq_rptr);
4911 WREG32(CP_HQD_PQ_WPTR, mqd->queue_state.cp_hqd_pq_wptr);
4914 /* set the pointer to the MQD */
4915 mqd->queue_state.cp_mqd_base_addr = mqd_gpu_addr & 0xfffffffc;
4916 mqd->queue_state.cp_mqd_base_addr_hi = upper_32_bits(mqd_gpu_addr);
4917 WREG32(CP_MQD_BASE_ADDR, mqd->queue_state.cp_mqd_base_addr);
4918 WREG32(CP_MQD_BASE_ADDR_HI, mqd->queue_state.cp_mqd_base_addr_hi);
4919 /* set MQD vmid to 0 */
4920 mqd->queue_state.cp_mqd_control = RREG32(CP_MQD_CONTROL);
4921 mqd->queue_state.cp_mqd_control &= ~MQD_VMID_MASK;
4922 WREG32(CP_MQD_CONTROL, mqd->queue_state.cp_mqd_control);
4924 /* set the pointer to the HQD, this is similar CP_RB0_BASE/_HI */
4925 hqd_gpu_addr = rdev->ring[idx].gpu_addr >> 8;
4926 mqd->queue_state.cp_hqd_pq_base = hqd_gpu_addr;
4927 mqd->queue_state.cp_hqd_pq_base_hi = upper_32_bits(hqd_gpu_addr);
4928 WREG32(CP_HQD_PQ_BASE, mqd->queue_state.cp_hqd_pq_base);
4929 WREG32(CP_HQD_PQ_BASE_HI, mqd->queue_state.cp_hqd_pq_base_hi);
4931 /* set up the HQD, this is similar to CP_RB0_CNTL */
4932 mqd->queue_state.cp_hqd_pq_control = RREG32(CP_HQD_PQ_CONTROL);
4933 mqd->queue_state.cp_hqd_pq_control &=
4934 ~(QUEUE_SIZE_MASK | RPTR_BLOCK_SIZE_MASK);
4936 mqd->queue_state.cp_hqd_pq_control |=
4937 order_base_2(rdev->ring[idx].ring_size / 8);
4938 mqd->queue_state.cp_hqd_pq_control |=
4939 (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8);
4941 mqd->queue_state.cp_hqd_pq_control |= BUF_SWAP_32BIT;
4943 mqd->queue_state.cp_hqd_pq_control &=
4944 ~(UNORD_DISPATCH | ROQ_PQ_IB_FLIP | PQ_VOLATILE);
4945 mqd->queue_state.cp_hqd_pq_control |=
4946 PRIV_STATE | KMD_QUEUE; /* assuming kernel queue control */
4947 WREG32(CP_HQD_PQ_CONTROL, mqd->queue_state.cp_hqd_pq_control);
4949 /* only used if CP_PQ_WPTR_POLL_CNTL.WPTR_POLL_EN=1 */
4951 wb_gpu_addr = rdev->wb.gpu_addr + CIK_WB_CP1_WPTR_OFFSET;
4953 wb_gpu_addr = rdev->wb.gpu_addr + CIK_WB_CP2_WPTR_OFFSET;
4954 mqd->queue_state.cp_hqd_pq_wptr_poll_addr = wb_gpu_addr & 0xfffffffc;
4955 mqd->queue_state.cp_hqd_pq_wptr_poll_addr_hi = upper_32_bits(wb_gpu_addr) & 0xffff;
4956 WREG32(CP_HQD_PQ_WPTR_POLL_ADDR, mqd->queue_state.cp_hqd_pq_wptr_poll_addr);
4957 WREG32(CP_HQD_PQ_WPTR_POLL_ADDR_HI,
4958 mqd->queue_state.cp_hqd_pq_wptr_poll_addr_hi);
4960 /* set the wb address wether it's enabled or not */
4962 wb_gpu_addr = rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET;
4964 wb_gpu_addr = rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET;
4965 mqd->queue_state.cp_hqd_pq_rptr_report_addr = wb_gpu_addr & 0xfffffffc;
4966 mqd->queue_state.cp_hqd_pq_rptr_report_addr_hi =
4967 upper_32_bits(wb_gpu_addr) & 0xffff;
4968 WREG32(CP_HQD_PQ_RPTR_REPORT_ADDR,
4969 mqd->queue_state.cp_hqd_pq_rptr_report_addr);
4970 WREG32(CP_HQD_PQ_RPTR_REPORT_ADDR_HI,
4971 mqd->queue_state.cp_hqd_pq_rptr_report_addr_hi);
4973 /* enable the doorbell if requested */
4975 mqd->queue_state.cp_hqd_pq_doorbell_control =
4976 RREG32(CP_HQD_PQ_DOORBELL_CONTROL);
4977 mqd->queue_state.cp_hqd_pq_doorbell_control &= ~DOORBELL_OFFSET_MASK;
4978 mqd->queue_state.cp_hqd_pq_doorbell_control |=
4979 DOORBELL_OFFSET(rdev->ring[idx].doorbell_index);
4980 mqd->queue_state.cp_hqd_pq_doorbell_control |= DOORBELL_EN;
4981 mqd->queue_state.cp_hqd_pq_doorbell_control &=
4982 ~(DOORBELL_SOURCE | DOORBELL_HIT);
4985 mqd->queue_state.cp_hqd_pq_doorbell_control = 0;
4987 WREG32(CP_HQD_PQ_DOORBELL_CONTROL,
4988 mqd->queue_state.cp_hqd_pq_doorbell_control);
4990 /* read and write pointers, similar to CP_RB0_WPTR/_RPTR */
4991 rdev->ring[idx].wptr = 0;
4992 mqd->queue_state.cp_hqd_pq_wptr = rdev->ring[idx].wptr;
4993 WREG32(CP_HQD_PQ_WPTR, mqd->queue_state.cp_hqd_pq_wptr);
4994 mqd->queue_state.cp_hqd_pq_rptr = RREG32(CP_HQD_PQ_RPTR);
4996 /* set the vmid for the queue */
4997 mqd->queue_state.cp_hqd_vmid = 0;
4998 WREG32(CP_HQD_VMID, mqd->queue_state.cp_hqd_vmid);
5000 /* activate the queue */
5001 mqd->queue_state.cp_hqd_active = 1;
5002 WREG32(CP_HQD_ACTIVE, mqd->queue_state.cp_hqd_active);
5004 cik_srbm_select(rdev, 0, 0, 0, 0);
5005 spin_unlock(&rdev->srbm_mutex);
5007 radeon_bo_kunmap(rdev->ring[idx].mqd_obj);
5008 radeon_bo_unreserve(rdev->ring[idx].mqd_obj);
5010 rdev->ring[idx].ready = true;
5011 r = radeon_ring_test(rdev, idx, &rdev->ring[idx]);
5013 rdev->ring[idx].ready = false;
5019 static void cik_cp_enable(struct radeon_device *rdev, bool enable)
5021 cik_cp_gfx_enable(rdev, enable);
5022 cik_cp_compute_enable(rdev, enable);
5025 static int cik_cp_load_microcode(struct radeon_device *rdev)
5029 r = cik_cp_gfx_load_microcode(rdev);
5032 r = cik_cp_compute_load_microcode(rdev);
5039 static void cik_cp_fini(struct radeon_device *rdev)
5041 cik_cp_gfx_fini(rdev);
5042 cik_cp_compute_fini(rdev);
5045 static int cik_cp_resume(struct radeon_device *rdev)
5049 cik_enable_gui_idle_interrupt(rdev, false);
5051 r = cik_cp_load_microcode(rdev);
5055 r = cik_cp_gfx_resume(rdev);
5058 r = cik_cp_compute_resume(rdev);
5062 cik_enable_gui_idle_interrupt(rdev, true);
5067 static void cik_print_gpu_status_regs(struct radeon_device *rdev)
5069 dev_info(rdev->dev, " GRBM_STATUS=0x%08X\n",
5070 RREG32(GRBM_STATUS));
5071 dev_info(rdev->dev, " GRBM_STATUS2=0x%08X\n",
5072 RREG32(GRBM_STATUS2));
5073 dev_info(rdev->dev, " GRBM_STATUS_SE0=0x%08X\n",
5074 RREG32(GRBM_STATUS_SE0));
5075 dev_info(rdev->dev, " GRBM_STATUS_SE1=0x%08X\n",
5076 RREG32(GRBM_STATUS_SE1));
5077 dev_info(rdev->dev, " GRBM_STATUS_SE2=0x%08X\n",
5078 RREG32(GRBM_STATUS_SE2));
5079 dev_info(rdev->dev, " GRBM_STATUS_SE3=0x%08X\n",
5080 RREG32(GRBM_STATUS_SE3));
5081 dev_info(rdev->dev, " SRBM_STATUS=0x%08X\n",
5082 RREG32(SRBM_STATUS));
5083 dev_info(rdev->dev, " SRBM_STATUS2=0x%08X\n",
5084 RREG32(SRBM_STATUS2));
5085 dev_info(rdev->dev, " SDMA0_STATUS_REG = 0x%08X\n",
5086 RREG32(SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET));
5087 dev_info(rdev->dev, " SDMA1_STATUS_REG = 0x%08X\n",
5088 RREG32(SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET));
5089 dev_info(rdev->dev, " CP_STAT = 0x%08x\n", RREG32(CP_STAT));
5090 dev_info(rdev->dev, " CP_STALLED_STAT1 = 0x%08x\n",
5091 RREG32(CP_STALLED_STAT1));
5092 dev_info(rdev->dev, " CP_STALLED_STAT2 = 0x%08x\n",
5093 RREG32(CP_STALLED_STAT2));
5094 dev_info(rdev->dev, " CP_STALLED_STAT3 = 0x%08x\n",
5095 RREG32(CP_STALLED_STAT3));
5096 dev_info(rdev->dev, " CP_CPF_BUSY_STAT = 0x%08x\n",
5097 RREG32(CP_CPF_BUSY_STAT));
5098 dev_info(rdev->dev, " CP_CPF_STALLED_STAT1 = 0x%08x\n",
5099 RREG32(CP_CPF_STALLED_STAT1));
5100 dev_info(rdev->dev, " CP_CPF_STATUS = 0x%08x\n", RREG32(CP_CPF_STATUS));
5101 dev_info(rdev->dev, " CP_CPC_BUSY_STAT = 0x%08x\n", RREG32(CP_CPC_BUSY_STAT));
5102 dev_info(rdev->dev, " CP_CPC_STALLED_STAT1 = 0x%08x\n",
5103 RREG32(CP_CPC_STALLED_STAT1));
5104 dev_info(rdev->dev, " CP_CPC_STATUS = 0x%08x\n", RREG32(CP_CPC_STATUS));
5108 * cik_gpu_check_soft_reset - check which blocks are busy
5110 * @rdev: radeon_device pointer
5112 * Check which blocks are busy and return the relevant reset
5113 * mask to be used by cik_gpu_soft_reset().
5114 * Returns a mask of the blocks to be reset.
5116 u32 cik_gpu_check_soft_reset(struct radeon_device *rdev)
5122 tmp = RREG32(GRBM_STATUS);
5123 if (tmp & (PA_BUSY | SC_BUSY |
5124 BCI_BUSY | SX_BUSY |
5125 TA_BUSY | VGT_BUSY |
5127 GDS_BUSY | SPI_BUSY |
5128 IA_BUSY | IA_BUSY_NO_DMA))
5129 reset_mask |= RADEON_RESET_GFX;
5131 if (tmp & (CP_BUSY | CP_COHERENCY_BUSY))
5132 reset_mask |= RADEON_RESET_CP;
5135 tmp = RREG32(GRBM_STATUS2);
5137 reset_mask |= RADEON_RESET_RLC;
5139 /* SDMA0_STATUS_REG */
5140 tmp = RREG32(SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET);
5141 if (!(tmp & SDMA_IDLE))
5142 reset_mask |= RADEON_RESET_DMA;
5144 /* SDMA1_STATUS_REG */
5145 tmp = RREG32(SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET);
5146 if (!(tmp & SDMA_IDLE))
5147 reset_mask |= RADEON_RESET_DMA1;
5150 tmp = RREG32(SRBM_STATUS2);
5151 if (tmp & SDMA_BUSY)
5152 reset_mask |= RADEON_RESET_DMA;
5154 if (tmp & SDMA1_BUSY)
5155 reset_mask |= RADEON_RESET_DMA1;
5158 tmp = RREG32(SRBM_STATUS);
5161 reset_mask |= RADEON_RESET_IH;
5164 reset_mask |= RADEON_RESET_SEM;
5166 if (tmp & GRBM_RQ_PENDING)
5167 reset_mask |= RADEON_RESET_GRBM;
5170 reset_mask |= RADEON_RESET_VMC;
5172 if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
5173 MCC_BUSY | MCD_BUSY))
5174 reset_mask |= RADEON_RESET_MC;
5176 if (evergreen_is_display_hung(rdev))
5177 reset_mask |= RADEON_RESET_DISPLAY;
5179 /* Skip MC reset as it's mostly likely not hung, just busy */
5180 if (reset_mask & RADEON_RESET_MC) {
5181 DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
5182 reset_mask &= ~RADEON_RESET_MC;
5189 * cik_gpu_soft_reset - soft reset GPU
5191 * @rdev: radeon_device pointer
5192 * @reset_mask: mask of which blocks to reset
5194 * Soft reset the blocks specified in @reset_mask.
5196 static void cik_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
5198 struct evergreen_mc_save save;
5199 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
5202 if (reset_mask == 0)
5205 dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
5207 cik_print_gpu_status_regs(rdev);
5208 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
5209 RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
5210 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
5211 RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
5220 /* Disable GFX parsing/prefetching */
5221 WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
5223 /* Disable MEC parsing/prefetching */
5224 WREG32(CP_MEC_CNTL, MEC_ME1_HALT | MEC_ME2_HALT);
5226 if (reset_mask & RADEON_RESET_DMA) {
5228 tmp = RREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET);
5230 WREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET, tmp);
5232 if (reset_mask & RADEON_RESET_DMA1) {
5234 tmp = RREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET);
5236 WREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET, tmp);
5239 evergreen_mc_stop(rdev, &save);
5240 if (evergreen_mc_wait_for_idle(rdev)) {
5241 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
5244 if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE | RADEON_RESET_CP))
5245 grbm_soft_reset = SOFT_RESET_CP | SOFT_RESET_GFX;
5247 if (reset_mask & RADEON_RESET_CP) {
5248 grbm_soft_reset |= SOFT_RESET_CP;
5250 srbm_soft_reset |= SOFT_RESET_GRBM;
5253 if (reset_mask & RADEON_RESET_DMA)
5254 srbm_soft_reset |= SOFT_RESET_SDMA;
5256 if (reset_mask & RADEON_RESET_DMA1)
5257 srbm_soft_reset |= SOFT_RESET_SDMA1;
5259 if (reset_mask & RADEON_RESET_DISPLAY)
5260 srbm_soft_reset |= SOFT_RESET_DC;
5262 if (reset_mask & RADEON_RESET_RLC)
5263 grbm_soft_reset |= SOFT_RESET_RLC;
5265 if (reset_mask & RADEON_RESET_SEM)
5266 srbm_soft_reset |= SOFT_RESET_SEM;
5268 if (reset_mask & RADEON_RESET_IH)
5269 srbm_soft_reset |= SOFT_RESET_IH;
5271 if (reset_mask & RADEON_RESET_GRBM)
5272 srbm_soft_reset |= SOFT_RESET_GRBM;
5274 if (reset_mask & RADEON_RESET_VMC)
5275 srbm_soft_reset |= SOFT_RESET_VMC;
5277 if (!(rdev->flags & RADEON_IS_IGP)) {
5278 if (reset_mask & RADEON_RESET_MC)
5279 srbm_soft_reset |= SOFT_RESET_MC;
5282 if (grbm_soft_reset) {
5283 tmp = RREG32(GRBM_SOFT_RESET);
5284 tmp |= grbm_soft_reset;
5285 dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
5286 WREG32(GRBM_SOFT_RESET, tmp);
5287 tmp = RREG32(GRBM_SOFT_RESET);
5291 tmp &= ~grbm_soft_reset;
5292 WREG32(GRBM_SOFT_RESET, tmp);
5293 tmp = RREG32(GRBM_SOFT_RESET);
5296 if (srbm_soft_reset) {
5297 tmp = RREG32(SRBM_SOFT_RESET);
5298 tmp |= srbm_soft_reset;
5299 dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
5300 WREG32(SRBM_SOFT_RESET, tmp);
5301 tmp = RREG32(SRBM_SOFT_RESET);
5305 tmp &= ~srbm_soft_reset;
5306 WREG32(SRBM_SOFT_RESET, tmp);
5307 tmp = RREG32(SRBM_SOFT_RESET);
5310 /* Wait a little for things to settle down */
5313 evergreen_mc_resume(rdev, &save);
5316 cik_print_gpu_status_regs(rdev);
5319 struct kv_reset_save_regs {
5320 u32 gmcon_reng_execute;
5325 static void kv_save_regs_for_reset(struct radeon_device *rdev,
5326 struct kv_reset_save_regs *save)
5328 save->gmcon_reng_execute = RREG32(GMCON_RENG_EXECUTE);
5329 save->gmcon_misc = RREG32(GMCON_MISC);
5330 save->gmcon_misc3 = RREG32(GMCON_MISC3);
5332 WREG32(GMCON_RENG_EXECUTE, save->gmcon_reng_execute & ~RENG_EXECUTE_ON_PWR_UP);
5333 WREG32(GMCON_MISC, save->gmcon_misc & ~(RENG_EXECUTE_ON_REG_UPDATE |
5334 STCTRL_STUTTER_EN));
5337 static void kv_restore_regs_for_reset(struct radeon_device *rdev,
5338 struct kv_reset_save_regs *save)
5342 WREG32(GMCON_PGFSM_WRITE, 0);
5343 WREG32(GMCON_PGFSM_CONFIG, 0x200010ff);
5345 for (i = 0; i < 5; i++)
5346 WREG32(GMCON_PGFSM_WRITE, 0);
5348 WREG32(GMCON_PGFSM_WRITE, 0);
5349 WREG32(GMCON_PGFSM_CONFIG, 0x300010ff);
5351 for (i = 0; i < 5; i++)
5352 WREG32(GMCON_PGFSM_WRITE, 0);
5354 WREG32(GMCON_PGFSM_WRITE, 0x210000);
5355 WREG32(GMCON_PGFSM_CONFIG, 0xa00010ff);
5357 for (i = 0; i < 5; i++)
5358 WREG32(GMCON_PGFSM_WRITE, 0);
5360 WREG32(GMCON_PGFSM_WRITE, 0x21003);
5361 WREG32(GMCON_PGFSM_CONFIG, 0xb00010ff);
5363 for (i = 0; i < 5; i++)
5364 WREG32(GMCON_PGFSM_WRITE, 0);
5366 WREG32(GMCON_PGFSM_WRITE, 0x2b00);
5367 WREG32(GMCON_PGFSM_CONFIG, 0xc00010ff);
5369 for (i = 0; i < 5; i++)
5370 WREG32(GMCON_PGFSM_WRITE, 0);
5372 WREG32(GMCON_PGFSM_WRITE, 0);
5373 WREG32(GMCON_PGFSM_CONFIG, 0xd00010ff);
5375 for (i = 0; i < 5; i++)
5376 WREG32(GMCON_PGFSM_WRITE, 0);
5378 WREG32(GMCON_PGFSM_WRITE, 0x420000);
5379 WREG32(GMCON_PGFSM_CONFIG, 0x100010ff);
5381 for (i = 0; i < 5; i++)
5382 WREG32(GMCON_PGFSM_WRITE, 0);
5384 WREG32(GMCON_PGFSM_WRITE, 0x120202);
5385 WREG32(GMCON_PGFSM_CONFIG, 0x500010ff);
5387 for (i = 0; i < 5; i++)
5388 WREG32(GMCON_PGFSM_WRITE, 0);
5390 WREG32(GMCON_PGFSM_WRITE, 0x3e3e36);
5391 WREG32(GMCON_PGFSM_CONFIG, 0x600010ff);
5393 for (i = 0; i < 5; i++)
5394 WREG32(GMCON_PGFSM_WRITE, 0);
5396 WREG32(GMCON_PGFSM_WRITE, 0x373f3e);
5397 WREG32(GMCON_PGFSM_CONFIG, 0x700010ff);
5399 for (i = 0; i < 5; i++)
5400 WREG32(GMCON_PGFSM_WRITE, 0);
5402 WREG32(GMCON_PGFSM_WRITE, 0x3e1332);
5403 WREG32(GMCON_PGFSM_CONFIG, 0xe00010ff);
5405 WREG32(GMCON_MISC3, save->gmcon_misc3);
5406 WREG32(GMCON_MISC, save->gmcon_misc);
5407 WREG32(GMCON_RENG_EXECUTE, save->gmcon_reng_execute);
5410 static void cik_gpu_pci_config_reset(struct radeon_device *rdev)
5412 struct evergreen_mc_save save;
5413 struct kv_reset_save_regs kv_save = { 0 };
5416 dev_info(rdev->dev, "GPU pci config reset\n");
5424 /* Disable GFX parsing/prefetching */
5425 WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
5427 /* Disable MEC parsing/prefetching */
5428 WREG32(CP_MEC_CNTL, MEC_ME1_HALT | MEC_ME2_HALT);
5431 tmp = RREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET);
5433 WREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET, tmp);
5435 tmp = RREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET);
5437 WREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET, tmp);
5438 /* XXX other engines? */
5440 /* halt the rlc, disable cp internal ints */
5445 /* disable mem access */
5446 evergreen_mc_stop(rdev, &save);
5447 if (evergreen_mc_wait_for_idle(rdev)) {
5448 dev_warn(rdev->dev, "Wait for MC idle timed out !\n");
5451 if (rdev->flags & RADEON_IS_IGP)
5452 kv_save_regs_for_reset(rdev, &kv_save);
5455 pci_disable_busmaster(rdev->pdev->dev);
5457 radeon_pci_config_reset(rdev);
5461 /* wait for asic to come out of reset */
5462 for (i = 0; i < rdev->usec_timeout; i++) {
5463 if (RREG32(CONFIG_MEMSIZE) != 0xffffffff)
5468 /* does asic init need to be run first??? */
5469 if (rdev->flags & RADEON_IS_IGP)
5470 kv_restore_regs_for_reset(rdev, &kv_save);
5474 * cik_asic_reset - soft reset GPU
5476 * @rdev: radeon_device pointer
5478 * Look up which blocks are hung and attempt
5480 * Returns 0 for success.
5482 int cik_asic_reset(struct radeon_device *rdev)
5486 reset_mask = cik_gpu_check_soft_reset(rdev);
5489 r600_set_bios_scratch_engine_hung(rdev, true);
5491 /* try soft reset */
5492 cik_gpu_soft_reset(rdev, reset_mask);
5494 reset_mask = cik_gpu_check_soft_reset(rdev);
5496 /* try pci config reset */
5497 if (reset_mask && radeon_hard_reset)
5498 cik_gpu_pci_config_reset(rdev);
5500 reset_mask = cik_gpu_check_soft_reset(rdev);
5503 r600_set_bios_scratch_engine_hung(rdev, false);
5509 * cik_gfx_is_lockup - check if the 3D engine is locked up
5511 * @rdev: radeon_device pointer
5512 * @ring: radeon_ring structure holding ring information
5514 * Check if the 3D engine is locked up (CIK).
5515 * Returns true if the engine is locked, false if not.
5517 bool cik_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
5519 u32 reset_mask = cik_gpu_check_soft_reset(rdev);
5521 if (!(reset_mask & (RADEON_RESET_GFX |
5522 RADEON_RESET_COMPUTE |
5523 RADEON_RESET_CP))) {
5524 radeon_ring_lockup_update(rdev, ring);
5527 return radeon_ring_test_lockup(rdev, ring);
5532 * cik_mc_program - program the GPU memory controller
5534 * @rdev: radeon_device pointer
5536 * Set the location of vram, gart, and AGP in the GPU's
5537 * physical address space (CIK).
5539 static void cik_mc_program(struct radeon_device *rdev)
5541 struct evergreen_mc_save save;
5545 /* Initialize HDP */
5546 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
5547 WREG32((0x2c14 + j), 0x00000000);
5548 WREG32((0x2c18 + j), 0x00000000);
5549 WREG32((0x2c1c + j), 0x00000000);
5550 WREG32((0x2c20 + j), 0x00000000);
5551 WREG32((0x2c24 + j), 0x00000000);
5553 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
5555 evergreen_mc_stop(rdev, &save);
5556 if (radeon_mc_wait_for_idle(rdev)) {
5557 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
5559 /* Lockout access through VGA aperture*/
5560 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
5561 /* Update configuration */
5562 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
5563 rdev->mc.vram_start >> 12);
5564 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
5565 rdev->mc.vram_end >> 12);
5566 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR,
5567 rdev->vram_scratch.gpu_addr >> 12);
5568 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
5569 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
5570 WREG32(MC_VM_FB_LOCATION, tmp);
5571 /* XXX double check these! */
5572 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
5573 WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
5574 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
5575 WREG32(MC_VM_AGP_BASE, 0);
5576 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
5577 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
5578 if (radeon_mc_wait_for_idle(rdev)) {
5579 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
5581 evergreen_mc_resume(rdev, &save);
5582 /* we need to own VRAM, so turn off the VGA renderer here
5583 * to stop it overwriting our objects */
5584 rv515_vga_render_disable(rdev);
5588 * cik_mc_init - initialize the memory controller driver params
5590 * @rdev: radeon_device pointer
5592 * Look up the amount of vram, vram width, and decide how to place
5593 * vram and gart within the GPU's physical address space (CIK).
5594 * Returns 0 for success.
5596 static int cik_mc_init(struct radeon_device *rdev)
5599 int chansize, numchan;
5601 /* Get VRAM informations */
5602 rdev->mc.vram_is_ddr = true;
5603 tmp = RREG32(MC_ARB_RAMCFG);
5604 if (tmp & CHANSIZE_MASK) {
5609 tmp = RREG32(MC_SHARED_CHMAP);
5610 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
5640 rdev->mc.vram_width = numchan * chansize;
5641 /* Could aper size report 0 ? */
5642 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
5643 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
5644 /* size in MB on si */
5645 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
5646 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
5647 rdev->mc.visible_vram_size = rdev->mc.aper_size;
5648 si_vram_gtt_location(rdev, &rdev->mc);
5649 radeon_update_bandwidth_info(rdev);
5656 * VMID 0 is the physical GPU addresses as used by the kernel.
5657 * VMIDs 1-15 are used for userspace clients and are handled
5658 * by the radeon vm/hsa code.
5661 * cik_pcie_gart_tlb_flush - gart tlb flush callback
5663 * @rdev: radeon_device pointer
5665 * Flush the TLB for the VMID 0 page table (CIK).
5667 void cik_pcie_gart_tlb_flush(struct radeon_device *rdev)
5669 /* flush hdp cache */
5670 WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0);
5672 /* bits 0-15 are the VM contexts0-15 */
5673 WREG32(VM_INVALIDATE_REQUEST, 0x1);
5677 * cik_pcie_gart_enable - gart enable
5679 * @rdev: radeon_device pointer
5681 * This sets up the TLBs, programs the page tables for VMID0,
5682 * sets up the hw for VMIDs 1-15 which are allocated on
5683 * demand, and sets up the global locations for the LDS, GDS,
5684 * and GPUVM for FSA64 clients (CIK).
5685 * Returns 0 for success, errors for failure.
5687 static int cik_pcie_gart_enable(struct radeon_device *rdev)
5691 if (rdev->gart.robj == NULL) {
5692 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
5695 r = radeon_gart_table_vram_pin(rdev);
5698 /* Setup TLB control */
5699 WREG32(MC_VM_MX_L1_TLB_CNTL,
5702 ENABLE_L1_FRAGMENT_PROCESSING |
5703 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
5704 ENABLE_ADVANCED_DRIVER_MODEL |
5705 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
5706 /* Setup L2 cache */
5707 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
5708 ENABLE_L2_FRAGMENT_PROCESSING |
5709 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
5710 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
5711 EFFECTIVE_L2_QUEUE_SIZE(7) |
5712 CONTEXT1_IDENTITY_ACCESS_MODE(1));
5713 WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
5714 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
5716 L2_CACHE_BIGK_FRAGMENT_SIZE(4));
5717 /* setup context0 */
5718 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
5719 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
5720 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
5721 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
5722 (u32)(rdev->dummy_page.addr >> 12));
5723 WREG32(VM_CONTEXT0_CNTL2, 0);
5724 WREG32(VM_CONTEXT0_CNTL, (ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
5725 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT));
5731 /* restore context1-15 */
5732 /* set vm size, must be a multiple of 4 */
5733 WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
5734 WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn);
5735 for (i = 1; i < 16; i++) {
5737 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
5738 rdev->vm_manager.saved_table_addr[i]);
5740 WREG32(VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2),
5741 rdev->vm_manager.saved_table_addr[i]);
5744 /* enable context1-15 */
5745 WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
5746 (u32)(rdev->dummy_page.addr >> 12));
5747 WREG32(VM_CONTEXT1_CNTL2, 4);
5748 WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
5749 PAGE_TABLE_BLOCK_SIZE(radeon_vm_block_size - 9) |
5750 RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
5751 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
5752 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
5753 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
5754 PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
5755 PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
5756 VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
5757 VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
5758 READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
5759 READ_PROTECTION_FAULT_ENABLE_DEFAULT |
5760 WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
5761 WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
5763 if (rdev->family == CHIP_KAVERI) {
5764 u32 tmp = RREG32(CHUB_CONTROL);
5766 WREG32(CHUB_CONTROL, tmp);
5769 /* XXX SH_MEM regs */
5770 /* where to put LDS, scratch, GPUVM in FSA64 space */
5771 spin_lock(&rdev->srbm_mutex);
5772 for (i = 0; i < 16; i++) {
5773 cik_srbm_select(rdev, 0, 0, 0, i);
5774 /* CP and shaders */
5775 WREG32(SH_MEM_CONFIG, 0);
5776 WREG32(SH_MEM_APE1_BASE, 1);
5777 WREG32(SH_MEM_APE1_LIMIT, 0);
5778 WREG32(SH_MEM_BASES, 0);
5780 WREG32(SDMA0_GFX_VIRTUAL_ADDR + SDMA0_REGISTER_OFFSET, 0);
5781 WREG32(SDMA0_GFX_APE1_CNTL + SDMA0_REGISTER_OFFSET, 0);
5782 WREG32(SDMA0_GFX_VIRTUAL_ADDR + SDMA1_REGISTER_OFFSET, 0);
5783 WREG32(SDMA0_GFX_APE1_CNTL + SDMA1_REGISTER_OFFSET, 0);
5784 /* XXX SDMA RLC - todo */
5786 cik_srbm_select(rdev, 0, 0, 0, 0);
5787 spin_unlock(&rdev->srbm_mutex);
5789 cik_pcie_gart_tlb_flush(rdev);
5790 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
5791 (unsigned)(rdev->mc.gtt_size >> 20),
5792 (unsigned long long)rdev->gart.table_addr);
5793 rdev->gart.ready = true;
5798 * cik_pcie_gart_disable - gart disable
5800 * @rdev: radeon_device pointer
5802 * This disables all VM page table (CIK).
5804 static void cik_pcie_gart_disable(struct radeon_device *rdev)
5808 for (i = 1; i < 16; ++i) {
5811 reg = VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2);
5813 reg = VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2);
5814 rdev->vm_manager.saved_table_addr[i] = RREG32(reg);
5817 /* Disable all tables */
5818 WREG32(VM_CONTEXT0_CNTL, 0);
5819 WREG32(VM_CONTEXT1_CNTL, 0);
5820 /* Setup TLB control */
5821 WREG32(MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE_NOT_IN_SYS |
5822 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
5823 /* Setup L2 cache */
5825 ENABLE_L2_FRAGMENT_PROCESSING |
5826 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
5827 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
5828 EFFECTIVE_L2_QUEUE_SIZE(7) |
5829 CONTEXT1_IDENTITY_ACCESS_MODE(1));
5830 WREG32(VM_L2_CNTL2, 0);
5831 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
5832 L2_CACHE_BIGK_FRAGMENT_SIZE(6));
5833 radeon_gart_table_vram_unpin(rdev);
5837 * cik_pcie_gart_fini - vm fini callback
5839 * @rdev: radeon_device pointer
5841 * Tears down the driver GART/VM setup (CIK).
5843 static void cik_pcie_gart_fini(struct radeon_device *rdev)
5845 cik_pcie_gart_disable(rdev);
5846 radeon_gart_table_vram_free(rdev);
5847 radeon_gart_fini(rdev);
5852 * cik_ib_parse - vm ib_parse callback
5854 * @rdev: radeon_device pointer
5855 * @ib: indirect buffer pointer
5857 * CIK uses hw IB checking so this is a nop (CIK).
5859 int cik_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
5866 * VMID 0 is the physical GPU addresses as used by the kernel.
5867 * VMIDs 1-15 are used for userspace clients and are handled
5868 * by the radeon vm/hsa code.
5871 * cik_vm_init - cik vm init callback
5873 * @rdev: radeon_device pointer
5875 * Inits cik specific vm parameters (number of VMs, base of vram for
5876 * VMIDs 1-15) (CIK).
5877 * Returns 0 for success.
5879 int cik_vm_init(struct radeon_device *rdev)
5882 rdev->vm_manager.nvm = 16;
5883 /* base offset of vram pages */
5884 if (rdev->flags & RADEON_IS_IGP) {
5885 u64 tmp = RREG32(MC_VM_FB_OFFSET);
5887 rdev->vm_manager.vram_base_offset = tmp;
5889 rdev->vm_manager.vram_base_offset = 0;
5895 * cik_vm_fini - cik vm fini callback
5897 * @rdev: radeon_device pointer
5899 * Tear down any asic specific VM setup (CIK).
5901 void cik_vm_fini(struct radeon_device *rdev)
5906 * cik_vm_decode_fault - print human readable fault info
5908 * @rdev: radeon_device pointer
5909 * @status: VM_CONTEXT1_PROTECTION_FAULT_STATUS register value
5910 * @addr: VM_CONTEXT1_PROTECTION_FAULT_ADDR register value
5912 * Print human readable fault information (CIK).
5914 static void cik_vm_decode_fault(struct radeon_device *rdev,
5915 u32 status, u32 addr, u32 mc_client)
5918 u32 vmid = (status & FAULT_VMID_MASK) >> FAULT_VMID_SHIFT;
5919 u32 protections = (status & PROTECTIONS_MASK) >> PROTECTIONS_SHIFT;
5920 char block[5] = { mc_client >> 24, (mc_client >> 16) & 0xff,
5921 (mc_client >> 8) & 0xff, mc_client & 0xff, 0 };
5923 if (rdev->family == CHIP_HAWAII)
5924 mc_id = (status & HAWAII_MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
5926 mc_id = (status & MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
5928 printk("VM fault (0x%02x, vmid %d) at page %u, %s from '%s' (0x%08x) (%d)\n",
5929 protections, vmid, addr,
5930 (status & MEMORY_CLIENT_RW_MASK) ? "write" : "read",
5931 block, mc_client, mc_id);
5935 * cik_vm_flush - cik vm flush using the CP
5937 * @rdev: radeon_device pointer
5939 * Update the page table base and flush the VM TLB
5940 * using the CP (CIK).
5942 void cik_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
5944 struct radeon_ring *ring = &rdev->ring[ridx];
5945 int usepfp = (ridx == RADEON_RING_TYPE_GFX_INDEX);
5950 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5951 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
5952 WRITE_DATA_DST_SEL(0)));
5954 radeon_ring_write(ring,
5955 (VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2);
5957 radeon_ring_write(ring,
5958 (VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm->id - 8) << 2)) >> 2);
5960 radeon_ring_write(ring, 0);
5961 radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
5963 /* update SH_MEM_* regs */
5964 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5965 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
5966 WRITE_DATA_DST_SEL(0)));
5967 radeon_ring_write(ring, SRBM_GFX_CNTL >> 2);
5968 radeon_ring_write(ring, 0);
5969 radeon_ring_write(ring, VMID(vm->id));
5971 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 6));
5972 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
5973 WRITE_DATA_DST_SEL(0)));
5974 radeon_ring_write(ring, SH_MEM_BASES >> 2);
5975 radeon_ring_write(ring, 0);
5977 radeon_ring_write(ring, 0); /* SH_MEM_BASES */
5978 radeon_ring_write(ring, 0); /* SH_MEM_CONFIG */
5979 radeon_ring_write(ring, 1); /* SH_MEM_APE1_BASE */
5980 radeon_ring_write(ring, 0); /* SH_MEM_APE1_LIMIT */
5982 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5983 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
5984 WRITE_DATA_DST_SEL(0)));
5985 radeon_ring_write(ring, SRBM_GFX_CNTL >> 2);
5986 radeon_ring_write(ring, 0);
5987 radeon_ring_write(ring, VMID(0));
5990 cik_hdp_flush_cp_ring_emit(rdev, ridx);
5992 /* bits 0-15 are the VM contexts0-15 */
5993 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5994 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
5995 WRITE_DATA_DST_SEL(0)));
5996 radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
5997 radeon_ring_write(ring, 0);
5998 radeon_ring_write(ring, 1 << vm->id);
6000 /* compute doesn't have PFP */
6002 /* sync PFP to ME, otherwise we might get invalid PFP reads */
6003 radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
6004 radeon_ring_write(ring, 0x0);
6010 * The RLC is a multi-purpose microengine that handles a
6011 * variety of functions, the most important of which is
6012 * the interrupt controller.
6014 static void cik_enable_gui_idle_interrupt(struct radeon_device *rdev,
6017 u32 tmp = RREG32(CP_INT_CNTL_RING0);
6020 tmp |= (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
6022 tmp &= ~(CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
6023 WREG32(CP_INT_CNTL_RING0, tmp);
6026 static void cik_enable_lbpw(struct radeon_device *rdev, bool enable)
6030 tmp = RREG32(RLC_LB_CNTL);
6032 tmp |= LOAD_BALANCE_ENABLE;
6034 tmp &= ~LOAD_BALANCE_ENABLE;
6035 WREG32(RLC_LB_CNTL, tmp);
6038 static void cik_wait_for_rlc_serdes(struct radeon_device *rdev)
6043 for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
6044 for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
6045 cik_select_se_sh(rdev, i, j);
6046 for (k = 0; k < rdev->usec_timeout; k++) {
6047 if (RREG32(RLC_SERDES_CU_MASTER_BUSY) == 0)
6053 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
6055 mask = SE_MASTER_BUSY_MASK | GC_MASTER_BUSY | TC0_MASTER_BUSY | TC1_MASTER_BUSY;
6056 for (k = 0; k < rdev->usec_timeout; k++) {
6057 if ((RREG32(RLC_SERDES_NONCU_MASTER_BUSY) & mask) == 0)
6063 static void cik_update_rlc(struct radeon_device *rdev, u32 rlc)
6067 tmp = RREG32(RLC_CNTL);
6069 WREG32(RLC_CNTL, rlc);
6072 static u32 cik_halt_rlc(struct radeon_device *rdev)
6076 orig = data = RREG32(RLC_CNTL);
6078 if (data & RLC_ENABLE) {
6081 data &= ~RLC_ENABLE;
6082 WREG32(RLC_CNTL, data);
6084 for (i = 0; i < rdev->usec_timeout; i++) {
6085 if ((RREG32(RLC_GPM_STAT) & RLC_GPM_BUSY) == 0)
6090 cik_wait_for_rlc_serdes(rdev);
6096 void cik_enter_rlc_safe_mode(struct radeon_device *rdev)
6100 tmp = REQ | MESSAGE(MSG_ENTER_RLC_SAFE_MODE);
6101 WREG32(RLC_GPR_REG2, tmp);
6103 mask = GFX_POWER_STATUS | GFX_CLOCK_STATUS;
6104 for (i = 0; i < rdev->usec_timeout; i++) {
6105 if ((RREG32(RLC_GPM_STAT) & mask) == mask)
6110 for (i = 0; i < rdev->usec_timeout; i++) {
6111 if ((RREG32(RLC_GPR_REG2) & REQ) == 0)
6117 void cik_exit_rlc_safe_mode(struct radeon_device *rdev)
6121 tmp = REQ | MESSAGE(MSG_EXIT_RLC_SAFE_MODE);
6122 WREG32(RLC_GPR_REG2, tmp);
6126 * cik_rlc_stop - stop the RLC ME
6128 * @rdev: radeon_device pointer
6130 * Halt the RLC ME (MicroEngine) (CIK).
6132 static void cik_rlc_stop(struct radeon_device *rdev)
6134 WREG32(RLC_CNTL, 0);
6136 cik_enable_gui_idle_interrupt(rdev, false);
6138 cik_wait_for_rlc_serdes(rdev);
6142 * cik_rlc_start - start the RLC ME
6144 * @rdev: radeon_device pointer
6146 * Unhalt the RLC ME (MicroEngine) (CIK).
6148 static void cik_rlc_start(struct radeon_device *rdev)
6150 WREG32(RLC_CNTL, RLC_ENABLE);
6152 cik_enable_gui_idle_interrupt(rdev, true);
6158 * cik_rlc_resume - setup the RLC hw
6160 * @rdev: radeon_device pointer
6162 * Initialize the RLC registers, load the ucode,
6163 * and start the RLC (CIK).
6164 * Returns 0 for success, -EINVAL if the ucode is not available.
6166 static int cik_rlc_resume(struct radeon_device *rdev)
6176 tmp = RREG32(RLC_CGCG_CGLS_CTRL) & 0xfffffffc;
6177 WREG32(RLC_CGCG_CGLS_CTRL, tmp);
6185 WREG32(RLC_LB_CNTR_INIT, 0);
6186 WREG32(RLC_LB_CNTR_MAX, 0x00008000);
6188 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
6189 WREG32(RLC_LB_INIT_CU_MASK, 0xffffffff);
6190 WREG32(RLC_LB_PARAMS, 0x00600408);
6191 WREG32(RLC_LB_CNTL, 0x80000004);
6193 WREG32(RLC_MC_CNTL, 0);
6194 WREG32(RLC_UCODE_CNTL, 0);
6197 const struct rlc_firmware_header_v1_0 *hdr =
6198 (const struct rlc_firmware_header_v1_0 *)rdev->rlc_fw->data;
6199 const __le32 *fw_data = (const __le32 *)
6200 ((const char *)rdev->rlc_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6202 radeon_ucode_print_rlc_hdr(&hdr->header);
6204 size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
6205 WREG32(RLC_GPM_UCODE_ADDR, 0);
6206 for (i = 0; i < size; i++)
6207 WREG32(RLC_GPM_UCODE_DATA, le32_to_cpup(fw_data++));
6208 WREG32(RLC_GPM_UCODE_ADDR, le32_to_cpu(hdr->header.ucode_version));
6210 const __be32 *fw_data;
6212 switch (rdev->family) {
6216 size = BONAIRE_RLC_UCODE_SIZE;
6219 size = KV_RLC_UCODE_SIZE;
6222 size = KB_RLC_UCODE_SIZE;
6225 size = ML_RLC_UCODE_SIZE;
6229 fw_data = (const __be32 *)rdev->rlc_fw->data;
6230 WREG32(RLC_GPM_UCODE_ADDR, 0);
6231 for (i = 0; i < size; i++)
6232 WREG32(RLC_GPM_UCODE_DATA, be32_to_cpup(fw_data++));
6233 WREG32(RLC_GPM_UCODE_ADDR, 0);
6236 /* XXX - find out what chips support lbpw */
6237 cik_enable_lbpw(rdev, false);
6239 if (rdev->family == CHIP_BONAIRE)
6240 WREG32(RLC_DRIVER_DMA_STATUS, 0);
6242 cik_rlc_start(rdev);
6247 static void cik_enable_cgcg(struct radeon_device *rdev, bool enable)
6249 u32 data, orig, tmp, tmp2;
6251 orig = data = RREG32(RLC_CGCG_CGLS_CTRL);
6253 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGCG)) {
6254 cik_enable_gui_idle_interrupt(rdev, true);
6256 tmp = cik_halt_rlc(rdev);
6258 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
6259 WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
6260 WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
6261 tmp2 = BPM_ADDR_MASK | CGCG_OVERRIDE_0 | CGLS_ENABLE;
6262 WREG32(RLC_SERDES_WR_CTRL, tmp2);
6264 cik_update_rlc(rdev, tmp);
6266 data |= CGCG_EN | CGLS_EN;
6268 cik_enable_gui_idle_interrupt(rdev, false);
6270 RREG32(CB_CGTT_SCLK_CTRL);
6271 RREG32(CB_CGTT_SCLK_CTRL);
6272 RREG32(CB_CGTT_SCLK_CTRL);
6273 RREG32(CB_CGTT_SCLK_CTRL);
6275 data &= ~(CGCG_EN | CGLS_EN);
6279 WREG32(RLC_CGCG_CGLS_CTRL, data);
6283 static void cik_enable_mgcg(struct radeon_device *rdev, bool enable)
6285 u32 data, orig, tmp = 0;
6287 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGCG)) {
6288 if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGLS) {
6289 if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CP_LS) {
6290 orig = data = RREG32(CP_MEM_SLP_CNTL);
6291 data |= CP_MEM_LS_EN;
6293 WREG32(CP_MEM_SLP_CNTL, data);
6297 orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
6300 WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
6302 tmp = cik_halt_rlc(rdev);
6304 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
6305 WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
6306 WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
6307 data = BPM_ADDR_MASK | MGCG_OVERRIDE_0;
6308 WREG32(RLC_SERDES_WR_CTRL, data);
6310 cik_update_rlc(rdev, tmp);
6312 if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGTS) {
6313 orig = data = RREG32(CGTS_SM_CTRL_REG);
6314 data &= ~SM_MODE_MASK;
6315 data |= SM_MODE(0x2);
6316 data |= SM_MODE_ENABLE;
6317 data &= ~CGTS_OVERRIDE;
6318 if ((rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGLS) &&
6319 (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGTS_LS))
6320 data &= ~CGTS_LS_OVERRIDE;
6321 data &= ~ON_MONITOR_ADD_MASK;
6322 data |= ON_MONITOR_ADD_EN;
6323 data |= ON_MONITOR_ADD(0x96);
6325 WREG32(CGTS_SM_CTRL_REG, data);
6328 orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
6331 WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
6333 data = RREG32(RLC_MEM_SLP_CNTL);
6334 if (data & RLC_MEM_LS_EN) {
6335 data &= ~RLC_MEM_LS_EN;
6336 WREG32(RLC_MEM_SLP_CNTL, data);
6339 data = RREG32(CP_MEM_SLP_CNTL);
6340 if (data & CP_MEM_LS_EN) {
6341 data &= ~CP_MEM_LS_EN;
6342 WREG32(CP_MEM_SLP_CNTL, data);
6345 orig = data = RREG32(CGTS_SM_CTRL_REG);
6346 data |= CGTS_OVERRIDE | CGTS_LS_OVERRIDE;
6348 WREG32(CGTS_SM_CTRL_REG, data);
6350 tmp = cik_halt_rlc(rdev);
6352 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
6353 WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
6354 WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
6355 data = BPM_ADDR_MASK | MGCG_OVERRIDE_1;
6356 WREG32(RLC_SERDES_WR_CTRL, data);
6358 cik_update_rlc(rdev, tmp);
6362 static const u32 mc_cg_registers[] =
6375 static void cik_enable_mc_ls(struct radeon_device *rdev,
6381 for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
6382 orig = data = RREG32(mc_cg_registers[i]);
6383 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_LS))
6384 data |= MC_LS_ENABLE;
6386 data &= ~MC_LS_ENABLE;
6388 WREG32(mc_cg_registers[i], data);
6392 static void cik_enable_mc_mgcg(struct radeon_device *rdev,
6398 for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
6399 orig = data = RREG32(mc_cg_registers[i]);
6400 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_MGCG))
6401 data |= MC_CG_ENABLE;
6403 data &= ~MC_CG_ENABLE;
6405 WREG32(mc_cg_registers[i], data);
6409 static void cik_enable_sdma_mgcg(struct radeon_device *rdev,
6414 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_MGCG)) {
6415 WREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET, 0x00000100);
6416 WREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET, 0x00000100);
6418 orig = data = RREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET);
6421 WREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET, data);
6423 orig = data = RREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET);
6426 WREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET, data);
6430 static void cik_enable_sdma_mgls(struct radeon_device *rdev,
6435 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_LS)) {
6436 orig = data = RREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET);
6439 WREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET, data);
6441 orig = data = RREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET);
6444 WREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET, data);
6446 orig = data = RREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET);
6449 WREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET, data);
6451 orig = data = RREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET);
6454 WREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET, data);
6458 static void cik_enable_uvd_mgcg(struct radeon_device *rdev,
6463 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_UVD_MGCG)) {
6464 data = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
6466 WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, data);
6468 orig = data = RREG32(UVD_CGC_CTRL);
6471 WREG32(UVD_CGC_CTRL, data);
6473 data = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
6475 WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, data);
6477 orig = data = RREG32(UVD_CGC_CTRL);
6480 WREG32(UVD_CGC_CTRL, data);
6484 static void cik_enable_bif_mgls(struct radeon_device *rdev,
6489 orig = data = RREG32_PCIE_PORT(PCIE_CNTL2);
6491 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_BIF_LS))
6492 data |= SLV_MEM_LS_EN | MST_MEM_LS_EN |
6493 REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN;
6495 data &= ~(SLV_MEM_LS_EN | MST_MEM_LS_EN |
6496 REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN);
6499 WREG32_PCIE_PORT(PCIE_CNTL2, data);
6502 static void cik_enable_hdp_mgcg(struct radeon_device *rdev,
6507 orig = data = RREG32(HDP_HOST_PATH_CNTL);
6509 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_MGCG))
6510 data &= ~CLOCK_GATING_DIS;
6512 data |= CLOCK_GATING_DIS;
6515 WREG32(HDP_HOST_PATH_CNTL, data);
6518 static void cik_enable_hdp_ls(struct radeon_device *rdev,
6523 orig = data = RREG32(HDP_MEM_POWER_LS);
6525 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_LS))
6526 data |= HDP_LS_ENABLE;
6528 data &= ~HDP_LS_ENABLE;
6531 WREG32(HDP_MEM_POWER_LS, data);
6534 void cik_update_cg(struct radeon_device *rdev,
6535 u32 block, bool enable)
6538 if (block & RADEON_CG_BLOCK_GFX) {
6539 cik_enable_gui_idle_interrupt(rdev, false);
6540 /* order matters! */
6542 cik_enable_mgcg(rdev, true);
6543 cik_enable_cgcg(rdev, true);
6545 cik_enable_cgcg(rdev, false);
6546 cik_enable_mgcg(rdev, false);
6548 cik_enable_gui_idle_interrupt(rdev, true);
6551 if (block & RADEON_CG_BLOCK_MC) {
6552 if (!(rdev->flags & RADEON_IS_IGP)) {
6553 cik_enable_mc_mgcg(rdev, enable);
6554 cik_enable_mc_ls(rdev, enable);
6558 if (block & RADEON_CG_BLOCK_SDMA) {
6559 cik_enable_sdma_mgcg(rdev, enable);
6560 cik_enable_sdma_mgls(rdev, enable);
6563 if (block & RADEON_CG_BLOCK_BIF) {
6564 cik_enable_bif_mgls(rdev, enable);
6567 if (block & RADEON_CG_BLOCK_UVD) {
6569 cik_enable_uvd_mgcg(rdev, enable);
6572 if (block & RADEON_CG_BLOCK_HDP) {
6573 cik_enable_hdp_mgcg(rdev, enable);
6574 cik_enable_hdp_ls(rdev, enable);
6577 if (block & RADEON_CG_BLOCK_VCE) {
6578 vce_v2_0_enable_mgcg(rdev, enable);
6582 static void cik_init_cg(struct radeon_device *rdev)
6585 cik_update_cg(rdev, RADEON_CG_BLOCK_GFX, true);
6588 si_init_uvd_internal_cg(rdev);
6590 cik_update_cg(rdev, (RADEON_CG_BLOCK_MC |
6591 RADEON_CG_BLOCK_SDMA |
6592 RADEON_CG_BLOCK_BIF |
6593 RADEON_CG_BLOCK_UVD |
6594 RADEON_CG_BLOCK_HDP), true);
6597 static void cik_fini_cg(struct radeon_device *rdev)
6599 cik_update_cg(rdev, (RADEON_CG_BLOCK_MC |
6600 RADEON_CG_BLOCK_SDMA |
6601 RADEON_CG_BLOCK_BIF |
6602 RADEON_CG_BLOCK_UVD |
6603 RADEON_CG_BLOCK_HDP), false);
6605 cik_update_cg(rdev, RADEON_CG_BLOCK_GFX, false);
6608 static void cik_enable_sck_slowdown_on_pu(struct radeon_device *rdev,
6613 orig = data = RREG32(RLC_PG_CNTL);
6614 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_RLC_SMU_HS))
6615 data |= SMU_CLK_SLOWDOWN_ON_PU_ENABLE;
6617 data &= ~SMU_CLK_SLOWDOWN_ON_PU_ENABLE;
6619 WREG32(RLC_PG_CNTL, data);
6622 static void cik_enable_sck_slowdown_on_pd(struct radeon_device *rdev,
6627 orig = data = RREG32(RLC_PG_CNTL);
6628 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_RLC_SMU_HS))
6629 data |= SMU_CLK_SLOWDOWN_ON_PD_ENABLE;
6631 data &= ~SMU_CLK_SLOWDOWN_ON_PD_ENABLE;
6633 WREG32(RLC_PG_CNTL, data);
6636 static void cik_enable_cp_pg(struct radeon_device *rdev, bool enable)
6640 orig = data = RREG32(RLC_PG_CNTL);
6641 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_CP))
6642 data &= ~DISABLE_CP_PG;
6644 data |= DISABLE_CP_PG;
6646 WREG32(RLC_PG_CNTL, data);
6649 static void cik_enable_gds_pg(struct radeon_device *rdev, bool enable)
6653 orig = data = RREG32(RLC_PG_CNTL);
6654 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GDS))
6655 data &= ~DISABLE_GDS_PG;
6657 data |= DISABLE_GDS_PG;
6659 WREG32(RLC_PG_CNTL, data);
6662 #define CP_ME_TABLE_SIZE 96
6663 #define CP_ME_TABLE_OFFSET 2048
6664 #define CP_MEC_TABLE_OFFSET 4096
6666 void cik_init_cp_pg_table(struct radeon_device *rdev)
6668 volatile u32 *dst_ptr;
6669 int me, i, max_me = 4;
6671 u32 table_offset, table_size;
6673 if (rdev->family == CHIP_KAVERI)
6676 if (rdev->rlc.cp_table_ptr == NULL)
6679 /* write the cp table buffer */
6680 dst_ptr = rdev->rlc.cp_table_ptr;
6681 for (me = 0; me < max_me; me++) {
6683 const __le32 *fw_data;
6684 const struct gfx_firmware_header_v1_0 *hdr;
6687 hdr = (const struct gfx_firmware_header_v1_0 *)rdev->ce_fw->data;
6688 fw_data = (const __le32 *)
6689 ((const char *)rdev->ce_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6690 table_offset = le32_to_cpu(hdr->jt_offset);
6691 table_size = le32_to_cpu(hdr->jt_size);
6692 } else if (me == 1) {
6693 hdr = (const struct gfx_firmware_header_v1_0 *)rdev->pfp_fw->data;
6694 fw_data = (const __le32 *)
6695 ((const char *)rdev->pfp_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6696 table_offset = le32_to_cpu(hdr->jt_offset);
6697 table_size = le32_to_cpu(hdr->jt_size);
6698 } else if (me == 2) {
6699 hdr = (const struct gfx_firmware_header_v1_0 *)rdev->me_fw->data;
6700 fw_data = (const __le32 *)
6701 ((const char *)rdev->me_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6702 table_offset = le32_to_cpu(hdr->jt_offset);
6703 table_size = le32_to_cpu(hdr->jt_size);
6704 } else if (me == 3) {
6705 hdr = (const struct gfx_firmware_header_v1_0 *)rdev->mec_fw->data;
6706 fw_data = (const __le32 *)
6707 ((const char *)rdev->mec_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6708 table_offset = le32_to_cpu(hdr->jt_offset);
6709 table_size = le32_to_cpu(hdr->jt_size);
6711 hdr = (const struct gfx_firmware_header_v1_0 *)rdev->mec2_fw->data;
6712 fw_data = (const __le32 *)
6713 ((const char *)rdev->mec2_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6714 table_offset = le32_to_cpu(hdr->jt_offset);
6715 table_size = le32_to_cpu(hdr->jt_size);
6718 for (i = 0; i < table_size; i ++) {
6719 dst_ptr[bo_offset + i] =
6720 cpu_to_le32(le32_to_cpu(fw_data[table_offset + i]));
6722 bo_offset += table_size;
6724 const __be32 *fw_data;
6725 table_size = CP_ME_TABLE_SIZE;
6728 fw_data = (const __be32 *)rdev->ce_fw->data;
6729 table_offset = CP_ME_TABLE_OFFSET;
6730 } else if (me == 1) {
6731 fw_data = (const __be32 *)rdev->pfp_fw->data;
6732 table_offset = CP_ME_TABLE_OFFSET;
6733 } else if (me == 2) {
6734 fw_data = (const __be32 *)rdev->me_fw->data;
6735 table_offset = CP_ME_TABLE_OFFSET;
6737 fw_data = (const __be32 *)rdev->mec_fw->data;
6738 table_offset = CP_MEC_TABLE_OFFSET;
6741 for (i = 0; i < table_size; i ++) {
6742 dst_ptr[bo_offset + i] =
6743 cpu_to_le32(be32_to_cpu(fw_data[table_offset + i]));
6745 bo_offset += table_size;
6750 static void cik_enable_gfx_cgpg(struct radeon_device *rdev,
6755 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG)) {
6756 orig = data = RREG32(RLC_PG_CNTL);
6757 data |= GFX_PG_ENABLE;
6759 WREG32(RLC_PG_CNTL, data);
6761 orig = data = RREG32(RLC_AUTO_PG_CTRL);
6764 WREG32(RLC_AUTO_PG_CTRL, data);
6766 orig = data = RREG32(RLC_PG_CNTL);
6767 data &= ~GFX_PG_ENABLE;
6769 WREG32(RLC_PG_CNTL, data);
6771 orig = data = RREG32(RLC_AUTO_PG_CTRL);
6772 data &= ~AUTO_PG_EN;
6774 WREG32(RLC_AUTO_PG_CTRL, data);
6776 data = RREG32(DB_RENDER_CONTROL);
6780 static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh)
6782 u32 mask = 0, tmp, tmp1;
6785 cik_select_se_sh(rdev, se, sh);
6786 tmp = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
6787 tmp1 = RREG32(GC_USER_SHADER_ARRAY_CONFIG);
6788 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
6795 for (i = 0; i < rdev->config.cik.max_cu_per_sh; i ++) {
6800 return (~tmp) & mask;
6803 static void cik_init_ao_cu_mask(struct radeon_device *rdev)
6805 u32 i, j, k, active_cu_number = 0;
6806 u32 mask, counter, cu_bitmap;
6809 for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
6810 for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
6814 for (k = 0; k < rdev->config.cik.max_cu_per_sh; k ++) {
6815 if (cik_get_cu_active_bitmap(rdev, i, j) & mask) {
6823 active_cu_number += counter;
6824 tmp |= (cu_bitmap << (i * 16 + j * 8));
6828 WREG32(RLC_PG_AO_CU_MASK, tmp);
6830 tmp = RREG32(RLC_MAX_PG_CU);
6831 tmp &= ~MAX_PU_CU_MASK;
6832 tmp |= MAX_PU_CU(active_cu_number);
6833 WREG32(RLC_MAX_PG_CU, tmp);
6836 static void cik_enable_gfx_static_mgpg(struct radeon_device *rdev,
6841 orig = data = RREG32(RLC_PG_CNTL);
6842 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_SMG))
6843 data |= STATIC_PER_CU_PG_ENABLE;
6845 data &= ~STATIC_PER_CU_PG_ENABLE;
6847 WREG32(RLC_PG_CNTL, data);
6850 static void cik_enable_gfx_dynamic_mgpg(struct radeon_device *rdev,
6855 orig = data = RREG32(RLC_PG_CNTL);
6856 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_DMG))
6857 data |= DYN_PER_CU_PG_ENABLE;
6859 data &= ~DYN_PER_CU_PG_ENABLE;
6861 WREG32(RLC_PG_CNTL, data);
6864 #define RLC_SAVE_AND_RESTORE_STARTING_OFFSET 0x90
6865 #define RLC_CLEAR_STATE_DESCRIPTOR_OFFSET 0x3D
6867 static void cik_init_gfx_cgpg(struct radeon_device *rdev)
6872 if (rdev->rlc.cs_data) {
6873 WREG32(RLC_GPM_SCRATCH_ADDR, RLC_CLEAR_STATE_DESCRIPTOR_OFFSET);
6874 WREG32(RLC_GPM_SCRATCH_DATA, upper_32_bits(rdev->rlc.clear_state_gpu_addr));
6875 WREG32(RLC_GPM_SCRATCH_DATA, lower_32_bits(rdev->rlc.clear_state_gpu_addr));
6876 WREG32(RLC_GPM_SCRATCH_DATA, rdev->rlc.clear_state_size);
6878 WREG32(RLC_GPM_SCRATCH_ADDR, RLC_CLEAR_STATE_DESCRIPTOR_OFFSET);
6879 for (i = 0; i < 3; i++)
6880 WREG32(RLC_GPM_SCRATCH_DATA, 0);
6882 if (rdev->rlc.reg_list) {
6883 WREG32(RLC_GPM_SCRATCH_ADDR, RLC_SAVE_AND_RESTORE_STARTING_OFFSET);
6884 for (i = 0; i < rdev->rlc.reg_list_size; i++)
6885 WREG32(RLC_GPM_SCRATCH_DATA, rdev->rlc.reg_list[i]);
6888 orig = data = RREG32(RLC_PG_CNTL);
6891 WREG32(RLC_PG_CNTL, data);
6893 WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
6894 WREG32(RLC_CP_TABLE_RESTORE, rdev->rlc.cp_table_gpu_addr >> 8);
6896 data = RREG32(CP_RB_WPTR_POLL_CNTL);
6897 data &= ~IDLE_POLL_COUNT_MASK;
6898 data |= IDLE_POLL_COUNT(0x60);
6899 WREG32(CP_RB_WPTR_POLL_CNTL, data);
6902 WREG32(RLC_PG_DELAY, data);
6904 data = RREG32(RLC_PG_DELAY_2);
6907 WREG32(RLC_PG_DELAY_2, data);
6909 data = RREG32(RLC_AUTO_PG_CTRL);
6910 data &= ~GRBM_REG_SGIT_MASK;
6911 data |= GRBM_REG_SGIT(0x700);
6912 WREG32(RLC_AUTO_PG_CTRL, data);
6916 static void cik_update_gfx_pg(struct radeon_device *rdev, bool enable)
6918 cik_enable_gfx_cgpg(rdev, enable);
6919 cik_enable_gfx_static_mgpg(rdev, enable);
6920 cik_enable_gfx_dynamic_mgpg(rdev, enable);
6923 u32 cik_get_csb_size(struct radeon_device *rdev)
6926 const struct cs_section_def *sect = NULL;
6927 const struct cs_extent_def *ext = NULL;
6929 if (rdev->rlc.cs_data == NULL)
6932 /* begin clear state */
6934 /* context control state */
6937 for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
6938 for (ext = sect->section; ext->extent != NULL; ++ext) {
6939 if (sect->id == SECT_CONTEXT)
6940 count += 2 + ext->reg_count;
6945 /* pa_sc_raster_config/pa_sc_raster_config1 */
6947 /* end clear state */
6955 void cik_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer)
6958 const struct cs_section_def *sect = NULL;
6959 const struct cs_extent_def *ext = NULL;
6961 if (rdev->rlc.cs_data == NULL)
6966 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
6967 buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
6969 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
6970 buffer[count++] = cpu_to_le32(0x80000000);
6971 buffer[count++] = cpu_to_le32(0x80000000);
6973 for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
6974 for (ext = sect->section; ext->extent != NULL; ++ext) {
6975 if (sect->id == SECT_CONTEXT) {
6977 cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
6978 buffer[count++] = cpu_to_le32(ext->reg_index - 0xa000);
6979 for (i = 0; i < ext->reg_count; i++)
6980 buffer[count++] = cpu_to_le32(ext->extent[i]);
6987 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 2));
6988 buffer[count++] = cpu_to_le32(PA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
6989 switch (rdev->family) {
6991 buffer[count++] = cpu_to_le32(0x16000012);
6992 buffer[count++] = cpu_to_le32(0x00000000);
6995 buffer[count++] = cpu_to_le32(0x00000000); /* XXX */
6996 buffer[count++] = cpu_to_le32(0x00000000);
7000 buffer[count++] = cpu_to_le32(0x00000000); /* XXX */
7001 buffer[count++] = cpu_to_le32(0x00000000);
7004 buffer[count++] = cpu_to_le32(0x3a00161a);
7005 buffer[count++] = cpu_to_le32(0x0000002e);
7008 buffer[count++] = cpu_to_le32(0x00000000);
7009 buffer[count++] = cpu_to_le32(0x00000000);
7013 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
7014 buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);
7016 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
7017 buffer[count++] = cpu_to_le32(0);
7020 static void cik_init_pg(struct radeon_device *rdev)
7022 if (rdev->pg_flags) {
7023 cik_enable_sck_slowdown_on_pu(rdev, true);
7024 cik_enable_sck_slowdown_on_pd(rdev, true);
7025 if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG) {
7026 cik_init_gfx_cgpg(rdev);
7027 cik_enable_cp_pg(rdev, true);
7028 cik_enable_gds_pg(rdev, true);
7030 cik_init_ao_cu_mask(rdev);
7031 cik_update_gfx_pg(rdev, true);
7035 static void cik_fini_pg(struct radeon_device *rdev)
7037 if (rdev->pg_flags) {
7038 cik_update_gfx_pg(rdev, false);
7039 if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG) {
7040 cik_enable_cp_pg(rdev, false);
7041 cik_enable_gds_pg(rdev, false);
7048 * Starting with r6xx, interrupts are handled via a ring buffer.
7049 * Ring buffers are areas of GPU accessible memory that the GPU
7050 * writes interrupt vectors into and the host reads vectors out of.
7051 * There is a rptr (read pointer) that determines where the
7052 * host is currently reading, and a wptr (write pointer)
7053 * which determines where the GPU has written. When the
7054 * pointers are equal, the ring is idle. When the GPU
7055 * writes vectors to the ring buffer, it increments the
7056 * wptr. When there is an interrupt, the host then starts
7057 * fetching commands and processing them until the pointers are
7058 * equal again at which point it updates the rptr.
7062 * cik_enable_interrupts - Enable the interrupt ring buffer
7064 * @rdev: radeon_device pointer
7066 * Enable the interrupt ring buffer (CIK).
7068 static void cik_enable_interrupts(struct radeon_device *rdev)
7070 u32 ih_cntl = RREG32(IH_CNTL);
7071 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
7073 ih_cntl |= ENABLE_INTR;
7074 ih_rb_cntl |= IH_RB_ENABLE;
7075 WREG32(IH_CNTL, ih_cntl);
7076 WREG32(IH_RB_CNTL, ih_rb_cntl);
7077 rdev->ih.enabled = true;
7081 * cik_disable_interrupts - Disable the interrupt ring buffer
7083 * @rdev: radeon_device pointer
7085 * Disable the interrupt ring buffer (CIK).
7087 static void cik_disable_interrupts(struct radeon_device *rdev)
7089 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
7090 u32 ih_cntl = RREG32(IH_CNTL);
7092 ih_rb_cntl &= ~IH_RB_ENABLE;
7093 ih_cntl &= ~ENABLE_INTR;
7094 WREG32(IH_RB_CNTL, ih_rb_cntl);
7095 WREG32(IH_CNTL, ih_cntl);
7096 /* set rptr, wptr to 0 */
7097 WREG32(IH_RB_RPTR, 0);
7098 WREG32(IH_RB_WPTR, 0);
7099 rdev->ih.enabled = false;
7104 * cik_disable_interrupt_state - Disable all interrupt sources
7106 * @rdev: radeon_device pointer
7108 * Clear all interrupt enable bits used by the driver (CIK).
7110 static void cik_disable_interrupt_state(struct radeon_device *rdev)
7115 tmp = RREG32(CP_INT_CNTL_RING0) &
7116 (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
7117 WREG32(CP_INT_CNTL_RING0, tmp);
7119 tmp = RREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
7120 WREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET, tmp);
7121 tmp = RREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
7122 WREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET, tmp);
7123 /* compute queues */
7124 WREG32(CP_ME1_PIPE0_INT_CNTL, 0);
7125 WREG32(CP_ME1_PIPE1_INT_CNTL, 0);
7126 WREG32(CP_ME1_PIPE2_INT_CNTL, 0);
7127 WREG32(CP_ME1_PIPE3_INT_CNTL, 0);
7128 WREG32(CP_ME2_PIPE0_INT_CNTL, 0);
7129 WREG32(CP_ME2_PIPE1_INT_CNTL, 0);
7130 WREG32(CP_ME2_PIPE2_INT_CNTL, 0);
7131 WREG32(CP_ME2_PIPE3_INT_CNTL, 0);
7133 WREG32(GRBM_INT_CNTL, 0);
7134 /* vline/vblank, etc. */
7135 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
7136 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
7137 if (rdev->num_crtc >= 4) {
7138 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
7139 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
7141 if (rdev->num_crtc >= 6) {
7142 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
7143 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
7146 if (rdev->num_crtc >= 2) {
7147 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
7148 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
7150 if (rdev->num_crtc >= 4) {
7151 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
7152 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
7154 if (rdev->num_crtc >= 6) {
7155 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
7156 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
7160 WREG32(DAC_AUTODETECT_INT_CONTROL, 0);
7162 /* digital hotplug */
7163 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
7164 WREG32(DC_HPD1_INT_CONTROL, tmp);
7165 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
7166 WREG32(DC_HPD2_INT_CONTROL, tmp);
7167 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
7168 WREG32(DC_HPD3_INT_CONTROL, tmp);
7169 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
7170 WREG32(DC_HPD4_INT_CONTROL, tmp);
7171 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
7172 WREG32(DC_HPD5_INT_CONTROL, tmp);
7173 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
7174 WREG32(DC_HPD6_INT_CONTROL, tmp);
7179 * cik_irq_init - init and enable the interrupt ring
7181 * @rdev: radeon_device pointer
7183 * Allocate a ring buffer for the interrupt controller,
7184 * enable the RLC, disable interrupts, enable the IH
7185 * ring buffer and enable it (CIK).
7186 * Called at device load and reume.
7187 * Returns 0 for success, errors for failure.
7189 static int cik_irq_init(struct radeon_device *rdev)
7193 u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
7196 ret = r600_ih_ring_alloc(rdev);
7201 cik_disable_interrupts(rdev);
7204 ret = cik_rlc_resume(rdev);
7206 r600_ih_ring_fini(rdev);
7210 /* setup interrupt control */
7211 /* XXX this should actually be a bus address, not an MC address. same on older asics */
7212 WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
7213 interrupt_cntl = RREG32(INTERRUPT_CNTL);
7214 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
7215 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
7217 interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
7218 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
7219 interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
7220 WREG32(INTERRUPT_CNTL, interrupt_cntl);
7222 WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
7223 rb_bufsz = order_base_2(rdev->ih.ring_size / 4);
7225 ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
7226 IH_WPTR_OVERFLOW_CLEAR |
7229 if (rdev->wb.enabled)
7230 ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
7232 /* set the writeback address whether it's enabled or not */
7233 WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
7234 WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
7236 WREG32(IH_RB_CNTL, ih_rb_cntl);
7238 /* set rptr, wptr to 0 */
7239 WREG32(IH_RB_RPTR, 0);
7240 WREG32(IH_RB_WPTR, 0);
7242 /* Default settings for IH_CNTL (disabled at first) */
7243 ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10) | MC_VMID(0);
7244 /* RPTR_REARM only works if msi's are enabled */
7245 if (rdev->msi_enabled)
7246 ih_cntl |= RPTR_REARM;
7247 WREG32(IH_CNTL, ih_cntl);
7249 /* force the active interrupt state to all disabled */
7250 cik_disable_interrupt_state(rdev);
7252 pci_enable_busmaster(rdev->pdev->dev);
7255 cik_enable_interrupts(rdev);
7261 * cik_irq_set - enable/disable interrupt sources
7263 * @rdev: radeon_device pointer
7265 * Enable interrupt sources on the GPU (vblanks, hpd,
7267 * Returns 0 for success, errors for failure.
7269 int cik_irq_set(struct radeon_device *rdev)
7272 u32 cp_m1p0, cp_m1p1, cp_m1p2, cp_m1p3;
7273 u32 cp_m2p0, cp_m2p1, cp_m2p2, cp_m2p3;
7274 u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
7275 u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;
7276 u32 grbm_int_cntl = 0;
7277 u32 dma_cntl, dma_cntl1;
7280 if (!rdev->irq.installed) {
7281 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
7284 /* don't enable anything if the ih is disabled */
7285 if (!rdev->ih.enabled) {
7286 cik_disable_interrupts(rdev);
7287 /* force the active interrupt state to all disabled */
7288 cik_disable_interrupt_state(rdev);
7292 cp_int_cntl = RREG32(CP_INT_CNTL_RING0) &
7293 (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
7294 cp_int_cntl |= PRIV_INSTR_INT_ENABLE | PRIV_REG_INT_ENABLE;
7296 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
7297 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
7298 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
7299 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
7300 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
7301 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
7303 dma_cntl = RREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
7304 dma_cntl1 = RREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
7306 cp_m1p0 = RREG32(CP_ME1_PIPE0_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
7307 cp_m1p1 = RREG32(CP_ME1_PIPE1_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
7308 cp_m1p2 = RREG32(CP_ME1_PIPE2_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
7309 cp_m1p3 = RREG32(CP_ME1_PIPE3_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
7310 cp_m2p0 = RREG32(CP_ME2_PIPE0_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
7311 cp_m2p1 = RREG32(CP_ME2_PIPE1_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
7312 cp_m2p2 = RREG32(CP_ME2_PIPE2_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
7313 cp_m2p3 = RREG32(CP_ME2_PIPE3_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
7315 if (rdev->flags & RADEON_IS_IGP)
7316 thermal_int = RREG32_SMC(CG_THERMAL_INT_CTRL) &
7317 ~(THERM_INTH_MASK | THERM_INTL_MASK);
7319 thermal_int = RREG32_SMC(CG_THERMAL_INT) &
7320 ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
7322 /* enable CP interrupts on all rings */
7323 if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
7324 DRM_DEBUG("cik_irq_set: sw int gfx\n");
7325 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
7327 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
7328 struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
7329 DRM_DEBUG("si_irq_set: sw int cp1\n");
7330 if (ring->me == 1) {
7331 switch (ring->pipe) {
7333 cp_m1p0 |= TIME_STAMP_INT_ENABLE;
7336 cp_m1p1 |= TIME_STAMP_INT_ENABLE;
7339 cp_m1p2 |= TIME_STAMP_INT_ENABLE;
7342 cp_m1p2 |= TIME_STAMP_INT_ENABLE;
7345 DRM_DEBUG("si_irq_set: sw int cp1 invalid pipe %d\n", ring->pipe);
7348 } else if (ring->me == 2) {
7349 switch (ring->pipe) {
7351 cp_m2p0 |= TIME_STAMP_INT_ENABLE;
7354 cp_m2p1 |= TIME_STAMP_INT_ENABLE;
7357 cp_m2p2 |= TIME_STAMP_INT_ENABLE;
7360 cp_m2p2 |= TIME_STAMP_INT_ENABLE;
7363 DRM_DEBUG("si_irq_set: sw int cp1 invalid pipe %d\n", ring->pipe);
7367 DRM_DEBUG("si_irq_set: sw int cp1 invalid me %d\n", ring->me);
7370 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
7371 struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
7372 DRM_DEBUG("si_irq_set: sw int cp2\n");
7373 if (ring->me == 1) {
7374 switch (ring->pipe) {
7376 cp_m1p0 |= TIME_STAMP_INT_ENABLE;
7379 cp_m1p1 |= TIME_STAMP_INT_ENABLE;
7382 cp_m1p2 |= TIME_STAMP_INT_ENABLE;
7385 cp_m1p2 |= TIME_STAMP_INT_ENABLE;
7388 DRM_DEBUG("si_irq_set: sw int cp2 invalid pipe %d\n", ring->pipe);
7391 } else if (ring->me == 2) {
7392 switch (ring->pipe) {
7394 cp_m2p0 |= TIME_STAMP_INT_ENABLE;
7397 cp_m2p1 |= TIME_STAMP_INT_ENABLE;
7400 cp_m2p2 |= TIME_STAMP_INT_ENABLE;
7403 cp_m2p2 |= TIME_STAMP_INT_ENABLE;
7406 DRM_DEBUG("si_irq_set: sw int cp2 invalid pipe %d\n", ring->pipe);
7410 DRM_DEBUG("si_irq_set: sw int cp2 invalid me %d\n", ring->me);
7414 if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
7415 DRM_DEBUG("cik_irq_set: sw int dma\n");
7416 dma_cntl |= TRAP_ENABLE;
7419 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
7420 DRM_DEBUG("cik_irq_set: sw int dma1\n");
7421 dma_cntl1 |= TRAP_ENABLE;
7424 if (rdev->irq.crtc_vblank_int[0] ||
7425 atomic_read(&rdev->irq.pflip[0])) {
7426 DRM_DEBUG("cik_irq_set: vblank 0\n");
7427 crtc1 |= VBLANK_INTERRUPT_MASK;
7429 if (rdev->irq.crtc_vblank_int[1] ||
7430 atomic_read(&rdev->irq.pflip[1])) {
7431 DRM_DEBUG("cik_irq_set: vblank 1\n");
7432 crtc2 |= VBLANK_INTERRUPT_MASK;
7434 if (rdev->irq.crtc_vblank_int[2] ||
7435 atomic_read(&rdev->irq.pflip[2])) {
7436 DRM_DEBUG("cik_irq_set: vblank 2\n");
7437 crtc3 |= VBLANK_INTERRUPT_MASK;
7439 if (rdev->irq.crtc_vblank_int[3] ||
7440 atomic_read(&rdev->irq.pflip[3])) {
7441 DRM_DEBUG("cik_irq_set: vblank 3\n");
7442 crtc4 |= VBLANK_INTERRUPT_MASK;
7444 if (rdev->irq.crtc_vblank_int[4] ||
7445 atomic_read(&rdev->irq.pflip[4])) {
7446 DRM_DEBUG("cik_irq_set: vblank 4\n");
7447 crtc5 |= VBLANK_INTERRUPT_MASK;
7449 if (rdev->irq.crtc_vblank_int[5] ||
7450 atomic_read(&rdev->irq.pflip[5])) {
7451 DRM_DEBUG("cik_irq_set: vblank 5\n");
7452 crtc6 |= VBLANK_INTERRUPT_MASK;
7454 if (rdev->irq.hpd[0]) {
7455 DRM_DEBUG("cik_irq_set: hpd 1\n");
7456 hpd1 |= DC_HPDx_INT_EN;
7458 if (rdev->irq.hpd[1]) {
7459 DRM_DEBUG("cik_irq_set: hpd 2\n");
7460 hpd2 |= DC_HPDx_INT_EN;
7462 if (rdev->irq.hpd[2]) {
7463 DRM_DEBUG("cik_irq_set: hpd 3\n");
7464 hpd3 |= DC_HPDx_INT_EN;
7466 if (rdev->irq.hpd[3]) {
7467 DRM_DEBUG("cik_irq_set: hpd 4\n");
7468 hpd4 |= DC_HPDx_INT_EN;
7470 if (rdev->irq.hpd[4]) {
7471 DRM_DEBUG("cik_irq_set: hpd 5\n");
7472 hpd5 |= DC_HPDx_INT_EN;
7474 if (rdev->irq.hpd[5]) {
7475 DRM_DEBUG("cik_irq_set: hpd 6\n");
7476 hpd6 |= DC_HPDx_INT_EN;
7479 if (rdev->irq.dpm_thermal) {
7480 DRM_DEBUG("dpm thermal\n");
7481 if (rdev->flags & RADEON_IS_IGP)
7482 thermal_int |= THERM_INTH_MASK | THERM_INTL_MASK;
7484 thermal_int |= THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW;
7487 WREG32(CP_INT_CNTL_RING0, cp_int_cntl);
7489 WREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET, dma_cntl);
7490 WREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET, dma_cntl1);
7492 WREG32(CP_ME1_PIPE0_INT_CNTL, cp_m1p0);
7493 WREG32(CP_ME1_PIPE1_INT_CNTL, cp_m1p1);
7494 WREG32(CP_ME1_PIPE2_INT_CNTL, cp_m1p2);
7495 WREG32(CP_ME1_PIPE3_INT_CNTL, cp_m1p3);
7496 WREG32(CP_ME2_PIPE0_INT_CNTL, cp_m2p0);
7497 WREG32(CP_ME2_PIPE1_INT_CNTL, cp_m2p1);
7498 WREG32(CP_ME2_PIPE2_INT_CNTL, cp_m2p2);
7499 WREG32(CP_ME2_PIPE3_INT_CNTL, cp_m2p3);
7501 WREG32(GRBM_INT_CNTL, grbm_int_cntl);
7503 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
7504 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
7505 if (rdev->num_crtc >= 4) {
7506 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
7507 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
7509 if (rdev->num_crtc >= 6) {
7510 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
7511 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
7514 if (rdev->num_crtc >= 2) {
7515 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET,
7516 GRPH_PFLIP_INT_MASK);
7517 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET,
7518 GRPH_PFLIP_INT_MASK);
7520 if (rdev->num_crtc >= 4) {
7521 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET,
7522 GRPH_PFLIP_INT_MASK);
7523 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET,
7524 GRPH_PFLIP_INT_MASK);
7526 if (rdev->num_crtc >= 6) {
7527 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET,
7528 GRPH_PFLIP_INT_MASK);
7529 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET,
7530 GRPH_PFLIP_INT_MASK);
7533 WREG32(DC_HPD1_INT_CONTROL, hpd1);
7534 WREG32(DC_HPD2_INT_CONTROL, hpd2);
7535 WREG32(DC_HPD3_INT_CONTROL, hpd3);
7536 WREG32(DC_HPD4_INT_CONTROL, hpd4);
7537 WREG32(DC_HPD5_INT_CONTROL, hpd5);
7538 WREG32(DC_HPD6_INT_CONTROL, hpd6);
7540 if (rdev->flags & RADEON_IS_IGP)
7541 WREG32_SMC(CG_THERMAL_INT_CTRL, thermal_int);
7543 WREG32_SMC(CG_THERMAL_INT, thermal_int);
7549 * cik_irq_ack - ack interrupt sources
7551 * @rdev: radeon_device pointer
7553 * Ack interrupt sources on the GPU (vblanks, hpd,
7554 * etc.) (CIK). Certain interrupts sources are sw
7555 * generated and do not require an explicit ack.
7557 static inline void cik_irq_ack(struct radeon_device *rdev)
7561 rdev->irq.stat_regs.cik.disp_int = RREG32(DISP_INTERRUPT_STATUS);
7562 rdev->irq.stat_regs.cik.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
7563 rdev->irq.stat_regs.cik.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
7564 rdev->irq.stat_regs.cik.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
7565 rdev->irq.stat_regs.cik.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
7566 rdev->irq.stat_regs.cik.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
7567 rdev->irq.stat_regs.cik.disp_int_cont6 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE6);
7569 rdev->irq.stat_regs.cik.d1grph_int = RREG32(GRPH_INT_STATUS +
7570 EVERGREEN_CRTC0_REGISTER_OFFSET);
7571 rdev->irq.stat_regs.cik.d2grph_int = RREG32(GRPH_INT_STATUS +
7572 EVERGREEN_CRTC1_REGISTER_OFFSET);
7573 if (rdev->num_crtc >= 4) {
7574 rdev->irq.stat_regs.cik.d3grph_int = RREG32(GRPH_INT_STATUS +
7575 EVERGREEN_CRTC2_REGISTER_OFFSET);
7576 rdev->irq.stat_regs.cik.d4grph_int = RREG32(GRPH_INT_STATUS +
7577 EVERGREEN_CRTC3_REGISTER_OFFSET);
7579 if (rdev->num_crtc >= 6) {
7580 rdev->irq.stat_regs.cik.d5grph_int = RREG32(GRPH_INT_STATUS +
7581 EVERGREEN_CRTC4_REGISTER_OFFSET);
7582 rdev->irq.stat_regs.cik.d6grph_int = RREG32(GRPH_INT_STATUS +
7583 EVERGREEN_CRTC5_REGISTER_OFFSET);
7586 if (rdev->irq.stat_regs.cik.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
7587 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET,
7588 GRPH_PFLIP_INT_CLEAR);
7589 if (rdev->irq.stat_regs.cik.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
7590 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET,
7591 GRPH_PFLIP_INT_CLEAR);
7592 if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VBLANK_INTERRUPT)
7593 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
7594 if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VLINE_INTERRUPT)
7595 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
7596 if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
7597 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
7598 if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VLINE_INTERRUPT)
7599 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
7601 if (rdev->num_crtc >= 4) {
7602 if (rdev->irq.stat_regs.cik.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
7603 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET,
7604 GRPH_PFLIP_INT_CLEAR);
7605 if (rdev->irq.stat_regs.cik.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
7606 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET,
7607 GRPH_PFLIP_INT_CLEAR);
7608 if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
7609 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
7610 if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
7611 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
7612 if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
7613 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
7614 if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
7615 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
7618 if (rdev->num_crtc >= 6) {
7619 if (rdev->irq.stat_regs.cik.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
7620 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET,
7621 GRPH_PFLIP_INT_CLEAR);
7622 if (rdev->irq.stat_regs.cik.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
7623 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET,
7624 GRPH_PFLIP_INT_CLEAR);
7625 if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
7626 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
7627 if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
7628 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
7629 if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
7630 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
7631 if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
7632 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
7635 if (rdev->irq.stat_regs.cik.disp_int & DC_HPD1_INTERRUPT) {
7636 tmp = RREG32(DC_HPD1_INT_CONTROL);
7637 tmp |= DC_HPDx_INT_ACK;
7638 WREG32(DC_HPD1_INT_CONTROL, tmp);
7640 if (rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_INTERRUPT) {
7641 tmp = RREG32(DC_HPD2_INT_CONTROL);
7642 tmp |= DC_HPDx_INT_ACK;
7643 WREG32(DC_HPD2_INT_CONTROL, tmp);
7645 if (rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_INTERRUPT) {
7646 tmp = RREG32(DC_HPD3_INT_CONTROL);
7647 tmp |= DC_HPDx_INT_ACK;
7648 WREG32(DC_HPD3_INT_CONTROL, tmp);
7650 if (rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_INTERRUPT) {
7651 tmp = RREG32(DC_HPD4_INT_CONTROL);
7652 tmp |= DC_HPDx_INT_ACK;
7653 WREG32(DC_HPD4_INT_CONTROL, tmp);
7655 if (rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_INTERRUPT) {
7656 tmp = RREG32(DC_HPD5_INT_CONTROL);
7657 tmp |= DC_HPDx_INT_ACK;
7658 WREG32(DC_HPD5_INT_CONTROL, tmp);
7660 if (rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_INTERRUPT) {
7661 tmp = RREG32(DC_HPD5_INT_CONTROL);
7662 tmp |= DC_HPDx_INT_ACK;
7663 WREG32(DC_HPD6_INT_CONTROL, tmp);
7668 * cik_irq_disable - disable interrupts
7670 * @rdev: radeon_device pointer
7672 * Disable interrupts on the hw (CIK).
7674 static void cik_irq_disable(struct radeon_device *rdev)
7676 cik_disable_interrupts(rdev);
7677 /* Wait and acknowledge irq */
7680 cik_disable_interrupt_state(rdev);
7684 * cik_irq_disable - disable interrupts for suspend
7686 * @rdev: radeon_device pointer
7688 * Disable interrupts and stop the RLC (CIK).
7691 static void cik_irq_suspend(struct radeon_device *rdev)
7693 cik_irq_disable(rdev);
7698 * cik_irq_fini - tear down interrupt support
7700 * @rdev: radeon_device pointer
7702 * Disable interrupts on the hw and free the IH ring
7704 * Used for driver unload.
7706 static void cik_irq_fini(struct radeon_device *rdev)
7708 cik_irq_suspend(rdev);
7709 r600_ih_ring_fini(rdev);
7713 * cik_get_ih_wptr - get the IH ring buffer wptr
7715 * @rdev: radeon_device pointer
7717 * Get the IH ring buffer wptr from either the register
7718 * or the writeback memory buffer (CIK). Also check for
7719 * ring buffer overflow and deal with it.
7720 * Used by cik_irq_process().
7721 * Returns the value of the wptr.
7723 static inline u32 cik_get_ih_wptr(struct radeon_device *rdev)
7727 if (rdev->wb.enabled)
7728 wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
7730 wptr = RREG32(IH_RB_WPTR);
7732 if (wptr & RB_OVERFLOW) {
7733 wptr &= ~RB_OVERFLOW;
7734 /* When a ring buffer overflow happen start parsing interrupt
7735 * from the last not overwritten vector (wptr + 16). Hopefully
7736 * this should allow us to catchup.
7738 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n",
7739 wptr, rdev->ih.rptr, (wptr + 16) & rdev->ih.ptr_mask);
7740 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
7741 tmp = RREG32(IH_RB_CNTL);
7742 tmp |= IH_WPTR_OVERFLOW_CLEAR;
7743 WREG32(IH_RB_CNTL, tmp);
7745 return (wptr & rdev->ih.ptr_mask);
7749 * Each IV ring entry is 128 bits:
7750 * [7:0] - interrupt source id
7752 * [59:32] - interrupt source data
7753 * [63:60] - reserved
7756 * ME_ID [1:0], PIPE_ID[1:0], QUEUE_ID[2:0]
7757 * QUEUE_ID - for compute, which of the 8 queues owned by the dispatcher
7758 * - for gfx, hw shader state (0=PS...5=LS, 6=CS)
7759 * ME_ID - 0 = gfx, 1 = first 4 CS pipes, 2 = second 4 CS pipes
7760 * PIPE_ID - ME0 0=3D
7761 * - ME1&2 compute dispatcher (4 pipes each)
7763 * INSTANCE_ID [1:0], QUEUE_ID[1:0]
7764 * INSTANCE_ID - 0 = sdma0, 1 = sdma1
7765 * QUEUE_ID - 0 = gfx, 1 = rlc0, 2 = rlc1
7768 * [127:96] - reserved
7771 * cik_irq_process - interrupt handler
7773 * @rdev: radeon_device pointer
7775 * Interrupt hander (CIK). Walk the IH ring,
7776 * ack interrupts and schedule work to handle
7778 * Returns irq process return code.
7780 irqreturn_t cik_irq_process(struct radeon_device *rdev)
7782 struct radeon_ring *cp1_ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
7783 struct radeon_ring *cp2_ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
7786 u32 src_id, src_data, ring_id;
7787 u8 me_id, pipe_id, queue_id;
7789 bool queue_hotplug = false;
7790 bool queue_reset = false;
7791 u32 addr, status, mc_client;
7792 bool queue_thermal = false;
7794 if (!rdev->ih.enabled || rdev->shutdown)
7797 wptr = cik_get_ih_wptr(rdev);
7800 /* is somebody else already processing irqs? */
7801 if (atomic_xchg(&rdev->ih.lock, 1))
7804 rptr = rdev->ih.rptr;
7805 DRM_DEBUG("cik_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
7807 /* Order reading of wptr vs. reading of IH ring data */
7810 /* display interrupts */
7813 while (rptr != wptr) {
7814 /* wptr/rptr are in bytes! */
7815 ring_index = rptr / 4;
7816 src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
7817 src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
7818 ring_id = le32_to_cpu(rdev->ih.ring[ring_index + 2]) & 0xff;
7821 case 1: /* D1 vblank/vline */
7823 case 0: /* D1 vblank */
7824 if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VBLANK_INTERRUPT) {
7825 if (rdev->irq.crtc_vblank_int[0]) {
7826 drm_handle_vblank(rdev->ddev, 0);
7827 rdev->pm.vblank_sync = true;
7828 wake_up(&rdev->irq.vblank_queue);
7830 if (atomic_read(&rdev->irq.pflip[0]))
7831 radeon_crtc_handle_vblank(rdev, 0);
7832 rdev->irq.stat_regs.cik.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
7833 DRM_DEBUG("IH: D1 vblank\n");
7836 case 1: /* D1 vline */
7837 if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VLINE_INTERRUPT) {
7838 rdev->irq.stat_regs.cik.disp_int &= ~LB_D1_VLINE_INTERRUPT;
7839 DRM_DEBUG("IH: D1 vline\n");
7843 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
7847 case 2: /* D2 vblank/vline */
7849 case 0: /* D2 vblank */
7850 if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
7851 if (rdev->irq.crtc_vblank_int[1]) {
7852 drm_handle_vblank(rdev->ddev, 1);
7853 rdev->pm.vblank_sync = true;
7854 wake_up(&rdev->irq.vblank_queue);
7856 if (atomic_read(&rdev->irq.pflip[1]))
7857 radeon_crtc_handle_vblank(rdev, 1);
7858 rdev->irq.stat_regs.cik.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
7859 DRM_DEBUG("IH: D2 vblank\n");
7862 case 1: /* D2 vline */
7863 if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VLINE_INTERRUPT) {
7864 rdev->irq.stat_regs.cik.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
7865 DRM_DEBUG("IH: D2 vline\n");
7869 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
7873 case 3: /* D3 vblank/vline */
7875 case 0: /* D3 vblank */
7876 if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
7877 if (rdev->irq.crtc_vblank_int[2]) {
7878 drm_handle_vblank(rdev->ddev, 2);
7879 rdev->pm.vblank_sync = true;
7880 wake_up(&rdev->irq.vblank_queue);
7882 if (atomic_read(&rdev->irq.pflip[2]))
7883 radeon_crtc_handle_vblank(rdev, 2);
7884 rdev->irq.stat_regs.cik.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
7885 DRM_DEBUG("IH: D3 vblank\n");
7888 case 1: /* D3 vline */
7889 if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) {
7890 rdev->irq.stat_regs.cik.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
7891 DRM_DEBUG("IH: D3 vline\n");
7895 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
7899 case 4: /* D4 vblank/vline */
7901 case 0: /* D4 vblank */
7902 if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
7903 if (rdev->irq.crtc_vblank_int[3]) {
7904 drm_handle_vblank(rdev->ddev, 3);
7905 rdev->pm.vblank_sync = true;
7906 wake_up(&rdev->irq.vblank_queue);
7908 if (atomic_read(&rdev->irq.pflip[3]))
7909 radeon_crtc_handle_vblank(rdev, 3);
7910 rdev->irq.stat_regs.cik.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
7911 DRM_DEBUG("IH: D4 vblank\n");
7914 case 1: /* D4 vline */
7915 if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) {
7916 rdev->irq.stat_regs.cik.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
7917 DRM_DEBUG("IH: D4 vline\n");
7921 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
7925 case 5: /* D5 vblank/vline */
7927 case 0: /* D5 vblank */
7928 if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
7929 if (rdev->irq.crtc_vblank_int[4]) {
7930 drm_handle_vblank(rdev->ddev, 4);
7931 rdev->pm.vblank_sync = true;
7932 wake_up(&rdev->irq.vblank_queue);
7934 if (atomic_read(&rdev->irq.pflip[4]))
7935 radeon_crtc_handle_vblank(rdev, 4);
7936 rdev->irq.stat_regs.cik.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
7937 DRM_DEBUG("IH: D5 vblank\n");
7940 case 1: /* D5 vline */
7941 if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) {
7942 rdev->irq.stat_regs.cik.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
7943 DRM_DEBUG("IH: D5 vline\n");
7947 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
7951 case 6: /* D6 vblank/vline */
7953 case 0: /* D6 vblank */
7954 if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
7955 if (rdev->irq.crtc_vblank_int[5]) {
7956 drm_handle_vblank(rdev->ddev, 5);
7957 rdev->pm.vblank_sync = true;
7958 wake_up(&rdev->irq.vblank_queue);
7960 if (atomic_read(&rdev->irq.pflip[5]))
7961 radeon_crtc_handle_vblank(rdev, 5);
7962 rdev->irq.stat_regs.cik.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
7963 DRM_DEBUG("IH: D6 vblank\n");
7966 case 1: /* D6 vline */
7967 if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) {
7968 rdev->irq.stat_regs.cik.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
7969 DRM_DEBUG("IH: D6 vline\n");
7973 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
7977 case 8: /* D1 page flip */
7978 case 10: /* D2 page flip */
7979 case 12: /* D3 page flip */
7980 case 14: /* D4 page flip */
7981 case 16: /* D5 page flip */
7982 case 18: /* D6 page flip */
7983 DRM_DEBUG("IH: D%d flip\n", ((src_id - 8) >> 1) + 1);
7984 if (radeon_use_pflipirq > 0)
7985 radeon_crtc_handle_flip(rdev, (src_id - 8) >> 1);
7987 case 42: /* HPD hotplug */
7990 if (rdev->irq.stat_regs.cik.disp_int & DC_HPD1_INTERRUPT) {
7991 rdev->irq.stat_regs.cik.disp_int &= ~DC_HPD1_INTERRUPT;
7992 queue_hotplug = true;
7993 DRM_DEBUG("IH: HPD1\n");
7997 if (rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_INTERRUPT) {
7998 rdev->irq.stat_regs.cik.disp_int_cont &= ~DC_HPD2_INTERRUPT;
7999 queue_hotplug = true;
8000 DRM_DEBUG("IH: HPD2\n");
8004 if (rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_INTERRUPT) {
8005 rdev->irq.stat_regs.cik.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
8006 queue_hotplug = true;
8007 DRM_DEBUG("IH: HPD3\n");
8011 if (rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_INTERRUPT) {
8012 rdev->irq.stat_regs.cik.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
8013 queue_hotplug = true;
8014 DRM_DEBUG("IH: HPD4\n");
8018 if (rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_INTERRUPT) {
8019 rdev->irq.stat_regs.cik.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
8020 queue_hotplug = true;
8021 DRM_DEBUG("IH: HPD5\n");
8025 if (rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_INTERRUPT) {
8026 rdev->irq.stat_regs.cik.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
8027 queue_hotplug = true;
8028 DRM_DEBUG("IH: HPD6\n");
8032 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
8037 DRM_DEBUG("IH: UVD int: 0x%08x\n", src_data);
8038 radeon_fence_process(rdev, R600_RING_TYPE_UVD_INDEX);
8042 addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
8043 status = RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS);
8044 mc_client = RREG32(VM_CONTEXT1_PROTECTION_FAULT_MCCLIENT);
8045 /* reset addr and status */
8046 WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
8047 if (addr == 0x0 && status == 0x0)
8049 dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
8050 dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
8052 dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
8054 cik_vm_decode_fault(rdev, status, addr, mc_client);
8057 DRM_DEBUG("IH: VCE int: 0x%08x\n", src_data);
8060 radeon_fence_process(rdev, TN_RING_TYPE_VCE1_INDEX);
8063 radeon_fence_process(rdev, TN_RING_TYPE_VCE2_INDEX);
8066 DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
8070 case 176: /* GFX RB CP_INT */
8071 case 177: /* GFX IB CP_INT */
8072 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
8074 case 181: /* CP EOP event */
8075 DRM_DEBUG("IH: CP EOP\n");
8076 /* XXX check the bitfield order! */
8077 me_id = (ring_id & 0x60) >> 5;
8078 pipe_id = (ring_id & 0x18) >> 3;
8079 queue_id = (ring_id & 0x7) >> 0;
8082 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
8086 if ((cp1_ring->me == me_id) & (cp1_ring->pipe == pipe_id))
8087 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
8088 if ((cp2_ring->me == me_id) & (cp2_ring->pipe == pipe_id))
8089 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
8093 case 184: /* CP Privileged reg access */
8094 DRM_ERROR("Illegal register access in command stream\n");
8095 /* XXX check the bitfield order! */
8096 me_id = (ring_id & 0x60) >> 5;
8097 pipe_id = (ring_id & 0x18) >> 3;
8098 queue_id = (ring_id & 0x7) >> 0;
8101 /* This results in a full GPU reset, but all we need to do is soft
8102 * reset the CP for gfx
8116 case 185: /* CP Privileged inst */
8117 DRM_ERROR("Illegal instruction in command stream\n");
8118 /* XXX check the bitfield order! */
8119 me_id = (ring_id & 0x60) >> 5;
8120 pipe_id = (ring_id & 0x18) >> 3;
8121 queue_id = (ring_id & 0x7) >> 0;
8124 /* This results in a full GPU reset, but all we need to do is soft
8125 * reset the CP for gfx
8139 case 224: /* SDMA trap event */
8140 /* XXX check the bitfield order! */
8141 me_id = (ring_id & 0x3) >> 0;
8142 queue_id = (ring_id & 0xc) >> 2;
8143 DRM_DEBUG("IH: SDMA trap\n");
8148 radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
8161 radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
8173 case 230: /* thermal low to high */
8174 DRM_DEBUG("IH: thermal low to high\n");
8175 rdev->pm.dpm.thermal.high_to_low = false;
8176 queue_thermal = true;
8178 case 231: /* thermal high to low */
8179 DRM_DEBUG("IH: thermal high to low\n");
8180 rdev->pm.dpm.thermal.high_to_low = true;
8181 queue_thermal = true;
8183 case 233: /* GUI IDLE */
8184 DRM_DEBUG("IH: GUI idle\n");
8186 case 241: /* SDMA Privileged inst */
8187 case 247: /* SDMA Privileged inst */
8188 DRM_ERROR("Illegal instruction in SDMA command stream\n");
8189 /* XXX check the bitfield order! */
8190 me_id = (ring_id & 0x3) >> 0;
8191 queue_id = (ring_id & 0xc) >> 2;
8226 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
8230 /* wptr/rptr are in bytes! */
8232 rptr &= rdev->ih.ptr_mask;
8233 WREG32(IH_RB_RPTR, rptr);
8236 schedule_work(&rdev->hotplug_work);
8238 rdev->needs_reset = true;
8239 wake_up_all(&rdev->fence_queue);
8242 taskqueue_enqueue(rdev->tq, &rdev->pm.dpm.thermal.work);
8243 rdev->ih.rptr = rptr;
8244 atomic_set(&rdev->ih.lock, 0);
8246 /* make sure wptr hasn't changed while processing */
8247 wptr = cik_get_ih_wptr(rdev);
8255 * startup/shutdown callbacks
8258 * cik_startup - program the asic to a functional state
8260 * @rdev: radeon_device pointer
8262 * Programs the asic to a functional state (CIK).
8263 * Called by cik_init() and cik_resume().
8264 * Returns 0 for success, error for failure.
8266 static int cik_startup(struct radeon_device *rdev)
8268 struct radeon_ring *ring;
8272 /* enable pcie gen2/3 link */
8273 cik_pcie_gen3_enable(rdev);
8275 cik_program_aspm(rdev);
8277 /* scratch needs to be initialized before MC */
8278 r = r600_vram_scratch_init(rdev);
8282 cik_mc_program(rdev);
8284 if (!(rdev->flags & RADEON_IS_IGP) && !rdev->pm.dpm_enabled) {
8285 r = ci_mc_load_microcode(rdev);
8287 DRM_ERROR("Failed to load MC firmware!\n");
8292 r = cik_pcie_gart_enable(rdev);
8297 /* allocate rlc buffers */
8298 if (rdev->flags & RADEON_IS_IGP) {
8299 if (rdev->family == CHIP_KAVERI) {
8300 rdev->rlc.reg_list = spectre_rlc_save_restore_register_list;
8301 rdev->rlc.reg_list_size =
8302 (u32)ARRAY_SIZE(spectre_rlc_save_restore_register_list);
8304 rdev->rlc.reg_list = kalindi_rlc_save_restore_register_list;
8305 rdev->rlc.reg_list_size =
8306 (u32)ARRAY_SIZE(kalindi_rlc_save_restore_register_list);
8309 rdev->rlc.cs_data = ci_cs_data;
8310 rdev->rlc.cp_table_size = CP_ME_TABLE_SIZE * 5 * 4;
8311 r = sumo_rlc_init(rdev);
8313 DRM_ERROR("Failed to init rlc BOs!\n");
8317 /* allocate wb buffer */
8318 r = radeon_wb_init(rdev);
8322 /* allocate mec buffers */
8323 r = cik_mec_init(rdev);
8325 DRM_ERROR("Failed to init MEC BOs!\n");
8329 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
8331 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
8335 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
8337 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
8341 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
8343 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
8347 r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
8349 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
8353 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
8355 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
8359 r = radeon_uvd_resume(rdev);
8361 r = uvd_v4_2_resume(rdev);
8363 r = radeon_fence_driver_start_ring(rdev,
8364 R600_RING_TYPE_UVD_INDEX);
8366 dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
8370 rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
8372 r = radeon_vce_resume(rdev);
8374 r = vce_v2_0_resume(rdev);
8376 r = radeon_fence_driver_start_ring(rdev,
8377 TN_RING_TYPE_VCE1_INDEX);
8379 r = radeon_fence_driver_start_ring(rdev,
8380 TN_RING_TYPE_VCE2_INDEX);
8383 dev_err(rdev->dev, "VCE init error (%d).\n", r);
8384 rdev->ring[TN_RING_TYPE_VCE1_INDEX].ring_size = 0;
8385 rdev->ring[TN_RING_TYPE_VCE2_INDEX].ring_size = 0;
8389 if (!rdev->irq.installed) {
8390 r = radeon_irq_kms_init(rdev);
8395 r = cik_irq_init(rdev);
8397 DRM_ERROR("radeon: IH init failed (%d).\n", r);
8398 radeon_irq_kms_fini(rdev);
8403 if (rdev->family == CHIP_HAWAII) {
8405 nop = PACKET3(PACKET3_NOP, 0x3FFF);
8407 nop = RADEON_CP_PACKET2;
8409 nop = PACKET3(PACKET3_NOP, 0x3FFF);
8412 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
8413 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
8418 /* set up the compute queues */
8419 /* type-2 packets are deprecated on MEC, use type-3 instead */
8420 ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
8421 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP1_RPTR_OFFSET,
8425 ring->me = 1; /* first MEC */
8426 ring->pipe = 0; /* first pipe */
8427 ring->queue = 0; /* first queue */
8428 ring->wptr_offs = CIK_WB_CP1_WPTR_OFFSET;
8430 /* type-2 packets are deprecated on MEC, use type-3 instead */
8431 ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
8432 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP2_RPTR_OFFSET,
8436 /* dGPU only have 1 MEC */
8437 ring->me = 1; /* first MEC */
8438 ring->pipe = 0; /* first pipe */
8439 ring->queue = 1; /* second queue */
8440 ring->wptr_offs = CIK_WB_CP2_WPTR_OFFSET;
8442 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
8443 r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
8444 SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0));
8448 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
8449 r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
8450 SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0));
8454 r = cik_cp_resume(rdev);
8458 r = cik_sdma_resume(rdev);
8462 ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
8463 if (ring->ring_size) {
8464 r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
8467 r = uvd_v1_0_init(rdev);
8469 DRM_ERROR("radeon: failed initializing UVD (%d).\n", r);
8474 ring = &rdev->ring[TN_RING_TYPE_VCE1_INDEX];
8475 if (ring->ring_size)
8476 r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
8479 ring = &rdev->ring[TN_RING_TYPE_VCE2_INDEX];
8480 if (ring->ring_size)
8481 r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
8485 r = vce_v1_0_init(rdev);
8486 else if (r != -ENOENT)
8487 DRM_ERROR("radeon: failed initializing VCE (%d).\n", r);
8489 r = radeon_ib_pool_init(rdev);
8491 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
8495 r = radeon_vm_manager_init(rdev);
8497 dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
8501 r = dce6_audio_init(rdev);
8509 * cik_resume - resume the asic to a functional state
8511 * @rdev: radeon_device pointer
8513 * Programs the asic to a functional state (CIK).
8515 * Returns 0 for success, error for failure.
8517 int cik_resume(struct radeon_device *rdev)
8522 atom_asic_init(rdev->mode_info.atom_context);
8524 /* init golden registers */
8525 cik_init_golden_registers(rdev);
8527 if (rdev->pm.pm_method == PM_METHOD_DPM)
8528 radeon_pm_resume(rdev);
8530 rdev->accel_working = true;
8531 r = cik_startup(rdev);
8533 DRM_ERROR("cik startup failed on resume\n");
8534 rdev->accel_working = false;
8543 * cik_suspend - suspend the asic
8545 * @rdev: radeon_device pointer
8547 * Bring the chip into a state suitable for suspend (CIK).
8548 * Called at suspend.
8549 * Returns 0 for success.
8551 int cik_suspend(struct radeon_device *rdev)
8553 radeon_pm_suspend(rdev);
8554 dce6_audio_fini(rdev);
8555 radeon_vm_manager_fini(rdev);
8556 cik_cp_enable(rdev, false);
8557 cik_sdma_enable(rdev, false);
8558 uvd_v1_0_fini(rdev);
8559 radeon_uvd_suspend(rdev);
8560 radeon_vce_suspend(rdev);
8563 cik_irq_suspend(rdev);
8564 radeon_wb_disable(rdev);
8565 cik_pcie_gart_disable(rdev);
8569 /* Plan is to move initialization in that function and use
8570 * helper function so that radeon_device_init pretty much
8571 * do nothing more than calling asic specific function. This
8572 * should also allow to remove a bunch of callback function
8576 * cik_init - asic specific driver and hw init
8578 * @rdev: radeon_device pointer
8580 * Setup asic specific driver variables and program the hw
8581 * to a functional state (CIK).
8582 * Called at driver startup.
8583 * Returns 0 for success, errors for failure.
8585 int cik_init(struct radeon_device *rdev)
8587 struct radeon_ring *ring;
8591 if (!radeon_get_bios(rdev)) {
8592 if (ASIC_IS_AVIVO(rdev))
8595 /* Must be an ATOMBIOS */
8596 if (!rdev->is_atom_bios) {
8597 dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
8600 r = radeon_atombios_init(rdev);
8604 /* Post card if necessary */
8605 if (!radeon_card_posted(rdev)) {
8607 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
8610 DRM_INFO("GPU not posted. posting now...\n");
8611 atom_asic_init(rdev->mode_info.atom_context);
8613 /* init golden registers */
8614 cik_init_golden_registers(rdev);
8615 /* Initialize scratch registers */
8616 cik_scratch_init(rdev);
8617 /* Initialize surface registers */
8618 radeon_surface_init(rdev);
8619 /* Initialize clocks */
8620 radeon_get_clock_info(rdev->ddev);
8623 r = radeon_fence_driver_init(rdev);
8627 /* initialize memory controller */
8628 r = cik_mc_init(rdev);
8631 /* Memory manager */
8632 r = radeon_bo_init(rdev);
8636 if (rdev->flags & RADEON_IS_IGP) {
8637 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
8638 !rdev->mec_fw || !rdev->sdma_fw || !rdev->rlc_fw) {
8639 r = cik_init_microcode(rdev);
8641 DRM_ERROR("Failed to load firmware!\n");
8646 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
8647 !rdev->mec_fw || !rdev->sdma_fw || !rdev->rlc_fw ||
8649 r = cik_init_microcode(rdev);
8651 DRM_ERROR("Failed to load firmware!\n");
8657 /* Initialize power management */
8658 radeon_pm_init(rdev);
8660 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
8661 ring->ring_obj = NULL;
8662 r600_ring_init(rdev, ring, 1024 * 1024);
8664 ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
8665 ring->ring_obj = NULL;
8666 r600_ring_init(rdev, ring, 1024 * 1024);
8667 r = radeon_doorbell_get(rdev, &ring->doorbell_index);
8671 ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
8672 ring->ring_obj = NULL;
8673 r600_ring_init(rdev, ring, 1024 * 1024);
8674 r = radeon_doorbell_get(rdev, &ring->doorbell_index);
8678 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
8679 ring->ring_obj = NULL;
8680 r600_ring_init(rdev, ring, 256 * 1024);
8682 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
8683 ring->ring_obj = NULL;
8684 r600_ring_init(rdev, ring, 256 * 1024);
8686 r = radeon_uvd_init(rdev);
8688 ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
8689 ring->ring_obj = NULL;
8690 r600_ring_init(rdev, ring, 4096);
8693 r = radeon_vce_init(rdev);
8695 ring = &rdev->ring[TN_RING_TYPE_VCE1_INDEX];
8696 ring->ring_obj = NULL;
8697 r600_ring_init(rdev, ring, 4096);
8699 ring = &rdev->ring[TN_RING_TYPE_VCE2_INDEX];
8700 ring->ring_obj = NULL;
8701 r600_ring_init(rdev, ring, 4096);
8704 rdev->ih.ring_obj = NULL;
8705 r600_ih_ring_init(rdev, 64 * 1024);
8707 r = r600_pcie_gart_init(rdev);
8711 rdev->accel_working = true;
8712 r = cik_startup(rdev);
8714 dev_err(rdev->dev, "disabling GPU acceleration\n");
8716 cik_sdma_fini(rdev);
8718 sumo_rlc_fini(rdev);
8720 radeon_wb_fini(rdev);
8721 radeon_ib_pool_fini(rdev);
8722 radeon_vm_manager_fini(rdev);
8723 radeon_irq_kms_fini(rdev);
8724 cik_pcie_gart_fini(rdev);
8725 rdev->accel_working = false;
8728 /* Don't start up if the MC ucode is missing.
8729 * The default clocks and voltages before the MC ucode
8730 * is loaded are not suffient for advanced operations.
8732 if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
8733 DRM_ERROR("radeon: MC ucode required for NI+.\n");
8741 * cik_fini - asic specific driver and hw fini
8743 * @rdev: radeon_device pointer
8745 * Tear down the asic specific driver variables and program the hw
8746 * to an idle state (CIK).
8747 * Called at driver unload.
8749 void cik_fini(struct radeon_device *rdev)
8751 radeon_pm_fini(rdev);
8753 cik_sdma_fini(rdev);
8757 sumo_rlc_fini(rdev);
8759 radeon_wb_fini(rdev);
8760 radeon_vm_manager_fini(rdev);
8761 radeon_ib_pool_fini(rdev);
8762 radeon_irq_kms_fini(rdev);
8763 uvd_v1_0_fini(rdev);
8764 radeon_uvd_fini(rdev);
8765 radeon_vce_fini(rdev);
8766 cik_pcie_gart_fini(rdev);
8767 r600_vram_scratch_fini(rdev);
8768 radeon_gem_fini(rdev);
8769 radeon_fence_driver_fini(rdev);
8770 radeon_bo_fini(rdev);
8771 radeon_atombios_fini(rdev);
8776 void dce8_program_fmt(struct drm_encoder *encoder)
8778 struct drm_device *dev = encoder->dev;
8779 struct radeon_device *rdev = dev->dev_private;
8780 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
8781 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
8782 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
8785 enum radeon_connector_dither dither = RADEON_FMT_DITHER_DISABLE;
8788 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
8789 bpc = radeon_get_monitor_bpc(connector);
8790 dither = radeon_connector->dither;
8793 /* LVDS/eDP FMT is set up by atom */
8794 if (radeon_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
8797 /* not needed for analog */
8798 if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1) ||
8799 (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2))
8807 if (dither == RADEON_FMT_DITHER_ENABLE)
8808 /* XXX sort out optimal dither settings */
8809 tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
8810 FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH(0));
8812 tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH(0));
8815 if (dither == RADEON_FMT_DITHER_ENABLE)
8816 /* XXX sort out optimal dither settings */
8817 tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
8818 FMT_RGB_RANDOM_ENABLE |
8819 FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH(1));
8821 tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH(1));
8824 if (dither == RADEON_FMT_DITHER_ENABLE)
8825 /* XXX sort out optimal dither settings */
8826 tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
8827 FMT_RGB_RANDOM_ENABLE |
8828 FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH(2));
8830 tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH(2));
8837 WREG32(FMT_BIT_DEPTH_CONTROL + radeon_crtc->crtc_offset, tmp);
8840 /* display watermark setup */
8842 * dce8_line_buffer_adjust - Set up the line buffer
8844 * @rdev: radeon_device pointer
8845 * @radeon_crtc: the selected display controller
8846 * @mode: the current display mode on the selected display
8849 * Setup up the line buffer allocation for
8850 * the selected display controller (CIK).
8851 * Returns the line buffer size in pixels.
8853 static u32 dce8_line_buffer_adjust(struct radeon_device *rdev,
8854 struct radeon_crtc *radeon_crtc,
8855 struct drm_display_mode *mode)
8857 u32 tmp, buffer_alloc, i;
8858 u32 pipe_offset = radeon_crtc->crtc_id * 0x20;
8861 * There are 6 line buffers, one for each display controllers.
8862 * There are 3 partitions per LB. Select the number of partitions
8863 * to enable based on the display width. For display widths larger
8864 * than 4096, you need use to use 2 display controllers and combine
8865 * them using the stereo blender.
8867 if (radeon_crtc->base.enabled && mode) {
8868 if (mode->crtc_hdisplay < 1920) {
8871 } else if (mode->crtc_hdisplay < 2560) {
8874 } else if (mode->crtc_hdisplay < 4096) {
8876 buffer_alloc = (rdev->flags & RADEON_IS_IGP) ? 2 : 4;
8878 DRM_DEBUG_KMS("Mode too big for LB!\n");
8880 buffer_alloc = (rdev->flags & RADEON_IS_IGP) ? 2 : 4;
8887 WREG32(LB_MEMORY_CTRL + radeon_crtc->crtc_offset,
8888 LB_MEMORY_CONFIG(tmp) | LB_MEMORY_SIZE(0x6B0));
8890 WREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
8891 DMIF_BUFFERS_ALLOCATED(buffer_alloc));
8892 for (i = 0; i < rdev->usec_timeout; i++) {
8893 if (RREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
8894 DMIF_BUFFERS_ALLOCATED_COMPLETED)
8899 if (radeon_crtc->base.enabled && mode) {
8911 /* controller not enabled, so no lb used */
8916 * cik_get_number_of_dram_channels - get the number of dram channels
8918 * @rdev: radeon_device pointer
8920 * Look up the number of video ram channels (CIK).
8921 * Used for display watermark bandwidth calculations
8922 * Returns the number of dram channels
8924 static u32 cik_get_number_of_dram_channels(struct radeon_device *rdev)
8926 u32 tmp = RREG32(MC_SHARED_CHMAP);
8928 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
8951 struct dce8_wm_params {
8952 u32 dram_channels; /* number of dram channels */
8953 u32 yclk; /* bandwidth per dram data pin in kHz */
8954 u32 sclk; /* engine clock in kHz */
8955 u32 disp_clk; /* display clock in kHz */
8956 u32 src_width; /* viewport width */
8957 u32 active_time; /* active display time in ns */
8958 u32 blank_time; /* blank time in ns */
8959 bool interlaced; /* mode is interlaced */
8960 fixed20_12 vsc; /* vertical scale ratio */
8961 u32 num_heads; /* number of active crtcs */
8962 u32 bytes_per_pixel; /* bytes per pixel display + overlay */
8963 u32 lb_size; /* line buffer allocated to pipe */
8964 u32 vtaps; /* vertical scaler taps */
8968 * dce8_dram_bandwidth - get the dram bandwidth
8970 * @wm: watermark calculation data
8972 * Calculate the raw dram bandwidth (CIK).
8973 * Used for display watermark bandwidth calculations
8974 * Returns the dram bandwidth in MBytes/s
8976 static u32 dce8_dram_bandwidth(struct dce8_wm_params *wm)
8978 /* Calculate raw DRAM Bandwidth */
8979 fixed20_12 dram_efficiency; /* 0.7 */
8980 fixed20_12 yclk, dram_channels, bandwidth;
8983 a.full = dfixed_const(1000);
8984 yclk.full = dfixed_const(wm->yclk);
8985 yclk.full = dfixed_div(yclk, a);
8986 dram_channels.full = dfixed_const(wm->dram_channels * 4);
8987 a.full = dfixed_const(10);
8988 dram_efficiency.full = dfixed_const(7);
8989 dram_efficiency.full = dfixed_div(dram_efficiency, a);
8990 bandwidth.full = dfixed_mul(dram_channels, yclk);
8991 bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
8993 return dfixed_trunc(bandwidth);
8997 * dce8_dram_bandwidth_for_display - get the dram bandwidth for display
8999 * @wm: watermark calculation data
9001 * Calculate the dram bandwidth used for display (CIK).
9002 * Used for display watermark bandwidth calculations
9003 * Returns the dram bandwidth for display in MBytes/s
9005 static u32 dce8_dram_bandwidth_for_display(struct dce8_wm_params *wm)
9007 /* Calculate DRAM Bandwidth and the part allocated to display. */
9008 fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
9009 fixed20_12 yclk, dram_channels, bandwidth;
9012 a.full = dfixed_const(1000);
9013 yclk.full = dfixed_const(wm->yclk);
9014 yclk.full = dfixed_div(yclk, a);
9015 dram_channels.full = dfixed_const(wm->dram_channels * 4);
9016 a.full = dfixed_const(10);
9017 disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
9018 disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
9019 bandwidth.full = dfixed_mul(dram_channels, yclk);
9020 bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
9022 return dfixed_trunc(bandwidth);
9026 * dce8_data_return_bandwidth - get the data return bandwidth
9028 * @wm: watermark calculation data
9030 * Calculate the data return bandwidth used for display (CIK).
9031 * Used for display watermark bandwidth calculations
9032 * Returns the data return bandwidth in MBytes/s
9034 static u32 dce8_data_return_bandwidth(struct dce8_wm_params *wm)
9036 /* Calculate the display Data return Bandwidth */
9037 fixed20_12 return_efficiency; /* 0.8 */
9038 fixed20_12 sclk, bandwidth;
9041 a.full = dfixed_const(1000);
9042 sclk.full = dfixed_const(wm->sclk);
9043 sclk.full = dfixed_div(sclk, a);
9044 a.full = dfixed_const(10);
9045 return_efficiency.full = dfixed_const(8);
9046 return_efficiency.full = dfixed_div(return_efficiency, a);
9047 a.full = dfixed_const(32);
9048 bandwidth.full = dfixed_mul(a, sclk);
9049 bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
9051 return dfixed_trunc(bandwidth);
9055 * dce8_dmif_request_bandwidth - get the dmif bandwidth
9057 * @wm: watermark calculation data
9059 * Calculate the dmif bandwidth used for display (CIK).
9060 * Used for display watermark bandwidth calculations
9061 * Returns the dmif bandwidth in MBytes/s
9063 static u32 dce8_dmif_request_bandwidth(struct dce8_wm_params *wm)
9065 /* Calculate the DMIF Request Bandwidth */
9066 fixed20_12 disp_clk_request_efficiency; /* 0.8 */
9067 fixed20_12 disp_clk, bandwidth;
9070 a.full = dfixed_const(1000);
9071 disp_clk.full = dfixed_const(wm->disp_clk);
9072 disp_clk.full = dfixed_div(disp_clk, a);
9073 a.full = dfixed_const(32);
9074 b.full = dfixed_mul(a, disp_clk);
9076 a.full = dfixed_const(10);
9077 disp_clk_request_efficiency.full = dfixed_const(8);
9078 disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
9080 bandwidth.full = dfixed_mul(b, disp_clk_request_efficiency);
9082 return dfixed_trunc(bandwidth);
9086 * dce8_available_bandwidth - get the min available bandwidth
9088 * @wm: watermark calculation data
9090 * Calculate the min available bandwidth used for display (CIK).
9091 * Used for display watermark bandwidth calculations
9092 * Returns the min available bandwidth in MBytes/s
9094 static u32 dce8_available_bandwidth(struct dce8_wm_params *wm)
9096 /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
9097 u32 dram_bandwidth = dce8_dram_bandwidth(wm);
9098 u32 data_return_bandwidth = dce8_data_return_bandwidth(wm);
9099 u32 dmif_req_bandwidth = dce8_dmif_request_bandwidth(wm);
9101 return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
9105 * dce8_average_bandwidth - get the average available bandwidth
9107 * @wm: watermark calculation data
9109 * Calculate the average available bandwidth used for display (CIK).
9110 * Used for display watermark bandwidth calculations
9111 * Returns the average available bandwidth in MBytes/s
9113 static u32 dce8_average_bandwidth(struct dce8_wm_params *wm)
9115 /* Calculate the display mode Average Bandwidth
9116 * DisplayMode should contain the source and destination dimensions,
9120 fixed20_12 line_time;
9121 fixed20_12 src_width;
9122 fixed20_12 bandwidth;
9125 a.full = dfixed_const(1000);
9126 line_time.full = dfixed_const(wm->active_time + wm->blank_time);
9127 line_time.full = dfixed_div(line_time, a);
9128 bpp.full = dfixed_const(wm->bytes_per_pixel);
9129 src_width.full = dfixed_const(wm->src_width);
9130 bandwidth.full = dfixed_mul(src_width, bpp);
9131 bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
9132 bandwidth.full = dfixed_div(bandwidth, line_time);
9134 return dfixed_trunc(bandwidth);
9138 * dce8_latency_watermark - get the latency watermark
9140 * @wm: watermark calculation data
9142 * Calculate the latency watermark (CIK).
9143 * Used for display watermark bandwidth calculations
9144 * Returns the latency watermark in ns
9146 static u32 dce8_latency_watermark(struct dce8_wm_params *wm)
9148 /* First calculate the latency in ns */
9149 u32 mc_latency = 2000; /* 2000 ns. */
9150 u32 available_bandwidth = dce8_available_bandwidth(wm);
9151 u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
9152 u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
9153 u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
9154 u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
9155 (wm->num_heads * cursor_line_pair_return_time);
9156 u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
9157 u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
9158 u32 tmp, dmif_size = 12288;
9161 if (wm->num_heads == 0)
9164 a.full = dfixed_const(2);
9165 b.full = dfixed_const(1);
9166 if ((wm->vsc.full > a.full) ||
9167 ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
9169 ((wm->vsc.full >= a.full) && wm->interlaced))
9170 max_src_lines_per_dst_line = 4;
9172 max_src_lines_per_dst_line = 2;
9174 a.full = dfixed_const(available_bandwidth);
9175 b.full = dfixed_const(wm->num_heads);
9176 a.full = dfixed_div(a, b);
9178 b.full = dfixed_const(mc_latency + 512);
9179 c.full = dfixed_const(wm->disp_clk);
9180 b.full = dfixed_div(b, c);
9182 c.full = dfixed_const(dmif_size);
9183 b.full = dfixed_div(c, b);
9185 tmp = min(dfixed_trunc(a), dfixed_trunc(b));
9187 b.full = dfixed_const(1000);
9188 c.full = dfixed_const(wm->disp_clk);
9189 b.full = dfixed_div(c, b);
9190 c.full = dfixed_const(wm->bytes_per_pixel);
9191 b.full = dfixed_mul(b, c);
9193 lb_fill_bw = min(tmp, dfixed_trunc(b));
9195 a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
9196 b.full = dfixed_const(1000);
9197 c.full = dfixed_const(lb_fill_bw);
9198 b.full = dfixed_div(c, b);
9199 a.full = dfixed_div(a, b);
9200 line_fill_time = dfixed_trunc(a);
9202 if (line_fill_time < wm->active_time)
9205 return latency + (line_fill_time - wm->active_time);
9210 * dce8_average_bandwidth_vs_dram_bandwidth_for_display - check
9211 * average and available dram bandwidth
9213 * @wm: watermark calculation data
9215 * Check if the display average bandwidth fits in the display
9216 * dram bandwidth (CIK).
9217 * Used for display watermark bandwidth calculations
9218 * Returns true if the display fits, false if not.
9220 static bool dce8_average_bandwidth_vs_dram_bandwidth_for_display(struct dce8_wm_params *wm)
9222 if (dce8_average_bandwidth(wm) <=
9223 (dce8_dram_bandwidth_for_display(wm) / wm->num_heads))
9230 * dce8_average_bandwidth_vs_available_bandwidth - check
9231 * average and available bandwidth
9233 * @wm: watermark calculation data
9235 * Check if the display average bandwidth fits in the display
9236 * available bandwidth (CIK).
9237 * Used for display watermark bandwidth calculations
9238 * Returns true if the display fits, false if not.
9240 static bool dce8_average_bandwidth_vs_available_bandwidth(struct dce8_wm_params *wm)
9242 if (dce8_average_bandwidth(wm) <=
9243 (dce8_available_bandwidth(wm) / wm->num_heads))
9250 * dce8_check_latency_hiding - check latency hiding
9252 * @wm: watermark calculation data
9254 * Check latency hiding (CIK).
9255 * Used for display watermark bandwidth calculations
9256 * Returns true if the display fits, false if not.
9258 static bool dce8_check_latency_hiding(struct dce8_wm_params *wm)
9260 u32 lb_partitions = wm->lb_size / wm->src_width;
9261 u32 line_time = wm->active_time + wm->blank_time;
9262 u32 latency_tolerant_lines;
9266 a.full = dfixed_const(1);
9267 if (wm->vsc.full > a.full)
9268 latency_tolerant_lines = 1;
9270 if (lb_partitions <= (wm->vtaps + 1))
9271 latency_tolerant_lines = 1;
9273 latency_tolerant_lines = 2;
9276 latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
9278 if (dce8_latency_watermark(wm) <= latency_hiding)
9285 * dce8_program_watermarks - program display watermarks
9287 * @rdev: radeon_device pointer
9288 * @radeon_crtc: the selected display controller
9289 * @lb_size: line buffer size
9290 * @num_heads: number of display controllers in use
9292 * Calculate and program the display watermarks for the
9293 * selected display controller (CIK).
9295 static void dce8_program_watermarks(struct radeon_device *rdev,
9296 struct radeon_crtc *radeon_crtc,
9297 u32 lb_size, u32 num_heads)
9299 struct drm_display_mode *mode = &radeon_crtc->base.mode;
9300 struct dce8_wm_params wm_low, wm_high;
9303 u32 latency_watermark_a = 0, latency_watermark_b = 0;
9306 if (radeon_crtc->base.enabled && num_heads && mode) {
9307 pixel_period = 1000000 / (u32)mode->clock;
9308 line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
9310 /* watermark for high clocks */
9311 if ((rdev->pm.pm_method == PM_METHOD_DPM) &&
9312 rdev->pm.dpm_enabled) {
9314 radeon_dpm_get_mclk(rdev, false) * 10;
9316 radeon_dpm_get_sclk(rdev, false) * 10;
9318 wm_high.yclk = rdev->pm.current_mclk * 10;
9319 wm_high.sclk = rdev->pm.current_sclk * 10;
9322 wm_high.disp_clk = mode->clock;
9323 wm_high.src_width = mode->crtc_hdisplay;
9324 wm_high.active_time = mode->crtc_hdisplay * pixel_period;
9325 wm_high.blank_time = line_time - wm_high.active_time;
9326 wm_high.interlaced = false;
9327 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
9328 wm_high.interlaced = true;
9329 wm_high.vsc = radeon_crtc->vsc;
9331 if (radeon_crtc->rmx_type != RMX_OFF)
9333 wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
9334 wm_high.lb_size = lb_size;
9335 wm_high.dram_channels = cik_get_number_of_dram_channels(rdev);
9336 wm_high.num_heads = num_heads;
9338 /* set for high clocks */
9339 latency_watermark_a = min(dce8_latency_watermark(&wm_high), (u32)65535);
9341 /* possibly force display priority to high */
9342 /* should really do this at mode validation time... */
9343 if (!dce8_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
9344 !dce8_average_bandwidth_vs_available_bandwidth(&wm_high) ||
9345 !dce8_check_latency_hiding(&wm_high) ||
9346 (rdev->disp_priority == 2)) {
9347 DRM_DEBUG_KMS("force priority to high\n");
9350 /* watermark for low clocks */
9351 if ((rdev->pm.pm_method == PM_METHOD_DPM) &&
9352 rdev->pm.dpm_enabled) {
9354 radeon_dpm_get_mclk(rdev, true) * 10;
9356 radeon_dpm_get_sclk(rdev, true) * 10;
9358 wm_low.yclk = rdev->pm.current_mclk * 10;
9359 wm_low.sclk = rdev->pm.current_sclk * 10;
9362 wm_low.disp_clk = mode->clock;
9363 wm_low.src_width = mode->crtc_hdisplay;
9364 wm_low.active_time = mode->crtc_hdisplay * pixel_period;
9365 wm_low.blank_time = line_time - wm_low.active_time;
9366 wm_low.interlaced = false;
9367 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
9368 wm_low.interlaced = true;
9369 wm_low.vsc = radeon_crtc->vsc;
9371 if (radeon_crtc->rmx_type != RMX_OFF)
9373 wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
9374 wm_low.lb_size = lb_size;
9375 wm_low.dram_channels = cik_get_number_of_dram_channels(rdev);
9376 wm_low.num_heads = num_heads;
9378 /* set for low clocks */
9379 latency_watermark_b = min(dce8_latency_watermark(&wm_low), (u32)65535);
9381 /* possibly force display priority to high */
9382 /* should really do this at mode validation time... */
9383 if (!dce8_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
9384 !dce8_average_bandwidth_vs_available_bandwidth(&wm_low) ||
9385 !dce8_check_latency_hiding(&wm_low) ||
9386 (rdev->disp_priority == 2)) {
9387 DRM_DEBUG_KMS("force priority to high\n");
9392 wm_mask = RREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset);
9394 tmp &= ~LATENCY_WATERMARK_MASK(3);
9395 tmp |= LATENCY_WATERMARK_MASK(1);
9396 WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, tmp);
9397 WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
9398 (LATENCY_LOW_WATERMARK(latency_watermark_a) |
9399 LATENCY_HIGH_WATERMARK(line_time)));
9401 tmp = RREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset);
9402 tmp &= ~LATENCY_WATERMARK_MASK(3);
9403 tmp |= LATENCY_WATERMARK_MASK(2);
9404 WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, tmp);
9405 WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
9406 (LATENCY_LOW_WATERMARK(latency_watermark_b) |
9407 LATENCY_HIGH_WATERMARK(line_time)));
9408 /* restore original selection */
9409 WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, wm_mask);
9411 /* save values for DPM */
9412 radeon_crtc->line_time = line_time;
9413 radeon_crtc->wm_high = latency_watermark_a;
9414 radeon_crtc->wm_low = latency_watermark_b;
9418 * dce8_bandwidth_update - program display watermarks
9420 * @rdev: radeon_device pointer
9422 * Calculate and program the display watermarks and line
9423 * buffer allocation (CIK).
9425 void dce8_bandwidth_update(struct radeon_device *rdev)
9427 struct drm_display_mode *mode = NULL;
9428 u32 num_heads = 0, lb_size;
9431 if (!rdev->mode_info.mode_config_initialized)
9434 radeon_update_display_priority(rdev);
9436 for (i = 0; i < rdev->num_crtc; i++) {
9437 if (rdev->mode_info.crtcs[i]->base.enabled)
9440 for (i = 0; i < rdev->num_crtc; i++) {
9441 mode = &rdev->mode_info.crtcs[i]->base.mode;
9442 lb_size = dce8_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode);
9443 dce8_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
9448 * cik_get_gpu_clock_counter - return GPU clock counter snapshot
9450 * @rdev: radeon_device pointer
9452 * Fetches a GPU clock counter snapshot (SI).
9453 * Returns the 64 bit clock counter snapshot.
9455 uint64_t cik_get_gpu_clock_counter(struct radeon_device *rdev)
9459 spin_lock(&rdev->gpu_clock_mutex);
9460 WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
9461 clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
9462 ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
9463 spin_unlock(&rdev->gpu_clock_mutex);
9467 static int cik_set_uvd_clock(struct radeon_device *rdev, u32 clock,
9468 u32 cntl_reg, u32 status_reg)
9471 struct atom_clock_dividers dividers;
9474 r = radeon_atom_get_clock_dividers(rdev, COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
9475 clock, false, ÷rs);
9479 tmp = RREG32_SMC(cntl_reg);
9480 tmp &= ~(DCLK_DIR_CNTL_EN|DCLK_DIVIDER_MASK);
9481 tmp |= dividers.post_divider;
9482 WREG32_SMC(cntl_reg, tmp);
9484 for (i = 0; i < 100; i++) {
9485 if (RREG32_SMC(status_reg) & DCLK_STATUS)
9495 int cik_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
9499 r = cik_set_uvd_clock(rdev, vclk, CG_VCLK_CNTL, CG_VCLK_STATUS);
9503 r = cik_set_uvd_clock(rdev, dclk, CG_DCLK_CNTL, CG_DCLK_STATUS);
9507 int cik_set_vce_clocks(struct radeon_device *rdev, u32 evclk, u32 ecclk)
9510 struct atom_clock_dividers dividers;
9513 r = radeon_atom_get_clock_dividers(rdev, COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
9514 ecclk, false, ÷rs);
9518 for (i = 0; i < 100; i++) {
9519 if (RREG32_SMC(CG_ECLK_STATUS) & ECLK_STATUS)
9526 tmp = RREG32_SMC(CG_ECLK_CNTL);
9527 tmp &= ~(ECLK_DIR_CNTL_EN|ECLK_DIVIDER_MASK);
9528 tmp |= dividers.post_divider;
9529 WREG32_SMC(CG_ECLK_CNTL, tmp);
9531 for (i = 0; i < 100; i++) {
9532 if (RREG32_SMC(CG_ECLK_STATUS) & ECLK_STATUS)
9542 static void cik_pcie_gen3_enable(struct radeon_device *rdev)
9544 struct pci_dev *root = rdev->pdev->bus->self;
9545 int bridge_pos, gpu_pos;
9546 u32 speed_cntl, mask, current_data_rate;
9550 if (radeon_pcie_gen2 == 0)
9553 if (rdev->flags & RADEON_IS_IGP)
9556 if (!(rdev->flags & RADEON_IS_PCIE))
9559 ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask);
9563 if (!(mask & (DRM_PCIE_SPEED_50 | DRM_PCIE_SPEED_80)))
9566 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
9567 current_data_rate = (speed_cntl & LC_CURRENT_DATA_RATE_MASK) >>
9568 LC_CURRENT_DATA_RATE_SHIFT;
9569 if (mask & DRM_PCIE_SPEED_80) {
9570 if (current_data_rate == 2) {
9571 DRM_INFO("PCIE gen 3 link speeds already enabled\n");
9574 DRM_INFO("enabling PCIE gen 3 link speeds, disable with radeon.pcie_gen2=0\n");
9575 } else if (mask & DRM_PCIE_SPEED_50) {
9576 if (current_data_rate == 1) {
9577 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
9580 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
9583 bridge_pos = pci_get_pciecap_ptr(root->dev);
9587 gpu_pos = pci_get_pciecap_ptr(rdev->pdev->dev);
9591 if (mask & DRM_PCIE_SPEED_80) {
9592 /* re-try equalization if gen3 is not already enabled */
9593 if (current_data_rate != 2) {
9594 u16 bridge_cfg, gpu_cfg;
9595 u16 bridge_cfg2, gpu_cfg2;
9596 u32 max_lw, current_lw, tmp;
9598 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
9599 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
9601 tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
9602 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
9604 tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
9605 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
9607 tmp = RREG32_PCIE_PORT(PCIE_LC_STATUS1);
9608 max_lw = (tmp & LC_DETECTED_LINK_WIDTH_MASK) >> LC_DETECTED_LINK_WIDTH_SHIFT;
9609 current_lw = (tmp & LC_OPERATING_LINK_WIDTH_MASK) >> LC_OPERATING_LINK_WIDTH_SHIFT;
9611 if (current_lw < max_lw) {
9612 tmp = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
9613 if (tmp & LC_RENEGOTIATION_SUPPORT) {
9614 tmp &= ~(LC_LINK_WIDTH_MASK | LC_UPCONFIGURE_DIS);
9615 tmp |= (max_lw << LC_LINK_WIDTH_SHIFT);
9616 tmp |= LC_UPCONFIGURE_SUPPORT | LC_RENEGOTIATE_EN | LC_RECONFIG_NOW;
9617 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, tmp);
9621 for (i = 0; i < 10; i++) {
9623 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_DEVSTA, &tmp16);
9624 if (tmp16 & PCI_EXP_DEVSTA_TRPND)
9627 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
9628 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
9630 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &bridge_cfg2);
9631 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &gpu_cfg2);
9633 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
9634 tmp |= LC_SET_QUIESCE;
9635 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
9637 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
9639 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
9644 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &tmp16);
9645 tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
9646 tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
9647 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
9649 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &tmp16);
9650 tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
9651 tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
9652 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
9655 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &tmp16);
9656 tmp16 &= ~((1 << 4) | (7 << 9));
9657 tmp16 |= (bridge_cfg2 & ((1 << 4) | (7 << 9)));
9658 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, tmp16);
9660 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
9661 tmp16 &= ~((1 << 4) | (7 << 9));
9662 tmp16 |= (gpu_cfg2 & ((1 << 4) | (7 << 9)));
9663 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
9665 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
9666 tmp &= ~LC_SET_QUIESCE;
9667 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
9672 /* set the link speed */
9673 speed_cntl |= LC_FORCE_EN_SW_SPEED_CHANGE | LC_FORCE_DIS_HW_SPEED_CHANGE;
9674 speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
9675 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
9677 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
9679 if (mask & DRM_PCIE_SPEED_80)
9680 tmp16 |= 3; /* gen3 */
9681 else if (mask & DRM_PCIE_SPEED_50)
9682 tmp16 |= 2; /* gen2 */
9684 tmp16 |= 1; /* gen1 */
9685 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
9687 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
9688 speed_cntl |= LC_INITIATE_LINK_SPEED_CHANGE;
9689 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
9691 for (i = 0; i < rdev->usec_timeout; i++) {
9692 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
9693 if ((speed_cntl & LC_INITIATE_LINK_SPEED_CHANGE) == 0)
9699 static void cik_program_aspm(struct radeon_device *rdev)
9702 bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
9703 bool disable_clkreq = false;
9705 if (radeon_aspm == 0)
9708 /* XXX double check IGPs */
9709 if (rdev->flags & RADEON_IS_IGP)
9712 if (!(rdev->flags & RADEON_IS_PCIE))
9715 orig = data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
9716 data &= ~LC_XMIT_N_FTS_MASK;
9717 data |= LC_XMIT_N_FTS(0x24) | LC_XMIT_N_FTS_OVERRIDE_EN;
9719 WREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL, data);
9721 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL3);
9722 data |= LC_GO_TO_RECOVERY;
9724 WREG32_PCIE_PORT(PCIE_LC_CNTL3, data);
9726 orig = data = RREG32_PCIE_PORT(PCIE_P_CNTL);
9727 data |= P_IGNORE_EDB_ERR;
9729 WREG32_PCIE_PORT(PCIE_P_CNTL, data);
9731 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
9732 data &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
9733 data |= LC_PMI_TO_L1_DIS;
9735 data |= LC_L0S_INACTIVITY(7);
9738 data |= LC_L1_INACTIVITY(7);
9739 data &= ~LC_PMI_TO_L1_DIS;
9741 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
9743 if (!disable_plloff_in_l1) {
9744 bool clk_req_support;
9746 orig = data = RREG32_PCIE_PORT(PB0_PIF_PWRDOWN_0);
9747 data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
9748 data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
9750 WREG32_PCIE_PORT(PB0_PIF_PWRDOWN_0, data);
9752 orig = data = RREG32_PCIE_PORT(PB0_PIF_PWRDOWN_1);
9753 data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
9754 data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
9756 WREG32_PCIE_PORT(PB0_PIF_PWRDOWN_1, data);
9758 orig = data = RREG32_PCIE_PORT(PB1_PIF_PWRDOWN_0);
9759 data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
9760 data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
9762 WREG32_PCIE_PORT(PB1_PIF_PWRDOWN_0, data);
9764 orig = data = RREG32_PCIE_PORT(PB1_PIF_PWRDOWN_1);
9765 data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
9766 data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
9768 WREG32_PCIE_PORT(PB1_PIF_PWRDOWN_1, data);
9770 orig = data = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
9771 data &= ~LC_DYN_LANES_PWR_STATE_MASK;
9772 data |= LC_DYN_LANES_PWR_STATE(3);
9774 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
9776 if (!disable_clkreq) {
9778 struct pci_dev *root = rdev->pdev->bus->self;
9781 clk_req_support = false;
9782 pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
9783 if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
9784 clk_req_support = true;
9786 clk_req_support = false;
9789 clk_req_support = false;
9792 if (clk_req_support) {
9793 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL2);
9794 data |= LC_ALLOW_PDWN_IN_L1 | LC_ALLOW_PDWN_IN_L23;
9796 WREG32_PCIE_PORT(PCIE_LC_CNTL2, data);
9798 orig = data = RREG32_SMC(THM_CLK_CNTL);
9799 data &= ~(CMON_CLK_SEL_MASK | TMON_CLK_SEL_MASK);
9800 data |= CMON_CLK_SEL(1) | TMON_CLK_SEL(1);
9802 WREG32_SMC(THM_CLK_CNTL, data);
9804 orig = data = RREG32_SMC(MISC_CLK_CTRL);
9805 data &= ~(DEEP_SLEEP_CLK_SEL_MASK | ZCLK_SEL_MASK);
9806 data |= DEEP_SLEEP_CLK_SEL(1) | ZCLK_SEL(1);
9808 WREG32_SMC(MISC_CLK_CTRL, data);
9810 orig = data = RREG32_SMC(CG_CLKPIN_CNTL);
9811 data &= ~BCLK_AS_XCLK;
9813 WREG32_SMC(CG_CLKPIN_CNTL, data);
9815 orig = data = RREG32_SMC(CG_CLKPIN_CNTL_2);
9816 data &= ~FORCE_BIF_REFCLK_EN;
9818 WREG32_SMC(CG_CLKPIN_CNTL_2, data);
9820 orig = data = RREG32_SMC(MPLL_BYPASSCLK_SEL);
9821 data &= ~MPLL_CLKOUT_SEL_MASK;
9822 data |= MPLL_CLKOUT_SEL(4);
9824 WREG32_SMC(MPLL_BYPASSCLK_SEL, data);
9829 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
9832 orig = data = RREG32_PCIE_PORT(PCIE_CNTL2);
9833 data |= SLV_MEM_LS_EN | MST_MEM_LS_EN | REPLAY_MEM_LS_EN;
9835 WREG32_PCIE_PORT(PCIE_CNTL2, data);
9838 data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
9839 if((data & LC_N_FTS_MASK) == LC_N_FTS_MASK) {
9840 data = RREG32_PCIE_PORT(PCIE_LC_STATUS1);
9841 if ((data & LC_REVERSE_XMIT) && (data & LC_REVERSE_RCVR)) {
9842 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
9843 data &= ~LC_L0S_INACTIVITY_MASK;
9845 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);