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