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/slab.h>
26 #include <linux/module.h>
29 #include "radeon_asic.h"
30 #include "radeon_audio.h"
33 #include "cik_blit_shaders.h"
34 #include "radeon_ucode.h"
35 #include "clearstate_ci.h"
37 #define SH_MEM_CONFIG_GFX_DEFAULT \
38 ALIGNMENT_MODE(SH_MEM_ALIGNMENT_MODE_UNALIGNED)
40 MODULE_FIRMWARE("radeon/BONAIRE_pfp.bin");
41 MODULE_FIRMWARE("radeon/BONAIRE_me.bin");
42 MODULE_FIRMWARE("radeon/BONAIRE_ce.bin");
43 MODULE_FIRMWARE("radeon/BONAIRE_mec.bin");
44 MODULE_FIRMWARE("radeon/BONAIRE_mc.bin");
45 MODULE_FIRMWARE("radeon/BONAIRE_mc2.bin");
46 MODULE_FIRMWARE("radeon/BONAIRE_rlc.bin");
47 MODULE_FIRMWARE("radeon/BONAIRE_sdma.bin");
48 MODULE_FIRMWARE("radeon/BONAIRE_smc.bin");
50 MODULE_FIRMWARE("radeon/bonaire_pfp.bin");
51 MODULE_FIRMWARE("radeon/bonaire_me.bin");
52 MODULE_FIRMWARE("radeon/bonaire_ce.bin");
53 MODULE_FIRMWARE("radeon/bonaire_mec.bin");
54 MODULE_FIRMWARE("radeon/bonaire_mc.bin");
55 MODULE_FIRMWARE("radeon/bonaire_rlc.bin");
56 MODULE_FIRMWARE("radeon/bonaire_sdma.bin");
57 MODULE_FIRMWARE("radeon/bonaire_smc.bin");
58 MODULE_FIRMWARE("radeon/bonaire_k_smc.bin");
60 MODULE_FIRMWARE("radeon/HAWAII_pfp.bin");
61 MODULE_FIRMWARE("radeon/HAWAII_me.bin");
62 MODULE_FIRMWARE("radeon/HAWAII_ce.bin");
63 MODULE_FIRMWARE("radeon/HAWAII_mec.bin");
64 MODULE_FIRMWARE("radeon/HAWAII_mc.bin");
65 MODULE_FIRMWARE("radeon/HAWAII_mc2.bin");
66 MODULE_FIRMWARE("radeon/HAWAII_rlc.bin");
67 MODULE_FIRMWARE("radeon/HAWAII_sdma.bin");
68 MODULE_FIRMWARE("radeon/HAWAII_smc.bin");
70 MODULE_FIRMWARE("radeon/hawaii_pfp.bin");
71 MODULE_FIRMWARE("radeon/hawaii_me.bin");
72 MODULE_FIRMWARE("radeon/hawaii_ce.bin");
73 MODULE_FIRMWARE("radeon/hawaii_mec.bin");
74 MODULE_FIRMWARE("radeon/hawaii_mc.bin");
75 MODULE_FIRMWARE("radeon/hawaii_rlc.bin");
76 MODULE_FIRMWARE("radeon/hawaii_sdma.bin");
77 MODULE_FIRMWARE("radeon/hawaii_smc.bin");
78 MODULE_FIRMWARE("radeon/hawaii_k_smc.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_rlc.bin");
85 MODULE_FIRMWARE("radeon/KAVERI_sdma.bin");
87 MODULE_FIRMWARE("radeon/kaveri_pfp.bin");
88 MODULE_FIRMWARE("radeon/kaveri_me.bin");
89 MODULE_FIRMWARE("radeon/kaveri_ce.bin");
90 MODULE_FIRMWARE("radeon/kaveri_mec.bin");
91 MODULE_FIRMWARE("radeon/kaveri_mec2.bin");
92 MODULE_FIRMWARE("radeon/kaveri_rlc.bin");
93 MODULE_FIRMWARE("radeon/kaveri_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/kabini_pfp.bin");
103 MODULE_FIRMWARE("radeon/kabini_me.bin");
104 MODULE_FIRMWARE("radeon/kabini_ce.bin");
105 MODULE_FIRMWARE("radeon/kabini_mec.bin");
106 MODULE_FIRMWARE("radeon/kabini_rlc.bin");
107 MODULE_FIRMWARE("radeon/kabini_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 MODULE_FIRMWARE("radeon/mullins_pfp.bin");
117 MODULE_FIRMWARE("radeon/mullins_me.bin");
118 MODULE_FIRMWARE("radeon/mullins_ce.bin");
119 MODULE_FIRMWARE("radeon/mullins_mec.bin");
120 MODULE_FIRMWARE("radeon/mullins_rlc.bin");
121 MODULE_FIRMWARE("radeon/mullins_sdma.bin");
123 static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh);
124 static void cik_rlc_stop(struct radeon_device *rdev);
125 static void cik_pcie_gen3_enable(struct radeon_device *rdev);
126 static void cik_program_aspm(struct radeon_device *rdev);
127 static void cik_init_pg(struct radeon_device *rdev);
128 static void cik_init_cg(struct radeon_device *rdev);
129 static void cik_fini_pg(struct radeon_device *rdev);
130 static void cik_fini_cg(struct radeon_device *rdev);
131 static void cik_enable_gui_idle_interrupt(struct radeon_device *rdev,
135 * cik_get_allowed_info_register - fetch the register for the info ioctl
137 * @rdev: radeon_device pointer
138 * @reg: register offset in bytes
139 * @val: register value
141 * Returns 0 for success or -EINVAL for an invalid register
144 int cik_get_allowed_info_register(struct radeon_device *rdev,
150 case GRBM_STATUS_SE0:
151 case GRBM_STATUS_SE1:
152 case GRBM_STATUS_SE2:
153 case GRBM_STATUS_SE3:
156 case (SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET):
157 case (SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET):
168 * Indirect registers accessor
170 u32 cik_didt_rreg(struct radeon_device *rdev, u32 reg)
175 spin_lock_irqsave(&rdev->didt_idx_lock, flags);
176 WREG32(CIK_DIDT_IND_INDEX, (reg));
177 r = RREG32(CIK_DIDT_IND_DATA);
178 spin_unlock_irqrestore(&rdev->didt_idx_lock, flags);
182 void cik_didt_wreg(struct radeon_device *rdev, u32 reg, u32 v)
186 spin_lock_irqsave(&rdev->didt_idx_lock, flags);
187 WREG32(CIK_DIDT_IND_INDEX, (reg));
188 WREG32(CIK_DIDT_IND_DATA, (v));
189 spin_unlock_irqrestore(&rdev->didt_idx_lock, flags);
192 /* get temperature in millidegrees */
193 int ci_get_temp(struct radeon_device *rdev)
198 temp = (RREG32_SMC(CG_MULT_THERMAL_STATUS) & CTF_TEMP_MASK) >>
204 actual_temp = temp & 0x1ff;
206 actual_temp = actual_temp * 1000;
211 /* get temperature in millidegrees */
212 int kv_get_temp(struct radeon_device *rdev)
217 temp = RREG32_SMC(0xC0300E0C);
220 actual_temp = (temp / 8) - 49;
224 actual_temp = actual_temp * 1000;
230 * Indirect registers accessor
232 u32 cik_pciep_rreg(struct radeon_device *rdev, u32 reg)
237 spin_lock_irqsave(&rdev->pciep_idx_lock, flags);
238 WREG32(PCIE_INDEX, reg);
239 (void)RREG32(PCIE_INDEX);
240 r = RREG32(PCIE_DATA);
241 spin_unlock_irqrestore(&rdev->pciep_idx_lock, flags);
245 void cik_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
249 spin_lock_irqsave(&rdev->pciep_idx_lock, flags);
250 WREG32(PCIE_INDEX, reg);
251 (void)RREG32(PCIE_INDEX);
252 WREG32(PCIE_DATA, v);
253 (void)RREG32(PCIE_DATA);
254 spin_unlock_irqrestore(&rdev->pciep_idx_lock, flags);
257 static const u32 spectre_rlc_save_restore_register_list[] =
259 (0x0e00 << 16) | (0xc12c >> 2),
261 (0x0e00 << 16) | (0xc140 >> 2),
263 (0x0e00 << 16) | (0xc150 >> 2),
265 (0x0e00 << 16) | (0xc15c >> 2),
267 (0x0e00 << 16) | (0xc168 >> 2),
269 (0x0e00 << 16) | (0xc170 >> 2),
271 (0x0e00 << 16) | (0xc178 >> 2),
273 (0x0e00 << 16) | (0xc204 >> 2),
275 (0x0e00 << 16) | (0xc2b4 >> 2),
277 (0x0e00 << 16) | (0xc2b8 >> 2),
279 (0x0e00 << 16) | (0xc2bc >> 2),
281 (0x0e00 << 16) | (0xc2c0 >> 2),
283 (0x0e00 << 16) | (0x8228 >> 2),
285 (0x0e00 << 16) | (0x829c >> 2),
287 (0x0e00 << 16) | (0x869c >> 2),
289 (0x0600 << 16) | (0x98f4 >> 2),
291 (0x0e00 << 16) | (0x98f8 >> 2),
293 (0x0e00 << 16) | (0x9900 >> 2),
295 (0x0e00 << 16) | (0xc260 >> 2),
297 (0x0e00 << 16) | (0x90e8 >> 2),
299 (0x0e00 << 16) | (0x3c000 >> 2),
301 (0x0e00 << 16) | (0x3c00c >> 2),
303 (0x0e00 << 16) | (0x8c1c >> 2),
305 (0x0e00 << 16) | (0x9700 >> 2),
307 (0x0e00 << 16) | (0xcd20 >> 2),
309 (0x4e00 << 16) | (0xcd20 >> 2),
311 (0x5e00 << 16) | (0xcd20 >> 2),
313 (0x6e00 << 16) | (0xcd20 >> 2),
315 (0x7e00 << 16) | (0xcd20 >> 2),
317 (0x8e00 << 16) | (0xcd20 >> 2),
319 (0x9e00 << 16) | (0xcd20 >> 2),
321 (0xae00 << 16) | (0xcd20 >> 2),
323 (0xbe00 << 16) | (0xcd20 >> 2),
325 (0x0e00 << 16) | (0x89bc >> 2),
327 (0x0e00 << 16) | (0x8900 >> 2),
330 (0x0e00 << 16) | (0xc130 >> 2),
332 (0x0e00 << 16) | (0xc134 >> 2),
334 (0x0e00 << 16) | (0xc1fc >> 2),
336 (0x0e00 << 16) | (0xc208 >> 2),
338 (0x0e00 << 16) | (0xc264 >> 2),
340 (0x0e00 << 16) | (0xc268 >> 2),
342 (0x0e00 << 16) | (0xc26c >> 2),
344 (0x0e00 << 16) | (0xc270 >> 2),
346 (0x0e00 << 16) | (0xc274 >> 2),
348 (0x0e00 << 16) | (0xc278 >> 2),
350 (0x0e00 << 16) | (0xc27c >> 2),
352 (0x0e00 << 16) | (0xc280 >> 2),
354 (0x0e00 << 16) | (0xc284 >> 2),
356 (0x0e00 << 16) | (0xc288 >> 2),
358 (0x0e00 << 16) | (0xc28c >> 2),
360 (0x0e00 << 16) | (0xc290 >> 2),
362 (0x0e00 << 16) | (0xc294 >> 2),
364 (0x0e00 << 16) | (0xc298 >> 2),
366 (0x0e00 << 16) | (0xc29c >> 2),
368 (0x0e00 << 16) | (0xc2a0 >> 2),
370 (0x0e00 << 16) | (0xc2a4 >> 2),
372 (0x0e00 << 16) | (0xc2a8 >> 2),
374 (0x0e00 << 16) | (0xc2ac >> 2),
376 (0x0e00 << 16) | (0xc2b0 >> 2),
378 (0x0e00 << 16) | (0x301d0 >> 2),
380 (0x0e00 << 16) | (0x30238 >> 2),
382 (0x0e00 << 16) | (0x30250 >> 2),
384 (0x0e00 << 16) | (0x30254 >> 2),
386 (0x0e00 << 16) | (0x30258 >> 2),
388 (0x0e00 << 16) | (0x3025c >> 2),
390 (0x4e00 << 16) | (0xc900 >> 2),
392 (0x5e00 << 16) | (0xc900 >> 2),
394 (0x6e00 << 16) | (0xc900 >> 2),
396 (0x7e00 << 16) | (0xc900 >> 2),
398 (0x8e00 << 16) | (0xc900 >> 2),
400 (0x9e00 << 16) | (0xc900 >> 2),
402 (0xae00 << 16) | (0xc900 >> 2),
404 (0xbe00 << 16) | (0xc900 >> 2),
406 (0x4e00 << 16) | (0xc904 >> 2),
408 (0x5e00 << 16) | (0xc904 >> 2),
410 (0x6e00 << 16) | (0xc904 >> 2),
412 (0x7e00 << 16) | (0xc904 >> 2),
414 (0x8e00 << 16) | (0xc904 >> 2),
416 (0x9e00 << 16) | (0xc904 >> 2),
418 (0xae00 << 16) | (0xc904 >> 2),
420 (0xbe00 << 16) | (0xc904 >> 2),
422 (0x4e00 << 16) | (0xc908 >> 2),
424 (0x5e00 << 16) | (0xc908 >> 2),
426 (0x6e00 << 16) | (0xc908 >> 2),
428 (0x7e00 << 16) | (0xc908 >> 2),
430 (0x8e00 << 16) | (0xc908 >> 2),
432 (0x9e00 << 16) | (0xc908 >> 2),
434 (0xae00 << 16) | (0xc908 >> 2),
436 (0xbe00 << 16) | (0xc908 >> 2),
438 (0x4e00 << 16) | (0xc90c >> 2),
440 (0x5e00 << 16) | (0xc90c >> 2),
442 (0x6e00 << 16) | (0xc90c >> 2),
444 (0x7e00 << 16) | (0xc90c >> 2),
446 (0x8e00 << 16) | (0xc90c >> 2),
448 (0x9e00 << 16) | (0xc90c >> 2),
450 (0xae00 << 16) | (0xc90c >> 2),
452 (0xbe00 << 16) | (0xc90c >> 2),
454 (0x4e00 << 16) | (0xc910 >> 2),
456 (0x5e00 << 16) | (0xc910 >> 2),
458 (0x6e00 << 16) | (0xc910 >> 2),
460 (0x7e00 << 16) | (0xc910 >> 2),
462 (0x8e00 << 16) | (0xc910 >> 2),
464 (0x9e00 << 16) | (0xc910 >> 2),
466 (0xae00 << 16) | (0xc910 >> 2),
468 (0xbe00 << 16) | (0xc910 >> 2),
470 (0x0e00 << 16) | (0xc99c >> 2),
472 (0x0e00 << 16) | (0x9834 >> 2),
474 (0x0000 << 16) | (0x30f00 >> 2),
476 (0x0001 << 16) | (0x30f00 >> 2),
478 (0x0000 << 16) | (0x30f04 >> 2),
480 (0x0001 << 16) | (0x30f04 >> 2),
482 (0x0000 << 16) | (0x30f08 >> 2),
484 (0x0001 << 16) | (0x30f08 >> 2),
486 (0x0000 << 16) | (0x30f0c >> 2),
488 (0x0001 << 16) | (0x30f0c >> 2),
490 (0x0600 << 16) | (0x9b7c >> 2),
492 (0x0e00 << 16) | (0x8a14 >> 2),
494 (0x0e00 << 16) | (0x8a18 >> 2),
496 (0x0600 << 16) | (0x30a00 >> 2),
498 (0x0e00 << 16) | (0x8bf0 >> 2),
500 (0x0e00 << 16) | (0x8bcc >> 2),
502 (0x0e00 << 16) | (0x8b24 >> 2),
504 (0x0e00 << 16) | (0x30a04 >> 2),
506 (0x0600 << 16) | (0x30a10 >> 2),
508 (0x0600 << 16) | (0x30a14 >> 2),
510 (0x0600 << 16) | (0x30a18 >> 2),
512 (0x0600 << 16) | (0x30a2c >> 2),
514 (0x0e00 << 16) | (0xc700 >> 2),
516 (0x0e00 << 16) | (0xc704 >> 2),
518 (0x0e00 << 16) | (0xc708 >> 2),
520 (0x0e00 << 16) | (0xc768 >> 2),
522 (0x0400 << 16) | (0xc770 >> 2),
524 (0x0400 << 16) | (0xc774 >> 2),
526 (0x0400 << 16) | (0xc778 >> 2),
528 (0x0400 << 16) | (0xc77c >> 2),
530 (0x0400 << 16) | (0xc780 >> 2),
532 (0x0400 << 16) | (0xc784 >> 2),
534 (0x0400 << 16) | (0xc788 >> 2),
536 (0x0400 << 16) | (0xc78c >> 2),
538 (0x0400 << 16) | (0xc798 >> 2),
540 (0x0400 << 16) | (0xc79c >> 2),
542 (0x0400 << 16) | (0xc7a0 >> 2),
544 (0x0400 << 16) | (0xc7a4 >> 2),
546 (0x0400 << 16) | (0xc7a8 >> 2),
548 (0x0400 << 16) | (0xc7ac >> 2),
550 (0x0400 << 16) | (0xc7b0 >> 2),
552 (0x0400 << 16) | (0xc7b4 >> 2),
554 (0x0e00 << 16) | (0x9100 >> 2),
556 (0x0e00 << 16) | (0x3c010 >> 2),
558 (0x0e00 << 16) | (0x92a8 >> 2),
560 (0x0e00 << 16) | (0x92ac >> 2),
562 (0x0e00 << 16) | (0x92b4 >> 2),
564 (0x0e00 << 16) | (0x92b8 >> 2),
566 (0x0e00 << 16) | (0x92bc >> 2),
568 (0x0e00 << 16) | (0x92c0 >> 2),
570 (0x0e00 << 16) | (0x92c4 >> 2),
572 (0x0e00 << 16) | (0x92c8 >> 2),
574 (0x0e00 << 16) | (0x92cc >> 2),
576 (0x0e00 << 16) | (0x92d0 >> 2),
578 (0x0e00 << 16) | (0x8c00 >> 2),
580 (0x0e00 << 16) | (0x8c04 >> 2),
582 (0x0e00 << 16) | (0x8c20 >> 2),
584 (0x0e00 << 16) | (0x8c38 >> 2),
586 (0x0e00 << 16) | (0x8c3c >> 2),
588 (0x0e00 << 16) | (0xae00 >> 2),
590 (0x0e00 << 16) | (0x9604 >> 2),
592 (0x0e00 << 16) | (0xac08 >> 2),
594 (0x0e00 << 16) | (0xac0c >> 2),
596 (0x0e00 << 16) | (0xac10 >> 2),
598 (0x0e00 << 16) | (0xac14 >> 2),
600 (0x0e00 << 16) | (0xac58 >> 2),
602 (0x0e00 << 16) | (0xac68 >> 2),
604 (0x0e00 << 16) | (0xac6c >> 2),
606 (0x0e00 << 16) | (0xac70 >> 2),
608 (0x0e00 << 16) | (0xac74 >> 2),
610 (0x0e00 << 16) | (0xac78 >> 2),
612 (0x0e00 << 16) | (0xac7c >> 2),
614 (0x0e00 << 16) | (0xac80 >> 2),
616 (0x0e00 << 16) | (0xac84 >> 2),
618 (0x0e00 << 16) | (0xac88 >> 2),
620 (0x0e00 << 16) | (0xac8c >> 2),
622 (0x0e00 << 16) | (0x970c >> 2),
624 (0x0e00 << 16) | (0x9714 >> 2),
626 (0x0e00 << 16) | (0x9718 >> 2),
628 (0x0e00 << 16) | (0x971c >> 2),
630 (0x0e00 << 16) | (0x31068 >> 2),
632 (0x4e00 << 16) | (0x31068 >> 2),
634 (0x5e00 << 16) | (0x31068 >> 2),
636 (0x6e00 << 16) | (0x31068 >> 2),
638 (0x7e00 << 16) | (0x31068 >> 2),
640 (0x8e00 << 16) | (0x31068 >> 2),
642 (0x9e00 << 16) | (0x31068 >> 2),
644 (0xae00 << 16) | (0x31068 >> 2),
646 (0xbe00 << 16) | (0x31068 >> 2),
648 (0x0e00 << 16) | (0xcd10 >> 2),
650 (0x0e00 << 16) | (0xcd14 >> 2),
652 (0x0e00 << 16) | (0x88b0 >> 2),
654 (0x0e00 << 16) | (0x88b4 >> 2),
656 (0x0e00 << 16) | (0x88b8 >> 2),
658 (0x0e00 << 16) | (0x88bc >> 2),
660 (0x0400 << 16) | (0x89c0 >> 2),
662 (0x0e00 << 16) | (0x88c4 >> 2),
664 (0x0e00 << 16) | (0x88c8 >> 2),
666 (0x0e00 << 16) | (0x88d0 >> 2),
668 (0x0e00 << 16) | (0x88d4 >> 2),
670 (0x0e00 << 16) | (0x88d8 >> 2),
672 (0x0e00 << 16) | (0x8980 >> 2),
674 (0x0e00 << 16) | (0x30938 >> 2),
676 (0x0e00 << 16) | (0x3093c >> 2),
678 (0x0e00 << 16) | (0x30940 >> 2),
680 (0x0e00 << 16) | (0x89a0 >> 2),
682 (0x0e00 << 16) | (0x30900 >> 2),
684 (0x0e00 << 16) | (0x30904 >> 2),
686 (0x0e00 << 16) | (0x89b4 >> 2),
688 (0x0e00 << 16) | (0x3c210 >> 2),
690 (0x0e00 << 16) | (0x3c214 >> 2),
692 (0x0e00 << 16) | (0x3c218 >> 2),
694 (0x0e00 << 16) | (0x8904 >> 2),
697 (0x0e00 << 16) | (0x8c28 >> 2),
698 (0x0e00 << 16) | (0x8c2c >> 2),
699 (0x0e00 << 16) | (0x8c30 >> 2),
700 (0x0e00 << 16) | (0x8c34 >> 2),
701 (0x0e00 << 16) | (0x9600 >> 2),
704 static const u32 kalindi_rlc_save_restore_register_list[] =
706 (0x0e00 << 16) | (0xc12c >> 2),
708 (0x0e00 << 16) | (0xc140 >> 2),
710 (0x0e00 << 16) | (0xc150 >> 2),
712 (0x0e00 << 16) | (0xc15c >> 2),
714 (0x0e00 << 16) | (0xc168 >> 2),
716 (0x0e00 << 16) | (0xc170 >> 2),
718 (0x0e00 << 16) | (0xc204 >> 2),
720 (0x0e00 << 16) | (0xc2b4 >> 2),
722 (0x0e00 << 16) | (0xc2b8 >> 2),
724 (0x0e00 << 16) | (0xc2bc >> 2),
726 (0x0e00 << 16) | (0xc2c0 >> 2),
728 (0x0e00 << 16) | (0x8228 >> 2),
730 (0x0e00 << 16) | (0x829c >> 2),
732 (0x0e00 << 16) | (0x869c >> 2),
734 (0x0600 << 16) | (0x98f4 >> 2),
736 (0x0e00 << 16) | (0x98f8 >> 2),
738 (0x0e00 << 16) | (0x9900 >> 2),
740 (0x0e00 << 16) | (0xc260 >> 2),
742 (0x0e00 << 16) | (0x90e8 >> 2),
744 (0x0e00 << 16) | (0x3c000 >> 2),
746 (0x0e00 << 16) | (0x3c00c >> 2),
748 (0x0e00 << 16) | (0x8c1c >> 2),
750 (0x0e00 << 16) | (0x9700 >> 2),
752 (0x0e00 << 16) | (0xcd20 >> 2),
754 (0x4e00 << 16) | (0xcd20 >> 2),
756 (0x5e00 << 16) | (0xcd20 >> 2),
758 (0x6e00 << 16) | (0xcd20 >> 2),
760 (0x7e00 << 16) | (0xcd20 >> 2),
762 (0x0e00 << 16) | (0x89bc >> 2),
764 (0x0e00 << 16) | (0x8900 >> 2),
767 (0x0e00 << 16) | (0xc130 >> 2),
769 (0x0e00 << 16) | (0xc134 >> 2),
771 (0x0e00 << 16) | (0xc1fc >> 2),
773 (0x0e00 << 16) | (0xc208 >> 2),
775 (0x0e00 << 16) | (0xc264 >> 2),
777 (0x0e00 << 16) | (0xc268 >> 2),
779 (0x0e00 << 16) | (0xc26c >> 2),
781 (0x0e00 << 16) | (0xc270 >> 2),
783 (0x0e00 << 16) | (0xc274 >> 2),
785 (0x0e00 << 16) | (0xc28c >> 2),
787 (0x0e00 << 16) | (0xc290 >> 2),
789 (0x0e00 << 16) | (0xc294 >> 2),
791 (0x0e00 << 16) | (0xc298 >> 2),
793 (0x0e00 << 16) | (0xc2a0 >> 2),
795 (0x0e00 << 16) | (0xc2a4 >> 2),
797 (0x0e00 << 16) | (0xc2a8 >> 2),
799 (0x0e00 << 16) | (0xc2ac >> 2),
801 (0x0e00 << 16) | (0x301d0 >> 2),
803 (0x0e00 << 16) | (0x30238 >> 2),
805 (0x0e00 << 16) | (0x30250 >> 2),
807 (0x0e00 << 16) | (0x30254 >> 2),
809 (0x0e00 << 16) | (0x30258 >> 2),
811 (0x0e00 << 16) | (0x3025c >> 2),
813 (0x4e00 << 16) | (0xc900 >> 2),
815 (0x5e00 << 16) | (0xc900 >> 2),
817 (0x6e00 << 16) | (0xc900 >> 2),
819 (0x7e00 << 16) | (0xc900 >> 2),
821 (0x4e00 << 16) | (0xc904 >> 2),
823 (0x5e00 << 16) | (0xc904 >> 2),
825 (0x6e00 << 16) | (0xc904 >> 2),
827 (0x7e00 << 16) | (0xc904 >> 2),
829 (0x4e00 << 16) | (0xc908 >> 2),
831 (0x5e00 << 16) | (0xc908 >> 2),
833 (0x6e00 << 16) | (0xc908 >> 2),
835 (0x7e00 << 16) | (0xc908 >> 2),
837 (0x4e00 << 16) | (0xc90c >> 2),
839 (0x5e00 << 16) | (0xc90c >> 2),
841 (0x6e00 << 16) | (0xc90c >> 2),
843 (0x7e00 << 16) | (0xc90c >> 2),
845 (0x4e00 << 16) | (0xc910 >> 2),
847 (0x5e00 << 16) | (0xc910 >> 2),
849 (0x6e00 << 16) | (0xc910 >> 2),
851 (0x7e00 << 16) | (0xc910 >> 2),
853 (0x0e00 << 16) | (0xc99c >> 2),
855 (0x0e00 << 16) | (0x9834 >> 2),
857 (0x0000 << 16) | (0x30f00 >> 2),
859 (0x0000 << 16) | (0x30f04 >> 2),
861 (0x0000 << 16) | (0x30f08 >> 2),
863 (0x0000 << 16) | (0x30f0c >> 2),
865 (0x0600 << 16) | (0x9b7c >> 2),
867 (0x0e00 << 16) | (0x8a14 >> 2),
869 (0x0e00 << 16) | (0x8a18 >> 2),
871 (0x0600 << 16) | (0x30a00 >> 2),
873 (0x0e00 << 16) | (0x8bf0 >> 2),
875 (0x0e00 << 16) | (0x8bcc >> 2),
877 (0x0e00 << 16) | (0x8b24 >> 2),
879 (0x0e00 << 16) | (0x30a04 >> 2),
881 (0x0600 << 16) | (0x30a10 >> 2),
883 (0x0600 << 16) | (0x30a14 >> 2),
885 (0x0600 << 16) | (0x30a18 >> 2),
887 (0x0600 << 16) | (0x30a2c >> 2),
889 (0x0e00 << 16) | (0xc700 >> 2),
891 (0x0e00 << 16) | (0xc704 >> 2),
893 (0x0e00 << 16) | (0xc708 >> 2),
895 (0x0e00 << 16) | (0xc768 >> 2),
897 (0x0400 << 16) | (0xc770 >> 2),
899 (0x0400 << 16) | (0xc774 >> 2),
901 (0x0400 << 16) | (0xc798 >> 2),
903 (0x0400 << 16) | (0xc79c >> 2),
905 (0x0e00 << 16) | (0x9100 >> 2),
907 (0x0e00 << 16) | (0x3c010 >> 2),
909 (0x0e00 << 16) | (0x8c00 >> 2),
911 (0x0e00 << 16) | (0x8c04 >> 2),
913 (0x0e00 << 16) | (0x8c20 >> 2),
915 (0x0e00 << 16) | (0x8c38 >> 2),
917 (0x0e00 << 16) | (0x8c3c >> 2),
919 (0x0e00 << 16) | (0xae00 >> 2),
921 (0x0e00 << 16) | (0x9604 >> 2),
923 (0x0e00 << 16) | (0xac08 >> 2),
925 (0x0e00 << 16) | (0xac0c >> 2),
927 (0x0e00 << 16) | (0xac10 >> 2),
929 (0x0e00 << 16) | (0xac14 >> 2),
931 (0x0e00 << 16) | (0xac58 >> 2),
933 (0x0e00 << 16) | (0xac68 >> 2),
935 (0x0e00 << 16) | (0xac6c >> 2),
937 (0x0e00 << 16) | (0xac70 >> 2),
939 (0x0e00 << 16) | (0xac74 >> 2),
941 (0x0e00 << 16) | (0xac78 >> 2),
943 (0x0e00 << 16) | (0xac7c >> 2),
945 (0x0e00 << 16) | (0xac80 >> 2),
947 (0x0e00 << 16) | (0xac84 >> 2),
949 (0x0e00 << 16) | (0xac88 >> 2),
951 (0x0e00 << 16) | (0xac8c >> 2),
953 (0x0e00 << 16) | (0x970c >> 2),
955 (0x0e00 << 16) | (0x9714 >> 2),
957 (0x0e00 << 16) | (0x9718 >> 2),
959 (0x0e00 << 16) | (0x971c >> 2),
961 (0x0e00 << 16) | (0x31068 >> 2),
963 (0x4e00 << 16) | (0x31068 >> 2),
965 (0x5e00 << 16) | (0x31068 >> 2),
967 (0x6e00 << 16) | (0x31068 >> 2),
969 (0x7e00 << 16) | (0x31068 >> 2),
971 (0x0e00 << 16) | (0xcd10 >> 2),
973 (0x0e00 << 16) | (0xcd14 >> 2),
975 (0x0e00 << 16) | (0x88b0 >> 2),
977 (0x0e00 << 16) | (0x88b4 >> 2),
979 (0x0e00 << 16) | (0x88b8 >> 2),
981 (0x0e00 << 16) | (0x88bc >> 2),
983 (0x0400 << 16) | (0x89c0 >> 2),
985 (0x0e00 << 16) | (0x88c4 >> 2),
987 (0x0e00 << 16) | (0x88c8 >> 2),
989 (0x0e00 << 16) | (0x88d0 >> 2),
991 (0x0e00 << 16) | (0x88d4 >> 2),
993 (0x0e00 << 16) | (0x88d8 >> 2),
995 (0x0e00 << 16) | (0x8980 >> 2),
997 (0x0e00 << 16) | (0x30938 >> 2),
999 (0x0e00 << 16) | (0x3093c >> 2),
1001 (0x0e00 << 16) | (0x30940 >> 2),
1003 (0x0e00 << 16) | (0x89a0 >> 2),
1005 (0x0e00 << 16) | (0x30900 >> 2),
1007 (0x0e00 << 16) | (0x30904 >> 2),
1009 (0x0e00 << 16) | (0x89b4 >> 2),
1011 (0x0e00 << 16) | (0x3e1fc >> 2),
1013 (0x0e00 << 16) | (0x3c210 >> 2),
1015 (0x0e00 << 16) | (0x3c214 >> 2),
1017 (0x0e00 << 16) | (0x3c218 >> 2),
1019 (0x0e00 << 16) | (0x8904 >> 2),
1022 (0x0e00 << 16) | (0x8c28 >> 2),
1023 (0x0e00 << 16) | (0x8c2c >> 2),
1024 (0x0e00 << 16) | (0x8c30 >> 2),
1025 (0x0e00 << 16) | (0x8c34 >> 2),
1026 (0x0e00 << 16) | (0x9600 >> 2),
1029 static const u32 bonaire_golden_spm_registers[] =
1031 0x30800, 0xe0ffffff, 0xe0000000
1034 static const u32 bonaire_golden_common_registers[] =
1036 0xc770, 0xffffffff, 0x00000800,
1037 0xc774, 0xffffffff, 0x00000800,
1038 0xc798, 0xffffffff, 0x00007fbf,
1039 0xc79c, 0xffffffff, 0x00007faf
1042 static const u32 bonaire_golden_registers[] =
1044 0x3354, 0x00000333, 0x00000333,
1045 0x3350, 0x000c0fc0, 0x00040200,
1046 0x9a10, 0x00010000, 0x00058208,
1047 0x3c000, 0xffff1fff, 0x00140000,
1048 0x3c200, 0xfdfc0fff, 0x00000100,
1049 0x3c234, 0x40000000, 0x40000200,
1050 0x9830, 0xffffffff, 0x00000000,
1051 0x9834, 0xf00fffff, 0x00000400,
1052 0x9838, 0x0002021c, 0x00020200,
1053 0xc78, 0x00000080, 0x00000000,
1054 0x5bb0, 0x000000f0, 0x00000070,
1055 0x5bc0, 0xf0311fff, 0x80300000,
1056 0x98f8, 0x73773777, 0x12010001,
1057 0x350c, 0x00810000, 0x408af000,
1058 0x7030, 0x31000111, 0x00000011,
1059 0x2f48, 0x73773777, 0x12010001,
1060 0x220c, 0x00007fb6, 0x0021a1b1,
1061 0x2210, 0x00007fb6, 0x002021b1,
1062 0x2180, 0x00007fb6, 0x00002191,
1063 0x2218, 0x00007fb6, 0x002121b1,
1064 0x221c, 0x00007fb6, 0x002021b1,
1065 0x21dc, 0x00007fb6, 0x00002191,
1066 0x21e0, 0x00007fb6, 0x00002191,
1067 0x3628, 0x0000003f, 0x0000000a,
1068 0x362c, 0x0000003f, 0x0000000a,
1069 0x2ae4, 0x00073ffe, 0x000022a2,
1070 0x240c, 0x000007ff, 0x00000000,
1071 0x8a14, 0xf000003f, 0x00000007,
1072 0x8bf0, 0x00002001, 0x00000001,
1073 0x8b24, 0xffffffff, 0x00ffffff,
1074 0x30a04, 0x0000ff0f, 0x00000000,
1075 0x28a4c, 0x07ffffff, 0x06000000,
1076 0x4d8, 0x00000fff, 0x00000100,
1077 0x3e78, 0x00000001, 0x00000002,
1078 0x9100, 0x03000000, 0x0362c688,
1079 0x8c00, 0x000000ff, 0x00000001,
1080 0xe40, 0x00001fff, 0x00001fff,
1081 0x9060, 0x0000007f, 0x00000020,
1082 0x9508, 0x00010000, 0x00010000,
1083 0xac14, 0x000003ff, 0x000000f3,
1084 0xac0c, 0xffffffff, 0x00001032
1087 static const u32 bonaire_mgcg_cgcg_init[] =
1089 0xc420, 0xffffffff, 0xfffffffc,
1090 0x30800, 0xffffffff, 0xe0000000,
1091 0x3c2a0, 0xffffffff, 0x00000100,
1092 0x3c208, 0xffffffff, 0x00000100,
1093 0x3c2c0, 0xffffffff, 0xc0000100,
1094 0x3c2c8, 0xffffffff, 0xc0000100,
1095 0x3c2c4, 0xffffffff, 0xc0000100,
1096 0x55e4, 0xffffffff, 0x00600100,
1097 0x3c280, 0xffffffff, 0x00000100,
1098 0x3c214, 0xffffffff, 0x06000100,
1099 0x3c220, 0xffffffff, 0x00000100,
1100 0x3c218, 0xffffffff, 0x06000100,
1101 0x3c204, 0xffffffff, 0x00000100,
1102 0x3c2e0, 0xffffffff, 0x00000100,
1103 0x3c224, 0xffffffff, 0x00000100,
1104 0x3c200, 0xffffffff, 0x00000100,
1105 0x3c230, 0xffffffff, 0x00000100,
1106 0x3c234, 0xffffffff, 0x00000100,
1107 0x3c250, 0xffffffff, 0x00000100,
1108 0x3c254, 0xffffffff, 0x00000100,
1109 0x3c258, 0xffffffff, 0x00000100,
1110 0x3c25c, 0xffffffff, 0x00000100,
1111 0x3c260, 0xffffffff, 0x00000100,
1112 0x3c27c, 0xffffffff, 0x00000100,
1113 0x3c278, 0xffffffff, 0x00000100,
1114 0x3c210, 0xffffffff, 0x06000100,
1115 0x3c290, 0xffffffff, 0x00000100,
1116 0x3c274, 0xffffffff, 0x00000100,
1117 0x3c2b4, 0xffffffff, 0x00000100,
1118 0x3c2b0, 0xffffffff, 0x00000100,
1119 0x3c270, 0xffffffff, 0x00000100,
1120 0x30800, 0xffffffff, 0xe0000000,
1121 0x3c020, 0xffffffff, 0x00010000,
1122 0x3c024, 0xffffffff, 0x00030002,
1123 0x3c028, 0xffffffff, 0x00040007,
1124 0x3c02c, 0xffffffff, 0x00060005,
1125 0x3c030, 0xffffffff, 0x00090008,
1126 0x3c034, 0xffffffff, 0x00010000,
1127 0x3c038, 0xffffffff, 0x00030002,
1128 0x3c03c, 0xffffffff, 0x00040007,
1129 0x3c040, 0xffffffff, 0x00060005,
1130 0x3c044, 0xffffffff, 0x00090008,
1131 0x3c048, 0xffffffff, 0x00010000,
1132 0x3c04c, 0xffffffff, 0x00030002,
1133 0x3c050, 0xffffffff, 0x00040007,
1134 0x3c054, 0xffffffff, 0x00060005,
1135 0x3c058, 0xffffffff, 0x00090008,
1136 0x3c05c, 0xffffffff, 0x00010000,
1137 0x3c060, 0xffffffff, 0x00030002,
1138 0x3c064, 0xffffffff, 0x00040007,
1139 0x3c068, 0xffffffff, 0x00060005,
1140 0x3c06c, 0xffffffff, 0x00090008,
1141 0x3c070, 0xffffffff, 0x00010000,
1142 0x3c074, 0xffffffff, 0x00030002,
1143 0x3c078, 0xffffffff, 0x00040007,
1144 0x3c07c, 0xffffffff, 0x00060005,
1145 0x3c080, 0xffffffff, 0x00090008,
1146 0x3c084, 0xffffffff, 0x00010000,
1147 0x3c088, 0xffffffff, 0x00030002,
1148 0x3c08c, 0xffffffff, 0x00040007,
1149 0x3c090, 0xffffffff, 0x00060005,
1150 0x3c094, 0xffffffff, 0x00090008,
1151 0x3c098, 0xffffffff, 0x00010000,
1152 0x3c09c, 0xffffffff, 0x00030002,
1153 0x3c0a0, 0xffffffff, 0x00040007,
1154 0x3c0a4, 0xffffffff, 0x00060005,
1155 0x3c0a8, 0xffffffff, 0x00090008,
1156 0x3c000, 0xffffffff, 0x96e00200,
1157 0x8708, 0xffffffff, 0x00900100,
1158 0xc424, 0xffffffff, 0x0020003f,
1159 0x38, 0xffffffff, 0x0140001c,
1160 0x3c, 0x000f0000, 0x000f0000,
1161 0x220, 0xffffffff, 0xC060000C,
1162 0x224, 0xc0000fff, 0x00000100,
1163 0xf90, 0xffffffff, 0x00000100,
1164 0xf98, 0x00000101, 0x00000000,
1165 0x20a8, 0xffffffff, 0x00000104,
1166 0x55e4, 0xff000fff, 0x00000100,
1167 0x30cc, 0xc0000fff, 0x00000104,
1168 0xc1e4, 0x00000001, 0x00000001,
1169 0xd00c, 0xff000ff0, 0x00000100,
1170 0xd80c, 0xff000ff0, 0x00000100
1173 static const u32 spectre_golden_spm_registers[] =
1175 0x30800, 0xe0ffffff, 0xe0000000
1178 static const u32 spectre_golden_common_registers[] =
1180 0xc770, 0xffffffff, 0x00000800,
1181 0xc774, 0xffffffff, 0x00000800,
1182 0xc798, 0xffffffff, 0x00007fbf,
1183 0xc79c, 0xffffffff, 0x00007faf
1186 static const u32 spectre_golden_registers[] =
1188 0x3c000, 0xffff1fff, 0x96940200,
1189 0x3c00c, 0xffff0001, 0xff000000,
1190 0x3c200, 0xfffc0fff, 0x00000100,
1191 0x6ed8, 0x00010101, 0x00010000,
1192 0x9834, 0xf00fffff, 0x00000400,
1193 0x9838, 0xfffffffc, 0x00020200,
1194 0x5bb0, 0x000000f0, 0x00000070,
1195 0x5bc0, 0xf0311fff, 0x80300000,
1196 0x98f8, 0x73773777, 0x12010001,
1197 0x9b7c, 0x00ff0000, 0x00fc0000,
1198 0x2f48, 0x73773777, 0x12010001,
1199 0x8a14, 0xf000003f, 0x00000007,
1200 0x8b24, 0xffffffff, 0x00ffffff,
1201 0x28350, 0x3f3f3fff, 0x00000082,
1202 0x28354, 0x0000003f, 0x00000000,
1203 0x3e78, 0x00000001, 0x00000002,
1204 0x913c, 0xffff03df, 0x00000004,
1205 0xc768, 0x00000008, 0x00000008,
1206 0x8c00, 0x000008ff, 0x00000800,
1207 0x9508, 0x00010000, 0x00010000,
1208 0xac0c, 0xffffffff, 0x54763210,
1209 0x214f8, 0x01ff01ff, 0x00000002,
1210 0x21498, 0x007ff800, 0x00200000,
1211 0x2015c, 0xffffffff, 0x00000f40,
1212 0x30934, 0xffffffff, 0x00000001
1215 static const u32 spectre_mgcg_cgcg_init[] =
1217 0xc420, 0xffffffff, 0xfffffffc,
1218 0x30800, 0xffffffff, 0xe0000000,
1219 0x3c2a0, 0xffffffff, 0x00000100,
1220 0x3c208, 0xffffffff, 0x00000100,
1221 0x3c2c0, 0xffffffff, 0x00000100,
1222 0x3c2c8, 0xffffffff, 0x00000100,
1223 0x3c2c4, 0xffffffff, 0x00000100,
1224 0x55e4, 0xffffffff, 0x00600100,
1225 0x3c280, 0xffffffff, 0x00000100,
1226 0x3c214, 0xffffffff, 0x06000100,
1227 0x3c220, 0xffffffff, 0x00000100,
1228 0x3c218, 0xffffffff, 0x06000100,
1229 0x3c204, 0xffffffff, 0x00000100,
1230 0x3c2e0, 0xffffffff, 0x00000100,
1231 0x3c224, 0xffffffff, 0x00000100,
1232 0x3c200, 0xffffffff, 0x00000100,
1233 0x3c230, 0xffffffff, 0x00000100,
1234 0x3c234, 0xffffffff, 0x00000100,
1235 0x3c250, 0xffffffff, 0x00000100,
1236 0x3c254, 0xffffffff, 0x00000100,
1237 0x3c258, 0xffffffff, 0x00000100,
1238 0x3c25c, 0xffffffff, 0x00000100,
1239 0x3c260, 0xffffffff, 0x00000100,
1240 0x3c27c, 0xffffffff, 0x00000100,
1241 0x3c278, 0xffffffff, 0x00000100,
1242 0x3c210, 0xffffffff, 0x06000100,
1243 0x3c290, 0xffffffff, 0x00000100,
1244 0x3c274, 0xffffffff, 0x00000100,
1245 0x3c2b4, 0xffffffff, 0x00000100,
1246 0x3c2b0, 0xffffffff, 0x00000100,
1247 0x3c270, 0xffffffff, 0x00000100,
1248 0x30800, 0xffffffff, 0xe0000000,
1249 0x3c020, 0xffffffff, 0x00010000,
1250 0x3c024, 0xffffffff, 0x00030002,
1251 0x3c028, 0xffffffff, 0x00040007,
1252 0x3c02c, 0xffffffff, 0x00060005,
1253 0x3c030, 0xffffffff, 0x00090008,
1254 0x3c034, 0xffffffff, 0x00010000,
1255 0x3c038, 0xffffffff, 0x00030002,
1256 0x3c03c, 0xffffffff, 0x00040007,
1257 0x3c040, 0xffffffff, 0x00060005,
1258 0x3c044, 0xffffffff, 0x00090008,
1259 0x3c048, 0xffffffff, 0x00010000,
1260 0x3c04c, 0xffffffff, 0x00030002,
1261 0x3c050, 0xffffffff, 0x00040007,
1262 0x3c054, 0xffffffff, 0x00060005,
1263 0x3c058, 0xffffffff, 0x00090008,
1264 0x3c05c, 0xffffffff, 0x00010000,
1265 0x3c060, 0xffffffff, 0x00030002,
1266 0x3c064, 0xffffffff, 0x00040007,
1267 0x3c068, 0xffffffff, 0x00060005,
1268 0x3c06c, 0xffffffff, 0x00090008,
1269 0x3c070, 0xffffffff, 0x00010000,
1270 0x3c074, 0xffffffff, 0x00030002,
1271 0x3c078, 0xffffffff, 0x00040007,
1272 0x3c07c, 0xffffffff, 0x00060005,
1273 0x3c080, 0xffffffff, 0x00090008,
1274 0x3c084, 0xffffffff, 0x00010000,
1275 0x3c088, 0xffffffff, 0x00030002,
1276 0x3c08c, 0xffffffff, 0x00040007,
1277 0x3c090, 0xffffffff, 0x00060005,
1278 0x3c094, 0xffffffff, 0x00090008,
1279 0x3c098, 0xffffffff, 0x00010000,
1280 0x3c09c, 0xffffffff, 0x00030002,
1281 0x3c0a0, 0xffffffff, 0x00040007,
1282 0x3c0a4, 0xffffffff, 0x00060005,
1283 0x3c0a8, 0xffffffff, 0x00090008,
1284 0x3c0ac, 0xffffffff, 0x00010000,
1285 0x3c0b0, 0xffffffff, 0x00030002,
1286 0x3c0b4, 0xffffffff, 0x00040007,
1287 0x3c0b8, 0xffffffff, 0x00060005,
1288 0x3c0bc, 0xffffffff, 0x00090008,
1289 0x3c000, 0xffffffff, 0x96e00200,
1290 0x8708, 0xffffffff, 0x00900100,
1291 0xc424, 0xffffffff, 0x0020003f,
1292 0x38, 0xffffffff, 0x0140001c,
1293 0x3c, 0x000f0000, 0x000f0000,
1294 0x220, 0xffffffff, 0xC060000C,
1295 0x224, 0xc0000fff, 0x00000100,
1296 0xf90, 0xffffffff, 0x00000100,
1297 0xf98, 0x00000101, 0x00000000,
1298 0x20a8, 0xffffffff, 0x00000104,
1299 0x55e4, 0xff000fff, 0x00000100,
1300 0x30cc, 0xc0000fff, 0x00000104,
1301 0xc1e4, 0x00000001, 0x00000001,
1302 0xd00c, 0xff000ff0, 0x00000100,
1303 0xd80c, 0xff000ff0, 0x00000100
1306 static const u32 kalindi_golden_spm_registers[] =
1308 0x30800, 0xe0ffffff, 0xe0000000
1311 static const u32 kalindi_golden_common_registers[] =
1313 0xc770, 0xffffffff, 0x00000800,
1314 0xc774, 0xffffffff, 0x00000800,
1315 0xc798, 0xffffffff, 0x00007fbf,
1316 0xc79c, 0xffffffff, 0x00007faf
1319 static const u32 kalindi_golden_registers[] =
1321 0x3c000, 0xffffdfff, 0x6e944040,
1322 0x55e4, 0xff607fff, 0xfc000100,
1323 0x3c220, 0xff000fff, 0x00000100,
1324 0x3c224, 0xff000fff, 0x00000100,
1325 0x3c200, 0xfffc0fff, 0x00000100,
1326 0x6ed8, 0x00010101, 0x00010000,
1327 0x9830, 0xffffffff, 0x00000000,
1328 0x9834, 0xf00fffff, 0x00000400,
1329 0x5bb0, 0x000000f0, 0x00000070,
1330 0x5bc0, 0xf0311fff, 0x80300000,
1331 0x98f8, 0x73773777, 0x12010001,
1332 0x98fc, 0xffffffff, 0x00000010,
1333 0x9b7c, 0x00ff0000, 0x00fc0000,
1334 0x8030, 0x00001f0f, 0x0000100a,
1335 0x2f48, 0x73773777, 0x12010001,
1336 0x2408, 0x000fffff, 0x000c007f,
1337 0x8a14, 0xf000003f, 0x00000007,
1338 0x8b24, 0x3fff3fff, 0x00ffcfff,
1339 0x30a04, 0x0000ff0f, 0x00000000,
1340 0x28a4c, 0x07ffffff, 0x06000000,
1341 0x4d8, 0x00000fff, 0x00000100,
1342 0x3e78, 0x00000001, 0x00000002,
1343 0xc768, 0x00000008, 0x00000008,
1344 0x8c00, 0x000000ff, 0x00000003,
1345 0x214f8, 0x01ff01ff, 0x00000002,
1346 0x21498, 0x007ff800, 0x00200000,
1347 0x2015c, 0xffffffff, 0x00000f40,
1348 0x88c4, 0x001f3ae3, 0x00000082,
1349 0x88d4, 0x0000001f, 0x00000010,
1350 0x30934, 0xffffffff, 0x00000000
1353 static const u32 kalindi_mgcg_cgcg_init[] =
1355 0xc420, 0xffffffff, 0xfffffffc,
1356 0x30800, 0xffffffff, 0xe0000000,
1357 0x3c2a0, 0xffffffff, 0x00000100,
1358 0x3c208, 0xffffffff, 0x00000100,
1359 0x3c2c0, 0xffffffff, 0x00000100,
1360 0x3c2c8, 0xffffffff, 0x00000100,
1361 0x3c2c4, 0xffffffff, 0x00000100,
1362 0x55e4, 0xffffffff, 0x00600100,
1363 0x3c280, 0xffffffff, 0x00000100,
1364 0x3c214, 0xffffffff, 0x06000100,
1365 0x3c220, 0xffffffff, 0x00000100,
1366 0x3c218, 0xffffffff, 0x06000100,
1367 0x3c204, 0xffffffff, 0x00000100,
1368 0x3c2e0, 0xffffffff, 0x00000100,
1369 0x3c224, 0xffffffff, 0x00000100,
1370 0x3c200, 0xffffffff, 0x00000100,
1371 0x3c230, 0xffffffff, 0x00000100,
1372 0x3c234, 0xffffffff, 0x00000100,
1373 0x3c250, 0xffffffff, 0x00000100,
1374 0x3c254, 0xffffffff, 0x00000100,
1375 0x3c258, 0xffffffff, 0x00000100,
1376 0x3c25c, 0xffffffff, 0x00000100,
1377 0x3c260, 0xffffffff, 0x00000100,
1378 0x3c27c, 0xffffffff, 0x00000100,
1379 0x3c278, 0xffffffff, 0x00000100,
1380 0x3c210, 0xffffffff, 0x06000100,
1381 0x3c290, 0xffffffff, 0x00000100,
1382 0x3c274, 0xffffffff, 0x00000100,
1383 0x3c2b4, 0xffffffff, 0x00000100,
1384 0x3c2b0, 0xffffffff, 0x00000100,
1385 0x3c270, 0xffffffff, 0x00000100,
1386 0x30800, 0xffffffff, 0xe0000000,
1387 0x3c020, 0xffffffff, 0x00010000,
1388 0x3c024, 0xffffffff, 0x00030002,
1389 0x3c028, 0xffffffff, 0x00040007,
1390 0x3c02c, 0xffffffff, 0x00060005,
1391 0x3c030, 0xffffffff, 0x00090008,
1392 0x3c034, 0xffffffff, 0x00010000,
1393 0x3c038, 0xffffffff, 0x00030002,
1394 0x3c03c, 0xffffffff, 0x00040007,
1395 0x3c040, 0xffffffff, 0x00060005,
1396 0x3c044, 0xffffffff, 0x00090008,
1397 0x3c000, 0xffffffff, 0x96e00200,
1398 0x8708, 0xffffffff, 0x00900100,
1399 0xc424, 0xffffffff, 0x0020003f,
1400 0x38, 0xffffffff, 0x0140001c,
1401 0x3c, 0x000f0000, 0x000f0000,
1402 0x220, 0xffffffff, 0xC060000C,
1403 0x224, 0xc0000fff, 0x00000100,
1404 0x20a8, 0xffffffff, 0x00000104,
1405 0x55e4, 0xff000fff, 0x00000100,
1406 0x30cc, 0xc0000fff, 0x00000104,
1407 0xc1e4, 0x00000001, 0x00000001,
1408 0xd00c, 0xff000ff0, 0x00000100,
1409 0xd80c, 0xff000ff0, 0x00000100
1412 static const u32 hawaii_golden_spm_registers[] =
1414 0x30800, 0xe0ffffff, 0xe0000000
1417 static const u32 hawaii_golden_common_registers[] =
1419 0x30800, 0xffffffff, 0xe0000000,
1420 0x28350, 0xffffffff, 0x3a00161a,
1421 0x28354, 0xffffffff, 0x0000002e,
1422 0x9a10, 0xffffffff, 0x00018208,
1423 0x98f8, 0xffffffff, 0x12011003
1426 static const u32 hawaii_golden_registers[] =
1428 0x3354, 0x00000333, 0x00000333,
1429 0x9a10, 0x00010000, 0x00058208,
1430 0x9830, 0xffffffff, 0x00000000,
1431 0x9834, 0xf00fffff, 0x00000400,
1432 0x9838, 0x0002021c, 0x00020200,
1433 0xc78, 0x00000080, 0x00000000,
1434 0x5bb0, 0x000000f0, 0x00000070,
1435 0x5bc0, 0xf0311fff, 0x80300000,
1436 0x350c, 0x00810000, 0x408af000,
1437 0x7030, 0x31000111, 0x00000011,
1438 0x2f48, 0x73773777, 0x12010001,
1439 0x2120, 0x0000007f, 0x0000001b,
1440 0x21dc, 0x00007fb6, 0x00002191,
1441 0x3628, 0x0000003f, 0x0000000a,
1442 0x362c, 0x0000003f, 0x0000000a,
1443 0x2ae4, 0x00073ffe, 0x000022a2,
1444 0x240c, 0x000007ff, 0x00000000,
1445 0x8bf0, 0x00002001, 0x00000001,
1446 0x8b24, 0xffffffff, 0x00ffffff,
1447 0x30a04, 0x0000ff0f, 0x00000000,
1448 0x28a4c, 0x07ffffff, 0x06000000,
1449 0x3e78, 0x00000001, 0x00000002,
1450 0xc768, 0x00000008, 0x00000008,
1451 0xc770, 0x00000f00, 0x00000800,
1452 0xc774, 0x00000f00, 0x00000800,
1453 0xc798, 0x00ffffff, 0x00ff7fbf,
1454 0xc79c, 0x00ffffff, 0x00ff7faf,
1455 0x8c00, 0x000000ff, 0x00000800,
1456 0xe40, 0x00001fff, 0x00001fff,
1457 0x9060, 0x0000007f, 0x00000020,
1458 0x9508, 0x00010000, 0x00010000,
1459 0xae00, 0x00100000, 0x000ff07c,
1460 0xac14, 0x000003ff, 0x0000000f,
1461 0xac10, 0xffffffff, 0x7564fdec,
1462 0xac0c, 0xffffffff, 0x3120b9a8,
1463 0xac08, 0x20000000, 0x0f9c0000
1466 static const u32 hawaii_mgcg_cgcg_init[] =
1468 0xc420, 0xffffffff, 0xfffffffd,
1469 0x30800, 0xffffffff, 0xe0000000,
1470 0x3c2a0, 0xffffffff, 0x00000100,
1471 0x3c208, 0xffffffff, 0x00000100,
1472 0x3c2c0, 0xffffffff, 0x00000100,
1473 0x3c2c8, 0xffffffff, 0x00000100,
1474 0x3c2c4, 0xffffffff, 0x00000100,
1475 0x55e4, 0xffffffff, 0x00200100,
1476 0x3c280, 0xffffffff, 0x00000100,
1477 0x3c214, 0xffffffff, 0x06000100,
1478 0x3c220, 0xffffffff, 0x00000100,
1479 0x3c218, 0xffffffff, 0x06000100,
1480 0x3c204, 0xffffffff, 0x00000100,
1481 0x3c2e0, 0xffffffff, 0x00000100,
1482 0x3c224, 0xffffffff, 0x00000100,
1483 0x3c200, 0xffffffff, 0x00000100,
1484 0x3c230, 0xffffffff, 0x00000100,
1485 0x3c234, 0xffffffff, 0x00000100,
1486 0x3c250, 0xffffffff, 0x00000100,
1487 0x3c254, 0xffffffff, 0x00000100,
1488 0x3c258, 0xffffffff, 0x00000100,
1489 0x3c25c, 0xffffffff, 0x00000100,
1490 0x3c260, 0xffffffff, 0x00000100,
1491 0x3c27c, 0xffffffff, 0x00000100,
1492 0x3c278, 0xffffffff, 0x00000100,
1493 0x3c210, 0xffffffff, 0x06000100,
1494 0x3c290, 0xffffffff, 0x00000100,
1495 0x3c274, 0xffffffff, 0x00000100,
1496 0x3c2b4, 0xffffffff, 0x00000100,
1497 0x3c2b0, 0xffffffff, 0x00000100,
1498 0x3c270, 0xffffffff, 0x00000100,
1499 0x30800, 0xffffffff, 0xe0000000,
1500 0x3c020, 0xffffffff, 0x00010000,
1501 0x3c024, 0xffffffff, 0x00030002,
1502 0x3c028, 0xffffffff, 0x00040007,
1503 0x3c02c, 0xffffffff, 0x00060005,
1504 0x3c030, 0xffffffff, 0x00090008,
1505 0x3c034, 0xffffffff, 0x00010000,
1506 0x3c038, 0xffffffff, 0x00030002,
1507 0x3c03c, 0xffffffff, 0x00040007,
1508 0x3c040, 0xffffffff, 0x00060005,
1509 0x3c044, 0xffffffff, 0x00090008,
1510 0x3c048, 0xffffffff, 0x00010000,
1511 0x3c04c, 0xffffffff, 0x00030002,
1512 0x3c050, 0xffffffff, 0x00040007,
1513 0x3c054, 0xffffffff, 0x00060005,
1514 0x3c058, 0xffffffff, 0x00090008,
1515 0x3c05c, 0xffffffff, 0x00010000,
1516 0x3c060, 0xffffffff, 0x00030002,
1517 0x3c064, 0xffffffff, 0x00040007,
1518 0x3c068, 0xffffffff, 0x00060005,
1519 0x3c06c, 0xffffffff, 0x00090008,
1520 0x3c070, 0xffffffff, 0x00010000,
1521 0x3c074, 0xffffffff, 0x00030002,
1522 0x3c078, 0xffffffff, 0x00040007,
1523 0x3c07c, 0xffffffff, 0x00060005,
1524 0x3c080, 0xffffffff, 0x00090008,
1525 0x3c084, 0xffffffff, 0x00010000,
1526 0x3c088, 0xffffffff, 0x00030002,
1527 0x3c08c, 0xffffffff, 0x00040007,
1528 0x3c090, 0xffffffff, 0x00060005,
1529 0x3c094, 0xffffffff, 0x00090008,
1530 0x3c098, 0xffffffff, 0x00010000,
1531 0x3c09c, 0xffffffff, 0x00030002,
1532 0x3c0a0, 0xffffffff, 0x00040007,
1533 0x3c0a4, 0xffffffff, 0x00060005,
1534 0x3c0a8, 0xffffffff, 0x00090008,
1535 0x3c0ac, 0xffffffff, 0x00010000,
1536 0x3c0b0, 0xffffffff, 0x00030002,
1537 0x3c0b4, 0xffffffff, 0x00040007,
1538 0x3c0b8, 0xffffffff, 0x00060005,
1539 0x3c0bc, 0xffffffff, 0x00090008,
1540 0x3c0c0, 0xffffffff, 0x00010000,
1541 0x3c0c4, 0xffffffff, 0x00030002,
1542 0x3c0c8, 0xffffffff, 0x00040007,
1543 0x3c0cc, 0xffffffff, 0x00060005,
1544 0x3c0d0, 0xffffffff, 0x00090008,
1545 0x3c0d4, 0xffffffff, 0x00010000,
1546 0x3c0d8, 0xffffffff, 0x00030002,
1547 0x3c0dc, 0xffffffff, 0x00040007,
1548 0x3c0e0, 0xffffffff, 0x00060005,
1549 0x3c0e4, 0xffffffff, 0x00090008,
1550 0x3c0e8, 0xffffffff, 0x00010000,
1551 0x3c0ec, 0xffffffff, 0x00030002,
1552 0x3c0f0, 0xffffffff, 0x00040007,
1553 0x3c0f4, 0xffffffff, 0x00060005,
1554 0x3c0f8, 0xffffffff, 0x00090008,
1555 0xc318, 0xffffffff, 0x00020200,
1556 0x3350, 0xffffffff, 0x00000200,
1557 0x15c0, 0xffffffff, 0x00000400,
1558 0x55e8, 0xffffffff, 0x00000000,
1559 0x2f50, 0xffffffff, 0x00000902,
1560 0x3c000, 0xffffffff, 0x96940200,
1561 0x8708, 0xffffffff, 0x00900100,
1562 0xc424, 0xffffffff, 0x0020003f,
1563 0x38, 0xffffffff, 0x0140001c,
1564 0x3c, 0x000f0000, 0x000f0000,
1565 0x220, 0xffffffff, 0xc060000c,
1566 0x224, 0xc0000fff, 0x00000100,
1567 0xf90, 0xffffffff, 0x00000100,
1568 0xf98, 0x00000101, 0x00000000,
1569 0x20a8, 0xffffffff, 0x00000104,
1570 0x55e4, 0xff000fff, 0x00000100,
1571 0x30cc, 0xc0000fff, 0x00000104,
1572 0xc1e4, 0x00000001, 0x00000001,
1573 0xd00c, 0xff000ff0, 0x00000100,
1574 0xd80c, 0xff000ff0, 0x00000100
1577 static const u32 godavari_golden_registers[] =
1579 0x55e4, 0xff607fff, 0xfc000100,
1580 0x6ed8, 0x00010101, 0x00010000,
1581 0x9830, 0xffffffff, 0x00000000,
1582 0x98302, 0xf00fffff, 0x00000400,
1583 0x6130, 0xffffffff, 0x00010000,
1584 0x5bb0, 0x000000f0, 0x00000070,
1585 0x5bc0, 0xf0311fff, 0x80300000,
1586 0x98f8, 0x73773777, 0x12010001,
1587 0x98fc, 0xffffffff, 0x00000010,
1588 0x8030, 0x00001f0f, 0x0000100a,
1589 0x2f48, 0x73773777, 0x12010001,
1590 0x2408, 0x000fffff, 0x000c007f,
1591 0x8a14, 0xf000003f, 0x00000007,
1592 0x8b24, 0xffffffff, 0x00ff0fff,
1593 0x30a04, 0x0000ff0f, 0x00000000,
1594 0x28a4c, 0x07ffffff, 0x06000000,
1595 0x4d8, 0x00000fff, 0x00000100,
1596 0xd014, 0x00010000, 0x00810001,
1597 0xd814, 0x00010000, 0x00810001,
1598 0x3e78, 0x00000001, 0x00000002,
1599 0xc768, 0x00000008, 0x00000008,
1600 0xc770, 0x00000f00, 0x00000800,
1601 0xc774, 0x00000f00, 0x00000800,
1602 0xc798, 0x00ffffff, 0x00ff7fbf,
1603 0xc79c, 0x00ffffff, 0x00ff7faf,
1604 0x8c00, 0x000000ff, 0x00000001,
1605 0x214f8, 0x01ff01ff, 0x00000002,
1606 0x21498, 0x007ff800, 0x00200000,
1607 0x2015c, 0xffffffff, 0x00000f40,
1608 0x88c4, 0x001f3ae3, 0x00000082,
1609 0x88d4, 0x0000001f, 0x00000010,
1610 0x30934, 0xffffffff, 0x00000000
1614 static void cik_init_golden_registers(struct radeon_device *rdev)
1616 /* Some of the registers might be dependent on GRBM_GFX_INDEX */
1617 mutex_lock(&rdev->grbm_idx_mutex);
1618 switch (rdev->family) {
1620 radeon_program_register_sequence(rdev,
1621 bonaire_mgcg_cgcg_init,
1622 (const u32)ARRAY_SIZE(bonaire_mgcg_cgcg_init));
1623 radeon_program_register_sequence(rdev,
1624 bonaire_golden_registers,
1625 (const u32)ARRAY_SIZE(bonaire_golden_registers));
1626 radeon_program_register_sequence(rdev,
1627 bonaire_golden_common_registers,
1628 (const u32)ARRAY_SIZE(bonaire_golden_common_registers));
1629 radeon_program_register_sequence(rdev,
1630 bonaire_golden_spm_registers,
1631 (const u32)ARRAY_SIZE(bonaire_golden_spm_registers));
1634 radeon_program_register_sequence(rdev,
1635 kalindi_mgcg_cgcg_init,
1636 (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
1637 radeon_program_register_sequence(rdev,
1638 kalindi_golden_registers,
1639 (const u32)ARRAY_SIZE(kalindi_golden_registers));
1640 radeon_program_register_sequence(rdev,
1641 kalindi_golden_common_registers,
1642 (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
1643 radeon_program_register_sequence(rdev,
1644 kalindi_golden_spm_registers,
1645 (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
1648 radeon_program_register_sequence(rdev,
1649 kalindi_mgcg_cgcg_init,
1650 (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
1651 radeon_program_register_sequence(rdev,
1652 godavari_golden_registers,
1653 (const u32)ARRAY_SIZE(godavari_golden_registers));
1654 radeon_program_register_sequence(rdev,
1655 kalindi_golden_common_registers,
1656 (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
1657 radeon_program_register_sequence(rdev,
1658 kalindi_golden_spm_registers,
1659 (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
1662 radeon_program_register_sequence(rdev,
1663 spectre_mgcg_cgcg_init,
1664 (const u32)ARRAY_SIZE(spectre_mgcg_cgcg_init));
1665 radeon_program_register_sequence(rdev,
1666 spectre_golden_registers,
1667 (const u32)ARRAY_SIZE(spectre_golden_registers));
1668 radeon_program_register_sequence(rdev,
1669 spectre_golden_common_registers,
1670 (const u32)ARRAY_SIZE(spectre_golden_common_registers));
1671 radeon_program_register_sequence(rdev,
1672 spectre_golden_spm_registers,
1673 (const u32)ARRAY_SIZE(spectre_golden_spm_registers));
1676 radeon_program_register_sequence(rdev,
1677 hawaii_mgcg_cgcg_init,
1678 (const u32)ARRAY_SIZE(hawaii_mgcg_cgcg_init));
1679 radeon_program_register_sequence(rdev,
1680 hawaii_golden_registers,
1681 (const u32)ARRAY_SIZE(hawaii_golden_registers));
1682 radeon_program_register_sequence(rdev,
1683 hawaii_golden_common_registers,
1684 (const u32)ARRAY_SIZE(hawaii_golden_common_registers));
1685 radeon_program_register_sequence(rdev,
1686 hawaii_golden_spm_registers,
1687 (const u32)ARRAY_SIZE(hawaii_golden_spm_registers));
1692 mutex_unlock(&rdev->grbm_idx_mutex);
1696 * cik_get_xclk - get the xclk
1698 * @rdev: radeon_device pointer
1700 * Returns the reference clock used by the gfx engine
1703 u32 cik_get_xclk(struct radeon_device *rdev)
1705 u32 reference_clock = rdev->clock.spll.reference_freq;
1707 if (rdev->flags & RADEON_IS_IGP) {
1708 if (RREG32_SMC(GENERAL_PWRMGT) & GPU_COUNTER_CLK)
1709 return reference_clock / 2;
1711 if (RREG32_SMC(CG_CLKPIN_CNTL) & XTALIN_DIVIDE)
1712 return reference_clock / 4;
1714 return reference_clock;
1718 * cik_mm_rdoorbell - read a doorbell dword
1720 * @rdev: radeon_device pointer
1721 * @index: doorbell index
1723 * Returns the value in the doorbell aperture at the
1724 * requested doorbell index (CIK).
1726 u32 cik_mm_rdoorbell(struct radeon_device *rdev, u32 index)
1728 if (index < rdev->doorbell.num_doorbells) {
1729 return readl(rdev->doorbell.ptr + index);
1731 DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
1737 * cik_mm_wdoorbell - write a doorbell dword
1739 * @rdev: radeon_device pointer
1740 * @index: doorbell index
1741 * @v: value to write
1743 * Writes @v to the doorbell aperture at the
1744 * requested doorbell index (CIK).
1746 void cik_mm_wdoorbell(struct radeon_device *rdev, u32 index, u32 v)
1748 if (index < rdev->doorbell.num_doorbells) {
1749 writel(v, rdev->doorbell.ptr + index);
1751 DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
1755 #define BONAIRE_IO_MC_REGS_SIZE 36
1757 static const u32 bonaire_io_mc_regs[BONAIRE_IO_MC_REGS_SIZE][2] =
1759 {0x00000070, 0x04400000},
1760 {0x00000071, 0x80c01803},
1761 {0x00000072, 0x00004004},
1762 {0x00000073, 0x00000100},
1763 {0x00000074, 0x00ff0000},
1764 {0x00000075, 0x34000000},
1765 {0x00000076, 0x08000014},
1766 {0x00000077, 0x00cc08ec},
1767 {0x00000078, 0x00000400},
1768 {0x00000079, 0x00000000},
1769 {0x0000007a, 0x04090000},
1770 {0x0000007c, 0x00000000},
1771 {0x0000007e, 0x4408a8e8},
1772 {0x0000007f, 0x00000304},
1773 {0x00000080, 0x00000000},
1774 {0x00000082, 0x00000001},
1775 {0x00000083, 0x00000002},
1776 {0x00000084, 0xf3e4f400},
1777 {0x00000085, 0x052024e3},
1778 {0x00000087, 0x00000000},
1779 {0x00000088, 0x01000000},
1780 {0x0000008a, 0x1c0a0000},
1781 {0x0000008b, 0xff010000},
1782 {0x0000008d, 0xffffefff},
1783 {0x0000008e, 0xfff3efff},
1784 {0x0000008f, 0xfff3efbf},
1785 {0x00000092, 0xf7ffffff},
1786 {0x00000093, 0xffffff7f},
1787 {0x00000095, 0x00101101},
1788 {0x00000096, 0x00000fff},
1789 {0x00000097, 0x00116fff},
1790 {0x00000098, 0x60010000},
1791 {0x00000099, 0x10010000},
1792 {0x0000009a, 0x00006000},
1793 {0x0000009b, 0x00001000},
1794 {0x0000009f, 0x00b48000}
1797 #define HAWAII_IO_MC_REGS_SIZE 22
1799 static const u32 hawaii_io_mc_regs[HAWAII_IO_MC_REGS_SIZE][2] =
1801 {0x0000007d, 0x40000000},
1802 {0x0000007e, 0x40180304},
1803 {0x0000007f, 0x0000ff00},
1804 {0x00000081, 0x00000000},
1805 {0x00000083, 0x00000800},
1806 {0x00000086, 0x00000000},
1807 {0x00000087, 0x00000100},
1808 {0x00000088, 0x00020100},
1809 {0x00000089, 0x00000000},
1810 {0x0000008b, 0x00040000},
1811 {0x0000008c, 0x00000100},
1812 {0x0000008e, 0xff010000},
1813 {0x00000090, 0xffffefff},
1814 {0x00000091, 0xfff3efff},
1815 {0x00000092, 0xfff3efbf},
1816 {0x00000093, 0xf7ffffff},
1817 {0x00000094, 0xffffff7f},
1818 {0x00000095, 0x00000fff},
1819 {0x00000096, 0x00116fff},
1820 {0x00000097, 0x60010000},
1821 {0x00000098, 0x10010000},
1822 {0x0000009f, 0x00c79000}
1827 * cik_srbm_select - select specific register instances
1829 * @rdev: radeon_device pointer
1830 * @me: selected ME (micro engine)
1835 * Switches the currently active registers instances. Some
1836 * registers are instanced per VMID, others are instanced per
1837 * me/pipe/queue combination.
1839 static void cik_srbm_select(struct radeon_device *rdev,
1840 u32 me, u32 pipe, u32 queue, u32 vmid)
1842 u32 srbm_gfx_cntl = (PIPEID(pipe & 0x3) |
1845 QUEUEID(queue & 0x7));
1846 WREG32(SRBM_GFX_CNTL, srbm_gfx_cntl);
1851 * ci_mc_load_microcode - load MC ucode into the hw
1853 * @rdev: radeon_device pointer
1855 * Load the GDDR MC ucode into the hw (CIK).
1856 * Returns 0 on success, error on failure.
1858 int ci_mc_load_microcode(struct radeon_device *rdev)
1860 const __be32 *fw_data = NULL;
1861 const __le32 *new_fw_data = NULL;
1863 u32 *io_mc_regs = NULL;
1864 const __le32 *new_io_mc_regs = NULL;
1865 int i, regs_size, ucode_size;
1871 const struct mc_firmware_header_v1_0 *hdr =
1872 (const struct mc_firmware_header_v1_0 *)rdev->mc_fw->data;
1874 radeon_ucode_print_mc_hdr(&hdr->header);
1876 regs_size = le32_to_cpu(hdr->io_debug_size_bytes) / (4 * 2);
1877 new_io_mc_regs = (const __le32 *)
1878 (rdev->mc_fw->data + le32_to_cpu(hdr->io_debug_array_offset_bytes));
1879 ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
1880 new_fw_data = (const __le32 *)
1881 (rdev->mc_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
1883 ucode_size = rdev->mc_fw->datasize / 4;
1885 switch (rdev->family) {
1887 io_mc_regs = (u32 *)&bonaire_io_mc_regs;
1888 regs_size = BONAIRE_IO_MC_REGS_SIZE;
1891 io_mc_regs = (u32 *)&hawaii_io_mc_regs;
1892 regs_size = HAWAII_IO_MC_REGS_SIZE;
1897 fw_data = (const __be32 *)rdev->mc_fw->data;
1900 running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
1903 /* reset the engine and set to writable */
1904 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
1905 WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
1907 /* load mc io regs */
1908 for (i = 0; i < regs_size; i++) {
1910 WREG32(MC_SEQ_IO_DEBUG_INDEX, le32_to_cpup(new_io_mc_regs++));
1911 WREG32(MC_SEQ_IO_DEBUG_DATA, le32_to_cpup(new_io_mc_regs++));
1913 WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
1914 WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
1918 tmp = RREG32(MC_SEQ_MISC0);
1919 if ((rdev->pdev->device == 0x6649) && ((tmp & 0xff00) == 0x5600)) {
1920 WREG32(MC_SEQ_IO_DEBUG_INDEX, 5);
1921 WREG32(MC_SEQ_IO_DEBUG_DATA, 0x00000023);
1922 WREG32(MC_SEQ_IO_DEBUG_INDEX, 9);
1923 WREG32(MC_SEQ_IO_DEBUG_DATA, 0x000001f0);
1926 /* load the MC ucode */
1927 for (i = 0; i < ucode_size; i++) {
1929 WREG32(MC_SEQ_SUP_PGM, le32_to_cpup(new_fw_data++));
1931 WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
1934 /* put the engine back into the active state */
1935 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
1936 WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
1937 WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
1939 /* wait for training to complete */
1940 for (i = 0; i < rdev->usec_timeout; i++) {
1941 if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D0)
1945 for (i = 0; i < rdev->usec_timeout; i++) {
1946 if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D1)
1956 * cik_init_microcode - load ucode images from disk
1958 * @rdev: radeon_device pointer
1960 * Use the firmware interface to load the ucode images into
1961 * the driver (not loaded into hw).
1962 * Returns 0 on success, error on failure.
1964 static int cik_init_microcode(struct radeon_device *rdev)
1966 const char *chip_name;
1967 const char *new_chip_name;
1968 size_t pfp_req_size, me_req_size, ce_req_size,
1969 mec_req_size, rlc_req_size, mc_req_size = 0,
1970 sdma_req_size, smc_req_size = 0, mc2_req_size = 0;
1975 bool new_smc = false;
1979 switch (rdev->family) {
1981 chip_name = "BONAIRE";
1982 if ((rdev->pdev->revision == 0x80) ||
1983 (rdev->pdev->revision == 0x81) ||
1984 (rdev->pdev->device == 0x665f))
1986 new_chip_name = "bonaire";
1987 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
1988 me_req_size = CIK_ME_UCODE_SIZE * 4;
1989 ce_req_size = CIK_CE_UCODE_SIZE * 4;
1990 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
1991 rlc_req_size = BONAIRE_RLC_UCODE_SIZE * 4;
1992 mc_req_size = BONAIRE_MC_UCODE_SIZE * 4;
1993 mc2_req_size = BONAIRE_MC2_UCODE_SIZE * 4;
1994 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
1995 smc_req_size = ALIGN(BONAIRE_SMC_UCODE_SIZE, 4);
1999 chip_name = "HAWAII";
2000 if (rdev->pdev->revision == 0x80)
2002 new_chip_name = "hawaii";
2003 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
2004 me_req_size = CIK_ME_UCODE_SIZE * 4;
2005 ce_req_size = CIK_CE_UCODE_SIZE * 4;
2006 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
2007 rlc_req_size = BONAIRE_RLC_UCODE_SIZE * 4;
2008 mc_req_size = HAWAII_MC_UCODE_SIZE * 4;
2009 mc2_req_size = HAWAII_MC2_UCODE_SIZE * 4;
2010 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
2011 smc_req_size = ALIGN(HAWAII_SMC_UCODE_SIZE, 4);
2015 chip_name = "KAVERI";
2016 new_chip_name = "kaveri";
2017 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
2018 me_req_size = CIK_ME_UCODE_SIZE * 4;
2019 ce_req_size = CIK_CE_UCODE_SIZE * 4;
2020 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
2021 rlc_req_size = KV_RLC_UCODE_SIZE * 4;
2022 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
2026 chip_name = "KABINI";
2027 new_chip_name = "kabini";
2028 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
2029 me_req_size = CIK_ME_UCODE_SIZE * 4;
2030 ce_req_size = CIK_CE_UCODE_SIZE * 4;
2031 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
2032 rlc_req_size = KB_RLC_UCODE_SIZE * 4;
2033 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
2037 chip_name = "MULLINS";
2038 new_chip_name = "mullins";
2039 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
2040 me_req_size = CIK_ME_UCODE_SIZE * 4;
2041 ce_req_size = CIK_CE_UCODE_SIZE * 4;
2042 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
2043 rlc_req_size = ML_RLC_UCODE_SIZE * 4;
2044 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
2050 DRM_INFO("Loading %s Microcode\n", new_chip_name);
2052 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_pfp", new_chip_name);
2053 err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
2055 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_pfp", chip_name);
2056 err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
2059 if (rdev->pfp_fw->datasize != pfp_req_size) {
2060 pr_err("cik_cp: Bogus length %zu in firmware \"%s\"\n",
2061 rdev->pfp_fw->datasize, fw_name);
2066 err = radeon_ucode_validate(rdev->pfp_fw);
2068 pr_err("cik_fw: validation failed for firmware \"%s\"\n",
2076 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_me", new_chip_name);
2077 err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
2079 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_me", chip_name);
2080 err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
2083 if (rdev->me_fw->datasize != me_req_size) {
2084 pr_err("cik_cp: Bogus length %zu in firmware \"%s\"\n",
2085 rdev->me_fw->datasize, fw_name);
2089 err = radeon_ucode_validate(rdev->me_fw);
2091 pr_err("cik_fw: validation failed for firmware \"%s\"\n",
2099 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_ce", new_chip_name);
2100 err = request_firmware(&rdev->ce_fw, fw_name, rdev->dev);
2102 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_ce", chip_name);
2103 err = request_firmware(&rdev->ce_fw, fw_name, rdev->dev);
2106 if (rdev->ce_fw->datasize != ce_req_size) {
2107 pr_err("cik_cp: Bogus length %zu in firmware \"%s\"\n",
2108 rdev->ce_fw->datasize, fw_name);
2112 err = radeon_ucode_validate(rdev->ce_fw);
2114 pr_err("cik_fw: validation failed for firmware \"%s\"\n",
2122 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_mec", new_chip_name);
2123 err = request_firmware(&rdev->mec_fw, fw_name, rdev->dev);
2125 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_mec", chip_name);
2126 err = request_firmware(&rdev->mec_fw, fw_name, rdev->dev);
2129 if (rdev->mec_fw->datasize != mec_req_size) {
2130 pr_err("cik_cp: Bogus length %zu in firmware \"%s\"\n",
2131 rdev->mec_fw->datasize, fw_name);
2135 err = radeon_ucode_validate(rdev->mec_fw);
2137 pr_err("cik_fw: validation failed for firmware \"%s\"\n",
2145 if (rdev->family == CHIP_KAVERI) {
2146 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_mec2", new_chip_name);
2147 err = request_firmware(&rdev->mec2_fw, fw_name, rdev->dev);
2151 err = radeon_ucode_validate(rdev->mec2_fw);
2160 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_rlc", new_chip_name);
2161 err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
2163 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_rlc", chip_name);
2164 err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
2167 if (rdev->rlc_fw->datasize != rlc_req_size) {
2168 pr_err("cik_rlc: Bogus length %zu in firmware \"%s\"\n",
2169 rdev->rlc_fw->datasize, fw_name);
2173 err = radeon_ucode_validate(rdev->rlc_fw);
2175 pr_err("cik_fw: validation failed for firmware \"%s\"\n",
2183 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_sdma", new_chip_name);
2184 err = request_firmware(&rdev->sdma_fw, fw_name, rdev->dev);
2186 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_sdma", chip_name);
2187 err = request_firmware(&rdev->sdma_fw, fw_name, rdev->dev);
2190 if (rdev->sdma_fw->datasize != sdma_req_size) {
2191 pr_err("cik_sdma: Bogus length %zu in firmware \"%s\"\n",
2192 rdev->sdma_fw->datasize, fw_name);
2196 err = radeon_ucode_validate(rdev->sdma_fw);
2198 pr_err("cik_fw: validation failed for firmware \"%s\"\n",
2206 /* No SMC, MC ucode on APUs */
2207 if (!(rdev->flags & RADEON_IS_IGP)) {
2208 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_mc", new_chip_name);
2209 err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
2211 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_mc2", chip_name);
2212 err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
2214 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_mc", chip_name);
2215 err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
2219 if ((rdev->mc_fw->datasize != mc_req_size) &&
2220 (rdev->mc_fw->datasize != mc2_req_size)){
2221 pr_err("cik_mc: Bogus length %zu in firmware \"%s\"\n",
2222 rdev->mc_fw->datasize, fw_name);
2225 DRM_INFO("%s: %zu bytes\n", fw_name, rdev->mc_fw->datasize);
2227 err = radeon_ucode_validate(rdev->mc_fw);
2229 pr_err("cik_fw: validation failed for firmware \"%s\"\n",
2238 ksnprintf(fw_name, sizeof(fw_name), "amdgpufw_%s_k_smc", new_chip_name);
2240 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_smc", new_chip_name);
2241 err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
2243 ksnprintf(fw_name, sizeof(fw_name), "radeonkmsfw_%s_smc", chip_name);
2244 err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
2246 pr_err("smc: error loading firmware \"%s\"\n",
2248 release_firmware(rdev->smc_fw);
2249 rdev->smc_fw = NULL;
2251 } else if (rdev->smc_fw->datasize != smc_req_size) {
2252 pr_err("cik_smc: Bogus length %zu in firmware \"%s\"\n",
2253 rdev->smc_fw->datasize, fw_name);
2257 err = radeon_ucode_validate(rdev->smc_fw);
2259 pr_err("cik_fw: validation failed for firmware \"%s\"\n",
2269 rdev->new_fw = false;
2270 } else if (new_fw < num_fw) {
2271 pr_err("ci_fw: mixing new and old firmware!\n");
2274 rdev->new_fw = true;
2280 pr_err("cik_cp: Failed to load firmware \"%s\"\n",
2282 release_firmware(rdev->pfp_fw);
2283 rdev->pfp_fw = NULL;
2284 release_firmware(rdev->me_fw);
2286 release_firmware(rdev->ce_fw);
2288 release_firmware(rdev->mec_fw);
2289 rdev->mec_fw = NULL;
2290 release_firmware(rdev->mec2_fw);
2291 rdev->mec2_fw = NULL;
2292 release_firmware(rdev->rlc_fw);
2293 rdev->rlc_fw = NULL;
2294 release_firmware(rdev->sdma_fw);
2295 rdev->sdma_fw = NULL;
2296 release_firmware(rdev->mc_fw);
2298 release_firmware(rdev->smc_fw);
2299 rdev->smc_fw = NULL;
2305 * cik_fini_microcode - drop the firmwares image references
2307 * @rdev: radeon_device pointer
2309 * Drop the pfp, me, mec, mec2, rlc, sdma, mc, smc and ce firmware image references.
2310 * Called at driver shutdown.
2312 static void cik_fini_microcode(struct radeon_device *rdev)
2314 release_firmware(rdev->pfp_fw);
2315 rdev->pfp_fw = NULL;
2316 release_firmware(rdev->me_fw);
2318 release_firmware(rdev->ce_fw);
2320 release_firmware(rdev->mec_fw);
2321 rdev->mec_fw = NULL;
2322 release_firmware(rdev->mec2_fw);
2323 rdev->mec2_fw = NULL;
2324 release_firmware(rdev->rlc_fw);
2325 rdev->rlc_fw = NULL;
2326 release_firmware(rdev->sdma_fw);
2327 rdev->sdma_fw = NULL;
2328 release_firmware(rdev->mc_fw);
2330 release_firmware(rdev->smc_fw);
2331 rdev->smc_fw = NULL;
2338 * cik_tiling_mode_table_init - init the hw tiling table
2340 * @rdev: radeon_device pointer
2342 * Starting with SI, the tiling setup is done globally in a
2343 * set of 32 tiling modes. Rather than selecting each set of
2344 * parameters per surface as on older asics, we just select
2345 * which index in the tiling table we want to use, and the
2346 * surface uses those parameters (CIK).
2348 static void cik_tiling_mode_table_init(struct radeon_device *rdev)
2350 u32 *tile = rdev->config.cik.tile_mode_array;
2351 u32 *macrotile = rdev->config.cik.macrotile_mode_array;
2352 const u32 num_tile_mode_states =
2353 ARRAY_SIZE(rdev->config.cik.tile_mode_array);
2354 const u32 num_secondary_tile_mode_states =
2355 ARRAY_SIZE(rdev->config.cik.macrotile_mode_array);
2356 u32 reg_offset, split_equal_to_row_size;
2357 u32 num_pipe_configs;
2358 u32 num_rbs = rdev->config.cik.max_backends_per_se *
2359 rdev->config.cik.max_shader_engines;
2361 switch (rdev->config.cik.mem_row_size_in_kb) {
2363 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_1KB;
2367 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_2KB;
2370 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_4KB;
2374 num_pipe_configs = rdev->config.cik.max_tile_pipes;
2375 if (num_pipe_configs > 8)
2376 num_pipe_configs = 16;
2378 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
2379 tile[reg_offset] = 0;
2380 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
2381 macrotile[reg_offset] = 0;
2383 switch(num_pipe_configs) {
2385 tile[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2386 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2387 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2388 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
2389 tile[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2390 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2391 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2392 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
2393 tile[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2394 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2395 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2396 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2397 tile[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2398 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2399 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2400 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
2401 tile[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2402 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2403 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2404 TILE_SPLIT(split_equal_to_row_size));
2405 tile[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2406 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2407 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2408 tile[6] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2409 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2410 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2411 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2412 tile[7] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2413 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2414 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2415 TILE_SPLIT(split_equal_to_row_size));
2416 tile[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2417 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16));
2418 tile[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2419 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2420 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
2421 tile[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2422 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2423 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2424 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2425 tile[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2426 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2427 PIPE_CONFIG(ADDR_SURF_P16_32x32_8x16) |
2428 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2429 tile[12] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2430 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2431 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2432 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2433 tile[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2434 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2435 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
2436 tile[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2437 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2438 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2439 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2440 tile[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2441 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2442 PIPE_CONFIG(ADDR_SURF_P16_32x32_8x16) |
2443 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2444 tile[17] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2445 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2446 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2447 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2448 tile[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2449 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2450 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
2451 tile[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2452 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2453 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2454 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2455 tile[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2456 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2457 PIPE_CONFIG(ADDR_SURF_P16_32x32_8x16) |
2458 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2459 tile[30] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2460 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2461 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2462 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2464 macrotile[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2465 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2466 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2467 NUM_BANKS(ADDR_SURF_16_BANK));
2468 macrotile[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2469 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2470 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2471 NUM_BANKS(ADDR_SURF_16_BANK));
2472 macrotile[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2473 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2474 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2475 NUM_BANKS(ADDR_SURF_16_BANK));
2476 macrotile[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2477 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2478 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2479 NUM_BANKS(ADDR_SURF_16_BANK));
2480 macrotile[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2481 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2482 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2483 NUM_BANKS(ADDR_SURF_8_BANK));
2484 macrotile[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2485 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2486 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2487 NUM_BANKS(ADDR_SURF_4_BANK));
2488 macrotile[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2489 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2490 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2491 NUM_BANKS(ADDR_SURF_2_BANK));
2492 macrotile[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2493 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2494 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2495 NUM_BANKS(ADDR_SURF_16_BANK));
2496 macrotile[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2497 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2498 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2499 NUM_BANKS(ADDR_SURF_16_BANK));
2500 macrotile[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2501 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2502 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2503 NUM_BANKS(ADDR_SURF_16_BANK));
2504 macrotile[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2505 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2506 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2507 NUM_BANKS(ADDR_SURF_8_BANK));
2508 macrotile[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2509 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2510 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2511 NUM_BANKS(ADDR_SURF_4_BANK));
2512 macrotile[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2513 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2514 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2515 NUM_BANKS(ADDR_SURF_2_BANK));
2516 macrotile[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2517 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2518 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2519 NUM_BANKS(ADDR_SURF_2_BANK));
2521 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
2522 WREG32(GB_TILE_MODE0 + (reg_offset * 4), tile[reg_offset]);
2523 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
2524 WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), macrotile[reg_offset]);
2528 tile[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2529 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2530 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2531 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
2532 tile[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2533 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2534 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2535 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
2536 tile[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2537 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2538 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2539 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2540 tile[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2541 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2542 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2543 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
2544 tile[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2545 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2546 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2547 TILE_SPLIT(split_equal_to_row_size));
2548 tile[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2549 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2550 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2551 tile[6] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2552 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2553 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2554 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2555 tile[7] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2556 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2557 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2558 TILE_SPLIT(split_equal_to_row_size));
2559 tile[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2560 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16));
2561 tile[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2562 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2563 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
2564 tile[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2565 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2566 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2567 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2568 tile[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2569 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2570 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2571 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2572 tile[12] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2573 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2574 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2575 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2576 tile[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2577 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2578 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
2579 tile[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2580 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2581 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2582 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2583 tile[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2584 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2585 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2586 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2587 tile[17] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2588 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2589 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2590 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2591 tile[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2592 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2593 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
2594 tile[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2595 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2596 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2597 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2598 tile[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2599 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2600 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2601 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2602 tile[30] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2603 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2604 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2605 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2607 macrotile[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2608 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2609 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2610 NUM_BANKS(ADDR_SURF_16_BANK));
2611 macrotile[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2612 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2613 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2614 NUM_BANKS(ADDR_SURF_16_BANK));
2615 macrotile[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2616 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2617 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2618 NUM_BANKS(ADDR_SURF_16_BANK));
2619 macrotile[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2620 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2621 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2622 NUM_BANKS(ADDR_SURF_16_BANK));
2623 macrotile[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2624 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2625 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2626 NUM_BANKS(ADDR_SURF_8_BANK));
2627 macrotile[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2628 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2629 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2630 NUM_BANKS(ADDR_SURF_4_BANK));
2631 macrotile[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2632 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2633 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2634 NUM_BANKS(ADDR_SURF_2_BANK));
2635 macrotile[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2636 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2637 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2638 NUM_BANKS(ADDR_SURF_16_BANK));
2639 macrotile[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2640 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2641 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2642 NUM_BANKS(ADDR_SURF_16_BANK));
2643 macrotile[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2644 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2645 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2646 NUM_BANKS(ADDR_SURF_16_BANK));
2647 macrotile[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2648 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2649 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2650 NUM_BANKS(ADDR_SURF_16_BANK));
2651 macrotile[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2652 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2653 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2654 NUM_BANKS(ADDR_SURF_8_BANK));
2655 macrotile[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2656 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2657 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2658 NUM_BANKS(ADDR_SURF_4_BANK));
2659 macrotile[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2660 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2661 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2662 NUM_BANKS(ADDR_SURF_2_BANK));
2664 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
2665 WREG32(GB_TILE_MODE0 + (reg_offset * 4), tile[reg_offset]);
2666 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
2667 WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), macrotile[reg_offset]);
2672 tile[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2673 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2674 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2675 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
2676 tile[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2677 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2678 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2679 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
2680 tile[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2681 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2682 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2683 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2684 tile[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2685 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2686 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2687 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
2688 tile[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2689 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2690 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2691 TILE_SPLIT(split_equal_to_row_size));
2692 tile[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2693 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2694 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2695 tile[6] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2696 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2697 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2698 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2699 tile[7] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2700 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2701 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2702 TILE_SPLIT(split_equal_to_row_size));
2703 tile[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2704 PIPE_CONFIG(ADDR_SURF_P4_16x16));
2705 tile[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2706 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2707 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
2708 tile[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2709 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2710 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2711 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2712 tile[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2713 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2714 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2715 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2716 tile[12] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2717 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2718 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2719 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2720 tile[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2721 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2722 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
2723 tile[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2724 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2725 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2726 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2727 tile[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2728 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2729 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2730 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2731 tile[17] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2732 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2733 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2734 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2735 tile[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2736 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2737 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
2738 tile[28] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2739 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2740 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2741 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2742 tile[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2743 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2744 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2745 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2746 tile[30] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2747 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2748 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2749 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2751 } else if (num_rbs < 4) {
2752 tile[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2753 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2754 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2755 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
2756 tile[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2757 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2758 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2759 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
2760 tile[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2761 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2762 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2763 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2764 tile[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2765 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2766 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2767 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
2768 tile[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2769 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2770 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2771 TILE_SPLIT(split_equal_to_row_size));
2772 tile[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2773 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2774 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2775 tile[6] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2776 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2777 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2778 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2779 tile[7] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2780 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2781 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2782 TILE_SPLIT(split_equal_to_row_size));
2783 tile[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2784 PIPE_CONFIG(ADDR_SURF_P4_8x16));
2785 tile[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2786 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2787 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
2788 tile[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2789 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2790 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2791 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2792 tile[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2793 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2794 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2795 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2796 tile[12] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2797 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2798 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2799 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2800 tile[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2801 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2802 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
2803 tile[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2804 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2805 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2806 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2807 tile[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2808 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2809 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2810 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2811 tile[17] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2812 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2813 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2814 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2815 tile[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2816 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2817 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
2818 tile[28] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2819 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2820 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2821 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2822 tile[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2823 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2824 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2825 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2826 tile[30] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2827 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2828 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2829 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2832 macrotile[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2833 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2834 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2835 NUM_BANKS(ADDR_SURF_16_BANK));
2836 macrotile[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2837 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2838 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2839 NUM_BANKS(ADDR_SURF_16_BANK));
2840 macrotile[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2841 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2842 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2843 NUM_BANKS(ADDR_SURF_16_BANK));
2844 macrotile[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2845 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2846 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2847 NUM_BANKS(ADDR_SURF_16_BANK));
2848 macrotile[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2849 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2850 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2851 NUM_BANKS(ADDR_SURF_16_BANK));
2852 macrotile[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2853 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2854 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2855 NUM_BANKS(ADDR_SURF_8_BANK));
2856 macrotile[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2857 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2858 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2859 NUM_BANKS(ADDR_SURF_4_BANK));
2860 macrotile[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2861 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2862 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2863 NUM_BANKS(ADDR_SURF_16_BANK));
2864 macrotile[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2865 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2866 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2867 NUM_BANKS(ADDR_SURF_16_BANK));
2868 macrotile[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2869 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2870 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2871 NUM_BANKS(ADDR_SURF_16_BANK));
2872 macrotile[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2873 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2874 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2875 NUM_BANKS(ADDR_SURF_16_BANK));
2876 macrotile[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2877 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2878 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2879 NUM_BANKS(ADDR_SURF_16_BANK));
2880 macrotile[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2881 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2882 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2883 NUM_BANKS(ADDR_SURF_8_BANK));
2884 macrotile[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2885 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2886 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2887 NUM_BANKS(ADDR_SURF_4_BANK));
2889 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
2890 WREG32(GB_TILE_MODE0 + (reg_offset * 4), tile[reg_offset]);
2891 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
2892 WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), macrotile[reg_offset]);
2896 tile[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2897 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2898 PIPE_CONFIG(ADDR_SURF_P2) |
2899 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
2900 tile[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2901 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2902 PIPE_CONFIG(ADDR_SURF_P2) |
2903 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
2904 tile[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2905 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2906 PIPE_CONFIG(ADDR_SURF_P2) |
2907 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2908 tile[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2909 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2910 PIPE_CONFIG(ADDR_SURF_P2) |
2911 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
2912 tile[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2913 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2914 PIPE_CONFIG(ADDR_SURF_P2) |
2915 TILE_SPLIT(split_equal_to_row_size));
2916 tile[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2917 PIPE_CONFIG(ADDR_SURF_P2) |
2918 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2919 tile[6] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2920 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2921 PIPE_CONFIG(ADDR_SURF_P2) |
2922 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2923 tile[7] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2924 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2925 PIPE_CONFIG(ADDR_SURF_P2) |
2926 TILE_SPLIT(split_equal_to_row_size));
2927 tile[8] = ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2928 PIPE_CONFIG(ADDR_SURF_P2);
2929 tile[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2930 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2931 PIPE_CONFIG(ADDR_SURF_P2));
2932 tile[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2933 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2934 PIPE_CONFIG(ADDR_SURF_P2) |
2935 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2936 tile[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2937 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2938 PIPE_CONFIG(ADDR_SURF_P2) |
2939 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2940 tile[12] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2941 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2942 PIPE_CONFIG(ADDR_SURF_P2) |
2943 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2944 tile[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2945 PIPE_CONFIG(ADDR_SURF_P2) |
2946 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
2947 tile[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2948 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2949 PIPE_CONFIG(ADDR_SURF_P2) |
2950 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2951 tile[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2952 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2953 PIPE_CONFIG(ADDR_SURF_P2) |
2954 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2955 tile[17] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2956 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2957 PIPE_CONFIG(ADDR_SURF_P2) |
2958 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2959 tile[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2960 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2961 PIPE_CONFIG(ADDR_SURF_P2));
2962 tile[28] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2963 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2964 PIPE_CONFIG(ADDR_SURF_P2) |
2965 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2966 tile[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2967 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2968 PIPE_CONFIG(ADDR_SURF_P2) |
2969 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2970 tile[30] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2971 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2972 PIPE_CONFIG(ADDR_SURF_P2) |
2973 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2975 macrotile[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2976 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2977 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2978 NUM_BANKS(ADDR_SURF_16_BANK));
2979 macrotile[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2980 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2981 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2982 NUM_BANKS(ADDR_SURF_16_BANK));
2983 macrotile[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2984 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2985 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2986 NUM_BANKS(ADDR_SURF_16_BANK));
2987 macrotile[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2988 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2989 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2990 NUM_BANKS(ADDR_SURF_16_BANK));
2991 macrotile[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2992 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2993 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2994 NUM_BANKS(ADDR_SURF_16_BANK));
2995 macrotile[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2996 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2997 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2998 NUM_BANKS(ADDR_SURF_16_BANK));
2999 macrotile[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3000 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3001 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3002 NUM_BANKS(ADDR_SURF_8_BANK));
3003 macrotile[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3004 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
3005 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3006 NUM_BANKS(ADDR_SURF_16_BANK));
3007 macrotile[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3008 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3009 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3010 NUM_BANKS(ADDR_SURF_16_BANK));
3011 macrotile[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3012 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3013 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3014 NUM_BANKS(ADDR_SURF_16_BANK));
3015 macrotile[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3016 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3017 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3018 NUM_BANKS(ADDR_SURF_16_BANK));
3019 macrotile[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3020 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3021 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3022 NUM_BANKS(ADDR_SURF_16_BANK));
3023 macrotile[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3024 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3025 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3026 NUM_BANKS(ADDR_SURF_16_BANK));
3027 macrotile[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3028 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3029 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3030 NUM_BANKS(ADDR_SURF_8_BANK));
3032 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
3033 WREG32(GB_TILE_MODE0 + (reg_offset * 4), tile[reg_offset]);
3034 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
3035 WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), macrotile[reg_offset]);
3039 DRM_ERROR("unknown num pipe config: 0x%x\n", num_pipe_configs);
3044 * cik_select_se_sh - select which SE, SH to address
3046 * @rdev: radeon_device pointer
3047 * @se_num: shader engine to address
3048 * @sh_num: sh block to address
3050 * Select which SE, SH combinations to address. Certain
3051 * registers are instanced per SE or SH. 0xffffffff means
3052 * broadcast to all SEs or SHs (CIK).
3054 static void cik_select_se_sh(struct radeon_device *rdev,
3055 u32 se_num, u32 sh_num)
3057 u32 data = INSTANCE_BROADCAST_WRITES;
3059 if ((se_num == 0xffffffff) && (sh_num == 0xffffffff))
3060 data |= SH_BROADCAST_WRITES | SE_BROADCAST_WRITES;
3061 else if (se_num == 0xffffffff)
3062 data |= SE_BROADCAST_WRITES | SH_INDEX(sh_num);
3063 else if (sh_num == 0xffffffff)
3064 data |= SH_BROADCAST_WRITES | SE_INDEX(se_num);
3066 data |= SH_INDEX(sh_num) | SE_INDEX(se_num);
3067 WREG32(GRBM_GFX_INDEX, data);
3071 * cik_create_bitmask - create a bitmask
3073 * @bit_width: length of the mask
3075 * create a variable length bit mask (CIK).
3076 * Returns the bitmask.
3078 static u32 cik_create_bitmask(u32 bit_width)
3082 for (i = 0; i < bit_width; i++) {
3090 * cik_get_rb_disabled - computes the mask of disabled RBs
3092 * @rdev: radeon_device pointer
3093 * @max_rb_num: max RBs (render backends) for the asic
3094 * @se_num: number of SEs (shader engines) for the asic
3095 * @sh_per_se: number of SH blocks per SE for the asic
3097 * Calculates the bitmask of disabled RBs (CIK).
3098 * Returns the disabled RB bitmask.
3100 static u32 cik_get_rb_disabled(struct radeon_device *rdev,
3101 u32 max_rb_num_per_se,
3106 data = RREG32(CC_RB_BACKEND_DISABLE);
3108 data &= BACKEND_DISABLE_MASK;
3111 data |= RREG32(GC_USER_RB_BACKEND_DISABLE);
3113 data >>= BACKEND_DISABLE_SHIFT;
3115 mask = cik_create_bitmask(max_rb_num_per_se / sh_per_se);
3121 * cik_setup_rb - setup the RBs on the asic
3123 * @rdev: radeon_device pointer
3124 * @se_num: number of SEs (shader engines) for the asic
3125 * @sh_per_se: number of SH blocks per SE for the asic
3126 * @max_rb_num: max RBs (render backends) for the asic
3128 * Configures per-SE/SH RB registers (CIK).
3130 static void cik_setup_rb(struct radeon_device *rdev,
3131 u32 se_num, u32 sh_per_se,
3132 u32 max_rb_num_per_se)
3136 u32 disabled_rbs = 0;
3137 u32 enabled_rbs = 0;
3139 mutex_lock(&rdev->grbm_idx_mutex);
3140 for (i = 0; i < se_num; i++) {
3141 for (j = 0; j < sh_per_se; j++) {
3142 cik_select_se_sh(rdev, i, j);
3143 data = cik_get_rb_disabled(rdev, max_rb_num_per_se, sh_per_se);
3144 if (rdev->family == CHIP_HAWAII)
3145 disabled_rbs |= data << ((i * sh_per_se + j) * HAWAII_RB_BITMAP_WIDTH_PER_SH);
3147 disabled_rbs |= data << ((i * sh_per_se + j) * CIK_RB_BITMAP_WIDTH_PER_SH);
3150 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
3151 mutex_unlock(&rdev->grbm_idx_mutex);
3154 for (i = 0; i < max_rb_num_per_se * se_num; i++) {
3155 if (!(disabled_rbs & mask))
3156 enabled_rbs |= mask;
3160 rdev->config.cik.backend_enable_mask = enabled_rbs;
3162 mutex_lock(&rdev->grbm_idx_mutex);
3163 for (i = 0; i < se_num; i++) {
3164 cik_select_se_sh(rdev, i, 0xffffffff);
3166 for (j = 0; j < sh_per_se; j++) {
3167 switch (enabled_rbs & 3) {
3170 data |= PKR_MAP(RASTER_CONFIG_RB_MAP_3);
3172 data |= PKR_MAP(RASTER_CONFIG_RB_MAP_0);
3175 data |= (RASTER_CONFIG_RB_MAP_0 << (i * sh_per_se + j) * 2);
3178 data |= (RASTER_CONFIG_RB_MAP_3 << (i * sh_per_se + j) * 2);
3182 data |= (RASTER_CONFIG_RB_MAP_2 << (i * sh_per_se + j) * 2);
3187 WREG32(PA_SC_RASTER_CONFIG, data);
3189 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
3190 mutex_unlock(&rdev->grbm_idx_mutex);
3194 * cik_gpu_init - setup the 3D engine
3196 * @rdev: radeon_device pointer
3198 * Configures the 3D engine and tiling configuration
3199 * registers so that the 3D engine is usable.
3201 static void cik_gpu_init(struct radeon_device *rdev)
3203 u32 gb_addr_config = RREG32(GB_ADDR_CONFIG);
3204 u32 mc_shared_chmap, mc_arb_ramcfg;
3205 u32 hdp_host_path_cntl;
3209 switch (rdev->family) {
3211 rdev->config.cik.max_shader_engines = 2;
3212 rdev->config.cik.max_tile_pipes = 4;
3213 rdev->config.cik.max_cu_per_sh = 7;
3214 rdev->config.cik.max_sh_per_se = 1;
3215 rdev->config.cik.max_backends_per_se = 2;
3216 rdev->config.cik.max_texture_channel_caches = 4;
3217 rdev->config.cik.max_gprs = 256;
3218 rdev->config.cik.max_gs_threads = 32;
3219 rdev->config.cik.max_hw_contexts = 8;
3221 rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
3222 rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
3223 rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
3224 rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
3225 gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
3228 rdev->config.cik.max_shader_engines = 4;
3229 rdev->config.cik.max_tile_pipes = 16;
3230 rdev->config.cik.max_cu_per_sh = 11;
3231 rdev->config.cik.max_sh_per_se = 1;
3232 rdev->config.cik.max_backends_per_se = 4;
3233 rdev->config.cik.max_texture_channel_caches = 16;
3234 rdev->config.cik.max_gprs = 256;
3235 rdev->config.cik.max_gs_threads = 32;
3236 rdev->config.cik.max_hw_contexts = 8;
3238 rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
3239 rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
3240 rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
3241 rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
3242 gb_addr_config = HAWAII_GB_ADDR_CONFIG_GOLDEN;
3245 rdev->config.cik.max_shader_engines = 1;
3246 rdev->config.cik.max_tile_pipes = 4;
3247 rdev->config.cik.max_cu_per_sh = 8;
3248 rdev->config.cik.max_backends_per_se = 2;
3249 rdev->config.cik.max_sh_per_se = 1;
3250 rdev->config.cik.max_texture_channel_caches = 4;
3251 rdev->config.cik.max_gprs = 256;
3252 rdev->config.cik.max_gs_threads = 16;
3253 rdev->config.cik.max_hw_contexts = 8;
3255 rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
3256 rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
3257 rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
3258 rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
3259 gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
3264 rdev->config.cik.max_shader_engines = 1;
3265 rdev->config.cik.max_tile_pipes = 2;
3266 rdev->config.cik.max_cu_per_sh = 2;
3267 rdev->config.cik.max_sh_per_se = 1;
3268 rdev->config.cik.max_backends_per_se = 1;
3269 rdev->config.cik.max_texture_channel_caches = 2;
3270 rdev->config.cik.max_gprs = 256;
3271 rdev->config.cik.max_gs_threads = 16;
3272 rdev->config.cik.max_hw_contexts = 8;
3274 rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
3275 rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
3276 rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
3277 rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
3278 gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
3282 /* Initialize HDP */
3283 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
3284 WREG32((0x2c14 + j), 0x00000000);
3285 WREG32((0x2c18 + j), 0x00000000);
3286 WREG32((0x2c1c + j), 0x00000000);
3287 WREG32((0x2c20 + j), 0x00000000);
3288 WREG32((0x2c24 + j), 0x00000000);
3291 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
3292 WREG32(SRBM_INT_CNTL, 0x1);
3293 WREG32(SRBM_INT_ACK, 0x1);
3295 WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
3297 mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
3298 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
3300 rdev->config.cik.num_tile_pipes = rdev->config.cik.max_tile_pipes;
3301 rdev->config.cik.mem_max_burst_length_bytes = 256;
3302 tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
3303 rdev->config.cik.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
3304 if (rdev->config.cik.mem_row_size_in_kb > 4)
3305 rdev->config.cik.mem_row_size_in_kb = 4;
3306 /* XXX use MC settings? */
3307 rdev->config.cik.shader_engine_tile_size = 32;
3308 rdev->config.cik.num_gpus = 1;
3309 rdev->config.cik.multi_gpu_tile_size = 64;
3311 /* fix up row size */
3312 gb_addr_config &= ~ROW_SIZE_MASK;
3313 switch (rdev->config.cik.mem_row_size_in_kb) {
3316 gb_addr_config |= ROW_SIZE(0);
3319 gb_addr_config |= ROW_SIZE(1);
3322 gb_addr_config |= ROW_SIZE(2);
3326 /* setup tiling info dword. gb_addr_config is not adequate since it does
3327 * not have bank info, so create a custom tiling dword.
3328 * bits 3:0 num_pipes
3329 * bits 7:4 num_banks
3330 * bits 11:8 group_size
3331 * bits 15:12 row_size
3333 rdev->config.cik.tile_config = 0;
3334 switch (rdev->config.cik.num_tile_pipes) {
3336 rdev->config.cik.tile_config |= (0 << 0);
3339 rdev->config.cik.tile_config |= (1 << 0);
3342 rdev->config.cik.tile_config |= (2 << 0);
3346 /* XXX what about 12? */
3347 rdev->config.cik.tile_config |= (3 << 0);
3350 rdev->config.cik.tile_config |=
3351 ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) << 4;
3352 rdev->config.cik.tile_config |=
3353 ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
3354 rdev->config.cik.tile_config |=
3355 ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
3357 WREG32(GB_ADDR_CONFIG, gb_addr_config);
3358 WREG32(HDP_ADDR_CONFIG, gb_addr_config);
3359 WREG32(DMIF_ADDR_CALC, gb_addr_config);
3360 WREG32(SDMA0_TILING_CONFIG + SDMA0_REGISTER_OFFSET, gb_addr_config & 0x70);
3361 WREG32(SDMA0_TILING_CONFIG + SDMA1_REGISTER_OFFSET, gb_addr_config & 0x70);
3362 WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
3363 WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
3364 WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
3366 cik_tiling_mode_table_init(rdev);
3368 cik_setup_rb(rdev, rdev->config.cik.max_shader_engines,
3369 rdev->config.cik.max_sh_per_se,
3370 rdev->config.cik.max_backends_per_se);
3372 rdev->config.cik.active_cus = 0;
3373 for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
3374 for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
3375 rdev->config.cik.active_cus +=
3376 hweight32(cik_get_cu_active_bitmap(rdev, i, j));
3380 /* set HW defaults for 3D engine */
3381 WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
3383 mutex_lock(&rdev->grbm_idx_mutex);
3385 * making sure that the following register writes will be broadcasted
3386 * to all the shaders
3388 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
3389 WREG32(SX_DEBUG_1, 0x20);
3391 WREG32(TA_CNTL_AUX, 0x00010000);
3393 tmp = RREG32(SPI_CONFIG_CNTL);
3395 WREG32(SPI_CONFIG_CNTL, tmp);
3397 WREG32(SQ_CONFIG, 1);
3399 WREG32(DB_DEBUG, 0);
3401 tmp = RREG32(DB_DEBUG2) & ~0xf00fffff;
3403 WREG32(DB_DEBUG2, tmp);
3405 tmp = RREG32(DB_DEBUG3) & ~0x0002021c;
3407 WREG32(DB_DEBUG3, tmp);
3409 tmp = RREG32(CB_HW_CONTROL) & ~0x00010000;
3411 WREG32(CB_HW_CONTROL, tmp);
3413 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
3415 WREG32(PA_SC_FIFO_SIZE, (SC_FRONTEND_PRIM_FIFO_SIZE(rdev->config.cik.sc_prim_fifo_size_frontend) |
3416 SC_BACKEND_PRIM_FIFO_SIZE(rdev->config.cik.sc_prim_fifo_size_backend) |
3417 SC_HIZ_TILE_FIFO_SIZE(rdev->config.cik.sc_hiz_tile_fifo_size) |
3418 SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.cik.sc_earlyz_tile_fifo_size)));
3420 WREG32(VGT_NUM_INSTANCES, 1);
3422 WREG32(CP_PERFMON_CNTL, 0);
3424 WREG32(SQ_CONFIG, 0);
3426 WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
3427 FORCE_EOV_MAX_REZ_CNT(255)));
3429 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
3430 AUTO_INVLD_EN(ES_AND_GS_AUTO));
3432 WREG32(VGT_GS_VERTEX_REUSE, 16);
3433 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
3435 tmp = RREG32(HDP_MISC_CNTL);
3436 tmp |= HDP_FLUSH_INVALIDATE_CACHE;
3437 WREG32(HDP_MISC_CNTL, tmp);
3439 hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
3440 WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
3442 WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
3443 WREG32(PA_SC_ENHANCE, ENABLE_PA_SC_OUT_OF_ORDER);
3444 mutex_unlock(&rdev->grbm_idx_mutex);
3450 * GPU scratch registers helpers function.
3453 * cik_scratch_init - setup driver info for CP scratch regs
3455 * @rdev: radeon_device pointer
3457 * Set up the number and offset of the CP scratch registers.
3458 * NOTE: use of CP scratch registers is a legacy inferface and
3459 * is not used by default on newer asics (r6xx+). On newer asics,
3460 * memory buffers are used for fences rather than scratch regs.
3462 static void cik_scratch_init(struct radeon_device *rdev)
3466 rdev->scratch.num_reg = 7;
3467 rdev->scratch.reg_base = SCRATCH_REG0;
3468 for (i = 0; i < rdev->scratch.num_reg; i++) {
3469 rdev->scratch.free[i] = true;
3470 rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
3475 * cik_ring_test - basic gfx ring test
3477 * @rdev: radeon_device pointer
3478 * @ring: radeon_ring structure holding ring information
3480 * Allocate a scratch register and write to it using the gfx ring (CIK).
3481 * Provides a basic gfx ring test to verify that the ring is working.
3482 * Used by cik_cp_gfx_resume();
3483 * Returns 0 on success, error on failure.
3485 int cik_ring_test(struct radeon_device *rdev, struct radeon_ring *ring)
3492 r = radeon_scratch_get(rdev, &scratch);
3494 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
3497 WREG32(scratch, 0xCAFEDEAD);
3498 r = radeon_ring_lock(rdev, ring, 3);
3500 DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ring->idx, r);
3501 radeon_scratch_free(rdev, scratch);
3504 radeon_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
3505 radeon_ring_write(ring, ((scratch - PACKET3_SET_UCONFIG_REG_START) >> 2));
3506 radeon_ring_write(ring, 0xDEADBEEF);
3507 radeon_ring_unlock_commit(rdev, ring, false);
3509 for (i = 0; i < rdev->usec_timeout; i++) {
3510 tmp = RREG32(scratch);
3511 if (tmp == 0xDEADBEEF)
3515 if (i < rdev->usec_timeout) {
3516 DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
3518 DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
3519 ring->idx, scratch, tmp);
3522 radeon_scratch_free(rdev, scratch);
3527 * cik_hdp_flush_cp_ring_emit - emit an hdp flush on the cp
3529 * @rdev: radeon_device pointer
3530 * @ridx: radeon ring index
3532 * Emits an hdp flush on the cp.
3534 static void cik_hdp_flush_cp_ring_emit(struct radeon_device *rdev,
3537 struct radeon_ring *ring = &rdev->ring[ridx];
3540 switch (ring->idx) {
3541 case CAYMAN_RING_TYPE_CP1_INDEX:
3542 case CAYMAN_RING_TYPE_CP2_INDEX:
3546 ref_and_mask = CP2 << ring->pipe;
3549 ref_and_mask = CP6 << ring->pipe;
3555 case RADEON_RING_TYPE_GFX_INDEX:
3560 radeon_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
3561 radeon_ring_write(ring, (WAIT_REG_MEM_OPERATION(1) | /* write, wait, write */
3562 WAIT_REG_MEM_FUNCTION(3) | /* == */
3563 WAIT_REG_MEM_ENGINE(1))); /* pfp */
3564 radeon_ring_write(ring, GPU_HDP_FLUSH_REQ >> 2);
3565 radeon_ring_write(ring, GPU_HDP_FLUSH_DONE >> 2);
3566 radeon_ring_write(ring, ref_and_mask);
3567 radeon_ring_write(ring, ref_and_mask);
3568 radeon_ring_write(ring, 0x20); /* poll interval */
3572 * cik_fence_gfx_ring_emit - emit a fence on the gfx ring
3574 * @rdev: radeon_device pointer
3575 * @fence: radeon fence object
3577 * Emits a fence sequnce number on the gfx ring and flushes
3580 void cik_fence_gfx_ring_emit(struct radeon_device *rdev,
3581 struct radeon_fence *fence)
3583 struct radeon_ring *ring = &rdev->ring[fence->ring];
3584 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
3586 /* Workaround for cache flush problems. First send a dummy EOP
3587 * event down the pipe with seq one below.
3589 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
3590 radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
3592 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
3594 radeon_ring_write(ring, addr & 0xfffffffc);
3595 radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) |
3596 DATA_SEL(1) | INT_SEL(0));
3597 radeon_ring_write(ring, fence->seq - 1);
3598 radeon_ring_write(ring, 0);
3600 /* Then send the real EOP event down the pipe. */
3601 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
3602 radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
3604 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
3606 radeon_ring_write(ring, addr & 0xfffffffc);
3607 radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) | DATA_SEL(1) | INT_SEL(2));
3608 radeon_ring_write(ring, fence->seq);
3609 radeon_ring_write(ring, 0);
3613 * cik_fence_compute_ring_emit - emit a fence on the compute ring
3615 * @rdev: radeon_device pointer
3616 * @fence: radeon fence object
3618 * Emits a fence sequnce number on the compute ring and flushes
3621 void cik_fence_compute_ring_emit(struct radeon_device *rdev,
3622 struct radeon_fence *fence)
3624 struct radeon_ring *ring = &rdev->ring[fence->ring];
3625 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
3627 /* RELEASE_MEM - flush caches, send int */
3628 radeon_ring_write(ring, PACKET3(PACKET3_RELEASE_MEM, 5));
3629 radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
3631 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
3633 radeon_ring_write(ring, DATA_SEL(1) | INT_SEL(2));
3634 radeon_ring_write(ring, addr & 0xfffffffc);
3635 radeon_ring_write(ring, upper_32_bits(addr));
3636 radeon_ring_write(ring, fence->seq);
3637 radeon_ring_write(ring, 0);
3641 * cik_semaphore_ring_emit - emit a semaphore on the CP ring
3643 * @rdev: radeon_device pointer
3644 * @ring: radeon ring buffer object
3645 * @semaphore: radeon semaphore object
3646 * @emit_wait: Is this a sempahore wait?
3648 * Emits a semaphore signal/wait packet to the CP ring and prevents the PFP
3649 * from running ahead of semaphore waits.
3651 bool cik_semaphore_ring_emit(struct radeon_device *rdev,
3652 struct radeon_ring *ring,
3653 struct radeon_semaphore *semaphore,
3656 uint64_t addr = semaphore->gpu_addr;
3657 unsigned sel = emit_wait ? PACKET3_SEM_SEL_WAIT : PACKET3_SEM_SEL_SIGNAL;
3659 radeon_ring_write(ring, PACKET3(PACKET3_MEM_SEMAPHORE, 1));
3660 radeon_ring_write(ring, lower_32_bits(addr));
3661 radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) | sel);
3663 if (emit_wait && ring->idx == RADEON_RING_TYPE_GFX_INDEX) {
3664 /* Prevent the PFP from running ahead of the semaphore wait */
3665 radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
3666 radeon_ring_write(ring, 0x0);
3673 * cik_copy_cpdma - copy pages using the CP DMA engine
3675 * @rdev: radeon_device pointer
3676 * @src_offset: src GPU address
3677 * @dst_offset: dst GPU address
3678 * @num_gpu_pages: number of GPU pages to xfer
3679 * @resv: reservation object to sync to
3681 * Copy GPU paging using the CP DMA engine (CIK+).
3682 * Used by the radeon ttm implementation to move pages if
3683 * registered as the asic copy callback.
3685 struct radeon_fence *cik_copy_cpdma(struct radeon_device *rdev,
3686 uint64_t src_offset, uint64_t dst_offset,
3687 unsigned num_gpu_pages,
3688 struct reservation_object *resv)
3690 struct radeon_fence *fence;
3691 struct radeon_sync sync;
3692 int ring_index = rdev->asic->copy.blit_ring_index;
3693 struct radeon_ring *ring = &rdev->ring[ring_index];
3694 u32 size_in_bytes, cur_size_in_bytes, control;
3698 radeon_sync_create(&sync);
3700 size_in_bytes = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT);
3701 num_loops = DIV_ROUND_UP(size_in_bytes, 0x1fffff);
3702 r = radeon_ring_lock(rdev, ring, num_loops * 7 + 18);
3704 DRM_ERROR("radeon: moving bo (%d).\n", r);
3705 radeon_sync_free(rdev, &sync, NULL);
3709 radeon_sync_resv(rdev, &sync, resv, false);
3710 radeon_sync_rings(rdev, &sync, ring->idx);
3712 for (i = 0; i < num_loops; i++) {
3713 cur_size_in_bytes = size_in_bytes;
3714 if (cur_size_in_bytes > 0x1fffff)
3715 cur_size_in_bytes = 0x1fffff;
3716 size_in_bytes -= cur_size_in_bytes;
3718 if (size_in_bytes == 0)
3719 control |= PACKET3_DMA_DATA_CP_SYNC;
3720 radeon_ring_write(ring, PACKET3(PACKET3_DMA_DATA, 5));
3721 radeon_ring_write(ring, control);
3722 radeon_ring_write(ring, lower_32_bits(src_offset));
3723 radeon_ring_write(ring, upper_32_bits(src_offset));
3724 radeon_ring_write(ring, lower_32_bits(dst_offset));
3725 radeon_ring_write(ring, upper_32_bits(dst_offset));
3726 radeon_ring_write(ring, cur_size_in_bytes);
3727 src_offset += cur_size_in_bytes;
3728 dst_offset += cur_size_in_bytes;
3731 r = radeon_fence_emit(rdev, &fence, ring->idx);
3733 radeon_ring_unlock_undo(rdev, ring);
3734 radeon_sync_free(rdev, &sync, NULL);
3738 radeon_ring_unlock_commit(rdev, ring, false);
3739 radeon_sync_free(rdev, &sync, fence);
3748 * cik_ring_ib_execute - emit an IB (Indirect Buffer) on the gfx ring
3750 * @rdev: radeon_device pointer
3751 * @ib: radeon indirect buffer object
3753 * Emits a DE (drawing engine) or CE (constant engine) IB
3754 * on the gfx ring. IBs are usually generated by userspace
3755 * acceleration drivers and submitted to the kernel for
3756 * scheduling on the ring. This function schedules the IB
3757 * on the gfx ring for execution by the GPU.
3759 void cik_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
3761 struct radeon_ring *ring = &rdev->ring[ib->ring];
3762 unsigned vm_id = ib->vm ? ib->vm->ids[ib->ring].id : 0;
3763 u32 header, control = INDIRECT_BUFFER_VALID;
3765 if (ib->is_const_ib) {
3766 /* set switch buffer packet before const IB */
3767 radeon_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
3768 radeon_ring_write(ring, 0);
3770 header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
3773 if (ring->rptr_save_reg) {
3774 next_rptr = ring->wptr + 3 + 4;
3775 radeon_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
3776 radeon_ring_write(ring, ((ring->rptr_save_reg -
3777 PACKET3_SET_UCONFIG_REG_START) >> 2));
3778 radeon_ring_write(ring, next_rptr);
3779 } else if (rdev->wb.enabled) {
3780 next_rptr = ring->wptr + 5 + 4;
3781 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
3782 radeon_ring_write(ring, WRITE_DATA_DST_SEL(1));
3783 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
3784 radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr));
3785 radeon_ring_write(ring, next_rptr);
3788 header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
3791 control |= ib->length_dw | (vm_id << 24);
3793 radeon_ring_write(ring, header);
3794 radeon_ring_write(ring, (ib->gpu_addr & 0xFFFFFFFC));
3795 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
3796 radeon_ring_write(ring, control);
3800 * cik_ib_test - basic gfx ring IB test
3802 * @rdev: radeon_device pointer
3803 * @ring: radeon_ring structure holding ring information
3805 * Allocate an IB and execute it on the gfx ring (CIK).
3806 * Provides a basic gfx ring test to verify that IBs are working.
3807 * Returns 0 on success, error on failure.
3809 int cik_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
3811 struct radeon_ib ib;
3817 r = radeon_scratch_get(rdev, &scratch);
3819 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
3822 WREG32(scratch, 0xCAFEDEAD);
3823 r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
3825 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
3826 radeon_scratch_free(rdev, scratch);
3829 ib.ptr[0] = PACKET3(PACKET3_SET_UCONFIG_REG, 1);
3830 ib.ptr[1] = ((scratch - PACKET3_SET_UCONFIG_REG_START) >> 2);
3831 ib.ptr[2] = 0xDEADBEEF;
3833 r = radeon_ib_schedule(rdev, &ib, NULL, false);
3835 radeon_scratch_free(rdev, scratch);
3836 radeon_ib_free(rdev, &ib);
3837 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
3840 r = radeon_fence_wait_timeout(ib.fence, false, usecs_to_jiffies(
3841 RADEON_USEC_IB_TEST_TIMEOUT));
3843 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
3844 radeon_scratch_free(rdev, scratch);
3845 radeon_ib_free(rdev, &ib);
3847 } else if (r == 0) {
3848 DRM_ERROR("radeon: fence wait timed out.\n");
3849 radeon_scratch_free(rdev, scratch);
3850 radeon_ib_free(rdev, &ib);
3854 for (i = 0; i < rdev->usec_timeout; i++) {
3855 tmp = RREG32(scratch);
3856 if (tmp == 0xDEADBEEF)
3860 if (i < rdev->usec_timeout) {
3861 DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
3863 DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
3867 radeon_scratch_free(rdev, scratch);
3868 radeon_ib_free(rdev, &ib);
3874 * On CIK, gfx and compute now have independant command processors.
3877 * Gfx consists of a single ring and can process both gfx jobs and
3878 * compute jobs. The gfx CP consists of three microengines (ME):
3879 * PFP - Pre-Fetch Parser
3881 * CE - Constant Engine
3882 * The PFP and ME make up what is considered the Drawing Engine (DE).
3883 * The CE is an asynchronous engine used for updating buffer desciptors
3884 * used by the DE so that they can be loaded into cache in parallel
3885 * while the DE is processing state update packets.
3888 * The compute CP consists of two microengines (ME):
3889 * MEC1 - Compute MicroEngine 1
3890 * MEC2 - Compute MicroEngine 2
3891 * Each MEC supports 4 compute pipes and each pipe supports 8 queues.
3892 * The queues are exposed to userspace and are programmed directly
3893 * by the compute runtime.
3896 * cik_cp_gfx_enable - enable/disable the gfx CP MEs
3898 * @rdev: radeon_device pointer
3899 * @enable: enable or disable the MEs
3901 * Halts or unhalts the gfx MEs.
3903 static void cik_cp_gfx_enable(struct radeon_device *rdev, bool enable)
3906 WREG32(CP_ME_CNTL, 0);
3908 if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
3909 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
3910 WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT));
3911 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
3917 * cik_cp_gfx_load_microcode - load the gfx CP ME ucode
3919 * @rdev: radeon_device pointer
3921 * Loads the gfx PFP, ME, and CE ucode.
3922 * Returns 0 for success, -EINVAL if the ucode is not available.
3924 static int cik_cp_gfx_load_microcode(struct radeon_device *rdev)
3928 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw)
3931 cik_cp_gfx_enable(rdev, false);
3934 const struct gfx_firmware_header_v1_0 *pfp_hdr =
3935 (const struct gfx_firmware_header_v1_0 *)rdev->pfp_fw->data;
3936 const struct gfx_firmware_header_v1_0 *ce_hdr =
3937 (const struct gfx_firmware_header_v1_0 *)rdev->ce_fw->data;
3938 const struct gfx_firmware_header_v1_0 *me_hdr =
3939 (const struct gfx_firmware_header_v1_0 *)rdev->me_fw->data;
3940 const __le32 *fw_data;
3943 radeon_ucode_print_gfx_hdr(&pfp_hdr->header);
3944 radeon_ucode_print_gfx_hdr(&ce_hdr->header);
3945 radeon_ucode_print_gfx_hdr(&me_hdr->header);
3948 fw_data = (const __le32 *)
3949 (rdev->pfp_fw->data + le32_to_cpu(pfp_hdr->header.ucode_array_offset_bytes));
3950 fw_size = le32_to_cpu(pfp_hdr->header.ucode_size_bytes) / 4;
3951 WREG32(CP_PFP_UCODE_ADDR, 0);
3952 for (i = 0; i < fw_size; i++)
3953 WREG32(CP_PFP_UCODE_DATA, le32_to_cpup(fw_data++));
3954 WREG32(CP_PFP_UCODE_ADDR, le32_to_cpu(pfp_hdr->header.ucode_version));
3957 fw_data = (const __le32 *)
3958 (rdev->ce_fw->data + le32_to_cpu(ce_hdr->header.ucode_array_offset_bytes));
3959 fw_size = le32_to_cpu(ce_hdr->header.ucode_size_bytes) / 4;
3960 WREG32(CP_CE_UCODE_ADDR, 0);
3961 for (i = 0; i < fw_size; i++)
3962 WREG32(CP_CE_UCODE_DATA, le32_to_cpup(fw_data++));
3963 WREG32(CP_CE_UCODE_ADDR, le32_to_cpu(ce_hdr->header.ucode_version));
3966 fw_data = (const __be32 *)
3967 (rdev->me_fw->data + le32_to_cpu(me_hdr->header.ucode_array_offset_bytes));
3968 fw_size = le32_to_cpu(me_hdr->header.ucode_size_bytes) / 4;
3969 WREG32(CP_ME_RAM_WADDR, 0);
3970 for (i = 0; i < fw_size; i++)
3971 WREG32(CP_ME_RAM_DATA, le32_to_cpup(fw_data++));
3972 WREG32(CP_ME_RAM_WADDR, le32_to_cpu(me_hdr->header.ucode_version));
3973 WREG32(CP_ME_RAM_RADDR, le32_to_cpu(me_hdr->header.ucode_version));
3975 const __be32 *fw_data;
3978 fw_data = (const __be32 *)rdev->pfp_fw->data;
3979 WREG32(CP_PFP_UCODE_ADDR, 0);
3980 for (i = 0; i < CIK_PFP_UCODE_SIZE; i++)
3981 WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
3982 WREG32(CP_PFP_UCODE_ADDR, 0);
3985 fw_data = (const __be32 *)rdev->ce_fw->data;
3986 WREG32(CP_CE_UCODE_ADDR, 0);
3987 for (i = 0; i < CIK_CE_UCODE_SIZE; i++)
3988 WREG32(CP_CE_UCODE_DATA, be32_to_cpup(fw_data++));
3989 WREG32(CP_CE_UCODE_ADDR, 0);
3992 fw_data = (const __be32 *)rdev->me_fw->data;
3993 WREG32(CP_ME_RAM_WADDR, 0);
3994 for (i = 0; i < CIK_ME_UCODE_SIZE; i++)
3995 WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
3996 WREG32(CP_ME_RAM_WADDR, 0);
4003 * cik_cp_gfx_start - start the gfx ring
4005 * @rdev: radeon_device pointer
4007 * Enables the ring and loads the clear state context and other
4008 * packets required to init the ring.
4009 * Returns 0 for success, error for failure.
4011 static int cik_cp_gfx_start(struct radeon_device *rdev)
4013 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
4017 WREG32(CP_MAX_CONTEXT, rdev->config.cik.max_hw_contexts - 1);
4018 WREG32(CP_ENDIAN_SWAP, 0);
4019 WREG32(CP_DEVICE_ID, 1);
4021 cik_cp_gfx_enable(rdev, true);
4023 r = radeon_ring_lock(rdev, ring, cik_default_size + 17);
4025 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
4029 /* init the CE partitions. CE only used for gfx on CIK */
4030 radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
4031 radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
4032 radeon_ring_write(ring, 0x8000);
4033 radeon_ring_write(ring, 0x8000);
4035 /* setup clear context state */
4036 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
4037 radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
4039 radeon_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
4040 radeon_ring_write(ring, 0x80000000);
4041 radeon_ring_write(ring, 0x80000000);
4043 for (i = 0; i < cik_default_size; i++)
4044 radeon_ring_write(ring, cik_default_state[i]);
4046 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
4047 radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
4049 /* set clear context state */
4050 radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
4051 radeon_ring_write(ring, 0);
4053 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
4054 radeon_ring_write(ring, 0x00000316);
4055 radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
4056 radeon_ring_write(ring, 0x00000010); /* VGT_OUT_DEALLOC_CNTL */
4058 radeon_ring_unlock_commit(rdev, ring, false);
4064 * cik_cp_gfx_fini - stop the gfx ring
4066 * @rdev: radeon_device pointer
4068 * Stop the gfx ring and tear down the driver ring
4071 static void cik_cp_gfx_fini(struct radeon_device *rdev)
4073 cik_cp_gfx_enable(rdev, false);
4074 radeon_ring_fini(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
4078 * cik_cp_gfx_resume - setup the gfx ring buffer registers
4080 * @rdev: radeon_device pointer
4082 * Program the location and size of the gfx ring buffer
4083 * and test it to make sure it's working.
4084 * Returns 0 for success, error for failure.
4086 static int cik_cp_gfx_resume(struct radeon_device *rdev)
4088 struct radeon_ring *ring;
4094 WREG32(CP_SEM_WAIT_TIMER, 0x0);
4095 if (rdev->family != CHIP_HAWAII)
4096 WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
4098 /* Set the write pointer delay */
4099 WREG32(CP_RB_WPTR_DELAY, 0);
4101 /* set the RB to use vmid 0 */
4102 WREG32(CP_RB_VMID, 0);
4104 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
4106 /* ring 0 - compute and gfx */
4107 /* Set ring buffer size */
4108 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
4109 rb_bufsz = order_base_2(ring->ring_size / 8);
4110 tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
4112 tmp |= BUF_SWAP_32BIT;
4114 WREG32(CP_RB0_CNTL, tmp);
4116 /* Initialize the ring buffer's read and write pointers */
4117 WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA);
4119 WREG32(CP_RB0_WPTR, ring->wptr);
4121 /* set the wb address wether it's enabled or not */
4122 WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
4123 WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
4125 /* scratch register shadowing is no longer supported */
4126 WREG32(SCRATCH_UMSK, 0);
4128 if (!rdev->wb.enabled)
4129 tmp |= RB_NO_UPDATE;
4132 WREG32(CP_RB0_CNTL, tmp);
4134 rb_addr = ring->gpu_addr >> 8;
4135 WREG32(CP_RB0_BASE, rb_addr);
4136 WREG32(CP_RB0_BASE_HI, upper_32_bits(rb_addr));
4138 /* start the ring */
4139 cik_cp_gfx_start(rdev);
4140 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
4141 r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
4143 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
4147 if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
4148 radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
4153 u32 cik_gfx_get_rptr(struct radeon_device *rdev,
4154 struct radeon_ring *ring)
4158 if (rdev->wb.enabled)
4159 rptr = rdev->wb.wb[ring->rptr_offs/4];
4161 rptr = RREG32(CP_RB0_RPTR);
4166 u32 cik_gfx_get_wptr(struct radeon_device *rdev,
4167 struct radeon_ring *ring)
4169 return RREG32(CP_RB0_WPTR);
4172 void cik_gfx_set_wptr(struct radeon_device *rdev,
4173 struct radeon_ring *ring)
4175 WREG32(CP_RB0_WPTR, ring->wptr);
4176 (void)RREG32(CP_RB0_WPTR);
4179 u32 cik_compute_get_rptr(struct radeon_device *rdev,
4180 struct radeon_ring *ring)
4184 if (rdev->wb.enabled) {
4185 rptr = rdev->wb.wb[ring->rptr_offs/4];
4187 mutex_lock(&rdev->srbm_mutex);
4188 cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
4189 rptr = RREG32(CP_HQD_PQ_RPTR);
4190 cik_srbm_select(rdev, 0, 0, 0, 0);
4191 mutex_unlock(&rdev->srbm_mutex);
4197 u32 cik_compute_get_wptr(struct radeon_device *rdev,
4198 struct radeon_ring *ring)
4202 if (rdev->wb.enabled) {
4203 /* XXX check if swapping is necessary on BE */
4204 wptr = rdev->wb.wb[ring->wptr_offs/4];
4206 mutex_lock(&rdev->srbm_mutex);
4207 cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
4208 wptr = RREG32(CP_HQD_PQ_WPTR);
4209 cik_srbm_select(rdev, 0, 0, 0, 0);
4210 mutex_unlock(&rdev->srbm_mutex);
4216 void cik_compute_set_wptr(struct radeon_device *rdev,
4217 struct radeon_ring *ring)
4219 /* XXX check if swapping is necessary on BE */
4220 rdev->wb.wb[ring->wptr_offs/4] = ring->wptr;
4221 WDOORBELL32(ring->doorbell_index, ring->wptr);
4224 static void cik_compute_stop(struct radeon_device *rdev,
4225 struct radeon_ring *ring)
4229 cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
4230 /* Disable wptr polling. */
4231 tmp = RREG32(CP_PQ_WPTR_POLL_CNTL);
4232 tmp &= ~WPTR_POLL_EN;
4233 WREG32(CP_PQ_WPTR_POLL_CNTL, tmp);
4235 if (RREG32(CP_HQD_ACTIVE) & 1) {
4236 WREG32(CP_HQD_DEQUEUE_REQUEST, 1);
4237 for (j = 0; j < rdev->usec_timeout; j++) {
4238 if (!(RREG32(CP_HQD_ACTIVE) & 1))
4242 WREG32(CP_HQD_DEQUEUE_REQUEST, 0);
4243 WREG32(CP_HQD_PQ_RPTR, 0);
4244 WREG32(CP_HQD_PQ_WPTR, 0);
4246 cik_srbm_select(rdev, 0, 0, 0, 0);
4250 * cik_cp_compute_enable - enable/disable the compute CP MEs
4252 * @rdev: radeon_device pointer
4253 * @enable: enable or disable the MEs
4255 * Halts or unhalts the compute MEs.
4257 static void cik_cp_compute_enable(struct radeon_device *rdev, bool enable)
4260 WREG32(CP_MEC_CNTL, 0);
4263 * To make hibernation reliable we need to clear compute ring
4264 * configuration before halting the compute ring.
4266 mutex_lock(&rdev->srbm_mutex);
4267 cik_compute_stop(rdev,&rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX]);
4268 cik_compute_stop(rdev,&rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX]);
4269 mutex_unlock(&rdev->srbm_mutex);
4271 WREG32(CP_MEC_CNTL, (MEC_ME1_HALT | MEC_ME2_HALT));
4272 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
4273 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
4279 * cik_cp_compute_load_microcode - load the compute CP ME ucode
4281 * @rdev: radeon_device pointer
4283 * Loads the compute MEC1&2 ucode.
4284 * Returns 0 for success, -EINVAL if the ucode is not available.
4286 static int cik_cp_compute_load_microcode(struct radeon_device *rdev)
4293 cik_cp_compute_enable(rdev, false);
4296 const struct gfx_firmware_header_v1_0 *mec_hdr =
4297 (const struct gfx_firmware_header_v1_0 *)rdev->mec_fw->data;
4298 const __le32 *fw_data;
4301 radeon_ucode_print_gfx_hdr(&mec_hdr->header);
4304 fw_data = (const __le32 *)
4305 (rdev->mec_fw->data + le32_to_cpu(mec_hdr->header.ucode_array_offset_bytes));
4306 fw_size = le32_to_cpu(mec_hdr->header.ucode_size_bytes) / 4;
4307 WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
4308 for (i = 0; i < fw_size; i++)
4309 WREG32(CP_MEC_ME1_UCODE_DATA, le32_to_cpup(fw_data++));
4310 WREG32(CP_MEC_ME1_UCODE_ADDR, le32_to_cpu(mec_hdr->header.ucode_version));
4313 if (rdev->family == CHIP_KAVERI) {
4314 const struct gfx_firmware_header_v1_0 *mec2_hdr =
4315 (const struct gfx_firmware_header_v1_0 *)rdev->mec2_fw->data;
4317 fw_data = (const __le32 *)
4318 (rdev->mec2_fw->data +
4319 le32_to_cpu(mec2_hdr->header.ucode_array_offset_bytes));
4320 fw_size = le32_to_cpu(mec2_hdr->header.ucode_size_bytes) / 4;
4321 WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
4322 for (i = 0; i < fw_size; i++)
4323 WREG32(CP_MEC_ME2_UCODE_DATA, le32_to_cpup(fw_data++));
4324 WREG32(CP_MEC_ME2_UCODE_ADDR, le32_to_cpu(mec2_hdr->header.ucode_version));
4327 const __be32 *fw_data;
4330 fw_data = (const __be32 *)rdev->mec_fw->data;
4331 WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
4332 for (i = 0; i < CIK_MEC_UCODE_SIZE; i++)
4333 WREG32(CP_MEC_ME1_UCODE_DATA, be32_to_cpup(fw_data++));
4334 WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
4336 if (rdev->family == CHIP_KAVERI) {
4338 fw_data = (const __be32 *)rdev->mec_fw->data;
4339 WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
4340 for (i = 0; i < CIK_MEC_UCODE_SIZE; i++)
4341 WREG32(CP_MEC_ME2_UCODE_DATA, be32_to_cpup(fw_data++));
4342 WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
4350 * cik_cp_compute_start - start the compute queues
4352 * @rdev: radeon_device pointer
4354 * Enable the compute queues.
4355 * Returns 0 for success, error for failure.
4357 static int cik_cp_compute_start(struct radeon_device *rdev)
4359 cik_cp_compute_enable(rdev, true);
4365 * cik_cp_compute_fini - stop the compute queues
4367 * @rdev: radeon_device pointer
4369 * Stop the compute queues and tear down the driver queue
4372 static void cik_cp_compute_fini(struct radeon_device *rdev)
4376 cik_cp_compute_enable(rdev, false);
4378 for (i = 0; i < 2; i++) {
4380 idx = CAYMAN_RING_TYPE_CP1_INDEX;
4382 idx = CAYMAN_RING_TYPE_CP2_INDEX;
4384 if (rdev->ring[idx].mqd_obj) {
4385 r = radeon_bo_reserve(rdev->ring[idx].mqd_obj, false);
4386 if (unlikely(r != 0))
4387 dev_warn(rdev->dev, "(%d) reserve MQD bo failed\n", r);
4389 radeon_bo_unpin(rdev->ring[idx].mqd_obj);
4390 radeon_bo_unreserve(rdev->ring[idx].mqd_obj);
4392 radeon_bo_unref(&rdev->ring[idx].mqd_obj);
4393 rdev->ring[idx].mqd_obj = NULL;
4398 static void cik_mec_fini(struct radeon_device *rdev)
4402 if (rdev->mec.hpd_eop_obj) {
4403 r = radeon_bo_reserve(rdev->mec.hpd_eop_obj, false);
4404 if (unlikely(r != 0))
4405 dev_warn(rdev->dev, "(%d) reserve HPD EOP bo failed\n", r);
4406 radeon_bo_unpin(rdev->mec.hpd_eop_obj);
4407 radeon_bo_unreserve(rdev->mec.hpd_eop_obj);
4409 radeon_bo_unref(&rdev->mec.hpd_eop_obj);
4410 rdev->mec.hpd_eop_obj = NULL;
4414 #define MEC_HPD_SIZE 2048
4416 static int cik_mec_init(struct radeon_device *rdev)
4422 * KV: 2 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 64 Queues total
4423 * CI/KB: 1 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 32 Queues total
4424 * Nonetheless, we assign only 1 pipe because all other pipes will
4427 rdev->mec.num_mec = 1;
4428 rdev->mec.num_pipe = 1;
4429 rdev->mec.num_queue = rdev->mec.num_mec * rdev->mec.num_pipe * 8;
4431 if (rdev->mec.hpd_eop_obj == NULL) {
4432 r = radeon_bo_create(rdev,
4433 rdev->mec.num_mec *rdev->mec.num_pipe * MEC_HPD_SIZE * 2,
4435 RADEON_GEM_DOMAIN_GTT, 0, NULL, NULL,
4436 &rdev->mec.hpd_eop_obj);
4438 dev_warn(rdev->dev, "(%d) create HDP EOP bo failed\n", r);
4443 r = radeon_bo_reserve(rdev->mec.hpd_eop_obj, false);
4444 if (unlikely(r != 0)) {
4448 r = radeon_bo_pin(rdev->mec.hpd_eop_obj, RADEON_GEM_DOMAIN_GTT,
4449 &rdev->mec.hpd_eop_gpu_addr);
4451 dev_warn(rdev->dev, "(%d) pin HDP EOP bo failed\n", r);
4455 r = radeon_bo_kmap(rdev->mec.hpd_eop_obj, (void **)&hpd);
4457 dev_warn(rdev->dev, "(%d) map HDP EOP bo failed\n", r);
4462 /* clear memory. Not sure if this is required or not */
4463 memset(hpd, 0, rdev->mec.num_mec *rdev->mec.num_pipe * MEC_HPD_SIZE * 2);
4465 radeon_bo_kunmap(rdev->mec.hpd_eop_obj);
4466 radeon_bo_unreserve(rdev->mec.hpd_eop_obj);
4471 struct hqd_registers
4473 u32 cp_mqd_base_addr;
4474 u32 cp_mqd_base_addr_hi;
4477 u32 cp_hqd_persistent_state;
4478 u32 cp_hqd_pipe_priority;
4479 u32 cp_hqd_queue_priority;
4482 u32 cp_hqd_pq_base_hi;
4484 u32 cp_hqd_pq_rptr_report_addr;
4485 u32 cp_hqd_pq_rptr_report_addr_hi;
4486 u32 cp_hqd_pq_wptr_poll_addr;
4487 u32 cp_hqd_pq_wptr_poll_addr_hi;
4488 u32 cp_hqd_pq_doorbell_control;
4490 u32 cp_hqd_pq_control;
4491 u32 cp_hqd_ib_base_addr;
4492 u32 cp_hqd_ib_base_addr_hi;
4494 u32 cp_hqd_ib_control;
4495 u32 cp_hqd_iq_timer;
4497 u32 cp_hqd_dequeue_request;
4498 u32 cp_hqd_dma_offload;
4499 u32 cp_hqd_sema_cmd;
4500 u32 cp_hqd_msg_type;
4501 u32 cp_hqd_atomic0_preop_lo;
4502 u32 cp_hqd_atomic0_preop_hi;
4503 u32 cp_hqd_atomic1_preop_lo;
4504 u32 cp_hqd_atomic1_preop_hi;
4505 u32 cp_hqd_hq_scheduler0;
4506 u32 cp_hqd_hq_scheduler1;
4513 u32 dispatch_initiator;
4517 u32 pipeline_stat_enable;
4518 u32 perf_counter_enable;
4524 u32 resource_limits;
4525 u32 static_thread_mgmt01[2];
4527 u32 static_thread_mgmt23[2];
4529 u32 thread_trace_enable;
4532 u32 vgtcs_invoke_count[2];
4533 struct hqd_registers queue_state;
4535 u32 interrupt_queue[64];
4539 * cik_cp_compute_resume - setup the compute queue registers
4541 * @rdev: radeon_device pointer
4543 * Program the compute queues and test them to make sure they
4545 * Returns 0 for success, error for failure.
4547 static int cik_cp_compute_resume(struct radeon_device *rdev)
4551 bool use_doorbell = true;
4557 struct bonaire_mqd *mqd;
4559 r = cik_cp_compute_start(rdev);
4563 /* fix up chicken bits */
4564 tmp = RREG32(CP_CPF_DEBUG);
4566 WREG32(CP_CPF_DEBUG, tmp);
4568 /* init the pipes */
4569 mutex_lock(&rdev->srbm_mutex);
4571 for (i = 0; i < rdev->mec.num_pipe; ++i) {
4572 cik_srbm_select(rdev, 0, i, 0, 0);
4574 eop_gpu_addr = rdev->mec.hpd_eop_gpu_addr + (i * MEC_HPD_SIZE * 2) ;
4575 /* write the EOP addr */
4576 WREG32(CP_HPD_EOP_BASE_ADDR, eop_gpu_addr >> 8);
4577 WREG32(CP_HPD_EOP_BASE_ADDR_HI, upper_32_bits(eop_gpu_addr) >> 8);
4579 /* set the VMID assigned */
4580 WREG32(CP_HPD_EOP_VMID, 0);
4582 /* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */
4583 tmp = RREG32(CP_HPD_EOP_CONTROL);
4584 tmp &= ~EOP_SIZE_MASK;
4585 tmp |= order_base_2(MEC_HPD_SIZE / 8);
4586 WREG32(CP_HPD_EOP_CONTROL, tmp);
4589 mutex_unlock(&rdev->srbm_mutex);
4591 /* init the queues. Just two for now. */
4592 for (i = 0; i < 2; i++) {
4594 idx = CAYMAN_RING_TYPE_CP1_INDEX;
4596 idx = CAYMAN_RING_TYPE_CP2_INDEX;
4598 if (rdev->ring[idx].mqd_obj == NULL) {
4599 r = radeon_bo_create(rdev,
4600 sizeof(struct bonaire_mqd),
4602 RADEON_GEM_DOMAIN_GTT, 0, NULL,
4603 NULL, &rdev->ring[idx].mqd_obj);
4605 dev_warn(rdev->dev, "(%d) create MQD bo failed\n", r);
4610 r = radeon_bo_reserve(rdev->ring[idx].mqd_obj, false);
4611 if (unlikely(r != 0)) {
4612 cik_cp_compute_fini(rdev);
4615 r = radeon_bo_pin(rdev->ring[idx].mqd_obj, RADEON_GEM_DOMAIN_GTT,
4618 dev_warn(rdev->dev, "(%d) pin MQD bo failed\n", r);
4619 cik_cp_compute_fini(rdev);
4622 r = radeon_bo_kmap(rdev->ring[idx].mqd_obj, (void **)&buf);
4624 dev_warn(rdev->dev, "(%d) map MQD bo failed\n", r);
4625 cik_cp_compute_fini(rdev);
4629 /* init the mqd struct */
4630 memset(buf, 0, sizeof(struct bonaire_mqd));
4632 mqd = (struct bonaire_mqd *)buf;
4633 mqd->header = 0xC0310800;
4634 mqd->static_thread_mgmt01[0] = 0xffffffff;
4635 mqd->static_thread_mgmt01[1] = 0xffffffff;
4636 mqd->static_thread_mgmt23[0] = 0xffffffff;
4637 mqd->static_thread_mgmt23[1] = 0xffffffff;
4639 mutex_lock(&rdev->srbm_mutex);
4640 cik_srbm_select(rdev, rdev->ring[idx].me,
4641 rdev->ring[idx].pipe,
4642 rdev->ring[idx].queue, 0);
4644 /* disable wptr polling */
4645 tmp = RREG32(CP_PQ_WPTR_POLL_CNTL);
4646 tmp &= ~WPTR_POLL_EN;
4647 WREG32(CP_PQ_WPTR_POLL_CNTL, tmp);
4649 /* enable doorbell? */
4650 mqd->queue_state.cp_hqd_pq_doorbell_control =
4651 RREG32(CP_HQD_PQ_DOORBELL_CONTROL);
4653 mqd->queue_state.cp_hqd_pq_doorbell_control |= DOORBELL_EN;
4655 mqd->queue_state.cp_hqd_pq_doorbell_control &= ~DOORBELL_EN;
4656 WREG32(CP_HQD_PQ_DOORBELL_CONTROL,
4657 mqd->queue_state.cp_hqd_pq_doorbell_control);
4659 /* disable the queue if it's active */
4660 mqd->queue_state.cp_hqd_dequeue_request = 0;
4661 mqd->queue_state.cp_hqd_pq_rptr = 0;
4662 mqd->queue_state.cp_hqd_pq_wptr= 0;
4663 if (RREG32(CP_HQD_ACTIVE) & 1) {
4664 WREG32(CP_HQD_DEQUEUE_REQUEST, 1);
4665 for (j = 0; j < rdev->usec_timeout; j++) {
4666 if (!(RREG32(CP_HQD_ACTIVE) & 1))
4670 WREG32(CP_HQD_DEQUEUE_REQUEST, mqd->queue_state.cp_hqd_dequeue_request);
4671 WREG32(CP_HQD_PQ_RPTR, mqd->queue_state.cp_hqd_pq_rptr);
4672 WREG32(CP_HQD_PQ_WPTR, mqd->queue_state.cp_hqd_pq_wptr);
4675 /* set the pointer to the MQD */
4676 mqd->queue_state.cp_mqd_base_addr = mqd_gpu_addr & 0xfffffffc;
4677 mqd->queue_state.cp_mqd_base_addr_hi = upper_32_bits(mqd_gpu_addr);
4678 WREG32(CP_MQD_BASE_ADDR, mqd->queue_state.cp_mqd_base_addr);
4679 WREG32(CP_MQD_BASE_ADDR_HI, mqd->queue_state.cp_mqd_base_addr_hi);
4680 /* set MQD vmid to 0 */
4681 mqd->queue_state.cp_mqd_control = RREG32(CP_MQD_CONTROL);
4682 mqd->queue_state.cp_mqd_control &= ~MQD_VMID_MASK;
4683 WREG32(CP_MQD_CONTROL, mqd->queue_state.cp_mqd_control);
4685 /* set the pointer to the HQD, this is similar CP_RB0_BASE/_HI */
4686 hqd_gpu_addr = rdev->ring[idx].gpu_addr >> 8;
4687 mqd->queue_state.cp_hqd_pq_base = hqd_gpu_addr;
4688 mqd->queue_state.cp_hqd_pq_base_hi = upper_32_bits(hqd_gpu_addr);
4689 WREG32(CP_HQD_PQ_BASE, mqd->queue_state.cp_hqd_pq_base);
4690 WREG32(CP_HQD_PQ_BASE_HI, mqd->queue_state.cp_hqd_pq_base_hi);
4692 /* set up the HQD, this is similar to CP_RB0_CNTL */
4693 mqd->queue_state.cp_hqd_pq_control = RREG32(CP_HQD_PQ_CONTROL);
4694 mqd->queue_state.cp_hqd_pq_control &=
4695 ~(QUEUE_SIZE_MASK | RPTR_BLOCK_SIZE_MASK);
4697 mqd->queue_state.cp_hqd_pq_control |=
4698 order_base_2(rdev->ring[idx].ring_size / 8);
4699 mqd->queue_state.cp_hqd_pq_control |=
4700 (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8);
4702 mqd->queue_state.cp_hqd_pq_control |= BUF_SWAP_32BIT;
4704 mqd->queue_state.cp_hqd_pq_control &=
4705 ~(UNORD_DISPATCH | ROQ_PQ_IB_FLIP | PQ_VOLATILE);
4706 mqd->queue_state.cp_hqd_pq_control |=
4707 PRIV_STATE | KMD_QUEUE; /* assuming kernel queue control */
4708 WREG32(CP_HQD_PQ_CONTROL, mqd->queue_state.cp_hqd_pq_control);
4710 /* only used if CP_PQ_WPTR_POLL_CNTL.WPTR_POLL_EN=1 */
4712 wb_gpu_addr = rdev->wb.gpu_addr + CIK_WB_CP1_WPTR_OFFSET;
4714 wb_gpu_addr = rdev->wb.gpu_addr + CIK_WB_CP2_WPTR_OFFSET;
4715 mqd->queue_state.cp_hqd_pq_wptr_poll_addr = wb_gpu_addr & 0xfffffffc;
4716 mqd->queue_state.cp_hqd_pq_wptr_poll_addr_hi = upper_32_bits(wb_gpu_addr) & 0xffff;
4717 WREG32(CP_HQD_PQ_WPTR_POLL_ADDR, mqd->queue_state.cp_hqd_pq_wptr_poll_addr);
4718 WREG32(CP_HQD_PQ_WPTR_POLL_ADDR_HI,
4719 mqd->queue_state.cp_hqd_pq_wptr_poll_addr_hi);
4721 /* set the wb address wether it's enabled or not */
4723 wb_gpu_addr = rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET;
4725 wb_gpu_addr = rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET;
4726 mqd->queue_state.cp_hqd_pq_rptr_report_addr = wb_gpu_addr & 0xfffffffc;
4727 mqd->queue_state.cp_hqd_pq_rptr_report_addr_hi =
4728 upper_32_bits(wb_gpu_addr) & 0xffff;
4729 WREG32(CP_HQD_PQ_RPTR_REPORT_ADDR,
4730 mqd->queue_state.cp_hqd_pq_rptr_report_addr);
4731 WREG32(CP_HQD_PQ_RPTR_REPORT_ADDR_HI,
4732 mqd->queue_state.cp_hqd_pq_rptr_report_addr_hi);
4734 /* enable the doorbell if requested */
4736 mqd->queue_state.cp_hqd_pq_doorbell_control =
4737 RREG32(CP_HQD_PQ_DOORBELL_CONTROL);
4738 mqd->queue_state.cp_hqd_pq_doorbell_control &= ~DOORBELL_OFFSET_MASK;
4739 mqd->queue_state.cp_hqd_pq_doorbell_control |=
4740 DOORBELL_OFFSET(rdev->ring[idx].doorbell_index);
4741 mqd->queue_state.cp_hqd_pq_doorbell_control |= DOORBELL_EN;
4742 mqd->queue_state.cp_hqd_pq_doorbell_control &=
4743 ~(DOORBELL_SOURCE | DOORBELL_HIT);
4746 mqd->queue_state.cp_hqd_pq_doorbell_control = 0;
4748 WREG32(CP_HQD_PQ_DOORBELL_CONTROL,
4749 mqd->queue_state.cp_hqd_pq_doorbell_control);
4751 /* read and write pointers, similar to CP_RB0_WPTR/_RPTR */
4752 rdev->ring[idx].wptr = 0;
4753 mqd->queue_state.cp_hqd_pq_wptr = rdev->ring[idx].wptr;
4754 WREG32(CP_HQD_PQ_WPTR, mqd->queue_state.cp_hqd_pq_wptr);
4755 mqd->queue_state.cp_hqd_pq_rptr = RREG32(CP_HQD_PQ_RPTR);
4757 /* set the vmid for the queue */
4758 mqd->queue_state.cp_hqd_vmid = 0;
4759 WREG32(CP_HQD_VMID, mqd->queue_state.cp_hqd_vmid);
4761 /* activate the queue */
4762 mqd->queue_state.cp_hqd_active = 1;
4763 WREG32(CP_HQD_ACTIVE, mqd->queue_state.cp_hqd_active);
4765 cik_srbm_select(rdev, 0, 0, 0, 0);
4766 mutex_unlock(&rdev->srbm_mutex);
4768 radeon_bo_kunmap(rdev->ring[idx].mqd_obj);
4769 radeon_bo_unreserve(rdev->ring[idx].mqd_obj);
4771 rdev->ring[idx].ready = true;
4772 r = radeon_ring_test(rdev, idx, &rdev->ring[idx]);
4774 rdev->ring[idx].ready = false;
4780 static void cik_cp_enable(struct radeon_device *rdev, bool enable)
4782 cik_cp_gfx_enable(rdev, enable);
4783 cik_cp_compute_enable(rdev, enable);
4786 static int cik_cp_load_microcode(struct radeon_device *rdev)
4790 r = cik_cp_gfx_load_microcode(rdev);
4793 r = cik_cp_compute_load_microcode(rdev);
4800 static void cik_cp_fini(struct radeon_device *rdev)
4802 cik_cp_gfx_fini(rdev);
4803 cik_cp_compute_fini(rdev);
4806 static int cik_cp_resume(struct radeon_device *rdev)
4810 cik_enable_gui_idle_interrupt(rdev, false);
4812 r = cik_cp_load_microcode(rdev);
4816 r = cik_cp_gfx_resume(rdev);
4819 r = cik_cp_compute_resume(rdev);
4823 cik_enable_gui_idle_interrupt(rdev, true);
4828 static void cik_print_gpu_status_regs(struct radeon_device *rdev)
4830 dev_info(rdev->dev, " GRBM_STATUS=0x%08X\n",
4831 RREG32(GRBM_STATUS));
4832 dev_info(rdev->dev, " GRBM_STATUS2=0x%08X\n",
4833 RREG32(GRBM_STATUS2));
4834 dev_info(rdev->dev, " GRBM_STATUS_SE0=0x%08X\n",
4835 RREG32(GRBM_STATUS_SE0));
4836 dev_info(rdev->dev, " GRBM_STATUS_SE1=0x%08X\n",
4837 RREG32(GRBM_STATUS_SE1));
4838 dev_info(rdev->dev, " GRBM_STATUS_SE2=0x%08X\n",
4839 RREG32(GRBM_STATUS_SE2));
4840 dev_info(rdev->dev, " GRBM_STATUS_SE3=0x%08X\n",
4841 RREG32(GRBM_STATUS_SE3));
4842 dev_info(rdev->dev, " SRBM_STATUS=0x%08X\n",
4843 RREG32(SRBM_STATUS));
4844 dev_info(rdev->dev, " SRBM_STATUS2=0x%08X\n",
4845 RREG32(SRBM_STATUS2));
4846 dev_info(rdev->dev, " SDMA0_STATUS_REG = 0x%08X\n",
4847 RREG32(SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET));
4848 dev_info(rdev->dev, " SDMA1_STATUS_REG = 0x%08X\n",
4849 RREG32(SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET));
4850 dev_info(rdev->dev, " CP_STAT = 0x%08x\n", RREG32(CP_STAT));
4851 dev_info(rdev->dev, " CP_STALLED_STAT1 = 0x%08x\n",
4852 RREG32(CP_STALLED_STAT1));
4853 dev_info(rdev->dev, " CP_STALLED_STAT2 = 0x%08x\n",
4854 RREG32(CP_STALLED_STAT2));
4855 dev_info(rdev->dev, " CP_STALLED_STAT3 = 0x%08x\n",
4856 RREG32(CP_STALLED_STAT3));
4857 dev_info(rdev->dev, " CP_CPF_BUSY_STAT = 0x%08x\n",
4858 RREG32(CP_CPF_BUSY_STAT));
4859 dev_info(rdev->dev, " CP_CPF_STALLED_STAT1 = 0x%08x\n",
4860 RREG32(CP_CPF_STALLED_STAT1));
4861 dev_info(rdev->dev, " CP_CPF_STATUS = 0x%08x\n", RREG32(CP_CPF_STATUS));
4862 dev_info(rdev->dev, " CP_CPC_BUSY_STAT = 0x%08x\n", RREG32(CP_CPC_BUSY_STAT));
4863 dev_info(rdev->dev, " CP_CPC_STALLED_STAT1 = 0x%08x\n",
4864 RREG32(CP_CPC_STALLED_STAT1));
4865 dev_info(rdev->dev, " CP_CPC_STATUS = 0x%08x\n", RREG32(CP_CPC_STATUS));
4869 * cik_gpu_check_soft_reset - check which blocks are busy
4871 * @rdev: radeon_device pointer
4873 * Check which blocks are busy and return the relevant reset
4874 * mask to be used by cik_gpu_soft_reset().
4875 * Returns a mask of the blocks to be reset.
4877 u32 cik_gpu_check_soft_reset(struct radeon_device *rdev)
4883 tmp = RREG32(GRBM_STATUS);
4884 if (tmp & (PA_BUSY | SC_BUSY |
4885 BCI_BUSY | SX_BUSY |
4886 TA_BUSY | VGT_BUSY |
4888 GDS_BUSY | SPI_BUSY |
4889 IA_BUSY | IA_BUSY_NO_DMA))
4890 reset_mask |= RADEON_RESET_GFX;
4892 if (tmp & (CP_BUSY | CP_COHERENCY_BUSY))
4893 reset_mask |= RADEON_RESET_CP;
4896 tmp = RREG32(GRBM_STATUS2);
4898 reset_mask |= RADEON_RESET_RLC;
4900 /* SDMA0_STATUS_REG */
4901 tmp = RREG32(SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET);
4902 if (!(tmp & SDMA_IDLE))
4903 reset_mask |= RADEON_RESET_DMA;
4905 /* SDMA1_STATUS_REG */
4906 tmp = RREG32(SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET);
4907 if (!(tmp & SDMA_IDLE))
4908 reset_mask |= RADEON_RESET_DMA1;
4911 tmp = RREG32(SRBM_STATUS2);
4912 if (tmp & SDMA_BUSY)
4913 reset_mask |= RADEON_RESET_DMA;
4915 if (tmp & SDMA1_BUSY)
4916 reset_mask |= RADEON_RESET_DMA1;
4919 tmp = RREG32(SRBM_STATUS);
4922 reset_mask |= RADEON_RESET_IH;
4925 reset_mask |= RADEON_RESET_SEM;
4927 if (tmp & GRBM_RQ_PENDING)
4928 reset_mask |= RADEON_RESET_GRBM;
4931 reset_mask |= RADEON_RESET_VMC;
4933 if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
4934 MCC_BUSY | MCD_BUSY))
4935 reset_mask |= RADEON_RESET_MC;
4937 if (evergreen_is_display_hung(rdev))
4938 reset_mask |= RADEON_RESET_DISPLAY;
4940 /* Skip MC reset as it's mostly likely not hung, just busy */
4941 if (reset_mask & RADEON_RESET_MC) {
4942 DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
4943 reset_mask &= ~RADEON_RESET_MC;
4950 * cik_gpu_soft_reset - soft reset GPU
4952 * @rdev: radeon_device pointer
4953 * @reset_mask: mask of which blocks to reset
4955 * Soft reset the blocks specified in @reset_mask.
4957 static void cik_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
4959 struct evergreen_mc_save save;
4960 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
4963 if (reset_mask == 0)
4966 dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
4968 cik_print_gpu_status_regs(rdev);
4969 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
4970 RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
4971 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
4972 RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
4981 /* Disable GFX parsing/prefetching */
4982 WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
4984 /* Disable MEC parsing/prefetching */
4985 WREG32(CP_MEC_CNTL, MEC_ME1_HALT | MEC_ME2_HALT);
4987 if (reset_mask & RADEON_RESET_DMA) {
4989 tmp = RREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET);
4991 WREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET, tmp);
4993 if (reset_mask & RADEON_RESET_DMA1) {
4995 tmp = RREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET);
4997 WREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET, tmp);
5000 evergreen_mc_stop(rdev, &save);
5001 if (evergreen_mc_wait_for_idle(rdev)) {
5002 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
5005 if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE | RADEON_RESET_CP))
5006 grbm_soft_reset = SOFT_RESET_CP | SOFT_RESET_GFX;
5008 if (reset_mask & RADEON_RESET_CP) {
5009 grbm_soft_reset |= SOFT_RESET_CP;
5011 srbm_soft_reset |= SOFT_RESET_GRBM;
5014 if (reset_mask & RADEON_RESET_DMA)
5015 srbm_soft_reset |= SOFT_RESET_SDMA;
5017 if (reset_mask & RADEON_RESET_DMA1)
5018 srbm_soft_reset |= SOFT_RESET_SDMA1;
5020 if (reset_mask & RADEON_RESET_DISPLAY)
5021 srbm_soft_reset |= SOFT_RESET_DC;
5023 if (reset_mask & RADEON_RESET_RLC)
5024 grbm_soft_reset |= SOFT_RESET_RLC;
5026 if (reset_mask & RADEON_RESET_SEM)
5027 srbm_soft_reset |= SOFT_RESET_SEM;
5029 if (reset_mask & RADEON_RESET_IH)
5030 srbm_soft_reset |= SOFT_RESET_IH;
5032 if (reset_mask & RADEON_RESET_GRBM)
5033 srbm_soft_reset |= SOFT_RESET_GRBM;
5035 if (reset_mask & RADEON_RESET_VMC)
5036 srbm_soft_reset |= SOFT_RESET_VMC;
5038 if (!(rdev->flags & RADEON_IS_IGP)) {
5039 if (reset_mask & RADEON_RESET_MC)
5040 srbm_soft_reset |= SOFT_RESET_MC;
5043 if (grbm_soft_reset) {
5044 tmp = RREG32(GRBM_SOFT_RESET);
5045 tmp |= grbm_soft_reset;
5046 dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
5047 WREG32(GRBM_SOFT_RESET, tmp);
5048 tmp = RREG32(GRBM_SOFT_RESET);
5052 tmp &= ~grbm_soft_reset;
5053 WREG32(GRBM_SOFT_RESET, tmp);
5054 tmp = RREG32(GRBM_SOFT_RESET);
5057 if (srbm_soft_reset) {
5058 tmp = RREG32(SRBM_SOFT_RESET);
5059 tmp |= srbm_soft_reset;
5060 dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
5061 WREG32(SRBM_SOFT_RESET, tmp);
5062 tmp = RREG32(SRBM_SOFT_RESET);
5066 tmp &= ~srbm_soft_reset;
5067 WREG32(SRBM_SOFT_RESET, tmp);
5068 tmp = RREG32(SRBM_SOFT_RESET);
5071 /* Wait a little for things to settle down */
5074 evergreen_mc_resume(rdev, &save);
5077 cik_print_gpu_status_regs(rdev);
5080 struct kv_reset_save_regs {
5081 u32 gmcon_reng_execute;
5086 static void kv_save_regs_for_reset(struct radeon_device *rdev,
5087 struct kv_reset_save_regs *save)
5089 save->gmcon_reng_execute = RREG32(GMCON_RENG_EXECUTE);
5090 save->gmcon_misc = RREG32(GMCON_MISC);
5091 save->gmcon_misc3 = RREG32(GMCON_MISC3);
5093 WREG32(GMCON_RENG_EXECUTE, save->gmcon_reng_execute & ~RENG_EXECUTE_ON_PWR_UP);
5094 WREG32(GMCON_MISC, save->gmcon_misc & ~(RENG_EXECUTE_ON_REG_UPDATE |
5095 STCTRL_STUTTER_EN));
5098 static void kv_restore_regs_for_reset(struct radeon_device *rdev,
5099 struct kv_reset_save_regs *save)
5103 WREG32(GMCON_PGFSM_WRITE, 0);
5104 WREG32(GMCON_PGFSM_CONFIG, 0x200010ff);
5106 for (i = 0; i < 5; i++)
5107 WREG32(GMCON_PGFSM_WRITE, 0);
5109 WREG32(GMCON_PGFSM_WRITE, 0);
5110 WREG32(GMCON_PGFSM_CONFIG, 0x300010ff);
5112 for (i = 0; i < 5; i++)
5113 WREG32(GMCON_PGFSM_WRITE, 0);
5115 WREG32(GMCON_PGFSM_WRITE, 0x210000);
5116 WREG32(GMCON_PGFSM_CONFIG, 0xa00010ff);
5118 for (i = 0; i < 5; i++)
5119 WREG32(GMCON_PGFSM_WRITE, 0);
5121 WREG32(GMCON_PGFSM_WRITE, 0x21003);
5122 WREG32(GMCON_PGFSM_CONFIG, 0xb00010ff);
5124 for (i = 0; i < 5; i++)
5125 WREG32(GMCON_PGFSM_WRITE, 0);
5127 WREG32(GMCON_PGFSM_WRITE, 0x2b00);
5128 WREG32(GMCON_PGFSM_CONFIG, 0xc00010ff);
5130 for (i = 0; i < 5; i++)
5131 WREG32(GMCON_PGFSM_WRITE, 0);
5133 WREG32(GMCON_PGFSM_WRITE, 0);
5134 WREG32(GMCON_PGFSM_CONFIG, 0xd00010ff);
5136 for (i = 0; i < 5; i++)
5137 WREG32(GMCON_PGFSM_WRITE, 0);
5139 WREG32(GMCON_PGFSM_WRITE, 0x420000);
5140 WREG32(GMCON_PGFSM_CONFIG, 0x100010ff);
5142 for (i = 0; i < 5; i++)
5143 WREG32(GMCON_PGFSM_WRITE, 0);
5145 WREG32(GMCON_PGFSM_WRITE, 0x120202);
5146 WREG32(GMCON_PGFSM_CONFIG, 0x500010ff);
5148 for (i = 0; i < 5; i++)
5149 WREG32(GMCON_PGFSM_WRITE, 0);
5151 WREG32(GMCON_PGFSM_WRITE, 0x3e3e36);
5152 WREG32(GMCON_PGFSM_CONFIG, 0x600010ff);
5154 for (i = 0; i < 5; i++)
5155 WREG32(GMCON_PGFSM_WRITE, 0);
5157 WREG32(GMCON_PGFSM_WRITE, 0x373f3e);
5158 WREG32(GMCON_PGFSM_CONFIG, 0x700010ff);
5160 for (i = 0; i < 5; i++)
5161 WREG32(GMCON_PGFSM_WRITE, 0);
5163 WREG32(GMCON_PGFSM_WRITE, 0x3e1332);
5164 WREG32(GMCON_PGFSM_CONFIG, 0xe00010ff);
5166 WREG32(GMCON_MISC3, save->gmcon_misc3);
5167 WREG32(GMCON_MISC, save->gmcon_misc);
5168 WREG32(GMCON_RENG_EXECUTE, save->gmcon_reng_execute);
5171 static void cik_gpu_pci_config_reset(struct radeon_device *rdev)
5173 struct evergreen_mc_save save;
5174 struct kv_reset_save_regs kv_save = { 0 };
5177 dev_info(rdev->dev, "GPU pci config reset\n");
5185 /* Disable GFX parsing/prefetching */
5186 WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
5188 /* Disable MEC parsing/prefetching */
5189 WREG32(CP_MEC_CNTL, MEC_ME1_HALT | MEC_ME2_HALT);
5192 tmp = RREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET);
5194 WREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET, tmp);
5196 tmp = RREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET);
5198 WREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET, tmp);
5199 /* XXX other engines? */
5201 /* halt the rlc, disable cp internal ints */
5206 /* disable mem access */
5207 evergreen_mc_stop(rdev, &save);
5208 if (evergreen_mc_wait_for_idle(rdev)) {
5209 dev_warn(rdev->dev, "Wait for MC idle timed out !\n");
5212 if (rdev->flags & RADEON_IS_IGP)
5213 kv_save_regs_for_reset(rdev, &kv_save);
5216 pci_clear_master(rdev->pdev);
5218 radeon_pci_config_reset(rdev);
5222 /* wait for asic to come out of reset */
5223 for (i = 0; i < rdev->usec_timeout; i++) {
5224 if (RREG32(CONFIG_MEMSIZE) != 0xffffffff)
5229 /* does asic init need to be run first??? */
5230 if (rdev->flags & RADEON_IS_IGP)
5231 kv_restore_regs_for_reset(rdev, &kv_save);
5235 * cik_asic_reset - soft reset GPU
5237 * @rdev: radeon_device pointer
5238 * @hard: force hard reset
5240 * Look up which blocks are hung and attempt
5242 * Returns 0 for success.
5244 int cik_asic_reset(struct radeon_device *rdev, bool hard)
5249 cik_gpu_pci_config_reset(rdev);
5253 reset_mask = cik_gpu_check_soft_reset(rdev);
5256 r600_set_bios_scratch_engine_hung(rdev, true);
5258 /* try soft reset */
5259 cik_gpu_soft_reset(rdev, reset_mask);
5261 reset_mask = cik_gpu_check_soft_reset(rdev);
5263 /* try pci config reset */
5264 if (reset_mask && radeon_hard_reset)
5265 cik_gpu_pci_config_reset(rdev);
5267 reset_mask = cik_gpu_check_soft_reset(rdev);
5270 r600_set_bios_scratch_engine_hung(rdev, false);
5276 * cik_gfx_is_lockup - check if the 3D engine is locked up
5278 * @rdev: radeon_device pointer
5279 * @ring: radeon_ring structure holding ring information
5281 * Check if the 3D engine is locked up (CIK).
5282 * Returns true if the engine is locked, false if not.
5284 bool cik_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
5286 u32 reset_mask = cik_gpu_check_soft_reset(rdev);
5288 if (!(reset_mask & (RADEON_RESET_GFX |
5289 RADEON_RESET_COMPUTE |
5290 RADEON_RESET_CP))) {
5291 radeon_ring_lockup_update(rdev, ring);
5294 return radeon_ring_test_lockup(rdev, ring);
5299 * cik_mc_program - program the GPU memory controller
5301 * @rdev: radeon_device pointer
5303 * Set the location of vram, gart, and AGP in the GPU's
5304 * physical address space (CIK).
5306 static void cik_mc_program(struct radeon_device *rdev)
5308 struct evergreen_mc_save save;
5312 /* Initialize HDP */
5313 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
5314 WREG32((0x2c14 + j), 0x00000000);
5315 WREG32((0x2c18 + j), 0x00000000);
5316 WREG32((0x2c1c + j), 0x00000000);
5317 WREG32((0x2c20 + j), 0x00000000);
5318 WREG32((0x2c24 + j), 0x00000000);
5320 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
5322 evergreen_mc_stop(rdev, &save);
5323 if (radeon_mc_wait_for_idle(rdev)) {
5324 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
5326 /* Lockout access through VGA aperture*/
5327 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
5328 /* Update configuration */
5329 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
5330 rdev->mc.vram_start >> 12);
5331 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
5332 rdev->mc.vram_end >> 12);
5333 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR,
5334 rdev->vram_scratch.gpu_addr >> 12);
5335 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
5336 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
5337 WREG32(MC_VM_FB_LOCATION, tmp);
5338 /* XXX double check these! */
5339 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
5340 WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
5341 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
5342 WREG32(MC_VM_AGP_BASE, 0);
5343 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
5344 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
5345 if (radeon_mc_wait_for_idle(rdev)) {
5346 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
5348 evergreen_mc_resume(rdev, &save);
5349 /* we need to own VRAM, so turn off the VGA renderer here
5350 * to stop it overwriting our objects */
5351 rv515_vga_render_disable(rdev);
5355 * cik_mc_init - initialize the memory controller driver params
5357 * @rdev: radeon_device pointer
5359 * Look up the amount of vram, vram width, and decide how to place
5360 * vram and gart within the GPU's physical address space (CIK).
5361 * Returns 0 for success.
5363 static int cik_mc_init(struct radeon_device *rdev)
5366 int chansize, numchan;
5368 /* Get VRAM informations */
5369 rdev->mc.vram_is_ddr = true;
5370 tmp = RREG32(MC_ARB_RAMCFG);
5371 if (tmp & CHANSIZE_MASK) {
5376 tmp = RREG32(MC_SHARED_CHMAP);
5377 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
5407 rdev->mc.vram_width = numchan * chansize;
5408 /* Could aper size report 0 ? */
5409 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
5410 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
5411 /* size in MB on si */
5412 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
5413 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
5414 rdev->mc.visible_vram_size = rdev->mc.aper_size;
5415 si_vram_gtt_location(rdev, &rdev->mc);
5416 radeon_update_bandwidth_info(rdev);
5423 * VMID 0 is the physical GPU addresses as used by the kernel.
5424 * VMIDs 1-15 are used for userspace clients and are handled
5425 * by the radeon vm/hsa code.
5428 * cik_pcie_gart_tlb_flush - gart tlb flush callback
5430 * @rdev: radeon_device pointer
5432 * Flush the TLB for the VMID 0 page table (CIK).
5434 void cik_pcie_gart_tlb_flush(struct radeon_device *rdev)
5436 /* flush hdp cache */
5437 WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0);
5439 /* bits 0-15 are the VM contexts0-15 */
5440 WREG32(VM_INVALIDATE_REQUEST, 0x1);
5444 * cik_pcie_gart_enable - gart enable
5446 * @rdev: radeon_device pointer
5448 * This sets up the TLBs, programs the page tables for VMID0,
5449 * sets up the hw for VMIDs 1-15 which are allocated on
5450 * demand, and sets up the global locations for the LDS, GDS,
5451 * and GPUVM for FSA64 clients (CIK).
5452 * Returns 0 for success, errors for failure.
5454 static int cik_pcie_gart_enable(struct radeon_device *rdev)
5458 if (rdev->gart.robj == NULL) {
5459 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
5462 r = radeon_gart_table_vram_pin(rdev);
5465 /* Setup TLB control */
5466 WREG32(MC_VM_MX_L1_TLB_CNTL,
5469 ENABLE_L1_FRAGMENT_PROCESSING |
5470 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
5471 ENABLE_ADVANCED_DRIVER_MODEL |
5472 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
5473 /* Setup L2 cache */
5474 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
5475 ENABLE_L2_FRAGMENT_PROCESSING |
5476 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
5477 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
5478 EFFECTIVE_L2_QUEUE_SIZE(7) |
5479 CONTEXT1_IDENTITY_ACCESS_MODE(1));
5480 WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
5481 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
5483 L2_CACHE_BIGK_FRAGMENT_SIZE(4));
5484 /* setup context0 */
5485 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
5486 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
5487 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
5488 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
5489 (u32)(rdev->dummy_page.addr >> 12));
5490 WREG32(VM_CONTEXT0_CNTL2, 0);
5491 WREG32(VM_CONTEXT0_CNTL, (ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
5492 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT));
5498 /* restore context1-15 */
5499 /* set vm size, must be a multiple of 4 */
5500 WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
5501 WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn - 1);
5502 for (i = 1; i < 16; i++) {
5504 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
5505 rdev->vm_manager.saved_table_addr[i]);
5507 WREG32(VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2),
5508 rdev->vm_manager.saved_table_addr[i]);
5511 /* enable context1-15 */
5512 WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
5513 (u32)(rdev->dummy_page.addr >> 12));
5514 WREG32(VM_CONTEXT1_CNTL2, 4);
5515 WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
5516 PAGE_TABLE_BLOCK_SIZE(radeon_vm_block_size - 9) |
5517 RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
5518 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
5519 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
5520 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
5521 PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
5522 PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
5523 VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
5524 VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
5525 READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
5526 READ_PROTECTION_FAULT_ENABLE_DEFAULT |
5527 WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
5528 WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
5530 if (rdev->family == CHIP_KAVERI) {
5531 u32 tmp = RREG32(CHUB_CONTROL);
5533 WREG32(CHUB_CONTROL, tmp);
5536 /* XXX SH_MEM regs */
5537 /* where to put LDS, scratch, GPUVM in FSA64 space */
5538 mutex_lock(&rdev->srbm_mutex);
5539 for (i = 0; i < 16; i++) {
5540 cik_srbm_select(rdev, 0, 0, 0, i);
5541 /* CP and shaders */
5542 WREG32(SH_MEM_CONFIG, SH_MEM_CONFIG_GFX_DEFAULT);
5543 WREG32(SH_MEM_APE1_BASE, 1);
5544 WREG32(SH_MEM_APE1_LIMIT, 0);
5545 WREG32(SH_MEM_BASES, 0);
5547 WREG32(SDMA0_GFX_VIRTUAL_ADDR + SDMA0_REGISTER_OFFSET, 0);
5548 WREG32(SDMA0_GFX_APE1_CNTL + SDMA0_REGISTER_OFFSET, 0);
5549 WREG32(SDMA0_GFX_VIRTUAL_ADDR + SDMA1_REGISTER_OFFSET, 0);
5550 WREG32(SDMA0_GFX_APE1_CNTL + SDMA1_REGISTER_OFFSET, 0);
5551 /* XXX SDMA RLC - todo */
5553 cik_srbm_select(rdev, 0, 0, 0, 0);
5554 mutex_unlock(&rdev->srbm_mutex);
5556 cik_pcie_gart_tlb_flush(rdev);
5557 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
5558 (unsigned)(rdev->mc.gtt_size >> 20),
5559 (unsigned long long)rdev->gart.table_addr);
5560 rdev->gart.ready = true;
5565 * cik_pcie_gart_disable - gart disable
5567 * @rdev: radeon_device pointer
5569 * This disables all VM page table (CIK).
5571 static void cik_pcie_gart_disable(struct radeon_device *rdev)
5575 for (i = 1; i < 16; ++i) {
5578 reg = VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2);
5580 reg = VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2);
5581 rdev->vm_manager.saved_table_addr[i] = RREG32(reg);
5584 /* Disable all tables */
5585 WREG32(VM_CONTEXT0_CNTL, 0);
5586 WREG32(VM_CONTEXT1_CNTL, 0);
5587 /* Setup TLB control */
5588 WREG32(MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE_NOT_IN_SYS |
5589 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
5590 /* Setup L2 cache */
5592 ENABLE_L2_FRAGMENT_PROCESSING |
5593 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
5594 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
5595 EFFECTIVE_L2_QUEUE_SIZE(7) |
5596 CONTEXT1_IDENTITY_ACCESS_MODE(1));
5597 WREG32(VM_L2_CNTL2, 0);
5598 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
5599 L2_CACHE_BIGK_FRAGMENT_SIZE(6));
5600 radeon_gart_table_vram_unpin(rdev);
5604 * cik_pcie_gart_fini - vm fini callback
5606 * @rdev: radeon_device pointer
5608 * Tears down the driver GART/VM setup (CIK).
5610 static void cik_pcie_gart_fini(struct radeon_device *rdev)
5612 cik_pcie_gart_disable(rdev);
5613 radeon_gart_table_vram_free(rdev);
5614 radeon_gart_fini(rdev);
5619 * cik_ib_parse - vm ib_parse callback
5621 * @rdev: radeon_device pointer
5622 * @ib: indirect buffer pointer
5624 * CIK uses hw IB checking so this is a nop (CIK).
5626 int cik_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
5633 * VMID 0 is the physical GPU addresses as used by the kernel.
5634 * VMIDs 1-15 are used for userspace clients and are handled
5635 * by the radeon vm/hsa code.
5638 * cik_vm_init - cik vm init callback
5640 * @rdev: radeon_device pointer
5642 * Inits cik specific vm parameters (number of VMs, base of vram for
5643 * VMIDs 1-15) (CIK).
5644 * Returns 0 for success.
5646 int cik_vm_init(struct radeon_device *rdev)
5650 * VMID 0 is reserved for System
5651 * radeon graphics/compute will use VMIDs 1-15
5653 rdev->vm_manager.nvm = 16;
5654 /* base offset of vram pages */
5655 if (rdev->flags & RADEON_IS_IGP) {
5656 u64 tmp = RREG32(MC_VM_FB_OFFSET);
5658 rdev->vm_manager.vram_base_offset = tmp;
5660 rdev->vm_manager.vram_base_offset = 0;
5666 * cik_vm_fini - cik vm fini callback
5668 * @rdev: radeon_device pointer
5670 * Tear down any asic specific VM setup (CIK).
5672 void cik_vm_fini(struct radeon_device *rdev)
5677 * cik_vm_decode_fault - print human readable fault info
5679 * @rdev: radeon_device pointer
5680 * @status: VM_CONTEXT1_PROTECTION_FAULT_STATUS register value
5681 * @addr: VM_CONTEXT1_PROTECTION_FAULT_ADDR register value
5683 * Print human readable fault information (CIK).
5685 static void cik_vm_decode_fault(struct radeon_device *rdev,
5686 u32 status, u32 addr, u32 mc_client)
5689 u32 vmid = (status & FAULT_VMID_MASK) >> FAULT_VMID_SHIFT;
5690 u32 protections = (status & PROTECTIONS_MASK) >> PROTECTIONS_SHIFT;
5691 char block[5] = { mc_client >> 24, (mc_client >> 16) & 0xff,
5692 (mc_client >> 8) & 0xff, mc_client & 0xff, 0 };
5694 if (rdev->family == CHIP_HAWAII)
5695 mc_id = (status & HAWAII_MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
5697 mc_id = (status & MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
5699 printk("VM fault (0x%02x, vmid %d) at page %u, %s from '%s' (0x%08x) (%d)\n",
5700 protections, vmid, addr,
5701 (status & MEMORY_CLIENT_RW_MASK) ? "write" : "read",
5702 block, mc_client, mc_id);
5706 * cik_vm_flush - cik vm flush using the CP
5708 * @rdev: radeon_device pointer
5710 * Update the page table base and flush the VM TLB
5711 * using the CP (CIK).
5713 void cik_vm_flush(struct radeon_device *rdev, struct radeon_ring *ring,
5714 unsigned vm_id, uint64_t pd_addr)
5716 int usepfp = (ring->idx == RADEON_RING_TYPE_GFX_INDEX);
5718 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5719 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
5720 WRITE_DATA_DST_SEL(0)));
5722 radeon_ring_write(ring,
5723 (VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm_id << 2)) >> 2);
5725 radeon_ring_write(ring,
5726 (VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm_id - 8) << 2)) >> 2);
5728 radeon_ring_write(ring, 0);
5729 radeon_ring_write(ring, pd_addr >> 12);
5731 /* update SH_MEM_* regs */
5732 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5733 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
5734 WRITE_DATA_DST_SEL(0)));
5735 radeon_ring_write(ring, SRBM_GFX_CNTL >> 2);
5736 radeon_ring_write(ring, 0);
5737 radeon_ring_write(ring, VMID(vm_id));
5739 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 6));
5740 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
5741 WRITE_DATA_DST_SEL(0)));
5742 radeon_ring_write(ring, SH_MEM_BASES >> 2);
5743 radeon_ring_write(ring, 0);
5745 radeon_ring_write(ring, 0); /* SH_MEM_BASES */
5746 radeon_ring_write(ring, SH_MEM_CONFIG_GFX_DEFAULT); /* SH_MEM_CONFIG */
5747 radeon_ring_write(ring, 1); /* SH_MEM_APE1_BASE */
5748 radeon_ring_write(ring, 0); /* SH_MEM_APE1_LIMIT */
5750 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5751 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
5752 WRITE_DATA_DST_SEL(0)));
5753 radeon_ring_write(ring, SRBM_GFX_CNTL >> 2);
5754 radeon_ring_write(ring, 0);
5755 radeon_ring_write(ring, VMID(0));
5758 cik_hdp_flush_cp_ring_emit(rdev, ring->idx);
5760 /* bits 0-15 are the VM contexts0-15 */
5761 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5762 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
5763 WRITE_DATA_DST_SEL(0)));
5764 radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
5765 radeon_ring_write(ring, 0);
5766 radeon_ring_write(ring, 1 << vm_id);
5768 /* wait for the invalidate to complete */
5769 radeon_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
5770 radeon_ring_write(ring, (WAIT_REG_MEM_OPERATION(0) | /* wait */
5771 WAIT_REG_MEM_FUNCTION(0) | /* always */
5772 WAIT_REG_MEM_ENGINE(0))); /* me */
5773 radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
5774 radeon_ring_write(ring, 0);
5775 radeon_ring_write(ring, 0); /* ref */
5776 radeon_ring_write(ring, 0); /* mask */
5777 radeon_ring_write(ring, 0x20); /* poll interval */
5779 /* compute doesn't have PFP */
5781 /* sync PFP to ME, otherwise we might get invalid PFP reads */
5782 radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
5783 radeon_ring_write(ring, 0x0);
5789 * The RLC is a multi-purpose microengine that handles a
5790 * variety of functions, the most important of which is
5791 * the interrupt controller.
5793 static void cik_enable_gui_idle_interrupt(struct radeon_device *rdev,
5796 u32 tmp = RREG32(CP_INT_CNTL_RING0);
5799 tmp |= (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
5801 tmp &= ~(CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
5802 WREG32(CP_INT_CNTL_RING0, tmp);
5805 static void cik_enable_lbpw(struct radeon_device *rdev, bool enable)
5809 tmp = RREG32(RLC_LB_CNTL);
5811 tmp |= LOAD_BALANCE_ENABLE;
5813 tmp &= ~LOAD_BALANCE_ENABLE;
5814 WREG32(RLC_LB_CNTL, tmp);
5817 static void cik_wait_for_rlc_serdes(struct radeon_device *rdev)
5822 mutex_lock(&rdev->grbm_idx_mutex);
5823 for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
5824 for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
5825 cik_select_se_sh(rdev, i, j);
5826 for (k = 0; k < rdev->usec_timeout; k++) {
5827 if (RREG32(RLC_SERDES_CU_MASTER_BUSY) == 0)
5833 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
5834 mutex_unlock(&rdev->grbm_idx_mutex);
5836 mask = SE_MASTER_BUSY_MASK | GC_MASTER_BUSY | TC0_MASTER_BUSY | TC1_MASTER_BUSY;
5837 for (k = 0; k < rdev->usec_timeout; k++) {
5838 if ((RREG32(RLC_SERDES_NONCU_MASTER_BUSY) & mask) == 0)
5844 static void cik_update_rlc(struct radeon_device *rdev, u32 rlc)
5848 tmp = RREG32(RLC_CNTL);
5850 WREG32(RLC_CNTL, rlc);
5853 static u32 cik_halt_rlc(struct radeon_device *rdev)
5857 orig = data = RREG32(RLC_CNTL);
5859 if (data & RLC_ENABLE) {
5862 data &= ~RLC_ENABLE;
5863 WREG32(RLC_CNTL, data);
5865 for (i = 0; i < rdev->usec_timeout; i++) {
5866 if ((RREG32(RLC_GPM_STAT) & RLC_GPM_BUSY) == 0)
5871 cik_wait_for_rlc_serdes(rdev);
5877 void cik_enter_rlc_safe_mode(struct radeon_device *rdev)
5881 tmp = REQ | MESSAGE(MSG_ENTER_RLC_SAFE_MODE);
5882 WREG32(RLC_GPR_REG2, tmp);
5884 mask = GFX_POWER_STATUS | GFX_CLOCK_STATUS;
5885 for (i = 0; i < rdev->usec_timeout; i++) {
5886 if ((RREG32(RLC_GPM_STAT) & mask) == mask)
5891 for (i = 0; i < rdev->usec_timeout; i++) {
5892 if ((RREG32(RLC_GPR_REG2) & REQ) == 0)
5898 void cik_exit_rlc_safe_mode(struct radeon_device *rdev)
5902 tmp = REQ | MESSAGE(MSG_EXIT_RLC_SAFE_MODE);
5903 WREG32(RLC_GPR_REG2, tmp);
5907 * cik_rlc_stop - stop the RLC ME
5909 * @rdev: radeon_device pointer
5911 * Halt the RLC ME (MicroEngine) (CIK).
5913 static void cik_rlc_stop(struct radeon_device *rdev)
5915 WREG32(RLC_CNTL, 0);
5917 cik_enable_gui_idle_interrupt(rdev, false);
5919 cik_wait_for_rlc_serdes(rdev);
5923 * cik_rlc_start - start the RLC ME
5925 * @rdev: radeon_device pointer
5927 * Unhalt the RLC ME (MicroEngine) (CIK).
5929 static void cik_rlc_start(struct radeon_device *rdev)
5931 WREG32(RLC_CNTL, RLC_ENABLE);
5933 cik_enable_gui_idle_interrupt(rdev, true);
5939 * cik_rlc_resume - setup the RLC hw
5941 * @rdev: radeon_device pointer
5943 * Initialize the RLC registers, load the ucode,
5944 * and start the RLC (CIK).
5945 * Returns 0 for success, -EINVAL if the ucode is not available.
5947 static int cik_rlc_resume(struct radeon_device *rdev)
5957 tmp = RREG32(RLC_CGCG_CGLS_CTRL) & 0xfffffffc;
5958 WREG32(RLC_CGCG_CGLS_CTRL, tmp);
5966 WREG32(RLC_LB_CNTR_INIT, 0);
5967 WREG32(RLC_LB_CNTR_MAX, 0x00008000);
5969 mutex_lock(&rdev->grbm_idx_mutex);
5970 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
5971 WREG32(RLC_LB_INIT_CU_MASK, 0xffffffff);
5972 WREG32(RLC_LB_PARAMS, 0x00600408);
5973 WREG32(RLC_LB_CNTL, 0x80000004);
5974 mutex_unlock(&rdev->grbm_idx_mutex);
5976 WREG32(RLC_MC_CNTL, 0);
5977 WREG32(RLC_UCODE_CNTL, 0);
5980 const struct rlc_firmware_header_v1_0 *hdr =
5981 (const struct rlc_firmware_header_v1_0 *)rdev->rlc_fw->data;
5982 const __le32 *fw_data = (const __le32 *)
5983 (rdev->rlc_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
5985 radeon_ucode_print_rlc_hdr(&hdr->header);
5987 size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
5988 WREG32(RLC_GPM_UCODE_ADDR, 0);
5989 for (i = 0; i < size; i++)
5990 WREG32(RLC_GPM_UCODE_DATA, le32_to_cpup(fw_data++));
5991 WREG32(RLC_GPM_UCODE_ADDR, le32_to_cpu(hdr->header.ucode_version));
5993 const __be32 *fw_data;
5995 switch (rdev->family) {
5999 size = BONAIRE_RLC_UCODE_SIZE;
6002 size = KV_RLC_UCODE_SIZE;
6005 size = KB_RLC_UCODE_SIZE;
6008 size = ML_RLC_UCODE_SIZE;
6012 fw_data = (const __be32 *)rdev->rlc_fw->data;
6013 WREG32(RLC_GPM_UCODE_ADDR, 0);
6014 for (i = 0; i < size; i++)
6015 WREG32(RLC_GPM_UCODE_DATA, be32_to_cpup(fw_data++));
6016 WREG32(RLC_GPM_UCODE_ADDR, 0);
6019 /* XXX - find out what chips support lbpw */
6020 cik_enable_lbpw(rdev, false);
6022 if (rdev->family == CHIP_BONAIRE)
6023 WREG32(RLC_DRIVER_DMA_STATUS, 0);
6025 cik_rlc_start(rdev);
6030 static void cik_enable_cgcg(struct radeon_device *rdev, bool enable)
6032 u32 data, orig, tmp, tmp2;
6034 orig = data = RREG32(RLC_CGCG_CGLS_CTRL);
6036 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGCG)) {
6037 cik_enable_gui_idle_interrupt(rdev, true);
6039 tmp = cik_halt_rlc(rdev);
6041 mutex_lock(&rdev->grbm_idx_mutex);
6042 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
6043 WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
6044 WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
6045 tmp2 = BPM_ADDR_MASK | CGCG_OVERRIDE_0 | CGLS_ENABLE;
6046 WREG32(RLC_SERDES_WR_CTRL, tmp2);
6047 mutex_unlock(&rdev->grbm_idx_mutex);
6049 cik_update_rlc(rdev, tmp);
6051 data |= CGCG_EN | CGLS_EN;
6053 cik_enable_gui_idle_interrupt(rdev, false);
6055 RREG32(CB_CGTT_SCLK_CTRL);
6056 RREG32(CB_CGTT_SCLK_CTRL);
6057 RREG32(CB_CGTT_SCLK_CTRL);
6058 RREG32(CB_CGTT_SCLK_CTRL);
6060 data &= ~(CGCG_EN | CGLS_EN);
6064 WREG32(RLC_CGCG_CGLS_CTRL, data);
6068 static void cik_enable_mgcg(struct radeon_device *rdev, bool enable)
6070 u32 data, orig, tmp = 0;
6072 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGCG)) {
6073 if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGLS) {
6074 if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CP_LS) {
6075 orig = data = RREG32(CP_MEM_SLP_CNTL);
6076 data |= CP_MEM_LS_EN;
6078 WREG32(CP_MEM_SLP_CNTL, data);
6082 orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
6086 WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
6088 tmp = cik_halt_rlc(rdev);
6090 mutex_lock(&rdev->grbm_idx_mutex);
6091 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
6092 WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
6093 WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
6094 data = BPM_ADDR_MASK | MGCG_OVERRIDE_0;
6095 WREG32(RLC_SERDES_WR_CTRL, data);
6096 mutex_unlock(&rdev->grbm_idx_mutex);
6098 cik_update_rlc(rdev, tmp);
6100 if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGTS) {
6101 orig = data = RREG32(CGTS_SM_CTRL_REG);
6102 data &= ~SM_MODE_MASK;
6103 data |= SM_MODE(0x2);
6104 data |= SM_MODE_ENABLE;
6105 data &= ~CGTS_OVERRIDE;
6106 if ((rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGLS) &&
6107 (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGTS_LS))
6108 data &= ~CGTS_LS_OVERRIDE;
6109 data &= ~ON_MONITOR_ADD_MASK;
6110 data |= ON_MONITOR_ADD_EN;
6111 data |= ON_MONITOR_ADD(0x96);
6113 WREG32(CGTS_SM_CTRL_REG, data);
6116 orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
6119 WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
6121 data = RREG32(RLC_MEM_SLP_CNTL);
6122 if (data & RLC_MEM_LS_EN) {
6123 data &= ~RLC_MEM_LS_EN;
6124 WREG32(RLC_MEM_SLP_CNTL, data);
6127 data = RREG32(CP_MEM_SLP_CNTL);
6128 if (data & CP_MEM_LS_EN) {
6129 data &= ~CP_MEM_LS_EN;
6130 WREG32(CP_MEM_SLP_CNTL, data);
6133 orig = data = RREG32(CGTS_SM_CTRL_REG);
6134 data |= CGTS_OVERRIDE | CGTS_LS_OVERRIDE;
6136 WREG32(CGTS_SM_CTRL_REG, data);
6138 tmp = cik_halt_rlc(rdev);
6140 mutex_lock(&rdev->grbm_idx_mutex);
6141 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
6142 WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
6143 WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
6144 data = BPM_ADDR_MASK | MGCG_OVERRIDE_1;
6145 WREG32(RLC_SERDES_WR_CTRL, data);
6146 mutex_unlock(&rdev->grbm_idx_mutex);
6148 cik_update_rlc(rdev, tmp);
6152 static const u32 mc_cg_registers[] =
6165 static void cik_enable_mc_ls(struct radeon_device *rdev,
6171 for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
6172 orig = data = RREG32(mc_cg_registers[i]);
6173 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_LS))
6174 data |= MC_LS_ENABLE;
6176 data &= ~MC_LS_ENABLE;
6178 WREG32(mc_cg_registers[i], data);
6182 static void cik_enable_mc_mgcg(struct radeon_device *rdev,
6188 for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
6189 orig = data = RREG32(mc_cg_registers[i]);
6190 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_MGCG))
6191 data |= MC_CG_ENABLE;
6193 data &= ~MC_CG_ENABLE;
6195 WREG32(mc_cg_registers[i], data);
6199 static void cik_enable_sdma_mgcg(struct radeon_device *rdev,
6204 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_MGCG)) {
6205 WREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET, 0x00000100);
6206 WREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET, 0x00000100);
6208 orig = data = RREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET);
6211 WREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET, data);
6213 orig = data = RREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET);
6216 WREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET, data);
6220 static void cik_enable_sdma_mgls(struct radeon_device *rdev,
6225 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_LS)) {
6226 orig = data = RREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET);
6229 WREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET, data);
6231 orig = data = RREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET);
6234 WREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET, data);
6236 orig = data = RREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET);
6239 WREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET, data);
6241 orig = data = RREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET);
6244 WREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET, data);
6248 static void cik_enable_uvd_mgcg(struct radeon_device *rdev,
6253 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_UVD_MGCG)) {
6254 data = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
6256 WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, data);
6258 orig = data = RREG32(UVD_CGC_CTRL);
6261 WREG32(UVD_CGC_CTRL, data);
6263 data = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
6265 WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, data);
6267 orig = data = RREG32(UVD_CGC_CTRL);
6270 WREG32(UVD_CGC_CTRL, data);
6274 static void cik_enable_bif_mgls(struct radeon_device *rdev,
6279 orig = data = RREG32_PCIE_PORT(PCIE_CNTL2);
6281 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_BIF_LS))
6282 data |= SLV_MEM_LS_EN | MST_MEM_LS_EN |
6283 REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN;
6285 data &= ~(SLV_MEM_LS_EN | MST_MEM_LS_EN |
6286 REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN);
6289 WREG32_PCIE_PORT(PCIE_CNTL2, data);
6292 static void cik_enable_hdp_mgcg(struct radeon_device *rdev,
6297 orig = data = RREG32(HDP_HOST_PATH_CNTL);
6299 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_MGCG))
6300 data &= ~CLOCK_GATING_DIS;
6302 data |= CLOCK_GATING_DIS;
6305 WREG32(HDP_HOST_PATH_CNTL, data);
6308 static void cik_enable_hdp_ls(struct radeon_device *rdev,
6313 orig = data = RREG32(HDP_MEM_POWER_LS);
6315 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_LS))
6316 data |= HDP_LS_ENABLE;
6318 data &= ~HDP_LS_ENABLE;
6321 WREG32(HDP_MEM_POWER_LS, data);
6324 void cik_update_cg(struct radeon_device *rdev,
6325 u32 block, bool enable)
6328 if (block & RADEON_CG_BLOCK_GFX) {
6329 cik_enable_gui_idle_interrupt(rdev, false);
6330 /* order matters! */
6332 cik_enable_mgcg(rdev, true);
6333 cik_enable_cgcg(rdev, true);
6335 cik_enable_cgcg(rdev, false);
6336 cik_enable_mgcg(rdev, false);
6338 cik_enable_gui_idle_interrupt(rdev, true);
6341 if (block & RADEON_CG_BLOCK_MC) {
6342 if (!(rdev->flags & RADEON_IS_IGP)) {
6343 cik_enable_mc_mgcg(rdev, enable);
6344 cik_enable_mc_ls(rdev, enable);
6348 if (block & RADEON_CG_BLOCK_SDMA) {
6349 cik_enable_sdma_mgcg(rdev, enable);
6350 cik_enable_sdma_mgls(rdev, enable);
6353 if (block & RADEON_CG_BLOCK_BIF) {
6354 cik_enable_bif_mgls(rdev, enable);
6357 if (block & RADEON_CG_BLOCK_UVD) {
6359 cik_enable_uvd_mgcg(rdev, enable);
6362 if (block & RADEON_CG_BLOCK_HDP) {
6363 cik_enable_hdp_mgcg(rdev, enable);
6364 cik_enable_hdp_ls(rdev, enable);
6367 if (block & RADEON_CG_BLOCK_VCE) {
6368 vce_v2_0_enable_mgcg(rdev, enable);
6372 static void cik_init_cg(struct radeon_device *rdev)
6375 cik_update_cg(rdev, RADEON_CG_BLOCK_GFX, true);
6378 si_init_uvd_internal_cg(rdev);
6380 cik_update_cg(rdev, (RADEON_CG_BLOCK_MC |
6381 RADEON_CG_BLOCK_SDMA |
6382 RADEON_CG_BLOCK_BIF |
6383 RADEON_CG_BLOCK_UVD |
6384 RADEON_CG_BLOCK_HDP), true);
6387 static void cik_fini_cg(struct radeon_device *rdev)
6389 cik_update_cg(rdev, (RADEON_CG_BLOCK_MC |
6390 RADEON_CG_BLOCK_SDMA |
6391 RADEON_CG_BLOCK_BIF |
6392 RADEON_CG_BLOCK_UVD |
6393 RADEON_CG_BLOCK_HDP), false);
6395 cik_update_cg(rdev, RADEON_CG_BLOCK_GFX, false);
6398 static void cik_enable_sck_slowdown_on_pu(struct radeon_device *rdev,
6403 orig = data = RREG32(RLC_PG_CNTL);
6404 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_RLC_SMU_HS))
6405 data |= SMU_CLK_SLOWDOWN_ON_PU_ENABLE;
6407 data &= ~SMU_CLK_SLOWDOWN_ON_PU_ENABLE;
6409 WREG32(RLC_PG_CNTL, data);
6412 static void cik_enable_sck_slowdown_on_pd(struct radeon_device *rdev,
6417 orig = data = RREG32(RLC_PG_CNTL);
6418 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_RLC_SMU_HS))
6419 data |= SMU_CLK_SLOWDOWN_ON_PD_ENABLE;
6421 data &= ~SMU_CLK_SLOWDOWN_ON_PD_ENABLE;
6423 WREG32(RLC_PG_CNTL, data);
6426 static void cik_enable_cp_pg(struct radeon_device *rdev, bool enable)
6430 orig = data = RREG32(RLC_PG_CNTL);
6431 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_CP))
6432 data &= ~DISABLE_CP_PG;
6434 data |= DISABLE_CP_PG;
6436 WREG32(RLC_PG_CNTL, data);
6439 static void cik_enable_gds_pg(struct radeon_device *rdev, bool enable)
6443 orig = data = RREG32(RLC_PG_CNTL);
6444 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GDS))
6445 data &= ~DISABLE_GDS_PG;
6447 data |= DISABLE_GDS_PG;
6449 WREG32(RLC_PG_CNTL, data);
6452 #define CP_ME_TABLE_SIZE 96
6453 #define CP_ME_TABLE_OFFSET 2048
6454 #define CP_MEC_TABLE_OFFSET 4096
6456 void cik_init_cp_pg_table(struct radeon_device *rdev)
6458 volatile u32 *dst_ptr;
6459 int me, i, max_me = 4;
6461 u32 table_offset, table_size;
6463 if (rdev->family == CHIP_KAVERI)
6466 if (rdev->rlc.cp_table_ptr == NULL)
6469 /* write the cp table buffer */
6470 dst_ptr = rdev->rlc.cp_table_ptr;
6471 for (me = 0; me < max_me; me++) {
6473 const __le32 *fw_data;
6474 const struct gfx_firmware_header_v1_0 *hdr;
6477 hdr = (const struct gfx_firmware_header_v1_0 *)rdev->ce_fw->data;
6478 fw_data = (const __le32 *)
6479 (rdev->ce_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6480 table_offset = le32_to_cpu(hdr->jt_offset);
6481 table_size = le32_to_cpu(hdr->jt_size);
6482 } else if (me == 1) {
6483 hdr = (const struct gfx_firmware_header_v1_0 *)rdev->pfp_fw->data;
6484 fw_data = (const __le32 *)
6485 (rdev->pfp_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6486 table_offset = le32_to_cpu(hdr->jt_offset);
6487 table_size = le32_to_cpu(hdr->jt_size);
6488 } else if (me == 2) {
6489 hdr = (const struct gfx_firmware_header_v1_0 *)rdev->me_fw->data;
6490 fw_data = (const __le32 *)
6491 (rdev->me_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6492 table_offset = le32_to_cpu(hdr->jt_offset);
6493 table_size = le32_to_cpu(hdr->jt_size);
6494 } else if (me == 3) {
6495 hdr = (const struct gfx_firmware_header_v1_0 *)rdev->mec_fw->data;
6496 fw_data = (const __le32 *)
6497 (rdev->mec_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6498 table_offset = le32_to_cpu(hdr->jt_offset);
6499 table_size = le32_to_cpu(hdr->jt_size);
6501 hdr = (const struct gfx_firmware_header_v1_0 *)rdev->mec2_fw->data;
6502 fw_data = (const __le32 *)
6503 (rdev->mec2_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6504 table_offset = le32_to_cpu(hdr->jt_offset);
6505 table_size = le32_to_cpu(hdr->jt_size);
6508 for (i = 0; i < table_size; i ++) {
6509 dst_ptr[bo_offset + i] =
6510 cpu_to_le32(le32_to_cpu(fw_data[table_offset + i]));
6512 bo_offset += table_size;
6514 const __be32 *fw_data;
6515 table_size = CP_ME_TABLE_SIZE;
6518 fw_data = (const __be32 *)rdev->ce_fw->data;
6519 table_offset = CP_ME_TABLE_OFFSET;
6520 } else if (me == 1) {
6521 fw_data = (const __be32 *)rdev->pfp_fw->data;
6522 table_offset = CP_ME_TABLE_OFFSET;
6523 } else if (me == 2) {
6524 fw_data = (const __be32 *)rdev->me_fw->data;
6525 table_offset = CP_ME_TABLE_OFFSET;
6527 fw_data = (const __be32 *)rdev->mec_fw->data;
6528 table_offset = CP_MEC_TABLE_OFFSET;
6531 for (i = 0; i < table_size; i ++) {
6532 dst_ptr[bo_offset + i] =
6533 cpu_to_le32(be32_to_cpu(fw_data[table_offset + i]));
6535 bo_offset += table_size;
6540 static void cik_enable_gfx_cgpg(struct radeon_device *rdev,
6545 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG)) {
6546 orig = data = RREG32(RLC_PG_CNTL);
6547 data |= GFX_PG_ENABLE;
6549 WREG32(RLC_PG_CNTL, data);
6551 orig = data = RREG32(RLC_AUTO_PG_CTRL);
6554 WREG32(RLC_AUTO_PG_CTRL, data);
6556 orig = data = RREG32(RLC_PG_CNTL);
6557 data &= ~GFX_PG_ENABLE;
6559 WREG32(RLC_PG_CNTL, data);
6561 orig = data = RREG32(RLC_AUTO_PG_CTRL);
6562 data &= ~AUTO_PG_EN;
6564 WREG32(RLC_AUTO_PG_CTRL, data);
6566 data = RREG32(DB_RENDER_CONTROL);
6570 static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh)
6572 u32 mask = 0, tmp, tmp1;
6575 mutex_lock(&rdev->grbm_idx_mutex);
6576 cik_select_se_sh(rdev, se, sh);
6577 tmp = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
6578 tmp1 = RREG32(GC_USER_SHADER_ARRAY_CONFIG);
6579 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
6580 mutex_unlock(&rdev->grbm_idx_mutex);
6587 for (i = 0; i < rdev->config.cik.max_cu_per_sh; i ++) {
6592 return (~tmp) & mask;
6595 static void cik_init_ao_cu_mask(struct radeon_device *rdev)
6597 u32 i, j, k, active_cu_number = 0;
6598 u32 mask, counter, cu_bitmap;
6601 for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
6602 for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
6606 for (k = 0; k < rdev->config.cik.max_cu_per_sh; k ++) {
6607 if (cik_get_cu_active_bitmap(rdev, i, j) & mask) {
6615 active_cu_number += counter;
6616 tmp |= (cu_bitmap << (i * 16 + j * 8));
6620 WREG32(RLC_PG_AO_CU_MASK, tmp);
6622 tmp = RREG32(RLC_MAX_PG_CU);
6623 tmp &= ~MAX_PU_CU_MASK;
6624 tmp |= MAX_PU_CU(active_cu_number);
6625 WREG32(RLC_MAX_PG_CU, tmp);
6628 static void cik_enable_gfx_static_mgpg(struct radeon_device *rdev,
6633 orig = data = RREG32(RLC_PG_CNTL);
6634 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_SMG))
6635 data |= STATIC_PER_CU_PG_ENABLE;
6637 data &= ~STATIC_PER_CU_PG_ENABLE;
6639 WREG32(RLC_PG_CNTL, data);
6642 static void cik_enable_gfx_dynamic_mgpg(struct radeon_device *rdev,
6647 orig = data = RREG32(RLC_PG_CNTL);
6648 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_DMG))
6649 data |= DYN_PER_CU_PG_ENABLE;
6651 data &= ~DYN_PER_CU_PG_ENABLE;
6653 WREG32(RLC_PG_CNTL, data);
6656 #define RLC_SAVE_AND_RESTORE_STARTING_OFFSET 0x90
6657 #define RLC_CLEAR_STATE_DESCRIPTOR_OFFSET 0x3D
6659 static void cik_init_gfx_cgpg(struct radeon_device *rdev)
6664 if (rdev->rlc.cs_data) {
6665 WREG32(RLC_GPM_SCRATCH_ADDR, RLC_CLEAR_STATE_DESCRIPTOR_OFFSET);
6666 WREG32(RLC_GPM_SCRATCH_DATA, upper_32_bits(rdev->rlc.clear_state_gpu_addr));
6667 WREG32(RLC_GPM_SCRATCH_DATA, lower_32_bits(rdev->rlc.clear_state_gpu_addr));
6668 WREG32(RLC_GPM_SCRATCH_DATA, rdev->rlc.clear_state_size);
6670 WREG32(RLC_GPM_SCRATCH_ADDR, RLC_CLEAR_STATE_DESCRIPTOR_OFFSET);
6671 for (i = 0; i < 3; i++)
6672 WREG32(RLC_GPM_SCRATCH_DATA, 0);
6674 if (rdev->rlc.reg_list) {
6675 WREG32(RLC_GPM_SCRATCH_ADDR, RLC_SAVE_AND_RESTORE_STARTING_OFFSET);
6676 for (i = 0; i < rdev->rlc.reg_list_size; i++)
6677 WREG32(RLC_GPM_SCRATCH_DATA, rdev->rlc.reg_list[i]);
6680 orig = data = RREG32(RLC_PG_CNTL);
6683 WREG32(RLC_PG_CNTL, data);
6685 WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
6686 WREG32(RLC_CP_TABLE_RESTORE, rdev->rlc.cp_table_gpu_addr >> 8);
6688 data = RREG32(CP_RB_WPTR_POLL_CNTL);
6689 data &= ~IDLE_POLL_COUNT_MASK;
6690 data |= IDLE_POLL_COUNT(0x60);
6691 WREG32(CP_RB_WPTR_POLL_CNTL, data);
6694 WREG32(RLC_PG_DELAY, data);
6696 data = RREG32(RLC_PG_DELAY_2);
6699 WREG32(RLC_PG_DELAY_2, data);
6701 data = RREG32(RLC_AUTO_PG_CTRL);
6702 data &= ~GRBM_REG_SGIT_MASK;
6703 data |= GRBM_REG_SGIT(0x700);
6704 WREG32(RLC_AUTO_PG_CTRL, data);
6708 static void cik_update_gfx_pg(struct radeon_device *rdev, bool enable)
6710 cik_enable_gfx_cgpg(rdev, enable);
6711 cik_enable_gfx_static_mgpg(rdev, enable);
6712 cik_enable_gfx_dynamic_mgpg(rdev, enable);
6715 u32 cik_get_csb_size(struct radeon_device *rdev)
6718 const struct cs_section_def *sect = NULL;
6719 const struct cs_extent_def *ext = NULL;
6721 if (rdev->rlc.cs_data == NULL)
6724 /* begin clear state */
6726 /* context control state */
6729 for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
6730 for (ext = sect->section; ext->extent != NULL; ++ext) {
6731 if (sect->id == SECT_CONTEXT)
6732 count += 2 + ext->reg_count;
6737 /* pa_sc_raster_config/pa_sc_raster_config1 */
6739 /* end clear state */
6747 void cik_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer)
6750 const struct cs_section_def *sect = NULL;
6751 const struct cs_extent_def *ext = NULL;
6753 if (rdev->rlc.cs_data == NULL)
6758 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
6759 buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
6761 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
6762 buffer[count++] = cpu_to_le32(0x80000000);
6763 buffer[count++] = cpu_to_le32(0x80000000);
6765 for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
6766 for (ext = sect->section; ext->extent != NULL; ++ext) {
6767 if (sect->id == SECT_CONTEXT) {
6769 cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
6770 buffer[count++] = cpu_to_le32(ext->reg_index - 0xa000);
6771 for (i = 0; i < ext->reg_count; i++)
6772 buffer[count++] = cpu_to_le32(ext->extent[i]);
6779 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 2));
6780 buffer[count++] = cpu_to_le32(PA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
6781 switch (rdev->family) {
6783 buffer[count++] = cpu_to_le32(0x16000012);
6784 buffer[count++] = cpu_to_le32(0x00000000);
6787 buffer[count++] = cpu_to_le32(0x00000000); /* XXX */
6788 buffer[count++] = cpu_to_le32(0x00000000);
6792 buffer[count++] = cpu_to_le32(0x00000000); /* XXX */
6793 buffer[count++] = cpu_to_le32(0x00000000);
6796 buffer[count++] = cpu_to_le32(0x3a00161a);
6797 buffer[count++] = cpu_to_le32(0x0000002e);
6800 buffer[count++] = cpu_to_le32(0x00000000);
6801 buffer[count++] = cpu_to_le32(0x00000000);
6805 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
6806 buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);
6808 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
6809 buffer[count++] = cpu_to_le32(0);
6812 static void cik_init_pg(struct radeon_device *rdev)
6814 if (rdev->pg_flags) {
6815 cik_enable_sck_slowdown_on_pu(rdev, true);
6816 cik_enable_sck_slowdown_on_pd(rdev, true);
6817 if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG) {
6818 cik_init_gfx_cgpg(rdev);
6819 cik_enable_cp_pg(rdev, true);
6820 cik_enable_gds_pg(rdev, true);
6822 cik_init_ao_cu_mask(rdev);
6823 cik_update_gfx_pg(rdev, true);
6827 static void cik_fini_pg(struct radeon_device *rdev)
6829 if (rdev->pg_flags) {
6830 cik_update_gfx_pg(rdev, false);
6831 if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG) {
6832 cik_enable_cp_pg(rdev, false);
6833 cik_enable_gds_pg(rdev, false);
6840 * Starting with r6xx, interrupts are handled via a ring buffer.
6841 * Ring buffers are areas of GPU accessible memory that the GPU
6842 * writes interrupt vectors into and the host reads vectors out of.
6843 * There is a rptr (read pointer) that determines where the
6844 * host is currently reading, and a wptr (write pointer)
6845 * which determines where the GPU has written. When the
6846 * pointers are equal, the ring is idle. When the GPU
6847 * writes vectors to the ring buffer, it increments the
6848 * wptr. When there is an interrupt, the host then starts
6849 * fetching commands and processing them until the pointers are
6850 * equal again at which point it updates the rptr.
6854 * cik_enable_interrupts - Enable the interrupt ring buffer
6856 * @rdev: radeon_device pointer
6858 * Enable the interrupt ring buffer (CIK).
6860 static void cik_enable_interrupts(struct radeon_device *rdev)
6862 u32 ih_cntl = RREG32(IH_CNTL);
6863 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
6865 ih_cntl |= ENABLE_INTR;
6866 ih_rb_cntl |= IH_RB_ENABLE;
6867 WREG32(IH_CNTL, ih_cntl);
6868 WREG32(IH_RB_CNTL, ih_rb_cntl);
6869 rdev->ih.enabled = true;
6873 * cik_disable_interrupts - Disable the interrupt ring buffer
6875 * @rdev: radeon_device pointer
6877 * Disable the interrupt ring buffer (CIK).
6879 static void cik_disable_interrupts(struct radeon_device *rdev)
6881 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
6882 u32 ih_cntl = RREG32(IH_CNTL);
6884 ih_rb_cntl &= ~IH_RB_ENABLE;
6885 ih_cntl &= ~ENABLE_INTR;
6886 WREG32(IH_RB_CNTL, ih_rb_cntl);
6887 WREG32(IH_CNTL, ih_cntl);
6888 /* set rptr, wptr to 0 */
6889 WREG32(IH_RB_RPTR, 0);
6890 WREG32(IH_RB_WPTR, 0);
6891 rdev->ih.enabled = false;
6896 * cik_disable_interrupt_state - Disable all interrupt sources
6898 * @rdev: radeon_device pointer
6900 * Clear all interrupt enable bits used by the driver (CIK).
6902 static void cik_disable_interrupt_state(struct radeon_device *rdev)
6907 tmp = RREG32(CP_INT_CNTL_RING0) &
6908 (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
6909 WREG32(CP_INT_CNTL_RING0, tmp);
6911 tmp = RREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
6912 WREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET, tmp);
6913 tmp = RREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
6914 WREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET, tmp);
6915 /* compute queues */
6916 WREG32(CP_ME1_PIPE0_INT_CNTL, 0);
6917 WREG32(CP_ME1_PIPE1_INT_CNTL, 0);
6918 WREG32(CP_ME1_PIPE2_INT_CNTL, 0);
6919 WREG32(CP_ME1_PIPE3_INT_CNTL, 0);
6920 WREG32(CP_ME2_PIPE0_INT_CNTL, 0);
6921 WREG32(CP_ME2_PIPE1_INT_CNTL, 0);
6922 WREG32(CP_ME2_PIPE2_INT_CNTL, 0);
6923 WREG32(CP_ME2_PIPE3_INT_CNTL, 0);
6925 WREG32(GRBM_INT_CNTL, 0);
6927 WREG32(SRBM_INT_CNTL, 0);
6928 /* vline/vblank, etc. */
6929 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
6930 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
6931 if (rdev->num_crtc >= 4) {
6932 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
6933 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
6935 if (rdev->num_crtc >= 6) {
6936 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
6937 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
6940 if (rdev->num_crtc >= 2) {
6941 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
6942 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
6944 if (rdev->num_crtc >= 4) {
6945 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
6946 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
6948 if (rdev->num_crtc >= 6) {
6949 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
6950 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
6954 WREG32(DAC_AUTODETECT_INT_CONTROL, 0);
6956 /* digital hotplug */
6957 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
6958 WREG32(DC_HPD1_INT_CONTROL, tmp);
6959 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
6960 WREG32(DC_HPD2_INT_CONTROL, tmp);
6961 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
6962 WREG32(DC_HPD3_INT_CONTROL, tmp);
6963 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
6964 WREG32(DC_HPD4_INT_CONTROL, tmp);
6965 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
6966 WREG32(DC_HPD5_INT_CONTROL, tmp);
6967 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
6968 WREG32(DC_HPD6_INT_CONTROL, tmp);
6973 * cik_irq_init - init and enable the interrupt ring
6975 * @rdev: radeon_device pointer
6977 * Allocate a ring buffer for the interrupt controller,
6978 * enable the RLC, disable interrupts, enable the IH
6979 * ring buffer and enable it (CIK).
6980 * Called at device load and reume.
6981 * Returns 0 for success, errors for failure.
6983 static int cik_irq_init(struct radeon_device *rdev)
6987 u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
6990 ret = r600_ih_ring_alloc(rdev);
6995 cik_disable_interrupts(rdev);
6998 ret = cik_rlc_resume(rdev);
7000 r600_ih_ring_fini(rdev);
7004 /* setup interrupt control */
7005 /* XXX this should actually be a bus address, not an MC address. same on older asics */
7006 WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
7007 interrupt_cntl = RREG32(INTERRUPT_CNTL);
7008 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
7009 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
7011 interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
7012 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
7013 interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
7014 WREG32(INTERRUPT_CNTL, interrupt_cntl);
7016 WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
7017 rb_bufsz = order_base_2(rdev->ih.ring_size / 4);
7019 ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
7020 IH_WPTR_OVERFLOW_CLEAR |
7023 if (rdev->wb.enabled)
7024 ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
7026 /* set the writeback address whether it's enabled or not */
7027 WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
7028 WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
7030 WREG32(IH_RB_CNTL, ih_rb_cntl);
7032 /* set rptr, wptr to 0 */
7033 WREG32(IH_RB_RPTR, 0);
7034 WREG32(IH_RB_WPTR, 0);
7036 /* Default settings for IH_CNTL (disabled at first) */
7037 ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10) | MC_VMID(0);
7038 /* RPTR_REARM only works if msi's are enabled */
7039 if (rdev->msi_enabled)
7040 ih_cntl |= RPTR_REARM;
7041 WREG32(IH_CNTL, ih_cntl);
7043 /* force the active interrupt state to all disabled */
7044 cik_disable_interrupt_state(rdev);
7046 pci_set_master(rdev->pdev);
7049 cik_enable_interrupts(rdev);
7055 * cik_irq_set - enable/disable interrupt sources
7057 * @rdev: radeon_device pointer
7059 * Enable interrupt sources on the GPU (vblanks, hpd,
7061 * Returns 0 for success, errors for failure.
7063 int cik_irq_set(struct radeon_device *rdev)
7067 u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
7068 u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;
7069 u32 grbm_int_cntl = 0;
7070 u32 dma_cntl, dma_cntl1;
7072 if (!rdev->irq.installed) {
7073 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
7076 /* don't enable anything if the ih is disabled */
7077 if (!rdev->ih.enabled) {
7078 cik_disable_interrupts(rdev);
7079 /* force the active interrupt state to all disabled */
7080 cik_disable_interrupt_state(rdev);
7084 cp_int_cntl = RREG32(CP_INT_CNTL_RING0) &
7085 (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
7086 cp_int_cntl |= PRIV_INSTR_INT_ENABLE | PRIV_REG_INT_ENABLE;
7088 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
7089 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
7090 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
7091 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
7092 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
7093 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
7095 dma_cntl = RREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
7096 dma_cntl1 = RREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
7098 cp_m1p0 = RREG32(CP_ME1_PIPE0_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
7100 /* enable CP interrupts on all rings */
7101 if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
7102 DRM_DEBUG("cik_irq_set: sw int gfx\n");
7103 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
7105 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
7106 struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
7107 DRM_DEBUG("si_irq_set: sw int cp1\n");
7108 if (ring->me == 1) {
7109 switch (ring->pipe) {
7111 cp_m1p0 |= TIME_STAMP_INT_ENABLE;
7114 DRM_DEBUG("si_irq_set: sw int cp1 invalid pipe %d\n", ring->pipe);
7118 DRM_DEBUG("si_irq_set: sw int cp1 invalid me %d\n", ring->me);
7121 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
7122 struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
7123 DRM_DEBUG("si_irq_set: sw int cp2\n");
7124 if (ring->me == 1) {
7125 switch (ring->pipe) {
7127 cp_m1p0 |= TIME_STAMP_INT_ENABLE;
7130 DRM_DEBUG("si_irq_set: sw int cp2 invalid pipe %d\n", ring->pipe);
7134 DRM_DEBUG("si_irq_set: sw int cp2 invalid me %d\n", ring->me);
7138 if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
7139 DRM_DEBUG("cik_irq_set: sw int dma\n");
7140 dma_cntl |= TRAP_ENABLE;
7143 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
7144 DRM_DEBUG("cik_irq_set: sw int dma1\n");
7145 dma_cntl1 |= TRAP_ENABLE;
7148 if (rdev->irq.crtc_vblank_int[0] ||
7149 atomic_read(&rdev->irq.pflip[0])) {
7150 DRM_DEBUG("cik_irq_set: vblank 0\n");
7151 crtc1 |= VBLANK_INTERRUPT_MASK;
7153 if (rdev->irq.crtc_vblank_int[1] ||
7154 atomic_read(&rdev->irq.pflip[1])) {
7155 DRM_DEBUG("cik_irq_set: vblank 1\n");
7156 crtc2 |= VBLANK_INTERRUPT_MASK;
7158 if (rdev->irq.crtc_vblank_int[2] ||
7159 atomic_read(&rdev->irq.pflip[2])) {
7160 DRM_DEBUG("cik_irq_set: vblank 2\n");
7161 crtc3 |= VBLANK_INTERRUPT_MASK;
7163 if (rdev->irq.crtc_vblank_int[3] ||
7164 atomic_read(&rdev->irq.pflip[3])) {
7165 DRM_DEBUG("cik_irq_set: vblank 3\n");
7166 crtc4 |= VBLANK_INTERRUPT_MASK;
7168 if (rdev->irq.crtc_vblank_int[4] ||
7169 atomic_read(&rdev->irq.pflip[4])) {
7170 DRM_DEBUG("cik_irq_set: vblank 4\n");
7171 crtc5 |= VBLANK_INTERRUPT_MASK;
7173 if (rdev->irq.crtc_vblank_int[5] ||
7174 atomic_read(&rdev->irq.pflip[5])) {
7175 DRM_DEBUG("cik_irq_set: vblank 5\n");
7176 crtc6 |= VBLANK_INTERRUPT_MASK;
7178 if (rdev->irq.hpd[0]) {
7179 DRM_DEBUG("cik_irq_set: hpd 1\n");
7180 hpd1 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
7182 if (rdev->irq.hpd[1]) {
7183 DRM_DEBUG("cik_irq_set: hpd 2\n");
7184 hpd2 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
7186 if (rdev->irq.hpd[2]) {
7187 DRM_DEBUG("cik_irq_set: hpd 3\n");
7188 hpd3 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
7190 if (rdev->irq.hpd[3]) {
7191 DRM_DEBUG("cik_irq_set: hpd 4\n");
7192 hpd4 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
7194 if (rdev->irq.hpd[4]) {
7195 DRM_DEBUG("cik_irq_set: hpd 5\n");
7196 hpd5 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
7198 if (rdev->irq.hpd[5]) {
7199 DRM_DEBUG("cik_irq_set: hpd 6\n");
7200 hpd6 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
7203 WREG32(CP_INT_CNTL_RING0, cp_int_cntl);
7205 WREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET, dma_cntl);
7206 WREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET, dma_cntl1);
7208 WREG32(CP_ME1_PIPE0_INT_CNTL, cp_m1p0);
7210 WREG32(GRBM_INT_CNTL, grbm_int_cntl);
7212 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
7213 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
7214 if (rdev->num_crtc >= 4) {
7215 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
7216 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
7218 if (rdev->num_crtc >= 6) {
7219 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
7220 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
7223 if (rdev->num_crtc >= 2) {
7224 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET,
7225 GRPH_PFLIP_INT_MASK);
7226 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET,
7227 GRPH_PFLIP_INT_MASK);
7229 if (rdev->num_crtc >= 4) {
7230 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET,
7231 GRPH_PFLIP_INT_MASK);
7232 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET,
7233 GRPH_PFLIP_INT_MASK);
7235 if (rdev->num_crtc >= 6) {
7236 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET,
7237 GRPH_PFLIP_INT_MASK);
7238 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET,
7239 GRPH_PFLIP_INT_MASK);
7242 WREG32(DC_HPD1_INT_CONTROL, hpd1);
7243 WREG32(DC_HPD2_INT_CONTROL, hpd2);
7244 WREG32(DC_HPD3_INT_CONTROL, hpd3);
7245 WREG32(DC_HPD4_INT_CONTROL, hpd4);
7246 WREG32(DC_HPD5_INT_CONTROL, hpd5);
7247 WREG32(DC_HPD6_INT_CONTROL, hpd6);
7250 RREG32(SRBM_STATUS);
7256 * cik_irq_ack - ack interrupt sources
7258 * @rdev: radeon_device pointer
7260 * Ack interrupt sources on the GPU (vblanks, hpd,
7261 * etc.) (CIK). Certain interrupts sources are sw
7262 * generated and do not require an explicit ack.
7264 static inline void cik_irq_ack(struct radeon_device *rdev)
7268 rdev->irq.stat_regs.cik.disp_int = RREG32(DISP_INTERRUPT_STATUS);
7269 rdev->irq.stat_regs.cik.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
7270 rdev->irq.stat_regs.cik.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
7271 rdev->irq.stat_regs.cik.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
7272 rdev->irq.stat_regs.cik.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
7273 rdev->irq.stat_regs.cik.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
7274 rdev->irq.stat_regs.cik.disp_int_cont6 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE6);
7276 rdev->irq.stat_regs.cik.d1grph_int = RREG32(GRPH_INT_STATUS +
7277 EVERGREEN_CRTC0_REGISTER_OFFSET);
7278 rdev->irq.stat_regs.cik.d2grph_int = RREG32(GRPH_INT_STATUS +
7279 EVERGREEN_CRTC1_REGISTER_OFFSET);
7280 if (rdev->num_crtc >= 4) {
7281 rdev->irq.stat_regs.cik.d3grph_int = RREG32(GRPH_INT_STATUS +
7282 EVERGREEN_CRTC2_REGISTER_OFFSET);
7283 rdev->irq.stat_regs.cik.d4grph_int = RREG32(GRPH_INT_STATUS +
7284 EVERGREEN_CRTC3_REGISTER_OFFSET);
7286 if (rdev->num_crtc >= 6) {
7287 rdev->irq.stat_regs.cik.d5grph_int = RREG32(GRPH_INT_STATUS +
7288 EVERGREEN_CRTC4_REGISTER_OFFSET);
7289 rdev->irq.stat_regs.cik.d6grph_int = RREG32(GRPH_INT_STATUS +
7290 EVERGREEN_CRTC5_REGISTER_OFFSET);
7293 if (rdev->irq.stat_regs.cik.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
7294 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET,
7295 GRPH_PFLIP_INT_CLEAR);
7296 if (rdev->irq.stat_regs.cik.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
7297 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET,
7298 GRPH_PFLIP_INT_CLEAR);
7299 if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VBLANK_INTERRUPT)
7300 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
7301 if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VLINE_INTERRUPT)
7302 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
7303 if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
7304 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
7305 if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VLINE_INTERRUPT)
7306 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
7308 if (rdev->num_crtc >= 4) {
7309 if (rdev->irq.stat_regs.cik.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
7310 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET,
7311 GRPH_PFLIP_INT_CLEAR);
7312 if (rdev->irq.stat_regs.cik.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
7313 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET,
7314 GRPH_PFLIP_INT_CLEAR);
7315 if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
7316 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
7317 if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
7318 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
7319 if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
7320 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
7321 if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
7322 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
7325 if (rdev->num_crtc >= 6) {
7326 if (rdev->irq.stat_regs.cik.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
7327 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET,
7328 GRPH_PFLIP_INT_CLEAR);
7329 if (rdev->irq.stat_regs.cik.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
7330 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET,
7331 GRPH_PFLIP_INT_CLEAR);
7332 if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
7333 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
7334 if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
7335 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
7336 if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
7337 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
7338 if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
7339 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
7342 if (rdev->irq.stat_regs.cik.disp_int & DC_HPD1_INTERRUPT) {
7343 tmp = RREG32(DC_HPD1_INT_CONTROL);
7344 tmp |= DC_HPDx_INT_ACK;
7345 WREG32(DC_HPD1_INT_CONTROL, tmp);
7347 if (rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_INTERRUPT) {
7348 tmp = RREG32(DC_HPD2_INT_CONTROL);
7349 tmp |= DC_HPDx_INT_ACK;
7350 WREG32(DC_HPD2_INT_CONTROL, tmp);
7352 if (rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_INTERRUPT) {
7353 tmp = RREG32(DC_HPD3_INT_CONTROL);
7354 tmp |= DC_HPDx_INT_ACK;
7355 WREG32(DC_HPD3_INT_CONTROL, tmp);
7357 if (rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_INTERRUPT) {
7358 tmp = RREG32(DC_HPD4_INT_CONTROL);
7359 tmp |= DC_HPDx_INT_ACK;
7360 WREG32(DC_HPD4_INT_CONTROL, tmp);
7362 if (rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_INTERRUPT) {
7363 tmp = RREG32(DC_HPD5_INT_CONTROL);
7364 tmp |= DC_HPDx_INT_ACK;
7365 WREG32(DC_HPD5_INT_CONTROL, tmp);
7367 if (rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_INTERRUPT) {
7368 tmp = RREG32(DC_HPD6_INT_CONTROL);
7369 tmp |= DC_HPDx_INT_ACK;
7370 WREG32(DC_HPD6_INT_CONTROL, tmp);
7372 if (rdev->irq.stat_regs.cik.disp_int & DC_HPD1_RX_INTERRUPT) {
7373 tmp = RREG32(DC_HPD1_INT_CONTROL);
7374 tmp |= DC_HPDx_RX_INT_ACK;
7375 WREG32(DC_HPD1_INT_CONTROL, tmp);
7377 if (rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_RX_INTERRUPT) {
7378 tmp = RREG32(DC_HPD2_INT_CONTROL);
7379 tmp |= DC_HPDx_RX_INT_ACK;
7380 WREG32(DC_HPD2_INT_CONTROL, tmp);
7382 if (rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_RX_INTERRUPT) {
7383 tmp = RREG32(DC_HPD3_INT_CONTROL);
7384 tmp |= DC_HPDx_RX_INT_ACK;
7385 WREG32(DC_HPD3_INT_CONTROL, tmp);
7387 if (rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_RX_INTERRUPT) {
7388 tmp = RREG32(DC_HPD4_INT_CONTROL);
7389 tmp |= DC_HPDx_RX_INT_ACK;
7390 WREG32(DC_HPD4_INT_CONTROL, tmp);
7392 if (rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_RX_INTERRUPT) {
7393 tmp = RREG32(DC_HPD5_INT_CONTROL);
7394 tmp |= DC_HPDx_RX_INT_ACK;
7395 WREG32(DC_HPD5_INT_CONTROL, tmp);
7397 if (rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_RX_INTERRUPT) {
7398 tmp = RREG32(DC_HPD6_INT_CONTROL);
7399 tmp |= DC_HPDx_RX_INT_ACK;
7400 WREG32(DC_HPD6_INT_CONTROL, tmp);
7405 * cik_irq_disable - disable interrupts
7407 * @rdev: radeon_device pointer
7409 * Disable interrupts on the hw (CIK).
7411 static void cik_irq_disable(struct radeon_device *rdev)
7413 cik_disable_interrupts(rdev);
7414 /* Wait and acknowledge irq */
7417 cik_disable_interrupt_state(rdev);
7421 * cik_irq_disable - disable interrupts for suspend
7423 * @rdev: radeon_device pointer
7425 * Disable interrupts and stop the RLC (CIK).
7428 static void cik_irq_suspend(struct radeon_device *rdev)
7430 cik_irq_disable(rdev);
7435 * cik_irq_fini - tear down interrupt support
7437 * @rdev: radeon_device pointer
7439 * Disable interrupts on the hw and free the IH ring
7441 * Used for driver unload.
7443 static void cik_irq_fini(struct radeon_device *rdev)
7445 cik_irq_suspend(rdev);
7446 r600_ih_ring_fini(rdev);
7450 * cik_get_ih_wptr - get the IH ring buffer wptr
7452 * @rdev: radeon_device pointer
7454 * Get the IH ring buffer wptr from either the register
7455 * or the writeback memory buffer (CIK). Also check for
7456 * ring buffer overflow and deal with it.
7457 * Used by cik_irq_process().
7458 * Returns the value of the wptr.
7460 static inline u32 cik_get_ih_wptr(struct radeon_device *rdev)
7464 if (rdev->wb.enabled)
7465 wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
7467 wptr = RREG32(IH_RB_WPTR);
7469 if (wptr & RB_OVERFLOW) {
7470 wptr &= ~RB_OVERFLOW;
7471 /* When a ring buffer overflow happen start parsing interrupt
7472 * from the last not overwritten vector (wptr + 16). Hopefully
7473 * this should allow us to catchup.
7475 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n",
7476 wptr, rdev->ih.rptr, (wptr + 16) & rdev->ih.ptr_mask);
7477 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
7478 tmp = RREG32(IH_RB_CNTL);
7479 tmp |= IH_WPTR_OVERFLOW_CLEAR;
7480 WREG32(IH_RB_CNTL, tmp);
7482 return (wptr & rdev->ih.ptr_mask);
7486 * Each IV ring entry is 128 bits:
7487 * [7:0] - interrupt source id
7489 * [59:32] - interrupt source data
7490 * [63:60] - reserved
7493 * ME_ID [1:0], PIPE_ID[1:0], QUEUE_ID[2:0]
7494 * QUEUE_ID - for compute, which of the 8 queues owned by the dispatcher
7495 * - for gfx, hw shader state (0=PS...5=LS, 6=CS)
7496 * ME_ID - 0 = gfx, 1 = first 4 CS pipes, 2 = second 4 CS pipes
7497 * PIPE_ID - ME0 0=3D
7498 * - ME1&2 compute dispatcher (4 pipes each)
7500 * INSTANCE_ID [1:0], QUEUE_ID[1:0]
7501 * INSTANCE_ID - 0 = sdma0, 1 = sdma1
7502 * QUEUE_ID - 0 = gfx, 1 = rlc0, 2 = rlc1
7505 * [127:96] - reserved
7508 * cik_irq_process - interrupt handler
7510 * @rdev: radeon_device pointer
7512 * Interrupt hander (CIK). Walk the IH ring,
7513 * ack interrupts and schedule work to handle
7515 * Returns irq process return code.
7517 irqreturn_t cik_irq_process(struct radeon_device *rdev)
7519 struct radeon_ring *cp1_ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
7520 struct radeon_ring *cp2_ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
7523 u32 src_id, src_data, ring_id;
7524 u8 me_id, pipe_id, queue_id;
7526 bool queue_hotplug = false;
7527 bool queue_dp = false;
7528 bool queue_reset = false;
7529 u32 addr, status, mc_client;
7530 bool queue_thermal = false;
7532 if (!rdev->ih.enabled || rdev->shutdown)
7535 wptr = cik_get_ih_wptr(rdev);
7538 /* is somebody else already processing irqs? */
7539 if (atomic_xchg(&rdev->ih.lock, 1))
7542 rptr = rdev->ih.rptr;
7543 DRM_DEBUG_VBLANK("cik_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
7545 /* Order reading of wptr vs. reading of IH ring data */
7548 /* display interrupts */
7551 while (rptr != wptr) {
7552 /* wptr/rptr are in bytes! */
7553 ring_index = rptr / 4;
7555 src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
7556 src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
7557 ring_id = le32_to_cpu(rdev->ih.ring[ring_index + 2]) & 0xff;
7560 case 1: /* D1 vblank/vline */
7562 case 0: /* D1 vblank */
7563 if (!(rdev->irq.stat_regs.cik.disp_int & LB_D1_VBLANK_INTERRUPT))
7564 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7566 if (rdev->irq.crtc_vblank_int[0]) {
7567 drm_handle_vblank(rdev->ddev, 0);
7568 rdev->pm.vblank_sync = true;
7569 wake_up(&rdev->irq.vblank_queue);
7571 if (atomic_read(&rdev->irq.pflip[0]))
7572 radeon_crtc_handle_vblank(rdev, 0);
7573 rdev->irq.stat_regs.cik.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
7574 DRM_DEBUG_VBLANK("IH: D1 vblank\n");
7577 case 1: /* D1 vline */
7578 if (!(rdev->irq.stat_regs.cik.disp_int & LB_D1_VLINE_INTERRUPT))
7579 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7581 rdev->irq.stat_regs.cik.disp_int &= ~LB_D1_VLINE_INTERRUPT;
7582 DRM_DEBUG_VBLANK("IH: D1 vline\n");
7586 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
7590 case 2: /* D2 vblank/vline */
7592 case 0: /* D2 vblank */
7593 if (!(rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VBLANK_INTERRUPT))
7594 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7596 if (rdev->irq.crtc_vblank_int[1]) {
7597 drm_handle_vblank(rdev->ddev, 1);
7598 rdev->pm.vblank_sync = true;
7599 wake_up(&rdev->irq.vblank_queue);
7601 if (atomic_read(&rdev->irq.pflip[1]))
7602 radeon_crtc_handle_vblank(rdev, 1);
7603 rdev->irq.stat_regs.cik.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
7604 DRM_DEBUG_VBLANK("IH: D2 vblank\n");
7607 case 1: /* D2 vline */
7608 if (!(rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VLINE_INTERRUPT))
7609 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7611 rdev->irq.stat_regs.cik.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
7612 DRM_DEBUG_VBLANK("IH: D2 vline\n");
7616 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
7620 case 3: /* D3 vblank/vline */
7622 case 0: /* D3 vblank */
7623 if (!(rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT))
7624 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7626 if (rdev->irq.crtc_vblank_int[2]) {
7627 drm_handle_vblank(rdev->ddev, 2);
7628 rdev->pm.vblank_sync = true;
7629 wake_up(&rdev->irq.vblank_queue);
7631 if (atomic_read(&rdev->irq.pflip[2]))
7632 radeon_crtc_handle_vblank(rdev, 2);
7633 rdev->irq.stat_regs.cik.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
7634 DRM_DEBUG_VBLANK("IH: D3 vblank\n");
7637 case 1: /* D3 vline */
7638 if (!(rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VLINE_INTERRUPT))
7639 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7641 rdev->irq.stat_regs.cik.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
7642 DRM_DEBUG_VBLANK("IH: D3 vline\n");
7646 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
7650 case 4: /* D4 vblank/vline */
7652 case 0: /* D4 vblank */
7653 if (!(rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT))
7654 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7656 if (rdev->irq.crtc_vblank_int[3]) {
7657 drm_handle_vblank(rdev->ddev, 3);
7658 rdev->pm.vblank_sync = true;
7659 wake_up(&rdev->irq.vblank_queue);
7661 if (atomic_read(&rdev->irq.pflip[3]))
7662 radeon_crtc_handle_vblank(rdev, 3);
7663 rdev->irq.stat_regs.cik.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
7664 DRM_DEBUG_VBLANK("IH: D4 vblank\n");
7667 case 1: /* D4 vline */
7668 if (!(rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VLINE_INTERRUPT))
7669 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7671 rdev->irq.stat_regs.cik.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
7672 DRM_DEBUG_VBLANK("IH: D4 vline\n");
7676 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
7680 case 5: /* D5 vblank/vline */
7682 case 0: /* D5 vblank */
7683 if (!(rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT))
7684 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7686 if (rdev->irq.crtc_vblank_int[4]) {
7687 drm_handle_vblank(rdev->ddev, 4);
7688 rdev->pm.vblank_sync = true;
7689 wake_up(&rdev->irq.vblank_queue);
7691 if (atomic_read(&rdev->irq.pflip[4]))
7692 radeon_crtc_handle_vblank(rdev, 4);
7693 rdev->irq.stat_regs.cik.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
7694 DRM_DEBUG_VBLANK("IH: D5 vblank\n");
7697 case 1: /* D5 vline */
7698 if (!(rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VLINE_INTERRUPT))
7699 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7701 rdev->irq.stat_regs.cik.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
7702 DRM_DEBUG("IH: D5 vline\n");
7706 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
7710 case 6: /* D6 vblank/vline */
7712 case 0: /* D6 vblank */
7713 if (!(rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT))
7714 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7716 if (rdev->irq.crtc_vblank_int[5]) {
7717 drm_handle_vblank(rdev->ddev, 5);
7718 rdev->pm.vblank_sync = true;
7719 wake_up(&rdev->irq.vblank_queue);
7721 if (atomic_read(&rdev->irq.pflip[5]))
7722 radeon_crtc_handle_vblank(rdev, 5);
7723 rdev->irq.stat_regs.cik.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
7724 DRM_DEBUG_VBLANK("IH: D6 vblank\n");
7727 case 1: /* D6 vline */
7728 if (!(rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VLINE_INTERRUPT))
7729 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7731 rdev->irq.stat_regs.cik.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
7732 DRM_DEBUG_VBLANK("IH: D6 vline\n");
7736 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
7740 case 8: /* D1 page flip */
7741 case 10: /* D2 page flip */
7742 case 12: /* D3 page flip */
7743 case 14: /* D4 page flip */
7744 case 16: /* D5 page flip */
7745 case 18: /* D6 page flip */
7746 DRM_DEBUG("IH: D%d flip\n", ((src_id - 8) >> 1) + 1);
7747 if (radeon_use_pflipirq > 0)
7748 radeon_crtc_handle_flip(rdev, (src_id - 8) >> 1);
7750 case 42: /* HPD hotplug */
7753 if (!(rdev->irq.stat_regs.cik.disp_int & DC_HPD1_INTERRUPT))
7754 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7756 rdev->irq.stat_regs.cik.disp_int &= ~DC_HPD1_INTERRUPT;
7757 queue_hotplug = true;
7758 DRM_DEBUG("IH: HPD1\n");
7762 if (!(rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_INTERRUPT))
7763 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7765 rdev->irq.stat_regs.cik.disp_int_cont &= ~DC_HPD2_INTERRUPT;
7766 queue_hotplug = true;
7767 DRM_DEBUG("IH: HPD2\n");
7771 if (!(rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_INTERRUPT))
7772 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7774 rdev->irq.stat_regs.cik.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
7775 queue_hotplug = true;
7776 DRM_DEBUG("IH: HPD3\n");
7780 if (!(rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_INTERRUPT))
7781 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7783 rdev->irq.stat_regs.cik.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
7784 queue_hotplug = true;
7785 DRM_DEBUG("IH: HPD4\n");
7789 if (!(rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_INTERRUPT))
7790 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7792 rdev->irq.stat_regs.cik.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
7793 queue_hotplug = true;
7794 DRM_DEBUG("IH: HPD5\n");
7798 if (!(rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_INTERRUPT))
7799 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7801 rdev->irq.stat_regs.cik.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
7802 queue_hotplug = true;
7803 DRM_DEBUG("IH: HPD6\n");
7807 if (!(rdev->irq.stat_regs.cik.disp_int & DC_HPD1_RX_INTERRUPT))
7808 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7810 rdev->irq.stat_regs.cik.disp_int &= ~DC_HPD1_RX_INTERRUPT;
7812 DRM_DEBUG("IH: HPD_RX 1\n");
7816 if (!(rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_RX_INTERRUPT))
7817 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7819 rdev->irq.stat_regs.cik.disp_int_cont &= ~DC_HPD2_RX_INTERRUPT;
7821 DRM_DEBUG("IH: HPD_RX 2\n");
7825 if (!(rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_RX_INTERRUPT))
7826 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7828 rdev->irq.stat_regs.cik.disp_int_cont2 &= ~DC_HPD3_RX_INTERRUPT;
7830 DRM_DEBUG("IH: HPD_RX 3\n");
7834 if (!(rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_RX_INTERRUPT))
7835 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7837 rdev->irq.stat_regs.cik.disp_int_cont3 &= ~DC_HPD4_RX_INTERRUPT;
7839 DRM_DEBUG("IH: HPD_RX 4\n");
7843 if (!(rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_RX_INTERRUPT))
7844 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7846 rdev->irq.stat_regs.cik.disp_int_cont4 &= ~DC_HPD5_RX_INTERRUPT;
7848 DRM_DEBUG("IH: HPD_RX 5\n");
7852 if (!(rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_RX_INTERRUPT))
7853 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7855 rdev->irq.stat_regs.cik.disp_int_cont5 &= ~DC_HPD6_RX_INTERRUPT;
7857 DRM_DEBUG("IH: HPD_RX 6\n");
7861 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
7866 DRM_ERROR("SRBM_READ_ERROR: 0x%x\n", RREG32(SRBM_READ_ERROR));
7867 WREG32(SRBM_INT_ACK, 0x1);
7870 DRM_DEBUG("IH: UVD int: 0x%08x\n", src_data);
7871 radeon_fence_process(rdev, R600_RING_TYPE_UVD_INDEX);
7875 addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
7876 status = RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS);
7877 mc_client = RREG32(VM_CONTEXT1_PROTECTION_FAULT_MCCLIENT);
7878 /* reset addr and status */
7879 WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
7880 if (addr == 0x0 && status == 0x0)
7882 dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
7883 dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
7885 dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
7887 cik_vm_decode_fault(rdev, status, addr, mc_client);
7890 DRM_DEBUG("IH: VCE int: 0x%08x\n", src_data);
7893 radeon_fence_process(rdev, TN_RING_TYPE_VCE1_INDEX);
7896 radeon_fence_process(rdev, TN_RING_TYPE_VCE2_INDEX);
7899 DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
7903 case 176: /* GFX RB CP_INT */
7904 case 177: /* GFX IB CP_INT */
7905 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
7907 case 181: /* CP EOP event */
7908 DRM_DEBUG("IH: CP EOP\n");
7909 /* XXX check the bitfield order! */
7910 me_id = (ring_id & 0x60) >> 5;
7911 pipe_id = (ring_id & 0x18) >> 3;
7912 queue_id = (ring_id & 0x7) >> 0;
7915 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
7919 if ((cp1_ring->me == me_id) & (cp1_ring->pipe == pipe_id))
7920 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
7921 if ((cp2_ring->me == me_id) & (cp2_ring->pipe == pipe_id))
7922 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
7926 case 184: /* CP Privileged reg access */
7927 DRM_ERROR("Illegal register access in command stream\n");
7928 /* XXX check the bitfield order! */
7929 me_id = (ring_id & 0x60) >> 5;
7930 pipe_id = (ring_id & 0x18) >> 3;
7931 queue_id = (ring_id & 0x7) >> 0;
7934 /* This results in a full GPU reset, but all we need to do is soft
7935 * reset the CP for gfx
7949 case 185: /* CP Privileged inst */
7950 DRM_ERROR("Illegal instruction in command stream\n");
7951 /* XXX check the bitfield order! */
7952 me_id = (ring_id & 0x60) >> 5;
7953 pipe_id = (ring_id & 0x18) >> 3;
7954 queue_id = (ring_id & 0x7) >> 0;
7957 /* This results in a full GPU reset, but all we need to do is soft
7958 * reset the CP for gfx
7972 case 224: /* SDMA trap event */
7973 /* XXX check the bitfield order! */
7974 me_id = (ring_id & 0x3) >> 0;
7975 queue_id = (ring_id & 0xc) >> 2;
7976 DRM_DEBUG("IH: SDMA trap\n");
7981 radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
7994 radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
8006 case 230: /* thermal low to high */
8007 DRM_DEBUG("IH: thermal low to high\n");
8008 rdev->pm.dpm.thermal.high_to_low = false;
8009 queue_thermal = true;
8011 case 231: /* thermal high to low */
8012 DRM_DEBUG("IH: thermal high to low\n");
8013 rdev->pm.dpm.thermal.high_to_low = true;
8014 queue_thermal = true;
8016 case 233: /* GUI IDLE */
8017 DRM_DEBUG("IH: GUI idle\n");
8019 case 241: /* SDMA Privileged inst */
8020 case 247: /* SDMA Privileged inst */
8021 DRM_ERROR("Illegal instruction in SDMA command stream\n");
8022 /* XXX check the bitfield order! */
8023 me_id = (ring_id & 0x3) >> 0;
8024 queue_id = (ring_id & 0xc) >> 2;
8059 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
8063 /* wptr/rptr are in bytes! */
8065 rptr &= rdev->ih.ptr_mask;
8066 WREG32(IH_RB_RPTR, rptr);
8069 schedule_work(&rdev->dp_work);
8071 schedule_delayed_work(&rdev->hotplug_work, 0);
8073 rdev->needs_reset = true;
8074 wake_up_all(&rdev->fence_queue);
8077 schedule_work(&rdev->pm.dpm.thermal.work);
8078 rdev->ih.rptr = rptr;
8079 atomic_set(&rdev->ih.lock, 0);
8081 /* make sure wptr hasn't changed while processing */
8082 wptr = cik_get_ih_wptr(rdev);
8090 * startup/shutdown callbacks
8092 static void cik_uvd_init(struct radeon_device *rdev)
8099 r = radeon_uvd_init(rdev);
8101 dev_err(rdev->dev, "failed UVD (%d) init.\n", r);
8103 * At this point rdev->uvd.vcpu_bo is NULL which trickles down
8104 * to early fails cik_uvd_start() and thus nothing happens
8105 * there. So it is pointless to try to go through that code
8106 * hence why we disable uvd here.
8111 rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_obj = NULL;
8112 r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_UVD_INDEX], 4096);
8115 static void cik_uvd_start(struct radeon_device *rdev)
8122 r = radeon_uvd_resume(rdev);
8124 dev_err(rdev->dev, "failed UVD resume (%d).\n", r);
8127 r = uvd_v4_2_resume(rdev);
8129 dev_err(rdev->dev, "failed UVD 4.2 resume (%d).\n", r);
8132 r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_UVD_INDEX);
8134 dev_err(rdev->dev, "failed initializing UVD fences (%d).\n", r);
8140 rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
8143 static void cik_uvd_resume(struct radeon_device *rdev)
8145 struct radeon_ring *ring;
8148 if (!rdev->has_uvd || !rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size)
8151 ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
8152 r = radeon_ring_init(rdev, ring, ring->ring_size, 0, PACKET0(UVD_NO_OP, 0));
8154 dev_err(rdev->dev, "failed initializing UVD ring (%d).\n", r);
8157 r = uvd_v1_0_init(rdev);
8159 dev_err(rdev->dev, "failed initializing UVD (%d).\n", r);
8164 static void cik_vce_init(struct radeon_device *rdev)
8171 r = radeon_vce_init(rdev);
8173 dev_err(rdev->dev, "failed VCE (%d) init.\n", r);
8175 * At this point rdev->vce.vcpu_bo is NULL which trickles down
8176 * to early fails cik_vce_start() and thus nothing happens
8177 * there. So it is pointless to try to go through that code
8178 * hence why we disable vce here.
8183 rdev->ring[TN_RING_TYPE_VCE1_INDEX].ring_obj = NULL;
8184 r600_ring_init(rdev, &rdev->ring[TN_RING_TYPE_VCE1_INDEX], 4096);
8185 rdev->ring[TN_RING_TYPE_VCE2_INDEX].ring_obj = NULL;
8186 r600_ring_init(rdev, &rdev->ring[TN_RING_TYPE_VCE2_INDEX], 4096);
8189 static void cik_vce_start(struct radeon_device *rdev)
8196 r = radeon_vce_resume(rdev);
8198 dev_err(rdev->dev, "failed VCE resume (%d).\n", r);
8201 r = vce_v2_0_resume(rdev);
8203 dev_err(rdev->dev, "failed VCE resume (%d).\n", r);
8206 r = radeon_fence_driver_start_ring(rdev, TN_RING_TYPE_VCE1_INDEX);
8208 dev_err(rdev->dev, "failed initializing VCE1 fences (%d).\n", r);
8211 r = radeon_fence_driver_start_ring(rdev, TN_RING_TYPE_VCE2_INDEX);
8213 dev_err(rdev->dev, "failed initializing VCE2 fences (%d).\n", r);
8219 rdev->ring[TN_RING_TYPE_VCE1_INDEX].ring_size = 0;
8220 rdev->ring[TN_RING_TYPE_VCE2_INDEX].ring_size = 0;
8223 static void cik_vce_resume(struct radeon_device *rdev)
8225 struct radeon_ring *ring;
8228 if (!rdev->has_vce || !rdev->ring[TN_RING_TYPE_VCE1_INDEX].ring_size)
8231 ring = &rdev->ring[TN_RING_TYPE_VCE1_INDEX];
8232 r = radeon_ring_init(rdev, ring, ring->ring_size, 0, VCE_CMD_NO_OP);
8234 dev_err(rdev->dev, "failed initializing VCE1 ring (%d).\n", r);
8237 ring = &rdev->ring[TN_RING_TYPE_VCE2_INDEX];
8238 r = radeon_ring_init(rdev, ring, ring->ring_size, 0, VCE_CMD_NO_OP);
8240 dev_err(rdev->dev, "failed initializing VCE1 ring (%d).\n", r);
8243 r = vce_v1_0_init(rdev);
8245 dev_err(rdev->dev, "failed initializing VCE (%d).\n", r);
8251 * cik_startup - program the asic to a functional state
8253 * @rdev: radeon_device pointer
8255 * Programs the asic to a functional state (CIK).
8256 * Called by cik_init() and cik_resume().
8257 * Returns 0 for success, error for failure.
8259 static int cik_startup(struct radeon_device *rdev)
8261 struct radeon_ring *ring;
8265 /* enable pcie gen2/3 link */
8266 cik_pcie_gen3_enable(rdev);
8268 cik_program_aspm(rdev);
8270 /* scratch needs to be initialized before MC */
8271 r = r600_vram_scratch_init(rdev);
8275 cik_mc_program(rdev);
8277 if (!(rdev->flags & RADEON_IS_IGP) && !rdev->pm.dpm_enabled) {
8278 r = ci_mc_load_microcode(rdev);
8280 DRM_ERROR("Failed to load MC firmware!\n");
8285 r = cik_pcie_gart_enable(rdev);
8290 /* allocate rlc buffers */
8291 if (rdev->flags & RADEON_IS_IGP) {
8292 if (rdev->family == CHIP_KAVERI) {
8293 rdev->rlc.reg_list = spectre_rlc_save_restore_register_list;
8294 rdev->rlc.reg_list_size =
8295 (u32)ARRAY_SIZE(spectre_rlc_save_restore_register_list);
8297 rdev->rlc.reg_list = kalindi_rlc_save_restore_register_list;
8298 rdev->rlc.reg_list_size =
8299 (u32)ARRAY_SIZE(kalindi_rlc_save_restore_register_list);
8302 rdev->rlc.cs_data = ci_cs_data;
8303 rdev->rlc.cp_table_size = ALIGN(CP_ME_TABLE_SIZE * 5 * 4, 2048); /* CP JT */
8304 rdev->rlc.cp_table_size += 64 * 1024; /* GDS */
8305 r = sumo_rlc_init(rdev);
8307 DRM_ERROR("Failed to init rlc BOs!\n");
8311 /* allocate wb buffer */
8312 r = radeon_wb_init(rdev);
8316 /* allocate mec buffers */
8317 r = cik_mec_init(rdev);
8319 DRM_ERROR("Failed to init MEC BOs!\n");
8323 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
8325 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
8329 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
8331 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
8335 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
8337 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
8341 r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
8343 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
8347 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
8349 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
8353 cik_uvd_start(rdev);
8354 cik_vce_start(rdev);
8357 if (!rdev->irq.installed) {
8358 r = radeon_irq_kms_init(rdev);
8363 r = cik_irq_init(rdev);
8365 DRM_ERROR("radeon: IH init failed (%d).\n", r);
8366 radeon_irq_kms_fini(rdev);
8371 if (rdev->family == CHIP_HAWAII) {
8373 nop = PACKET3(PACKET3_NOP, 0x3FFF);
8375 nop = RADEON_CP_PACKET2;
8377 nop = PACKET3(PACKET3_NOP, 0x3FFF);
8380 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
8381 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
8386 /* set up the compute queues */
8387 /* type-2 packets are deprecated on MEC, use type-3 instead */
8388 ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
8389 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP1_RPTR_OFFSET,
8393 ring->me = 1; /* first MEC */
8394 ring->pipe = 0; /* first pipe */
8395 ring->queue = 0; /* first queue */
8396 ring->wptr_offs = CIK_WB_CP1_WPTR_OFFSET;
8398 /* type-2 packets are deprecated on MEC, use type-3 instead */
8399 ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
8400 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP2_RPTR_OFFSET,
8404 /* dGPU only have 1 MEC */
8405 ring->me = 1; /* first MEC */
8406 ring->pipe = 0; /* first pipe */
8407 ring->queue = 1; /* second queue */
8408 ring->wptr_offs = CIK_WB_CP2_WPTR_OFFSET;
8410 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
8411 r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
8412 SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0));
8416 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
8417 r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
8418 SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0));
8422 r = cik_cp_resume(rdev);
8426 r = cik_sdma_resume(rdev);
8430 cik_uvd_resume(rdev);
8431 cik_vce_resume(rdev);
8433 r = radeon_ib_pool_init(rdev);
8435 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
8439 r = radeon_vm_manager_init(rdev);
8441 dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
8445 r = radeon_audio_init(rdev);
8453 * cik_resume - resume the asic to a functional state
8455 * @rdev: radeon_device pointer
8457 * Programs the asic to a functional state (CIK).
8459 * Returns 0 for success, error for failure.
8461 int cik_resume(struct radeon_device *rdev)
8466 atom_asic_init(rdev->mode_info.atom_context);
8468 /* init golden registers */
8469 cik_init_golden_registers(rdev);
8471 if (rdev->pm.pm_method == PM_METHOD_DPM)
8472 radeon_pm_resume(rdev);
8474 rdev->accel_working = true;
8475 r = cik_startup(rdev);
8477 DRM_ERROR("cik startup failed on resume\n");
8478 rdev->accel_working = false;
8487 * cik_suspend - suspend the asic
8489 * @rdev: radeon_device pointer
8491 * Bring the chip into a state suitable for suspend (CIK).
8492 * Called at suspend.
8493 * Returns 0 for success.
8495 int cik_suspend(struct radeon_device *rdev)
8497 radeon_pm_suspend(rdev);
8498 radeon_audio_fini(rdev);
8499 radeon_vm_manager_fini(rdev);
8500 cik_cp_enable(rdev, false);
8501 cik_sdma_enable(rdev, false);
8502 if (rdev->has_uvd) {
8503 uvd_v1_0_fini(rdev);
8504 radeon_uvd_suspend(rdev);
8507 radeon_vce_suspend(rdev);
8510 cik_irq_suspend(rdev);
8511 radeon_wb_disable(rdev);
8512 cik_pcie_gart_disable(rdev);
8516 /* Plan is to move initialization in that function and use
8517 * helper function so that radeon_device_init pretty much
8518 * do nothing more than calling asic specific function. This
8519 * should also allow to remove a bunch of callback function
8523 * cik_init - asic specific driver and hw init
8525 * @rdev: radeon_device pointer
8527 * Setup asic specific driver variables and program the hw
8528 * to a functional state (CIK).
8529 * Called at driver startup.
8530 * Returns 0 for success, errors for failure.
8532 int cik_init(struct radeon_device *rdev)
8534 struct radeon_ring *ring;
8538 if (!radeon_get_bios(rdev)) {
8539 if (ASIC_IS_AVIVO(rdev))
8542 /* Must be an ATOMBIOS */
8543 if (!rdev->is_atom_bios) {
8544 dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
8547 r = radeon_atombios_init(rdev);
8551 /* Post card if necessary */
8552 if (!radeon_card_posted(rdev)) {
8554 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
8557 DRM_INFO("GPU not posted. posting now...\n");
8558 atom_asic_init(rdev->mode_info.atom_context);
8560 /* init golden registers */
8561 cik_init_golden_registers(rdev);
8562 /* Initialize scratch registers */
8563 cik_scratch_init(rdev);
8564 /* Initialize surface registers */
8565 radeon_surface_init(rdev);
8566 /* Initialize clocks */
8567 radeon_get_clock_info(rdev->ddev);
8570 r = radeon_fence_driver_init(rdev);
8574 /* initialize memory controller */
8575 r = cik_mc_init(rdev);
8578 /* Memory manager */
8579 r = radeon_bo_init(rdev);
8583 if (rdev->flags & RADEON_IS_IGP) {
8584 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
8585 !rdev->mec_fw || !rdev->sdma_fw || !rdev->rlc_fw) {
8586 r = cik_init_microcode(rdev);
8588 DRM_ERROR("Failed to load firmware!\n");
8593 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
8594 !rdev->mec_fw || !rdev->sdma_fw || !rdev->rlc_fw ||
8596 r = cik_init_microcode(rdev);
8598 DRM_ERROR("Failed to load firmware!\n");
8604 /* Initialize power management */
8605 radeon_pm_init(rdev);
8607 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
8608 ring->ring_obj = NULL;
8609 r600_ring_init(rdev, ring, 1024 * 1024);
8611 ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
8612 ring->ring_obj = NULL;
8613 r600_ring_init(rdev, ring, 1024 * 1024);
8614 r = radeon_doorbell_get(rdev, &ring->doorbell_index);
8618 ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
8619 ring->ring_obj = NULL;
8620 r600_ring_init(rdev, ring, 1024 * 1024);
8621 r = radeon_doorbell_get(rdev, &ring->doorbell_index);
8625 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
8626 ring->ring_obj = NULL;
8627 r600_ring_init(rdev, ring, 256 * 1024);
8629 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
8630 ring->ring_obj = NULL;
8631 r600_ring_init(rdev, ring, 256 * 1024);
8636 rdev->ih.ring_obj = NULL;
8637 r600_ih_ring_init(rdev, 64 * 1024);
8639 r = r600_pcie_gart_init(rdev);
8643 rdev->accel_working = true;
8644 r = cik_startup(rdev);
8646 dev_err(rdev->dev, "disabling GPU acceleration\n");
8648 cik_sdma_fini(rdev);
8650 sumo_rlc_fini(rdev);
8652 radeon_wb_fini(rdev);
8653 radeon_ib_pool_fini(rdev);
8654 radeon_vm_manager_fini(rdev);
8655 radeon_irq_kms_fini(rdev);
8656 cik_pcie_gart_fini(rdev);
8657 rdev->accel_working = false;
8660 /* Don't start up if the MC ucode is missing.
8661 * The default clocks and voltages before the MC ucode
8662 * is loaded are not suffient for advanced operations.
8664 if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
8665 DRM_ERROR("radeon: MC ucode required for NI+.\n");
8673 * cik_fini - asic specific driver and hw fini
8675 * @rdev: radeon_device pointer
8677 * Tear down the asic specific driver variables and program the hw
8678 * to an idle state (CIK).
8679 * Called at driver unload.
8681 void cik_fini(struct radeon_device *rdev)
8683 radeon_pm_fini(rdev);
8685 cik_sdma_fini(rdev);
8689 sumo_rlc_fini(rdev);
8691 radeon_wb_fini(rdev);
8692 radeon_vm_manager_fini(rdev);
8693 radeon_ib_pool_fini(rdev);
8694 radeon_irq_kms_fini(rdev);
8695 uvd_v1_0_fini(rdev);
8696 radeon_uvd_fini(rdev);
8697 radeon_vce_fini(rdev);
8698 cik_pcie_gart_fini(rdev);
8699 r600_vram_scratch_fini(rdev);
8700 radeon_gem_fini(rdev);
8701 radeon_fence_driver_fini(rdev);
8702 radeon_bo_fini(rdev);
8703 radeon_atombios_fini(rdev);
8704 cik_fini_microcode(rdev);
8709 void dce8_program_fmt(struct drm_encoder *encoder)
8711 struct drm_device *dev = encoder->dev;
8712 struct radeon_device *rdev = dev->dev_private;
8713 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
8714 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
8715 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
8718 enum radeon_connector_dither dither = RADEON_FMT_DITHER_DISABLE;
8721 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
8722 bpc = radeon_get_monitor_bpc(connector);
8723 dither = radeon_connector->dither;
8726 /* LVDS/eDP FMT is set up by atom */
8727 if (radeon_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
8730 /* not needed for analog */
8731 if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1) ||
8732 (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2))
8740 if (dither == RADEON_FMT_DITHER_ENABLE)
8741 /* XXX sort out optimal dither settings */
8742 tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
8743 FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH(0));
8745 tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH(0));
8748 if (dither == RADEON_FMT_DITHER_ENABLE)
8749 /* XXX sort out optimal dither settings */
8750 tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
8751 FMT_RGB_RANDOM_ENABLE |
8752 FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH(1));
8754 tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH(1));
8757 if (dither == RADEON_FMT_DITHER_ENABLE)
8758 /* XXX sort out optimal dither settings */
8759 tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
8760 FMT_RGB_RANDOM_ENABLE |
8761 FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH(2));
8763 tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH(2));
8770 WREG32(FMT_BIT_DEPTH_CONTROL + radeon_crtc->crtc_offset, tmp);
8773 /* display watermark setup */
8775 * dce8_line_buffer_adjust - Set up the line buffer
8777 * @rdev: radeon_device pointer
8778 * @radeon_crtc: the selected display controller
8779 * @mode: the current display mode on the selected display
8782 * Setup up the line buffer allocation for
8783 * the selected display controller (CIK).
8784 * Returns the line buffer size in pixels.
8786 static u32 dce8_line_buffer_adjust(struct radeon_device *rdev,
8787 struct radeon_crtc *radeon_crtc,
8788 struct drm_display_mode *mode)
8790 u32 tmp, buffer_alloc, i;
8791 u32 pipe_offset = radeon_crtc->crtc_id * 0x20;
8794 * There are 6 line buffers, one for each display controllers.
8795 * There are 3 partitions per LB. Select the number of partitions
8796 * to enable based on the display width. For display widths larger
8797 * than 4096, you need use to use 2 display controllers and combine
8798 * them using the stereo blender.
8800 if (radeon_crtc->base.enabled && mode) {
8801 if (mode->crtc_hdisplay < 1920) {
8804 } else if (mode->crtc_hdisplay < 2560) {
8807 } else if (mode->crtc_hdisplay < 4096) {
8809 buffer_alloc = (rdev->flags & RADEON_IS_IGP) ? 2 : 4;
8811 DRM_DEBUG_KMS("Mode too big for LB!\n");
8813 buffer_alloc = (rdev->flags & RADEON_IS_IGP) ? 2 : 4;
8820 WREG32(LB_MEMORY_CTRL + radeon_crtc->crtc_offset,
8821 LB_MEMORY_CONFIG(tmp) | LB_MEMORY_SIZE(0x6B0));
8823 WREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
8824 DMIF_BUFFERS_ALLOCATED(buffer_alloc));
8825 for (i = 0; i < rdev->usec_timeout; i++) {
8826 if (RREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
8827 DMIF_BUFFERS_ALLOCATED_COMPLETED)
8832 if (radeon_crtc->base.enabled && mode) {
8844 /* controller not enabled, so no lb used */
8849 * cik_get_number_of_dram_channels - get the number of dram channels
8851 * @rdev: radeon_device pointer
8853 * Look up the number of video ram channels (CIK).
8854 * Used for display watermark bandwidth calculations
8855 * Returns the number of dram channels
8857 static u32 cik_get_number_of_dram_channels(struct radeon_device *rdev)
8859 u32 tmp = RREG32(MC_SHARED_CHMAP);
8861 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
8884 struct dce8_wm_params {
8885 u32 dram_channels; /* number of dram channels */
8886 u32 yclk; /* bandwidth per dram data pin in kHz */
8887 u32 sclk; /* engine clock in kHz */
8888 u32 disp_clk; /* display clock in kHz */
8889 u32 src_width; /* viewport width */
8890 u32 active_time; /* active display time in ns */
8891 u32 blank_time; /* blank time in ns */
8892 bool interlaced; /* mode is interlaced */
8893 fixed20_12 vsc; /* vertical scale ratio */
8894 u32 num_heads; /* number of active crtcs */
8895 u32 bytes_per_pixel; /* bytes per pixel display + overlay */
8896 u32 lb_size; /* line buffer allocated to pipe */
8897 u32 vtaps; /* vertical scaler taps */
8901 * dce8_dram_bandwidth - get the dram bandwidth
8903 * @wm: watermark calculation data
8905 * Calculate the raw dram bandwidth (CIK).
8906 * Used for display watermark bandwidth calculations
8907 * Returns the dram bandwidth in MBytes/s
8909 static u32 dce8_dram_bandwidth(struct dce8_wm_params *wm)
8911 /* Calculate raw DRAM Bandwidth */
8912 fixed20_12 dram_efficiency; /* 0.7 */
8913 fixed20_12 yclk, dram_channels, bandwidth;
8916 a.full = dfixed_const(1000);
8917 yclk.full = dfixed_const(wm->yclk);
8918 yclk.full = dfixed_div(yclk, a);
8919 dram_channels.full = dfixed_const(wm->dram_channels * 4);
8920 a.full = dfixed_const(10);
8921 dram_efficiency.full = dfixed_const(7);
8922 dram_efficiency.full = dfixed_div(dram_efficiency, a);
8923 bandwidth.full = dfixed_mul(dram_channels, yclk);
8924 bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
8926 return dfixed_trunc(bandwidth);
8930 * dce8_dram_bandwidth_for_display - get the dram bandwidth for display
8932 * @wm: watermark calculation data
8934 * Calculate the dram bandwidth used for display (CIK).
8935 * Used for display watermark bandwidth calculations
8936 * Returns the dram bandwidth for display in MBytes/s
8938 static u32 dce8_dram_bandwidth_for_display(struct dce8_wm_params *wm)
8940 /* Calculate DRAM Bandwidth and the part allocated to display. */
8941 fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
8942 fixed20_12 yclk, dram_channels, bandwidth;
8945 a.full = dfixed_const(1000);
8946 yclk.full = dfixed_const(wm->yclk);
8947 yclk.full = dfixed_div(yclk, a);
8948 dram_channels.full = dfixed_const(wm->dram_channels * 4);
8949 a.full = dfixed_const(10);
8950 disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
8951 disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
8952 bandwidth.full = dfixed_mul(dram_channels, yclk);
8953 bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
8955 return dfixed_trunc(bandwidth);
8959 * dce8_data_return_bandwidth - get the data return bandwidth
8961 * @wm: watermark calculation data
8963 * Calculate the data return bandwidth used for display (CIK).
8964 * Used for display watermark bandwidth calculations
8965 * Returns the data return bandwidth in MBytes/s
8967 static u32 dce8_data_return_bandwidth(struct dce8_wm_params *wm)
8969 /* Calculate the display Data return Bandwidth */
8970 fixed20_12 return_efficiency; /* 0.8 */
8971 fixed20_12 sclk, bandwidth;
8974 a.full = dfixed_const(1000);
8975 sclk.full = dfixed_const(wm->sclk);
8976 sclk.full = dfixed_div(sclk, a);
8977 a.full = dfixed_const(10);
8978 return_efficiency.full = dfixed_const(8);
8979 return_efficiency.full = dfixed_div(return_efficiency, a);
8980 a.full = dfixed_const(32);
8981 bandwidth.full = dfixed_mul(a, sclk);
8982 bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
8984 return dfixed_trunc(bandwidth);
8988 * dce8_dmif_request_bandwidth - get the dmif bandwidth
8990 * @wm: watermark calculation data
8992 * Calculate the dmif bandwidth used for display (CIK).
8993 * Used for display watermark bandwidth calculations
8994 * Returns the dmif bandwidth in MBytes/s
8996 static u32 dce8_dmif_request_bandwidth(struct dce8_wm_params *wm)
8998 /* Calculate the DMIF Request Bandwidth */
8999 fixed20_12 disp_clk_request_efficiency; /* 0.8 */
9000 fixed20_12 disp_clk, bandwidth;
9003 a.full = dfixed_const(1000);
9004 disp_clk.full = dfixed_const(wm->disp_clk);
9005 disp_clk.full = dfixed_div(disp_clk, a);
9006 a.full = dfixed_const(32);
9007 b.full = dfixed_mul(a, disp_clk);
9009 a.full = dfixed_const(10);
9010 disp_clk_request_efficiency.full = dfixed_const(8);
9011 disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
9013 bandwidth.full = dfixed_mul(b, disp_clk_request_efficiency);
9015 return dfixed_trunc(bandwidth);
9019 * dce8_available_bandwidth - get the min available bandwidth
9021 * @wm: watermark calculation data
9023 * Calculate the min available bandwidth used for display (CIK).
9024 * Used for display watermark bandwidth calculations
9025 * Returns the min available bandwidth in MBytes/s
9027 static u32 dce8_available_bandwidth(struct dce8_wm_params *wm)
9029 /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
9030 u32 dram_bandwidth = dce8_dram_bandwidth(wm);
9031 u32 data_return_bandwidth = dce8_data_return_bandwidth(wm);
9032 u32 dmif_req_bandwidth = dce8_dmif_request_bandwidth(wm);
9034 return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
9038 * dce8_average_bandwidth - get the average available bandwidth
9040 * @wm: watermark calculation data
9042 * Calculate the average available bandwidth used for display (CIK).
9043 * Used for display watermark bandwidth calculations
9044 * Returns the average available bandwidth in MBytes/s
9046 static u32 dce8_average_bandwidth(struct dce8_wm_params *wm)
9048 /* Calculate the display mode Average Bandwidth
9049 * DisplayMode should contain the source and destination dimensions,
9053 fixed20_12 line_time;
9054 fixed20_12 src_width;
9055 fixed20_12 bandwidth;
9058 a.full = dfixed_const(1000);
9059 line_time.full = dfixed_const(wm->active_time + wm->blank_time);
9060 line_time.full = dfixed_div(line_time, a);
9061 bpp.full = dfixed_const(wm->bytes_per_pixel);
9062 src_width.full = dfixed_const(wm->src_width);
9063 bandwidth.full = dfixed_mul(src_width, bpp);
9064 bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
9065 bandwidth.full = dfixed_div(bandwidth, line_time);
9067 return dfixed_trunc(bandwidth);
9071 * dce8_latency_watermark - get the latency watermark
9073 * @wm: watermark calculation data
9075 * Calculate the latency watermark (CIK).
9076 * Used for display watermark bandwidth calculations
9077 * Returns the latency watermark in ns
9079 static u32 dce8_latency_watermark(struct dce8_wm_params *wm)
9081 /* First calculate the latency in ns */
9082 u32 mc_latency = 2000; /* 2000 ns. */
9083 u32 available_bandwidth = dce8_available_bandwidth(wm);
9084 u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
9085 u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
9086 u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
9087 u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
9088 (wm->num_heads * cursor_line_pair_return_time);
9089 u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
9090 u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
9091 u32 tmp, dmif_size = 12288;
9094 if (wm->num_heads == 0)
9097 a.full = dfixed_const(2);
9098 b.full = dfixed_const(1);
9099 if ((wm->vsc.full > a.full) ||
9100 ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
9102 ((wm->vsc.full >= a.full) && wm->interlaced))
9103 max_src_lines_per_dst_line = 4;
9105 max_src_lines_per_dst_line = 2;
9107 a.full = dfixed_const(available_bandwidth);
9108 b.full = dfixed_const(wm->num_heads);
9109 a.full = dfixed_div(a, b);
9110 tmp = div_u64((u64) dmif_size * (u64) wm->disp_clk, mc_latency + 512);
9111 tmp = min(dfixed_trunc(a), tmp);
9113 lb_fill_bw = min(tmp, wm->disp_clk * wm->bytes_per_pixel / 1000);
9115 a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
9116 b.full = dfixed_const(1000);
9117 c.full = dfixed_const(lb_fill_bw);
9118 b.full = dfixed_div(c, b);
9119 a.full = dfixed_div(a, b);
9120 line_fill_time = dfixed_trunc(a);
9122 if (line_fill_time < wm->active_time)
9125 return latency + (line_fill_time - wm->active_time);
9130 * dce8_average_bandwidth_vs_dram_bandwidth_for_display - check
9131 * average and available dram bandwidth
9133 * @wm: watermark calculation data
9135 * Check if the display average bandwidth fits in the display
9136 * dram bandwidth (CIK).
9137 * Used for display watermark bandwidth calculations
9138 * Returns true if the display fits, false if not.
9140 static bool dce8_average_bandwidth_vs_dram_bandwidth_for_display(struct dce8_wm_params *wm)
9142 if (dce8_average_bandwidth(wm) <=
9143 (dce8_dram_bandwidth_for_display(wm) / wm->num_heads))
9150 * dce8_average_bandwidth_vs_available_bandwidth - check
9151 * average and available bandwidth
9153 * @wm: watermark calculation data
9155 * Check if the display average bandwidth fits in the display
9156 * available bandwidth (CIK).
9157 * Used for display watermark bandwidth calculations
9158 * Returns true if the display fits, false if not.
9160 static bool dce8_average_bandwidth_vs_available_bandwidth(struct dce8_wm_params *wm)
9162 if (dce8_average_bandwidth(wm) <=
9163 (dce8_available_bandwidth(wm) / wm->num_heads))
9170 * dce8_check_latency_hiding - check latency hiding
9172 * @wm: watermark calculation data
9174 * Check latency hiding (CIK).
9175 * Used for display watermark bandwidth calculations
9176 * Returns true if the display fits, false if not.
9178 static bool dce8_check_latency_hiding(struct dce8_wm_params *wm)
9180 u32 lb_partitions = wm->lb_size / wm->src_width;
9181 u32 line_time = wm->active_time + wm->blank_time;
9182 u32 latency_tolerant_lines;
9186 a.full = dfixed_const(1);
9187 if (wm->vsc.full > a.full)
9188 latency_tolerant_lines = 1;
9190 if (lb_partitions <= (wm->vtaps + 1))
9191 latency_tolerant_lines = 1;
9193 latency_tolerant_lines = 2;
9196 latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
9198 if (dce8_latency_watermark(wm) <= latency_hiding)
9205 * dce8_program_watermarks - program display watermarks
9207 * @rdev: radeon_device pointer
9208 * @radeon_crtc: the selected display controller
9209 * @lb_size: line buffer size
9210 * @num_heads: number of display controllers in use
9212 * Calculate and program the display watermarks for the
9213 * selected display controller (CIK).
9215 static void dce8_program_watermarks(struct radeon_device *rdev,
9216 struct radeon_crtc *radeon_crtc,
9217 u32 lb_size, u32 num_heads)
9219 struct drm_display_mode *mode = &radeon_crtc->base.mode;
9220 struct dce8_wm_params wm_low, wm_high;
9223 u32 latency_watermark_a = 0, latency_watermark_b = 0;
9226 if (radeon_crtc->base.enabled && num_heads && mode) {
9227 active_time = (u32) div_u64((u64)mode->crtc_hdisplay * 1000000,
9229 line_time = (u32) div_u64((u64)mode->crtc_htotal * 1000000,
9231 line_time = min(line_time, (u32)65535);
9233 /* watermark for high clocks */
9234 if ((rdev->pm.pm_method == PM_METHOD_DPM) &&
9235 rdev->pm.dpm_enabled) {
9237 radeon_dpm_get_mclk(rdev, false) * 10;
9239 radeon_dpm_get_sclk(rdev, false) * 10;
9241 wm_high.yclk = rdev->pm.current_mclk * 10;
9242 wm_high.sclk = rdev->pm.current_sclk * 10;
9245 wm_high.disp_clk = mode->clock;
9246 wm_high.src_width = mode->crtc_hdisplay;
9247 wm_high.active_time = active_time;
9248 wm_high.blank_time = line_time - wm_high.active_time;
9249 wm_high.interlaced = false;
9250 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
9251 wm_high.interlaced = true;
9252 wm_high.vsc = radeon_crtc->vsc;
9254 if (radeon_crtc->rmx_type != RMX_OFF)
9256 wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
9257 wm_high.lb_size = lb_size;
9258 wm_high.dram_channels = cik_get_number_of_dram_channels(rdev);
9259 wm_high.num_heads = num_heads;
9261 /* set for high clocks */
9262 latency_watermark_a = min(dce8_latency_watermark(&wm_high), (u32)65535);
9264 /* possibly force display priority to high */
9265 /* should really do this at mode validation time... */
9266 if (!dce8_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
9267 !dce8_average_bandwidth_vs_available_bandwidth(&wm_high) ||
9268 !dce8_check_latency_hiding(&wm_high) ||
9269 (rdev->disp_priority == 2)) {
9270 DRM_DEBUG_KMS("force priority to high\n");
9273 /* watermark for low clocks */
9274 if ((rdev->pm.pm_method == PM_METHOD_DPM) &&
9275 rdev->pm.dpm_enabled) {
9277 radeon_dpm_get_mclk(rdev, true) * 10;
9279 radeon_dpm_get_sclk(rdev, true) * 10;
9281 wm_low.yclk = rdev->pm.current_mclk * 10;
9282 wm_low.sclk = rdev->pm.current_sclk * 10;
9285 wm_low.disp_clk = mode->clock;
9286 wm_low.src_width = mode->crtc_hdisplay;
9287 wm_low.active_time = active_time;
9288 wm_low.blank_time = line_time - wm_low.active_time;
9289 wm_low.interlaced = false;
9290 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
9291 wm_low.interlaced = true;
9292 wm_low.vsc = radeon_crtc->vsc;
9294 if (radeon_crtc->rmx_type != RMX_OFF)
9296 wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
9297 wm_low.lb_size = lb_size;
9298 wm_low.dram_channels = cik_get_number_of_dram_channels(rdev);
9299 wm_low.num_heads = num_heads;
9301 /* set for low clocks */
9302 latency_watermark_b = min(dce8_latency_watermark(&wm_low), (u32)65535);
9304 /* possibly force display priority to high */
9305 /* should really do this at mode validation time... */
9306 if (!dce8_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
9307 !dce8_average_bandwidth_vs_available_bandwidth(&wm_low) ||
9308 !dce8_check_latency_hiding(&wm_low) ||
9309 (rdev->disp_priority == 2)) {
9310 DRM_DEBUG_KMS("force priority to high\n");
9313 /* Save number of lines the linebuffer leads before the scanout */
9314 radeon_crtc->lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode->crtc_hdisplay);
9318 wm_mask = RREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset);
9320 tmp &= ~LATENCY_WATERMARK_MASK(3);
9321 tmp |= LATENCY_WATERMARK_MASK(1);
9322 WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, tmp);
9323 WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
9324 (LATENCY_LOW_WATERMARK(latency_watermark_a) |
9325 LATENCY_HIGH_WATERMARK(line_time)));
9327 tmp = RREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset);
9328 tmp &= ~LATENCY_WATERMARK_MASK(3);
9329 tmp |= LATENCY_WATERMARK_MASK(2);
9330 WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, tmp);
9331 WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
9332 (LATENCY_LOW_WATERMARK(latency_watermark_b) |
9333 LATENCY_HIGH_WATERMARK(line_time)));
9334 /* restore original selection */
9335 WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, wm_mask);
9337 /* save values for DPM */
9338 radeon_crtc->line_time = line_time;
9339 radeon_crtc->wm_high = latency_watermark_a;
9340 radeon_crtc->wm_low = latency_watermark_b;
9344 * dce8_bandwidth_update - program display watermarks
9346 * @rdev: radeon_device pointer
9348 * Calculate and program the display watermarks and line
9349 * buffer allocation (CIK).
9351 void dce8_bandwidth_update(struct radeon_device *rdev)
9353 struct drm_display_mode *mode = NULL;
9354 u32 num_heads = 0, lb_size;
9357 if (!rdev->mode_info.mode_config_initialized)
9360 radeon_update_display_priority(rdev);
9362 for (i = 0; i < rdev->num_crtc; i++) {
9363 if (rdev->mode_info.crtcs[i]->base.enabled)
9366 for (i = 0; i < rdev->num_crtc; i++) {
9367 mode = &rdev->mode_info.crtcs[i]->base.mode;
9368 lb_size = dce8_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode);
9369 dce8_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
9374 * cik_get_gpu_clock_counter - return GPU clock counter snapshot
9376 * @rdev: radeon_device pointer
9378 * Fetches a GPU clock counter snapshot (SI).
9379 * Returns the 64 bit clock counter snapshot.
9381 uint64_t cik_get_gpu_clock_counter(struct radeon_device *rdev)
9385 mutex_lock(&rdev->gpu_clock_mutex);
9386 WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
9387 clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
9388 ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
9389 mutex_unlock(&rdev->gpu_clock_mutex);
9393 static int cik_set_uvd_clock(struct radeon_device *rdev, u32 clock,
9394 u32 cntl_reg, u32 status_reg)
9397 struct atom_clock_dividers dividers;
9400 r = radeon_atom_get_clock_dividers(rdev, COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
9401 clock, false, ÷rs);
9405 tmp = RREG32_SMC(cntl_reg);
9406 tmp &= ~(DCLK_DIR_CNTL_EN|DCLK_DIVIDER_MASK);
9407 tmp |= dividers.post_divider;
9408 WREG32_SMC(cntl_reg, tmp);
9410 for (i = 0; i < 100; i++) {
9411 if (RREG32_SMC(status_reg) & DCLK_STATUS)
9421 int cik_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
9425 r = cik_set_uvd_clock(rdev, vclk, CG_VCLK_CNTL, CG_VCLK_STATUS);
9429 r = cik_set_uvd_clock(rdev, dclk, CG_DCLK_CNTL, CG_DCLK_STATUS);
9433 int cik_set_vce_clocks(struct radeon_device *rdev, u32 evclk, u32 ecclk)
9436 struct atom_clock_dividers dividers;
9439 r = radeon_atom_get_clock_dividers(rdev, COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
9440 ecclk, false, ÷rs);
9444 for (i = 0; i < 100; i++) {
9445 if (RREG32_SMC(CG_ECLK_STATUS) & ECLK_STATUS)
9452 tmp = RREG32_SMC(CG_ECLK_CNTL);
9453 tmp &= ~(ECLK_DIR_CNTL_EN|ECLK_DIVIDER_MASK);
9454 tmp |= dividers.post_divider;
9455 WREG32_SMC(CG_ECLK_CNTL, tmp);
9457 for (i = 0; i < 100; i++) {
9458 if (RREG32_SMC(CG_ECLK_STATUS) & ECLK_STATUS)
9468 static void cik_pcie_gen3_enable(struct radeon_device *rdev)
9470 struct pci_dev *root = rdev->pdev->bus->self;
9471 int bridge_pos, gpu_pos;
9472 u32 speed_cntl, mask, current_data_rate;
9477 if (pci_is_root_bus(rdev->pdev->bus))
9481 if (radeon_pcie_gen2 == 0)
9484 if (rdev->flags & RADEON_IS_IGP)
9487 if (!(rdev->flags & RADEON_IS_PCIE))
9490 ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask);
9494 if (!(mask & (DRM_PCIE_SPEED_50 | DRM_PCIE_SPEED_80)))
9497 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
9498 current_data_rate = (speed_cntl & LC_CURRENT_DATA_RATE_MASK) >>
9499 LC_CURRENT_DATA_RATE_SHIFT;
9500 if (mask & DRM_PCIE_SPEED_80) {
9501 if (current_data_rate == 2) {
9502 DRM_INFO("PCIE gen 3 link speeds already enabled\n");
9505 DRM_INFO("enabling PCIE gen 3 link speeds, disable with radeon.pcie_gen2=0\n");
9506 } else if (mask & DRM_PCIE_SPEED_50) {
9507 if (current_data_rate == 1) {
9508 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
9511 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
9514 bridge_pos = pci_pcie_cap(root);
9518 gpu_pos = pci_pcie_cap(rdev->pdev);
9522 if (mask & DRM_PCIE_SPEED_80) {
9523 /* re-try equalization if gen3 is not already enabled */
9524 if (current_data_rate != 2) {
9525 u16 bridge_cfg, gpu_cfg;
9526 u16 bridge_cfg2, gpu_cfg2;
9527 u32 max_lw, current_lw, tmp;
9529 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
9530 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
9532 tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
9533 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
9535 tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
9536 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
9538 tmp = RREG32_PCIE_PORT(PCIE_LC_STATUS1);
9539 max_lw = (tmp & LC_DETECTED_LINK_WIDTH_MASK) >> LC_DETECTED_LINK_WIDTH_SHIFT;
9540 current_lw = (tmp & LC_OPERATING_LINK_WIDTH_MASK) >> LC_OPERATING_LINK_WIDTH_SHIFT;
9542 if (current_lw < max_lw) {
9543 tmp = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
9544 if (tmp & LC_RENEGOTIATION_SUPPORT) {
9545 tmp &= ~(LC_LINK_WIDTH_MASK | LC_UPCONFIGURE_DIS);
9546 tmp |= (max_lw << LC_LINK_WIDTH_SHIFT);
9547 tmp |= LC_UPCONFIGURE_SUPPORT | LC_RENEGOTIATE_EN | LC_RECONFIG_NOW;
9548 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, tmp);
9552 for (i = 0; i < 10; i++) {
9554 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_DEVSTA, &tmp16);
9555 if (tmp16 & PCI_EXP_DEVSTA_TRPND)
9558 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
9559 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
9561 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &bridge_cfg2);
9562 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &gpu_cfg2);
9564 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
9565 tmp |= LC_SET_QUIESCE;
9566 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
9568 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
9570 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
9575 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &tmp16);
9576 tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
9577 tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
9578 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
9580 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &tmp16);
9581 tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
9582 tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
9583 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
9586 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &tmp16);
9587 tmp16 &= ~((1 << 4) | (7 << 9));
9588 tmp16 |= (bridge_cfg2 & ((1 << 4) | (7 << 9)));
9589 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, tmp16);
9591 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
9592 tmp16 &= ~((1 << 4) | (7 << 9));
9593 tmp16 |= (gpu_cfg2 & ((1 << 4) | (7 << 9)));
9594 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
9596 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
9597 tmp &= ~LC_SET_QUIESCE;
9598 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
9603 /* set the link speed */
9604 speed_cntl |= LC_FORCE_EN_SW_SPEED_CHANGE | LC_FORCE_DIS_HW_SPEED_CHANGE;
9605 speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
9606 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
9608 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
9610 if (mask & DRM_PCIE_SPEED_80)
9611 tmp16 |= 3; /* gen3 */
9612 else if (mask & DRM_PCIE_SPEED_50)
9613 tmp16 |= 2; /* gen2 */
9615 tmp16 |= 1; /* gen1 */
9616 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
9618 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
9619 speed_cntl |= LC_INITIATE_LINK_SPEED_CHANGE;
9620 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
9622 for (i = 0; i < rdev->usec_timeout; i++) {
9623 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
9624 if ((speed_cntl & LC_INITIATE_LINK_SPEED_CHANGE) == 0)
9630 static void cik_program_aspm(struct radeon_device *rdev)
9633 bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
9635 bool disable_clkreq = false;
9638 if (radeon_aspm == 0)
9641 /* XXX double check IGPs */
9642 if (rdev->flags & RADEON_IS_IGP)
9645 if (!(rdev->flags & RADEON_IS_PCIE))
9648 orig = data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
9649 data &= ~LC_XMIT_N_FTS_MASK;
9650 data |= LC_XMIT_N_FTS(0x24) | LC_XMIT_N_FTS_OVERRIDE_EN;
9652 WREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL, data);
9654 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL3);
9655 data |= LC_GO_TO_RECOVERY;
9657 WREG32_PCIE_PORT(PCIE_LC_CNTL3, data);
9659 orig = data = RREG32_PCIE_PORT(PCIE_P_CNTL);
9660 data |= P_IGNORE_EDB_ERR;
9662 WREG32_PCIE_PORT(PCIE_P_CNTL, data);
9664 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
9665 data &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
9666 data |= LC_PMI_TO_L1_DIS;
9668 data |= LC_L0S_INACTIVITY(7);
9671 data |= LC_L1_INACTIVITY(7);
9672 data &= ~LC_PMI_TO_L1_DIS;
9674 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
9676 if (!disable_plloff_in_l1) {
9677 bool clk_req_support;
9679 orig = data = RREG32_PCIE_PORT(PB0_PIF_PWRDOWN_0);
9680 data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
9681 data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
9683 WREG32_PCIE_PORT(PB0_PIF_PWRDOWN_0, data);
9685 orig = data = RREG32_PCIE_PORT(PB0_PIF_PWRDOWN_1);
9686 data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
9687 data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
9689 WREG32_PCIE_PORT(PB0_PIF_PWRDOWN_1, data);
9691 orig = data = RREG32_PCIE_PORT(PB1_PIF_PWRDOWN_0);
9692 data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
9693 data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
9695 WREG32_PCIE_PORT(PB1_PIF_PWRDOWN_0, data);
9697 orig = data = RREG32_PCIE_PORT(PB1_PIF_PWRDOWN_1);
9698 data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
9699 data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
9701 WREG32_PCIE_PORT(PB1_PIF_PWRDOWN_1, data);
9703 orig = data = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
9704 data &= ~LC_DYN_LANES_PWR_STATE_MASK;
9705 data |= LC_DYN_LANES_PWR_STATE(3);
9707 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
9710 if (!disable_clkreq &&
9711 !pci_is_root_bus(rdev->pdev->bus)) {
9712 struct pci_dev *root = rdev->pdev->bus->self;
9715 clk_req_support = false;
9716 pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
9717 if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
9718 clk_req_support = true;
9720 clk_req_support = false;
9723 clk_req_support = false;
9726 if (clk_req_support) {
9727 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL2);
9728 data |= LC_ALLOW_PDWN_IN_L1 | LC_ALLOW_PDWN_IN_L23;
9730 WREG32_PCIE_PORT(PCIE_LC_CNTL2, data);
9732 orig = data = RREG32_SMC(THM_CLK_CNTL);
9733 data &= ~(CMON_CLK_SEL_MASK | TMON_CLK_SEL_MASK);
9734 data |= CMON_CLK_SEL(1) | TMON_CLK_SEL(1);
9736 WREG32_SMC(THM_CLK_CNTL, data);
9738 orig = data = RREG32_SMC(MISC_CLK_CTRL);
9739 data &= ~(DEEP_SLEEP_CLK_SEL_MASK | ZCLK_SEL_MASK);
9740 data |= DEEP_SLEEP_CLK_SEL(1) | ZCLK_SEL(1);
9742 WREG32_SMC(MISC_CLK_CTRL, data);
9744 orig = data = RREG32_SMC(CG_CLKPIN_CNTL);
9745 data &= ~BCLK_AS_XCLK;
9747 WREG32_SMC(CG_CLKPIN_CNTL, data);
9749 orig = data = RREG32_SMC(CG_CLKPIN_CNTL_2);
9750 data &= ~FORCE_BIF_REFCLK_EN;
9752 WREG32_SMC(CG_CLKPIN_CNTL_2, data);
9754 orig = data = RREG32_SMC(MPLL_BYPASSCLK_SEL);
9755 data &= ~MPLL_CLKOUT_SEL_MASK;
9756 data |= MPLL_CLKOUT_SEL(4);
9758 WREG32_SMC(MPLL_BYPASSCLK_SEL, data);
9763 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
9766 orig = data = RREG32_PCIE_PORT(PCIE_CNTL2);
9767 data |= SLV_MEM_LS_EN | MST_MEM_LS_EN | REPLAY_MEM_LS_EN;
9769 WREG32_PCIE_PORT(PCIE_CNTL2, data);
9772 data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
9773 if((data & LC_N_FTS_MASK) == LC_N_FTS_MASK) {
9774 data = RREG32_PCIE_PORT(PCIE_LC_STATUS1);
9775 if ((data & LC_REVERSE_XMIT) && (data & LC_REVERSE_RCVR)) {
9776 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
9777 data &= ~LC_L0S_INACTIVITY_MASK;
9779 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);