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"
36 #include "radeon_kfd.h"
38 MODULE_FIRMWARE("radeon/BONAIRE_pfp.bin");
39 MODULE_FIRMWARE("radeon/BONAIRE_me.bin");
40 MODULE_FIRMWARE("radeon/BONAIRE_ce.bin");
41 MODULE_FIRMWARE("radeon/BONAIRE_mec.bin");
42 MODULE_FIRMWARE("radeon/BONAIRE_mc.bin");
43 MODULE_FIRMWARE("radeon/BONAIRE_mc2.bin");
44 MODULE_FIRMWARE("radeon/BONAIRE_rlc.bin");
45 MODULE_FIRMWARE("radeon/BONAIRE_sdma.bin");
46 MODULE_FIRMWARE("radeon/BONAIRE_smc.bin");
48 MODULE_FIRMWARE("radeon/bonaire_pfp.bin");
49 MODULE_FIRMWARE("radeon/bonaire_me.bin");
50 MODULE_FIRMWARE("radeon/bonaire_ce.bin");
51 MODULE_FIRMWARE("radeon/bonaire_mec.bin");
52 MODULE_FIRMWARE("radeon/bonaire_mc.bin");
53 MODULE_FIRMWARE("radeon/bonaire_rlc.bin");
54 MODULE_FIRMWARE("radeon/bonaire_sdma.bin");
55 MODULE_FIRMWARE("radeon/bonaire_smc.bin");
57 MODULE_FIRMWARE("radeon/HAWAII_pfp.bin");
58 MODULE_FIRMWARE("radeon/HAWAII_me.bin");
59 MODULE_FIRMWARE("radeon/HAWAII_ce.bin");
60 MODULE_FIRMWARE("radeon/HAWAII_mec.bin");
61 MODULE_FIRMWARE("radeon/HAWAII_mc.bin");
62 MODULE_FIRMWARE("radeon/HAWAII_mc2.bin");
63 MODULE_FIRMWARE("radeon/HAWAII_rlc.bin");
64 MODULE_FIRMWARE("radeon/HAWAII_sdma.bin");
65 MODULE_FIRMWARE("radeon/HAWAII_smc.bin");
67 MODULE_FIRMWARE("radeon/hawaii_pfp.bin");
68 MODULE_FIRMWARE("radeon/hawaii_me.bin");
69 MODULE_FIRMWARE("radeon/hawaii_ce.bin");
70 MODULE_FIRMWARE("radeon/hawaii_mec.bin");
71 MODULE_FIRMWARE("radeon/hawaii_mc.bin");
72 MODULE_FIRMWARE("radeon/hawaii_rlc.bin");
73 MODULE_FIRMWARE("radeon/hawaii_sdma.bin");
74 MODULE_FIRMWARE("radeon/hawaii_smc.bin");
76 MODULE_FIRMWARE("radeon/KAVERI_pfp.bin");
77 MODULE_FIRMWARE("radeon/KAVERI_me.bin");
78 MODULE_FIRMWARE("radeon/KAVERI_ce.bin");
79 MODULE_FIRMWARE("radeon/KAVERI_mec.bin");
80 MODULE_FIRMWARE("radeon/KAVERI_rlc.bin");
81 MODULE_FIRMWARE("radeon/KAVERI_sdma.bin");
83 MODULE_FIRMWARE("radeon/kaveri_pfp.bin");
84 MODULE_FIRMWARE("radeon/kaveri_me.bin");
85 MODULE_FIRMWARE("radeon/kaveri_ce.bin");
86 MODULE_FIRMWARE("radeon/kaveri_mec.bin");
87 MODULE_FIRMWARE("radeon/kaveri_mec2.bin");
88 MODULE_FIRMWARE("radeon/kaveri_rlc.bin");
89 MODULE_FIRMWARE("radeon/kaveri_sdma.bin");
91 MODULE_FIRMWARE("radeon/KABINI_pfp.bin");
92 MODULE_FIRMWARE("radeon/KABINI_me.bin");
93 MODULE_FIRMWARE("radeon/KABINI_ce.bin");
94 MODULE_FIRMWARE("radeon/KABINI_mec.bin");
95 MODULE_FIRMWARE("radeon/KABINI_rlc.bin");
96 MODULE_FIRMWARE("radeon/KABINI_sdma.bin");
98 MODULE_FIRMWARE("radeon/kabini_pfp.bin");
99 MODULE_FIRMWARE("radeon/kabini_me.bin");
100 MODULE_FIRMWARE("radeon/kabini_ce.bin");
101 MODULE_FIRMWARE("radeon/kabini_mec.bin");
102 MODULE_FIRMWARE("radeon/kabini_rlc.bin");
103 MODULE_FIRMWARE("radeon/kabini_sdma.bin");
105 MODULE_FIRMWARE("radeon/MULLINS_pfp.bin");
106 MODULE_FIRMWARE("radeon/MULLINS_me.bin");
107 MODULE_FIRMWARE("radeon/MULLINS_ce.bin");
108 MODULE_FIRMWARE("radeon/MULLINS_mec.bin");
109 MODULE_FIRMWARE("radeon/MULLINS_rlc.bin");
110 MODULE_FIRMWARE("radeon/MULLINS_sdma.bin");
112 MODULE_FIRMWARE("radeon/mullins_pfp.bin");
113 MODULE_FIRMWARE("radeon/mullins_me.bin");
114 MODULE_FIRMWARE("radeon/mullins_ce.bin");
115 MODULE_FIRMWARE("radeon/mullins_mec.bin");
116 MODULE_FIRMWARE("radeon/mullins_rlc.bin");
117 MODULE_FIRMWARE("radeon/mullins_sdma.bin");
119 extern int r600_ih_ring_alloc(struct radeon_device *rdev);
120 extern void r600_ih_ring_fini(struct radeon_device *rdev);
121 extern void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save);
122 extern void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save);
123 extern bool evergreen_is_display_hung(struct radeon_device *rdev);
124 extern void sumo_rlc_fini(struct radeon_device *rdev);
125 extern int sumo_rlc_init(struct radeon_device *rdev);
126 extern void si_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
127 extern void si_rlc_reset(struct radeon_device *rdev);
128 extern void si_init_uvd_internal_cg(struct radeon_device *rdev);
129 static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh);
130 extern int cik_sdma_resume(struct radeon_device *rdev);
131 extern void cik_sdma_enable(struct radeon_device *rdev, bool enable);
132 extern void cik_sdma_fini(struct radeon_device *rdev);
133 extern void vce_v2_0_enable_mgcg(struct radeon_device *rdev, bool enable);
134 static void cik_rlc_stop(struct radeon_device *rdev);
135 static void cik_pcie_gen3_enable(struct radeon_device *rdev);
136 static void cik_program_aspm(struct radeon_device *rdev);
137 static void cik_init_pg(struct radeon_device *rdev);
138 static void cik_init_cg(struct radeon_device *rdev);
139 static void cik_fini_pg(struct radeon_device *rdev);
140 static void cik_fini_cg(struct radeon_device *rdev);
141 static void cik_enable_gui_idle_interrupt(struct radeon_device *rdev,
145 * cik_get_allowed_info_register - fetch the register for the info ioctl
147 * @rdev: radeon_device pointer
148 * @reg: register offset in bytes
149 * @val: register value
151 * Returns 0 for success or -EINVAL for an invalid register
154 int cik_get_allowed_info_register(struct radeon_device *rdev,
160 case GRBM_STATUS_SE0:
161 case GRBM_STATUS_SE1:
162 case GRBM_STATUS_SE2:
163 case GRBM_STATUS_SE3:
166 case (SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET):
167 case (SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET):
177 /* get temperature in millidegrees */
178 int ci_get_temp(struct radeon_device *rdev)
183 temp = (RREG32_SMC(CG_MULT_THERMAL_STATUS) & CTF_TEMP_MASK) >>
189 actual_temp = temp & 0x1ff;
191 actual_temp = actual_temp * 1000;
196 /* get temperature in millidegrees */
197 int kv_get_temp(struct radeon_device *rdev)
202 temp = RREG32_SMC(0xC0300E0C);
205 actual_temp = (temp / 8) - 49;
209 actual_temp = actual_temp * 1000;
215 * Indirect registers accessor
217 u32 cik_pciep_rreg(struct radeon_device *rdev, u32 reg)
222 spin_lock_irqsave(&rdev->pciep_idx_lock, flags);
223 WREG32(PCIE_INDEX, reg);
224 (void)RREG32(PCIE_INDEX);
225 r = RREG32(PCIE_DATA);
226 spin_unlock_irqrestore(&rdev->pciep_idx_lock, flags);
230 void cik_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
234 spin_lock_irqsave(&rdev->pciep_idx_lock, flags);
235 WREG32(PCIE_INDEX, reg);
236 (void)RREG32(PCIE_INDEX);
237 WREG32(PCIE_DATA, v);
238 (void)RREG32(PCIE_DATA);
239 spin_unlock_irqrestore(&rdev->pciep_idx_lock, flags);
242 static const u32 spectre_rlc_save_restore_register_list[] =
244 (0x0e00 << 16) | (0xc12c >> 2),
246 (0x0e00 << 16) | (0xc140 >> 2),
248 (0x0e00 << 16) | (0xc150 >> 2),
250 (0x0e00 << 16) | (0xc15c >> 2),
252 (0x0e00 << 16) | (0xc168 >> 2),
254 (0x0e00 << 16) | (0xc170 >> 2),
256 (0x0e00 << 16) | (0xc178 >> 2),
258 (0x0e00 << 16) | (0xc204 >> 2),
260 (0x0e00 << 16) | (0xc2b4 >> 2),
262 (0x0e00 << 16) | (0xc2b8 >> 2),
264 (0x0e00 << 16) | (0xc2bc >> 2),
266 (0x0e00 << 16) | (0xc2c0 >> 2),
268 (0x0e00 << 16) | (0x8228 >> 2),
270 (0x0e00 << 16) | (0x829c >> 2),
272 (0x0e00 << 16) | (0x869c >> 2),
274 (0x0600 << 16) | (0x98f4 >> 2),
276 (0x0e00 << 16) | (0x98f8 >> 2),
278 (0x0e00 << 16) | (0x9900 >> 2),
280 (0x0e00 << 16) | (0xc260 >> 2),
282 (0x0e00 << 16) | (0x90e8 >> 2),
284 (0x0e00 << 16) | (0x3c000 >> 2),
286 (0x0e00 << 16) | (0x3c00c >> 2),
288 (0x0e00 << 16) | (0x8c1c >> 2),
290 (0x0e00 << 16) | (0x9700 >> 2),
292 (0x0e00 << 16) | (0xcd20 >> 2),
294 (0x4e00 << 16) | (0xcd20 >> 2),
296 (0x5e00 << 16) | (0xcd20 >> 2),
298 (0x6e00 << 16) | (0xcd20 >> 2),
300 (0x7e00 << 16) | (0xcd20 >> 2),
302 (0x8e00 << 16) | (0xcd20 >> 2),
304 (0x9e00 << 16) | (0xcd20 >> 2),
306 (0xae00 << 16) | (0xcd20 >> 2),
308 (0xbe00 << 16) | (0xcd20 >> 2),
310 (0x0e00 << 16) | (0x89bc >> 2),
312 (0x0e00 << 16) | (0x8900 >> 2),
315 (0x0e00 << 16) | (0xc130 >> 2),
317 (0x0e00 << 16) | (0xc134 >> 2),
319 (0x0e00 << 16) | (0xc1fc >> 2),
321 (0x0e00 << 16) | (0xc208 >> 2),
323 (0x0e00 << 16) | (0xc264 >> 2),
325 (0x0e00 << 16) | (0xc268 >> 2),
327 (0x0e00 << 16) | (0xc26c >> 2),
329 (0x0e00 << 16) | (0xc270 >> 2),
331 (0x0e00 << 16) | (0xc274 >> 2),
333 (0x0e00 << 16) | (0xc278 >> 2),
335 (0x0e00 << 16) | (0xc27c >> 2),
337 (0x0e00 << 16) | (0xc280 >> 2),
339 (0x0e00 << 16) | (0xc284 >> 2),
341 (0x0e00 << 16) | (0xc288 >> 2),
343 (0x0e00 << 16) | (0xc28c >> 2),
345 (0x0e00 << 16) | (0xc290 >> 2),
347 (0x0e00 << 16) | (0xc294 >> 2),
349 (0x0e00 << 16) | (0xc298 >> 2),
351 (0x0e00 << 16) | (0xc29c >> 2),
353 (0x0e00 << 16) | (0xc2a0 >> 2),
355 (0x0e00 << 16) | (0xc2a4 >> 2),
357 (0x0e00 << 16) | (0xc2a8 >> 2),
359 (0x0e00 << 16) | (0xc2ac >> 2),
361 (0x0e00 << 16) | (0xc2b0 >> 2),
363 (0x0e00 << 16) | (0x301d0 >> 2),
365 (0x0e00 << 16) | (0x30238 >> 2),
367 (0x0e00 << 16) | (0x30250 >> 2),
369 (0x0e00 << 16) | (0x30254 >> 2),
371 (0x0e00 << 16) | (0x30258 >> 2),
373 (0x0e00 << 16) | (0x3025c >> 2),
375 (0x4e00 << 16) | (0xc900 >> 2),
377 (0x5e00 << 16) | (0xc900 >> 2),
379 (0x6e00 << 16) | (0xc900 >> 2),
381 (0x7e00 << 16) | (0xc900 >> 2),
383 (0x8e00 << 16) | (0xc900 >> 2),
385 (0x9e00 << 16) | (0xc900 >> 2),
387 (0xae00 << 16) | (0xc900 >> 2),
389 (0xbe00 << 16) | (0xc900 >> 2),
391 (0x4e00 << 16) | (0xc904 >> 2),
393 (0x5e00 << 16) | (0xc904 >> 2),
395 (0x6e00 << 16) | (0xc904 >> 2),
397 (0x7e00 << 16) | (0xc904 >> 2),
399 (0x8e00 << 16) | (0xc904 >> 2),
401 (0x9e00 << 16) | (0xc904 >> 2),
403 (0xae00 << 16) | (0xc904 >> 2),
405 (0xbe00 << 16) | (0xc904 >> 2),
407 (0x4e00 << 16) | (0xc908 >> 2),
409 (0x5e00 << 16) | (0xc908 >> 2),
411 (0x6e00 << 16) | (0xc908 >> 2),
413 (0x7e00 << 16) | (0xc908 >> 2),
415 (0x8e00 << 16) | (0xc908 >> 2),
417 (0x9e00 << 16) | (0xc908 >> 2),
419 (0xae00 << 16) | (0xc908 >> 2),
421 (0xbe00 << 16) | (0xc908 >> 2),
423 (0x4e00 << 16) | (0xc90c >> 2),
425 (0x5e00 << 16) | (0xc90c >> 2),
427 (0x6e00 << 16) | (0xc90c >> 2),
429 (0x7e00 << 16) | (0xc90c >> 2),
431 (0x8e00 << 16) | (0xc90c >> 2),
433 (0x9e00 << 16) | (0xc90c >> 2),
435 (0xae00 << 16) | (0xc90c >> 2),
437 (0xbe00 << 16) | (0xc90c >> 2),
439 (0x4e00 << 16) | (0xc910 >> 2),
441 (0x5e00 << 16) | (0xc910 >> 2),
443 (0x6e00 << 16) | (0xc910 >> 2),
445 (0x7e00 << 16) | (0xc910 >> 2),
447 (0x8e00 << 16) | (0xc910 >> 2),
449 (0x9e00 << 16) | (0xc910 >> 2),
451 (0xae00 << 16) | (0xc910 >> 2),
453 (0xbe00 << 16) | (0xc910 >> 2),
455 (0x0e00 << 16) | (0xc99c >> 2),
457 (0x0e00 << 16) | (0x9834 >> 2),
459 (0x0000 << 16) | (0x30f00 >> 2),
461 (0x0001 << 16) | (0x30f00 >> 2),
463 (0x0000 << 16) | (0x30f04 >> 2),
465 (0x0001 << 16) | (0x30f04 >> 2),
467 (0x0000 << 16) | (0x30f08 >> 2),
469 (0x0001 << 16) | (0x30f08 >> 2),
471 (0x0000 << 16) | (0x30f0c >> 2),
473 (0x0001 << 16) | (0x30f0c >> 2),
475 (0x0600 << 16) | (0x9b7c >> 2),
477 (0x0e00 << 16) | (0x8a14 >> 2),
479 (0x0e00 << 16) | (0x8a18 >> 2),
481 (0x0600 << 16) | (0x30a00 >> 2),
483 (0x0e00 << 16) | (0x8bf0 >> 2),
485 (0x0e00 << 16) | (0x8bcc >> 2),
487 (0x0e00 << 16) | (0x8b24 >> 2),
489 (0x0e00 << 16) | (0x30a04 >> 2),
491 (0x0600 << 16) | (0x30a10 >> 2),
493 (0x0600 << 16) | (0x30a14 >> 2),
495 (0x0600 << 16) | (0x30a18 >> 2),
497 (0x0600 << 16) | (0x30a2c >> 2),
499 (0x0e00 << 16) | (0xc700 >> 2),
501 (0x0e00 << 16) | (0xc704 >> 2),
503 (0x0e00 << 16) | (0xc708 >> 2),
505 (0x0e00 << 16) | (0xc768 >> 2),
507 (0x0400 << 16) | (0xc770 >> 2),
509 (0x0400 << 16) | (0xc774 >> 2),
511 (0x0400 << 16) | (0xc778 >> 2),
513 (0x0400 << 16) | (0xc77c >> 2),
515 (0x0400 << 16) | (0xc780 >> 2),
517 (0x0400 << 16) | (0xc784 >> 2),
519 (0x0400 << 16) | (0xc788 >> 2),
521 (0x0400 << 16) | (0xc78c >> 2),
523 (0x0400 << 16) | (0xc798 >> 2),
525 (0x0400 << 16) | (0xc79c >> 2),
527 (0x0400 << 16) | (0xc7a0 >> 2),
529 (0x0400 << 16) | (0xc7a4 >> 2),
531 (0x0400 << 16) | (0xc7a8 >> 2),
533 (0x0400 << 16) | (0xc7ac >> 2),
535 (0x0400 << 16) | (0xc7b0 >> 2),
537 (0x0400 << 16) | (0xc7b4 >> 2),
539 (0x0e00 << 16) | (0x9100 >> 2),
541 (0x0e00 << 16) | (0x3c010 >> 2),
543 (0x0e00 << 16) | (0x92a8 >> 2),
545 (0x0e00 << 16) | (0x92ac >> 2),
547 (0x0e00 << 16) | (0x92b4 >> 2),
549 (0x0e00 << 16) | (0x92b8 >> 2),
551 (0x0e00 << 16) | (0x92bc >> 2),
553 (0x0e00 << 16) | (0x92c0 >> 2),
555 (0x0e00 << 16) | (0x92c4 >> 2),
557 (0x0e00 << 16) | (0x92c8 >> 2),
559 (0x0e00 << 16) | (0x92cc >> 2),
561 (0x0e00 << 16) | (0x92d0 >> 2),
563 (0x0e00 << 16) | (0x8c00 >> 2),
565 (0x0e00 << 16) | (0x8c04 >> 2),
567 (0x0e00 << 16) | (0x8c20 >> 2),
569 (0x0e00 << 16) | (0x8c38 >> 2),
571 (0x0e00 << 16) | (0x8c3c >> 2),
573 (0x0e00 << 16) | (0xae00 >> 2),
575 (0x0e00 << 16) | (0x9604 >> 2),
577 (0x0e00 << 16) | (0xac08 >> 2),
579 (0x0e00 << 16) | (0xac0c >> 2),
581 (0x0e00 << 16) | (0xac10 >> 2),
583 (0x0e00 << 16) | (0xac14 >> 2),
585 (0x0e00 << 16) | (0xac58 >> 2),
587 (0x0e00 << 16) | (0xac68 >> 2),
589 (0x0e00 << 16) | (0xac6c >> 2),
591 (0x0e00 << 16) | (0xac70 >> 2),
593 (0x0e00 << 16) | (0xac74 >> 2),
595 (0x0e00 << 16) | (0xac78 >> 2),
597 (0x0e00 << 16) | (0xac7c >> 2),
599 (0x0e00 << 16) | (0xac80 >> 2),
601 (0x0e00 << 16) | (0xac84 >> 2),
603 (0x0e00 << 16) | (0xac88 >> 2),
605 (0x0e00 << 16) | (0xac8c >> 2),
607 (0x0e00 << 16) | (0x970c >> 2),
609 (0x0e00 << 16) | (0x9714 >> 2),
611 (0x0e00 << 16) | (0x9718 >> 2),
613 (0x0e00 << 16) | (0x971c >> 2),
615 (0x0e00 << 16) | (0x31068 >> 2),
617 (0x4e00 << 16) | (0x31068 >> 2),
619 (0x5e00 << 16) | (0x31068 >> 2),
621 (0x6e00 << 16) | (0x31068 >> 2),
623 (0x7e00 << 16) | (0x31068 >> 2),
625 (0x8e00 << 16) | (0x31068 >> 2),
627 (0x9e00 << 16) | (0x31068 >> 2),
629 (0xae00 << 16) | (0x31068 >> 2),
631 (0xbe00 << 16) | (0x31068 >> 2),
633 (0x0e00 << 16) | (0xcd10 >> 2),
635 (0x0e00 << 16) | (0xcd14 >> 2),
637 (0x0e00 << 16) | (0x88b0 >> 2),
639 (0x0e00 << 16) | (0x88b4 >> 2),
641 (0x0e00 << 16) | (0x88b8 >> 2),
643 (0x0e00 << 16) | (0x88bc >> 2),
645 (0x0400 << 16) | (0x89c0 >> 2),
647 (0x0e00 << 16) | (0x88c4 >> 2),
649 (0x0e00 << 16) | (0x88c8 >> 2),
651 (0x0e00 << 16) | (0x88d0 >> 2),
653 (0x0e00 << 16) | (0x88d4 >> 2),
655 (0x0e00 << 16) | (0x88d8 >> 2),
657 (0x0e00 << 16) | (0x8980 >> 2),
659 (0x0e00 << 16) | (0x30938 >> 2),
661 (0x0e00 << 16) | (0x3093c >> 2),
663 (0x0e00 << 16) | (0x30940 >> 2),
665 (0x0e00 << 16) | (0x89a0 >> 2),
667 (0x0e00 << 16) | (0x30900 >> 2),
669 (0x0e00 << 16) | (0x30904 >> 2),
671 (0x0e00 << 16) | (0x89b4 >> 2),
673 (0x0e00 << 16) | (0x3c210 >> 2),
675 (0x0e00 << 16) | (0x3c214 >> 2),
677 (0x0e00 << 16) | (0x3c218 >> 2),
679 (0x0e00 << 16) | (0x8904 >> 2),
682 (0x0e00 << 16) | (0x8c28 >> 2),
683 (0x0e00 << 16) | (0x8c2c >> 2),
684 (0x0e00 << 16) | (0x8c30 >> 2),
685 (0x0e00 << 16) | (0x8c34 >> 2),
686 (0x0e00 << 16) | (0x9600 >> 2),
689 static const u32 kalindi_rlc_save_restore_register_list[] =
691 (0x0e00 << 16) | (0xc12c >> 2),
693 (0x0e00 << 16) | (0xc140 >> 2),
695 (0x0e00 << 16) | (0xc150 >> 2),
697 (0x0e00 << 16) | (0xc15c >> 2),
699 (0x0e00 << 16) | (0xc168 >> 2),
701 (0x0e00 << 16) | (0xc170 >> 2),
703 (0x0e00 << 16) | (0xc204 >> 2),
705 (0x0e00 << 16) | (0xc2b4 >> 2),
707 (0x0e00 << 16) | (0xc2b8 >> 2),
709 (0x0e00 << 16) | (0xc2bc >> 2),
711 (0x0e00 << 16) | (0xc2c0 >> 2),
713 (0x0e00 << 16) | (0x8228 >> 2),
715 (0x0e00 << 16) | (0x829c >> 2),
717 (0x0e00 << 16) | (0x869c >> 2),
719 (0x0600 << 16) | (0x98f4 >> 2),
721 (0x0e00 << 16) | (0x98f8 >> 2),
723 (0x0e00 << 16) | (0x9900 >> 2),
725 (0x0e00 << 16) | (0xc260 >> 2),
727 (0x0e00 << 16) | (0x90e8 >> 2),
729 (0x0e00 << 16) | (0x3c000 >> 2),
731 (0x0e00 << 16) | (0x3c00c >> 2),
733 (0x0e00 << 16) | (0x8c1c >> 2),
735 (0x0e00 << 16) | (0x9700 >> 2),
737 (0x0e00 << 16) | (0xcd20 >> 2),
739 (0x4e00 << 16) | (0xcd20 >> 2),
741 (0x5e00 << 16) | (0xcd20 >> 2),
743 (0x6e00 << 16) | (0xcd20 >> 2),
745 (0x7e00 << 16) | (0xcd20 >> 2),
747 (0x0e00 << 16) | (0x89bc >> 2),
749 (0x0e00 << 16) | (0x8900 >> 2),
752 (0x0e00 << 16) | (0xc130 >> 2),
754 (0x0e00 << 16) | (0xc134 >> 2),
756 (0x0e00 << 16) | (0xc1fc >> 2),
758 (0x0e00 << 16) | (0xc208 >> 2),
760 (0x0e00 << 16) | (0xc264 >> 2),
762 (0x0e00 << 16) | (0xc268 >> 2),
764 (0x0e00 << 16) | (0xc26c >> 2),
766 (0x0e00 << 16) | (0xc270 >> 2),
768 (0x0e00 << 16) | (0xc274 >> 2),
770 (0x0e00 << 16) | (0xc28c >> 2),
772 (0x0e00 << 16) | (0xc290 >> 2),
774 (0x0e00 << 16) | (0xc294 >> 2),
776 (0x0e00 << 16) | (0xc298 >> 2),
778 (0x0e00 << 16) | (0xc2a0 >> 2),
780 (0x0e00 << 16) | (0xc2a4 >> 2),
782 (0x0e00 << 16) | (0xc2a8 >> 2),
784 (0x0e00 << 16) | (0xc2ac >> 2),
786 (0x0e00 << 16) | (0x301d0 >> 2),
788 (0x0e00 << 16) | (0x30238 >> 2),
790 (0x0e00 << 16) | (0x30250 >> 2),
792 (0x0e00 << 16) | (0x30254 >> 2),
794 (0x0e00 << 16) | (0x30258 >> 2),
796 (0x0e00 << 16) | (0x3025c >> 2),
798 (0x4e00 << 16) | (0xc900 >> 2),
800 (0x5e00 << 16) | (0xc900 >> 2),
802 (0x6e00 << 16) | (0xc900 >> 2),
804 (0x7e00 << 16) | (0xc900 >> 2),
806 (0x4e00 << 16) | (0xc904 >> 2),
808 (0x5e00 << 16) | (0xc904 >> 2),
810 (0x6e00 << 16) | (0xc904 >> 2),
812 (0x7e00 << 16) | (0xc904 >> 2),
814 (0x4e00 << 16) | (0xc908 >> 2),
816 (0x5e00 << 16) | (0xc908 >> 2),
818 (0x6e00 << 16) | (0xc908 >> 2),
820 (0x7e00 << 16) | (0xc908 >> 2),
822 (0x4e00 << 16) | (0xc90c >> 2),
824 (0x5e00 << 16) | (0xc90c >> 2),
826 (0x6e00 << 16) | (0xc90c >> 2),
828 (0x7e00 << 16) | (0xc90c >> 2),
830 (0x4e00 << 16) | (0xc910 >> 2),
832 (0x5e00 << 16) | (0xc910 >> 2),
834 (0x6e00 << 16) | (0xc910 >> 2),
836 (0x7e00 << 16) | (0xc910 >> 2),
838 (0x0e00 << 16) | (0xc99c >> 2),
840 (0x0e00 << 16) | (0x9834 >> 2),
842 (0x0000 << 16) | (0x30f00 >> 2),
844 (0x0000 << 16) | (0x30f04 >> 2),
846 (0x0000 << 16) | (0x30f08 >> 2),
848 (0x0000 << 16) | (0x30f0c >> 2),
850 (0x0600 << 16) | (0x9b7c >> 2),
852 (0x0e00 << 16) | (0x8a14 >> 2),
854 (0x0e00 << 16) | (0x8a18 >> 2),
856 (0x0600 << 16) | (0x30a00 >> 2),
858 (0x0e00 << 16) | (0x8bf0 >> 2),
860 (0x0e00 << 16) | (0x8bcc >> 2),
862 (0x0e00 << 16) | (0x8b24 >> 2),
864 (0x0e00 << 16) | (0x30a04 >> 2),
866 (0x0600 << 16) | (0x30a10 >> 2),
868 (0x0600 << 16) | (0x30a14 >> 2),
870 (0x0600 << 16) | (0x30a18 >> 2),
872 (0x0600 << 16) | (0x30a2c >> 2),
874 (0x0e00 << 16) | (0xc700 >> 2),
876 (0x0e00 << 16) | (0xc704 >> 2),
878 (0x0e00 << 16) | (0xc708 >> 2),
880 (0x0e00 << 16) | (0xc768 >> 2),
882 (0x0400 << 16) | (0xc770 >> 2),
884 (0x0400 << 16) | (0xc774 >> 2),
886 (0x0400 << 16) | (0xc798 >> 2),
888 (0x0400 << 16) | (0xc79c >> 2),
890 (0x0e00 << 16) | (0x9100 >> 2),
892 (0x0e00 << 16) | (0x3c010 >> 2),
894 (0x0e00 << 16) | (0x8c00 >> 2),
896 (0x0e00 << 16) | (0x8c04 >> 2),
898 (0x0e00 << 16) | (0x8c20 >> 2),
900 (0x0e00 << 16) | (0x8c38 >> 2),
902 (0x0e00 << 16) | (0x8c3c >> 2),
904 (0x0e00 << 16) | (0xae00 >> 2),
906 (0x0e00 << 16) | (0x9604 >> 2),
908 (0x0e00 << 16) | (0xac08 >> 2),
910 (0x0e00 << 16) | (0xac0c >> 2),
912 (0x0e00 << 16) | (0xac10 >> 2),
914 (0x0e00 << 16) | (0xac14 >> 2),
916 (0x0e00 << 16) | (0xac58 >> 2),
918 (0x0e00 << 16) | (0xac68 >> 2),
920 (0x0e00 << 16) | (0xac6c >> 2),
922 (0x0e00 << 16) | (0xac70 >> 2),
924 (0x0e00 << 16) | (0xac74 >> 2),
926 (0x0e00 << 16) | (0xac78 >> 2),
928 (0x0e00 << 16) | (0xac7c >> 2),
930 (0x0e00 << 16) | (0xac80 >> 2),
932 (0x0e00 << 16) | (0xac84 >> 2),
934 (0x0e00 << 16) | (0xac88 >> 2),
936 (0x0e00 << 16) | (0xac8c >> 2),
938 (0x0e00 << 16) | (0x970c >> 2),
940 (0x0e00 << 16) | (0x9714 >> 2),
942 (0x0e00 << 16) | (0x9718 >> 2),
944 (0x0e00 << 16) | (0x971c >> 2),
946 (0x0e00 << 16) | (0x31068 >> 2),
948 (0x4e00 << 16) | (0x31068 >> 2),
950 (0x5e00 << 16) | (0x31068 >> 2),
952 (0x6e00 << 16) | (0x31068 >> 2),
954 (0x7e00 << 16) | (0x31068 >> 2),
956 (0x0e00 << 16) | (0xcd10 >> 2),
958 (0x0e00 << 16) | (0xcd14 >> 2),
960 (0x0e00 << 16) | (0x88b0 >> 2),
962 (0x0e00 << 16) | (0x88b4 >> 2),
964 (0x0e00 << 16) | (0x88b8 >> 2),
966 (0x0e00 << 16) | (0x88bc >> 2),
968 (0x0400 << 16) | (0x89c0 >> 2),
970 (0x0e00 << 16) | (0x88c4 >> 2),
972 (0x0e00 << 16) | (0x88c8 >> 2),
974 (0x0e00 << 16) | (0x88d0 >> 2),
976 (0x0e00 << 16) | (0x88d4 >> 2),
978 (0x0e00 << 16) | (0x88d8 >> 2),
980 (0x0e00 << 16) | (0x8980 >> 2),
982 (0x0e00 << 16) | (0x30938 >> 2),
984 (0x0e00 << 16) | (0x3093c >> 2),
986 (0x0e00 << 16) | (0x30940 >> 2),
988 (0x0e00 << 16) | (0x89a0 >> 2),
990 (0x0e00 << 16) | (0x30900 >> 2),
992 (0x0e00 << 16) | (0x30904 >> 2),
994 (0x0e00 << 16) | (0x89b4 >> 2),
996 (0x0e00 << 16) | (0x3e1fc >> 2),
998 (0x0e00 << 16) | (0x3c210 >> 2),
1000 (0x0e00 << 16) | (0x3c214 >> 2),
1002 (0x0e00 << 16) | (0x3c218 >> 2),
1004 (0x0e00 << 16) | (0x8904 >> 2),
1007 (0x0e00 << 16) | (0x8c28 >> 2),
1008 (0x0e00 << 16) | (0x8c2c >> 2),
1009 (0x0e00 << 16) | (0x8c30 >> 2),
1010 (0x0e00 << 16) | (0x8c34 >> 2),
1011 (0x0e00 << 16) | (0x9600 >> 2),
1014 static const u32 bonaire_golden_spm_registers[] =
1016 0x30800, 0xe0ffffff, 0xe0000000
1019 static const u32 bonaire_golden_common_registers[] =
1021 0xc770, 0xffffffff, 0x00000800,
1022 0xc774, 0xffffffff, 0x00000800,
1023 0xc798, 0xffffffff, 0x00007fbf,
1024 0xc79c, 0xffffffff, 0x00007faf
1027 static const u32 bonaire_golden_registers[] =
1029 0x3354, 0x00000333, 0x00000333,
1030 0x3350, 0x000c0fc0, 0x00040200,
1031 0x9a10, 0x00010000, 0x00058208,
1032 0x3c000, 0xffff1fff, 0x00140000,
1033 0x3c200, 0xfdfc0fff, 0x00000100,
1034 0x3c234, 0x40000000, 0x40000200,
1035 0x9830, 0xffffffff, 0x00000000,
1036 0x9834, 0xf00fffff, 0x00000400,
1037 0x9838, 0x0002021c, 0x00020200,
1038 0xc78, 0x00000080, 0x00000000,
1039 0x5bb0, 0x000000f0, 0x00000070,
1040 0x5bc0, 0xf0311fff, 0x80300000,
1041 0x98f8, 0x73773777, 0x12010001,
1042 0x350c, 0x00810000, 0x408af000,
1043 0x7030, 0x31000111, 0x00000011,
1044 0x2f48, 0x73773777, 0x12010001,
1045 0x220c, 0x00007fb6, 0x0021a1b1,
1046 0x2210, 0x00007fb6, 0x002021b1,
1047 0x2180, 0x00007fb6, 0x00002191,
1048 0x2218, 0x00007fb6, 0x002121b1,
1049 0x221c, 0x00007fb6, 0x002021b1,
1050 0x21dc, 0x00007fb6, 0x00002191,
1051 0x21e0, 0x00007fb6, 0x00002191,
1052 0x3628, 0x0000003f, 0x0000000a,
1053 0x362c, 0x0000003f, 0x0000000a,
1054 0x2ae4, 0x00073ffe, 0x000022a2,
1055 0x240c, 0x000007ff, 0x00000000,
1056 0x8a14, 0xf000003f, 0x00000007,
1057 0x8bf0, 0x00002001, 0x00000001,
1058 0x8b24, 0xffffffff, 0x00ffffff,
1059 0x30a04, 0x0000ff0f, 0x00000000,
1060 0x28a4c, 0x07ffffff, 0x06000000,
1061 0x4d8, 0x00000fff, 0x00000100,
1062 0x3e78, 0x00000001, 0x00000002,
1063 0x9100, 0x03000000, 0x0362c688,
1064 0x8c00, 0x000000ff, 0x00000001,
1065 0xe40, 0x00001fff, 0x00001fff,
1066 0x9060, 0x0000007f, 0x00000020,
1067 0x9508, 0x00010000, 0x00010000,
1068 0xac14, 0x000003ff, 0x000000f3,
1069 0xac0c, 0xffffffff, 0x00001032
1072 static const u32 bonaire_mgcg_cgcg_init[] =
1074 0xc420, 0xffffffff, 0xfffffffc,
1075 0x30800, 0xffffffff, 0xe0000000,
1076 0x3c2a0, 0xffffffff, 0x00000100,
1077 0x3c208, 0xffffffff, 0x00000100,
1078 0x3c2c0, 0xffffffff, 0xc0000100,
1079 0x3c2c8, 0xffffffff, 0xc0000100,
1080 0x3c2c4, 0xffffffff, 0xc0000100,
1081 0x55e4, 0xffffffff, 0x00600100,
1082 0x3c280, 0xffffffff, 0x00000100,
1083 0x3c214, 0xffffffff, 0x06000100,
1084 0x3c220, 0xffffffff, 0x00000100,
1085 0x3c218, 0xffffffff, 0x06000100,
1086 0x3c204, 0xffffffff, 0x00000100,
1087 0x3c2e0, 0xffffffff, 0x00000100,
1088 0x3c224, 0xffffffff, 0x00000100,
1089 0x3c200, 0xffffffff, 0x00000100,
1090 0x3c230, 0xffffffff, 0x00000100,
1091 0x3c234, 0xffffffff, 0x00000100,
1092 0x3c250, 0xffffffff, 0x00000100,
1093 0x3c254, 0xffffffff, 0x00000100,
1094 0x3c258, 0xffffffff, 0x00000100,
1095 0x3c25c, 0xffffffff, 0x00000100,
1096 0x3c260, 0xffffffff, 0x00000100,
1097 0x3c27c, 0xffffffff, 0x00000100,
1098 0x3c278, 0xffffffff, 0x00000100,
1099 0x3c210, 0xffffffff, 0x06000100,
1100 0x3c290, 0xffffffff, 0x00000100,
1101 0x3c274, 0xffffffff, 0x00000100,
1102 0x3c2b4, 0xffffffff, 0x00000100,
1103 0x3c2b0, 0xffffffff, 0x00000100,
1104 0x3c270, 0xffffffff, 0x00000100,
1105 0x30800, 0xffffffff, 0xe0000000,
1106 0x3c020, 0xffffffff, 0x00010000,
1107 0x3c024, 0xffffffff, 0x00030002,
1108 0x3c028, 0xffffffff, 0x00040007,
1109 0x3c02c, 0xffffffff, 0x00060005,
1110 0x3c030, 0xffffffff, 0x00090008,
1111 0x3c034, 0xffffffff, 0x00010000,
1112 0x3c038, 0xffffffff, 0x00030002,
1113 0x3c03c, 0xffffffff, 0x00040007,
1114 0x3c040, 0xffffffff, 0x00060005,
1115 0x3c044, 0xffffffff, 0x00090008,
1116 0x3c048, 0xffffffff, 0x00010000,
1117 0x3c04c, 0xffffffff, 0x00030002,
1118 0x3c050, 0xffffffff, 0x00040007,
1119 0x3c054, 0xffffffff, 0x00060005,
1120 0x3c058, 0xffffffff, 0x00090008,
1121 0x3c05c, 0xffffffff, 0x00010000,
1122 0x3c060, 0xffffffff, 0x00030002,
1123 0x3c064, 0xffffffff, 0x00040007,
1124 0x3c068, 0xffffffff, 0x00060005,
1125 0x3c06c, 0xffffffff, 0x00090008,
1126 0x3c070, 0xffffffff, 0x00010000,
1127 0x3c074, 0xffffffff, 0x00030002,
1128 0x3c078, 0xffffffff, 0x00040007,
1129 0x3c07c, 0xffffffff, 0x00060005,
1130 0x3c080, 0xffffffff, 0x00090008,
1131 0x3c084, 0xffffffff, 0x00010000,
1132 0x3c088, 0xffffffff, 0x00030002,
1133 0x3c08c, 0xffffffff, 0x00040007,
1134 0x3c090, 0xffffffff, 0x00060005,
1135 0x3c094, 0xffffffff, 0x00090008,
1136 0x3c098, 0xffffffff, 0x00010000,
1137 0x3c09c, 0xffffffff, 0x00030002,
1138 0x3c0a0, 0xffffffff, 0x00040007,
1139 0x3c0a4, 0xffffffff, 0x00060005,
1140 0x3c0a8, 0xffffffff, 0x00090008,
1141 0x3c000, 0xffffffff, 0x96e00200,
1142 0x8708, 0xffffffff, 0x00900100,
1143 0xc424, 0xffffffff, 0x0020003f,
1144 0x38, 0xffffffff, 0x0140001c,
1145 0x3c, 0x000f0000, 0x000f0000,
1146 0x220, 0xffffffff, 0xC060000C,
1147 0x224, 0xc0000fff, 0x00000100,
1148 0xf90, 0xffffffff, 0x00000100,
1149 0xf98, 0x00000101, 0x00000000,
1150 0x20a8, 0xffffffff, 0x00000104,
1151 0x55e4, 0xff000fff, 0x00000100,
1152 0x30cc, 0xc0000fff, 0x00000104,
1153 0xc1e4, 0x00000001, 0x00000001,
1154 0xd00c, 0xff000ff0, 0x00000100,
1155 0xd80c, 0xff000ff0, 0x00000100
1158 static const u32 spectre_golden_spm_registers[] =
1160 0x30800, 0xe0ffffff, 0xe0000000
1163 static const u32 spectre_golden_common_registers[] =
1165 0xc770, 0xffffffff, 0x00000800,
1166 0xc774, 0xffffffff, 0x00000800,
1167 0xc798, 0xffffffff, 0x00007fbf,
1168 0xc79c, 0xffffffff, 0x00007faf
1171 static const u32 spectre_golden_registers[] =
1173 0x3c000, 0xffff1fff, 0x96940200,
1174 0x3c00c, 0xffff0001, 0xff000000,
1175 0x3c200, 0xfffc0fff, 0x00000100,
1176 0x6ed8, 0x00010101, 0x00010000,
1177 0x9834, 0xf00fffff, 0x00000400,
1178 0x9838, 0xfffffffc, 0x00020200,
1179 0x5bb0, 0x000000f0, 0x00000070,
1180 0x5bc0, 0xf0311fff, 0x80300000,
1181 0x98f8, 0x73773777, 0x12010001,
1182 0x9b7c, 0x00ff0000, 0x00fc0000,
1183 0x2f48, 0x73773777, 0x12010001,
1184 0x8a14, 0xf000003f, 0x00000007,
1185 0x8b24, 0xffffffff, 0x00ffffff,
1186 0x28350, 0x3f3f3fff, 0x00000082,
1187 0x28354, 0x0000003f, 0x00000000,
1188 0x3e78, 0x00000001, 0x00000002,
1189 0x913c, 0xffff03df, 0x00000004,
1190 0xc768, 0x00000008, 0x00000008,
1191 0x8c00, 0x000008ff, 0x00000800,
1192 0x9508, 0x00010000, 0x00010000,
1193 0xac0c, 0xffffffff, 0x54763210,
1194 0x214f8, 0x01ff01ff, 0x00000002,
1195 0x21498, 0x007ff800, 0x00200000,
1196 0x2015c, 0xffffffff, 0x00000f40,
1197 0x30934, 0xffffffff, 0x00000001
1200 static const u32 spectre_mgcg_cgcg_init[] =
1202 0xc420, 0xffffffff, 0xfffffffc,
1203 0x30800, 0xffffffff, 0xe0000000,
1204 0x3c2a0, 0xffffffff, 0x00000100,
1205 0x3c208, 0xffffffff, 0x00000100,
1206 0x3c2c0, 0xffffffff, 0x00000100,
1207 0x3c2c8, 0xffffffff, 0x00000100,
1208 0x3c2c4, 0xffffffff, 0x00000100,
1209 0x55e4, 0xffffffff, 0x00600100,
1210 0x3c280, 0xffffffff, 0x00000100,
1211 0x3c214, 0xffffffff, 0x06000100,
1212 0x3c220, 0xffffffff, 0x00000100,
1213 0x3c218, 0xffffffff, 0x06000100,
1214 0x3c204, 0xffffffff, 0x00000100,
1215 0x3c2e0, 0xffffffff, 0x00000100,
1216 0x3c224, 0xffffffff, 0x00000100,
1217 0x3c200, 0xffffffff, 0x00000100,
1218 0x3c230, 0xffffffff, 0x00000100,
1219 0x3c234, 0xffffffff, 0x00000100,
1220 0x3c250, 0xffffffff, 0x00000100,
1221 0x3c254, 0xffffffff, 0x00000100,
1222 0x3c258, 0xffffffff, 0x00000100,
1223 0x3c25c, 0xffffffff, 0x00000100,
1224 0x3c260, 0xffffffff, 0x00000100,
1225 0x3c27c, 0xffffffff, 0x00000100,
1226 0x3c278, 0xffffffff, 0x00000100,
1227 0x3c210, 0xffffffff, 0x06000100,
1228 0x3c290, 0xffffffff, 0x00000100,
1229 0x3c274, 0xffffffff, 0x00000100,
1230 0x3c2b4, 0xffffffff, 0x00000100,
1231 0x3c2b0, 0xffffffff, 0x00000100,
1232 0x3c270, 0xffffffff, 0x00000100,
1233 0x30800, 0xffffffff, 0xe0000000,
1234 0x3c020, 0xffffffff, 0x00010000,
1235 0x3c024, 0xffffffff, 0x00030002,
1236 0x3c028, 0xffffffff, 0x00040007,
1237 0x3c02c, 0xffffffff, 0x00060005,
1238 0x3c030, 0xffffffff, 0x00090008,
1239 0x3c034, 0xffffffff, 0x00010000,
1240 0x3c038, 0xffffffff, 0x00030002,
1241 0x3c03c, 0xffffffff, 0x00040007,
1242 0x3c040, 0xffffffff, 0x00060005,
1243 0x3c044, 0xffffffff, 0x00090008,
1244 0x3c048, 0xffffffff, 0x00010000,
1245 0x3c04c, 0xffffffff, 0x00030002,
1246 0x3c050, 0xffffffff, 0x00040007,
1247 0x3c054, 0xffffffff, 0x00060005,
1248 0x3c058, 0xffffffff, 0x00090008,
1249 0x3c05c, 0xffffffff, 0x00010000,
1250 0x3c060, 0xffffffff, 0x00030002,
1251 0x3c064, 0xffffffff, 0x00040007,
1252 0x3c068, 0xffffffff, 0x00060005,
1253 0x3c06c, 0xffffffff, 0x00090008,
1254 0x3c070, 0xffffffff, 0x00010000,
1255 0x3c074, 0xffffffff, 0x00030002,
1256 0x3c078, 0xffffffff, 0x00040007,
1257 0x3c07c, 0xffffffff, 0x00060005,
1258 0x3c080, 0xffffffff, 0x00090008,
1259 0x3c084, 0xffffffff, 0x00010000,
1260 0x3c088, 0xffffffff, 0x00030002,
1261 0x3c08c, 0xffffffff, 0x00040007,
1262 0x3c090, 0xffffffff, 0x00060005,
1263 0x3c094, 0xffffffff, 0x00090008,
1264 0x3c098, 0xffffffff, 0x00010000,
1265 0x3c09c, 0xffffffff, 0x00030002,
1266 0x3c0a0, 0xffffffff, 0x00040007,
1267 0x3c0a4, 0xffffffff, 0x00060005,
1268 0x3c0a8, 0xffffffff, 0x00090008,
1269 0x3c0ac, 0xffffffff, 0x00010000,
1270 0x3c0b0, 0xffffffff, 0x00030002,
1271 0x3c0b4, 0xffffffff, 0x00040007,
1272 0x3c0b8, 0xffffffff, 0x00060005,
1273 0x3c0bc, 0xffffffff, 0x00090008,
1274 0x3c000, 0xffffffff, 0x96e00200,
1275 0x8708, 0xffffffff, 0x00900100,
1276 0xc424, 0xffffffff, 0x0020003f,
1277 0x38, 0xffffffff, 0x0140001c,
1278 0x3c, 0x000f0000, 0x000f0000,
1279 0x220, 0xffffffff, 0xC060000C,
1280 0x224, 0xc0000fff, 0x00000100,
1281 0xf90, 0xffffffff, 0x00000100,
1282 0xf98, 0x00000101, 0x00000000,
1283 0x20a8, 0xffffffff, 0x00000104,
1284 0x55e4, 0xff000fff, 0x00000100,
1285 0x30cc, 0xc0000fff, 0x00000104,
1286 0xc1e4, 0x00000001, 0x00000001,
1287 0xd00c, 0xff000ff0, 0x00000100,
1288 0xd80c, 0xff000ff0, 0x00000100
1291 static const u32 kalindi_golden_spm_registers[] =
1293 0x30800, 0xe0ffffff, 0xe0000000
1296 static const u32 kalindi_golden_common_registers[] =
1298 0xc770, 0xffffffff, 0x00000800,
1299 0xc774, 0xffffffff, 0x00000800,
1300 0xc798, 0xffffffff, 0x00007fbf,
1301 0xc79c, 0xffffffff, 0x00007faf
1304 static const u32 kalindi_golden_registers[] =
1306 0x3c000, 0xffffdfff, 0x6e944040,
1307 0x55e4, 0xff607fff, 0xfc000100,
1308 0x3c220, 0xff000fff, 0x00000100,
1309 0x3c224, 0xff000fff, 0x00000100,
1310 0x3c200, 0xfffc0fff, 0x00000100,
1311 0x6ed8, 0x00010101, 0x00010000,
1312 0x9830, 0xffffffff, 0x00000000,
1313 0x9834, 0xf00fffff, 0x00000400,
1314 0x5bb0, 0x000000f0, 0x00000070,
1315 0x5bc0, 0xf0311fff, 0x80300000,
1316 0x98f8, 0x73773777, 0x12010001,
1317 0x98fc, 0xffffffff, 0x00000010,
1318 0x9b7c, 0x00ff0000, 0x00fc0000,
1319 0x8030, 0x00001f0f, 0x0000100a,
1320 0x2f48, 0x73773777, 0x12010001,
1321 0x2408, 0x000fffff, 0x000c007f,
1322 0x8a14, 0xf000003f, 0x00000007,
1323 0x8b24, 0x3fff3fff, 0x00ffcfff,
1324 0x30a04, 0x0000ff0f, 0x00000000,
1325 0x28a4c, 0x07ffffff, 0x06000000,
1326 0x4d8, 0x00000fff, 0x00000100,
1327 0x3e78, 0x00000001, 0x00000002,
1328 0xc768, 0x00000008, 0x00000008,
1329 0x8c00, 0x000000ff, 0x00000003,
1330 0x214f8, 0x01ff01ff, 0x00000002,
1331 0x21498, 0x007ff800, 0x00200000,
1332 0x2015c, 0xffffffff, 0x00000f40,
1333 0x88c4, 0x001f3ae3, 0x00000082,
1334 0x88d4, 0x0000001f, 0x00000010,
1335 0x30934, 0xffffffff, 0x00000000
1338 static const u32 kalindi_mgcg_cgcg_init[] =
1340 0xc420, 0xffffffff, 0xfffffffc,
1341 0x30800, 0xffffffff, 0xe0000000,
1342 0x3c2a0, 0xffffffff, 0x00000100,
1343 0x3c208, 0xffffffff, 0x00000100,
1344 0x3c2c0, 0xffffffff, 0x00000100,
1345 0x3c2c8, 0xffffffff, 0x00000100,
1346 0x3c2c4, 0xffffffff, 0x00000100,
1347 0x55e4, 0xffffffff, 0x00600100,
1348 0x3c280, 0xffffffff, 0x00000100,
1349 0x3c214, 0xffffffff, 0x06000100,
1350 0x3c220, 0xffffffff, 0x00000100,
1351 0x3c218, 0xffffffff, 0x06000100,
1352 0x3c204, 0xffffffff, 0x00000100,
1353 0x3c2e0, 0xffffffff, 0x00000100,
1354 0x3c224, 0xffffffff, 0x00000100,
1355 0x3c200, 0xffffffff, 0x00000100,
1356 0x3c230, 0xffffffff, 0x00000100,
1357 0x3c234, 0xffffffff, 0x00000100,
1358 0x3c250, 0xffffffff, 0x00000100,
1359 0x3c254, 0xffffffff, 0x00000100,
1360 0x3c258, 0xffffffff, 0x00000100,
1361 0x3c25c, 0xffffffff, 0x00000100,
1362 0x3c260, 0xffffffff, 0x00000100,
1363 0x3c27c, 0xffffffff, 0x00000100,
1364 0x3c278, 0xffffffff, 0x00000100,
1365 0x3c210, 0xffffffff, 0x06000100,
1366 0x3c290, 0xffffffff, 0x00000100,
1367 0x3c274, 0xffffffff, 0x00000100,
1368 0x3c2b4, 0xffffffff, 0x00000100,
1369 0x3c2b0, 0xffffffff, 0x00000100,
1370 0x3c270, 0xffffffff, 0x00000100,
1371 0x30800, 0xffffffff, 0xe0000000,
1372 0x3c020, 0xffffffff, 0x00010000,
1373 0x3c024, 0xffffffff, 0x00030002,
1374 0x3c028, 0xffffffff, 0x00040007,
1375 0x3c02c, 0xffffffff, 0x00060005,
1376 0x3c030, 0xffffffff, 0x00090008,
1377 0x3c034, 0xffffffff, 0x00010000,
1378 0x3c038, 0xffffffff, 0x00030002,
1379 0x3c03c, 0xffffffff, 0x00040007,
1380 0x3c040, 0xffffffff, 0x00060005,
1381 0x3c044, 0xffffffff, 0x00090008,
1382 0x3c000, 0xffffffff, 0x96e00200,
1383 0x8708, 0xffffffff, 0x00900100,
1384 0xc424, 0xffffffff, 0x0020003f,
1385 0x38, 0xffffffff, 0x0140001c,
1386 0x3c, 0x000f0000, 0x000f0000,
1387 0x220, 0xffffffff, 0xC060000C,
1388 0x224, 0xc0000fff, 0x00000100,
1389 0x20a8, 0xffffffff, 0x00000104,
1390 0x55e4, 0xff000fff, 0x00000100,
1391 0x30cc, 0xc0000fff, 0x00000104,
1392 0xc1e4, 0x00000001, 0x00000001,
1393 0xd00c, 0xff000ff0, 0x00000100,
1394 0xd80c, 0xff000ff0, 0x00000100
1397 static const u32 hawaii_golden_spm_registers[] =
1399 0x30800, 0xe0ffffff, 0xe0000000
1402 static const u32 hawaii_golden_common_registers[] =
1404 0x30800, 0xffffffff, 0xe0000000,
1405 0x28350, 0xffffffff, 0x3a00161a,
1406 0x28354, 0xffffffff, 0x0000002e,
1407 0x9a10, 0xffffffff, 0x00018208,
1408 0x98f8, 0xffffffff, 0x12011003
1411 static const u32 hawaii_golden_registers[] =
1413 0x3354, 0x00000333, 0x00000333,
1414 0x9a10, 0x00010000, 0x00058208,
1415 0x9830, 0xffffffff, 0x00000000,
1416 0x9834, 0xf00fffff, 0x00000400,
1417 0x9838, 0x0002021c, 0x00020200,
1418 0xc78, 0x00000080, 0x00000000,
1419 0x5bb0, 0x000000f0, 0x00000070,
1420 0x5bc0, 0xf0311fff, 0x80300000,
1421 0x350c, 0x00810000, 0x408af000,
1422 0x7030, 0x31000111, 0x00000011,
1423 0x2f48, 0x73773777, 0x12010001,
1424 0x2120, 0x0000007f, 0x0000001b,
1425 0x21dc, 0x00007fb6, 0x00002191,
1426 0x3628, 0x0000003f, 0x0000000a,
1427 0x362c, 0x0000003f, 0x0000000a,
1428 0x2ae4, 0x00073ffe, 0x000022a2,
1429 0x240c, 0x000007ff, 0x00000000,
1430 0x8bf0, 0x00002001, 0x00000001,
1431 0x8b24, 0xffffffff, 0x00ffffff,
1432 0x30a04, 0x0000ff0f, 0x00000000,
1433 0x28a4c, 0x07ffffff, 0x06000000,
1434 0x3e78, 0x00000001, 0x00000002,
1435 0xc768, 0x00000008, 0x00000008,
1436 0xc770, 0x00000f00, 0x00000800,
1437 0xc774, 0x00000f00, 0x00000800,
1438 0xc798, 0x00ffffff, 0x00ff7fbf,
1439 0xc79c, 0x00ffffff, 0x00ff7faf,
1440 0x8c00, 0x000000ff, 0x00000800,
1441 0xe40, 0x00001fff, 0x00001fff,
1442 0x9060, 0x0000007f, 0x00000020,
1443 0x9508, 0x00010000, 0x00010000,
1444 0xae00, 0x00100000, 0x000ff07c,
1445 0xac14, 0x000003ff, 0x0000000f,
1446 0xac10, 0xffffffff, 0x7564fdec,
1447 0xac0c, 0xffffffff, 0x3120b9a8,
1448 0xac08, 0x20000000, 0x0f9c0000
1451 static const u32 hawaii_mgcg_cgcg_init[] =
1453 0xc420, 0xffffffff, 0xfffffffd,
1454 0x30800, 0xffffffff, 0xe0000000,
1455 0x3c2a0, 0xffffffff, 0x00000100,
1456 0x3c208, 0xffffffff, 0x00000100,
1457 0x3c2c0, 0xffffffff, 0x00000100,
1458 0x3c2c8, 0xffffffff, 0x00000100,
1459 0x3c2c4, 0xffffffff, 0x00000100,
1460 0x55e4, 0xffffffff, 0x00200100,
1461 0x3c280, 0xffffffff, 0x00000100,
1462 0x3c214, 0xffffffff, 0x06000100,
1463 0x3c220, 0xffffffff, 0x00000100,
1464 0x3c218, 0xffffffff, 0x06000100,
1465 0x3c204, 0xffffffff, 0x00000100,
1466 0x3c2e0, 0xffffffff, 0x00000100,
1467 0x3c224, 0xffffffff, 0x00000100,
1468 0x3c200, 0xffffffff, 0x00000100,
1469 0x3c230, 0xffffffff, 0x00000100,
1470 0x3c234, 0xffffffff, 0x00000100,
1471 0x3c250, 0xffffffff, 0x00000100,
1472 0x3c254, 0xffffffff, 0x00000100,
1473 0x3c258, 0xffffffff, 0x00000100,
1474 0x3c25c, 0xffffffff, 0x00000100,
1475 0x3c260, 0xffffffff, 0x00000100,
1476 0x3c27c, 0xffffffff, 0x00000100,
1477 0x3c278, 0xffffffff, 0x00000100,
1478 0x3c210, 0xffffffff, 0x06000100,
1479 0x3c290, 0xffffffff, 0x00000100,
1480 0x3c274, 0xffffffff, 0x00000100,
1481 0x3c2b4, 0xffffffff, 0x00000100,
1482 0x3c2b0, 0xffffffff, 0x00000100,
1483 0x3c270, 0xffffffff, 0x00000100,
1484 0x30800, 0xffffffff, 0xe0000000,
1485 0x3c020, 0xffffffff, 0x00010000,
1486 0x3c024, 0xffffffff, 0x00030002,
1487 0x3c028, 0xffffffff, 0x00040007,
1488 0x3c02c, 0xffffffff, 0x00060005,
1489 0x3c030, 0xffffffff, 0x00090008,
1490 0x3c034, 0xffffffff, 0x00010000,
1491 0x3c038, 0xffffffff, 0x00030002,
1492 0x3c03c, 0xffffffff, 0x00040007,
1493 0x3c040, 0xffffffff, 0x00060005,
1494 0x3c044, 0xffffffff, 0x00090008,
1495 0x3c048, 0xffffffff, 0x00010000,
1496 0x3c04c, 0xffffffff, 0x00030002,
1497 0x3c050, 0xffffffff, 0x00040007,
1498 0x3c054, 0xffffffff, 0x00060005,
1499 0x3c058, 0xffffffff, 0x00090008,
1500 0x3c05c, 0xffffffff, 0x00010000,
1501 0x3c060, 0xffffffff, 0x00030002,
1502 0x3c064, 0xffffffff, 0x00040007,
1503 0x3c068, 0xffffffff, 0x00060005,
1504 0x3c06c, 0xffffffff, 0x00090008,
1505 0x3c070, 0xffffffff, 0x00010000,
1506 0x3c074, 0xffffffff, 0x00030002,
1507 0x3c078, 0xffffffff, 0x00040007,
1508 0x3c07c, 0xffffffff, 0x00060005,
1509 0x3c080, 0xffffffff, 0x00090008,
1510 0x3c084, 0xffffffff, 0x00010000,
1511 0x3c088, 0xffffffff, 0x00030002,
1512 0x3c08c, 0xffffffff, 0x00040007,
1513 0x3c090, 0xffffffff, 0x00060005,
1514 0x3c094, 0xffffffff, 0x00090008,
1515 0x3c098, 0xffffffff, 0x00010000,
1516 0x3c09c, 0xffffffff, 0x00030002,
1517 0x3c0a0, 0xffffffff, 0x00040007,
1518 0x3c0a4, 0xffffffff, 0x00060005,
1519 0x3c0a8, 0xffffffff, 0x00090008,
1520 0x3c0ac, 0xffffffff, 0x00010000,
1521 0x3c0b0, 0xffffffff, 0x00030002,
1522 0x3c0b4, 0xffffffff, 0x00040007,
1523 0x3c0b8, 0xffffffff, 0x00060005,
1524 0x3c0bc, 0xffffffff, 0x00090008,
1525 0x3c0c0, 0xffffffff, 0x00010000,
1526 0x3c0c4, 0xffffffff, 0x00030002,
1527 0x3c0c8, 0xffffffff, 0x00040007,
1528 0x3c0cc, 0xffffffff, 0x00060005,
1529 0x3c0d0, 0xffffffff, 0x00090008,
1530 0x3c0d4, 0xffffffff, 0x00010000,
1531 0x3c0d8, 0xffffffff, 0x00030002,
1532 0x3c0dc, 0xffffffff, 0x00040007,
1533 0x3c0e0, 0xffffffff, 0x00060005,
1534 0x3c0e4, 0xffffffff, 0x00090008,
1535 0x3c0e8, 0xffffffff, 0x00010000,
1536 0x3c0ec, 0xffffffff, 0x00030002,
1537 0x3c0f0, 0xffffffff, 0x00040007,
1538 0x3c0f4, 0xffffffff, 0x00060005,
1539 0x3c0f8, 0xffffffff, 0x00090008,
1540 0xc318, 0xffffffff, 0x00020200,
1541 0x3350, 0xffffffff, 0x00000200,
1542 0x15c0, 0xffffffff, 0x00000400,
1543 0x55e8, 0xffffffff, 0x00000000,
1544 0x2f50, 0xffffffff, 0x00000902,
1545 0x3c000, 0xffffffff, 0x96940200,
1546 0x8708, 0xffffffff, 0x00900100,
1547 0xc424, 0xffffffff, 0x0020003f,
1548 0x38, 0xffffffff, 0x0140001c,
1549 0x3c, 0x000f0000, 0x000f0000,
1550 0x220, 0xffffffff, 0xc060000c,
1551 0x224, 0xc0000fff, 0x00000100,
1552 0xf90, 0xffffffff, 0x00000100,
1553 0xf98, 0x00000101, 0x00000000,
1554 0x20a8, 0xffffffff, 0x00000104,
1555 0x55e4, 0xff000fff, 0x00000100,
1556 0x30cc, 0xc0000fff, 0x00000104,
1557 0xc1e4, 0x00000001, 0x00000001,
1558 0xd00c, 0xff000ff0, 0x00000100,
1559 0xd80c, 0xff000ff0, 0x00000100
1562 static const u32 godavari_golden_registers[] =
1564 0x55e4, 0xff607fff, 0xfc000100,
1565 0x6ed8, 0x00010101, 0x00010000,
1566 0x9830, 0xffffffff, 0x00000000,
1567 0x98302, 0xf00fffff, 0x00000400,
1568 0x6130, 0xffffffff, 0x00010000,
1569 0x5bb0, 0x000000f0, 0x00000070,
1570 0x5bc0, 0xf0311fff, 0x80300000,
1571 0x98f8, 0x73773777, 0x12010001,
1572 0x98fc, 0xffffffff, 0x00000010,
1573 0x8030, 0x00001f0f, 0x0000100a,
1574 0x2f48, 0x73773777, 0x12010001,
1575 0x2408, 0x000fffff, 0x000c007f,
1576 0x8a14, 0xf000003f, 0x00000007,
1577 0x8b24, 0xffffffff, 0x00ff0fff,
1578 0x30a04, 0x0000ff0f, 0x00000000,
1579 0x28a4c, 0x07ffffff, 0x06000000,
1580 0x4d8, 0x00000fff, 0x00000100,
1581 0xd014, 0x00010000, 0x00810001,
1582 0xd814, 0x00010000, 0x00810001,
1583 0x3e78, 0x00000001, 0x00000002,
1584 0xc768, 0x00000008, 0x00000008,
1585 0xc770, 0x00000f00, 0x00000800,
1586 0xc774, 0x00000f00, 0x00000800,
1587 0xc798, 0x00ffffff, 0x00ff7fbf,
1588 0xc79c, 0x00ffffff, 0x00ff7faf,
1589 0x8c00, 0x000000ff, 0x00000001,
1590 0x214f8, 0x01ff01ff, 0x00000002,
1591 0x21498, 0x007ff800, 0x00200000,
1592 0x2015c, 0xffffffff, 0x00000f40,
1593 0x88c4, 0x001f3ae3, 0x00000082,
1594 0x88d4, 0x0000001f, 0x00000010,
1595 0x30934, 0xffffffff, 0x00000000
1599 static void cik_init_golden_registers(struct radeon_device *rdev)
1601 /* Some of the registers might be dependent on GRBM_GFX_INDEX */
1602 mutex_lock(&rdev->grbm_idx_mutex);
1603 switch (rdev->family) {
1605 radeon_program_register_sequence(rdev,
1606 bonaire_mgcg_cgcg_init,
1607 (const u32)ARRAY_SIZE(bonaire_mgcg_cgcg_init));
1608 radeon_program_register_sequence(rdev,
1609 bonaire_golden_registers,
1610 (const u32)ARRAY_SIZE(bonaire_golden_registers));
1611 radeon_program_register_sequence(rdev,
1612 bonaire_golden_common_registers,
1613 (const u32)ARRAY_SIZE(bonaire_golden_common_registers));
1614 radeon_program_register_sequence(rdev,
1615 bonaire_golden_spm_registers,
1616 (const u32)ARRAY_SIZE(bonaire_golden_spm_registers));
1619 radeon_program_register_sequence(rdev,
1620 kalindi_mgcg_cgcg_init,
1621 (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
1622 radeon_program_register_sequence(rdev,
1623 kalindi_golden_registers,
1624 (const u32)ARRAY_SIZE(kalindi_golden_registers));
1625 radeon_program_register_sequence(rdev,
1626 kalindi_golden_common_registers,
1627 (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
1628 radeon_program_register_sequence(rdev,
1629 kalindi_golden_spm_registers,
1630 (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
1633 radeon_program_register_sequence(rdev,
1634 kalindi_mgcg_cgcg_init,
1635 (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
1636 radeon_program_register_sequence(rdev,
1637 godavari_golden_registers,
1638 (const u32)ARRAY_SIZE(godavari_golden_registers));
1639 radeon_program_register_sequence(rdev,
1640 kalindi_golden_common_registers,
1641 (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
1642 radeon_program_register_sequence(rdev,
1643 kalindi_golden_spm_registers,
1644 (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
1647 radeon_program_register_sequence(rdev,
1648 spectre_mgcg_cgcg_init,
1649 (const u32)ARRAY_SIZE(spectre_mgcg_cgcg_init));
1650 radeon_program_register_sequence(rdev,
1651 spectre_golden_registers,
1652 (const u32)ARRAY_SIZE(spectre_golden_registers));
1653 radeon_program_register_sequence(rdev,
1654 spectre_golden_common_registers,
1655 (const u32)ARRAY_SIZE(spectre_golden_common_registers));
1656 radeon_program_register_sequence(rdev,
1657 spectre_golden_spm_registers,
1658 (const u32)ARRAY_SIZE(spectre_golden_spm_registers));
1661 radeon_program_register_sequence(rdev,
1662 hawaii_mgcg_cgcg_init,
1663 (const u32)ARRAY_SIZE(hawaii_mgcg_cgcg_init));
1664 radeon_program_register_sequence(rdev,
1665 hawaii_golden_registers,
1666 (const u32)ARRAY_SIZE(hawaii_golden_registers));
1667 radeon_program_register_sequence(rdev,
1668 hawaii_golden_common_registers,
1669 (const u32)ARRAY_SIZE(hawaii_golden_common_registers));
1670 radeon_program_register_sequence(rdev,
1671 hawaii_golden_spm_registers,
1672 (const u32)ARRAY_SIZE(hawaii_golden_spm_registers));
1677 mutex_unlock(&rdev->grbm_idx_mutex);
1681 * cik_get_xclk - get the xclk
1683 * @rdev: radeon_device pointer
1685 * Returns the reference clock used by the gfx engine
1688 u32 cik_get_xclk(struct radeon_device *rdev)
1690 u32 reference_clock = rdev->clock.spll.reference_freq;
1692 if (rdev->flags & RADEON_IS_IGP) {
1693 if (RREG32_SMC(GENERAL_PWRMGT) & GPU_COUNTER_CLK)
1694 return reference_clock / 2;
1696 if (RREG32_SMC(CG_CLKPIN_CNTL) & XTALIN_DIVIDE)
1697 return reference_clock / 4;
1699 return reference_clock;
1703 * cik_mm_rdoorbell - read a doorbell dword
1705 * @rdev: radeon_device pointer
1706 * @index: doorbell index
1708 * Returns the value in the doorbell aperture at the
1709 * requested doorbell index (CIK).
1711 u32 cik_mm_rdoorbell(struct radeon_device *rdev, u32 index)
1713 if (index < rdev->doorbell.num_doorbells) {
1714 return readl(rdev->doorbell.ptr + index);
1716 DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
1722 * cik_mm_wdoorbell - write a doorbell dword
1724 * @rdev: radeon_device pointer
1725 * @index: doorbell index
1726 * @v: value to write
1728 * Writes @v to the doorbell aperture at the
1729 * requested doorbell index (CIK).
1731 void cik_mm_wdoorbell(struct radeon_device *rdev, u32 index, u32 v)
1733 if (index < rdev->doorbell.num_doorbells) {
1734 writel(v, rdev->doorbell.ptr + index);
1736 DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
1740 #define BONAIRE_IO_MC_REGS_SIZE 36
1742 static const u32 bonaire_io_mc_regs[BONAIRE_IO_MC_REGS_SIZE][2] =
1744 {0x00000070, 0x04400000},
1745 {0x00000071, 0x80c01803},
1746 {0x00000072, 0x00004004},
1747 {0x00000073, 0x00000100},
1748 {0x00000074, 0x00ff0000},
1749 {0x00000075, 0x34000000},
1750 {0x00000076, 0x08000014},
1751 {0x00000077, 0x00cc08ec},
1752 {0x00000078, 0x00000400},
1753 {0x00000079, 0x00000000},
1754 {0x0000007a, 0x04090000},
1755 {0x0000007c, 0x00000000},
1756 {0x0000007e, 0x4408a8e8},
1757 {0x0000007f, 0x00000304},
1758 {0x00000080, 0x00000000},
1759 {0x00000082, 0x00000001},
1760 {0x00000083, 0x00000002},
1761 {0x00000084, 0xf3e4f400},
1762 {0x00000085, 0x052024e3},
1763 {0x00000087, 0x00000000},
1764 {0x00000088, 0x01000000},
1765 {0x0000008a, 0x1c0a0000},
1766 {0x0000008b, 0xff010000},
1767 {0x0000008d, 0xffffefff},
1768 {0x0000008e, 0xfff3efff},
1769 {0x0000008f, 0xfff3efbf},
1770 {0x00000092, 0xf7ffffff},
1771 {0x00000093, 0xffffff7f},
1772 {0x00000095, 0x00101101},
1773 {0x00000096, 0x00000fff},
1774 {0x00000097, 0x00116fff},
1775 {0x00000098, 0x60010000},
1776 {0x00000099, 0x10010000},
1777 {0x0000009a, 0x00006000},
1778 {0x0000009b, 0x00001000},
1779 {0x0000009f, 0x00b48000}
1782 #define HAWAII_IO_MC_REGS_SIZE 22
1784 static const u32 hawaii_io_mc_regs[HAWAII_IO_MC_REGS_SIZE][2] =
1786 {0x0000007d, 0x40000000},
1787 {0x0000007e, 0x40180304},
1788 {0x0000007f, 0x0000ff00},
1789 {0x00000081, 0x00000000},
1790 {0x00000083, 0x00000800},
1791 {0x00000086, 0x00000000},
1792 {0x00000087, 0x00000100},
1793 {0x00000088, 0x00020100},
1794 {0x00000089, 0x00000000},
1795 {0x0000008b, 0x00040000},
1796 {0x0000008c, 0x00000100},
1797 {0x0000008e, 0xff010000},
1798 {0x00000090, 0xffffefff},
1799 {0x00000091, 0xfff3efff},
1800 {0x00000092, 0xfff3efbf},
1801 {0x00000093, 0xf7ffffff},
1802 {0x00000094, 0xffffff7f},
1803 {0x00000095, 0x00000fff},
1804 {0x00000096, 0x00116fff},
1805 {0x00000097, 0x60010000},
1806 {0x00000098, 0x10010000},
1807 {0x0000009f, 0x00c79000}
1812 * cik_srbm_select - select specific register instances
1814 * @rdev: radeon_device pointer
1815 * @me: selected ME (micro engine)
1820 * Switches the currently active registers instances. Some
1821 * registers are instanced per VMID, others are instanced per
1822 * me/pipe/queue combination.
1824 static void cik_srbm_select(struct radeon_device *rdev,
1825 u32 me, u32 pipe, u32 queue, u32 vmid)
1827 u32 srbm_gfx_cntl = (PIPEID(pipe & 0x3) |
1830 QUEUEID(queue & 0x7));
1831 WREG32(SRBM_GFX_CNTL, srbm_gfx_cntl);
1836 * ci_mc_load_microcode - load MC ucode into the hw
1838 * @rdev: radeon_device pointer
1840 * Load the GDDR MC ucode into the hw (CIK).
1841 * Returns 0 on success, error on failure.
1843 int ci_mc_load_microcode(struct radeon_device *rdev)
1845 const __be32 *fw_data = NULL;
1846 const __le32 *new_fw_data = NULL;
1847 u32 running, blackout = 0, tmp;
1848 u32 *io_mc_regs = NULL;
1849 const __le32 *new_io_mc_regs = NULL;
1850 int i, regs_size, ucode_size;
1856 const struct mc_firmware_header_v1_0 *hdr =
1857 (const struct mc_firmware_header_v1_0 *)rdev->mc_fw->data;
1859 radeon_ucode_print_mc_hdr(&hdr->header);
1861 regs_size = le32_to_cpu(hdr->io_debug_size_bytes) / (4 * 2);
1862 new_io_mc_regs = (const __le32 *)
1863 (rdev->mc_fw->data + le32_to_cpu(hdr->io_debug_array_offset_bytes));
1864 ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
1865 new_fw_data = (const __le32 *)
1866 (rdev->mc_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
1868 ucode_size = rdev->mc_fw->size / 4;
1870 switch (rdev->family) {
1872 io_mc_regs = (u32 *)&bonaire_io_mc_regs;
1873 regs_size = BONAIRE_IO_MC_REGS_SIZE;
1876 io_mc_regs = (u32 *)&hawaii_io_mc_regs;
1877 regs_size = HAWAII_IO_MC_REGS_SIZE;
1882 fw_data = (const __be32 *)rdev->mc_fw->data;
1885 running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
1889 blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
1890 WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
1893 /* reset the engine and set to writable */
1894 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
1895 WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
1897 /* load mc io regs */
1898 for (i = 0; i < regs_size; i++) {
1900 WREG32(MC_SEQ_IO_DEBUG_INDEX, le32_to_cpup(new_io_mc_regs++));
1901 WREG32(MC_SEQ_IO_DEBUG_DATA, le32_to_cpup(new_io_mc_regs++));
1903 WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
1904 WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
1908 tmp = RREG32(MC_SEQ_MISC0);
1909 if ((rdev->pdev->device == 0x6649) && ((tmp & 0xff00) == 0x5600)) {
1910 WREG32(MC_SEQ_IO_DEBUG_INDEX, 5);
1911 WREG32(MC_SEQ_IO_DEBUG_DATA, 0x00000023);
1912 WREG32(MC_SEQ_IO_DEBUG_INDEX, 9);
1913 WREG32(MC_SEQ_IO_DEBUG_DATA, 0x000001f0);
1916 /* load the MC ucode */
1917 for (i = 0; i < ucode_size; i++) {
1919 WREG32(MC_SEQ_SUP_PGM, le32_to_cpup(new_fw_data++));
1921 WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
1924 /* put the engine back into the active state */
1925 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
1926 WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
1927 WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
1929 /* wait for training to complete */
1930 for (i = 0; i < rdev->usec_timeout; i++) {
1931 if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D0)
1935 for (i = 0; i < rdev->usec_timeout; i++) {
1936 if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D1)
1942 WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
1949 * cik_init_microcode - load ucode images from disk
1951 * @rdev: radeon_device pointer
1953 * Use the firmware interface to load the ucode images into
1954 * the driver (not loaded into hw).
1955 * Returns 0 on success, error on failure.
1957 static int cik_init_microcode(struct radeon_device *rdev)
1959 const char *chip_name;
1960 const char *new_chip_name;
1961 size_t pfp_req_size, me_req_size, ce_req_size,
1962 mec_req_size, rlc_req_size, mc_req_size = 0,
1963 sdma_req_size, smc_req_size = 0, mc2_req_size = 0;
1971 switch (rdev->family) {
1973 chip_name = "BONAIRE";
1974 new_chip_name = "bonaire";
1975 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
1976 me_req_size = CIK_ME_UCODE_SIZE * 4;
1977 ce_req_size = CIK_CE_UCODE_SIZE * 4;
1978 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
1979 rlc_req_size = BONAIRE_RLC_UCODE_SIZE * 4;
1980 mc_req_size = BONAIRE_MC_UCODE_SIZE * 4;
1981 mc2_req_size = BONAIRE_MC2_UCODE_SIZE * 4;
1982 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
1983 smc_req_size = ALIGN(BONAIRE_SMC_UCODE_SIZE, 4);
1987 chip_name = "HAWAII";
1988 new_chip_name = "hawaii";
1989 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
1990 me_req_size = CIK_ME_UCODE_SIZE * 4;
1991 ce_req_size = CIK_CE_UCODE_SIZE * 4;
1992 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
1993 rlc_req_size = BONAIRE_RLC_UCODE_SIZE * 4;
1994 mc_req_size = HAWAII_MC_UCODE_SIZE * 4;
1995 mc2_req_size = HAWAII_MC2_UCODE_SIZE * 4;
1996 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
1997 smc_req_size = ALIGN(HAWAII_SMC_UCODE_SIZE, 4);
2001 chip_name = "KAVERI";
2002 new_chip_name = "kaveri";
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 = KV_RLC_UCODE_SIZE * 4;
2008 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
2012 chip_name = "KABINI";
2013 new_chip_name = "kabini";
2014 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
2015 me_req_size = CIK_ME_UCODE_SIZE * 4;
2016 ce_req_size = CIK_CE_UCODE_SIZE * 4;
2017 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
2018 rlc_req_size = KB_RLC_UCODE_SIZE * 4;
2019 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
2023 chip_name = "MULLINS";
2024 new_chip_name = "mullins";
2025 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
2026 me_req_size = CIK_ME_UCODE_SIZE * 4;
2027 ce_req_size = CIK_CE_UCODE_SIZE * 4;
2028 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
2029 rlc_req_size = ML_RLC_UCODE_SIZE * 4;
2030 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
2036 DRM_INFO("Loading %s Microcode\n", new_chip_name);
2038 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", new_chip_name);
2039 err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
2041 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
2042 err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
2045 if (rdev->pfp_fw->size != pfp_req_size) {
2047 "cik_cp: Bogus length %zu in firmware \"%s\"\n",
2048 rdev->pfp_fw->size, fw_name);
2053 err = radeon_ucode_validate(rdev->pfp_fw);
2056 "cik_fw: validation failed for firmware \"%s\"\n",
2064 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", new_chip_name);
2065 err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
2067 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
2068 err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
2071 if (rdev->me_fw->size != me_req_size) {
2073 "cik_cp: Bogus length %zu in firmware \"%s\"\n",
2074 rdev->me_fw->size, fw_name);
2078 err = radeon_ucode_validate(rdev->me_fw);
2081 "cik_fw: validation failed for firmware \"%s\"\n",
2089 snprintf(fw_name, sizeof(fw_name), "radeon/%s_ce.bin", new_chip_name);
2090 err = request_firmware(&rdev->ce_fw, fw_name, rdev->dev);
2092 snprintf(fw_name, sizeof(fw_name), "radeon/%s_ce.bin", chip_name);
2093 err = request_firmware(&rdev->ce_fw, fw_name, rdev->dev);
2096 if (rdev->ce_fw->size != ce_req_size) {
2098 "cik_cp: Bogus length %zu in firmware \"%s\"\n",
2099 rdev->ce_fw->size, fw_name);
2103 err = radeon_ucode_validate(rdev->ce_fw);
2106 "cik_fw: validation failed for firmware \"%s\"\n",
2114 snprintf(fw_name, sizeof(fw_name), "radeon/%s_mec.bin", new_chip_name);
2115 err = request_firmware(&rdev->mec_fw, fw_name, rdev->dev);
2117 snprintf(fw_name, sizeof(fw_name), "radeon/%s_mec.bin", chip_name);
2118 err = request_firmware(&rdev->mec_fw, fw_name, rdev->dev);
2121 if (rdev->mec_fw->size != mec_req_size) {
2123 "cik_cp: Bogus length %zu in firmware \"%s\"\n",
2124 rdev->mec_fw->size, fw_name);
2128 err = radeon_ucode_validate(rdev->mec_fw);
2131 "cik_fw: validation failed for firmware \"%s\"\n",
2139 if (rdev->family == CHIP_KAVERI) {
2140 snprintf(fw_name, sizeof(fw_name), "radeon/%s_mec2.bin", new_chip_name);
2141 err = request_firmware(&rdev->mec2_fw, fw_name, rdev->dev);
2145 err = radeon_ucode_validate(rdev->mec2_fw);
2154 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", new_chip_name);
2155 err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
2157 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", chip_name);
2158 err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
2161 if (rdev->rlc_fw->size != rlc_req_size) {
2163 "cik_rlc: Bogus length %zu in firmware \"%s\"\n",
2164 rdev->rlc_fw->size, fw_name);
2168 err = radeon_ucode_validate(rdev->rlc_fw);
2171 "cik_fw: validation failed for firmware \"%s\"\n",
2179 snprintf(fw_name, sizeof(fw_name), "radeon/%s_sdma.bin", new_chip_name);
2180 err = request_firmware(&rdev->sdma_fw, fw_name, rdev->dev);
2182 snprintf(fw_name, sizeof(fw_name), "radeon/%s_sdma.bin", chip_name);
2183 err = request_firmware(&rdev->sdma_fw, fw_name, rdev->dev);
2186 if (rdev->sdma_fw->size != sdma_req_size) {
2188 "cik_sdma: Bogus length %zu in firmware \"%s\"\n",
2189 rdev->sdma_fw->size, fw_name);
2193 err = radeon_ucode_validate(rdev->sdma_fw);
2196 "cik_fw: validation failed for firmware \"%s\"\n",
2204 /* No SMC, MC ucode on APUs */
2205 if (!(rdev->flags & RADEON_IS_IGP)) {
2206 snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", new_chip_name);
2207 err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
2209 snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc2.bin", chip_name);
2210 err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
2212 snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
2213 err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
2217 if ((rdev->mc_fw->size != mc_req_size) &&
2218 (rdev->mc_fw->size != mc2_req_size)){
2220 "cik_mc: Bogus length %zu in firmware \"%s\"\n",
2221 rdev->mc_fw->size, fw_name);
2224 DRM_INFO("%s: %zu bytes\n", fw_name, rdev->mc_fw->size);
2226 err = radeon_ucode_validate(rdev->mc_fw);
2229 "cik_fw: validation failed for firmware \"%s\"\n",
2237 snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", new_chip_name);
2238 err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
2240 snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", chip_name);
2241 err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
2244 "smc: error loading firmware \"%s\"\n",
2246 release_firmware(rdev->smc_fw);
2247 rdev->smc_fw = NULL;
2249 } else if (rdev->smc_fw->size != smc_req_size) {
2251 "cik_smc: Bogus length %zu in firmware \"%s\"\n",
2252 rdev->smc_fw->size, fw_name);
2256 err = radeon_ucode_validate(rdev->smc_fw);
2259 "cik_fw: validation failed for firmware \"%s\"\n",
2269 rdev->new_fw = false;
2270 } else if (new_fw < num_fw) {
2271 printk(KERN_ERR "ci_fw: mixing new and old firmware!\n");
2274 rdev->new_fw = true;
2281 "cik_cp: Failed to load firmware \"%s\"\n",
2283 release_firmware(rdev->pfp_fw);
2284 rdev->pfp_fw = NULL;
2285 release_firmware(rdev->me_fw);
2287 release_firmware(rdev->ce_fw);
2289 release_firmware(rdev->mec_fw);
2290 rdev->mec_fw = NULL;
2291 release_firmware(rdev->mec2_fw);
2292 rdev->mec2_fw = NULL;
2293 release_firmware(rdev->rlc_fw);
2294 rdev->rlc_fw = NULL;
2295 release_firmware(rdev->sdma_fw);
2296 rdev->sdma_fw = NULL;
2297 release_firmware(rdev->mc_fw);
2299 release_firmware(rdev->smc_fw);
2300 rdev->smc_fw = NULL;
2309 * cik_tiling_mode_table_init - init the hw tiling table
2311 * @rdev: radeon_device pointer
2313 * Starting with SI, the tiling setup is done globally in a
2314 * set of 32 tiling modes. Rather than selecting each set of
2315 * parameters per surface as on older asics, we just select
2316 * which index in the tiling table we want to use, and the
2317 * surface uses those parameters (CIK).
2319 static void cik_tiling_mode_table_init(struct radeon_device *rdev)
2321 const u32 num_tile_mode_states = 32;
2322 const u32 num_secondary_tile_mode_states = 16;
2323 u32 reg_offset, gb_tile_moden, split_equal_to_row_size;
2324 u32 num_pipe_configs;
2325 u32 num_rbs = rdev->config.cik.max_backends_per_se *
2326 rdev->config.cik.max_shader_engines;
2328 switch (rdev->config.cik.mem_row_size_in_kb) {
2330 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_1KB;
2334 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_2KB;
2337 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_4KB;
2341 num_pipe_configs = rdev->config.cik.max_tile_pipes;
2342 if (num_pipe_configs > 8)
2343 num_pipe_configs = 16;
2345 if (num_pipe_configs == 16) {
2346 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
2347 switch (reg_offset) {
2349 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2350 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2351 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2352 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
2355 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2356 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2357 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2358 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
2361 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2362 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2363 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2364 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2367 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2368 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2369 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2370 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
2373 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2374 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2375 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2376 TILE_SPLIT(split_equal_to_row_size));
2379 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2380 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2381 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2384 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2385 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2386 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2387 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2390 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2391 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2392 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2393 TILE_SPLIT(split_equal_to_row_size));
2396 gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2397 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16));
2400 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2401 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2402 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
2405 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2406 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2407 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2408 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2411 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2412 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2413 PIPE_CONFIG(ADDR_SURF_P16_32x32_8x16) |
2414 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2417 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2418 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2419 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2420 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2423 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2424 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2425 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
2428 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2429 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2430 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2431 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2434 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2435 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2436 PIPE_CONFIG(ADDR_SURF_P16_32x32_8x16) |
2437 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2440 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2441 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2442 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2443 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2446 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2447 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2448 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
2451 gb_tile_moden = (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));
2457 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2458 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2459 PIPE_CONFIG(ADDR_SURF_P16_32x32_8x16) |
2460 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2463 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2464 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2465 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2466 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2472 rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
2473 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2475 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
2476 switch (reg_offset) {
2478 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2479 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2480 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2481 NUM_BANKS(ADDR_SURF_16_BANK));
2484 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2485 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2486 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2487 NUM_BANKS(ADDR_SURF_16_BANK));
2490 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2491 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2492 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2493 NUM_BANKS(ADDR_SURF_16_BANK));
2496 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2497 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2498 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2499 NUM_BANKS(ADDR_SURF_16_BANK));
2502 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2503 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2504 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2505 NUM_BANKS(ADDR_SURF_8_BANK));
2508 gb_tile_moden = (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));
2514 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2515 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2516 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2517 NUM_BANKS(ADDR_SURF_2_BANK));
2520 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2521 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2522 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2523 NUM_BANKS(ADDR_SURF_16_BANK));
2526 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2527 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2528 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2529 NUM_BANKS(ADDR_SURF_16_BANK));
2532 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2533 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2534 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2535 NUM_BANKS(ADDR_SURF_16_BANK));
2538 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2539 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2540 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2541 NUM_BANKS(ADDR_SURF_8_BANK));
2544 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2545 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2546 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2547 NUM_BANKS(ADDR_SURF_4_BANK));
2550 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2551 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2552 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2553 NUM_BANKS(ADDR_SURF_2_BANK));
2556 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2557 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2558 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2559 NUM_BANKS(ADDR_SURF_2_BANK));
2565 rdev->config.cik.macrotile_mode_array[reg_offset] = gb_tile_moden;
2566 WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2568 } else if (num_pipe_configs == 8) {
2569 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
2570 switch (reg_offset) {
2572 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2573 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2574 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2575 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
2578 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2579 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2580 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2581 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
2584 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2585 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2586 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2587 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2590 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2591 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2592 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2593 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
2596 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2597 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2598 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2599 TILE_SPLIT(split_equal_to_row_size));
2602 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2603 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2604 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2607 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2608 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2609 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2610 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2613 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2614 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2615 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2616 TILE_SPLIT(split_equal_to_row_size));
2619 gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2620 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16));
2623 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2624 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2625 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
2628 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2629 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2630 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2631 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2634 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2635 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2636 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2637 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2640 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2641 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2642 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2643 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2646 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2647 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2648 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
2651 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2652 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2653 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2654 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2657 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2658 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2659 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2660 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2663 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2664 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2665 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2666 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2669 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2670 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2671 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
2674 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2675 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2676 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2677 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2680 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2681 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2682 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2683 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2686 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2687 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2688 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2689 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2695 rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
2696 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2698 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
2699 switch (reg_offset) {
2701 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2702 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2703 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2704 NUM_BANKS(ADDR_SURF_16_BANK));
2707 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2708 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2709 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2710 NUM_BANKS(ADDR_SURF_16_BANK));
2713 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2714 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2715 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2716 NUM_BANKS(ADDR_SURF_16_BANK));
2719 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2720 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2721 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2722 NUM_BANKS(ADDR_SURF_16_BANK));
2725 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2726 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2727 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2728 NUM_BANKS(ADDR_SURF_8_BANK));
2731 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2732 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2733 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2734 NUM_BANKS(ADDR_SURF_4_BANK));
2737 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2738 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2739 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2740 NUM_BANKS(ADDR_SURF_2_BANK));
2743 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2744 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2745 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2746 NUM_BANKS(ADDR_SURF_16_BANK));
2749 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2750 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2751 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2752 NUM_BANKS(ADDR_SURF_16_BANK));
2755 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2756 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2757 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2758 NUM_BANKS(ADDR_SURF_16_BANK));
2761 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2762 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2763 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2764 NUM_BANKS(ADDR_SURF_16_BANK));
2767 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2768 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2769 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2770 NUM_BANKS(ADDR_SURF_8_BANK));
2773 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2774 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2775 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2776 NUM_BANKS(ADDR_SURF_4_BANK));
2779 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2780 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2781 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2782 NUM_BANKS(ADDR_SURF_2_BANK));
2788 rdev->config.cik.macrotile_mode_array[reg_offset] = gb_tile_moden;
2789 WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2791 } else if (num_pipe_configs == 4) {
2793 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
2794 switch (reg_offset) {
2796 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2797 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2798 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2799 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
2802 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2803 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2804 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2805 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
2808 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2809 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2810 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2811 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2814 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2815 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2816 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2817 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
2820 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2821 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2822 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2823 TILE_SPLIT(split_equal_to_row_size));
2826 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2827 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2828 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2831 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2832 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2833 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2834 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2837 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2838 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2839 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2840 TILE_SPLIT(split_equal_to_row_size));
2843 gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2844 PIPE_CONFIG(ADDR_SURF_P4_16x16));
2847 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2848 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2849 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
2852 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2853 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2854 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2855 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2858 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2859 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2860 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2861 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2864 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2865 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2866 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2867 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2870 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2871 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2872 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
2875 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2876 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2877 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2878 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2881 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2882 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2883 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2884 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2887 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2888 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2889 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2890 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2893 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2894 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2895 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
2898 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2899 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2900 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2901 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2904 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2905 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2906 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2907 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2910 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2911 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2912 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2913 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2919 rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
2920 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2922 } else if (num_rbs < 4) {
2923 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
2924 switch (reg_offset) {
2926 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2927 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2928 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2929 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
2932 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2933 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2934 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2935 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
2938 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2939 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2940 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2941 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2944 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2945 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2946 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2947 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
2950 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2951 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2952 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2953 TILE_SPLIT(split_equal_to_row_size));
2956 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2957 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2958 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2961 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2962 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2963 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2964 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2967 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2968 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2969 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2970 TILE_SPLIT(split_equal_to_row_size));
2973 gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2974 PIPE_CONFIG(ADDR_SURF_P4_8x16));
2977 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2978 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2979 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
2982 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2983 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2984 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2985 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2988 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2989 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2990 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2991 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2994 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2995 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2996 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2997 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3000 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3001 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
3002 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
3005 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3006 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3007 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
3008 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3011 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3012 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3013 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
3014 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3017 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
3018 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3019 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
3020 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3023 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3024 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
3025 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
3028 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
3029 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3030 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
3031 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3034 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3035 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3036 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
3037 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3040 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
3041 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3042 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
3043 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3049 rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
3050 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
3053 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
3054 switch (reg_offset) {
3056 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3057 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3058 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3059 NUM_BANKS(ADDR_SURF_16_BANK));
3062 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3063 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3064 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3065 NUM_BANKS(ADDR_SURF_16_BANK));
3068 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3069 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3070 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3071 NUM_BANKS(ADDR_SURF_16_BANK));
3074 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3075 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3076 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3077 NUM_BANKS(ADDR_SURF_16_BANK));
3080 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3081 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3082 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3083 NUM_BANKS(ADDR_SURF_16_BANK));
3086 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3087 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3088 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3089 NUM_BANKS(ADDR_SURF_8_BANK));
3092 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3093 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3094 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
3095 NUM_BANKS(ADDR_SURF_4_BANK));
3098 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3099 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
3100 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3101 NUM_BANKS(ADDR_SURF_16_BANK));
3104 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3105 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3106 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3107 NUM_BANKS(ADDR_SURF_16_BANK));
3110 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3111 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3112 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3113 NUM_BANKS(ADDR_SURF_16_BANK));
3116 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3117 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3118 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3119 NUM_BANKS(ADDR_SURF_16_BANK));
3122 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3123 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3124 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3125 NUM_BANKS(ADDR_SURF_16_BANK));
3128 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3129 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3130 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3131 NUM_BANKS(ADDR_SURF_8_BANK));
3134 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3135 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3136 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
3137 NUM_BANKS(ADDR_SURF_4_BANK));
3143 rdev->config.cik.macrotile_mode_array[reg_offset] = gb_tile_moden;
3144 WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
3146 } else if (num_pipe_configs == 2) {
3147 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
3148 switch (reg_offset) {
3150 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3151 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
3152 PIPE_CONFIG(ADDR_SURF_P2) |
3153 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
3156 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3157 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
3158 PIPE_CONFIG(ADDR_SURF_P2) |
3159 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
3162 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3163 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
3164 PIPE_CONFIG(ADDR_SURF_P2) |
3165 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
3168 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3169 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
3170 PIPE_CONFIG(ADDR_SURF_P2) |
3171 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
3174 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3175 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
3176 PIPE_CONFIG(ADDR_SURF_P2) |
3177 TILE_SPLIT(split_equal_to_row_size));
3180 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3181 PIPE_CONFIG(ADDR_SURF_P2) |
3182 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3185 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
3186 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
3187 PIPE_CONFIG(ADDR_SURF_P2) |
3188 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
3191 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
3192 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
3193 PIPE_CONFIG(ADDR_SURF_P2) |
3194 TILE_SPLIT(split_equal_to_row_size));
3197 gb_tile_moden = ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
3198 PIPE_CONFIG(ADDR_SURF_P2);
3201 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3202 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3203 PIPE_CONFIG(ADDR_SURF_P2));
3206 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3207 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3208 PIPE_CONFIG(ADDR_SURF_P2) |
3209 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3212 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3213 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3214 PIPE_CONFIG(ADDR_SURF_P2) |
3215 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3218 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
3219 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3220 PIPE_CONFIG(ADDR_SURF_P2) |
3221 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3224 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3225 PIPE_CONFIG(ADDR_SURF_P2) |
3226 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
3229 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3230 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3231 PIPE_CONFIG(ADDR_SURF_P2) |
3232 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3235 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3236 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3237 PIPE_CONFIG(ADDR_SURF_P2) |
3238 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3241 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
3242 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3243 PIPE_CONFIG(ADDR_SURF_P2) |
3244 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3247 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3248 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3249 PIPE_CONFIG(ADDR_SURF_P2));
3252 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
3253 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3254 PIPE_CONFIG(ADDR_SURF_P2) |
3255 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3258 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3259 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3260 PIPE_CONFIG(ADDR_SURF_P2) |
3261 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3264 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
3265 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3266 PIPE_CONFIG(ADDR_SURF_P2) |
3267 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3273 rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
3274 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
3276 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
3277 switch (reg_offset) {
3279 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3280 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3281 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3282 NUM_BANKS(ADDR_SURF_16_BANK));
3285 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3286 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3287 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3288 NUM_BANKS(ADDR_SURF_16_BANK));
3291 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3292 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3293 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3294 NUM_BANKS(ADDR_SURF_16_BANK));
3297 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3298 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3299 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3300 NUM_BANKS(ADDR_SURF_16_BANK));
3303 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3304 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3305 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3306 NUM_BANKS(ADDR_SURF_16_BANK));
3309 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3310 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3311 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3312 NUM_BANKS(ADDR_SURF_16_BANK));
3315 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3316 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3317 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3318 NUM_BANKS(ADDR_SURF_8_BANK));
3321 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3322 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
3323 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3324 NUM_BANKS(ADDR_SURF_16_BANK));
3327 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3328 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3329 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3330 NUM_BANKS(ADDR_SURF_16_BANK));
3333 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3334 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3335 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3336 NUM_BANKS(ADDR_SURF_16_BANK));
3339 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3340 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3341 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3342 NUM_BANKS(ADDR_SURF_16_BANK));
3345 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3346 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3347 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3348 NUM_BANKS(ADDR_SURF_16_BANK));
3351 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3352 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3353 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3354 NUM_BANKS(ADDR_SURF_16_BANK));
3357 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3358 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3359 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3360 NUM_BANKS(ADDR_SURF_8_BANK));
3366 rdev->config.cik.macrotile_mode_array[reg_offset] = gb_tile_moden;
3367 WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
3370 DRM_ERROR("unknown num pipe config: 0x%x\n", num_pipe_configs);
3374 * cik_select_se_sh - select which SE, SH to address
3376 * @rdev: radeon_device pointer
3377 * @se_num: shader engine to address
3378 * @sh_num: sh block to address
3380 * Select which SE, SH combinations to address. Certain
3381 * registers are instanced per SE or SH. 0xffffffff means
3382 * broadcast to all SEs or SHs (CIK).
3384 static void cik_select_se_sh(struct radeon_device *rdev,
3385 u32 se_num, u32 sh_num)
3387 u32 data = INSTANCE_BROADCAST_WRITES;
3389 if ((se_num == 0xffffffff) && (sh_num == 0xffffffff))
3390 data |= SH_BROADCAST_WRITES | SE_BROADCAST_WRITES;
3391 else if (se_num == 0xffffffff)
3392 data |= SE_BROADCAST_WRITES | SH_INDEX(sh_num);
3393 else if (sh_num == 0xffffffff)
3394 data |= SH_BROADCAST_WRITES | SE_INDEX(se_num);
3396 data |= SH_INDEX(sh_num) | SE_INDEX(se_num);
3397 WREG32(GRBM_GFX_INDEX, data);
3401 * cik_create_bitmask - create a bitmask
3403 * @bit_width: length of the mask
3405 * create a variable length bit mask (CIK).
3406 * Returns the bitmask.
3408 static u32 cik_create_bitmask(u32 bit_width)
3412 for (i = 0; i < bit_width; i++) {
3420 * cik_get_rb_disabled - computes the mask of disabled RBs
3422 * @rdev: radeon_device pointer
3423 * @max_rb_num: max RBs (render backends) for the asic
3424 * @se_num: number of SEs (shader engines) for the asic
3425 * @sh_per_se: number of SH blocks per SE for the asic
3427 * Calculates the bitmask of disabled RBs (CIK).
3428 * Returns the disabled RB bitmask.
3430 static u32 cik_get_rb_disabled(struct radeon_device *rdev,
3431 u32 max_rb_num_per_se,
3436 data = RREG32(CC_RB_BACKEND_DISABLE);
3438 data &= BACKEND_DISABLE_MASK;
3441 data |= RREG32(GC_USER_RB_BACKEND_DISABLE);
3443 data >>= BACKEND_DISABLE_SHIFT;
3445 mask = cik_create_bitmask(max_rb_num_per_se / sh_per_se);
3451 * cik_setup_rb - setup the RBs on the asic
3453 * @rdev: radeon_device pointer
3454 * @se_num: number of SEs (shader engines) for the asic
3455 * @sh_per_se: number of SH blocks per SE for the asic
3456 * @max_rb_num: max RBs (render backends) for the asic
3458 * Configures per-SE/SH RB registers (CIK).
3460 static void cik_setup_rb(struct radeon_device *rdev,
3461 u32 se_num, u32 sh_per_se,
3462 u32 max_rb_num_per_se)
3466 u32 disabled_rbs = 0;
3467 u32 enabled_rbs = 0;
3469 mutex_lock(&rdev->grbm_idx_mutex);
3470 for (i = 0; i < se_num; i++) {
3471 for (j = 0; j < sh_per_se; j++) {
3472 cik_select_se_sh(rdev, i, j);
3473 data = cik_get_rb_disabled(rdev, max_rb_num_per_se, sh_per_se);
3474 if (rdev->family == CHIP_HAWAII)
3475 disabled_rbs |= data << ((i * sh_per_se + j) * HAWAII_RB_BITMAP_WIDTH_PER_SH);
3477 disabled_rbs |= data << ((i * sh_per_se + j) * CIK_RB_BITMAP_WIDTH_PER_SH);
3480 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
3481 mutex_unlock(&rdev->grbm_idx_mutex);
3484 for (i = 0; i < max_rb_num_per_se * se_num; i++) {
3485 if (!(disabled_rbs & mask))
3486 enabled_rbs |= mask;
3490 rdev->config.cik.backend_enable_mask = enabled_rbs;
3492 mutex_lock(&rdev->grbm_idx_mutex);
3493 for (i = 0; i < se_num; i++) {
3494 cik_select_se_sh(rdev, i, 0xffffffff);
3496 for (j = 0; j < sh_per_se; j++) {
3497 switch (enabled_rbs & 3) {
3500 data |= PKR_MAP(RASTER_CONFIG_RB_MAP_3);
3502 data |= PKR_MAP(RASTER_CONFIG_RB_MAP_0);
3505 data |= (RASTER_CONFIG_RB_MAP_0 << (i * sh_per_se + j) * 2);
3508 data |= (RASTER_CONFIG_RB_MAP_3 << (i * sh_per_se + j) * 2);
3512 data |= (RASTER_CONFIG_RB_MAP_2 << (i * sh_per_se + j) * 2);
3517 WREG32(PA_SC_RASTER_CONFIG, data);
3519 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
3520 mutex_unlock(&rdev->grbm_idx_mutex);
3524 * cik_gpu_init - setup the 3D engine
3526 * @rdev: radeon_device pointer
3528 * Configures the 3D engine and tiling configuration
3529 * registers so that the 3D engine is usable.
3531 static void cik_gpu_init(struct radeon_device *rdev)
3533 u32 gb_addr_config = RREG32(GB_ADDR_CONFIG);
3534 u32 mc_shared_chmap, mc_arb_ramcfg;
3535 u32 hdp_host_path_cntl;
3539 switch (rdev->family) {
3541 rdev->config.cik.max_shader_engines = 2;
3542 rdev->config.cik.max_tile_pipes = 4;
3543 rdev->config.cik.max_cu_per_sh = 7;
3544 rdev->config.cik.max_sh_per_se = 1;
3545 rdev->config.cik.max_backends_per_se = 2;
3546 rdev->config.cik.max_texture_channel_caches = 4;
3547 rdev->config.cik.max_gprs = 256;
3548 rdev->config.cik.max_gs_threads = 32;
3549 rdev->config.cik.max_hw_contexts = 8;
3551 rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
3552 rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
3553 rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
3554 rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
3555 gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
3558 rdev->config.cik.max_shader_engines = 4;
3559 rdev->config.cik.max_tile_pipes = 16;
3560 rdev->config.cik.max_cu_per_sh = 11;
3561 rdev->config.cik.max_sh_per_se = 1;
3562 rdev->config.cik.max_backends_per_se = 4;
3563 rdev->config.cik.max_texture_channel_caches = 16;
3564 rdev->config.cik.max_gprs = 256;
3565 rdev->config.cik.max_gs_threads = 32;
3566 rdev->config.cik.max_hw_contexts = 8;
3568 rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
3569 rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
3570 rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
3571 rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
3572 gb_addr_config = HAWAII_GB_ADDR_CONFIG_GOLDEN;
3575 rdev->config.cik.max_shader_engines = 1;
3576 rdev->config.cik.max_tile_pipes = 4;
3577 if ((rdev->pdev->device == 0x1304) ||
3578 (rdev->pdev->device == 0x1305) ||
3579 (rdev->pdev->device == 0x130C) ||
3580 (rdev->pdev->device == 0x130F) ||
3581 (rdev->pdev->device == 0x1310) ||
3582 (rdev->pdev->device == 0x1311) ||
3583 (rdev->pdev->device == 0x131C)) {
3584 rdev->config.cik.max_cu_per_sh = 8;
3585 rdev->config.cik.max_backends_per_se = 2;
3586 } else if ((rdev->pdev->device == 0x1309) ||
3587 (rdev->pdev->device == 0x130A) ||
3588 (rdev->pdev->device == 0x130D) ||
3589 (rdev->pdev->device == 0x1313) ||
3590 (rdev->pdev->device == 0x131D)) {
3591 rdev->config.cik.max_cu_per_sh = 6;
3592 rdev->config.cik.max_backends_per_se = 2;
3593 } else if ((rdev->pdev->device == 0x1306) ||
3594 (rdev->pdev->device == 0x1307) ||
3595 (rdev->pdev->device == 0x130B) ||
3596 (rdev->pdev->device == 0x130E) ||
3597 (rdev->pdev->device == 0x1315) ||
3598 (rdev->pdev->device == 0x1318) ||
3599 (rdev->pdev->device == 0x131B)) {
3600 rdev->config.cik.max_cu_per_sh = 4;
3601 rdev->config.cik.max_backends_per_se = 1;
3603 rdev->config.cik.max_cu_per_sh = 3;
3604 rdev->config.cik.max_backends_per_se = 1;
3606 rdev->config.cik.max_sh_per_se = 1;
3607 rdev->config.cik.max_texture_channel_caches = 4;
3608 rdev->config.cik.max_gprs = 256;
3609 rdev->config.cik.max_gs_threads = 16;
3610 rdev->config.cik.max_hw_contexts = 8;
3612 rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
3613 rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
3614 rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
3615 rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
3616 gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
3621 rdev->config.cik.max_shader_engines = 1;
3622 rdev->config.cik.max_tile_pipes = 2;
3623 rdev->config.cik.max_cu_per_sh = 2;
3624 rdev->config.cik.max_sh_per_se = 1;
3625 rdev->config.cik.max_backends_per_se = 1;
3626 rdev->config.cik.max_texture_channel_caches = 2;
3627 rdev->config.cik.max_gprs = 256;
3628 rdev->config.cik.max_gs_threads = 16;
3629 rdev->config.cik.max_hw_contexts = 8;
3631 rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
3632 rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
3633 rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
3634 rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
3635 gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
3639 /* Initialize HDP */
3640 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
3641 WREG32((0x2c14 + j), 0x00000000);
3642 WREG32((0x2c18 + j), 0x00000000);
3643 WREG32((0x2c1c + j), 0x00000000);
3644 WREG32((0x2c20 + j), 0x00000000);
3645 WREG32((0x2c24 + j), 0x00000000);
3648 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
3649 WREG32(SRBM_INT_CNTL, 0x1);
3650 WREG32(SRBM_INT_ACK, 0x1);
3652 WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
3654 mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
3655 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
3657 rdev->config.cik.num_tile_pipes = rdev->config.cik.max_tile_pipes;
3658 rdev->config.cik.mem_max_burst_length_bytes = 256;
3659 tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
3660 rdev->config.cik.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
3661 if (rdev->config.cik.mem_row_size_in_kb > 4)
3662 rdev->config.cik.mem_row_size_in_kb = 4;
3663 /* XXX use MC settings? */
3664 rdev->config.cik.shader_engine_tile_size = 32;
3665 rdev->config.cik.num_gpus = 1;
3666 rdev->config.cik.multi_gpu_tile_size = 64;
3668 /* fix up row size */
3669 gb_addr_config &= ~ROW_SIZE_MASK;
3670 switch (rdev->config.cik.mem_row_size_in_kb) {
3673 gb_addr_config |= ROW_SIZE(0);
3676 gb_addr_config |= ROW_SIZE(1);
3679 gb_addr_config |= ROW_SIZE(2);
3683 /* setup tiling info dword. gb_addr_config is not adequate since it does
3684 * not have bank info, so create a custom tiling dword.
3685 * bits 3:0 num_pipes
3686 * bits 7:4 num_banks
3687 * bits 11:8 group_size
3688 * bits 15:12 row_size
3690 rdev->config.cik.tile_config = 0;
3691 switch (rdev->config.cik.num_tile_pipes) {
3693 rdev->config.cik.tile_config |= (0 << 0);
3696 rdev->config.cik.tile_config |= (1 << 0);
3699 rdev->config.cik.tile_config |= (2 << 0);
3703 /* XXX what about 12? */
3704 rdev->config.cik.tile_config |= (3 << 0);
3707 rdev->config.cik.tile_config |=
3708 ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) << 4;
3709 rdev->config.cik.tile_config |=
3710 ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
3711 rdev->config.cik.tile_config |=
3712 ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
3714 WREG32(GB_ADDR_CONFIG, gb_addr_config);
3715 WREG32(HDP_ADDR_CONFIG, gb_addr_config);
3716 WREG32(DMIF_ADDR_CALC, gb_addr_config);
3717 WREG32(SDMA0_TILING_CONFIG + SDMA0_REGISTER_OFFSET, gb_addr_config & 0x70);
3718 WREG32(SDMA0_TILING_CONFIG + SDMA1_REGISTER_OFFSET, gb_addr_config & 0x70);
3719 WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
3720 WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
3721 WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
3723 cik_tiling_mode_table_init(rdev);
3725 cik_setup_rb(rdev, rdev->config.cik.max_shader_engines,
3726 rdev->config.cik.max_sh_per_se,
3727 rdev->config.cik.max_backends_per_se);
3729 rdev->config.cik.active_cus = 0;
3730 for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
3731 for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
3732 rdev->config.cik.active_cus +=
3733 hweight32(cik_get_cu_active_bitmap(rdev, i, j));
3737 /* set HW defaults for 3D engine */
3738 WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
3740 mutex_lock(&rdev->grbm_idx_mutex);
3742 * making sure that the following register writes will be broadcasted
3743 * to all the shaders
3745 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
3746 WREG32(SX_DEBUG_1, 0x20);
3748 WREG32(TA_CNTL_AUX, 0x00010000);
3750 tmp = RREG32(SPI_CONFIG_CNTL);
3752 WREG32(SPI_CONFIG_CNTL, tmp);
3754 WREG32(SQ_CONFIG, 1);
3756 WREG32(DB_DEBUG, 0);
3758 tmp = RREG32(DB_DEBUG2) & ~0xf00fffff;
3760 WREG32(DB_DEBUG2, tmp);
3762 tmp = RREG32(DB_DEBUG3) & ~0x0002021c;
3764 WREG32(DB_DEBUG3, tmp);
3766 tmp = RREG32(CB_HW_CONTROL) & ~0x00010000;
3768 WREG32(CB_HW_CONTROL, tmp);
3770 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
3772 WREG32(PA_SC_FIFO_SIZE, (SC_FRONTEND_PRIM_FIFO_SIZE(rdev->config.cik.sc_prim_fifo_size_frontend) |
3773 SC_BACKEND_PRIM_FIFO_SIZE(rdev->config.cik.sc_prim_fifo_size_backend) |
3774 SC_HIZ_TILE_FIFO_SIZE(rdev->config.cik.sc_hiz_tile_fifo_size) |
3775 SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.cik.sc_earlyz_tile_fifo_size)));
3777 WREG32(VGT_NUM_INSTANCES, 1);
3779 WREG32(CP_PERFMON_CNTL, 0);
3781 WREG32(SQ_CONFIG, 0);
3783 WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
3784 FORCE_EOV_MAX_REZ_CNT(255)));
3786 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
3787 AUTO_INVLD_EN(ES_AND_GS_AUTO));
3789 WREG32(VGT_GS_VERTEX_REUSE, 16);
3790 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
3792 tmp = RREG32(HDP_MISC_CNTL);
3793 tmp |= HDP_FLUSH_INVALIDATE_CACHE;
3794 WREG32(HDP_MISC_CNTL, tmp);
3796 hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
3797 WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
3799 WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
3800 WREG32(PA_SC_ENHANCE, ENABLE_PA_SC_OUT_OF_ORDER);
3801 mutex_unlock(&rdev->grbm_idx_mutex);
3807 * GPU scratch registers helpers function.
3810 * cik_scratch_init - setup driver info for CP scratch regs
3812 * @rdev: radeon_device pointer
3814 * Set up the number and offset of the CP scratch registers.
3815 * NOTE: use of CP scratch registers is a legacy inferface and
3816 * is not used by default on newer asics (r6xx+). On newer asics,
3817 * memory buffers are used for fences rather than scratch regs.
3819 static void cik_scratch_init(struct radeon_device *rdev)
3823 rdev->scratch.num_reg = 7;
3824 rdev->scratch.reg_base = SCRATCH_REG0;
3825 for (i = 0; i < rdev->scratch.num_reg; i++) {
3826 rdev->scratch.free[i] = true;
3827 rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
3832 * cik_ring_test - basic gfx ring test
3834 * @rdev: radeon_device pointer
3835 * @ring: radeon_ring structure holding ring information
3837 * Allocate a scratch register and write to it using the gfx ring (CIK).
3838 * Provides a basic gfx ring test to verify that the ring is working.
3839 * Used by cik_cp_gfx_resume();
3840 * Returns 0 on success, error on failure.
3842 int cik_ring_test(struct radeon_device *rdev, struct radeon_ring *ring)
3849 r = radeon_scratch_get(rdev, &scratch);
3851 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
3854 WREG32(scratch, 0xCAFEDEAD);
3855 r = radeon_ring_lock(rdev, ring, 3);
3857 DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ring->idx, r);
3858 radeon_scratch_free(rdev, scratch);
3861 radeon_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
3862 radeon_ring_write(ring, ((scratch - PACKET3_SET_UCONFIG_REG_START) >> 2));
3863 radeon_ring_write(ring, 0xDEADBEEF);
3864 radeon_ring_unlock_commit(rdev, ring, false);
3866 for (i = 0; i < rdev->usec_timeout; i++) {
3867 tmp = RREG32(scratch);
3868 if (tmp == 0xDEADBEEF)
3872 if (i < rdev->usec_timeout) {
3873 DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
3875 DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
3876 ring->idx, scratch, tmp);
3879 radeon_scratch_free(rdev, scratch);
3884 * cik_hdp_flush_cp_ring_emit - emit an hdp flush on the cp
3886 * @rdev: radeon_device pointer
3887 * @ridx: radeon ring index
3889 * Emits an hdp flush on the cp.
3891 static void cik_hdp_flush_cp_ring_emit(struct radeon_device *rdev,
3894 struct radeon_ring *ring = &rdev->ring[ridx];
3897 switch (ring->idx) {
3898 case CAYMAN_RING_TYPE_CP1_INDEX:
3899 case CAYMAN_RING_TYPE_CP2_INDEX:
3903 ref_and_mask = CP2 << ring->pipe;
3906 ref_and_mask = CP6 << ring->pipe;
3912 case RADEON_RING_TYPE_GFX_INDEX:
3917 radeon_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
3918 radeon_ring_write(ring, (WAIT_REG_MEM_OPERATION(1) | /* write, wait, write */
3919 WAIT_REG_MEM_FUNCTION(3) | /* == */
3920 WAIT_REG_MEM_ENGINE(1))); /* pfp */
3921 radeon_ring_write(ring, GPU_HDP_FLUSH_REQ >> 2);
3922 radeon_ring_write(ring, GPU_HDP_FLUSH_DONE >> 2);
3923 radeon_ring_write(ring, ref_and_mask);
3924 radeon_ring_write(ring, ref_and_mask);
3925 radeon_ring_write(ring, 0x20); /* poll interval */
3929 * cik_fence_gfx_ring_emit - emit a fence on the gfx ring
3931 * @rdev: radeon_device pointer
3932 * @fence: radeon fence object
3934 * Emits a fence sequnce number on the gfx ring and flushes
3937 void cik_fence_gfx_ring_emit(struct radeon_device *rdev,
3938 struct radeon_fence *fence)
3940 struct radeon_ring *ring = &rdev->ring[fence->ring];
3941 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
3943 /* Workaround for cache flush problems. First send a dummy EOP
3944 * event down the pipe with seq one below.
3946 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
3947 radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
3949 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
3951 radeon_ring_write(ring, addr & 0xfffffffc);
3952 radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) |
3953 DATA_SEL(1) | INT_SEL(0));
3954 radeon_ring_write(ring, fence->seq - 1);
3955 radeon_ring_write(ring, 0);
3957 /* Then send the real EOP event down the pipe. */
3958 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
3959 radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
3961 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
3963 radeon_ring_write(ring, addr & 0xfffffffc);
3964 radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) | DATA_SEL(1) | INT_SEL(2));
3965 radeon_ring_write(ring, fence->seq);
3966 radeon_ring_write(ring, 0);
3970 * cik_fence_compute_ring_emit - emit a fence on the compute ring
3972 * @rdev: radeon_device pointer
3973 * @fence: radeon fence object
3975 * Emits a fence sequnce number on the compute ring and flushes
3978 void cik_fence_compute_ring_emit(struct radeon_device *rdev,
3979 struct radeon_fence *fence)
3981 struct radeon_ring *ring = &rdev->ring[fence->ring];
3982 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
3984 /* RELEASE_MEM - flush caches, send int */
3985 radeon_ring_write(ring, PACKET3(PACKET3_RELEASE_MEM, 5));
3986 radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
3988 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
3990 radeon_ring_write(ring, DATA_SEL(1) | INT_SEL(2));
3991 radeon_ring_write(ring, addr & 0xfffffffc);
3992 radeon_ring_write(ring, upper_32_bits(addr));
3993 radeon_ring_write(ring, fence->seq);
3994 radeon_ring_write(ring, 0);
3998 * cik_semaphore_ring_emit - emit a semaphore on the CP ring
4000 * @rdev: radeon_device pointer
4001 * @ring: radeon ring buffer object
4002 * @semaphore: radeon semaphore object
4003 * @emit_wait: Is this a sempahore wait?
4005 * Emits a semaphore signal/wait packet to the CP ring and prevents the PFP
4006 * from running ahead of semaphore waits.
4008 bool cik_semaphore_ring_emit(struct radeon_device *rdev,
4009 struct radeon_ring *ring,
4010 struct radeon_semaphore *semaphore,
4013 uint64_t addr = semaphore->gpu_addr;
4014 unsigned sel = emit_wait ? PACKET3_SEM_SEL_WAIT : PACKET3_SEM_SEL_SIGNAL;
4016 radeon_ring_write(ring, PACKET3(PACKET3_MEM_SEMAPHORE, 1));
4017 radeon_ring_write(ring, lower_32_bits(addr));
4018 radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) | sel);
4020 if (emit_wait && ring->idx == RADEON_RING_TYPE_GFX_INDEX) {
4021 /* Prevent the PFP from running ahead of the semaphore wait */
4022 radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
4023 radeon_ring_write(ring, 0x0);
4030 * cik_copy_cpdma - copy pages using the CP DMA engine
4032 * @rdev: radeon_device pointer
4033 * @src_offset: src GPU address
4034 * @dst_offset: dst GPU address
4035 * @num_gpu_pages: number of GPU pages to xfer
4036 * @resv: reservation object to sync to
4038 * Copy GPU paging using the CP DMA engine (CIK+).
4039 * Used by the radeon ttm implementation to move pages if
4040 * registered as the asic copy callback.
4042 struct radeon_fence *cik_copy_cpdma(struct radeon_device *rdev,
4043 uint64_t src_offset, uint64_t dst_offset,
4044 unsigned num_gpu_pages,
4045 struct reservation_object *resv)
4047 struct radeon_fence *fence;
4048 struct radeon_sync sync;
4049 int ring_index = rdev->asic->copy.blit_ring_index;
4050 struct radeon_ring *ring = &rdev->ring[ring_index];
4051 u32 size_in_bytes, cur_size_in_bytes, control;
4055 radeon_sync_create(&sync);
4057 size_in_bytes = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT);
4058 num_loops = DIV_ROUND_UP(size_in_bytes, 0x1fffff);
4059 r = radeon_ring_lock(rdev, ring, num_loops * 7 + 18);
4061 DRM_ERROR("radeon: moving bo (%d).\n", r);
4062 radeon_sync_free(rdev, &sync, NULL);
4066 radeon_sync_resv(rdev, &sync, resv, false);
4067 radeon_sync_rings(rdev, &sync, ring->idx);
4069 for (i = 0; i < num_loops; i++) {
4070 cur_size_in_bytes = size_in_bytes;
4071 if (cur_size_in_bytes > 0x1fffff)
4072 cur_size_in_bytes = 0x1fffff;
4073 size_in_bytes -= cur_size_in_bytes;
4075 if (size_in_bytes == 0)
4076 control |= PACKET3_DMA_DATA_CP_SYNC;
4077 radeon_ring_write(ring, PACKET3(PACKET3_DMA_DATA, 5));
4078 radeon_ring_write(ring, control);
4079 radeon_ring_write(ring, lower_32_bits(src_offset));
4080 radeon_ring_write(ring, upper_32_bits(src_offset));
4081 radeon_ring_write(ring, lower_32_bits(dst_offset));
4082 radeon_ring_write(ring, upper_32_bits(dst_offset));
4083 radeon_ring_write(ring, cur_size_in_bytes);
4084 src_offset += cur_size_in_bytes;
4085 dst_offset += cur_size_in_bytes;
4088 r = radeon_fence_emit(rdev, &fence, ring->idx);
4090 radeon_ring_unlock_undo(rdev, ring);
4091 radeon_sync_free(rdev, &sync, NULL);
4095 radeon_ring_unlock_commit(rdev, ring, false);
4096 radeon_sync_free(rdev, &sync, fence);
4105 * cik_ring_ib_execute - emit an IB (Indirect Buffer) on the gfx ring
4107 * @rdev: radeon_device pointer
4108 * @ib: radeon indirect buffer object
4110 * Emits an DE (drawing engine) or CE (constant engine) IB
4111 * on the gfx ring. IBs are usually generated by userspace
4112 * acceleration drivers and submitted to the kernel for
4113 * sheduling on the ring. This function schedules the IB
4114 * on the gfx ring for execution by the GPU.
4116 void cik_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
4118 struct radeon_ring *ring = &rdev->ring[ib->ring];
4119 unsigned vm_id = ib->vm ? ib->vm->ids[ib->ring].id : 0;
4120 u32 header, control = INDIRECT_BUFFER_VALID;
4122 if (ib->is_const_ib) {
4123 /* set switch buffer packet before const IB */
4124 radeon_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
4125 radeon_ring_write(ring, 0);
4127 header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
4130 if (ring->rptr_save_reg) {
4131 next_rptr = ring->wptr + 3 + 4;
4132 radeon_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
4133 radeon_ring_write(ring, ((ring->rptr_save_reg -
4134 PACKET3_SET_UCONFIG_REG_START) >> 2));
4135 radeon_ring_write(ring, next_rptr);
4136 } else if (rdev->wb.enabled) {
4137 next_rptr = ring->wptr + 5 + 4;
4138 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
4139 radeon_ring_write(ring, WRITE_DATA_DST_SEL(1));
4140 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
4141 radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr));
4142 radeon_ring_write(ring, next_rptr);
4145 header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
4148 control |= ib->length_dw | (vm_id << 24);
4150 radeon_ring_write(ring, header);
4151 radeon_ring_write(ring,
4155 (ib->gpu_addr & 0xFFFFFFFC));
4156 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
4157 radeon_ring_write(ring, control);
4161 * cik_ib_test - basic gfx ring IB test
4163 * @rdev: radeon_device pointer
4164 * @ring: radeon_ring structure holding ring information
4166 * Allocate an IB and execute it on the gfx ring (CIK).
4167 * Provides a basic gfx ring test to verify that IBs are working.
4168 * Returns 0 on success, error on failure.
4170 int cik_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
4172 struct radeon_ib ib;
4178 r = radeon_scratch_get(rdev, &scratch);
4180 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
4183 WREG32(scratch, 0xCAFEDEAD);
4184 r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
4186 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
4187 radeon_scratch_free(rdev, scratch);
4190 ib.ptr[0] = PACKET3(PACKET3_SET_UCONFIG_REG, 1);
4191 ib.ptr[1] = ((scratch - PACKET3_SET_UCONFIG_REG_START) >> 2);
4192 ib.ptr[2] = 0xDEADBEEF;
4194 r = radeon_ib_schedule(rdev, &ib, NULL, false);
4196 radeon_scratch_free(rdev, scratch);
4197 radeon_ib_free(rdev, &ib);
4198 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
4201 r = radeon_fence_wait(ib.fence, false);
4203 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
4204 radeon_scratch_free(rdev, scratch);
4205 radeon_ib_free(rdev, &ib);
4208 for (i = 0; i < rdev->usec_timeout; i++) {
4209 tmp = RREG32(scratch);
4210 if (tmp == 0xDEADBEEF)
4214 if (i < rdev->usec_timeout) {
4215 DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
4217 DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
4221 radeon_scratch_free(rdev, scratch);
4222 radeon_ib_free(rdev, &ib);
4228 * On CIK, gfx and compute now have independant command processors.
4231 * Gfx consists of a single ring and can process both gfx jobs and
4232 * compute jobs. The gfx CP consists of three microengines (ME):
4233 * PFP - Pre-Fetch Parser
4235 * CE - Constant Engine
4236 * The PFP and ME make up what is considered the Drawing Engine (DE).
4237 * The CE is an asynchronous engine used for updating buffer desciptors
4238 * used by the DE so that they can be loaded into cache in parallel
4239 * while the DE is processing state update packets.
4242 * The compute CP consists of two microengines (ME):
4243 * MEC1 - Compute MicroEngine 1
4244 * MEC2 - Compute MicroEngine 2
4245 * Each MEC supports 4 compute pipes and each pipe supports 8 queues.
4246 * The queues are exposed to userspace and are programmed directly
4247 * by the compute runtime.
4250 * cik_cp_gfx_enable - enable/disable the gfx CP MEs
4252 * @rdev: radeon_device pointer
4253 * @enable: enable or disable the MEs
4255 * Halts or unhalts the gfx MEs.
4257 static void cik_cp_gfx_enable(struct radeon_device *rdev, bool enable)
4260 WREG32(CP_ME_CNTL, 0);
4262 if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
4263 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
4264 WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT));
4265 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
4271 * cik_cp_gfx_load_microcode - load the gfx CP ME ucode
4273 * @rdev: radeon_device pointer
4275 * Loads the gfx PFP, ME, and CE ucode.
4276 * Returns 0 for success, -EINVAL if the ucode is not available.
4278 static int cik_cp_gfx_load_microcode(struct radeon_device *rdev)
4282 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw)
4285 cik_cp_gfx_enable(rdev, false);
4288 const struct gfx_firmware_header_v1_0 *pfp_hdr =
4289 (const struct gfx_firmware_header_v1_0 *)rdev->pfp_fw->data;
4290 const struct gfx_firmware_header_v1_0 *ce_hdr =
4291 (const struct gfx_firmware_header_v1_0 *)rdev->ce_fw->data;
4292 const struct gfx_firmware_header_v1_0 *me_hdr =
4293 (const struct gfx_firmware_header_v1_0 *)rdev->me_fw->data;
4294 const __le32 *fw_data;
4297 radeon_ucode_print_gfx_hdr(&pfp_hdr->header);
4298 radeon_ucode_print_gfx_hdr(&ce_hdr->header);
4299 radeon_ucode_print_gfx_hdr(&me_hdr->header);
4302 fw_data = (const __le32 *)
4303 (rdev->pfp_fw->data + le32_to_cpu(pfp_hdr->header.ucode_array_offset_bytes));
4304 fw_size = le32_to_cpu(pfp_hdr->header.ucode_size_bytes) / 4;
4305 WREG32(CP_PFP_UCODE_ADDR, 0);
4306 for (i = 0; i < fw_size; i++)
4307 WREG32(CP_PFP_UCODE_DATA, le32_to_cpup(fw_data++));
4308 WREG32(CP_PFP_UCODE_ADDR, le32_to_cpu(pfp_hdr->header.ucode_version));
4311 fw_data = (const __le32 *)
4312 (rdev->ce_fw->data + le32_to_cpu(ce_hdr->header.ucode_array_offset_bytes));
4313 fw_size = le32_to_cpu(ce_hdr->header.ucode_size_bytes) / 4;
4314 WREG32(CP_CE_UCODE_ADDR, 0);
4315 for (i = 0; i < fw_size; i++)
4316 WREG32(CP_CE_UCODE_DATA, le32_to_cpup(fw_data++));
4317 WREG32(CP_CE_UCODE_ADDR, le32_to_cpu(ce_hdr->header.ucode_version));
4320 fw_data = (const __be32 *)
4321 (rdev->me_fw->data + le32_to_cpu(me_hdr->header.ucode_array_offset_bytes));
4322 fw_size = le32_to_cpu(me_hdr->header.ucode_size_bytes) / 4;
4323 WREG32(CP_ME_RAM_WADDR, 0);
4324 for (i = 0; i < fw_size; i++)
4325 WREG32(CP_ME_RAM_DATA, le32_to_cpup(fw_data++));
4326 WREG32(CP_ME_RAM_WADDR, le32_to_cpu(me_hdr->header.ucode_version));
4327 WREG32(CP_ME_RAM_RADDR, le32_to_cpu(me_hdr->header.ucode_version));
4329 const __be32 *fw_data;
4332 fw_data = (const __be32 *)rdev->pfp_fw->data;
4333 WREG32(CP_PFP_UCODE_ADDR, 0);
4334 for (i = 0; i < CIK_PFP_UCODE_SIZE; i++)
4335 WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
4336 WREG32(CP_PFP_UCODE_ADDR, 0);
4339 fw_data = (const __be32 *)rdev->ce_fw->data;
4340 WREG32(CP_CE_UCODE_ADDR, 0);
4341 for (i = 0; i < CIK_CE_UCODE_SIZE; i++)
4342 WREG32(CP_CE_UCODE_DATA, be32_to_cpup(fw_data++));
4343 WREG32(CP_CE_UCODE_ADDR, 0);
4346 fw_data = (const __be32 *)rdev->me_fw->data;
4347 WREG32(CP_ME_RAM_WADDR, 0);
4348 for (i = 0; i < CIK_ME_UCODE_SIZE; i++)
4349 WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
4350 WREG32(CP_ME_RAM_WADDR, 0);
4357 * cik_cp_gfx_start - start the gfx ring
4359 * @rdev: radeon_device pointer
4361 * Enables the ring and loads the clear state context and other
4362 * packets required to init the ring.
4363 * Returns 0 for success, error for failure.
4365 static int cik_cp_gfx_start(struct radeon_device *rdev)
4367 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
4371 WREG32(CP_MAX_CONTEXT, rdev->config.cik.max_hw_contexts - 1);
4372 WREG32(CP_ENDIAN_SWAP, 0);
4373 WREG32(CP_DEVICE_ID, 1);
4375 cik_cp_gfx_enable(rdev, true);
4377 r = radeon_ring_lock(rdev, ring, cik_default_size + 17);
4379 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
4383 /* init the CE partitions. CE only used for gfx on CIK */
4384 radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
4385 radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
4386 radeon_ring_write(ring, 0x8000);
4387 radeon_ring_write(ring, 0x8000);
4389 /* setup clear context state */
4390 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
4391 radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
4393 radeon_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
4394 radeon_ring_write(ring, 0x80000000);
4395 radeon_ring_write(ring, 0x80000000);
4397 for (i = 0; i < cik_default_size; i++)
4398 radeon_ring_write(ring, cik_default_state[i]);
4400 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
4401 radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
4403 /* set clear context state */
4404 radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
4405 radeon_ring_write(ring, 0);
4407 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
4408 radeon_ring_write(ring, 0x00000316);
4409 radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
4410 radeon_ring_write(ring, 0x00000010); /* VGT_OUT_DEALLOC_CNTL */
4412 radeon_ring_unlock_commit(rdev, ring, false);
4418 * cik_cp_gfx_fini - stop the gfx ring
4420 * @rdev: radeon_device pointer
4422 * Stop the gfx ring and tear down the driver ring
4425 static void cik_cp_gfx_fini(struct radeon_device *rdev)
4427 cik_cp_gfx_enable(rdev, false);
4428 radeon_ring_fini(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
4432 * cik_cp_gfx_resume - setup the gfx ring buffer registers
4434 * @rdev: radeon_device pointer
4436 * Program the location and size of the gfx ring buffer
4437 * and test it to make sure it's working.
4438 * Returns 0 for success, error for failure.
4440 static int cik_cp_gfx_resume(struct radeon_device *rdev)
4442 struct radeon_ring *ring;
4448 WREG32(CP_SEM_WAIT_TIMER, 0x0);
4449 if (rdev->family != CHIP_HAWAII)
4450 WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
4452 /* Set the write pointer delay */
4453 WREG32(CP_RB_WPTR_DELAY, 0);
4455 /* set the RB to use vmid 0 */
4456 WREG32(CP_RB_VMID, 0);
4458 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
4460 /* ring 0 - compute and gfx */
4461 /* Set ring buffer size */
4462 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
4463 rb_bufsz = order_base_2(ring->ring_size / 8);
4464 tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
4466 tmp |= BUF_SWAP_32BIT;
4468 WREG32(CP_RB0_CNTL, tmp);
4470 /* Initialize the ring buffer's read and write pointers */
4471 WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA);
4473 WREG32(CP_RB0_WPTR, ring->wptr);
4475 /* set the wb address wether it's enabled or not */
4476 WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
4477 WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
4479 /* scratch register shadowing is no longer supported */
4480 WREG32(SCRATCH_UMSK, 0);
4482 if (!rdev->wb.enabled)
4483 tmp |= RB_NO_UPDATE;
4486 WREG32(CP_RB0_CNTL, tmp);
4488 rb_addr = ring->gpu_addr >> 8;
4489 WREG32(CP_RB0_BASE, rb_addr);
4490 WREG32(CP_RB0_BASE_HI, upper_32_bits(rb_addr));
4492 /* start the ring */
4493 cik_cp_gfx_start(rdev);
4494 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
4495 r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
4497 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
4501 if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
4502 radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
4507 u32 cik_gfx_get_rptr(struct radeon_device *rdev,
4508 struct radeon_ring *ring)
4512 if (rdev->wb.enabled)
4513 rptr = rdev->wb.wb[ring->rptr_offs/4];
4515 rptr = RREG32(CP_RB0_RPTR);
4520 u32 cik_gfx_get_wptr(struct radeon_device *rdev,
4521 struct radeon_ring *ring)
4525 wptr = RREG32(CP_RB0_WPTR);
4530 void cik_gfx_set_wptr(struct radeon_device *rdev,
4531 struct radeon_ring *ring)
4533 WREG32(CP_RB0_WPTR, ring->wptr);
4534 (void)RREG32(CP_RB0_WPTR);
4537 u32 cik_compute_get_rptr(struct radeon_device *rdev,
4538 struct radeon_ring *ring)
4542 if (rdev->wb.enabled) {
4543 rptr = rdev->wb.wb[ring->rptr_offs/4];
4545 mutex_lock(&rdev->srbm_mutex);
4546 cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
4547 rptr = RREG32(CP_HQD_PQ_RPTR);
4548 cik_srbm_select(rdev, 0, 0, 0, 0);
4549 mutex_unlock(&rdev->srbm_mutex);
4555 u32 cik_compute_get_wptr(struct radeon_device *rdev,
4556 struct radeon_ring *ring)
4560 if (rdev->wb.enabled) {
4561 /* XXX check if swapping is necessary on BE */
4562 wptr = rdev->wb.wb[ring->wptr_offs/4];
4564 mutex_lock(&rdev->srbm_mutex);
4565 cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
4566 wptr = RREG32(CP_HQD_PQ_WPTR);
4567 cik_srbm_select(rdev, 0, 0, 0, 0);
4568 mutex_unlock(&rdev->srbm_mutex);
4574 void cik_compute_set_wptr(struct radeon_device *rdev,
4575 struct radeon_ring *ring)
4577 /* XXX check if swapping is necessary on BE */
4578 rdev->wb.wb[ring->wptr_offs/4] = ring->wptr;
4579 WDOORBELL32(ring->doorbell_index, ring->wptr);
4582 static void cik_compute_stop(struct radeon_device *rdev,
4583 struct radeon_ring *ring)
4587 cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
4588 /* Disable wptr polling. */
4589 tmp = RREG32(CP_PQ_WPTR_POLL_CNTL);
4590 tmp &= ~WPTR_POLL_EN;
4591 WREG32(CP_PQ_WPTR_POLL_CNTL, tmp);
4593 if (RREG32(CP_HQD_ACTIVE) & 1) {
4594 WREG32(CP_HQD_DEQUEUE_REQUEST, 1);
4595 for (j = 0; j < rdev->usec_timeout; j++) {
4596 if (!(RREG32(CP_HQD_ACTIVE) & 1))
4600 WREG32(CP_HQD_DEQUEUE_REQUEST, 0);
4601 WREG32(CP_HQD_PQ_RPTR, 0);
4602 WREG32(CP_HQD_PQ_WPTR, 0);
4604 cik_srbm_select(rdev, 0, 0, 0, 0);
4608 * cik_cp_compute_enable - enable/disable the compute CP MEs
4610 * @rdev: radeon_device pointer
4611 * @enable: enable or disable the MEs
4613 * Halts or unhalts the compute MEs.
4615 static void cik_cp_compute_enable(struct radeon_device *rdev, bool enable)
4618 WREG32(CP_MEC_CNTL, 0);
4621 * To make hibernation reliable we need to clear compute ring
4622 * configuration before halting the compute ring.
4624 mutex_lock(&rdev->srbm_mutex);
4625 cik_compute_stop(rdev,&rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX]);
4626 cik_compute_stop(rdev,&rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX]);
4627 mutex_unlock(&rdev->srbm_mutex);
4629 WREG32(CP_MEC_CNTL, (MEC_ME1_HALT | MEC_ME2_HALT));
4630 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
4631 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
4637 * cik_cp_compute_load_microcode - load the compute CP ME ucode
4639 * @rdev: radeon_device pointer
4641 * Loads the compute MEC1&2 ucode.
4642 * Returns 0 for success, -EINVAL if the ucode is not available.
4644 static int cik_cp_compute_load_microcode(struct radeon_device *rdev)
4651 cik_cp_compute_enable(rdev, false);
4654 const struct gfx_firmware_header_v1_0 *mec_hdr =
4655 (const struct gfx_firmware_header_v1_0 *)rdev->mec_fw->data;
4656 const __le32 *fw_data;
4659 radeon_ucode_print_gfx_hdr(&mec_hdr->header);
4662 fw_data = (const __le32 *)
4663 (rdev->mec_fw->data + le32_to_cpu(mec_hdr->header.ucode_array_offset_bytes));
4664 fw_size = le32_to_cpu(mec_hdr->header.ucode_size_bytes) / 4;
4665 WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
4666 for (i = 0; i < fw_size; i++)
4667 WREG32(CP_MEC_ME1_UCODE_DATA, le32_to_cpup(fw_data++));
4668 WREG32(CP_MEC_ME1_UCODE_ADDR, le32_to_cpu(mec_hdr->header.ucode_version));
4671 if (rdev->family == CHIP_KAVERI) {
4672 const struct gfx_firmware_header_v1_0 *mec2_hdr =
4673 (const struct gfx_firmware_header_v1_0 *)rdev->mec2_fw->data;
4675 fw_data = (const __le32 *)
4676 (rdev->mec2_fw->data +
4677 le32_to_cpu(mec2_hdr->header.ucode_array_offset_bytes));
4678 fw_size = le32_to_cpu(mec2_hdr->header.ucode_size_bytes) / 4;
4679 WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
4680 for (i = 0; i < fw_size; i++)
4681 WREG32(CP_MEC_ME2_UCODE_DATA, le32_to_cpup(fw_data++));
4682 WREG32(CP_MEC_ME2_UCODE_ADDR, le32_to_cpu(mec2_hdr->header.ucode_version));
4685 const __be32 *fw_data;
4688 fw_data = (const __be32 *)rdev->mec_fw->data;
4689 WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
4690 for (i = 0; i < CIK_MEC_UCODE_SIZE; i++)
4691 WREG32(CP_MEC_ME1_UCODE_DATA, be32_to_cpup(fw_data++));
4692 WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
4694 if (rdev->family == CHIP_KAVERI) {
4696 fw_data = (const __be32 *)rdev->mec_fw->data;
4697 WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
4698 for (i = 0; i < CIK_MEC_UCODE_SIZE; i++)
4699 WREG32(CP_MEC_ME2_UCODE_DATA, be32_to_cpup(fw_data++));
4700 WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
4708 * cik_cp_compute_start - start the compute queues
4710 * @rdev: radeon_device pointer
4712 * Enable the compute queues.
4713 * Returns 0 for success, error for failure.
4715 static int cik_cp_compute_start(struct radeon_device *rdev)
4717 cik_cp_compute_enable(rdev, true);
4723 * cik_cp_compute_fini - stop the compute queues
4725 * @rdev: radeon_device pointer
4727 * Stop the compute queues and tear down the driver queue
4730 static void cik_cp_compute_fini(struct radeon_device *rdev)
4734 cik_cp_compute_enable(rdev, false);
4736 for (i = 0; i < 2; i++) {
4738 idx = CAYMAN_RING_TYPE_CP1_INDEX;
4740 idx = CAYMAN_RING_TYPE_CP2_INDEX;
4742 if (rdev->ring[idx].mqd_obj) {
4743 r = radeon_bo_reserve(rdev->ring[idx].mqd_obj, false);
4744 if (unlikely(r != 0))
4745 dev_warn(rdev->dev, "(%d) reserve MQD bo failed\n", r);
4747 radeon_bo_unpin(rdev->ring[idx].mqd_obj);
4748 radeon_bo_unreserve(rdev->ring[idx].mqd_obj);
4750 radeon_bo_unref(&rdev->ring[idx].mqd_obj);
4751 rdev->ring[idx].mqd_obj = NULL;
4756 static void cik_mec_fini(struct radeon_device *rdev)
4760 if (rdev->mec.hpd_eop_obj) {
4761 r = radeon_bo_reserve(rdev->mec.hpd_eop_obj, false);
4762 if (unlikely(r != 0))
4763 dev_warn(rdev->dev, "(%d) reserve HPD EOP bo failed\n", r);
4764 radeon_bo_unpin(rdev->mec.hpd_eop_obj);
4765 radeon_bo_unreserve(rdev->mec.hpd_eop_obj);
4767 radeon_bo_unref(&rdev->mec.hpd_eop_obj);
4768 rdev->mec.hpd_eop_obj = NULL;
4772 #define MEC_HPD_SIZE 2048
4774 static int cik_mec_init(struct radeon_device *rdev)
4780 * KV: 2 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 64 Queues total
4781 * CI/KB: 1 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 32 Queues total
4782 * Nonetheless, we assign only 1 pipe because all other pipes will
4785 rdev->mec.num_mec = 1;
4786 rdev->mec.num_pipe = 1;
4787 rdev->mec.num_queue = rdev->mec.num_mec * rdev->mec.num_pipe * 8;
4789 if (rdev->mec.hpd_eop_obj == NULL) {
4790 r = radeon_bo_create(rdev,
4791 rdev->mec.num_mec *rdev->mec.num_pipe * MEC_HPD_SIZE * 2,
4793 RADEON_GEM_DOMAIN_GTT, 0, NULL, NULL,
4794 &rdev->mec.hpd_eop_obj);
4796 dev_warn(rdev->dev, "(%d) create HDP EOP bo failed\n", r);
4801 r = radeon_bo_reserve(rdev->mec.hpd_eop_obj, false);
4802 if (unlikely(r != 0)) {
4806 r = radeon_bo_pin(rdev->mec.hpd_eop_obj, RADEON_GEM_DOMAIN_GTT,
4807 &rdev->mec.hpd_eop_gpu_addr);
4809 dev_warn(rdev->dev, "(%d) pin HDP EOP bo failed\n", r);
4813 r = radeon_bo_kmap(rdev->mec.hpd_eop_obj, (void **)&hpd);
4815 dev_warn(rdev->dev, "(%d) map HDP EOP bo failed\n", r);
4820 /* clear memory. Not sure if this is required or not */
4821 memset(hpd, 0, rdev->mec.num_mec *rdev->mec.num_pipe * MEC_HPD_SIZE * 2);
4823 radeon_bo_kunmap(rdev->mec.hpd_eop_obj);
4824 radeon_bo_unreserve(rdev->mec.hpd_eop_obj);
4829 struct hqd_registers
4831 u32 cp_mqd_base_addr;
4832 u32 cp_mqd_base_addr_hi;
4835 u32 cp_hqd_persistent_state;
4836 u32 cp_hqd_pipe_priority;
4837 u32 cp_hqd_queue_priority;
4840 u32 cp_hqd_pq_base_hi;
4842 u32 cp_hqd_pq_rptr_report_addr;
4843 u32 cp_hqd_pq_rptr_report_addr_hi;
4844 u32 cp_hqd_pq_wptr_poll_addr;
4845 u32 cp_hqd_pq_wptr_poll_addr_hi;
4846 u32 cp_hqd_pq_doorbell_control;
4848 u32 cp_hqd_pq_control;
4849 u32 cp_hqd_ib_base_addr;
4850 u32 cp_hqd_ib_base_addr_hi;
4852 u32 cp_hqd_ib_control;
4853 u32 cp_hqd_iq_timer;
4855 u32 cp_hqd_dequeue_request;
4856 u32 cp_hqd_dma_offload;
4857 u32 cp_hqd_sema_cmd;
4858 u32 cp_hqd_msg_type;
4859 u32 cp_hqd_atomic0_preop_lo;
4860 u32 cp_hqd_atomic0_preop_hi;
4861 u32 cp_hqd_atomic1_preop_lo;
4862 u32 cp_hqd_atomic1_preop_hi;
4863 u32 cp_hqd_hq_scheduler0;
4864 u32 cp_hqd_hq_scheduler1;
4871 u32 dispatch_initiator;
4875 u32 pipeline_stat_enable;
4876 u32 perf_counter_enable;
4882 u32 resource_limits;
4883 u32 static_thread_mgmt01[2];
4885 u32 static_thread_mgmt23[2];
4887 u32 thread_trace_enable;
4890 u32 vgtcs_invoke_count[2];
4891 struct hqd_registers queue_state;
4893 u32 interrupt_queue[64];
4897 * cik_cp_compute_resume - setup the compute queue registers
4899 * @rdev: radeon_device pointer
4901 * Program the compute queues and test them to make sure they
4903 * Returns 0 for success, error for failure.
4905 static int cik_cp_compute_resume(struct radeon_device *rdev)
4909 bool use_doorbell = true;
4915 struct bonaire_mqd *mqd;
4917 r = cik_cp_compute_start(rdev);
4921 /* fix up chicken bits */
4922 tmp = RREG32(CP_CPF_DEBUG);
4924 WREG32(CP_CPF_DEBUG, tmp);
4926 /* init the pipes */
4927 mutex_lock(&rdev->srbm_mutex);
4929 eop_gpu_addr = rdev->mec.hpd_eop_gpu_addr;
4931 cik_srbm_select(rdev, 0, 0, 0, 0);
4933 /* write the EOP addr */
4934 WREG32(CP_HPD_EOP_BASE_ADDR, eop_gpu_addr >> 8);
4935 WREG32(CP_HPD_EOP_BASE_ADDR_HI, upper_32_bits(eop_gpu_addr) >> 8);
4937 /* set the VMID assigned */
4938 WREG32(CP_HPD_EOP_VMID, 0);
4940 /* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */
4941 tmp = RREG32(CP_HPD_EOP_CONTROL);
4942 tmp &= ~EOP_SIZE_MASK;
4943 tmp |= order_base_2(MEC_HPD_SIZE / 8);
4944 WREG32(CP_HPD_EOP_CONTROL, tmp);
4946 mutex_unlock(&rdev->srbm_mutex);
4948 /* init the queues. Just two for now. */
4949 for (i = 0; i < 2; i++) {
4951 idx = CAYMAN_RING_TYPE_CP1_INDEX;
4953 idx = CAYMAN_RING_TYPE_CP2_INDEX;
4955 if (rdev->ring[idx].mqd_obj == NULL) {
4956 r = radeon_bo_create(rdev,
4957 sizeof(struct bonaire_mqd),
4959 RADEON_GEM_DOMAIN_GTT, 0, NULL,
4960 NULL, &rdev->ring[idx].mqd_obj);
4962 dev_warn(rdev->dev, "(%d) create MQD bo failed\n", r);
4967 r = radeon_bo_reserve(rdev->ring[idx].mqd_obj, false);
4968 if (unlikely(r != 0)) {
4969 cik_cp_compute_fini(rdev);
4972 r = radeon_bo_pin(rdev->ring[idx].mqd_obj, RADEON_GEM_DOMAIN_GTT,
4975 dev_warn(rdev->dev, "(%d) pin MQD bo failed\n", r);
4976 cik_cp_compute_fini(rdev);
4979 r = radeon_bo_kmap(rdev->ring[idx].mqd_obj, (void **)&buf);
4981 dev_warn(rdev->dev, "(%d) map MQD bo failed\n", r);
4982 cik_cp_compute_fini(rdev);
4986 /* init the mqd struct */
4987 memset(buf, 0, sizeof(struct bonaire_mqd));
4989 mqd = (struct bonaire_mqd *)buf;
4990 mqd->header = 0xC0310800;
4991 mqd->static_thread_mgmt01[0] = 0xffffffff;
4992 mqd->static_thread_mgmt01[1] = 0xffffffff;
4993 mqd->static_thread_mgmt23[0] = 0xffffffff;
4994 mqd->static_thread_mgmt23[1] = 0xffffffff;
4996 mutex_lock(&rdev->srbm_mutex);
4997 cik_srbm_select(rdev, rdev->ring[idx].me,
4998 rdev->ring[idx].pipe,
4999 rdev->ring[idx].queue, 0);
5001 /* disable wptr polling */
5002 tmp = RREG32(CP_PQ_WPTR_POLL_CNTL);
5003 tmp &= ~WPTR_POLL_EN;
5004 WREG32(CP_PQ_WPTR_POLL_CNTL, tmp);
5006 /* enable doorbell? */
5007 mqd->queue_state.cp_hqd_pq_doorbell_control =
5008 RREG32(CP_HQD_PQ_DOORBELL_CONTROL);
5010 mqd->queue_state.cp_hqd_pq_doorbell_control |= DOORBELL_EN;
5012 mqd->queue_state.cp_hqd_pq_doorbell_control &= ~DOORBELL_EN;
5013 WREG32(CP_HQD_PQ_DOORBELL_CONTROL,
5014 mqd->queue_state.cp_hqd_pq_doorbell_control);
5016 /* disable the queue if it's active */
5017 mqd->queue_state.cp_hqd_dequeue_request = 0;
5018 mqd->queue_state.cp_hqd_pq_rptr = 0;
5019 mqd->queue_state.cp_hqd_pq_wptr= 0;
5020 if (RREG32(CP_HQD_ACTIVE) & 1) {
5021 WREG32(CP_HQD_DEQUEUE_REQUEST, 1);
5022 for (j = 0; j < rdev->usec_timeout; j++) {
5023 if (!(RREG32(CP_HQD_ACTIVE) & 1))
5027 WREG32(CP_HQD_DEQUEUE_REQUEST, mqd->queue_state.cp_hqd_dequeue_request);
5028 WREG32(CP_HQD_PQ_RPTR, mqd->queue_state.cp_hqd_pq_rptr);
5029 WREG32(CP_HQD_PQ_WPTR, mqd->queue_state.cp_hqd_pq_wptr);
5032 /* set the pointer to the MQD */
5033 mqd->queue_state.cp_mqd_base_addr = mqd_gpu_addr & 0xfffffffc;
5034 mqd->queue_state.cp_mqd_base_addr_hi = upper_32_bits(mqd_gpu_addr);
5035 WREG32(CP_MQD_BASE_ADDR, mqd->queue_state.cp_mqd_base_addr);
5036 WREG32(CP_MQD_BASE_ADDR_HI, mqd->queue_state.cp_mqd_base_addr_hi);
5037 /* set MQD vmid to 0 */
5038 mqd->queue_state.cp_mqd_control = RREG32(CP_MQD_CONTROL);
5039 mqd->queue_state.cp_mqd_control &= ~MQD_VMID_MASK;
5040 WREG32(CP_MQD_CONTROL, mqd->queue_state.cp_mqd_control);
5042 /* set the pointer to the HQD, this is similar CP_RB0_BASE/_HI */
5043 hqd_gpu_addr = rdev->ring[idx].gpu_addr >> 8;
5044 mqd->queue_state.cp_hqd_pq_base = hqd_gpu_addr;
5045 mqd->queue_state.cp_hqd_pq_base_hi = upper_32_bits(hqd_gpu_addr);
5046 WREG32(CP_HQD_PQ_BASE, mqd->queue_state.cp_hqd_pq_base);
5047 WREG32(CP_HQD_PQ_BASE_HI, mqd->queue_state.cp_hqd_pq_base_hi);
5049 /* set up the HQD, this is similar to CP_RB0_CNTL */
5050 mqd->queue_state.cp_hqd_pq_control = RREG32(CP_HQD_PQ_CONTROL);
5051 mqd->queue_state.cp_hqd_pq_control &=
5052 ~(QUEUE_SIZE_MASK | RPTR_BLOCK_SIZE_MASK);
5054 mqd->queue_state.cp_hqd_pq_control |=
5055 order_base_2(rdev->ring[idx].ring_size / 8);
5056 mqd->queue_state.cp_hqd_pq_control |=
5057 (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8);
5059 mqd->queue_state.cp_hqd_pq_control |= BUF_SWAP_32BIT;
5061 mqd->queue_state.cp_hqd_pq_control &=
5062 ~(UNORD_DISPATCH | ROQ_PQ_IB_FLIP | PQ_VOLATILE);
5063 mqd->queue_state.cp_hqd_pq_control |=
5064 PRIV_STATE | KMD_QUEUE; /* assuming kernel queue control */
5065 WREG32(CP_HQD_PQ_CONTROL, mqd->queue_state.cp_hqd_pq_control);
5067 /* only used if CP_PQ_WPTR_POLL_CNTL.WPTR_POLL_EN=1 */
5069 wb_gpu_addr = rdev->wb.gpu_addr + CIK_WB_CP1_WPTR_OFFSET;
5071 wb_gpu_addr = rdev->wb.gpu_addr + CIK_WB_CP2_WPTR_OFFSET;
5072 mqd->queue_state.cp_hqd_pq_wptr_poll_addr = wb_gpu_addr & 0xfffffffc;
5073 mqd->queue_state.cp_hqd_pq_wptr_poll_addr_hi = upper_32_bits(wb_gpu_addr) & 0xffff;
5074 WREG32(CP_HQD_PQ_WPTR_POLL_ADDR, mqd->queue_state.cp_hqd_pq_wptr_poll_addr);
5075 WREG32(CP_HQD_PQ_WPTR_POLL_ADDR_HI,
5076 mqd->queue_state.cp_hqd_pq_wptr_poll_addr_hi);
5078 /* set the wb address wether it's enabled or not */
5080 wb_gpu_addr = rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET;
5082 wb_gpu_addr = rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET;
5083 mqd->queue_state.cp_hqd_pq_rptr_report_addr = wb_gpu_addr & 0xfffffffc;
5084 mqd->queue_state.cp_hqd_pq_rptr_report_addr_hi =
5085 upper_32_bits(wb_gpu_addr) & 0xffff;
5086 WREG32(CP_HQD_PQ_RPTR_REPORT_ADDR,
5087 mqd->queue_state.cp_hqd_pq_rptr_report_addr);
5088 WREG32(CP_HQD_PQ_RPTR_REPORT_ADDR_HI,
5089 mqd->queue_state.cp_hqd_pq_rptr_report_addr_hi);
5091 /* enable the doorbell if requested */
5093 mqd->queue_state.cp_hqd_pq_doorbell_control =
5094 RREG32(CP_HQD_PQ_DOORBELL_CONTROL);
5095 mqd->queue_state.cp_hqd_pq_doorbell_control &= ~DOORBELL_OFFSET_MASK;
5096 mqd->queue_state.cp_hqd_pq_doorbell_control |=
5097 DOORBELL_OFFSET(rdev->ring[idx].doorbell_index);
5098 mqd->queue_state.cp_hqd_pq_doorbell_control |= DOORBELL_EN;
5099 mqd->queue_state.cp_hqd_pq_doorbell_control &=
5100 ~(DOORBELL_SOURCE | DOORBELL_HIT);
5103 mqd->queue_state.cp_hqd_pq_doorbell_control = 0;
5105 WREG32(CP_HQD_PQ_DOORBELL_CONTROL,
5106 mqd->queue_state.cp_hqd_pq_doorbell_control);
5108 /* read and write pointers, similar to CP_RB0_WPTR/_RPTR */
5109 rdev->ring[idx].wptr = 0;
5110 mqd->queue_state.cp_hqd_pq_wptr = rdev->ring[idx].wptr;
5111 WREG32(CP_HQD_PQ_WPTR, mqd->queue_state.cp_hqd_pq_wptr);
5112 mqd->queue_state.cp_hqd_pq_rptr = RREG32(CP_HQD_PQ_RPTR);
5114 /* set the vmid for the queue */
5115 mqd->queue_state.cp_hqd_vmid = 0;
5116 WREG32(CP_HQD_VMID, mqd->queue_state.cp_hqd_vmid);
5118 /* activate the queue */
5119 mqd->queue_state.cp_hqd_active = 1;
5120 WREG32(CP_HQD_ACTIVE, mqd->queue_state.cp_hqd_active);
5122 cik_srbm_select(rdev, 0, 0, 0, 0);
5123 mutex_unlock(&rdev->srbm_mutex);
5125 radeon_bo_kunmap(rdev->ring[idx].mqd_obj);
5126 radeon_bo_unreserve(rdev->ring[idx].mqd_obj);
5128 rdev->ring[idx].ready = true;
5129 r = radeon_ring_test(rdev, idx, &rdev->ring[idx]);
5131 rdev->ring[idx].ready = false;
5137 static void cik_cp_enable(struct radeon_device *rdev, bool enable)
5139 cik_cp_gfx_enable(rdev, enable);
5140 cik_cp_compute_enable(rdev, enable);
5143 static int cik_cp_load_microcode(struct radeon_device *rdev)
5147 r = cik_cp_gfx_load_microcode(rdev);
5150 r = cik_cp_compute_load_microcode(rdev);
5157 static void cik_cp_fini(struct radeon_device *rdev)
5159 cik_cp_gfx_fini(rdev);
5160 cik_cp_compute_fini(rdev);
5163 static int cik_cp_resume(struct radeon_device *rdev)
5167 cik_enable_gui_idle_interrupt(rdev, false);
5169 r = cik_cp_load_microcode(rdev);
5173 r = cik_cp_gfx_resume(rdev);
5176 r = cik_cp_compute_resume(rdev);
5180 cik_enable_gui_idle_interrupt(rdev, true);
5185 static void cik_print_gpu_status_regs(struct radeon_device *rdev)
5187 dev_info(rdev->dev, " GRBM_STATUS=0x%08X\n",
5188 RREG32(GRBM_STATUS));
5189 dev_info(rdev->dev, " GRBM_STATUS2=0x%08X\n",
5190 RREG32(GRBM_STATUS2));
5191 dev_info(rdev->dev, " GRBM_STATUS_SE0=0x%08X\n",
5192 RREG32(GRBM_STATUS_SE0));
5193 dev_info(rdev->dev, " GRBM_STATUS_SE1=0x%08X\n",
5194 RREG32(GRBM_STATUS_SE1));
5195 dev_info(rdev->dev, " GRBM_STATUS_SE2=0x%08X\n",
5196 RREG32(GRBM_STATUS_SE2));
5197 dev_info(rdev->dev, " GRBM_STATUS_SE3=0x%08X\n",
5198 RREG32(GRBM_STATUS_SE3));
5199 dev_info(rdev->dev, " SRBM_STATUS=0x%08X\n",
5200 RREG32(SRBM_STATUS));
5201 dev_info(rdev->dev, " SRBM_STATUS2=0x%08X\n",
5202 RREG32(SRBM_STATUS2));
5203 dev_info(rdev->dev, " SDMA0_STATUS_REG = 0x%08X\n",
5204 RREG32(SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET));
5205 dev_info(rdev->dev, " SDMA1_STATUS_REG = 0x%08X\n",
5206 RREG32(SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET));
5207 dev_info(rdev->dev, " CP_STAT = 0x%08x\n", RREG32(CP_STAT));
5208 dev_info(rdev->dev, " CP_STALLED_STAT1 = 0x%08x\n",
5209 RREG32(CP_STALLED_STAT1));
5210 dev_info(rdev->dev, " CP_STALLED_STAT2 = 0x%08x\n",
5211 RREG32(CP_STALLED_STAT2));
5212 dev_info(rdev->dev, " CP_STALLED_STAT3 = 0x%08x\n",
5213 RREG32(CP_STALLED_STAT3));
5214 dev_info(rdev->dev, " CP_CPF_BUSY_STAT = 0x%08x\n",
5215 RREG32(CP_CPF_BUSY_STAT));
5216 dev_info(rdev->dev, " CP_CPF_STALLED_STAT1 = 0x%08x\n",
5217 RREG32(CP_CPF_STALLED_STAT1));
5218 dev_info(rdev->dev, " CP_CPF_STATUS = 0x%08x\n", RREG32(CP_CPF_STATUS));
5219 dev_info(rdev->dev, " CP_CPC_BUSY_STAT = 0x%08x\n", RREG32(CP_CPC_BUSY_STAT));
5220 dev_info(rdev->dev, " CP_CPC_STALLED_STAT1 = 0x%08x\n",
5221 RREG32(CP_CPC_STALLED_STAT1));
5222 dev_info(rdev->dev, " CP_CPC_STATUS = 0x%08x\n", RREG32(CP_CPC_STATUS));
5226 * cik_gpu_check_soft_reset - check which blocks are busy
5228 * @rdev: radeon_device pointer
5230 * Check which blocks are busy and return the relevant reset
5231 * mask to be used by cik_gpu_soft_reset().
5232 * Returns a mask of the blocks to be reset.
5234 u32 cik_gpu_check_soft_reset(struct radeon_device *rdev)
5240 tmp = RREG32(GRBM_STATUS);
5241 if (tmp & (PA_BUSY | SC_BUSY |
5242 BCI_BUSY | SX_BUSY |
5243 TA_BUSY | VGT_BUSY |
5245 GDS_BUSY | SPI_BUSY |
5246 IA_BUSY | IA_BUSY_NO_DMA))
5247 reset_mask |= RADEON_RESET_GFX;
5249 if (tmp & (CP_BUSY | CP_COHERENCY_BUSY))
5250 reset_mask |= RADEON_RESET_CP;
5253 tmp = RREG32(GRBM_STATUS2);
5255 reset_mask |= RADEON_RESET_RLC;
5257 /* SDMA0_STATUS_REG */
5258 tmp = RREG32(SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET);
5259 if (!(tmp & SDMA_IDLE))
5260 reset_mask |= RADEON_RESET_DMA;
5262 /* SDMA1_STATUS_REG */
5263 tmp = RREG32(SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET);
5264 if (!(tmp & SDMA_IDLE))
5265 reset_mask |= RADEON_RESET_DMA1;
5268 tmp = RREG32(SRBM_STATUS2);
5269 if (tmp & SDMA_BUSY)
5270 reset_mask |= RADEON_RESET_DMA;
5272 if (tmp & SDMA1_BUSY)
5273 reset_mask |= RADEON_RESET_DMA1;
5276 tmp = RREG32(SRBM_STATUS);
5279 reset_mask |= RADEON_RESET_IH;
5282 reset_mask |= RADEON_RESET_SEM;
5284 if (tmp & GRBM_RQ_PENDING)
5285 reset_mask |= RADEON_RESET_GRBM;
5288 reset_mask |= RADEON_RESET_VMC;
5290 if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
5291 MCC_BUSY | MCD_BUSY))
5292 reset_mask |= RADEON_RESET_MC;
5294 if (evergreen_is_display_hung(rdev))
5295 reset_mask |= RADEON_RESET_DISPLAY;
5297 /* Skip MC reset as it's mostly likely not hung, just busy */
5298 if (reset_mask & RADEON_RESET_MC) {
5299 DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
5300 reset_mask &= ~RADEON_RESET_MC;
5307 * cik_gpu_soft_reset - soft reset GPU
5309 * @rdev: radeon_device pointer
5310 * @reset_mask: mask of which blocks to reset
5312 * Soft reset the blocks specified in @reset_mask.
5314 static void cik_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
5316 struct evergreen_mc_save save;
5317 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
5320 if (reset_mask == 0)
5323 dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
5325 cik_print_gpu_status_regs(rdev);
5326 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
5327 RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
5328 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
5329 RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
5338 /* Disable GFX parsing/prefetching */
5339 WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
5341 /* Disable MEC parsing/prefetching */
5342 WREG32(CP_MEC_CNTL, MEC_ME1_HALT | MEC_ME2_HALT);
5344 if (reset_mask & RADEON_RESET_DMA) {
5346 tmp = RREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET);
5348 WREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET, tmp);
5350 if (reset_mask & RADEON_RESET_DMA1) {
5352 tmp = RREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET);
5354 WREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET, tmp);
5357 evergreen_mc_stop(rdev, &save);
5358 if (evergreen_mc_wait_for_idle(rdev)) {
5359 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
5362 if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE | RADEON_RESET_CP))
5363 grbm_soft_reset = SOFT_RESET_CP | SOFT_RESET_GFX;
5365 if (reset_mask & RADEON_RESET_CP) {
5366 grbm_soft_reset |= SOFT_RESET_CP;
5368 srbm_soft_reset |= SOFT_RESET_GRBM;
5371 if (reset_mask & RADEON_RESET_DMA)
5372 srbm_soft_reset |= SOFT_RESET_SDMA;
5374 if (reset_mask & RADEON_RESET_DMA1)
5375 srbm_soft_reset |= SOFT_RESET_SDMA1;
5377 if (reset_mask & RADEON_RESET_DISPLAY)
5378 srbm_soft_reset |= SOFT_RESET_DC;
5380 if (reset_mask & RADEON_RESET_RLC)
5381 grbm_soft_reset |= SOFT_RESET_RLC;
5383 if (reset_mask & RADEON_RESET_SEM)
5384 srbm_soft_reset |= SOFT_RESET_SEM;
5386 if (reset_mask & RADEON_RESET_IH)
5387 srbm_soft_reset |= SOFT_RESET_IH;
5389 if (reset_mask & RADEON_RESET_GRBM)
5390 srbm_soft_reset |= SOFT_RESET_GRBM;
5392 if (reset_mask & RADEON_RESET_VMC)
5393 srbm_soft_reset |= SOFT_RESET_VMC;
5395 if (!(rdev->flags & RADEON_IS_IGP)) {
5396 if (reset_mask & RADEON_RESET_MC)
5397 srbm_soft_reset |= SOFT_RESET_MC;
5400 if (grbm_soft_reset) {
5401 tmp = RREG32(GRBM_SOFT_RESET);
5402 tmp |= grbm_soft_reset;
5403 dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
5404 WREG32(GRBM_SOFT_RESET, tmp);
5405 tmp = RREG32(GRBM_SOFT_RESET);
5409 tmp &= ~grbm_soft_reset;
5410 WREG32(GRBM_SOFT_RESET, tmp);
5411 tmp = RREG32(GRBM_SOFT_RESET);
5414 if (srbm_soft_reset) {
5415 tmp = RREG32(SRBM_SOFT_RESET);
5416 tmp |= srbm_soft_reset;
5417 dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
5418 WREG32(SRBM_SOFT_RESET, tmp);
5419 tmp = RREG32(SRBM_SOFT_RESET);
5423 tmp &= ~srbm_soft_reset;
5424 WREG32(SRBM_SOFT_RESET, tmp);
5425 tmp = RREG32(SRBM_SOFT_RESET);
5428 /* Wait a little for things to settle down */
5431 evergreen_mc_resume(rdev, &save);
5434 cik_print_gpu_status_regs(rdev);
5437 struct kv_reset_save_regs {
5438 u32 gmcon_reng_execute;
5443 static void kv_save_regs_for_reset(struct radeon_device *rdev,
5444 struct kv_reset_save_regs *save)
5446 save->gmcon_reng_execute = RREG32(GMCON_RENG_EXECUTE);
5447 save->gmcon_misc = RREG32(GMCON_MISC);
5448 save->gmcon_misc3 = RREG32(GMCON_MISC3);
5450 WREG32(GMCON_RENG_EXECUTE, save->gmcon_reng_execute & ~RENG_EXECUTE_ON_PWR_UP);
5451 WREG32(GMCON_MISC, save->gmcon_misc & ~(RENG_EXECUTE_ON_REG_UPDATE |
5452 STCTRL_STUTTER_EN));
5455 static void kv_restore_regs_for_reset(struct radeon_device *rdev,
5456 struct kv_reset_save_regs *save)
5460 WREG32(GMCON_PGFSM_WRITE, 0);
5461 WREG32(GMCON_PGFSM_CONFIG, 0x200010ff);
5463 for (i = 0; i < 5; i++)
5464 WREG32(GMCON_PGFSM_WRITE, 0);
5466 WREG32(GMCON_PGFSM_WRITE, 0);
5467 WREG32(GMCON_PGFSM_CONFIG, 0x300010ff);
5469 for (i = 0; i < 5; i++)
5470 WREG32(GMCON_PGFSM_WRITE, 0);
5472 WREG32(GMCON_PGFSM_WRITE, 0x210000);
5473 WREG32(GMCON_PGFSM_CONFIG, 0xa00010ff);
5475 for (i = 0; i < 5; i++)
5476 WREG32(GMCON_PGFSM_WRITE, 0);
5478 WREG32(GMCON_PGFSM_WRITE, 0x21003);
5479 WREG32(GMCON_PGFSM_CONFIG, 0xb00010ff);
5481 for (i = 0; i < 5; i++)
5482 WREG32(GMCON_PGFSM_WRITE, 0);
5484 WREG32(GMCON_PGFSM_WRITE, 0x2b00);
5485 WREG32(GMCON_PGFSM_CONFIG, 0xc00010ff);
5487 for (i = 0; i < 5; i++)
5488 WREG32(GMCON_PGFSM_WRITE, 0);
5490 WREG32(GMCON_PGFSM_WRITE, 0);
5491 WREG32(GMCON_PGFSM_CONFIG, 0xd00010ff);
5493 for (i = 0; i < 5; i++)
5494 WREG32(GMCON_PGFSM_WRITE, 0);
5496 WREG32(GMCON_PGFSM_WRITE, 0x420000);
5497 WREG32(GMCON_PGFSM_CONFIG, 0x100010ff);
5499 for (i = 0; i < 5; i++)
5500 WREG32(GMCON_PGFSM_WRITE, 0);
5502 WREG32(GMCON_PGFSM_WRITE, 0x120202);
5503 WREG32(GMCON_PGFSM_CONFIG, 0x500010ff);
5505 for (i = 0; i < 5; i++)
5506 WREG32(GMCON_PGFSM_WRITE, 0);
5508 WREG32(GMCON_PGFSM_WRITE, 0x3e3e36);
5509 WREG32(GMCON_PGFSM_CONFIG, 0x600010ff);
5511 for (i = 0; i < 5; i++)
5512 WREG32(GMCON_PGFSM_WRITE, 0);
5514 WREG32(GMCON_PGFSM_WRITE, 0x373f3e);
5515 WREG32(GMCON_PGFSM_CONFIG, 0x700010ff);
5517 for (i = 0; i < 5; i++)
5518 WREG32(GMCON_PGFSM_WRITE, 0);
5520 WREG32(GMCON_PGFSM_WRITE, 0x3e1332);
5521 WREG32(GMCON_PGFSM_CONFIG, 0xe00010ff);
5523 WREG32(GMCON_MISC3, save->gmcon_misc3);
5524 WREG32(GMCON_MISC, save->gmcon_misc);
5525 WREG32(GMCON_RENG_EXECUTE, save->gmcon_reng_execute);
5528 static void cik_gpu_pci_config_reset(struct radeon_device *rdev)
5530 struct evergreen_mc_save save;
5531 struct kv_reset_save_regs kv_save = { 0 };
5534 dev_info(rdev->dev, "GPU pci config reset\n");
5542 /* Disable GFX parsing/prefetching */
5543 WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
5545 /* Disable MEC parsing/prefetching */
5546 WREG32(CP_MEC_CNTL, MEC_ME1_HALT | MEC_ME2_HALT);
5549 tmp = RREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET);
5551 WREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET, tmp);
5553 tmp = RREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET);
5555 WREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET, tmp);
5556 /* XXX other engines? */
5558 /* halt the rlc, disable cp internal ints */
5563 /* disable mem access */
5564 evergreen_mc_stop(rdev, &save);
5565 if (evergreen_mc_wait_for_idle(rdev)) {
5566 dev_warn(rdev->dev, "Wait for MC idle timed out !\n");
5569 if (rdev->flags & RADEON_IS_IGP)
5570 kv_save_regs_for_reset(rdev, &kv_save);
5573 pci_clear_master(rdev->pdev);
5575 radeon_pci_config_reset(rdev);
5579 /* wait for asic to come out of reset */
5580 for (i = 0; i < rdev->usec_timeout; i++) {
5581 if (RREG32(CONFIG_MEMSIZE) != 0xffffffff)
5586 /* does asic init need to be run first??? */
5587 if (rdev->flags & RADEON_IS_IGP)
5588 kv_restore_regs_for_reset(rdev, &kv_save);
5592 * cik_asic_reset - soft reset GPU
5594 * @rdev: radeon_device pointer
5596 * Look up which blocks are hung and attempt
5598 * Returns 0 for success.
5600 int cik_asic_reset(struct radeon_device *rdev)
5604 reset_mask = cik_gpu_check_soft_reset(rdev);
5607 r600_set_bios_scratch_engine_hung(rdev, true);
5609 /* try soft reset */
5610 cik_gpu_soft_reset(rdev, reset_mask);
5612 reset_mask = cik_gpu_check_soft_reset(rdev);
5614 /* try pci config reset */
5615 if (reset_mask && radeon_hard_reset)
5616 cik_gpu_pci_config_reset(rdev);
5618 reset_mask = cik_gpu_check_soft_reset(rdev);
5621 r600_set_bios_scratch_engine_hung(rdev, false);
5627 * cik_gfx_is_lockup - check if the 3D engine is locked up
5629 * @rdev: radeon_device pointer
5630 * @ring: radeon_ring structure holding ring information
5632 * Check if the 3D engine is locked up (CIK).
5633 * Returns true if the engine is locked, false if not.
5635 bool cik_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
5637 u32 reset_mask = cik_gpu_check_soft_reset(rdev);
5639 if (!(reset_mask & (RADEON_RESET_GFX |
5640 RADEON_RESET_COMPUTE |
5641 RADEON_RESET_CP))) {
5642 radeon_ring_lockup_update(rdev, ring);
5645 return radeon_ring_test_lockup(rdev, ring);
5650 * cik_mc_program - program the GPU memory controller
5652 * @rdev: radeon_device pointer
5654 * Set the location of vram, gart, and AGP in the GPU's
5655 * physical address space (CIK).
5657 static void cik_mc_program(struct radeon_device *rdev)
5659 struct evergreen_mc_save save;
5663 /* Initialize HDP */
5664 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
5665 WREG32((0x2c14 + j), 0x00000000);
5666 WREG32((0x2c18 + j), 0x00000000);
5667 WREG32((0x2c1c + j), 0x00000000);
5668 WREG32((0x2c20 + j), 0x00000000);
5669 WREG32((0x2c24 + j), 0x00000000);
5671 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
5673 evergreen_mc_stop(rdev, &save);
5674 if (radeon_mc_wait_for_idle(rdev)) {
5675 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
5677 /* Lockout access through VGA aperture*/
5678 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
5679 /* Update configuration */
5680 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
5681 rdev->mc.vram_start >> 12);
5682 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
5683 rdev->mc.vram_end >> 12);
5684 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR,
5685 rdev->vram_scratch.gpu_addr >> 12);
5686 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
5687 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
5688 WREG32(MC_VM_FB_LOCATION, tmp);
5689 /* XXX double check these! */
5690 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
5691 WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
5692 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
5693 WREG32(MC_VM_AGP_BASE, 0);
5694 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
5695 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
5696 if (radeon_mc_wait_for_idle(rdev)) {
5697 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
5699 evergreen_mc_resume(rdev, &save);
5700 /* we need to own VRAM, so turn off the VGA renderer here
5701 * to stop it overwriting our objects */
5702 rv515_vga_render_disable(rdev);
5706 * cik_mc_init - initialize the memory controller driver params
5708 * @rdev: radeon_device pointer
5710 * Look up the amount of vram, vram width, and decide how to place
5711 * vram and gart within the GPU's physical address space (CIK).
5712 * Returns 0 for success.
5714 static int cik_mc_init(struct radeon_device *rdev)
5717 int chansize, numchan;
5719 /* Get VRAM informations */
5720 rdev->mc.vram_is_ddr = true;
5721 tmp = RREG32(MC_ARB_RAMCFG);
5722 if (tmp & CHANSIZE_MASK) {
5727 tmp = RREG32(MC_SHARED_CHMAP);
5728 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
5758 rdev->mc.vram_width = numchan * chansize;
5759 /* Could aper size report 0 ? */
5760 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
5761 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
5762 /* size in MB on si */
5763 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
5764 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
5765 rdev->mc.visible_vram_size = rdev->mc.aper_size;
5766 si_vram_gtt_location(rdev, &rdev->mc);
5767 radeon_update_bandwidth_info(rdev);
5774 * VMID 0 is the physical GPU addresses as used by the kernel.
5775 * VMIDs 1-15 are used for userspace clients and are handled
5776 * by the radeon vm/hsa code.
5779 * cik_pcie_gart_tlb_flush - gart tlb flush callback
5781 * @rdev: radeon_device pointer
5783 * Flush the TLB for the VMID 0 page table (CIK).
5785 void cik_pcie_gart_tlb_flush(struct radeon_device *rdev)
5787 /* flush hdp cache */
5788 WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0);
5790 /* bits 0-15 are the VM contexts0-15 */
5791 WREG32(VM_INVALIDATE_REQUEST, 0x1);
5794 static void cik_pcie_init_compute_vmid(struct radeon_device *rdev)
5797 uint32_t sh_mem_bases, sh_mem_config;
5799 sh_mem_bases = 0x6000 | 0x6000 << 16;
5800 sh_mem_config = ALIGNMENT_MODE(SH_MEM_ALIGNMENT_MODE_UNALIGNED);
5801 sh_mem_config |= DEFAULT_MTYPE(MTYPE_NONCACHED);
5803 mutex_lock(&rdev->srbm_mutex);
5804 for (i = 8; i < 16; i++) {
5805 cik_srbm_select(rdev, 0, 0, 0, i);
5806 /* CP and shaders */
5807 WREG32(SH_MEM_CONFIG, sh_mem_config);
5808 WREG32(SH_MEM_APE1_BASE, 1);
5809 WREG32(SH_MEM_APE1_LIMIT, 0);
5810 WREG32(SH_MEM_BASES, sh_mem_bases);
5812 cik_srbm_select(rdev, 0, 0, 0, 0);
5813 mutex_unlock(&rdev->srbm_mutex);
5817 * cik_pcie_gart_enable - gart enable
5819 * @rdev: radeon_device pointer
5821 * This sets up the TLBs, programs the page tables for VMID0,
5822 * sets up the hw for VMIDs 1-15 which are allocated on
5823 * demand, and sets up the global locations for the LDS, GDS,
5824 * and GPUVM for FSA64 clients (CIK).
5825 * Returns 0 for success, errors for failure.
5827 static int cik_pcie_gart_enable(struct radeon_device *rdev)
5831 if (rdev->gart.robj == NULL) {
5832 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
5835 r = radeon_gart_table_vram_pin(rdev);
5838 /* Setup TLB control */
5839 WREG32(MC_VM_MX_L1_TLB_CNTL,
5842 ENABLE_L1_FRAGMENT_PROCESSING |
5843 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
5844 ENABLE_ADVANCED_DRIVER_MODEL |
5845 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
5846 /* Setup L2 cache */
5847 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
5848 ENABLE_L2_FRAGMENT_PROCESSING |
5849 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
5850 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
5851 EFFECTIVE_L2_QUEUE_SIZE(7) |
5852 CONTEXT1_IDENTITY_ACCESS_MODE(1));
5853 WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
5854 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
5856 L2_CACHE_BIGK_FRAGMENT_SIZE(4));
5857 /* setup context0 */
5858 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
5859 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
5860 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
5861 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
5862 (u32)(rdev->dummy_page.addr >> 12));
5863 WREG32(VM_CONTEXT0_CNTL2, 0);
5864 WREG32(VM_CONTEXT0_CNTL, (ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
5865 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT));
5871 /* restore context1-15 */
5872 /* set vm size, must be a multiple of 4 */
5873 WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
5874 WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn - 1);
5875 for (i = 1; i < 16; i++) {
5877 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
5878 rdev->vm_manager.saved_table_addr[i]);
5880 WREG32(VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2),
5881 rdev->vm_manager.saved_table_addr[i]);
5884 /* enable context1-15 */
5885 WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
5886 (u32)(rdev->dummy_page.addr >> 12));
5887 WREG32(VM_CONTEXT1_CNTL2, 4);
5888 WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
5889 PAGE_TABLE_BLOCK_SIZE(radeon_vm_block_size - 9) |
5890 RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
5891 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
5892 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
5893 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
5894 PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
5895 PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
5896 VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
5897 VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
5898 READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
5899 READ_PROTECTION_FAULT_ENABLE_DEFAULT |
5900 WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
5901 WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
5903 if (rdev->family == CHIP_KAVERI) {
5904 u32 tmp = RREG32(CHUB_CONTROL);
5906 WREG32(CHUB_CONTROL, tmp);
5909 /* XXX SH_MEM regs */
5910 /* where to put LDS, scratch, GPUVM in FSA64 space */
5911 mutex_lock(&rdev->srbm_mutex);
5912 for (i = 0; i < 16; i++) {
5913 cik_srbm_select(rdev, 0, 0, 0, i);
5914 /* CP and shaders */
5915 WREG32(SH_MEM_CONFIG, 0);
5916 WREG32(SH_MEM_APE1_BASE, 1);
5917 WREG32(SH_MEM_APE1_LIMIT, 0);
5918 WREG32(SH_MEM_BASES, 0);
5920 WREG32(SDMA0_GFX_VIRTUAL_ADDR + SDMA0_REGISTER_OFFSET, 0);
5921 WREG32(SDMA0_GFX_APE1_CNTL + SDMA0_REGISTER_OFFSET, 0);
5922 WREG32(SDMA0_GFX_VIRTUAL_ADDR + SDMA1_REGISTER_OFFSET, 0);
5923 WREG32(SDMA0_GFX_APE1_CNTL + SDMA1_REGISTER_OFFSET, 0);
5924 /* XXX SDMA RLC - todo */
5926 cik_srbm_select(rdev, 0, 0, 0, 0);
5927 mutex_unlock(&rdev->srbm_mutex);
5929 cik_pcie_init_compute_vmid(rdev);
5931 cik_pcie_gart_tlb_flush(rdev);
5932 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
5933 (unsigned)(rdev->mc.gtt_size >> 20),
5934 (unsigned long long)rdev->gart.table_addr);
5935 rdev->gart.ready = true;
5940 * cik_pcie_gart_disable - gart disable
5942 * @rdev: radeon_device pointer
5944 * This disables all VM page table (CIK).
5946 static void cik_pcie_gart_disable(struct radeon_device *rdev)
5950 for (i = 1; i < 16; ++i) {
5953 reg = VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2);
5955 reg = VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2);
5956 rdev->vm_manager.saved_table_addr[i] = RREG32(reg);
5959 /* Disable all tables */
5960 WREG32(VM_CONTEXT0_CNTL, 0);
5961 WREG32(VM_CONTEXT1_CNTL, 0);
5962 /* Setup TLB control */
5963 WREG32(MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE_NOT_IN_SYS |
5964 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
5965 /* Setup L2 cache */
5967 ENABLE_L2_FRAGMENT_PROCESSING |
5968 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
5969 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
5970 EFFECTIVE_L2_QUEUE_SIZE(7) |
5971 CONTEXT1_IDENTITY_ACCESS_MODE(1));
5972 WREG32(VM_L2_CNTL2, 0);
5973 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
5974 L2_CACHE_BIGK_FRAGMENT_SIZE(6));
5975 radeon_gart_table_vram_unpin(rdev);
5979 * cik_pcie_gart_fini - vm fini callback
5981 * @rdev: radeon_device pointer
5983 * Tears down the driver GART/VM setup (CIK).
5985 static void cik_pcie_gart_fini(struct radeon_device *rdev)
5987 cik_pcie_gart_disable(rdev);
5988 radeon_gart_table_vram_free(rdev);
5989 radeon_gart_fini(rdev);
5994 * cik_ib_parse - vm ib_parse callback
5996 * @rdev: radeon_device pointer
5997 * @ib: indirect buffer pointer
5999 * CIK uses hw IB checking so this is a nop (CIK).
6001 int cik_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
6008 * VMID 0 is the physical GPU addresses as used by the kernel.
6009 * VMIDs 1-15 are used for userspace clients and are handled
6010 * by the radeon vm/hsa code.
6013 * cik_vm_init - cik vm init callback
6015 * @rdev: radeon_device pointer
6017 * Inits cik specific vm parameters (number of VMs, base of vram for
6018 * VMIDs 1-15) (CIK).
6019 * Returns 0 for success.
6021 int cik_vm_init(struct radeon_device *rdev)
6025 * VMID 0 is reserved for System
6026 * radeon graphics/compute will use VMIDs 1-7
6027 * amdkfd will use VMIDs 8-15
6029 rdev->vm_manager.nvm = RADEON_NUM_OF_VMIDS;
6030 /* base offset of vram pages */
6031 if (rdev->flags & RADEON_IS_IGP) {
6032 u64 tmp = RREG32(MC_VM_FB_OFFSET);
6034 rdev->vm_manager.vram_base_offset = tmp;
6036 rdev->vm_manager.vram_base_offset = 0;
6042 * cik_vm_fini - cik vm fini callback
6044 * @rdev: radeon_device pointer
6046 * Tear down any asic specific VM setup (CIK).
6048 void cik_vm_fini(struct radeon_device *rdev)
6053 * cik_vm_decode_fault - print human readable fault info
6055 * @rdev: radeon_device pointer
6056 * @status: VM_CONTEXT1_PROTECTION_FAULT_STATUS register value
6057 * @addr: VM_CONTEXT1_PROTECTION_FAULT_ADDR register value
6059 * Print human readable fault information (CIK).
6061 static void cik_vm_decode_fault(struct radeon_device *rdev,
6062 u32 status, u32 addr, u32 mc_client)
6065 u32 vmid = (status & FAULT_VMID_MASK) >> FAULT_VMID_SHIFT;
6066 u32 protections = (status & PROTECTIONS_MASK) >> PROTECTIONS_SHIFT;
6067 char block[5] = { mc_client >> 24, (mc_client >> 16) & 0xff,
6068 (mc_client >> 8) & 0xff, mc_client & 0xff, 0 };
6070 if (rdev->family == CHIP_HAWAII)
6071 mc_id = (status & HAWAII_MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
6073 mc_id = (status & MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
6075 printk("VM fault (0x%02x, vmid %d) at page %u, %s from '%s' (0x%08x) (%d)\n",
6076 protections, vmid, addr,
6077 (status & MEMORY_CLIENT_RW_MASK) ? "write" : "read",
6078 block, mc_client, mc_id);
6082 * cik_vm_flush - cik vm flush using the CP
6084 * @rdev: radeon_device pointer
6086 * Update the page table base and flush the VM TLB
6087 * using the CP (CIK).
6089 void cik_vm_flush(struct radeon_device *rdev, struct radeon_ring *ring,
6090 unsigned vm_id, uint64_t pd_addr)
6092 int usepfp = (ring->idx == RADEON_RING_TYPE_GFX_INDEX);
6094 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
6095 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
6096 WRITE_DATA_DST_SEL(0)));
6098 radeon_ring_write(ring,
6099 (VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm_id << 2)) >> 2);
6101 radeon_ring_write(ring,
6102 (VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm_id - 8) << 2)) >> 2);
6104 radeon_ring_write(ring, 0);
6105 radeon_ring_write(ring, pd_addr >> 12);
6107 /* update SH_MEM_* regs */
6108 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
6109 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
6110 WRITE_DATA_DST_SEL(0)));
6111 radeon_ring_write(ring, SRBM_GFX_CNTL >> 2);
6112 radeon_ring_write(ring, 0);
6113 radeon_ring_write(ring, VMID(vm_id));
6115 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 6));
6116 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
6117 WRITE_DATA_DST_SEL(0)));
6118 radeon_ring_write(ring, SH_MEM_BASES >> 2);
6119 radeon_ring_write(ring, 0);
6121 radeon_ring_write(ring, 0); /* SH_MEM_BASES */
6122 radeon_ring_write(ring, 0); /* SH_MEM_CONFIG */
6123 radeon_ring_write(ring, 1); /* SH_MEM_APE1_BASE */
6124 radeon_ring_write(ring, 0); /* SH_MEM_APE1_LIMIT */
6126 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
6127 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
6128 WRITE_DATA_DST_SEL(0)));
6129 radeon_ring_write(ring, SRBM_GFX_CNTL >> 2);
6130 radeon_ring_write(ring, 0);
6131 radeon_ring_write(ring, VMID(0));
6134 cik_hdp_flush_cp_ring_emit(rdev, ring->idx);
6136 /* bits 0-15 are the VM contexts0-15 */
6137 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
6138 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
6139 WRITE_DATA_DST_SEL(0)));
6140 radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
6141 radeon_ring_write(ring, 0);
6142 radeon_ring_write(ring, 1 << vm_id);
6144 /* wait for the invalidate to complete */
6145 radeon_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
6146 radeon_ring_write(ring, (WAIT_REG_MEM_OPERATION(0) | /* wait */
6147 WAIT_REG_MEM_FUNCTION(0) | /* always */
6148 WAIT_REG_MEM_ENGINE(0))); /* me */
6149 radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
6150 radeon_ring_write(ring, 0);
6151 radeon_ring_write(ring, 0); /* ref */
6152 radeon_ring_write(ring, 0); /* mask */
6153 radeon_ring_write(ring, 0x20); /* poll interval */
6155 /* compute doesn't have PFP */
6157 /* sync PFP to ME, otherwise we might get invalid PFP reads */
6158 radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
6159 radeon_ring_write(ring, 0x0);
6165 * The RLC is a multi-purpose microengine that handles a
6166 * variety of functions, the most important of which is
6167 * the interrupt controller.
6169 static void cik_enable_gui_idle_interrupt(struct radeon_device *rdev,
6172 u32 tmp = RREG32(CP_INT_CNTL_RING0);
6175 tmp |= (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
6177 tmp &= ~(CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
6178 WREG32(CP_INT_CNTL_RING0, tmp);
6181 static void cik_enable_lbpw(struct radeon_device *rdev, bool enable)
6185 tmp = RREG32(RLC_LB_CNTL);
6187 tmp |= LOAD_BALANCE_ENABLE;
6189 tmp &= ~LOAD_BALANCE_ENABLE;
6190 WREG32(RLC_LB_CNTL, tmp);
6193 static void cik_wait_for_rlc_serdes(struct radeon_device *rdev)
6198 mutex_lock(&rdev->grbm_idx_mutex);
6199 for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
6200 for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
6201 cik_select_se_sh(rdev, i, j);
6202 for (k = 0; k < rdev->usec_timeout; k++) {
6203 if (RREG32(RLC_SERDES_CU_MASTER_BUSY) == 0)
6209 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
6210 mutex_unlock(&rdev->grbm_idx_mutex);
6212 mask = SE_MASTER_BUSY_MASK | GC_MASTER_BUSY | TC0_MASTER_BUSY | TC1_MASTER_BUSY;
6213 for (k = 0; k < rdev->usec_timeout; k++) {
6214 if ((RREG32(RLC_SERDES_NONCU_MASTER_BUSY) & mask) == 0)
6220 static void cik_update_rlc(struct radeon_device *rdev, u32 rlc)
6224 tmp = RREG32(RLC_CNTL);
6226 WREG32(RLC_CNTL, rlc);
6229 static u32 cik_halt_rlc(struct radeon_device *rdev)
6233 orig = data = RREG32(RLC_CNTL);
6235 if (data & RLC_ENABLE) {
6238 data &= ~RLC_ENABLE;
6239 WREG32(RLC_CNTL, data);
6241 for (i = 0; i < rdev->usec_timeout; i++) {
6242 if ((RREG32(RLC_GPM_STAT) & RLC_GPM_BUSY) == 0)
6247 cik_wait_for_rlc_serdes(rdev);
6253 void cik_enter_rlc_safe_mode(struct radeon_device *rdev)
6257 tmp = REQ | MESSAGE(MSG_ENTER_RLC_SAFE_MODE);
6258 WREG32(RLC_GPR_REG2, tmp);
6260 mask = GFX_POWER_STATUS | GFX_CLOCK_STATUS;
6261 for (i = 0; i < rdev->usec_timeout; i++) {
6262 if ((RREG32(RLC_GPM_STAT) & mask) == mask)
6267 for (i = 0; i < rdev->usec_timeout; i++) {
6268 if ((RREG32(RLC_GPR_REG2) & REQ) == 0)
6274 void cik_exit_rlc_safe_mode(struct radeon_device *rdev)
6278 tmp = REQ | MESSAGE(MSG_EXIT_RLC_SAFE_MODE);
6279 WREG32(RLC_GPR_REG2, tmp);
6283 * cik_rlc_stop - stop the RLC ME
6285 * @rdev: radeon_device pointer
6287 * Halt the RLC ME (MicroEngine) (CIK).
6289 static void cik_rlc_stop(struct radeon_device *rdev)
6291 WREG32(RLC_CNTL, 0);
6293 cik_enable_gui_idle_interrupt(rdev, false);
6295 cik_wait_for_rlc_serdes(rdev);
6299 * cik_rlc_start - start the RLC ME
6301 * @rdev: radeon_device pointer
6303 * Unhalt the RLC ME (MicroEngine) (CIK).
6305 static void cik_rlc_start(struct radeon_device *rdev)
6307 WREG32(RLC_CNTL, RLC_ENABLE);
6309 cik_enable_gui_idle_interrupt(rdev, true);
6315 * cik_rlc_resume - setup the RLC hw
6317 * @rdev: radeon_device pointer
6319 * Initialize the RLC registers, load the ucode,
6320 * and start the RLC (CIK).
6321 * Returns 0 for success, -EINVAL if the ucode is not available.
6323 static int cik_rlc_resume(struct radeon_device *rdev)
6333 tmp = RREG32(RLC_CGCG_CGLS_CTRL) & 0xfffffffc;
6334 WREG32(RLC_CGCG_CGLS_CTRL, tmp);
6342 WREG32(RLC_LB_CNTR_INIT, 0);
6343 WREG32(RLC_LB_CNTR_MAX, 0x00008000);
6345 mutex_lock(&rdev->grbm_idx_mutex);
6346 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
6347 WREG32(RLC_LB_INIT_CU_MASK, 0xffffffff);
6348 WREG32(RLC_LB_PARAMS, 0x00600408);
6349 WREG32(RLC_LB_CNTL, 0x80000004);
6350 mutex_unlock(&rdev->grbm_idx_mutex);
6352 WREG32(RLC_MC_CNTL, 0);
6353 WREG32(RLC_UCODE_CNTL, 0);
6356 const struct rlc_firmware_header_v1_0 *hdr =
6357 (const struct rlc_firmware_header_v1_0 *)rdev->rlc_fw->data;
6358 const __le32 *fw_data = (const __le32 *)
6359 (rdev->rlc_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6361 radeon_ucode_print_rlc_hdr(&hdr->header);
6363 size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
6364 WREG32(RLC_GPM_UCODE_ADDR, 0);
6365 for (i = 0; i < size; i++)
6366 WREG32(RLC_GPM_UCODE_DATA, le32_to_cpup(fw_data++));
6367 WREG32(RLC_GPM_UCODE_ADDR, le32_to_cpu(hdr->header.ucode_version));
6369 const __be32 *fw_data;
6371 switch (rdev->family) {
6375 size = BONAIRE_RLC_UCODE_SIZE;
6378 size = KV_RLC_UCODE_SIZE;
6381 size = KB_RLC_UCODE_SIZE;
6384 size = ML_RLC_UCODE_SIZE;
6388 fw_data = (const __be32 *)rdev->rlc_fw->data;
6389 WREG32(RLC_GPM_UCODE_ADDR, 0);
6390 for (i = 0; i < size; i++)
6391 WREG32(RLC_GPM_UCODE_DATA, be32_to_cpup(fw_data++));
6392 WREG32(RLC_GPM_UCODE_ADDR, 0);
6395 /* XXX - find out what chips support lbpw */
6396 cik_enable_lbpw(rdev, false);
6398 if (rdev->family == CHIP_BONAIRE)
6399 WREG32(RLC_DRIVER_DMA_STATUS, 0);
6401 cik_rlc_start(rdev);
6406 static void cik_enable_cgcg(struct radeon_device *rdev, bool enable)
6408 u32 data, orig, tmp, tmp2;
6410 orig = data = RREG32(RLC_CGCG_CGLS_CTRL);
6412 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGCG)) {
6413 cik_enable_gui_idle_interrupt(rdev, true);
6415 tmp = cik_halt_rlc(rdev);
6417 mutex_lock(&rdev->grbm_idx_mutex);
6418 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
6419 WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
6420 WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
6421 tmp2 = BPM_ADDR_MASK | CGCG_OVERRIDE_0 | CGLS_ENABLE;
6422 WREG32(RLC_SERDES_WR_CTRL, tmp2);
6423 mutex_unlock(&rdev->grbm_idx_mutex);
6425 cik_update_rlc(rdev, tmp);
6427 data |= CGCG_EN | CGLS_EN;
6429 cik_enable_gui_idle_interrupt(rdev, false);
6431 RREG32(CB_CGTT_SCLK_CTRL);
6432 RREG32(CB_CGTT_SCLK_CTRL);
6433 RREG32(CB_CGTT_SCLK_CTRL);
6434 RREG32(CB_CGTT_SCLK_CTRL);
6436 data &= ~(CGCG_EN | CGLS_EN);
6440 WREG32(RLC_CGCG_CGLS_CTRL, data);
6444 static void cik_enable_mgcg(struct radeon_device *rdev, bool enable)
6446 u32 data, orig, tmp = 0;
6448 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGCG)) {
6449 if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGLS) {
6450 if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CP_LS) {
6451 orig = data = RREG32(CP_MEM_SLP_CNTL);
6452 data |= CP_MEM_LS_EN;
6454 WREG32(CP_MEM_SLP_CNTL, data);
6458 orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
6462 WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
6464 tmp = cik_halt_rlc(rdev);
6466 mutex_lock(&rdev->grbm_idx_mutex);
6467 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
6468 WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
6469 WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
6470 data = BPM_ADDR_MASK | MGCG_OVERRIDE_0;
6471 WREG32(RLC_SERDES_WR_CTRL, data);
6472 mutex_unlock(&rdev->grbm_idx_mutex);
6474 cik_update_rlc(rdev, tmp);
6476 if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGTS) {
6477 orig = data = RREG32(CGTS_SM_CTRL_REG);
6478 data &= ~SM_MODE_MASK;
6479 data |= SM_MODE(0x2);
6480 data |= SM_MODE_ENABLE;
6481 data &= ~CGTS_OVERRIDE;
6482 if ((rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGLS) &&
6483 (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGTS_LS))
6484 data &= ~CGTS_LS_OVERRIDE;
6485 data &= ~ON_MONITOR_ADD_MASK;
6486 data |= ON_MONITOR_ADD_EN;
6487 data |= ON_MONITOR_ADD(0x96);
6489 WREG32(CGTS_SM_CTRL_REG, data);
6492 orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
6495 WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
6497 data = RREG32(RLC_MEM_SLP_CNTL);
6498 if (data & RLC_MEM_LS_EN) {
6499 data &= ~RLC_MEM_LS_EN;
6500 WREG32(RLC_MEM_SLP_CNTL, data);
6503 data = RREG32(CP_MEM_SLP_CNTL);
6504 if (data & CP_MEM_LS_EN) {
6505 data &= ~CP_MEM_LS_EN;
6506 WREG32(CP_MEM_SLP_CNTL, data);
6509 orig = data = RREG32(CGTS_SM_CTRL_REG);
6510 data |= CGTS_OVERRIDE | CGTS_LS_OVERRIDE;
6512 WREG32(CGTS_SM_CTRL_REG, data);
6514 tmp = cik_halt_rlc(rdev);
6516 mutex_lock(&rdev->grbm_idx_mutex);
6517 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
6518 WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
6519 WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
6520 data = BPM_ADDR_MASK | MGCG_OVERRIDE_1;
6521 WREG32(RLC_SERDES_WR_CTRL, data);
6522 mutex_unlock(&rdev->grbm_idx_mutex);
6524 cik_update_rlc(rdev, tmp);
6528 static const u32 mc_cg_registers[] =
6541 static void cik_enable_mc_ls(struct radeon_device *rdev,
6547 for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
6548 orig = data = RREG32(mc_cg_registers[i]);
6549 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_LS))
6550 data |= MC_LS_ENABLE;
6552 data &= ~MC_LS_ENABLE;
6554 WREG32(mc_cg_registers[i], data);
6558 static void cik_enable_mc_mgcg(struct radeon_device *rdev,
6564 for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
6565 orig = data = RREG32(mc_cg_registers[i]);
6566 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_MGCG))
6567 data |= MC_CG_ENABLE;
6569 data &= ~MC_CG_ENABLE;
6571 WREG32(mc_cg_registers[i], data);
6575 static void cik_enable_sdma_mgcg(struct radeon_device *rdev,
6580 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_MGCG)) {
6581 WREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET, 0x00000100);
6582 WREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET, 0x00000100);
6584 orig = data = RREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET);
6587 WREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET, data);
6589 orig = data = RREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET);
6592 WREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET, data);
6596 static void cik_enable_sdma_mgls(struct radeon_device *rdev,
6601 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_LS)) {
6602 orig = data = RREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET);
6605 WREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET, data);
6607 orig = data = RREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET);
6610 WREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET, data);
6612 orig = data = RREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET);
6615 WREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET, data);
6617 orig = data = RREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET);
6620 WREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET, data);
6624 static void cik_enable_uvd_mgcg(struct radeon_device *rdev,
6629 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_UVD_MGCG)) {
6630 data = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
6632 WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, data);
6634 orig = data = RREG32(UVD_CGC_CTRL);
6637 WREG32(UVD_CGC_CTRL, data);
6639 data = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
6641 WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, data);
6643 orig = data = RREG32(UVD_CGC_CTRL);
6646 WREG32(UVD_CGC_CTRL, data);
6650 static void cik_enable_bif_mgls(struct radeon_device *rdev,
6655 orig = data = RREG32_PCIE_PORT(PCIE_CNTL2);
6657 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_BIF_LS))
6658 data |= SLV_MEM_LS_EN | MST_MEM_LS_EN |
6659 REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN;
6661 data &= ~(SLV_MEM_LS_EN | MST_MEM_LS_EN |
6662 REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN);
6665 WREG32_PCIE_PORT(PCIE_CNTL2, data);
6668 static void cik_enable_hdp_mgcg(struct radeon_device *rdev,
6673 orig = data = RREG32(HDP_HOST_PATH_CNTL);
6675 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_MGCG))
6676 data &= ~CLOCK_GATING_DIS;
6678 data |= CLOCK_GATING_DIS;
6681 WREG32(HDP_HOST_PATH_CNTL, data);
6684 static void cik_enable_hdp_ls(struct radeon_device *rdev,
6689 orig = data = RREG32(HDP_MEM_POWER_LS);
6691 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_LS))
6692 data |= HDP_LS_ENABLE;
6694 data &= ~HDP_LS_ENABLE;
6697 WREG32(HDP_MEM_POWER_LS, data);
6700 void cik_update_cg(struct radeon_device *rdev,
6701 u32 block, bool enable)
6704 if (block & RADEON_CG_BLOCK_GFX) {
6705 cik_enable_gui_idle_interrupt(rdev, false);
6706 /* order matters! */
6708 cik_enable_mgcg(rdev, true);
6709 cik_enable_cgcg(rdev, true);
6711 cik_enable_cgcg(rdev, false);
6712 cik_enable_mgcg(rdev, false);
6714 cik_enable_gui_idle_interrupt(rdev, true);
6717 if (block & RADEON_CG_BLOCK_MC) {
6718 if (!(rdev->flags & RADEON_IS_IGP)) {
6719 cik_enable_mc_mgcg(rdev, enable);
6720 cik_enable_mc_ls(rdev, enable);
6724 if (block & RADEON_CG_BLOCK_SDMA) {
6725 cik_enable_sdma_mgcg(rdev, enable);
6726 cik_enable_sdma_mgls(rdev, enable);
6729 if (block & RADEON_CG_BLOCK_BIF) {
6730 cik_enable_bif_mgls(rdev, enable);
6733 if (block & RADEON_CG_BLOCK_UVD) {
6735 cik_enable_uvd_mgcg(rdev, enable);
6738 if (block & RADEON_CG_BLOCK_HDP) {
6739 cik_enable_hdp_mgcg(rdev, enable);
6740 cik_enable_hdp_ls(rdev, enable);
6743 if (block & RADEON_CG_BLOCK_VCE) {
6744 vce_v2_0_enable_mgcg(rdev, enable);
6748 static void cik_init_cg(struct radeon_device *rdev)
6751 cik_update_cg(rdev, RADEON_CG_BLOCK_GFX, true);
6754 si_init_uvd_internal_cg(rdev);
6756 cik_update_cg(rdev, (RADEON_CG_BLOCK_MC |
6757 RADEON_CG_BLOCK_SDMA |
6758 RADEON_CG_BLOCK_BIF |
6759 RADEON_CG_BLOCK_UVD |
6760 RADEON_CG_BLOCK_HDP), true);
6763 static void cik_fini_cg(struct radeon_device *rdev)
6765 cik_update_cg(rdev, (RADEON_CG_BLOCK_MC |
6766 RADEON_CG_BLOCK_SDMA |
6767 RADEON_CG_BLOCK_BIF |
6768 RADEON_CG_BLOCK_UVD |
6769 RADEON_CG_BLOCK_HDP), false);
6771 cik_update_cg(rdev, RADEON_CG_BLOCK_GFX, false);
6774 static void cik_enable_sck_slowdown_on_pu(struct radeon_device *rdev,
6779 orig = data = RREG32(RLC_PG_CNTL);
6780 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_RLC_SMU_HS))
6781 data |= SMU_CLK_SLOWDOWN_ON_PU_ENABLE;
6783 data &= ~SMU_CLK_SLOWDOWN_ON_PU_ENABLE;
6785 WREG32(RLC_PG_CNTL, data);
6788 static void cik_enable_sck_slowdown_on_pd(struct radeon_device *rdev,
6793 orig = data = RREG32(RLC_PG_CNTL);
6794 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_RLC_SMU_HS))
6795 data |= SMU_CLK_SLOWDOWN_ON_PD_ENABLE;
6797 data &= ~SMU_CLK_SLOWDOWN_ON_PD_ENABLE;
6799 WREG32(RLC_PG_CNTL, data);
6802 static void cik_enable_cp_pg(struct radeon_device *rdev, bool enable)
6806 orig = data = RREG32(RLC_PG_CNTL);
6807 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_CP))
6808 data &= ~DISABLE_CP_PG;
6810 data |= DISABLE_CP_PG;
6812 WREG32(RLC_PG_CNTL, data);
6815 static void cik_enable_gds_pg(struct radeon_device *rdev, bool enable)
6819 orig = data = RREG32(RLC_PG_CNTL);
6820 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GDS))
6821 data &= ~DISABLE_GDS_PG;
6823 data |= DISABLE_GDS_PG;
6825 WREG32(RLC_PG_CNTL, data);
6828 #define CP_ME_TABLE_SIZE 96
6829 #define CP_ME_TABLE_OFFSET 2048
6830 #define CP_MEC_TABLE_OFFSET 4096
6832 void cik_init_cp_pg_table(struct radeon_device *rdev)
6834 volatile u32 *dst_ptr;
6835 int me, i, max_me = 4;
6837 u32 table_offset, table_size;
6839 if (rdev->family == CHIP_KAVERI)
6842 if (rdev->rlc.cp_table_ptr == NULL)
6845 /* write the cp table buffer */
6846 dst_ptr = rdev->rlc.cp_table_ptr;
6847 for (me = 0; me < max_me; me++) {
6849 const __le32 *fw_data;
6850 const struct gfx_firmware_header_v1_0 *hdr;
6853 hdr = (const struct gfx_firmware_header_v1_0 *)rdev->ce_fw->data;
6854 fw_data = (const __le32 *)
6855 (rdev->ce_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6856 table_offset = le32_to_cpu(hdr->jt_offset);
6857 table_size = le32_to_cpu(hdr->jt_size);
6858 } else if (me == 1) {
6859 hdr = (const struct gfx_firmware_header_v1_0 *)rdev->pfp_fw->data;
6860 fw_data = (const __le32 *)
6861 (rdev->pfp_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6862 table_offset = le32_to_cpu(hdr->jt_offset);
6863 table_size = le32_to_cpu(hdr->jt_size);
6864 } else if (me == 2) {
6865 hdr = (const struct gfx_firmware_header_v1_0 *)rdev->me_fw->data;
6866 fw_data = (const __le32 *)
6867 (rdev->me_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6868 table_offset = le32_to_cpu(hdr->jt_offset);
6869 table_size = le32_to_cpu(hdr->jt_size);
6870 } else if (me == 3) {
6871 hdr = (const struct gfx_firmware_header_v1_0 *)rdev->mec_fw->data;
6872 fw_data = (const __le32 *)
6873 (rdev->mec_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6874 table_offset = le32_to_cpu(hdr->jt_offset);
6875 table_size = le32_to_cpu(hdr->jt_size);
6877 hdr = (const struct gfx_firmware_header_v1_0 *)rdev->mec2_fw->data;
6878 fw_data = (const __le32 *)
6879 (rdev->mec2_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
6880 table_offset = le32_to_cpu(hdr->jt_offset);
6881 table_size = le32_to_cpu(hdr->jt_size);
6884 for (i = 0; i < table_size; i ++) {
6885 dst_ptr[bo_offset + i] =
6886 cpu_to_le32(le32_to_cpu(fw_data[table_offset + i]));
6888 bo_offset += table_size;
6890 const __be32 *fw_data;
6891 table_size = CP_ME_TABLE_SIZE;
6894 fw_data = (const __be32 *)rdev->ce_fw->data;
6895 table_offset = CP_ME_TABLE_OFFSET;
6896 } else if (me == 1) {
6897 fw_data = (const __be32 *)rdev->pfp_fw->data;
6898 table_offset = CP_ME_TABLE_OFFSET;
6899 } else if (me == 2) {
6900 fw_data = (const __be32 *)rdev->me_fw->data;
6901 table_offset = CP_ME_TABLE_OFFSET;
6903 fw_data = (const __be32 *)rdev->mec_fw->data;
6904 table_offset = CP_MEC_TABLE_OFFSET;
6907 for (i = 0; i < table_size; i ++) {
6908 dst_ptr[bo_offset + i] =
6909 cpu_to_le32(be32_to_cpu(fw_data[table_offset + i]));
6911 bo_offset += table_size;
6916 static void cik_enable_gfx_cgpg(struct radeon_device *rdev,
6921 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG)) {
6922 orig = data = RREG32(RLC_PG_CNTL);
6923 data |= GFX_PG_ENABLE;
6925 WREG32(RLC_PG_CNTL, data);
6927 orig = data = RREG32(RLC_AUTO_PG_CTRL);
6930 WREG32(RLC_AUTO_PG_CTRL, data);
6932 orig = data = RREG32(RLC_PG_CNTL);
6933 data &= ~GFX_PG_ENABLE;
6935 WREG32(RLC_PG_CNTL, data);
6937 orig = data = RREG32(RLC_AUTO_PG_CTRL);
6938 data &= ~AUTO_PG_EN;
6940 WREG32(RLC_AUTO_PG_CTRL, data);
6942 data = RREG32(DB_RENDER_CONTROL);
6946 static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh)
6948 u32 mask = 0, tmp, tmp1;
6951 mutex_lock(&rdev->grbm_idx_mutex);
6952 cik_select_se_sh(rdev, se, sh);
6953 tmp = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
6954 tmp1 = RREG32(GC_USER_SHADER_ARRAY_CONFIG);
6955 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
6956 mutex_unlock(&rdev->grbm_idx_mutex);
6963 for (i = 0; i < rdev->config.cik.max_cu_per_sh; i ++) {
6968 return (~tmp) & mask;
6971 static void cik_init_ao_cu_mask(struct radeon_device *rdev)
6973 u32 i, j, k, active_cu_number = 0;
6974 u32 mask, counter, cu_bitmap;
6977 for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
6978 for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
6982 for (k = 0; k < rdev->config.cik.max_cu_per_sh; k ++) {
6983 if (cik_get_cu_active_bitmap(rdev, i, j) & mask) {
6991 active_cu_number += counter;
6992 tmp |= (cu_bitmap << (i * 16 + j * 8));
6996 WREG32(RLC_PG_AO_CU_MASK, tmp);
6998 tmp = RREG32(RLC_MAX_PG_CU);
6999 tmp &= ~MAX_PU_CU_MASK;
7000 tmp |= MAX_PU_CU(active_cu_number);
7001 WREG32(RLC_MAX_PG_CU, tmp);
7004 static void cik_enable_gfx_static_mgpg(struct radeon_device *rdev,
7009 orig = data = RREG32(RLC_PG_CNTL);
7010 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_SMG))
7011 data |= STATIC_PER_CU_PG_ENABLE;
7013 data &= ~STATIC_PER_CU_PG_ENABLE;
7015 WREG32(RLC_PG_CNTL, data);
7018 static void cik_enable_gfx_dynamic_mgpg(struct radeon_device *rdev,
7023 orig = data = RREG32(RLC_PG_CNTL);
7024 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_DMG))
7025 data |= DYN_PER_CU_PG_ENABLE;
7027 data &= ~DYN_PER_CU_PG_ENABLE;
7029 WREG32(RLC_PG_CNTL, data);
7032 #define RLC_SAVE_AND_RESTORE_STARTING_OFFSET 0x90
7033 #define RLC_CLEAR_STATE_DESCRIPTOR_OFFSET 0x3D
7035 static void cik_init_gfx_cgpg(struct radeon_device *rdev)
7040 if (rdev->rlc.cs_data) {
7041 WREG32(RLC_GPM_SCRATCH_ADDR, RLC_CLEAR_STATE_DESCRIPTOR_OFFSET);
7042 WREG32(RLC_GPM_SCRATCH_DATA, upper_32_bits(rdev->rlc.clear_state_gpu_addr));
7043 WREG32(RLC_GPM_SCRATCH_DATA, lower_32_bits(rdev->rlc.clear_state_gpu_addr));
7044 WREG32(RLC_GPM_SCRATCH_DATA, rdev->rlc.clear_state_size);
7046 WREG32(RLC_GPM_SCRATCH_ADDR, RLC_CLEAR_STATE_DESCRIPTOR_OFFSET);
7047 for (i = 0; i < 3; i++)
7048 WREG32(RLC_GPM_SCRATCH_DATA, 0);
7050 if (rdev->rlc.reg_list) {
7051 WREG32(RLC_GPM_SCRATCH_ADDR, RLC_SAVE_AND_RESTORE_STARTING_OFFSET);
7052 for (i = 0; i < rdev->rlc.reg_list_size; i++)
7053 WREG32(RLC_GPM_SCRATCH_DATA, rdev->rlc.reg_list[i]);
7056 orig = data = RREG32(RLC_PG_CNTL);
7059 WREG32(RLC_PG_CNTL, data);
7061 WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
7062 WREG32(RLC_CP_TABLE_RESTORE, rdev->rlc.cp_table_gpu_addr >> 8);
7064 data = RREG32(CP_RB_WPTR_POLL_CNTL);
7065 data &= ~IDLE_POLL_COUNT_MASK;
7066 data |= IDLE_POLL_COUNT(0x60);
7067 WREG32(CP_RB_WPTR_POLL_CNTL, data);
7070 WREG32(RLC_PG_DELAY, data);
7072 data = RREG32(RLC_PG_DELAY_2);
7075 WREG32(RLC_PG_DELAY_2, data);
7077 data = RREG32(RLC_AUTO_PG_CTRL);
7078 data &= ~GRBM_REG_SGIT_MASK;
7079 data |= GRBM_REG_SGIT(0x700);
7080 WREG32(RLC_AUTO_PG_CTRL, data);
7084 static void cik_update_gfx_pg(struct radeon_device *rdev, bool enable)
7086 cik_enable_gfx_cgpg(rdev, enable);
7087 cik_enable_gfx_static_mgpg(rdev, enable);
7088 cik_enable_gfx_dynamic_mgpg(rdev, enable);
7091 u32 cik_get_csb_size(struct radeon_device *rdev)
7094 const struct cs_section_def *sect = NULL;
7095 const struct cs_extent_def *ext = NULL;
7097 if (rdev->rlc.cs_data == NULL)
7100 /* begin clear state */
7102 /* context control state */
7105 for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
7106 for (ext = sect->section; ext->extent != NULL; ++ext) {
7107 if (sect->id == SECT_CONTEXT)
7108 count += 2 + ext->reg_count;
7113 /* pa_sc_raster_config/pa_sc_raster_config1 */
7115 /* end clear state */
7123 void cik_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer)
7126 const struct cs_section_def *sect = NULL;
7127 const struct cs_extent_def *ext = NULL;
7129 if (rdev->rlc.cs_data == NULL)
7134 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
7135 buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
7137 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
7138 buffer[count++] = cpu_to_le32(0x80000000);
7139 buffer[count++] = cpu_to_le32(0x80000000);
7141 for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
7142 for (ext = sect->section; ext->extent != NULL; ++ext) {
7143 if (sect->id == SECT_CONTEXT) {
7145 cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
7146 buffer[count++] = cpu_to_le32(ext->reg_index - 0xa000);
7147 for (i = 0; i < ext->reg_count; i++)
7148 buffer[count++] = cpu_to_le32(ext->extent[i]);
7155 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 2));
7156 buffer[count++] = cpu_to_le32(PA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
7157 switch (rdev->family) {
7159 buffer[count++] = cpu_to_le32(0x16000012);
7160 buffer[count++] = cpu_to_le32(0x00000000);
7163 buffer[count++] = cpu_to_le32(0x00000000); /* XXX */
7164 buffer[count++] = cpu_to_le32(0x00000000);
7168 buffer[count++] = cpu_to_le32(0x00000000); /* XXX */
7169 buffer[count++] = cpu_to_le32(0x00000000);
7172 buffer[count++] = cpu_to_le32(0x3a00161a);
7173 buffer[count++] = cpu_to_le32(0x0000002e);
7176 buffer[count++] = cpu_to_le32(0x00000000);
7177 buffer[count++] = cpu_to_le32(0x00000000);
7181 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
7182 buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);
7184 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
7185 buffer[count++] = cpu_to_le32(0);
7188 static void cik_init_pg(struct radeon_device *rdev)
7190 if (rdev->pg_flags) {
7191 cik_enable_sck_slowdown_on_pu(rdev, true);
7192 cik_enable_sck_slowdown_on_pd(rdev, true);
7193 if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG) {
7194 cik_init_gfx_cgpg(rdev);
7195 cik_enable_cp_pg(rdev, true);
7196 cik_enable_gds_pg(rdev, true);
7198 cik_init_ao_cu_mask(rdev);
7199 cik_update_gfx_pg(rdev, true);
7203 static void cik_fini_pg(struct radeon_device *rdev)
7205 if (rdev->pg_flags) {
7206 cik_update_gfx_pg(rdev, false);
7207 if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG) {
7208 cik_enable_cp_pg(rdev, false);
7209 cik_enable_gds_pg(rdev, false);
7216 * Starting with r6xx, interrupts are handled via a ring buffer.
7217 * Ring buffers are areas of GPU accessible memory that the GPU
7218 * writes interrupt vectors into and the host reads vectors out of.
7219 * There is a rptr (read pointer) that determines where the
7220 * host is currently reading, and a wptr (write pointer)
7221 * which determines where the GPU has written. When the
7222 * pointers are equal, the ring is idle. When the GPU
7223 * writes vectors to the ring buffer, it increments the
7224 * wptr. When there is an interrupt, the host then starts
7225 * fetching commands and processing them until the pointers are
7226 * equal again at which point it updates the rptr.
7230 * cik_enable_interrupts - Enable the interrupt ring buffer
7232 * @rdev: radeon_device pointer
7234 * Enable the interrupt ring buffer (CIK).
7236 static void cik_enable_interrupts(struct radeon_device *rdev)
7238 u32 ih_cntl = RREG32(IH_CNTL);
7239 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
7241 ih_cntl |= ENABLE_INTR;
7242 ih_rb_cntl |= IH_RB_ENABLE;
7243 WREG32(IH_CNTL, ih_cntl);
7244 WREG32(IH_RB_CNTL, ih_rb_cntl);
7245 rdev->ih.enabled = true;
7249 * cik_disable_interrupts - Disable the interrupt ring buffer
7251 * @rdev: radeon_device pointer
7253 * Disable the interrupt ring buffer (CIK).
7255 static void cik_disable_interrupts(struct radeon_device *rdev)
7257 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
7258 u32 ih_cntl = RREG32(IH_CNTL);
7260 ih_rb_cntl &= ~IH_RB_ENABLE;
7261 ih_cntl &= ~ENABLE_INTR;
7262 WREG32(IH_RB_CNTL, ih_rb_cntl);
7263 WREG32(IH_CNTL, ih_cntl);
7264 /* set rptr, wptr to 0 */
7265 WREG32(IH_RB_RPTR, 0);
7266 WREG32(IH_RB_WPTR, 0);
7267 rdev->ih.enabled = false;
7272 * cik_disable_interrupt_state - Disable all interrupt sources
7274 * @rdev: radeon_device pointer
7276 * Clear all interrupt enable bits used by the driver (CIK).
7278 static void cik_disable_interrupt_state(struct radeon_device *rdev)
7283 tmp = RREG32(CP_INT_CNTL_RING0) &
7284 (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
7285 WREG32(CP_INT_CNTL_RING0, tmp);
7287 tmp = RREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
7288 WREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET, tmp);
7289 tmp = RREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
7290 WREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET, tmp);
7291 /* compute queues */
7292 WREG32(CP_ME1_PIPE0_INT_CNTL, 0);
7293 WREG32(CP_ME1_PIPE1_INT_CNTL, 0);
7294 WREG32(CP_ME1_PIPE2_INT_CNTL, 0);
7295 WREG32(CP_ME1_PIPE3_INT_CNTL, 0);
7296 WREG32(CP_ME2_PIPE0_INT_CNTL, 0);
7297 WREG32(CP_ME2_PIPE1_INT_CNTL, 0);
7298 WREG32(CP_ME2_PIPE2_INT_CNTL, 0);
7299 WREG32(CP_ME2_PIPE3_INT_CNTL, 0);
7301 WREG32(GRBM_INT_CNTL, 0);
7303 WREG32(SRBM_INT_CNTL, 0);
7304 /* vline/vblank, etc. */
7305 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
7306 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
7307 if (rdev->num_crtc >= 4) {
7308 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
7309 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
7311 if (rdev->num_crtc >= 6) {
7312 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
7313 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
7316 if (rdev->num_crtc >= 2) {
7317 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
7318 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
7320 if (rdev->num_crtc >= 4) {
7321 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
7322 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
7324 if (rdev->num_crtc >= 6) {
7325 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
7326 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
7330 WREG32(DAC_AUTODETECT_INT_CONTROL, 0);
7332 /* digital hotplug */
7333 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
7334 WREG32(DC_HPD1_INT_CONTROL, tmp);
7335 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
7336 WREG32(DC_HPD2_INT_CONTROL, tmp);
7337 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
7338 WREG32(DC_HPD3_INT_CONTROL, tmp);
7339 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
7340 WREG32(DC_HPD4_INT_CONTROL, tmp);
7341 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
7342 WREG32(DC_HPD5_INT_CONTROL, tmp);
7343 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
7344 WREG32(DC_HPD6_INT_CONTROL, tmp);
7349 * cik_irq_init - init and enable the interrupt ring
7351 * @rdev: radeon_device pointer
7353 * Allocate a ring buffer for the interrupt controller,
7354 * enable the RLC, disable interrupts, enable the IH
7355 * ring buffer and enable it (CIK).
7356 * Called at device load and reume.
7357 * Returns 0 for success, errors for failure.
7359 static int cik_irq_init(struct radeon_device *rdev)
7363 u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
7366 ret = r600_ih_ring_alloc(rdev);
7371 cik_disable_interrupts(rdev);
7374 ret = cik_rlc_resume(rdev);
7376 r600_ih_ring_fini(rdev);
7380 /* setup interrupt control */
7381 /* XXX this should actually be a bus address, not an MC address. same on older asics */
7382 WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
7383 interrupt_cntl = RREG32(INTERRUPT_CNTL);
7384 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
7385 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
7387 interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
7388 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
7389 interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
7390 WREG32(INTERRUPT_CNTL, interrupt_cntl);
7392 WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
7393 rb_bufsz = order_base_2(rdev->ih.ring_size / 4);
7395 ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
7396 IH_WPTR_OVERFLOW_CLEAR |
7399 if (rdev->wb.enabled)
7400 ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
7402 /* set the writeback address whether it's enabled or not */
7403 WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
7404 WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
7406 WREG32(IH_RB_CNTL, ih_rb_cntl);
7408 /* set rptr, wptr to 0 */
7409 WREG32(IH_RB_RPTR, 0);
7410 WREG32(IH_RB_WPTR, 0);
7412 /* Default settings for IH_CNTL (disabled at first) */
7413 ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10) | MC_VMID(0);
7414 /* RPTR_REARM only works if msi's are enabled */
7415 if (rdev->msi_enabled)
7416 ih_cntl |= RPTR_REARM;
7417 WREG32(IH_CNTL, ih_cntl);
7419 /* force the active interrupt state to all disabled */
7420 cik_disable_interrupt_state(rdev);
7422 pci_set_master(rdev->pdev);
7425 cik_enable_interrupts(rdev);
7431 * cik_irq_set - enable/disable interrupt sources
7433 * @rdev: radeon_device pointer
7435 * Enable interrupt sources on the GPU (vblanks, hpd,
7437 * Returns 0 for success, errors for failure.
7439 int cik_irq_set(struct radeon_device *rdev)
7443 u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
7444 u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;
7445 u32 grbm_int_cntl = 0;
7446 u32 dma_cntl, dma_cntl1;
7448 if (!rdev->irq.installed) {
7449 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
7452 /* don't enable anything if the ih is disabled */
7453 if (!rdev->ih.enabled) {
7454 cik_disable_interrupts(rdev);
7455 /* force the active interrupt state to all disabled */
7456 cik_disable_interrupt_state(rdev);
7460 cp_int_cntl = RREG32(CP_INT_CNTL_RING0) &
7461 (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
7462 cp_int_cntl |= PRIV_INSTR_INT_ENABLE | PRIV_REG_INT_ENABLE;
7464 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
7465 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
7466 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
7467 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
7468 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
7469 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
7471 dma_cntl = RREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
7472 dma_cntl1 = RREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
7474 cp_m1p0 = RREG32(CP_ME1_PIPE0_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
7476 /* enable CP interrupts on all rings */
7477 if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
7478 DRM_DEBUG("cik_irq_set: sw int gfx\n");
7479 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
7481 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
7482 struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
7483 DRM_DEBUG("si_irq_set: sw int cp1\n");
7484 if (ring->me == 1) {
7485 switch (ring->pipe) {
7487 cp_m1p0 |= TIME_STAMP_INT_ENABLE;
7490 DRM_DEBUG("si_irq_set: sw int cp1 invalid pipe %d\n", ring->pipe);
7494 DRM_DEBUG("si_irq_set: sw int cp1 invalid me %d\n", ring->me);
7497 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
7498 struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
7499 DRM_DEBUG("si_irq_set: sw int cp2\n");
7500 if (ring->me == 1) {
7501 switch (ring->pipe) {
7503 cp_m1p0 |= TIME_STAMP_INT_ENABLE;
7506 DRM_DEBUG("si_irq_set: sw int cp2 invalid pipe %d\n", ring->pipe);
7510 DRM_DEBUG("si_irq_set: sw int cp2 invalid me %d\n", ring->me);
7514 if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
7515 DRM_DEBUG("cik_irq_set: sw int dma\n");
7516 dma_cntl |= TRAP_ENABLE;
7519 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
7520 DRM_DEBUG("cik_irq_set: sw int dma1\n");
7521 dma_cntl1 |= TRAP_ENABLE;
7524 if (rdev->irq.crtc_vblank_int[0] ||
7525 atomic_read(&rdev->irq.pflip[0])) {
7526 DRM_DEBUG("cik_irq_set: vblank 0\n");
7527 crtc1 |= VBLANK_INTERRUPT_MASK;
7529 if (rdev->irq.crtc_vblank_int[1] ||
7530 atomic_read(&rdev->irq.pflip[1])) {
7531 DRM_DEBUG("cik_irq_set: vblank 1\n");
7532 crtc2 |= VBLANK_INTERRUPT_MASK;
7534 if (rdev->irq.crtc_vblank_int[2] ||
7535 atomic_read(&rdev->irq.pflip[2])) {
7536 DRM_DEBUG("cik_irq_set: vblank 2\n");
7537 crtc3 |= VBLANK_INTERRUPT_MASK;
7539 if (rdev->irq.crtc_vblank_int[3] ||
7540 atomic_read(&rdev->irq.pflip[3])) {
7541 DRM_DEBUG("cik_irq_set: vblank 3\n");
7542 crtc4 |= VBLANK_INTERRUPT_MASK;
7544 if (rdev->irq.crtc_vblank_int[4] ||
7545 atomic_read(&rdev->irq.pflip[4])) {
7546 DRM_DEBUG("cik_irq_set: vblank 4\n");
7547 crtc5 |= VBLANK_INTERRUPT_MASK;
7549 if (rdev->irq.crtc_vblank_int[5] ||
7550 atomic_read(&rdev->irq.pflip[5])) {
7551 DRM_DEBUG("cik_irq_set: vblank 5\n");
7552 crtc6 |= VBLANK_INTERRUPT_MASK;
7554 if (rdev->irq.hpd[0]) {
7555 DRM_DEBUG("cik_irq_set: hpd 1\n");
7556 hpd1 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
7558 if (rdev->irq.hpd[1]) {
7559 DRM_DEBUG("cik_irq_set: hpd 2\n");
7560 hpd2 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
7562 if (rdev->irq.hpd[2]) {
7563 DRM_DEBUG("cik_irq_set: hpd 3\n");
7564 hpd3 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
7566 if (rdev->irq.hpd[3]) {
7567 DRM_DEBUG("cik_irq_set: hpd 4\n");
7568 hpd4 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
7570 if (rdev->irq.hpd[4]) {
7571 DRM_DEBUG("cik_irq_set: hpd 5\n");
7572 hpd5 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
7574 if (rdev->irq.hpd[5]) {
7575 DRM_DEBUG("cik_irq_set: hpd 6\n");
7576 hpd6 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
7579 WREG32(CP_INT_CNTL_RING0, cp_int_cntl);
7581 WREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET, dma_cntl);
7582 WREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET, dma_cntl1);
7584 WREG32(CP_ME1_PIPE0_INT_CNTL, cp_m1p0);
7586 WREG32(GRBM_INT_CNTL, grbm_int_cntl);
7588 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
7589 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
7590 if (rdev->num_crtc >= 4) {
7591 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
7592 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
7594 if (rdev->num_crtc >= 6) {
7595 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
7596 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
7599 if (rdev->num_crtc >= 2) {
7600 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET,
7601 GRPH_PFLIP_INT_MASK);
7602 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET,
7603 GRPH_PFLIP_INT_MASK);
7605 if (rdev->num_crtc >= 4) {
7606 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET,
7607 GRPH_PFLIP_INT_MASK);
7608 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET,
7609 GRPH_PFLIP_INT_MASK);
7611 if (rdev->num_crtc >= 6) {
7612 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET,
7613 GRPH_PFLIP_INT_MASK);
7614 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET,
7615 GRPH_PFLIP_INT_MASK);
7618 WREG32(DC_HPD1_INT_CONTROL, hpd1);
7619 WREG32(DC_HPD2_INT_CONTROL, hpd2);
7620 WREG32(DC_HPD3_INT_CONTROL, hpd3);
7621 WREG32(DC_HPD4_INT_CONTROL, hpd4);
7622 WREG32(DC_HPD5_INT_CONTROL, hpd5);
7623 WREG32(DC_HPD6_INT_CONTROL, hpd6);
7626 RREG32(SRBM_STATUS);
7632 * cik_irq_ack - ack interrupt sources
7634 * @rdev: radeon_device pointer
7636 * Ack interrupt sources on the GPU (vblanks, hpd,
7637 * etc.) (CIK). Certain interrupts sources are sw
7638 * generated and do not require an explicit ack.
7640 static inline void cik_irq_ack(struct radeon_device *rdev)
7644 rdev->irq.stat_regs.cik.disp_int = RREG32(DISP_INTERRUPT_STATUS);
7645 rdev->irq.stat_regs.cik.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
7646 rdev->irq.stat_regs.cik.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
7647 rdev->irq.stat_regs.cik.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
7648 rdev->irq.stat_regs.cik.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
7649 rdev->irq.stat_regs.cik.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
7650 rdev->irq.stat_regs.cik.disp_int_cont6 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE6);
7652 rdev->irq.stat_regs.cik.d1grph_int = RREG32(GRPH_INT_STATUS +
7653 EVERGREEN_CRTC0_REGISTER_OFFSET);
7654 rdev->irq.stat_regs.cik.d2grph_int = RREG32(GRPH_INT_STATUS +
7655 EVERGREEN_CRTC1_REGISTER_OFFSET);
7656 if (rdev->num_crtc >= 4) {
7657 rdev->irq.stat_regs.cik.d3grph_int = RREG32(GRPH_INT_STATUS +
7658 EVERGREEN_CRTC2_REGISTER_OFFSET);
7659 rdev->irq.stat_regs.cik.d4grph_int = RREG32(GRPH_INT_STATUS +
7660 EVERGREEN_CRTC3_REGISTER_OFFSET);
7662 if (rdev->num_crtc >= 6) {
7663 rdev->irq.stat_regs.cik.d5grph_int = RREG32(GRPH_INT_STATUS +
7664 EVERGREEN_CRTC4_REGISTER_OFFSET);
7665 rdev->irq.stat_regs.cik.d6grph_int = RREG32(GRPH_INT_STATUS +
7666 EVERGREEN_CRTC5_REGISTER_OFFSET);
7669 if (rdev->irq.stat_regs.cik.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
7670 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET,
7671 GRPH_PFLIP_INT_CLEAR);
7672 if (rdev->irq.stat_regs.cik.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
7673 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET,
7674 GRPH_PFLIP_INT_CLEAR);
7675 if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VBLANK_INTERRUPT)
7676 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
7677 if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VLINE_INTERRUPT)
7678 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
7679 if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
7680 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
7681 if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VLINE_INTERRUPT)
7682 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
7684 if (rdev->num_crtc >= 4) {
7685 if (rdev->irq.stat_regs.cik.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
7686 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET,
7687 GRPH_PFLIP_INT_CLEAR);
7688 if (rdev->irq.stat_regs.cik.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
7689 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET,
7690 GRPH_PFLIP_INT_CLEAR);
7691 if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
7692 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
7693 if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
7694 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
7695 if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
7696 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
7697 if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
7698 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
7701 if (rdev->num_crtc >= 6) {
7702 if (rdev->irq.stat_regs.cik.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
7703 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET,
7704 GRPH_PFLIP_INT_CLEAR);
7705 if (rdev->irq.stat_regs.cik.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
7706 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET,
7707 GRPH_PFLIP_INT_CLEAR);
7708 if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
7709 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
7710 if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
7711 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
7712 if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
7713 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
7714 if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
7715 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
7718 if (rdev->irq.stat_regs.cik.disp_int & DC_HPD1_INTERRUPT) {
7719 tmp = RREG32(DC_HPD1_INT_CONTROL);
7720 tmp |= DC_HPDx_INT_ACK;
7721 WREG32(DC_HPD1_INT_CONTROL, tmp);
7723 if (rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_INTERRUPT) {
7724 tmp = RREG32(DC_HPD2_INT_CONTROL);
7725 tmp |= DC_HPDx_INT_ACK;
7726 WREG32(DC_HPD2_INT_CONTROL, tmp);
7728 if (rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_INTERRUPT) {
7729 tmp = RREG32(DC_HPD3_INT_CONTROL);
7730 tmp |= DC_HPDx_INT_ACK;
7731 WREG32(DC_HPD3_INT_CONTROL, tmp);
7733 if (rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_INTERRUPT) {
7734 tmp = RREG32(DC_HPD4_INT_CONTROL);
7735 tmp |= DC_HPDx_INT_ACK;
7736 WREG32(DC_HPD4_INT_CONTROL, tmp);
7738 if (rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_INTERRUPT) {
7739 tmp = RREG32(DC_HPD5_INT_CONTROL);
7740 tmp |= DC_HPDx_INT_ACK;
7741 WREG32(DC_HPD5_INT_CONTROL, tmp);
7743 if (rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_INTERRUPT) {
7744 tmp = RREG32(DC_HPD5_INT_CONTROL);
7745 tmp |= DC_HPDx_INT_ACK;
7746 WREG32(DC_HPD6_INT_CONTROL, tmp);
7748 if (rdev->irq.stat_regs.cik.disp_int & DC_HPD1_RX_INTERRUPT) {
7749 tmp = RREG32(DC_HPD1_INT_CONTROL);
7750 tmp |= DC_HPDx_RX_INT_ACK;
7751 WREG32(DC_HPD1_INT_CONTROL, tmp);
7753 if (rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_RX_INTERRUPT) {
7754 tmp = RREG32(DC_HPD2_INT_CONTROL);
7755 tmp |= DC_HPDx_RX_INT_ACK;
7756 WREG32(DC_HPD2_INT_CONTROL, tmp);
7758 if (rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_RX_INTERRUPT) {
7759 tmp = RREG32(DC_HPD3_INT_CONTROL);
7760 tmp |= DC_HPDx_RX_INT_ACK;
7761 WREG32(DC_HPD3_INT_CONTROL, tmp);
7763 if (rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_RX_INTERRUPT) {
7764 tmp = RREG32(DC_HPD4_INT_CONTROL);
7765 tmp |= DC_HPDx_RX_INT_ACK;
7766 WREG32(DC_HPD4_INT_CONTROL, tmp);
7768 if (rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_RX_INTERRUPT) {
7769 tmp = RREG32(DC_HPD5_INT_CONTROL);
7770 tmp |= DC_HPDx_RX_INT_ACK;
7771 WREG32(DC_HPD5_INT_CONTROL, tmp);
7773 if (rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_RX_INTERRUPT) {
7774 tmp = RREG32(DC_HPD5_INT_CONTROL);
7775 tmp |= DC_HPDx_RX_INT_ACK;
7776 WREG32(DC_HPD6_INT_CONTROL, tmp);
7781 * cik_irq_disable - disable interrupts
7783 * @rdev: radeon_device pointer
7785 * Disable interrupts on the hw (CIK).
7787 static void cik_irq_disable(struct radeon_device *rdev)
7789 cik_disable_interrupts(rdev);
7790 /* Wait and acknowledge irq */
7793 cik_disable_interrupt_state(rdev);
7797 * cik_irq_disable - disable interrupts for suspend
7799 * @rdev: radeon_device pointer
7801 * Disable interrupts and stop the RLC (CIK).
7804 static void cik_irq_suspend(struct radeon_device *rdev)
7806 cik_irq_disable(rdev);
7811 * cik_irq_fini - tear down interrupt support
7813 * @rdev: radeon_device pointer
7815 * Disable interrupts on the hw and free the IH ring
7817 * Used for driver unload.
7819 static void cik_irq_fini(struct radeon_device *rdev)
7821 cik_irq_suspend(rdev);
7822 r600_ih_ring_fini(rdev);
7826 * cik_get_ih_wptr - get the IH ring buffer wptr
7828 * @rdev: radeon_device pointer
7830 * Get the IH ring buffer wptr from either the register
7831 * or the writeback memory buffer (CIK). Also check for
7832 * ring buffer overflow and deal with it.
7833 * Used by cik_irq_process().
7834 * Returns the value of the wptr.
7836 static inline u32 cik_get_ih_wptr(struct radeon_device *rdev)
7840 if (rdev->wb.enabled)
7841 wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
7843 wptr = RREG32(IH_RB_WPTR);
7845 if (wptr & RB_OVERFLOW) {
7846 wptr &= ~RB_OVERFLOW;
7847 /* When a ring buffer overflow happen start parsing interrupt
7848 * from the last not overwritten vector (wptr + 16). Hopefully
7849 * this should allow us to catchup.
7851 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n",
7852 wptr, rdev->ih.rptr, (wptr + 16) & rdev->ih.ptr_mask);
7853 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
7854 tmp = RREG32(IH_RB_CNTL);
7855 tmp |= IH_WPTR_OVERFLOW_CLEAR;
7856 WREG32(IH_RB_CNTL, tmp);
7858 return (wptr & rdev->ih.ptr_mask);
7862 * Each IV ring entry is 128 bits:
7863 * [7:0] - interrupt source id
7865 * [59:32] - interrupt source data
7866 * [63:60] - reserved
7869 * ME_ID [1:0], PIPE_ID[1:0], QUEUE_ID[2:0]
7870 * QUEUE_ID - for compute, which of the 8 queues owned by the dispatcher
7871 * - for gfx, hw shader state (0=PS...5=LS, 6=CS)
7872 * ME_ID - 0 = gfx, 1 = first 4 CS pipes, 2 = second 4 CS pipes
7873 * PIPE_ID - ME0 0=3D
7874 * - ME1&2 compute dispatcher (4 pipes each)
7876 * INSTANCE_ID [1:0], QUEUE_ID[1:0]
7877 * INSTANCE_ID - 0 = sdma0, 1 = sdma1
7878 * QUEUE_ID - 0 = gfx, 1 = rlc0, 2 = rlc1
7881 * [127:96] - reserved
7884 * cik_irq_process - interrupt handler
7886 * @rdev: radeon_device pointer
7888 * Interrupt hander (CIK). Walk the IH ring,
7889 * ack interrupts and schedule work to handle
7891 * Returns irq process return code.
7893 int cik_irq_process(struct radeon_device *rdev)
7895 struct radeon_ring *cp1_ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
7896 struct radeon_ring *cp2_ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
7899 u32 src_id, src_data, ring_id;
7900 u8 me_id, pipe_id, queue_id;
7902 bool queue_hotplug = false;
7903 bool queue_dp = false;
7904 bool queue_reset = false;
7905 u32 addr, status, mc_client;
7906 bool queue_thermal = false;
7908 if (!rdev->ih.enabled || rdev->shutdown)
7911 wptr = cik_get_ih_wptr(rdev);
7914 /* is somebody else already processing irqs? */
7915 if (atomic_xchg(&rdev->ih.lock, 1))
7918 rptr = rdev->ih.rptr;
7919 DRM_DEBUG("cik_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
7921 /* Order reading of wptr vs. reading of IH ring data */
7924 /* display interrupts */
7927 while (rptr != wptr) {
7928 /* wptr/rptr are in bytes! */
7929 ring_index = rptr / 4;
7931 radeon_kfd_interrupt(rdev,
7932 (const void *) &rdev->ih.ring[ring_index]);
7934 src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
7935 src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
7936 ring_id = le32_to_cpu(rdev->ih.ring[ring_index + 2]) & 0xff;
7939 case 1: /* D1 vblank/vline */
7941 case 0: /* D1 vblank */
7942 if (!(rdev->irq.stat_regs.cik.disp_int & LB_D1_VBLANK_INTERRUPT))
7943 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7945 if (rdev->irq.crtc_vblank_int[0]) {
7946 drm_handle_vblank(rdev->ddev, 0);
7947 rdev->pm.vblank_sync = true;
7948 wake_up(&rdev->irq.vblank_queue);
7950 if (atomic_read(&rdev->irq.pflip[0]))
7951 radeon_crtc_handle_vblank(rdev, 0);
7952 rdev->irq.stat_regs.cik.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
7953 DRM_DEBUG("IH: D1 vblank\n");
7956 case 1: /* D1 vline */
7957 if (!(rdev->irq.stat_regs.cik.disp_int & LB_D1_VLINE_INTERRUPT))
7958 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7960 rdev->irq.stat_regs.cik.disp_int &= ~LB_D1_VLINE_INTERRUPT;
7961 DRM_DEBUG("IH: D1 vline\n");
7965 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
7969 case 2: /* D2 vblank/vline */
7971 case 0: /* D2 vblank */
7972 if (!(rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VBLANK_INTERRUPT))
7973 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7975 if (rdev->irq.crtc_vblank_int[1]) {
7976 drm_handle_vblank(rdev->ddev, 1);
7977 rdev->pm.vblank_sync = true;
7978 wake_up(&rdev->irq.vblank_queue);
7980 if (atomic_read(&rdev->irq.pflip[1]))
7981 radeon_crtc_handle_vblank(rdev, 1);
7982 rdev->irq.stat_regs.cik.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
7983 DRM_DEBUG("IH: D2 vblank\n");
7986 case 1: /* D2 vline */
7987 if (!(rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VLINE_INTERRUPT))
7988 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
7990 rdev->irq.stat_regs.cik.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
7991 DRM_DEBUG("IH: D2 vline\n");
7995 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
7999 case 3: /* D3 vblank/vline */
8001 case 0: /* D3 vblank */
8002 if (!(rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT))
8003 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8005 if (rdev->irq.crtc_vblank_int[2]) {
8006 drm_handle_vblank(rdev->ddev, 2);
8007 rdev->pm.vblank_sync = true;
8008 wake_up(&rdev->irq.vblank_queue);
8010 if (atomic_read(&rdev->irq.pflip[2]))
8011 radeon_crtc_handle_vblank(rdev, 2);
8012 rdev->irq.stat_regs.cik.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
8013 DRM_DEBUG("IH: D3 vblank\n");
8016 case 1: /* D3 vline */
8017 if (!(rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VLINE_INTERRUPT))
8018 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8020 rdev->irq.stat_regs.cik.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
8021 DRM_DEBUG("IH: D3 vline\n");
8025 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
8029 case 4: /* D4 vblank/vline */
8031 case 0: /* D4 vblank */
8032 if (!(rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT))
8033 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8035 if (rdev->irq.crtc_vblank_int[3]) {
8036 drm_handle_vblank(rdev->ddev, 3);
8037 rdev->pm.vblank_sync = true;
8038 wake_up(&rdev->irq.vblank_queue);
8040 if (atomic_read(&rdev->irq.pflip[3]))
8041 radeon_crtc_handle_vblank(rdev, 3);
8042 rdev->irq.stat_regs.cik.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
8043 DRM_DEBUG("IH: D4 vblank\n");
8046 case 1: /* D4 vline */
8047 if (!(rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VLINE_INTERRUPT))
8048 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8050 rdev->irq.stat_regs.cik.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
8051 DRM_DEBUG("IH: D4 vline\n");
8055 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
8059 case 5: /* D5 vblank/vline */
8061 case 0: /* D5 vblank */
8062 if (!(rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT))
8063 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8065 if (rdev->irq.crtc_vblank_int[4]) {
8066 drm_handle_vblank(rdev->ddev, 4);
8067 rdev->pm.vblank_sync = true;
8068 wake_up(&rdev->irq.vblank_queue);
8070 if (atomic_read(&rdev->irq.pflip[4]))
8071 radeon_crtc_handle_vblank(rdev, 4);
8072 rdev->irq.stat_regs.cik.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
8073 DRM_DEBUG("IH: D5 vblank\n");
8076 case 1: /* D5 vline */
8077 if (!(rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VLINE_INTERRUPT))
8078 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8080 rdev->irq.stat_regs.cik.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
8081 DRM_DEBUG("IH: D5 vline\n");
8085 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
8089 case 6: /* D6 vblank/vline */
8091 case 0: /* D6 vblank */
8092 if (!(rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT))
8093 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8095 if (rdev->irq.crtc_vblank_int[5]) {
8096 drm_handle_vblank(rdev->ddev, 5);
8097 rdev->pm.vblank_sync = true;
8098 wake_up(&rdev->irq.vblank_queue);
8100 if (atomic_read(&rdev->irq.pflip[5]))
8101 radeon_crtc_handle_vblank(rdev, 5);
8102 rdev->irq.stat_regs.cik.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
8103 DRM_DEBUG("IH: D6 vblank\n");
8106 case 1: /* D6 vline */
8107 if (!(rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VLINE_INTERRUPT))
8108 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8110 rdev->irq.stat_regs.cik.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
8111 DRM_DEBUG("IH: D6 vline\n");
8115 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
8119 case 8: /* D1 page flip */
8120 case 10: /* D2 page flip */
8121 case 12: /* D3 page flip */
8122 case 14: /* D4 page flip */
8123 case 16: /* D5 page flip */
8124 case 18: /* D6 page flip */
8125 DRM_DEBUG("IH: D%d flip\n", ((src_id - 8) >> 1) + 1);
8126 if (radeon_use_pflipirq > 0)
8127 radeon_crtc_handle_flip(rdev, (src_id - 8) >> 1);
8129 case 42: /* HPD hotplug */
8132 if (!(rdev->irq.stat_regs.cik.disp_int & DC_HPD1_INTERRUPT))
8133 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8135 rdev->irq.stat_regs.cik.disp_int &= ~DC_HPD1_INTERRUPT;
8136 queue_hotplug = true;
8137 DRM_DEBUG("IH: HPD1\n");
8141 if (!(rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_INTERRUPT))
8142 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8144 rdev->irq.stat_regs.cik.disp_int_cont &= ~DC_HPD2_INTERRUPT;
8145 queue_hotplug = true;
8146 DRM_DEBUG("IH: HPD2\n");
8150 if (!(rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_INTERRUPT))
8151 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8153 rdev->irq.stat_regs.cik.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
8154 queue_hotplug = true;
8155 DRM_DEBUG("IH: HPD3\n");
8159 if (!(rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_INTERRUPT))
8160 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8162 rdev->irq.stat_regs.cik.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
8163 queue_hotplug = true;
8164 DRM_DEBUG("IH: HPD4\n");
8168 if (!(rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_INTERRUPT))
8169 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8171 rdev->irq.stat_regs.cik.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
8172 queue_hotplug = true;
8173 DRM_DEBUG("IH: HPD5\n");
8177 if (!(rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_INTERRUPT))
8178 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8180 rdev->irq.stat_regs.cik.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
8181 queue_hotplug = true;
8182 DRM_DEBUG("IH: HPD6\n");
8186 if (!(rdev->irq.stat_regs.cik.disp_int & DC_HPD1_RX_INTERRUPT))
8187 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8189 rdev->irq.stat_regs.cik.disp_int &= ~DC_HPD1_RX_INTERRUPT;
8191 DRM_DEBUG("IH: HPD_RX 1\n");
8195 if (!(rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_RX_INTERRUPT))
8196 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8198 rdev->irq.stat_regs.cik.disp_int_cont &= ~DC_HPD2_RX_INTERRUPT;
8200 DRM_DEBUG("IH: HPD_RX 2\n");
8204 if (!(rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_RX_INTERRUPT))
8205 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8207 rdev->irq.stat_regs.cik.disp_int_cont2 &= ~DC_HPD3_RX_INTERRUPT;
8209 DRM_DEBUG("IH: HPD_RX 3\n");
8213 if (!(rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_RX_INTERRUPT))
8214 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8216 rdev->irq.stat_regs.cik.disp_int_cont3 &= ~DC_HPD4_RX_INTERRUPT;
8218 DRM_DEBUG("IH: HPD_RX 4\n");
8222 if (!(rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_RX_INTERRUPT))
8223 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8225 rdev->irq.stat_regs.cik.disp_int_cont4 &= ~DC_HPD5_RX_INTERRUPT;
8227 DRM_DEBUG("IH: HPD_RX 5\n");
8231 if (!(rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_RX_INTERRUPT))
8232 DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
8234 rdev->irq.stat_regs.cik.disp_int_cont5 &= ~DC_HPD6_RX_INTERRUPT;
8236 DRM_DEBUG("IH: HPD_RX 6\n");
8240 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
8245 DRM_ERROR("SRBM_READ_ERROR: 0x%x\n", RREG32(SRBM_READ_ERROR));
8246 WREG32(SRBM_INT_ACK, 0x1);
8249 DRM_DEBUG("IH: UVD int: 0x%08x\n", src_data);
8250 radeon_fence_process(rdev, R600_RING_TYPE_UVD_INDEX);
8254 addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
8255 status = RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS);
8256 mc_client = RREG32(VM_CONTEXT1_PROTECTION_FAULT_MCCLIENT);
8257 /* reset addr and status */
8258 WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
8259 if (addr == 0x0 && status == 0x0)
8261 dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
8262 dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
8264 dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
8266 cik_vm_decode_fault(rdev, status, addr, mc_client);
8269 DRM_DEBUG("IH: VCE int: 0x%08x\n", src_data);
8272 radeon_fence_process(rdev, TN_RING_TYPE_VCE1_INDEX);
8275 radeon_fence_process(rdev, TN_RING_TYPE_VCE2_INDEX);
8278 DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
8282 case 176: /* GFX RB CP_INT */
8283 case 177: /* GFX IB CP_INT */
8284 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
8286 case 181: /* CP EOP event */
8287 DRM_DEBUG("IH: CP EOP\n");
8288 /* XXX check the bitfield order! */
8289 me_id = (ring_id & 0x60) >> 5;
8290 pipe_id = (ring_id & 0x18) >> 3;
8291 queue_id = (ring_id & 0x7) >> 0;
8294 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
8298 if ((cp1_ring->me == me_id) & (cp1_ring->pipe == pipe_id))
8299 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
8300 if ((cp2_ring->me == me_id) & (cp2_ring->pipe == pipe_id))
8301 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
8305 case 184: /* CP Privileged reg access */
8306 DRM_ERROR("Illegal register access in command stream\n");
8307 /* XXX check the bitfield order! */
8308 me_id = (ring_id & 0x60) >> 5;
8309 pipe_id = (ring_id & 0x18) >> 3;
8310 queue_id = (ring_id & 0x7) >> 0;
8313 /* This results in a full GPU reset, but all we need to do is soft
8314 * reset the CP for gfx
8328 case 185: /* CP Privileged inst */
8329 DRM_ERROR("Illegal instruction in command stream\n");
8330 /* XXX check the bitfield order! */
8331 me_id = (ring_id & 0x60) >> 5;
8332 pipe_id = (ring_id & 0x18) >> 3;
8333 queue_id = (ring_id & 0x7) >> 0;
8336 /* This results in a full GPU reset, but all we need to do is soft
8337 * reset the CP for gfx
8351 case 224: /* SDMA trap event */
8352 /* XXX check the bitfield order! */
8353 me_id = (ring_id & 0x3) >> 0;
8354 queue_id = (ring_id & 0xc) >> 2;
8355 DRM_DEBUG("IH: SDMA trap\n");
8360 radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
8373 radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
8385 case 230: /* thermal low to high */
8386 DRM_DEBUG("IH: thermal low to high\n");
8387 rdev->pm.dpm.thermal.high_to_low = false;
8388 queue_thermal = true;
8390 case 231: /* thermal high to low */
8391 DRM_DEBUG("IH: thermal high to low\n");
8392 rdev->pm.dpm.thermal.high_to_low = true;
8393 queue_thermal = true;
8395 case 233: /* GUI IDLE */
8396 DRM_DEBUG("IH: GUI idle\n");
8398 case 241: /* SDMA Privileged inst */
8399 case 247: /* SDMA Privileged inst */
8400 DRM_ERROR("Illegal instruction in SDMA command stream\n");
8401 /* XXX check the bitfield order! */
8402 me_id = (ring_id & 0x3) >> 0;
8403 queue_id = (ring_id & 0xc) >> 2;
8438 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
8442 /* wptr/rptr are in bytes! */
8444 rptr &= rdev->ih.ptr_mask;
8445 WREG32(IH_RB_RPTR, rptr);
8448 schedule_work(&rdev->dp_work);
8450 schedule_work(&rdev->hotplug_work);
8452 rdev->needs_reset = true;
8453 wake_up_all(&rdev->fence_queue);
8456 schedule_work(&rdev->pm.dpm.thermal.work);
8457 rdev->ih.rptr = rptr;
8458 atomic_set(&rdev->ih.lock, 0);
8460 /* make sure wptr hasn't changed while processing */
8461 wptr = cik_get_ih_wptr(rdev);
8469 * startup/shutdown callbacks
8472 * cik_startup - program the asic to a functional state
8474 * @rdev: radeon_device pointer
8476 * Programs the asic to a functional state (CIK).
8477 * Called by cik_init() and cik_resume().
8478 * Returns 0 for success, error for failure.
8480 static int cik_startup(struct radeon_device *rdev)
8482 struct radeon_ring *ring;
8486 /* enable pcie gen2/3 link */
8487 cik_pcie_gen3_enable(rdev);
8489 cik_program_aspm(rdev);
8491 /* scratch needs to be initialized before MC */
8492 r = r600_vram_scratch_init(rdev);
8496 cik_mc_program(rdev);
8498 if (!(rdev->flags & RADEON_IS_IGP) && !rdev->pm.dpm_enabled) {
8499 r = ci_mc_load_microcode(rdev);
8501 DRM_ERROR("Failed to load MC firmware!\n");
8506 r = cik_pcie_gart_enable(rdev);
8511 /* allocate rlc buffers */
8512 if (rdev->flags & RADEON_IS_IGP) {
8513 if (rdev->family == CHIP_KAVERI) {
8514 rdev->rlc.reg_list = spectre_rlc_save_restore_register_list;
8515 rdev->rlc.reg_list_size =
8516 (u32)ARRAY_SIZE(spectre_rlc_save_restore_register_list);
8518 rdev->rlc.reg_list = kalindi_rlc_save_restore_register_list;
8519 rdev->rlc.reg_list_size =
8520 (u32)ARRAY_SIZE(kalindi_rlc_save_restore_register_list);
8523 rdev->rlc.cs_data = ci_cs_data;
8524 rdev->rlc.cp_table_size = CP_ME_TABLE_SIZE * 5 * 4;
8525 r = sumo_rlc_init(rdev);
8527 DRM_ERROR("Failed to init rlc BOs!\n");
8531 /* allocate wb buffer */
8532 r = radeon_wb_init(rdev);
8536 /* allocate mec buffers */
8537 r = cik_mec_init(rdev);
8539 DRM_ERROR("Failed to init MEC BOs!\n");
8543 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
8545 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
8549 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
8551 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
8555 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
8557 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
8561 r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
8563 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
8567 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
8569 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
8573 r = radeon_uvd_resume(rdev);
8575 r = uvd_v4_2_resume(rdev);
8577 r = radeon_fence_driver_start_ring(rdev,
8578 R600_RING_TYPE_UVD_INDEX);
8580 dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
8584 rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
8586 r = radeon_vce_resume(rdev);
8588 r = vce_v2_0_resume(rdev);
8590 r = radeon_fence_driver_start_ring(rdev,
8591 TN_RING_TYPE_VCE1_INDEX);
8593 r = radeon_fence_driver_start_ring(rdev,
8594 TN_RING_TYPE_VCE2_INDEX);
8597 dev_err(rdev->dev, "VCE init error (%d).\n", r);
8598 rdev->ring[TN_RING_TYPE_VCE1_INDEX].ring_size = 0;
8599 rdev->ring[TN_RING_TYPE_VCE2_INDEX].ring_size = 0;
8603 if (!rdev->irq.installed) {
8604 r = radeon_irq_kms_init(rdev);
8609 r = cik_irq_init(rdev);
8611 DRM_ERROR("radeon: IH init failed (%d).\n", r);
8612 radeon_irq_kms_fini(rdev);
8617 if (rdev->family == CHIP_HAWAII) {
8619 nop = PACKET3(PACKET3_NOP, 0x3FFF);
8621 nop = RADEON_CP_PACKET2;
8623 nop = PACKET3(PACKET3_NOP, 0x3FFF);
8626 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
8627 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
8632 /* set up the compute queues */
8633 /* type-2 packets are deprecated on MEC, use type-3 instead */
8634 ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
8635 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP1_RPTR_OFFSET,
8639 ring->me = 1; /* first MEC */
8640 ring->pipe = 0; /* first pipe */
8641 ring->queue = 0; /* first queue */
8642 ring->wptr_offs = CIK_WB_CP1_WPTR_OFFSET;
8644 /* type-2 packets are deprecated on MEC, use type-3 instead */
8645 ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
8646 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP2_RPTR_OFFSET,
8650 /* dGPU only have 1 MEC */
8651 ring->me = 1; /* first MEC */
8652 ring->pipe = 0; /* first pipe */
8653 ring->queue = 1; /* second queue */
8654 ring->wptr_offs = CIK_WB_CP2_WPTR_OFFSET;
8656 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
8657 r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
8658 SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0));
8662 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
8663 r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
8664 SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0));
8668 r = cik_cp_resume(rdev);
8672 r = cik_sdma_resume(rdev);
8676 ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
8677 if (ring->ring_size) {
8678 r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
8681 r = uvd_v1_0_init(rdev);
8683 DRM_ERROR("radeon: failed initializing UVD (%d).\n", r);
8688 ring = &rdev->ring[TN_RING_TYPE_VCE1_INDEX];
8689 if (ring->ring_size)
8690 r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
8693 ring = &rdev->ring[TN_RING_TYPE_VCE2_INDEX];
8694 if (ring->ring_size)
8695 r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
8699 r = vce_v1_0_init(rdev);
8700 else if (r != -ENOENT)
8701 DRM_ERROR("radeon: failed initializing VCE (%d).\n", r);
8703 r = radeon_ib_pool_init(rdev);
8705 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
8709 r = radeon_vm_manager_init(rdev);
8711 dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
8715 r = radeon_audio_init(rdev);
8719 r = radeon_kfd_resume(rdev);
8727 * cik_resume - resume the asic to a functional state
8729 * @rdev: radeon_device pointer
8731 * Programs the asic to a functional state (CIK).
8733 * Returns 0 for success, error for failure.
8735 int cik_resume(struct radeon_device *rdev)
8740 atom_asic_init(rdev->mode_info.atom_context);
8742 /* init golden registers */
8743 cik_init_golden_registers(rdev);
8745 if (rdev->pm.pm_method == PM_METHOD_DPM)
8746 radeon_pm_resume(rdev);
8748 rdev->accel_working = true;
8749 r = cik_startup(rdev);
8751 DRM_ERROR("cik startup failed on resume\n");
8752 rdev->accel_working = false;
8761 * cik_suspend - suspend the asic
8763 * @rdev: radeon_device pointer
8765 * Bring the chip into a state suitable for suspend (CIK).
8766 * Called at suspend.
8767 * Returns 0 for success.
8769 int cik_suspend(struct radeon_device *rdev)
8771 radeon_kfd_suspend(rdev);
8772 radeon_pm_suspend(rdev);
8773 radeon_audio_fini(rdev);
8774 radeon_vm_manager_fini(rdev);
8775 cik_cp_enable(rdev, false);
8776 cik_sdma_enable(rdev, false);
8777 uvd_v1_0_fini(rdev);
8778 radeon_uvd_suspend(rdev);
8779 radeon_vce_suspend(rdev);
8782 cik_irq_suspend(rdev);
8783 radeon_wb_disable(rdev);
8784 cik_pcie_gart_disable(rdev);
8788 /* Plan is to move initialization in that function and use
8789 * helper function so that radeon_device_init pretty much
8790 * do nothing more than calling asic specific function. This
8791 * should also allow to remove a bunch of callback function
8795 * cik_init - asic specific driver and hw init
8797 * @rdev: radeon_device pointer
8799 * Setup asic specific driver variables and program the hw
8800 * to a functional state (CIK).
8801 * Called at driver startup.
8802 * Returns 0 for success, errors for failure.
8804 int cik_init(struct radeon_device *rdev)
8806 struct radeon_ring *ring;
8810 if (!radeon_get_bios(rdev)) {
8811 if (ASIC_IS_AVIVO(rdev))
8814 /* Must be an ATOMBIOS */
8815 if (!rdev->is_atom_bios) {
8816 dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
8819 r = radeon_atombios_init(rdev);
8823 /* Post card if necessary */
8824 if (!radeon_card_posted(rdev)) {
8826 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
8829 DRM_INFO("GPU not posted. posting now...\n");
8830 atom_asic_init(rdev->mode_info.atom_context);
8832 /* init golden registers */
8833 cik_init_golden_registers(rdev);
8834 /* Initialize scratch registers */
8835 cik_scratch_init(rdev);
8836 /* Initialize surface registers */
8837 radeon_surface_init(rdev);
8838 /* Initialize clocks */
8839 radeon_get_clock_info(rdev->ddev);
8842 r = radeon_fence_driver_init(rdev);
8846 /* initialize memory controller */
8847 r = cik_mc_init(rdev);
8850 /* Memory manager */
8851 r = radeon_bo_init(rdev);
8855 if (rdev->flags & RADEON_IS_IGP) {
8856 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
8857 !rdev->mec_fw || !rdev->sdma_fw || !rdev->rlc_fw) {
8858 r = cik_init_microcode(rdev);
8860 DRM_ERROR("Failed to load firmware!\n");
8865 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
8866 !rdev->mec_fw || !rdev->sdma_fw || !rdev->rlc_fw ||
8868 r = cik_init_microcode(rdev);
8870 DRM_ERROR("Failed to load firmware!\n");
8876 /* Initialize power management */
8877 radeon_pm_init(rdev);
8879 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
8880 ring->ring_obj = NULL;
8881 r600_ring_init(rdev, ring, 1024 * 1024);
8883 ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
8884 ring->ring_obj = NULL;
8885 r600_ring_init(rdev, ring, 1024 * 1024);
8886 r = radeon_doorbell_get(rdev, &ring->doorbell_index);
8890 ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
8891 ring->ring_obj = NULL;
8892 r600_ring_init(rdev, ring, 1024 * 1024);
8893 r = radeon_doorbell_get(rdev, &ring->doorbell_index);
8897 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
8898 ring->ring_obj = NULL;
8899 r600_ring_init(rdev, ring, 256 * 1024);
8901 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
8902 ring->ring_obj = NULL;
8903 r600_ring_init(rdev, ring, 256 * 1024);
8905 r = radeon_uvd_init(rdev);
8907 ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
8908 ring->ring_obj = NULL;
8909 r600_ring_init(rdev, ring, 4096);
8912 r = radeon_vce_init(rdev);
8914 ring = &rdev->ring[TN_RING_TYPE_VCE1_INDEX];
8915 ring->ring_obj = NULL;
8916 r600_ring_init(rdev, ring, 4096);
8918 ring = &rdev->ring[TN_RING_TYPE_VCE2_INDEX];
8919 ring->ring_obj = NULL;
8920 r600_ring_init(rdev, ring, 4096);
8923 rdev->ih.ring_obj = NULL;
8924 r600_ih_ring_init(rdev, 64 * 1024);
8926 r = r600_pcie_gart_init(rdev);
8930 rdev->accel_working = true;
8931 r = cik_startup(rdev);
8933 dev_err(rdev->dev, "disabling GPU acceleration\n");
8935 cik_sdma_fini(rdev);
8937 sumo_rlc_fini(rdev);
8939 radeon_wb_fini(rdev);
8940 radeon_ib_pool_fini(rdev);
8941 radeon_vm_manager_fini(rdev);
8942 radeon_irq_kms_fini(rdev);
8943 cik_pcie_gart_fini(rdev);
8944 rdev->accel_working = false;
8947 /* Don't start up if the MC ucode is missing.
8948 * The default clocks and voltages before the MC ucode
8949 * is loaded are not suffient for advanced operations.
8951 if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
8952 DRM_ERROR("radeon: MC ucode required for NI+.\n");
8960 * cik_fini - asic specific driver and hw fini
8962 * @rdev: radeon_device pointer
8964 * Tear down the asic specific driver variables and program the hw
8965 * to an idle state (CIK).
8966 * Called at driver unload.
8968 void cik_fini(struct radeon_device *rdev)
8970 radeon_pm_fini(rdev);
8972 cik_sdma_fini(rdev);
8976 sumo_rlc_fini(rdev);
8978 radeon_wb_fini(rdev);
8979 radeon_vm_manager_fini(rdev);
8980 radeon_ib_pool_fini(rdev);
8981 radeon_irq_kms_fini(rdev);
8982 uvd_v1_0_fini(rdev);
8983 radeon_uvd_fini(rdev);
8984 radeon_vce_fini(rdev);
8985 cik_pcie_gart_fini(rdev);
8986 r600_vram_scratch_fini(rdev);
8987 radeon_gem_fini(rdev);
8988 radeon_fence_driver_fini(rdev);
8989 radeon_bo_fini(rdev);
8990 radeon_atombios_fini(rdev);
8995 void dce8_program_fmt(struct drm_encoder *encoder)
8997 struct drm_device *dev = encoder->dev;
8998 struct radeon_device *rdev = dev->dev_private;
8999 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
9000 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
9001 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
9004 enum radeon_connector_dither dither = RADEON_FMT_DITHER_DISABLE;
9007 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
9008 bpc = radeon_get_monitor_bpc(connector);
9009 dither = radeon_connector->dither;
9012 /* LVDS/eDP FMT is set up by atom */
9013 if (radeon_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
9016 /* not needed for analog */
9017 if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1) ||
9018 (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2))
9026 if (dither == RADEON_FMT_DITHER_ENABLE)
9027 /* XXX sort out optimal dither settings */
9028 tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
9029 FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH(0));
9031 tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH(0));
9034 if (dither == RADEON_FMT_DITHER_ENABLE)
9035 /* XXX sort out optimal dither settings */
9036 tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
9037 FMT_RGB_RANDOM_ENABLE |
9038 FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH(1));
9040 tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH(1));
9043 if (dither == RADEON_FMT_DITHER_ENABLE)
9044 /* XXX sort out optimal dither settings */
9045 tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
9046 FMT_RGB_RANDOM_ENABLE |
9047 FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH(2));
9049 tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH(2));
9056 WREG32(FMT_BIT_DEPTH_CONTROL + radeon_crtc->crtc_offset, tmp);
9059 /* display watermark setup */
9061 * dce8_line_buffer_adjust - Set up the line buffer
9063 * @rdev: radeon_device pointer
9064 * @radeon_crtc: the selected display controller
9065 * @mode: the current display mode on the selected display
9068 * Setup up the line buffer allocation for
9069 * the selected display controller (CIK).
9070 * Returns the line buffer size in pixels.
9072 static u32 dce8_line_buffer_adjust(struct radeon_device *rdev,
9073 struct radeon_crtc *radeon_crtc,
9074 struct drm_display_mode *mode)
9076 u32 tmp, buffer_alloc, i;
9077 u32 pipe_offset = radeon_crtc->crtc_id * 0x20;
9080 * There are 6 line buffers, one for each display controllers.
9081 * There are 3 partitions per LB. Select the number of partitions
9082 * to enable based on the display width. For display widths larger
9083 * than 4096, you need use to use 2 display controllers and combine
9084 * them using the stereo blender.
9086 if (radeon_crtc->base.enabled && mode) {
9087 if (mode->crtc_hdisplay < 1920) {
9090 } else if (mode->crtc_hdisplay < 2560) {
9093 } else if (mode->crtc_hdisplay < 4096) {
9095 buffer_alloc = (rdev->flags & RADEON_IS_IGP) ? 2 : 4;
9097 DRM_DEBUG_KMS("Mode too big for LB!\n");
9099 buffer_alloc = (rdev->flags & RADEON_IS_IGP) ? 2 : 4;
9106 WREG32(LB_MEMORY_CTRL + radeon_crtc->crtc_offset,
9107 LB_MEMORY_CONFIG(tmp) | LB_MEMORY_SIZE(0x6B0));
9109 WREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
9110 DMIF_BUFFERS_ALLOCATED(buffer_alloc));
9111 for (i = 0; i < rdev->usec_timeout; i++) {
9112 if (RREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
9113 DMIF_BUFFERS_ALLOCATED_COMPLETED)
9118 if (radeon_crtc->base.enabled && mode) {
9130 /* controller not enabled, so no lb used */
9135 * cik_get_number_of_dram_channels - get the number of dram channels
9137 * @rdev: radeon_device pointer
9139 * Look up the number of video ram channels (CIK).
9140 * Used for display watermark bandwidth calculations
9141 * Returns the number of dram channels
9143 static u32 cik_get_number_of_dram_channels(struct radeon_device *rdev)
9145 u32 tmp = RREG32(MC_SHARED_CHMAP);
9147 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
9170 struct dce8_wm_params {
9171 u32 dram_channels; /* number of dram channels */
9172 u32 yclk; /* bandwidth per dram data pin in kHz */
9173 u32 sclk; /* engine clock in kHz */
9174 u32 disp_clk; /* display clock in kHz */
9175 u32 src_width; /* viewport width */
9176 u32 active_time; /* active display time in ns */
9177 u32 blank_time; /* blank time in ns */
9178 bool interlaced; /* mode is interlaced */
9179 fixed20_12 vsc; /* vertical scale ratio */
9180 u32 num_heads; /* number of active crtcs */
9181 u32 bytes_per_pixel; /* bytes per pixel display + overlay */
9182 u32 lb_size; /* line buffer allocated to pipe */
9183 u32 vtaps; /* vertical scaler taps */
9187 * dce8_dram_bandwidth - get the dram bandwidth
9189 * @wm: watermark calculation data
9191 * Calculate the raw dram bandwidth (CIK).
9192 * Used for display watermark bandwidth calculations
9193 * Returns the dram bandwidth in MBytes/s
9195 static u32 dce8_dram_bandwidth(struct dce8_wm_params *wm)
9197 /* Calculate raw DRAM Bandwidth */
9198 fixed20_12 dram_efficiency; /* 0.7 */
9199 fixed20_12 yclk, dram_channels, bandwidth;
9202 a.full = dfixed_const(1000);
9203 yclk.full = dfixed_const(wm->yclk);
9204 yclk.full = dfixed_div(yclk, a);
9205 dram_channels.full = dfixed_const(wm->dram_channels * 4);
9206 a.full = dfixed_const(10);
9207 dram_efficiency.full = dfixed_const(7);
9208 dram_efficiency.full = dfixed_div(dram_efficiency, a);
9209 bandwidth.full = dfixed_mul(dram_channels, yclk);
9210 bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
9212 return dfixed_trunc(bandwidth);
9216 * dce8_dram_bandwidth_for_display - get the dram bandwidth for display
9218 * @wm: watermark calculation data
9220 * Calculate the dram bandwidth used for display (CIK).
9221 * Used for display watermark bandwidth calculations
9222 * Returns the dram bandwidth for display in MBytes/s
9224 static u32 dce8_dram_bandwidth_for_display(struct dce8_wm_params *wm)
9226 /* Calculate DRAM Bandwidth and the part allocated to display. */
9227 fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
9228 fixed20_12 yclk, dram_channels, bandwidth;
9231 a.full = dfixed_const(1000);
9232 yclk.full = dfixed_const(wm->yclk);
9233 yclk.full = dfixed_div(yclk, a);
9234 dram_channels.full = dfixed_const(wm->dram_channels * 4);
9235 a.full = dfixed_const(10);
9236 disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
9237 disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
9238 bandwidth.full = dfixed_mul(dram_channels, yclk);
9239 bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
9241 return dfixed_trunc(bandwidth);
9245 * dce8_data_return_bandwidth - get the data return bandwidth
9247 * @wm: watermark calculation data
9249 * Calculate the data return bandwidth used for display (CIK).
9250 * Used for display watermark bandwidth calculations
9251 * Returns the data return bandwidth in MBytes/s
9253 static u32 dce8_data_return_bandwidth(struct dce8_wm_params *wm)
9255 /* Calculate the display Data return Bandwidth */
9256 fixed20_12 return_efficiency; /* 0.8 */
9257 fixed20_12 sclk, bandwidth;
9260 a.full = dfixed_const(1000);
9261 sclk.full = dfixed_const(wm->sclk);
9262 sclk.full = dfixed_div(sclk, a);
9263 a.full = dfixed_const(10);
9264 return_efficiency.full = dfixed_const(8);
9265 return_efficiency.full = dfixed_div(return_efficiency, a);
9266 a.full = dfixed_const(32);
9267 bandwidth.full = dfixed_mul(a, sclk);
9268 bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
9270 return dfixed_trunc(bandwidth);
9274 * dce8_dmif_request_bandwidth - get the dmif bandwidth
9276 * @wm: watermark calculation data
9278 * Calculate the dmif bandwidth used for display (CIK).
9279 * Used for display watermark bandwidth calculations
9280 * Returns the dmif bandwidth in MBytes/s
9282 static u32 dce8_dmif_request_bandwidth(struct dce8_wm_params *wm)
9284 /* Calculate the DMIF Request Bandwidth */
9285 fixed20_12 disp_clk_request_efficiency; /* 0.8 */
9286 fixed20_12 disp_clk, bandwidth;
9289 a.full = dfixed_const(1000);
9290 disp_clk.full = dfixed_const(wm->disp_clk);
9291 disp_clk.full = dfixed_div(disp_clk, a);
9292 a.full = dfixed_const(32);
9293 b.full = dfixed_mul(a, disp_clk);
9295 a.full = dfixed_const(10);
9296 disp_clk_request_efficiency.full = dfixed_const(8);
9297 disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
9299 bandwidth.full = dfixed_mul(b, disp_clk_request_efficiency);
9301 return dfixed_trunc(bandwidth);
9305 * dce8_available_bandwidth - get the min available bandwidth
9307 * @wm: watermark calculation data
9309 * Calculate the min available bandwidth used for display (CIK).
9310 * Used for display watermark bandwidth calculations
9311 * Returns the min available bandwidth in MBytes/s
9313 static u32 dce8_available_bandwidth(struct dce8_wm_params *wm)
9315 /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
9316 u32 dram_bandwidth = dce8_dram_bandwidth(wm);
9317 u32 data_return_bandwidth = dce8_data_return_bandwidth(wm);
9318 u32 dmif_req_bandwidth = dce8_dmif_request_bandwidth(wm);
9320 return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
9324 * dce8_average_bandwidth - get the average available bandwidth
9326 * @wm: watermark calculation data
9328 * Calculate the average available bandwidth used for display (CIK).
9329 * Used for display watermark bandwidth calculations
9330 * Returns the average available bandwidth in MBytes/s
9332 static u32 dce8_average_bandwidth(struct dce8_wm_params *wm)
9334 /* Calculate the display mode Average Bandwidth
9335 * DisplayMode should contain the source and destination dimensions,
9339 fixed20_12 line_time;
9340 fixed20_12 src_width;
9341 fixed20_12 bandwidth;
9344 a.full = dfixed_const(1000);
9345 line_time.full = dfixed_const(wm->active_time + wm->blank_time);
9346 line_time.full = dfixed_div(line_time, a);
9347 bpp.full = dfixed_const(wm->bytes_per_pixel);
9348 src_width.full = dfixed_const(wm->src_width);
9349 bandwidth.full = dfixed_mul(src_width, bpp);
9350 bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
9351 bandwidth.full = dfixed_div(bandwidth, line_time);
9353 return dfixed_trunc(bandwidth);
9357 * dce8_latency_watermark - get the latency watermark
9359 * @wm: watermark calculation data
9361 * Calculate the latency watermark (CIK).
9362 * Used for display watermark bandwidth calculations
9363 * Returns the latency watermark in ns
9365 static u32 dce8_latency_watermark(struct dce8_wm_params *wm)
9367 /* First calculate the latency in ns */
9368 u32 mc_latency = 2000; /* 2000 ns. */
9369 u32 available_bandwidth = dce8_available_bandwidth(wm);
9370 u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
9371 u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
9372 u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
9373 u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
9374 (wm->num_heads * cursor_line_pair_return_time);
9375 u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
9376 u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
9377 u32 tmp, dmif_size = 12288;
9380 if (wm->num_heads == 0)
9383 a.full = dfixed_const(2);
9384 b.full = dfixed_const(1);
9385 if ((wm->vsc.full > a.full) ||
9386 ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
9388 ((wm->vsc.full >= a.full) && wm->interlaced))
9389 max_src_lines_per_dst_line = 4;
9391 max_src_lines_per_dst_line = 2;
9393 a.full = dfixed_const(available_bandwidth);
9394 b.full = dfixed_const(wm->num_heads);
9395 a.full = dfixed_div(a, b);
9397 b.full = dfixed_const(mc_latency + 512);
9398 c.full = dfixed_const(wm->disp_clk);
9399 b.full = dfixed_div(b, c);
9401 c.full = dfixed_const(dmif_size);
9402 b.full = dfixed_div(c, b);
9404 tmp = min(dfixed_trunc(a), dfixed_trunc(b));
9406 b.full = dfixed_const(1000);
9407 c.full = dfixed_const(wm->disp_clk);
9408 b.full = dfixed_div(c, b);
9409 c.full = dfixed_const(wm->bytes_per_pixel);
9410 b.full = dfixed_mul(b, c);
9412 lb_fill_bw = min(tmp, dfixed_trunc(b));
9414 a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
9415 b.full = dfixed_const(1000);
9416 c.full = dfixed_const(lb_fill_bw);
9417 b.full = dfixed_div(c, b);
9418 a.full = dfixed_div(a, b);
9419 line_fill_time = dfixed_trunc(a);
9421 if (line_fill_time < wm->active_time)
9424 return latency + (line_fill_time - wm->active_time);
9429 * dce8_average_bandwidth_vs_dram_bandwidth_for_display - check
9430 * average and available dram bandwidth
9432 * @wm: watermark calculation data
9434 * Check if the display average bandwidth fits in the display
9435 * dram bandwidth (CIK).
9436 * Used for display watermark bandwidth calculations
9437 * Returns true if the display fits, false if not.
9439 static bool dce8_average_bandwidth_vs_dram_bandwidth_for_display(struct dce8_wm_params *wm)
9441 if (dce8_average_bandwidth(wm) <=
9442 (dce8_dram_bandwidth_for_display(wm) / wm->num_heads))
9449 * dce8_average_bandwidth_vs_available_bandwidth - check
9450 * average and available bandwidth
9452 * @wm: watermark calculation data
9454 * Check if the display average bandwidth fits in the display
9455 * available bandwidth (CIK).
9456 * Used for display watermark bandwidth calculations
9457 * Returns true if the display fits, false if not.
9459 static bool dce8_average_bandwidth_vs_available_bandwidth(struct dce8_wm_params *wm)
9461 if (dce8_average_bandwidth(wm) <=
9462 (dce8_available_bandwidth(wm) / wm->num_heads))
9469 * dce8_check_latency_hiding - check latency hiding
9471 * @wm: watermark calculation data
9473 * Check latency hiding (CIK).
9474 * Used for display watermark bandwidth calculations
9475 * Returns true if the display fits, false if not.
9477 static bool dce8_check_latency_hiding(struct dce8_wm_params *wm)
9479 u32 lb_partitions = wm->lb_size / wm->src_width;
9480 u32 line_time = wm->active_time + wm->blank_time;
9481 u32 latency_tolerant_lines;
9485 a.full = dfixed_const(1);
9486 if (wm->vsc.full > a.full)
9487 latency_tolerant_lines = 1;
9489 if (lb_partitions <= (wm->vtaps + 1))
9490 latency_tolerant_lines = 1;
9492 latency_tolerant_lines = 2;
9495 latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
9497 if (dce8_latency_watermark(wm) <= latency_hiding)
9504 * dce8_program_watermarks - program display watermarks
9506 * @rdev: radeon_device pointer
9507 * @radeon_crtc: the selected display controller
9508 * @lb_size: line buffer size
9509 * @num_heads: number of display controllers in use
9511 * Calculate and program the display watermarks for the
9512 * selected display controller (CIK).
9514 static void dce8_program_watermarks(struct radeon_device *rdev,
9515 struct radeon_crtc *radeon_crtc,
9516 u32 lb_size, u32 num_heads)
9518 struct drm_display_mode *mode = &radeon_crtc->base.mode;
9519 struct dce8_wm_params wm_low, wm_high;
9522 u32 latency_watermark_a = 0, latency_watermark_b = 0;
9525 if (radeon_crtc->base.enabled && num_heads && mode) {
9526 pixel_period = 1000000 / (u32)mode->clock;
9527 line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
9529 /* watermark for high clocks */
9530 if ((rdev->pm.pm_method == PM_METHOD_DPM) &&
9531 rdev->pm.dpm_enabled) {
9533 radeon_dpm_get_mclk(rdev, false) * 10;
9535 radeon_dpm_get_sclk(rdev, false) * 10;
9537 wm_high.yclk = rdev->pm.current_mclk * 10;
9538 wm_high.sclk = rdev->pm.current_sclk * 10;
9541 wm_high.disp_clk = mode->clock;
9542 wm_high.src_width = mode->crtc_hdisplay;
9543 wm_high.active_time = mode->crtc_hdisplay * pixel_period;
9544 wm_high.blank_time = line_time - wm_high.active_time;
9545 wm_high.interlaced = false;
9546 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
9547 wm_high.interlaced = true;
9548 wm_high.vsc = radeon_crtc->vsc;
9550 if (radeon_crtc->rmx_type != RMX_OFF)
9552 wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
9553 wm_high.lb_size = lb_size;
9554 wm_high.dram_channels = cik_get_number_of_dram_channels(rdev);
9555 wm_high.num_heads = num_heads;
9557 /* set for high clocks */
9558 latency_watermark_a = min(dce8_latency_watermark(&wm_high), (u32)65535);
9560 /* possibly force display priority to high */
9561 /* should really do this at mode validation time... */
9562 if (!dce8_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
9563 !dce8_average_bandwidth_vs_available_bandwidth(&wm_high) ||
9564 !dce8_check_latency_hiding(&wm_high) ||
9565 (rdev->disp_priority == 2)) {
9566 DRM_DEBUG_KMS("force priority to high\n");
9569 /* watermark for low clocks */
9570 if ((rdev->pm.pm_method == PM_METHOD_DPM) &&
9571 rdev->pm.dpm_enabled) {
9573 radeon_dpm_get_mclk(rdev, true) * 10;
9575 radeon_dpm_get_sclk(rdev, true) * 10;
9577 wm_low.yclk = rdev->pm.current_mclk * 10;
9578 wm_low.sclk = rdev->pm.current_sclk * 10;
9581 wm_low.disp_clk = mode->clock;
9582 wm_low.src_width = mode->crtc_hdisplay;
9583 wm_low.active_time = mode->crtc_hdisplay * pixel_period;
9584 wm_low.blank_time = line_time - wm_low.active_time;
9585 wm_low.interlaced = false;
9586 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
9587 wm_low.interlaced = true;
9588 wm_low.vsc = radeon_crtc->vsc;
9590 if (radeon_crtc->rmx_type != RMX_OFF)
9592 wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
9593 wm_low.lb_size = lb_size;
9594 wm_low.dram_channels = cik_get_number_of_dram_channels(rdev);
9595 wm_low.num_heads = num_heads;
9597 /* set for low clocks */
9598 latency_watermark_b = min(dce8_latency_watermark(&wm_low), (u32)65535);
9600 /* possibly force display priority to high */
9601 /* should really do this at mode validation time... */
9602 if (!dce8_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
9603 !dce8_average_bandwidth_vs_available_bandwidth(&wm_low) ||
9604 !dce8_check_latency_hiding(&wm_low) ||
9605 (rdev->disp_priority == 2)) {
9606 DRM_DEBUG_KMS("force priority to high\n");
9611 wm_mask = RREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset);
9613 tmp &= ~LATENCY_WATERMARK_MASK(3);
9614 tmp |= LATENCY_WATERMARK_MASK(1);
9615 WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, tmp);
9616 WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
9617 (LATENCY_LOW_WATERMARK(latency_watermark_a) |
9618 LATENCY_HIGH_WATERMARK(line_time)));
9620 tmp = RREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset);
9621 tmp &= ~LATENCY_WATERMARK_MASK(3);
9622 tmp |= LATENCY_WATERMARK_MASK(2);
9623 WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, tmp);
9624 WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
9625 (LATENCY_LOW_WATERMARK(latency_watermark_b) |
9626 LATENCY_HIGH_WATERMARK(line_time)));
9627 /* restore original selection */
9628 WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, wm_mask);
9630 /* save values for DPM */
9631 radeon_crtc->line_time = line_time;
9632 radeon_crtc->wm_high = latency_watermark_a;
9633 radeon_crtc->wm_low = latency_watermark_b;
9637 * dce8_bandwidth_update - program display watermarks
9639 * @rdev: radeon_device pointer
9641 * Calculate and program the display watermarks and line
9642 * buffer allocation (CIK).
9644 void dce8_bandwidth_update(struct radeon_device *rdev)
9646 struct drm_display_mode *mode = NULL;
9647 u32 num_heads = 0, lb_size;
9650 if (!rdev->mode_info.mode_config_initialized)
9653 radeon_update_display_priority(rdev);
9655 for (i = 0; i < rdev->num_crtc; i++) {
9656 if (rdev->mode_info.crtcs[i]->base.enabled)
9659 for (i = 0; i < rdev->num_crtc; i++) {
9660 mode = &rdev->mode_info.crtcs[i]->base.mode;
9661 lb_size = dce8_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode);
9662 dce8_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
9667 * cik_get_gpu_clock_counter - return GPU clock counter snapshot
9669 * @rdev: radeon_device pointer
9671 * Fetches a GPU clock counter snapshot (SI).
9672 * Returns the 64 bit clock counter snapshot.
9674 uint64_t cik_get_gpu_clock_counter(struct radeon_device *rdev)
9678 mutex_lock(&rdev->gpu_clock_mutex);
9679 WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
9680 clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
9681 ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
9682 mutex_unlock(&rdev->gpu_clock_mutex);
9686 static int cik_set_uvd_clock(struct radeon_device *rdev, u32 clock,
9687 u32 cntl_reg, u32 status_reg)
9690 struct atom_clock_dividers dividers;
9693 r = radeon_atom_get_clock_dividers(rdev, COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
9694 clock, false, ÷rs);
9698 tmp = RREG32_SMC(cntl_reg);
9699 tmp &= ~(DCLK_DIR_CNTL_EN|DCLK_DIVIDER_MASK);
9700 tmp |= dividers.post_divider;
9701 WREG32_SMC(cntl_reg, tmp);
9703 for (i = 0; i < 100; i++) {
9704 if (RREG32_SMC(status_reg) & DCLK_STATUS)
9714 int cik_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
9718 r = cik_set_uvd_clock(rdev, vclk, CG_VCLK_CNTL, CG_VCLK_STATUS);
9722 r = cik_set_uvd_clock(rdev, dclk, CG_DCLK_CNTL, CG_DCLK_STATUS);
9726 int cik_set_vce_clocks(struct radeon_device *rdev, u32 evclk, u32 ecclk)
9729 struct atom_clock_dividers dividers;
9732 r = radeon_atom_get_clock_dividers(rdev, COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
9733 ecclk, false, ÷rs);
9737 for (i = 0; i < 100; i++) {
9738 if (RREG32_SMC(CG_ECLK_STATUS) & ECLK_STATUS)
9745 tmp = RREG32_SMC(CG_ECLK_CNTL);
9746 tmp &= ~(ECLK_DIR_CNTL_EN|ECLK_DIVIDER_MASK);
9747 tmp |= dividers.post_divider;
9748 WREG32_SMC(CG_ECLK_CNTL, tmp);
9750 for (i = 0; i < 100; i++) {
9751 if (RREG32_SMC(CG_ECLK_STATUS) & ECLK_STATUS)
9761 static void cik_pcie_gen3_enable(struct radeon_device *rdev)
9763 struct pci_dev *root = rdev->pdev->bus->self;
9764 int bridge_pos, gpu_pos;
9765 u32 speed_cntl, mask, current_data_rate;
9769 if (pci_is_root_bus(rdev->pdev->bus))
9772 if (radeon_pcie_gen2 == 0)
9775 if (rdev->flags & RADEON_IS_IGP)
9778 if (!(rdev->flags & RADEON_IS_PCIE))
9781 ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask);
9785 if (!(mask & (DRM_PCIE_SPEED_50 | DRM_PCIE_SPEED_80)))
9788 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
9789 current_data_rate = (speed_cntl & LC_CURRENT_DATA_RATE_MASK) >>
9790 LC_CURRENT_DATA_RATE_SHIFT;
9791 if (mask & DRM_PCIE_SPEED_80) {
9792 if (current_data_rate == 2) {
9793 DRM_INFO("PCIE gen 3 link speeds already enabled\n");
9796 DRM_INFO("enabling PCIE gen 3 link speeds, disable with radeon.pcie_gen2=0\n");
9797 } else if (mask & DRM_PCIE_SPEED_50) {
9798 if (current_data_rate == 1) {
9799 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
9802 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
9805 bridge_pos = pci_pcie_cap(root);
9809 gpu_pos = pci_pcie_cap(rdev->pdev);
9813 if (mask & DRM_PCIE_SPEED_80) {
9814 /* re-try equalization if gen3 is not already enabled */
9815 if (current_data_rate != 2) {
9816 u16 bridge_cfg, gpu_cfg;
9817 u16 bridge_cfg2, gpu_cfg2;
9818 u32 max_lw, current_lw, tmp;
9820 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
9821 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
9823 tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
9824 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
9826 tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
9827 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
9829 tmp = RREG32_PCIE_PORT(PCIE_LC_STATUS1);
9830 max_lw = (tmp & LC_DETECTED_LINK_WIDTH_MASK) >> LC_DETECTED_LINK_WIDTH_SHIFT;
9831 current_lw = (tmp & LC_OPERATING_LINK_WIDTH_MASK) >> LC_OPERATING_LINK_WIDTH_SHIFT;
9833 if (current_lw < max_lw) {
9834 tmp = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
9835 if (tmp & LC_RENEGOTIATION_SUPPORT) {
9836 tmp &= ~(LC_LINK_WIDTH_MASK | LC_UPCONFIGURE_DIS);
9837 tmp |= (max_lw << LC_LINK_WIDTH_SHIFT);
9838 tmp |= LC_UPCONFIGURE_SUPPORT | LC_RENEGOTIATE_EN | LC_RECONFIG_NOW;
9839 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, tmp);
9843 for (i = 0; i < 10; i++) {
9845 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_DEVSTA, &tmp16);
9846 if (tmp16 & PCI_EXP_DEVSTA_TRPND)
9849 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
9850 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
9852 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &bridge_cfg2);
9853 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &gpu_cfg2);
9855 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
9856 tmp |= LC_SET_QUIESCE;
9857 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
9859 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
9861 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
9866 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &tmp16);
9867 tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
9868 tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
9869 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
9871 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &tmp16);
9872 tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
9873 tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
9874 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
9877 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &tmp16);
9878 tmp16 &= ~((1 << 4) | (7 << 9));
9879 tmp16 |= (bridge_cfg2 & ((1 << 4) | (7 << 9)));
9880 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, tmp16);
9882 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
9883 tmp16 &= ~((1 << 4) | (7 << 9));
9884 tmp16 |= (gpu_cfg2 & ((1 << 4) | (7 << 9)));
9885 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
9887 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
9888 tmp &= ~LC_SET_QUIESCE;
9889 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
9894 /* set the link speed */
9895 speed_cntl |= LC_FORCE_EN_SW_SPEED_CHANGE | LC_FORCE_DIS_HW_SPEED_CHANGE;
9896 speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
9897 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
9899 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
9901 if (mask & DRM_PCIE_SPEED_80)
9902 tmp16 |= 3; /* gen3 */
9903 else if (mask & DRM_PCIE_SPEED_50)
9904 tmp16 |= 2; /* gen2 */
9906 tmp16 |= 1; /* gen1 */
9907 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
9909 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
9910 speed_cntl |= LC_INITIATE_LINK_SPEED_CHANGE;
9911 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
9913 for (i = 0; i < rdev->usec_timeout; i++) {
9914 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
9915 if ((speed_cntl & LC_INITIATE_LINK_SPEED_CHANGE) == 0)
9921 static void cik_program_aspm(struct radeon_device *rdev)
9924 bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
9925 bool disable_clkreq = false;
9927 if (radeon_aspm == 0)
9930 /* XXX double check IGPs */
9931 if (rdev->flags & RADEON_IS_IGP)
9934 if (!(rdev->flags & RADEON_IS_PCIE))
9937 orig = data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
9938 data &= ~LC_XMIT_N_FTS_MASK;
9939 data |= LC_XMIT_N_FTS(0x24) | LC_XMIT_N_FTS_OVERRIDE_EN;
9941 WREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL, data);
9943 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL3);
9944 data |= LC_GO_TO_RECOVERY;
9946 WREG32_PCIE_PORT(PCIE_LC_CNTL3, data);
9948 orig = data = RREG32_PCIE_PORT(PCIE_P_CNTL);
9949 data |= P_IGNORE_EDB_ERR;
9951 WREG32_PCIE_PORT(PCIE_P_CNTL, data);
9953 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
9954 data &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
9955 data |= LC_PMI_TO_L1_DIS;
9957 data |= LC_L0S_INACTIVITY(7);
9960 data |= LC_L1_INACTIVITY(7);
9961 data &= ~LC_PMI_TO_L1_DIS;
9963 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
9965 if (!disable_plloff_in_l1) {
9966 bool clk_req_support;
9968 orig = data = RREG32_PCIE_PORT(PB0_PIF_PWRDOWN_0);
9969 data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
9970 data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
9972 WREG32_PCIE_PORT(PB0_PIF_PWRDOWN_0, data);
9974 orig = data = RREG32_PCIE_PORT(PB0_PIF_PWRDOWN_1);
9975 data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
9976 data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
9978 WREG32_PCIE_PORT(PB0_PIF_PWRDOWN_1, data);
9980 orig = data = RREG32_PCIE_PORT(PB1_PIF_PWRDOWN_0);
9981 data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
9982 data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
9984 WREG32_PCIE_PORT(PB1_PIF_PWRDOWN_0, data);
9986 orig = data = RREG32_PCIE_PORT(PB1_PIF_PWRDOWN_1);
9987 data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
9988 data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
9990 WREG32_PCIE_PORT(PB1_PIF_PWRDOWN_1, data);
9992 orig = data = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
9993 data &= ~LC_DYN_LANES_PWR_STATE_MASK;
9994 data |= LC_DYN_LANES_PWR_STATE(3);
9996 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
9998 if (!disable_clkreq &&
9999 !pci_is_root_bus(rdev->pdev->bus)) {
10000 struct pci_dev *root = rdev->pdev->bus->self;
10003 clk_req_support = false;
10004 pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
10005 if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
10006 clk_req_support = true;
10008 clk_req_support = false;
10011 if (clk_req_support) {
10012 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL2);
10013 data |= LC_ALLOW_PDWN_IN_L1 | LC_ALLOW_PDWN_IN_L23;
10015 WREG32_PCIE_PORT(PCIE_LC_CNTL2, data);
10017 orig = data = RREG32_SMC(THM_CLK_CNTL);
10018 data &= ~(CMON_CLK_SEL_MASK | TMON_CLK_SEL_MASK);
10019 data |= CMON_CLK_SEL(1) | TMON_CLK_SEL(1);
10021 WREG32_SMC(THM_CLK_CNTL, data);
10023 orig = data = RREG32_SMC(MISC_CLK_CTRL);
10024 data &= ~(DEEP_SLEEP_CLK_SEL_MASK | ZCLK_SEL_MASK);
10025 data |= DEEP_SLEEP_CLK_SEL(1) | ZCLK_SEL(1);
10027 WREG32_SMC(MISC_CLK_CTRL, data);
10029 orig = data = RREG32_SMC(CG_CLKPIN_CNTL);
10030 data &= ~BCLK_AS_XCLK;
10032 WREG32_SMC(CG_CLKPIN_CNTL, data);
10034 orig = data = RREG32_SMC(CG_CLKPIN_CNTL_2);
10035 data &= ~FORCE_BIF_REFCLK_EN;
10037 WREG32_SMC(CG_CLKPIN_CNTL_2, data);
10039 orig = data = RREG32_SMC(MPLL_BYPASSCLK_SEL);
10040 data &= ~MPLL_CLKOUT_SEL_MASK;
10041 data |= MPLL_CLKOUT_SEL(4);
10043 WREG32_SMC(MPLL_BYPASSCLK_SEL, data);
10048 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
10051 orig = data = RREG32_PCIE_PORT(PCIE_CNTL2);
10052 data |= SLV_MEM_LS_EN | MST_MEM_LS_EN | REPLAY_MEM_LS_EN;
10054 WREG32_PCIE_PORT(PCIE_CNTL2, data);
10056 if (!disable_l0s) {
10057 data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
10058 if((data & LC_N_FTS_MASK) == LC_N_FTS_MASK) {
10059 data = RREG32_PCIE_PORT(PCIE_LC_STATUS1);
10060 if ((data & LC_REVERSE_XMIT) && (data & LC_REVERSE_RCVR)) {
10061 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
10062 data &= ~LC_L0S_INACTIVITY_MASK;
10064 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);