blob: 2acfe561796f111df7830a66299a50fa2102968e [file] [log] [blame]
Alex Deucher43b3cd92012-03-20 17:18:00 -04001/*
2 * Copyright 2011 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 */
Alex Deucher0f0de062012-03-20 17:18:17 -040024#include <linux/firmware.h>
Alex Deucher0f0de062012-03-20 17:18:17 -040025#include <linux/slab.h>
26#include <linux/module.h>
David Howells760285e2012-10-02 18:01:07 +010027#include <drm/drmP.h>
Alex Deucher43b3cd92012-03-20 17:18:00 -040028#include "radeon.h"
29#include "radeon_asic.h"
David Howells760285e2012-10-02 18:01:07 +010030#include <drm/radeon_drm.h>
Alex Deucher43b3cd92012-03-20 17:18:00 -040031#include "sid.h"
32#include "atom.h"
Alex Deucher48c0c902012-03-20 17:18:19 -040033#include "si_blit_shaders.h"
Alex Deucherbd8cd532013-04-12 16:48:21 -040034#include "clearstate_si.h"
Alex Deuchera0ceada2013-03-27 15:18:04 -040035#include "radeon_ucode.h"
Alex Deucher43b3cd92012-03-20 17:18:00 -040036
Alex Deucher0f0de062012-03-20 17:18:17 -040037
38MODULE_FIRMWARE("radeon/TAHITI_pfp.bin");
39MODULE_FIRMWARE("radeon/TAHITI_me.bin");
40MODULE_FIRMWARE("radeon/TAHITI_ce.bin");
41MODULE_FIRMWARE("radeon/TAHITI_mc.bin");
42MODULE_FIRMWARE("radeon/TAHITI_rlc.bin");
Alex Deuchera9e61412013-06-25 17:56:16 -040043MODULE_FIRMWARE("radeon/TAHITI_smc.bin");
Alex Deucher0f0de062012-03-20 17:18:17 -040044MODULE_FIRMWARE("radeon/PITCAIRN_pfp.bin");
45MODULE_FIRMWARE("radeon/PITCAIRN_me.bin");
46MODULE_FIRMWARE("radeon/PITCAIRN_ce.bin");
47MODULE_FIRMWARE("radeon/PITCAIRN_mc.bin");
48MODULE_FIRMWARE("radeon/PITCAIRN_rlc.bin");
Alex Deuchera9e61412013-06-25 17:56:16 -040049MODULE_FIRMWARE("radeon/PITCAIRN_smc.bin");
Alex Deucher0f0de062012-03-20 17:18:17 -040050MODULE_FIRMWARE("radeon/VERDE_pfp.bin");
51MODULE_FIRMWARE("radeon/VERDE_me.bin");
52MODULE_FIRMWARE("radeon/VERDE_ce.bin");
53MODULE_FIRMWARE("radeon/VERDE_mc.bin");
54MODULE_FIRMWARE("radeon/VERDE_rlc.bin");
Alex Deuchera9e61412013-06-25 17:56:16 -040055MODULE_FIRMWARE("radeon/VERDE_smc.bin");
Alex Deucherbcc7f5d2012-07-26 18:36:28 -040056MODULE_FIRMWARE("radeon/OLAND_pfp.bin");
57MODULE_FIRMWARE("radeon/OLAND_me.bin");
58MODULE_FIRMWARE("radeon/OLAND_ce.bin");
59MODULE_FIRMWARE("radeon/OLAND_mc.bin");
60MODULE_FIRMWARE("radeon/OLAND_rlc.bin");
Alex Deuchera9e61412013-06-25 17:56:16 -040061MODULE_FIRMWARE("radeon/OLAND_smc.bin");
Alex Deucherc04c00b2012-07-31 12:57:45 -040062MODULE_FIRMWARE("radeon/HAINAN_pfp.bin");
63MODULE_FIRMWARE("radeon/HAINAN_me.bin");
64MODULE_FIRMWARE("radeon/HAINAN_ce.bin");
65MODULE_FIRMWARE("radeon/HAINAN_mc.bin");
66MODULE_FIRMWARE("radeon/HAINAN_rlc.bin");
Alex Deuchera9e61412013-06-25 17:56:16 -040067MODULE_FIRMWARE("radeon/HAINAN_smc.bin");
Alex Deucher0f0de062012-03-20 17:18:17 -040068
Alex Deucherb9d305d2013-02-14 17:16:51 -050069static void si_pcie_gen3_enable(struct radeon_device *rdev);
Alex Deuchere0bcf1652013-02-15 11:56:59 -050070static void si_program_aspm(struct radeon_device *rdev);
Alex Deucher1fd11772013-04-17 17:53:50 -040071extern void sumo_rlc_fini(struct radeon_device *rdev);
72extern int sumo_rlc_init(struct radeon_device *rdev);
Alex Deucher25a857f2012-03-20 17:18:22 -040073extern int r600_ih_ring_alloc(struct radeon_device *rdev);
74extern void r600_ih_ring_fini(struct radeon_device *rdev);
Alex Deucher0a96d722012-03-20 17:18:11 -040075extern void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev);
Alex Deucherc476dde2012-03-20 17:18:12 -040076extern void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save);
77extern void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save);
Alex Deucherca7db222012-03-20 17:18:30 -040078extern u32 evergreen_get_number_of_dram_channels(struct radeon_device *rdev);
Alex Deucher1c534672013-01-18 15:08:38 -050079extern void evergreen_print_gpu_status_regs(struct radeon_device *rdev);
Alex Deucher014bb202013-01-18 19:36:20 -050080extern bool evergreen_is_display_hung(struct radeon_device *rdev);
Alex Deucher811e4d52013-09-03 13:31:33 -040081static void si_enable_gui_idle_interrupt(struct radeon_device *rdev,
82 bool enable);
Alex Deucher0a96d722012-03-20 17:18:11 -040083
Alex Deucher6d8cf002013-03-06 18:48:05 -050084static const u32 verde_rlc_save_restore_register_list[] =
85{
86 (0x8000 << 16) | (0x98f4 >> 2),
87 0x00000000,
88 (0x8040 << 16) | (0x98f4 >> 2),
89 0x00000000,
90 (0x8000 << 16) | (0xe80 >> 2),
91 0x00000000,
92 (0x8040 << 16) | (0xe80 >> 2),
93 0x00000000,
94 (0x8000 << 16) | (0x89bc >> 2),
95 0x00000000,
96 (0x8040 << 16) | (0x89bc >> 2),
97 0x00000000,
98 (0x8000 << 16) | (0x8c1c >> 2),
99 0x00000000,
100 (0x8040 << 16) | (0x8c1c >> 2),
101 0x00000000,
102 (0x9c00 << 16) | (0x98f0 >> 2),
103 0x00000000,
104 (0x9c00 << 16) | (0xe7c >> 2),
105 0x00000000,
106 (0x8000 << 16) | (0x9148 >> 2),
107 0x00000000,
108 (0x8040 << 16) | (0x9148 >> 2),
109 0x00000000,
110 (0x9c00 << 16) | (0x9150 >> 2),
111 0x00000000,
112 (0x9c00 << 16) | (0x897c >> 2),
113 0x00000000,
114 (0x9c00 << 16) | (0x8d8c >> 2),
115 0x00000000,
116 (0x9c00 << 16) | (0xac54 >> 2),
117 0X00000000,
118 0x3,
119 (0x9c00 << 16) | (0x98f8 >> 2),
120 0x00000000,
121 (0x9c00 << 16) | (0x9910 >> 2),
122 0x00000000,
123 (0x9c00 << 16) | (0x9914 >> 2),
124 0x00000000,
125 (0x9c00 << 16) | (0x9918 >> 2),
126 0x00000000,
127 (0x9c00 << 16) | (0x991c >> 2),
128 0x00000000,
129 (0x9c00 << 16) | (0x9920 >> 2),
130 0x00000000,
131 (0x9c00 << 16) | (0x9924 >> 2),
132 0x00000000,
133 (0x9c00 << 16) | (0x9928 >> 2),
134 0x00000000,
135 (0x9c00 << 16) | (0x992c >> 2),
136 0x00000000,
137 (0x9c00 << 16) | (0x9930 >> 2),
138 0x00000000,
139 (0x9c00 << 16) | (0x9934 >> 2),
140 0x00000000,
141 (0x9c00 << 16) | (0x9938 >> 2),
142 0x00000000,
143 (0x9c00 << 16) | (0x993c >> 2),
144 0x00000000,
145 (0x9c00 << 16) | (0x9940 >> 2),
146 0x00000000,
147 (0x9c00 << 16) | (0x9944 >> 2),
148 0x00000000,
149 (0x9c00 << 16) | (0x9948 >> 2),
150 0x00000000,
151 (0x9c00 << 16) | (0x994c >> 2),
152 0x00000000,
153 (0x9c00 << 16) | (0x9950 >> 2),
154 0x00000000,
155 (0x9c00 << 16) | (0x9954 >> 2),
156 0x00000000,
157 (0x9c00 << 16) | (0x9958 >> 2),
158 0x00000000,
159 (0x9c00 << 16) | (0x995c >> 2),
160 0x00000000,
161 (0x9c00 << 16) | (0x9960 >> 2),
162 0x00000000,
163 (0x9c00 << 16) | (0x9964 >> 2),
164 0x00000000,
165 (0x9c00 << 16) | (0x9968 >> 2),
166 0x00000000,
167 (0x9c00 << 16) | (0x996c >> 2),
168 0x00000000,
169 (0x9c00 << 16) | (0x9970 >> 2),
170 0x00000000,
171 (0x9c00 << 16) | (0x9974 >> 2),
172 0x00000000,
173 (0x9c00 << 16) | (0x9978 >> 2),
174 0x00000000,
175 (0x9c00 << 16) | (0x997c >> 2),
176 0x00000000,
177 (0x9c00 << 16) | (0x9980 >> 2),
178 0x00000000,
179 (0x9c00 << 16) | (0x9984 >> 2),
180 0x00000000,
181 (0x9c00 << 16) | (0x9988 >> 2),
182 0x00000000,
183 (0x9c00 << 16) | (0x998c >> 2),
184 0x00000000,
185 (0x9c00 << 16) | (0x8c00 >> 2),
186 0x00000000,
187 (0x9c00 << 16) | (0x8c14 >> 2),
188 0x00000000,
189 (0x9c00 << 16) | (0x8c04 >> 2),
190 0x00000000,
191 (0x9c00 << 16) | (0x8c08 >> 2),
192 0x00000000,
193 (0x8000 << 16) | (0x9b7c >> 2),
194 0x00000000,
195 (0x8040 << 16) | (0x9b7c >> 2),
196 0x00000000,
197 (0x8000 << 16) | (0xe84 >> 2),
198 0x00000000,
199 (0x8040 << 16) | (0xe84 >> 2),
200 0x00000000,
201 (0x8000 << 16) | (0x89c0 >> 2),
202 0x00000000,
203 (0x8040 << 16) | (0x89c0 >> 2),
204 0x00000000,
205 (0x8000 << 16) | (0x914c >> 2),
206 0x00000000,
207 (0x8040 << 16) | (0x914c >> 2),
208 0x00000000,
209 (0x8000 << 16) | (0x8c20 >> 2),
210 0x00000000,
211 (0x8040 << 16) | (0x8c20 >> 2),
212 0x00000000,
213 (0x8000 << 16) | (0x9354 >> 2),
214 0x00000000,
215 (0x8040 << 16) | (0x9354 >> 2),
216 0x00000000,
217 (0x9c00 << 16) | (0x9060 >> 2),
218 0x00000000,
219 (0x9c00 << 16) | (0x9364 >> 2),
220 0x00000000,
221 (0x9c00 << 16) | (0x9100 >> 2),
222 0x00000000,
223 (0x9c00 << 16) | (0x913c >> 2),
224 0x00000000,
225 (0x8000 << 16) | (0x90e0 >> 2),
226 0x00000000,
227 (0x8000 << 16) | (0x90e4 >> 2),
228 0x00000000,
229 (0x8000 << 16) | (0x90e8 >> 2),
230 0x00000000,
231 (0x8040 << 16) | (0x90e0 >> 2),
232 0x00000000,
233 (0x8040 << 16) | (0x90e4 >> 2),
234 0x00000000,
235 (0x8040 << 16) | (0x90e8 >> 2),
236 0x00000000,
237 (0x9c00 << 16) | (0x8bcc >> 2),
238 0x00000000,
239 (0x9c00 << 16) | (0x8b24 >> 2),
240 0x00000000,
241 (0x9c00 << 16) | (0x88c4 >> 2),
242 0x00000000,
243 (0x9c00 << 16) | (0x8e50 >> 2),
244 0x00000000,
245 (0x9c00 << 16) | (0x8c0c >> 2),
246 0x00000000,
247 (0x9c00 << 16) | (0x8e58 >> 2),
248 0x00000000,
249 (0x9c00 << 16) | (0x8e5c >> 2),
250 0x00000000,
251 (0x9c00 << 16) | (0x9508 >> 2),
252 0x00000000,
253 (0x9c00 << 16) | (0x950c >> 2),
254 0x00000000,
255 (0x9c00 << 16) | (0x9494 >> 2),
256 0x00000000,
257 (0x9c00 << 16) | (0xac0c >> 2),
258 0x00000000,
259 (0x9c00 << 16) | (0xac10 >> 2),
260 0x00000000,
261 (0x9c00 << 16) | (0xac14 >> 2),
262 0x00000000,
263 (0x9c00 << 16) | (0xae00 >> 2),
264 0x00000000,
265 (0x9c00 << 16) | (0xac08 >> 2),
266 0x00000000,
267 (0x9c00 << 16) | (0x88d4 >> 2),
268 0x00000000,
269 (0x9c00 << 16) | (0x88c8 >> 2),
270 0x00000000,
271 (0x9c00 << 16) | (0x88cc >> 2),
272 0x00000000,
273 (0x9c00 << 16) | (0x89b0 >> 2),
274 0x00000000,
275 (0x9c00 << 16) | (0x8b10 >> 2),
276 0x00000000,
277 (0x9c00 << 16) | (0x8a14 >> 2),
278 0x00000000,
279 (0x9c00 << 16) | (0x9830 >> 2),
280 0x00000000,
281 (0x9c00 << 16) | (0x9834 >> 2),
282 0x00000000,
283 (0x9c00 << 16) | (0x9838 >> 2),
284 0x00000000,
285 (0x9c00 << 16) | (0x9a10 >> 2),
286 0x00000000,
287 (0x8000 << 16) | (0x9870 >> 2),
288 0x00000000,
289 (0x8000 << 16) | (0x9874 >> 2),
290 0x00000000,
291 (0x8001 << 16) | (0x9870 >> 2),
292 0x00000000,
293 (0x8001 << 16) | (0x9874 >> 2),
294 0x00000000,
295 (0x8040 << 16) | (0x9870 >> 2),
296 0x00000000,
297 (0x8040 << 16) | (0x9874 >> 2),
298 0x00000000,
299 (0x8041 << 16) | (0x9870 >> 2),
300 0x00000000,
301 (0x8041 << 16) | (0x9874 >> 2),
302 0x00000000,
303 0x00000000
304};
305
Alex Deucher205996c2013-03-01 17:08:42 -0500306static const u32 tahiti_golden_rlc_registers[] =
307{
308 0xc424, 0xffffffff, 0x00601005,
309 0xc47c, 0xffffffff, 0x10104040,
310 0xc488, 0xffffffff, 0x0100000a,
311 0xc314, 0xffffffff, 0x00000800,
312 0xc30c, 0xffffffff, 0x800000f4,
313 0xf4a8, 0xffffffff, 0x00000000
314};
315
316static const u32 tahiti_golden_registers[] =
317{
318 0x9a10, 0x00010000, 0x00018208,
319 0x9830, 0xffffffff, 0x00000000,
320 0x9834, 0xf00fffff, 0x00000400,
321 0x9838, 0x0002021c, 0x00020200,
322 0xc78, 0x00000080, 0x00000000,
323 0xd030, 0x000300c0, 0x00800040,
324 0xd830, 0x000300c0, 0x00800040,
325 0x5bb0, 0x000000f0, 0x00000070,
326 0x5bc0, 0x00200000, 0x50100000,
327 0x7030, 0x31000311, 0x00000011,
328 0x277c, 0x00000003, 0x000007ff,
329 0x240c, 0x000007ff, 0x00000000,
330 0x8a14, 0xf000001f, 0x00000007,
331 0x8b24, 0xffffffff, 0x00ffffff,
332 0x8b10, 0x0000ff0f, 0x00000000,
333 0x28a4c, 0x07ffffff, 0x4e000000,
334 0x28350, 0x3f3f3fff, 0x2a00126a,
335 0x30, 0x000000ff, 0x0040,
336 0x34, 0x00000040, 0x00004040,
337 0x9100, 0x07ffffff, 0x03000000,
338 0x8e88, 0x01ff1f3f, 0x00000000,
339 0x8e84, 0x01ff1f3f, 0x00000000,
340 0x9060, 0x0000007f, 0x00000020,
341 0x9508, 0x00010000, 0x00010000,
342 0xac14, 0x00000200, 0x000002fb,
343 0xac10, 0xffffffff, 0x0000543b,
344 0xac0c, 0xffffffff, 0xa9210876,
345 0x88d0, 0xffffffff, 0x000fff40,
346 0x88d4, 0x0000001f, 0x00000010,
347 0x1410, 0x20000000, 0x20fffed8,
348 0x15c0, 0x000c0fc0, 0x000c0400
349};
350
351static const u32 tahiti_golden_registers2[] =
352{
353 0xc64, 0x00000001, 0x00000001
354};
355
356static const u32 pitcairn_golden_rlc_registers[] =
357{
358 0xc424, 0xffffffff, 0x00601004,
359 0xc47c, 0xffffffff, 0x10102020,
360 0xc488, 0xffffffff, 0x01000020,
361 0xc314, 0xffffffff, 0x00000800,
362 0xc30c, 0xffffffff, 0x800000a4
363};
364
365static const u32 pitcairn_golden_registers[] =
366{
367 0x9a10, 0x00010000, 0x00018208,
368 0x9830, 0xffffffff, 0x00000000,
369 0x9834, 0xf00fffff, 0x00000400,
370 0x9838, 0x0002021c, 0x00020200,
371 0xc78, 0x00000080, 0x00000000,
372 0xd030, 0x000300c0, 0x00800040,
373 0xd830, 0x000300c0, 0x00800040,
374 0x5bb0, 0x000000f0, 0x00000070,
375 0x5bc0, 0x00200000, 0x50100000,
376 0x7030, 0x31000311, 0x00000011,
377 0x2ae4, 0x00073ffe, 0x000022a2,
378 0x240c, 0x000007ff, 0x00000000,
379 0x8a14, 0xf000001f, 0x00000007,
380 0x8b24, 0xffffffff, 0x00ffffff,
381 0x8b10, 0x0000ff0f, 0x00000000,
382 0x28a4c, 0x07ffffff, 0x4e000000,
383 0x28350, 0x3f3f3fff, 0x2a00126a,
384 0x30, 0x000000ff, 0x0040,
385 0x34, 0x00000040, 0x00004040,
386 0x9100, 0x07ffffff, 0x03000000,
387 0x9060, 0x0000007f, 0x00000020,
388 0x9508, 0x00010000, 0x00010000,
389 0xac14, 0x000003ff, 0x000000f7,
390 0xac10, 0xffffffff, 0x00000000,
391 0xac0c, 0xffffffff, 0x32761054,
392 0x88d4, 0x0000001f, 0x00000010,
393 0x15c0, 0x000c0fc0, 0x000c0400
394};
395
396static const u32 verde_golden_rlc_registers[] =
397{
398 0xc424, 0xffffffff, 0x033f1005,
399 0xc47c, 0xffffffff, 0x10808020,
400 0xc488, 0xffffffff, 0x00800008,
401 0xc314, 0xffffffff, 0x00001000,
402 0xc30c, 0xffffffff, 0x80010014
403};
404
405static const u32 verde_golden_registers[] =
406{
407 0x9a10, 0x00010000, 0x00018208,
408 0x9830, 0xffffffff, 0x00000000,
409 0x9834, 0xf00fffff, 0x00000400,
410 0x9838, 0x0002021c, 0x00020200,
411 0xc78, 0x00000080, 0x00000000,
412 0xd030, 0x000300c0, 0x00800040,
413 0xd030, 0x000300c0, 0x00800040,
414 0xd830, 0x000300c0, 0x00800040,
415 0xd830, 0x000300c0, 0x00800040,
416 0x5bb0, 0x000000f0, 0x00000070,
417 0x5bc0, 0x00200000, 0x50100000,
418 0x7030, 0x31000311, 0x00000011,
419 0x2ae4, 0x00073ffe, 0x000022a2,
420 0x2ae4, 0x00073ffe, 0x000022a2,
421 0x2ae4, 0x00073ffe, 0x000022a2,
422 0x240c, 0x000007ff, 0x00000000,
423 0x240c, 0x000007ff, 0x00000000,
424 0x240c, 0x000007ff, 0x00000000,
425 0x8a14, 0xf000001f, 0x00000007,
426 0x8a14, 0xf000001f, 0x00000007,
427 0x8a14, 0xf000001f, 0x00000007,
428 0x8b24, 0xffffffff, 0x00ffffff,
429 0x8b10, 0x0000ff0f, 0x00000000,
430 0x28a4c, 0x07ffffff, 0x4e000000,
431 0x28350, 0x3f3f3fff, 0x0000124a,
432 0x28350, 0x3f3f3fff, 0x0000124a,
433 0x28350, 0x3f3f3fff, 0x0000124a,
434 0x30, 0x000000ff, 0x0040,
435 0x34, 0x00000040, 0x00004040,
436 0x9100, 0x07ffffff, 0x03000000,
437 0x9100, 0x07ffffff, 0x03000000,
438 0x8e88, 0x01ff1f3f, 0x00000000,
439 0x8e88, 0x01ff1f3f, 0x00000000,
440 0x8e88, 0x01ff1f3f, 0x00000000,
441 0x8e84, 0x01ff1f3f, 0x00000000,
442 0x8e84, 0x01ff1f3f, 0x00000000,
443 0x8e84, 0x01ff1f3f, 0x00000000,
444 0x9060, 0x0000007f, 0x00000020,
445 0x9508, 0x00010000, 0x00010000,
446 0xac14, 0x000003ff, 0x00000003,
447 0xac14, 0x000003ff, 0x00000003,
448 0xac14, 0x000003ff, 0x00000003,
449 0xac10, 0xffffffff, 0x00000000,
450 0xac10, 0xffffffff, 0x00000000,
451 0xac10, 0xffffffff, 0x00000000,
452 0xac0c, 0xffffffff, 0x00001032,
453 0xac0c, 0xffffffff, 0x00001032,
454 0xac0c, 0xffffffff, 0x00001032,
455 0x88d4, 0x0000001f, 0x00000010,
456 0x88d4, 0x0000001f, 0x00000010,
457 0x88d4, 0x0000001f, 0x00000010,
458 0x15c0, 0x000c0fc0, 0x000c0400
459};
460
461static const u32 oland_golden_rlc_registers[] =
462{
463 0xc424, 0xffffffff, 0x00601005,
464 0xc47c, 0xffffffff, 0x10104040,
465 0xc488, 0xffffffff, 0x0100000a,
466 0xc314, 0xffffffff, 0x00000800,
467 0xc30c, 0xffffffff, 0x800000f4
468};
469
470static const u32 oland_golden_registers[] =
471{
472 0x9a10, 0x00010000, 0x00018208,
473 0x9830, 0xffffffff, 0x00000000,
474 0x9834, 0xf00fffff, 0x00000400,
475 0x9838, 0x0002021c, 0x00020200,
476 0xc78, 0x00000080, 0x00000000,
477 0xd030, 0x000300c0, 0x00800040,
478 0xd830, 0x000300c0, 0x00800040,
479 0x5bb0, 0x000000f0, 0x00000070,
480 0x5bc0, 0x00200000, 0x50100000,
481 0x7030, 0x31000311, 0x00000011,
482 0x2ae4, 0x00073ffe, 0x000022a2,
483 0x240c, 0x000007ff, 0x00000000,
484 0x8a14, 0xf000001f, 0x00000007,
485 0x8b24, 0xffffffff, 0x00ffffff,
486 0x8b10, 0x0000ff0f, 0x00000000,
487 0x28a4c, 0x07ffffff, 0x4e000000,
488 0x28350, 0x3f3f3fff, 0x00000082,
489 0x30, 0x000000ff, 0x0040,
490 0x34, 0x00000040, 0x00004040,
491 0x9100, 0x07ffffff, 0x03000000,
492 0x9060, 0x0000007f, 0x00000020,
493 0x9508, 0x00010000, 0x00010000,
494 0xac14, 0x000003ff, 0x000000f3,
495 0xac10, 0xffffffff, 0x00000000,
496 0xac0c, 0xffffffff, 0x00003210,
497 0x88d4, 0x0000001f, 0x00000010,
498 0x15c0, 0x000c0fc0, 0x000c0400
499};
500
Alex Deucherfffbdda2013-05-13 13:36:23 -0400501static const u32 hainan_golden_registers[] =
502{
503 0x9a10, 0x00010000, 0x00018208,
504 0x9830, 0xffffffff, 0x00000000,
505 0x9834, 0xf00fffff, 0x00000400,
506 0x9838, 0x0002021c, 0x00020200,
507 0xd0c0, 0xff000fff, 0x00000100,
508 0xd030, 0x000300c0, 0x00800040,
509 0xd8c0, 0xff000fff, 0x00000100,
510 0xd830, 0x000300c0, 0x00800040,
511 0x2ae4, 0x00073ffe, 0x000022a2,
512 0x240c, 0x000007ff, 0x00000000,
513 0x8a14, 0xf000001f, 0x00000007,
514 0x8b24, 0xffffffff, 0x00ffffff,
515 0x8b10, 0x0000ff0f, 0x00000000,
516 0x28a4c, 0x07ffffff, 0x4e000000,
517 0x28350, 0x3f3f3fff, 0x00000000,
518 0x30, 0x000000ff, 0x0040,
519 0x34, 0x00000040, 0x00004040,
520 0x9100, 0x03e00000, 0x03600000,
521 0x9060, 0x0000007f, 0x00000020,
522 0x9508, 0x00010000, 0x00010000,
523 0xac14, 0x000003ff, 0x000000f1,
524 0xac10, 0xffffffff, 0x00000000,
525 0xac0c, 0xffffffff, 0x00003210,
526 0x88d4, 0x0000001f, 0x00000010,
527 0x15c0, 0x000c0fc0, 0x000c0400
528};
529
530static const u32 hainan_golden_registers2[] =
531{
532 0x98f8, 0xffffffff, 0x02010001
533};
534
Alex Deucher205996c2013-03-01 17:08:42 -0500535static const u32 tahiti_mgcg_cgcg_init[] =
536{
537 0xc400, 0xffffffff, 0xfffffffc,
538 0x802c, 0xffffffff, 0xe0000000,
539 0x9a60, 0xffffffff, 0x00000100,
540 0x92a4, 0xffffffff, 0x00000100,
541 0xc164, 0xffffffff, 0x00000100,
542 0x9774, 0xffffffff, 0x00000100,
543 0x8984, 0xffffffff, 0x06000100,
544 0x8a18, 0xffffffff, 0x00000100,
545 0x92a0, 0xffffffff, 0x00000100,
546 0xc380, 0xffffffff, 0x00000100,
547 0x8b28, 0xffffffff, 0x00000100,
548 0x9144, 0xffffffff, 0x00000100,
549 0x8d88, 0xffffffff, 0x00000100,
550 0x8d8c, 0xffffffff, 0x00000100,
551 0x9030, 0xffffffff, 0x00000100,
552 0x9034, 0xffffffff, 0x00000100,
553 0x9038, 0xffffffff, 0x00000100,
554 0x903c, 0xffffffff, 0x00000100,
555 0xad80, 0xffffffff, 0x00000100,
556 0xac54, 0xffffffff, 0x00000100,
557 0x897c, 0xffffffff, 0x06000100,
558 0x9868, 0xffffffff, 0x00000100,
559 0x9510, 0xffffffff, 0x00000100,
560 0xaf04, 0xffffffff, 0x00000100,
561 0xae04, 0xffffffff, 0x00000100,
562 0x949c, 0xffffffff, 0x00000100,
563 0x802c, 0xffffffff, 0xe0000000,
564 0x9160, 0xffffffff, 0x00010000,
565 0x9164, 0xffffffff, 0x00030002,
566 0x9168, 0xffffffff, 0x00040007,
567 0x916c, 0xffffffff, 0x00060005,
568 0x9170, 0xffffffff, 0x00090008,
569 0x9174, 0xffffffff, 0x00020001,
570 0x9178, 0xffffffff, 0x00040003,
571 0x917c, 0xffffffff, 0x00000007,
572 0x9180, 0xffffffff, 0x00060005,
573 0x9184, 0xffffffff, 0x00090008,
574 0x9188, 0xffffffff, 0x00030002,
575 0x918c, 0xffffffff, 0x00050004,
576 0x9190, 0xffffffff, 0x00000008,
577 0x9194, 0xffffffff, 0x00070006,
578 0x9198, 0xffffffff, 0x000a0009,
579 0x919c, 0xffffffff, 0x00040003,
580 0x91a0, 0xffffffff, 0x00060005,
581 0x91a4, 0xffffffff, 0x00000009,
582 0x91a8, 0xffffffff, 0x00080007,
583 0x91ac, 0xffffffff, 0x000b000a,
584 0x91b0, 0xffffffff, 0x00050004,
585 0x91b4, 0xffffffff, 0x00070006,
586 0x91b8, 0xffffffff, 0x0008000b,
587 0x91bc, 0xffffffff, 0x000a0009,
588 0x91c0, 0xffffffff, 0x000d000c,
589 0x91c4, 0xffffffff, 0x00060005,
590 0x91c8, 0xffffffff, 0x00080007,
591 0x91cc, 0xffffffff, 0x0000000b,
592 0x91d0, 0xffffffff, 0x000a0009,
593 0x91d4, 0xffffffff, 0x000d000c,
594 0x91d8, 0xffffffff, 0x00070006,
595 0x91dc, 0xffffffff, 0x00090008,
596 0x91e0, 0xffffffff, 0x0000000c,
597 0x91e4, 0xffffffff, 0x000b000a,
598 0x91e8, 0xffffffff, 0x000e000d,
599 0x91ec, 0xffffffff, 0x00080007,
600 0x91f0, 0xffffffff, 0x000a0009,
601 0x91f4, 0xffffffff, 0x0000000d,
602 0x91f8, 0xffffffff, 0x000c000b,
603 0x91fc, 0xffffffff, 0x000f000e,
604 0x9200, 0xffffffff, 0x00090008,
605 0x9204, 0xffffffff, 0x000b000a,
606 0x9208, 0xffffffff, 0x000c000f,
607 0x920c, 0xffffffff, 0x000e000d,
608 0x9210, 0xffffffff, 0x00110010,
609 0x9214, 0xffffffff, 0x000a0009,
610 0x9218, 0xffffffff, 0x000c000b,
611 0x921c, 0xffffffff, 0x0000000f,
612 0x9220, 0xffffffff, 0x000e000d,
613 0x9224, 0xffffffff, 0x00110010,
614 0x9228, 0xffffffff, 0x000b000a,
615 0x922c, 0xffffffff, 0x000d000c,
616 0x9230, 0xffffffff, 0x00000010,
617 0x9234, 0xffffffff, 0x000f000e,
618 0x9238, 0xffffffff, 0x00120011,
619 0x923c, 0xffffffff, 0x000c000b,
620 0x9240, 0xffffffff, 0x000e000d,
621 0x9244, 0xffffffff, 0x00000011,
622 0x9248, 0xffffffff, 0x0010000f,
623 0x924c, 0xffffffff, 0x00130012,
624 0x9250, 0xffffffff, 0x000d000c,
625 0x9254, 0xffffffff, 0x000f000e,
626 0x9258, 0xffffffff, 0x00100013,
627 0x925c, 0xffffffff, 0x00120011,
628 0x9260, 0xffffffff, 0x00150014,
629 0x9264, 0xffffffff, 0x000e000d,
630 0x9268, 0xffffffff, 0x0010000f,
631 0x926c, 0xffffffff, 0x00000013,
632 0x9270, 0xffffffff, 0x00120011,
633 0x9274, 0xffffffff, 0x00150014,
634 0x9278, 0xffffffff, 0x000f000e,
635 0x927c, 0xffffffff, 0x00110010,
636 0x9280, 0xffffffff, 0x00000014,
637 0x9284, 0xffffffff, 0x00130012,
638 0x9288, 0xffffffff, 0x00160015,
639 0x928c, 0xffffffff, 0x0010000f,
640 0x9290, 0xffffffff, 0x00120011,
641 0x9294, 0xffffffff, 0x00000015,
642 0x9298, 0xffffffff, 0x00140013,
643 0x929c, 0xffffffff, 0x00170016,
644 0x9150, 0xffffffff, 0x96940200,
645 0x8708, 0xffffffff, 0x00900100,
646 0xc478, 0xffffffff, 0x00000080,
647 0xc404, 0xffffffff, 0x0020003f,
648 0x30, 0xffffffff, 0x0000001c,
649 0x34, 0x000f0000, 0x000f0000,
650 0x160c, 0xffffffff, 0x00000100,
651 0x1024, 0xffffffff, 0x00000100,
652 0x102c, 0x00000101, 0x00000000,
653 0x20a8, 0xffffffff, 0x00000104,
654 0x264c, 0x000c0000, 0x000c0000,
655 0x2648, 0x000c0000, 0x000c0000,
656 0x55e4, 0xff000fff, 0x00000100,
657 0x55e8, 0x00000001, 0x00000001,
658 0x2f50, 0x00000001, 0x00000001,
659 0x30cc, 0xc0000fff, 0x00000104,
660 0xc1e4, 0x00000001, 0x00000001,
661 0xd0c0, 0xfffffff0, 0x00000100,
662 0xd8c0, 0xfffffff0, 0x00000100
663};
664
665static const u32 pitcairn_mgcg_cgcg_init[] =
666{
667 0xc400, 0xffffffff, 0xfffffffc,
668 0x802c, 0xffffffff, 0xe0000000,
669 0x9a60, 0xffffffff, 0x00000100,
670 0x92a4, 0xffffffff, 0x00000100,
671 0xc164, 0xffffffff, 0x00000100,
672 0x9774, 0xffffffff, 0x00000100,
673 0x8984, 0xffffffff, 0x06000100,
674 0x8a18, 0xffffffff, 0x00000100,
675 0x92a0, 0xffffffff, 0x00000100,
676 0xc380, 0xffffffff, 0x00000100,
677 0x8b28, 0xffffffff, 0x00000100,
678 0x9144, 0xffffffff, 0x00000100,
679 0x8d88, 0xffffffff, 0x00000100,
680 0x8d8c, 0xffffffff, 0x00000100,
681 0x9030, 0xffffffff, 0x00000100,
682 0x9034, 0xffffffff, 0x00000100,
683 0x9038, 0xffffffff, 0x00000100,
684 0x903c, 0xffffffff, 0x00000100,
685 0xad80, 0xffffffff, 0x00000100,
686 0xac54, 0xffffffff, 0x00000100,
687 0x897c, 0xffffffff, 0x06000100,
688 0x9868, 0xffffffff, 0x00000100,
689 0x9510, 0xffffffff, 0x00000100,
690 0xaf04, 0xffffffff, 0x00000100,
691 0xae04, 0xffffffff, 0x00000100,
692 0x949c, 0xffffffff, 0x00000100,
693 0x802c, 0xffffffff, 0xe0000000,
694 0x9160, 0xffffffff, 0x00010000,
695 0x9164, 0xffffffff, 0x00030002,
696 0x9168, 0xffffffff, 0x00040007,
697 0x916c, 0xffffffff, 0x00060005,
698 0x9170, 0xffffffff, 0x00090008,
699 0x9174, 0xffffffff, 0x00020001,
700 0x9178, 0xffffffff, 0x00040003,
701 0x917c, 0xffffffff, 0x00000007,
702 0x9180, 0xffffffff, 0x00060005,
703 0x9184, 0xffffffff, 0x00090008,
704 0x9188, 0xffffffff, 0x00030002,
705 0x918c, 0xffffffff, 0x00050004,
706 0x9190, 0xffffffff, 0x00000008,
707 0x9194, 0xffffffff, 0x00070006,
708 0x9198, 0xffffffff, 0x000a0009,
709 0x919c, 0xffffffff, 0x00040003,
710 0x91a0, 0xffffffff, 0x00060005,
711 0x91a4, 0xffffffff, 0x00000009,
712 0x91a8, 0xffffffff, 0x00080007,
713 0x91ac, 0xffffffff, 0x000b000a,
714 0x91b0, 0xffffffff, 0x00050004,
715 0x91b4, 0xffffffff, 0x00070006,
716 0x91b8, 0xffffffff, 0x0008000b,
717 0x91bc, 0xffffffff, 0x000a0009,
718 0x91c0, 0xffffffff, 0x000d000c,
719 0x9200, 0xffffffff, 0x00090008,
720 0x9204, 0xffffffff, 0x000b000a,
721 0x9208, 0xffffffff, 0x000c000f,
722 0x920c, 0xffffffff, 0x000e000d,
723 0x9210, 0xffffffff, 0x00110010,
724 0x9214, 0xffffffff, 0x000a0009,
725 0x9218, 0xffffffff, 0x000c000b,
726 0x921c, 0xffffffff, 0x0000000f,
727 0x9220, 0xffffffff, 0x000e000d,
728 0x9224, 0xffffffff, 0x00110010,
729 0x9228, 0xffffffff, 0x000b000a,
730 0x922c, 0xffffffff, 0x000d000c,
731 0x9230, 0xffffffff, 0x00000010,
732 0x9234, 0xffffffff, 0x000f000e,
733 0x9238, 0xffffffff, 0x00120011,
734 0x923c, 0xffffffff, 0x000c000b,
735 0x9240, 0xffffffff, 0x000e000d,
736 0x9244, 0xffffffff, 0x00000011,
737 0x9248, 0xffffffff, 0x0010000f,
738 0x924c, 0xffffffff, 0x00130012,
739 0x9250, 0xffffffff, 0x000d000c,
740 0x9254, 0xffffffff, 0x000f000e,
741 0x9258, 0xffffffff, 0x00100013,
742 0x925c, 0xffffffff, 0x00120011,
743 0x9260, 0xffffffff, 0x00150014,
744 0x9150, 0xffffffff, 0x96940200,
745 0x8708, 0xffffffff, 0x00900100,
746 0xc478, 0xffffffff, 0x00000080,
747 0xc404, 0xffffffff, 0x0020003f,
748 0x30, 0xffffffff, 0x0000001c,
749 0x34, 0x000f0000, 0x000f0000,
750 0x160c, 0xffffffff, 0x00000100,
751 0x1024, 0xffffffff, 0x00000100,
752 0x102c, 0x00000101, 0x00000000,
753 0x20a8, 0xffffffff, 0x00000104,
754 0x55e4, 0xff000fff, 0x00000100,
755 0x55e8, 0x00000001, 0x00000001,
756 0x2f50, 0x00000001, 0x00000001,
757 0x30cc, 0xc0000fff, 0x00000104,
758 0xc1e4, 0x00000001, 0x00000001,
759 0xd0c0, 0xfffffff0, 0x00000100,
760 0xd8c0, 0xfffffff0, 0x00000100
761};
762
763static const u32 verde_mgcg_cgcg_init[] =
764{
765 0xc400, 0xffffffff, 0xfffffffc,
766 0x802c, 0xffffffff, 0xe0000000,
767 0x9a60, 0xffffffff, 0x00000100,
768 0x92a4, 0xffffffff, 0x00000100,
769 0xc164, 0xffffffff, 0x00000100,
770 0x9774, 0xffffffff, 0x00000100,
771 0x8984, 0xffffffff, 0x06000100,
772 0x8a18, 0xffffffff, 0x00000100,
773 0x92a0, 0xffffffff, 0x00000100,
774 0xc380, 0xffffffff, 0x00000100,
775 0x8b28, 0xffffffff, 0x00000100,
776 0x9144, 0xffffffff, 0x00000100,
777 0x8d88, 0xffffffff, 0x00000100,
778 0x8d8c, 0xffffffff, 0x00000100,
779 0x9030, 0xffffffff, 0x00000100,
780 0x9034, 0xffffffff, 0x00000100,
781 0x9038, 0xffffffff, 0x00000100,
782 0x903c, 0xffffffff, 0x00000100,
783 0xad80, 0xffffffff, 0x00000100,
784 0xac54, 0xffffffff, 0x00000100,
785 0x897c, 0xffffffff, 0x06000100,
786 0x9868, 0xffffffff, 0x00000100,
787 0x9510, 0xffffffff, 0x00000100,
788 0xaf04, 0xffffffff, 0x00000100,
789 0xae04, 0xffffffff, 0x00000100,
790 0x949c, 0xffffffff, 0x00000100,
791 0x802c, 0xffffffff, 0xe0000000,
792 0x9160, 0xffffffff, 0x00010000,
793 0x9164, 0xffffffff, 0x00030002,
794 0x9168, 0xffffffff, 0x00040007,
795 0x916c, 0xffffffff, 0x00060005,
796 0x9170, 0xffffffff, 0x00090008,
797 0x9174, 0xffffffff, 0x00020001,
798 0x9178, 0xffffffff, 0x00040003,
799 0x917c, 0xffffffff, 0x00000007,
800 0x9180, 0xffffffff, 0x00060005,
801 0x9184, 0xffffffff, 0x00090008,
802 0x9188, 0xffffffff, 0x00030002,
803 0x918c, 0xffffffff, 0x00050004,
804 0x9190, 0xffffffff, 0x00000008,
805 0x9194, 0xffffffff, 0x00070006,
806 0x9198, 0xffffffff, 0x000a0009,
807 0x919c, 0xffffffff, 0x00040003,
808 0x91a0, 0xffffffff, 0x00060005,
809 0x91a4, 0xffffffff, 0x00000009,
810 0x91a8, 0xffffffff, 0x00080007,
811 0x91ac, 0xffffffff, 0x000b000a,
812 0x91b0, 0xffffffff, 0x00050004,
813 0x91b4, 0xffffffff, 0x00070006,
814 0x91b8, 0xffffffff, 0x0008000b,
815 0x91bc, 0xffffffff, 0x000a0009,
816 0x91c0, 0xffffffff, 0x000d000c,
817 0x9200, 0xffffffff, 0x00090008,
818 0x9204, 0xffffffff, 0x000b000a,
819 0x9208, 0xffffffff, 0x000c000f,
820 0x920c, 0xffffffff, 0x000e000d,
821 0x9210, 0xffffffff, 0x00110010,
822 0x9214, 0xffffffff, 0x000a0009,
823 0x9218, 0xffffffff, 0x000c000b,
824 0x921c, 0xffffffff, 0x0000000f,
825 0x9220, 0xffffffff, 0x000e000d,
826 0x9224, 0xffffffff, 0x00110010,
827 0x9228, 0xffffffff, 0x000b000a,
828 0x922c, 0xffffffff, 0x000d000c,
829 0x9230, 0xffffffff, 0x00000010,
830 0x9234, 0xffffffff, 0x000f000e,
831 0x9238, 0xffffffff, 0x00120011,
832 0x923c, 0xffffffff, 0x000c000b,
833 0x9240, 0xffffffff, 0x000e000d,
834 0x9244, 0xffffffff, 0x00000011,
835 0x9248, 0xffffffff, 0x0010000f,
836 0x924c, 0xffffffff, 0x00130012,
837 0x9250, 0xffffffff, 0x000d000c,
838 0x9254, 0xffffffff, 0x000f000e,
839 0x9258, 0xffffffff, 0x00100013,
840 0x925c, 0xffffffff, 0x00120011,
841 0x9260, 0xffffffff, 0x00150014,
842 0x9150, 0xffffffff, 0x96940200,
843 0x8708, 0xffffffff, 0x00900100,
844 0xc478, 0xffffffff, 0x00000080,
845 0xc404, 0xffffffff, 0x0020003f,
846 0x30, 0xffffffff, 0x0000001c,
847 0x34, 0x000f0000, 0x000f0000,
848 0x160c, 0xffffffff, 0x00000100,
849 0x1024, 0xffffffff, 0x00000100,
850 0x102c, 0x00000101, 0x00000000,
851 0x20a8, 0xffffffff, 0x00000104,
852 0x264c, 0x000c0000, 0x000c0000,
853 0x2648, 0x000c0000, 0x000c0000,
854 0x55e4, 0xff000fff, 0x00000100,
855 0x55e8, 0x00000001, 0x00000001,
856 0x2f50, 0x00000001, 0x00000001,
857 0x30cc, 0xc0000fff, 0x00000104,
858 0xc1e4, 0x00000001, 0x00000001,
859 0xd0c0, 0xfffffff0, 0x00000100,
860 0xd8c0, 0xfffffff0, 0x00000100
861};
862
863static const u32 oland_mgcg_cgcg_init[] =
864{
865 0xc400, 0xffffffff, 0xfffffffc,
866 0x802c, 0xffffffff, 0xe0000000,
867 0x9a60, 0xffffffff, 0x00000100,
868 0x92a4, 0xffffffff, 0x00000100,
869 0xc164, 0xffffffff, 0x00000100,
870 0x9774, 0xffffffff, 0x00000100,
871 0x8984, 0xffffffff, 0x06000100,
872 0x8a18, 0xffffffff, 0x00000100,
873 0x92a0, 0xffffffff, 0x00000100,
874 0xc380, 0xffffffff, 0x00000100,
875 0x8b28, 0xffffffff, 0x00000100,
876 0x9144, 0xffffffff, 0x00000100,
877 0x8d88, 0xffffffff, 0x00000100,
878 0x8d8c, 0xffffffff, 0x00000100,
879 0x9030, 0xffffffff, 0x00000100,
880 0x9034, 0xffffffff, 0x00000100,
881 0x9038, 0xffffffff, 0x00000100,
882 0x903c, 0xffffffff, 0x00000100,
883 0xad80, 0xffffffff, 0x00000100,
884 0xac54, 0xffffffff, 0x00000100,
885 0x897c, 0xffffffff, 0x06000100,
886 0x9868, 0xffffffff, 0x00000100,
887 0x9510, 0xffffffff, 0x00000100,
888 0xaf04, 0xffffffff, 0x00000100,
889 0xae04, 0xffffffff, 0x00000100,
890 0x949c, 0xffffffff, 0x00000100,
891 0x802c, 0xffffffff, 0xe0000000,
892 0x9160, 0xffffffff, 0x00010000,
893 0x9164, 0xffffffff, 0x00030002,
894 0x9168, 0xffffffff, 0x00040007,
895 0x916c, 0xffffffff, 0x00060005,
896 0x9170, 0xffffffff, 0x00090008,
897 0x9174, 0xffffffff, 0x00020001,
898 0x9178, 0xffffffff, 0x00040003,
899 0x917c, 0xffffffff, 0x00000007,
900 0x9180, 0xffffffff, 0x00060005,
901 0x9184, 0xffffffff, 0x00090008,
902 0x9188, 0xffffffff, 0x00030002,
903 0x918c, 0xffffffff, 0x00050004,
904 0x9190, 0xffffffff, 0x00000008,
905 0x9194, 0xffffffff, 0x00070006,
906 0x9198, 0xffffffff, 0x000a0009,
907 0x919c, 0xffffffff, 0x00040003,
908 0x91a0, 0xffffffff, 0x00060005,
909 0x91a4, 0xffffffff, 0x00000009,
910 0x91a8, 0xffffffff, 0x00080007,
911 0x91ac, 0xffffffff, 0x000b000a,
912 0x91b0, 0xffffffff, 0x00050004,
913 0x91b4, 0xffffffff, 0x00070006,
914 0x91b8, 0xffffffff, 0x0008000b,
915 0x91bc, 0xffffffff, 0x000a0009,
916 0x91c0, 0xffffffff, 0x000d000c,
917 0x91c4, 0xffffffff, 0x00060005,
918 0x91c8, 0xffffffff, 0x00080007,
919 0x91cc, 0xffffffff, 0x0000000b,
920 0x91d0, 0xffffffff, 0x000a0009,
921 0x91d4, 0xffffffff, 0x000d000c,
922 0x9150, 0xffffffff, 0x96940200,
923 0x8708, 0xffffffff, 0x00900100,
924 0xc478, 0xffffffff, 0x00000080,
925 0xc404, 0xffffffff, 0x0020003f,
926 0x30, 0xffffffff, 0x0000001c,
927 0x34, 0x000f0000, 0x000f0000,
928 0x160c, 0xffffffff, 0x00000100,
929 0x1024, 0xffffffff, 0x00000100,
930 0x102c, 0x00000101, 0x00000000,
931 0x20a8, 0xffffffff, 0x00000104,
932 0x264c, 0x000c0000, 0x000c0000,
933 0x2648, 0x000c0000, 0x000c0000,
934 0x55e4, 0xff000fff, 0x00000100,
935 0x55e8, 0x00000001, 0x00000001,
936 0x2f50, 0x00000001, 0x00000001,
937 0x30cc, 0xc0000fff, 0x00000104,
938 0xc1e4, 0x00000001, 0x00000001,
939 0xd0c0, 0xfffffff0, 0x00000100,
940 0xd8c0, 0xfffffff0, 0x00000100
941};
942
Alex Deucherfffbdda2013-05-13 13:36:23 -0400943static const u32 hainan_mgcg_cgcg_init[] =
944{
945 0xc400, 0xffffffff, 0xfffffffc,
946 0x802c, 0xffffffff, 0xe0000000,
947 0x9a60, 0xffffffff, 0x00000100,
948 0x92a4, 0xffffffff, 0x00000100,
949 0xc164, 0xffffffff, 0x00000100,
950 0x9774, 0xffffffff, 0x00000100,
951 0x8984, 0xffffffff, 0x06000100,
952 0x8a18, 0xffffffff, 0x00000100,
953 0x92a0, 0xffffffff, 0x00000100,
954 0xc380, 0xffffffff, 0x00000100,
955 0x8b28, 0xffffffff, 0x00000100,
956 0x9144, 0xffffffff, 0x00000100,
957 0x8d88, 0xffffffff, 0x00000100,
958 0x8d8c, 0xffffffff, 0x00000100,
959 0x9030, 0xffffffff, 0x00000100,
960 0x9034, 0xffffffff, 0x00000100,
961 0x9038, 0xffffffff, 0x00000100,
962 0x903c, 0xffffffff, 0x00000100,
963 0xad80, 0xffffffff, 0x00000100,
964 0xac54, 0xffffffff, 0x00000100,
965 0x897c, 0xffffffff, 0x06000100,
966 0x9868, 0xffffffff, 0x00000100,
967 0x9510, 0xffffffff, 0x00000100,
968 0xaf04, 0xffffffff, 0x00000100,
969 0xae04, 0xffffffff, 0x00000100,
970 0x949c, 0xffffffff, 0x00000100,
971 0x802c, 0xffffffff, 0xe0000000,
972 0x9160, 0xffffffff, 0x00010000,
973 0x9164, 0xffffffff, 0x00030002,
974 0x9168, 0xffffffff, 0x00040007,
975 0x916c, 0xffffffff, 0x00060005,
976 0x9170, 0xffffffff, 0x00090008,
977 0x9174, 0xffffffff, 0x00020001,
978 0x9178, 0xffffffff, 0x00040003,
979 0x917c, 0xffffffff, 0x00000007,
980 0x9180, 0xffffffff, 0x00060005,
981 0x9184, 0xffffffff, 0x00090008,
982 0x9188, 0xffffffff, 0x00030002,
983 0x918c, 0xffffffff, 0x00050004,
984 0x9190, 0xffffffff, 0x00000008,
985 0x9194, 0xffffffff, 0x00070006,
986 0x9198, 0xffffffff, 0x000a0009,
987 0x919c, 0xffffffff, 0x00040003,
988 0x91a0, 0xffffffff, 0x00060005,
989 0x91a4, 0xffffffff, 0x00000009,
990 0x91a8, 0xffffffff, 0x00080007,
991 0x91ac, 0xffffffff, 0x000b000a,
992 0x91b0, 0xffffffff, 0x00050004,
993 0x91b4, 0xffffffff, 0x00070006,
994 0x91b8, 0xffffffff, 0x0008000b,
995 0x91bc, 0xffffffff, 0x000a0009,
996 0x91c0, 0xffffffff, 0x000d000c,
997 0x91c4, 0xffffffff, 0x00060005,
998 0x91c8, 0xffffffff, 0x00080007,
999 0x91cc, 0xffffffff, 0x0000000b,
1000 0x91d0, 0xffffffff, 0x000a0009,
1001 0x91d4, 0xffffffff, 0x000d000c,
1002 0x9150, 0xffffffff, 0x96940200,
1003 0x8708, 0xffffffff, 0x00900100,
1004 0xc478, 0xffffffff, 0x00000080,
1005 0xc404, 0xffffffff, 0x0020003f,
1006 0x30, 0xffffffff, 0x0000001c,
1007 0x34, 0x000f0000, 0x000f0000,
1008 0x160c, 0xffffffff, 0x00000100,
1009 0x1024, 0xffffffff, 0x00000100,
1010 0x20a8, 0xffffffff, 0x00000104,
1011 0x264c, 0x000c0000, 0x000c0000,
1012 0x2648, 0x000c0000, 0x000c0000,
1013 0x2f50, 0x00000001, 0x00000001,
1014 0x30cc, 0xc0000fff, 0x00000104,
1015 0xc1e4, 0x00000001, 0x00000001,
1016 0xd0c0, 0xfffffff0, 0x00000100,
1017 0xd8c0, 0xfffffff0, 0x00000100
1018};
1019
Alex Deucher205996c2013-03-01 17:08:42 -05001020static u32 verde_pg_init[] =
1021{
1022 0x353c, 0xffffffff, 0x40000,
1023 0x3538, 0xffffffff, 0x200010ff,
1024 0x353c, 0xffffffff, 0x0,
1025 0x353c, 0xffffffff, 0x0,
1026 0x353c, 0xffffffff, 0x0,
1027 0x353c, 0xffffffff, 0x0,
1028 0x353c, 0xffffffff, 0x0,
1029 0x353c, 0xffffffff, 0x7007,
1030 0x3538, 0xffffffff, 0x300010ff,
1031 0x353c, 0xffffffff, 0x0,
1032 0x353c, 0xffffffff, 0x0,
1033 0x353c, 0xffffffff, 0x0,
1034 0x353c, 0xffffffff, 0x0,
1035 0x353c, 0xffffffff, 0x0,
1036 0x353c, 0xffffffff, 0x400000,
1037 0x3538, 0xffffffff, 0x100010ff,
1038 0x353c, 0xffffffff, 0x0,
1039 0x353c, 0xffffffff, 0x0,
1040 0x353c, 0xffffffff, 0x0,
1041 0x353c, 0xffffffff, 0x0,
1042 0x353c, 0xffffffff, 0x0,
1043 0x353c, 0xffffffff, 0x120200,
1044 0x3538, 0xffffffff, 0x500010ff,
1045 0x353c, 0xffffffff, 0x0,
1046 0x353c, 0xffffffff, 0x0,
1047 0x353c, 0xffffffff, 0x0,
1048 0x353c, 0xffffffff, 0x0,
1049 0x353c, 0xffffffff, 0x0,
1050 0x353c, 0xffffffff, 0x1e1e16,
1051 0x3538, 0xffffffff, 0x600010ff,
1052 0x353c, 0xffffffff, 0x0,
1053 0x353c, 0xffffffff, 0x0,
1054 0x353c, 0xffffffff, 0x0,
1055 0x353c, 0xffffffff, 0x0,
1056 0x353c, 0xffffffff, 0x0,
1057 0x353c, 0xffffffff, 0x171f1e,
1058 0x3538, 0xffffffff, 0x700010ff,
1059 0x353c, 0xffffffff, 0x0,
1060 0x353c, 0xffffffff, 0x0,
1061 0x353c, 0xffffffff, 0x0,
1062 0x353c, 0xffffffff, 0x0,
1063 0x353c, 0xffffffff, 0x0,
1064 0x353c, 0xffffffff, 0x0,
1065 0x3538, 0xffffffff, 0x9ff,
1066 0x3500, 0xffffffff, 0x0,
1067 0x3504, 0xffffffff, 0x10000800,
1068 0x3504, 0xffffffff, 0xf,
1069 0x3504, 0xffffffff, 0xf,
1070 0x3500, 0xffffffff, 0x4,
1071 0x3504, 0xffffffff, 0x1000051e,
1072 0x3504, 0xffffffff, 0xffff,
1073 0x3504, 0xffffffff, 0xffff,
1074 0x3500, 0xffffffff, 0x8,
1075 0x3504, 0xffffffff, 0x80500,
1076 0x3500, 0xffffffff, 0x12,
1077 0x3504, 0xffffffff, 0x9050c,
1078 0x3500, 0xffffffff, 0x1d,
1079 0x3504, 0xffffffff, 0xb052c,
1080 0x3500, 0xffffffff, 0x2a,
1081 0x3504, 0xffffffff, 0x1053e,
1082 0x3500, 0xffffffff, 0x2d,
1083 0x3504, 0xffffffff, 0x10546,
1084 0x3500, 0xffffffff, 0x30,
1085 0x3504, 0xffffffff, 0xa054e,
1086 0x3500, 0xffffffff, 0x3c,
1087 0x3504, 0xffffffff, 0x1055f,
1088 0x3500, 0xffffffff, 0x3f,
1089 0x3504, 0xffffffff, 0x10567,
1090 0x3500, 0xffffffff, 0x42,
1091 0x3504, 0xffffffff, 0x1056f,
1092 0x3500, 0xffffffff, 0x45,
1093 0x3504, 0xffffffff, 0x10572,
1094 0x3500, 0xffffffff, 0x48,
1095 0x3504, 0xffffffff, 0x20575,
1096 0x3500, 0xffffffff, 0x4c,
1097 0x3504, 0xffffffff, 0x190801,
1098 0x3500, 0xffffffff, 0x67,
1099 0x3504, 0xffffffff, 0x1082a,
1100 0x3500, 0xffffffff, 0x6a,
1101 0x3504, 0xffffffff, 0x1b082d,
1102 0x3500, 0xffffffff, 0x87,
1103 0x3504, 0xffffffff, 0x310851,
1104 0x3500, 0xffffffff, 0xba,
1105 0x3504, 0xffffffff, 0x891,
1106 0x3500, 0xffffffff, 0xbc,
1107 0x3504, 0xffffffff, 0x893,
1108 0x3500, 0xffffffff, 0xbe,
1109 0x3504, 0xffffffff, 0x20895,
1110 0x3500, 0xffffffff, 0xc2,
1111 0x3504, 0xffffffff, 0x20899,
1112 0x3500, 0xffffffff, 0xc6,
1113 0x3504, 0xffffffff, 0x2089d,
1114 0x3500, 0xffffffff, 0xca,
1115 0x3504, 0xffffffff, 0x8a1,
1116 0x3500, 0xffffffff, 0xcc,
1117 0x3504, 0xffffffff, 0x8a3,
1118 0x3500, 0xffffffff, 0xce,
1119 0x3504, 0xffffffff, 0x308a5,
1120 0x3500, 0xffffffff, 0xd3,
1121 0x3504, 0xffffffff, 0x6d08cd,
1122 0x3500, 0xffffffff, 0x142,
1123 0x3504, 0xffffffff, 0x2000095a,
1124 0x3504, 0xffffffff, 0x1,
1125 0x3500, 0xffffffff, 0x144,
1126 0x3504, 0xffffffff, 0x301f095b,
1127 0x3500, 0xffffffff, 0x165,
1128 0x3504, 0xffffffff, 0xc094d,
1129 0x3500, 0xffffffff, 0x173,
1130 0x3504, 0xffffffff, 0xf096d,
1131 0x3500, 0xffffffff, 0x184,
1132 0x3504, 0xffffffff, 0x15097f,
1133 0x3500, 0xffffffff, 0x19b,
1134 0x3504, 0xffffffff, 0xc0998,
1135 0x3500, 0xffffffff, 0x1a9,
1136 0x3504, 0xffffffff, 0x409a7,
1137 0x3500, 0xffffffff, 0x1af,
1138 0x3504, 0xffffffff, 0xcdc,
1139 0x3500, 0xffffffff, 0x1b1,
1140 0x3504, 0xffffffff, 0x800,
1141 0x3508, 0xffffffff, 0x6c9b2000,
1142 0x3510, 0xfc00, 0x2000,
1143 0x3544, 0xffffffff, 0xfc0,
1144 0x28d4, 0x00000100, 0x100
1145};
1146
1147static void si_init_golden_registers(struct radeon_device *rdev)
1148{
1149 switch (rdev->family) {
1150 case CHIP_TAHITI:
1151 radeon_program_register_sequence(rdev,
1152 tahiti_golden_registers,
1153 (const u32)ARRAY_SIZE(tahiti_golden_registers));
1154 radeon_program_register_sequence(rdev,
1155 tahiti_golden_rlc_registers,
1156 (const u32)ARRAY_SIZE(tahiti_golden_rlc_registers));
1157 radeon_program_register_sequence(rdev,
1158 tahiti_mgcg_cgcg_init,
1159 (const u32)ARRAY_SIZE(tahiti_mgcg_cgcg_init));
1160 radeon_program_register_sequence(rdev,
1161 tahiti_golden_registers2,
1162 (const u32)ARRAY_SIZE(tahiti_golden_registers2));
1163 break;
1164 case CHIP_PITCAIRN:
1165 radeon_program_register_sequence(rdev,
1166 pitcairn_golden_registers,
1167 (const u32)ARRAY_SIZE(pitcairn_golden_registers));
1168 radeon_program_register_sequence(rdev,
1169 pitcairn_golden_rlc_registers,
1170 (const u32)ARRAY_SIZE(pitcairn_golden_rlc_registers));
1171 radeon_program_register_sequence(rdev,
1172 pitcairn_mgcg_cgcg_init,
1173 (const u32)ARRAY_SIZE(pitcairn_mgcg_cgcg_init));
1174 break;
1175 case CHIP_VERDE:
1176 radeon_program_register_sequence(rdev,
1177 verde_golden_registers,
1178 (const u32)ARRAY_SIZE(verde_golden_registers));
1179 radeon_program_register_sequence(rdev,
1180 verde_golden_rlc_registers,
1181 (const u32)ARRAY_SIZE(verde_golden_rlc_registers));
1182 radeon_program_register_sequence(rdev,
1183 verde_mgcg_cgcg_init,
1184 (const u32)ARRAY_SIZE(verde_mgcg_cgcg_init));
1185 radeon_program_register_sequence(rdev,
1186 verde_pg_init,
1187 (const u32)ARRAY_SIZE(verde_pg_init));
1188 break;
1189 case CHIP_OLAND:
1190 radeon_program_register_sequence(rdev,
1191 oland_golden_registers,
1192 (const u32)ARRAY_SIZE(oland_golden_registers));
1193 radeon_program_register_sequence(rdev,
1194 oland_golden_rlc_registers,
1195 (const u32)ARRAY_SIZE(oland_golden_rlc_registers));
1196 radeon_program_register_sequence(rdev,
1197 oland_mgcg_cgcg_init,
1198 (const u32)ARRAY_SIZE(oland_mgcg_cgcg_init));
1199 break;
Alex Deucherfffbdda2013-05-13 13:36:23 -04001200 case CHIP_HAINAN:
1201 radeon_program_register_sequence(rdev,
1202 hainan_golden_registers,
1203 (const u32)ARRAY_SIZE(hainan_golden_registers));
1204 radeon_program_register_sequence(rdev,
1205 hainan_golden_registers2,
1206 (const u32)ARRAY_SIZE(hainan_golden_registers2));
1207 radeon_program_register_sequence(rdev,
1208 hainan_mgcg_cgcg_init,
1209 (const u32)ARRAY_SIZE(hainan_mgcg_cgcg_init));
1210 break;
Alex Deucher205996c2013-03-01 17:08:42 -05001211 default:
1212 break;
1213 }
1214}
1215
Alex Deucher454d2e22013-02-14 10:04:02 -05001216#define PCIE_BUS_CLK 10000
1217#define TCLK (PCIE_BUS_CLK / 10)
1218
1219/**
1220 * si_get_xclk - get the xclk
1221 *
1222 * @rdev: radeon_device pointer
1223 *
1224 * Returns the reference clock used by the gfx engine
1225 * (SI).
1226 */
1227u32 si_get_xclk(struct radeon_device *rdev)
1228{
1229 u32 reference_clock = rdev->clock.spll.reference_freq;
1230 u32 tmp;
1231
1232 tmp = RREG32(CG_CLKPIN_CNTL_2);
1233 if (tmp & MUX_TCLK_TO_XCLK)
1234 return TCLK;
1235
1236 tmp = RREG32(CG_CLKPIN_CNTL);
1237 if (tmp & XTALIN_DIVIDE)
1238 return reference_clock / 4;
1239
1240 return reference_clock;
1241}
1242
Alex Deucher1bd47d22012-03-20 17:18:10 -04001243/* get temperature in millidegrees */
1244int si_get_temp(struct radeon_device *rdev)
1245{
1246 u32 temp;
1247 int actual_temp = 0;
1248
1249 temp = (RREG32(CG_MULT_THERMAL_STATUS) & CTF_TEMP_MASK) >>
1250 CTF_TEMP_SHIFT;
1251
1252 if (temp & 0x200)
1253 actual_temp = 255;
1254 else
1255 actual_temp = temp & 0x1ff;
1256
1257 actual_temp = (actual_temp * 1000);
1258
1259 return actual_temp;
1260}
1261
Alex Deucher8b074dd2012-03-20 17:18:18 -04001262#define TAHITI_IO_MC_REGS_SIZE 36
1263
1264static const u32 tahiti_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
1265 {0x0000006f, 0x03044000},
1266 {0x00000070, 0x0480c018},
1267 {0x00000071, 0x00000040},
1268 {0x00000072, 0x01000000},
1269 {0x00000074, 0x000000ff},
1270 {0x00000075, 0x00143400},
1271 {0x00000076, 0x08ec0800},
1272 {0x00000077, 0x040000cc},
1273 {0x00000079, 0x00000000},
1274 {0x0000007a, 0x21000409},
1275 {0x0000007c, 0x00000000},
1276 {0x0000007d, 0xe8000000},
1277 {0x0000007e, 0x044408a8},
1278 {0x0000007f, 0x00000003},
1279 {0x00000080, 0x00000000},
1280 {0x00000081, 0x01000000},
1281 {0x00000082, 0x02000000},
1282 {0x00000083, 0x00000000},
1283 {0x00000084, 0xe3f3e4f4},
1284 {0x00000085, 0x00052024},
1285 {0x00000087, 0x00000000},
1286 {0x00000088, 0x66036603},
1287 {0x00000089, 0x01000000},
1288 {0x0000008b, 0x1c0a0000},
1289 {0x0000008c, 0xff010000},
1290 {0x0000008e, 0xffffefff},
1291 {0x0000008f, 0xfff3efff},
1292 {0x00000090, 0xfff3efbf},
1293 {0x00000094, 0x00101101},
1294 {0x00000095, 0x00000fff},
1295 {0x00000096, 0x00116fff},
1296 {0x00000097, 0x60010000},
1297 {0x00000098, 0x10010000},
1298 {0x00000099, 0x00006000},
1299 {0x0000009a, 0x00001000},
1300 {0x0000009f, 0x00a77400}
1301};
1302
1303static const u32 pitcairn_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
1304 {0x0000006f, 0x03044000},
1305 {0x00000070, 0x0480c018},
1306 {0x00000071, 0x00000040},
1307 {0x00000072, 0x01000000},
1308 {0x00000074, 0x000000ff},
1309 {0x00000075, 0x00143400},
1310 {0x00000076, 0x08ec0800},
1311 {0x00000077, 0x040000cc},
1312 {0x00000079, 0x00000000},
1313 {0x0000007a, 0x21000409},
1314 {0x0000007c, 0x00000000},
1315 {0x0000007d, 0xe8000000},
1316 {0x0000007e, 0x044408a8},
1317 {0x0000007f, 0x00000003},
1318 {0x00000080, 0x00000000},
1319 {0x00000081, 0x01000000},
1320 {0x00000082, 0x02000000},
1321 {0x00000083, 0x00000000},
1322 {0x00000084, 0xe3f3e4f4},
1323 {0x00000085, 0x00052024},
1324 {0x00000087, 0x00000000},
1325 {0x00000088, 0x66036603},
1326 {0x00000089, 0x01000000},
1327 {0x0000008b, 0x1c0a0000},
1328 {0x0000008c, 0xff010000},
1329 {0x0000008e, 0xffffefff},
1330 {0x0000008f, 0xfff3efff},
1331 {0x00000090, 0xfff3efbf},
1332 {0x00000094, 0x00101101},
1333 {0x00000095, 0x00000fff},
1334 {0x00000096, 0x00116fff},
1335 {0x00000097, 0x60010000},
1336 {0x00000098, 0x10010000},
1337 {0x00000099, 0x00006000},
1338 {0x0000009a, 0x00001000},
1339 {0x0000009f, 0x00a47400}
1340};
1341
1342static const u32 verde_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
1343 {0x0000006f, 0x03044000},
1344 {0x00000070, 0x0480c018},
1345 {0x00000071, 0x00000040},
1346 {0x00000072, 0x01000000},
1347 {0x00000074, 0x000000ff},
1348 {0x00000075, 0x00143400},
1349 {0x00000076, 0x08ec0800},
1350 {0x00000077, 0x040000cc},
1351 {0x00000079, 0x00000000},
1352 {0x0000007a, 0x21000409},
1353 {0x0000007c, 0x00000000},
1354 {0x0000007d, 0xe8000000},
1355 {0x0000007e, 0x044408a8},
1356 {0x0000007f, 0x00000003},
1357 {0x00000080, 0x00000000},
1358 {0x00000081, 0x01000000},
1359 {0x00000082, 0x02000000},
1360 {0x00000083, 0x00000000},
1361 {0x00000084, 0xe3f3e4f4},
1362 {0x00000085, 0x00052024},
1363 {0x00000087, 0x00000000},
1364 {0x00000088, 0x66036603},
1365 {0x00000089, 0x01000000},
1366 {0x0000008b, 0x1c0a0000},
1367 {0x0000008c, 0xff010000},
1368 {0x0000008e, 0xffffefff},
1369 {0x0000008f, 0xfff3efff},
1370 {0x00000090, 0xfff3efbf},
1371 {0x00000094, 0x00101101},
1372 {0x00000095, 0x00000fff},
1373 {0x00000096, 0x00116fff},
1374 {0x00000097, 0x60010000},
1375 {0x00000098, 0x10010000},
1376 {0x00000099, 0x00006000},
1377 {0x0000009a, 0x00001000},
1378 {0x0000009f, 0x00a37400}
1379};
1380
Alex Deucherbcc7f5d2012-07-26 18:36:28 -04001381static const u32 oland_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
1382 {0x0000006f, 0x03044000},
1383 {0x00000070, 0x0480c018},
1384 {0x00000071, 0x00000040},
1385 {0x00000072, 0x01000000},
1386 {0x00000074, 0x000000ff},
1387 {0x00000075, 0x00143400},
1388 {0x00000076, 0x08ec0800},
1389 {0x00000077, 0x040000cc},
1390 {0x00000079, 0x00000000},
1391 {0x0000007a, 0x21000409},
1392 {0x0000007c, 0x00000000},
1393 {0x0000007d, 0xe8000000},
1394 {0x0000007e, 0x044408a8},
1395 {0x0000007f, 0x00000003},
1396 {0x00000080, 0x00000000},
1397 {0x00000081, 0x01000000},
1398 {0x00000082, 0x02000000},
1399 {0x00000083, 0x00000000},
1400 {0x00000084, 0xe3f3e4f4},
1401 {0x00000085, 0x00052024},
1402 {0x00000087, 0x00000000},
1403 {0x00000088, 0x66036603},
1404 {0x00000089, 0x01000000},
1405 {0x0000008b, 0x1c0a0000},
1406 {0x0000008c, 0xff010000},
1407 {0x0000008e, 0xffffefff},
1408 {0x0000008f, 0xfff3efff},
1409 {0x00000090, 0xfff3efbf},
1410 {0x00000094, 0x00101101},
1411 {0x00000095, 0x00000fff},
1412 {0x00000096, 0x00116fff},
1413 {0x00000097, 0x60010000},
1414 {0x00000098, 0x10010000},
1415 {0x00000099, 0x00006000},
1416 {0x0000009a, 0x00001000},
1417 {0x0000009f, 0x00a17730}
1418};
1419
Alex Deucherc04c00b2012-07-31 12:57:45 -04001420static const u32 hainan_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
1421 {0x0000006f, 0x03044000},
1422 {0x00000070, 0x0480c018},
1423 {0x00000071, 0x00000040},
1424 {0x00000072, 0x01000000},
1425 {0x00000074, 0x000000ff},
1426 {0x00000075, 0x00143400},
1427 {0x00000076, 0x08ec0800},
1428 {0x00000077, 0x040000cc},
1429 {0x00000079, 0x00000000},
1430 {0x0000007a, 0x21000409},
1431 {0x0000007c, 0x00000000},
1432 {0x0000007d, 0xe8000000},
1433 {0x0000007e, 0x044408a8},
1434 {0x0000007f, 0x00000003},
1435 {0x00000080, 0x00000000},
1436 {0x00000081, 0x01000000},
1437 {0x00000082, 0x02000000},
1438 {0x00000083, 0x00000000},
1439 {0x00000084, 0xe3f3e4f4},
1440 {0x00000085, 0x00052024},
1441 {0x00000087, 0x00000000},
1442 {0x00000088, 0x66036603},
1443 {0x00000089, 0x01000000},
1444 {0x0000008b, 0x1c0a0000},
1445 {0x0000008c, 0xff010000},
1446 {0x0000008e, 0xffffefff},
1447 {0x0000008f, 0xfff3efff},
1448 {0x00000090, 0xfff3efbf},
1449 {0x00000094, 0x00101101},
1450 {0x00000095, 0x00000fff},
1451 {0x00000096, 0x00116fff},
1452 {0x00000097, 0x60010000},
1453 {0x00000098, 0x10010000},
1454 {0x00000099, 0x00006000},
1455 {0x0000009a, 0x00001000},
1456 {0x0000009f, 0x00a07730}
1457};
1458
Alex Deucher8b074dd2012-03-20 17:18:18 -04001459/* ucode loading */
1460static int si_mc_load_microcode(struct radeon_device *rdev)
1461{
1462 const __be32 *fw_data;
1463 u32 running, blackout = 0;
1464 u32 *io_mc_regs;
1465 int i, ucode_size, regs_size;
1466
1467 if (!rdev->mc_fw)
1468 return -EINVAL;
1469
1470 switch (rdev->family) {
1471 case CHIP_TAHITI:
1472 io_mc_regs = (u32 *)&tahiti_io_mc_regs;
1473 ucode_size = SI_MC_UCODE_SIZE;
1474 regs_size = TAHITI_IO_MC_REGS_SIZE;
1475 break;
1476 case CHIP_PITCAIRN:
1477 io_mc_regs = (u32 *)&pitcairn_io_mc_regs;
1478 ucode_size = SI_MC_UCODE_SIZE;
1479 regs_size = TAHITI_IO_MC_REGS_SIZE;
1480 break;
1481 case CHIP_VERDE:
1482 default:
1483 io_mc_regs = (u32 *)&verde_io_mc_regs;
1484 ucode_size = SI_MC_UCODE_SIZE;
1485 regs_size = TAHITI_IO_MC_REGS_SIZE;
1486 break;
Alex Deucherbcc7f5d2012-07-26 18:36:28 -04001487 case CHIP_OLAND:
1488 io_mc_regs = (u32 *)&oland_io_mc_regs;
1489 ucode_size = OLAND_MC_UCODE_SIZE;
1490 regs_size = TAHITI_IO_MC_REGS_SIZE;
1491 break;
Alex Deucherc04c00b2012-07-31 12:57:45 -04001492 case CHIP_HAINAN:
1493 io_mc_regs = (u32 *)&hainan_io_mc_regs;
1494 ucode_size = OLAND_MC_UCODE_SIZE;
1495 regs_size = TAHITI_IO_MC_REGS_SIZE;
1496 break;
Alex Deucher8b074dd2012-03-20 17:18:18 -04001497 }
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 Deucher0f0de062012-03-20 17:18:17 -04001545static int si_init_microcode(struct radeon_device *rdev)
1546{
Alex Deucher0f0de062012-03-20 17:18:17 -04001547 const char *chip_name;
1548 const char *rlc_chip_name;
1549 size_t pfp_req_size, me_req_size, ce_req_size, rlc_req_size, mc_req_size;
Alex Deuchera9e61412013-06-25 17:56:16 -04001550 size_t smc_req_size;
Alex Deucher0f0de062012-03-20 17:18:17 -04001551 char fw_name[30];
1552 int err;
1553
1554 DRM_DEBUG("\n");
1555
Alex Deucher0f0de062012-03-20 17:18:17 -04001556 switch (rdev->family) {
1557 case CHIP_TAHITI:
1558 chip_name = "TAHITI";
1559 rlc_chip_name = "TAHITI";
1560 pfp_req_size = SI_PFP_UCODE_SIZE * 4;
1561 me_req_size = SI_PM4_UCODE_SIZE * 4;
1562 ce_req_size = SI_CE_UCODE_SIZE * 4;
1563 rlc_req_size = SI_RLC_UCODE_SIZE * 4;
1564 mc_req_size = SI_MC_UCODE_SIZE * 4;
Alex Deuchera9e61412013-06-25 17:56:16 -04001565 smc_req_size = ALIGN(TAHITI_SMC_UCODE_SIZE, 4);
Alex Deucher0f0de062012-03-20 17:18:17 -04001566 break;
1567 case CHIP_PITCAIRN:
1568 chip_name = "PITCAIRN";
1569 rlc_chip_name = "PITCAIRN";
1570 pfp_req_size = SI_PFP_UCODE_SIZE * 4;
1571 me_req_size = SI_PM4_UCODE_SIZE * 4;
1572 ce_req_size = SI_CE_UCODE_SIZE * 4;
1573 rlc_req_size = SI_RLC_UCODE_SIZE * 4;
1574 mc_req_size = SI_MC_UCODE_SIZE * 4;
Alex Deuchera9e61412013-06-25 17:56:16 -04001575 smc_req_size = ALIGN(PITCAIRN_SMC_UCODE_SIZE, 4);
Alex Deucher0f0de062012-03-20 17:18:17 -04001576 break;
1577 case CHIP_VERDE:
1578 chip_name = "VERDE";
1579 rlc_chip_name = "VERDE";
1580 pfp_req_size = SI_PFP_UCODE_SIZE * 4;
1581 me_req_size = SI_PM4_UCODE_SIZE * 4;
1582 ce_req_size = SI_CE_UCODE_SIZE * 4;
1583 rlc_req_size = SI_RLC_UCODE_SIZE * 4;
1584 mc_req_size = SI_MC_UCODE_SIZE * 4;
Alex Deuchera9e61412013-06-25 17:56:16 -04001585 smc_req_size = ALIGN(VERDE_SMC_UCODE_SIZE, 4);
Alex Deucher0f0de062012-03-20 17:18:17 -04001586 break;
Alex Deucherbcc7f5d2012-07-26 18:36:28 -04001587 case CHIP_OLAND:
1588 chip_name = "OLAND";
1589 rlc_chip_name = "OLAND";
1590 pfp_req_size = SI_PFP_UCODE_SIZE * 4;
1591 me_req_size = SI_PM4_UCODE_SIZE * 4;
1592 ce_req_size = SI_CE_UCODE_SIZE * 4;
1593 rlc_req_size = SI_RLC_UCODE_SIZE * 4;
1594 mc_req_size = OLAND_MC_UCODE_SIZE * 4;
Alex Deuchera9e61412013-06-25 17:56:16 -04001595 smc_req_size = ALIGN(OLAND_SMC_UCODE_SIZE, 4);
Alex Deucherbcc7f5d2012-07-26 18:36:28 -04001596 break;
Alex Deucherc04c00b2012-07-31 12:57:45 -04001597 case CHIP_HAINAN:
1598 chip_name = "HAINAN";
1599 rlc_chip_name = "HAINAN";
1600 pfp_req_size = SI_PFP_UCODE_SIZE * 4;
1601 me_req_size = SI_PM4_UCODE_SIZE * 4;
1602 ce_req_size = SI_CE_UCODE_SIZE * 4;
1603 rlc_req_size = SI_RLC_UCODE_SIZE * 4;
1604 mc_req_size = OLAND_MC_UCODE_SIZE * 4;
Alex Deuchera9e61412013-06-25 17:56:16 -04001605 smc_req_size = ALIGN(HAINAN_SMC_UCODE_SIZE, 4);
Alex Deucherc04c00b2012-07-31 12:57:45 -04001606 break;
Alex Deucher0f0de062012-03-20 17:18:17 -04001607 default: BUG();
1608 }
1609
1610 DRM_INFO("Loading %s Microcode\n", chip_name);
1611
1612 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001613 err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
Alex Deucher0f0de062012-03-20 17:18:17 -04001614 if (err)
1615 goto out;
1616 if (rdev->pfp_fw->size != pfp_req_size) {
1617 printk(KERN_ERR
1618 "si_cp: Bogus length %zu in firmware \"%s\"\n",
1619 rdev->pfp_fw->size, fw_name);
1620 err = -EINVAL;
1621 goto out;
1622 }
1623
1624 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001625 err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
Alex Deucher0f0de062012-03-20 17:18:17 -04001626 if (err)
1627 goto out;
1628 if (rdev->me_fw->size != me_req_size) {
1629 printk(KERN_ERR
1630 "si_cp: Bogus length %zu in firmware \"%s\"\n",
1631 rdev->me_fw->size, fw_name);
1632 err = -EINVAL;
1633 }
1634
1635 snprintf(fw_name, sizeof(fw_name), "radeon/%s_ce.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001636 err = request_firmware(&rdev->ce_fw, fw_name, rdev->dev);
Alex Deucher0f0de062012-03-20 17:18:17 -04001637 if (err)
1638 goto out;
1639 if (rdev->ce_fw->size != ce_req_size) {
1640 printk(KERN_ERR
1641 "si_cp: Bogus length %zu in firmware \"%s\"\n",
1642 rdev->ce_fw->size, fw_name);
1643 err = -EINVAL;
1644 }
1645
1646 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001647 err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
Alex Deucher0f0de062012-03-20 17:18:17 -04001648 if (err)
1649 goto out;
1650 if (rdev->rlc_fw->size != rlc_req_size) {
1651 printk(KERN_ERR
1652 "si_rlc: Bogus length %zu in firmware \"%s\"\n",
1653 rdev->rlc_fw->size, fw_name);
1654 err = -EINVAL;
1655 }
1656
1657 snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001658 err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
Alex Deucher0f0de062012-03-20 17:18:17 -04001659 if (err)
1660 goto out;
1661 if (rdev->mc_fw->size != mc_req_size) {
1662 printk(KERN_ERR
1663 "si_mc: Bogus length %zu in firmware \"%s\"\n",
1664 rdev->mc_fw->size, fw_name);
1665 err = -EINVAL;
1666 }
1667
Alex Deuchera9e61412013-06-25 17:56:16 -04001668 snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001669 err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
Alex Deucher8a53fa22013-08-07 16:09:08 -04001670 if (err) {
1671 printk(KERN_ERR
1672 "smc: error loading firmware \"%s\"\n",
1673 fw_name);
1674 release_firmware(rdev->smc_fw);
1675 rdev->smc_fw = NULL;
1676 } else if (rdev->smc_fw->size != smc_req_size) {
Alex Deuchera9e61412013-06-25 17:56:16 -04001677 printk(KERN_ERR
1678 "si_smc: Bogus length %zu in firmware \"%s\"\n",
1679 rdev->smc_fw->size, fw_name);
1680 err = -EINVAL;
1681 }
1682
Alex Deucher0f0de062012-03-20 17:18:17 -04001683out:
Alex Deucher0f0de062012-03-20 17:18:17 -04001684 if (err) {
1685 if (err != -EINVAL)
1686 printk(KERN_ERR
1687 "si_cp: Failed to load firmware \"%s\"\n",
1688 fw_name);
1689 release_firmware(rdev->pfp_fw);
1690 rdev->pfp_fw = NULL;
1691 release_firmware(rdev->me_fw);
1692 rdev->me_fw = NULL;
1693 release_firmware(rdev->ce_fw);
1694 rdev->ce_fw = NULL;
1695 release_firmware(rdev->rlc_fw);
1696 rdev->rlc_fw = NULL;
1697 release_firmware(rdev->mc_fw);
1698 rdev->mc_fw = NULL;
Alex Deuchera9e61412013-06-25 17:56:16 -04001699 release_firmware(rdev->smc_fw);
1700 rdev->smc_fw = NULL;
Alex Deucher0f0de062012-03-20 17:18:17 -04001701 }
1702 return err;
1703}
1704
Alex Deucher43b3cd92012-03-20 17:18:00 -04001705/* watermark setup */
1706static u32 dce6_line_buffer_adjust(struct radeon_device *rdev,
1707 struct radeon_crtc *radeon_crtc,
1708 struct drm_display_mode *mode,
1709 struct drm_display_mode *other_mode)
1710{
Alex Deucher290d2452013-08-19 11:15:43 -04001711 u32 tmp, buffer_alloc, i;
1712 u32 pipe_offset = radeon_crtc->crtc_id * 0x20;
Alex Deucher43b3cd92012-03-20 17:18:00 -04001713 /*
1714 * Line Buffer Setup
1715 * There are 3 line buffers, each one shared by 2 display controllers.
1716 * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
1717 * the display controllers. The paritioning is done via one of four
1718 * preset allocations specified in bits 21:20:
1719 * 0 - half lb
1720 * 2 - whole lb, other crtc must be disabled
1721 */
1722 /* this can get tricky if we have two large displays on a paired group
1723 * of crtcs. Ideally for multiple large displays we'd assign them to
1724 * non-linked crtcs for maximum line buffer allocation.
1725 */
1726 if (radeon_crtc->base.enabled && mode) {
Alex Deucher290d2452013-08-19 11:15:43 -04001727 if (other_mode) {
Alex Deucher43b3cd92012-03-20 17:18:00 -04001728 tmp = 0; /* 1/2 */
Alex Deucher290d2452013-08-19 11:15:43 -04001729 buffer_alloc = 1;
1730 } else {
Alex Deucher43b3cd92012-03-20 17:18:00 -04001731 tmp = 2; /* whole */
Alex Deucher290d2452013-08-19 11:15:43 -04001732 buffer_alloc = 2;
1733 }
1734 } else {
Alex Deucher43b3cd92012-03-20 17:18:00 -04001735 tmp = 0;
Alex Deucher290d2452013-08-19 11:15:43 -04001736 buffer_alloc = 0;
1737 }
Alex Deucher43b3cd92012-03-20 17:18:00 -04001738
1739 WREG32(DC_LB_MEMORY_SPLIT + radeon_crtc->crtc_offset,
1740 DC_LB_MEMORY_CONFIG(tmp));
1741
Alex Deucher290d2452013-08-19 11:15:43 -04001742 WREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
1743 DMIF_BUFFERS_ALLOCATED(buffer_alloc));
1744 for (i = 0; i < rdev->usec_timeout; i++) {
1745 if (RREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
1746 DMIF_BUFFERS_ALLOCATED_COMPLETED)
1747 break;
1748 udelay(1);
1749 }
1750
Alex Deucher43b3cd92012-03-20 17:18:00 -04001751 if (radeon_crtc->base.enabled && mode) {
1752 switch (tmp) {
1753 case 0:
1754 default:
1755 return 4096 * 2;
1756 case 2:
1757 return 8192 * 2;
1758 }
1759 }
1760
1761 /* controller not enabled, so no lb used */
1762 return 0;
1763}
1764
Alex Deucherca7db222012-03-20 17:18:30 -04001765static u32 si_get_number_of_dram_channels(struct radeon_device *rdev)
Alex Deucher43b3cd92012-03-20 17:18:00 -04001766{
1767 u32 tmp = RREG32(MC_SHARED_CHMAP);
1768
1769 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
1770 case 0:
1771 default:
1772 return 1;
1773 case 1:
1774 return 2;
1775 case 2:
1776 return 4;
1777 case 3:
1778 return 8;
1779 case 4:
1780 return 3;
1781 case 5:
1782 return 6;
1783 case 6:
1784 return 10;
1785 case 7:
1786 return 12;
1787 case 8:
1788 return 16;
1789 }
1790}
1791
1792struct dce6_wm_params {
1793 u32 dram_channels; /* number of dram channels */
1794 u32 yclk; /* bandwidth per dram data pin in kHz */
1795 u32 sclk; /* engine clock in kHz */
1796 u32 disp_clk; /* display clock in kHz */
1797 u32 src_width; /* viewport width */
1798 u32 active_time; /* active display time in ns */
1799 u32 blank_time; /* blank time in ns */
1800 bool interlaced; /* mode is interlaced */
1801 fixed20_12 vsc; /* vertical scale ratio */
1802 u32 num_heads; /* number of active crtcs */
1803 u32 bytes_per_pixel; /* bytes per pixel display + overlay */
1804 u32 lb_size; /* line buffer allocated to pipe */
1805 u32 vtaps; /* vertical scaler taps */
1806};
1807
1808static u32 dce6_dram_bandwidth(struct dce6_wm_params *wm)
1809{
1810 /* Calculate raw DRAM Bandwidth */
1811 fixed20_12 dram_efficiency; /* 0.7 */
1812 fixed20_12 yclk, dram_channels, bandwidth;
1813 fixed20_12 a;
1814
1815 a.full = dfixed_const(1000);
1816 yclk.full = dfixed_const(wm->yclk);
1817 yclk.full = dfixed_div(yclk, a);
1818 dram_channels.full = dfixed_const(wm->dram_channels * 4);
1819 a.full = dfixed_const(10);
1820 dram_efficiency.full = dfixed_const(7);
1821 dram_efficiency.full = dfixed_div(dram_efficiency, a);
1822 bandwidth.full = dfixed_mul(dram_channels, yclk);
1823 bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
1824
1825 return dfixed_trunc(bandwidth);
1826}
1827
1828static u32 dce6_dram_bandwidth_for_display(struct dce6_wm_params *wm)
1829{
1830 /* Calculate DRAM Bandwidth and the part allocated to display. */
1831 fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
1832 fixed20_12 yclk, dram_channels, bandwidth;
1833 fixed20_12 a;
1834
1835 a.full = dfixed_const(1000);
1836 yclk.full = dfixed_const(wm->yclk);
1837 yclk.full = dfixed_div(yclk, a);
1838 dram_channels.full = dfixed_const(wm->dram_channels * 4);
1839 a.full = dfixed_const(10);
1840 disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
1841 disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
1842 bandwidth.full = dfixed_mul(dram_channels, yclk);
1843 bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
1844
1845 return dfixed_trunc(bandwidth);
1846}
1847
1848static u32 dce6_data_return_bandwidth(struct dce6_wm_params *wm)
1849{
1850 /* Calculate the display Data return Bandwidth */
1851 fixed20_12 return_efficiency; /* 0.8 */
1852 fixed20_12 sclk, bandwidth;
1853 fixed20_12 a;
1854
1855 a.full = dfixed_const(1000);
1856 sclk.full = dfixed_const(wm->sclk);
1857 sclk.full = dfixed_div(sclk, a);
1858 a.full = dfixed_const(10);
1859 return_efficiency.full = dfixed_const(8);
1860 return_efficiency.full = dfixed_div(return_efficiency, a);
1861 a.full = dfixed_const(32);
1862 bandwidth.full = dfixed_mul(a, sclk);
1863 bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
1864
1865 return dfixed_trunc(bandwidth);
1866}
1867
1868static u32 dce6_get_dmif_bytes_per_request(struct dce6_wm_params *wm)
1869{
1870 return 32;
1871}
1872
1873static u32 dce6_dmif_request_bandwidth(struct dce6_wm_params *wm)
1874{
1875 /* Calculate the DMIF Request Bandwidth */
1876 fixed20_12 disp_clk_request_efficiency; /* 0.8 */
1877 fixed20_12 disp_clk, sclk, bandwidth;
1878 fixed20_12 a, b1, b2;
1879 u32 min_bandwidth;
1880
1881 a.full = dfixed_const(1000);
1882 disp_clk.full = dfixed_const(wm->disp_clk);
1883 disp_clk.full = dfixed_div(disp_clk, a);
1884 a.full = dfixed_const(dce6_get_dmif_bytes_per_request(wm) / 2);
1885 b1.full = dfixed_mul(a, disp_clk);
1886
1887 a.full = dfixed_const(1000);
1888 sclk.full = dfixed_const(wm->sclk);
1889 sclk.full = dfixed_div(sclk, a);
1890 a.full = dfixed_const(dce6_get_dmif_bytes_per_request(wm));
1891 b2.full = dfixed_mul(a, sclk);
1892
1893 a.full = dfixed_const(10);
1894 disp_clk_request_efficiency.full = dfixed_const(8);
1895 disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
1896
1897 min_bandwidth = min(dfixed_trunc(b1), dfixed_trunc(b2));
1898
1899 a.full = dfixed_const(min_bandwidth);
1900 bandwidth.full = dfixed_mul(a, disp_clk_request_efficiency);
1901
1902 return dfixed_trunc(bandwidth);
1903}
1904
1905static u32 dce6_available_bandwidth(struct dce6_wm_params *wm)
1906{
1907 /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
1908 u32 dram_bandwidth = dce6_dram_bandwidth(wm);
1909 u32 data_return_bandwidth = dce6_data_return_bandwidth(wm);
1910 u32 dmif_req_bandwidth = dce6_dmif_request_bandwidth(wm);
1911
1912 return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
1913}
1914
1915static u32 dce6_average_bandwidth(struct dce6_wm_params *wm)
1916{
1917 /* Calculate the display mode Average Bandwidth
1918 * DisplayMode should contain the source and destination dimensions,
1919 * timing, etc.
1920 */
1921 fixed20_12 bpp;
1922 fixed20_12 line_time;
1923 fixed20_12 src_width;
1924 fixed20_12 bandwidth;
1925 fixed20_12 a;
1926
1927 a.full = dfixed_const(1000);
1928 line_time.full = dfixed_const(wm->active_time + wm->blank_time);
1929 line_time.full = dfixed_div(line_time, a);
1930 bpp.full = dfixed_const(wm->bytes_per_pixel);
1931 src_width.full = dfixed_const(wm->src_width);
1932 bandwidth.full = dfixed_mul(src_width, bpp);
1933 bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
1934 bandwidth.full = dfixed_div(bandwidth, line_time);
1935
1936 return dfixed_trunc(bandwidth);
1937}
1938
1939static u32 dce6_latency_watermark(struct dce6_wm_params *wm)
1940{
1941 /* First calcualte the latency in ns */
1942 u32 mc_latency = 2000; /* 2000 ns. */
1943 u32 available_bandwidth = dce6_available_bandwidth(wm);
1944 u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
1945 u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
1946 u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
1947 u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
1948 (wm->num_heads * cursor_line_pair_return_time);
1949 u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
1950 u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
1951 u32 tmp, dmif_size = 12288;
1952 fixed20_12 a, b, c;
1953
1954 if (wm->num_heads == 0)
1955 return 0;
1956
1957 a.full = dfixed_const(2);
1958 b.full = dfixed_const(1);
1959 if ((wm->vsc.full > a.full) ||
1960 ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
1961 (wm->vtaps >= 5) ||
1962 ((wm->vsc.full >= a.full) && wm->interlaced))
1963 max_src_lines_per_dst_line = 4;
1964 else
1965 max_src_lines_per_dst_line = 2;
1966
1967 a.full = dfixed_const(available_bandwidth);
1968 b.full = dfixed_const(wm->num_heads);
1969 a.full = dfixed_div(a, b);
1970
1971 b.full = dfixed_const(mc_latency + 512);
1972 c.full = dfixed_const(wm->disp_clk);
1973 b.full = dfixed_div(b, c);
1974
1975 c.full = dfixed_const(dmif_size);
1976 b.full = dfixed_div(c, b);
1977
1978 tmp = min(dfixed_trunc(a), dfixed_trunc(b));
1979
1980 b.full = dfixed_const(1000);
1981 c.full = dfixed_const(wm->disp_clk);
1982 b.full = dfixed_div(c, b);
1983 c.full = dfixed_const(wm->bytes_per_pixel);
1984 b.full = dfixed_mul(b, c);
1985
1986 lb_fill_bw = min(tmp, dfixed_trunc(b));
1987
1988 a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
1989 b.full = dfixed_const(1000);
1990 c.full = dfixed_const(lb_fill_bw);
1991 b.full = dfixed_div(c, b);
1992 a.full = dfixed_div(a, b);
1993 line_fill_time = dfixed_trunc(a);
1994
1995 if (line_fill_time < wm->active_time)
1996 return latency;
1997 else
1998 return latency + (line_fill_time - wm->active_time);
1999
2000}
2001
2002static bool dce6_average_bandwidth_vs_dram_bandwidth_for_display(struct dce6_wm_params *wm)
2003{
2004 if (dce6_average_bandwidth(wm) <=
2005 (dce6_dram_bandwidth_for_display(wm) / wm->num_heads))
2006 return true;
2007 else
2008 return false;
2009};
2010
2011static bool dce6_average_bandwidth_vs_available_bandwidth(struct dce6_wm_params *wm)
2012{
2013 if (dce6_average_bandwidth(wm) <=
2014 (dce6_available_bandwidth(wm) / wm->num_heads))
2015 return true;
2016 else
2017 return false;
2018};
2019
2020static bool dce6_check_latency_hiding(struct dce6_wm_params *wm)
2021{
2022 u32 lb_partitions = wm->lb_size / wm->src_width;
2023 u32 line_time = wm->active_time + wm->blank_time;
2024 u32 latency_tolerant_lines;
2025 u32 latency_hiding;
2026 fixed20_12 a;
2027
2028 a.full = dfixed_const(1);
2029 if (wm->vsc.full > a.full)
2030 latency_tolerant_lines = 1;
2031 else {
2032 if (lb_partitions <= (wm->vtaps + 1))
2033 latency_tolerant_lines = 1;
2034 else
2035 latency_tolerant_lines = 2;
2036 }
2037
2038 latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
2039
2040 if (dce6_latency_watermark(wm) <= latency_hiding)
2041 return true;
2042 else
2043 return false;
2044}
2045
2046static void dce6_program_watermarks(struct radeon_device *rdev,
2047 struct radeon_crtc *radeon_crtc,
2048 u32 lb_size, u32 num_heads)
2049{
2050 struct drm_display_mode *mode = &radeon_crtc->base.mode;
Alex Deucherc696e532012-05-03 10:43:25 -04002051 struct dce6_wm_params wm_low, wm_high;
2052 u32 dram_channels;
Alex Deucher43b3cd92012-03-20 17:18:00 -04002053 u32 pixel_period;
2054 u32 line_time = 0;
2055 u32 latency_watermark_a = 0, latency_watermark_b = 0;
2056 u32 priority_a_mark = 0, priority_b_mark = 0;
2057 u32 priority_a_cnt = PRIORITY_OFF;
2058 u32 priority_b_cnt = PRIORITY_OFF;
2059 u32 tmp, arb_control3;
2060 fixed20_12 a, b, c;
2061
2062 if (radeon_crtc->base.enabled && num_heads && mode) {
2063 pixel_period = 1000000 / (u32)mode->clock;
2064 line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
2065 priority_a_cnt = 0;
2066 priority_b_cnt = 0;
2067
Alex Deucherca7db222012-03-20 17:18:30 -04002068 if (rdev->family == CHIP_ARUBA)
Alex Deucherc696e532012-05-03 10:43:25 -04002069 dram_channels = evergreen_get_number_of_dram_channels(rdev);
Alex Deucherca7db222012-03-20 17:18:30 -04002070 else
Alex Deucherc696e532012-05-03 10:43:25 -04002071 dram_channels = si_get_number_of_dram_channels(rdev);
2072
2073 /* watermark for high clocks */
2074 if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
2075 wm_high.yclk =
2076 radeon_dpm_get_mclk(rdev, false) * 10;
2077 wm_high.sclk =
2078 radeon_dpm_get_sclk(rdev, false) * 10;
2079 } else {
2080 wm_high.yclk = rdev->pm.current_mclk * 10;
2081 wm_high.sclk = rdev->pm.current_sclk * 10;
2082 }
2083
2084 wm_high.disp_clk = mode->clock;
2085 wm_high.src_width = mode->crtc_hdisplay;
2086 wm_high.active_time = mode->crtc_hdisplay * pixel_period;
2087 wm_high.blank_time = line_time - wm_high.active_time;
2088 wm_high.interlaced = false;
2089 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
2090 wm_high.interlaced = true;
2091 wm_high.vsc = radeon_crtc->vsc;
2092 wm_high.vtaps = 1;
2093 if (radeon_crtc->rmx_type != RMX_OFF)
2094 wm_high.vtaps = 2;
2095 wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
2096 wm_high.lb_size = lb_size;
2097 wm_high.dram_channels = dram_channels;
2098 wm_high.num_heads = num_heads;
2099
2100 /* watermark for low clocks */
2101 if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
2102 wm_low.yclk =
2103 radeon_dpm_get_mclk(rdev, true) * 10;
2104 wm_low.sclk =
2105 radeon_dpm_get_sclk(rdev, true) * 10;
2106 } else {
2107 wm_low.yclk = rdev->pm.current_mclk * 10;
2108 wm_low.sclk = rdev->pm.current_sclk * 10;
2109 }
2110
2111 wm_low.disp_clk = mode->clock;
2112 wm_low.src_width = mode->crtc_hdisplay;
2113 wm_low.active_time = mode->crtc_hdisplay * pixel_period;
2114 wm_low.blank_time = line_time - wm_low.active_time;
2115 wm_low.interlaced = false;
2116 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
2117 wm_low.interlaced = true;
2118 wm_low.vsc = radeon_crtc->vsc;
2119 wm_low.vtaps = 1;
2120 if (radeon_crtc->rmx_type != RMX_OFF)
2121 wm_low.vtaps = 2;
2122 wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
2123 wm_low.lb_size = lb_size;
2124 wm_low.dram_channels = dram_channels;
2125 wm_low.num_heads = num_heads;
Alex Deucher43b3cd92012-03-20 17:18:00 -04002126
2127 /* set for high clocks */
Alex Deucherc696e532012-05-03 10:43:25 -04002128 latency_watermark_a = min(dce6_latency_watermark(&wm_high), (u32)65535);
Alex Deucher43b3cd92012-03-20 17:18:00 -04002129 /* set for low clocks */
Alex Deucherc696e532012-05-03 10:43:25 -04002130 latency_watermark_b = min(dce6_latency_watermark(&wm_low), (u32)65535);
Alex Deucher43b3cd92012-03-20 17:18:00 -04002131
2132 /* possibly force display priority to high */
2133 /* should really do this at mode validation time... */
Alex Deucherc696e532012-05-03 10:43:25 -04002134 if (!dce6_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
2135 !dce6_average_bandwidth_vs_available_bandwidth(&wm_high) ||
2136 !dce6_check_latency_hiding(&wm_high) ||
2137 (rdev->disp_priority == 2)) {
2138 DRM_DEBUG_KMS("force priority to high\n");
2139 priority_a_cnt |= PRIORITY_ALWAYS_ON;
2140 priority_b_cnt |= PRIORITY_ALWAYS_ON;
2141 }
2142 if (!dce6_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
2143 !dce6_average_bandwidth_vs_available_bandwidth(&wm_low) ||
2144 !dce6_check_latency_hiding(&wm_low) ||
Alex Deucher43b3cd92012-03-20 17:18:00 -04002145 (rdev->disp_priority == 2)) {
2146 DRM_DEBUG_KMS("force priority to high\n");
2147 priority_a_cnt |= PRIORITY_ALWAYS_ON;
2148 priority_b_cnt |= PRIORITY_ALWAYS_ON;
2149 }
2150
2151 a.full = dfixed_const(1000);
2152 b.full = dfixed_const(mode->clock);
2153 b.full = dfixed_div(b, a);
2154 c.full = dfixed_const(latency_watermark_a);
2155 c.full = dfixed_mul(c, b);
2156 c.full = dfixed_mul(c, radeon_crtc->hsc);
2157 c.full = dfixed_div(c, a);
2158 a.full = dfixed_const(16);
2159 c.full = dfixed_div(c, a);
2160 priority_a_mark = dfixed_trunc(c);
2161 priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
2162
2163 a.full = dfixed_const(1000);
2164 b.full = dfixed_const(mode->clock);
2165 b.full = dfixed_div(b, a);
2166 c.full = dfixed_const(latency_watermark_b);
2167 c.full = dfixed_mul(c, b);
2168 c.full = dfixed_mul(c, radeon_crtc->hsc);
2169 c.full = dfixed_div(c, a);
2170 a.full = dfixed_const(16);
2171 c.full = dfixed_div(c, a);
2172 priority_b_mark = dfixed_trunc(c);
2173 priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
2174 }
2175
2176 /* select wm A */
2177 arb_control3 = RREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset);
2178 tmp = arb_control3;
2179 tmp &= ~LATENCY_WATERMARK_MASK(3);
2180 tmp |= LATENCY_WATERMARK_MASK(1);
2181 WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, tmp);
2182 WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
2183 (LATENCY_LOW_WATERMARK(latency_watermark_a) |
2184 LATENCY_HIGH_WATERMARK(line_time)));
2185 /* select wm B */
2186 tmp = RREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset);
2187 tmp &= ~LATENCY_WATERMARK_MASK(3);
2188 tmp |= LATENCY_WATERMARK_MASK(2);
2189 WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, tmp);
2190 WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
2191 (LATENCY_LOW_WATERMARK(latency_watermark_b) |
2192 LATENCY_HIGH_WATERMARK(line_time)));
2193 /* restore original selection */
2194 WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, arb_control3);
2195
2196 /* write the priority marks */
2197 WREG32(PRIORITY_A_CNT + radeon_crtc->crtc_offset, priority_a_cnt);
2198 WREG32(PRIORITY_B_CNT + radeon_crtc->crtc_offset, priority_b_cnt);
2199
Alex Deucher7178d2a2013-03-21 10:38:49 -04002200 /* save values for DPM */
2201 radeon_crtc->line_time = line_time;
2202 radeon_crtc->wm_high = latency_watermark_a;
2203 radeon_crtc->wm_low = latency_watermark_b;
Alex Deucher43b3cd92012-03-20 17:18:00 -04002204}
2205
2206void dce6_bandwidth_update(struct radeon_device *rdev)
2207{
2208 struct drm_display_mode *mode0 = NULL;
2209 struct drm_display_mode *mode1 = NULL;
2210 u32 num_heads = 0, lb_size;
2211 int i;
2212
2213 radeon_update_display_priority(rdev);
2214
2215 for (i = 0; i < rdev->num_crtc; i++) {
2216 if (rdev->mode_info.crtcs[i]->base.enabled)
2217 num_heads++;
2218 }
2219 for (i = 0; i < rdev->num_crtc; i += 2) {
2220 mode0 = &rdev->mode_info.crtcs[i]->base.mode;
2221 mode1 = &rdev->mode_info.crtcs[i+1]->base.mode;
2222 lb_size = dce6_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode0, mode1);
2223 dce6_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
2224 lb_size = dce6_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i+1], mode1, mode0);
2225 dce6_program_watermarks(rdev, rdev->mode_info.crtcs[i+1], lb_size, num_heads);
2226 }
2227}
2228
Alex Deucher0a96d722012-03-20 17:18:11 -04002229/*
2230 * Core functions
2231 */
Alex Deucher0a96d722012-03-20 17:18:11 -04002232static void si_tiling_mode_table_init(struct radeon_device *rdev)
2233{
2234 const u32 num_tile_mode_states = 32;
2235 u32 reg_offset, gb_tile_moden, split_equal_to_row_size;
2236
2237 switch (rdev->config.si.mem_row_size_in_kb) {
2238 case 1:
2239 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_1KB;
2240 break;
2241 case 2:
2242 default:
2243 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_2KB;
2244 break;
2245 case 4:
2246 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_4KB;
2247 break;
2248 }
2249
2250 if ((rdev->family == CHIP_TAHITI) ||
2251 (rdev->family == CHIP_PITCAIRN)) {
2252 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
2253 switch (reg_offset) {
2254 case 0: /* non-AA compressed depth or any compressed stencil */
2255 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2256 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2257 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2258 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2259 NUM_BANKS(ADDR_SURF_16_BANK) |
2260 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2261 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2262 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2263 break;
2264 case 1: /* 2xAA/4xAA compressed depth only */
2265 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2266 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2267 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2268 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2269 NUM_BANKS(ADDR_SURF_16_BANK) |
2270 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2271 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2272 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2273 break;
2274 case 2: /* 8xAA compressed depth only */
2275 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2276 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2277 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2278 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2279 NUM_BANKS(ADDR_SURF_16_BANK) |
2280 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2281 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2282 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2283 break;
2284 case 3: /* 2xAA/4xAA compressed depth with stencil (for depth buffer) */
2285 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2286 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2287 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2288 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2289 NUM_BANKS(ADDR_SURF_16_BANK) |
2290 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2291 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2292 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2293 break;
2294 case 4: /* Maps w/ a dimension less than the 2D macro-tile dimensions (for mipmapped depth textures) */
2295 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2296 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2297 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2298 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2299 NUM_BANKS(ADDR_SURF_16_BANK) |
2300 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2301 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2302 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2303 break;
2304 case 5: /* Uncompressed 16bpp depth - and stencil buffer allocated with it */
2305 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2306 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2307 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2308 TILE_SPLIT(split_equal_to_row_size) |
2309 NUM_BANKS(ADDR_SURF_16_BANK) |
2310 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2311 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2312 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2313 break;
2314 case 6: /* Uncompressed 32bpp depth - and stencil buffer allocated with it */
2315 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2316 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2317 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2318 TILE_SPLIT(split_equal_to_row_size) |
2319 NUM_BANKS(ADDR_SURF_16_BANK) |
2320 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2321 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2322 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
2323 break;
2324 case 7: /* Uncompressed 8bpp stencil without depth (drivers typically do not use) */
2325 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2326 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2327 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2328 TILE_SPLIT(split_equal_to_row_size) |
2329 NUM_BANKS(ADDR_SURF_16_BANK) |
2330 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2331 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2332 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2333 break;
2334 case 8: /* 1D and 1D Array Surfaces */
2335 gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2336 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2337 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2338 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2339 NUM_BANKS(ADDR_SURF_16_BANK) |
2340 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2341 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2342 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2343 break;
2344 case 9: /* Displayable maps. */
2345 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2346 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2347 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2348 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2349 NUM_BANKS(ADDR_SURF_16_BANK) |
2350 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2351 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2352 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2353 break;
2354 case 10: /* Display 8bpp. */
2355 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2356 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2357 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2358 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2359 NUM_BANKS(ADDR_SURF_16_BANK) |
2360 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2361 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2362 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2363 break;
2364 case 11: /* Display 16bpp. */
2365 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2366 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2367 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2368 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2369 NUM_BANKS(ADDR_SURF_16_BANK) |
2370 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2371 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2372 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2373 break;
2374 case 12: /* Display 32bpp. */
2375 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2376 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2377 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2378 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2379 NUM_BANKS(ADDR_SURF_16_BANK) |
2380 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2381 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2382 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
2383 break;
2384 case 13: /* Thin. */
2385 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2386 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2387 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2388 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2389 NUM_BANKS(ADDR_SURF_16_BANK) |
2390 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2391 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2392 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2393 break;
2394 case 14: /* Thin 8 bpp. */
2395 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2396 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2397 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2398 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2399 NUM_BANKS(ADDR_SURF_16_BANK) |
2400 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2401 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2402 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
2403 break;
2404 case 15: /* Thin 16 bpp. */
2405 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2406 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2407 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2408 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2409 NUM_BANKS(ADDR_SURF_16_BANK) |
2410 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2411 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2412 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
2413 break;
2414 case 16: /* Thin 32 bpp. */
2415 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2416 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2417 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2418 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2419 NUM_BANKS(ADDR_SURF_16_BANK) |
2420 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2421 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2422 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
2423 break;
2424 case 17: /* Thin 64 bpp. */
2425 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2426 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2427 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2428 TILE_SPLIT(split_equal_to_row_size) |
2429 NUM_BANKS(ADDR_SURF_16_BANK) |
2430 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2431 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2432 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
2433 break;
2434 case 21: /* 8 bpp PRT. */
2435 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2436 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2437 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2438 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2439 NUM_BANKS(ADDR_SURF_16_BANK) |
2440 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2441 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2442 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2443 break;
2444 case 22: /* 16 bpp PRT */
2445 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2446 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2447 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2448 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2449 NUM_BANKS(ADDR_SURF_16_BANK) |
2450 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2451 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2452 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
2453 break;
2454 case 23: /* 32 bpp PRT */
2455 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2456 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2457 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2458 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2459 NUM_BANKS(ADDR_SURF_16_BANK) |
2460 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2461 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2462 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2463 break;
2464 case 24: /* 64 bpp PRT */
2465 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2466 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2467 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2468 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2469 NUM_BANKS(ADDR_SURF_16_BANK) |
2470 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2471 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2472 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2473 break;
2474 case 25: /* 128 bpp PRT */
2475 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2476 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2477 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2478 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_1KB) |
2479 NUM_BANKS(ADDR_SURF_8_BANK) |
2480 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2481 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2482 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
2483 break;
2484 default:
2485 gb_tile_moden = 0;
2486 break;
2487 }
Jerome Glisse64d7b8b2013-04-09 11:17:08 -04002488 rdev->config.si.tile_mode_array[reg_offset] = gb_tile_moden;
Alex Deucher0a96d722012-03-20 17:18:11 -04002489 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2490 }
Alex Deucherd0ae7fc2012-07-26 17:42:25 -04002491 } else if ((rdev->family == CHIP_VERDE) ||
Alex Deucher8b028592012-07-31 12:42:48 -04002492 (rdev->family == CHIP_OLAND) ||
2493 (rdev->family == CHIP_HAINAN)) {
Alex Deucher0a96d722012-03-20 17:18:11 -04002494 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
2495 switch (reg_offset) {
2496 case 0: /* non-AA compressed depth or any compressed stencil */
2497 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2498 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2499 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2500 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2501 NUM_BANKS(ADDR_SURF_16_BANK) |
2502 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2503 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2504 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
2505 break;
2506 case 1: /* 2xAA/4xAA compressed depth only */
2507 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2508 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2509 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2510 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2511 NUM_BANKS(ADDR_SURF_16_BANK) |
2512 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2513 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2514 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
2515 break;
2516 case 2: /* 8xAA compressed depth only */
2517 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2518 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2519 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2520 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2521 NUM_BANKS(ADDR_SURF_16_BANK) |
2522 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2523 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2524 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
2525 break;
2526 case 3: /* 2xAA/4xAA compressed depth with stencil (for depth buffer) */
2527 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2528 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2529 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2530 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2531 NUM_BANKS(ADDR_SURF_16_BANK) |
2532 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2533 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2534 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
2535 break;
2536 case 4: /* Maps w/ a dimension less than the 2D macro-tile dimensions (for mipmapped depth textures) */
2537 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2538 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2539 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2540 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2541 NUM_BANKS(ADDR_SURF_16_BANK) |
2542 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2543 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2544 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2545 break;
2546 case 5: /* Uncompressed 16bpp depth - and stencil buffer allocated with it */
2547 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2548 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2549 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2550 TILE_SPLIT(split_equal_to_row_size) |
2551 NUM_BANKS(ADDR_SURF_16_BANK) |
2552 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2553 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2554 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2555 break;
2556 case 6: /* Uncompressed 32bpp depth - and stencil buffer allocated with it */
2557 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2558 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2559 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2560 TILE_SPLIT(split_equal_to_row_size) |
2561 NUM_BANKS(ADDR_SURF_16_BANK) |
2562 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2563 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2564 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2565 break;
2566 case 7: /* Uncompressed 8bpp stencil without depth (drivers typically do not use) */
2567 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2568 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2569 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2570 TILE_SPLIT(split_equal_to_row_size) |
2571 NUM_BANKS(ADDR_SURF_16_BANK) |
2572 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2573 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2574 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
2575 break;
2576 case 8: /* 1D and 1D Array Surfaces */
2577 gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2578 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2579 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2580 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2581 NUM_BANKS(ADDR_SURF_16_BANK) |
2582 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2583 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2584 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2585 break;
2586 case 9: /* Displayable maps. */
2587 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2588 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2589 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2590 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2591 NUM_BANKS(ADDR_SURF_16_BANK) |
2592 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2593 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2594 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2595 break;
2596 case 10: /* Display 8bpp. */
2597 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2598 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2599 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2600 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2601 NUM_BANKS(ADDR_SURF_16_BANK) |
2602 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2603 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2604 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
2605 break;
2606 case 11: /* Display 16bpp. */
2607 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2608 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2609 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2610 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2611 NUM_BANKS(ADDR_SURF_16_BANK) |
2612 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2613 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2614 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2615 break;
2616 case 12: /* Display 32bpp. */
2617 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2618 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2619 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2620 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2621 NUM_BANKS(ADDR_SURF_16_BANK) |
2622 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2623 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2624 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2625 break;
2626 case 13: /* Thin. */
2627 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2628 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2629 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2630 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2631 NUM_BANKS(ADDR_SURF_16_BANK) |
2632 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2633 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2634 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2635 break;
2636 case 14: /* Thin 8 bpp. */
2637 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2638 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2639 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2640 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2641 NUM_BANKS(ADDR_SURF_16_BANK) |
2642 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2643 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2644 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2645 break;
2646 case 15: /* Thin 16 bpp. */
2647 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2648 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2649 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2650 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2651 NUM_BANKS(ADDR_SURF_16_BANK) |
2652 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2653 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2654 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2655 break;
2656 case 16: /* Thin 32 bpp. */
2657 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2658 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2659 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2660 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2661 NUM_BANKS(ADDR_SURF_16_BANK) |
2662 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2663 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2664 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2665 break;
2666 case 17: /* Thin 64 bpp. */
2667 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2668 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2669 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2670 TILE_SPLIT(split_equal_to_row_size) |
2671 NUM_BANKS(ADDR_SURF_16_BANK) |
2672 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2673 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2674 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2675 break;
2676 case 21: /* 8 bpp PRT. */
2677 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2678 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2679 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2680 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2681 NUM_BANKS(ADDR_SURF_16_BANK) |
2682 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2683 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2684 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2685 break;
2686 case 22: /* 16 bpp PRT */
2687 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2688 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2689 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2690 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2691 NUM_BANKS(ADDR_SURF_16_BANK) |
2692 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2693 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2694 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
2695 break;
2696 case 23: /* 32 bpp PRT */
2697 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2698 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2699 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2700 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2701 NUM_BANKS(ADDR_SURF_16_BANK) |
2702 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2703 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2704 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2705 break;
2706 case 24: /* 64 bpp PRT */
2707 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2708 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2709 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2710 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2711 NUM_BANKS(ADDR_SURF_16_BANK) |
2712 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2713 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2714 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2715 break;
2716 case 25: /* 128 bpp PRT */
2717 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2718 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2719 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2720 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_1KB) |
2721 NUM_BANKS(ADDR_SURF_8_BANK) |
2722 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2723 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2724 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
2725 break;
2726 default:
2727 gb_tile_moden = 0;
2728 break;
2729 }
Jerome Glisse64d7b8b2013-04-09 11:17:08 -04002730 rdev->config.si.tile_mode_array[reg_offset] = gb_tile_moden;
Alex Deucher0a96d722012-03-20 17:18:11 -04002731 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2732 }
2733 } else
2734 DRM_ERROR("unknown asic: 0x%x\n", rdev->family);
2735}
2736
Alex Deucher1a8ca752012-06-01 18:58:22 -04002737static void si_select_se_sh(struct radeon_device *rdev,
2738 u32 se_num, u32 sh_num)
2739{
2740 u32 data = INSTANCE_BROADCAST_WRITES;
2741
2742 if ((se_num == 0xffffffff) && (sh_num == 0xffffffff))
Alex Deucher79b52d62013-04-18 16:26:36 -04002743 data |= SH_BROADCAST_WRITES | SE_BROADCAST_WRITES;
Alex Deucher1a8ca752012-06-01 18:58:22 -04002744 else if (se_num == 0xffffffff)
2745 data |= SE_BROADCAST_WRITES | SH_INDEX(sh_num);
2746 else if (sh_num == 0xffffffff)
2747 data |= SH_BROADCAST_WRITES | SE_INDEX(se_num);
2748 else
2749 data |= SH_INDEX(sh_num) | SE_INDEX(se_num);
2750 WREG32(GRBM_GFX_INDEX, data);
2751}
2752
2753static u32 si_create_bitmask(u32 bit_width)
2754{
2755 u32 i, mask = 0;
2756
2757 for (i = 0; i < bit_width; i++) {
2758 mask <<= 1;
2759 mask |= 1;
2760 }
2761 return mask;
2762}
2763
2764static u32 si_get_cu_enabled(struct radeon_device *rdev, u32 cu_per_sh)
2765{
2766 u32 data, mask;
2767
2768 data = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
2769 if (data & 1)
2770 data &= INACTIVE_CUS_MASK;
2771 else
2772 data = 0;
2773 data |= RREG32(GC_USER_SHADER_ARRAY_CONFIG);
2774
2775 data >>= INACTIVE_CUS_SHIFT;
2776
2777 mask = si_create_bitmask(cu_per_sh);
2778
2779 return ~data & mask;
2780}
2781
2782static void si_setup_spi(struct radeon_device *rdev,
2783 u32 se_num, u32 sh_per_se,
2784 u32 cu_per_sh)
2785{
2786 int i, j, k;
2787 u32 data, mask, active_cu;
2788
2789 for (i = 0; i < se_num; i++) {
2790 for (j = 0; j < sh_per_se; j++) {
2791 si_select_se_sh(rdev, i, j);
2792 data = RREG32(SPI_STATIC_THREAD_MGMT_3);
2793 active_cu = si_get_cu_enabled(rdev, cu_per_sh);
2794
2795 mask = 1;
2796 for (k = 0; k < 16; k++) {
2797 mask <<= k;
2798 if (active_cu & mask) {
2799 data &= ~mask;
2800 WREG32(SPI_STATIC_THREAD_MGMT_3, data);
2801 break;
2802 }
2803 }
2804 }
2805 }
2806 si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
2807}
2808
2809static u32 si_get_rb_disabled(struct radeon_device *rdev,
2810 u32 max_rb_num, u32 se_num,
2811 u32 sh_per_se)
2812{
2813 u32 data, mask;
2814
2815 data = RREG32(CC_RB_BACKEND_DISABLE);
2816 if (data & 1)
2817 data &= BACKEND_DISABLE_MASK;
2818 else
2819 data = 0;
2820 data |= RREG32(GC_USER_RB_BACKEND_DISABLE);
2821
2822 data >>= BACKEND_DISABLE_SHIFT;
2823
2824 mask = si_create_bitmask(max_rb_num / se_num / sh_per_se);
2825
2826 return data & mask;
2827}
2828
2829static void si_setup_rb(struct radeon_device *rdev,
2830 u32 se_num, u32 sh_per_se,
2831 u32 max_rb_num)
2832{
2833 int i, j;
2834 u32 data, mask;
2835 u32 disabled_rbs = 0;
2836 u32 enabled_rbs = 0;
2837
2838 for (i = 0; i < se_num; i++) {
2839 for (j = 0; j < sh_per_se; j++) {
2840 si_select_se_sh(rdev, i, j);
2841 data = si_get_rb_disabled(rdev, max_rb_num, se_num, sh_per_se);
2842 disabled_rbs |= data << ((i * sh_per_se + j) * TAHITI_RB_BITMAP_WIDTH_PER_SH);
2843 }
2844 }
2845 si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
2846
2847 mask = 1;
2848 for (i = 0; i < max_rb_num; i++) {
2849 if (!(disabled_rbs & mask))
2850 enabled_rbs |= mask;
2851 mask <<= 1;
2852 }
2853
2854 for (i = 0; i < se_num; i++) {
2855 si_select_se_sh(rdev, i, 0xffffffff);
2856 data = 0;
2857 for (j = 0; j < sh_per_se; j++) {
2858 switch (enabled_rbs & 3) {
2859 case 1:
2860 data |= (RASTER_CONFIG_RB_MAP_0 << (i * sh_per_se + j) * 2);
2861 break;
2862 case 2:
2863 data |= (RASTER_CONFIG_RB_MAP_3 << (i * sh_per_se + j) * 2);
2864 break;
2865 case 3:
2866 default:
2867 data |= (RASTER_CONFIG_RB_MAP_2 << (i * sh_per_se + j) * 2);
2868 break;
2869 }
2870 enabled_rbs >>= 2;
2871 }
2872 WREG32(PA_SC_RASTER_CONFIG, data);
2873 }
2874 si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
2875}
2876
Alex Deucher0a96d722012-03-20 17:18:11 -04002877static void si_gpu_init(struct radeon_device *rdev)
2878{
Alex Deucher0a96d722012-03-20 17:18:11 -04002879 u32 gb_addr_config = 0;
2880 u32 mc_shared_chmap, mc_arb_ramcfg;
Alex Deucher0a96d722012-03-20 17:18:11 -04002881 u32 sx_debug_1;
Alex Deucher0a96d722012-03-20 17:18:11 -04002882 u32 hdp_host_path_cntl;
2883 u32 tmp;
2884 int i, j;
2885
2886 switch (rdev->family) {
2887 case CHIP_TAHITI:
2888 rdev->config.si.max_shader_engines = 2;
Alex Deucher0a96d722012-03-20 17:18:11 -04002889 rdev->config.si.max_tile_pipes = 12;
Alex Deucher1a8ca752012-06-01 18:58:22 -04002890 rdev->config.si.max_cu_per_sh = 8;
2891 rdev->config.si.max_sh_per_se = 2;
Alex Deucher0a96d722012-03-20 17:18:11 -04002892 rdev->config.si.max_backends_per_se = 4;
2893 rdev->config.si.max_texture_channel_caches = 12;
2894 rdev->config.si.max_gprs = 256;
2895 rdev->config.si.max_gs_threads = 32;
2896 rdev->config.si.max_hw_contexts = 8;
2897
2898 rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
2899 rdev->config.si.sc_prim_fifo_size_backend = 0x100;
2900 rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
2901 rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher1a8ca752012-06-01 18:58:22 -04002902 gb_addr_config = TAHITI_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher0a96d722012-03-20 17:18:11 -04002903 break;
2904 case CHIP_PITCAIRN:
2905 rdev->config.si.max_shader_engines = 2;
Alex Deucher0a96d722012-03-20 17:18:11 -04002906 rdev->config.si.max_tile_pipes = 8;
Alex Deucher1a8ca752012-06-01 18:58:22 -04002907 rdev->config.si.max_cu_per_sh = 5;
2908 rdev->config.si.max_sh_per_se = 2;
Alex Deucher0a96d722012-03-20 17:18:11 -04002909 rdev->config.si.max_backends_per_se = 4;
2910 rdev->config.si.max_texture_channel_caches = 8;
2911 rdev->config.si.max_gprs = 256;
2912 rdev->config.si.max_gs_threads = 32;
2913 rdev->config.si.max_hw_contexts = 8;
2914
2915 rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
2916 rdev->config.si.sc_prim_fifo_size_backend = 0x100;
2917 rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
2918 rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher1a8ca752012-06-01 18:58:22 -04002919 gb_addr_config = TAHITI_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher0a96d722012-03-20 17:18:11 -04002920 break;
2921 case CHIP_VERDE:
2922 default:
2923 rdev->config.si.max_shader_engines = 1;
Alex Deucher0a96d722012-03-20 17:18:11 -04002924 rdev->config.si.max_tile_pipes = 4;
Alex Deucher468ef1a2013-05-21 13:35:19 -04002925 rdev->config.si.max_cu_per_sh = 5;
Alex Deucher1a8ca752012-06-01 18:58:22 -04002926 rdev->config.si.max_sh_per_se = 2;
Alex Deucher0a96d722012-03-20 17:18:11 -04002927 rdev->config.si.max_backends_per_se = 4;
2928 rdev->config.si.max_texture_channel_caches = 4;
2929 rdev->config.si.max_gprs = 256;
2930 rdev->config.si.max_gs_threads = 32;
2931 rdev->config.si.max_hw_contexts = 8;
2932
2933 rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
2934 rdev->config.si.sc_prim_fifo_size_backend = 0x40;
2935 rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
2936 rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher1a8ca752012-06-01 18:58:22 -04002937 gb_addr_config = VERDE_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher0a96d722012-03-20 17:18:11 -04002938 break;
Alex Deucherd0ae7fc2012-07-26 17:42:25 -04002939 case CHIP_OLAND:
2940 rdev->config.si.max_shader_engines = 1;
2941 rdev->config.si.max_tile_pipes = 4;
2942 rdev->config.si.max_cu_per_sh = 6;
2943 rdev->config.si.max_sh_per_se = 1;
2944 rdev->config.si.max_backends_per_se = 2;
2945 rdev->config.si.max_texture_channel_caches = 4;
2946 rdev->config.si.max_gprs = 256;
2947 rdev->config.si.max_gs_threads = 16;
2948 rdev->config.si.max_hw_contexts = 8;
2949
2950 rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
2951 rdev->config.si.sc_prim_fifo_size_backend = 0x40;
2952 rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
2953 rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
2954 gb_addr_config = VERDE_GB_ADDR_CONFIG_GOLDEN;
2955 break;
Alex Deucher8b028592012-07-31 12:42:48 -04002956 case CHIP_HAINAN:
2957 rdev->config.si.max_shader_engines = 1;
2958 rdev->config.si.max_tile_pipes = 4;
2959 rdev->config.si.max_cu_per_sh = 5;
2960 rdev->config.si.max_sh_per_se = 1;
2961 rdev->config.si.max_backends_per_se = 1;
2962 rdev->config.si.max_texture_channel_caches = 2;
2963 rdev->config.si.max_gprs = 256;
2964 rdev->config.si.max_gs_threads = 16;
2965 rdev->config.si.max_hw_contexts = 8;
2966
2967 rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
2968 rdev->config.si.sc_prim_fifo_size_backend = 0x40;
2969 rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
2970 rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
2971 gb_addr_config = HAINAN_GB_ADDR_CONFIG_GOLDEN;
2972 break;
Alex Deucher0a96d722012-03-20 17:18:11 -04002973 }
2974
2975 /* Initialize HDP */
2976 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
2977 WREG32((0x2c14 + j), 0x00000000);
2978 WREG32((0x2c18 + j), 0x00000000);
2979 WREG32((0x2c1c + j), 0x00000000);
2980 WREG32((0x2c20 + j), 0x00000000);
2981 WREG32((0x2c24 + j), 0x00000000);
2982 }
2983
2984 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
2985
2986 evergreen_fix_pci_max_read_req_size(rdev);
2987
2988 WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
2989
2990 mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
2991 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
2992
Alex Deucher0a96d722012-03-20 17:18:11 -04002993 rdev->config.si.num_tile_pipes = rdev->config.si.max_tile_pipes;
Alex Deucher0a96d722012-03-20 17:18:11 -04002994 rdev->config.si.mem_max_burst_length_bytes = 256;
2995 tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
2996 rdev->config.si.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
2997 if (rdev->config.si.mem_row_size_in_kb > 4)
2998 rdev->config.si.mem_row_size_in_kb = 4;
2999 /* XXX use MC settings? */
3000 rdev->config.si.shader_engine_tile_size = 32;
3001 rdev->config.si.num_gpus = 1;
3002 rdev->config.si.multi_gpu_tile_size = 64;
3003
Alex Deucher1a8ca752012-06-01 18:58:22 -04003004 /* fix up row size */
3005 gb_addr_config &= ~ROW_SIZE_MASK;
Alex Deucher0a96d722012-03-20 17:18:11 -04003006 switch (rdev->config.si.mem_row_size_in_kb) {
3007 case 1:
3008 default:
3009 gb_addr_config |= ROW_SIZE(0);
3010 break;
3011 case 2:
3012 gb_addr_config |= ROW_SIZE(1);
3013 break;
3014 case 4:
3015 gb_addr_config |= ROW_SIZE(2);
3016 break;
3017 }
3018
Alex Deucher0a96d722012-03-20 17:18:11 -04003019 /* setup tiling info dword. gb_addr_config is not adequate since it does
3020 * not have bank info, so create a custom tiling dword.
3021 * bits 3:0 num_pipes
3022 * bits 7:4 num_banks
3023 * bits 11:8 group_size
3024 * bits 15:12 row_size
3025 */
3026 rdev->config.si.tile_config = 0;
3027 switch (rdev->config.si.num_tile_pipes) {
3028 case 1:
3029 rdev->config.si.tile_config |= (0 << 0);
3030 break;
3031 case 2:
3032 rdev->config.si.tile_config |= (1 << 0);
3033 break;
3034 case 4:
3035 rdev->config.si.tile_config |= (2 << 0);
3036 break;
3037 case 8:
3038 default:
3039 /* XXX what about 12? */
3040 rdev->config.si.tile_config |= (3 << 0);
3041 break;
Christian Königdca571a2012-07-31 13:48:51 +02003042 }
3043 switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
3044 case 0: /* four banks */
Alex Deucher1a8ca752012-06-01 18:58:22 -04003045 rdev->config.si.tile_config |= 0 << 4;
Christian Königdca571a2012-07-31 13:48:51 +02003046 break;
3047 case 1: /* eight banks */
3048 rdev->config.si.tile_config |= 1 << 4;
3049 break;
3050 case 2: /* sixteen banks */
3051 default:
3052 rdev->config.si.tile_config |= 2 << 4;
3053 break;
3054 }
Alex Deucher0a96d722012-03-20 17:18:11 -04003055 rdev->config.si.tile_config |=
3056 ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
3057 rdev->config.si.tile_config |=
3058 ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
3059
Alex Deucher0a96d722012-03-20 17:18:11 -04003060 WREG32(GB_ADDR_CONFIG, gb_addr_config);
3061 WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
Alex Deucher7c1c7c12013-04-05 10:28:08 -04003062 WREG32(DMIF_ADDR_CALC, gb_addr_config);
Alex Deucher0a96d722012-03-20 17:18:11 -04003063 WREG32(HDP_ADDR_CONFIG, gb_addr_config);
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05003064 WREG32(DMA_TILING_CONFIG + DMA0_REGISTER_OFFSET, gb_addr_config);
3065 WREG32(DMA_TILING_CONFIG + DMA1_REGISTER_OFFSET, gb_addr_config);
Alex Deucher1df0d522013-04-26 18:03:44 -04003066 if (rdev->has_uvd) {
3067 WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
3068 WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
3069 WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
3070 }
Alex Deucher0a96d722012-03-20 17:18:11 -04003071
Alex Deucher0a96d722012-03-20 17:18:11 -04003072 si_tiling_mode_table_init(rdev);
3073
Alex Deucher1a8ca752012-06-01 18:58:22 -04003074 si_setup_rb(rdev, rdev->config.si.max_shader_engines,
3075 rdev->config.si.max_sh_per_se,
3076 rdev->config.si.max_backends_per_se);
3077
3078 si_setup_spi(rdev, rdev->config.si.max_shader_engines,
3079 rdev->config.si.max_sh_per_se,
3080 rdev->config.si.max_cu_per_sh);
3081
3082
Alex Deucher0a96d722012-03-20 17:18:11 -04003083 /* set HW defaults for 3D engine */
3084 WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
3085 ROQ_IB2_START(0x2b)));
3086 WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
3087
3088 sx_debug_1 = RREG32(SX_DEBUG_1);
3089 WREG32(SX_DEBUG_1, sx_debug_1);
3090
3091 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
3092
3093 WREG32(PA_SC_FIFO_SIZE, (SC_FRONTEND_PRIM_FIFO_SIZE(rdev->config.si.sc_prim_fifo_size_frontend) |
3094 SC_BACKEND_PRIM_FIFO_SIZE(rdev->config.si.sc_prim_fifo_size_backend) |
3095 SC_HIZ_TILE_FIFO_SIZE(rdev->config.si.sc_hiz_tile_fifo_size) |
3096 SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.si.sc_earlyz_tile_fifo_size)));
3097
3098 WREG32(VGT_NUM_INSTANCES, 1);
3099
3100 WREG32(CP_PERFMON_CNTL, 0);
3101
3102 WREG32(SQ_CONFIG, 0);
3103
3104 WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
3105 FORCE_EOV_MAX_REZ_CNT(255)));
3106
3107 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
3108 AUTO_INVLD_EN(ES_AND_GS_AUTO));
3109
3110 WREG32(VGT_GS_VERTEX_REUSE, 16);
3111 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
3112
3113 WREG32(CB_PERFCOUNTER0_SELECT0, 0);
3114 WREG32(CB_PERFCOUNTER0_SELECT1, 0);
3115 WREG32(CB_PERFCOUNTER1_SELECT0, 0);
3116 WREG32(CB_PERFCOUNTER1_SELECT1, 0);
3117 WREG32(CB_PERFCOUNTER2_SELECT0, 0);
3118 WREG32(CB_PERFCOUNTER2_SELECT1, 0);
3119 WREG32(CB_PERFCOUNTER3_SELECT0, 0);
3120 WREG32(CB_PERFCOUNTER3_SELECT1, 0);
3121
3122 tmp = RREG32(HDP_MISC_CNTL);
3123 tmp |= HDP_FLUSH_INVALIDATE_CACHE;
3124 WREG32(HDP_MISC_CNTL, tmp);
3125
3126 hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
3127 WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
3128
3129 WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
3130
3131 udelay(50);
3132}
Alex Deucherc476dde2012-03-20 17:18:12 -04003133
Alex Deucher48c0c902012-03-20 17:18:19 -04003134/*
Alex Deucher2ece2e82012-03-20 17:18:20 -04003135 * GPU scratch registers helpers function.
3136 */
3137static void si_scratch_init(struct radeon_device *rdev)
3138{
3139 int i;
3140
3141 rdev->scratch.num_reg = 7;
3142 rdev->scratch.reg_base = SCRATCH_REG0;
3143 for (i = 0; i < rdev->scratch.num_reg; i++) {
3144 rdev->scratch.free[i] = true;
3145 rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
3146 }
3147}
3148
3149void si_fence_ring_emit(struct radeon_device *rdev,
3150 struct radeon_fence *fence)
3151{
3152 struct radeon_ring *ring = &rdev->ring[fence->ring];
3153 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
3154
3155 /* flush read cache over gart */
3156 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
3157 radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
3158 radeon_ring_write(ring, 0);
3159 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
3160 radeon_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
3161 PACKET3_TC_ACTION_ENA |
3162 PACKET3_SH_KCACHE_ACTION_ENA |
3163 PACKET3_SH_ICACHE_ACTION_ENA);
3164 radeon_ring_write(ring, 0xFFFFFFFF);
3165 radeon_ring_write(ring, 0);
3166 radeon_ring_write(ring, 10); /* poll interval */
3167 /* EVENT_WRITE_EOP - flush caches, send int */
3168 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
3169 radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) | EVENT_INDEX(5));
3170 radeon_ring_write(ring, addr & 0xffffffff);
3171 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
3172 radeon_ring_write(ring, fence->seq);
3173 radeon_ring_write(ring, 0);
3174}
3175
3176/*
3177 * IB stuff
3178 */
3179void si_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
3180{
Christian König876dc9f2012-05-08 14:24:01 +02003181 struct radeon_ring *ring = &rdev->ring[ib->ring];
Alex Deucher2ece2e82012-03-20 17:18:20 -04003182 u32 header;
3183
Alex Deuchera85a7da42012-07-17 14:02:29 -04003184 if (ib->is_const_ib) {
3185 /* set switch buffer packet before const IB */
3186 radeon_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
3187 radeon_ring_write(ring, 0);
Christian König45df6802012-07-06 16:22:55 +02003188
Alex Deucher2ece2e82012-03-20 17:18:20 -04003189 header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
Alex Deuchera85a7da42012-07-17 14:02:29 -04003190 } else {
Alex Deucher89d35802012-07-17 14:02:31 -04003191 u32 next_rptr;
Alex Deuchera85a7da42012-07-17 14:02:29 -04003192 if (ring->rptr_save_reg) {
Alex Deucher89d35802012-07-17 14:02:31 -04003193 next_rptr = ring->wptr + 3 + 4 + 8;
Alex Deuchera85a7da42012-07-17 14:02:29 -04003194 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
3195 radeon_ring_write(ring, ((ring->rptr_save_reg -
3196 PACKET3_SET_CONFIG_REG_START) >> 2));
3197 radeon_ring_write(ring, next_rptr);
Alex Deucher89d35802012-07-17 14:02:31 -04003198 } else if (rdev->wb.enabled) {
3199 next_rptr = ring->wptr + 5 + 4 + 8;
3200 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
3201 radeon_ring_write(ring, (1 << 8));
3202 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
3203 radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xffffffff);
3204 radeon_ring_write(ring, next_rptr);
Alex Deuchera85a7da42012-07-17 14:02:29 -04003205 }
3206
Alex Deucher2ece2e82012-03-20 17:18:20 -04003207 header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
Alex Deuchera85a7da42012-07-17 14:02:29 -04003208 }
Alex Deucher2ece2e82012-03-20 17:18:20 -04003209
3210 radeon_ring_write(ring, header);
3211 radeon_ring_write(ring,
3212#ifdef __BIG_ENDIAN
3213 (2 << 0) |
3214#endif
3215 (ib->gpu_addr & 0xFFFFFFFC));
3216 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
Christian König4bf3dd92012-08-06 18:57:44 +02003217 radeon_ring_write(ring, ib->length_dw |
3218 (ib->vm ? (ib->vm->id << 24) : 0));
Alex Deucher2ece2e82012-03-20 17:18:20 -04003219
Alex Deuchera85a7da42012-07-17 14:02:29 -04003220 if (!ib->is_const_ib) {
3221 /* flush read cache over gart for this vmid */
3222 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
3223 radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
Christian König4bf3dd92012-08-06 18:57:44 +02003224 radeon_ring_write(ring, ib->vm ? ib->vm->id : 0);
Alex Deuchera85a7da42012-07-17 14:02:29 -04003225 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
3226 radeon_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
3227 PACKET3_TC_ACTION_ENA |
3228 PACKET3_SH_KCACHE_ACTION_ENA |
3229 PACKET3_SH_ICACHE_ACTION_ENA);
3230 radeon_ring_write(ring, 0xFFFFFFFF);
3231 radeon_ring_write(ring, 0);
3232 radeon_ring_write(ring, 10); /* poll interval */
3233 }
Alex Deucher2ece2e82012-03-20 17:18:20 -04003234}
3235
3236/*
Alex Deucher48c0c902012-03-20 17:18:19 -04003237 * CP.
3238 */
3239static void si_cp_enable(struct radeon_device *rdev, bool enable)
3240{
3241 if (enable)
3242 WREG32(CP_ME_CNTL, 0);
3243 else {
3244 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
3245 WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT));
3246 WREG32(SCRATCH_UMSK, 0);
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05003247 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
3248 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
3249 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
Alex Deucher48c0c902012-03-20 17:18:19 -04003250 }
3251 udelay(50);
3252}
3253
3254static int si_cp_load_microcode(struct radeon_device *rdev)
3255{
3256 const __be32 *fw_data;
3257 int i;
3258
3259 if (!rdev->me_fw || !rdev->pfp_fw)
3260 return -EINVAL;
3261
3262 si_cp_enable(rdev, false);
3263
3264 /* PFP */
3265 fw_data = (const __be32 *)rdev->pfp_fw->data;
3266 WREG32(CP_PFP_UCODE_ADDR, 0);
3267 for (i = 0; i < SI_PFP_UCODE_SIZE; i++)
3268 WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
3269 WREG32(CP_PFP_UCODE_ADDR, 0);
3270
3271 /* CE */
3272 fw_data = (const __be32 *)rdev->ce_fw->data;
3273 WREG32(CP_CE_UCODE_ADDR, 0);
3274 for (i = 0; i < SI_CE_UCODE_SIZE; i++)
3275 WREG32(CP_CE_UCODE_DATA, be32_to_cpup(fw_data++));
3276 WREG32(CP_CE_UCODE_ADDR, 0);
3277
3278 /* ME */
3279 fw_data = (const __be32 *)rdev->me_fw->data;
3280 WREG32(CP_ME_RAM_WADDR, 0);
3281 for (i = 0; i < SI_PM4_UCODE_SIZE; i++)
3282 WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
3283 WREG32(CP_ME_RAM_WADDR, 0);
3284
3285 WREG32(CP_PFP_UCODE_ADDR, 0);
3286 WREG32(CP_CE_UCODE_ADDR, 0);
3287 WREG32(CP_ME_RAM_WADDR, 0);
3288 WREG32(CP_ME_RAM_RADDR, 0);
3289 return 0;
3290}
3291
3292static int si_cp_start(struct radeon_device *rdev)
3293{
3294 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
3295 int r, i;
3296
3297 r = radeon_ring_lock(rdev, ring, 7 + 4);
3298 if (r) {
3299 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
3300 return r;
3301 }
3302 /* init the CP */
3303 radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
3304 radeon_ring_write(ring, 0x1);
3305 radeon_ring_write(ring, 0x0);
3306 radeon_ring_write(ring, rdev->config.si.max_hw_contexts - 1);
3307 radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
3308 radeon_ring_write(ring, 0);
3309 radeon_ring_write(ring, 0);
3310
3311 /* init the CE partitions */
3312 radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
3313 radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
3314 radeon_ring_write(ring, 0xc000);
3315 radeon_ring_write(ring, 0xe000);
3316 radeon_ring_unlock_commit(rdev, ring);
3317
3318 si_cp_enable(rdev, true);
3319
3320 r = radeon_ring_lock(rdev, ring, si_default_size + 10);
3321 if (r) {
3322 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
3323 return r;
3324 }
3325
3326 /* setup clear context state */
3327 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
3328 radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
3329
3330 for (i = 0; i < si_default_size; i++)
3331 radeon_ring_write(ring, si_default_state[i]);
3332
3333 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
3334 radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
3335
3336 /* set clear context state */
3337 radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
3338 radeon_ring_write(ring, 0);
3339
3340 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
3341 radeon_ring_write(ring, 0x00000316);
3342 radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
3343 radeon_ring_write(ring, 0x00000010); /* VGT_OUT_DEALLOC_CNTL */
3344
3345 radeon_ring_unlock_commit(rdev, ring);
3346
3347 for (i = RADEON_RING_TYPE_GFX_INDEX; i <= CAYMAN_RING_TYPE_CP2_INDEX; ++i) {
3348 ring = &rdev->ring[i];
3349 r = radeon_ring_lock(rdev, ring, 2);
3350
3351 /* clear the compute context state */
3352 radeon_ring_write(ring, PACKET3_COMPUTE(PACKET3_CLEAR_STATE, 0));
3353 radeon_ring_write(ring, 0);
3354
3355 radeon_ring_unlock_commit(rdev, ring);
3356 }
3357
3358 return 0;
3359}
3360
3361static void si_cp_fini(struct radeon_device *rdev)
3362{
Christian König45df6802012-07-06 16:22:55 +02003363 struct radeon_ring *ring;
Alex Deucher48c0c902012-03-20 17:18:19 -04003364 si_cp_enable(rdev, false);
Christian König45df6802012-07-06 16:22:55 +02003365
3366 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
3367 radeon_ring_fini(rdev, ring);
3368 radeon_scratch_free(rdev, ring->rptr_save_reg);
3369
3370 ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
3371 radeon_ring_fini(rdev, ring);
3372 radeon_scratch_free(rdev, ring->rptr_save_reg);
3373
3374 ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
3375 radeon_ring_fini(rdev, ring);
3376 radeon_scratch_free(rdev, ring->rptr_save_reg);
Alex Deucher48c0c902012-03-20 17:18:19 -04003377}
3378
3379static int si_cp_resume(struct radeon_device *rdev)
3380{
3381 struct radeon_ring *ring;
3382 u32 tmp;
3383 u32 rb_bufsz;
3384 int r;
3385
Alex Deucher811e4d52013-09-03 13:31:33 -04003386 si_enable_gui_idle_interrupt(rdev, false);
3387
Alex Deucher48c0c902012-03-20 17:18:19 -04003388 WREG32(CP_SEM_WAIT_TIMER, 0x0);
3389 WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
3390
3391 /* Set the write pointer delay */
3392 WREG32(CP_RB_WPTR_DELAY, 0);
3393
3394 WREG32(CP_DEBUG, 0);
3395 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
3396
3397 /* ring 0 - compute and gfx */
3398 /* Set ring buffer size */
3399 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Daniel Vetterb72a8922013-07-10 14:11:59 +02003400 rb_bufsz = order_base_2(ring->ring_size / 8);
3401 tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
Alex Deucher48c0c902012-03-20 17:18:19 -04003402#ifdef __BIG_ENDIAN
3403 tmp |= BUF_SWAP_32BIT;
3404#endif
3405 WREG32(CP_RB0_CNTL, tmp);
3406
3407 /* Initialize the ring buffer's read and write pointers */
3408 WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA);
3409 ring->wptr = 0;
3410 WREG32(CP_RB0_WPTR, ring->wptr);
3411
Adam Buchbinder48fc7f72012-09-19 21:48:00 -04003412 /* set the wb address whether it's enabled or not */
Alex Deucher48c0c902012-03-20 17:18:19 -04003413 WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
3414 WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
3415
3416 if (rdev->wb.enabled)
3417 WREG32(SCRATCH_UMSK, 0xff);
3418 else {
3419 tmp |= RB_NO_UPDATE;
3420 WREG32(SCRATCH_UMSK, 0);
3421 }
3422
3423 mdelay(1);
3424 WREG32(CP_RB0_CNTL, tmp);
3425
3426 WREG32(CP_RB0_BASE, ring->gpu_addr >> 8);
3427
3428 ring->rptr = RREG32(CP_RB0_RPTR);
3429
3430 /* ring1 - compute only */
3431 /* Set ring buffer size */
3432 ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
Daniel Vetterb72a8922013-07-10 14:11:59 +02003433 rb_bufsz = order_base_2(ring->ring_size / 8);
3434 tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
Alex Deucher48c0c902012-03-20 17:18:19 -04003435#ifdef __BIG_ENDIAN
3436 tmp |= BUF_SWAP_32BIT;
3437#endif
3438 WREG32(CP_RB1_CNTL, tmp);
3439
3440 /* Initialize the ring buffer's read and write pointers */
3441 WREG32(CP_RB1_CNTL, tmp | RB_RPTR_WR_ENA);
3442 ring->wptr = 0;
3443 WREG32(CP_RB1_WPTR, ring->wptr);
3444
Adam Buchbinder48fc7f72012-09-19 21:48:00 -04003445 /* set the wb address whether it's enabled or not */
Alex Deucher48c0c902012-03-20 17:18:19 -04003446 WREG32(CP_RB1_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFFFFFFFC);
3447 WREG32(CP_RB1_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFF);
3448
3449 mdelay(1);
3450 WREG32(CP_RB1_CNTL, tmp);
3451
3452 WREG32(CP_RB1_BASE, ring->gpu_addr >> 8);
3453
3454 ring->rptr = RREG32(CP_RB1_RPTR);
3455
3456 /* ring2 - compute only */
3457 /* Set ring buffer size */
3458 ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
Daniel Vetterb72a8922013-07-10 14:11:59 +02003459 rb_bufsz = order_base_2(ring->ring_size / 8);
3460 tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
Alex Deucher48c0c902012-03-20 17:18:19 -04003461#ifdef __BIG_ENDIAN
3462 tmp |= BUF_SWAP_32BIT;
3463#endif
3464 WREG32(CP_RB2_CNTL, tmp);
3465
3466 /* Initialize the ring buffer's read and write pointers */
3467 WREG32(CP_RB2_CNTL, tmp | RB_RPTR_WR_ENA);
3468 ring->wptr = 0;
3469 WREG32(CP_RB2_WPTR, ring->wptr);
3470
Adam Buchbinder48fc7f72012-09-19 21:48:00 -04003471 /* set the wb address whether it's enabled or not */
Alex Deucher48c0c902012-03-20 17:18:19 -04003472 WREG32(CP_RB2_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFFFFFFFC);
3473 WREG32(CP_RB2_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFF);
3474
3475 mdelay(1);
3476 WREG32(CP_RB2_CNTL, tmp);
3477
3478 WREG32(CP_RB2_BASE, ring->gpu_addr >> 8);
3479
3480 ring->rptr = RREG32(CP_RB2_RPTR);
3481
3482 /* start the rings */
3483 si_cp_start(rdev);
3484 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
3485 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = true;
3486 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = true;
3487 r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
3488 if (r) {
3489 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
3490 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
3491 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
3492 return r;
3493 }
3494 r = radeon_ring_test(rdev, CAYMAN_RING_TYPE_CP1_INDEX, &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX]);
3495 if (r) {
3496 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
3497 }
3498 r = radeon_ring_test(rdev, CAYMAN_RING_TYPE_CP2_INDEX, &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX]);
3499 if (r) {
3500 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
3501 }
3502
Alex Deucher811e4d52013-09-03 13:31:33 -04003503 si_enable_gui_idle_interrupt(rdev, true);
3504
Alex Deucher48c0c902012-03-20 17:18:19 -04003505 return 0;
3506}
3507
Christian König2483b4e2013-08-13 11:56:54 +02003508u32 si_gpu_check_soft_reset(struct radeon_device *rdev)
Alex Deucher014bb202013-01-18 19:36:20 -05003509{
3510 u32 reset_mask = 0;
3511 u32 tmp;
3512
3513 /* GRBM_STATUS */
3514 tmp = RREG32(GRBM_STATUS);
3515 if (tmp & (PA_BUSY | SC_BUSY |
3516 BCI_BUSY | SX_BUSY |
3517 TA_BUSY | VGT_BUSY |
3518 DB_BUSY | CB_BUSY |
3519 GDS_BUSY | SPI_BUSY |
3520 IA_BUSY | IA_BUSY_NO_DMA))
3521 reset_mask |= RADEON_RESET_GFX;
3522
3523 if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
3524 CP_BUSY | CP_COHERENCY_BUSY))
3525 reset_mask |= RADEON_RESET_CP;
3526
3527 if (tmp & GRBM_EE_BUSY)
3528 reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
3529
3530 /* GRBM_STATUS2 */
3531 tmp = RREG32(GRBM_STATUS2);
3532 if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
3533 reset_mask |= RADEON_RESET_RLC;
3534
3535 /* DMA_STATUS_REG 0 */
3536 tmp = RREG32(DMA_STATUS_REG + DMA0_REGISTER_OFFSET);
3537 if (!(tmp & DMA_IDLE))
3538 reset_mask |= RADEON_RESET_DMA;
3539
3540 /* DMA_STATUS_REG 1 */
3541 tmp = RREG32(DMA_STATUS_REG + DMA1_REGISTER_OFFSET);
3542 if (!(tmp & DMA_IDLE))
3543 reset_mask |= RADEON_RESET_DMA1;
3544
3545 /* SRBM_STATUS2 */
3546 tmp = RREG32(SRBM_STATUS2);
3547 if (tmp & DMA_BUSY)
3548 reset_mask |= RADEON_RESET_DMA;
3549
3550 if (tmp & DMA1_BUSY)
3551 reset_mask |= RADEON_RESET_DMA1;
3552
3553 /* SRBM_STATUS */
3554 tmp = RREG32(SRBM_STATUS);
3555
3556 if (tmp & IH_BUSY)
3557 reset_mask |= RADEON_RESET_IH;
3558
3559 if (tmp & SEM_BUSY)
3560 reset_mask |= RADEON_RESET_SEM;
3561
3562 if (tmp & GRBM_RQ_PENDING)
3563 reset_mask |= RADEON_RESET_GRBM;
3564
3565 if (tmp & VMC_BUSY)
3566 reset_mask |= RADEON_RESET_VMC;
3567
3568 if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
3569 MCC_BUSY | MCD_BUSY))
3570 reset_mask |= RADEON_RESET_MC;
3571
3572 if (evergreen_is_display_hung(rdev))
3573 reset_mask |= RADEON_RESET_DISPLAY;
3574
3575 /* VM_L2_STATUS */
3576 tmp = RREG32(VM_L2_STATUS);
3577 if (tmp & L2_BUSY)
3578 reset_mask |= RADEON_RESET_VMC;
3579
Alex Deucherd808fc82013-02-28 10:03:08 -05003580 /* Skip MC reset as it's mostly likely not hung, just busy */
3581 if (reset_mask & RADEON_RESET_MC) {
3582 DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
3583 reset_mask &= ~RADEON_RESET_MC;
3584 }
3585
Alex Deucher014bb202013-01-18 19:36:20 -05003586 return reset_mask;
3587}
3588
3589static void si_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
Alex Deucher06bc6df2013-01-03 13:15:30 -05003590{
3591 struct evergreen_mc_save save;
Alex Deucher1c534672013-01-18 15:08:38 -05003592 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
3593 u32 tmp;
Alex Deucher19fc42e2013-01-14 11:04:39 -05003594
Alex Deucher06bc6df2013-01-03 13:15:30 -05003595 if (reset_mask == 0)
Alex Deucher014bb202013-01-18 19:36:20 -05003596 return;
Alex Deucher06bc6df2013-01-03 13:15:30 -05003597
3598 dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
3599
Alex Deucher1c534672013-01-18 15:08:38 -05003600 evergreen_print_gpu_status_regs(rdev);
Alex Deucher06bc6df2013-01-03 13:15:30 -05003601 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
3602 RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
3603 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
3604 RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
3605
Alex Deucher1c534672013-01-18 15:08:38 -05003606 /* Disable CP parsing/prefetching */
3607 WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
3608
3609 if (reset_mask & RADEON_RESET_DMA) {
3610 /* dma0 */
3611 tmp = RREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET);
3612 tmp &= ~DMA_RB_ENABLE;
3613 WREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET, tmp);
Alex Deucher014bb202013-01-18 19:36:20 -05003614 }
3615 if (reset_mask & RADEON_RESET_DMA1) {
Alex Deucher1c534672013-01-18 15:08:38 -05003616 /* dma1 */
3617 tmp = RREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET);
3618 tmp &= ~DMA_RB_ENABLE;
3619 WREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET, tmp);
3620 }
3621
Alex Deucherf770d782013-01-23 19:00:25 -05003622 udelay(50);
3623
3624 evergreen_mc_stop(rdev, &save);
3625 if (evergreen_mc_wait_for_idle(rdev)) {
3626 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
3627 }
3628
Alex Deucher1c534672013-01-18 15:08:38 -05003629 if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE | RADEON_RESET_CP)) {
3630 grbm_soft_reset = SOFT_RESET_CB |
3631 SOFT_RESET_DB |
3632 SOFT_RESET_GDS |
3633 SOFT_RESET_PA |
3634 SOFT_RESET_SC |
3635 SOFT_RESET_BCI |
3636 SOFT_RESET_SPI |
3637 SOFT_RESET_SX |
3638 SOFT_RESET_TC |
3639 SOFT_RESET_TA |
3640 SOFT_RESET_VGT |
3641 SOFT_RESET_IA;
3642 }
3643
3644 if (reset_mask & RADEON_RESET_CP) {
3645 grbm_soft_reset |= SOFT_RESET_CP | SOFT_RESET_VGT;
3646
3647 srbm_soft_reset |= SOFT_RESET_GRBM;
3648 }
Alex Deucher06bc6df2013-01-03 13:15:30 -05003649
3650 if (reset_mask & RADEON_RESET_DMA)
Alex Deucher014bb202013-01-18 19:36:20 -05003651 srbm_soft_reset |= SOFT_RESET_DMA;
3652
3653 if (reset_mask & RADEON_RESET_DMA1)
3654 srbm_soft_reset |= SOFT_RESET_DMA1;
3655
3656 if (reset_mask & RADEON_RESET_DISPLAY)
3657 srbm_soft_reset |= SOFT_RESET_DC;
3658
3659 if (reset_mask & RADEON_RESET_RLC)
3660 grbm_soft_reset |= SOFT_RESET_RLC;
3661
3662 if (reset_mask & RADEON_RESET_SEM)
3663 srbm_soft_reset |= SOFT_RESET_SEM;
3664
3665 if (reset_mask & RADEON_RESET_IH)
3666 srbm_soft_reset |= SOFT_RESET_IH;
3667
3668 if (reset_mask & RADEON_RESET_GRBM)
3669 srbm_soft_reset |= SOFT_RESET_GRBM;
3670
3671 if (reset_mask & RADEON_RESET_VMC)
3672 srbm_soft_reset |= SOFT_RESET_VMC;
3673
3674 if (reset_mask & RADEON_RESET_MC)
3675 srbm_soft_reset |= SOFT_RESET_MC;
Alex Deucher1c534672013-01-18 15:08:38 -05003676
3677 if (grbm_soft_reset) {
3678 tmp = RREG32(GRBM_SOFT_RESET);
3679 tmp |= grbm_soft_reset;
3680 dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
3681 WREG32(GRBM_SOFT_RESET, tmp);
3682 tmp = RREG32(GRBM_SOFT_RESET);
3683
3684 udelay(50);
3685
3686 tmp &= ~grbm_soft_reset;
3687 WREG32(GRBM_SOFT_RESET, tmp);
3688 tmp = RREG32(GRBM_SOFT_RESET);
3689 }
3690
3691 if (srbm_soft_reset) {
3692 tmp = RREG32(SRBM_SOFT_RESET);
3693 tmp |= srbm_soft_reset;
3694 dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
3695 WREG32(SRBM_SOFT_RESET, tmp);
3696 tmp = RREG32(SRBM_SOFT_RESET);
3697
3698 udelay(50);
3699
3700 tmp &= ~srbm_soft_reset;
3701 WREG32(SRBM_SOFT_RESET, tmp);
3702 tmp = RREG32(SRBM_SOFT_RESET);
3703 }
Alex Deucher06bc6df2013-01-03 13:15:30 -05003704
3705 /* Wait a little for things to settle down */
3706 udelay(50);
3707
Alex Deucherc476dde2012-03-20 17:18:12 -04003708 evergreen_mc_resume(rdev, &save);
Alex Deucher1c534672013-01-18 15:08:38 -05003709 udelay(50);
Alex Deucher410a3412013-01-18 13:05:39 -05003710
Alex Deucher1c534672013-01-18 15:08:38 -05003711 evergreen_print_gpu_status_regs(rdev);
Alex Deucherc476dde2012-03-20 17:18:12 -04003712}
3713
3714int si_asic_reset(struct radeon_device *rdev)
3715{
Alex Deucher014bb202013-01-18 19:36:20 -05003716 u32 reset_mask;
3717
3718 reset_mask = si_gpu_check_soft_reset(rdev);
3719
3720 if (reset_mask)
3721 r600_set_bios_scratch_engine_hung(rdev, true);
3722
3723 si_gpu_soft_reset(rdev, reset_mask);
3724
3725 reset_mask = si_gpu_check_soft_reset(rdev);
3726
3727 if (!reset_mask)
3728 r600_set_bios_scratch_engine_hung(rdev, false);
3729
3730 return 0;
Alex Deucherc476dde2012-03-20 17:18:12 -04003731}
3732
Alex Deucher123bc182013-01-24 11:37:19 -05003733/**
3734 * si_gfx_is_lockup - Check if the GFX engine is locked up
3735 *
3736 * @rdev: radeon_device pointer
3737 * @ring: radeon_ring structure holding ring information
3738 *
3739 * Check if the GFX engine is locked up.
3740 * Returns true if the engine appears to be locked up, false if not.
3741 */
3742bool si_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
3743{
3744 u32 reset_mask = si_gpu_check_soft_reset(rdev);
3745
3746 if (!(reset_mask & (RADEON_RESET_GFX |
3747 RADEON_RESET_COMPUTE |
3748 RADEON_RESET_CP))) {
3749 radeon_ring_lockup_update(ring);
3750 return false;
3751 }
3752 /* force CP activities */
3753 radeon_ring_force_activity(rdev, ring);
3754 return radeon_ring_test_lockup(rdev, ring);
3755}
3756
Alex Deucherd2800ee2012-03-20 17:18:13 -04003757/* MC */
3758static void si_mc_program(struct radeon_device *rdev)
3759{
3760 struct evergreen_mc_save save;
3761 u32 tmp;
3762 int i, j;
3763
3764 /* Initialize HDP */
3765 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
3766 WREG32((0x2c14 + j), 0x00000000);
3767 WREG32((0x2c18 + j), 0x00000000);
3768 WREG32((0x2c1c + j), 0x00000000);
3769 WREG32((0x2c20 + j), 0x00000000);
3770 WREG32((0x2c24 + j), 0x00000000);
3771 }
3772 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
3773
3774 evergreen_mc_stop(rdev, &save);
3775 if (radeon_mc_wait_for_idle(rdev)) {
3776 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
3777 }
Alex Deucher51535502012-08-30 14:34:30 -04003778 if (!ASIC_IS_NODCE(rdev))
3779 /* Lockout access through VGA aperture*/
3780 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
Alex Deucherd2800ee2012-03-20 17:18:13 -04003781 /* Update configuration */
3782 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
3783 rdev->mc.vram_start >> 12);
3784 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
3785 rdev->mc.vram_end >> 12);
3786 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR,
3787 rdev->vram_scratch.gpu_addr >> 12);
3788 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
3789 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
3790 WREG32(MC_VM_FB_LOCATION, tmp);
3791 /* XXX double check these! */
3792 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
3793 WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
3794 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
3795 WREG32(MC_VM_AGP_BASE, 0);
3796 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
3797 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
3798 if (radeon_mc_wait_for_idle(rdev)) {
3799 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
3800 }
3801 evergreen_mc_resume(rdev, &save);
Alex Deucher51535502012-08-30 14:34:30 -04003802 if (!ASIC_IS_NODCE(rdev)) {
3803 /* we need to own VRAM, so turn off the VGA renderer here
3804 * to stop it overwriting our objects */
3805 rv515_vga_render_disable(rdev);
3806 }
Alex Deucherd2800ee2012-03-20 17:18:13 -04003807}
3808
Alex Deucher1c491652013-04-09 12:45:26 -04003809void si_vram_gtt_location(struct radeon_device *rdev,
3810 struct radeon_mc *mc)
Alex Deucherd2800ee2012-03-20 17:18:13 -04003811{
3812 if (mc->mc_vram_size > 0xFFC0000000ULL) {
3813 /* leave room for at least 1024M GTT */
3814 dev_warn(rdev->dev, "limiting VRAM\n");
3815 mc->real_vram_size = 0xFFC0000000ULL;
3816 mc->mc_vram_size = 0xFFC0000000ULL;
3817 }
Alex Deucher9ed8b1f2013-04-08 11:13:01 -04003818 radeon_vram_location(rdev, &rdev->mc, 0);
Alex Deucherd2800ee2012-03-20 17:18:13 -04003819 rdev->mc.gtt_base_align = 0;
Alex Deucher9ed8b1f2013-04-08 11:13:01 -04003820 radeon_gtt_location(rdev, mc);
Alex Deucherd2800ee2012-03-20 17:18:13 -04003821}
3822
3823static int si_mc_init(struct radeon_device *rdev)
3824{
3825 u32 tmp;
3826 int chansize, numchan;
3827
3828 /* Get VRAM informations */
3829 rdev->mc.vram_is_ddr = true;
3830 tmp = RREG32(MC_ARB_RAMCFG);
3831 if (tmp & CHANSIZE_OVERRIDE) {
3832 chansize = 16;
3833 } else if (tmp & CHANSIZE_MASK) {
3834 chansize = 64;
3835 } else {
3836 chansize = 32;
3837 }
3838 tmp = RREG32(MC_SHARED_CHMAP);
3839 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
3840 case 0:
3841 default:
3842 numchan = 1;
3843 break;
3844 case 1:
3845 numchan = 2;
3846 break;
3847 case 2:
3848 numchan = 4;
3849 break;
3850 case 3:
3851 numchan = 8;
3852 break;
3853 case 4:
3854 numchan = 3;
3855 break;
3856 case 5:
3857 numchan = 6;
3858 break;
3859 case 6:
3860 numchan = 10;
3861 break;
3862 case 7:
3863 numchan = 12;
3864 break;
3865 case 8:
3866 numchan = 16;
3867 break;
3868 }
3869 rdev->mc.vram_width = numchan * chansize;
3870 /* Could aper size report 0 ? */
3871 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
3872 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
3873 /* size in MB on si */
Niels Ole Salscheiderfc986032013-05-18 21:19:23 +02003874 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
3875 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
Alex Deucherd2800ee2012-03-20 17:18:13 -04003876 rdev->mc.visible_vram_size = rdev->mc.aper_size;
3877 si_vram_gtt_location(rdev, &rdev->mc);
3878 radeon_update_bandwidth_info(rdev);
3879
3880 return 0;
3881}
3882
3883/*
3884 * GART
3885 */
3886void si_pcie_gart_tlb_flush(struct radeon_device *rdev)
3887{
3888 /* flush hdp cache */
3889 WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
3890
3891 /* bits 0-15 are the VM contexts0-15 */
3892 WREG32(VM_INVALIDATE_REQUEST, 1);
3893}
3894
Lauri Kasanen1109ca02012-08-31 13:43:50 -04003895static int si_pcie_gart_enable(struct radeon_device *rdev)
Alex Deucherd2800ee2012-03-20 17:18:13 -04003896{
3897 int r, i;
3898
3899 if (rdev->gart.robj == NULL) {
3900 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
3901 return -EINVAL;
3902 }
3903 r = radeon_gart_table_vram_pin(rdev);
3904 if (r)
3905 return r;
3906 radeon_gart_restore(rdev);
3907 /* Setup TLB control */
3908 WREG32(MC_VM_MX_L1_TLB_CNTL,
3909 (0xA << 7) |
3910 ENABLE_L1_TLB |
3911 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
3912 ENABLE_ADVANCED_DRIVER_MODEL |
3913 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
3914 /* Setup L2 cache */
3915 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
3916 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
3917 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
3918 EFFECTIVE_L2_QUEUE_SIZE(7) |
3919 CONTEXT1_IDENTITY_ACCESS_MODE(1));
3920 WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
3921 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
3922 L2_CACHE_BIGK_FRAGMENT_SIZE(0));
3923 /* setup context0 */
3924 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
3925 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
3926 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
3927 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
3928 (u32)(rdev->dummy_page.addr >> 12));
3929 WREG32(VM_CONTEXT0_CNTL2, 0);
3930 WREG32(VM_CONTEXT0_CNTL, (ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
3931 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT));
3932
3933 WREG32(0x15D4, 0);
3934 WREG32(0x15D8, 0);
3935 WREG32(0x15DC, 0);
3936
3937 /* empty context1-15 */
Alex Deucherd2800ee2012-03-20 17:18:13 -04003938 /* set vm size, must be a multiple of 4 */
3939 WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
Alex Deucherc21b3282012-06-28 17:53:07 -04003940 WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn);
Alex Deucher23d4f1f2012-10-08 09:45:46 -04003941 /* Assign the pt base to something valid for now; the pts used for
3942 * the VMs are determined by the application and setup and assigned
3943 * on the fly in the vm part of radeon_gart.c
3944 */
Alex Deucherd2800ee2012-03-20 17:18:13 -04003945 for (i = 1; i < 16; i++) {
3946 if (i < 8)
3947 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
3948 rdev->gart.table_addr >> 12);
3949 else
3950 WREG32(VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2),
3951 rdev->gart.table_addr >> 12);
3952 }
3953
3954 /* enable context1-15 */
3955 WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
3956 (u32)(rdev->dummy_page.addr >> 12));
Christian Königae133a12012-09-18 15:30:44 -04003957 WREG32(VM_CONTEXT1_CNTL2, 4);
Dmitry Cherkasovfa87e622012-09-17 19:36:19 +02003958 WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
Christian Königae133a12012-09-18 15:30:44 -04003959 RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
3960 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
3961 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
3962 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
3963 PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
3964 PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
3965 VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
3966 VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
3967 READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
3968 READ_PROTECTION_FAULT_ENABLE_DEFAULT |
3969 WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
3970 WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
Alex Deucherd2800ee2012-03-20 17:18:13 -04003971
3972 si_pcie_gart_tlb_flush(rdev);
3973 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
3974 (unsigned)(rdev->mc.gtt_size >> 20),
3975 (unsigned long long)rdev->gart.table_addr);
3976 rdev->gart.ready = true;
3977 return 0;
3978}
3979
Lauri Kasanen1109ca02012-08-31 13:43:50 -04003980static void si_pcie_gart_disable(struct radeon_device *rdev)
Alex Deucherd2800ee2012-03-20 17:18:13 -04003981{
3982 /* Disable all tables */
3983 WREG32(VM_CONTEXT0_CNTL, 0);
3984 WREG32(VM_CONTEXT1_CNTL, 0);
3985 /* Setup TLB control */
3986 WREG32(MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE_NOT_IN_SYS |
3987 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
3988 /* Setup L2 cache */
3989 WREG32(VM_L2_CNTL, ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
3990 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
3991 EFFECTIVE_L2_QUEUE_SIZE(7) |
3992 CONTEXT1_IDENTITY_ACCESS_MODE(1));
3993 WREG32(VM_L2_CNTL2, 0);
3994 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
3995 L2_CACHE_BIGK_FRAGMENT_SIZE(0));
3996 radeon_gart_table_vram_unpin(rdev);
3997}
3998
Lauri Kasanen1109ca02012-08-31 13:43:50 -04003999static void si_pcie_gart_fini(struct radeon_device *rdev)
Alex Deucherd2800ee2012-03-20 17:18:13 -04004000{
4001 si_pcie_gart_disable(rdev);
4002 radeon_gart_table_vram_free(rdev);
4003 radeon_gart_fini(rdev);
4004}
4005
Alex Deucher498dd8b2012-03-20 17:18:15 -04004006/* vm parser */
4007static bool si_vm_reg_valid(u32 reg)
4008{
4009 /* context regs are fine */
4010 if (reg >= 0x28000)
4011 return true;
4012
4013 /* check config regs */
4014 switch (reg) {
4015 case GRBM_GFX_INDEX:
Alex Deucherf418b882012-11-08 10:13:24 -05004016 case CP_STRMOUT_CNTL:
Alex Deucher498dd8b2012-03-20 17:18:15 -04004017 case VGT_VTX_VECT_EJECT_REG:
4018 case VGT_CACHE_INVALIDATION:
4019 case VGT_ESGS_RING_SIZE:
4020 case VGT_GSVS_RING_SIZE:
4021 case VGT_GS_VERTEX_REUSE:
4022 case VGT_PRIMITIVE_TYPE:
4023 case VGT_INDEX_TYPE:
4024 case VGT_NUM_INDICES:
4025 case VGT_NUM_INSTANCES:
4026 case VGT_TF_RING_SIZE:
4027 case VGT_HS_OFFCHIP_PARAM:
4028 case VGT_TF_MEMORY_BASE:
4029 case PA_CL_ENHANCE:
4030 case PA_SU_LINE_STIPPLE_VALUE:
4031 case PA_SC_LINE_STIPPLE_STATE:
4032 case PA_SC_ENHANCE:
4033 case SQC_CACHES:
4034 case SPI_STATIC_THREAD_MGMT_1:
4035 case SPI_STATIC_THREAD_MGMT_2:
4036 case SPI_STATIC_THREAD_MGMT_3:
4037 case SPI_PS_MAX_WAVE_ID:
4038 case SPI_CONFIG_CNTL:
4039 case SPI_CONFIG_CNTL_1:
4040 case TA_CNTL_AUX:
4041 return true;
4042 default:
4043 DRM_ERROR("Invalid register 0x%x in CS\n", reg);
4044 return false;
4045 }
4046}
4047
4048static int si_vm_packet3_ce_check(struct radeon_device *rdev,
4049 u32 *ib, struct radeon_cs_packet *pkt)
4050{
4051 switch (pkt->opcode) {
4052 case PACKET3_NOP:
4053 case PACKET3_SET_BASE:
4054 case PACKET3_SET_CE_DE_COUNTERS:
4055 case PACKET3_LOAD_CONST_RAM:
4056 case PACKET3_WRITE_CONST_RAM:
4057 case PACKET3_WRITE_CONST_RAM_OFFSET:
4058 case PACKET3_DUMP_CONST_RAM:
4059 case PACKET3_INCREMENT_CE_COUNTER:
4060 case PACKET3_WAIT_ON_DE_COUNTER:
4061 case PACKET3_CE_WRITE:
4062 break;
4063 default:
4064 DRM_ERROR("Invalid CE packet3: 0x%x\n", pkt->opcode);
4065 return -EINVAL;
4066 }
4067 return 0;
4068}
4069
Tom Stellarde5b9e752013-08-16 17:47:39 -04004070static int si_vm_packet3_cp_dma_check(u32 *ib, u32 idx)
4071{
4072 u32 start_reg, reg, i;
4073 u32 command = ib[idx + 4];
4074 u32 info = ib[idx + 1];
4075 u32 idx_value = ib[idx];
4076 if (command & PACKET3_CP_DMA_CMD_SAS) {
4077 /* src address space is register */
4078 if (((info & 0x60000000) >> 29) == 0) {
4079 start_reg = idx_value << 2;
4080 if (command & PACKET3_CP_DMA_CMD_SAIC) {
4081 reg = start_reg;
4082 if (!si_vm_reg_valid(reg)) {
4083 DRM_ERROR("CP DMA Bad SRC register\n");
4084 return -EINVAL;
4085 }
4086 } else {
4087 for (i = 0; i < (command & 0x1fffff); i++) {
4088 reg = start_reg + (4 * i);
4089 if (!si_vm_reg_valid(reg)) {
4090 DRM_ERROR("CP DMA Bad SRC register\n");
4091 return -EINVAL;
4092 }
4093 }
4094 }
4095 }
4096 }
4097 if (command & PACKET3_CP_DMA_CMD_DAS) {
4098 /* dst address space is register */
4099 if (((info & 0x00300000) >> 20) == 0) {
4100 start_reg = ib[idx + 2];
4101 if (command & PACKET3_CP_DMA_CMD_DAIC) {
4102 reg = start_reg;
4103 if (!si_vm_reg_valid(reg)) {
4104 DRM_ERROR("CP DMA Bad DST register\n");
4105 return -EINVAL;
4106 }
4107 } else {
4108 for (i = 0; i < (command & 0x1fffff); i++) {
4109 reg = start_reg + (4 * i);
4110 if (!si_vm_reg_valid(reg)) {
4111 DRM_ERROR("CP DMA Bad DST register\n");
4112 return -EINVAL;
4113 }
4114 }
4115 }
4116 }
4117 }
4118 return 0;
4119}
4120
Alex Deucher498dd8b2012-03-20 17:18:15 -04004121static int si_vm_packet3_gfx_check(struct radeon_device *rdev,
4122 u32 *ib, struct radeon_cs_packet *pkt)
4123{
Tom Stellarde5b9e752013-08-16 17:47:39 -04004124 int r;
Alex Deucher498dd8b2012-03-20 17:18:15 -04004125 u32 idx = pkt->idx + 1;
4126 u32 idx_value = ib[idx];
4127 u32 start_reg, end_reg, reg, i;
4128
4129 switch (pkt->opcode) {
4130 case PACKET3_NOP:
4131 case PACKET3_SET_BASE:
4132 case PACKET3_CLEAR_STATE:
4133 case PACKET3_INDEX_BUFFER_SIZE:
4134 case PACKET3_DISPATCH_DIRECT:
4135 case PACKET3_DISPATCH_INDIRECT:
4136 case PACKET3_ALLOC_GDS:
4137 case PACKET3_WRITE_GDS_RAM:
4138 case PACKET3_ATOMIC_GDS:
4139 case PACKET3_ATOMIC:
4140 case PACKET3_OCCLUSION_QUERY:
4141 case PACKET3_SET_PREDICATION:
4142 case PACKET3_COND_EXEC:
4143 case PACKET3_PRED_EXEC:
4144 case PACKET3_DRAW_INDIRECT:
4145 case PACKET3_DRAW_INDEX_INDIRECT:
4146 case PACKET3_INDEX_BASE:
4147 case PACKET3_DRAW_INDEX_2:
4148 case PACKET3_CONTEXT_CONTROL:
4149 case PACKET3_INDEX_TYPE:
4150 case PACKET3_DRAW_INDIRECT_MULTI:
4151 case PACKET3_DRAW_INDEX_AUTO:
4152 case PACKET3_DRAW_INDEX_IMMD:
4153 case PACKET3_NUM_INSTANCES:
4154 case PACKET3_DRAW_INDEX_MULTI_AUTO:
4155 case PACKET3_STRMOUT_BUFFER_UPDATE:
4156 case PACKET3_DRAW_INDEX_OFFSET_2:
4157 case PACKET3_DRAW_INDEX_MULTI_ELEMENT:
4158 case PACKET3_DRAW_INDEX_INDIRECT_MULTI:
4159 case PACKET3_MPEG_INDEX:
4160 case PACKET3_WAIT_REG_MEM:
4161 case PACKET3_MEM_WRITE:
4162 case PACKET3_PFP_SYNC_ME:
4163 case PACKET3_SURFACE_SYNC:
4164 case PACKET3_EVENT_WRITE:
4165 case PACKET3_EVENT_WRITE_EOP:
4166 case PACKET3_EVENT_WRITE_EOS:
4167 case PACKET3_SET_CONTEXT_REG:
4168 case PACKET3_SET_CONTEXT_REG_INDIRECT:
4169 case PACKET3_SET_SH_REG:
4170 case PACKET3_SET_SH_REG_OFFSET:
4171 case PACKET3_INCREMENT_DE_COUNTER:
4172 case PACKET3_WAIT_ON_CE_COUNTER:
4173 case PACKET3_WAIT_ON_AVAIL_BUFFER:
4174 case PACKET3_ME_WRITE:
4175 break;
4176 case PACKET3_COPY_DATA:
4177 if ((idx_value & 0xf00) == 0) {
4178 reg = ib[idx + 3] * 4;
4179 if (!si_vm_reg_valid(reg))
4180 return -EINVAL;
4181 }
4182 break;
4183 case PACKET3_WRITE_DATA:
4184 if ((idx_value & 0xf00) == 0) {
4185 start_reg = ib[idx + 1] * 4;
4186 if (idx_value & 0x10000) {
4187 if (!si_vm_reg_valid(start_reg))
4188 return -EINVAL;
4189 } else {
4190 for (i = 0; i < (pkt->count - 2); i++) {
4191 reg = start_reg + (4 * i);
4192 if (!si_vm_reg_valid(reg))
4193 return -EINVAL;
4194 }
4195 }
4196 }
4197 break;
4198 case PACKET3_COND_WRITE:
4199 if (idx_value & 0x100) {
4200 reg = ib[idx + 5] * 4;
4201 if (!si_vm_reg_valid(reg))
4202 return -EINVAL;
4203 }
4204 break;
4205 case PACKET3_COPY_DW:
4206 if (idx_value & 0x2) {
4207 reg = ib[idx + 3] * 4;
4208 if (!si_vm_reg_valid(reg))
4209 return -EINVAL;
4210 }
4211 break;
4212 case PACKET3_SET_CONFIG_REG:
4213 start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
4214 end_reg = 4 * pkt->count + start_reg - 4;
4215 if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
4216 (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
4217 (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
4218 DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
4219 return -EINVAL;
4220 }
4221 for (i = 0; i < pkt->count; i++) {
4222 reg = start_reg + (4 * i);
4223 if (!si_vm_reg_valid(reg))
4224 return -EINVAL;
4225 }
4226 break;
Alex Deucher5aa709b2012-12-03 19:42:37 -05004227 case PACKET3_CP_DMA:
Tom Stellarde5b9e752013-08-16 17:47:39 -04004228 r = si_vm_packet3_cp_dma_check(ib, idx);
4229 if (r)
4230 return r;
Alex Deucher5aa709b2012-12-03 19:42:37 -05004231 break;
Alex Deucher498dd8b2012-03-20 17:18:15 -04004232 default:
4233 DRM_ERROR("Invalid GFX packet3: 0x%x\n", pkt->opcode);
4234 return -EINVAL;
4235 }
4236 return 0;
4237}
4238
4239static int si_vm_packet3_compute_check(struct radeon_device *rdev,
4240 u32 *ib, struct radeon_cs_packet *pkt)
4241{
Tom Stellarde5b9e752013-08-16 17:47:39 -04004242 int r;
Alex Deucher498dd8b2012-03-20 17:18:15 -04004243 u32 idx = pkt->idx + 1;
4244 u32 idx_value = ib[idx];
4245 u32 start_reg, reg, i;
4246
4247 switch (pkt->opcode) {
4248 case PACKET3_NOP:
4249 case PACKET3_SET_BASE:
4250 case PACKET3_CLEAR_STATE:
4251 case PACKET3_DISPATCH_DIRECT:
4252 case PACKET3_DISPATCH_INDIRECT:
4253 case PACKET3_ALLOC_GDS:
4254 case PACKET3_WRITE_GDS_RAM:
4255 case PACKET3_ATOMIC_GDS:
4256 case PACKET3_ATOMIC:
4257 case PACKET3_OCCLUSION_QUERY:
4258 case PACKET3_SET_PREDICATION:
4259 case PACKET3_COND_EXEC:
4260 case PACKET3_PRED_EXEC:
4261 case PACKET3_CONTEXT_CONTROL:
4262 case PACKET3_STRMOUT_BUFFER_UPDATE:
4263 case PACKET3_WAIT_REG_MEM:
4264 case PACKET3_MEM_WRITE:
4265 case PACKET3_PFP_SYNC_ME:
4266 case PACKET3_SURFACE_SYNC:
4267 case PACKET3_EVENT_WRITE:
4268 case PACKET3_EVENT_WRITE_EOP:
4269 case PACKET3_EVENT_WRITE_EOS:
4270 case PACKET3_SET_CONTEXT_REG:
4271 case PACKET3_SET_CONTEXT_REG_INDIRECT:
4272 case PACKET3_SET_SH_REG:
4273 case PACKET3_SET_SH_REG_OFFSET:
4274 case PACKET3_INCREMENT_DE_COUNTER:
4275 case PACKET3_WAIT_ON_CE_COUNTER:
4276 case PACKET3_WAIT_ON_AVAIL_BUFFER:
4277 case PACKET3_ME_WRITE:
4278 break;
4279 case PACKET3_COPY_DATA:
4280 if ((idx_value & 0xf00) == 0) {
4281 reg = ib[idx + 3] * 4;
4282 if (!si_vm_reg_valid(reg))
4283 return -EINVAL;
4284 }
4285 break;
4286 case PACKET3_WRITE_DATA:
4287 if ((idx_value & 0xf00) == 0) {
4288 start_reg = ib[idx + 1] * 4;
4289 if (idx_value & 0x10000) {
4290 if (!si_vm_reg_valid(start_reg))
4291 return -EINVAL;
4292 } else {
4293 for (i = 0; i < (pkt->count - 2); i++) {
4294 reg = start_reg + (4 * i);
4295 if (!si_vm_reg_valid(reg))
4296 return -EINVAL;
4297 }
4298 }
4299 }
4300 break;
4301 case PACKET3_COND_WRITE:
4302 if (idx_value & 0x100) {
4303 reg = ib[idx + 5] * 4;
4304 if (!si_vm_reg_valid(reg))
4305 return -EINVAL;
4306 }
4307 break;
4308 case PACKET3_COPY_DW:
4309 if (idx_value & 0x2) {
4310 reg = ib[idx + 3] * 4;
4311 if (!si_vm_reg_valid(reg))
4312 return -EINVAL;
4313 }
4314 break;
Tom Stellarde5b9e752013-08-16 17:47:39 -04004315 case PACKET3_CP_DMA:
4316 r = si_vm_packet3_cp_dma_check(ib, idx);
4317 if (r)
4318 return r;
4319 break;
Alex Deucher498dd8b2012-03-20 17:18:15 -04004320 default:
4321 DRM_ERROR("Invalid Compute packet3: 0x%x\n", pkt->opcode);
4322 return -EINVAL;
4323 }
4324 return 0;
4325}
4326
4327int si_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
4328{
4329 int ret = 0;
4330 u32 idx = 0;
4331 struct radeon_cs_packet pkt;
4332
4333 do {
4334 pkt.idx = idx;
Ilija Hadzic4e872ae2013-01-02 18:27:48 -05004335 pkt.type = RADEON_CP_PACKET_GET_TYPE(ib->ptr[idx]);
4336 pkt.count = RADEON_CP_PACKET_GET_COUNT(ib->ptr[idx]);
Alex Deucher498dd8b2012-03-20 17:18:15 -04004337 pkt.one_reg_wr = 0;
4338 switch (pkt.type) {
Ilija Hadzic4e872ae2013-01-02 18:27:48 -05004339 case RADEON_PACKET_TYPE0:
Alex Deucher498dd8b2012-03-20 17:18:15 -04004340 dev_err(rdev->dev, "Packet0 not allowed!\n");
4341 ret = -EINVAL;
4342 break;
Ilija Hadzic4e872ae2013-01-02 18:27:48 -05004343 case RADEON_PACKET_TYPE2:
Alex Deucher498dd8b2012-03-20 17:18:15 -04004344 idx += 1;
4345 break;
Ilija Hadzic4e872ae2013-01-02 18:27:48 -05004346 case RADEON_PACKET_TYPE3:
4347 pkt.opcode = RADEON_CP_PACKET3_GET_OPCODE(ib->ptr[idx]);
Alex Deucher498dd8b2012-03-20 17:18:15 -04004348 if (ib->is_const_ib)
4349 ret = si_vm_packet3_ce_check(rdev, ib->ptr, &pkt);
4350 else {
Christian König876dc9f2012-05-08 14:24:01 +02004351 switch (ib->ring) {
Alex Deucher498dd8b2012-03-20 17:18:15 -04004352 case RADEON_RING_TYPE_GFX_INDEX:
4353 ret = si_vm_packet3_gfx_check(rdev, ib->ptr, &pkt);
4354 break;
4355 case CAYMAN_RING_TYPE_CP1_INDEX:
4356 case CAYMAN_RING_TYPE_CP2_INDEX:
4357 ret = si_vm_packet3_compute_check(rdev, ib->ptr, &pkt);
4358 break;
4359 default:
Christian König876dc9f2012-05-08 14:24:01 +02004360 dev_err(rdev->dev, "Non-PM4 ring %d !\n", ib->ring);
Alex Deucher498dd8b2012-03-20 17:18:15 -04004361 ret = -EINVAL;
4362 break;
4363 }
4364 }
4365 idx += pkt.count + 2;
4366 break;
4367 default:
4368 dev_err(rdev->dev, "Unknown packet type %d !\n", pkt.type);
4369 ret = -EINVAL;
4370 break;
4371 }
4372 if (ret)
4373 break;
4374 } while (idx < ib->length_dw);
4375
4376 return ret;
4377}
4378
Alex Deucherd2800ee2012-03-20 17:18:13 -04004379/*
4380 * vm
4381 */
4382int si_vm_init(struct radeon_device *rdev)
4383{
4384 /* number of VMs */
4385 rdev->vm_manager.nvm = 16;
4386 /* base offset of vram pages */
4387 rdev->vm_manager.vram_base_offset = 0;
4388
4389 return 0;
4390}
4391
4392void si_vm_fini(struct radeon_device *rdev)
4393{
4394}
4395
Alex Deucher82ffd922012-10-02 14:47:46 -04004396/**
Alex Deucherfbf6dc72013-06-13 18:47:58 -04004397 * si_vm_decode_fault - print human readable fault info
4398 *
4399 * @rdev: radeon_device pointer
4400 * @status: VM_CONTEXT1_PROTECTION_FAULT_STATUS register value
4401 * @addr: VM_CONTEXT1_PROTECTION_FAULT_ADDR register value
4402 *
4403 * Print human readable fault information (SI).
4404 */
4405static void si_vm_decode_fault(struct radeon_device *rdev,
4406 u32 status, u32 addr)
4407{
4408 u32 mc_id = (status & MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
4409 u32 vmid = (status & FAULT_VMID_MASK) >> FAULT_VMID_SHIFT;
4410 u32 protections = (status & PROTECTIONS_MASK) >> PROTECTIONS_SHIFT;
4411 char *block;
4412
4413 if (rdev->family == CHIP_TAHITI) {
4414 switch (mc_id) {
4415 case 160:
4416 case 144:
4417 case 96:
4418 case 80:
4419 case 224:
4420 case 208:
4421 case 32:
4422 case 16:
4423 block = "CB";
4424 break;
4425 case 161:
4426 case 145:
4427 case 97:
4428 case 81:
4429 case 225:
4430 case 209:
4431 case 33:
4432 case 17:
4433 block = "CB_FMASK";
4434 break;
4435 case 162:
4436 case 146:
4437 case 98:
4438 case 82:
4439 case 226:
4440 case 210:
4441 case 34:
4442 case 18:
4443 block = "CB_CMASK";
4444 break;
4445 case 163:
4446 case 147:
4447 case 99:
4448 case 83:
4449 case 227:
4450 case 211:
4451 case 35:
4452 case 19:
4453 block = "CB_IMMED";
4454 break;
4455 case 164:
4456 case 148:
4457 case 100:
4458 case 84:
4459 case 228:
4460 case 212:
4461 case 36:
4462 case 20:
4463 block = "DB";
4464 break;
4465 case 165:
4466 case 149:
4467 case 101:
4468 case 85:
4469 case 229:
4470 case 213:
4471 case 37:
4472 case 21:
4473 block = "DB_HTILE";
4474 break;
4475 case 167:
4476 case 151:
4477 case 103:
4478 case 87:
4479 case 231:
4480 case 215:
4481 case 39:
4482 case 23:
4483 block = "DB_STEN";
4484 break;
4485 case 72:
4486 case 68:
4487 case 64:
4488 case 8:
4489 case 4:
4490 case 0:
4491 case 136:
4492 case 132:
4493 case 128:
4494 case 200:
4495 case 196:
4496 case 192:
4497 block = "TC";
4498 break;
4499 case 112:
4500 case 48:
4501 block = "CP";
4502 break;
4503 case 49:
4504 case 177:
4505 case 50:
4506 case 178:
4507 block = "SH";
4508 break;
4509 case 53:
4510 case 190:
4511 block = "VGT";
4512 break;
4513 case 117:
4514 block = "IH";
4515 break;
4516 case 51:
4517 case 115:
4518 block = "RLC";
4519 break;
4520 case 119:
4521 case 183:
4522 block = "DMA0";
4523 break;
4524 case 61:
4525 block = "DMA1";
4526 break;
4527 case 248:
4528 case 120:
4529 block = "HDP";
4530 break;
4531 default:
4532 block = "unknown";
4533 break;
4534 }
4535 } else {
4536 switch (mc_id) {
4537 case 32:
4538 case 16:
4539 case 96:
4540 case 80:
4541 case 160:
4542 case 144:
4543 case 224:
4544 case 208:
4545 block = "CB";
4546 break;
4547 case 33:
4548 case 17:
4549 case 97:
4550 case 81:
4551 case 161:
4552 case 145:
4553 case 225:
4554 case 209:
4555 block = "CB_FMASK";
4556 break;
4557 case 34:
4558 case 18:
4559 case 98:
4560 case 82:
4561 case 162:
4562 case 146:
4563 case 226:
4564 case 210:
4565 block = "CB_CMASK";
4566 break;
4567 case 35:
4568 case 19:
4569 case 99:
4570 case 83:
4571 case 163:
4572 case 147:
4573 case 227:
4574 case 211:
4575 block = "CB_IMMED";
4576 break;
4577 case 36:
4578 case 20:
4579 case 100:
4580 case 84:
4581 case 164:
4582 case 148:
4583 case 228:
4584 case 212:
4585 block = "DB";
4586 break;
4587 case 37:
4588 case 21:
4589 case 101:
4590 case 85:
4591 case 165:
4592 case 149:
4593 case 229:
4594 case 213:
4595 block = "DB_HTILE";
4596 break;
4597 case 39:
4598 case 23:
4599 case 103:
4600 case 87:
4601 case 167:
4602 case 151:
4603 case 231:
4604 case 215:
4605 block = "DB_STEN";
4606 break;
4607 case 72:
4608 case 68:
4609 case 8:
4610 case 4:
4611 case 136:
4612 case 132:
4613 case 200:
4614 case 196:
4615 block = "TC";
4616 break;
4617 case 112:
4618 case 48:
4619 block = "CP";
4620 break;
4621 case 49:
4622 case 177:
4623 case 50:
4624 case 178:
4625 block = "SH";
4626 break;
4627 case 53:
4628 block = "VGT";
4629 break;
4630 case 117:
4631 block = "IH";
4632 break;
4633 case 51:
4634 case 115:
4635 block = "RLC";
4636 break;
4637 case 119:
4638 case 183:
4639 block = "DMA0";
4640 break;
4641 case 61:
4642 block = "DMA1";
4643 break;
4644 case 248:
4645 case 120:
4646 block = "HDP";
4647 break;
4648 default:
4649 block = "unknown";
4650 break;
4651 }
4652 }
4653
4654 printk("VM fault (0x%02x, vmid %d) at page %u, %s from %s (%d)\n",
4655 protections, vmid, addr,
4656 (status & MEMORY_CLIENT_RW_MASK) ? "write" : "read",
4657 block, mc_id);
4658}
4659
Alex Deucher498522b2012-10-02 14:43:38 -04004660void si_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
Alex Deucherd2800ee2012-03-20 17:18:13 -04004661{
Alex Deucher498522b2012-10-02 14:43:38 -04004662 struct radeon_ring *ring = &rdev->ring[ridx];
Alex Deucherd2800ee2012-03-20 17:18:13 -04004663
Christian Königee60e292012-08-09 16:21:08 +02004664 if (vm == NULL)
Alex Deucherd2800ee2012-03-20 17:18:13 -04004665 return;
4666
Alex Deucher76c44f22012-10-02 14:39:18 -04004667 /* write new base address */
4668 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
4669 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
4670 WRITE_DATA_DST_SEL(0)));
4671
Christian Königee60e292012-08-09 16:21:08 +02004672 if (vm->id < 8) {
Alex Deucher76c44f22012-10-02 14:39:18 -04004673 radeon_ring_write(ring,
4674 (VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2);
Christian Königee60e292012-08-09 16:21:08 +02004675 } else {
Alex Deucher76c44f22012-10-02 14:39:18 -04004676 radeon_ring_write(ring,
4677 (VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm->id - 8) << 2)) >> 2);
Christian Königee60e292012-08-09 16:21:08 +02004678 }
Alex Deucher76c44f22012-10-02 14:39:18 -04004679 radeon_ring_write(ring, 0);
Dmitry Cherkasovfa87e622012-09-17 19:36:19 +02004680 radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
Christian Königee60e292012-08-09 16:21:08 +02004681
Alex Deucherd2800ee2012-03-20 17:18:13 -04004682 /* flush hdp cache */
Alex Deucher76c44f22012-10-02 14:39:18 -04004683 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
4684 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
4685 WRITE_DATA_DST_SEL(0)));
4686 radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);
4687 radeon_ring_write(ring, 0);
Christian Königee60e292012-08-09 16:21:08 +02004688 radeon_ring_write(ring, 0x1);
4689
Alex Deucherd2800ee2012-03-20 17:18:13 -04004690 /* bits 0-15 are the VM contexts0-15 */
Alex Deucher76c44f22012-10-02 14:39:18 -04004691 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
4692 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
4693 WRITE_DATA_DST_SEL(0)));
4694 radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
4695 radeon_ring_write(ring, 0);
Alex Deucher498522b2012-10-02 14:43:38 -04004696 radeon_ring_write(ring, 1 << vm->id);
Christian König58f8cf52012-10-22 17:42:35 +02004697
4698 /* sync PFP to ME, otherwise we might get invalid PFP reads */
4699 radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
4700 radeon_ring_write(ring, 0x0);
Alex Deucherd2800ee2012-03-20 17:18:13 -04004701}
4702
Alex Deucher347e7592012-03-20 17:18:21 -04004703/*
Alex Deucherf8f84ac2013-03-07 12:56:35 -05004704 * Power and clock gating
4705 */
4706static void si_wait_for_rlc_serdes(struct radeon_device *rdev)
4707{
4708 int i;
4709
4710 for (i = 0; i < rdev->usec_timeout; i++) {
4711 if (RREG32(RLC_SERDES_MASTER_BUSY_0) == 0)
4712 break;
4713 udelay(1);
4714 }
4715
4716 for (i = 0; i < rdev->usec_timeout; i++) {
4717 if (RREG32(RLC_SERDES_MASTER_BUSY_1) == 0)
4718 break;
4719 udelay(1);
4720 }
4721}
4722
4723static void si_enable_gui_idle_interrupt(struct radeon_device *rdev,
4724 bool enable)
4725{
4726 u32 tmp = RREG32(CP_INT_CNTL_RING0);
4727 u32 mask;
4728 int i;
4729
4730 if (enable)
4731 tmp |= (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
4732 else
4733 tmp &= ~(CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
4734 WREG32(CP_INT_CNTL_RING0, tmp);
4735
4736 if (!enable) {
4737 /* read a gfx register */
4738 tmp = RREG32(DB_DEPTH_INFO);
4739
4740 mask = RLC_BUSY_STATUS | GFX_POWER_STATUS | GFX_CLOCK_STATUS | GFX_LS_STATUS;
4741 for (i = 0; i < rdev->usec_timeout; i++) {
4742 if ((RREG32(RLC_STAT) & mask) == (GFX_CLOCK_STATUS | GFX_POWER_STATUS))
4743 break;
4744 udelay(1);
4745 }
4746 }
4747}
4748
4749static void si_set_uvd_dcm(struct radeon_device *rdev,
4750 bool sw_mode)
4751{
4752 u32 tmp, tmp2;
4753
4754 tmp = RREG32(UVD_CGC_CTRL);
4755 tmp &= ~(CLK_OD_MASK | CG_DT_MASK);
4756 tmp |= DCM | CG_DT(1) | CLK_OD(4);
4757
4758 if (sw_mode) {
4759 tmp &= ~0x7ffff800;
4760 tmp2 = DYN_OR_EN | DYN_RR_EN | G_DIV_ID(7);
4761 } else {
4762 tmp |= 0x7ffff800;
4763 tmp2 = 0;
4764 }
4765
4766 WREG32(UVD_CGC_CTRL, tmp);
4767 WREG32_UVD_CTX(UVD_CGC_CTRL2, tmp2);
4768}
4769
Alex Deucher22c775c2013-07-23 09:41:05 -04004770void si_init_uvd_internal_cg(struct radeon_device *rdev)
Alex Deucherf8f84ac2013-03-07 12:56:35 -05004771{
4772 bool hw_mode = true;
4773
4774 if (hw_mode) {
4775 si_set_uvd_dcm(rdev, false);
4776 } else {
4777 u32 tmp = RREG32(UVD_CGC_CTRL);
4778 tmp &= ~DCM;
4779 WREG32(UVD_CGC_CTRL, tmp);
4780 }
4781}
4782
4783static u32 si_halt_rlc(struct radeon_device *rdev)
4784{
4785 u32 data, orig;
4786
4787 orig = data = RREG32(RLC_CNTL);
4788
4789 if (data & RLC_ENABLE) {
4790 data &= ~RLC_ENABLE;
4791 WREG32(RLC_CNTL, data);
4792
4793 si_wait_for_rlc_serdes(rdev);
4794 }
4795
4796 return orig;
4797}
4798
4799static void si_update_rlc(struct radeon_device *rdev, u32 rlc)
4800{
4801 u32 tmp;
4802
4803 tmp = RREG32(RLC_CNTL);
4804 if (tmp != rlc)
4805 WREG32(RLC_CNTL, rlc);
4806}
4807
4808static void si_enable_dma_pg(struct radeon_device *rdev, bool enable)
4809{
4810 u32 data, orig;
4811
4812 orig = data = RREG32(DMA_PG);
Alex Deuchere16866e2013-08-08 19:34:07 -04004813 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_SDMA))
Alex Deucherf8f84ac2013-03-07 12:56:35 -05004814 data |= PG_CNTL_ENABLE;
4815 else
4816 data &= ~PG_CNTL_ENABLE;
4817 if (orig != data)
4818 WREG32(DMA_PG, data);
4819}
4820
4821static void si_init_dma_pg(struct radeon_device *rdev)
4822{
4823 u32 tmp;
4824
4825 WREG32(DMA_PGFSM_WRITE, 0x00002000);
4826 WREG32(DMA_PGFSM_CONFIG, 0x100010ff);
4827
4828 for (tmp = 0; tmp < 5; tmp++)
4829 WREG32(DMA_PGFSM_WRITE, 0);
4830}
4831
4832static void si_enable_gfx_cgpg(struct radeon_device *rdev,
4833 bool enable)
4834{
4835 u32 tmp;
4836
Alex Deucher2b19d172013-09-04 16:58:29 -04004837 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG)) {
Alex Deucherf8f84ac2013-03-07 12:56:35 -05004838 tmp = RLC_PUD(0x10) | RLC_PDD(0x10) | RLC_TTPD(0x10) | RLC_MSD(0x10);
4839 WREG32(RLC_TTOP_D, tmp);
4840
4841 tmp = RREG32(RLC_PG_CNTL);
4842 tmp |= GFX_PG_ENABLE;
4843 WREG32(RLC_PG_CNTL, tmp);
4844
4845 tmp = RREG32(RLC_AUTO_PG_CTRL);
4846 tmp |= AUTO_PG_EN;
4847 WREG32(RLC_AUTO_PG_CTRL, tmp);
4848 } else {
4849 tmp = RREG32(RLC_AUTO_PG_CTRL);
4850 tmp &= ~AUTO_PG_EN;
4851 WREG32(RLC_AUTO_PG_CTRL, tmp);
4852
4853 tmp = RREG32(DB_RENDER_CONTROL);
4854 }
4855}
4856
4857static void si_init_gfx_cgpg(struct radeon_device *rdev)
4858{
4859 u32 tmp;
4860
4861 WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
4862
4863 tmp = RREG32(RLC_PG_CNTL);
4864 tmp |= GFX_PG_SRC;
4865 WREG32(RLC_PG_CNTL, tmp);
4866
4867 WREG32(RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
4868
4869 tmp = RREG32(RLC_AUTO_PG_CTRL);
4870
4871 tmp &= ~GRBM_REG_SGIT_MASK;
4872 tmp |= GRBM_REG_SGIT(0x700);
4873 tmp &= ~PG_AFTER_GRBM_REG_ST_MASK;
4874 WREG32(RLC_AUTO_PG_CTRL, tmp);
4875}
4876
Alex Deucherba190312013-04-17 16:27:40 -04004877static u32 si_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh)
Alex Deucherf8f84ac2013-03-07 12:56:35 -05004878{
4879 u32 mask = 0, tmp, tmp1;
4880 int i;
4881
4882 si_select_se_sh(rdev, se, sh);
4883 tmp = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
4884 tmp1 = RREG32(GC_USER_SHADER_ARRAY_CONFIG);
4885 si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
4886
4887 tmp &= 0xffff0000;
4888
4889 tmp |= tmp1;
4890 tmp >>= 16;
4891
4892 for (i = 0; i < rdev->config.si.max_cu_per_sh; i ++) {
4893 mask <<= 1;
4894 mask |= 1;
4895 }
4896
4897 return (~tmp) & mask;
4898}
4899
4900static void si_init_ao_cu_mask(struct radeon_device *rdev)
4901{
4902 u32 i, j, k, active_cu_number = 0;
4903 u32 mask, counter, cu_bitmap;
4904 u32 tmp = 0;
4905
4906 for (i = 0; i < rdev->config.si.max_shader_engines; i++) {
4907 for (j = 0; j < rdev->config.si.max_sh_per_se; j++) {
4908 mask = 1;
4909 cu_bitmap = 0;
4910 counter = 0;
4911 for (k = 0; k < rdev->config.si.max_cu_per_sh; k++) {
Alex Deucherba190312013-04-17 16:27:40 -04004912 if (si_get_cu_active_bitmap(rdev, i, j) & mask) {
Alex Deucherf8f84ac2013-03-07 12:56:35 -05004913 if (counter < 2)
4914 cu_bitmap |= mask;
4915 counter++;
4916 }
4917 mask <<= 1;
4918 }
4919
4920 active_cu_number += counter;
4921 tmp |= (cu_bitmap << (i * 16 + j * 8));
4922 }
4923 }
4924
4925 WREG32(RLC_PG_AO_CU_MASK, tmp);
4926
4927 tmp = RREG32(RLC_MAX_PG_CU);
4928 tmp &= ~MAX_PU_CU_MASK;
4929 tmp |= MAX_PU_CU(active_cu_number);
4930 WREG32(RLC_MAX_PG_CU, tmp);
4931}
4932
4933static void si_enable_cgcg(struct radeon_device *rdev,
4934 bool enable)
4935{
4936 u32 data, orig, tmp;
4937
4938 orig = data = RREG32(RLC_CGCG_CGLS_CTRL);
4939
Alex Deuchere16866e2013-08-08 19:34:07 -04004940 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGCG)) {
Alex Deucher5594a552013-08-15 16:20:26 -04004941 si_enable_gui_idle_interrupt(rdev, true);
Alex Deucherf8f84ac2013-03-07 12:56:35 -05004942
Alex Deucherf8f84ac2013-03-07 12:56:35 -05004943 WREG32(RLC_GCPM_GENERAL_3, 0x00000080);
4944
4945 tmp = si_halt_rlc(rdev);
4946
4947 WREG32(RLC_SERDES_WR_MASTER_MASK_0, 0xffffffff);
4948 WREG32(RLC_SERDES_WR_MASTER_MASK_1, 0xffffffff);
4949 WREG32(RLC_SERDES_WR_CTRL, 0x00b000ff);
4950
4951 si_wait_for_rlc_serdes(rdev);
4952
4953 si_update_rlc(rdev, tmp);
4954
4955 WREG32(RLC_SERDES_WR_CTRL, 0x007000ff);
4956
4957 data |= CGCG_EN | CGLS_EN;
4958 } else {
Alex Deucher5594a552013-08-15 16:20:26 -04004959 si_enable_gui_idle_interrupt(rdev, false);
4960
Alex Deucherf8f84ac2013-03-07 12:56:35 -05004961 RREG32(CB_CGTT_SCLK_CTRL);
4962 RREG32(CB_CGTT_SCLK_CTRL);
4963 RREG32(CB_CGTT_SCLK_CTRL);
4964 RREG32(CB_CGTT_SCLK_CTRL);
4965
4966 data &= ~(CGCG_EN | CGLS_EN);
4967 }
4968
4969 if (orig != data)
4970 WREG32(RLC_CGCG_CGLS_CTRL, data);
4971}
4972
4973static void si_enable_mgcg(struct radeon_device *rdev,
4974 bool enable)
4975{
4976 u32 data, orig, tmp = 0;
4977
Alex Deuchere16866e2013-08-08 19:34:07 -04004978 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGCG)) {
Alex Deucherf8f84ac2013-03-07 12:56:35 -05004979 orig = data = RREG32(CGTS_SM_CTRL_REG);
4980 data = 0x96940200;
4981 if (orig != data)
4982 WREG32(CGTS_SM_CTRL_REG, data);
4983
Alex Deuchere16866e2013-08-08 19:34:07 -04004984 if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CP_LS) {
4985 orig = data = RREG32(CP_MEM_SLP_CNTL);
4986 data |= CP_MEM_LS_EN;
4987 if (orig != data)
4988 WREG32(CP_MEM_SLP_CNTL, data);
4989 }
Alex Deucherf8f84ac2013-03-07 12:56:35 -05004990
4991 orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
4992 data &= 0xffffffc0;
4993 if (orig != data)
4994 WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
4995
4996 tmp = si_halt_rlc(rdev);
4997
4998 WREG32(RLC_SERDES_WR_MASTER_MASK_0, 0xffffffff);
4999 WREG32(RLC_SERDES_WR_MASTER_MASK_1, 0xffffffff);
5000 WREG32(RLC_SERDES_WR_CTRL, 0x00d000ff);
5001
5002 si_update_rlc(rdev, tmp);
5003 } else {
5004 orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
5005 data |= 0x00000003;
5006 if (orig != data)
5007 WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
5008
5009 data = RREG32(CP_MEM_SLP_CNTL);
5010 if (data & CP_MEM_LS_EN) {
5011 data &= ~CP_MEM_LS_EN;
5012 WREG32(CP_MEM_SLP_CNTL, data);
5013 }
5014 orig = data = RREG32(CGTS_SM_CTRL_REG);
5015 data |= LS_OVERRIDE | OVERRIDE;
5016 if (orig != data)
5017 WREG32(CGTS_SM_CTRL_REG, data);
5018
5019 tmp = si_halt_rlc(rdev);
5020
5021 WREG32(RLC_SERDES_WR_MASTER_MASK_0, 0xffffffff);
5022 WREG32(RLC_SERDES_WR_MASTER_MASK_1, 0xffffffff);
5023 WREG32(RLC_SERDES_WR_CTRL, 0x00e000ff);
5024
5025 si_update_rlc(rdev, tmp);
5026 }
5027}
5028
5029static void si_enable_uvd_mgcg(struct radeon_device *rdev,
5030 bool enable)
5031{
5032 u32 orig, data, tmp;
5033
Alex Deuchere16866e2013-08-08 19:34:07 -04005034 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_UVD_MGCG)) {
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005035 tmp = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
5036 tmp |= 0x3fff;
5037 WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, tmp);
5038
5039 orig = data = RREG32(UVD_CGC_CTRL);
5040 data |= DCM;
5041 if (orig != data)
5042 WREG32(UVD_CGC_CTRL, data);
5043
5044 WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_0, 0);
5045 WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_1, 0);
5046 } else {
5047 tmp = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
5048 tmp &= ~0x3fff;
5049 WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, tmp);
5050
5051 orig = data = RREG32(UVD_CGC_CTRL);
5052 data &= ~DCM;
5053 if (orig != data)
5054 WREG32(UVD_CGC_CTRL, data);
5055
5056 WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_0, 0xffffffff);
5057 WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_1, 0xffffffff);
5058 }
5059}
5060
5061static const u32 mc_cg_registers[] =
5062{
5063 MC_HUB_MISC_HUB_CG,
5064 MC_HUB_MISC_SIP_CG,
5065 MC_HUB_MISC_VM_CG,
5066 MC_XPB_CLK_GAT,
5067 ATC_MISC_CG,
5068 MC_CITF_MISC_WR_CG,
5069 MC_CITF_MISC_RD_CG,
5070 MC_CITF_MISC_VM_CG,
5071 VM_L2_CG,
5072};
5073
5074static void si_enable_mc_ls(struct radeon_device *rdev,
5075 bool enable)
5076{
5077 int i;
5078 u32 orig, data;
5079
5080 for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
5081 orig = data = RREG32(mc_cg_registers[i]);
Alex Deuchere16866e2013-08-08 19:34:07 -04005082 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_LS))
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005083 data |= MC_LS_ENABLE;
5084 else
5085 data &= ~MC_LS_ENABLE;
5086 if (data != orig)
5087 WREG32(mc_cg_registers[i], data);
5088 }
5089}
5090
Alex Deuchere16866e2013-08-08 19:34:07 -04005091static void si_enable_mc_mgcg(struct radeon_device *rdev,
5092 bool enable)
5093{
5094 int i;
5095 u32 orig, data;
5096
5097 for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
5098 orig = data = RREG32(mc_cg_registers[i]);
5099 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_MGCG))
5100 data |= MC_CG_ENABLE;
5101 else
5102 data &= ~MC_CG_ENABLE;
5103 if (data != orig)
5104 WREG32(mc_cg_registers[i], data);
5105 }
5106}
5107
5108static void si_enable_dma_mgcg(struct radeon_device *rdev,
5109 bool enable)
5110{
5111 u32 orig, data, offset;
5112 int i;
5113
5114 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_MGCG)) {
5115 for (i = 0; i < 2; i++) {
5116 if (i == 0)
5117 offset = DMA0_REGISTER_OFFSET;
5118 else
5119 offset = DMA1_REGISTER_OFFSET;
5120 orig = data = RREG32(DMA_POWER_CNTL + offset);
5121 data &= ~MEM_POWER_OVERRIDE;
5122 if (data != orig)
5123 WREG32(DMA_POWER_CNTL + offset, data);
5124 WREG32(DMA_CLK_CTRL + offset, 0x00000100);
5125 }
5126 } else {
5127 for (i = 0; i < 2; i++) {
5128 if (i == 0)
5129 offset = DMA0_REGISTER_OFFSET;
5130 else
5131 offset = DMA1_REGISTER_OFFSET;
5132 orig = data = RREG32(DMA_POWER_CNTL + offset);
5133 data |= MEM_POWER_OVERRIDE;
5134 if (data != orig)
5135 WREG32(DMA_POWER_CNTL + offset, data);
5136
5137 orig = data = RREG32(DMA_CLK_CTRL + offset);
5138 data = 0xff000000;
5139 if (data != orig)
5140 WREG32(DMA_CLK_CTRL + offset, data);
5141 }
5142 }
5143}
5144
5145static void si_enable_bif_mgls(struct radeon_device *rdev,
5146 bool enable)
5147{
5148 u32 orig, data;
5149
5150 orig = data = RREG32_PCIE(PCIE_CNTL2);
5151
5152 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_BIF_LS))
5153 data |= SLV_MEM_LS_EN | MST_MEM_LS_EN |
5154 REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN;
5155 else
5156 data &= ~(SLV_MEM_LS_EN | MST_MEM_LS_EN |
5157 REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN);
5158
5159 if (orig != data)
5160 WREG32_PCIE(PCIE_CNTL2, data);
5161}
5162
5163static void si_enable_hdp_mgcg(struct radeon_device *rdev,
5164 bool enable)
5165{
5166 u32 orig, data;
5167
5168 orig = data = RREG32(HDP_HOST_PATH_CNTL);
5169
5170 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_MGCG))
5171 data &= ~CLOCK_GATING_DIS;
5172 else
5173 data |= CLOCK_GATING_DIS;
5174
5175 if (orig != data)
5176 WREG32(HDP_HOST_PATH_CNTL, data);
5177}
5178
5179static void si_enable_hdp_ls(struct radeon_device *rdev,
5180 bool enable)
5181{
5182 u32 orig, data;
5183
5184 orig = data = RREG32(HDP_MEM_POWER_LS);
5185
5186 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_LS))
5187 data |= HDP_LS_ENABLE;
5188 else
5189 data &= ~HDP_LS_ENABLE;
5190
5191 if (orig != data)
5192 WREG32(HDP_MEM_POWER_LS, data);
5193}
5194
5195void si_update_cg(struct radeon_device *rdev,
5196 u32 block, bool enable)
5197{
5198 if (block & RADEON_CG_BLOCK_GFX) {
Alex Deucher811e4d52013-09-03 13:31:33 -04005199 si_enable_gui_idle_interrupt(rdev, false);
Alex Deuchere16866e2013-08-08 19:34:07 -04005200 /* order matters! */
5201 if (enable) {
5202 si_enable_mgcg(rdev, true);
5203 si_enable_cgcg(rdev, true);
5204 } else {
5205 si_enable_cgcg(rdev, false);
5206 si_enable_mgcg(rdev, false);
5207 }
Alex Deucher811e4d52013-09-03 13:31:33 -04005208 si_enable_gui_idle_interrupt(rdev, true);
Alex Deuchere16866e2013-08-08 19:34:07 -04005209 }
5210
5211 if (block & RADEON_CG_BLOCK_MC) {
5212 si_enable_mc_mgcg(rdev, enable);
5213 si_enable_mc_ls(rdev, enable);
5214 }
5215
5216 if (block & RADEON_CG_BLOCK_SDMA) {
5217 si_enable_dma_mgcg(rdev, enable);
5218 }
5219
5220 if (block & RADEON_CG_BLOCK_BIF) {
5221 si_enable_bif_mgls(rdev, enable);
5222 }
5223
5224 if (block & RADEON_CG_BLOCK_UVD) {
5225 if (rdev->has_uvd) {
5226 si_enable_uvd_mgcg(rdev, enable);
5227 }
5228 }
5229
5230 if (block & RADEON_CG_BLOCK_HDP) {
5231 si_enable_hdp_mgcg(rdev, enable);
5232 si_enable_hdp_ls(rdev, enable);
5233 }
5234}
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005235
5236static void si_init_cg(struct radeon_device *rdev)
5237{
Alex Deuchere16866e2013-08-08 19:34:07 -04005238 si_update_cg(rdev, (RADEON_CG_BLOCK_GFX |
5239 RADEON_CG_BLOCK_MC |
5240 RADEON_CG_BLOCK_SDMA |
5241 RADEON_CG_BLOCK_BIF |
5242 RADEON_CG_BLOCK_HDP), true);
Alex Deucherb2d70912013-07-27 17:53:25 -04005243 if (rdev->has_uvd) {
Alex Deuchere16866e2013-08-08 19:34:07 -04005244 si_update_cg(rdev, RADEON_CG_BLOCK_UVD, true);
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005245 si_init_uvd_internal_cg(rdev);
5246 }
5247}
5248
5249static void si_fini_cg(struct radeon_device *rdev)
5250{
Alex Deucher0116e1e2013-08-08 18:00:10 -04005251 if (rdev->has_uvd) {
Alex Deuchere16866e2013-08-08 19:34:07 -04005252 si_update_cg(rdev, RADEON_CG_BLOCK_UVD, false);
Alex Deucher0116e1e2013-08-08 18:00:10 -04005253 }
Alex Deuchere16866e2013-08-08 19:34:07 -04005254 si_update_cg(rdev, (RADEON_CG_BLOCK_GFX |
5255 RADEON_CG_BLOCK_MC |
5256 RADEON_CG_BLOCK_SDMA |
5257 RADEON_CG_BLOCK_BIF |
5258 RADEON_CG_BLOCK_HDP), false);
5259}
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005260
Alex Deucher59a82d02013-08-13 12:48:06 -04005261u32 si_get_csb_size(struct radeon_device *rdev)
5262{
5263 u32 count = 0;
5264 const struct cs_section_def *sect = NULL;
5265 const struct cs_extent_def *ext = NULL;
5266
5267 if (rdev->rlc.cs_data == NULL)
5268 return 0;
5269
5270 /* begin clear state */
5271 count += 2;
5272 /* context control state */
5273 count += 3;
5274
5275 for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
5276 for (ext = sect->section; ext->extent != NULL; ++ext) {
5277 if (sect->id == SECT_CONTEXT)
5278 count += 2 + ext->reg_count;
5279 else
5280 return 0;
5281 }
5282 }
5283 /* pa_sc_raster_config */
5284 count += 3;
5285 /* end clear state */
5286 count += 2;
5287 /* clear state */
5288 count += 2;
5289
5290 return count;
5291}
5292
5293void si_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer)
5294{
5295 u32 count = 0, i;
5296 const struct cs_section_def *sect = NULL;
5297 const struct cs_extent_def *ext = NULL;
5298
5299 if (rdev->rlc.cs_data == NULL)
5300 return;
5301 if (buffer == NULL)
5302 return;
5303
Alex Deucher6ba81e52013-10-23 18:27:10 -04005304 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
5305 buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
Alex Deucher59a82d02013-08-13 12:48:06 -04005306
Alex Deucher6ba81e52013-10-23 18:27:10 -04005307 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
5308 buffer[count++] = cpu_to_le32(0x80000000);
5309 buffer[count++] = cpu_to_le32(0x80000000);
Alex Deucher59a82d02013-08-13 12:48:06 -04005310
5311 for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
5312 for (ext = sect->section; ext->extent != NULL; ++ext) {
5313 if (sect->id == SECT_CONTEXT) {
Alex Deucher6ba81e52013-10-23 18:27:10 -04005314 buffer[count++] =
5315 cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
5316 buffer[count++] = cpu_to_le32(ext->reg_index - 0xa000);
Alex Deucher59a82d02013-08-13 12:48:06 -04005317 for (i = 0; i < ext->reg_count; i++)
Alex Deucher6ba81e52013-10-23 18:27:10 -04005318 buffer[count++] = cpu_to_le32(ext->extent[i]);
Alex Deucher59a82d02013-08-13 12:48:06 -04005319 } else {
5320 return;
5321 }
5322 }
5323 }
5324
Alex Deucher6ba81e52013-10-23 18:27:10 -04005325 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 1));
5326 buffer[count++] = cpu_to_le32(PA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
Alex Deucher59a82d02013-08-13 12:48:06 -04005327 switch (rdev->family) {
5328 case CHIP_TAHITI:
5329 case CHIP_PITCAIRN:
Alex Deucher6ba81e52013-10-23 18:27:10 -04005330 buffer[count++] = cpu_to_le32(0x2a00126a);
Alex Deucher59a82d02013-08-13 12:48:06 -04005331 break;
5332 case CHIP_VERDE:
Alex Deucher6ba81e52013-10-23 18:27:10 -04005333 buffer[count++] = cpu_to_le32(0x0000124a);
Alex Deucher59a82d02013-08-13 12:48:06 -04005334 break;
5335 case CHIP_OLAND:
Alex Deucher6ba81e52013-10-23 18:27:10 -04005336 buffer[count++] = cpu_to_le32(0x00000082);
Alex Deucher59a82d02013-08-13 12:48:06 -04005337 break;
5338 case CHIP_HAINAN:
Alex Deucher6ba81e52013-10-23 18:27:10 -04005339 buffer[count++] = cpu_to_le32(0x00000000);
Alex Deucher59a82d02013-08-13 12:48:06 -04005340 break;
5341 default:
Alex Deucher6ba81e52013-10-23 18:27:10 -04005342 buffer[count++] = cpu_to_le32(0x00000000);
Alex Deucher59a82d02013-08-13 12:48:06 -04005343 break;
5344 }
5345
Alex Deucher6ba81e52013-10-23 18:27:10 -04005346 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
5347 buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);
Alex Deucher59a82d02013-08-13 12:48:06 -04005348
Alex Deucher6ba81e52013-10-23 18:27:10 -04005349 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
5350 buffer[count++] = cpu_to_le32(0);
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005351}
5352
5353static void si_init_pg(struct radeon_device *rdev)
5354{
Alex Deucher0116e1e2013-08-08 18:00:10 -04005355 if (rdev->pg_flags) {
5356 if (rdev->pg_flags & RADEON_PG_SUPPORT_SDMA) {
5357 si_init_dma_pg(rdev);
Alex Deucher0116e1e2013-08-08 18:00:10 -04005358 }
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005359 si_init_ao_cu_mask(rdev);
Alex Deucher2b19d172013-09-04 16:58:29 -04005360 if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG) {
Alex Deucher0116e1e2013-08-08 18:00:10 -04005361 si_init_gfx_cgpg(rdev);
Alex Deucher0116e1e2013-08-08 18:00:10 -04005362 }
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005363 si_enable_dma_pg(rdev, true);
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005364 si_enable_gfx_cgpg(rdev, true);
5365 } else {
5366 WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
5367 WREG32(RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
5368 }
5369}
5370
5371static void si_fini_pg(struct radeon_device *rdev)
5372{
Alex Deucher0116e1e2013-08-08 18:00:10 -04005373 if (rdev->pg_flags) {
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005374 si_enable_dma_pg(rdev, false);
5375 si_enable_gfx_cgpg(rdev, false);
5376 }
5377}
5378
5379/*
Alex Deucher347e7592012-03-20 17:18:21 -04005380 * RLC
5381 */
Alex Deucher866d83d2013-04-15 17:13:29 -04005382void si_rlc_reset(struct radeon_device *rdev)
Alex Deucherd719cef2013-02-15 16:49:59 -05005383{
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005384 u32 tmp = RREG32(GRBM_SOFT_RESET);
Alex Deucherd719cef2013-02-15 16:49:59 -05005385
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005386 tmp |= SOFT_RESET_RLC;
5387 WREG32(GRBM_SOFT_RESET, tmp);
5388 udelay(50);
5389 tmp &= ~SOFT_RESET_RLC;
5390 WREG32(GRBM_SOFT_RESET, tmp);
5391 udelay(50);
Alex Deucherd719cef2013-02-15 16:49:59 -05005392}
5393
Alex Deucher347e7592012-03-20 17:18:21 -04005394static void si_rlc_stop(struct radeon_device *rdev)
5395{
5396 WREG32(RLC_CNTL, 0);
Alex Deucherd719cef2013-02-15 16:49:59 -05005397
5398 si_enable_gui_idle_interrupt(rdev, false);
5399
5400 si_wait_for_rlc_serdes(rdev);
Alex Deucher347e7592012-03-20 17:18:21 -04005401}
5402
5403static void si_rlc_start(struct radeon_device *rdev)
5404{
5405 WREG32(RLC_CNTL, RLC_ENABLE);
Alex Deucherd719cef2013-02-15 16:49:59 -05005406
5407 si_enable_gui_idle_interrupt(rdev, true);
5408
5409 udelay(50);
5410}
5411
5412static bool si_lbpw_supported(struct radeon_device *rdev)
5413{
5414 u32 tmp;
5415
5416 /* Enable LBPW only for DDR3 */
5417 tmp = RREG32(MC_SEQ_MISC0);
5418 if ((tmp & 0xF0000000) == 0xB0000000)
5419 return true;
5420 return false;
5421}
5422
5423static void si_enable_lbpw(struct radeon_device *rdev, bool enable)
5424{
5425 u32 tmp;
5426
5427 tmp = RREG32(RLC_LB_CNTL);
5428 if (enable)
5429 tmp |= LOAD_BALANCE_ENABLE;
5430 else
5431 tmp &= ~LOAD_BALANCE_ENABLE;
5432 WREG32(RLC_LB_CNTL, tmp);
5433
5434 if (!enable) {
5435 si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
5436 WREG32(SPI_LB_CU_MASK, 0x00ff);
5437 }
Alex Deucher347e7592012-03-20 17:18:21 -04005438}
5439
5440static int si_rlc_resume(struct radeon_device *rdev)
5441{
5442 u32 i;
5443 const __be32 *fw_data;
5444
5445 if (!rdev->rlc_fw)
5446 return -EINVAL;
5447
5448 si_rlc_stop(rdev);
5449
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005450 si_rlc_reset(rdev);
5451
5452 si_init_pg(rdev);
5453
5454 si_init_cg(rdev);
5455
Alex Deucher347e7592012-03-20 17:18:21 -04005456 WREG32(RLC_RL_BASE, 0);
5457 WREG32(RLC_RL_SIZE, 0);
5458 WREG32(RLC_LB_CNTL, 0);
5459 WREG32(RLC_LB_CNTR_MAX, 0xffffffff);
5460 WREG32(RLC_LB_CNTR_INIT, 0);
Alex Deucherd719cef2013-02-15 16:49:59 -05005461 WREG32(RLC_LB_INIT_CU_MASK, 0xffffffff);
Alex Deucher347e7592012-03-20 17:18:21 -04005462
Alex Deucher347e7592012-03-20 17:18:21 -04005463 WREG32(RLC_MC_CNTL, 0);
5464 WREG32(RLC_UCODE_CNTL, 0);
5465
5466 fw_data = (const __be32 *)rdev->rlc_fw->data;
5467 for (i = 0; i < SI_RLC_UCODE_SIZE; i++) {
5468 WREG32(RLC_UCODE_ADDR, i);
5469 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
5470 }
5471 WREG32(RLC_UCODE_ADDR, 0);
5472
Alex Deucherd719cef2013-02-15 16:49:59 -05005473 si_enable_lbpw(rdev, si_lbpw_supported(rdev));
5474
Alex Deucher347e7592012-03-20 17:18:21 -04005475 si_rlc_start(rdev);
5476
5477 return 0;
5478}
5479
Alex Deucher25a857f2012-03-20 17:18:22 -04005480static void si_enable_interrupts(struct radeon_device *rdev)
5481{
5482 u32 ih_cntl = RREG32(IH_CNTL);
5483 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
5484
5485 ih_cntl |= ENABLE_INTR;
5486 ih_rb_cntl |= IH_RB_ENABLE;
5487 WREG32(IH_CNTL, ih_cntl);
5488 WREG32(IH_RB_CNTL, ih_rb_cntl);
5489 rdev->ih.enabled = true;
5490}
5491
5492static void si_disable_interrupts(struct radeon_device *rdev)
5493{
5494 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
5495 u32 ih_cntl = RREG32(IH_CNTL);
5496
5497 ih_rb_cntl &= ~IH_RB_ENABLE;
5498 ih_cntl &= ~ENABLE_INTR;
5499 WREG32(IH_RB_CNTL, ih_rb_cntl);
5500 WREG32(IH_CNTL, ih_cntl);
5501 /* set rptr, wptr to 0 */
5502 WREG32(IH_RB_RPTR, 0);
5503 WREG32(IH_RB_WPTR, 0);
5504 rdev->ih.enabled = false;
Alex Deucher25a857f2012-03-20 17:18:22 -04005505 rdev->ih.rptr = 0;
5506}
5507
5508static void si_disable_interrupt_state(struct radeon_device *rdev)
5509{
5510 u32 tmp;
5511
Alex Deucher811e4d52013-09-03 13:31:33 -04005512 tmp = RREG32(CP_INT_CNTL_RING0) &
5513 (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
5514 WREG32(CP_INT_CNTL_RING0, tmp);
Alex Deucher25a857f2012-03-20 17:18:22 -04005515 WREG32(CP_INT_CNTL_RING1, 0);
5516 WREG32(CP_INT_CNTL_RING2, 0);
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05005517 tmp = RREG32(DMA_CNTL + DMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
5518 WREG32(DMA_CNTL + DMA0_REGISTER_OFFSET, tmp);
5519 tmp = RREG32(DMA_CNTL + DMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
5520 WREG32(DMA_CNTL + DMA1_REGISTER_OFFSET, tmp);
Alex Deucher25a857f2012-03-20 17:18:22 -04005521 WREG32(GRBM_INT_CNTL, 0);
Alex Deucher51535502012-08-30 14:34:30 -04005522 if (rdev->num_crtc >= 2) {
5523 WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
5524 WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
5525 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005526 if (rdev->num_crtc >= 4) {
5527 WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
5528 WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
5529 }
5530 if (rdev->num_crtc >= 6) {
5531 WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
5532 WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
5533 }
5534
Alex Deucher51535502012-08-30 14:34:30 -04005535 if (rdev->num_crtc >= 2) {
5536 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
5537 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
5538 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005539 if (rdev->num_crtc >= 4) {
5540 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
5541 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
5542 }
5543 if (rdev->num_crtc >= 6) {
5544 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
5545 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
5546 }
5547
Alex Deucher51535502012-08-30 14:34:30 -04005548 if (!ASIC_IS_NODCE(rdev)) {
5549 WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
Alex Deucher25a857f2012-03-20 17:18:22 -04005550
Alex Deucher51535502012-08-30 14:34:30 -04005551 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5552 WREG32(DC_HPD1_INT_CONTROL, tmp);
5553 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5554 WREG32(DC_HPD2_INT_CONTROL, tmp);
5555 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5556 WREG32(DC_HPD3_INT_CONTROL, tmp);
5557 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5558 WREG32(DC_HPD4_INT_CONTROL, tmp);
5559 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5560 WREG32(DC_HPD5_INT_CONTROL, tmp);
5561 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5562 WREG32(DC_HPD6_INT_CONTROL, tmp);
5563 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005564}
5565
5566static int si_irq_init(struct radeon_device *rdev)
5567{
5568 int ret = 0;
5569 int rb_bufsz;
5570 u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
5571
5572 /* allocate ring */
5573 ret = r600_ih_ring_alloc(rdev);
5574 if (ret)
5575 return ret;
5576
5577 /* disable irqs */
5578 si_disable_interrupts(rdev);
5579
5580 /* init rlc */
5581 ret = si_rlc_resume(rdev);
5582 if (ret) {
5583 r600_ih_ring_fini(rdev);
5584 return ret;
5585 }
5586
5587 /* setup interrupt control */
5588 /* set dummy read address to ring address */
5589 WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
5590 interrupt_cntl = RREG32(INTERRUPT_CNTL);
5591 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
5592 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
5593 */
5594 interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
5595 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
5596 interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
5597 WREG32(INTERRUPT_CNTL, interrupt_cntl);
5598
5599 WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
Daniel Vetterb72a8922013-07-10 14:11:59 +02005600 rb_bufsz = order_base_2(rdev->ih.ring_size / 4);
Alex Deucher25a857f2012-03-20 17:18:22 -04005601
5602 ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
5603 IH_WPTR_OVERFLOW_CLEAR |
5604 (rb_bufsz << 1));
5605
5606 if (rdev->wb.enabled)
5607 ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
5608
5609 /* set the writeback address whether it's enabled or not */
5610 WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
5611 WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
5612
5613 WREG32(IH_RB_CNTL, ih_rb_cntl);
5614
5615 /* set rptr, wptr to 0 */
5616 WREG32(IH_RB_RPTR, 0);
5617 WREG32(IH_RB_WPTR, 0);
5618
5619 /* Default settings for IH_CNTL (disabled at first) */
5620 ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10) | MC_VMID(0);
5621 /* RPTR_REARM only works if msi's are enabled */
5622 if (rdev->msi_enabled)
5623 ih_cntl |= RPTR_REARM;
5624 WREG32(IH_CNTL, ih_cntl);
5625
5626 /* force the active interrupt state to all disabled */
5627 si_disable_interrupt_state(rdev);
5628
Dave Airlie20998102012-04-03 11:53:05 +01005629 pci_set_master(rdev->pdev);
5630
Alex Deucher25a857f2012-03-20 17:18:22 -04005631 /* enable irqs */
5632 si_enable_interrupts(rdev);
5633
5634 return ret;
5635}
5636
5637int si_irq_set(struct radeon_device *rdev)
5638{
Alex Deucher811e4d52013-09-03 13:31:33 -04005639 u32 cp_int_cntl;
Alex Deucher25a857f2012-03-20 17:18:22 -04005640 u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0;
5641 u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
Alex Deucher51535502012-08-30 14:34:30 -04005642 u32 hpd1 = 0, hpd2 = 0, hpd3 = 0, hpd4 = 0, hpd5 = 0, hpd6 = 0;
Alex Deucher25a857f2012-03-20 17:18:22 -04005643 u32 grbm_int_cntl = 0;
5644 u32 grph1 = 0, grph2 = 0, grph3 = 0, grph4 = 0, grph5 = 0, grph6 = 0;
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05005645 u32 dma_cntl, dma_cntl1;
Alex Deuchera9e61412013-06-25 17:56:16 -04005646 u32 thermal_int = 0;
Alex Deucher25a857f2012-03-20 17:18:22 -04005647
5648 if (!rdev->irq.installed) {
5649 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
5650 return -EINVAL;
5651 }
5652 /* don't enable anything if the ih is disabled */
5653 if (!rdev->ih.enabled) {
5654 si_disable_interrupts(rdev);
5655 /* force the active interrupt state to all disabled */
5656 si_disable_interrupt_state(rdev);
5657 return 0;
5658 }
5659
Alex Deucher811e4d52013-09-03 13:31:33 -04005660 cp_int_cntl = RREG32(CP_INT_CNTL_RING0) &
5661 (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
5662
Alex Deucher51535502012-08-30 14:34:30 -04005663 if (!ASIC_IS_NODCE(rdev)) {
5664 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
5665 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
5666 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
5667 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
5668 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
5669 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
5670 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005671
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05005672 dma_cntl = RREG32(DMA_CNTL + DMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
5673 dma_cntl1 = RREG32(DMA_CNTL + DMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
5674
Alex Deuchera9e61412013-06-25 17:56:16 -04005675 thermal_int = RREG32(CG_THERMAL_INT) &
5676 ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
5677
Alex Deucher25a857f2012-03-20 17:18:22 -04005678 /* enable CP interrupts on all rings */
Christian Koenig736fc372012-05-17 19:52:00 +02005679 if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005680 DRM_DEBUG("si_irq_set: sw int gfx\n");
5681 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
5682 }
Christian Koenig736fc372012-05-17 19:52:00 +02005683 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005684 DRM_DEBUG("si_irq_set: sw int cp1\n");
5685 cp_int_cntl1 |= TIME_STAMP_INT_ENABLE;
5686 }
Christian Koenig736fc372012-05-17 19:52:00 +02005687 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005688 DRM_DEBUG("si_irq_set: sw int cp2\n");
5689 cp_int_cntl2 |= TIME_STAMP_INT_ENABLE;
5690 }
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05005691 if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
5692 DRM_DEBUG("si_irq_set: sw int dma\n");
5693 dma_cntl |= TRAP_ENABLE;
5694 }
5695
5696 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
5697 DRM_DEBUG("si_irq_set: sw int dma1\n");
5698 dma_cntl1 |= TRAP_ENABLE;
5699 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005700 if (rdev->irq.crtc_vblank_int[0] ||
Christian Koenig736fc372012-05-17 19:52:00 +02005701 atomic_read(&rdev->irq.pflip[0])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005702 DRM_DEBUG("si_irq_set: vblank 0\n");
5703 crtc1 |= VBLANK_INT_MASK;
5704 }
5705 if (rdev->irq.crtc_vblank_int[1] ||
Christian Koenig736fc372012-05-17 19:52:00 +02005706 atomic_read(&rdev->irq.pflip[1])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005707 DRM_DEBUG("si_irq_set: vblank 1\n");
5708 crtc2 |= VBLANK_INT_MASK;
5709 }
5710 if (rdev->irq.crtc_vblank_int[2] ||
Christian Koenig736fc372012-05-17 19:52:00 +02005711 atomic_read(&rdev->irq.pflip[2])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005712 DRM_DEBUG("si_irq_set: vblank 2\n");
5713 crtc3 |= VBLANK_INT_MASK;
5714 }
5715 if (rdev->irq.crtc_vblank_int[3] ||
Christian Koenig736fc372012-05-17 19:52:00 +02005716 atomic_read(&rdev->irq.pflip[3])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005717 DRM_DEBUG("si_irq_set: vblank 3\n");
5718 crtc4 |= VBLANK_INT_MASK;
5719 }
5720 if (rdev->irq.crtc_vblank_int[4] ||
Christian Koenig736fc372012-05-17 19:52:00 +02005721 atomic_read(&rdev->irq.pflip[4])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005722 DRM_DEBUG("si_irq_set: vblank 4\n");
5723 crtc5 |= VBLANK_INT_MASK;
5724 }
5725 if (rdev->irq.crtc_vblank_int[5] ||
Christian Koenig736fc372012-05-17 19:52:00 +02005726 atomic_read(&rdev->irq.pflip[5])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005727 DRM_DEBUG("si_irq_set: vblank 5\n");
5728 crtc6 |= VBLANK_INT_MASK;
5729 }
5730 if (rdev->irq.hpd[0]) {
5731 DRM_DEBUG("si_irq_set: hpd 1\n");
5732 hpd1 |= DC_HPDx_INT_EN;
5733 }
5734 if (rdev->irq.hpd[1]) {
5735 DRM_DEBUG("si_irq_set: hpd 2\n");
5736 hpd2 |= DC_HPDx_INT_EN;
5737 }
5738 if (rdev->irq.hpd[2]) {
5739 DRM_DEBUG("si_irq_set: hpd 3\n");
5740 hpd3 |= DC_HPDx_INT_EN;
5741 }
5742 if (rdev->irq.hpd[3]) {
5743 DRM_DEBUG("si_irq_set: hpd 4\n");
5744 hpd4 |= DC_HPDx_INT_EN;
5745 }
5746 if (rdev->irq.hpd[4]) {
5747 DRM_DEBUG("si_irq_set: hpd 5\n");
5748 hpd5 |= DC_HPDx_INT_EN;
5749 }
5750 if (rdev->irq.hpd[5]) {
5751 DRM_DEBUG("si_irq_set: hpd 6\n");
5752 hpd6 |= DC_HPDx_INT_EN;
5753 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005754
5755 WREG32(CP_INT_CNTL_RING0, cp_int_cntl);
5756 WREG32(CP_INT_CNTL_RING1, cp_int_cntl1);
5757 WREG32(CP_INT_CNTL_RING2, cp_int_cntl2);
5758
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05005759 WREG32(DMA_CNTL + DMA0_REGISTER_OFFSET, dma_cntl);
5760 WREG32(DMA_CNTL + DMA1_REGISTER_OFFSET, dma_cntl1);
5761
Alex Deucher25a857f2012-03-20 17:18:22 -04005762 WREG32(GRBM_INT_CNTL, grbm_int_cntl);
5763
Alex Deuchera9e61412013-06-25 17:56:16 -04005764 if (rdev->irq.dpm_thermal) {
5765 DRM_DEBUG("dpm thermal\n");
5766 thermal_int |= THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW;
5767 }
5768
Alex Deucher51535502012-08-30 14:34:30 -04005769 if (rdev->num_crtc >= 2) {
5770 WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
5771 WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
5772 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005773 if (rdev->num_crtc >= 4) {
5774 WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
5775 WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
5776 }
5777 if (rdev->num_crtc >= 6) {
5778 WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
5779 WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
5780 }
5781
Alex Deucher51535502012-08-30 14:34:30 -04005782 if (rdev->num_crtc >= 2) {
5783 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, grph1);
5784 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, grph2);
5785 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005786 if (rdev->num_crtc >= 4) {
5787 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, grph3);
5788 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, grph4);
5789 }
5790 if (rdev->num_crtc >= 6) {
5791 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, grph5);
5792 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, grph6);
5793 }
5794
Alex Deucher51535502012-08-30 14:34:30 -04005795 if (!ASIC_IS_NODCE(rdev)) {
5796 WREG32(DC_HPD1_INT_CONTROL, hpd1);
5797 WREG32(DC_HPD2_INT_CONTROL, hpd2);
5798 WREG32(DC_HPD3_INT_CONTROL, hpd3);
5799 WREG32(DC_HPD4_INT_CONTROL, hpd4);
5800 WREG32(DC_HPD5_INT_CONTROL, hpd5);
5801 WREG32(DC_HPD6_INT_CONTROL, hpd6);
5802 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005803
Alex Deuchera9e61412013-06-25 17:56:16 -04005804 WREG32(CG_THERMAL_INT, thermal_int);
5805
Alex Deucher25a857f2012-03-20 17:18:22 -04005806 return 0;
5807}
5808
5809static inline void si_irq_ack(struct radeon_device *rdev)
5810{
5811 u32 tmp;
5812
Alex Deucher51535502012-08-30 14:34:30 -04005813 if (ASIC_IS_NODCE(rdev))
5814 return;
5815
Alex Deucher25a857f2012-03-20 17:18:22 -04005816 rdev->irq.stat_regs.evergreen.disp_int = RREG32(DISP_INTERRUPT_STATUS);
5817 rdev->irq.stat_regs.evergreen.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
5818 rdev->irq.stat_regs.evergreen.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
5819 rdev->irq.stat_regs.evergreen.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
5820 rdev->irq.stat_regs.evergreen.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
5821 rdev->irq.stat_regs.evergreen.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
5822 rdev->irq.stat_regs.evergreen.d1grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
5823 rdev->irq.stat_regs.evergreen.d2grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
5824 if (rdev->num_crtc >= 4) {
5825 rdev->irq.stat_regs.evergreen.d3grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
5826 rdev->irq.stat_regs.evergreen.d4grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
5827 }
5828 if (rdev->num_crtc >= 6) {
5829 rdev->irq.stat_regs.evergreen.d5grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
5830 rdev->irq.stat_regs.evergreen.d6grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
5831 }
5832
5833 if (rdev->irq.stat_regs.evergreen.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
5834 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
5835 if (rdev->irq.stat_regs.evergreen.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
5836 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
5837 if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT)
5838 WREG32(VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
5839 if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT)
5840 WREG32(VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
5841 if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
5842 WREG32(VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
5843 if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT)
5844 WREG32(VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
5845
5846 if (rdev->num_crtc >= 4) {
5847 if (rdev->irq.stat_regs.evergreen.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
5848 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
5849 if (rdev->irq.stat_regs.evergreen.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
5850 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
5851 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
5852 WREG32(VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
5853 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
5854 WREG32(VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
5855 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
5856 WREG32(VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
5857 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
5858 WREG32(VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
5859 }
5860
5861 if (rdev->num_crtc >= 6) {
5862 if (rdev->irq.stat_regs.evergreen.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
5863 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
5864 if (rdev->irq.stat_regs.evergreen.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
5865 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
5866 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
5867 WREG32(VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
5868 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
5869 WREG32(VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
5870 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
5871 WREG32(VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
5872 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
5873 WREG32(VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
5874 }
5875
5876 if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
5877 tmp = RREG32(DC_HPD1_INT_CONTROL);
5878 tmp |= DC_HPDx_INT_ACK;
5879 WREG32(DC_HPD1_INT_CONTROL, tmp);
5880 }
5881 if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
5882 tmp = RREG32(DC_HPD2_INT_CONTROL);
5883 tmp |= DC_HPDx_INT_ACK;
5884 WREG32(DC_HPD2_INT_CONTROL, tmp);
5885 }
5886 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
5887 tmp = RREG32(DC_HPD3_INT_CONTROL);
5888 tmp |= DC_HPDx_INT_ACK;
5889 WREG32(DC_HPD3_INT_CONTROL, tmp);
5890 }
5891 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
5892 tmp = RREG32(DC_HPD4_INT_CONTROL);
5893 tmp |= DC_HPDx_INT_ACK;
5894 WREG32(DC_HPD4_INT_CONTROL, tmp);
5895 }
5896 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
5897 tmp = RREG32(DC_HPD5_INT_CONTROL);
5898 tmp |= DC_HPDx_INT_ACK;
5899 WREG32(DC_HPD5_INT_CONTROL, tmp);
5900 }
5901 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
5902 tmp = RREG32(DC_HPD5_INT_CONTROL);
5903 tmp |= DC_HPDx_INT_ACK;
5904 WREG32(DC_HPD6_INT_CONTROL, tmp);
5905 }
5906}
5907
5908static void si_irq_disable(struct radeon_device *rdev)
5909{
5910 si_disable_interrupts(rdev);
5911 /* Wait and acknowledge irq */
5912 mdelay(1);
5913 si_irq_ack(rdev);
5914 si_disable_interrupt_state(rdev);
5915}
5916
5917static void si_irq_suspend(struct radeon_device *rdev)
5918{
5919 si_irq_disable(rdev);
5920 si_rlc_stop(rdev);
5921}
5922
Alex Deucher9b136d52012-03-20 17:18:23 -04005923static void si_irq_fini(struct radeon_device *rdev)
5924{
5925 si_irq_suspend(rdev);
5926 r600_ih_ring_fini(rdev);
5927}
5928
Alex Deucher25a857f2012-03-20 17:18:22 -04005929static inline u32 si_get_ih_wptr(struct radeon_device *rdev)
5930{
5931 u32 wptr, tmp;
5932
5933 if (rdev->wb.enabled)
5934 wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
5935 else
5936 wptr = RREG32(IH_RB_WPTR);
5937
5938 if (wptr & RB_OVERFLOW) {
5939 /* When a ring buffer overflow happen start parsing interrupt
5940 * from the last not overwritten vector (wptr + 16). Hopefully
5941 * this should allow us to catchup.
5942 */
5943 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
5944 wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
5945 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
5946 tmp = RREG32(IH_RB_CNTL);
5947 tmp |= IH_WPTR_OVERFLOW_CLEAR;
5948 WREG32(IH_RB_CNTL, tmp);
5949 }
5950 return (wptr & rdev->ih.ptr_mask);
5951}
5952
5953/* SI IV Ring
5954 * Each IV ring entry is 128 bits:
5955 * [7:0] - interrupt source id
5956 * [31:8] - reserved
5957 * [59:32] - interrupt source data
5958 * [63:60] - reserved
5959 * [71:64] - RINGID
5960 * [79:72] - VMID
5961 * [127:80] - reserved
5962 */
5963int si_irq_process(struct radeon_device *rdev)
5964{
5965 u32 wptr;
5966 u32 rptr;
5967 u32 src_id, src_data, ring_id;
5968 u32 ring_index;
Alex Deucher25a857f2012-03-20 17:18:22 -04005969 bool queue_hotplug = false;
Alex Deuchera9e61412013-06-25 17:56:16 -04005970 bool queue_thermal = false;
Alex Deucherfbf6dc72013-06-13 18:47:58 -04005971 u32 status, addr;
Alex Deucher25a857f2012-03-20 17:18:22 -04005972
5973 if (!rdev->ih.enabled || rdev->shutdown)
5974 return IRQ_NONE;
5975
5976 wptr = si_get_ih_wptr(rdev);
Christian Koenigc20dc362012-05-16 21:45:24 +02005977
5978restart_ih:
5979 /* is somebody else already processing irqs? */
5980 if (atomic_xchg(&rdev->ih.lock, 1))
5981 return IRQ_NONE;
5982
Alex Deucher25a857f2012-03-20 17:18:22 -04005983 rptr = rdev->ih.rptr;
5984 DRM_DEBUG("si_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
5985
Alex Deucher25a857f2012-03-20 17:18:22 -04005986 /* Order reading of wptr vs. reading of IH ring data */
5987 rmb();
5988
5989 /* display interrupts */
5990 si_irq_ack(rdev);
5991
Alex Deucher25a857f2012-03-20 17:18:22 -04005992 while (rptr != wptr) {
5993 /* wptr/rptr are in bytes! */
5994 ring_index = rptr / 4;
5995 src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
5996 src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
5997 ring_id = le32_to_cpu(rdev->ih.ring[ring_index + 2]) & 0xff;
5998
5999 switch (src_id) {
6000 case 1: /* D1 vblank/vline */
6001 switch (src_data) {
6002 case 0: /* D1 vblank */
6003 if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT) {
6004 if (rdev->irq.crtc_vblank_int[0]) {
6005 drm_handle_vblank(rdev->ddev, 0);
6006 rdev->pm.vblank_sync = true;
6007 wake_up(&rdev->irq.vblank_queue);
6008 }
Christian Koenig736fc372012-05-17 19:52:00 +02006009 if (atomic_read(&rdev->irq.pflip[0]))
Alex Deucher25a857f2012-03-20 17:18:22 -04006010 radeon_crtc_handle_flip(rdev, 0);
6011 rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
6012 DRM_DEBUG("IH: D1 vblank\n");
6013 }
6014 break;
6015 case 1: /* D1 vline */
6016 if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT) {
6017 rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VLINE_INTERRUPT;
6018 DRM_DEBUG("IH: D1 vline\n");
6019 }
6020 break;
6021 default:
6022 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6023 break;
6024 }
6025 break;
6026 case 2: /* D2 vblank/vline */
6027 switch (src_data) {
6028 case 0: /* D2 vblank */
6029 if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
6030 if (rdev->irq.crtc_vblank_int[1]) {
6031 drm_handle_vblank(rdev->ddev, 1);
6032 rdev->pm.vblank_sync = true;
6033 wake_up(&rdev->irq.vblank_queue);
6034 }
Christian Koenig736fc372012-05-17 19:52:00 +02006035 if (atomic_read(&rdev->irq.pflip[1]))
Alex Deucher25a857f2012-03-20 17:18:22 -04006036 radeon_crtc_handle_flip(rdev, 1);
6037 rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
6038 DRM_DEBUG("IH: D2 vblank\n");
6039 }
6040 break;
6041 case 1: /* D2 vline */
6042 if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT) {
6043 rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
6044 DRM_DEBUG("IH: D2 vline\n");
6045 }
6046 break;
6047 default:
6048 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6049 break;
6050 }
6051 break;
6052 case 3: /* D3 vblank/vline */
6053 switch (src_data) {
6054 case 0: /* D3 vblank */
6055 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
6056 if (rdev->irq.crtc_vblank_int[2]) {
6057 drm_handle_vblank(rdev->ddev, 2);
6058 rdev->pm.vblank_sync = true;
6059 wake_up(&rdev->irq.vblank_queue);
6060 }
Christian Koenig736fc372012-05-17 19:52:00 +02006061 if (atomic_read(&rdev->irq.pflip[2]))
Alex Deucher25a857f2012-03-20 17:18:22 -04006062 radeon_crtc_handle_flip(rdev, 2);
6063 rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
6064 DRM_DEBUG("IH: D3 vblank\n");
6065 }
6066 break;
6067 case 1: /* D3 vline */
6068 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) {
6069 rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
6070 DRM_DEBUG("IH: D3 vline\n");
6071 }
6072 break;
6073 default:
6074 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6075 break;
6076 }
6077 break;
6078 case 4: /* D4 vblank/vline */
6079 switch (src_data) {
6080 case 0: /* D4 vblank */
6081 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
6082 if (rdev->irq.crtc_vblank_int[3]) {
6083 drm_handle_vblank(rdev->ddev, 3);
6084 rdev->pm.vblank_sync = true;
6085 wake_up(&rdev->irq.vblank_queue);
6086 }
Christian Koenig736fc372012-05-17 19:52:00 +02006087 if (atomic_read(&rdev->irq.pflip[3]))
Alex Deucher25a857f2012-03-20 17:18:22 -04006088 radeon_crtc_handle_flip(rdev, 3);
6089 rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
6090 DRM_DEBUG("IH: D4 vblank\n");
6091 }
6092 break;
6093 case 1: /* D4 vline */
6094 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) {
6095 rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
6096 DRM_DEBUG("IH: D4 vline\n");
6097 }
6098 break;
6099 default:
6100 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6101 break;
6102 }
6103 break;
6104 case 5: /* D5 vblank/vline */
6105 switch (src_data) {
6106 case 0: /* D5 vblank */
6107 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
6108 if (rdev->irq.crtc_vblank_int[4]) {
6109 drm_handle_vblank(rdev->ddev, 4);
6110 rdev->pm.vblank_sync = true;
6111 wake_up(&rdev->irq.vblank_queue);
6112 }
Christian Koenig736fc372012-05-17 19:52:00 +02006113 if (atomic_read(&rdev->irq.pflip[4]))
Alex Deucher25a857f2012-03-20 17:18:22 -04006114 radeon_crtc_handle_flip(rdev, 4);
6115 rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
6116 DRM_DEBUG("IH: D5 vblank\n");
6117 }
6118 break;
6119 case 1: /* D5 vline */
6120 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) {
6121 rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
6122 DRM_DEBUG("IH: D5 vline\n");
6123 }
6124 break;
6125 default:
6126 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6127 break;
6128 }
6129 break;
6130 case 6: /* D6 vblank/vline */
6131 switch (src_data) {
6132 case 0: /* D6 vblank */
6133 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
6134 if (rdev->irq.crtc_vblank_int[5]) {
6135 drm_handle_vblank(rdev->ddev, 5);
6136 rdev->pm.vblank_sync = true;
6137 wake_up(&rdev->irq.vblank_queue);
6138 }
Christian Koenig736fc372012-05-17 19:52:00 +02006139 if (atomic_read(&rdev->irq.pflip[5]))
Alex Deucher25a857f2012-03-20 17:18:22 -04006140 radeon_crtc_handle_flip(rdev, 5);
6141 rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
6142 DRM_DEBUG("IH: D6 vblank\n");
6143 }
6144 break;
6145 case 1: /* D6 vline */
6146 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) {
6147 rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
6148 DRM_DEBUG("IH: D6 vline\n");
6149 }
6150 break;
6151 default:
6152 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6153 break;
6154 }
6155 break;
6156 case 42: /* HPD hotplug */
6157 switch (src_data) {
6158 case 0:
6159 if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
6160 rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_INTERRUPT;
6161 queue_hotplug = true;
6162 DRM_DEBUG("IH: HPD1\n");
6163 }
6164 break;
6165 case 1:
6166 if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
6167 rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_INTERRUPT;
6168 queue_hotplug = true;
6169 DRM_DEBUG("IH: HPD2\n");
6170 }
6171 break;
6172 case 2:
6173 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
6174 rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
6175 queue_hotplug = true;
6176 DRM_DEBUG("IH: HPD3\n");
6177 }
6178 break;
6179 case 3:
6180 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
6181 rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
6182 queue_hotplug = true;
6183 DRM_DEBUG("IH: HPD4\n");
6184 }
6185 break;
6186 case 4:
6187 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
6188 rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
6189 queue_hotplug = true;
6190 DRM_DEBUG("IH: HPD5\n");
6191 }
6192 break;
6193 case 5:
6194 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
6195 rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
6196 queue_hotplug = true;
6197 DRM_DEBUG("IH: HPD6\n");
6198 }
6199 break;
6200 default:
6201 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6202 break;
6203 }
6204 break;
Christian Königae133a12012-09-18 15:30:44 -04006205 case 146:
6206 case 147:
Alex Deucherfbf6dc72013-06-13 18:47:58 -04006207 addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
6208 status = RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS);
Christian Königae133a12012-09-18 15:30:44 -04006209 dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
6210 dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
Alex Deucherfbf6dc72013-06-13 18:47:58 -04006211 addr);
Christian Königae133a12012-09-18 15:30:44 -04006212 dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
Alex Deucherfbf6dc72013-06-13 18:47:58 -04006213 status);
6214 si_vm_decode_fault(rdev, status, addr);
Christian Königae133a12012-09-18 15:30:44 -04006215 /* reset addr and status */
6216 WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
6217 break;
Alex Deucher25a857f2012-03-20 17:18:22 -04006218 case 176: /* RINGID0 CP_INT */
6219 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
6220 break;
6221 case 177: /* RINGID1 CP_INT */
6222 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
6223 break;
6224 case 178: /* RINGID2 CP_INT */
6225 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
6226 break;
6227 case 181: /* CP EOP event */
6228 DRM_DEBUG("IH: CP EOP\n");
6229 switch (ring_id) {
6230 case 0:
6231 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
6232 break;
6233 case 1:
6234 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
6235 break;
6236 case 2:
6237 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
6238 break;
6239 }
6240 break;
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006241 case 224: /* DMA trap event */
6242 DRM_DEBUG("IH: DMA trap\n");
6243 radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
6244 break;
Alex Deuchera9e61412013-06-25 17:56:16 -04006245 case 230: /* thermal low to high */
6246 DRM_DEBUG("IH: thermal low to high\n");
6247 rdev->pm.dpm.thermal.high_to_low = false;
6248 queue_thermal = true;
6249 break;
6250 case 231: /* thermal high to low */
6251 DRM_DEBUG("IH: thermal high to low\n");
6252 rdev->pm.dpm.thermal.high_to_low = true;
6253 queue_thermal = true;
6254 break;
Alex Deucher25a857f2012-03-20 17:18:22 -04006255 case 233: /* GUI IDLE */
6256 DRM_DEBUG("IH: GUI idle\n");
Alex Deucher25a857f2012-03-20 17:18:22 -04006257 break;
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006258 case 244: /* DMA trap event */
6259 DRM_DEBUG("IH: DMA1 trap\n");
6260 radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
6261 break;
Alex Deucher25a857f2012-03-20 17:18:22 -04006262 default:
6263 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6264 break;
6265 }
6266
6267 /* wptr/rptr are in bytes! */
6268 rptr += 16;
6269 rptr &= rdev->ih.ptr_mask;
6270 }
Alex Deucher25a857f2012-03-20 17:18:22 -04006271 if (queue_hotplug)
6272 schedule_work(&rdev->hotplug_work);
Alex Deuchera9e61412013-06-25 17:56:16 -04006273 if (queue_thermal && rdev->pm.dpm_enabled)
6274 schedule_work(&rdev->pm.dpm.thermal.work);
Alex Deucher25a857f2012-03-20 17:18:22 -04006275 rdev->ih.rptr = rptr;
6276 WREG32(IH_RB_RPTR, rdev->ih.rptr);
Christian Koenigc20dc362012-05-16 21:45:24 +02006277 atomic_set(&rdev->ih.lock, 0);
6278
6279 /* make sure wptr hasn't changed while processing */
6280 wptr = si_get_ih_wptr(rdev);
6281 if (wptr != rptr)
6282 goto restart_ih;
6283
Alex Deucher25a857f2012-03-20 17:18:22 -04006284 return IRQ_HANDLED;
6285}
6286
Alex Deucher9b136d52012-03-20 17:18:23 -04006287/*
6288 * startup/shutdown callbacks
6289 */
6290static int si_startup(struct radeon_device *rdev)
6291{
6292 struct radeon_ring *ring;
6293 int r;
6294
Alex Deucherb9d305d2013-02-14 17:16:51 -05006295 /* enable pcie gen2/3 link */
6296 si_pcie_gen3_enable(rdev);
Alex Deuchere0bcf1652013-02-15 11:56:59 -05006297 /* enable aspm */
6298 si_program_aspm(rdev);
Alex Deucherb9d305d2013-02-14 17:16:51 -05006299
Alex Deuchere5903d32013-08-30 08:58:20 -04006300 /* scratch needs to be initialized before MC */
6301 r = r600_vram_scratch_init(rdev);
6302 if (r)
6303 return r;
6304
Alex Deucher6fab3feb2013-08-04 12:13:17 -04006305 si_mc_program(rdev);
6306
Alex Deucher9b136d52012-03-20 17:18:23 -04006307 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
6308 !rdev->rlc_fw || !rdev->mc_fw) {
6309 r = si_init_microcode(rdev);
6310 if (r) {
6311 DRM_ERROR("Failed to load firmware!\n");
6312 return r;
6313 }
6314 }
6315
6316 r = si_mc_load_microcode(rdev);
6317 if (r) {
6318 DRM_ERROR("Failed to load MC firmware!\n");
6319 return r;
6320 }
6321
Alex Deucher9b136d52012-03-20 17:18:23 -04006322 r = si_pcie_gart_enable(rdev);
6323 if (r)
6324 return r;
6325 si_gpu_init(rdev);
6326
Alex Deucher9b136d52012-03-20 17:18:23 -04006327 /* allocate rlc buffers */
Alex Deucher1fd11772013-04-17 17:53:50 -04006328 if (rdev->family == CHIP_VERDE) {
6329 rdev->rlc.reg_list = verde_rlc_save_restore_register_list;
6330 rdev->rlc.reg_list_size =
6331 (u32)ARRAY_SIZE(verde_rlc_save_restore_register_list);
6332 }
6333 rdev->rlc.cs_data = si_cs_data;
6334 r = sumo_rlc_init(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006335 if (r) {
6336 DRM_ERROR("Failed to init rlc BOs!\n");
6337 return r;
6338 }
6339
6340 /* allocate wb buffer */
6341 r = radeon_wb_init(rdev);
6342 if (r)
6343 return r;
6344
6345 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
6346 if (r) {
6347 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
6348 return r;
6349 }
6350
6351 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
6352 if (r) {
6353 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
6354 return r;
6355 }
6356
6357 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
6358 if (r) {
6359 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
6360 return r;
6361 }
6362
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006363 r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
6364 if (r) {
6365 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
6366 return r;
6367 }
6368
6369 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
6370 if (r) {
6371 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
6372 return r;
6373 }
6374
Alex Deucher1df0d522013-04-26 18:03:44 -04006375 if (rdev->has_uvd) {
Christian Könige409b122013-08-13 11:56:53 +02006376 r = uvd_v2_2_resume(rdev);
Alex Deucher1df0d522013-04-26 18:03:44 -04006377 if (!r) {
6378 r = radeon_fence_driver_start_ring(rdev,
6379 R600_RING_TYPE_UVD_INDEX);
6380 if (r)
6381 dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
6382 }
Christian Königf2ba57b2013-04-08 12:41:29 +02006383 if (r)
Alex Deucher1df0d522013-04-26 18:03:44 -04006384 rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
Christian Königf2ba57b2013-04-08 12:41:29 +02006385 }
Christian Königf2ba57b2013-04-08 12:41:29 +02006386
Alex Deucher9b136d52012-03-20 17:18:23 -04006387 /* Enable IRQ */
Adis Hamziće49f3952013-06-02 16:47:54 +02006388 if (!rdev->irq.installed) {
6389 r = radeon_irq_kms_init(rdev);
6390 if (r)
6391 return r;
6392 }
6393
Alex Deucher9b136d52012-03-20 17:18:23 -04006394 r = si_irq_init(rdev);
6395 if (r) {
6396 DRM_ERROR("radeon: IH init failed (%d).\n", r);
6397 radeon_irq_kms_fini(rdev);
6398 return r;
6399 }
6400 si_irq_set(rdev);
6401
6402 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
6403 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
6404 CP_RB0_RPTR, CP_RB0_WPTR,
Christian König2e1e6da2013-08-13 11:56:52 +02006405 RADEON_CP_PACKET2);
Alex Deucher9b136d52012-03-20 17:18:23 -04006406 if (r)
6407 return r;
6408
6409 ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
6410 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP1_RPTR_OFFSET,
6411 CP_RB1_RPTR, CP_RB1_WPTR,
Christian König2e1e6da2013-08-13 11:56:52 +02006412 RADEON_CP_PACKET2);
Alex Deucher9b136d52012-03-20 17:18:23 -04006413 if (r)
6414 return r;
6415
6416 ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
6417 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP2_RPTR_OFFSET,
6418 CP_RB2_RPTR, CP_RB2_WPTR,
Christian König2e1e6da2013-08-13 11:56:52 +02006419 RADEON_CP_PACKET2);
Alex Deucher9b136d52012-03-20 17:18:23 -04006420 if (r)
6421 return r;
6422
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006423 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
6424 r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
6425 DMA_RB_RPTR + DMA0_REGISTER_OFFSET,
6426 DMA_RB_WPTR + DMA0_REGISTER_OFFSET,
Christian König2e1e6da2013-08-13 11:56:52 +02006427 DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0));
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006428 if (r)
6429 return r;
6430
6431 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
6432 r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
6433 DMA_RB_RPTR + DMA1_REGISTER_OFFSET,
6434 DMA_RB_WPTR + DMA1_REGISTER_OFFSET,
Christian König2e1e6da2013-08-13 11:56:52 +02006435 DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0));
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006436 if (r)
6437 return r;
6438
Alex Deucher9b136d52012-03-20 17:18:23 -04006439 r = si_cp_load_microcode(rdev);
6440 if (r)
6441 return r;
6442 r = si_cp_resume(rdev);
6443 if (r)
6444 return r;
6445
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006446 r = cayman_dma_resume(rdev);
6447 if (r)
6448 return r;
6449
Alex Deucher1df0d522013-04-26 18:03:44 -04006450 if (rdev->has_uvd) {
6451 ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
6452 if (ring->ring_size) {
Christian König02c9f7f2013-08-13 11:56:51 +02006453 r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
Alex Deucher1df0d522013-04-26 18:03:44 -04006454 UVD_RBC_RB_RPTR, UVD_RBC_RB_WPTR,
Christian König2e1e6da2013-08-13 11:56:52 +02006455 RADEON_CP_PACKET2);
Alex Deucher1df0d522013-04-26 18:03:44 -04006456 if (!r)
Christian Könige409b122013-08-13 11:56:53 +02006457 r = uvd_v1_0_init(rdev);
Alex Deucher1df0d522013-04-26 18:03:44 -04006458 if (r)
6459 DRM_ERROR("radeon: failed initializing UVD (%d).\n", r);
6460 }
Christian Königf2ba57b2013-04-08 12:41:29 +02006461 }
6462
Christian König2898c342012-07-05 11:55:34 +02006463 r = radeon_ib_pool_init(rdev);
6464 if (r) {
6465 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
Alex Deucher9b136d52012-03-20 17:18:23 -04006466 return r;
Christian König2898c342012-07-05 11:55:34 +02006467 }
Alex Deucher9b136d52012-03-20 17:18:23 -04006468
Christian Königc6105f22012-07-05 14:32:00 +02006469 r = radeon_vm_manager_init(rdev);
6470 if (r) {
6471 dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
Alex Deucher9b136d52012-03-20 17:18:23 -04006472 return r;
Christian Königc6105f22012-07-05 14:32:00 +02006473 }
Alex Deucher9b136d52012-03-20 17:18:23 -04006474
Alex Deucherb5306022013-07-31 16:51:33 -04006475 r = dce6_audio_init(rdev);
6476 if (r)
6477 return r;
6478
Alex Deucher9b136d52012-03-20 17:18:23 -04006479 return 0;
6480}
6481
6482int si_resume(struct radeon_device *rdev)
6483{
6484 int r;
6485
6486 /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
6487 * posting will perform necessary task to bring back GPU into good
6488 * shape.
6489 */
6490 /* post card */
6491 atom_asic_init(rdev->mode_info.atom_context);
6492
Alex Deucher205996c2013-03-01 17:08:42 -05006493 /* init golden registers */
6494 si_init_golden_registers(rdev);
6495
Alex Deucher9b136d52012-03-20 17:18:23 -04006496 rdev->accel_working = true;
6497 r = si_startup(rdev);
6498 if (r) {
6499 DRM_ERROR("si startup failed on resume\n");
6500 rdev->accel_working = false;
6501 return r;
6502 }
6503
6504 return r;
6505
6506}
6507
6508int si_suspend(struct radeon_device *rdev)
6509{
Alex Deucherb5306022013-07-31 16:51:33 -04006510 dce6_audio_fini(rdev);
Alex Deucherfa3daf92013-03-11 15:32:26 -04006511 radeon_vm_manager_fini(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006512 si_cp_enable(rdev, false);
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006513 cayman_dma_stop(rdev);
Alex Deucher1df0d522013-04-26 18:03:44 -04006514 if (rdev->has_uvd) {
Christian Könige409b122013-08-13 11:56:53 +02006515 uvd_v1_0_fini(rdev);
Alex Deucher1df0d522013-04-26 18:03:44 -04006516 radeon_uvd_suspend(rdev);
6517 }
Alex Deuchere16866e2013-08-08 19:34:07 -04006518 si_fini_pg(rdev);
6519 si_fini_cg(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006520 si_irq_suspend(rdev);
6521 radeon_wb_disable(rdev);
6522 si_pcie_gart_disable(rdev);
6523 return 0;
6524}
6525
6526/* Plan is to move initialization in that function and use
6527 * helper function so that radeon_device_init pretty much
6528 * do nothing more than calling asic specific function. This
6529 * should also allow to remove a bunch of callback function
6530 * like vram_info.
6531 */
6532int si_init(struct radeon_device *rdev)
6533{
6534 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
6535 int r;
6536
Alex Deucher9b136d52012-03-20 17:18:23 -04006537 /* Read BIOS */
6538 if (!radeon_get_bios(rdev)) {
6539 if (ASIC_IS_AVIVO(rdev))
6540 return -EINVAL;
6541 }
6542 /* Must be an ATOMBIOS */
6543 if (!rdev->is_atom_bios) {
6544 dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
6545 return -EINVAL;
6546 }
6547 r = radeon_atombios_init(rdev);
6548 if (r)
6549 return r;
6550
6551 /* Post card if necessary */
6552 if (!radeon_card_posted(rdev)) {
6553 if (!rdev->bios) {
6554 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
6555 return -EINVAL;
6556 }
6557 DRM_INFO("GPU not posted. posting now...\n");
6558 atom_asic_init(rdev->mode_info.atom_context);
6559 }
Alex Deucher205996c2013-03-01 17:08:42 -05006560 /* init golden registers */
6561 si_init_golden_registers(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006562 /* Initialize scratch registers */
6563 si_scratch_init(rdev);
6564 /* Initialize surface registers */
6565 radeon_surface_init(rdev);
6566 /* Initialize clocks */
6567 radeon_get_clock_info(rdev->ddev);
6568
6569 /* Fence driver */
6570 r = radeon_fence_driver_init(rdev);
6571 if (r)
6572 return r;
6573
6574 /* initialize memory controller */
6575 r = si_mc_init(rdev);
6576 if (r)
6577 return r;
6578 /* Memory manager */
6579 r = radeon_bo_init(rdev);
6580 if (r)
6581 return r;
6582
Alex Deucher9b136d52012-03-20 17:18:23 -04006583 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
6584 ring->ring_obj = NULL;
6585 r600_ring_init(rdev, ring, 1024 * 1024);
6586
6587 ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
6588 ring->ring_obj = NULL;
6589 r600_ring_init(rdev, ring, 1024 * 1024);
6590
6591 ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
6592 ring->ring_obj = NULL;
6593 r600_ring_init(rdev, ring, 1024 * 1024);
6594
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006595 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
6596 ring->ring_obj = NULL;
6597 r600_ring_init(rdev, ring, 64 * 1024);
6598
6599 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
6600 ring->ring_obj = NULL;
6601 r600_ring_init(rdev, ring, 64 * 1024);
6602
Alex Deucher1df0d522013-04-26 18:03:44 -04006603 if (rdev->has_uvd) {
6604 r = radeon_uvd_init(rdev);
6605 if (!r) {
6606 ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
6607 ring->ring_obj = NULL;
6608 r600_ring_init(rdev, ring, 4096);
6609 }
Christian Königf2ba57b2013-04-08 12:41:29 +02006610 }
6611
Alex Deucher9b136d52012-03-20 17:18:23 -04006612 rdev->ih.ring_obj = NULL;
6613 r600_ih_ring_init(rdev, 64 * 1024);
6614
6615 r = r600_pcie_gart_init(rdev);
6616 if (r)
6617 return r;
6618
Alex Deucher9b136d52012-03-20 17:18:23 -04006619 rdev->accel_working = true;
Alex Deucher9b136d52012-03-20 17:18:23 -04006620 r = si_startup(rdev);
6621 if (r) {
6622 dev_err(rdev->dev, "disabling GPU acceleration\n");
6623 si_cp_fini(rdev);
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006624 cayman_dma_fini(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006625 si_irq_fini(rdev);
Alex Deucher1fd11772013-04-17 17:53:50 -04006626 sumo_rlc_fini(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006627 radeon_wb_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02006628 radeon_ib_pool_fini(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006629 radeon_vm_manager_fini(rdev);
6630 radeon_irq_kms_fini(rdev);
6631 si_pcie_gart_fini(rdev);
6632 rdev->accel_working = false;
6633 }
6634
6635 /* Don't start up if the MC ucode is missing.
6636 * The default clocks and voltages before the MC ucode
6637 * is loaded are not suffient for advanced operations.
6638 */
6639 if (!rdev->mc_fw) {
6640 DRM_ERROR("radeon: MC ucode required for NI+.\n");
6641 return -EINVAL;
6642 }
6643
6644 return 0;
6645}
6646
6647void si_fini(struct radeon_device *rdev)
6648{
Alex Deucher9b136d52012-03-20 17:18:23 -04006649 si_cp_fini(rdev);
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006650 cayman_dma_fini(rdev);
Alex Deucherf8f84ac2013-03-07 12:56:35 -05006651 si_fini_pg(rdev);
Alex Deuchere16866e2013-08-08 19:34:07 -04006652 si_fini_cg(rdev);
Alex Deuchere0bcf1652013-02-15 11:56:59 -05006653 si_irq_fini(rdev);
Alex Deucher1fd11772013-04-17 17:53:50 -04006654 sumo_rlc_fini(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006655 radeon_wb_fini(rdev);
6656 radeon_vm_manager_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02006657 radeon_ib_pool_fini(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006658 radeon_irq_kms_fini(rdev);
Christian König2858c002013-08-01 17:34:07 +02006659 if (rdev->has_uvd) {
Christian Könige409b122013-08-13 11:56:53 +02006660 uvd_v1_0_fini(rdev);
Alex Deucher1df0d522013-04-26 18:03:44 -04006661 radeon_uvd_fini(rdev);
Christian König2858c002013-08-01 17:34:07 +02006662 }
Alex Deucher9b136d52012-03-20 17:18:23 -04006663 si_pcie_gart_fini(rdev);
6664 r600_vram_scratch_fini(rdev);
6665 radeon_gem_fini(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006666 radeon_fence_driver_fini(rdev);
6667 radeon_bo_fini(rdev);
6668 radeon_atombios_fini(rdev);
6669 kfree(rdev->bios);
6670 rdev->bios = NULL;
6671}
6672
Marek Olšák6759a0a2012-08-09 16:34:17 +02006673/**
Alex Deucherd0418892013-01-24 10:35:23 -05006674 * si_get_gpu_clock_counter - return GPU clock counter snapshot
Marek Olšák6759a0a2012-08-09 16:34:17 +02006675 *
6676 * @rdev: radeon_device pointer
6677 *
6678 * Fetches a GPU clock counter snapshot (SI).
6679 * Returns the 64 bit clock counter snapshot.
6680 */
Alex Deucherd0418892013-01-24 10:35:23 -05006681uint64_t si_get_gpu_clock_counter(struct radeon_device *rdev)
Marek Olšák6759a0a2012-08-09 16:34:17 +02006682{
6683 uint64_t clock;
6684
6685 mutex_lock(&rdev->gpu_clock_mutex);
6686 WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
6687 clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
6688 ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
6689 mutex_unlock(&rdev->gpu_clock_mutex);
6690 return clock;
6691}
Christian König2539eb02013-04-08 12:41:34 +02006692
Christian König2539eb02013-04-08 12:41:34 +02006693int si_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
6694{
Christian Königfacd1122013-04-29 11:55:02 +02006695 unsigned fb_div = 0, vclk_div = 0, dclk_div = 0;
Christian König2539eb02013-04-08 12:41:34 +02006696 int r;
6697
Christian König4ed10832013-04-18 15:25:58 +02006698 /* bypass vclk and dclk with bclk */
6699 WREG32_P(CG_UPLL_FUNC_CNTL_2,
6700 VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
6701 ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
6702
6703 /* put PLL in bypass mode */
6704 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK);
6705
6706 if (!vclk || !dclk) {
6707 /* keep the Bypass mode, put PLL to sleep */
6708 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
6709 return 0;
6710 }
6711
Christian Königfacd1122013-04-29 11:55:02 +02006712 r = radeon_uvd_calc_upll_dividers(rdev, vclk, dclk, 125000, 250000,
6713 16384, 0x03FFFFFF, 0, 128, 5,
6714 &fb_div, &vclk_div, &dclk_div);
6715 if (r)
6716 return r;
Christian König2539eb02013-04-08 12:41:34 +02006717
6718 /* set RESET_ANTI_MUX to 0 */
6719 WREG32_P(CG_UPLL_FUNC_CNTL_5, 0, ~RESET_ANTI_MUX_MASK);
6720
6721 /* set VCO_MODE to 1 */
6722 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_VCO_MODE_MASK, ~UPLL_VCO_MODE_MASK);
6723
6724 /* toggle UPLL_SLEEP to 1 then back to 0 */
6725 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
6726 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_SLEEP_MASK);
6727
6728 /* deassert UPLL_RESET */
6729 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
6730
6731 mdelay(1);
6732
Christian Königfacd1122013-04-29 11:55:02 +02006733 r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
Christian König2539eb02013-04-08 12:41:34 +02006734 if (r)
6735 return r;
6736
6737 /* assert UPLL_RESET again */
6738 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
6739
6740 /* disable spread spectrum. */
6741 WREG32_P(CG_UPLL_SPREAD_SPECTRUM, 0, ~SSEN_MASK);
6742
6743 /* set feedback divider */
Christian Königfacd1122013-04-29 11:55:02 +02006744 WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(fb_div), ~UPLL_FB_DIV_MASK);
Christian König2539eb02013-04-08 12:41:34 +02006745
6746 /* set ref divider to 0 */
6747 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_REF_DIV_MASK);
6748
Christian Königfacd1122013-04-29 11:55:02 +02006749 if (fb_div < 307200)
Christian König2539eb02013-04-08 12:41:34 +02006750 WREG32_P(CG_UPLL_FUNC_CNTL_4, 0, ~UPLL_SPARE_ISPARE9);
6751 else
6752 WREG32_P(CG_UPLL_FUNC_CNTL_4, UPLL_SPARE_ISPARE9, ~UPLL_SPARE_ISPARE9);
6753
6754 /* set PDIV_A and PDIV_B */
6755 WREG32_P(CG_UPLL_FUNC_CNTL_2,
Christian Königfacd1122013-04-29 11:55:02 +02006756 UPLL_PDIV_A(vclk_div) | UPLL_PDIV_B(dclk_div),
Christian König2539eb02013-04-08 12:41:34 +02006757 ~(UPLL_PDIV_A_MASK | UPLL_PDIV_B_MASK));
6758
6759 /* give the PLL some time to settle */
6760 mdelay(15);
6761
6762 /* deassert PLL_RESET */
6763 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
6764
6765 mdelay(15);
6766
6767 /* switch from bypass mode to normal mode */
6768 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
6769
Christian Königfacd1122013-04-29 11:55:02 +02006770 r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
Christian König2539eb02013-04-08 12:41:34 +02006771 if (r)
6772 return r;
6773
6774 /* switch VCLK and DCLK selection */
6775 WREG32_P(CG_UPLL_FUNC_CNTL_2,
6776 VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
6777 ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
6778
6779 mdelay(100);
6780
6781 return 0;
6782}
Alex Deucherb9d305d2013-02-14 17:16:51 -05006783
6784static void si_pcie_gen3_enable(struct radeon_device *rdev)
6785{
6786 struct pci_dev *root = rdev->pdev->bus->self;
6787 int bridge_pos, gpu_pos;
6788 u32 speed_cntl, mask, current_data_rate;
6789 int ret, i;
6790 u16 tmp16;
6791
6792 if (radeon_pcie_gen2 == 0)
6793 return;
6794
6795 if (rdev->flags & RADEON_IS_IGP)
6796 return;
6797
6798 if (!(rdev->flags & RADEON_IS_PCIE))
6799 return;
6800
6801 ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask);
6802 if (ret != 0)
6803 return;
6804
6805 if (!(mask & (DRM_PCIE_SPEED_50 | DRM_PCIE_SPEED_80)))
6806 return;
6807
6808 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
6809 current_data_rate = (speed_cntl & LC_CURRENT_DATA_RATE_MASK) >>
6810 LC_CURRENT_DATA_RATE_SHIFT;
6811 if (mask & DRM_PCIE_SPEED_80) {
6812 if (current_data_rate == 2) {
6813 DRM_INFO("PCIE gen 3 link speeds already enabled\n");
6814 return;
6815 }
6816 DRM_INFO("enabling PCIE gen 3 link speeds, disable with radeon.pcie_gen2=0\n");
6817 } else if (mask & DRM_PCIE_SPEED_50) {
6818 if (current_data_rate == 1) {
6819 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
6820 return;
6821 }
6822 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
6823 }
6824
6825 bridge_pos = pci_pcie_cap(root);
6826 if (!bridge_pos)
6827 return;
6828
6829 gpu_pos = pci_pcie_cap(rdev->pdev);
6830 if (!gpu_pos)
6831 return;
6832
6833 if (mask & DRM_PCIE_SPEED_80) {
6834 /* re-try equalization if gen3 is not already enabled */
6835 if (current_data_rate != 2) {
6836 u16 bridge_cfg, gpu_cfg;
6837 u16 bridge_cfg2, gpu_cfg2;
6838 u32 max_lw, current_lw, tmp;
6839
6840 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
6841 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
6842
6843 tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
6844 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
6845
6846 tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
6847 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
6848
6849 tmp = RREG32_PCIE(PCIE_LC_STATUS1);
6850 max_lw = (tmp & LC_DETECTED_LINK_WIDTH_MASK) >> LC_DETECTED_LINK_WIDTH_SHIFT;
6851 current_lw = (tmp & LC_OPERATING_LINK_WIDTH_MASK) >> LC_OPERATING_LINK_WIDTH_SHIFT;
6852
6853 if (current_lw < max_lw) {
6854 tmp = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
6855 if (tmp & LC_RENEGOTIATION_SUPPORT) {
6856 tmp &= ~(LC_LINK_WIDTH_MASK | LC_UPCONFIGURE_DIS);
6857 tmp |= (max_lw << LC_LINK_WIDTH_SHIFT);
6858 tmp |= LC_UPCONFIGURE_SUPPORT | LC_RENEGOTIATE_EN | LC_RECONFIG_NOW;
6859 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, tmp);
6860 }
6861 }
6862
6863 for (i = 0; i < 10; i++) {
6864 /* check status */
6865 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_DEVSTA, &tmp16);
6866 if (tmp16 & PCI_EXP_DEVSTA_TRPND)
6867 break;
6868
6869 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
6870 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
6871
6872 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &bridge_cfg2);
6873 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &gpu_cfg2);
6874
6875 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
6876 tmp |= LC_SET_QUIESCE;
6877 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
6878
6879 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
6880 tmp |= LC_REDO_EQ;
6881 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
6882
6883 mdelay(100);
6884
6885 /* linkctl */
6886 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &tmp16);
6887 tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
6888 tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
6889 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
6890
6891 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &tmp16);
6892 tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
6893 tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
6894 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
6895
6896 /* linkctl2 */
6897 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &tmp16);
6898 tmp16 &= ~((1 << 4) | (7 << 9));
6899 tmp16 |= (bridge_cfg2 & ((1 << 4) | (7 << 9)));
6900 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, tmp16);
6901
6902 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
6903 tmp16 &= ~((1 << 4) | (7 << 9));
6904 tmp16 |= (gpu_cfg2 & ((1 << 4) | (7 << 9)));
6905 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
6906
6907 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
6908 tmp &= ~LC_SET_QUIESCE;
6909 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
6910 }
6911 }
6912 }
6913
6914 /* set the link speed */
6915 speed_cntl |= LC_FORCE_EN_SW_SPEED_CHANGE | LC_FORCE_DIS_HW_SPEED_CHANGE;
6916 speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
6917 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
6918
6919 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
6920 tmp16 &= ~0xf;
6921 if (mask & DRM_PCIE_SPEED_80)
6922 tmp16 |= 3; /* gen3 */
6923 else if (mask & DRM_PCIE_SPEED_50)
6924 tmp16 |= 2; /* gen2 */
6925 else
6926 tmp16 |= 1; /* gen1 */
6927 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
6928
6929 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
6930 speed_cntl |= LC_INITIATE_LINK_SPEED_CHANGE;
6931 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
6932
6933 for (i = 0; i < rdev->usec_timeout; i++) {
6934 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
6935 if ((speed_cntl & LC_INITIATE_LINK_SPEED_CHANGE) == 0)
6936 break;
6937 udelay(1);
6938 }
6939}
6940
Alex Deuchere0bcf1652013-02-15 11:56:59 -05006941static void si_program_aspm(struct radeon_device *rdev)
6942{
6943 u32 data, orig;
6944 bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
6945 bool disable_clkreq = false;
6946
Alex Deucher1294d4a2013-07-16 15:58:50 -04006947 if (radeon_aspm == 0)
6948 return;
6949
Alex Deuchere0bcf1652013-02-15 11:56:59 -05006950 if (!(rdev->flags & RADEON_IS_PCIE))
6951 return;
6952
6953 orig = data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
6954 data &= ~LC_XMIT_N_FTS_MASK;
6955 data |= LC_XMIT_N_FTS(0x24) | LC_XMIT_N_FTS_OVERRIDE_EN;
6956 if (orig != data)
6957 WREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL, data);
6958
6959 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL3);
6960 data |= LC_GO_TO_RECOVERY;
6961 if (orig != data)
6962 WREG32_PCIE_PORT(PCIE_LC_CNTL3, data);
6963
6964 orig = data = RREG32_PCIE(PCIE_P_CNTL);
6965 data |= P_IGNORE_EDB_ERR;
6966 if (orig != data)
6967 WREG32_PCIE(PCIE_P_CNTL, data);
6968
6969 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
6970 data &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
6971 data |= LC_PMI_TO_L1_DIS;
6972 if (!disable_l0s)
6973 data |= LC_L0S_INACTIVITY(7);
6974
6975 if (!disable_l1) {
6976 data |= LC_L1_INACTIVITY(7);
6977 data &= ~LC_PMI_TO_L1_DIS;
6978 if (orig != data)
6979 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
6980
6981 if (!disable_plloff_in_l1) {
6982 bool clk_req_support;
6983
6984 orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
6985 data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
6986 data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
6987 if (orig != data)
6988 WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
6989
6990 orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
6991 data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
6992 data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
6993 if (orig != data)
6994 WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
6995
6996 orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
6997 data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
6998 data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
6999 if (orig != data)
7000 WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
7001
7002 orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
7003 data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
7004 data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
7005 if (orig != data)
7006 WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
7007
7008 if ((rdev->family != CHIP_OLAND) && (rdev->family != CHIP_HAINAN)) {
7009 orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
7010 data &= ~PLL_RAMP_UP_TIME_0_MASK;
7011 if (orig != data)
7012 WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
7013
7014 orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
7015 data &= ~PLL_RAMP_UP_TIME_1_MASK;
7016 if (orig != data)
7017 WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
7018
7019 orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_2);
7020 data &= ~PLL_RAMP_UP_TIME_2_MASK;
7021 if (orig != data)
7022 WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_2, data);
7023
7024 orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_3);
7025 data &= ~PLL_RAMP_UP_TIME_3_MASK;
7026 if (orig != data)
7027 WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_3, data);
7028
7029 orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
7030 data &= ~PLL_RAMP_UP_TIME_0_MASK;
7031 if (orig != data)
7032 WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
7033
7034 orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
7035 data &= ~PLL_RAMP_UP_TIME_1_MASK;
7036 if (orig != data)
7037 WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
7038
7039 orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_2);
7040 data &= ~PLL_RAMP_UP_TIME_2_MASK;
7041 if (orig != data)
7042 WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_2, data);
7043
7044 orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_3);
7045 data &= ~PLL_RAMP_UP_TIME_3_MASK;
7046 if (orig != data)
7047 WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_3, data);
7048 }
7049 orig = data = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
7050 data &= ~LC_DYN_LANES_PWR_STATE_MASK;
7051 data |= LC_DYN_LANES_PWR_STATE(3);
7052 if (orig != data)
7053 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
7054
7055 orig = data = RREG32_PIF_PHY0(PB0_PIF_CNTL);
7056 data &= ~LS2_EXIT_TIME_MASK;
7057 if ((rdev->family == CHIP_OLAND) || (rdev->family == CHIP_HAINAN))
7058 data |= LS2_EXIT_TIME(5);
7059 if (orig != data)
7060 WREG32_PIF_PHY0(PB0_PIF_CNTL, data);
7061
7062 orig = data = RREG32_PIF_PHY1(PB1_PIF_CNTL);
7063 data &= ~LS2_EXIT_TIME_MASK;
7064 if ((rdev->family == CHIP_OLAND) || (rdev->family == CHIP_HAINAN))
7065 data |= LS2_EXIT_TIME(5);
7066 if (orig != data)
7067 WREG32_PIF_PHY1(PB1_PIF_CNTL, data);
7068
7069 if (!disable_clkreq) {
7070 struct pci_dev *root = rdev->pdev->bus->self;
7071 u32 lnkcap;
7072
7073 clk_req_support = false;
7074 pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
7075 if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
7076 clk_req_support = true;
7077 } else {
7078 clk_req_support = false;
7079 }
7080
7081 if (clk_req_support) {
7082 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL2);
7083 data |= LC_ALLOW_PDWN_IN_L1 | LC_ALLOW_PDWN_IN_L23;
7084 if (orig != data)
7085 WREG32_PCIE_PORT(PCIE_LC_CNTL2, data);
7086
7087 orig = data = RREG32(THM_CLK_CNTL);
7088 data &= ~(CMON_CLK_SEL_MASK | TMON_CLK_SEL_MASK);
7089 data |= CMON_CLK_SEL(1) | TMON_CLK_SEL(1);
7090 if (orig != data)
7091 WREG32(THM_CLK_CNTL, data);
7092
7093 orig = data = RREG32(MISC_CLK_CNTL);
7094 data &= ~(DEEP_SLEEP_CLK_SEL_MASK | ZCLK_SEL_MASK);
7095 data |= DEEP_SLEEP_CLK_SEL(1) | ZCLK_SEL(1);
7096 if (orig != data)
7097 WREG32(MISC_CLK_CNTL, data);
7098
7099 orig = data = RREG32(CG_CLKPIN_CNTL);
7100 data &= ~BCLK_AS_XCLK;
7101 if (orig != data)
7102 WREG32(CG_CLKPIN_CNTL, data);
7103
7104 orig = data = RREG32(CG_CLKPIN_CNTL_2);
7105 data &= ~FORCE_BIF_REFCLK_EN;
7106 if (orig != data)
7107 WREG32(CG_CLKPIN_CNTL_2, data);
7108
7109 orig = data = RREG32(MPLL_BYPASSCLK_SEL);
7110 data &= ~MPLL_CLKOUT_SEL_MASK;
7111 data |= MPLL_CLKOUT_SEL(4);
7112 if (orig != data)
7113 WREG32(MPLL_BYPASSCLK_SEL, data);
7114
7115 orig = data = RREG32(SPLL_CNTL_MODE);
7116 data &= ~SPLL_REFCLK_SEL_MASK;
7117 if (orig != data)
7118 WREG32(SPLL_CNTL_MODE, data);
7119 }
7120 }
7121 } else {
7122 if (orig != data)
7123 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
7124 }
7125
7126 orig = data = RREG32_PCIE(PCIE_CNTL2);
7127 data |= SLV_MEM_LS_EN | MST_MEM_LS_EN | REPLAY_MEM_LS_EN;
7128 if (orig != data)
7129 WREG32_PCIE(PCIE_CNTL2, data);
7130
7131 if (!disable_l0s) {
7132 data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
7133 if((data & LC_N_FTS_MASK) == LC_N_FTS_MASK) {
7134 data = RREG32_PCIE(PCIE_LC_STATUS1);
7135 if ((data & LC_REVERSE_XMIT) && (data & LC_REVERSE_RCVR)) {
7136 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
7137 data &= ~LC_L0S_INACTIVITY_MASK;
7138 if (orig != data)
7139 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
7140 }
7141 }
7142 }
7143}