blob: 1f088800295d4df93db113e234ca593d57d81993 [file] [log] [blame]
Alex Deucher8cc1a532013-04-09 12:41:24 -04001/*
2 * Copyright 2012 Advanced Micro Devices, Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 * Authors: Alex Deucher
23 */
24#include <linux/firmware.h>
Alex Deucher8cc1a532013-04-09 12:41:24 -040025#include <linux/slab.h>
26#include <linux/module.h>
27#include "drmP.h"
28#include "radeon.h"
Alex Deucher6f2043c2013-04-09 12:43:41 -040029#include "radeon_asic.h"
Alex Deucher8cc1a532013-04-09 12:41:24 -040030#include "cikd.h"
31#include "atom.h"
Alex Deucher841cf442012-12-18 21:47:44 -050032#include "cik_blit_shaders.h"
Alex Deucher8c68e392013-06-21 15:38:37 -040033#include "radeon_ucode.h"
Alex Deucher22c775c2013-07-23 09:41:05 -040034#include "clearstate_ci.h"
Alex Deucher02c81322012-12-18 21:43:07 -050035
36MODULE_FIRMWARE("radeon/BONAIRE_pfp.bin");
37MODULE_FIRMWARE("radeon/BONAIRE_me.bin");
38MODULE_FIRMWARE("radeon/BONAIRE_ce.bin");
39MODULE_FIRMWARE("radeon/BONAIRE_mec.bin");
40MODULE_FIRMWARE("radeon/BONAIRE_mc.bin");
41MODULE_FIRMWARE("radeon/BONAIRE_rlc.bin");
Alex Deucher21a93e12013-04-09 12:47:11 -040042MODULE_FIRMWARE("radeon/BONAIRE_sdma.bin");
Alex Deuchercc8dbbb2013-08-14 01:03:41 -040043MODULE_FIRMWARE("radeon/BONAIRE_smc.bin");
Alex Deucher02c81322012-12-18 21:43:07 -050044MODULE_FIRMWARE("radeon/KAVERI_pfp.bin");
45MODULE_FIRMWARE("radeon/KAVERI_me.bin");
46MODULE_FIRMWARE("radeon/KAVERI_ce.bin");
47MODULE_FIRMWARE("radeon/KAVERI_mec.bin");
48MODULE_FIRMWARE("radeon/KAVERI_rlc.bin");
Alex Deucher21a93e12013-04-09 12:47:11 -040049MODULE_FIRMWARE("radeon/KAVERI_sdma.bin");
Alex Deucher02c81322012-12-18 21:43:07 -050050MODULE_FIRMWARE("radeon/KABINI_pfp.bin");
51MODULE_FIRMWARE("radeon/KABINI_me.bin");
52MODULE_FIRMWARE("radeon/KABINI_ce.bin");
53MODULE_FIRMWARE("radeon/KABINI_mec.bin");
54MODULE_FIRMWARE("radeon/KABINI_rlc.bin");
Alex Deucher21a93e12013-04-09 12:47:11 -040055MODULE_FIRMWARE("radeon/KABINI_sdma.bin");
Alex Deucher02c81322012-12-18 21:43:07 -050056
Alex Deuchera59781b2012-11-09 10:45:57 -050057extern int r600_ih_ring_alloc(struct radeon_device *rdev);
58extern void r600_ih_ring_fini(struct radeon_device *rdev);
Alex Deucher6f2043c2013-04-09 12:43:41 -040059extern void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save);
60extern void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save);
Alex Deuchercc066712013-04-09 12:59:51 -040061extern bool evergreen_is_display_hung(struct radeon_device *rdev);
Alex Deucher1fd11772013-04-17 17:53:50 -040062extern void sumo_rlc_fini(struct radeon_device *rdev);
63extern int sumo_rlc_init(struct radeon_device *rdev);
Alex Deucher1c491652013-04-09 12:45:26 -040064extern void si_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
Alex Deucher866d83d2013-04-15 17:13:29 -040065extern void si_rlc_reset(struct radeon_device *rdev);
Alex Deucher22c775c2013-07-23 09:41:05 -040066extern void si_init_uvd_internal_cg(struct radeon_device *rdev);
Christian König2483b4e2013-08-13 11:56:54 +020067extern int cik_sdma_resume(struct radeon_device *rdev);
68extern void cik_sdma_enable(struct radeon_device *rdev, bool enable);
69extern void cik_sdma_fini(struct radeon_device *rdev);
70extern void cik_sdma_vm_set_page(struct radeon_device *rdev,
71 struct radeon_ib *ib,
72 uint64_t pe,
73 uint64_t addr, unsigned count,
74 uint32_t incr, uint32_t flags);
Alex Deuchercc066712013-04-09 12:59:51 -040075static void cik_rlc_stop(struct radeon_device *rdev);
Alex Deucher8a7cd272013-08-06 11:29:39 -040076static void cik_pcie_gen3_enable(struct radeon_device *rdev);
Alex Deucher7235711a42013-04-04 13:58:09 -040077static void cik_program_aspm(struct radeon_device *rdev);
Alex Deucher22c775c2013-07-23 09:41:05 -040078static void cik_init_pg(struct radeon_device *rdev);
79static void cik_init_cg(struct radeon_device *rdev);
Alex Deucher6f2043c2013-04-09 12:43:41 -040080
Alex Deucher286d9cc2013-06-21 15:50:47 -040081/* get temperature in millidegrees */
82int ci_get_temp(struct radeon_device *rdev)
83{
84 u32 temp;
85 int actual_temp = 0;
86
87 temp = (RREG32_SMC(CG_MULT_THERMAL_STATUS) & CTF_TEMP_MASK) >>
88 CTF_TEMP_SHIFT;
89
90 if (temp & 0x200)
91 actual_temp = 255;
92 else
93 actual_temp = temp & 0x1ff;
94
95 actual_temp = actual_temp * 1000;
96
97 return actual_temp;
98}
99
100/* get temperature in millidegrees */
101int kv_get_temp(struct radeon_device *rdev)
102{
103 u32 temp;
104 int actual_temp = 0;
105
106 temp = RREG32_SMC(0xC0300E0C);
107
108 if (temp)
109 actual_temp = (temp / 8) - 49;
110 else
111 actual_temp = 0;
112
113 actual_temp = actual_temp * 1000;
114
115 return actual_temp;
116}
117
Alex Deucher6e2c3c02013-04-03 19:28:32 -0400118/*
119 * Indirect registers accessor
120 */
121u32 cik_pciep_rreg(struct radeon_device *rdev, u32 reg)
122{
123 u32 r;
124
125 WREG32(PCIE_INDEX, reg);
126 (void)RREG32(PCIE_INDEX);
127 r = RREG32(PCIE_DATA);
128 return r;
129}
130
131void cik_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
132{
133 WREG32(PCIE_INDEX, reg);
134 (void)RREG32(PCIE_INDEX);
135 WREG32(PCIE_DATA, v);
136 (void)RREG32(PCIE_DATA);
137}
138
Alex Deucher22c775c2013-07-23 09:41:05 -0400139static const u32 spectre_rlc_save_restore_register_list[] =
140{
141 (0x0e00 << 16) | (0xc12c >> 2),
142 0x00000000,
143 (0x0e00 << 16) | (0xc140 >> 2),
144 0x00000000,
145 (0x0e00 << 16) | (0xc150 >> 2),
146 0x00000000,
147 (0x0e00 << 16) | (0xc15c >> 2),
148 0x00000000,
149 (0x0e00 << 16) | (0xc168 >> 2),
150 0x00000000,
151 (0x0e00 << 16) | (0xc170 >> 2),
152 0x00000000,
153 (0x0e00 << 16) | (0xc178 >> 2),
154 0x00000000,
155 (0x0e00 << 16) | (0xc204 >> 2),
156 0x00000000,
157 (0x0e00 << 16) | (0xc2b4 >> 2),
158 0x00000000,
159 (0x0e00 << 16) | (0xc2b8 >> 2),
160 0x00000000,
161 (0x0e00 << 16) | (0xc2bc >> 2),
162 0x00000000,
163 (0x0e00 << 16) | (0xc2c0 >> 2),
164 0x00000000,
165 (0x0e00 << 16) | (0x8228 >> 2),
166 0x00000000,
167 (0x0e00 << 16) | (0x829c >> 2),
168 0x00000000,
169 (0x0e00 << 16) | (0x869c >> 2),
170 0x00000000,
171 (0x0600 << 16) | (0x98f4 >> 2),
172 0x00000000,
173 (0x0e00 << 16) | (0x98f8 >> 2),
174 0x00000000,
175 (0x0e00 << 16) | (0x9900 >> 2),
176 0x00000000,
177 (0x0e00 << 16) | (0xc260 >> 2),
178 0x00000000,
179 (0x0e00 << 16) | (0x90e8 >> 2),
180 0x00000000,
181 (0x0e00 << 16) | (0x3c000 >> 2),
182 0x00000000,
183 (0x0e00 << 16) | (0x3c00c >> 2),
184 0x00000000,
185 (0x0e00 << 16) | (0x8c1c >> 2),
186 0x00000000,
187 (0x0e00 << 16) | (0x9700 >> 2),
188 0x00000000,
189 (0x0e00 << 16) | (0xcd20 >> 2),
190 0x00000000,
191 (0x4e00 << 16) | (0xcd20 >> 2),
192 0x00000000,
193 (0x5e00 << 16) | (0xcd20 >> 2),
194 0x00000000,
195 (0x6e00 << 16) | (0xcd20 >> 2),
196 0x00000000,
197 (0x7e00 << 16) | (0xcd20 >> 2),
198 0x00000000,
199 (0x8e00 << 16) | (0xcd20 >> 2),
200 0x00000000,
201 (0x9e00 << 16) | (0xcd20 >> 2),
202 0x00000000,
203 (0xae00 << 16) | (0xcd20 >> 2),
204 0x00000000,
205 (0xbe00 << 16) | (0xcd20 >> 2),
206 0x00000000,
207 (0x0e00 << 16) | (0x89bc >> 2),
208 0x00000000,
209 (0x0e00 << 16) | (0x8900 >> 2),
210 0x00000000,
211 0x3,
212 (0x0e00 << 16) | (0xc130 >> 2),
213 0x00000000,
214 (0x0e00 << 16) | (0xc134 >> 2),
215 0x00000000,
216 (0x0e00 << 16) | (0xc1fc >> 2),
217 0x00000000,
218 (0x0e00 << 16) | (0xc208 >> 2),
219 0x00000000,
220 (0x0e00 << 16) | (0xc264 >> 2),
221 0x00000000,
222 (0x0e00 << 16) | (0xc268 >> 2),
223 0x00000000,
224 (0x0e00 << 16) | (0xc26c >> 2),
225 0x00000000,
226 (0x0e00 << 16) | (0xc270 >> 2),
227 0x00000000,
228 (0x0e00 << 16) | (0xc274 >> 2),
229 0x00000000,
230 (0x0e00 << 16) | (0xc278 >> 2),
231 0x00000000,
232 (0x0e00 << 16) | (0xc27c >> 2),
233 0x00000000,
234 (0x0e00 << 16) | (0xc280 >> 2),
235 0x00000000,
236 (0x0e00 << 16) | (0xc284 >> 2),
237 0x00000000,
238 (0x0e00 << 16) | (0xc288 >> 2),
239 0x00000000,
240 (0x0e00 << 16) | (0xc28c >> 2),
241 0x00000000,
242 (0x0e00 << 16) | (0xc290 >> 2),
243 0x00000000,
244 (0x0e00 << 16) | (0xc294 >> 2),
245 0x00000000,
246 (0x0e00 << 16) | (0xc298 >> 2),
247 0x00000000,
248 (0x0e00 << 16) | (0xc29c >> 2),
249 0x00000000,
250 (0x0e00 << 16) | (0xc2a0 >> 2),
251 0x00000000,
252 (0x0e00 << 16) | (0xc2a4 >> 2),
253 0x00000000,
254 (0x0e00 << 16) | (0xc2a8 >> 2),
255 0x00000000,
256 (0x0e00 << 16) | (0xc2ac >> 2),
257 0x00000000,
258 (0x0e00 << 16) | (0xc2b0 >> 2),
259 0x00000000,
260 (0x0e00 << 16) | (0x301d0 >> 2),
261 0x00000000,
262 (0x0e00 << 16) | (0x30238 >> 2),
263 0x00000000,
264 (0x0e00 << 16) | (0x30250 >> 2),
265 0x00000000,
266 (0x0e00 << 16) | (0x30254 >> 2),
267 0x00000000,
268 (0x0e00 << 16) | (0x30258 >> 2),
269 0x00000000,
270 (0x0e00 << 16) | (0x3025c >> 2),
271 0x00000000,
272 (0x4e00 << 16) | (0xc900 >> 2),
273 0x00000000,
274 (0x5e00 << 16) | (0xc900 >> 2),
275 0x00000000,
276 (0x6e00 << 16) | (0xc900 >> 2),
277 0x00000000,
278 (0x7e00 << 16) | (0xc900 >> 2),
279 0x00000000,
280 (0x8e00 << 16) | (0xc900 >> 2),
281 0x00000000,
282 (0x9e00 << 16) | (0xc900 >> 2),
283 0x00000000,
284 (0xae00 << 16) | (0xc900 >> 2),
285 0x00000000,
286 (0xbe00 << 16) | (0xc900 >> 2),
287 0x00000000,
288 (0x4e00 << 16) | (0xc904 >> 2),
289 0x00000000,
290 (0x5e00 << 16) | (0xc904 >> 2),
291 0x00000000,
292 (0x6e00 << 16) | (0xc904 >> 2),
293 0x00000000,
294 (0x7e00 << 16) | (0xc904 >> 2),
295 0x00000000,
296 (0x8e00 << 16) | (0xc904 >> 2),
297 0x00000000,
298 (0x9e00 << 16) | (0xc904 >> 2),
299 0x00000000,
300 (0xae00 << 16) | (0xc904 >> 2),
301 0x00000000,
302 (0xbe00 << 16) | (0xc904 >> 2),
303 0x00000000,
304 (0x4e00 << 16) | (0xc908 >> 2),
305 0x00000000,
306 (0x5e00 << 16) | (0xc908 >> 2),
307 0x00000000,
308 (0x6e00 << 16) | (0xc908 >> 2),
309 0x00000000,
310 (0x7e00 << 16) | (0xc908 >> 2),
311 0x00000000,
312 (0x8e00 << 16) | (0xc908 >> 2),
313 0x00000000,
314 (0x9e00 << 16) | (0xc908 >> 2),
315 0x00000000,
316 (0xae00 << 16) | (0xc908 >> 2),
317 0x00000000,
318 (0xbe00 << 16) | (0xc908 >> 2),
319 0x00000000,
320 (0x4e00 << 16) | (0xc90c >> 2),
321 0x00000000,
322 (0x5e00 << 16) | (0xc90c >> 2),
323 0x00000000,
324 (0x6e00 << 16) | (0xc90c >> 2),
325 0x00000000,
326 (0x7e00 << 16) | (0xc90c >> 2),
327 0x00000000,
328 (0x8e00 << 16) | (0xc90c >> 2),
329 0x00000000,
330 (0x9e00 << 16) | (0xc90c >> 2),
331 0x00000000,
332 (0xae00 << 16) | (0xc90c >> 2),
333 0x00000000,
334 (0xbe00 << 16) | (0xc90c >> 2),
335 0x00000000,
336 (0x4e00 << 16) | (0xc910 >> 2),
337 0x00000000,
338 (0x5e00 << 16) | (0xc910 >> 2),
339 0x00000000,
340 (0x6e00 << 16) | (0xc910 >> 2),
341 0x00000000,
342 (0x7e00 << 16) | (0xc910 >> 2),
343 0x00000000,
344 (0x8e00 << 16) | (0xc910 >> 2),
345 0x00000000,
346 (0x9e00 << 16) | (0xc910 >> 2),
347 0x00000000,
348 (0xae00 << 16) | (0xc910 >> 2),
349 0x00000000,
350 (0xbe00 << 16) | (0xc910 >> 2),
351 0x00000000,
352 (0x0e00 << 16) | (0xc99c >> 2),
353 0x00000000,
354 (0x0e00 << 16) | (0x9834 >> 2),
355 0x00000000,
356 (0x0000 << 16) | (0x30f00 >> 2),
357 0x00000000,
358 (0x0001 << 16) | (0x30f00 >> 2),
359 0x00000000,
360 (0x0000 << 16) | (0x30f04 >> 2),
361 0x00000000,
362 (0x0001 << 16) | (0x30f04 >> 2),
363 0x00000000,
364 (0x0000 << 16) | (0x30f08 >> 2),
365 0x00000000,
366 (0x0001 << 16) | (0x30f08 >> 2),
367 0x00000000,
368 (0x0000 << 16) | (0x30f0c >> 2),
369 0x00000000,
370 (0x0001 << 16) | (0x30f0c >> 2),
371 0x00000000,
372 (0x0600 << 16) | (0x9b7c >> 2),
373 0x00000000,
374 (0x0e00 << 16) | (0x8a14 >> 2),
375 0x00000000,
376 (0x0e00 << 16) | (0x8a18 >> 2),
377 0x00000000,
378 (0x0600 << 16) | (0x30a00 >> 2),
379 0x00000000,
380 (0x0e00 << 16) | (0x8bf0 >> 2),
381 0x00000000,
382 (0x0e00 << 16) | (0x8bcc >> 2),
383 0x00000000,
384 (0x0e00 << 16) | (0x8b24 >> 2),
385 0x00000000,
386 (0x0e00 << 16) | (0x30a04 >> 2),
387 0x00000000,
388 (0x0600 << 16) | (0x30a10 >> 2),
389 0x00000000,
390 (0x0600 << 16) | (0x30a14 >> 2),
391 0x00000000,
392 (0x0600 << 16) | (0x30a18 >> 2),
393 0x00000000,
394 (0x0600 << 16) | (0x30a2c >> 2),
395 0x00000000,
396 (0x0e00 << 16) | (0xc700 >> 2),
397 0x00000000,
398 (0x0e00 << 16) | (0xc704 >> 2),
399 0x00000000,
400 (0x0e00 << 16) | (0xc708 >> 2),
401 0x00000000,
402 (0x0e00 << 16) | (0xc768 >> 2),
403 0x00000000,
404 (0x0400 << 16) | (0xc770 >> 2),
405 0x00000000,
406 (0x0400 << 16) | (0xc774 >> 2),
407 0x00000000,
408 (0x0400 << 16) | (0xc778 >> 2),
409 0x00000000,
410 (0x0400 << 16) | (0xc77c >> 2),
411 0x00000000,
412 (0x0400 << 16) | (0xc780 >> 2),
413 0x00000000,
414 (0x0400 << 16) | (0xc784 >> 2),
415 0x00000000,
416 (0x0400 << 16) | (0xc788 >> 2),
417 0x00000000,
418 (0x0400 << 16) | (0xc78c >> 2),
419 0x00000000,
420 (0x0400 << 16) | (0xc798 >> 2),
421 0x00000000,
422 (0x0400 << 16) | (0xc79c >> 2),
423 0x00000000,
424 (0x0400 << 16) | (0xc7a0 >> 2),
425 0x00000000,
426 (0x0400 << 16) | (0xc7a4 >> 2),
427 0x00000000,
428 (0x0400 << 16) | (0xc7a8 >> 2),
429 0x00000000,
430 (0x0400 << 16) | (0xc7ac >> 2),
431 0x00000000,
432 (0x0400 << 16) | (0xc7b0 >> 2),
433 0x00000000,
434 (0x0400 << 16) | (0xc7b4 >> 2),
435 0x00000000,
436 (0x0e00 << 16) | (0x9100 >> 2),
437 0x00000000,
438 (0x0e00 << 16) | (0x3c010 >> 2),
439 0x00000000,
440 (0x0e00 << 16) | (0x92a8 >> 2),
441 0x00000000,
442 (0x0e00 << 16) | (0x92ac >> 2),
443 0x00000000,
444 (0x0e00 << 16) | (0x92b4 >> 2),
445 0x00000000,
446 (0x0e00 << 16) | (0x92b8 >> 2),
447 0x00000000,
448 (0x0e00 << 16) | (0x92bc >> 2),
449 0x00000000,
450 (0x0e00 << 16) | (0x92c0 >> 2),
451 0x00000000,
452 (0x0e00 << 16) | (0x92c4 >> 2),
453 0x00000000,
454 (0x0e00 << 16) | (0x92c8 >> 2),
455 0x00000000,
456 (0x0e00 << 16) | (0x92cc >> 2),
457 0x00000000,
458 (0x0e00 << 16) | (0x92d0 >> 2),
459 0x00000000,
460 (0x0e00 << 16) | (0x8c00 >> 2),
461 0x00000000,
462 (0x0e00 << 16) | (0x8c04 >> 2),
463 0x00000000,
464 (0x0e00 << 16) | (0x8c20 >> 2),
465 0x00000000,
466 (0x0e00 << 16) | (0x8c38 >> 2),
467 0x00000000,
468 (0x0e00 << 16) | (0x8c3c >> 2),
469 0x00000000,
470 (0x0e00 << 16) | (0xae00 >> 2),
471 0x00000000,
472 (0x0e00 << 16) | (0x9604 >> 2),
473 0x00000000,
474 (0x0e00 << 16) | (0xac08 >> 2),
475 0x00000000,
476 (0x0e00 << 16) | (0xac0c >> 2),
477 0x00000000,
478 (0x0e00 << 16) | (0xac10 >> 2),
479 0x00000000,
480 (0x0e00 << 16) | (0xac14 >> 2),
481 0x00000000,
482 (0x0e00 << 16) | (0xac58 >> 2),
483 0x00000000,
484 (0x0e00 << 16) | (0xac68 >> 2),
485 0x00000000,
486 (0x0e00 << 16) | (0xac6c >> 2),
487 0x00000000,
488 (0x0e00 << 16) | (0xac70 >> 2),
489 0x00000000,
490 (0x0e00 << 16) | (0xac74 >> 2),
491 0x00000000,
492 (0x0e00 << 16) | (0xac78 >> 2),
493 0x00000000,
494 (0x0e00 << 16) | (0xac7c >> 2),
495 0x00000000,
496 (0x0e00 << 16) | (0xac80 >> 2),
497 0x00000000,
498 (0x0e00 << 16) | (0xac84 >> 2),
499 0x00000000,
500 (0x0e00 << 16) | (0xac88 >> 2),
501 0x00000000,
502 (0x0e00 << 16) | (0xac8c >> 2),
503 0x00000000,
504 (0x0e00 << 16) | (0x970c >> 2),
505 0x00000000,
506 (0x0e00 << 16) | (0x9714 >> 2),
507 0x00000000,
508 (0x0e00 << 16) | (0x9718 >> 2),
509 0x00000000,
510 (0x0e00 << 16) | (0x971c >> 2),
511 0x00000000,
512 (0x0e00 << 16) | (0x31068 >> 2),
513 0x00000000,
514 (0x4e00 << 16) | (0x31068 >> 2),
515 0x00000000,
516 (0x5e00 << 16) | (0x31068 >> 2),
517 0x00000000,
518 (0x6e00 << 16) | (0x31068 >> 2),
519 0x00000000,
520 (0x7e00 << 16) | (0x31068 >> 2),
521 0x00000000,
522 (0x8e00 << 16) | (0x31068 >> 2),
523 0x00000000,
524 (0x9e00 << 16) | (0x31068 >> 2),
525 0x00000000,
526 (0xae00 << 16) | (0x31068 >> 2),
527 0x00000000,
528 (0xbe00 << 16) | (0x31068 >> 2),
529 0x00000000,
530 (0x0e00 << 16) | (0xcd10 >> 2),
531 0x00000000,
532 (0x0e00 << 16) | (0xcd14 >> 2),
533 0x00000000,
534 (0x0e00 << 16) | (0x88b0 >> 2),
535 0x00000000,
536 (0x0e00 << 16) | (0x88b4 >> 2),
537 0x00000000,
538 (0x0e00 << 16) | (0x88b8 >> 2),
539 0x00000000,
540 (0x0e00 << 16) | (0x88bc >> 2),
541 0x00000000,
542 (0x0400 << 16) | (0x89c0 >> 2),
543 0x00000000,
544 (0x0e00 << 16) | (0x88c4 >> 2),
545 0x00000000,
546 (0x0e00 << 16) | (0x88c8 >> 2),
547 0x00000000,
548 (0x0e00 << 16) | (0x88d0 >> 2),
549 0x00000000,
550 (0x0e00 << 16) | (0x88d4 >> 2),
551 0x00000000,
552 (0x0e00 << 16) | (0x88d8 >> 2),
553 0x00000000,
554 (0x0e00 << 16) | (0x8980 >> 2),
555 0x00000000,
556 (0x0e00 << 16) | (0x30938 >> 2),
557 0x00000000,
558 (0x0e00 << 16) | (0x3093c >> 2),
559 0x00000000,
560 (0x0e00 << 16) | (0x30940 >> 2),
561 0x00000000,
562 (0x0e00 << 16) | (0x89a0 >> 2),
563 0x00000000,
564 (0x0e00 << 16) | (0x30900 >> 2),
565 0x00000000,
566 (0x0e00 << 16) | (0x30904 >> 2),
567 0x00000000,
568 (0x0e00 << 16) | (0x89b4 >> 2),
569 0x00000000,
570 (0x0e00 << 16) | (0x3c210 >> 2),
571 0x00000000,
572 (0x0e00 << 16) | (0x3c214 >> 2),
573 0x00000000,
574 (0x0e00 << 16) | (0x3c218 >> 2),
575 0x00000000,
576 (0x0e00 << 16) | (0x8904 >> 2),
577 0x00000000,
578 0x5,
579 (0x0e00 << 16) | (0x8c28 >> 2),
580 (0x0e00 << 16) | (0x8c2c >> 2),
581 (0x0e00 << 16) | (0x8c30 >> 2),
582 (0x0e00 << 16) | (0x8c34 >> 2),
583 (0x0e00 << 16) | (0x9600 >> 2),
584};
585
586static const u32 kalindi_rlc_save_restore_register_list[] =
587{
588 (0x0e00 << 16) | (0xc12c >> 2),
589 0x00000000,
590 (0x0e00 << 16) | (0xc140 >> 2),
591 0x00000000,
592 (0x0e00 << 16) | (0xc150 >> 2),
593 0x00000000,
594 (0x0e00 << 16) | (0xc15c >> 2),
595 0x00000000,
596 (0x0e00 << 16) | (0xc168 >> 2),
597 0x00000000,
598 (0x0e00 << 16) | (0xc170 >> 2),
599 0x00000000,
600 (0x0e00 << 16) | (0xc204 >> 2),
601 0x00000000,
602 (0x0e00 << 16) | (0xc2b4 >> 2),
603 0x00000000,
604 (0x0e00 << 16) | (0xc2b8 >> 2),
605 0x00000000,
606 (0x0e00 << 16) | (0xc2bc >> 2),
607 0x00000000,
608 (0x0e00 << 16) | (0xc2c0 >> 2),
609 0x00000000,
610 (0x0e00 << 16) | (0x8228 >> 2),
611 0x00000000,
612 (0x0e00 << 16) | (0x829c >> 2),
613 0x00000000,
614 (0x0e00 << 16) | (0x869c >> 2),
615 0x00000000,
616 (0x0600 << 16) | (0x98f4 >> 2),
617 0x00000000,
618 (0x0e00 << 16) | (0x98f8 >> 2),
619 0x00000000,
620 (0x0e00 << 16) | (0x9900 >> 2),
621 0x00000000,
622 (0x0e00 << 16) | (0xc260 >> 2),
623 0x00000000,
624 (0x0e00 << 16) | (0x90e8 >> 2),
625 0x00000000,
626 (0x0e00 << 16) | (0x3c000 >> 2),
627 0x00000000,
628 (0x0e00 << 16) | (0x3c00c >> 2),
629 0x00000000,
630 (0x0e00 << 16) | (0x8c1c >> 2),
631 0x00000000,
632 (0x0e00 << 16) | (0x9700 >> 2),
633 0x00000000,
634 (0x0e00 << 16) | (0xcd20 >> 2),
635 0x00000000,
636 (0x4e00 << 16) | (0xcd20 >> 2),
637 0x00000000,
638 (0x5e00 << 16) | (0xcd20 >> 2),
639 0x00000000,
640 (0x6e00 << 16) | (0xcd20 >> 2),
641 0x00000000,
642 (0x7e00 << 16) | (0xcd20 >> 2),
643 0x00000000,
644 (0x0e00 << 16) | (0x89bc >> 2),
645 0x00000000,
646 (0x0e00 << 16) | (0x8900 >> 2),
647 0x00000000,
648 0x3,
649 (0x0e00 << 16) | (0xc130 >> 2),
650 0x00000000,
651 (0x0e00 << 16) | (0xc134 >> 2),
652 0x00000000,
653 (0x0e00 << 16) | (0xc1fc >> 2),
654 0x00000000,
655 (0x0e00 << 16) | (0xc208 >> 2),
656 0x00000000,
657 (0x0e00 << 16) | (0xc264 >> 2),
658 0x00000000,
659 (0x0e00 << 16) | (0xc268 >> 2),
660 0x00000000,
661 (0x0e00 << 16) | (0xc26c >> 2),
662 0x00000000,
663 (0x0e00 << 16) | (0xc270 >> 2),
664 0x00000000,
665 (0x0e00 << 16) | (0xc274 >> 2),
666 0x00000000,
667 (0x0e00 << 16) | (0xc28c >> 2),
668 0x00000000,
669 (0x0e00 << 16) | (0xc290 >> 2),
670 0x00000000,
671 (0x0e00 << 16) | (0xc294 >> 2),
672 0x00000000,
673 (0x0e00 << 16) | (0xc298 >> 2),
674 0x00000000,
675 (0x0e00 << 16) | (0xc2a0 >> 2),
676 0x00000000,
677 (0x0e00 << 16) | (0xc2a4 >> 2),
678 0x00000000,
679 (0x0e00 << 16) | (0xc2a8 >> 2),
680 0x00000000,
681 (0x0e00 << 16) | (0xc2ac >> 2),
682 0x00000000,
683 (0x0e00 << 16) | (0x301d0 >> 2),
684 0x00000000,
685 (0x0e00 << 16) | (0x30238 >> 2),
686 0x00000000,
687 (0x0e00 << 16) | (0x30250 >> 2),
688 0x00000000,
689 (0x0e00 << 16) | (0x30254 >> 2),
690 0x00000000,
691 (0x0e00 << 16) | (0x30258 >> 2),
692 0x00000000,
693 (0x0e00 << 16) | (0x3025c >> 2),
694 0x00000000,
695 (0x4e00 << 16) | (0xc900 >> 2),
696 0x00000000,
697 (0x5e00 << 16) | (0xc900 >> 2),
698 0x00000000,
699 (0x6e00 << 16) | (0xc900 >> 2),
700 0x00000000,
701 (0x7e00 << 16) | (0xc900 >> 2),
702 0x00000000,
703 (0x4e00 << 16) | (0xc904 >> 2),
704 0x00000000,
705 (0x5e00 << 16) | (0xc904 >> 2),
706 0x00000000,
707 (0x6e00 << 16) | (0xc904 >> 2),
708 0x00000000,
709 (0x7e00 << 16) | (0xc904 >> 2),
710 0x00000000,
711 (0x4e00 << 16) | (0xc908 >> 2),
712 0x00000000,
713 (0x5e00 << 16) | (0xc908 >> 2),
714 0x00000000,
715 (0x6e00 << 16) | (0xc908 >> 2),
716 0x00000000,
717 (0x7e00 << 16) | (0xc908 >> 2),
718 0x00000000,
719 (0x4e00 << 16) | (0xc90c >> 2),
720 0x00000000,
721 (0x5e00 << 16) | (0xc90c >> 2),
722 0x00000000,
723 (0x6e00 << 16) | (0xc90c >> 2),
724 0x00000000,
725 (0x7e00 << 16) | (0xc90c >> 2),
726 0x00000000,
727 (0x4e00 << 16) | (0xc910 >> 2),
728 0x00000000,
729 (0x5e00 << 16) | (0xc910 >> 2),
730 0x00000000,
731 (0x6e00 << 16) | (0xc910 >> 2),
732 0x00000000,
733 (0x7e00 << 16) | (0xc910 >> 2),
734 0x00000000,
735 (0x0e00 << 16) | (0xc99c >> 2),
736 0x00000000,
737 (0x0e00 << 16) | (0x9834 >> 2),
738 0x00000000,
739 (0x0000 << 16) | (0x30f00 >> 2),
740 0x00000000,
741 (0x0000 << 16) | (0x30f04 >> 2),
742 0x00000000,
743 (0x0000 << 16) | (0x30f08 >> 2),
744 0x00000000,
745 (0x0000 << 16) | (0x30f0c >> 2),
746 0x00000000,
747 (0x0600 << 16) | (0x9b7c >> 2),
748 0x00000000,
749 (0x0e00 << 16) | (0x8a14 >> 2),
750 0x00000000,
751 (0x0e00 << 16) | (0x8a18 >> 2),
752 0x00000000,
753 (0x0600 << 16) | (0x30a00 >> 2),
754 0x00000000,
755 (0x0e00 << 16) | (0x8bf0 >> 2),
756 0x00000000,
757 (0x0e00 << 16) | (0x8bcc >> 2),
758 0x00000000,
759 (0x0e00 << 16) | (0x8b24 >> 2),
760 0x00000000,
761 (0x0e00 << 16) | (0x30a04 >> 2),
762 0x00000000,
763 (0x0600 << 16) | (0x30a10 >> 2),
764 0x00000000,
765 (0x0600 << 16) | (0x30a14 >> 2),
766 0x00000000,
767 (0x0600 << 16) | (0x30a18 >> 2),
768 0x00000000,
769 (0x0600 << 16) | (0x30a2c >> 2),
770 0x00000000,
771 (0x0e00 << 16) | (0xc700 >> 2),
772 0x00000000,
773 (0x0e00 << 16) | (0xc704 >> 2),
774 0x00000000,
775 (0x0e00 << 16) | (0xc708 >> 2),
776 0x00000000,
777 (0x0e00 << 16) | (0xc768 >> 2),
778 0x00000000,
779 (0x0400 << 16) | (0xc770 >> 2),
780 0x00000000,
781 (0x0400 << 16) | (0xc774 >> 2),
782 0x00000000,
783 (0x0400 << 16) | (0xc798 >> 2),
784 0x00000000,
785 (0x0400 << 16) | (0xc79c >> 2),
786 0x00000000,
787 (0x0e00 << 16) | (0x9100 >> 2),
788 0x00000000,
789 (0x0e00 << 16) | (0x3c010 >> 2),
790 0x00000000,
791 (0x0e00 << 16) | (0x8c00 >> 2),
792 0x00000000,
793 (0x0e00 << 16) | (0x8c04 >> 2),
794 0x00000000,
795 (0x0e00 << 16) | (0x8c20 >> 2),
796 0x00000000,
797 (0x0e00 << 16) | (0x8c38 >> 2),
798 0x00000000,
799 (0x0e00 << 16) | (0x8c3c >> 2),
800 0x00000000,
801 (0x0e00 << 16) | (0xae00 >> 2),
802 0x00000000,
803 (0x0e00 << 16) | (0x9604 >> 2),
804 0x00000000,
805 (0x0e00 << 16) | (0xac08 >> 2),
806 0x00000000,
807 (0x0e00 << 16) | (0xac0c >> 2),
808 0x00000000,
809 (0x0e00 << 16) | (0xac10 >> 2),
810 0x00000000,
811 (0x0e00 << 16) | (0xac14 >> 2),
812 0x00000000,
813 (0x0e00 << 16) | (0xac58 >> 2),
814 0x00000000,
815 (0x0e00 << 16) | (0xac68 >> 2),
816 0x00000000,
817 (0x0e00 << 16) | (0xac6c >> 2),
818 0x00000000,
819 (0x0e00 << 16) | (0xac70 >> 2),
820 0x00000000,
821 (0x0e00 << 16) | (0xac74 >> 2),
822 0x00000000,
823 (0x0e00 << 16) | (0xac78 >> 2),
824 0x00000000,
825 (0x0e00 << 16) | (0xac7c >> 2),
826 0x00000000,
827 (0x0e00 << 16) | (0xac80 >> 2),
828 0x00000000,
829 (0x0e00 << 16) | (0xac84 >> 2),
830 0x00000000,
831 (0x0e00 << 16) | (0xac88 >> 2),
832 0x00000000,
833 (0x0e00 << 16) | (0xac8c >> 2),
834 0x00000000,
835 (0x0e00 << 16) | (0x970c >> 2),
836 0x00000000,
837 (0x0e00 << 16) | (0x9714 >> 2),
838 0x00000000,
839 (0x0e00 << 16) | (0x9718 >> 2),
840 0x00000000,
841 (0x0e00 << 16) | (0x971c >> 2),
842 0x00000000,
843 (0x0e00 << 16) | (0x31068 >> 2),
844 0x00000000,
845 (0x4e00 << 16) | (0x31068 >> 2),
846 0x00000000,
847 (0x5e00 << 16) | (0x31068 >> 2),
848 0x00000000,
849 (0x6e00 << 16) | (0x31068 >> 2),
850 0x00000000,
851 (0x7e00 << 16) | (0x31068 >> 2),
852 0x00000000,
853 (0x0e00 << 16) | (0xcd10 >> 2),
854 0x00000000,
855 (0x0e00 << 16) | (0xcd14 >> 2),
856 0x00000000,
857 (0x0e00 << 16) | (0x88b0 >> 2),
858 0x00000000,
859 (0x0e00 << 16) | (0x88b4 >> 2),
860 0x00000000,
861 (0x0e00 << 16) | (0x88b8 >> 2),
862 0x00000000,
863 (0x0e00 << 16) | (0x88bc >> 2),
864 0x00000000,
865 (0x0400 << 16) | (0x89c0 >> 2),
866 0x00000000,
867 (0x0e00 << 16) | (0x88c4 >> 2),
868 0x00000000,
869 (0x0e00 << 16) | (0x88c8 >> 2),
870 0x00000000,
871 (0x0e00 << 16) | (0x88d0 >> 2),
872 0x00000000,
873 (0x0e00 << 16) | (0x88d4 >> 2),
874 0x00000000,
875 (0x0e00 << 16) | (0x88d8 >> 2),
876 0x00000000,
877 (0x0e00 << 16) | (0x8980 >> 2),
878 0x00000000,
879 (0x0e00 << 16) | (0x30938 >> 2),
880 0x00000000,
881 (0x0e00 << 16) | (0x3093c >> 2),
882 0x00000000,
883 (0x0e00 << 16) | (0x30940 >> 2),
884 0x00000000,
885 (0x0e00 << 16) | (0x89a0 >> 2),
886 0x00000000,
887 (0x0e00 << 16) | (0x30900 >> 2),
888 0x00000000,
889 (0x0e00 << 16) | (0x30904 >> 2),
890 0x00000000,
891 (0x0e00 << 16) | (0x89b4 >> 2),
892 0x00000000,
893 (0x0e00 << 16) | (0x3e1fc >> 2),
894 0x00000000,
895 (0x0e00 << 16) | (0x3c210 >> 2),
896 0x00000000,
897 (0x0e00 << 16) | (0x3c214 >> 2),
898 0x00000000,
899 (0x0e00 << 16) | (0x3c218 >> 2),
900 0x00000000,
901 (0x0e00 << 16) | (0x8904 >> 2),
902 0x00000000,
903 0x5,
904 (0x0e00 << 16) | (0x8c28 >> 2),
905 (0x0e00 << 16) | (0x8c2c >> 2),
906 (0x0e00 << 16) | (0x8c30 >> 2),
907 (0x0e00 << 16) | (0x8c34 >> 2),
908 (0x0e00 << 16) | (0x9600 >> 2),
909};
910
Alex Deucher0aafd312013-04-09 14:43:30 -0400911static const u32 bonaire_golden_spm_registers[] =
912{
913 0x30800, 0xe0ffffff, 0xe0000000
914};
915
916static const u32 bonaire_golden_common_registers[] =
917{
918 0xc770, 0xffffffff, 0x00000800,
919 0xc774, 0xffffffff, 0x00000800,
920 0xc798, 0xffffffff, 0x00007fbf,
921 0xc79c, 0xffffffff, 0x00007faf
922};
923
924static const u32 bonaire_golden_registers[] =
925{
926 0x3354, 0x00000333, 0x00000333,
927 0x3350, 0x000c0fc0, 0x00040200,
928 0x9a10, 0x00010000, 0x00058208,
929 0x3c000, 0xffff1fff, 0x00140000,
930 0x3c200, 0xfdfc0fff, 0x00000100,
931 0x3c234, 0x40000000, 0x40000200,
932 0x9830, 0xffffffff, 0x00000000,
933 0x9834, 0xf00fffff, 0x00000400,
934 0x9838, 0x0002021c, 0x00020200,
935 0xc78, 0x00000080, 0x00000000,
936 0x5bb0, 0x000000f0, 0x00000070,
937 0x5bc0, 0xf0311fff, 0x80300000,
938 0x98f8, 0x73773777, 0x12010001,
939 0x350c, 0x00810000, 0x408af000,
940 0x7030, 0x31000111, 0x00000011,
941 0x2f48, 0x73773777, 0x12010001,
942 0x220c, 0x00007fb6, 0x0021a1b1,
943 0x2210, 0x00007fb6, 0x002021b1,
944 0x2180, 0x00007fb6, 0x00002191,
945 0x2218, 0x00007fb6, 0x002121b1,
946 0x221c, 0x00007fb6, 0x002021b1,
947 0x21dc, 0x00007fb6, 0x00002191,
948 0x21e0, 0x00007fb6, 0x00002191,
949 0x3628, 0x0000003f, 0x0000000a,
950 0x362c, 0x0000003f, 0x0000000a,
951 0x2ae4, 0x00073ffe, 0x000022a2,
952 0x240c, 0x000007ff, 0x00000000,
953 0x8a14, 0xf000003f, 0x00000007,
954 0x8bf0, 0x00002001, 0x00000001,
955 0x8b24, 0xffffffff, 0x00ffffff,
956 0x30a04, 0x0000ff0f, 0x00000000,
957 0x28a4c, 0x07ffffff, 0x06000000,
958 0x4d8, 0x00000fff, 0x00000100,
959 0x3e78, 0x00000001, 0x00000002,
960 0x9100, 0x03000000, 0x0362c688,
961 0x8c00, 0x000000ff, 0x00000001,
962 0xe40, 0x00001fff, 0x00001fff,
963 0x9060, 0x0000007f, 0x00000020,
964 0x9508, 0x00010000, 0x00010000,
965 0xac14, 0x000003ff, 0x000000f3,
966 0xac0c, 0xffffffff, 0x00001032
967};
968
969static const u32 bonaire_mgcg_cgcg_init[] =
970{
971 0xc420, 0xffffffff, 0xfffffffc,
972 0x30800, 0xffffffff, 0xe0000000,
973 0x3c2a0, 0xffffffff, 0x00000100,
974 0x3c208, 0xffffffff, 0x00000100,
975 0x3c2c0, 0xffffffff, 0xc0000100,
976 0x3c2c8, 0xffffffff, 0xc0000100,
977 0x3c2c4, 0xffffffff, 0xc0000100,
978 0x55e4, 0xffffffff, 0x00600100,
979 0x3c280, 0xffffffff, 0x00000100,
980 0x3c214, 0xffffffff, 0x06000100,
981 0x3c220, 0xffffffff, 0x00000100,
982 0x3c218, 0xffffffff, 0x06000100,
983 0x3c204, 0xffffffff, 0x00000100,
984 0x3c2e0, 0xffffffff, 0x00000100,
985 0x3c224, 0xffffffff, 0x00000100,
986 0x3c200, 0xffffffff, 0x00000100,
987 0x3c230, 0xffffffff, 0x00000100,
988 0x3c234, 0xffffffff, 0x00000100,
989 0x3c250, 0xffffffff, 0x00000100,
990 0x3c254, 0xffffffff, 0x00000100,
991 0x3c258, 0xffffffff, 0x00000100,
992 0x3c25c, 0xffffffff, 0x00000100,
993 0x3c260, 0xffffffff, 0x00000100,
994 0x3c27c, 0xffffffff, 0x00000100,
995 0x3c278, 0xffffffff, 0x00000100,
996 0x3c210, 0xffffffff, 0x06000100,
997 0x3c290, 0xffffffff, 0x00000100,
998 0x3c274, 0xffffffff, 0x00000100,
999 0x3c2b4, 0xffffffff, 0x00000100,
1000 0x3c2b0, 0xffffffff, 0x00000100,
1001 0x3c270, 0xffffffff, 0x00000100,
1002 0x30800, 0xffffffff, 0xe0000000,
1003 0x3c020, 0xffffffff, 0x00010000,
1004 0x3c024, 0xffffffff, 0x00030002,
1005 0x3c028, 0xffffffff, 0x00040007,
1006 0x3c02c, 0xffffffff, 0x00060005,
1007 0x3c030, 0xffffffff, 0x00090008,
1008 0x3c034, 0xffffffff, 0x00010000,
1009 0x3c038, 0xffffffff, 0x00030002,
1010 0x3c03c, 0xffffffff, 0x00040007,
1011 0x3c040, 0xffffffff, 0x00060005,
1012 0x3c044, 0xffffffff, 0x00090008,
1013 0x3c048, 0xffffffff, 0x00010000,
1014 0x3c04c, 0xffffffff, 0x00030002,
1015 0x3c050, 0xffffffff, 0x00040007,
1016 0x3c054, 0xffffffff, 0x00060005,
1017 0x3c058, 0xffffffff, 0x00090008,
1018 0x3c05c, 0xffffffff, 0x00010000,
1019 0x3c060, 0xffffffff, 0x00030002,
1020 0x3c064, 0xffffffff, 0x00040007,
1021 0x3c068, 0xffffffff, 0x00060005,
1022 0x3c06c, 0xffffffff, 0x00090008,
1023 0x3c070, 0xffffffff, 0x00010000,
1024 0x3c074, 0xffffffff, 0x00030002,
1025 0x3c078, 0xffffffff, 0x00040007,
1026 0x3c07c, 0xffffffff, 0x00060005,
1027 0x3c080, 0xffffffff, 0x00090008,
1028 0x3c084, 0xffffffff, 0x00010000,
1029 0x3c088, 0xffffffff, 0x00030002,
1030 0x3c08c, 0xffffffff, 0x00040007,
1031 0x3c090, 0xffffffff, 0x00060005,
1032 0x3c094, 0xffffffff, 0x00090008,
1033 0x3c098, 0xffffffff, 0x00010000,
1034 0x3c09c, 0xffffffff, 0x00030002,
1035 0x3c0a0, 0xffffffff, 0x00040007,
1036 0x3c0a4, 0xffffffff, 0x00060005,
1037 0x3c0a8, 0xffffffff, 0x00090008,
1038 0x3c000, 0xffffffff, 0x96e00200,
1039 0x8708, 0xffffffff, 0x00900100,
1040 0xc424, 0xffffffff, 0x0020003f,
1041 0x38, 0xffffffff, 0x0140001c,
1042 0x3c, 0x000f0000, 0x000f0000,
1043 0x220, 0xffffffff, 0xC060000C,
1044 0x224, 0xc0000fff, 0x00000100,
1045 0xf90, 0xffffffff, 0x00000100,
1046 0xf98, 0x00000101, 0x00000000,
1047 0x20a8, 0xffffffff, 0x00000104,
1048 0x55e4, 0xff000fff, 0x00000100,
1049 0x30cc, 0xc0000fff, 0x00000104,
1050 0xc1e4, 0x00000001, 0x00000001,
1051 0xd00c, 0xff000ff0, 0x00000100,
1052 0xd80c, 0xff000ff0, 0x00000100
1053};
1054
1055static const u32 spectre_golden_spm_registers[] =
1056{
1057 0x30800, 0xe0ffffff, 0xe0000000
1058};
1059
1060static const u32 spectre_golden_common_registers[] =
1061{
1062 0xc770, 0xffffffff, 0x00000800,
1063 0xc774, 0xffffffff, 0x00000800,
1064 0xc798, 0xffffffff, 0x00007fbf,
1065 0xc79c, 0xffffffff, 0x00007faf
1066};
1067
1068static const u32 spectre_golden_registers[] =
1069{
1070 0x3c000, 0xffff1fff, 0x96940200,
1071 0x3c00c, 0xffff0001, 0xff000000,
1072 0x3c200, 0xfffc0fff, 0x00000100,
1073 0x6ed8, 0x00010101, 0x00010000,
1074 0x9834, 0xf00fffff, 0x00000400,
1075 0x9838, 0xfffffffc, 0x00020200,
1076 0x5bb0, 0x000000f0, 0x00000070,
1077 0x5bc0, 0xf0311fff, 0x80300000,
1078 0x98f8, 0x73773777, 0x12010001,
1079 0x9b7c, 0x00ff0000, 0x00fc0000,
1080 0x2f48, 0x73773777, 0x12010001,
1081 0x8a14, 0xf000003f, 0x00000007,
1082 0x8b24, 0xffffffff, 0x00ffffff,
1083 0x28350, 0x3f3f3fff, 0x00000082,
1084 0x28355, 0x0000003f, 0x00000000,
1085 0x3e78, 0x00000001, 0x00000002,
1086 0x913c, 0xffff03df, 0x00000004,
1087 0xc768, 0x00000008, 0x00000008,
1088 0x8c00, 0x000008ff, 0x00000800,
1089 0x9508, 0x00010000, 0x00010000,
1090 0xac0c, 0xffffffff, 0x54763210,
1091 0x214f8, 0x01ff01ff, 0x00000002,
1092 0x21498, 0x007ff800, 0x00200000,
1093 0x2015c, 0xffffffff, 0x00000f40,
1094 0x30934, 0xffffffff, 0x00000001
1095};
1096
1097static const u32 spectre_mgcg_cgcg_init[] =
1098{
1099 0xc420, 0xffffffff, 0xfffffffc,
1100 0x30800, 0xffffffff, 0xe0000000,
1101 0x3c2a0, 0xffffffff, 0x00000100,
1102 0x3c208, 0xffffffff, 0x00000100,
1103 0x3c2c0, 0xffffffff, 0x00000100,
1104 0x3c2c8, 0xffffffff, 0x00000100,
1105 0x3c2c4, 0xffffffff, 0x00000100,
1106 0x55e4, 0xffffffff, 0x00600100,
1107 0x3c280, 0xffffffff, 0x00000100,
1108 0x3c214, 0xffffffff, 0x06000100,
1109 0x3c220, 0xffffffff, 0x00000100,
1110 0x3c218, 0xffffffff, 0x06000100,
1111 0x3c204, 0xffffffff, 0x00000100,
1112 0x3c2e0, 0xffffffff, 0x00000100,
1113 0x3c224, 0xffffffff, 0x00000100,
1114 0x3c200, 0xffffffff, 0x00000100,
1115 0x3c230, 0xffffffff, 0x00000100,
1116 0x3c234, 0xffffffff, 0x00000100,
1117 0x3c250, 0xffffffff, 0x00000100,
1118 0x3c254, 0xffffffff, 0x00000100,
1119 0x3c258, 0xffffffff, 0x00000100,
1120 0x3c25c, 0xffffffff, 0x00000100,
1121 0x3c260, 0xffffffff, 0x00000100,
1122 0x3c27c, 0xffffffff, 0x00000100,
1123 0x3c278, 0xffffffff, 0x00000100,
1124 0x3c210, 0xffffffff, 0x06000100,
1125 0x3c290, 0xffffffff, 0x00000100,
1126 0x3c274, 0xffffffff, 0x00000100,
1127 0x3c2b4, 0xffffffff, 0x00000100,
1128 0x3c2b0, 0xffffffff, 0x00000100,
1129 0x3c270, 0xffffffff, 0x00000100,
1130 0x30800, 0xffffffff, 0xe0000000,
1131 0x3c020, 0xffffffff, 0x00010000,
1132 0x3c024, 0xffffffff, 0x00030002,
1133 0x3c028, 0xffffffff, 0x00040007,
1134 0x3c02c, 0xffffffff, 0x00060005,
1135 0x3c030, 0xffffffff, 0x00090008,
1136 0x3c034, 0xffffffff, 0x00010000,
1137 0x3c038, 0xffffffff, 0x00030002,
1138 0x3c03c, 0xffffffff, 0x00040007,
1139 0x3c040, 0xffffffff, 0x00060005,
1140 0x3c044, 0xffffffff, 0x00090008,
1141 0x3c048, 0xffffffff, 0x00010000,
1142 0x3c04c, 0xffffffff, 0x00030002,
1143 0x3c050, 0xffffffff, 0x00040007,
1144 0x3c054, 0xffffffff, 0x00060005,
1145 0x3c058, 0xffffffff, 0x00090008,
1146 0x3c05c, 0xffffffff, 0x00010000,
1147 0x3c060, 0xffffffff, 0x00030002,
1148 0x3c064, 0xffffffff, 0x00040007,
1149 0x3c068, 0xffffffff, 0x00060005,
1150 0x3c06c, 0xffffffff, 0x00090008,
1151 0x3c070, 0xffffffff, 0x00010000,
1152 0x3c074, 0xffffffff, 0x00030002,
1153 0x3c078, 0xffffffff, 0x00040007,
1154 0x3c07c, 0xffffffff, 0x00060005,
1155 0x3c080, 0xffffffff, 0x00090008,
1156 0x3c084, 0xffffffff, 0x00010000,
1157 0x3c088, 0xffffffff, 0x00030002,
1158 0x3c08c, 0xffffffff, 0x00040007,
1159 0x3c090, 0xffffffff, 0x00060005,
1160 0x3c094, 0xffffffff, 0x00090008,
1161 0x3c098, 0xffffffff, 0x00010000,
1162 0x3c09c, 0xffffffff, 0x00030002,
1163 0x3c0a0, 0xffffffff, 0x00040007,
1164 0x3c0a4, 0xffffffff, 0x00060005,
1165 0x3c0a8, 0xffffffff, 0x00090008,
1166 0x3c0ac, 0xffffffff, 0x00010000,
1167 0x3c0b0, 0xffffffff, 0x00030002,
1168 0x3c0b4, 0xffffffff, 0x00040007,
1169 0x3c0b8, 0xffffffff, 0x00060005,
1170 0x3c0bc, 0xffffffff, 0x00090008,
1171 0x3c000, 0xffffffff, 0x96e00200,
1172 0x8708, 0xffffffff, 0x00900100,
1173 0xc424, 0xffffffff, 0x0020003f,
1174 0x38, 0xffffffff, 0x0140001c,
1175 0x3c, 0x000f0000, 0x000f0000,
1176 0x220, 0xffffffff, 0xC060000C,
1177 0x224, 0xc0000fff, 0x00000100,
1178 0xf90, 0xffffffff, 0x00000100,
1179 0xf98, 0x00000101, 0x00000000,
1180 0x20a8, 0xffffffff, 0x00000104,
1181 0x55e4, 0xff000fff, 0x00000100,
1182 0x30cc, 0xc0000fff, 0x00000104,
1183 0xc1e4, 0x00000001, 0x00000001,
1184 0xd00c, 0xff000ff0, 0x00000100,
1185 0xd80c, 0xff000ff0, 0x00000100
1186};
1187
1188static const u32 kalindi_golden_spm_registers[] =
1189{
1190 0x30800, 0xe0ffffff, 0xe0000000
1191};
1192
1193static const u32 kalindi_golden_common_registers[] =
1194{
1195 0xc770, 0xffffffff, 0x00000800,
1196 0xc774, 0xffffffff, 0x00000800,
1197 0xc798, 0xffffffff, 0x00007fbf,
1198 0xc79c, 0xffffffff, 0x00007faf
1199};
1200
1201static const u32 kalindi_golden_registers[] =
1202{
1203 0x3c000, 0xffffdfff, 0x6e944040,
1204 0x55e4, 0xff607fff, 0xfc000100,
1205 0x3c220, 0xff000fff, 0x00000100,
1206 0x3c224, 0xff000fff, 0x00000100,
1207 0x3c200, 0xfffc0fff, 0x00000100,
1208 0x6ed8, 0x00010101, 0x00010000,
1209 0x9830, 0xffffffff, 0x00000000,
1210 0x9834, 0xf00fffff, 0x00000400,
1211 0x5bb0, 0x000000f0, 0x00000070,
1212 0x5bc0, 0xf0311fff, 0x80300000,
1213 0x98f8, 0x73773777, 0x12010001,
1214 0x98fc, 0xffffffff, 0x00000010,
1215 0x9b7c, 0x00ff0000, 0x00fc0000,
1216 0x8030, 0x00001f0f, 0x0000100a,
1217 0x2f48, 0x73773777, 0x12010001,
1218 0x2408, 0x000fffff, 0x000c007f,
1219 0x8a14, 0xf000003f, 0x00000007,
1220 0x8b24, 0x3fff3fff, 0x00ffcfff,
1221 0x30a04, 0x0000ff0f, 0x00000000,
1222 0x28a4c, 0x07ffffff, 0x06000000,
1223 0x4d8, 0x00000fff, 0x00000100,
1224 0x3e78, 0x00000001, 0x00000002,
1225 0xc768, 0x00000008, 0x00000008,
1226 0x8c00, 0x000000ff, 0x00000003,
1227 0x214f8, 0x01ff01ff, 0x00000002,
1228 0x21498, 0x007ff800, 0x00200000,
1229 0x2015c, 0xffffffff, 0x00000f40,
1230 0x88c4, 0x001f3ae3, 0x00000082,
1231 0x88d4, 0x0000001f, 0x00000010,
1232 0x30934, 0xffffffff, 0x00000000
1233};
1234
1235static const u32 kalindi_mgcg_cgcg_init[] =
1236{
1237 0xc420, 0xffffffff, 0xfffffffc,
1238 0x30800, 0xffffffff, 0xe0000000,
1239 0x3c2a0, 0xffffffff, 0x00000100,
1240 0x3c208, 0xffffffff, 0x00000100,
1241 0x3c2c0, 0xffffffff, 0x00000100,
1242 0x3c2c8, 0xffffffff, 0x00000100,
1243 0x3c2c4, 0xffffffff, 0x00000100,
1244 0x55e4, 0xffffffff, 0x00600100,
1245 0x3c280, 0xffffffff, 0x00000100,
1246 0x3c214, 0xffffffff, 0x06000100,
1247 0x3c220, 0xffffffff, 0x00000100,
1248 0x3c218, 0xffffffff, 0x06000100,
1249 0x3c204, 0xffffffff, 0x00000100,
1250 0x3c2e0, 0xffffffff, 0x00000100,
1251 0x3c224, 0xffffffff, 0x00000100,
1252 0x3c200, 0xffffffff, 0x00000100,
1253 0x3c230, 0xffffffff, 0x00000100,
1254 0x3c234, 0xffffffff, 0x00000100,
1255 0x3c250, 0xffffffff, 0x00000100,
1256 0x3c254, 0xffffffff, 0x00000100,
1257 0x3c258, 0xffffffff, 0x00000100,
1258 0x3c25c, 0xffffffff, 0x00000100,
1259 0x3c260, 0xffffffff, 0x00000100,
1260 0x3c27c, 0xffffffff, 0x00000100,
1261 0x3c278, 0xffffffff, 0x00000100,
1262 0x3c210, 0xffffffff, 0x06000100,
1263 0x3c290, 0xffffffff, 0x00000100,
1264 0x3c274, 0xffffffff, 0x00000100,
1265 0x3c2b4, 0xffffffff, 0x00000100,
1266 0x3c2b0, 0xffffffff, 0x00000100,
1267 0x3c270, 0xffffffff, 0x00000100,
1268 0x30800, 0xffffffff, 0xe0000000,
1269 0x3c020, 0xffffffff, 0x00010000,
1270 0x3c024, 0xffffffff, 0x00030002,
1271 0x3c028, 0xffffffff, 0x00040007,
1272 0x3c02c, 0xffffffff, 0x00060005,
1273 0x3c030, 0xffffffff, 0x00090008,
1274 0x3c034, 0xffffffff, 0x00010000,
1275 0x3c038, 0xffffffff, 0x00030002,
1276 0x3c03c, 0xffffffff, 0x00040007,
1277 0x3c040, 0xffffffff, 0x00060005,
1278 0x3c044, 0xffffffff, 0x00090008,
1279 0x3c000, 0xffffffff, 0x96e00200,
1280 0x8708, 0xffffffff, 0x00900100,
1281 0xc424, 0xffffffff, 0x0020003f,
1282 0x38, 0xffffffff, 0x0140001c,
1283 0x3c, 0x000f0000, 0x000f0000,
1284 0x220, 0xffffffff, 0xC060000C,
1285 0x224, 0xc0000fff, 0x00000100,
1286 0x20a8, 0xffffffff, 0x00000104,
1287 0x55e4, 0xff000fff, 0x00000100,
1288 0x30cc, 0xc0000fff, 0x00000104,
1289 0xc1e4, 0x00000001, 0x00000001,
1290 0xd00c, 0xff000ff0, 0x00000100,
1291 0xd80c, 0xff000ff0, 0x00000100
1292};
1293
1294static void cik_init_golden_registers(struct radeon_device *rdev)
1295{
1296 switch (rdev->family) {
1297 case CHIP_BONAIRE:
1298 radeon_program_register_sequence(rdev,
1299 bonaire_mgcg_cgcg_init,
1300 (const u32)ARRAY_SIZE(bonaire_mgcg_cgcg_init));
1301 radeon_program_register_sequence(rdev,
1302 bonaire_golden_registers,
1303 (const u32)ARRAY_SIZE(bonaire_golden_registers));
1304 radeon_program_register_sequence(rdev,
1305 bonaire_golden_common_registers,
1306 (const u32)ARRAY_SIZE(bonaire_golden_common_registers));
1307 radeon_program_register_sequence(rdev,
1308 bonaire_golden_spm_registers,
1309 (const u32)ARRAY_SIZE(bonaire_golden_spm_registers));
1310 break;
1311 case CHIP_KABINI:
1312 radeon_program_register_sequence(rdev,
1313 kalindi_mgcg_cgcg_init,
1314 (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
1315 radeon_program_register_sequence(rdev,
1316 kalindi_golden_registers,
1317 (const u32)ARRAY_SIZE(kalindi_golden_registers));
1318 radeon_program_register_sequence(rdev,
1319 kalindi_golden_common_registers,
1320 (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
1321 radeon_program_register_sequence(rdev,
1322 kalindi_golden_spm_registers,
1323 (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
1324 break;
1325 case CHIP_KAVERI:
1326 radeon_program_register_sequence(rdev,
1327 spectre_mgcg_cgcg_init,
1328 (const u32)ARRAY_SIZE(spectre_mgcg_cgcg_init));
1329 radeon_program_register_sequence(rdev,
1330 spectre_golden_registers,
1331 (const u32)ARRAY_SIZE(spectre_golden_registers));
1332 radeon_program_register_sequence(rdev,
1333 spectre_golden_common_registers,
1334 (const u32)ARRAY_SIZE(spectre_golden_common_registers));
1335 radeon_program_register_sequence(rdev,
1336 spectre_golden_spm_registers,
1337 (const u32)ARRAY_SIZE(spectre_golden_spm_registers));
1338 break;
1339 default:
1340 break;
1341 }
1342}
1343
Alex Deucher2c679122013-04-09 13:32:18 -04001344/**
1345 * cik_get_xclk - get the xclk
1346 *
1347 * @rdev: radeon_device pointer
1348 *
1349 * Returns the reference clock used by the gfx engine
1350 * (CIK).
1351 */
1352u32 cik_get_xclk(struct radeon_device *rdev)
1353{
1354 u32 reference_clock = rdev->clock.spll.reference_freq;
1355
1356 if (rdev->flags & RADEON_IS_IGP) {
1357 if (RREG32_SMC(GENERAL_PWRMGT) & GPU_COUNTER_CLK)
1358 return reference_clock / 2;
1359 } else {
1360 if (RREG32_SMC(CG_CLKPIN_CNTL) & XTALIN_DIVIDE)
1361 return reference_clock / 4;
1362 }
1363 return reference_clock;
1364}
1365
Alex Deucher75efdee2013-03-04 12:47:46 -05001366/**
1367 * cik_mm_rdoorbell - read a doorbell dword
1368 *
1369 * @rdev: radeon_device pointer
1370 * @offset: byte offset into the aperture
1371 *
1372 * Returns the value in the doorbell aperture at the
1373 * requested offset (CIK).
1374 */
1375u32 cik_mm_rdoorbell(struct radeon_device *rdev, u32 offset)
1376{
1377 if (offset < rdev->doorbell.size) {
1378 return readl(((void __iomem *)rdev->doorbell.ptr) + offset);
1379 } else {
1380 DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", offset);
1381 return 0;
1382 }
1383}
1384
1385/**
1386 * cik_mm_wdoorbell - write a doorbell dword
1387 *
1388 * @rdev: radeon_device pointer
1389 * @offset: byte offset into the aperture
1390 * @v: value to write
1391 *
1392 * Writes @v to the doorbell aperture at the
1393 * requested offset (CIK).
1394 */
1395void cik_mm_wdoorbell(struct radeon_device *rdev, u32 offset, u32 v)
1396{
1397 if (offset < rdev->doorbell.size) {
1398 writel(v, ((void __iomem *)rdev->doorbell.ptr) + offset);
1399 } else {
1400 DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", offset);
1401 }
1402}
1403
Alex Deucherbc8273f2012-06-29 19:44:04 -04001404#define BONAIRE_IO_MC_REGS_SIZE 36
1405
1406static const u32 bonaire_io_mc_regs[BONAIRE_IO_MC_REGS_SIZE][2] =
1407{
1408 {0x00000070, 0x04400000},
1409 {0x00000071, 0x80c01803},
1410 {0x00000072, 0x00004004},
1411 {0x00000073, 0x00000100},
1412 {0x00000074, 0x00ff0000},
1413 {0x00000075, 0x34000000},
1414 {0x00000076, 0x08000014},
1415 {0x00000077, 0x00cc08ec},
1416 {0x00000078, 0x00000400},
1417 {0x00000079, 0x00000000},
1418 {0x0000007a, 0x04090000},
1419 {0x0000007c, 0x00000000},
1420 {0x0000007e, 0x4408a8e8},
1421 {0x0000007f, 0x00000304},
1422 {0x00000080, 0x00000000},
1423 {0x00000082, 0x00000001},
1424 {0x00000083, 0x00000002},
1425 {0x00000084, 0xf3e4f400},
1426 {0x00000085, 0x052024e3},
1427 {0x00000087, 0x00000000},
1428 {0x00000088, 0x01000000},
1429 {0x0000008a, 0x1c0a0000},
1430 {0x0000008b, 0xff010000},
1431 {0x0000008d, 0xffffefff},
1432 {0x0000008e, 0xfff3efff},
1433 {0x0000008f, 0xfff3efbf},
1434 {0x00000092, 0xf7ffffff},
1435 {0x00000093, 0xffffff7f},
1436 {0x00000095, 0x00101101},
1437 {0x00000096, 0x00000fff},
1438 {0x00000097, 0x00116fff},
1439 {0x00000098, 0x60010000},
1440 {0x00000099, 0x10010000},
1441 {0x0000009a, 0x00006000},
1442 {0x0000009b, 0x00001000},
1443 {0x0000009f, 0x00b48000}
1444};
1445
Alex Deucherb556b122013-01-29 10:44:22 -05001446/**
1447 * cik_srbm_select - select specific register instances
1448 *
1449 * @rdev: radeon_device pointer
1450 * @me: selected ME (micro engine)
1451 * @pipe: pipe
1452 * @queue: queue
1453 * @vmid: VMID
1454 *
1455 * Switches the currently active registers instances. Some
1456 * registers are instanced per VMID, others are instanced per
1457 * me/pipe/queue combination.
1458 */
1459static void cik_srbm_select(struct radeon_device *rdev,
1460 u32 me, u32 pipe, u32 queue, u32 vmid)
1461{
1462 u32 srbm_gfx_cntl = (PIPEID(pipe & 0x3) |
1463 MEID(me & 0x3) |
1464 VMID(vmid & 0xf) |
1465 QUEUEID(queue & 0x7));
1466 WREG32(SRBM_GFX_CNTL, srbm_gfx_cntl);
1467}
1468
Alex Deucherbc8273f2012-06-29 19:44:04 -04001469/* ucode loading */
1470/**
1471 * ci_mc_load_microcode - load MC ucode into the hw
1472 *
1473 * @rdev: radeon_device pointer
1474 *
1475 * Load the GDDR MC ucode into the hw (CIK).
1476 * Returns 0 on success, error on failure.
1477 */
1478static int ci_mc_load_microcode(struct radeon_device *rdev)
1479{
1480 const __be32 *fw_data;
1481 u32 running, blackout = 0;
1482 u32 *io_mc_regs;
1483 int i, ucode_size, regs_size;
1484
1485 if (!rdev->mc_fw)
1486 return -EINVAL;
1487
1488 switch (rdev->family) {
1489 case CHIP_BONAIRE:
1490 default:
1491 io_mc_regs = (u32 *)&bonaire_io_mc_regs;
1492 ucode_size = CIK_MC_UCODE_SIZE;
1493 regs_size = BONAIRE_IO_MC_REGS_SIZE;
1494 break;
1495 }
1496
1497 running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
1498
1499 if (running == 0) {
1500 if (running) {
1501 blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
1502 WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
1503 }
1504
1505 /* reset the engine and set to writable */
1506 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
1507 WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
1508
1509 /* load mc io regs */
1510 for (i = 0; i < regs_size; i++) {
1511 WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
1512 WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
1513 }
1514 /* load the MC ucode */
1515 fw_data = (const __be32 *)rdev->mc_fw->data;
1516 for (i = 0; i < ucode_size; i++)
1517 WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
1518
1519 /* put the engine back into the active state */
1520 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
1521 WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
1522 WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
1523
1524 /* wait for training to complete */
1525 for (i = 0; i < rdev->usec_timeout; i++) {
1526 if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D0)
1527 break;
1528 udelay(1);
1529 }
1530 for (i = 0; i < rdev->usec_timeout; i++) {
1531 if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D1)
1532 break;
1533 udelay(1);
1534 }
1535
1536 if (running)
1537 WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
1538 }
1539
1540 return 0;
1541}
1542
Alex Deucher02c81322012-12-18 21:43:07 -05001543/**
1544 * cik_init_microcode - load ucode images from disk
1545 *
1546 * @rdev: radeon_device pointer
1547 *
1548 * Use the firmware interface to load the ucode images into
1549 * the driver (not loaded into hw).
1550 * Returns 0 on success, error on failure.
1551 */
1552static int cik_init_microcode(struct radeon_device *rdev)
1553{
Alex Deucher02c81322012-12-18 21:43:07 -05001554 const char *chip_name;
1555 size_t pfp_req_size, me_req_size, ce_req_size,
Alex Deucher21a93e12013-04-09 12:47:11 -04001556 mec_req_size, rlc_req_size, mc_req_size,
Alex Deuchercc8dbbb2013-08-14 01:03:41 -04001557 sdma_req_size, smc_req_size;
Alex Deucher02c81322012-12-18 21:43:07 -05001558 char fw_name[30];
1559 int err;
1560
1561 DRM_DEBUG("\n");
1562
Alex Deucher02c81322012-12-18 21:43:07 -05001563 switch (rdev->family) {
1564 case CHIP_BONAIRE:
1565 chip_name = "BONAIRE";
1566 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
1567 me_req_size = CIK_ME_UCODE_SIZE * 4;
1568 ce_req_size = CIK_CE_UCODE_SIZE * 4;
1569 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
1570 rlc_req_size = BONAIRE_RLC_UCODE_SIZE * 4;
1571 mc_req_size = CIK_MC_UCODE_SIZE * 4;
Alex Deucher21a93e12013-04-09 12:47:11 -04001572 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
Alex Deuchercc8dbbb2013-08-14 01:03:41 -04001573 smc_req_size = ALIGN(BONAIRE_SMC_UCODE_SIZE, 4);
Alex Deucher02c81322012-12-18 21:43:07 -05001574 break;
1575 case CHIP_KAVERI:
1576 chip_name = "KAVERI";
1577 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
1578 me_req_size = CIK_ME_UCODE_SIZE * 4;
1579 ce_req_size = CIK_CE_UCODE_SIZE * 4;
1580 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
1581 rlc_req_size = KV_RLC_UCODE_SIZE * 4;
Alex Deucher21a93e12013-04-09 12:47:11 -04001582 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
Alex Deucher02c81322012-12-18 21:43:07 -05001583 break;
1584 case CHIP_KABINI:
1585 chip_name = "KABINI";
1586 pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
1587 me_req_size = CIK_ME_UCODE_SIZE * 4;
1588 ce_req_size = CIK_CE_UCODE_SIZE * 4;
1589 mec_req_size = CIK_MEC_UCODE_SIZE * 4;
1590 rlc_req_size = KB_RLC_UCODE_SIZE * 4;
Alex Deucher21a93e12013-04-09 12:47:11 -04001591 sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
Alex Deucher02c81322012-12-18 21:43:07 -05001592 break;
1593 default: BUG();
1594 }
1595
1596 DRM_INFO("Loading %s Microcode\n", chip_name);
1597
1598 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001599 err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
Alex Deucher02c81322012-12-18 21:43:07 -05001600 if (err)
1601 goto out;
1602 if (rdev->pfp_fw->size != pfp_req_size) {
1603 printk(KERN_ERR
1604 "cik_cp: Bogus length %zu in firmware \"%s\"\n",
1605 rdev->pfp_fw->size, fw_name);
1606 err = -EINVAL;
1607 goto out;
1608 }
1609
1610 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001611 err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
Alex Deucher02c81322012-12-18 21:43:07 -05001612 if (err)
1613 goto out;
1614 if (rdev->me_fw->size != me_req_size) {
1615 printk(KERN_ERR
1616 "cik_cp: Bogus length %zu in firmware \"%s\"\n",
1617 rdev->me_fw->size, fw_name);
1618 err = -EINVAL;
1619 }
1620
1621 snprintf(fw_name, sizeof(fw_name), "radeon/%s_ce.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001622 err = request_firmware(&rdev->ce_fw, fw_name, rdev->dev);
Alex Deucher02c81322012-12-18 21:43:07 -05001623 if (err)
1624 goto out;
1625 if (rdev->ce_fw->size != ce_req_size) {
1626 printk(KERN_ERR
1627 "cik_cp: Bogus length %zu in firmware \"%s\"\n",
1628 rdev->ce_fw->size, fw_name);
1629 err = -EINVAL;
1630 }
1631
1632 snprintf(fw_name, sizeof(fw_name), "radeon/%s_mec.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001633 err = request_firmware(&rdev->mec_fw, fw_name, rdev->dev);
Alex Deucher02c81322012-12-18 21:43:07 -05001634 if (err)
1635 goto out;
1636 if (rdev->mec_fw->size != mec_req_size) {
1637 printk(KERN_ERR
1638 "cik_cp: Bogus length %zu in firmware \"%s\"\n",
1639 rdev->mec_fw->size, fw_name);
1640 err = -EINVAL;
1641 }
1642
1643 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001644 err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
Alex Deucher02c81322012-12-18 21:43:07 -05001645 if (err)
1646 goto out;
1647 if (rdev->rlc_fw->size != rlc_req_size) {
1648 printk(KERN_ERR
1649 "cik_rlc: Bogus length %zu in firmware \"%s\"\n",
1650 rdev->rlc_fw->size, fw_name);
1651 err = -EINVAL;
1652 }
1653
Alex Deucher21a93e12013-04-09 12:47:11 -04001654 snprintf(fw_name, sizeof(fw_name), "radeon/%s_sdma.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001655 err = request_firmware(&rdev->sdma_fw, fw_name, rdev->dev);
Alex Deucher21a93e12013-04-09 12:47:11 -04001656 if (err)
1657 goto out;
1658 if (rdev->sdma_fw->size != sdma_req_size) {
1659 printk(KERN_ERR
1660 "cik_sdma: Bogus length %zu in firmware \"%s\"\n",
1661 rdev->sdma_fw->size, fw_name);
1662 err = -EINVAL;
1663 }
1664
Alex Deuchercc8dbbb2013-08-14 01:03:41 -04001665 /* No SMC, MC ucode on APUs */
Alex Deucher02c81322012-12-18 21:43:07 -05001666 if (!(rdev->flags & RADEON_IS_IGP)) {
1667 snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001668 err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
Alex Deucher02c81322012-12-18 21:43:07 -05001669 if (err)
1670 goto out;
1671 if (rdev->mc_fw->size != mc_req_size) {
1672 printk(KERN_ERR
1673 "cik_mc: Bogus length %zu in firmware \"%s\"\n",
1674 rdev->mc_fw->size, fw_name);
1675 err = -EINVAL;
1676 }
Alex Deuchercc8dbbb2013-08-14 01:03:41 -04001677
1678 snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", chip_name);
1679 err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
1680 if (err) {
1681 printk(KERN_ERR
1682 "smc: error loading firmware \"%s\"\n",
1683 fw_name);
1684 release_firmware(rdev->smc_fw);
1685 rdev->smc_fw = NULL;
1686 } else if (rdev->smc_fw->size != smc_req_size) {
1687 printk(KERN_ERR
1688 "cik_smc: Bogus length %zu in firmware \"%s\"\n",
1689 rdev->smc_fw->size, fw_name);
1690 err = -EINVAL;
1691 }
Alex Deucher02c81322012-12-18 21:43:07 -05001692 }
1693
1694out:
Alex Deucher02c81322012-12-18 21:43:07 -05001695 if (err) {
1696 if (err != -EINVAL)
1697 printk(KERN_ERR
1698 "cik_cp: Failed to load firmware \"%s\"\n",
1699 fw_name);
1700 release_firmware(rdev->pfp_fw);
1701 rdev->pfp_fw = NULL;
1702 release_firmware(rdev->me_fw);
1703 rdev->me_fw = NULL;
1704 release_firmware(rdev->ce_fw);
1705 rdev->ce_fw = NULL;
1706 release_firmware(rdev->rlc_fw);
1707 rdev->rlc_fw = NULL;
1708 release_firmware(rdev->mc_fw);
1709 rdev->mc_fw = NULL;
Alex Deuchercc8dbbb2013-08-14 01:03:41 -04001710 release_firmware(rdev->smc_fw);
1711 rdev->smc_fw = NULL;
Alex Deucher02c81322012-12-18 21:43:07 -05001712 }
1713 return err;
1714}
1715
Alex Deucher8cc1a532013-04-09 12:41:24 -04001716/*
1717 * Core functions
1718 */
1719/**
1720 * cik_tiling_mode_table_init - init the hw tiling table
1721 *
1722 * @rdev: radeon_device pointer
1723 *
1724 * Starting with SI, the tiling setup is done globally in a
1725 * set of 32 tiling modes. Rather than selecting each set of
1726 * parameters per surface as on older asics, we just select
1727 * which index in the tiling table we want to use, and the
1728 * surface uses those parameters (CIK).
1729 */
1730static void cik_tiling_mode_table_init(struct radeon_device *rdev)
1731{
1732 const u32 num_tile_mode_states = 32;
1733 const u32 num_secondary_tile_mode_states = 16;
1734 u32 reg_offset, gb_tile_moden, split_equal_to_row_size;
1735 u32 num_pipe_configs;
1736 u32 num_rbs = rdev->config.cik.max_backends_per_se *
1737 rdev->config.cik.max_shader_engines;
1738
1739 switch (rdev->config.cik.mem_row_size_in_kb) {
1740 case 1:
1741 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_1KB;
1742 break;
1743 case 2:
1744 default:
1745 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_2KB;
1746 break;
1747 case 4:
1748 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_4KB;
1749 break;
1750 }
1751
1752 num_pipe_configs = rdev->config.cik.max_tile_pipes;
1753 if (num_pipe_configs > 8)
1754 num_pipe_configs = 8; /* ??? */
1755
1756 if (num_pipe_configs == 8) {
1757 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
1758 switch (reg_offset) {
1759 case 0:
1760 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
1761 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
1762 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
1763 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
1764 break;
1765 case 1:
1766 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
1767 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
1768 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
1769 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
1770 break;
1771 case 2:
1772 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
1773 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
1774 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
1775 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
1776 break;
1777 case 3:
1778 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
1779 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
1780 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
1781 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
1782 break;
1783 case 4:
1784 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
1785 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
1786 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
1787 TILE_SPLIT(split_equal_to_row_size));
1788 break;
1789 case 5:
1790 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
1791 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
1792 break;
1793 case 6:
1794 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
1795 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
1796 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
1797 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
1798 break;
1799 case 7:
1800 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
1801 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
1802 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
1803 TILE_SPLIT(split_equal_to_row_size));
1804 break;
1805 case 8:
1806 gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
1807 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16));
1808 break;
1809 case 9:
1810 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
1811 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
1812 break;
1813 case 10:
1814 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
1815 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
1816 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
1817 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
1818 break;
1819 case 11:
1820 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
1821 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
1822 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
1823 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
1824 break;
1825 case 12:
1826 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
1827 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
1828 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
1829 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
1830 break;
1831 case 13:
1832 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
1833 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
1834 break;
1835 case 14:
1836 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
1837 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
1838 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
1839 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
1840 break;
1841 case 16:
1842 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
1843 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
1844 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
1845 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
1846 break;
1847 case 17:
1848 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
1849 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
1850 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
1851 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
1852 break;
1853 case 27:
1854 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
1855 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
1856 break;
1857 case 28:
1858 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
1859 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
1860 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
1861 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
1862 break;
1863 case 29:
1864 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
1865 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
1866 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
1867 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
1868 break;
1869 case 30:
1870 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
1871 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
1872 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
1873 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
1874 break;
1875 default:
1876 gb_tile_moden = 0;
1877 break;
1878 }
Alex Deucher39aee492013-04-10 13:41:25 -04001879 rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
Alex Deucher8cc1a532013-04-09 12:41:24 -04001880 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
1881 }
1882 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
1883 switch (reg_offset) {
1884 case 0:
1885 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
1886 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
1887 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
1888 NUM_BANKS(ADDR_SURF_16_BANK));
1889 break;
1890 case 1:
1891 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
1892 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
1893 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
1894 NUM_BANKS(ADDR_SURF_16_BANK));
1895 break;
1896 case 2:
1897 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
1898 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
1899 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
1900 NUM_BANKS(ADDR_SURF_16_BANK));
1901 break;
1902 case 3:
1903 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
1904 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
1905 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
1906 NUM_BANKS(ADDR_SURF_16_BANK));
1907 break;
1908 case 4:
1909 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
1910 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
1911 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
1912 NUM_BANKS(ADDR_SURF_8_BANK));
1913 break;
1914 case 5:
1915 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
1916 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
1917 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
1918 NUM_BANKS(ADDR_SURF_4_BANK));
1919 break;
1920 case 6:
1921 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
1922 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
1923 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
1924 NUM_BANKS(ADDR_SURF_2_BANK));
1925 break;
1926 case 8:
1927 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
1928 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
1929 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
1930 NUM_BANKS(ADDR_SURF_16_BANK));
1931 break;
1932 case 9:
1933 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
1934 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
1935 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
1936 NUM_BANKS(ADDR_SURF_16_BANK));
1937 break;
1938 case 10:
1939 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
1940 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
1941 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
1942 NUM_BANKS(ADDR_SURF_16_BANK));
1943 break;
1944 case 11:
1945 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
1946 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
1947 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
1948 NUM_BANKS(ADDR_SURF_16_BANK));
1949 break;
1950 case 12:
1951 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
1952 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
1953 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
1954 NUM_BANKS(ADDR_SURF_8_BANK));
1955 break;
1956 case 13:
1957 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
1958 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
1959 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
1960 NUM_BANKS(ADDR_SURF_4_BANK));
1961 break;
1962 case 14:
1963 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
1964 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
1965 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
1966 NUM_BANKS(ADDR_SURF_2_BANK));
1967 break;
1968 default:
1969 gb_tile_moden = 0;
1970 break;
1971 }
1972 WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
1973 }
1974 } else if (num_pipe_configs == 4) {
1975 if (num_rbs == 4) {
1976 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
1977 switch (reg_offset) {
1978 case 0:
1979 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
1980 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
1981 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
1982 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
1983 break;
1984 case 1:
1985 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
1986 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
1987 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
1988 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
1989 break;
1990 case 2:
1991 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
1992 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
1993 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
1994 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
1995 break;
1996 case 3:
1997 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
1998 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
1999 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2000 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
2001 break;
2002 case 4:
2003 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2004 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2005 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2006 TILE_SPLIT(split_equal_to_row_size));
2007 break;
2008 case 5:
2009 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2010 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2011 break;
2012 case 6:
2013 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2014 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2015 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2016 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2017 break;
2018 case 7:
2019 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2020 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2021 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2022 TILE_SPLIT(split_equal_to_row_size));
2023 break;
2024 case 8:
2025 gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2026 PIPE_CONFIG(ADDR_SURF_P4_16x16));
2027 break;
2028 case 9:
2029 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2030 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
2031 break;
2032 case 10:
2033 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2034 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2035 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2036 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2037 break;
2038 case 11:
2039 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2040 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2041 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2042 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2043 break;
2044 case 12:
2045 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2046 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2047 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2048 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2049 break;
2050 case 13:
2051 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2052 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
2053 break;
2054 case 14:
2055 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2056 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2057 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2058 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2059 break;
2060 case 16:
2061 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2062 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2063 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2064 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2065 break;
2066 case 17:
2067 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2068 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2069 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2070 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2071 break;
2072 case 27:
2073 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2074 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
2075 break;
2076 case 28:
2077 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2078 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2079 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2080 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2081 break;
2082 case 29:
2083 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2084 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2085 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2086 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2087 break;
2088 case 30:
2089 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2090 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2091 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2092 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2093 break;
2094 default:
2095 gb_tile_moden = 0;
2096 break;
2097 }
Alex Deucher39aee492013-04-10 13:41:25 -04002098 rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
Alex Deucher8cc1a532013-04-09 12:41:24 -04002099 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2100 }
2101 } else if (num_rbs < 4) {
2102 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
2103 switch (reg_offset) {
2104 case 0:
2105 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2106 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2107 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2108 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
2109 break;
2110 case 1:
2111 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2112 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2113 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2114 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
2115 break;
2116 case 2:
2117 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2118 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2119 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2120 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2121 break;
2122 case 3:
2123 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2124 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2125 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2126 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
2127 break;
2128 case 4:
2129 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2130 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2131 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2132 TILE_SPLIT(split_equal_to_row_size));
2133 break;
2134 case 5:
2135 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2136 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2137 break;
2138 case 6:
2139 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2140 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2141 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2142 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2143 break;
2144 case 7:
2145 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2146 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2147 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2148 TILE_SPLIT(split_equal_to_row_size));
2149 break;
2150 case 8:
2151 gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2152 PIPE_CONFIG(ADDR_SURF_P4_8x16));
2153 break;
2154 case 9:
2155 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2156 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
2157 break;
2158 case 10:
2159 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2160 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2161 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2162 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2163 break;
2164 case 11:
2165 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2166 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2167 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2168 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2169 break;
2170 case 12:
2171 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2172 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2173 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2174 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2175 break;
2176 case 13:
2177 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2178 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
2179 break;
2180 case 14:
2181 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2182 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2183 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2184 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2185 break;
2186 case 16:
2187 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2188 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2189 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2190 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2191 break;
2192 case 17:
2193 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2194 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2195 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2196 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2197 break;
2198 case 27:
2199 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2200 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
2201 break;
2202 case 28:
2203 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2204 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2205 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2206 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2207 break;
2208 case 29:
2209 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2210 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2211 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2212 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2213 break;
2214 case 30:
2215 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2216 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2217 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2218 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2219 break;
2220 default:
2221 gb_tile_moden = 0;
2222 break;
2223 }
Alex Deucher39aee492013-04-10 13:41:25 -04002224 rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
Alex Deucher8cc1a532013-04-09 12:41:24 -04002225 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2226 }
2227 }
2228 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
2229 switch (reg_offset) {
2230 case 0:
2231 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2232 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2233 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2234 NUM_BANKS(ADDR_SURF_16_BANK));
2235 break;
2236 case 1:
2237 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2238 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2239 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2240 NUM_BANKS(ADDR_SURF_16_BANK));
2241 break;
2242 case 2:
2243 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2244 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2245 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2246 NUM_BANKS(ADDR_SURF_16_BANK));
2247 break;
2248 case 3:
2249 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2250 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2251 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2252 NUM_BANKS(ADDR_SURF_16_BANK));
2253 break;
2254 case 4:
2255 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2256 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2257 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2258 NUM_BANKS(ADDR_SURF_16_BANK));
2259 break;
2260 case 5:
2261 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2262 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2263 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2264 NUM_BANKS(ADDR_SURF_8_BANK));
2265 break;
2266 case 6:
2267 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2268 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2269 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2270 NUM_BANKS(ADDR_SURF_4_BANK));
2271 break;
2272 case 8:
2273 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2274 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2275 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2276 NUM_BANKS(ADDR_SURF_16_BANK));
2277 break;
2278 case 9:
2279 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2280 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2281 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2282 NUM_BANKS(ADDR_SURF_16_BANK));
2283 break;
2284 case 10:
2285 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2286 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2287 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2288 NUM_BANKS(ADDR_SURF_16_BANK));
2289 break;
2290 case 11:
2291 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2292 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2293 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2294 NUM_BANKS(ADDR_SURF_16_BANK));
2295 break;
2296 case 12:
2297 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2298 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2299 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2300 NUM_BANKS(ADDR_SURF_16_BANK));
2301 break;
2302 case 13:
2303 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2304 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2305 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2306 NUM_BANKS(ADDR_SURF_8_BANK));
2307 break;
2308 case 14:
2309 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2310 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2311 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2312 NUM_BANKS(ADDR_SURF_4_BANK));
2313 break;
2314 default:
2315 gb_tile_moden = 0;
2316 break;
2317 }
2318 WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2319 }
2320 } else if (num_pipe_configs == 2) {
2321 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
2322 switch (reg_offset) {
2323 case 0:
2324 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2325 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2326 PIPE_CONFIG(ADDR_SURF_P2) |
2327 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
2328 break;
2329 case 1:
2330 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2331 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2332 PIPE_CONFIG(ADDR_SURF_P2) |
2333 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
2334 break;
2335 case 2:
2336 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2337 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2338 PIPE_CONFIG(ADDR_SURF_P2) |
2339 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2340 break;
2341 case 3:
2342 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2343 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2344 PIPE_CONFIG(ADDR_SURF_P2) |
2345 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
2346 break;
2347 case 4:
2348 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2349 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2350 PIPE_CONFIG(ADDR_SURF_P2) |
2351 TILE_SPLIT(split_equal_to_row_size));
2352 break;
2353 case 5:
2354 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2355 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2356 break;
2357 case 6:
2358 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2359 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2360 PIPE_CONFIG(ADDR_SURF_P2) |
2361 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
2362 break;
2363 case 7:
2364 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2365 MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
2366 PIPE_CONFIG(ADDR_SURF_P2) |
2367 TILE_SPLIT(split_equal_to_row_size));
2368 break;
2369 case 8:
2370 gb_tile_moden = ARRAY_MODE(ARRAY_LINEAR_ALIGNED);
2371 break;
2372 case 9:
2373 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2374 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
2375 break;
2376 case 10:
2377 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2378 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2379 PIPE_CONFIG(ADDR_SURF_P2) |
2380 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2381 break;
2382 case 11:
2383 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2384 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2385 PIPE_CONFIG(ADDR_SURF_P2) |
2386 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2387 break;
2388 case 12:
2389 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2390 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2391 PIPE_CONFIG(ADDR_SURF_P2) |
2392 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2393 break;
2394 case 13:
2395 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2396 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
2397 break;
2398 case 14:
2399 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2400 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2401 PIPE_CONFIG(ADDR_SURF_P2) |
2402 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2403 break;
2404 case 16:
2405 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2406 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2407 PIPE_CONFIG(ADDR_SURF_P2) |
2408 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2409 break;
2410 case 17:
2411 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2412 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2413 PIPE_CONFIG(ADDR_SURF_P2) |
2414 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2415 break;
2416 case 27:
2417 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2418 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
2419 break;
2420 case 28:
2421 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2422 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2423 PIPE_CONFIG(ADDR_SURF_P2) |
2424 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2425 break;
2426 case 29:
2427 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2428 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2429 PIPE_CONFIG(ADDR_SURF_P2) |
2430 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2431 break;
2432 case 30:
2433 gb_tile_moden = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
2434 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2435 PIPE_CONFIG(ADDR_SURF_P2) |
2436 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2437 break;
2438 default:
2439 gb_tile_moden = 0;
2440 break;
2441 }
Alex Deucher39aee492013-04-10 13:41:25 -04002442 rdev->config.cik.tile_mode_array[reg_offset] = gb_tile_moden;
Alex Deucher8cc1a532013-04-09 12:41:24 -04002443 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2444 }
2445 for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++) {
2446 switch (reg_offset) {
2447 case 0:
2448 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2449 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2450 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2451 NUM_BANKS(ADDR_SURF_16_BANK));
2452 break;
2453 case 1:
2454 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2455 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2456 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2457 NUM_BANKS(ADDR_SURF_16_BANK));
2458 break;
2459 case 2:
2460 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2461 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2462 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2463 NUM_BANKS(ADDR_SURF_16_BANK));
2464 break;
2465 case 3:
2466 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2467 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2468 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2469 NUM_BANKS(ADDR_SURF_16_BANK));
2470 break;
2471 case 4:
2472 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2473 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2474 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2475 NUM_BANKS(ADDR_SURF_16_BANK));
2476 break;
2477 case 5:
2478 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2479 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2480 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2481 NUM_BANKS(ADDR_SURF_16_BANK));
2482 break;
2483 case 6:
2484 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2485 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2486 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2487 NUM_BANKS(ADDR_SURF_8_BANK));
2488 break;
2489 case 8:
2490 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
2491 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2492 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2493 NUM_BANKS(ADDR_SURF_16_BANK));
2494 break;
2495 case 9:
2496 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
2497 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2498 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2499 NUM_BANKS(ADDR_SURF_16_BANK));
2500 break;
2501 case 10:
2502 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2503 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2504 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2505 NUM_BANKS(ADDR_SURF_16_BANK));
2506 break;
2507 case 11:
2508 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2509 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2510 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2511 NUM_BANKS(ADDR_SURF_16_BANK));
2512 break;
2513 case 12:
2514 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2515 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2516 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2517 NUM_BANKS(ADDR_SURF_16_BANK));
2518 break;
2519 case 13:
2520 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2521 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2522 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2523 NUM_BANKS(ADDR_SURF_16_BANK));
2524 break;
2525 case 14:
2526 gb_tile_moden = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2527 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2528 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2529 NUM_BANKS(ADDR_SURF_8_BANK));
2530 break;
2531 default:
2532 gb_tile_moden = 0;
2533 break;
2534 }
2535 WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2536 }
2537 } else
2538 DRM_ERROR("unknown num pipe config: 0x%x\n", num_pipe_configs);
2539}
2540
2541/**
2542 * cik_select_se_sh - select which SE, SH to address
2543 *
2544 * @rdev: radeon_device pointer
2545 * @se_num: shader engine to address
2546 * @sh_num: sh block to address
2547 *
2548 * Select which SE, SH combinations to address. Certain
2549 * registers are instanced per SE or SH. 0xffffffff means
2550 * broadcast to all SEs or SHs (CIK).
2551 */
2552static void cik_select_se_sh(struct radeon_device *rdev,
2553 u32 se_num, u32 sh_num)
2554{
2555 u32 data = INSTANCE_BROADCAST_WRITES;
2556
2557 if ((se_num == 0xffffffff) && (sh_num == 0xffffffff))
Alex Deucherb0fe3d32013-04-18 16:25:47 -04002558 data |= SH_BROADCAST_WRITES | SE_BROADCAST_WRITES;
Alex Deucher8cc1a532013-04-09 12:41:24 -04002559 else if (se_num == 0xffffffff)
2560 data |= SE_BROADCAST_WRITES | SH_INDEX(sh_num);
2561 else if (sh_num == 0xffffffff)
2562 data |= SH_BROADCAST_WRITES | SE_INDEX(se_num);
2563 else
2564 data |= SH_INDEX(sh_num) | SE_INDEX(se_num);
2565 WREG32(GRBM_GFX_INDEX, data);
2566}
2567
2568/**
2569 * cik_create_bitmask - create a bitmask
2570 *
2571 * @bit_width: length of the mask
2572 *
2573 * create a variable length bit mask (CIK).
2574 * Returns the bitmask.
2575 */
2576static u32 cik_create_bitmask(u32 bit_width)
2577{
2578 u32 i, mask = 0;
2579
2580 for (i = 0; i < bit_width; i++) {
2581 mask <<= 1;
2582 mask |= 1;
2583 }
2584 return mask;
2585}
2586
2587/**
2588 * cik_select_se_sh - select which SE, SH to address
2589 *
2590 * @rdev: radeon_device pointer
2591 * @max_rb_num: max RBs (render backends) for the asic
2592 * @se_num: number of SEs (shader engines) for the asic
2593 * @sh_per_se: number of SH blocks per SE for the asic
2594 *
2595 * Calculates the bitmask of disabled RBs (CIK).
2596 * Returns the disabled RB bitmask.
2597 */
2598static u32 cik_get_rb_disabled(struct radeon_device *rdev,
2599 u32 max_rb_num, u32 se_num,
2600 u32 sh_per_se)
2601{
2602 u32 data, mask;
2603
2604 data = RREG32(CC_RB_BACKEND_DISABLE);
2605 if (data & 1)
2606 data &= BACKEND_DISABLE_MASK;
2607 else
2608 data = 0;
2609 data |= RREG32(GC_USER_RB_BACKEND_DISABLE);
2610
2611 data >>= BACKEND_DISABLE_SHIFT;
2612
2613 mask = cik_create_bitmask(max_rb_num / se_num / sh_per_se);
2614
2615 return data & mask;
2616}
2617
2618/**
2619 * cik_setup_rb - setup the RBs on the asic
2620 *
2621 * @rdev: radeon_device pointer
2622 * @se_num: number of SEs (shader engines) for the asic
2623 * @sh_per_se: number of SH blocks per SE for the asic
2624 * @max_rb_num: max RBs (render backends) for the asic
2625 *
2626 * Configures per-SE/SH RB registers (CIK).
2627 */
2628static void cik_setup_rb(struct radeon_device *rdev,
2629 u32 se_num, u32 sh_per_se,
2630 u32 max_rb_num)
2631{
2632 int i, j;
2633 u32 data, mask;
2634 u32 disabled_rbs = 0;
2635 u32 enabled_rbs = 0;
2636
2637 for (i = 0; i < se_num; i++) {
2638 for (j = 0; j < sh_per_se; j++) {
2639 cik_select_se_sh(rdev, i, j);
2640 data = cik_get_rb_disabled(rdev, max_rb_num, se_num, sh_per_se);
2641 disabled_rbs |= data << ((i * sh_per_se + j) * CIK_RB_BITMAP_WIDTH_PER_SH);
2642 }
2643 }
2644 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
2645
2646 mask = 1;
2647 for (i = 0; i < max_rb_num; i++) {
2648 if (!(disabled_rbs & mask))
2649 enabled_rbs |= mask;
2650 mask <<= 1;
2651 }
2652
2653 for (i = 0; i < se_num; i++) {
2654 cik_select_se_sh(rdev, i, 0xffffffff);
2655 data = 0;
2656 for (j = 0; j < sh_per_se; j++) {
2657 switch (enabled_rbs & 3) {
2658 case 1:
2659 data |= (RASTER_CONFIG_RB_MAP_0 << (i * sh_per_se + j) * 2);
2660 break;
2661 case 2:
2662 data |= (RASTER_CONFIG_RB_MAP_3 << (i * sh_per_se + j) * 2);
2663 break;
2664 case 3:
2665 default:
2666 data |= (RASTER_CONFIG_RB_MAP_2 << (i * sh_per_se + j) * 2);
2667 break;
2668 }
2669 enabled_rbs >>= 2;
2670 }
2671 WREG32(PA_SC_RASTER_CONFIG, data);
2672 }
2673 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
2674}
2675
2676/**
2677 * cik_gpu_init - setup the 3D engine
2678 *
2679 * @rdev: radeon_device pointer
2680 *
2681 * Configures the 3D engine and tiling configuration
2682 * registers so that the 3D engine is usable.
2683 */
2684static void cik_gpu_init(struct radeon_device *rdev)
2685{
2686 u32 gb_addr_config = RREG32(GB_ADDR_CONFIG);
2687 u32 mc_shared_chmap, mc_arb_ramcfg;
2688 u32 hdp_host_path_cntl;
2689 u32 tmp;
2690 int i, j;
2691
2692 switch (rdev->family) {
2693 case CHIP_BONAIRE:
2694 rdev->config.cik.max_shader_engines = 2;
2695 rdev->config.cik.max_tile_pipes = 4;
2696 rdev->config.cik.max_cu_per_sh = 7;
2697 rdev->config.cik.max_sh_per_se = 1;
2698 rdev->config.cik.max_backends_per_se = 2;
2699 rdev->config.cik.max_texture_channel_caches = 4;
2700 rdev->config.cik.max_gprs = 256;
2701 rdev->config.cik.max_gs_threads = 32;
2702 rdev->config.cik.max_hw_contexts = 8;
2703
2704 rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
2705 rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
2706 rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
2707 rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
2708 gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
2709 break;
2710 case CHIP_KAVERI:
2711 /* TODO */
2712 break;
2713 case CHIP_KABINI:
2714 default:
2715 rdev->config.cik.max_shader_engines = 1;
2716 rdev->config.cik.max_tile_pipes = 2;
2717 rdev->config.cik.max_cu_per_sh = 2;
2718 rdev->config.cik.max_sh_per_se = 1;
2719 rdev->config.cik.max_backends_per_se = 1;
2720 rdev->config.cik.max_texture_channel_caches = 2;
2721 rdev->config.cik.max_gprs = 256;
2722 rdev->config.cik.max_gs_threads = 16;
2723 rdev->config.cik.max_hw_contexts = 8;
2724
2725 rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
2726 rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
2727 rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
2728 rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
2729 gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
2730 break;
2731 }
2732
2733 /* Initialize HDP */
2734 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
2735 WREG32((0x2c14 + j), 0x00000000);
2736 WREG32((0x2c18 + j), 0x00000000);
2737 WREG32((0x2c1c + j), 0x00000000);
2738 WREG32((0x2c20 + j), 0x00000000);
2739 WREG32((0x2c24 + j), 0x00000000);
2740 }
2741
2742 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
2743
2744 WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
2745
2746 mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
2747 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
2748
2749 rdev->config.cik.num_tile_pipes = rdev->config.cik.max_tile_pipes;
2750 rdev->config.cik.mem_max_burst_length_bytes = 256;
2751 tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
2752 rdev->config.cik.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
2753 if (rdev->config.cik.mem_row_size_in_kb > 4)
2754 rdev->config.cik.mem_row_size_in_kb = 4;
2755 /* XXX use MC settings? */
2756 rdev->config.cik.shader_engine_tile_size = 32;
2757 rdev->config.cik.num_gpus = 1;
2758 rdev->config.cik.multi_gpu_tile_size = 64;
2759
2760 /* fix up row size */
2761 gb_addr_config &= ~ROW_SIZE_MASK;
2762 switch (rdev->config.cik.mem_row_size_in_kb) {
2763 case 1:
2764 default:
2765 gb_addr_config |= ROW_SIZE(0);
2766 break;
2767 case 2:
2768 gb_addr_config |= ROW_SIZE(1);
2769 break;
2770 case 4:
2771 gb_addr_config |= ROW_SIZE(2);
2772 break;
2773 }
2774
2775 /* setup tiling info dword. gb_addr_config is not adequate since it does
2776 * not have bank info, so create a custom tiling dword.
2777 * bits 3:0 num_pipes
2778 * bits 7:4 num_banks
2779 * bits 11:8 group_size
2780 * bits 15:12 row_size
2781 */
2782 rdev->config.cik.tile_config = 0;
2783 switch (rdev->config.cik.num_tile_pipes) {
2784 case 1:
2785 rdev->config.cik.tile_config |= (0 << 0);
2786 break;
2787 case 2:
2788 rdev->config.cik.tile_config |= (1 << 0);
2789 break;
2790 case 4:
2791 rdev->config.cik.tile_config |= (2 << 0);
2792 break;
2793 case 8:
2794 default:
2795 /* XXX what about 12? */
2796 rdev->config.cik.tile_config |= (3 << 0);
2797 break;
2798 }
2799 if ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT)
2800 rdev->config.cik.tile_config |= 1 << 4;
2801 else
2802 rdev->config.cik.tile_config |= 0 << 4;
2803 rdev->config.cik.tile_config |=
2804 ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
2805 rdev->config.cik.tile_config |=
2806 ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
2807
2808 WREG32(GB_ADDR_CONFIG, gb_addr_config);
2809 WREG32(HDP_ADDR_CONFIG, gb_addr_config);
2810 WREG32(DMIF_ADDR_CALC, gb_addr_config);
Alex Deucher21a93e12013-04-09 12:47:11 -04002811 WREG32(SDMA0_TILING_CONFIG + SDMA0_REGISTER_OFFSET, gb_addr_config & 0x70);
2812 WREG32(SDMA0_TILING_CONFIG + SDMA1_REGISTER_OFFSET, gb_addr_config & 0x70);
Christian König87167bb2013-04-09 13:39:21 -04002813 WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
2814 WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
2815 WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
Alex Deucher8cc1a532013-04-09 12:41:24 -04002816
2817 cik_tiling_mode_table_init(rdev);
2818
2819 cik_setup_rb(rdev, rdev->config.cik.max_shader_engines,
2820 rdev->config.cik.max_sh_per_se,
2821 rdev->config.cik.max_backends_per_se);
2822
2823 /* set HW defaults for 3D engine */
2824 WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
2825
2826 WREG32(SX_DEBUG_1, 0x20);
2827
2828 WREG32(TA_CNTL_AUX, 0x00010000);
2829
2830 tmp = RREG32(SPI_CONFIG_CNTL);
2831 tmp |= 0x03000000;
2832 WREG32(SPI_CONFIG_CNTL, tmp);
2833
2834 WREG32(SQ_CONFIG, 1);
2835
2836 WREG32(DB_DEBUG, 0);
2837
2838 tmp = RREG32(DB_DEBUG2) & ~0xf00fffff;
2839 tmp |= 0x00000400;
2840 WREG32(DB_DEBUG2, tmp);
2841
2842 tmp = RREG32(DB_DEBUG3) & ~0x0002021c;
2843 tmp |= 0x00020200;
2844 WREG32(DB_DEBUG3, tmp);
2845
2846 tmp = RREG32(CB_HW_CONTROL) & ~0x00010000;
2847 tmp |= 0x00018208;
2848 WREG32(CB_HW_CONTROL, tmp);
2849
2850 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
2851
2852 WREG32(PA_SC_FIFO_SIZE, (SC_FRONTEND_PRIM_FIFO_SIZE(rdev->config.cik.sc_prim_fifo_size_frontend) |
2853 SC_BACKEND_PRIM_FIFO_SIZE(rdev->config.cik.sc_prim_fifo_size_backend) |
2854 SC_HIZ_TILE_FIFO_SIZE(rdev->config.cik.sc_hiz_tile_fifo_size) |
2855 SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.cik.sc_earlyz_tile_fifo_size)));
2856
2857 WREG32(VGT_NUM_INSTANCES, 1);
2858
2859 WREG32(CP_PERFMON_CNTL, 0);
2860
2861 WREG32(SQ_CONFIG, 0);
2862
2863 WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
2864 FORCE_EOV_MAX_REZ_CNT(255)));
2865
2866 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
2867 AUTO_INVLD_EN(ES_AND_GS_AUTO));
2868
2869 WREG32(VGT_GS_VERTEX_REUSE, 16);
2870 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
2871
2872 tmp = RREG32(HDP_MISC_CNTL);
2873 tmp |= HDP_FLUSH_INVALIDATE_CACHE;
2874 WREG32(HDP_MISC_CNTL, tmp);
2875
2876 hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
2877 WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
2878
2879 WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
2880 WREG32(PA_SC_ENHANCE, ENABLE_PA_SC_OUT_OF_ORDER);
2881
2882 udelay(50);
2883}
2884
Alex Deucher841cf442012-12-18 21:47:44 -05002885/*
Alex Deucher2cae3bc2012-07-05 11:45:40 -04002886 * GPU scratch registers helpers function.
2887 */
2888/**
2889 * cik_scratch_init - setup driver info for CP scratch regs
2890 *
2891 * @rdev: radeon_device pointer
2892 *
2893 * Set up the number and offset of the CP scratch registers.
2894 * NOTE: use of CP scratch registers is a legacy inferface and
2895 * is not used by default on newer asics (r6xx+). On newer asics,
2896 * memory buffers are used for fences rather than scratch regs.
2897 */
2898static void cik_scratch_init(struct radeon_device *rdev)
2899{
2900 int i;
2901
2902 rdev->scratch.num_reg = 7;
2903 rdev->scratch.reg_base = SCRATCH_REG0;
2904 for (i = 0; i < rdev->scratch.num_reg; i++) {
2905 rdev->scratch.free[i] = true;
2906 rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
2907 }
2908}
2909
2910/**
Alex Deucherfbc832c2012-07-20 14:41:35 -04002911 * cik_ring_test - basic gfx ring test
2912 *
2913 * @rdev: radeon_device pointer
2914 * @ring: radeon_ring structure holding ring information
2915 *
2916 * Allocate a scratch register and write to it using the gfx ring (CIK).
2917 * Provides a basic gfx ring test to verify that the ring is working.
2918 * Used by cik_cp_gfx_resume();
2919 * Returns 0 on success, error on failure.
2920 */
2921int cik_ring_test(struct radeon_device *rdev, struct radeon_ring *ring)
2922{
2923 uint32_t scratch;
2924 uint32_t tmp = 0;
2925 unsigned i;
2926 int r;
2927
2928 r = radeon_scratch_get(rdev, &scratch);
2929 if (r) {
2930 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
2931 return r;
2932 }
2933 WREG32(scratch, 0xCAFEDEAD);
2934 r = radeon_ring_lock(rdev, ring, 3);
2935 if (r) {
2936 DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ring->idx, r);
2937 radeon_scratch_free(rdev, scratch);
2938 return r;
2939 }
2940 radeon_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
2941 radeon_ring_write(ring, ((scratch - PACKET3_SET_UCONFIG_REG_START) >> 2));
2942 radeon_ring_write(ring, 0xDEADBEEF);
2943 radeon_ring_unlock_commit(rdev, ring);
Alex Deucher963e81f2013-06-26 17:37:11 -04002944
Alex Deucherfbc832c2012-07-20 14:41:35 -04002945 for (i = 0; i < rdev->usec_timeout; i++) {
2946 tmp = RREG32(scratch);
2947 if (tmp == 0xDEADBEEF)
2948 break;
2949 DRM_UDELAY(1);
2950 }
2951 if (i < rdev->usec_timeout) {
2952 DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
2953 } else {
2954 DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
2955 ring->idx, scratch, tmp);
2956 r = -EINVAL;
2957 }
2958 radeon_scratch_free(rdev, scratch);
2959 return r;
2960}
2961
2962/**
Alex Deucherb07fdd32013-04-11 09:36:17 -04002963 * cik_fence_gfx_ring_emit - emit a fence on the gfx ring
Alex Deucher2cae3bc2012-07-05 11:45:40 -04002964 *
2965 * @rdev: radeon_device pointer
2966 * @fence: radeon fence object
2967 *
2968 * Emits a fence sequnce number on the gfx ring and flushes
2969 * GPU caches.
2970 */
Alex Deucherb07fdd32013-04-11 09:36:17 -04002971void cik_fence_gfx_ring_emit(struct radeon_device *rdev,
2972 struct radeon_fence *fence)
Alex Deucher2cae3bc2012-07-05 11:45:40 -04002973{
2974 struct radeon_ring *ring = &rdev->ring[fence->ring];
2975 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
2976
2977 /* EVENT_WRITE_EOP - flush caches, send int */
2978 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
2979 radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
2980 EOP_TC_ACTION_EN |
2981 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
2982 EVENT_INDEX(5)));
2983 radeon_ring_write(ring, addr & 0xfffffffc);
2984 radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) | DATA_SEL(1) | INT_SEL(2));
2985 radeon_ring_write(ring, fence->seq);
2986 radeon_ring_write(ring, 0);
2987 /* HDP flush */
2988 /* We should be using the new WAIT_REG_MEM special op packet here
2989 * but it causes the CP to hang
2990 */
2991 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
2992 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
2993 WRITE_DATA_DST_SEL(0)));
2994 radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);
2995 radeon_ring_write(ring, 0);
2996 radeon_ring_write(ring, 0);
2997}
2998
Alex Deucherb07fdd32013-04-11 09:36:17 -04002999/**
3000 * cik_fence_compute_ring_emit - emit a fence on the compute ring
3001 *
3002 * @rdev: radeon_device pointer
3003 * @fence: radeon fence object
3004 *
3005 * Emits a fence sequnce number on the compute ring and flushes
3006 * GPU caches.
3007 */
3008void cik_fence_compute_ring_emit(struct radeon_device *rdev,
3009 struct radeon_fence *fence)
3010{
3011 struct radeon_ring *ring = &rdev->ring[fence->ring];
3012 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
3013
3014 /* RELEASE_MEM - flush caches, send int */
3015 radeon_ring_write(ring, PACKET3(PACKET3_RELEASE_MEM, 5));
3016 radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
3017 EOP_TC_ACTION_EN |
3018 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
3019 EVENT_INDEX(5)));
3020 radeon_ring_write(ring, DATA_SEL(1) | INT_SEL(2));
3021 radeon_ring_write(ring, addr & 0xfffffffc);
3022 radeon_ring_write(ring, upper_32_bits(addr));
3023 radeon_ring_write(ring, fence->seq);
3024 radeon_ring_write(ring, 0);
3025 /* HDP flush */
3026 /* We should be using the new WAIT_REG_MEM special op packet here
3027 * but it causes the CP to hang
3028 */
3029 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
3030 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
3031 WRITE_DATA_DST_SEL(0)));
3032 radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);
3033 radeon_ring_write(ring, 0);
3034 radeon_ring_write(ring, 0);
3035}
3036
Alex Deucher2cae3bc2012-07-05 11:45:40 -04003037void cik_semaphore_ring_emit(struct radeon_device *rdev,
3038 struct radeon_ring *ring,
3039 struct radeon_semaphore *semaphore,
3040 bool emit_wait)
3041{
3042 uint64_t addr = semaphore->gpu_addr;
3043 unsigned sel = emit_wait ? PACKET3_SEM_SEL_WAIT : PACKET3_SEM_SEL_SIGNAL;
3044
3045 radeon_ring_write(ring, PACKET3(PACKET3_MEM_SEMAPHORE, 1));
3046 radeon_ring_write(ring, addr & 0xffffffff);
3047 radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) | sel);
3048}
3049
3050/*
3051 * IB stuff
3052 */
3053/**
3054 * cik_ring_ib_execute - emit an IB (Indirect Buffer) on the gfx ring
3055 *
3056 * @rdev: radeon_device pointer
3057 * @ib: radeon indirect buffer object
3058 *
3059 * Emits an DE (drawing engine) or CE (constant engine) IB
3060 * on the gfx ring. IBs are usually generated by userspace
3061 * acceleration drivers and submitted to the kernel for
3062 * sheduling on the ring. This function schedules the IB
3063 * on the gfx ring for execution by the GPU.
3064 */
3065void cik_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
3066{
3067 struct radeon_ring *ring = &rdev->ring[ib->ring];
3068 u32 header, control = INDIRECT_BUFFER_VALID;
3069
3070 if (ib->is_const_ib) {
3071 /* set switch buffer packet before const IB */
3072 radeon_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
3073 radeon_ring_write(ring, 0);
3074
3075 header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
3076 } else {
3077 u32 next_rptr;
3078 if (ring->rptr_save_reg) {
3079 next_rptr = ring->wptr + 3 + 4;
3080 radeon_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
3081 radeon_ring_write(ring, ((ring->rptr_save_reg -
3082 PACKET3_SET_UCONFIG_REG_START) >> 2));
3083 radeon_ring_write(ring, next_rptr);
3084 } else if (rdev->wb.enabled) {
3085 next_rptr = ring->wptr + 5 + 4;
3086 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
3087 radeon_ring_write(ring, WRITE_DATA_DST_SEL(1));
3088 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
3089 radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xffffffff);
3090 radeon_ring_write(ring, next_rptr);
3091 }
3092
3093 header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
3094 }
3095
3096 control |= ib->length_dw |
3097 (ib->vm ? (ib->vm->id << 24) : 0);
3098
3099 radeon_ring_write(ring, header);
3100 radeon_ring_write(ring,
3101#ifdef __BIG_ENDIAN
3102 (2 << 0) |
3103#endif
3104 (ib->gpu_addr & 0xFFFFFFFC));
3105 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
3106 radeon_ring_write(ring, control);
3107}
3108
Alex Deucherfbc832c2012-07-20 14:41:35 -04003109/**
3110 * cik_ib_test - basic gfx ring IB test
3111 *
3112 * @rdev: radeon_device pointer
3113 * @ring: radeon_ring structure holding ring information
3114 *
3115 * Allocate an IB and execute it on the gfx ring (CIK).
3116 * Provides a basic gfx ring test to verify that IBs are working.
3117 * Returns 0 on success, error on failure.
3118 */
3119int cik_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
3120{
3121 struct radeon_ib ib;
3122 uint32_t scratch;
3123 uint32_t tmp = 0;
3124 unsigned i;
3125 int r;
3126
3127 r = radeon_scratch_get(rdev, &scratch);
3128 if (r) {
3129 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
3130 return r;
3131 }
3132 WREG32(scratch, 0xCAFEDEAD);
3133 r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
3134 if (r) {
3135 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
3136 return r;
3137 }
3138 ib.ptr[0] = PACKET3(PACKET3_SET_UCONFIG_REG, 1);
3139 ib.ptr[1] = ((scratch - PACKET3_SET_UCONFIG_REG_START) >> 2);
3140 ib.ptr[2] = 0xDEADBEEF;
3141 ib.length_dw = 3;
3142 r = radeon_ib_schedule(rdev, &ib, NULL);
3143 if (r) {
3144 radeon_scratch_free(rdev, scratch);
3145 radeon_ib_free(rdev, &ib);
3146 DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
3147 return r;
3148 }
3149 r = radeon_fence_wait(ib.fence, false);
3150 if (r) {
3151 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
3152 return r;
3153 }
3154 for (i = 0; i < rdev->usec_timeout; i++) {
3155 tmp = RREG32(scratch);
3156 if (tmp == 0xDEADBEEF)
3157 break;
3158 DRM_UDELAY(1);
3159 }
3160 if (i < rdev->usec_timeout) {
3161 DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
3162 } else {
3163 DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
3164 scratch, tmp);
3165 r = -EINVAL;
3166 }
3167 radeon_scratch_free(rdev, scratch);
3168 radeon_ib_free(rdev, &ib);
3169 return r;
3170}
3171
Alex Deucher2cae3bc2012-07-05 11:45:40 -04003172/*
Alex Deucher841cf442012-12-18 21:47:44 -05003173 * CP.
3174 * On CIK, gfx and compute now have independant command processors.
3175 *
3176 * GFX
3177 * Gfx consists of a single ring and can process both gfx jobs and
3178 * compute jobs. The gfx CP consists of three microengines (ME):
3179 * PFP - Pre-Fetch Parser
3180 * ME - Micro Engine
3181 * CE - Constant Engine
3182 * The PFP and ME make up what is considered the Drawing Engine (DE).
3183 * The CE is an asynchronous engine used for updating buffer desciptors
3184 * used by the DE so that they can be loaded into cache in parallel
3185 * while the DE is processing state update packets.
3186 *
3187 * Compute
3188 * The compute CP consists of two microengines (ME):
3189 * MEC1 - Compute MicroEngine 1
3190 * MEC2 - Compute MicroEngine 2
3191 * Each MEC supports 4 compute pipes and each pipe supports 8 queues.
3192 * The queues are exposed to userspace and are programmed directly
3193 * by the compute runtime.
3194 */
3195/**
3196 * cik_cp_gfx_enable - enable/disable the gfx CP MEs
3197 *
3198 * @rdev: radeon_device pointer
3199 * @enable: enable or disable the MEs
3200 *
3201 * Halts or unhalts the gfx MEs.
3202 */
3203static void cik_cp_gfx_enable(struct radeon_device *rdev, bool enable)
3204{
3205 if (enable)
3206 WREG32(CP_ME_CNTL, 0);
3207 else {
3208 WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT));
3209 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
3210 }
3211 udelay(50);
3212}
3213
3214/**
3215 * cik_cp_gfx_load_microcode - load the gfx CP ME ucode
3216 *
3217 * @rdev: radeon_device pointer
3218 *
3219 * Loads the gfx PFP, ME, and CE ucode.
3220 * Returns 0 for success, -EINVAL if the ucode is not available.
3221 */
3222static int cik_cp_gfx_load_microcode(struct radeon_device *rdev)
3223{
3224 const __be32 *fw_data;
3225 int i;
3226
3227 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw)
3228 return -EINVAL;
3229
3230 cik_cp_gfx_enable(rdev, false);
3231
3232 /* PFP */
3233 fw_data = (const __be32 *)rdev->pfp_fw->data;
3234 WREG32(CP_PFP_UCODE_ADDR, 0);
3235 for (i = 0; i < CIK_PFP_UCODE_SIZE; i++)
3236 WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
3237 WREG32(CP_PFP_UCODE_ADDR, 0);
3238
3239 /* CE */
3240 fw_data = (const __be32 *)rdev->ce_fw->data;
3241 WREG32(CP_CE_UCODE_ADDR, 0);
3242 for (i = 0; i < CIK_CE_UCODE_SIZE; i++)
3243 WREG32(CP_CE_UCODE_DATA, be32_to_cpup(fw_data++));
3244 WREG32(CP_CE_UCODE_ADDR, 0);
3245
3246 /* ME */
3247 fw_data = (const __be32 *)rdev->me_fw->data;
3248 WREG32(CP_ME_RAM_WADDR, 0);
3249 for (i = 0; i < CIK_ME_UCODE_SIZE; i++)
3250 WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
3251 WREG32(CP_ME_RAM_WADDR, 0);
3252
3253 WREG32(CP_PFP_UCODE_ADDR, 0);
3254 WREG32(CP_CE_UCODE_ADDR, 0);
3255 WREG32(CP_ME_RAM_WADDR, 0);
3256 WREG32(CP_ME_RAM_RADDR, 0);
3257 return 0;
3258}
3259
3260/**
3261 * cik_cp_gfx_start - start the gfx ring
3262 *
3263 * @rdev: radeon_device pointer
3264 *
3265 * Enables the ring and loads the clear state context and other
3266 * packets required to init the ring.
3267 * Returns 0 for success, error for failure.
3268 */
3269static int cik_cp_gfx_start(struct radeon_device *rdev)
3270{
3271 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
3272 int r, i;
3273
3274 /* init the CP */
3275 WREG32(CP_MAX_CONTEXT, rdev->config.cik.max_hw_contexts - 1);
3276 WREG32(CP_ENDIAN_SWAP, 0);
3277 WREG32(CP_DEVICE_ID, 1);
3278
3279 cik_cp_gfx_enable(rdev, true);
3280
3281 r = radeon_ring_lock(rdev, ring, cik_default_size + 17);
3282 if (r) {
3283 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
3284 return r;
3285 }
3286
3287 /* init the CE partitions. CE only used for gfx on CIK */
3288 radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
3289 radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
3290 radeon_ring_write(ring, 0xc000);
3291 radeon_ring_write(ring, 0xc000);
3292
3293 /* setup clear context state */
3294 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
3295 radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
3296
3297 radeon_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
3298 radeon_ring_write(ring, 0x80000000);
3299 radeon_ring_write(ring, 0x80000000);
3300
3301 for (i = 0; i < cik_default_size; i++)
3302 radeon_ring_write(ring, cik_default_state[i]);
3303
3304 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
3305 radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
3306
3307 /* set clear context state */
3308 radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
3309 radeon_ring_write(ring, 0);
3310
3311 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
3312 radeon_ring_write(ring, 0x00000316);
3313 radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
3314 radeon_ring_write(ring, 0x00000010); /* VGT_OUT_DEALLOC_CNTL */
3315
3316 radeon_ring_unlock_commit(rdev, ring);
3317
3318 return 0;
3319}
3320
3321/**
3322 * cik_cp_gfx_fini - stop the gfx ring
3323 *
3324 * @rdev: radeon_device pointer
3325 *
3326 * Stop the gfx ring and tear down the driver ring
3327 * info.
3328 */
3329static void cik_cp_gfx_fini(struct radeon_device *rdev)
3330{
3331 cik_cp_gfx_enable(rdev, false);
3332 radeon_ring_fini(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
3333}
3334
3335/**
3336 * cik_cp_gfx_resume - setup the gfx ring buffer registers
3337 *
3338 * @rdev: radeon_device pointer
3339 *
3340 * Program the location and size of the gfx ring buffer
3341 * and test it to make sure it's working.
3342 * Returns 0 for success, error for failure.
3343 */
3344static int cik_cp_gfx_resume(struct radeon_device *rdev)
3345{
3346 struct radeon_ring *ring;
3347 u32 tmp;
3348 u32 rb_bufsz;
3349 u64 rb_addr;
3350 int r;
3351
3352 WREG32(CP_SEM_WAIT_TIMER, 0x0);
3353 WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
3354
3355 /* Set the write pointer delay */
3356 WREG32(CP_RB_WPTR_DELAY, 0);
3357
3358 /* set the RB to use vmid 0 */
3359 WREG32(CP_RB_VMID, 0);
3360
3361 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
3362
3363 /* ring 0 - compute and gfx */
3364 /* Set ring buffer size */
3365 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
3366 rb_bufsz = drm_order(ring->ring_size / 8);
3367 tmp = (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
3368#ifdef __BIG_ENDIAN
3369 tmp |= BUF_SWAP_32BIT;
3370#endif
3371 WREG32(CP_RB0_CNTL, tmp);
3372
3373 /* Initialize the ring buffer's read and write pointers */
3374 WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA);
3375 ring->wptr = 0;
3376 WREG32(CP_RB0_WPTR, ring->wptr);
3377
3378 /* set the wb address wether it's enabled or not */
3379 WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
3380 WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
3381
3382 /* scratch register shadowing is no longer supported */
3383 WREG32(SCRATCH_UMSK, 0);
3384
3385 if (!rdev->wb.enabled)
3386 tmp |= RB_NO_UPDATE;
3387
3388 mdelay(1);
3389 WREG32(CP_RB0_CNTL, tmp);
3390
3391 rb_addr = ring->gpu_addr >> 8;
3392 WREG32(CP_RB0_BASE, rb_addr);
3393 WREG32(CP_RB0_BASE_HI, upper_32_bits(rb_addr));
3394
3395 ring->rptr = RREG32(CP_RB0_RPTR);
3396
3397 /* start the ring */
3398 cik_cp_gfx_start(rdev);
3399 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
3400 r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
3401 if (r) {
3402 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
3403 return r;
3404 }
3405 return 0;
3406}
3407
Alex Deucher963e81f2013-06-26 17:37:11 -04003408u32 cik_compute_ring_get_rptr(struct radeon_device *rdev,
3409 struct radeon_ring *ring)
3410{
3411 u32 rptr;
3412
3413
3414
3415 if (rdev->wb.enabled) {
3416 rptr = le32_to_cpu(rdev->wb.wb[ring->rptr_offs/4]);
3417 } else {
Alex Deucherf61d5b462013-08-06 12:40:16 -04003418 mutex_lock(&rdev->srbm_mutex);
Alex Deucher963e81f2013-06-26 17:37:11 -04003419 cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
3420 rptr = RREG32(CP_HQD_PQ_RPTR);
3421 cik_srbm_select(rdev, 0, 0, 0, 0);
Alex Deucherf61d5b462013-08-06 12:40:16 -04003422 mutex_unlock(&rdev->srbm_mutex);
Alex Deucher963e81f2013-06-26 17:37:11 -04003423 }
Alex Deucher963e81f2013-06-26 17:37:11 -04003424
3425 return rptr;
3426}
3427
3428u32 cik_compute_ring_get_wptr(struct radeon_device *rdev,
3429 struct radeon_ring *ring)
3430{
3431 u32 wptr;
3432
3433 if (rdev->wb.enabled) {
3434 wptr = le32_to_cpu(rdev->wb.wb[ring->wptr_offs/4]);
3435 } else {
Alex Deucherf61d5b462013-08-06 12:40:16 -04003436 mutex_lock(&rdev->srbm_mutex);
Alex Deucher963e81f2013-06-26 17:37:11 -04003437 cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
3438 wptr = RREG32(CP_HQD_PQ_WPTR);
3439 cik_srbm_select(rdev, 0, 0, 0, 0);
Alex Deucherf61d5b462013-08-06 12:40:16 -04003440 mutex_unlock(&rdev->srbm_mutex);
Alex Deucher963e81f2013-06-26 17:37:11 -04003441 }
Alex Deucher963e81f2013-06-26 17:37:11 -04003442
3443 return wptr;
3444}
3445
3446void cik_compute_ring_set_wptr(struct radeon_device *rdev,
3447 struct radeon_ring *ring)
3448{
Christian König2e1e6da2013-08-13 11:56:52 +02003449 rdev->wb.wb[ring->wptr_offs/4] = cpu_to_le32(ring->wptr);
3450 WDOORBELL32(ring->doorbell_offset, ring->wptr);
Alex Deucher963e81f2013-06-26 17:37:11 -04003451}
3452
Alex Deucher841cf442012-12-18 21:47:44 -05003453/**
3454 * cik_cp_compute_enable - enable/disable the compute CP MEs
3455 *
3456 * @rdev: radeon_device pointer
3457 * @enable: enable or disable the MEs
3458 *
3459 * Halts or unhalts the compute MEs.
3460 */
3461static void cik_cp_compute_enable(struct radeon_device *rdev, bool enable)
3462{
3463 if (enable)
3464 WREG32(CP_MEC_CNTL, 0);
3465 else
3466 WREG32(CP_MEC_CNTL, (MEC_ME1_HALT | MEC_ME2_HALT));
3467 udelay(50);
3468}
3469
3470/**
3471 * cik_cp_compute_load_microcode - load the compute CP ME ucode
3472 *
3473 * @rdev: radeon_device pointer
3474 *
3475 * Loads the compute MEC1&2 ucode.
3476 * Returns 0 for success, -EINVAL if the ucode is not available.
3477 */
3478static int cik_cp_compute_load_microcode(struct radeon_device *rdev)
3479{
3480 const __be32 *fw_data;
3481 int i;
3482
3483 if (!rdev->mec_fw)
3484 return -EINVAL;
3485
3486 cik_cp_compute_enable(rdev, false);
3487
3488 /* MEC1 */
3489 fw_data = (const __be32 *)rdev->mec_fw->data;
3490 WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
3491 for (i = 0; i < CIK_MEC_UCODE_SIZE; i++)
3492 WREG32(CP_MEC_ME1_UCODE_DATA, be32_to_cpup(fw_data++));
3493 WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
3494
3495 if (rdev->family == CHIP_KAVERI) {
3496 /* MEC2 */
3497 fw_data = (const __be32 *)rdev->mec_fw->data;
3498 WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
3499 for (i = 0; i < CIK_MEC_UCODE_SIZE; i++)
3500 WREG32(CP_MEC_ME2_UCODE_DATA, be32_to_cpup(fw_data++));
3501 WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
3502 }
3503
3504 return 0;
3505}
3506
3507/**
3508 * cik_cp_compute_start - start the compute queues
3509 *
3510 * @rdev: radeon_device pointer
3511 *
3512 * Enable the compute queues.
3513 * Returns 0 for success, error for failure.
3514 */
3515static int cik_cp_compute_start(struct radeon_device *rdev)
3516{
Alex Deucher963e81f2013-06-26 17:37:11 -04003517 cik_cp_compute_enable(rdev, true);
3518
Alex Deucher841cf442012-12-18 21:47:44 -05003519 return 0;
3520}
3521
3522/**
3523 * cik_cp_compute_fini - stop the compute queues
3524 *
3525 * @rdev: radeon_device pointer
3526 *
3527 * Stop the compute queues and tear down the driver queue
3528 * info.
3529 */
3530static void cik_cp_compute_fini(struct radeon_device *rdev)
3531{
Alex Deucher963e81f2013-06-26 17:37:11 -04003532 int i, idx, r;
3533
Alex Deucher841cf442012-12-18 21:47:44 -05003534 cik_cp_compute_enable(rdev, false);
Alex Deucher963e81f2013-06-26 17:37:11 -04003535
3536 for (i = 0; i < 2; i++) {
3537 if (i == 0)
3538 idx = CAYMAN_RING_TYPE_CP1_INDEX;
3539 else
3540 idx = CAYMAN_RING_TYPE_CP2_INDEX;
3541
3542 if (rdev->ring[idx].mqd_obj) {
3543 r = radeon_bo_reserve(rdev->ring[idx].mqd_obj, false);
3544 if (unlikely(r != 0))
3545 dev_warn(rdev->dev, "(%d) reserve MQD bo failed\n", r);
3546
3547 radeon_bo_unpin(rdev->ring[idx].mqd_obj);
3548 radeon_bo_unreserve(rdev->ring[idx].mqd_obj);
3549
3550 radeon_bo_unref(&rdev->ring[idx].mqd_obj);
3551 rdev->ring[idx].mqd_obj = NULL;
3552 }
3553 }
Alex Deucher841cf442012-12-18 21:47:44 -05003554}
3555
Alex Deucher963e81f2013-06-26 17:37:11 -04003556static void cik_mec_fini(struct radeon_device *rdev)
3557{
3558 int r;
3559
3560 if (rdev->mec.hpd_eop_obj) {
3561 r = radeon_bo_reserve(rdev->mec.hpd_eop_obj, false);
3562 if (unlikely(r != 0))
3563 dev_warn(rdev->dev, "(%d) reserve HPD EOP bo failed\n", r);
3564 radeon_bo_unpin(rdev->mec.hpd_eop_obj);
3565 radeon_bo_unreserve(rdev->mec.hpd_eop_obj);
3566
3567 radeon_bo_unref(&rdev->mec.hpd_eop_obj);
3568 rdev->mec.hpd_eop_obj = NULL;
3569 }
3570}
3571
3572#define MEC_HPD_SIZE 2048
3573
3574static int cik_mec_init(struct radeon_device *rdev)
3575{
3576 int r;
3577 u32 *hpd;
3578
3579 /*
3580 * KV: 2 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 64 Queues total
3581 * CI/KB: 1 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 32 Queues total
3582 */
3583 if (rdev->family == CHIP_KAVERI)
3584 rdev->mec.num_mec = 2;
3585 else
3586 rdev->mec.num_mec = 1;
3587 rdev->mec.num_pipe = 4;
3588 rdev->mec.num_queue = rdev->mec.num_mec * rdev->mec.num_pipe * 8;
3589
3590 if (rdev->mec.hpd_eop_obj == NULL) {
3591 r = radeon_bo_create(rdev,
3592 rdev->mec.num_mec *rdev->mec.num_pipe * MEC_HPD_SIZE * 2,
3593 PAGE_SIZE, true,
3594 RADEON_GEM_DOMAIN_GTT, NULL,
3595 &rdev->mec.hpd_eop_obj);
3596 if (r) {
3597 dev_warn(rdev->dev, "(%d) create HDP EOP bo failed\n", r);
3598 return r;
3599 }
3600 }
3601
3602 r = radeon_bo_reserve(rdev->mec.hpd_eop_obj, false);
3603 if (unlikely(r != 0)) {
3604 cik_mec_fini(rdev);
3605 return r;
3606 }
3607 r = radeon_bo_pin(rdev->mec.hpd_eop_obj, RADEON_GEM_DOMAIN_GTT,
3608 &rdev->mec.hpd_eop_gpu_addr);
3609 if (r) {
3610 dev_warn(rdev->dev, "(%d) pin HDP EOP bo failed\n", r);
3611 cik_mec_fini(rdev);
3612 return r;
3613 }
3614 r = radeon_bo_kmap(rdev->mec.hpd_eop_obj, (void **)&hpd);
3615 if (r) {
3616 dev_warn(rdev->dev, "(%d) map HDP EOP bo failed\n", r);
3617 cik_mec_fini(rdev);
3618 return r;
3619 }
3620
3621 /* clear memory. Not sure if this is required or not */
3622 memset(hpd, 0, rdev->mec.num_mec *rdev->mec.num_pipe * MEC_HPD_SIZE * 2);
3623
3624 radeon_bo_kunmap(rdev->mec.hpd_eop_obj);
3625 radeon_bo_unreserve(rdev->mec.hpd_eop_obj);
3626
3627 return 0;
3628}
3629
3630struct hqd_registers
3631{
3632 u32 cp_mqd_base_addr;
3633 u32 cp_mqd_base_addr_hi;
3634 u32 cp_hqd_active;
3635 u32 cp_hqd_vmid;
3636 u32 cp_hqd_persistent_state;
3637 u32 cp_hqd_pipe_priority;
3638 u32 cp_hqd_queue_priority;
3639 u32 cp_hqd_quantum;
3640 u32 cp_hqd_pq_base;
3641 u32 cp_hqd_pq_base_hi;
3642 u32 cp_hqd_pq_rptr;
3643 u32 cp_hqd_pq_rptr_report_addr;
3644 u32 cp_hqd_pq_rptr_report_addr_hi;
3645 u32 cp_hqd_pq_wptr_poll_addr;
3646 u32 cp_hqd_pq_wptr_poll_addr_hi;
3647 u32 cp_hqd_pq_doorbell_control;
3648 u32 cp_hqd_pq_wptr;
3649 u32 cp_hqd_pq_control;
3650 u32 cp_hqd_ib_base_addr;
3651 u32 cp_hqd_ib_base_addr_hi;
3652 u32 cp_hqd_ib_rptr;
3653 u32 cp_hqd_ib_control;
3654 u32 cp_hqd_iq_timer;
3655 u32 cp_hqd_iq_rptr;
3656 u32 cp_hqd_dequeue_request;
3657 u32 cp_hqd_dma_offload;
3658 u32 cp_hqd_sema_cmd;
3659 u32 cp_hqd_msg_type;
3660 u32 cp_hqd_atomic0_preop_lo;
3661 u32 cp_hqd_atomic0_preop_hi;
3662 u32 cp_hqd_atomic1_preop_lo;
3663 u32 cp_hqd_atomic1_preop_hi;
3664 u32 cp_hqd_hq_scheduler0;
3665 u32 cp_hqd_hq_scheduler1;
3666 u32 cp_mqd_control;
3667};
3668
3669struct bonaire_mqd
3670{
3671 u32 header;
3672 u32 dispatch_initiator;
3673 u32 dimensions[3];
3674 u32 start_idx[3];
3675 u32 num_threads[3];
3676 u32 pipeline_stat_enable;
3677 u32 perf_counter_enable;
3678 u32 pgm[2];
3679 u32 tba[2];
3680 u32 tma[2];
3681 u32 pgm_rsrc[2];
3682 u32 vmid;
3683 u32 resource_limits;
3684 u32 static_thread_mgmt01[2];
3685 u32 tmp_ring_size;
3686 u32 static_thread_mgmt23[2];
3687 u32 restart[3];
3688 u32 thread_trace_enable;
3689 u32 reserved1;
3690 u32 user_data[16];
3691 u32 vgtcs_invoke_count[2];
3692 struct hqd_registers queue_state;
3693 u32 dequeue_cntr;
3694 u32 interrupt_queue[64];
3695};
3696
Alex Deucher841cf442012-12-18 21:47:44 -05003697/**
3698 * cik_cp_compute_resume - setup the compute queue registers
3699 *
3700 * @rdev: radeon_device pointer
3701 *
3702 * Program the compute queues and test them to make sure they
3703 * are working.
3704 * Returns 0 for success, error for failure.
3705 */
3706static int cik_cp_compute_resume(struct radeon_device *rdev)
3707{
Alex Deucher963e81f2013-06-26 17:37:11 -04003708 int r, i, idx;
3709 u32 tmp;
3710 bool use_doorbell = true;
3711 u64 hqd_gpu_addr;
3712 u64 mqd_gpu_addr;
3713 u64 eop_gpu_addr;
3714 u64 wb_gpu_addr;
3715 u32 *buf;
3716 struct bonaire_mqd *mqd;
Alex Deucher841cf442012-12-18 21:47:44 -05003717
Alex Deucher841cf442012-12-18 21:47:44 -05003718 r = cik_cp_compute_start(rdev);
3719 if (r)
3720 return r;
Alex Deucher963e81f2013-06-26 17:37:11 -04003721
3722 /* fix up chicken bits */
3723 tmp = RREG32(CP_CPF_DEBUG);
3724 tmp |= (1 << 23);
3725 WREG32(CP_CPF_DEBUG, tmp);
3726
3727 /* init the pipes */
Alex Deucherf61d5b462013-08-06 12:40:16 -04003728 mutex_lock(&rdev->srbm_mutex);
Alex Deucher963e81f2013-06-26 17:37:11 -04003729 for (i = 0; i < (rdev->mec.num_pipe * rdev->mec.num_mec); i++) {
3730 int me = (i < 4) ? 1 : 2;
3731 int pipe = (i < 4) ? i : (i - 4);
3732
3733 eop_gpu_addr = rdev->mec.hpd_eop_gpu_addr + (i * MEC_HPD_SIZE * 2);
3734
3735 cik_srbm_select(rdev, me, pipe, 0, 0);
3736
3737 /* write the EOP addr */
3738 WREG32(CP_HPD_EOP_BASE_ADDR, eop_gpu_addr >> 8);
3739 WREG32(CP_HPD_EOP_BASE_ADDR_HI, upper_32_bits(eop_gpu_addr) >> 8);
3740
3741 /* set the VMID assigned */
3742 WREG32(CP_HPD_EOP_VMID, 0);
3743
3744 /* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */
3745 tmp = RREG32(CP_HPD_EOP_CONTROL);
3746 tmp &= ~EOP_SIZE_MASK;
3747 tmp |= drm_order(MEC_HPD_SIZE / 8);
3748 WREG32(CP_HPD_EOP_CONTROL, tmp);
3749 }
3750 cik_srbm_select(rdev, 0, 0, 0, 0);
Alex Deucherf61d5b462013-08-06 12:40:16 -04003751 mutex_unlock(&rdev->srbm_mutex);
Alex Deucher963e81f2013-06-26 17:37:11 -04003752
3753 /* init the queues. Just two for now. */
3754 for (i = 0; i < 2; i++) {
3755 if (i == 0)
3756 idx = CAYMAN_RING_TYPE_CP1_INDEX;
3757 else
3758 idx = CAYMAN_RING_TYPE_CP2_INDEX;
3759
3760 if (rdev->ring[idx].mqd_obj == NULL) {
3761 r = radeon_bo_create(rdev,
3762 sizeof(struct bonaire_mqd),
3763 PAGE_SIZE, true,
3764 RADEON_GEM_DOMAIN_GTT, NULL,
3765 &rdev->ring[idx].mqd_obj);
3766 if (r) {
3767 dev_warn(rdev->dev, "(%d) create MQD bo failed\n", r);
3768 return r;
3769 }
3770 }
3771
3772 r = radeon_bo_reserve(rdev->ring[idx].mqd_obj, false);
3773 if (unlikely(r != 0)) {
3774 cik_cp_compute_fini(rdev);
3775 return r;
3776 }
3777 r = radeon_bo_pin(rdev->ring[idx].mqd_obj, RADEON_GEM_DOMAIN_GTT,
3778 &mqd_gpu_addr);
3779 if (r) {
3780 dev_warn(rdev->dev, "(%d) pin MQD bo failed\n", r);
3781 cik_cp_compute_fini(rdev);
3782 return r;
3783 }
3784 r = radeon_bo_kmap(rdev->ring[idx].mqd_obj, (void **)&buf);
3785 if (r) {
3786 dev_warn(rdev->dev, "(%d) map MQD bo failed\n", r);
3787 cik_cp_compute_fini(rdev);
3788 return r;
3789 }
3790
3791 /* doorbell offset */
3792 rdev->ring[idx].doorbell_offset =
3793 (rdev->ring[idx].doorbell_page_num * PAGE_SIZE) + 0;
3794
3795 /* init the mqd struct */
3796 memset(buf, 0, sizeof(struct bonaire_mqd));
3797
3798 mqd = (struct bonaire_mqd *)buf;
3799 mqd->header = 0xC0310800;
3800 mqd->static_thread_mgmt01[0] = 0xffffffff;
3801 mqd->static_thread_mgmt01[1] = 0xffffffff;
3802 mqd->static_thread_mgmt23[0] = 0xffffffff;
3803 mqd->static_thread_mgmt23[1] = 0xffffffff;
3804
Alex Deucherf61d5b462013-08-06 12:40:16 -04003805 mutex_lock(&rdev->srbm_mutex);
Alex Deucher963e81f2013-06-26 17:37:11 -04003806 cik_srbm_select(rdev, rdev->ring[idx].me,
3807 rdev->ring[idx].pipe,
3808 rdev->ring[idx].queue, 0);
3809
3810 /* disable wptr polling */
3811 tmp = RREG32(CP_PQ_WPTR_POLL_CNTL);
3812 tmp &= ~WPTR_POLL_EN;
3813 WREG32(CP_PQ_WPTR_POLL_CNTL, tmp);
3814
3815 /* enable doorbell? */
3816 mqd->queue_state.cp_hqd_pq_doorbell_control =
3817 RREG32(CP_HQD_PQ_DOORBELL_CONTROL);
3818 if (use_doorbell)
3819 mqd->queue_state.cp_hqd_pq_doorbell_control |= DOORBELL_EN;
3820 else
3821 mqd->queue_state.cp_hqd_pq_doorbell_control &= ~DOORBELL_EN;
3822 WREG32(CP_HQD_PQ_DOORBELL_CONTROL,
3823 mqd->queue_state.cp_hqd_pq_doorbell_control);
3824
3825 /* disable the queue if it's active */
3826 mqd->queue_state.cp_hqd_dequeue_request = 0;
3827 mqd->queue_state.cp_hqd_pq_rptr = 0;
3828 mqd->queue_state.cp_hqd_pq_wptr= 0;
3829 if (RREG32(CP_HQD_ACTIVE) & 1) {
3830 WREG32(CP_HQD_DEQUEUE_REQUEST, 1);
3831 for (i = 0; i < rdev->usec_timeout; i++) {
3832 if (!(RREG32(CP_HQD_ACTIVE) & 1))
3833 break;
3834 udelay(1);
3835 }
3836 WREG32(CP_HQD_DEQUEUE_REQUEST, mqd->queue_state.cp_hqd_dequeue_request);
3837 WREG32(CP_HQD_PQ_RPTR, mqd->queue_state.cp_hqd_pq_rptr);
3838 WREG32(CP_HQD_PQ_WPTR, mqd->queue_state.cp_hqd_pq_wptr);
3839 }
3840
3841 /* set the pointer to the MQD */
3842 mqd->queue_state.cp_mqd_base_addr = mqd_gpu_addr & 0xfffffffc;
3843 mqd->queue_state.cp_mqd_base_addr_hi = upper_32_bits(mqd_gpu_addr);
3844 WREG32(CP_MQD_BASE_ADDR, mqd->queue_state.cp_mqd_base_addr);
3845 WREG32(CP_MQD_BASE_ADDR_HI, mqd->queue_state.cp_mqd_base_addr_hi);
3846 /* set MQD vmid to 0 */
3847 mqd->queue_state.cp_mqd_control = RREG32(CP_MQD_CONTROL);
3848 mqd->queue_state.cp_mqd_control &= ~MQD_VMID_MASK;
3849 WREG32(CP_MQD_CONTROL, mqd->queue_state.cp_mqd_control);
3850
3851 /* set the pointer to the HQD, this is similar CP_RB0_BASE/_HI */
3852 hqd_gpu_addr = rdev->ring[idx].gpu_addr >> 8;
3853 mqd->queue_state.cp_hqd_pq_base = hqd_gpu_addr;
3854 mqd->queue_state.cp_hqd_pq_base_hi = upper_32_bits(hqd_gpu_addr);
3855 WREG32(CP_HQD_PQ_BASE, mqd->queue_state.cp_hqd_pq_base);
3856 WREG32(CP_HQD_PQ_BASE_HI, mqd->queue_state.cp_hqd_pq_base_hi);
3857
3858 /* set up the HQD, this is similar to CP_RB0_CNTL */
3859 mqd->queue_state.cp_hqd_pq_control = RREG32(CP_HQD_PQ_CONTROL);
3860 mqd->queue_state.cp_hqd_pq_control &=
3861 ~(QUEUE_SIZE_MASK | RPTR_BLOCK_SIZE_MASK);
3862
3863 mqd->queue_state.cp_hqd_pq_control |=
3864 drm_order(rdev->ring[idx].ring_size / 8);
3865 mqd->queue_state.cp_hqd_pq_control |=
3866 (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8);
3867#ifdef __BIG_ENDIAN
3868 mqd->queue_state.cp_hqd_pq_control |= BUF_SWAP_32BIT;
3869#endif
3870 mqd->queue_state.cp_hqd_pq_control &=
3871 ~(UNORD_DISPATCH | ROQ_PQ_IB_FLIP | PQ_VOLATILE);
3872 mqd->queue_state.cp_hqd_pq_control |=
3873 PRIV_STATE | KMD_QUEUE; /* assuming kernel queue control */
3874 WREG32(CP_HQD_PQ_CONTROL, mqd->queue_state.cp_hqd_pq_control);
3875
3876 /* only used if CP_PQ_WPTR_POLL_CNTL.WPTR_POLL_EN=1 */
3877 if (i == 0)
3878 wb_gpu_addr = rdev->wb.gpu_addr + CIK_WB_CP1_WPTR_OFFSET;
3879 else
3880 wb_gpu_addr = rdev->wb.gpu_addr + CIK_WB_CP2_WPTR_OFFSET;
3881 mqd->queue_state.cp_hqd_pq_wptr_poll_addr = wb_gpu_addr & 0xfffffffc;
3882 mqd->queue_state.cp_hqd_pq_wptr_poll_addr_hi = upper_32_bits(wb_gpu_addr) & 0xffff;
3883 WREG32(CP_HQD_PQ_WPTR_POLL_ADDR, mqd->queue_state.cp_hqd_pq_wptr_poll_addr);
3884 WREG32(CP_HQD_PQ_WPTR_POLL_ADDR_HI,
3885 mqd->queue_state.cp_hqd_pq_wptr_poll_addr_hi);
3886
3887 /* set the wb address wether it's enabled or not */
3888 if (i == 0)
3889 wb_gpu_addr = rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET;
3890 else
3891 wb_gpu_addr = rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET;
3892 mqd->queue_state.cp_hqd_pq_rptr_report_addr = wb_gpu_addr & 0xfffffffc;
3893 mqd->queue_state.cp_hqd_pq_rptr_report_addr_hi =
3894 upper_32_bits(wb_gpu_addr) & 0xffff;
3895 WREG32(CP_HQD_PQ_RPTR_REPORT_ADDR,
3896 mqd->queue_state.cp_hqd_pq_rptr_report_addr);
3897 WREG32(CP_HQD_PQ_RPTR_REPORT_ADDR_HI,
3898 mqd->queue_state.cp_hqd_pq_rptr_report_addr_hi);
3899
3900 /* enable the doorbell if requested */
3901 if (use_doorbell) {
3902 mqd->queue_state.cp_hqd_pq_doorbell_control =
3903 RREG32(CP_HQD_PQ_DOORBELL_CONTROL);
3904 mqd->queue_state.cp_hqd_pq_doorbell_control &= ~DOORBELL_OFFSET_MASK;
3905 mqd->queue_state.cp_hqd_pq_doorbell_control |=
3906 DOORBELL_OFFSET(rdev->ring[idx].doorbell_offset / 4);
3907 mqd->queue_state.cp_hqd_pq_doorbell_control |= DOORBELL_EN;
3908 mqd->queue_state.cp_hqd_pq_doorbell_control &=
3909 ~(DOORBELL_SOURCE | DOORBELL_HIT);
3910
3911 } else {
3912 mqd->queue_state.cp_hqd_pq_doorbell_control = 0;
3913 }
3914 WREG32(CP_HQD_PQ_DOORBELL_CONTROL,
3915 mqd->queue_state.cp_hqd_pq_doorbell_control);
3916
3917 /* read and write pointers, similar to CP_RB0_WPTR/_RPTR */
3918 rdev->ring[idx].wptr = 0;
3919 mqd->queue_state.cp_hqd_pq_wptr = rdev->ring[idx].wptr;
3920 WREG32(CP_HQD_PQ_WPTR, mqd->queue_state.cp_hqd_pq_wptr);
3921 rdev->ring[idx].rptr = RREG32(CP_HQD_PQ_RPTR);
3922 mqd->queue_state.cp_hqd_pq_rptr = rdev->ring[idx].rptr;
3923
3924 /* set the vmid for the queue */
3925 mqd->queue_state.cp_hqd_vmid = 0;
3926 WREG32(CP_HQD_VMID, mqd->queue_state.cp_hqd_vmid);
3927
3928 /* activate the queue */
3929 mqd->queue_state.cp_hqd_active = 1;
3930 WREG32(CP_HQD_ACTIVE, mqd->queue_state.cp_hqd_active);
3931
3932 cik_srbm_select(rdev, 0, 0, 0, 0);
Alex Deucherf61d5b462013-08-06 12:40:16 -04003933 mutex_unlock(&rdev->srbm_mutex);
Alex Deucher963e81f2013-06-26 17:37:11 -04003934
3935 radeon_bo_kunmap(rdev->ring[idx].mqd_obj);
3936 radeon_bo_unreserve(rdev->ring[idx].mqd_obj);
3937
3938 rdev->ring[idx].ready = true;
3939 r = radeon_ring_test(rdev, idx, &rdev->ring[idx]);
3940 if (r)
3941 rdev->ring[idx].ready = false;
3942 }
3943
Alex Deucher841cf442012-12-18 21:47:44 -05003944 return 0;
3945}
3946
Alex Deucher841cf442012-12-18 21:47:44 -05003947static void cik_cp_enable(struct radeon_device *rdev, bool enable)
3948{
3949 cik_cp_gfx_enable(rdev, enable);
3950 cik_cp_compute_enable(rdev, enable);
3951}
3952
Alex Deucher841cf442012-12-18 21:47:44 -05003953static int cik_cp_load_microcode(struct radeon_device *rdev)
3954{
3955 int r;
3956
3957 r = cik_cp_gfx_load_microcode(rdev);
3958 if (r)
3959 return r;
3960 r = cik_cp_compute_load_microcode(rdev);
3961 if (r)
3962 return r;
3963
3964 return 0;
3965}
3966
Alex Deucher841cf442012-12-18 21:47:44 -05003967static void cik_cp_fini(struct radeon_device *rdev)
3968{
3969 cik_cp_gfx_fini(rdev);
3970 cik_cp_compute_fini(rdev);
3971}
3972
Alex Deucher841cf442012-12-18 21:47:44 -05003973static int cik_cp_resume(struct radeon_device *rdev)
3974{
3975 int r;
3976
Alex Deucher841cf442012-12-18 21:47:44 -05003977 r = cik_cp_load_microcode(rdev);
3978 if (r)
3979 return r;
3980
3981 r = cik_cp_gfx_resume(rdev);
3982 if (r)
3983 return r;
3984 r = cik_cp_compute_resume(rdev);
3985 if (r)
3986 return r;
3987
3988 return 0;
3989}
3990
Alex Deuchercc066712013-04-09 12:59:51 -04003991static void cik_print_gpu_status_regs(struct radeon_device *rdev)
3992{
3993 dev_info(rdev->dev, " GRBM_STATUS=0x%08X\n",
3994 RREG32(GRBM_STATUS));
3995 dev_info(rdev->dev, " GRBM_STATUS2=0x%08X\n",
3996 RREG32(GRBM_STATUS2));
3997 dev_info(rdev->dev, " GRBM_STATUS_SE0=0x%08X\n",
3998 RREG32(GRBM_STATUS_SE0));
3999 dev_info(rdev->dev, " GRBM_STATUS_SE1=0x%08X\n",
4000 RREG32(GRBM_STATUS_SE1));
4001 dev_info(rdev->dev, " GRBM_STATUS_SE2=0x%08X\n",
4002 RREG32(GRBM_STATUS_SE2));
4003 dev_info(rdev->dev, " GRBM_STATUS_SE3=0x%08X\n",
4004 RREG32(GRBM_STATUS_SE3));
4005 dev_info(rdev->dev, " SRBM_STATUS=0x%08X\n",
4006 RREG32(SRBM_STATUS));
4007 dev_info(rdev->dev, " SRBM_STATUS2=0x%08X\n",
4008 RREG32(SRBM_STATUS2));
4009 dev_info(rdev->dev, " SDMA0_STATUS_REG = 0x%08X\n",
4010 RREG32(SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET));
4011 dev_info(rdev->dev, " SDMA1_STATUS_REG = 0x%08X\n",
4012 RREG32(SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET));
Alex Deucher963e81f2013-06-26 17:37:11 -04004013 dev_info(rdev->dev, " CP_STAT = 0x%08x\n", RREG32(CP_STAT));
4014 dev_info(rdev->dev, " CP_STALLED_STAT1 = 0x%08x\n",
4015 RREG32(CP_STALLED_STAT1));
4016 dev_info(rdev->dev, " CP_STALLED_STAT2 = 0x%08x\n",
4017 RREG32(CP_STALLED_STAT2));
4018 dev_info(rdev->dev, " CP_STALLED_STAT3 = 0x%08x\n",
4019 RREG32(CP_STALLED_STAT3));
4020 dev_info(rdev->dev, " CP_CPF_BUSY_STAT = 0x%08x\n",
4021 RREG32(CP_CPF_BUSY_STAT));
4022 dev_info(rdev->dev, " CP_CPF_STALLED_STAT1 = 0x%08x\n",
4023 RREG32(CP_CPF_STALLED_STAT1));
4024 dev_info(rdev->dev, " CP_CPF_STATUS = 0x%08x\n", RREG32(CP_CPF_STATUS));
4025 dev_info(rdev->dev, " CP_CPC_BUSY_STAT = 0x%08x\n", RREG32(CP_CPC_BUSY_STAT));
4026 dev_info(rdev->dev, " CP_CPC_STALLED_STAT1 = 0x%08x\n",
4027 RREG32(CP_CPC_STALLED_STAT1));
4028 dev_info(rdev->dev, " CP_CPC_STATUS = 0x%08x\n", RREG32(CP_CPC_STATUS));
Alex Deuchercc066712013-04-09 12:59:51 -04004029}
4030
Alex Deucher6f2043c2013-04-09 12:43:41 -04004031/**
Alex Deuchercc066712013-04-09 12:59:51 -04004032 * cik_gpu_check_soft_reset - check which blocks are busy
4033 *
4034 * @rdev: radeon_device pointer
4035 *
4036 * Check which blocks are busy and return the relevant reset
4037 * mask to be used by cik_gpu_soft_reset().
4038 * Returns a mask of the blocks to be reset.
4039 */
Christian König2483b4e2013-08-13 11:56:54 +02004040u32 cik_gpu_check_soft_reset(struct radeon_device *rdev)
Alex Deuchercc066712013-04-09 12:59:51 -04004041{
4042 u32 reset_mask = 0;
4043 u32 tmp;
4044
4045 /* GRBM_STATUS */
4046 tmp = RREG32(GRBM_STATUS);
4047 if (tmp & (PA_BUSY | SC_BUSY |
4048 BCI_BUSY | SX_BUSY |
4049 TA_BUSY | VGT_BUSY |
4050 DB_BUSY | CB_BUSY |
4051 GDS_BUSY | SPI_BUSY |
4052 IA_BUSY | IA_BUSY_NO_DMA))
4053 reset_mask |= RADEON_RESET_GFX;
4054
4055 if (tmp & (CP_BUSY | CP_COHERENCY_BUSY))
4056 reset_mask |= RADEON_RESET_CP;
4057
4058 /* GRBM_STATUS2 */
4059 tmp = RREG32(GRBM_STATUS2);
4060 if (tmp & RLC_BUSY)
4061 reset_mask |= RADEON_RESET_RLC;
4062
4063 /* SDMA0_STATUS_REG */
4064 tmp = RREG32(SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET);
4065 if (!(tmp & SDMA_IDLE))
4066 reset_mask |= RADEON_RESET_DMA;
4067
4068 /* SDMA1_STATUS_REG */
4069 tmp = RREG32(SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET);
4070 if (!(tmp & SDMA_IDLE))
4071 reset_mask |= RADEON_RESET_DMA1;
4072
4073 /* SRBM_STATUS2 */
4074 tmp = RREG32(SRBM_STATUS2);
4075 if (tmp & SDMA_BUSY)
4076 reset_mask |= RADEON_RESET_DMA;
4077
4078 if (tmp & SDMA1_BUSY)
4079 reset_mask |= RADEON_RESET_DMA1;
4080
4081 /* SRBM_STATUS */
4082 tmp = RREG32(SRBM_STATUS);
4083
4084 if (tmp & IH_BUSY)
4085 reset_mask |= RADEON_RESET_IH;
4086
4087 if (tmp & SEM_BUSY)
4088 reset_mask |= RADEON_RESET_SEM;
4089
4090 if (tmp & GRBM_RQ_PENDING)
4091 reset_mask |= RADEON_RESET_GRBM;
4092
4093 if (tmp & VMC_BUSY)
4094 reset_mask |= RADEON_RESET_VMC;
4095
4096 if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
4097 MCC_BUSY | MCD_BUSY))
4098 reset_mask |= RADEON_RESET_MC;
4099
4100 if (evergreen_is_display_hung(rdev))
4101 reset_mask |= RADEON_RESET_DISPLAY;
4102
4103 /* Skip MC reset as it's mostly likely not hung, just busy */
4104 if (reset_mask & RADEON_RESET_MC) {
4105 DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
4106 reset_mask &= ~RADEON_RESET_MC;
4107 }
4108
4109 return reset_mask;
4110}
4111
4112/**
4113 * cik_gpu_soft_reset - soft reset GPU
4114 *
4115 * @rdev: radeon_device pointer
4116 * @reset_mask: mask of which blocks to reset
4117 *
4118 * Soft reset the blocks specified in @reset_mask.
4119 */
4120static void cik_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
4121{
4122 struct evergreen_mc_save save;
4123 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
4124 u32 tmp;
4125
4126 if (reset_mask == 0)
4127 return;
4128
4129 dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
4130
4131 cik_print_gpu_status_regs(rdev);
4132 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
4133 RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
4134 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
4135 RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
4136
4137 /* stop the rlc */
4138 cik_rlc_stop(rdev);
4139
4140 /* Disable GFX parsing/prefetching */
4141 WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
4142
4143 /* Disable MEC parsing/prefetching */
4144 WREG32(CP_MEC_CNTL, MEC_ME1_HALT | MEC_ME2_HALT);
4145
4146 if (reset_mask & RADEON_RESET_DMA) {
4147 /* sdma0 */
4148 tmp = RREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET);
4149 tmp |= SDMA_HALT;
4150 WREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET, tmp);
4151 }
4152 if (reset_mask & RADEON_RESET_DMA1) {
4153 /* sdma1 */
4154 tmp = RREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET);
4155 tmp |= SDMA_HALT;
4156 WREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET, tmp);
4157 }
4158
4159 evergreen_mc_stop(rdev, &save);
4160 if (evergreen_mc_wait_for_idle(rdev)) {
4161 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
4162 }
4163
4164 if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE | RADEON_RESET_CP))
4165 grbm_soft_reset = SOFT_RESET_CP | SOFT_RESET_GFX;
4166
4167 if (reset_mask & RADEON_RESET_CP) {
4168 grbm_soft_reset |= SOFT_RESET_CP;
4169
4170 srbm_soft_reset |= SOFT_RESET_GRBM;
4171 }
4172
4173 if (reset_mask & RADEON_RESET_DMA)
4174 srbm_soft_reset |= SOFT_RESET_SDMA;
4175
4176 if (reset_mask & RADEON_RESET_DMA1)
4177 srbm_soft_reset |= SOFT_RESET_SDMA1;
4178
4179 if (reset_mask & RADEON_RESET_DISPLAY)
4180 srbm_soft_reset |= SOFT_RESET_DC;
4181
4182 if (reset_mask & RADEON_RESET_RLC)
4183 grbm_soft_reset |= SOFT_RESET_RLC;
4184
4185 if (reset_mask & RADEON_RESET_SEM)
4186 srbm_soft_reset |= SOFT_RESET_SEM;
4187
4188 if (reset_mask & RADEON_RESET_IH)
4189 srbm_soft_reset |= SOFT_RESET_IH;
4190
4191 if (reset_mask & RADEON_RESET_GRBM)
4192 srbm_soft_reset |= SOFT_RESET_GRBM;
4193
4194 if (reset_mask & RADEON_RESET_VMC)
4195 srbm_soft_reset |= SOFT_RESET_VMC;
4196
4197 if (!(rdev->flags & RADEON_IS_IGP)) {
4198 if (reset_mask & RADEON_RESET_MC)
4199 srbm_soft_reset |= SOFT_RESET_MC;
4200 }
4201
4202 if (grbm_soft_reset) {
4203 tmp = RREG32(GRBM_SOFT_RESET);
4204 tmp |= grbm_soft_reset;
4205 dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
4206 WREG32(GRBM_SOFT_RESET, tmp);
4207 tmp = RREG32(GRBM_SOFT_RESET);
4208
4209 udelay(50);
4210
4211 tmp &= ~grbm_soft_reset;
4212 WREG32(GRBM_SOFT_RESET, tmp);
4213 tmp = RREG32(GRBM_SOFT_RESET);
4214 }
4215
4216 if (srbm_soft_reset) {
4217 tmp = RREG32(SRBM_SOFT_RESET);
4218 tmp |= srbm_soft_reset;
4219 dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
4220 WREG32(SRBM_SOFT_RESET, tmp);
4221 tmp = RREG32(SRBM_SOFT_RESET);
4222
4223 udelay(50);
4224
4225 tmp &= ~srbm_soft_reset;
4226 WREG32(SRBM_SOFT_RESET, tmp);
4227 tmp = RREG32(SRBM_SOFT_RESET);
4228 }
4229
4230 /* Wait a little for things to settle down */
4231 udelay(50);
4232
4233 evergreen_mc_resume(rdev, &save);
4234 udelay(50);
4235
4236 cik_print_gpu_status_regs(rdev);
4237}
4238
4239/**
4240 * cik_asic_reset - soft reset GPU
4241 *
4242 * @rdev: radeon_device pointer
4243 *
4244 * Look up which blocks are hung and attempt
4245 * to reset them.
4246 * Returns 0 for success.
4247 */
4248int cik_asic_reset(struct radeon_device *rdev)
4249{
4250 u32 reset_mask;
4251
4252 reset_mask = cik_gpu_check_soft_reset(rdev);
4253
4254 if (reset_mask)
4255 r600_set_bios_scratch_engine_hung(rdev, true);
4256
4257 cik_gpu_soft_reset(rdev, reset_mask);
4258
4259 reset_mask = cik_gpu_check_soft_reset(rdev);
4260
4261 if (!reset_mask)
4262 r600_set_bios_scratch_engine_hung(rdev, false);
4263
4264 return 0;
4265}
4266
4267/**
4268 * cik_gfx_is_lockup - check if the 3D engine is locked up
Alex Deucher6f2043c2013-04-09 12:43:41 -04004269 *
4270 * @rdev: radeon_device pointer
4271 * @ring: radeon_ring structure holding ring information
4272 *
4273 * Check if the 3D engine is locked up (CIK).
4274 * Returns true if the engine is locked, false if not.
4275 */
Alex Deuchercc066712013-04-09 12:59:51 -04004276bool cik_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
Alex Deucher6f2043c2013-04-09 12:43:41 -04004277{
Alex Deuchercc066712013-04-09 12:59:51 -04004278 u32 reset_mask = cik_gpu_check_soft_reset(rdev);
Alex Deucher6f2043c2013-04-09 12:43:41 -04004279
Alex Deuchercc066712013-04-09 12:59:51 -04004280 if (!(reset_mask & (RADEON_RESET_GFX |
4281 RADEON_RESET_COMPUTE |
4282 RADEON_RESET_CP))) {
Alex Deucher6f2043c2013-04-09 12:43:41 -04004283 radeon_ring_lockup_update(ring);
4284 return false;
4285 }
4286 /* force CP activities */
4287 radeon_ring_force_activity(rdev, ring);
4288 return radeon_ring_test_lockup(rdev, ring);
4289}
4290
Alex Deucher1c491652013-04-09 12:45:26 -04004291/* MC */
4292/**
4293 * cik_mc_program - program the GPU memory controller
4294 *
4295 * @rdev: radeon_device pointer
4296 *
4297 * Set the location of vram, gart, and AGP in the GPU's
4298 * physical address space (CIK).
4299 */
4300static void cik_mc_program(struct radeon_device *rdev)
4301{
4302 struct evergreen_mc_save save;
4303 u32 tmp;
4304 int i, j;
4305
4306 /* Initialize HDP */
4307 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
4308 WREG32((0x2c14 + j), 0x00000000);
4309 WREG32((0x2c18 + j), 0x00000000);
4310 WREG32((0x2c1c + j), 0x00000000);
4311 WREG32((0x2c20 + j), 0x00000000);
4312 WREG32((0x2c24 + j), 0x00000000);
4313 }
4314 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
4315
4316 evergreen_mc_stop(rdev, &save);
4317 if (radeon_mc_wait_for_idle(rdev)) {
4318 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
4319 }
4320 /* Lockout access through VGA aperture*/
4321 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
4322 /* Update configuration */
4323 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
4324 rdev->mc.vram_start >> 12);
4325 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
4326 rdev->mc.vram_end >> 12);
4327 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR,
4328 rdev->vram_scratch.gpu_addr >> 12);
4329 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
4330 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
4331 WREG32(MC_VM_FB_LOCATION, tmp);
4332 /* XXX double check these! */
4333 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
4334 WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
4335 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
4336 WREG32(MC_VM_AGP_BASE, 0);
4337 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
4338 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
4339 if (radeon_mc_wait_for_idle(rdev)) {
4340 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
4341 }
4342 evergreen_mc_resume(rdev, &save);
4343 /* we need to own VRAM, so turn off the VGA renderer here
4344 * to stop it overwriting our objects */
4345 rv515_vga_render_disable(rdev);
4346}
4347
4348/**
4349 * cik_mc_init - initialize the memory controller driver params
4350 *
4351 * @rdev: radeon_device pointer
4352 *
4353 * Look up the amount of vram, vram width, and decide how to place
4354 * vram and gart within the GPU's physical address space (CIK).
4355 * Returns 0 for success.
4356 */
4357static int cik_mc_init(struct radeon_device *rdev)
4358{
4359 u32 tmp;
4360 int chansize, numchan;
4361
4362 /* Get VRAM informations */
4363 rdev->mc.vram_is_ddr = true;
4364 tmp = RREG32(MC_ARB_RAMCFG);
4365 if (tmp & CHANSIZE_MASK) {
4366 chansize = 64;
4367 } else {
4368 chansize = 32;
4369 }
4370 tmp = RREG32(MC_SHARED_CHMAP);
4371 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
4372 case 0:
4373 default:
4374 numchan = 1;
4375 break;
4376 case 1:
4377 numchan = 2;
4378 break;
4379 case 2:
4380 numchan = 4;
4381 break;
4382 case 3:
4383 numchan = 8;
4384 break;
4385 case 4:
4386 numchan = 3;
4387 break;
4388 case 5:
4389 numchan = 6;
4390 break;
4391 case 6:
4392 numchan = 10;
4393 break;
4394 case 7:
4395 numchan = 12;
4396 break;
4397 case 8:
4398 numchan = 16;
4399 break;
4400 }
4401 rdev->mc.vram_width = numchan * chansize;
4402 /* Could aper size report 0 ? */
4403 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
4404 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
4405 /* size in MB on si */
4406 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024;
4407 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024;
4408 rdev->mc.visible_vram_size = rdev->mc.aper_size;
4409 si_vram_gtt_location(rdev, &rdev->mc);
4410 radeon_update_bandwidth_info(rdev);
4411
4412 return 0;
4413}
4414
4415/*
4416 * GART
4417 * VMID 0 is the physical GPU addresses as used by the kernel.
4418 * VMIDs 1-15 are used for userspace clients and are handled
4419 * by the radeon vm/hsa code.
4420 */
4421/**
4422 * cik_pcie_gart_tlb_flush - gart tlb flush callback
4423 *
4424 * @rdev: radeon_device pointer
4425 *
4426 * Flush the TLB for the VMID 0 page table (CIK).
4427 */
4428void cik_pcie_gart_tlb_flush(struct radeon_device *rdev)
4429{
4430 /* flush hdp cache */
4431 WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0);
4432
4433 /* bits 0-15 are the VM contexts0-15 */
4434 WREG32(VM_INVALIDATE_REQUEST, 0x1);
4435}
4436
4437/**
4438 * cik_pcie_gart_enable - gart enable
4439 *
4440 * @rdev: radeon_device pointer
4441 *
4442 * This sets up the TLBs, programs the page tables for VMID0,
4443 * sets up the hw for VMIDs 1-15 which are allocated on
4444 * demand, and sets up the global locations for the LDS, GDS,
4445 * and GPUVM for FSA64 clients (CIK).
4446 * Returns 0 for success, errors for failure.
4447 */
4448static int cik_pcie_gart_enable(struct radeon_device *rdev)
4449{
4450 int r, i;
4451
4452 if (rdev->gart.robj == NULL) {
4453 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
4454 return -EINVAL;
4455 }
4456 r = radeon_gart_table_vram_pin(rdev);
4457 if (r)
4458 return r;
4459 radeon_gart_restore(rdev);
4460 /* Setup TLB control */
4461 WREG32(MC_VM_MX_L1_TLB_CNTL,
4462 (0xA << 7) |
4463 ENABLE_L1_TLB |
4464 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
4465 ENABLE_ADVANCED_DRIVER_MODEL |
4466 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
4467 /* Setup L2 cache */
4468 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
4469 ENABLE_L2_FRAGMENT_PROCESSING |
4470 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
4471 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
4472 EFFECTIVE_L2_QUEUE_SIZE(7) |
4473 CONTEXT1_IDENTITY_ACCESS_MODE(1));
4474 WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
4475 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
4476 L2_CACHE_BIGK_FRAGMENT_SIZE(6));
4477 /* setup context0 */
4478 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
4479 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
4480 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
4481 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
4482 (u32)(rdev->dummy_page.addr >> 12));
4483 WREG32(VM_CONTEXT0_CNTL2, 0);
4484 WREG32(VM_CONTEXT0_CNTL, (ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
4485 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT));
4486
4487 WREG32(0x15D4, 0);
4488 WREG32(0x15D8, 0);
4489 WREG32(0x15DC, 0);
4490
4491 /* empty context1-15 */
4492 /* FIXME start with 4G, once using 2 level pt switch to full
4493 * vm size space
4494 */
4495 /* set vm size, must be a multiple of 4 */
4496 WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
4497 WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn);
4498 for (i = 1; i < 16; i++) {
4499 if (i < 8)
4500 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
4501 rdev->gart.table_addr >> 12);
4502 else
4503 WREG32(VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2),
4504 rdev->gart.table_addr >> 12);
4505 }
4506
4507 /* enable context1-15 */
4508 WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
4509 (u32)(rdev->dummy_page.addr >> 12));
Alex Deuchera00024b2012-09-18 16:06:01 -04004510 WREG32(VM_CONTEXT1_CNTL2, 4);
Alex Deucher1c491652013-04-09 12:45:26 -04004511 WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
Alex Deuchera00024b2012-09-18 16:06:01 -04004512 RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
4513 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
4514 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
4515 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
4516 PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
4517 PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
4518 VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
4519 VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
4520 READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
4521 READ_PROTECTION_FAULT_ENABLE_DEFAULT |
4522 WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
4523 WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
Alex Deucher1c491652013-04-09 12:45:26 -04004524
4525 /* TC cache setup ??? */
4526 WREG32(TC_CFG_L1_LOAD_POLICY0, 0);
4527 WREG32(TC_CFG_L1_LOAD_POLICY1, 0);
4528 WREG32(TC_CFG_L1_STORE_POLICY, 0);
4529
4530 WREG32(TC_CFG_L2_LOAD_POLICY0, 0);
4531 WREG32(TC_CFG_L2_LOAD_POLICY1, 0);
4532 WREG32(TC_CFG_L2_STORE_POLICY0, 0);
4533 WREG32(TC_CFG_L2_STORE_POLICY1, 0);
4534 WREG32(TC_CFG_L2_ATOMIC_POLICY, 0);
4535
4536 WREG32(TC_CFG_L1_VOLATILE, 0);
4537 WREG32(TC_CFG_L2_VOLATILE, 0);
4538
4539 if (rdev->family == CHIP_KAVERI) {
4540 u32 tmp = RREG32(CHUB_CONTROL);
4541 tmp &= ~BYPASS_VM;
4542 WREG32(CHUB_CONTROL, tmp);
4543 }
4544
4545 /* XXX SH_MEM regs */
4546 /* where to put LDS, scratch, GPUVM in FSA64 space */
Alex Deucherf61d5b462013-08-06 12:40:16 -04004547 mutex_lock(&rdev->srbm_mutex);
Alex Deucher1c491652013-04-09 12:45:26 -04004548 for (i = 0; i < 16; i++) {
Alex Deucherb556b122013-01-29 10:44:22 -05004549 cik_srbm_select(rdev, 0, 0, 0, i);
Alex Deucher21a93e12013-04-09 12:47:11 -04004550 /* CP and shaders */
Alex Deucher1c491652013-04-09 12:45:26 -04004551 WREG32(SH_MEM_CONFIG, 0);
4552 WREG32(SH_MEM_APE1_BASE, 1);
4553 WREG32(SH_MEM_APE1_LIMIT, 0);
4554 WREG32(SH_MEM_BASES, 0);
Alex Deucher21a93e12013-04-09 12:47:11 -04004555 /* SDMA GFX */
4556 WREG32(SDMA0_GFX_VIRTUAL_ADDR + SDMA0_REGISTER_OFFSET, 0);
4557 WREG32(SDMA0_GFX_APE1_CNTL + SDMA0_REGISTER_OFFSET, 0);
4558 WREG32(SDMA0_GFX_VIRTUAL_ADDR + SDMA1_REGISTER_OFFSET, 0);
4559 WREG32(SDMA0_GFX_APE1_CNTL + SDMA1_REGISTER_OFFSET, 0);
4560 /* XXX SDMA RLC - todo */
Alex Deucher1c491652013-04-09 12:45:26 -04004561 }
Alex Deucherb556b122013-01-29 10:44:22 -05004562 cik_srbm_select(rdev, 0, 0, 0, 0);
Alex Deucherf61d5b462013-08-06 12:40:16 -04004563 mutex_unlock(&rdev->srbm_mutex);
Alex Deucher1c491652013-04-09 12:45:26 -04004564
4565 cik_pcie_gart_tlb_flush(rdev);
4566 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
4567 (unsigned)(rdev->mc.gtt_size >> 20),
4568 (unsigned long long)rdev->gart.table_addr);
4569 rdev->gart.ready = true;
4570 return 0;
4571}
4572
4573/**
4574 * cik_pcie_gart_disable - gart disable
4575 *
4576 * @rdev: radeon_device pointer
4577 *
4578 * This disables all VM page table (CIK).
4579 */
4580static void cik_pcie_gart_disable(struct radeon_device *rdev)
4581{
4582 /* Disable all tables */
4583 WREG32(VM_CONTEXT0_CNTL, 0);
4584 WREG32(VM_CONTEXT1_CNTL, 0);
4585 /* Setup TLB control */
4586 WREG32(MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE_NOT_IN_SYS |
4587 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
4588 /* Setup L2 cache */
4589 WREG32(VM_L2_CNTL,
4590 ENABLE_L2_FRAGMENT_PROCESSING |
4591 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
4592 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
4593 EFFECTIVE_L2_QUEUE_SIZE(7) |
4594 CONTEXT1_IDENTITY_ACCESS_MODE(1));
4595 WREG32(VM_L2_CNTL2, 0);
4596 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
4597 L2_CACHE_BIGK_FRAGMENT_SIZE(6));
4598 radeon_gart_table_vram_unpin(rdev);
4599}
4600
4601/**
4602 * cik_pcie_gart_fini - vm fini callback
4603 *
4604 * @rdev: radeon_device pointer
4605 *
4606 * Tears down the driver GART/VM setup (CIK).
4607 */
4608static void cik_pcie_gart_fini(struct radeon_device *rdev)
4609{
4610 cik_pcie_gart_disable(rdev);
4611 radeon_gart_table_vram_free(rdev);
4612 radeon_gart_fini(rdev);
4613}
4614
4615/* vm parser */
4616/**
4617 * cik_ib_parse - vm ib_parse callback
4618 *
4619 * @rdev: radeon_device pointer
4620 * @ib: indirect buffer pointer
4621 *
4622 * CIK uses hw IB checking so this is a nop (CIK).
4623 */
4624int cik_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
4625{
4626 return 0;
4627}
4628
4629/*
4630 * vm
4631 * VMID 0 is the physical GPU addresses as used by the kernel.
4632 * VMIDs 1-15 are used for userspace clients and are handled
4633 * by the radeon vm/hsa code.
4634 */
4635/**
4636 * cik_vm_init - cik vm init callback
4637 *
4638 * @rdev: radeon_device pointer
4639 *
4640 * Inits cik specific vm parameters (number of VMs, base of vram for
4641 * VMIDs 1-15) (CIK).
4642 * Returns 0 for success.
4643 */
4644int cik_vm_init(struct radeon_device *rdev)
4645{
4646 /* number of VMs */
4647 rdev->vm_manager.nvm = 16;
4648 /* base offset of vram pages */
4649 if (rdev->flags & RADEON_IS_IGP) {
4650 u64 tmp = RREG32(MC_VM_FB_OFFSET);
4651 tmp <<= 22;
4652 rdev->vm_manager.vram_base_offset = tmp;
4653 } else
4654 rdev->vm_manager.vram_base_offset = 0;
4655
4656 return 0;
4657}
4658
4659/**
4660 * cik_vm_fini - cik vm fini callback
4661 *
4662 * @rdev: radeon_device pointer
4663 *
4664 * Tear down any asic specific VM setup (CIK).
4665 */
4666void cik_vm_fini(struct radeon_device *rdev)
4667{
4668}
4669
Alex Deucherf96ab482012-08-31 10:37:47 -04004670/**
Alex Deucher3ec7d112013-06-14 10:42:22 -04004671 * cik_vm_decode_fault - print human readable fault info
4672 *
4673 * @rdev: radeon_device pointer
4674 * @status: VM_CONTEXT1_PROTECTION_FAULT_STATUS register value
4675 * @addr: VM_CONTEXT1_PROTECTION_FAULT_ADDR register value
4676 *
4677 * Print human readable fault information (CIK).
4678 */
4679static void cik_vm_decode_fault(struct radeon_device *rdev,
4680 u32 status, u32 addr, u32 mc_client)
4681{
4682 u32 mc_id = (status & MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
4683 u32 vmid = (status & FAULT_VMID_MASK) >> FAULT_VMID_SHIFT;
4684 u32 protections = (status & PROTECTIONS_MASK) >> PROTECTIONS_SHIFT;
4685 char *block = (char *)&mc_client;
4686
4687 printk("VM fault (0x%02x, vmid %d) at page %u, %s from %s (%d)\n",
4688 protections, vmid, addr,
4689 (status & MEMORY_CLIENT_RW_MASK) ? "write" : "read",
4690 block, mc_id);
4691}
4692
4693/**
Alex Deucherf96ab482012-08-31 10:37:47 -04004694 * cik_vm_flush - cik vm flush using the CP
4695 *
4696 * @rdev: radeon_device pointer
4697 *
4698 * Update the page table base and flush the VM TLB
4699 * using the CP (CIK).
4700 */
4701void cik_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
4702{
4703 struct radeon_ring *ring = &rdev->ring[ridx];
4704
4705 if (vm == NULL)
4706 return;
4707
4708 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
4709 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
4710 WRITE_DATA_DST_SEL(0)));
4711 if (vm->id < 8) {
4712 radeon_ring_write(ring,
4713 (VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2);
4714 } else {
4715 radeon_ring_write(ring,
4716 (VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm->id - 8) << 2)) >> 2);
4717 }
4718 radeon_ring_write(ring, 0);
4719 radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
4720
4721 /* update SH_MEM_* regs */
4722 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
4723 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
4724 WRITE_DATA_DST_SEL(0)));
4725 radeon_ring_write(ring, SRBM_GFX_CNTL >> 2);
4726 radeon_ring_write(ring, 0);
4727 radeon_ring_write(ring, VMID(vm->id));
4728
4729 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 6));
4730 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
4731 WRITE_DATA_DST_SEL(0)));
4732 radeon_ring_write(ring, SH_MEM_BASES >> 2);
4733 radeon_ring_write(ring, 0);
4734
4735 radeon_ring_write(ring, 0); /* SH_MEM_BASES */
4736 radeon_ring_write(ring, 0); /* SH_MEM_CONFIG */
4737 radeon_ring_write(ring, 1); /* SH_MEM_APE1_BASE */
4738 radeon_ring_write(ring, 0); /* SH_MEM_APE1_LIMIT */
4739
4740 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
4741 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
4742 WRITE_DATA_DST_SEL(0)));
4743 radeon_ring_write(ring, SRBM_GFX_CNTL >> 2);
4744 radeon_ring_write(ring, 0);
4745 radeon_ring_write(ring, VMID(0));
4746
4747 /* HDP flush */
4748 /* We should be using the WAIT_REG_MEM packet here like in
4749 * cik_fence_ring_emit(), but it causes the CP to hang in this
4750 * context...
4751 */
4752 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
4753 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
4754 WRITE_DATA_DST_SEL(0)));
4755 radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);
4756 radeon_ring_write(ring, 0);
4757 radeon_ring_write(ring, 0);
4758
4759 /* bits 0-15 are the VM contexts0-15 */
4760 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
4761 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
4762 WRITE_DATA_DST_SEL(0)));
4763 radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
4764 radeon_ring_write(ring, 0);
4765 radeon_ring_write(ring, 1 << vm->id);
4766
Alex Deucherb07fdd32013-04-11 09:36:17 -04004767 /* compute doesn't have PFP */
4768 if (ridx == RADEON_RING_TYPE_GFX_INDEX) {
4769 /* sync PFP to ME, otherwise we might get invalid PFP reads */
4770 radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
4771 radeon_ring_write(ring, 0x0);
4772 }
Alex Deucherf96ab482012-08-31 10:37:47 -04004773}
4774
Alex Deucher605de6b2012-10-22 13:04:03 -04004775/**
Alex Deucherd0e092d2012-08-31 11:00:53 -04004776 * cik_vm_set_page - update the page tables using sDMA
4777 *
4778 * @rdev: radeon_device pointer
4779 * @ib: indirect buffer to fill with commands
4780 * @pe: addr of the page entry
4781 * @addr: dst addr to write into pe
4782 * @count: number of page entries to update
4783 * @incr: increase next addr by incr bytes
4784 * @flags: access flags
4785 *
4786 * Update the page tables using CP or sDMA (CIK).
4787 */
4788void cik_vm_set_page(struct radeon_device *rdev,
4789 struct radeon_ib *ib,
4790 uint64_t pe,
4791 uint64_t addr, unsigned count,
4792 uint32_t incr, uint32_t flags)
4793{
4794 uint32_t r600_flags = cayman_vm_page_flags(rdev, flags);
4795 uint64_t value;
4796 unsigned ndw;
4797
4798 if (rdev->asic->vm.pt_ring_index == RADEON_RING_TYPE_GFX_INDEX) {
4799 /* CP */
4800 while (count) {
4801 ndw = 2 + count * 2;
4802 if (ndw > 0x3FFE)
4803 ndw = 0x3FFE;
4804
4805 ib->ptr[ib->length_dw++] = PACKET3(PACKET3_WRITE_DATA, ndw);
4806 ib->ptr[ib->length_dw++] = (WRITE_DATA_ENGINE_SEL(0) |
4807 WRITE_DATA_DST_SEL(1));
4808 ib->ptr[ib->length_dw++] = pe;
4809 ib->ptr[ib->length_dw++] = upper_32_bits(pe);
4810 for (; ndw > 2; ndw -= 2, --count, pe += 8) {
4811 if (flags & RADEON_VM_PAGE_SYSTEM) {
4812 value = radeon_vm_map_gart(rdev, addr);
4813 value &= 0xFFFFFFFFFFFFF000ULL;
4814 } else if (flags & RADEON_VM_PAGE_VALID) {
4815 value = addr;
4816 } else {
4817 value = 0;
4818 }
4819 addr += incr;
4820 value |= r600_flags;
4821 ib->ptr[ib->length_dw++] = value;
4822 ib->ptr[ib->length_dw++] = upper_32_bits(value);
4823 }
4824 }
4825 } else {
4826 /* DMA */
Christian König2483b4e2013-08-13 11:56:54 +02004827 cik_sdma_vm_set_page(rdev, ib, pe, addr, count, incr, flags);
Alex Deucherd0e092d2012-08-31 11:00:53 -04004828 }
4829}
4830
Alex Deucherf6796ca2012-11-09 10:44:08 -05004831/*
4832 * RLC
4833 * The RLC is a multi-purpose microengine that handles a
4834 * variety of functions, the most important of which is
4835 * the interrupt controller.
4836 */
Alex Deucher866d83d2013-04-15 17:13:29 -04004837static void cik_enable_gui_idle_interrupt(struct radeon_device *rdev,
4838 bool enable)
Alex Deucherf6796ca2012-11-09 10:44:08 -05004839{
Alex Deucher866d83d2013-04-15 17:13:29 -04004840 u32 tmp = RREG32(CP_INT_CNTL_RING0);
Alex Deucherf6796ca2012-11-09 10:44:08 -05004841
Alex Deucher866d83d2013-04-15 17:13:29 -04004842 if (enable)
4843 tmp |= (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
4844 else
4845 tmp &= ~(CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
Alex Deucherf6796ca2012-11-09 10:44:08 -05004846 WREG32(CP_INT_CNTL_RING0, tmp);
Alex Deucher866d83d2013-04-15 17:13:29 -04004847}
Alex Deucherf6796ca2012-11-09 10:44:08 -05004848
Alex Deucher866d83d2013-04-15 17:13:29 -04004849static void cik_enable_lbpw(struct radeon_device *rdev, bool enable)
4850{
4851 u32 tmp;
Alex Deucherf6796ca2012-11-09 10:44:08 -05004852
Alex Deucher866d83d2013-04-15 17:13:29 -04004853 tmp = RREG32(RLC_LB_CNTL);
4854 if (enable)
4855 tmp |= LOAD_BALANCE_ENABLE;
4856 else
4857 tmp &= ~LOAD_BALANCE_ENABLE;
4858 WREG32(RLC_LB_CNTL, tmp);
4859}
Alex Deucherf6796ca2012-11-09 10:44:08 -05004860
Alex Deucher866d83d2013-04-15 17:13:29 -04004861static void cik_wait_for_rlc_serdes(struct radeon_device *rdev)
4862{
4863 u32 i, j, k;
4864 u32 mask;
Alex Deucherf6796ca2012-11-09 10:44:08 -05004865
4866 for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
4867 for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
4868 cik_select_se_sh(rdev, i, j);
4869 for (k = 0; k < rdev->usec_timeout; k++) {
4870 if (RREG32(RLC_SERDES_CU_MASTER_BUSY) == 0)
4871 break;
4872 udelay(1);
4873 }
4874 }
4875 }
4876 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
4877
4878 mask = SE_MASTER_BUSY_MASK | GC_MASTER_BUSY | TC0_MASTER_BUSY | TC1_MASTER_BUSY;
4879 for (k = 0; k < rdev->usec_timeout; k++) {
4880 if ((RREG32(RLC_SERDES_NONCU_MASTER_BUSY) & mask) == 0)
4881 break;
4882 udelay(1);
4883 }
4884}
4885
Alex Deucher22c775c2013-07-23 09:41:05 -04004886static void cik_update_rlc(struct radeon_device *rdev, u32 rlc)
4887{
4888 u32 tmp;
4889
4890 tmp = RREG32(RLC_CNTL);
4891 if (tmp != rlc)
4892 WREG32(RLC_CNTL, rlc);
4893}
4894
4895static u32 cik_halt_rlc(struct radeon_device *rdev)
4896{
4897 u32 data, orig;
4898
4899 orig = data = RREG32(RLC_CNTL);
4900
4901 if (data & RLC_ENABLE) {
4902 u32 i;
4903
4904 data &= ~RLC_ENABLE;
4905 WREG32(RLC_CNTL, data);
4906
4907 for (i = 0; i < rdev->usec_timeout; i++) {
4908 if ((RREG32(RLC_GPM_STAT) & RLC_GPM_BUSY) == 0)
4909 break;
4910 udelay(1);
4911 }
4912
4913 cik_wait_for_rlc_serdes(rdev);
4914 }
4915
4916 return orig;
4917}
4918
Alex Deuchera412fce2013-04-22 20:23:31 -04004919void cik_enter_rlc_safe_mode(struct radeon_device *rdev)
4920{
4921 u32 tmp, i, mask;
4922
4923 tmp = REQ | MESSAGE(MSG_ENTER_RLC_SAFE_MODE);
4924 WREG32(RLC_GPR_REG2, tmp);
4925
4926 mask = GFX_POWER_STATUS | GFX_CLOCK_STATUS;
4927 for (i = 0; i < rdev->usec_timeout; i++) {
4928 if ((RREG32(RLC_GPM_STAT) & mask) == mask)
4929 break;
4930 udelay(1);
4931 }
4932
4933 for (i = 0; i < rdev->usec_timeout; i++) {
4934 if ((RREG32(RLC_GPR_REG2) & REQ) == 0)
4935 break;
4936 udelay(1);
4937 }
4938}
4939
4940void cik_exit_rlc_safe_mode(struct radeon_device *rdev)
4941{
4942 u32 tmp;
4943
4944 tmp = REQ | MESSAGE(MSG_EXIT_RLC_SAFE_MODE);
4945 WREG32(RLC_GPR_REG2, tmp);
4946}
4947
Alex Deucherf6796ca2012-11-09 10:44:08 -05004948/**
Alex Deucher866d83d2013-04-15 17:13:29 -04004949 * cik_rlc_stop - stop the RLC ME
4950 *
4951 * @rdev: radeon_device pointer
4952 *
4953 * Halt the RLC ME (MicroEngine) (CIK).
4954 */
4955static void cik_rlc_stop(struct radeon_device *rdev)
4956{
Alex Deucher22c775c2013-07-23 09:41:05 -04004957 WREG32(RLC_CNTL, 0);
Alex Deucher866d83d2013-04-15 17:13:29 -04004958
4959 cik_enable_gui_idle_interrupt(rdev, false);
4960
Alex Deucher866d83d2013-04-15 17:13:29 -04004961 cik_wait_for_rlc_serdes(rdev);
4962}
4963
4964/**
Alex Deucherf6796ca2012-11-09 10:44:08 -05004965 * cik_rlc_start - start the RLC ME
4966 *
4967 * @rdev: radeon_device pointer
4968 *
4969 * Unhalt the RLC ME (MicroEngine) (CIK).
4970 */
4971static void cik_rlc_start(struct radeon_device *rdev)
4972{
Alex Deucherf6796ca2012-11-09 10:44:08 -05004973 WREG32(RLC_CNTL, RLC_ENABLE);
4974
Alex Deucher866d83d2013-04-15 17:13:29 -04004975 cik_enable_gui_idle_interrupt(rdev, true);
Alex Deucherf6796ca2012-11-09 10:44:08 -05004976
4977 udelay(50);
4978}
4979
4980/**
4981 * cik_rlc_resume - setup the RLC hw
4982 *
4983 * @rdev: radeon_device pointer
4984 *
4985 * Initialize the RLC registers, load the ucode,
4986 * and start the RLC (CIK).
4987 * Returns 0 for success, -EINVAL if the ucode is not available.
4988 */
4989static int cik_rlc_resume(struct radeon_device *rdev)
4990{
Alex Deucher22c775c2013-07-23 09:41:05 -04004991 u32 i, size, tmp;
Alex Deucherf6796ca2012-11-09 10:44:08 -05004992 const __be32 *fw_data;
4993
4994 if (!rdev->rlc_fw)
4995 return -EINVAL;
4996
4997 switch (rdev->family) {
4998 case CHIP_BONAIRE:
4999 default:
5000 size = BONAIRE_RLC_UCODE_SIZE;
5001 break;
5002 case CHIP_KAVERI:
5003 size = KV_RLC_UCODE_SIZE;
5004 break;
5005 case CHIP_KABINI:
5006 size = KB_RLC_UCODE_SIZE;
5007 break;
5008 }
5009
5010 cik_rlc_stop(rdev);
5011
Alex Deucher22c775c2013-07-23 09:41:05 -04005012 /* disable CG */
5013 tmp = RREG32(RLC_CGCG_CGLS_CTRL) & 0xfffffffc;
5014 WREG32(RLC_CGCG_CGLS_CTRL, tmp);
5015
Alex Deucher866d83d2013-04-15 17:13:29 -04005016 si_rlc_reset(rdev);
Alex Deucherf6796ca2012-11-09 10:44:08 -05005017
Alex Deucher22c775c2013-07-23 09:41:05 -04005018 cik_init_pg(rdev);
5019
5020 cik_init_cg(rdev);
5021
Alex Deucherf6796ca2012-11-09 10:44:08 -05005022 WREG32(RLC_LB_CNTR_INIT, 0);
5023 WREG32(RLC_LB_CNTR_MAX, 0x00008000);
5024
5025 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
5026 WREG32(RLC_LB_INIT_CU_MASK, 0xffffffff);
5027 WREG32(RLC_LB_PARAMS, 0x00600408);
5028 WREG32(RLC_LB_CNTL, 0x80000004);
5029
5030 WREG32(RLC_MC_CNTL, 0);
5031 WREG32(RLC_UCODE_CNTL, 0);
5032
5033 fw_data = (const __be32 *)rdev->rlc_fw->data;
5034 WREG32(RLC_GPM_UCODE_ADDR, 0);
5035 for (i = 0; i < size; i++)
5036 WREG32(RLC_GPM_UCODE_DATA, be32_to_cpup(fw_data++));
5037 WREG32(RLC_GPM_UCODE_ADDR, 0);
5038
Alex Deucher866d83d2013-04-15 17:13:29 -04005039 /* XXX - find out what chips support lbpw */
5040 cik_enable_lbpw(rdev, false);
5041
Alex Deucher22c775c2013-07-23 09:41:05 -04005042 if (rdev->family == CHIP_BONAIRE)
5043 WREG32(RLC_DRIVER_DMA_STATUS, 0);
Alex Deucherf6796ca2012-11-09 10:44:08 -05005044
5045 cik_rlc_start(rdev);
5046
5047 return 0;
5048}
Alex Deuchera59781b2012-11-09 10:45:57 -05005049
Alex Deucher22c775c2013-07-23 09:41:05 -04005050static void cik_enable_cgcg(struct radeon_device *rdev, bool enable)
5051{
5052 u32 data, orig, tmp, tmp2;
5053
5054 orig = data = RREG32(RLC_CGCG_CGLS_CTRL);
5055
Alex Deucher473359b2013-08-09 11:18:39 -04005056 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGCG)) {
Alex Deucherddc76ff2013-08-12 17:25:26 -04005057 cik_enable_gui_idle_interrupt(rdev, true);
5058
Alex Deucher22c775c2013-07-23 09:41:05 -04005059 tmp = cik_halt_rlc(rdev);
5060
5061 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
5062 WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
5063 WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
5064 tmp2 = BPM_ADDR_MASK | CGCG_OVERRIDE_0 | CGLS_ENABLE;
5065 WREG32(RLC_SERDES_WR_CTRL, tmp2);
5066
5067 cik_update_rlc(rdev, tmp);
5068
5069 data |= CGCG_EN | CGLS_EN;
5070 } else {
Alex Deucherddc76ff2013-08-12 17:25:26 -04005071 cik_enable_gui_idle_interrupt(rdev, false);
5072
Alex Deucher22c775c2013-07-23 09:41:05 -04005073 RREG32(CB_CGTT_SCLK_CTRL);
5074 RREG32(CB_CGTT_SCLK_CTRL);
5075 RREG32(CB_CGTT_SCLK_CTRL);
5076 RREG32(CB_CGTT_SCLK_CTRL);
5077
5078 data &= ~(CGCG_EN | CGLS_EN);
5079 }
5080
5081 if (orig != data)
5082 WREG32(RLC_CGCG_CGLS_CTRL, data);
5083
5084}
5085
5086static void cik_enable_mgcg(struct radeon_device *rdev, bool enable)
5087{
5088 u32 data, orig, tmp = 0;
5089
Alex Deucher473359b2013-08-09 11:18:39 -04005090 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGCG)) {
5091 if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGLS) {
5092 if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CP_LS) {
5093 orig = data = RREG32(CP_MEM_SLP_CNTL);
5094 data |= CP_MEM_LS_EN;
5095 if (orig != data)
5096 WREG32(CP_MEM_SLP_CNTL, data);
5097 }
5098 }
Alex Deucher22c775c2013-07-23 09:41:05 -04005099
5100 orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
5101 data &= 0xfffffffd;
5102 if (orig != data)
5103 WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
5104
5105 tmp = cik_halt_rlc(rdev);
5106
5107 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
5108 WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
5109 WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
5110 data = BPM_ADDR_MASK | MGCG_OVERRIDE_0;
5111 WREG32(RLC_SERDES_WR_CTRL, data);
5112
5113 cik_update_rlc(rdev, tmp);
5114
Alex Deucher473359b2013-08-09 11:18:39 -04005115 if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGTS) {
5116 orig = data = RREG32(CGTS_SM_CTRL_REG);
5117 data &= ~SM_MODE_MASK;
5118 data |= SM_MODE(0x2);
5119 data |= SM_MODE_ENABLE;
5120 data &= ~CGTS_OVERRIDE;
5121 if ((rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGLS) &&
5122 (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGTS_LS))
5123 data &= ~CGTS_LS_OVERRIDE;
5124 data &= ~ON_MONITOR_ADD_MASK;
5125 data |= ON_MONITOR_ADD_EN;
5126 data |= ON_MONITOR_ADD(0x96);
5127 if (orig != data)
5128 WREG32(CGTS_SM_CTRL_REG, data);
5129 }
Alex Deucher22c775c2013-07-23 09:41:05 -04005130 } else {
5131 orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
5132 data |= 0x00000002;
5133 if (orig != data)
5134 WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
5135
5136 data = RREG32(RLC_MEM_SLP_CNTL);
5137 if (data & RLC_MEM_LS_EN) {
5138 data &= ~RLC_MEM_LS_EN;
5139 WREG32(RLC_MEM_SLP_CNTL, data);
5140 }
5141
5142 data = RREG32(CP_MEM_SLP_CNTL);
5143 if (data & CP_MEM_LS_EN) {
5144 data &= ~CP_MEM_LS_EN;
5145 WREG32(CP_MEM_SLP_CNTL, data);
5146 }
5147
5148 orig = data = RREG32(CGTS_SM_CTRL_REG);
5149 data |= CGTS_OVERRIDE | CGTS_LS_OVERRIDE;
5150 if (orig != data)
5151 WREG32(CGTS_SM_CTRL_REG, data);
5152
5153 tmp = cik_halt_rlc(rdev);
5154
5155 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
5156 WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
5157 WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
5158 data = BPM_ADDR_MASK | MGCG_OVERRIDE_1;
5159 WREG32(RLC_SERDES_WR_CTRL, data);
5160
5161 cik_update_rlc(rdev, tmp);
5162 }
5163}
5164
5165static const u32 mc_cg_registers[] =
5166{
5167 MC_HUB_MISC_HUB_CG,
5168 MC_HUB_MISC_SIP_CG,
5169 MC_HUB_MISC_VM_CG,
5170 MC_XPB_CLK_GAT,
5171 ATC_MISC_CG,
5172 MC_CITF_MISC_WR_CG,
5173 MC_CITF_MISC_RD_CG,
5174 MC_CITF_MISC_VM_CG,
5175 VM_L2_CG,
5176};
5177
5178static void cik_enable_mc_ls(struct radeon_device *rdev,
5179 bool enable)
5180{
5181 int i;
5182 u32 orig, data;
5183
5184 for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
5185 orig = data = RREG32(mc_cg_registers[i]);
Alex Deucher473359b2013-08-09 11:18:39 -04005186 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_LS))
Alex Deucher22c775c2013-07-23 09:41:05 -04005187 data |= MC_LS_ENABLE;
5188 else
5189 data &= ~MC_LS_ENABLE;
5190 if (data != orig)
5191 WREG32(mc_cg_registers[i], data);
5192 }
5193}
5194
5195static void cik_enable_mc_mgcg(struct radeon_device *rdev,
5196 bool enable)
5197{
5198 int i;
5199 u32 orig, data;
5200
5201 for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
5202 orig = data = RREG32(mc_cg_registers[i]);
Alex Deucher473359b2013-08-09 11:18:39 -04005203 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_MGCG))
Alex Deucher22c775c2013-07-23 09:41:05 -04005204 data |= MC_CG_ENABLE;
5205 else
5206 data &= ~MC_CG_ENABLE;
5207 if (data != orig)
5208 WREG32(mc_cg_registers[i], data);
5209 }
5210}
5211
5212static void cik_enable_sdma_mgcg(struct radeon_device *rdev,
5213 bool enable)
5214{
5215 u32 orig, data;
5216
Alex Deucher473359b2013-08-09 11:18:39 -04005217 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_MGCG)) {
Alex Deucher22c775c2013-07-23 09:41:05 -04005218 WREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET, 0x00000100);
5219 WREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET, 0x00000100);
5220 } else {
5221 orig = data = RREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET);
5222 data |= 0xff000000;
5223 if (data != orig)
5224 WREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET, data);
5225
5226 orig = data = RREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET);
5227 data |= 0xff000000;
5228 if (data != orig)
5229 WREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET, data);
5230 }
5231}
5232
5233static void cik_enable_sdma_mgls(struct radeon_device *rdev,
5234 bool enable)
5235{
5236 u32 orig, data;
5237
Alex Deucher473359b2013-08-09 11:18:39 -04005238 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_LS)) {
Alex Deucher22c775c2013-07-23 09:41:05 -04005239 orig = data = RREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET);
5240 data |= 0x100;
5241 if (orig != data)
5242 WREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET, data);
5243
5244 orig = data = RREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET);
5245 data |= 0x100;
5246 if (orig != data)
5247 WREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET, data);
5248 } else {
5249 orig = data = RREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET);
5250 data &= ~0x100;
5251 if (orig != data)
5252 WREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET, data);
5253
5254 orig = data = RREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET);
5255 data &= ~0x100;
5256 if (orig != data)
5257 WREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET, data);
5258 }
5259}
5260
5261static void cik_enable_uvd_mgcg(struct radeon_device *rdev,
5262 bool enable)
5263{
5264 u32 orig, data;
5265
Alex Deucher473359b2013-08-09 11:18:39 -04005266 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_UVD_MGCG)) {
Alex Deucher22c775c2013-07-23 09:41:05 -04005267 data = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
5268 data = 0xfff;
5269 WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, data);
5270
5271 orig = data = RREG32(UVD_CGC_CTRL);
5272 data |= DCM;
5273 if (orig != data)
5274 WREG32(UVD_CGC_CTRL, data);
5275 } else {
5276 data = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
5277 data &= ~0xfff;
5278 WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, data);
5279
5280 orig = data = RREG32(UVD_CGC_CTRL);
5281 data &= ~DCM;
5282 if (orig != data)
5283 WREG32(UVD_CGC_CTRL, data);
5284 }
5285}
5286
Alex Deucher473359b2013-08-09 11:18:39 -04005287static void cik_enable_bif_mgls(struct radeon_device *rdev,
5288 bool enable)
5289{
5290 u32 orig, data;
5291
5292 orig = data = RREG32_PCIE_PORT(PCIE_CNTL2);
5293
5294 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_BIF_LS))
5295 data |= SLV_MEM_LS_EN | MST_MEM_LS_EN |
5296 REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN;
5297 else
5298 data &= ~(SLV_MEM_LS_EN | MST_MEM_LS_EN |
5299 REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN);
5300
5301 if (orig != data)
5302 WREG32_PCIE_PORT(PCIE_CNTL2, data);
5303}
5304
Alex Deucher22c775c2013-07-23 09:41:05 -04005305static void cik_enable_hdp_mgcg(struct radeon_device *rdev,
5306 bool enable)
5307{
5308 u32 orig, data;
5309
5310 orig = data = RREG32(HDP_HOST_PATH_CNTL);
5311
Alex Deucher473359b2013-08-09 11:18:39 -04005312 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_MGCG))
Alex Deucher22c775c2013-07-23 09:41:05 -04005313 data &= ~CLOCK_GATING_DIS;
5314 else
5315 data |= CLOCK_GATING_DIS;
5316
5317 if (orig != data)
5318 WREG32(HDP_HOST_PATH_CNTL, data);
5319}
5320
5321static void cik_enable_hdp_ls(struct radeon_device *rdev,
5322 bool enable)
5323{
5324 u32 orig, data;
5325
5326 orig = data = RREG32(HDP_MEM_POWER_LS);
5327
Alex Deucher473359b2013-08-09 11:18:39 -04005328 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_LS))
Alex Deucher22c775c2013-07-23 09:41:05 -04005329 data |= HDP_LS_ENABLE;
5330 else
5331 data &= ~HDP_LS_ENABLE;
5332
5333 if (orig != data)
5334 WREG32(HDP_MEM_POWER_LS, data);
5335}
5336
5337void cik_update_cg(struct radeon_device *rdev,
5338 u32 block, bool enable)
5339{
5340 if (block & RADEON_CG_BLOCK_GFX) {
5341 /* order matters! */
5342 if (enable) {
5343 cik_enable_mgcg(rdev, true);
5344 cik_enable_cgcg(rdev, true);
5345 } else {
5346 cik_enable_cgcg(rdev, false);
5347 cik_enable_mgcg(rdev, false);
5348 }
5349 }
5350
5351 if (block & RADEON_CG_BLOCK_MC) {
5352 if (!(rdev->flags & RADEON_IS_IGP)) {
5353 cik_enable_mc_mgcg(rdev, enable);
5354 cik_enable_mc_ls(rdev, enable);
5355 }
5356 }
5357
5358 if (block & RADEON_CG_BLOCK_SDMA) {
5359 cik_enable_sdma_mgcg(rdev, enable);
5360 cik_enable_sdma_mgls(rdev, enable);
5361 }
5362
Alex Deucher473359b2013-08-09 11:18:39 -04005363 if (block & RADEON_CG_BLOCK_BIF) {
5364 cik_enable_bif_mgls(rdev, enable);
5365 }
5366
Alex Deucher22c775c2013-07-23 09:41:05 -04005367 if (block & RADEON_CG_BLOCK_UVD) {
5368 if (rdev->has_uvd)
5369 cik_enable_uvd_mgcg(rdev, enable);
5370 }
5371
5372 if (block & RADEON_CG_BLOCK_HDP) {
5373 cik_enable_hdp_mgcg(rdev, enable);
5374 cik_enable_hdp_ls(rdev, enable);
5375 }
5376}
5377
5378static void cik_init_cg(struct radeon_device *rdev)
5379{
5380
Alex Deucherddc76ff2013-08-12 17:25:26 -04005381 cik_update_cg(rdev, RADEON_CG_BLOCK_GFX, true);
Alex Deucher22c775c2013-07-23 09:41:05 -04005382
5383 if (rdev->has_uvd)
5384 si_init_uvd_internal_cg(rdev);
5385
5386 cik_update_cg(rdev, (RADEON_CG_BLOCK_MC |
5387 RADEON_CG_BLOCK_SDMA |
Alex Deucher473359b2013-08-09 11:18:39 -04005388 RADEON_CG_BLOCK_BIF |
Alex Deucher22c775c2013-07-23 09:41:05 -04005389 RADEON_CG_BLOCK_UVD |
5390 RADEON_CG_BLOCK_HDP), true);
5391}
5392
Alex Deucher473359b2013-08-09 11:18:39 -04005393static void cik_fini_cg(struct radeon_device *rdev)
5394{
5395 cik_update_cg(rdev, (RADEON_CG_BLOCK_MC |
5396 RADEON_CG_BLOCK_SDMA |
5397 RADEON_CG_BLOCK_BIF |
5398 RADEON_CG_BLOCK_UVD |
5399 RADEON_CG_BLOCK_HDP), false);
5400
5401 cik_update_cg(rdev, RADEON_CG_BLOCK_GFX, false);
5402}
5403
Alex Deucher22c775c2013-07-23 09:41:05 -04005404static void cik_enable_sck_slowdown_on_pu(struct radeon_device *rdev,
5405 bool enable)
5406{
5407 u32 data, orig;
5408
5409 orig = data = RREG32(RLC_PG_CNTL);
Alex Deucher473359b2013-08-09 11:18:39 -04005410 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_RLC_SMU_HS))
Alex Deucher22c775c2013-07-23 09:41:05 -04005411 data |= SMU_CLK_SLOWDOWN_ON_PU_ENABLE;
5412 else
5413 data &= ~SMU_CLK_SLOWDOWN_ON_PU_ENABLE;
5414 if (orig != data)
5415 WREG32(RLC_PG_CNTL, data);
5416}
5417
5418static void cik_enable_sck_slowdown_on_pd(struct radeon_device *rdev,
5419 bool enable)
5420{
5421 u32 data, orig;
5422
5423 orig = data = RREG32(RLC_PG_CNTL);
Alex Deucher473359b2013-08-09 11:18:39 -04005424 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_RLC_SMU_HS))
Alex Deucher22c775c2013-07-23 09:41:05 -04005425 data |= SMU_CLK_SLOWDOWN_ON_PD_ENABLE;
5426 else
5427 data &= ~SMU_CLK_SLOWDOWN_ON_PD_ENABLE;
5428 if (orig != data)
5429 WREG32(RLC_PG_CNTL, data);
5430}
5431
5432static void cik_enable_cp_pg(struct radeon_device *rdev, bool enable)
5433{
5434 u32 data, orig;
5435
5436 orig = data = RREG32(RLC_PG_CNTL);
Alex Deucher473359b2013-08-09 11:18:39 -04005437 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_CP))
Alex Deucher22c775c2013-07-23 09:41:05 -04005438 data &= ~DISABLE_CP_PG;
5439 else
5440 data |= DISABLE_CP_PG;
5441 if (orig != data)
5442 WREG32(RLC_PG_CNTL, data);
5443}
5444
5445static void cik_enable_gds_pg(struct radeon_device *rdev, bool enable)
5446{
5447 u32 data, orig;
5448
5449 orig = data = RREG32(RLC_PG_CNTL);
Alex Deucher473359b2013-08-09 11:18:39 -04005450 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GDS))
Alex Deucher22c775c2013-07-23 09:41:05 -04005451 data &= ~DISABLE_GDS_PG;
5452 else
5453 data |= DISABLE_GDS_PG;
5454 if (orig != data)
5455 WREG32(RLC_PG_CNTL, data);
5456}
5457
5458#define CP_ME_TABLE_SIZE 96
5459#define CP_ME_TABLE_OFFSET 2048
5460#define CP_MEC_TABLE_OFFSET 4096
5461
5462void cik_init_cp_pg_table(struct radeon_device *rdev)
5463{
5464 const __be32 *fw_data;
5465 volatile u32 *dst_ptr;
5466 int me, i, max_me = 4;
5467 u32 bo_offset = 0;
5468 u32 table_offset;
5469
5470 if (rdev->family == CHIP_KAVERI)
5471 max_me = 5;
5472
5473 if (rdev->rlc.cp_table_ptr == NULL)
5474 return;
5475
5476 /* write the cp table buffer */
5477 dst_ptr = rdev->rlc.cp_table_ptr;
5478 for (me = 0; me < max_me; me++) {
5479 if (me == 0) {
5480 fw_data = (const __be32 *)rdev->ce_fw->data;
5481 table_offset = CP_ME_TABLE_OFFSET;
5482 } else if (me == 1) {
5483 fw_data = (const __be32 *)rdev->pfp_fw->data;
5484 table_offset = CP_ME_TABLE_OFFSET;
5485 } else if (me == 2) {
5486 fw_data = (const __be32 *)rdev->me_fw->data;
5487 table_offset = CP_ME_TABLE_OFFSET;
5488 } else {
5489 fw_data = (const __be32 *)rdev->mec_fw->data;
5490 table_offset = CP_MEC_TABLE_OFFSET;
5491 }
5492
5493 for (i = 0; i < CP_ME_TABLE_SIZE; i ++) {
5494 dst_ptr[bo_offset + i] = be32_to_cpu(fw_data[table_offset + i]);
5495 }
5496 bo_offset += CP_ME_TABLE_SIZE;
5497 }
5498}
5499
5500static void cik_enable_gfx_cgpg(struct radeon_device *rdev,
5501 bool enable)
5502{
5503 u32 data, orig;
5504
Alex Deucher473359b2013-08-09 11:18:39 -04005505 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_CG)) {
Alex Deucher22c775c2013-07-23 09:41:05 -04005506 orig = data = RREG32(RLC_PG_CNTL);
5507 data |= GFX_PG_ENABLE;
5508 if (orig != data)
5509 WREG32(RLC_PG_CNTL, data);
5510
5511 orig = data = RREG32(RLC_AUTO_PG_CTRL);
5512 data |= AUTO_PG_EN;
5513 if (orig != data)
5514 WREG32(RLC_AUTO_PG_CTRL, data);
5515 } else {
5516 orig = data = RREG32(RLC_PG_CNTL);
5517 data &= ~GFX_PG_ENABLE;
5518 if (orig != data)
5519 WREG32(RLC_PG_CNTL, data);
5520
5521 orig = data = RREG32(RLC_AUTO_PG_CTRL);
5522 data &= ~AUTO_PG_EN;
5523 if (orig != data)
5524 WREG32(RLC_AUTO_PG_CTRL, data);
5525
5526 data = RREG32(DB_RENDER_CONTROL);
5527 }
5528}
5529
5530static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh)
5531{
5532 u32 mask = 0, tmp, tmp1;
5533 int i;
5534
5535 cik_select_se_sh(rdev, se, sh);
5536 tmp = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
5537 tmp1 = RREG32(GC_USER_SHADER_ARRAY_CONFIG);
5538 cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
5539
5540 tmp &= 0xffff0000;
5541
5542 tmp |= tmp1;
5543 tmp >>= 16;
5544
5545 for (i = 0; i < rdev->config.cik.max_cu_per_sh; i ++) {
5546 mask <<= 1;
5547 mask |= 1;
5548 }
5549
5550 return (~tmp) & mask;
5551}
5552
5553static void cik_init_ao_cu_mask(struct radeon_device *rdev)
5554{
5555 u32 i, j, k, active_cu_number = 0;
5556 u32 mask, counter, cu_bitmap;
5557 u32 tmp = 0;
5558
5559 for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
5560 for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
5561 mask = 1;
5562 cu_bitmap = 0;
5563 counter = 0;
5564 for (k = 0; k < rdev->config.cik.max_cu_per_sh; k ++) {
5565 if (cik_get_cu_active_bitmap(rdev, i, j) & mask) {
5566 if (counter < 2)
5567 cu_bitmap |= mask;
5568 counter ++;
5569 }
5570 mask <<= 1;
5571 }
5572
5573 active_cu_number += counter;
5574 tmp |= (cu_bitmap << (i * 16 + j * 8));
5575 }
5576 }
5577
5578 WREG32(RLC_PG_AO_CU_MASK, tmp);
5579
5580 tmp = RREG32(RLC_MAX_PG_CU);
5581 tmp &= ~MAX_PU_CU_MASK;
5582 tmp |= MAX_PU_CU(active_cu_number);
5583 WREG32(RLC_MAX_PG_CU, tmp);
5584}
5585
5586static void cik_enable_gfx_static_mgpg(struct radeon_device *rdev,
5587 bool enable)
5588{
5589 u32 data, orig;
5590
5591 orig = data = RREG32(RLC_PG_CNTL);
Alex Deucher473359b2013-08-09 11:18:39 -04005592 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_SMG))
Alex Deucher22c775c2013-07-23 09:41:05 -04005593 data |= STATIC_PER_CU_PG_ENABLE;
5594 else
5595 data &= ~STATIC_PER_CU_PG_ENABLE;
5596 if (orig != data)
5597 WREG32(RLC_PG_CNTL, data);
5598}
5599
5600static void cik_enable_gfx_dynamic_mgpg(struct radeon_device *rdev,
5601 bool enable)
5602{
5603 u32 data, orig;
5604
5605 orig = data = RREG32(RLC_PG_CNTL);
Alex Deucher473359b2013-08-09 11:18:39 -04005606 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_DMG))
Alex Deucher22c775c2013-07-23 09:41:05 -04005607 data |= DYN_PER_CU_PG_ENABLE;
5608 else
5609 data &= ~DYN_PER_CU_PG_ENABLE;
5610 if (orig != data)
5611 WREG32(RLC_PG_CNTL, data);
5612}
5613
5614#define RLC_SAVE_AND_RESTORE_STARTING_OFFSET 0x90
5615#define RLC_CLEAR_STATE_DESCRIPTOR_OFFSET 0x3D
5616
5617static void cik_init_gfx_cgpg(struct radeon_device *rdev)
5618{
5619 u32 data, orig;
5620 u32 i;
5621
5622 if (rdev->rlc.cs_data) {
5623 WREG32(RLC_GPM_SCRATCH_ADDR, RLC_CLEAR_STATE_DESCRIPTOR_OFFSET);
5624 WREG32(RLC_GPM_SCRATCH_DATA, upper_32_bits(rdev->rlc.clear_state_gpu_addr));
5625 WREG32(RLC_GPM_SCRATCH_DATA, rdev->rlc.clear_state_gpu_addr);
5626 WREG32(RLC_GPM_SCRATCH_DATA, rdev->rlc.clear_state_size);
5627 } else {
5628 WREG32(RLC_GPM_SCRATCH_ADDR, RLC_CLEAR_STATE_DESCRIPTOR_OFFSET);
5629 for (i = 0; i < 3; i++)
5630 WREG32(RLC_GPM_SCRATCH_DATA, 0);
5631 }
5632 if (rdev->rlc.reg_list) {
5633 WREG32(RLC_GPM_SCRATCH_ADDR, RLC_SAVE_AND_RESTORE_STARTING_OFFSET);
5634 for (i = 0; i < rdev->rlc.reg_list_size; i++)
5635 WREG32(RLC_GPM_SCRATCH_DATA, rdev->rlc.reg_list[i]);
5636 }
5637
5638 orig = data = RREG32(RLC_PG_CNTL);
5639 data |= GFX_PG_SRC;
5640 if (orig != data)
5641 WREG32(RLC_PG_CNTL, data);
5642
5643 WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
5644 WREG32(RLC_CP_TABLE_RESTORE, rdev->rlc.cp_table_gpu_addr >> 8);
5645
5646 data = RREG32(CP_RB_WPTR_POLL_CNTL);
5647 data &= ~IDLE_POLL_COUNT_MASK;
5648 data |= IDLE_POLL_COUNT(0x60);
5649 WREG32(CP_RB_WPTR_POLL_CNTL, data);
5650
5651 data = 0x10101010;
5652 WREG32(RLC_PG_DELAY, data);
5653
5654 data = RREG32(RLC_PG_DELAY_2);
5655 data &= ~0xff;
5656 data |= 0x3;
5657 WREG32(RLC_PG_DELAY_2, data);
5658
5659 data = RREG32(RLC_AUTO_PG_CTRL);
5660 data &= ~GRBM_REG_SGIT_MASK;
5661 data |= GRBM_REG_SGIT(0x700);
5662 WREG32(RLC_AUTO_PG_CTRL, data);
5663
5664}
5665
5666static void cik_update_gfx_pg(struct radeon_device *rdev, bool enable)
5667{
Alex Deucher473359b2013-08-09 11:18:39 -04005668 cik_enable_gfx_cgpg(rdev, enable);
5669 cik_enable_gfx_static_mgpg(rdev, enable);
5670 cik_enable_gfx_dynamic_mgpg(rdev, enable);
Alex Deucher22c775c2013-07-23 09:41:05 -04005671}
5672
Alex Deucher473359b2013-08-09 11:18:39 -04005673static void cik_init_pg(struct radeon_device *rdev)
Alex Deucher22c775c2013-07-23 09:41:05 -04005674{
Alex Deucher473359b2013-08-09 11:18:39 -04005675 if (rdev->pg_flags) {
Alex Deucher22c775c2013-07-23 09:41:05 -04005676 cik_enable_sck_slowdown_on_pu(rdev, true);
5677 cik_enable_sck_slowdown_on_pd(rdev, true);
Alex Deucher473359b2013-08-09 11:18:39 -04005678 if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_CG) {
5679 cik_init_gfx_cgpg(rdev);
5680 cik_enable_cp_pg(rdev, true);
5681 cik_enable_gds_pg(rdev, true);
5682 }
Alex Deucher22c775c2013-07-23 09:41:05 -04005683 cik_init_ao_cu_mask(rdev);
5684 cik_update_gfx_pg(rdev, true);
5685 }
5686}
5687
Alex Deucher473359b2013-08-09 11:18:39 -04005688static void cik_fini_pg(struct radeon_device *rdev)
5689{
5690 if (rdev->pg_flags) {
5691 cik_update_gfx_pg(rdev, false);
5692 if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_CG) {
5693 cik_enable_cp_pg(rdev, false);
5694 cik_enable_gds_pg(rdev, false);
5695 }
5696 }
5697}
5698
Alex Deuchera59781b2012-11-09 10:45:57 -05005699/*
5700 * Interrupts
5701 * Starting with r6xx, interrupts are handled via a ring buffer.
5702 * Ring buffers are areas of GPU accessible memory that the GPU
5703 * writes interrupt vectors into and the host reads vectors out of.
5704 * There is a rptr (read pointer) that determines where the
5705 * host is currently reading, and a wptr (write pointer)
5706 * which determines where the GPU has written. When the
5707 * pointers are equal, the ring is idle. When the GPU
5708 * writes vectors to the ring buffer, it increments the
5709 * wptr. When there is an interrupt, the host then starts
5710 * fetching commands and processing them until the pointers are
5711 * equal again at which point it updates the rptr.
5712 */
5713
5714/**
5715 * cik_enable_interrupts - Enable the interrupt ring buffer
5716 *
5717 * @rdev: radeon_device pointer
5718 *
5719 * Enable the interrupt ring buffer (CIK).
5720 */
5721static void cik_enable_interrupts(struct radeon_device *rdev)
5722{
5723 u32 ih_cntl = RREG32(IH_CNTL);
5724 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
5725
5726 ih_cntl |= ENABLE_INTR;
5727 ih_rb_cntl |= IH_RB_ENABLE;
5728 WREG32(IH_CNTL, ih_cntl);
5729 WREG32(IH_RB_CNTL, ih_rb_cntl);
5730 rdev->ih.enabled = true;
5731}
5732
5733/**
5734 * cik_disable_interrupts - Disable the interrupt ring buffer
5735 *
5736 * @rdev: radeon_device pointer
5737 *
5738 * Disable the interrupt ring buffer (CIK).
5739 */
5740static void cik_disable_interrupts(struct radeon_device *rdev)
5741{
5742 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
5743 u32 ih_cntl = RREG32(IH_CNTL);
5744
5745 ih_rb_cntl &= ~IH_RB_ENABLE;
5746 ih_cntl &= ~ENABLE_INTR;
5747 WREG32(IH_RB_CNTL, ih_rb_cntl);
5748 WREG32(IH_CNTL, ih_cntl);
5749 /* set rptr, wptr to 0 */
5750 WREG32(IH_RB_RPTR, 0);
5751 WREG32(IH_RB_WPTR, 0);
5752 rdev->ih.enabled = false;
5753 rdev->ih.rptr = 0;
5754}
5755
5756/**
5757 * cik_disable_interrupt_state - Disable all interrupt sources
5758 *
5759 * @rdev: radeon_device pointer
5760 *
5761 * Clear all interrupt enable bits used by the driver (CIK).
5762 */
5763static void cik_disable_interrupt_state(struct radeon_device *rdev)
5764{
5765 u32 tmp;
5766
5767 /* gfx ring */
5768 WREG32(CP_INT_CNTL_RING0, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
Alex Deucher21a93e12013-04-09 12:47:11 -04005769 /* sdma */
5770 tmp = RREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
5771 WREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET, tmp);
5772 tmp = RREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
5773 WREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET, tmp);
Alex Deuchera59781b2012-11-09 10:45:57 -05005774 /* compute queues */
5775 WREG32(CP_ME1_PIPE0_INT_CNTL, 0);
5776 WREG32(CP_ME1_PIPE1_INT_CNTL, 0);
5777 WREG32(CP_ME1_PIPE2_INT_CNTL, 0);
5778 WREG32(CP_ME1_PIPE3_INT_CNTL, 0);
5779 WREG32(CP_ME2_PIPE0_INT_CNTL, 0);
5780 WREG32(CP_ME2_PIPE1_INT_CNTL, 0);
5781 WREG32(CP_ME2_PIPE2_INT_CNTL, 0);
5782 WREG32(CP_ME2_PIPE3_INT_CNTL, 0);
5783 /* grbm */
5784 WREG32(GRBM_INT_CNTL, 0);
5785 /* vline/vblank, etc. */
5786 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
5787 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
5788 if (rdev->num_crtc >= 4) {
5789 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
5790 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
5791 }
5792 if (rdev->num_crtc >= 6) {
5793 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
5794 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
5795 }
5796
5797 /* dac hotplug */
5798 WREG32(DAC_AUTODETECT_INT_CONTROL, 0);
5799
5800 /* digital hotplug */
5801 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5802 WREG32(DC_HPD1_INT_CONTROL, tmp);
5803 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5804 WREG32(DC_HPD2_INT_CONTROL, tmp);
5805 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5806 WREG32(DC_HPD3_INT_CONTROL, tmp);
5807 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5808 WREG32(DC_HPD4_INT_CONTROL, tmp);
5809 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5810 WREG32(DC_HPD5_INT_CONTROL, tmp);
5811 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5812 WREG32(DC_HPD6_INT_CONTROL, tmp);
5813
5814}
5815
5816/**
5817 * cik_irq_init - init and enable the interrupt ring
5818 *
5819 * @rdev: radeon_device pointer
5820 *
5821 * Allocate a ring buffer for the interrupt controller,
5822 * enable the RLC, disable interrupts, enable the IH
5823 * ring buffer and enable it (CIK).
5824 * Called at device load and reume.
5825 * Returns 0 for success, errors for failure.
5826 */
5827static int cik_irq_init(struct radeon_device *rdev)
5828{
5829 int ret = 0;
5830 int rb_bufsz;
5831 u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
5832
5833 /* allocate ring */
5834 ret = r600_ih_ring_alloc(rdev);
5835 if (ret)
5836 return ret;
5837
5838 /* disable irqs */
5839 cik_disable_interrupts(rdev);
5840
5841 /* init rlc */
5842 ret = cik_rlc_resume(rdev);
5843 if (ret) {
5844 r600_ih_ring_fini(rdev);
5845 return ret;
5846 }
5847
5848 /* setup interrupt control */
5849 /* XXX this should actually be a bus address, not an MC address. same on older asics */
5850 WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
5851 interrupt_cntl = RREG32(INTERRUPT_CNTL);
5852 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
5853 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
5854 */
5855 interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
5856 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
5857 interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
5858 WREG32(INTERRUPT_CNTL, interrupt_cntl);
5859
5860 WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
5861 rb_bufsz = drm_order(rdev->ih.ring_size / 4);
5862
5863 ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
5864 IH_WPTR_OVERFLOW_CLEAR |
5865 (rb_bufsz << 1));
5866
5867 if (rdev->wb.enabled)
5868 ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
5869
5870 /* set the writeback address whether it's enabled or not */
5871 WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
5872 WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
5873
5874 WREG32(IH_RB_CNTL, ih_rb_cntl);
5875
5876 /* set rptr, wptr to 0 */
5877 WREG32(IH_RB_RPTR, 0);
5878 WREG32(IH_RB_WPTR, 0);
5879
5880 /* Default settings for IH_CNTL (disabled at first) */
5881 ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10) | MC_VMID(0);
5882 /* RPTR_REARM only works if msi's are enabled */
5883 if (rdev->msi_enabled)
5884 ih_cntl |= RPTR_REARM;
5885 WREG32(IH_CNTL, ih_cntl);
5886
5887 /* force the active interrupt state to all disabled */
5888 cik_disable_interrupt_state(rdev);
5889
5890 pci_set_master(rdev->pdev);
5891
5892 /* enable irqs */
5893 cik_enable_interrupts(rdev);
5894
5895 return ret;
5896}
5897
5898/**
5899 * cik_irq_set - enable/disable interrupt sources
5900 *
5901 * @rdev: radeon_device pointer
5902 *
5903 * Enable interrupt sources on the GPU (vblanks, hpd,
5904 * etc.) (CIK).
5905 * Returns 0 for success, errors for failure.
5906 */
5907int cik_irq_set(struct radeon_device *rdev)
5908{
5909 u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE |
5910 PRIV_INSTR_INT_ENABLE | PRIV_REG_INT_ENABLE;
Alex Deucher2b0781a2013-04-09 14:26:16 -04005911 u32 cp_m1p0, cp_m1p1, cp_m1p2, cp_m1p3;
5912 u32 cp_m2p0, cp_m2p1, cp_m2p2, cp_m2p3;
Alex Deuchera59781b2012-11-09 10:45:57 -05005913 u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
5914 u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;
5915 u32 grbm_int_cntl = 0;
Alex Deucher21a93e12013-04-09 12:47:11 -04005916 u32 dma_cntl, dma_cntl1;
Alex Deucher41a524a2013-08-14 01:01:40 -04005917 u32 thermal_int;
Alex Deuchera59781b2012-11-09 10:45:57 -05005918
5919 if (!rdev->irq.installed) {
5920 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
5921 return -EINVAL;
5922 }
5923 /* don't enable anything if the ih is disabled */
5924 if (!rdev->ih.enabled) {
5925 cik_disable_interrupts(rdev);
5926 /* force the active interrupt state to all disabled */
5927 cik_disable_interrupt_state(rdev);
5928 return 0;
5929 }
5930
5931 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
5932 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
5933 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
5934 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
5935 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
5936 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
5937
Alex Deucher21a93e12013-04-09 12:47:11 -04005938 dma_cntl = RREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
5939 dma_cntl1 = RREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
5940
Alex Deucher2b0781a2013-04-09 14:26:16 -04005941 cp_m1p0 = RREG32(CP_ME1_PIPE0_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
5942 cp_m1p1 = RREG32(CP_ME1_PIPE1_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
5943 cp_m1p2 = RREG32(CP_ME1_PIPE2_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
5944 cp_m1p3 = RREG32(CP_ME1_PIPE3_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
5945 cp_m2p0 = RREG32(CP_ME2_PIPE0_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
5946 cp_m2p1 = RREG32(CP_ME2_PIPE1_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
5947 cp_m2p2 = RREG32(CP_ME2_PIPE2_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
5948 cp_m2p3 = RREG32(CP_ME2_PIPE3_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
5949
Alex Deuchercc8dbbb2013-08-14 01:03:41 -04005950 if (rdev->flags & RADEON_IS_IGP)
5951 thermal_int = RREG32_SMC(CG_THERMAL_INT_CTRL) &
5952 ~(THERM_INTH_MASK | THERM_INTL_MASK);
5953 else
5954 thermal_int = RREG32_SMC(CG_THERMAL_INT) &
5955 ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
Alex Deucher41a524a2013-08-14 01:01:40 -04005956
Alex Deuchera59781b2012-11-09 10:45:57 -05005957 /* enable CP interrupts on all rings */
5958 if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
5959 DRM_DEBUG("cik_irq_set: sw int gfx\n");
5960 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
5961 }
Alex Deucher2b0781a2013-04-09 14:26:16 -04005962 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
5963 struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
5964 DRM_DEBUG("si_irq_set: sw int cp1\n");
5965 if (ring->me == 1) {
5966 switch (ring->pipe) {
5967 case 0:
5968 cp_m1p0 |= TIME_STAMP_INT_ENABLE;
5969 break;
5970 case 1:
5971 cp_m1p1 |= TIME_STAMP_INT_ENABLE;
5972 break;
5973 case 2:
5974 cp_m1p2 |= TIME_STAMP_INT_ENABLE;
5975 break;
5976 case 3:
5977 cp_m1p2 |= TIME_STAMP_INT_ENABLE;
5978 break;
5979 default:
5980 DRM_DEBUG("si_irq_set: sw int cp1 invalid pipe %d\n", ring->pipe);
5981 break;
5982 }
5983 } else if (ring->me == 2) {
5984 switch (ring->pipe) {
5985 case 0:
5986 cp_m2p0 |= TIME_STAMP_INT_ENABLE;
5987 break;
5988 case 1:
5989 cp_m2p1 |= TIME_STAMP_INT_ENABLE;
5990 break;
5991 case 2:
5992 cp_m2p2 |= TIME_STAMP_INT_ENABLE;
5993 break;
5994 case 3:
5995 cp_m2p2 |= TIME_STAMP_INT_ENABLE;
5996 break;
5997 default:
5998 DRM_DEBUG("si_irq_set: sw int cp1 invalid pipe %d\n", ring->pipe);
5999 break;
6000 }
6001 } else {
6002 DRM_DEBUG("si_irq_set: sw int cp1 invalid me %d\n", ring->me);
6003 }
6004 }
6005 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
6006 struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
6007 DRM_DEBUG("si_irq_set: sw int cp2\n");
6008 if (ring->me == 1) {
6009 switch (ring->pipe) {
6010 case 0:
6011 cp_m1p0 |= TIME_STAMP_INT_ENABLE;
6012 break;
6013 case 1:
6014 cp_m1p1 |= TIME_STAMP_INT_ENABLE;
6015 break;
6016 case 2:
6017 cp_m1p2 |= TIME_STAMP_INT_ENABLE;
6018 break;
6019 case 3:
6020 cp_m1p2 |= TIME_STAMP_INT_ENABLE;
6021 break;
6022 default:
6023 DRM_DEBUG("si_irq_set: sw int cp2 invalid pipe %d\n", ring->pipe);
6024 break;
6025 }
6026 } else if (ring->me == 2) {
6027 switch (ring->pipe) {
6028 case 0:
6029 cp_m2p0 |= TIME_STAMP_INT_ENABLE;
6030 break;
6031 case 1:
6032 cp_m2p1 |= TIME_STAMP_INT_ENABLE;
6033 break;
6034 case 2:
6035 cp_m2p2 |= TIME_STAMP_INT_ENABLE;
6036 break;
6037 case 3:
6038 cp_m2p2 |= TIME_STAMP_INT_ENABLE;
6039 break;
6040 default:
6041 DRM_DEBUG("si_irq_set: sw int cp2 invalid pipe %d\n", ring->pipe);
6042 break;
6043 }
6044 } else {
6045 DRM_DEBUG("si_irq_set: sw int cp2 invalid me %d\n", ring->me);
6046 }
6047 }
Alex Deuchera59781b2012-11-09 10:45:57 -05006048
Alex Deucher21a93e12013-04-09 12:47:11 -04006049 if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
6050 DRM_DEBUG("cik_irq_set: sw int dma\n");
6051 dma_cntl |= TRAP_ENABLE;
6052 }
6053
6054 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
6055 DRM_DEBUG("cik_irq_set: sw int dma1\n");
6056 dma_cntl1 |= TRAP_ENABLE;
6057 }
6058
Alex Deuchera59781b2012-11-09 10:45:57 -05006059 if (rdev->irq.crtc_vblank_int[0] ||
6060 atomic_read(&rdev->irq.pflip[0])) {
6061 DRM_DEBUG("cik_irq_set: vblank 0\n");
6062 crtc1 |= VBLANK_INTERRUPT_MASK;
6063 }
6064 if (rdev->irq.crtc_vblank_int[1] ||
6065 atomic_read(&rdev->irq.pflip[1])) {
6066 DRM_DEBUG("cik_irq_set: vblank 1\n");
6067 crtc2 |= VBLANK_INTERRUPT_MASK;
6068 }
6069 if (rdev->irq.crtc_vblank_int[2] ||
6070 atomic_read(&rdev->irq.pflip[2])) {
6071 DRM_DEBUG("cik_irq_set: vblank 2\n");
6072 crtc3 |= VBLANK_INTERRUPT_MASK;
6073 }
6074 if (rdev->irq.crtc_vblank_int[3] ||
6075 atomic_read(&rdev->irq.pflip[3])) {
6076 DRM_DEBUG("cik_irq_set: vblank 3\n");
6077 crtc4 |= VBLANK_INTERRUPT_MASK;
6078 }
6079 if (rdev->irq.crtc_vblank_int[4] ||
6080 atomic_read(&rdev->irq.pflip[4])) {
6081 DRM_DEBUG("cik_irq_set: vblank 4\n");
6082 crtc5 |= VBLANK_INTERRUPT_MASK;
6083 }
6084 if (rdev->irq.crtc_vblank_int[5] ||
6085 atomic_read(&rdev->irq.pflip[5])) {
6086 DRM_DEBUG("cik_irq_set: vblank 5\n");
6087 crtc6 |= VBLANK_INTERRUPT_MASK;
6088 }
6089 if (rdev->irq.hpd[0]) {
6090 DRM_DEBUG("cik_irq_set: hpd 1\n");
6091 hpd1 |= DC_HPDx_INT_EN;
6092 }
6093 if (rdev->irq.hpd[1]) {
6094 DRM_DEBUG("cik_irq_set: hpd 2\n");
6095 hpd2 |= DC_HPDx_INT_EN;
6096 }
6097 if (rdev->irq.hpd[2]) {
6098 DRM_DEBUG("cik_irq_set: hpd 3\n");
6099 hpd3 |= DC_HPDx_INT_EN;
6100 }
6101 if (rdev->irq.hpd[3]) {
6102 DRM_DEBUG("cik_irq_set: hpd 4\n");
6103 hpd4 |= DC_HPDx_INT_EN;
6104 }
6105 if (rdev->irq.hpd[4]) {
6106 DRM_DEBUG("cik_irq_set: hpd 5\n");
6107 hpd5 |= DC_HPDx_INT_EN;
6108 }
6109 if (rdev->irq.hpd[5]) {
6110 DRM_DEBUG("cik_irq_set: hpd 6\n");
6111 hpd6 |= DC_HPDx_INT_EN;
6112 }
6113
Alex Deucher41a524a2013-08-14 01:01:40 -04006114 if (rdev->irq.dpm_thermal) {
6115 DRM_DEBUG("dpm thermal\n");
Alex Deuchercc8dbbb2013-08-14 01:03:41 -04006116 if (rdev->flags & RADEON_IS_IGP)
6117 thermal_int |= THERM_INTH_MASK | THERM_INTL_MASK;
6118 else
6119 thermal_int |= THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW;
Alex Deucher41a524a2013-08-14 01:01:40 -04006120 }
6121
Alex Deuchera59781b2012-11-09 10:45:57 -05006122 WREG32(CP_INT_CNTL_RING0, cp_int_cntl);
6123
Alex Deucher21a93e12013-04-09 12:47:11 -04006124 WREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET, dma_cntl);
6125 WREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET, dma_cntl1);
6126
Alex Deucher2b0781a2013-04-09 14:26:16 -04006127 WREG32(CP_ME1_PIPE0_INT_CNTL, cp_m1p0);
6128 WREG32(CP_ME1_PIPE1_INT_CNTL, cp_m1p1);
6129 WREG32(CP_ME1_PIPE2_INT_CNTL, cp_m1p2);
6130 WREG32(CP_ME1_PIPE3_INT_CNTL, cp_m1p3);
6131 WREG32(CP_ME2_PIPE0_INT_CNTL, cp_m2p0);
6132 WREG32(CP_ME2_PIPE1_INT_CNTL, cp_m2p1);
6133 WREG32(CP_ME2_PIPE2_INT_CNTL, cp_m2p2);
6134 WREG32(CP_ME2_PIPE3_INT_CNTL, cp_m2p3);
6135
Alex Deuchera59781b2012-11-09 10:45:57 -05006136 WREG32(GRBM_INT_CNTL, grbm_int_cntl);
6137
6138 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
6139 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
6140 if (rdev->num_crtc >= 4) {
6141 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
6142 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
6143 }
6144 if (rdev->num_crtc >= 6) {
6145 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
6146 WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
6147 }
6148
6149 WREG32(DC_HPD1_INT_CONTROL, hpd1);
6150 WREG32(DC_HPD2_INT_CONTROL, hpd2);
6151 WREG32(DC_HPD3_INT_CONTROL, hpd3);
6152 WREG32(DC_HPD4_INT_CONTROL, hpd4);
6153 WREG32(DC_HPD5_INT_CONTROL, hpd5);
6154 WREG32(DC_HPD6_INT_CONTROL, hpd6);
6155
Alex Deuchercc8dbbb2013-08-14 01:03:41 -04006156 if (rdev->flags & RADEON_IS_IGP)
6157 WREG32_SMC(CG_THERMAL_INT_CTRL, thermal_int);
6158 else
6159 WREG32_SMC(CG_THERMAL_INT, thermal_int);
Alex Deucher41a524a2013-08-14 01:01:40 -04006160
Alex Deuchera59781b2012-11-09 10:45:57 -05006161 return 0;
6162}
6163
6164/**
6165 * cik_irq_ack - ack interrupt sources
6166 *
6167 * @rdev: radeon_device pointer
6168 *
6169 * Ack interrupt sources on the GPU (vblanks, hpd,
6170 * etc.) (CIK). Certain interrupts sources are sw
6171 * generated and do not require an explicit ack.
6172 */
6173static inline void cik_irq_ack(struct radeon_device *rdev)
6174{
6175 u32 tmp;
6176
6177 rdev->irq.stat_regs.cik.disp_int = RREG32(DISP_INTERRUPT_STATUS);
6178 rdev->irq.stat_regs.cik.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
6179 rdev->irq.stat_regs.cik.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
6180 rdev->irq.stat_regs.cik.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
6181 rdev->irq.stat_regs.cik.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
6182 rdev->irq.stat_regs.cik.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
6183 rdev->irq.stat_regs.cik.disp_int_cont6 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE6);
6184
6185 if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VBLANK_INTERRUPT)
6186 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
6187 if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VLINE_INTERRUPT)
6188 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
6189 if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
6190 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
6191 if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VLINE_INTERRUPT)
6192 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
6193
6194 if (rdev->num_crtc >= 4) {
6195 if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
6196 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
6197 if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
6198 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
6199 if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
6200 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
6201 if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
6202 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
6203 }
6204
6205 if (rdev->num_crtc >= 6) {
6206 if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
6207 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
6208 if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
6209 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
6210 if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
6211 WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
6212 if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
6213 WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
6214 }
6215
6216 if (rdev->irq.stat_regs.cik.disp_int & DC_HPD1_INTERRUPT) {
6217 tmp = RREG32(DC_HPD1_INT_CONTROL);
6218 tmp |= DC_HPDx_INT_ACK;
6219 WREG32(DC_HPD1_INT_CONTROL, tmp);
6220 }
6221 if (rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_INTERRUPT) {
6222 tmp = RREG32(DC_HPD2_INT_CONTROL);
6223 tmp |= DC_HPDx_INT_ACK;
6224 WREG32(DC_HPD2_INT_CONTROL, tmp);
6225 }
6226 if (rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_INTERRUPT) {
6227 tmp = RREG32(DC_HPD3_INT_CONTROL);
6228 tmp |= DC_HPDx_INT_ACK;
6229 WREG32(DC_HPD3_INT_CONTROL, tmp);
6230 }
6231 if (rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_INTERRUPT) {
6232 tmp = RREG32(DC_HPD4_INT_CONTROL);
6233 tmp |= DC_HPDx_INT_ACK;
6234 WREG32(DC_HPD4_INT_CONTROL, tmp);
6235 }
6236 if (rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_INTERRUPT) {
6237 tmp = RREG32(DC_HPD5_INT_CONTROL);
6238 tmp |= DC_HPDx_INT_ACK;
6239 WREG32(DC_HPD5_INT_CONTROL, tmp);
6240 }
6241 if (rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_INTERRUPT) {
6242 tmp = RREG32(DC_HPD5_INT_CONTROL);
6243 tmp |= DC_HPDx_INT_ACK;
6244 WREG32(DC_HPD6_INT_CONTROL, tmp);
6245 }
6246}
6247
6248/**
6249 * cik_irq_disable - disable interrupts
6250 *
6251 * @rdev: radeon_device pointer
6252 *
6253 * Disable interrupts on the hw (CIK).
6254 */
6255static void cik_irq_disable(struct radeon_device *rdev)
6256{
6257 cik_disable_interrupts(rdev);
6258 /* Wait and acknowledge irq */
6259 mdelay(1);
6260 cik_irq_ack(rdev);
6261 cik_disable_interrupt_state(rdev);
6262}
6263
6264/**
6265 * cik_irq_disable - disable interrupts for suspend
6266 *
6267 * @rdev: radeon_device pointer
6268 *
6269 * Disable interrupts and stop the RLC (CIK).
6270 * Used for suspend.
6271 */
6272static void cik_irq_suspend(struct radeon_device *rdev)
6273{
6274 cik_irq_disable(rdev);
6275 cik_rlc_stop(rdev);
6276}
6277
6278/**
6279 * cik_irq_fini - tear down interrupt support
6280 *
6281 * @rdev: radeon_device pointer
6282 *
6283 * Disable interrupts on the hw and free the IH ring
6284 * buffer (CIK).
6285 * Used for driver unload.
6286 */
6287static void cik_irq_fini(struct radeon_device *rdev)
6288{
6289 cik_irq_suspend(rdev);
6290 r600_ih_ring_fini(rdev);
6291}
6292
6293/**
6294 * cik_get_ih_wptr - get the IH ring buffer wptr
6295 *
6296 * @rdev: radeon_device pointer
6297 *
6298 * Get the IH ring buffer wptr from either the register
6299 * or the writeback memory buffer (CIK). Also check for
6300 * ring buffer overflow and deal with it.
6301 * Used by cik_irq_process().
6302 * Returns the value of the wptr.
6303 */
6304static inline u32 cik_get_ih_wptr(struct radeon_device *rdev)
6305{
6306 u32 wptr, tmp;
6307
6308 if (rdev->wb.enabled)
6309 wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
6310 else
6311 wptr = RREG32(IH_RB_WPTR);
6312
6313 if (wptr & RB_OVERFLOW) {
6314 /* When a ring buffer overflow happen start parsing interrupt
6315 * from the last not overwritten vector (wptr + 16). Hopefully
6316 * this should allow us to catchup.
6317 */
6318 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
6319 wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
6320 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
6321 tmp = RREG32(IH_RB_CNTL);
6322 tmp |= IH_WPTR_OVERFLOW_CLEAR;
6323 WREG32(IH_RB_CNTL, tmp);
6324 }
6325 return (wptr & rdev->ih.ptr_mask);
6326}
6327
6328/* CIK IV Ring
6329 * Each IV ring entry is 128 bits:
6330 * [7:0] - interrupt source id
6331 * [31:8] - reserved
6332 * [59:32] - interrupt source data
6333 * [63:60] - reserved
Alex Deucher21a93e12013-04-09 12:47:11 -04006334 * [71:64] - RINGID
6335 * CP:
6336 * ME_ID [1:0], PIPE_ID[1:0], QUEUE_ID[2:0]
Alex Deuchera59781b2012-11-09 10:45:57 -05006337 * QUEUE_ID - for compute, which of the 8 queues owned by the dispatcher
6338 * - for gfx, hw shader state (0=PS...5=LS, 6=CS)
6339 * ME_ID - 0 = gfx, 1 = first 4 CS pipes, 2 = second 4 CS pipes
6340 * PIPE_ID - ME0 0=3D
6341 * - ME1&2 compute dispatcher (4 pipes each)
Alex Deucher21a93e12013-04-09 12:47:11 -04006342 * SDMA:
6343 * INSTANCE_ID [1:0], QUEUE_ID[1:0]
6344 * INSTANCE_ID - 0 = sdma0, 1 = sdma1
6345 * QUEUE_ID - 0 = gfx, 1 = rlc0, 2 = rlc1
Alex Deuchera59781b2012-11-09 10:45:57 -05006346 * [79:72] - VMID
6347 * [95:80] - PASID
6348 * [127:96] - reserved
6349 */
6350/**
6351 * cik_irq_process - interrupt handler
6352 *
6353 * @rdev: radeon_device pointer
6354 *
6355 * Interrupt hander (CIK). Walk the IH ring,
6356 * ack interrupts and schedule work to handle
6357 * interrupt events.
6358 * Returns irq process return code.
6359 */
6360int cik_irq_process(struct radeon_device *rdev)
6361{
Alex Deucher2b0781a2013-04-09 14:26:16 -04006362 struct radeon_ring *cp1_ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
6363 struct radeon_ring *cp2_ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
Alex Deuchera59781b2012-11-09 10:45:57 -05006364 u32 wptr;
6365 u32 rptr;
6366 u32 src_id, src_data, ring_id;
6367 u8 me_id, pipe_id, queue_id;
6368 u32 ring_index;
6369 bool queue_hotplug = false;
6370 bool queue_reset = false;
Alex Deucher3ec7d112013-06-14 10:42:22 -04006371 u32 addr, status, mc_client;
Alex Deucher41a524a2013-08-14 01:01:40 -04006372 bool queue_thermal = false;
Alex Deuchera59781b2012-11-09 10:45:57 -05006373
6374 if (!rdev->ih.enabled || rdev->shutdown)
6375 return IRQ_NONE;
6376
6377 wptr = cik_get_ih_wptr(rdev);
6378
6379restart_ih:
6380 /* is somebody else already processing irqs? */
6381 if (atomic_xchg(&rdev->ih.lock, 1))
6382 return IRQ_NONE;
6383
6384 rptr = rdev->ih.rptr;
6385 DRM_DEBUG("cik_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
6386
6387 /* Order reading of wptr vs. reading of IH ring data */
6388 rmb();
6389
6390 /* display interrupts */
6391 cik_irq_ack(rdev);
6392
6393 while (rptr != wptr) {
6394 /* wptr/rptr are in bytes! */
6395 ring_index = rptr / 4;
6396 src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
6397 src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
6398 ring_id = le32_to_cpu(rdev->ih.ring[ring_index + 2]) & 0xff;
Alex Deuchera59781b2012-11-09 10:45:57 -05006399
6400 switch (src_id) {
6401 case 1: /* D1 vblank/vline */
6402 switch (src_data) {
6403 case 0: /* D1 vblank */
6404 if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VBLANK_INTERRUPT) {
6405 if (rdev->irq.crtc_vblank_int[0]) {
6406 drm_handle_vblank(rdev->ddev, 0);
6407 rdev->pm.vblank_sync = true;
6408 wake_up(&rdev->irq.vblank_queue);
6409 }
6410 if (atomic_read(&rdev->irq.pflip[0]))
6411 radeon_crtc_handle_flip(rdev, 0);
6412 rdev->irq.stat_regs.cik.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
6413 DRM_DEBUG("IH: D1 vblank\n");
6414 }
6415 break;
6416 case 1: /* D1 vline */
6417 if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VLINE_INTERRUPT) {
6418 rdev->irq.stat_regs.cik.disp_int &= ~LB_D1_VLINE_INTERRUPT;
6419 DRM_DEBUG("IH: D1 vline\n");
6420 }
6421 break;
6422 default:
6423 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6424 break;
6425 }
6426 break;
6427 case 2: /* D2 vblank/vline */
6428 switch (src_data) {
6429 case 0: /* D2 vblank */
6430 if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
6431 if (rdev->irq.crtc_vblank_int[1]) {
6432 drm_handle_vblank(rdev->ddev, 1);
6433 rdev->pm.vblank_sync = true;
6434 wake_up(&rdev->irq.vblank_queue);
6435 }
6436 if (atomic_read(&rdev->irq.pflip[1]))
6437 radeon_crtc_handle_flip(rdev, 1);
6438 rdev->irq.stat_regs.cik.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
6439 DRM_DEBUG("IH: D2 vblank\n");
6440 }
6441 break;
6442 case 1: /* D2 vline */
6443 if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VLINE_INTERRUPT) {
6444 rdev->irq.stat_regs.cik.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
6445 DRM_DEBUG("IH: D2 vline\n");
6446 }
6447 break;
6448 default:
6449 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6450 break;
6451 }
6452 break;
6453 case 3: /* D3 vblank/vline */
6454 switch (src_data) {
6455 case 0: /* D3 vblank */
6456 if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
6457 if (rdev->irq.crtc_vblank_int[2]) {
6458 drm_handle_vblank(rdev->ddev, 2);
6459 rdev->pm.vblank_sync = true;
6460 wake_up(&rdev->irq.vblank_queue);
6461 }
6462 if (atomic_read(&rdev->irq.pflip[2]))
6463 radeon_crtc_handle_flip(rdev, 2);
6464 rdev->irq.stat_regs.cik.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
6465 DRM_DEBUG("IH: D3 vblank\n");
6466 }
6467 break;
6468 case 1: /* D3 vline */
6469 if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) {
6470 rdev->irq.stat_regs.cik.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
6471 DRM_DEBUG("IH: D3 vline\n");
6472 }
6473 break;
6474 default:
6475 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6476 break;
6477 }
6478 break;
6479 case 4: /* D4 vblank/vline */
6480 switch (src_data) {
6481 case 0: /* D4 vblank */
6482 if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
6483 if (rdev->irq.crtc_vblank_int[3]) {
6484 drm_handle_vblank(rdev->ddev, 3);
6485 rdev->pm.vblank_sync = true;
6486 wake_up(&rdev->irq.vblank_queue);
6487 }
6488 if (atomic_read(&rdev->irq.pflip[3]))
6489 radeon_crtc_handle_flip(rdev, 3);
6490 rdev->irq.stat_regs.cik.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
6491 DRM_DEBUG("IH: D4 vblank\n");
6492 }
6493 break;
6494 case 1: /* D4 vline */
6495 if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) {
6496 rdev->irq.stat_regs.cik.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
6497 DRM_DEBUG("IH: D4 vline\n");
6498 }
6499 break;
6500 default:
6501 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6502 break;
6503 }
6504 break;
6505 case 5: /* D5 vblank/vline */
6506 switch (src_data) {
6507 case 0: /* D5 vblank */
6508 if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
6509 if (rdev->irq.crtc_vblank_int[4]) {
6510 drm_handle_vblank(rdev->ddev, 4);
6511 rdev->pm.vblank_sync = true;
6512 wake_up(&rdev->irq.vblank_queue);
6513 }
6514 if (atomic_read(&rdev->irq.pflip[4]))
6515 radeon_crtc_handle_flip(rdev, 4);
6516 rdev->irq.stat_regs.cik.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
6517 DRM_DEBUG("IH: D5 vblank\n");
6518 }
6519 break;
6520 case 1: /* D5 vline */
6521 if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) {
6522 rdev->irq.stat_regs.cik.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
6523 DRM_DEBUG("IH: D5 vline\n");
6524 }
6525 break;
6526 default:
6527 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6528 break;
6529 }
6530 break;
6531 case 6: /* D6 vblank/vline */
6532 switch (src_data) {
6533 case 0: /* D6 vblank */
6534 if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
6535 if (rdev->irq.crtc_vblank_int[5]) {
6536 drm_handle_vblank(rdev->ddev, 5);
6537 rdev->pm.vblank_sync = true;
6538 wake_up(&rdev->irq.vblank_queue);
6539 }
6540 if (atomic_read(&rdev->irq.pflip[5]))
6541 radeon_crtc_handle_flip(rdev, 5);
6542 rdev->irq.stat_regs.cik.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
6543 DRM_DEBUG("IH: D6 vblank\n");
6544 }
6545 break;
6546 case 1: /* D6 vline */
6547 if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) {
6548 rdev->irq.stat_regs.cik.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
6549 DRM_DEBUG("IH: D6 vline\n");
6550 }
6551 break;
6552 default:
6553 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6554 break;
6555 }
6556 break;
6557 case 42: /* HPD hotplug */
6558 switch (src_data) {
6559 case 0:
6560 if (rdev->irq.stat_regs.cik.disp_int & DC_HPD1_INTERRUPT) {
6561 rdev->irq.stat_regs.cik.disp_int &= ~DC_HPD1_INTERRUPT;
6562 queue_hotplug = true;
6563 DRM_DEBUG("IH: HPD1\n");
6564 }
6565 break;
6566 case 1:
6567 if (rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_INTERRUPT) {
6568 rdev->irq.stat_regs.cik.disp_int_cont &= ~DC_HPD2_INTERRUPT;
6569 queue_hotplug = true;
6570 DRM_DEBUG("IH: HPD2\n");
6571 }
6572 break;
6573 case 2:
6574 if (rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_INTERRUPT) {
6575 rdev->irq.stat_regs.cik.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
6576 queue_hotplug = true;
6577 DRM_DEBUG("IH: HPD3\n");
6578 }
6579 break;
6580 case 3:
6581 if (rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_INTERRUPT) {
6582 rdev->irq.stat_regs.cik.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
6583 queue_hotplug = true;
6584 DRM_DEBUG("IH: HPD4\n");
6585 }
6586 break;
6587 case 4:
6588 if (rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_INTERRUPT) {
6589 rdev->irq.stat_regs.cik.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
6590 queue_hotplug = true;
6591 DRM_DEBUG("IH: HPD5\n");
6592 }
6593 break;
6594 case 5:
6595 if (rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_INTERRUPT) {
6596 rdev->irq.stat_regs.cik.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
6597 queue_hotplug = true;
6598 DRM_DEBUG("IH: HPD6\n");
6599 }
6600 break;
6601 default:
6602 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6603 break;
6604 }
6605 break;
Alex Deucher9d97c992012-09-06 14:24:48 -04006606 case 146:
6607 case 147:
Alex Deucher3ec7d112013-06-14 10:42:22 -04006608 addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
6609 status = RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS);
6610 mc_client = RREG32(VM_CONTEXT1_PROTECTION_FAULT_MCCLIENT);
Alex Deucher9d97c992012-09-06 14:24:48 -04006611 dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
6612 dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
Alex Deucher3ec7d112013-06-14 10:42:22 -04006613 addr);
Alex Deucher9d97c992012-09-06 14:24:48 -04006614 dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
Alex Deucher3ec7d112013-06-14 10:42:22 -04006615 status);
6616 cik_vm_decode_fault(rdev, status, addr, mc_client);
Alex Deucher9d97c992012-09-06 14:24:48 -04006617 /* reset addr and status */
6618 WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
6619 break;
Alex Deuchera59781b2012-11-09 10:45:57 -05006620 case 176: /* GFX RB CP_INT */
6621 case 177: /* GFX IB CP_INT */
6622 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
6623 break;
6624 case 181: /* CP EOP event */
6625 DRM_DEBUG("IH: CP EOP\n");
Alex Deucher21a93e12013-04-09 12:47:11 -04006626 /* XXX check the bitfield order! */
6627 me_id = (ring_id & 0x60) >> 5;
6628 pipe_id = (ring_id & 0x18) >> 3;
6629 queue_id = (ring_id & 0x7) >> 0;
Alex Deuchera59781b2012-11-09 10:45:57 -05006630 switch (me_id) {
6631 case 0:
6632 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
6633 break;
6634 case 1:
Alex Deuchera59781b2012-11-09 10:45:57 -05006635 case 2:
Alex Deucher2b0781a2013-04-09 14:26:16 -04006636 if ((cp1_ring->me == me_id) & (cp1_ring->pipe == pipe_id))
6637 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
6638 if ((cp2_ring->me == me_id) & (cp2_ring->pipe == pipe_id))
6639 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
Alex Deuchera59781b2012-11-09 10:45:57 -05006640 break;
6641 }
6642 break;
6643 case 184: /* CP Privileged reg access */
6644 DRM_ERROR("Illegal register access in command stream\n");
6645 /* XXX check the bitfield order! */
6646 me_id = (ring_id & 0x60) >> 5;
6647 pipe_id = (ring_id & 0x18) >> 3;
6648 queue_id = (ring_id & 0x7) >> 0;
6649 switch (me_id) {
6650 case 0:
6651 /* This results in a full GPU reset, but all we need to do is soft
6652 * reset the CP for gfx
6653 */
6654 queue_reset = true;
6655 break;
6656 case 1:
6657 /* XXX compute */
Alex Deucher2b0781a2013-04-09 14:26:16 -04006658 queue_reset = true;
Alex Deuchera59781b2012-11-09 10:45:57 -05006659 break;
6660 case 2:
6661 /* XXX compute */
Alex Deucher2b0781a2013-04-09 14:26:16 -04006662 queue_reset = true;
Alex Deuchera59781b2012-11-09 10:45:57 -05006663 break;
6664 }
6665 break;
6666 case 185: /* CP Privileged inst */
6667 DRM_ERROR("Illegal instruction in command stream\n");
Alex Deucher21a93e12013-04-09 12:47:11 -04006668 /* XXX check the bitfield order! */
6669 me_id = (ring_id & 0x60) >> 5;
6670 pipe_id = (ring_id & 0x18) >> 3;
6671 queue_id = (ring_id & 0x7) >> 0;
Alex Deuchera59781b2012-11-09 10:45:57 -05006672 switch (me_id) {
6673 case 0:
6674 /* This results in a full GPU reset, but all we need to do is soft
6675 * reset the CP for gfx
6676 */
6677 queue_reset = true;
6678 break;
6679 case 1:
6680 /* XXX compute */
Alex Deucher2b0781a2013-04-09 14:26:16 -04006681 queue_reset = true;
Alex Deuchera59781b2012-11-09 10:45:57 -05006682 break;
6683 case 2:
6684 /* XXX compute */
Alex Deucher2b0781a2013-04-09 14:26:16 -04006685 queue_reset = true;
Alex Deuchera59781b2012-11-09 10:45:57 -05006686 break;
6687 }
6688 break;
Alex Deucher21a93e12013-04-09 12:47:11 -04006689 case 224: /* SDMA trap event */
6690 /* XXX check the bitfield order! */
6691 me_id = (ring_id & 0x3) >> 0;
6692 queue_id = (ring_id & 0xc) >> 2;
6693 DRM_DEBUG("IH: SDMA trap\n");
6694 switch (me_id) {
6695 case 0:
6696 switch (queue_id) {
6697 case 0:
6698 radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
6699 break;
6700 case 1:
6701 /* XXX compute */
6702 break;
6703 case 2:
6704 /* XXX compute */
6705 break;
6706 }
6707 break;
6708 case 1:
6709 switch (queue_id) {
6710 case 0:
6711 radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
6712 break;
6713 case 1:
6714 /* XXX compute */
6715 break;
6716 case 2:
6717 /* XXX compute */
6718 break;
6719 }
6720 break;
6721 }
6722 break;
Alex Deucher41a524a2013-08-14 01:01:40 -04006723 case 230: /* thermal low to high */
6724 DRM_DEBUG("IH: thermal low to high\n");
6725 rdev->pm.dpm.thermal.high_to_low = false;
6726 queue_thermal = true;
6727 break;
6728 case 231: /* thermal high to low */
6729 DRM_DEBUG("IH: thermal high to low\n");
6730 rdev->pm.dpm.thermal.high_to_low = true;
6731 queue_thermal = true;
6732 break;
6733 case 233: /* GUI IDLE */
6734 DRM_DEBUG("IH: GUI idle\n");
6735 break;
Alex Deucher21a93e12013-04-09 12:47:11 -04006736 case 241: /* SDMA Privileged inst */
6737 case 247: /* SDMA Privileged inst */
6738 DRM_ERROR("Illegal instruction in SDMA command stream\n");
6739 /* XXX check the bitfield order! */
6740 me_id = (ring_id & 0x3) >> 0;
6741 queue_id = (ring_id & 0xc) >> 2;
6742 switch (me_id) {
6743 case 0:
6744 switch (queue_id) {
6745 case 0:
6746 queue_reset = true;
6747 break;
6748 case 1:
6749 /* XXX compute */
6750 queue_reset = true;
6751 break;
6752 case 2:
6753 /* XXX compute */
6754 queue_reset = true;
6755 break;
6756 }
6757 break;
6758 case 1:
6759 switch (queue_id) {
6760 case 0:
6761 queue_reset = true;
6762 break;
6763 case 1:
6764 /* XXX compute */
6765 queue_reset = true;
6766 break;
6767 case 2:
6768 /* XXX compute */
6769 queue_reset = true;
6770 break;
6771 }
6772 break;
6773 }
6774 break;
Alex Deuchera59781b2012-11-09 10:45:57 -05006775 default:
6776 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6777 break;
6778 }
6779
6780 /* wptr/rptr are in bytes! */
6781 rptr += 16;
6782 rptr &= rdev->ih.ptr_mask;
6783 }
6784 if (queue_hotplug)
6785 schedule_work(&rdev->hotplug_work);
6786 if (queue_reset)
6787 schedule_work(&rdev->reset_work);
Alex Deucher41a524a2013-08-14 01:01:40 -04006788 if (queue_thermal)
6789 schedule_work(&rdev->pm.dpm.thermal.work);
Alex Deuchera59781b2012-11-09 10:45:57 -05006790 rdev->ih.rptr = rptr;
6791 WREG32(IH_RB_RPTR, rdev->ih.rptr);
6792 atomic_set(&rdev->ih.lock, 0);
6793
6794 /* make sure wptr hasn't changed while processing */
6795 wptr = cik_get_ih_wptr(rdev);
6796 if (wptr != rptr)
6797 goto restart_ih;
6798
6799 return IRQ_HANDLED;
6800}
Alex Deucher7bf94a22012-08-17 11:48:29 -04006801
6802/*
6803 * startup/shutdown callbacks
6804 */
6805/**
6806 * cik_startup - program the asic to a functional state
6807 *
6808 * @rdev: radeon_device pointer
6809 *
6810 * Programs the asic to a functional state (CIK).
6811 * Called by cik_init() and cik_resume().
6812 * Returns 0 for success, error for failure.
6813 */
6814static int cik_startup(struct radeon_device *rdev)
6815{
6816 struct radeon_ring *ring;
6817 int r;
6818
Alex Deucher8a7cd272013-08-06 11:29:39 -04006819 /* enable pcie gen2/3 link */
6820 cik_pcie_gen3_enable(rdev);
Alex Deucher7235711a42013-04-04 13:58:09 -04006821 /* enable aspm */
6822 cik_program_aspm(rdev);
Alex Deucher8a7cd272013-08-06 11:29:39 -04006823
Alex Deucher6fab3feb2013-08-04 12:13:17 -04006824 cik_mc_program(rdev);
6825
Alex Deucher7bf94a22012-08-17 11:48:29 -04006826 if (rdev->flags & RADEON_IS_IGP) {
6827 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
6828 !rdev->mec_fw || !rdev->sdma_fw || !rdev->rlc_fw) {
6829 r = cik_init_microcode(rdev);
6830 if (r) {
6831 DRM_ERROR("Failed to load firmware!\n");
6832 return r;
6833 }
6834 }
6835 } else {
6836 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
6837 !rdev->mec_fw || !rdev->sdma_fw || !rdev->rlc_fw ||
6838 !rdev->mc_fw) {
6839 r = cik_init_microcode(rdev);
6840 if (r) {
6841 DRM_ERROR("Failed to load firmware!\n");
6842 return r;
6843 }
6844 }
6845
6846 r = ci_mc_load_microcode(rdev);
6847 if (r) {
6848 DRM_ERROR("Failed to load MC firmware!\n");
6849 return r;
6850 }
6851 }
6852
6853 r = r600_vram_scratch_init(rdev);
6854 if (r)
6855 return r;
6856
Alex Deucher7bf94a22012-08-17 11:48:29 -04006857 r = cik_pcie_gart_enable(rdev);
6858 if (r)
6859 return r;
6860 cik_gpu_init(rdev);
6861
6862 /* allocate rlc buffers */
Alex Deucher22c775c2013-07-23 09:41:05 -04006863 if (rdev->flags & RADEON_IS_IGP) {
6864 if (rdev->family == CHIP_KAVERI) {
6865 rdev->rlc.reg_list = spectre_rlc_save_restore_register_list;
6866 rdev->rlc.reg_list_size =
6867 (u32)ARRAY_SIZE(spectre_rlc_save_restore_register_list);
6868 } else {
6869 rdev->rlc.reg_list = kalindi_rlc_save_restore_register_list;
6870 rdev->rlc.reg_list_size =
6871 (u32)ARRAY_SIZE(kalindi_rlc_save_restore_register_list);
6872 }
6873 }
6874 rdev->rlc.cs_data = ci_cs_data;
6875 rdev->rlc.cp_table_size = CP_ME_TABLE_SIZE * 5 * 4;
Alex Deucher1fd11772013-04-17 17:53:50 -04006876 r = sumo_rlc_init(rdev);
Alex Deucher7bf94a22012-08-17 11:48:29 -04006877 if (r) {
6878 DRM_ERROR("Failed to init rlc BOs!\n");
6879 return r;
6880 }
6881
6882 /* allocate wb buffer */
6883 r = radeon_wb_init(rdev);
6884 if (r)
6885 return r;
6886
Alex Deucher963e81f2013-06-26 17:37:11 -04006887 /* allocate mec buffers */
6888 r = cik_mec_init(rdev);
6889 if (r) {
6890 DRM_ERROR("Failed to init MEC BOs!\n");
6891 return r;
6892 }
6893
Alex Deucher7bf94a22012-08-17 11:48:29 -04006894 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
6895 if (r) {
6896 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
6897 return r;
6898 }
6899
Alex Deucher963e81f2013-06-26 17:37:11 -04006900 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
6901 if (r) {
6902 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
6903 return r;
6904 }
6905
6906 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
6907 if (r) {
6908 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
6909 return r;
6910 }
6911
Alex Deucher7bf94a22012-08-17 11:48:29 -04006912 r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
6913 if (r) {
6914 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
6915 return r;
6916 }
6917
6918 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
6919 if (r) {
6920 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
6921 return r;
6922 }
6923
Christian Könige409b122013-08-13 11:56:53 +02006924 r = uvd_v4_2_resume(rdev);
Christian König87167bb2013-04-09 13:39:21 -04006925 if (!r) {
6926 r = radeon_fence_driver_start_ring(rdev,
6927 R600_RING_TYPE_UVD_INDEX);
6928 if (r)
6929 dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
6930 }
6931 if (r)
6932 rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
6933
Alex Deucher7bf94a22012-08-17 11:48:29 -04006934 /* Enable IRQ */
6935 if (!rdev->irq.installed) {
6936 r = radeon_irq_kms_init(rdev);
6937 if (r)
6938 return r;
6939 }
6940
6941 r = cik_irq_init(rdev);
6942 if (r) {
6943 DRM_ERROR("radeon: IH init failed (%d).\n", r);
6944 radeon_irq_kms_fini(rdev);
6945 return r;
6946 }
6947 cik_irq_set(rdev);
6948
6949 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
6950 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
6951 CP_RB0_RPTR, CP_RB0_WPTR,
Christian König2e1e6da2013-08-13 11:56:52 +02006952 RADEON_CP_PACKET2);
Alex Deucher7bf94a22012-08-17 11:48:29 -04006953 if (r)
6954 return r;
6955
Alex Deucher963e81f2013-06-26 17:37:11 -04006956 /* set up the compute queues */
Alex Deucher2615b532013-06-03 11:21:58 -04006957 /* type-2 packets are deprecated on MEC, use type-3 instead */
Alex Deucher963e81f2013-06-26 17:37:11 -04006958 ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
6959 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP1_RPTR_OFFSET,
6960 CP_HQD_PQ_RPTR, CP_HQD_PQ_WPTR,
Christian König2e1e6da2013-08-13 11:56:52 +02006961 PACKET3(PACKET3_NOP, 0x3FFF));
Alex Deucher963e81f2013-06-26 17:37:11 -04006962 if (r)
6963 return r;
6964 ring->me = 1; /* first MEC */
6965 ring->pipe = 0; /* first pipe */
6966 ring->queue = 0; /* first queue */
6967 ring->wptr_offs = CIK_WB_CP1_WPTR_OFFSET;
6968
Alex Deucher2615b532013-06-03 11:21:58 -04006969 /* type-2 packets are deprecated on MEC, use type-3 instead */
Alex Deucher963e81f2013-06-26 17:37:11 -04006970 ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
6971 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP2_RPTR_OFFSET,
6972 CP_HQD_PQ_RPTR, CP_HQD_PQ_WPTR,
Christian König2e1e6da2013-08-13 11:56:52 +02006973 PACKET3(PACKET3_NOP, 0x3FFF));
Alex Deucher963e81f2013-06-26 17:37:11 -04006974 if (r)
6975 return r;
6976 /* dGPU only have 1 MEC */
6977 ring->me = 1; /* first MEC */
6978 ring->pipe = 0; /* first pipe */
6979 ring->queue = 1; /* second queue */
6980 ring->wptr_offs = CIK_WB_CP2_WPTR_OFFSET;
6981
Alex Deucher7bf94a22012-08-17 11:48:29 -04006982 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
6983 r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
6984 SDMA0_GFX_RB_RPTR + SDMA0_REGISTER_OFFSET,
6985 SDMA0_GFX_RB_WPTR + SDMA0_REGISTER_OFFSET,
Christian König2e1e6da2013-08-13 11:56:52 +02006986 SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0));
Alex Deucher7bf94a22012-08-17 11:48:29 -04006987 if (r)
6988 return r;
6989
6990 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
6991 r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
6992 SDMA0_GFX_RB_RPTR + SDMA1_REGISTER_OFFSET,
6993 SDMA0_GFX_RB_WPTR + SDMA1_REGISTER_OFFSET,
Christian König2e1e6da2013-08-13 11:56:52 +02006994 SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0));
Alex Deucher7bf94a22012-08-17 11:48:29 -04006995 if (r)
6996 return r;
6997
6998 r = cik_cp_resume(rdev);
6999 if (r)
7000 return r;
7001
7002 r = cik_sdma_resume(rdev);
7003 if (r)
7004 return r;
7005
Christian König87167bb2013-04-09 13:39:21 -04007006 ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
7007 if (ring->ring_size) {
Christian König02c9f7f2013-08-13 11:56:51 +02007008 r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
Christian König87167bb2013-04-09 13:39:21 -04007009 UVD_RBC_RB_RPTR, UVD_RBC_RB_WPTR,
Christian König2e1e6da2013-08-13 11:56:52 +02007010 RADEON_CP_PACKET2);
Christian König87167bb2013-04-09 13:39:21 -04007011 if (!r)
Christian Könige409b122013-08-13 11:56:53 +02007012 r = uvd_v1_0_init(rdev);
Christian König87167bb2013-04-09 13:39:21 -04007013 if (r)
7014 DRM_ERROR("radeon: failed initializing UVD (%d).\n", r);
7015 }
7016
Alex Deucher7bf94a22012-08-17 11:48:29 -04007017 r = radeon_ib_pool_init(rdev);
7018 if (r) {
7019 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
7020 return r;
7021 }
7022
7023 r = radeon_vm_manager_init(rdev);
7024 if (r) {
7025 dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
7026 return r;
7027 }
7028
Alex Deucherb5306022013-07-31 16:51:33 -04007029 r = dce6_audio_init(rdev);
7030 if (r)
7031 return r;
7032
Alex Deucher7bf94a22012-08-17 11:48:29 -04007033 return 0;
7034}
7035
7036/**
7037 * cik_resume - resume the asic to a functional state
7038 *
7039 * @rdev: radeon_device pointer
7040 *
7041 * Programs the asic to a functional state (CIK).
7042 * Called at resume.
7043 * Returns 0 for success, error for failure.
7044 */
7045int cik_resume(struct radeon_device *rdev)
7046{
7047 int r;
7048
7049 /* post card */
7050 atom_asic_init(rdev->mode_info.atom_context);
7051
Alex Deucher0aafd312013-04-09 14:43:30 -04007052 /* init golden registers */
7053 cik_init_golden_registers(rdev);
7054
Alex Deucher7bf94a22012-08-17 11:48:29 -04007055 rdev->accel_working = true;
7056 r = cik_startup(rdev);
7057 if (r) {
7058 DRM_ERROR("cik startup failed on resume\n");
7059 rdev->accel_working = false;
7060 return r;
7061 }
7062
7063 return r;
7064
7065}
7066
7067/**
7068 * cik_suspend - suspend the asic
7069 *
7070 * @rdev: radeon_device pointer
7071 *
7072 * Bring the chip into a state suitable for suspend (CIK).
7073 * Called at suspend.
7074 * Returns 0 for success.
7075 */
7076int cik_suspend(struct radeon_device *rdev)
7077{
Alex Deucherb5306022013-07-31 16:51:33 -04007078 dce6_audio_fini(rdev);
Alex Deucher7bf94a22012-08-17 11:48:29 -04007079 radeon_vm_manager_fini(rdev);
7080 cik_cp_enable(rdev, false);
7081 cik_sdma_enable(rdev, false);
Christian Könige409b122013-08-13 11:56:53 +02007082 uvd_v1_0_fini(rdev);
Christian König87167bb2013-04-09 13:39:21 -04007083 radeon_uvd_suspend(rdev);
Alex Deucher473359b2013-08-09 11:18:39 -04007084 cik_fini_pg(rdev);
7085 cik_fini_cg(rdev);
Alex Deucher7bf94a22012-08-17 11:48:29 -04007086 cik_irq_suspend(rdev);
7087 radeon_wb_disable(rdev);
7088 cik_pcie_gart_disable(rdev);
7089 return 0;
7090}
7091
7092/* Plan is to move initialization in that function and use
7093 * helper function so that radeon_device_init pretty much
7094 * do nothing more than calling asic specific function. This
7095 * should also allow to remove a bunch of callback function
7096 * like vram_info.
7097 */
7098/**
7099 * cik_init - asic specific driver and hw init
7100 *
7101 * @rdev: radeon_device pointer
7102 *
7103 * Setup asic specific driver variables and program the hw
7104 * to a functional state (CIK).
7105 * Called at driver startup.
7106 * Returns 0 for success, errors for failure.
7107 */
7108int cik_init(struct radeon_device *rdev)
7109{
7110 struct radeon_ring *ring;
7111 int r;
7112
7113 /* Read BIOS */
7114 if (!radeon_get_bios(rdev)) {
7115 if (ASIC_IS_AVIVO(rdev))
7116 return -EINVAL;
7117 }
7118 /* Must be an ATOMBIOS */
7119 if (!rdev->is_atom_bios) {
7120 dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
7121 return -EINVAL;
7122 }
7123 r = radeon_atombios_init(rdev);
7124 if (r)
7125 return r;
7126
7127 /* Post card if necessary */
7128 if (!radeon_card_posted(rdev)) {
7129 if (!rdev->bios) {
7130 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
7131 return -EINVAL;
7132 }
7133 DRM_INFO("GPU not posted. posting now...\n");
7134 atom_asic_init(rdev->mode_info.atom_context);
7135 }
Alex Deucher0aafd312013-04-09 14:43:30 -04007136 /* init golden registers */
7137 cik_init_golden_registers(rdev);
Alex Deucher7bf94a22012-08-17 11:48:29 -04007138 /* Initialize scratch registers */
7139 cik_scratch_init(rdev);
7140 /* Initialize surface registers */
7141 radeon_surface_init(rdev);
7142 /* Initialize clocks */
7143 radeon_get_clock_info(rdev->ddev);
7144
7145 /* Fence driver */
7146 r = radeon_fence_driver_init(rdev);
7147 if (r)
7148 return r;
7149
7150 /* initialize memory controller */
7151 r = cik_mc_init(rdev);
7152 if (r)
7153 return r;
7154 /* Memory manager */
7155 r = radeon_bo_init(rdev);
7156 if (r)
7157 return r;
7158
7159 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
7160 ring->ring_obj = NULL;
7161 r600_ring_init(rdev, ring, 1024 * 1024);
7162
Alex Deucher963e81f2013-06-26 17:37:11 -04007163 ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
7164 ring->ring_obj = NULL;
7165 r600_ring_init(rdev, ring, 1024 * 1024);
7166 r = radeon_doorbell_get(rdev, &ring->doorbell_page_num);
7167 if (r)
7168 return r;
7169
7170 ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
7171 ring->ring_obj = NULL;
7172 r600_ring_init(rdev, ring, 1024 * 1024);
7173 r = radeon_doorbell_get(rdev, &ring->doorbell_page_num);
7174 if (r)
7175 return r;
7176
Alex Deucher7bf94a22012-08-17 11:48:29 -04007177 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
7178 ring->ring_obj = NULL;
7179 r600_ring_init(rdev, ring, 256 * 1024);
7180
7181 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
7182 ring->ring_obj = NULL;
7183 r600_ring_init(rdev, ring, 256 * 1024);
7184
Christian König87167bb2013-04-09 13:39:21 -04007185 r = radeon_uvd_init(rdev);
7186 if (!r) {
7187 ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
7188 ring->ring_obj = NULL;
7189 r600_ring_init(rdev, ring, 4096);
7190 }
7191
Alex Deucher7bf94a22012-08-17 11:48:29 -04007192 rdev->ih.ring_obj = NULL;
7193 r600_ih_ring_init(rdev, 64 * 1024);
7194
7195 r = r600_pcie_gart_init(rdev);
7196 if (r)
7197 return r;
7198
7199 rdev->accel_working = true;
7200 r = cik_startup(rdev);
7201 if (r) {
7202 dev_err(rdev->dev, "disabling GPU acceleration\n");
7203 cik_cp_fini(rdev);
7204 cik_sdma_fini(rdev);
7205 cik_irq_fini(rdev);
Alex Deucher1fd11772013-04-17 17:53:50 -04007206 sumo_rlc_fini(rdev);
Alex Deucher963e81f2013-06-26 17:37:11 -04007207 cik_mec_fini(rdev);
Alex Deucher7bf94a22012-08-17 11:48:29 -04007208 radeon_wb_fini(rdev);
7209 radeon_ib_pool_fini(rdev);
7210 radeon_vm_manager_fini(rdev);
7211 radeon_irq_kms_fini(rdev);
7212 cik_pcie_gart_fini(rdev);
7213 rdev->accel_working = false;
7214 }
7215
7216 /* Don't start up if the MC ucode is missing.
7217 * The default clocks and voltages before the MC ucode
7218 * is loaded are not suffient for advanced operations.
7219 */
7220 if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
7221 DRM_ERROR("radeon: MC ucode required for NI+.\n");
7222 return -EINVAL;
7223 }
7224
7225 return 0;
7226}
7227
7228/**
7229 * cik_fini - asic specific driver and hw fini
7230 *
7231 * @rdev: radeon_device pointer
7232 *
7233 * Tear down the asic specific driver variables and program the hw
7234 * to an idle state (CIK).
7235 * Called at driver unload.
7236 */
7237void cik_fini(struct radeon_device *rdev)
7238{
7239 cik_cp_fini(rdev);
7240 cik_sdma_fini(rdev);
Alex Deucher473359b2013-08-09 11:18:39 -04007241 cik_fini_pg(rdev);
7242 cik_fini_cg(rdev);
Alex Deucher7bf94a22012-08-17 11:48:29 -04007243 cik_irq_fini(rdev);
Alex Deucher1fd11772013-04-17 17:53:50 -04007244 sumo_rlc_fini(rdev);
Alex Deucher963e81f2013-06-26 17:37:11 -04007245 cik_mec_fini(rdev);
Alex Deucher7bf94a22012-08-17 11:48:29 -04007246 radeon_wb_fini(rdev);
7247 radeon_vm_manager_fini(rdev);
7248 radeon_ib_pool_fini(rdev);
7249 radeon_irq_kms_fini(rdev);
Christian Könige409b122013-08-13 11:56:53 +02007250 uvd_v1_0_fini(rdev);
Christian König87167bb2013-04-09 13:39:21 -04007251 radeon_uvd_fini(rdev);
Alex Deucher7bf94a22012-08-17 11:48:29 -04007252 cik_pcie_gart_fini(rdev);
7253 r600_vram_scratch_fini(rdev);
7254 radeon_gem_fini(rdev);
7255 radeon_fence_driver_fini(rdev);
7256 radeon_bo_fini(rdev);
7257 radeon_atombios_fini(rdev);
7258 kfree(rdev->bios);
7259 rdev->bios = NULL;
7260}
Alex Deuchercd84a272012-07-20 17:13:13 -04007261
7262/* display watermark setup */
7263/**
7264 * dce8_line_buffer_adjust - Set up the line buffer
7265 *
7266 * @rdev: radeon_device pointer
7267 * @radeon_crtc: the selected display controller
7268 * @mode: the current display mode on the selected display
7269 * controller
7270 *
7271 * Setup up the line buffer allocation for
7272 * the selected display controller (CIK).
7273 * Returns the line buffer size in pixels.
7274 */
7275static u32 dce8_line_buffer_adjust(struct radeon_device *rdev,
7276 struct radeon_crtc *radeon_crtc,
7277 struct drm_display_mode *mode)
7278{
7279 u32 tmp;
7280
7281 /*
7282 * Line Buffer Setup
7283 * There are 6 line buffers, one for each display controllers.
7284 * There are 3 partitions per LB. Select the number of partitions
7285 * to enable based on the display width. For display widths larger
7286 * than 4096, you need use to use 2 display controllers and combine
7287 * them using the stereo blender.
7288 */
7289 if (radeon_crtc->base.enabled && mode) {
7290 if (mode->crtc_hdisplay < 1920)
7291 tmp = 1;
7292 else if (mode->crtc_hdisplay < 2560)
7293 tmp = 2;
7294 else if (mode->crtc_hdisplay < 4096)
7295 tmp = 0;
7296 else {
7297 DRM_DEBUG_KMS("Mode too big for LB!\n");
7298 tmp = 0;
7299 }
7300 } else
7301 tmp = 1;
7302
7303 WREG32(LB_MEMORY_CTRL + radeon_crtc->crtc_offset,
7304 LB_MEMORY_CONFIG(tmp) | LB_MEMORY_SIZE(0x6B0));
7305
7306 if (radeon_crtc->base.enabled && mode) {
7307 switch (tmp) {
7308 case 0:
7309 default:
7310 return 4096 * 2;
7311 case 1:
7312 return 1920 * 2;
7313 case 2:
7314 return 2560 * 2;
7315 }
7316 }
7317
7318 /* controller not enabled, so no lb used */
7319 return 0;
7320}
7321
7322/**
7323 * cik_get_number_of_dram_channels - get the number of dram channels
7324 *
7325 * @rdev: radeon_device pointer
7326 *
7327 * Look up the number of video ram channels (CIK).
7328 * Used for display watermark bandwidth calculations
7329 * Returns the number of dram channels
7330 */
7331static u32 cik_get_number_of_dram_channels(struct radeon_device *rdev)
7332{
7333 u32 tmp = RREG32(MC_SHARED_CHMAP);
7334
7335 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
7336 case 0:
7337 default:
7338 return 1;
7339 case 1:
7340 return 2;
7341 case 2:
7342 return 4;
7343 case 3:
7344 return 8;
7345 case 4:
7346 return 3;
7347 case 5:
7348 return 6;
7349 case 6:
7350 return 10;
7351 case 7:
7352 return 12;
7353 case 8:
7354 return 16;
7355 }
7356}
7357
7358struct dce8_wm_params {
7359 u32 dram_channels; /* number of dram channels */
7360 u32 yclk; /* bandwidth per dram data pin in kHz */
7361 u32 sclk; /* engine clock in kHz */
7362 u32 disp_clk; /* display clock in kHz */
7363 u32 src_width; /* viewport width */
7364 u32 active_time; /* active display time in ns */
7365 u32 blank_time; /* blank time in ns */
7366 bool interlaced; /* mode is interlaced */
7367 fixed20_12 vsc; /* vertical scale ratio */
7368 u32 num_heads; /* number of active crtcs */
7369 u32 bytes_per_pixel; /* bytes per pixel display + overlay */
7370 u32 lb_size; /* line buffer allocated to pipe */
7371 u32 vtaps; /* vertical scaler taps */
7372};
7373
7374/**
7375 * dce8_dram_bandwidth - get the dram bandwidth
7376 *
7377 * @wm: watermark calculation data
7378 *
7379 * Calculate the raw dram bandwidth (CIK).
7380 * Used for display watermark bandwidth calculations
7381 * Returns the dram bandwidth in MBytes/s
7382 */
7383static u32 dce8_dram_bandwidth(struct dce8_wm_params *wm)
7384{
7385 /* Calculate raw DRAM Bandwidth */
7386 fixed20_12 dram_efficiency; /* 0.7 */
7387 fixed20_12 yclk, dram_channels, bandwidth;
7388 fixed20_12 a;
7389
7390 a.full = dfixed_const(1000);
7391 yclk.full = dfixed_const(wm->yclk);
7392 yclk.full = dfixed_div(yclk, a);
7393 dram_channels.full = dfixed_const(wm->dram_channels * 4);
7394 a.full = dfixed_const(10);
7395 dram_efficiency.full = dfixed_const(7);
7396 dram_efficiency.full = dfixed_div(dram_efficiency, a);
7397 bandwidth.full = dfixed_mul(dram_channels, yclk);
7398 bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
7399
7400 return dfixed_trunc(bandwidth);
7401}
7402
7403/**
7404 * dce8_dram_bandwidth_for_display - get the dram bandwidth for display
7405 *
7406 * @wm: watermark calculation data
7407 *
7408 * Calculate the dram bandwidth used for display (CIK).
7409 * Used for display watermark bandwidth calculations
7410 * Returns the dram bandwidth for display in MBytes/s
7411 */
7412static u32 dce8_dram_bandwidth_for_display(struct dce8_wm_params *wm)
7413{
7414 /* Calculate DRAM Bandwidth and the part allocated to display. */
7415 fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
7416 fixed20_12 yclk, dram_channels, bandwidth;
7417 fixed20_12 a;
7418
7419 a.full = dfixed_const(1000);
7420 yclk.full = dfixed_const(wm->yclk);
7421 yclk.full = dfixed_div(yclk, a);
7422 dram_channels.full = dfixed_const(wm->dram_channels * 4);
7423 a.full = dfixed_const(10);
7424 disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
7425 disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
7426 bandwidth.full = dfixed_mul(dram_channels, yclk);
7427 bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
7428
7429 return dfixed_trunc(bandwidth);
7430}
7431
7432/**
7433 * dce8_data_return_bandwidth - get the data return bandwidth
7434 *
7435 * @wm: watermark calculation data
7436 *
7437 * Calculate the data return bandwidth used for display (CIK).
7438 * Used for display watermark bandwidth calculations
7439 * Returns the data return bandwidth in MBytes/s
7440 */
7441static u32 dce8_data_return_bandwidth(struct dce8_wm_params *wm)
7442{
7443 /* Calculate the display Data return Bandwidth */
7444 fixed20_12 return_efficiency; /* 0.8 */
7445 fixed20_12 sclk, bandwidth;
7446 fixed20_12 a;
7447
7448 a.full = dfixed_const(1000);
7449 sclk.full = dfixed_const(wm->sclk);
7450 sclk.full = dfixed_div(sclk, a);
7451 a.full = dfixed_const(10);
7452 return_efficiency.full = dfixed_const(8);
7453 return_efficiency.full = dfixed_div(return_efficiency, a);
7454 a.full = dfixed_const(32);
7455 bandwidth.full = dfixed_mul(a, sclk);
7456 bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
7457
7458 return dfixed_trunc(bandwidth);
7459}
7460
7461/**
7462 * dce8_dmif_request_bandwidth - get the dmif bandwidth
7463 *
7464 * @wm: watermark calculation data
7465 *
7466 * Calculate the dmif bandwidth used for display (CIK).
7467 * Used for display watermark bandwidth calculations
7468 * Returns the dmif bandwidth in MBytes/s
7469 */
7470static u32 dce8_dmif_request_bandwidth(struct dce8_wm_params *wm)
7471{
7472 /* Calculate the DMIF Request Bandwidth */
7473 fixed20_12 disp_clk_request_efficiency; /* 0.8 */
7474 fixed20_12 disp_clk, bandwidth;
7475 fixed20_12 a, b;
7476
7477 a.full = dfixed_const(1000);
7478 disp_clk.full = dfixed_const(wm->disp_clk);
7479 disp_clk.full = dfixed_div(disp_clk, a);
7480 a.full = dfixed_const(32);
7481 b.full = dfixed_mul(a, disp_clk);
7482
7483 a.full = dfixed_const(10);
7484 disp_clk_request_efficiency.full = dfixed_const(8);
7485 disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
7486
7487 bandwidth.full = dfixed_mul(b, disp_clk_request_efficiency);
7488
7489 return dfixed_trunc(bandwidth);
7490}
7491
7492/**
7493 * dce8_available_bandwidth - get the min available bandwidth
7494 *
7495 * @wm: watermark calculation data
7496 *
7497 * Calculate the min available bandwidth used for display (CIK).
7498 * Used for display watermark bandwidth calculations
7499 * Returns the min available bandwidth in MBytes/s
7500 */
7501static u32 dce8_available_bandwidth(struct dce8_wm_params *wm)
7502{
7503 /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
7504 u32 dram_bandwidth = dce8_dram_bandwidth(wm);
7505 u32 data_return_bandwidth = dce8_data_return_bandwidth(wm);
7506 u32 dmif_req_bandwidth = dce8_dmif_request_bandwidth(wm);
7507
7508 return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
7509}
7510
7511/**
7512 * dce8_average_bandwidth - get the average available bandwidth
7513 *
7514 * @wm: watermark calculation data
7515 *
7516 * Calculate the average available bandwidth used for display (CIK).
7517 * Used for display watermark bandwidth calculations
7518 * Returns the average available bandwidth in MBytes/s
7519 */
7520static u32 dce8_average_bandwidth(struct dce8_wm_params *wm)
7521{
7522 /* Calculate the display mode Average Bandwidth
7523 * DisplayMode should contain the source and destination dimensions,
7524 * timing, etc.
7525 */
7526 fixed20_12 bpp;
7527 fixed20_12 line_time;
7528 fixed20_12 src_width;
7529 fixed20_12 bandwidth;
7530 fixed20_12 a;
7531
7532 a.full = dfixed_const(1000);
7533 line_time.full = dfixed_const(wm->active_time + wm->blank_time);
7534 line_time.full = dfixed_div(line_time, a);
7535 bpp.full = dfixed_const(wm->bytes_per_pixel);
7536 src_width.full = dfixed_const(wm->src_width);
7537 bandwidth.full = dfixed_mul(src_width, bpp);
7538 bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
7539 bandwidth.full = dfixed_div(bandwidth, line_time);
7540
7541 return dfixed_trunc(bandwidth);
7542}
7543
7544/**
7545 * dce8_latency_watermark - get the latency watermark
7546 *
7547 * @wm: watermark calculation data
7548 *
7549 * Calculate the latency watermark (CIK).
7550 * Used for display watermark bandwidth calculations
7551 * Returns the latency watermark in ns
7552 */
7553static u32 dce8_latency_watermark(struct dce8_wm_params *wm)
7554{
7555 /* First calculate the latency in ns */
7556 u32 mc_latency = 2000; /* 2000 ns. */
7557 u32 available_bandwidth = dce8_available_bandwidth(wm);
7558 u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
7559 u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
7560 u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
7561 u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
7562 (wm->num_heads * cursor_line_pair_return_time);
7563 u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
7564 u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
7565 u32 tmp, dmif_size = 12288;
7566 fixed20_12 a, b, c;
7567
7568 if (wm->num_heads == 0)
7569 return 0;
7570
7571 a.full = dfixed_const(2);
7572 b.full = dfixed_const(1);
7573 if ((wm->vsc.full > a.full) ||
7574 ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
7575 (wm->vtaps >= 5) ||
7576 ((wm->vsc.full >= a.full) && wm->interlaced))
7577 max_src_lines_per_dst_line = 4;
7578 else
7579 max_src_lines_per_dst_line = 2;
7580
7581 a.full = dfixed_const(available_bandwidth);
7582 b.full = dfixed_const(wm->num_heads);
7583 a.full = dfixed_div(a, b);
7584
7585 b.full = dfixed_const(mc_latency + 512);
7586 c.full = dfixed_const(wm->disp_clk);
7587 b.full = dfixed_div(b, c);
7588
7589 c.full = dfixed_const(dmif_size);
7590 b.full = dfixed_div(c, b);
7591
7592 tmp = min(dfixed_trunc(a), dfixed_trunc(b));
7593
7594 b.full = dfixed_const(1000);
7595 c.full = dfixed_const(wm->disp_clk);
7596 b.full = dfixed_div(c, b);
7597 c.full = dfixed_const(wm->bytes_per_pixel);
7598 b.full = dfixed_mul(b, c);
7599
7600 lb_fill_bw = min(tmp, dfixed_trunc(b));
7601
7602 a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
7603 b.full = dfixed_const(1000);
7604 c.full = dfixed_const(lb_fill_bw);
7605 b.full = dfixed_div(c, b);
7606 a.full = dfixed_div(a, b);
7607 line_fill_time = dfixed_trunc(a);
7608
7609 if (line_fill_time < wm->active_time)
7610 return latency;
7611 else
7612 return latency + (line_fill_time - wm->active_time);
7613
7614}
7615
7616/**
7617 * dce8_average_bandwidth_vs_dram_bandwidth_for_display - check
7618 * average and available dram bandwidth
7619 *
7620 * @wm: watermark calculation data
7621 *
7622 * Check if the display average bandwidth fits in the display
7623 * dram bandwidth (CIK).
7624 * Used for display watermark bandwidth calculations
7625 * Returns true if the display fits, false if not.
7626 */
7627static bool dce8_average_bandwidth_vs_dram_bandwidth_for_display(struct dce8_wm_params *wm)
7628{
7629 if (dce8_average_bandwidth(wm) <=
7630 (dce8_dram_bandwidth_for_display(wm) / wm->num_heads))
7631 return true;
7632 else
7633 return false;
7634}
7635
7636/**
7637 * dce8_average_bandwidth_vs_available_bandwidth - check
7638 * average and available bandwidth
7639 *
7640 * @wm: watermark calculation data
7641 *
7642 * Check if the display average bandwidth fits in the display
7643 * available bandwidth (CIK).
7644 * Used for display watermark bandwidth calculations
7645 * Returns true if the display fits, false if not.
7646 */
7647static bool dce8_average_bandwidth_vs_available_bandwidth(struct dce8_wm_params *wm)
7648{
7649 if (dce8_average_bandwidth(wm) <=
7650 (dce8_available_bandwidth(wm) / wm->num_heads))
7651 return true;
7652 else
7653 return false;
7654}
7655
7656/**
7657 * dce8_check_latency_hiding - check latency hiding
7658 *
7659 * @wm: watermark calculation data
7660 *
7661 * Check latency hiding (CIK).
7662 * Used for display watermark bandwidth calculations
7663 * Returns true if the display fits, false if not.
7664 */
7665static bool dce8_check_latency_hiding(struct dce8_wm_params *wm)
7666{
7667 u32 lb_partitions = wm->lb_size / wm->src_width;
7668 u32 line_time = wm->active_time + wm->blank_time;
7669 u32 latency_tolerant_lines;
7670 u32 latency_hiding;
7671 fixed20_12 a;
7672
7673 a.full = dfixed_const(1);
7674 if (wm->vsc.full > a.full)
7675 latency_tolerant_lines = 1;
7676 else {
7677 if (lb_partitions <= (wm->vtaps + 1))
7678 latency_tolerant_lines = 1;
7679 else
7680 latency_tolerant_lines = 2;
7681 }
7682
7683 latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
7684
7685 if (dce8_latency_watermark(wm) <= latency_hiding)
7686 return true;
7687 else
7688 return false;
7689}
7690
7691/**
7692 * dce8_program_watermarks - program display watermarks
7693 *
7694 * @rdev: radeon_device pointer
7695 * @radeon_crtc: the selected display controller
7696 * @lb_size: line buffer size
7697 * @num_heads: number of display controllers in use
7698 *
7699 * Calculate and program the display watermarks for the
7700 * selected display controller (CIK).
7701 */
7702static void dce8_program_watermarks(struct radeon_device *rdev,
7703 struct radeon_crtc *radeon_crtc,
7704 u32 lb_size, u32 num_heads)
7705{
7706 struct drm_display_mode *mode = &radeon_crtc->base.mode;
Alex Deucher58ea2de2013-01-24 10:03:39 -05007707 struct dce8_wm_params wm_low, wm_high;
Alex Deuchercd84a272012-07-20 17:13:13 -04007708 u32 pixel_period;
7709 u32 line_time = 0;
7710 u32 latency_watermark_a = 0, latency_watermark_b = 0;
7711 u32 tmp, wm_mask;
7712
7713 if (radeon_crtc->base.enabled && num_heads && mode) {
7714 pixel_period = 1000000 / (u32)mode->clock;
7715 line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
7716
Alex Deucher58ea2de2013-01-24 10:03:39 -05007717 /* watermark for high clocks */
7718 if ((rdev->pm.pm_method == PM_METHOD_DPM) &&
7719 rdev->pm.dpm_enabled) {
7720 wm_high.yclk =
7721 radeon_dpm_get_mclk(rdev, false) * 10;
7722 wm_high.sclk =
7723 radeon_dpm_get_sclk(rdev, false) * 10;
7724 } else {
7725 wm_high.yclk = rdev->pm.current_mclk * 10;
7726 wm_high.sclk = rdev->pm.current_sclk * 10;
7727 }
7728
7729 wm_high.disp_clk = mode->clock;
7730 wm_high.src_width = mode->crtc_hdisplay;
7731 wm_high.active_time = mode->crtc_hdisplay * pixel_period;
7732 wm_high.blank_time = line_time - wm_high.active_time;
7733 wm_high.interlaced = false;
Alex Deuchercd84a272012-07-20 17:13:13 -04007734 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
Alex Deucher58ea2de2013-01-24 10:03:39 -05007735 wm_high.interlaced = true;
7736 wm_high.vsc = radeon_crtc->vsc;
7737 wm_high.vtaps = 1;
Alex Deuchercd84a272012-07-20 17:13:13 -04007738 if (radeon_crtc->rmx_type != RMX_OFF)
Alex Deucher58ea2de2013-01-24 10:03:39 -05007739 wm_high.vtaps = 2;
7740 wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
7741 wm_high.lb_size = lb_size;
7742 wm_high.dram_channels = cik_get_number_of_dram_channels(rdev);
7743 wm_high.num_heads = num_heads;
Alex Deuchercd84a272012-07-20 17:13:13 -04007744
7745 /* set for high clocks */
Alex Deucher58ea2de2013-01-24 10:03:39 -05007746 latency_watermark_a = min(dce8_latency_watermark(&wm_high), (u32)65535);
Alex Deuchercd84a272012-07-20 17:13:13 -04007747
7748 /* possibly force display priority to high */
7749 /* should really do this at mode validation time... */
Alex Deucher58ea2de2013-01-24 10:03:39 -05007750 if (!dce8_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
7751 !dce8_average_bandwidth_vs_available_bandwidth(&wm_high) ||
7752 !dce8_check_latency_hiding(&wm_high) ||
7753 (rdev->disp_priority == 2)) {
7754 DRM_DEBUG_KMS("force priority to high\n");
7755 }
7756
7757 /* watermark for low clocks */
7758 if ((rdev->pm.pm_method == PM_METHOD_DPM) &&
7759 rdev->pm.dpm_enabled) {
7760 wm_low.yclk =
7761 radeon_dpm_get_mclk(rdev, true) * 10;
7762 wm_low.sclk =
7763 radeon_dpm_get_sclk(rdev, true) * 10;
7764 } else {
7765 wm_low.yclk = rdev->pm.current_mclk * 10;
7766 wm_low.sclk = rdev->pm.current_sclk * 10;
7767 }
7768
7769 wm_low.disp_clk = mode->clock;
7770 wm_low.src_width = mode->crtc_hdisplay;
7771 wm_low.active_time = mode->crtc_hdisplay * pixel_period;
7772 wm_low.blank_time = line_time - wm_low.active_time;
7773 wm_low.interlaced = false;
7774 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
7775 wm_low.interlaced = true;
7776 wm_low.vsc = radeon_crtc->vsc;
7777 wm_low.vtaps = 1;
7778 if (radeon_crtc->rmx_type != RMX_OFF)
7779 wm_low.vtaps = 2;
7780 wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
7781 wm_low.lb_size = lb_size;
7782 wm_low.dram_channels = cik_get_number_of_dram_channels(rdev);
7783 wm_low.num_heads = num_heads;
7784
7785 /* set for low clocks */
7786 latency_watermark_b = min(dce8_latency_watermark(&wm_low), (u32)65535);
7787
7788 /* possibly force display priority to high */
7789 /* should really do this at mode validation time... */
7790 if (!dce8_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
7791 !dce8_average_bandwidth_vs_available_bandwidth(&wm_low) ||
7792 !dce8_check_latency_hiding(&wm_low) ||
Alex Deuchercd84a272012-07-20 17:13:13 -04007793 (rdev->disp_priority == 2)) {
7794 DRM_DEBUG_KMS("force priority to high\n");
7795 }
7796 }
7797
7798 /* select wm A */
7799 wm_mask = RREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset);
7800 tmp = wm_mask;
7801 tmp &= ~LATENCY_WATERMARK_MASK(3);
7802 tmp |= LATENCY_WATERMARK_MASK(1);
7803 WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, tmp);
7804 WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
7805 (LATENCY_LOW_WATERMARK(latency_watermark_a) |
7806 LATENCY_HIGH_WATERMARK(line_time)));
7807 /* select wm B */
7808 tmp = RREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset);
7809 tmp &= ~LATENCY_WATERMARK_MASK(3);
7810 tmp |= LATENCY_WATERMARK_MASK(2);
7811 WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, tmp);
7812 WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
7813 (LATENCY_LOW_WATERMARK(latency_watermark_b) |
7814 LATENCY_HIGH_WATERMARK(line_time)));
7815 /* restore original selection */
7816 WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, wm_mask);
Alex Deucher58ea2de2013-01-24 10:03:39 -05007817
7818 /* save values for DPM */
7819 radeon_crtc->line_time = line_time;
7820 radeon_crtc->wm_high = latency_watermark_a;
7821 radeon_crtc->wm_low = latency_watermark_b;
Alex Deuchercd84a272012-07-20 17:13:13 -04007822}
7823
7824/**
7825 * dce8_bandwidth_update - program display watermarks
7826 *
7827 * @rdev: radeon_device pointer
7828 *
7829 * Calculate and program the display watermarks and line
7830 * buffer allocation (CIK).
7831 */
7832void dce8_bandwidth_update(struct radeon_device *rdev)
7833{
7834 struct drm_display_mode *mode = NULL;
7835 u32 num_heads = 0, lb_size;
7836 int i;
7837
7838 radeon_update_display_priority(rdev);
7839
7840 for (i = 0; i < rdev->num_crtc; i++) {
7841 if (rdev->mode_info.crtcs[i]->base.enabled)
7842 num_heads++;
7843 }
7844 for (i = 0; i < rdev->num_crtc; i++) {
7845 mode = &rdev->mode_info.crtcs[i]->base.mode;
7846 lb_size = dce8_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode);
7847 dce8_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
7848 }
7849}
Alex Deucher44fa3462012-12-18 22:17:00 -05007850
7851/**
7852 * cik_get_gpu_clock_counter - return GPU clock counter snapshot
7853 *
7854 * @rdev: radeon_device pointer
7855 *
7856 * Fetches a GPU clock counter snapshot (SI).
7857 * Returns the 64 bit clock counter snapshot.
7858 */
7859uint64_t cik_get_gpu_clock_counter(struct radeon_device *rdev)
7860{
7861 uint64_t clock;
7862
7863 mutex_lock(&rdev->gpu_clock_mutex);
7864 WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
7865 clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
7866 ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
7867 mutex_unlock(&rdev->gpu_clock_mutex);
7868 return clock;
7869}
7870
Christian König87167bb2013-04-09 13:39:21 -04007871static int cik_set_uvd_clock(struct radeon_device *rdev, u32 clock,
7872 u32 cntl_reg, u32 status_reg)
7873{
7874 int r, i;
7875 struct atom_clock_dividers dividers;
7876 uint32_t tmp;
7877
7878 r = radeon_atom_get_clock_dividers(rdev, COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
7879 clock, false, &dividers);
7880 if (r)
7881 return r;
7882
7883 tmp = RREG32_SMC(cntl_reg);
7884 tmp &= ~(DCLK_DIR_CNTL_EN|DCLK_DIVIDER_MASK);
7885 tmp |= dividers.post_divider;
7886 WREG32_SMC(cntl_reg, tmp);
7887
7888 for (i = 0; i < 100; i++) {
7889 if (RREG32_SMC(status_reg) & DCLK_STATUS)
7890 break;
7891 mdelay(10);
7892 }
7893 if (i == 100)
7894 return -ETIMEDOUT;
7895
7896 return 0;
7897}
7898
7899int cik_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
7900{
7901 int r = 0;
7902
7903 r = cik_set_uvd_clock(rdev, vclk, CG_VCLK_CNTL, CG_VCLK_STATUS);
7904 if (r)
7905 return r;
7906
7907 r = cik_set_uvd_clock(rdev, dclk, CG_DCLK_CNTL, CG_DCLK_STATUS);
7908 return r;
7909}
7910
Alex Deucher8a7cd272013-08-06 11:29:39 -04007911static void cik_pcie_gen3_enable(struct radeon_device *rdev)
7912{
7913 struct pci_dev *root = rdev->pdev->bus->self;
7914 int bridge_pos, gpu_pos;
7915 u32 speed_cntl, mask, current_data_rate;
7916 int ret, i;
7917 u16 tmp16;
7918
7919 if (radeon_pcie_gen2 == 0)
7920 return;
7921
7922 if (rdev->flags & RADEON_IS_IGP)
7923 return;
7924
7925 if (!(rdev->flags & RADEON_IS_PCIE))
7926 return;
7927
7928 ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask);
7929 if (ret != 0)
7930 return;
7931
7932 if (!(mask & (DRM_PCIE_SPEED_50 | DRM_PCIE_SPEED_80)))
7933 return;
7934
7935 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
7936 current_data_rate = (speed_cntl & LC_CURRENT_DATA_RATE_MASK) >>
7937 LC_CURRENT_DATA_RATE_SHIFT;
7938 if (mask & DRM_PCIE_SPEED_80) {
7939 if (current_data_rate == 2) {
7940 DRM_INFO("PCIE gen 3 link speeds already enabled\n");
7941 return;
7942 }
7943 DRM_INFO("enabling PCIE gen 3 link speeds, disable with radeon.pcie_gen2=0\n");
7944 } else if (mask & DRM_PCIE_SPEED_50) {
7945 if (current_data_rate == 1) {
7946 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
7947 return;
7948 }
7949 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
7950 }
7951
7952 bridge_pos = pci_pcie_cap(root);
7953 if (!bridge_pos)
7954 return;
7955
7956 gpu_pos = pci_pcie_cap(rdev->pdev);
7957 if (!gpu_pos)
7958 return;
7959
7960 if (mask & DRM_PCIE_SPEED_80) {
7961 /* re-try equalization if gen3 is not already enabled */
7962 if (current_data_rate != 2) {
7963 u16 bridge_cfg, gpu_cfg;
7964 u16 bridge_cfg2, gpu_cfg2;
7965 u32 max_lw, current_lw, tmp;
7966
7967 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
7968 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
7969
7970 tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
7971 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
7972
7973 tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
7974 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
7975
7976 tmp = RREG32_PCIE_PORT(PCIE_LC_STATUS1);
7977 max_lw = (tmp & LC_DETECTED_LINK_WIDTH_MASK) >> LC_DETECTED_LINK_WIDTH_SHIFT;
7978 current_lw = (tmp & LC_OPERATING_LINK_WIDTH_MASK) >> LC_OPERATING_LINK_WIDTH_SHIFT;
7979
7980 if (current_lw < max_lw) {
7981 tmp = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
7982 if (tmp & LC_RENEGOTIATION_SUPPORT) {
7983 tmp &= ~(LC_LINK_WIDTH_MASK | LC_UPCONFIGURE_DIS);
7984 tmp |= (max_lw << LC_LINK_WIDTH_SHIFT);
7985 tmp |= LC_UPCONFIGURE_SUPPORT | LC_RENEGOTIATE_EN | LC_RECONFIG_NOW;
7986 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, tmp);
7987 }
7988 }
7989
7990 for (i = 0; i < 10; i++) {
7991 /* check status */
7992 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_DEVSTA, &tmp16);
7993 if (tmp16 & PCI_EXP_DEVSTA_TRPND)
7994 break;
7995
7996 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
7997 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
7998
7999 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &bridge_cfg2);
8000 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &gpu_cfg2);
8001
8002 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
8003 tmp |= LC_SET_QUIESCE;
8004 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
8005
8006 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
8007 tmp |= LC_REDO_EQ;
8008 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
8009
8010 mdelay(100);
8011
8012 /* linkctl */
8013 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &tmp16);
8014 tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
8015 tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
8016 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
8017
8018 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &tmp16);
8019 tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
8020 tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
8021 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
8022
8023 /* linkctl2 */
8024 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &tmp16);
8025 tmp16 &= ~((1 << 4) | (7 << 9));
8026 tmp16 |= (bridge_cfg2 & ((1 << 4) | (7 << 9)));
8027 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, tmp16);
8028
8029 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
8030 tmp16 &= ~((1 << 4) | (7 << 9));
8031 tmp16 |= (gpu_cfg2 & ((1 << 4) | (7 << 9)));
8032 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
8033
8034 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
8035 tmp &= ~LC_SET_QUIESCE;
8036 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
8037 }
8038 }
8039 }
8040
8041 /* set the link speed */
8042 speed_cntl |= LC_FORCE_EN_SW_SPEED_CHANGE | LC_FORCE_DIS_HW_SPEED_CHANGE;
8043 speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
8044 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
8045
8046 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
8047 tmp16 &= ~0xf;
8048 if (mask & DRM_PCIE_SPEED_80)
8049 tmp16 |= 3; /* gen3 */
8050 else if (mask & DRM_PCIE_SPEED_50)
8051 tmp16 |= 2; /* gen2 */
8052 else
8053 tmp16 |= 1; /* gen1 */
8054 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
8055
8056 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
8057 speed_cntl |= LC_INITIATE_LINK_SPEED_CHANGE;
8058 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
8059
8060 for (i = 0; i < rdev->usec_timeout; i++) {
8061 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
8062 if ((speed_cntl & LC_INITIATE_LINK_SPEED_CHANGE) == 0)
8063 break;
8064 udelay(1);
8065 }
8066}
Alex Deucher7235711a42013-04-04 13:58:09 -04008067
8068static void cik_program_aspm(struct radeon_device *rdev)
8069{
8070 u32 data, orig;
8071 bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
8072 bool disable_clkreq = false;
8073
8074 if (radeon_aspm == 0)
8075 return;
8076
8077 /* XXX double check IGPs */
8078 if (rdev->flags & RADEON_IS_IGP)
8079 return;
8080
8081 if (!(rdev->flags & RADEON_IS_PCIE))
8082 return;
8083
8084 orig = data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
8085 data &= ~LC_XMIT_N_FTS_MASK;
8086 data |= LC_XMIT_N_FTS(0x24) | LC_XMIT_N_FTS_OVERRIDE_EN;
8087 if (orig != data)
8088 WREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL, data);
8089
8090 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL3);
8091 data |= LC_GO_TO_RECOVERY;
8092 if (orig != data)
8093 WREG32_PCIE_PORT(PCIE_LC_CNTL3, data);
8094
8095 orig = data = RREG32_PCIE_PORT(PCIE_P_CNTL);
8096 data |= P_IGNORE_EDB_ERR;
8097 if (orig != data)
8098 WREG32_PCIE_PORT(PCIE_P_CNTL, data);
8099
8100 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
8101 data &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
8102 data |= LC_PMI_TO_L1_DIS;
8103 if (!disable_l0s)
8104 data |= LC_L0S_INACTIVITY(7);
8105
8106 if (!disable_l1) {
8107 data |= LC_L1_INACTIVITY(7);
8108 data &= ~LC_PMI_TO_L1_DIS;
8109 if (orig != data)
8110 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
8111
8112 if (!disable_plloff_in_l1) {
8113 bool clk_req_support;
8114
8115 orig = data = RREG32_PCIE_PORT(PB0_PIF_PWRDOWN_0);
8116 data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
8117 data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
8118 if (orig != data)
8119 WREG32_PCIE_PORT(PB0_PIF_PWRDOWN_0, data);
8120
8121 orig = data = RREG32_PCIE_PORT(PB0_PIF_PWRDOWN_1);
8122 data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
8123 data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
8124 if (orig != data)
8125 WREG32_PCIE_PORT(PB0_PIF_PWRDOWN_1, data);
8126
8127 orig = data = RREG32_PCIE_PORT(PB1_PIF_PWRDOWN_0);
8128 data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
8129 data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
8130 if (orig != data)
8131 WREG32_PCIE_PORT(PB1_PIF_PWRDOWN_0, data);
8132
8133 orig = data = RREG32_PCIE_PORT(PB1_PIF_PWRDOWN_1);
8134 data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
8135 data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
8136 if (orig != data)
8137 WREG32_PCIE_PORT(PB1_PIF_PWRDOWN_1, data);
8138
8139 orig = data = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
8140 data &= ~LC_DYN_LANES_PWR_STATE_MASK;
8141 data |= LC_DYN_LANES_PWR_STATE(3);
8142 if (orig != data)
8143 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
8144
8145 if (!disable_clkreq) {
8146 struct pci_dev *root = rdev->pdev->bus->self;
8147 u32 lnkcap;
8148
8149 clk_req_support = false;
8150 pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
8151 if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
8152 clk_req_support = true;
8153 } else {
8154 clk_req_support = false;
8155 }
8156
8157 if (clk_req_support) {
8158 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL2);
8159 data |= LC_ALLOW_PDWN_IN_L1 | LC_ALLOW_PDWN_IN_L23;
8160 if (orig != data)
8161 WREG32_PCIE_PORT(PCIE_LC_CNTL2, data);
8162
8163 orig = data = RREG32_SMC(THM_CLK_CNTL);
8164 data &= ~(CMON_CLK_SEL_MASK | TMON_CLK_SEL_MASK);
8165 data |= CMON_CLK_SEL(1) | TMON_CLK_SEL(1);
8166 if (orig != data)
8167 WREG32_SMC(THM_CLK_CNTL, data);
8168
8169 orig = data = RREG32_SMC(MISC_CLK_CTRL);
8170 data &= ~(DEEP_SLEEP_CLK_SEL_MASK | ZCLK_SEL_MASK);
8171 data |= DEEP_SLEEP_CLK_SEL(1) | ZCLK_SEL(1);
8172 if (orig != data)
8173 WREG32_SMC(MISC_CLK_CTRL, data);
8174
8175 orig = data = RREG32_SMC(CG_CLKPIN_CNTL);
8176 data &= ~BCLK_AS_XCLK;
8177 if (orig != data)
8178 WREG32_SMC(CG_CLKPIN_CNTL, data);
8179
8180 orig = data = RREG32_SMC(CG_CLKPIN_CNTL_2);
8181 data &= ~FORCE_BIF_REFCLK_EN;
8182 if (orig != data)
8183 WREG32_SMC(CG_CLKPIN_CNTL_2, data);
8184
8185 orig = data = RREG32_SMC(MPLL_BYPASSCLK_SEL);
8186 data &= ~MPLL_CLKOUT_SEL_MASK;
8187 data |= MPLL_CLKOUT_SEL(4);
8188 if (orig != data)
8189 WREG32_SMC(MPLL_BYPASSCLK_SEL, data);
8190 }
8191 }
8192 } else {
8193 if (orig != data)
8194 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
8195 }
8196
8197 orig = data = RREG32_PCIE_PORT(PCIE_CNTL2);
8198 data |= SLV_MEM_LS_EN | MST_MEM_LS_EN | REPLAY_MEM_LS_EN;
8199 if (orig != data)
8200 WREG32_PCIE_PORT(PCIE_CNTL2, data);
8201
8202 if (!disable_l0s) {
8203 data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
8204 if((data & LC_N_FTS_MASK) == LC_N_FTS_MASK) {
8205 data = RREG32_PCIE_PORT(PCIE_LC_STATUS1);
8206 if ((data & LC_REVERSE_XMIT) && (data & LC_REVERSE_RCVR)) {
8207 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
8208 data &= ~LC_L0S_INACTIVITY_MASK;
8209 if (orig != data)
8210 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
8211 }
8212 }
8213 }
8214}