blob: 626163ef483dd10567d1de42ba3d1fcb817bcbfa [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 Deucher4a5c8ea2013-11-15 16:35:55 -050083static void si_init_pg(struct radeon_device *rdev);
84static void si_init_cg(struct radeon_device *rdev);
Alex Deuchera6f4ae82013-10-02 14:50:57 -040085static void si_fini_pg(struct radeon_device *rdev);
86static void si_fini_cg(struct radeon_device *rdev);
87static void si_rlc_stop(struct radeon_device *rdev);
Alex Deucher0a96d722012-03-20 17:18:11 -040088
Alex Deucher6d8cf002013-03-06 18:48:05 -050089static const u32 verde_rlc_save_restore_register_list[] =
90{
91 (0x8000 << 16) | (0x98f4 >> 2),
92 0x00000000,
93 (0x8040 << 16) | (0x98f4 >> 2),
94 0x00000000,
95 (0x8000 << 16) | (0xe80 >> 2),
96 0x00000000,
97 (0x8040 << 16) | (0xe80 >> 2),
98 0x00000000,
99 (0x8000 << 16) | (0x89bc >> 2),
100 0x00000000,
101 (0x8040 << 16) | (0x89bc >> 2),
102 0x00000000,
103 (0x8000 << 16) | (0x8c1c >> 2),
104 0x00000000,
105 (0x8040 << 16) | (0x8c1c >> 2),
106 0x00000000,
107 (0x9c00 << 16) | (0x98f0 >> 2),
108 0x00000000,
109 (0x9c00 << 16) | (0xe7c >> 2),
110 0x00000000,
111 (0x8000 << 16) | (0x9148 >> 2),
112 0x00000000,
113 (0x8040 << 16) | (0x9148 >> 2),
114 0x00000000,
115 (0x9c00 << 16) | (0x9150 >> 2),
116 0x00000000,
117 (0x9c00 << 16) | (0x897c >> 2),
118 0x00000000,
119 (0x9c00 << 16) | (0x8d8c >> 2),
120 0x00000000,
121 (0x9c00 << 16) | (0xac54 >> 2),
122 0X00000000,
123 0x3,
124 (0x9c00 << 16) | (0x98f8 >> 2),
125 0x00000000,
126 (0x9c00 << 16) | (0x9910 >> 2),
127 0x00000000,
128 (0x9c00 << 16) | (0x9914 >> 2),
129 0x00000000,
130 (0x9c00 << 16) | (0x9918 >> 2),
131 0x00000000,
132 (0x9c00 << 16) | (0x991c >> 2),
133 0x00000000,
134 (0x9c00 << 16) | (0x9920 >> 2),
135 0x00000000,
136 (0x9c00 << 16) | (0x9924 >> 2),
137 0x00000000,
138 (0x9c00 << 16) | (0x9928 >> 2),
139 0x00000000,
140 (0x9c00 << 16) | (0x992c >> 2),
141 0x00000000,
142 (0x9c00 << 16) | (0x9930 >> 2),
143 0x00000000,
144 (0x9c00 << 16) | (0x9934 >> 2),
145 0x00000000,
146 (0x9c00 << 16) | (0x9938 >> 2),
147 0x00000000,
148 (0x9c00 << 16) | (0x993c >> 2),
149 0x00000000,
150 (0x9c00 << 16) | (0x9940 >> 2),
151 0x00000000,
152 (0x9c00 << 16) | (0x9944 >> 2),
153 0x00000000,
154 (0x9c00 << 16) | (0x9948 >> 2),
155 0x00000000,
156 (0x9c00 << 16) | (0x994c >> 2),
157 0x00000000,
158 (0x9c00 << 16) | (0x9950 >> 2),
159 0x00000000,
160 (0x9c00 << 16) | (0x9954 >> 2),
161 0x00000000,
162 (0x9c00 << 16) | (0x9958 >> 2),
163 0x00000000,
164 (0x9c00 << 16) | (0x995c >> 2),
165 0x00000000,
166 (0x9c00 << 16) | (0x9960 >> 2),
167 0x00000000,
168 (0x9c00 << 16) | (0x9964 >> 2),
169 0x00000000,
170 (0x9c00 << 16) | (0x9968 >> 2),
171 0x00000000,
172 (0x9c00 << 16) | (0x996c >> 2),
173 0x00000000,
174 (0x9c00 << 16) | (0x9970 >> 2),
175 0x00000000,
176 (0x9c00 << 16) | (0x9974 >> 2),
177 0x00000000,
178 (0x9c00 << 16) | (0x9978 >> 2),
179 0x00000000,
180 (0x9c00 << 16) | (0x997c >> 2),
181 0x00000000,
182 (0x9c00 << 16) | (0x9980 >> 2),
183 0x00000000,
184 (0x9c00 << 16) | (0x9984 >> 2),
185 0x00000000,
186 (0x9c00 << 16) | (0x9988 >> 2),
187 0x00000000,
188 (0x9c00 << 16) | (0x998c >> 2),
189 0x00000000,
190 (0x9c00 << 16) | (0x8c00 >> 2),
191 0x00000000,
192 (0x9c00 << 16) | (0x8c14 >> 2),
193 0x00000000,
194 (0x9c00 << 16) | (0x8c04 >> 2),
195 0x00000000,
196 (0x9c00 << 16) | (0x8c08 >> 2),
197 0x00000000,
198 (0x8000 << 16) | (0x9b7c >> 2),
199 0x00000000,
200 (0x8040 << 16) | (0x9b7c >> 2),
201 0x00000000,
202 (0x8000 << 16) | (0xe84 >> 2),
203 0x00000000,
204 (0x8040 << 16) | (0xe84 >> 2),
205 0x00000000,
206 (0x8000 << 16) | (0x89c0 >> 2),
207 0x00000000,
208 (0x8040 << 16) | (0x89c0 >> 2),
209 0x00000000,
210 (0x8000 << 16) | (0x914c >> 2),
211 0x00000000,
212 (0x8040 << 16) | (0x914c >> 2),
213 0x00000000,
214 (0x8000 << 16) | (0x8c20 >> 2),
215 0x00000000,
216 (0x8040 << 16) | (0x8c20 >> 2),
217 0x00000000,
218 (0x8000 << 16) | (0x9354 >> 2),
219 0x00000000,
220 (0x8040 << 16) | (0x9354 >> 2),
221 0x00000000,
222 (0x9c00 << 16) | (0x9060 >> 2),
223 0x00000000,
224 (0x9c00 << 16) | (0x9364 >> 2),
225 0x00000000,
226 (0x9c00 << 16) | (0x9100 >> 2),
227 0x00000000,
228 (0x9c00 << 16) | (0x913c >> 2),
229 0x00000000,
230 (0x8000 << 16) | (0x90e0 >> 2),
231 0x00000000,
232 (0x8000 << 16) | (0x90e4 >> 2),
233 0x00000000,
234 (0x8000 << 16) | (0x90e8 >> 2),
235 0x00000000,
236 (0x8040 << 16) | (0x90e0 >> 2),
237 0x00000000,
238 (0x8040 << 16) | (0x90e4 >> 2),
239 0x00000000,
240 (0x8040 << 16) | (0x90e8 >> 2),
241 0x00000000,
242 (0x9c00 << 16) | (0x8bcc >> 2),
243 0x00000000,
244 (0x9c00 << 16) | (0x8b24 >> 2),
245 0x00000000,
246 (0x9c00 << 16) | (0x88c4 >> 2),
247 0x00000000,
248 (0x9c00 << 16) | (0x8e50 >> 2),
249 0x00000000,
250 (0x9c00 << 16) | (0x8c0c >> 2),
251 0x00000000,
252 (0x9c00 << 16) | (0x8e58 >> 2),
253 0x00000000,
254 (0x9c00 << 16) | (0x8e5c >> 2),
255 0x00000000,
256 (0x9c00 << 16) | (0x9508 >> 2),
257 0x00000000,
258 (0x9c00 << 16) | (0x950c >> 2),
259 0x00000000,
260 (0x9c00 << 16) | (0x9494 >> 2),
261 0x00000000,
262 (0x9c00 << 16) | (0xac0c >> 2),
263 0x00000000,
264 (0x9c00 << 16) | (0xac10 >> 2),
265 0x00000000,
266 (0x9c00 << 16) | (0xac14 >> 2),
267 0x00000000,
268 (0x9c00 << 16) | (0xae00 >> 2),
269 0x00000000,
270 (0x9c00 << 16) | (0xac08 >> 2),
271 0x00000000,
272 (0x9c00 << 16) | (0x88d4 >> 2),
273 0x00000000,
274 (0x9c00 << 16) | (0x88c8 >> 2),
275 0x00000000,
276 (0x9c00 << 16) | (0x88cc >> 2),
277 0x00000000,
278 (0x9c00 << 16) | (0x89b0 >> 2),
279 0x00000000,
280 (0x9c00 << 16) | (0x8b10 >> 2),
281 0x00000000,
282 (0x9c00 << 16) | (0x8a14 >> 2),
283 0x00000000,
284 (0x9c00 << 16) | (0x9830 >> 2),
285 0x00000000,
286 (0x9c00 << 16) | (0x9834 >> 2),
287 0x00000000,
288 (0x9c00 << 16) | (0x9838 >> 2),
289 0x00000000,
290 (0x9c00 << 16) | (0x9a10 >> 2),
291 0x00000000,
292 (0x8000 << 16) | (0x9870 >> 2),
293 0x00000000,
294 (0x8000 << 16) | (0x9874 >> 2),
295 0x00000000,
296 (0x8001 << 16) | (0x9870 >> 2),
297 0x00000000,
298 (0x8001 << 16) | (0x9874 >> 2),
299 0x00000000,
300 (0x8040 << 16) | (0x9870 >> 2),
301 0x00000000,
302 (0x8040 << 16) | (0x9874 >> 2),
303 0x00000000,
304 (0x8041 << 16) | (0x9870 >> 2),
305 0x00000000,
306 (0x8041 << 16) | (0x9874 >> 2),
307 0x00000000,
308 0x00000000
309};
310
Alex Deucher205996c2013-03-01 17:08:42 -0500311static const u32 tahiti_golden_rlc_registers[] =
312{
313 0xc424, 0xffffffff, 0x00601005,
314 0xc47c, 0xffffffff, 0x10104040,
315 0xc488, 0xffffffff, 0x0100000a,
316 0xc314, 0xffffffff, 0x00000800,
317 0xc30c, 0xffffffff, 0x800000f4,
318 0xf4a8, 0xffffffff, 0x00000000
319};
320
321static const u32 tahiti_golden_registers[] =
322{
323 0x9a10, 0x00010000, 0x00018208,
324 0x9830, 0xffffffff, 0x00000000,
325 0x9834, 0xf00fffff, 0x00000400,
326 0x9838, 0x0002021c, 0x00020200,
327 0xc78, 0x00000080, 0x00000000,
328 0xd030, 0x000300c0, 0x00800040,
329 0xd830, 0x000300c0, 0x00800040,
330 0x5bb0, 0x000000f0, 0x00000070,
331 0x5bc0, 0x00200000, 0x50100000,
332 0x7030, 0x31000311, 0x00000011,
333 0x277c, 0x00000003, 0x000007ff,
334 0x240c, 0x000007ff, 0x00000000,
335 0x8a14, 0xf000001f, 0x00000007,
336 0x8b24, 0xffffffff, 0x00ffffff,
337 0x8b10, 0x0000ff0f, 0x00000000,
338 0x28a4c, 0x07ffffff, 0x4e000000,
339 0x28350, 0x3f3f3fff, 0x2a00126a,
340 0x30, 0x000000ff, 0x0040,
341 0x34, 0x00000040, 0x00004040,
342 0x9100, 0x07ffffff, 0x03000000,
343 0x8e88, 0x01ff1f3f, 0x00000000,
344 0x8e84, 0x01ff1f3f, 0x00000000,
345 0x9060, 0x0000007f, 0x00000020,
346 0x9508, 0x00010000, 0x00010000,
347 0xac14, 0x00000200, 0x000002fb,
348 0xac10, 0xffffffff, 0x0000543b,
349 0xac0c, 0xffffffff, 0xa9210876,
350 0x88d0, 0xffffffff, 0x000fff40,
351 0x88d4, 0x0000001f, 0x00000010,
352 0x1410, 0x20000000, 0x20fffed8,
353 0x15c0, 0x000c0fc0, 0x000c0400
354};
355
356static const u32 tahiti_golden_registers2[] =
357{
358 0xc64, 0x00000001, 0x00000001
359};
360
361static const u32 pitcairn_golden_rlc_registers[] =
362{
363 0xc424, 0xffffffff, 0x00601004,
364 0xc47c, 0xffffffff, 0x10102020,
365 0xc488, 0xffffffff, 0x01000020,
366 0xc314, 0xffffffff, 0x00000800,
367 0xc30c, 0xffffffff, 0x800000a4
368};
369
370static const u32 pitcairn_golden_registers[] =
371{
372 0x9a10, 0x00010000, 0x00018208,
373 0x9830, 0xffffffff, 0x00000000,
374 0x9834, 0xf00fffff, 0x00000400,
375 0x9838, 0x0002021c, 0x00020200,
376 0xc78, 0x00000080, 0x00000000,
377 0xd030, 0x000300c0, 0x00800040,
378 0xd830, 0x000300c0, 0x00800040,
379 0x5bb0, 0x000000f0, 0x00000070,
380 0x5bc0, 0x00200000, 0x50100000,
381 0x7030, 0x31000311, 0x00000011,
382 0x2ae4, 0x00073ffe, 0x000022a2,
383 0x240c, 0x000007ff, 0x00000000,
384 0x8a14, 0xf000001f, 0x00000007,
385 0x8b24, 0xffffffff, 0x00ffffff,
386 0x8b10, 0x0000ff0f, 0x00000000,
387 0x28a4c, 0x07ffffff, 0x4e000000,
388 0x28350, 0x3f3f3fff, 0x2a00126a,
389 0x30, 0x000000ff, 0x0040,
390 0x34, 0x00000040, 0x00004040,
391 0x9100, 0x07ffffff, 0x03000000,
392 0x9060, 0x0000007f, 0x00000020,
393 0x9508, 0x00010000, 0x00010000,
394 0xac14, 0x000003ff, 0x000000f7,
395 0xac10, 0xffffffff, 0x00000000,
396 0xac0c, 0xffffffff, 0x32761054,
397 0x88d4, 0x0000001f, 0x00000010,
398 0x15c0, 0x000c0fc0, 0x000c0400
399};
400
401static const u32 verde_golden_rlc_registers[] =
402{
403 0xc424, 0xffffffff, 0x033f1005,
404 0xc47c, 0xffffffff, 0x10808020,
405 0xc488, 0xffffffff, 0x00800008,
406 0xc314, 0xffffffff, 0x00001000,
407 0xc30c, 0xffffffff, 0x80010014
408};
409
410static const u32 verde_golden_registers[] =
411{
412 0x9a10, 0x00010000, 0x00018208,
413 0x9830, 0xffffffff, 0x00000000,
414 0x9834, 0xf00fffff, 0x00000400,
415 0x9838, 0x0002021c, 0x00020200,
416 0xc78, 0x00000080, 0x00000000,
417 0xd030, 0x000300c0, 0x00800040,
418 0xd030, 0x000300c0, 0x00800040,
419 0xd830, 0x000300c0, 0x00800040,
420 0xd830, 0x000300c0, 0x00800040,
421 0x5bb0, 0x000000f0, 0x00000070,
422 0x5bc0, 0x00200000, 0x50100000,
423 0x7030, 0x31000311, 0x00000011,
424 0x2ae4, 0x00073ffe, 0x000022a2,
425 0x2ae4, 0x00073ffe, 0x000022a2,
426 0x2ae4, 0x00073ffe, 0x000022a2,
427 0x240c, 0x000007ff, 0x00000000,
428 0x240c, 0x000007ff, 0x00000000,
429 0x240c, 0x000007ff, 0x00000000,
430 0x8a14, 0xf000001f, 0x00000007,
431 0x8a14, 0xf000001f, 0x00000007,
432 0x8a14, 0xf000001f, 0x00000007,
433 0x8b24, 0xffffffff, 0x00ffffff,
434 0x8b10, 0x0000ff0f, 0x00000000,
435 0x28a4c, 0x07ffffff, 0x4e000000,
436 0x28350, 0x3f3f3fff, 0x0000124a,
437 0x28350, 0x3f3f3fff, 0x0000124a,
438 0x28350, 0x3f3f3fff, 0x0000124a,
439 0x30, 0x000000ff, 0x0040,
440 0x34, 0x00000040, 0x00004040,
441 0x9100, 0x07ffffff, 0x03000000,
442 0x9100, 0x07ffffff, 0x03000000,
443 0x8e88, 0x01ff1f3f, 0x00000000,
444 0x8e88, 0x01ff1f3f, 0x00000000,
445 0x8e88, 0x01ff1f3f, 0x00000000,
446 0x8e84, 0x01ff1f3f, 0x00000000,
447 0x8e84, 0x01ff1f3f, 0x00000000,
448 0x8e84, 0x01ff1f3f, 0x00000000,
449 0x9060, 0x0000007f, 0x00000020,
450 0x9508, 0x00010000, 0x00010000,
451 0xac14, 0x000003ff, 0x00000003,
452 0xac14, 0x000003ff, 0x00000003,
453 0xac14, 0x000003ff, 0x00000003,
454 0xac10, 0xffffffff, 0x00000000,
455 0xac10, 0xffffffff, 0x00000000,
456 0xac10, 0xffffffff, 0x00000000,
457 0xac0c, 0xffffffff, 0x00001032,
458 0xac0c, 0xffffffff, 0x00001032,
459 0xac0c, 0xffffffff, 0x00001032,
460 0x88d4, 0x0000001f, 0x00000010,
461 0x88d4, 0x0000001f, 0x00000010,
462 0x88d4, 0x0000001f, 0x00000010,
463 0x15c0, 0x000c0fc0, 0x000c0400
464};
465
466static const u32 oland_golden_rlc_registers[] =
467{
468 0xc424, 0xffffffff, 0x00601005,
469 0xc47c, 0xffffffff, 0x10104040,
470 0xc488, 0xffffffff, 0x0100000a,
471 0xc314, 0xffffffff, 0x00000800,
472 0xc30c, 0xffffffff, 0x800000f4
473};
474
475static const u32 oland_golden_registers[] =
476{
477 0x9a10, 0x00010000, 0x00018208,
478 0x9830, 0xffffffff, 0x00000000,
479 0x9834, 0xf00fffff, 0x00000400,
480 0x9838, 0x0002021c, 0x00020200,
481 0xc78, 0x00000080, 0x00000000,
482 0xd030, 0x000300c0, 0x00800040,
483 0xd830, 0x000300c0, 0x00800040,
484 0x5bb0, 0x000000f0, 0x00000070,
485 0x5bc0, 0x00200000, 0x50100000,
486 0x7030, 0x31000311, 0x00000011,
487 0x2ae4, 0x00073ffe, 0x000022a2,
488 0x240c, 0x000007ff, 0x00000000,
489 0x8a14, 0xf000001f, 0x00000007,
490 0x8b24, 0xffffffff, 0x00ffffff,
491 0x8b10, 0x0000ff0f, 0x00000000,
492 0x28a4c, 0x07ffffff, 0x4e000000,
493 0x28350, 0x3f3f3fff, 0x00000082,
494 0x30, 0x000000ff, 0x0040,
495 0x34, 0x00000040, 0x00004040,
496 0x9100, 0x07ffffff, 0x03000000,
497 0x9060, 0x0000007f, 0x00000020,
498 0x9508, 0x00010000, 0x00010000,
499 0xac14, 0x000003ff, 0x000000f3,
500 0xac10, 0xffffffff, 0x00000000,
501 0xac0c, 0xffffffff, 0x00003210,
502 0x88d4, 0x0000001f, 0x00000010,
503 0x15c0, 0x000c0fc0, 0x000c0400
504};
505
Alex Deucherfffbdda2013-05-13 13:36:23 -0400506static const u32 hainan_golden_registers[] =
507{
508 0x9a10, 0x00010000, 0x00018208,
509 0x9830, 0xffffffff, 0x00000000,
510 0x9834, 0xf00fffff, 0x00000400,
511 0x9838, 0x0002021c, 0x00020200,
512 0xd0c0, 0xff000fff, 0x00000100,
513 0xd030, 0x000300c0, 0x00800040,
514 0xd8c0, 0xff000fff, 0x00000100,
515 0xd830, 0x000300c0, 0x00800040,
516 0x2ae4, 0x00073ffe, 0x000022a2,
517 0x240c, 0x000007ff, 0x00000000,
518 0x8a14, 0xf000001f, 0x00000007,
519 0x8b24, 0xffffffff, 0x00ffffff,
520 0x8b10, 0x0000ff0f, 0x00000000,
521 0x28a4c, 0x07ffffff, 0x4e000000,
522 0x28350, 0x3f3f3fff, 0x00000000,
523 0x30, 0x000000ff, 0x0040,
524 0x34, 0x00000040, 0x00004040,
525 0x9100, 0x03e00000, 0x03600000,
526 0x9060, 0x0000007f, 0x00000020,
527 0x9508, 0x00010000, 0x00010000,
528 0xac14, 0x000003ff, 0x000000f1,
529 0xac10, 0xffffffff, 0x00000000,
530 0xac0c, 0xffffffff, 0x00003210,
531 0x88d4, 0x0000001f, 0x00000010,
532 0x15c0, 0x000c0fc0, 0x000c0400
533};
534
535static const u32 hainan_golden_registers2[] =
536{
537 0x98f8, 0xffffffff, 0x02010001
538};
539
Alex Deucher205996c2013-03-01 17:08:42 -0500540static const u32 tahiti_mgcg_cgcg_init[] =
541{
542 0xc400, 0xffffffff, 0xfffffffc,
543 0x802c, 0xffffffff, 0xe0000000,
544 0x9a60, 0xffffffff, 0x00000100,
545 0x92a4, 0xffffffff, 0x00000100,
546 0xc164, 0xffffffff, 0x00000100,
547 0x9774, 0xffffffff, 0x00000100,
548 0x8984, 0xffffffff, 0x06000100,
549 0x8a18, 0xffffffff, 0x00000100,
550 0x92a0, 0xffffffff, 0x00000100,
551 0xc380, 0xffffffff, 0x00000100,
552 0x8b28, 0xffffffff, 0x00000100,
553 0x9144, 0xffffffff, 0x00000100,
554 0x8d88, 0xffffffff, 0x00000100,
555 0x8d8c, 0xffffffff, 0x00000100,
556 0x9030, 0xffffffff, 0x00000100,
557 0x9034, 0xffffffff, 0x00000100,
558 0x9038, 0xffffffff, 0x00000100,
559 0x903c, 0xffffffff, 0x00000100,
560 0xad80, 0xffffffff, 0x00000100,
561 0xac54, 0xffffffff, 0x00000100,
562 0x897c, 0xffffffff, 0x06000100,
563 0x9868, 0xffffffff, 0x00000100,
564 0x9510, 0xffffffff, 0x00000100,
565 0xaf04, 0xffffffff, 0x00000100,
566 0xae04, 0xffffffff, 0x00000100,
567 0x949c, 0xffffffff, 0x00000100,
568 0x802c, 0xffffffff, 0xe0000000,
569 0x9160, 0xffffffff, 0x00010000,
570 0x9164, 0xffffffff, 0x00030002,
571 0x9168, 0xffffffff, 0x00040007,
572 0x916c, 0xffffffff, 0x00060005,
573 0x9170, 0xffffffff, 0x00090008,
574 0x9174, 0xffffffff, 0x00020001,
575 0x9178, 0xffffffff, 0x00040003,
576 0x917c, 0xffffffff, 0x00000007,
577 0x9180, 0xffffffff, 0x00060005,
578 0x9184, 0xffffffff, 0x00090008,
579 0x9188, 0xffffffff, 0x00030002,
580 0x918c, 0xffffffff, 0x00050004,
581 0x9190, 0xffffffff, 0x00000008,
582 0x9194, 0xffffffff, 0x00070006,
583 0x9198, 0xffffffff, 0x000a0009,
584 0x919c, 0xffffffff, 0x00040003,
585 0x91a0, 0xffffffff, 0x00060005,
586 0x91a4, 0xffffffff, 0x00000009,
587 0x91a8, 0xffffffff, 0x00080007,
588 0x91ac, 0xffffffff, 0x000b000a,
589 0x91b0, 0xffffffff, 0x00050004,
590 0x91b4, 0xffffffff, 0x00070006,
591 0x91b8, 0xffffffff, 0x0008000b,
592 0x91bc, 0xffffffff, 0x000a0009,
593 0x91c0, 0xffffffff, 0x000d000c,
594 0x91c4, 0xffffffff, 0x00060005,
595 0x91c8, 0xffffffff, 0x00080007,
596 0x91cc, 0xffffffff, 0x0000000b,
597 0x91d0, 0xffffffff, 0x000a0009,
598 0x91d4, 0xffffffff, 0x000d000c,
599 0x91d8, 0xffffffff, 0x00070006,
600 0x91dc, 0xffffffff, 0x00090008,
601 0x91e0, 0xffffffff, 0x0000000c,
602 0x91e4, 0xffffffff, 0x000b000a,
603 0x91e8, 0xffffffff, 0x000e000d,
604 0x91ec, 0xffffffff, 0x00080007,
605 0x91f0, 0xffffffff, 0x000a0009,
606 0x91f4, 0xffffffff, 0x0000000d,
607 0x91f8, 0xffffffff, 0x000c000b,
608 0x91fc, 0xffffffff, 0x000f000e,
609 0x9200, 0xffffffff, 0x00090008,
610 0x9204, 0xffffffff, 0x000b000a,
611 0x9208, 0xffffffff, 0x000c000f,
612 0x920c, 0xffffffff, 0x000e000d,
613 0x9210, 0xffffffff, 0x00110010,
614 0x9214, 0xffffffff, 0x000a0009,
615 0x9218, 0xffffffff, 0x000c000b,
616 0x921c, 0xffffffff, 0x0000000f,
617 0x9220, 0xffffffff, 0x000e000d,
618 0x9224, 0xffffffff, 0x00110010,
619 0x9228, 0xffffffff, 0x000b000a,
620 0x922c, 0xffffffff, 0x000d000c,
621 0x9230, 0xffffffff, 0x00000010,
622 0x9234, 0xffffffff, 0x000f000e,
623 0x9238, 0xffffffff, 0x00120011,
624 0x923c, 0xffffffff, 0x000c000b,
625 0x9240, 0xffffffff, 0x000e000d,
626 0x9244, 0xffffffff, 0x00000011,
627 0x9248, 0xffffffff, 0x0010000f,
628 0x924c, 0xffffffff, 0x00130012,
629 0x9250, 0xffffffff, 0x000d000c,
630 0x9254, 0xffffffff, 0x000f000e,
631 0x9258, 0xffffffff, 0x00100013,
632 0x925c, 0xffffffff, 0x00120011,
633 0x9260, 0xffffffff, 0x00150014,
634 0x9264, 0xffffffff, 0x000e000d,
635 0x9268, 0xffffffff, 0x0010000f,
636 0x926c, 0xffffffff, 0x00000013,
637 0x9270, 0xffffffff, 0x00120011,
638 0x9274, 0xffffffff, 0x00150014,
639 0x9278, 0xffffffff, 0x000f000e,
640 0x927c, 0xffffffff, 0x00110010,
641 0x9280, 0xffffffff, 0x00000014,
642 0x9284, 0xffffffff, 0x00130012,
643 0x9288, 0xffffffff, 0x00160015,
644 0x928c, 0xffffffff, 0x0010000f,
645 0x9290, 0xffffffff, 0x00120011,
646 0x9294, 0xffffffff, 0x00000015,
647 0x9298, 0xffffffff, 0x00140013,
648 0x929c, 0xffffffff, 0x00170016,
649 0x9150, 0xffffffff, 0x96940200,
650 0x8708, 0xffffffff, 0x00900100,
651 0xc478, 0xffffffff, 0x00000080,
652 0xc404, 0xffffffff, 0x0020003f,
653 0x30, 0xffffffff, 0x0000001c,
654 0x34, 0x000f0000, 0x000f0000,
655 0x160c, 0xffffffff, 0x00000100,
656 0x1024, 0xffffffff, 0x00000100,
657 0x102c, 0x00000101, 0x00000000,
658 0x20a8, 0xffffffff, 0x00000104,
659 0x264c, 0x000c0000, 0x000c0000,
660 0x2648, 0x000c0000, 0x000c0000,
661 0x55e4, 0xff000fff, 0x00000100,
662 0x55e8, 0x00000001, 0x00000001,
663 0x2f50, 0x00000001, 0x00000001,
664 0x30cc, 0xc0000fff, 0x00000104,
665 0xc1e4, 0x00000001, 0x00000001,
666 0xd0c0, 0xfffffff0, 0x00000100,
667 0xd8c0, 0xfffffff0, 0x00000100
668};
669
670static const u32 pitcairn_mgcg_cgcg_init[] =
671{
672 0xc400, 0xffffffff, 0xfffffffc,
673 0x802c, 0xffffffff, 0xe0000000,
674 0x9a60, 0xffffffff, 0x00000100,
675 0x92a4, 0xffffffff, 0x00000100,
676 0xc164, 0xffffffff, 0x00000100,
677 0x9774, 0xffffffff, 0x00000100,
678 0x8984, 0xffffffff, 0x06000100,
679 0x8a18, 0xffffffff, 0x00000100,
680 0x92a0, 0xffffffff, 0x00000100,
681 0xc380, 0xffffffff, 0x00000100,
682 0x8b28, 0xffffffff, 0x00000100,
683 0x9144, 0xffffffff, 0x00000100,
684 0x8d88, 0xffffffff, 0x00000100,
685 0x8d8c, 0xffffffff, 0x00000100,
686 0x9030, 0xffffffff, 0x00000100,
687 0x9034, 0xffffffff, 0x00000100,
688 0x9038, 0xffffffff, 0x00000100,
689 0x903c, 0xffffffff, 0x00000100,
690 0xad80, 0xffffffff, 0x00000100,
691 0xac54, 0xffffffff, 0x00000100,
692 0x897c, 0xffffffff, 0x06000100,
693 0x9868, 0xffffffff, 0x00000100,
694 0x9510, 0xffffffff, 0x00000100,
695 0xaf04, 0xffffffff, 0x00000100,
696 0xae04, 0xffffffff, 0x00000100,
697 0x949c, 0xffffffff, 0x00000100,
698 0x802c, 0xffffffff, 0xe0000000,
699 0x9160, 0xffffffff, 0x00010000,
700 0x9164, 0xffffffff, 0x00030002,
701 0x9168, 0xffffffff, 0x00040007,
702 0x916c, 0xffffffff, 0x00060005,
703 0x9170, 0xffffffff, 0x00090008,
704 0x9174, 0xffffffff, 0x00020001,
705 0x9178, 0xffffffff, 0x00040003,
706 0x917c, 0xffffffff, 0x00000007,
707 0x9180, 0xffffffff, 0x00060005,
708 0x9184, 0xffffffff, 0x00090008,
709 0x9188, 0xffffffff, 0x00030002,
710 0x918c, 0xffffffff, 0x00050004,
711 0x9190, 0xffffffff, 0x00000008,
712 0x9194, 0xffffffff, 0x00070006,
713 0x9198, 0xffffffff, 0x000a0009,
714 0x919c, 0xffffffff, 0x00040003,
715 0x91a0, 0xffffffff, 0x00060005,
716 0x91a4, 0xffffffff, 0x00000009,
717 0x91a8, 0xffffffff, 0x00080007,
718 0x91ac, 0xffffffff, 0x000b000a,
719 0x91b0, 0xffffffff, 0x00050004,
720 0x91b4, 0xffffffff, 0x00070006,
721 0x91b8, 0xffffffff, 0x0008000b,
722 0x91bc, 0xffffffff, 0x000a0009,
723 0x91c0, 0xffffffff, 0x000d000c,
724 0x9200, 0xffffffff, 0x00090008,
725 0x9204, 0xffffffff, 0x000b000a,
726 0x9208, 0xffffffff, 0x000c000f,
727 0x920c, 0xffffffff, 0x000e000d,
728 0x9210, 0xffffffff, 0x00110010,
729 0x9214, 0xffffffff, 0x000a0009,
730 0x9218, 0xffffffff, 0x000c000b,
731 0x921c, 0xffffffff, 0x0000000f,
732 0x9220, 0xffffffff, 0x000e000d,
733 0x9224, 0xffffffff, 0x00110010,
734 0x9228, 0xffffffff, 0x000b000a,
735 0x922c, 0xffffffff, 0x000d000c,
736 0x9230, 0xffffffff, 0x00000010,
737 0x9234, 0xffffffff, 0x000f000e,
738 0x9238, 0xffffffff, 0x00120011,
739 0x923c, 0xffffffff, 0x000c000b,
740 0x9240, 0xffffffff, 0x000e000d,
741 0x9244, 0xffffffff, 0x00000011,
742 0x9248, 0xffffffff, 0x0010000f,
743 0x924c, 0xffffffff, 0x00130012,
744 0x9250, 0xffffffff, 0x000d000c,
745 0x9254, 0xffffffff, 0x000f000e,
746 0x9258, 0xffffffff, 0x00100013,
747 0x925c, 0xffffffff, 0x00120011,
748 0x9260, 0xffffffff, 0x00150014,
749 0x9150, 0xffffffff, 0x96940200,
750 0x8708, 0xffffffff, 0x00900100,
751 0xc478, 0xffffffff, 0x00000080,
752 0xc404, 0xffffffff, 0x0020003f,
753 0x30, 0xffffffff, 0x0000001c,
754 0x34, 0x000f0000, 0x000f0000,
755 0x160c, 0xffffffff, 0x00000100,
756 0x1024, 0xffffffff, 0x00000100,
757 0x102c, 0x00000101, 0x00000000,
758 0x20a8, 0xffffffff, 0x00000104,
759 0x55e4, 0xff000fff, 0x00000100,
760 0x55e8, 0x00000001, 0x00000001,
761 0x2f50, 0x00000001, 0x00000001,
762 0x30cc, 0xc0000fff, 0x00000104,
763 0xc1e4, 0x00000001, 0x00000001,
764 0xd0c0, 0xfffffff0, 0x00000100,
765 0xd8c0, 0xfffffff0, 0x00000100
766};
767
768static const u32 verde_mgcg_cgcg_init[] =
769{
770 0xc400, 0xffffffff, 0xfffffffc,
771 0x802c, 0xffffffff, 0xe0000000,
772 0x9a60, 0xffffffff, 0x00000100,
773 0x92a4, 0xffffffff, 0x00000100,
774 0xc164, 0xffffffff, 0x00000100,
775 0x9774, 0xffffffff, 0x00000100,
776 0x8984, 0xffffffff, 0x06000100,
777 0x8a18, 0xffffffff, 0x00000100,
778 0x92a0, 0xffffffff, 0x00000100,
779 0xc380, 0xffffffff, 0x00000100,
780 0x8b28, 0xffffffff, 0x00000100,
781 0x9144, 0xffffffff, 0x00000100,
782 0x8d88, 0xffffffff, 0x00000100,
783 0x8d8c, 0xffffffff, 0x00000100,
784 0x9030, 0xffffffff, 0x00000100,
785 0x9034, 0xffffffff, 0x00000100,
786 0x9038, 0xffffffff, 0x00000100,
787 0x903c, 0xffffffff, 0x00000100,
788 0xad80, 0xffffffff, 0x00000100,
789 0xac54, 0xffffffff, 0x00000100,
790 0x897c, 0xffffffff, 0x06000100,
791 0x9868, 0xffffffff, 0x00000100,
792 0x9510, 0xffffffff, 0x00000100,
793 0xaf04, 0xffffffff, 0x00000100,
794 0xae04, 0xffffffff, 0x00000100,
795 0x949c, 0xffffffff, 0x00000100,
796 0x802c, 0xffffffff, 0xe0000000,
797 0x9160, 0xffffffff, 0x00010000,
798 0x9164, 0xffffffff, 0x00030002,
799 0x9168, 0xffffffff, 0x00040007,
800 0x916c, 0xffffffff, 0x00060005,
801 0x9170, 0xffffffff, 0x00090008,
802 0x9174, 0xffffffff, 0x00020001,
803 0x9178, 0xffffffff, 0x00040003,
804 0x917c, 0xffffffff, 0x00000007,
805 0x9180, 0xffffffff, 0x00060005,
806 0x9184, 0xffffffff, 0x00090008,
807 0x9188, 0xffffffff, 0x00030002,
808 0x918c, 0xffffffff, 0x00050004,
809 0x9190, 0xffffffff, 0x00000008,
810 0x9194, 0xffffffff, 0x00070006,
811 0x9198, 0xffffffff, 0x000a0009,
812 0x919c, 0xffffffff, 0x00040003,
813 0x91a0, 0xffffffff, 0x00060005,
814 0x91a4, 0xffffffff, 0x00000009,
815 0x91a8, 0xffffffff, 0x00080007,
816 0x91ac, 0xffffffff, 0x000b000a,
817 0x91b0, 0xffffffff, 0x00050004,
818 0x91b4, 0xffffffff, 0x00070006,
819 0x91b8, 0xffffffff, 0x0008000b,
820 0x91bc, 0xffffffff, 0x000a0009,
821 0x91c0, 0xffffffff, 0x000d000c,
822 0x9200, 0xffffffff, 0x00090008,
823 0x9204, 0xffffffff, 0x000b000a,
824 0x9208, 0xffffffff, 0x000c000f,
825 0x920c, 0xffffffff, 0x000e000d,
826 0x9210, 0xffffffff, 0x00110010,
827 0x9214, 0xffffffff, 0x000a0009,
828 0x9218, 0xffffffff, 0x000c000b,
829 0x921c, 0xffffffff, 0x0000000f,
830 0x9220, 0xffffffff, 0x000e000d,
831 0x9224, 0xffffffff, 0x00110010,
832 0x9228, 0xffffffff, 0x000b000a,
833 0x922c, 0xffffffff, 0x000d000c,
834 0x9230, 0xffffffff, 0x00000010,
835 0x9234, 0xffffffff, 0x000f000e,
836 0x9238, 0xffffffff, 0x00120011,
837 0x923c, 0xffffffff, 0x000c000b,
838 0x9240, 0xffffffff, 0x000e000d,
839 0x9244, 0xffffffff, 0x00000011,
840 0x9248, 0xffffffff, 0x0010000f,
841 0x924c, 0xffffffff, 0x00130012,
842 0x9250, 0xffffffff, 0x000d000c,
843 0x9254, 0xffffffff, 0x000f000e,
844 0x9258, 0xffffffff, 0x00100013,
845 0x925c, 0xffffffff, 0x00120011,
846 0x9260, 0xffffffff, 0x00150014,
847 0x9150, 0xffffffff, 0x96940200,
848 0x8708, 0xffffffff, 0x00900100,
849 0xc478, 0xffffffff, 0x00000080,
850 0xc404, 0xffffffff, 0x0020003f,
851 0x30, 0xffffffff, 0x0000001c,
852 0x34, 0x000f0000, 0x000f0000,
853 0x160c, 0xffffffff, 0x00000100,
854 0x1024, 0xffffffff, 0x00000100,
855 0x102c, 0x00000101, 0x00000000,
856 0x20a8, 0xffffffff, 0x00000104,
857 0x264c, 0x000c0000, 0x000c0000,
858 0x2648, 0x000c0000, 0x000c0000,
859 0x55e4, 0xff000fff, 0x00000100,
860 0x55e8, 0x00000001, 0x00000001,
861 0x2f50, 0x00000001, 0x00000001,
862 0x30cc, 0xc0000fff, 0x00000104,
863 0xc1e4, 0x00000001, 0x00000001,
864 0xd0c0, 0xfffffff0, 0x00000100,
865 0xd8c0, 0xfffffff0, 0x00000100
866};
867
868static const u32 oland_mgcg_cgcg_init[] =
869{
870 0xc400, 0xffffffff, 0xfffffffc,
871 0x802c, 0xffffffff, 0xe0000000,
872 0x9a60, 0xffffffff, 0x00000100,
873 0x92a4, 0xffffffff, 0x00000100,
874 0xc164, 0xffffffff, 0x00000100,
875 0x9774, 0xffffffff, 0x00000100,
876 0x8984, 0xffffffff, 0x06000100,
877 0x8a18, 0xffffffff, 0x00000100,
878 0x92a0, 0xffffffff, 0x00000100,
879 0xc380, 0xffffffff, 0x00000100,
880 0x8b28, 0xffffffff, 0x00000100,
881 0x9144, 0xffffffff, 0x00000100,
882 0x8d88, 0xffffffff, 0x00000100,
883 0x8d8c, 0xffffffff, 0x00000100,
884 0x9030, 0xffffffff, 0x00000100,
885 0x9034, 0xffffffff, 0x00000100,
886 0x9038, 0xffffffff, 0x00000100,
887 0x903c, 0xffffffff, 0x00000100,
888 0xad80, 0xffffffff, 0x00000100,
889 0xac54, 0xffffffff, 0x00000100,
890 0x897c, 0xffffffff, 0x06000100,
891 0x9868, 0xffffffff, 0x00000100,
892 0x9510, 0xffffffff, 0x00000100,
893 0xaf04, 0xffffffff, 0x00000100,
894 0xae04, 0xffffffff, 0x00000100,
895 0x949c, 0xffffffff, 0x00000100,
896 0x802c, 0xffffffff, 0xe0000000,
897 0x9160, 0xffffffff, 0x00010000,
898 0x9164, 0xffffffff, 0x00030002,
899 0x9168, 0xffffffff, 0x00040007,
900 0x916c, 0xffffffff, 0x00060005,
901 0x9170, 0xffffffff, 0x00090008,
902 0x9174, 0xffffffff, 0x00020001,
903 0x9178, 0xffffffff, 0x00040003,
904 0x917c, 0xffffffff, 0x00000007,
905 0x9180, 0xffffffff, 0x00060005,
906 0x9184, 0xffffffff, 0x00090008,
907 0x9188, 0xffffffff, 0x00030002,
908 0x918c, 0xffffffff, 0x00050004,
909 0x9190, 0xffffffff, 0x00000008,
910 0x9194, 0xffffffff, 0x00070006,
911 0x9198, 0xffffffff, 0x000a0009,
912 0x919c, 0xffffffff, 0x00040003,
913 0x91a0, 0xffffffff, 0x00060005,
914 0x91a4, 0xffffffff, 0x00000009,
915 0x91a8, 0xffffffff, 0x00080007,
916 0x91ac, 0xffffffff, 0x000b000a,
917 0x91b0, 0xffffffff, 0x00050004,
918 0x91b4, 0xffffffff, 0x00070006,
919 0x91b8, 0xffffffff, 0x0008000b,
920 0x91bc, 0xffffffff, 0x000a0009,
921 0x91c0, 0xffffffff, 0x000d000c,
922 0x91c4, 0xffffffff, 0x00060005,
923 0x91c8, 0xffffffff, 0x00080007,
924 0x91cc, 0xffffffff, 0x0000000b,
925 0x91d0, 0xffffffff, 0x000a0009,
926 0x91d4, 0xffffffff, 0x000d000c,
927 0x9150, 0xffffffff, 0x96940200,
928 0x8708, 0xffffffff, 0x00900100,
929 0xc478, 0xffffffff, 0x00000080,
930 0xc404, 0xffffffff, 0x0020003f,
931 0x30, 0xffffffff, 0x0000001c,
932 0x34, 0x000f0000, 0x000f0000,
933 0x160c, 0xffffffff, 0x00000100,
934 0x1024, 0xffffffff, 0x00000100,
935 0x102c, 0x00000101, 0x00000000,
936 0x20a8, 0xffffffff, 0x00000104,
937 0x264c, 0x000c0000, 0x000c0000,
938 0x2648, 0x000c0000, 0x000c0000,
939 0x55e4, 0xff000fff, 0x00000100,
940 0x55e8, 0x00000001, 0x00000001,
941 0x2f50, 0x00000001, 0x00000001,
942 0x30cc, 0xc0000fff, 0x00000104,
943 0xc1e4, 0x00000001, 0x00000001,
944 0xd0c0, 0xfffffff0, 0x00000100,
945 0xd8c0, 0xfffffff0, 0x00000100
946};
947
Alex Deucherfffbdda2013-05-13 13:36:23 -0400948static const u32 hainan_mgcg_cgcg_init[] =
949{
950 0xc400, 0xffffffff, 0xfffffffc,
951 0x802c, 0xffffffff, 0xe0000000,
952 0x9a60, 0xffffffff, 0x00000100,
953 0x92a4, 0xffffffff, 0x00000100,
954 0xc164, 0xffffffff, 0x00000100,
955 0x9774, 0xffffffff, 0x00000100,
956 0x8984, 0xffffffff, 0x06000100,
957 0x8a18, 0xffffffff, 0x00000100,
958 0x92a0, 0xffffffff, 0x00000100,
959 0xc380, 0xffffffff, 0x00000100,
960 0x8b28, 0xffffffff, 0x00000100,
961 0x9144, 0xffffffff, 0x00000100,
962 0x8d88, 0xffffffff, 0x00000100,
963 0x8d8c, 0xffffffff, 0x00000100,
964 0x9030, 0xffffffff, 0x00000100,
965 0x9034, 0xffffffff, 0x00000100,
966 0x9038, 0xffffffff, 0x00000100,
967 0x903c, 0xffffffff, 0x00000100,
968 0xad80, 0xffffffff, 0x00000100,
969 0xac54, 0xffffffff, 0x00000100,
970 0x897c, 0xffffffff, 0x06000100,
971 0x9868, 0xffffffff, 0x00000100,
972 0x9510, 0xffffffff, 0x00000100,
973 0xaf04, 0xffffffff, 0x00000100,
974 0xae04, 0xffffffff, 0x00000100,
975 0x949c, 0xffffffff, 0x00000100,
976 0x802c, 0xffffffff, 0xe0000000,
977 0x9160, 0xffffffff, 0x00010000,
978 0x9164, 0xffffffff, 0x00030002,
979 0x9168, 0xffffffff, 0x00040007,
980 0x916c, 0xffffffff, 0x00060005,
981 0x9170, 0xffffffff, 0x00090008,
982 0x9174, 0xffffffff, 0x00020001,
983 0x9178, 0xffffffff, 0x00040003,
984 0x917c, 0xffffffff, 0x00000007,
985 0x9180, 0xffffffff, 0x00060005,
986 0x9184, 0xffffffff, 0x00090008,
987 0x9188, 0xffffffff, 0x00030002,
988 0x918c, 0xffffffff, 0x00050004,
989 0x9190, 0xffffffff, 0x00000008,
990 0x9194, 0xffffffff, 0x00070006,
991 0x9198, 0xffffffff, 0x000a0009,
992 0x919c, 0xffffffff, 0x00040003,
993 0x91a0, 0xffffffff, 0x00060005,
994 0x91a4, 0xffffffff, 0x00000009,
995 0x91a8, 0xffffffff, 0x00080007,
996 0x91ac, 0xffffffff, 0x000b000a,
997 0x91b0, 0xffffffff, 0x00050004,
998 0x91b4, 0xffffffff, 0x00070006,
999 0x91b8, 0xffffffff, 0x0008000b,
1000 0x91bc, 0xffffffff, 0x000a0009,
1001 0x91c0, 0xffffffff, 0x000d000c,
1002 0x91c4, 0xffffffff, 0x00060005,
1003 0x91c8, 0xffffffff, 0x00080007,
1004 0x91cc, 0xffffffff, 0x0000000b,
1005 0x91d0, 0xffffffff, 0x000a0009,
1006 0x91d4, 0xffffffff, 0x000d000c,
1007 0x9150, 0xffffffff, 0x96940200,
1008 0x8708, 0xffffffff, 0x00900100,
1009 0xc478, 0xffffffff, 0x00000080,
1010 0xc404, 0xffffffff, 0x0020003f,
1011 0x30, 0xffffffff, 0x0000001c,
1012 0x34, 0x000f0000, 0x000f0000,
1013 0x160c, 0xffffffff, 0x00000100,
1014 0x1024, 0xffffffff, 0x00000100,
1015 0x20a8, 0xffffffff, 0x00000104,
1016 0x264c, 0x000c0000, 0x000c0000,
1017 0x2648, 0x000c0000, 0x000c0000,
1018 0x2f50, 0x00000001, 0x00000001,
1019 0x30cc, 0xc0000fff, 0x00000104,
1020 0xc1e4, 0x00000001, 0x00000001,
1021 0xd0c0, 0xfffffff0, 0x00000100,
1022 0xd8c0, 0xfffffff0, 0x00000100
1023};
1024
Alex Deucher205996c2013-03-01 17:08:42 -05001025static u32 verde_pg_init[] =
1026{
1027 0x353c, 0xffffffff, 0x40000,
1028 0x3538, 0xffffffff, 0x200010ff,
1029 0x353c, 0xffffffff, 0x0,
1030 0x353c, 0xffffffff, 0x0,
1031 0x353c, 0xffffffff, 0x0,
1032 0x353c, 0xffffffff, 0x0,
1033 0x353c, 0xffffffff, 0x0,
1034 0x353c, 0xffffffff, 0x7007,
1035 0x3538, 0xffffffff, 0x300010ff,
1036 0x353c, 0xffffffff, 0x0,
1037 0x353c, 0xffffffff, 0x0,
1038 0x353c, 0xffffffff, 0x0,
1039 0x353c, 0xffffffff, 0x0,
1040 0x353c, 0xffffffff, 0x0,
1041 0x353c, 0xffffffff, 0x400000,
1042 0x3538, 0xffffffff, 0x100010ff,
1043 0x353c, 0xffffffff, 0x0,
1044 0x353c, 0xffffffff, 0x0,
1045 0x353c, 0xffffffff, 0x0,
1046 0x353c, 0xffffffff, 0x0,
1047 0x353c, 0xffffffff, 0x0,
1048 0x353c, 0xffffffff, 0x120200,
1049 0x3538, 0xffffffff, 0x500010ff,
1050 0x353c, 0xffffffff, 0x0,
1051 0x353c, 0xffffffff, 0x0,
1052 0x353c, 0xffffffff, 0x0,
1053 0x353c, 0xffffffff, 0x0,
1054 0x353c, 0xffffffff, 0x0,
1055 0x353c, 0xffffffff, 0x1e1e16,
1056 0x3538, 0xffffffff, 0x600010ff,
1057 0x353c, 0xffffffff, 0x0,
1058 0x353c, 0xffffffff, 0x0,
1059 0x353c, 0xffffffff, 0x0,
1060 0x353c, 0xffffffff, 0x0,
1061 0x353c, 0xffffffff, 0x0,
1062 0x353c, 0xffffffff, 0x171f1e,
1063 0x3538, 0xffffffff, 0x700010ff,
1064 0x353c, 0xffffffff, 0x0,
1065 0x353c, 0xffffffff, 0x0,
1066 0x353c, 0xffffffff, 0x0,
1067 0x353c, 0xffffffff, 0x0,
1068 0x353c, 0xffffffff, 0x0,
1069 0x353c, 0xffffffff, 0x0,
1070 0x3538, 0xffffffff, 0x9ff,
1071 0x3500, 0xffffffff, 0x0,
1072 0x3504, 0xffffffff, 0x10000800,
1073 0x3504, 0xffffffff, 0xf,
1074 0x3504, 0xffffffff, 0xf,
1075 0x3500, 0xffffffff, 0x4,
1076 0x3504, 0xffffffff, 0x1000051e,
1077 0x3504, 0xffffffff, 0xffff,
1078 0x3504, 0xffffffff, 0xffff,
1079 0x3500, 0xffffffff, 0x8,
1080 0x3504, 0xffffffff, 0x80500,
1081 0x3500, 0xffffffff, 0x12,
1082 0x3504, 0xffffffff, 0x9050c,
1083 0x3500, 0xffffffff, 0x1d,
1084 0x3504, 0xffffffff, 0xb052c,
1085 0x3500, 0xffffffff, 0x2a,
1086 0x3504, 0xffffffff, 0x1053e,
1087 0x3500, 0xffffffff, 0x2d,
1088 0x3504, 0xffffffff, 0x10546,
1089 0x3500, 0xffffffff, 0x30,
1090 0x3504, 0xffffffff, 0xa054e,
1091 0x3500, 0xffffffff, 0x3c,
1092 0x3504, 0xffffffff, 0x1055f,
1093 0x3500, 0xffffffff, 0x3f,
1094 0x3504, 0xffffffff, 0x10567,
1095 0x3500, 0xffffffff, 0x42,
1096 0x3504, 0xffffffff, 0x1056f,
1097 0x3500, 0xffffffff, 0x45,
1098 0x3504, 0xffffffff, 0x10572,
1099 0x3500, 0xffffffff, 0x48,
1100 0x3504, 0xffffffff, 0x20575,
1101 0x3500, 0xffffffff, 0x4c,
1102 0x3504, 0xffffffff, 0x190801,
1103 0x3500, 0xffffffff, 0x67,
1104 0x3504, 0xffffffff, 0x1082a,
1105 0x3500, 0xffffffff, 0x6a,
1106 0x3504, 0xffffffff, 0x1b082d,
1107 0x3500, 0xffffffff, 0x87,
1108 0x3504, 0xffffffff, 0x310851,
1109 0x3500, 0xffffffff, 0xba,
1110 0x3504, 0xffffffff, 0x891,
1111 0x3500, 0xffffffff, 0xbc,
1112 0x3504, 0xffffffff, 0x893,
1113 0x3500, 0xffffffff, 0xbe,
1114 0x3504, 0xffffffff, 0x20895,
1115 0x3500, 0xffffffff, 0xc2,
1116 0x3504, 0xffffffff, 0x20899,
1117 0x3500, 0xffffffff, 0xc6,
1118 0x3504, 0xffffffff, 0x2089d,
1119 0x3500, 0xffffffff, 0xca,
1120 0x3504, 0xffffffff, 0x8a1,
1121 0x3500, 0xffffffff, 0xcc,
1122 0x3504, 0xffffffff, 0x8a3,
1123 0x3500, 0xffffffff, 0xce,
1124 0x3504, 0xffffffff, 0x308a5,
1125 0x3500, 0xffffffff, 0xd3,
1126 0x3504, 0xffffffff, 0x6d08cd,
1127 0x3500, 0xffffffff, 0x142,
1128 0x3504, 0xffffffff, 0x2000095a,
1129 0x3504, 0xffffffff, 0x1,
1130 0x3500, 0xffffffff, 0x144,
1131 0x3504, 0xffffffff, 0x301f095b,
1132 0x3500, 0xffffffff, 0x165,
1133 0x3504, 0xffffffff, 0xc094d,
1134 0x3500, 0xffffffff, 0x173,
1135 0x3504, 0xffffffff, 0xf096d,
1136 0x3500, 0xffffffff, 0x184,
1137 0x3504, 0xffffffff, 0x15097f,
1138 0x3500, 0xffffffff, 0x19b,
1139 0x3504, 0xffffffff, 0xc0998,
1140 0x3500, 0xffffffff, 0x1a9,
1141 0x3504, 0xffffffff, 0x409a7,
1142 0x3500, 0xffffffff, 0x1af,
1143 0x3504, 0xffffffff, 0xcdc,
1144 0x3500, 0xffffffff, 0x1b1,
1145 0x3504, 0xffffffff, 0x800,
1146 0x3508, 0xffffffff, 0x6c9b2000,
1147 0x3510, 0xfc00, 0x2000,
1148 0x3544, 0xffffffff, 0xfc0,
1149 0x28d4, 0x00000100, 0x100
1150};
1151
1152static void si_init_golden_registers(struct radeon_device *rdev)
1153{
1154 switch (rdev->family) {
1155 case CHIP_TAHITI:
1156 radeon_program_register_sequence(rdev,
1157 tahiti_golden_registers,
1158 (const u32)ARRAY_SIZE(tahiti_golden_registers));
1159 radeon_program_register_sequence(rdev,
1160 tahiti_golden_rlc_registers,
1161 (const u32)ARRAY_SIZE(tahiti_golden_rlc_registers));
1162 radeon_program_register_sequence(rdev,
1163 tahiti_mgcg_cgcg_init,
1164 (const u32)ARRAY_SIZE(tahiti_mgcg_cgcg_init));
1165 radeon_program_register_sequence(rdev,
1166 tahiti_golden_registers2,
1167 (const u32)ARRAY_SIZE(tahiti_golden_registers2));
1168 break;
1169 case CHIP_PITCAIRN:
1170 radeon_program_register_sequence(rdev,
1171 pitcairn_golden_registers,
1172 (const u32)ARRAY_SIZE(pitcairn_golden_registers));
1173 radeon_program_register_sequence(rdev,
1174 pitcairn_golden_rlc_registers,
1175 (const u32)ARRAY_SIZE(pitcairn_golden_rlc_registers));
1176 radeon_program_register_sequence(rdev,
1177 pitcairn_mgcg_cgcg_init,
1178 (const u32)ARRAY_SIZE(pitcairn_mgcg_cgcg_init));
1179 break;
1180 case CHIP_VERDE:
1181 radeon_program_register_sequence(rdev,
1182 verde_golden_registers,
1183 (const u32)ARRAY_SIZE(verde_golden_registers));
1184 radeon_program_register_sequence(rdev,
1185 verde_golden_rlc_registers,
1186 (const u32)ARRAY_SIZE(verde_golden_rlc_registers));
1187 radeon_program_register_sequence(rdev,
1188 verde_mgcg_cgcg_init,
1189 (const u32)ARRAY_SIZE(verde_mgcg_cgcg_init));
1190 radeon_program_register_sequence(rdev,
1191 verde_pg_init,
1192 (const u32)ARRAY_SIZE(verde_pg_init));
1193 break;
1194 case CHIP_OLAND:
1195 radeon_program_register_sequence(rdev,
1196 oland_golden_registers,
1197 (const u32)ARRAY_SIZE(oland_golden_registers));
1198 radeon_program_register_sequence(rdev,
1199 oland_golden_rlc_registers,
1200 (const u32)ARRAY_SIZE(oland_golden_rlc_registers));
1201 radeon_program_register_sequence(rdev,
1202 oland_mgcg_cgcg_init,
1203 (const u32)ARRAY_SIZE(oland_mgcg_cgcg_init));
1204 break;
Alex Deucherfffbdda2013-05-13 13:36:23 -04001205 case CHIP_HAINAN:
1206 radeon_program_register_sequence(rdev,
1207 hainan_golden_registers,
1208 (const u32)ARRAY_SIZE(hainan_golden_registers));
1209 radeon_program_register_sequence(rdev,
1210 hainan_golden_registers2,
1211 (const u32)ARRAY_SIZE(hainan_golden_registers2));
1212 radeon_program_register_sequence(rdev,
1213 hainan_mgcg_cgcg_init,
1214 (const u32)ARRAY_SIZE(hainan_mgcg_cgcg_init));
1215 break;
Alex Deucher205996c2013-03-01 17:08:42 -05001216 default:
1217 break;
1218 }
1219}
1220
Alex Deucher454d2e22013-02-14 10:04:02 -05001221#define PCIE_BUS_CLK 10000
1222#define TCLK (PCIE_BUS_CLK / 10)
1223
1224/**
1225 * si_get_xclk - get the xclk
1226 *
1227 * @rdev: radeon_device pointer
1228 *
1229 * Returns the reference clock used by the gfx engine
1230 * (SI).
1231 */
1232u32 si_get_xclk(struct radeon_device *rdev)
1233{
1234 u32 reference_clock = rdev->clock.spll.reference_freq;
1235 u32 tmp;
1236
1237 tmp = RREG32(CG_CLKPIN_CNTL_2);
1238 if (tmp & MUX_TCLK_TO_XCLK)
1239 return TCLK;
1240
1241 tmp = RREG32(CG_CLKPIN_CNTL);
1242 if (tmp & XTALIN_DIVIDE)
1243 return reference_clock / 4;
1244
1245 return reference_clock;
1246}
1247
Alex Deucher1bd47d22012-03-20 17:18:10 -04001248/* get temperature in millidegrees */
1249int si_get_temp(struct radeon_device *rdev)
1250{
1251 u32 temp;
1252 int actual_temp = 0;
1253
1254 temp = (RREG32(CG_MULT_THERMAL_STATUS) & CTF_TEMP_MASK) >>
1255 CTF_TEMP_SHIFT;
1256
1257 if (temp & 0x200)
1258 actual_temp = 255;
1259 else
1260 actual_temp = temp & 0x1ff;
1261
1262 actual_temp = (actual_temp * 1000);
1263
1264 return actual_temp;
1265}
1266
Alex Deucher8b074dd2012-03-20 17:18:18 -04001267#define TAHITI_IO_MC_REGS_SIZE 36
1268
1269static const u32 tahiti_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
1270 {0x0000006f, 0x03044000},
1271 {0x00000070, 0x0480c018},
1272 {0x00000071, 0x00000040},
1273 {0x00000072, 0x01000000},
1274 {0x00000074, 0x000000ff},
1275 {0x00000075, 0x00143400},
1276 {0x00000076, 0x08ec0800},
1277 {0x00000077, 0x040000cc},
1278 {0x00000079, 0x00000000},
1279 {0x0000007a, 0x21000409},
1280 {0x0000007c, 0x00000000},
1281 {0x0000007d, 0xe8000000},
1282 {0x0000007e, 0x044408a8},
1283 {0x0000007f, 0x00000003},
1284 {0x00000080, 0x00000000},
1285 {0x00000081, 0x01000000},
1286 {0x00000082, 0x02000000},
1287 {0x00000083, 0x00000000},
1288 {0x00000084, 0xe3f3e4f4},
1289 {0x00000085, 0x00052024},
1290 {0x00000087, 0x00000000},
1291 {0x00000088, 0x66036603},
1292 {0x00000089, 0x01000000},
1293 {0x0000008b, 0x1c0a0000},
1294 {0x0000008c, 0xff010000},
1295 {0x0000008e, 0xffffefff},
1296 {0x0000008f, 0xfff3efff},
1297 {0x00000090, 0xfff3efbf},
1298 {0x00000094, 0x00101101},
1299 {0x00000095, 0x00000fff},
1300 {0x00000096, 0x00116fff},
1301 {0x00000097, 0x60010000},
1302 {0x00000098, 0x10010000},
1303 {0x00000099, 0x00006000},
1304 {0x0000009a, 0x00001000},
1305 {0x0000009f, 0x00a77400}
1306};
1307
1308static const u32 pitcairn_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
1309 {0x0000006f, 0x03044000},
1310 {0x00000070, 0x0480c018},
1311 {0x00000071, 0x00000040},
1312 {0x00000072, 0x01000000},
1313 {0x00000074, 0x000000ff},
1314 {0x00000075, 0x00143400},
1315 {0x00000076, 0x08ec0800},
1316 {0x00000077, 0x040000cc},
1317 {0x00000079, 0x00000000},
1318 {0x0000007a, 0x21000409},
1319 {0x0000007c, 0x00000000},
1320 {0x0000007d, 0xe8000000},
1321 {0x0000007e, 0x044408a8},
1322 {0x0000007f, 0x00000003},
1323 {0x00000080, 0x00000000},
1324 {0x00000081, 0x01000000},
1325 {0x00000082, 0x02000000},
1326 {0x00000083, 0x00000000},
1327 {0x00000084, 0xe3f3e4f4},
1328 {0x00000085, 0x00052024},
1329 {0x00000087, 0x00000000},
1330 {0x00000088, 0x66036603},
1331 {0x00000089, 0x01000000},
1332 {0x0000008b, 0x1c0a0000},
1333 {0x0000008c, 0xff010000},
1334 {0x0000008e, 0xffffefff},
1335 {0x0000008f, 0xfff3efff},
1336 {0x00000090, 0xfff3efbf},
1337 {0x00000094, 0x00101101},
1338 {0x00000095, 0x00000fff},
1339 {0x00000096, 0x00116fff},
1340 {0x00000097, 0x60010000},
1341 {0x00000098, 0x10010000},
1342 {0x00000099, 0x00006000},
1343 {0x0000009a, 0x00001000},
1344 {0x0000009f, 0x00a47400}
1345};
1346
1347static const u32 verde_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
1348 {0x0000006f, 0x03044000},
1349 {0x00000070, 0x0480c018},
1350 {0x00000071, 0x00000040},
1351 {0x00000072, 0x01000000},
1352 {0x00000074, 0x000000ff},
1353 {0x00000075, 0x00143400},
1354 {0x00000076, 0x08ec0800},
1355 {0x00000077, 0x040000cc},
1356 {0x00000079, 0x00000000},
1357 {0x0000007a, 0x21000409},
1358 {0x0000007c, 0x00000000},
1359 {0x0000007d, 0xe8000000},
1360 {0x0000007e, 0x044408a8},
1361 {0x0000007f, 0x00000003},
1362 {0x00000080, 0x00000000},
1363 {0x00000081, 0x01000000},
1364 {0x00000082, 0x02000000},
1365 {0x00000083, 0x00000000},
1366 {0x00000084, 0xe3f3e4f4},
1367 {0x00000085, 0x00052024},
1368 {0x00000087, 0x00000000},
1369 {0x00000088, 0x66036603},
1370 {0x00000089, 0x01000000},
1371 {0x0000008b, 0x1c0a0000},
1372 {0x0000008c, 0xff010000},
1373 {0x0000008e, 0xffffefff},
1374 {0x0000008f, 0xfff3efff},
1375 {0x00000090, 0xfff3efbf},
1376 {0x00000094, 0x00101101},
1377 {0x00000095, 0x00000fff},
1378 {0x00000096, 0x00116fff},
1379 {0x00000097, 0x60010000},
1380 {0x00000098, 0x10010000},
1381 {0x00000099, 0x00006000},
1382 {0x0000009a, 0x00001000},
1383 {0x0000009f, 0x00a37400}
1384};
1385
Alex Deucherbcc7f5d2012-07-26 18:36:28 -04001386static const u32 oland_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
1387 {0x0000006f, 0x03044000},
1388 {0x00000070, 0x0480c018},
1389 {0x00000071, 0x00000040},
1390 {0x00000072, 0x01000000},
1391 {0x00000074, 0x000000ff},
1392 {0x00000075, 0x00143400},
1393 {0x00000076, 0x08ec0800},
1394 {0x00000077, 0x040000cc},
1395 {0x00000079, 0x00000000},
1396 {0x0000007a, 0x21000409},
1397 {0x0000007c, 0x00000000},
1398 {0x0000007d, 0xe8000000},
1399 {0x0000007e, 0x044408a8},
1400 {0x0000007f, 0x00000003},
1401 {0x00000080, 0x00000000},
1402 {0x00000081, 0x01000000},
1403 {0x00000082, 0x02000000},
1404 {0x00000083, 0x00000000},
1405 {0x00000084, 0xe3f3e4f4},
1406 {0x00000085, 0x00052024},
1407 {0x00000087, 0x00000000},
1408 {0x00000088, 0x66036603},
1409 {0x00000089, 0x01000000},
1410 {0x0000008b, 0x1c0a0000},
1411 {0x0000008c, 0xff010000},
1412 {0x0000008e, 0xffffefff},
1413 {0x0000008f, 0xfff3efff},
1414 {0x00000090, 0xfff3efbf},
1415 {0x00000094, 0x00101101},
1416 {0x00000095, 0x00000fff},
1417 {0x00000096, 0x00116fff},
1418 {0x00000097, 0x60010000},
1419 {0x00000098, 0x10010000},
1420 {0x00000099, 0x00006000},
1421 {0x0000009a, 0x00001000},
1422 {0x0000009f, 0x00a17730}
1423};
1424
Alex Deucherc04c00b2012-07-31 12:57:45 -04001425static const u32 hainan_io_mc_regs[TAHITI_IO_MC_REGS_SIZE][2] = {
1426 {0x0000006f, 0x03044000},
1427 {0x00000070, 0x0480c018},
1428 {0x00000071, 0x00000040},
1429 {0x00000072, 0x01000000},
1430 {0x00000074, 0x000000ff},
1431 {0x00000075, 0x00143400},
1432 {0x00000076, 0x08ec0800},
1433 {0x00000077, 0x040000cc},
1434 {0x00000079, 0x00000000},
1435 {0x0000007a, 0x21000409},
1436 {0x0000007c, 0x00000000},
1437 {0x0000007d, 0xe8000000},
1438 {0x0000007e, 0x044408a8},
1439 {0x0000007f, 0x00000003},
1440 {0x00000080, 0x00000000},
1441 {0x00000081, 0x01000000},
1442 {0x00000082, 0x02000000},
1443 {0x00000083, 0x00000000},
1444 {0x00000084, 0xe3f3e4f4},
1445 {0x00000085, 0x00052024},
1446 {0x00000087, 0x00000000},
1447 {0x00000088, 0x66036603},
1448 {0x00000089, 0x01000000},
1449 {0x0000008b, 0x1c0a0000},
1450 {0x0000008c, 0xff010000},
1451 {0x0000008e, 0xffffefff},
1452 {0x0000008f, 0xfff3efff},
1453 {0x00000090, 0xfff3efbf},
1454 {0x00000094, 0x00101101},
1455 {0x00000095, 0x00000fff},
1456 {0x00000096, 0x00116fff},
1457 {0x00000097, 0x60010000},
1458 {0x00000098, 0x10010000},
1459 {0x00000099, 0x00006000},
1460 {0x0000009a, 0x00001000},
1461 {0x0000009f, 0x00a07730}
1462};
1463
Alex Deucher8b074dd2012-03-20 17:18:18 -04001464/* ucode loading */
Alex Deucher6c7bcce2013-12-18 14:07:14 -05001465int si_mc_load_microcode(struct radeon_device *rdev)
Alex Deucher8b074dd2012-03-20 17:18:18 -04001466{
1467 const __be32 *fw_data;
1468 u32 running, blackout = 0;
1469 u32 *io_mc_regs;
1470 int i, ucode_size, regs_size;
1471
1472 if (!rdev->mc_fw)
1473 return -EINVAL;
1474
1475 switch (rdev->family) {
1476 case CHIP_TAHITI:
1477 io_mc_regs = (u32 *)&tahiti_io_mc_regs;
1478 ucode_size = SI_MC_UCODE_SIZE;
1479 regs_size = TAHITI_IO_MC_REGS_SIZE;
1480 break;
1481 case CHIP_PITCAIRN:
1482 io_mc_regs = (u32 *)&pitcairn_io_mc_regs;
1483 ucode_size = SI_MC_UCODE_SIZE;
1484 regs_size = TAHITI_IO_MC_REGS_SIZE;
1485 break;
1486 case CHIP_VERDE:
1487 default:
1488 io_mc_regs = (u32 *)&verde_io_mc_regs;
1489 ucode_size = SI_MC_UCODE_SIZE;
1490 regs_size = TAHITI_IO_MC_REGS_SIZE;
1491 break;
Alex Deucherbcc7f5d2012-07-26 18:36:28 -04001492 case CHIP_OLAND:
1493 io_mc_regs = (u32 *)&oland_io_mc_regs;
1494 ucode_size = OLAND_MC_UCODE_SIZE;
1495 regs_size = TAHITI_IO_MC_REGS_SIZE;
1496 break;
Alex Deucherc04c00b2012-07-31 12:57:45 -04001497 case CHIP_HAINAN:
1498 io_mc_regs = (u32 *)&hainan_io_mc_regs;
1499 ucode_size = OLAND_MC_UCODE_SIZE;
1500 regs_size = TAHITI_IO_MC_REGS_SIZE;
1501 break;
Alex Deucher8b074dd2012-03-20 17:18:18 -04001502 }
1503
1504 running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
1505
1506 if (running == 0) {
1507 if (running) {
1508 blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
1509 WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
1510 }
1511
1512 /* reset the engine and set to writable */
1513 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
1514 WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
1515
1516 /* load mc io regs */
1517 for (i = 0; i < regs_size; i++) {
1518 WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
1519 WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
1520 }
1521 /* load the MC ucode */
1522 fw_data = (const __be32 *)rdev->mc_fw->data;
1523 for (i = 0; i < ucode_size; i++)
1524 WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
1525
1526 /* put the engine back into the active state */
1527 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
1528 WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
1529 WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
1530
1531 /* wait for training to complete */
1532 for (i = 0; i < rdev->usec_timeout; i++) {
1533 if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D0)
1534 break;
1535 udelay(1);
1536 }
1537 for (i = 0; i < rdev->usec_timeout; i++) {
1538 if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D1)
1539 break;
1540 udelay(1);
1541 }
1542
1543 if (running)
1544 WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
1545 }
1546
1547 return 0;
1548}
1549
Alex Deucher0f0de062012-03-20 17:18:17 -04001550static int si_init_microcode(struct radeon_device *rdev)
1551{
Alex Deucher0f0de062012-03-20 17:18:17 -04001552 const char *chip_name;
1553 const char *rlc_chip_name;
1554 size_t pfp_req_size, me_req_size, ce_req_size, rlc_req_size, mc_req_size;
Alex Deuchera9e61412013-06-25 17:56:16 -04001555 size_t smc_req_size;
Alex Deucher0f0de062012-03-20 17:18:17 -04001556 char fw_name[30];
1557 int err;
1558
1559 DRM_DEBUG("\n");
1560
Alex Deucher0f0de062012-03-20 17:18:17 -04001561 switch (rdev->family) {
1562 case CHIP_TAHITI:
1563 chip_name = "TAHITI";
1564 rlc_chip_name = "TAHITI";
1565 pfp_req_size = SI_PFP_UCODE_SIZE * 4;
1566 me_req_size = SI_PM4_UCODE_SIZE * 4;
1567 ce_req_size = SI_CE_UCODE_SIZE * 4;
1568 rlc_req_size = SI_RLC_UCODE_SIZE * 4;
1569 mc_req_size = SI_MC_UCODE_SIZE * 4;
Alex Deuchera9e61412013-06-25 17:56:16 -04001570 smc_req_size = ALIGN(TAHITI_SMC_UCODE_SIZE, 4);
Alex Deucher0f0de062012-03-20 17:18:17 -04001571 break;
1572 case CHIP_PITCAIRN:
1573 chip_name = "PITCAIRN";
1574 rlc_chip_name = "PITCAIRN";
1575 pfp_req_size = SI_PFP_UCODE_SIZE * 4;
1576 me_req_size = SI_PM4_UCODE_SIZE * 4;
1577 ce_req_size = SI_CE_UCODE_SIZE * 4;
1578 rlc_req_size = SI_RLC_UCODE_SIZE * 4;
1579 mc_req_size = SI_MC_UCODE_SIZE * 4;
Alex Deuchera9e61412013-06-25 17:56:16 -04001580 smc_req_size = ALIGN(PITCAIRN_SMC_UCODE_SIZE, 4);
Alex Deucher0f0de062012-03-20 17:18:17 -04001581 break;
1582 case CHIP_VERDE:
1583 chip_name = "VERDE";
1584 rlc_chip_name = "VERDE";
1585 pfp_req_size = SI_PFP_UCODE_SIZE * 4;
1586 me_req_size = SI_PM4_UCODE_SIZE * 4;
1587 ce_req_size = SI_CE_UCODE_SIZE * 4;
1588 rlc_req_size = SI_RLC_UCODE_SIZE * 4;
1589 mc_req_size = SI_MC_UCODE_SIZE * 4;
Alex Deuchera9e61412013-06-25 17:56:16 -04001590 smc_req_size = ALIGN(VERDE_SMC_UCODE_SIZE, 4);
Alex Deucher0f0de062012-03-20 17:18:17 -04001591 break;
Alex Deucherbcc7f5d2012-07-26 18:36:28 -04001592 case CHIP_OLAND:
1593 chip_name = "OLAND";
1594 rlc_chip_name = "OLAND";
1595 pfp_req_size = SI_PFP_UCODE_SIZE * 4;
1596 me_req_size = SI_PM4_UCODE_SIZE * 4;
1597 ce_req_size = SI_CE_UCODE_SIZE * 4;
1598 rlc_req_size = SI_RLC_UCODE_SIZE * 4;
1599 mc_req_size = OLAND_MC_UCODE_SIZE * 4;
Alex Deuchera9e61412013-06-25 17:56:16 -04001600 smc_req_size = ALIGN(OLAND_SMC_UCODE_SIZE, 4);
Alex Deucherbcc7f5d2012-07-26 18:36:28 -04001601 break;
Alex Deucherc04c00b2012-07-31 12:57:45 -04001602 case CHIP_HAINAN:
1603 chip_name = "HAINAN";
1604 rlc_chip_name = "HAINAN";
1605 pfp_req_size = SI_PFP_UCODE_SIZE * 4;
1606 me_req_size = SI_PM4_UCODE_SIZE * 4;
1607 ce_req_size = SI_CE_UCODE_SIZE * 4;
1608 rlc_req_size = SI_RLC_UCODE_SIZE * 4;
1609 mc_req_size = OLAND_MC_UCODE_SIZE * 4;
Alex Deuchera9e61412013-06-25 17:56:16 -04001610 smc_req_size = ALIGN(HAINAN_SMC_UCODE_SIZE, 4);
Alex Deucherc04c00b2012-07-31 12:57:45 -04001611 break;
Alex Deucher0f0de062012-03-20 17:18:17 -04001612 default: BUG();
1613 }
1614
1615 DRM_INFO("Loading %s Microcode\n", chip_name);
1616
1617 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001618 err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
Alex Deucher0f0de062012-03-20 17:18:17 -04001619 if (err)
1620 goto out;
1621 if (rdev->pfp_fw->size != pfp_req_size) {
1622 printk(KERN_ERR
1623 "si_cp: Bogus length %zu in firmware \"%s\"\n",
1624 rdev->pfp_fw->size, fw_name);
1625 err = -EINVAL;
1626 goto out;
1627 }
1628
1629 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001630 err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
Alex Deucher0f0de062012-03-20 17:18:17 -04001631 if (err)
1632 goto out;
1633 if (rdev->me_fw->size != me_req_size) {
1634 printk(KERN_ERR
1635 "si_cp: Bogus length %zu in firmware \"%s\"\n",
1636 rdev->me_fw->size, fw_name);
1637 err = -EINVAL;
1638 }
1639
1640 snprintf(fw_name, sizeof(fw_name), "radeon/%s_ce.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001641 err = request_firmware(&rdev->ce_fw, fw_name, rdev->dev);
Alex Deucher0f0de062012-03-20 17:18:17 -04001642 if (err)
1643 goto out;
1644 if (rdev->ce_fw->size != ce_req_size) {
1645 printk(KERN_ERR
1646 "si_cp: Bogus length %zu in firmware \"%s\"\n",
1647 rdev->ce_fw->size, fw_name);
1648 err = -EINVAL;
1649 }
1650
1651 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001652 err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
Alex Deucher0f0de062012-03-20 17:18:17 -04001653 if (err)
1654 goto out;
1655 if (rdev->rlc_fw->size != rlc_req_size) {
1656 printk(KERN_ERR
1657 "si_rlc: Bogus length %zu in firmware \"%s\"\n",
1658 rdev->rlc_fw->size, fw_name);
1659 err = -EINVAL;
1660 }
1661
1662 snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001663 err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
Alex Deucher0f0de062012-03-20 17:18:17 -04001664 if (err)
1665 goto out;
1666 if (rdev->mc_fw->size != mc_req_size) {
1667 printk(KERN_ERR
1668 "si_mc: Bogus length %zu in firmware \"%s\"\n",
1669 rdev->mc_fw->size, fw_name);
1670 err = -EINVAL;
1671 }
1672
Alex Deuchera9e61412013-06-25 17:56:16 -04001673 snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", chip_name);
Jerome Glisse0a168932013-07-11 15:53:01 -04001674 err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
Alex Deucher8a53fa22013-08-07 16:09:08 -04001675 if (err) {
1676 printk(KERN_ERR
1677 "smc: error loading firmware \"%s\"\n",
1678 fw_name);
1679 release_firmware(rdev->smc_fw);
1680 rdev->smc_fw = NULL;
Alex Deucherd8367112013-10-16 11:36:30 -04001681 err = 0;
Alex Deucher8a53fa22013-08-07 16:09:08 -04001682 } else if (rdev->smc_fw->size != smc_req_size) {
Alex Deuchera9e61412013-06-25 17:56:16 -04001683 printk(KERN_ERR
1684 "si_smc: Bogus length %zu in firmware \"%s\"\n",
1685 rdev->smc_fw->size, fw_name);
1686 err = -EINVAL;
1687 }
1688
Alex Deucher0f0de062012-03-20 17:18:17 -04001689out:
Alex Deucher0f0de062012-03-20 17:18:17 -04001690 if (err) {
1691 if (err != -EINVAL)
1692 printk(KERN_ERR
1693 "si_cp: Failed to load firmware \"%s\"\n",
1694 fw_name);
1695 release_firmware(rdev->pfp_fw);
1696 rdev->pfp_fw = NULL;
1697 release_firmware(rdev->me_fw);
1698 rdev->me_fw = NULL;
1699 release_firmware(rdev->ce_fw);
1700 rdev->ce_fw = NULL;
1701 release_firmware(rdev->rlc_fw);
1702 rdev->rlc_fw = NULL;
1703 release_firmware(rdev->mc_fw);
1704 rdev->mc_fw = NULL;
Alex Deuchera9e61412013-06-25 17:56:16 -04001705 release_firmware(rdev->smc_fw);
1706 rdev->smc_fw = NULL;
Alex Deucher0f0de062012-03-20 17:18:17 -04001707 }
1708 return err;
1709}
1710
Alex Deucher43b3cd92012-03-20 17:18:00 -04001711/* watermark setup */
1712static u32 dce6_line_buffer_adjust(struct radeon_device *rdev,
1713 struct radeon_crtc *radeon_crtc,
1714 struct drm_display_mode *mode,
1715 struct drm_display_mode *other_mode)
1716{
Alex Deucher290d2452013-08-19 11:15:43 -04001717 u32 tmp, buffer_alloc, i;
1718 u32 pipe_offset = radeon_crtc->crtc_id * 0x20;
Alex Deucher43b3cd92012-03-20 17:18:00 -04001719 /*
1720 * Line Buffer Setup
1721 * There are 3 line buffers, each one shared by 2 display controllers.
1722 * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
1723 * the display controllers. The paritioning is done via one of four
1724 * preset allocations specified in bits 21:20:
1725 * 0 - half lb
1726 * 2 - whole lb, other crtc must be disabled
1727 */
1728 /* this can get tricky if we have two large displays on a paired group
1729 * of crtcs. Ideally for multiple large displays we'd assign them to
1730 * non-linked crtcs for maximum line buffer allocation.
1731 */
1732 if (radeon_crtc->base.enabled && mode) {
Alex Deucher290d2452013-08-19 11:15:43 -04001733 if (other_mode) {
Alex Deucher43b3cd92012-03-20 17:18:00 -04001734 tmp = 0; /* 1/2 */
Alex Deucher290d2452013-08-19 11:15:43 -04001735 buffer_alloc = 1;
1736 } else {
Alex Deucher43b3cd92012-03-20 17:18:00 -04001737 tmp = 2; /* whole */
Alex Deucher290d2452013-08-19 11:15:43 -04001738 buffer_alloc = 2;
1739 }
1740 } else {
Alex Deucher43b3cd92012-03-20 17:18:00 -04001741 tmp = 0;
Alex Deucher290d2452013-08-19 11:15:43 -04001742 buffer_alloc = 0;
1743 }
Alex Deucher43b3cd92012-03-20 17:18:00 -04001744
1745 WREG32(DC_LB_MEMORY_SPLIT + radeon_crtc->crtc_offset,
1746 DC_LB_MEMORY_CONFIG(tmp));
1747
Alex Deucher290d2452013-08-19 11:15:43 -04001748 WREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
1749 DMIF_BUFFERS_ALLOCATED(buffer_alloc));
1750 for (i = 0; i < rdev->usec_timeout; i++) {
1751 if (RREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
1752 DMIF_BUFFERS_ALLOCATED_COMPLETED)
1753 break;
1754 udelay(1);
1755 }
1756
Alex Deucher43b3cd92012-03-20 17:18:00 -04001757 if (radeon_crtc->base.enabled && mode) {
1758 switch (tmp) {
1759 case 0:
1760 default:
1761 return 4096 * 2;
1762 case 2:
1763 return 8192 * 2;
1764 }
1765 }
1766
1767 /* controller not enabled, so no lb used */
1768 return 0;
1769}
1770
Alex Deucherca7db222012-03-20 17:18:30 -04001771static u32 si_get_number_of_dram_channels(struct radeon_device *rdev)
Alex Deucher43b3cd92012-03-20 17:18:00 -04001772{
1773 u32 tmp = RREG32(MC_SHARED_CHMAP);
1774
1775 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
1776 case 0:
1777 default:
1778 return 1;
1779 case 1:
1780 return 2;
1781 case 2:
1782 return 4;
1783 case 3:
1784 return 8;
1785 case 4:
1786 return 3;
1787 case 5:
1788 return 6;
1789 case 6:
1790 return 10;
1791 case 7:
1792 return 12;
1793 case 8:
1794 return 16;
1795 }
1796}
1797
1798struct dce6_wm_params {
1799 u32 dram_channels; /* number of dram channels */
1800 u32 yclk; /* bandwidth per dram data pin in kHz */
1801 u32 sclk; /* engine clock in kHz */
1802 u32 disp_clk; /* display clock in kHz */
1803 u32 src_width; /* viewport width */
1804 u32 active_time; /* active display time in ns */
1805 u32 blank_time; /* blank time in ns */
1806 bool interlaced; /* mode is interlaced */
1807 fixed20_12 vsc; /* vertical scale ratio */
1808 u32 num_heads; /* number of active crtcs */
1809 u32 bytes_per_pixel; /* bytes per pixel display + overlay */
1810 u32 lb_size; /* line buffer allocated to pipe */
1811 u32 vtaps; /* vertical scaler taps */
1812};
1813
1814static u32 dce6_dram_bandwidth(struct dce6_wm_params *wm)
1815{
1816 /* Calculate raw DRAM Bandwidth */
1817 fixed20_12 dram_efficiency; /* 0.7 */
1818 fixed20_12 yclk, dram_channels, bandwidth;
1819 fixed20_12 a;
1820
1821 a.full = dfixed_const(1000);
1822 yclk.full = dfixed_const(wm->yclk);
1823 yclk.full = dfixed_div(yclk, a);
1824 dram_channels.full = dfixed_const(wm->dram_channels * 4);
1825 a.full = dfixed_const(10);
1826 dram_efficiency.full = dfixed_const(7);
1827 dram_efficiency.full = dfixed_div(dram_efficiency, a);
1828 bandwidth.full = dfixed_mul(dram_channels, yclk);
1829 bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
1830
1831 return dfixed_trunc(bandwidth);
1832}
1833
1834static u32 dce6_dram_bandwidth_for_display(struct dce6_wm_params *wm)
1835{
1836 /* Calculate DRAM Bandwidth and the part allocated to display. */
1837 fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
1838 fixed20_12 yclk, dram_channels, bandwidth;
1839 fixed20_12 a;
1840
1841 a.full = dfixed_const(1000);
1842 yclk.full = dfixed_const(wm->yclk);
1843 yclk.full = dfixed_div(yclk, a);
1844 dram_channels.full = dfixed_const(wm->dram_channels * 4);
1845 a.full = dfixed_const(10);
1846 disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
1847 disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
1848 bandwidth.full = dfixed_mul(dram_channels, yclk);
1849 bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
1850
1851 return dfixed_trunc(bandwidth);
1852}
1853
1854static u32 dce6_data_return_bandwidth(struct dce6_wm_params *wm)
1855{
1856 /* Calculate the display Data return Bandwidth */
1857 fixed20_12 return_efficiency; /* 0.8 */
1858 fixed20_12 sclk, bandwidth;
1859 fixed20_12 a;
1860
1861 a.full = dfixed_const(1000);
1862 sclk.full = dfixed_const(wm->sclk);
1863 sclk.full = dfixed_div(sclk, a);
1864 a.full = dfixed_const(10);
1865 return_efficiency.full = dfixed_const(8);
1866 return_efficiency.full = dfixed_div(return_efficiency, a);
1867 a.full = dfixed_const(32);
1868 bandwidth.full = dfixed_mul(a, sclk);
1869 bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
1870
1871 return dfixed_trunc(bandwidth);
1872}
1873
1874static u32 dce6_get_dmif_bytes_per_request(struct dce6_wm_params *wm)
1875{
1876 return 32;
1877}
1878
1879static u32 dce6_dmif_request_bandwidth(struct dce6_wm_params *wm)
1880{
1881 /* Calculate the DMIF Request Bandwidth */
1882 fixed20_12 disp_clk_request_efficiency; /* 0.8 */
1883 fixed20_12 disp_clk, sclk, bandwidth;
1884 fixed20_12 a, b1, b2;
1885 u32 min_bandwidth;
1886
1887 a.full = dfixed_const(1000);
1888 disp_clk.full = dfixed_const(wm->disp_clk);
1889 disp_clk.full = dfixed_div(disp_clk, a);
1890 a.full = dfixed_const(dce6_get_dmif_bytes_per_request(wm) / 2);
1891 b1.full = dfixed_mul(a, disp_clk);
1892
1893 a.full = dfixed_const(1000);
1894 sclk.full = dfixed_const(wm->sclk);
1895 sclk.full = dfixed_div(sclk, a);
1896 a.full = dfixed_const(dce6_get_dmif_bytes_per_request(wm));
1897 b2.full = dfixed_mul(a, sclk);
1898
1899 a.full = dfixed_const(10);
1900 disp_clk_request_efficiency.full = dfixed_const(8);
1901 disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
1902
1903 min_bandwidth = min(dfixed_trunc(b1), dfixed_trunc(b2));
1904
1905 a.full = dfixed_const(min_bandwidth);
1906 bandwidth.full = dfixed_mul(a, disp_clk_request_efficiency);
1907
1908 return dfixed_trunc(bandwidth);
1909}
1910
1911static u32 dce6_available_bandwidth(struct dce6_wm_params *wm)
1912{
1913 /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
1914 u32 dram_bandwidth = dce6_dram_bandwidth(wm);
1915 u32 data_return_bandwidth = dce6_data_return_bandwidth(wm);
1916 u32 dmif_req_bandwidth = dce6_dmif_request_bandwidth(wm);
1917
1918 return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
1919}
1920
1921static u32 dce6_average_bandwidth(struct dce6_wm_params *wm)
1922{
1923 /* Calculate the display mode Average Bandwidth
1924 * DisplayMode should contain the source and destination dimensions,
1925 * timing, etc.
1926 */
1927 fixed20_12 bpp;
1928 fixed20_12 line_time;
1929 fixed20_12 src_width;
1930 fixed20_12 bandwidth;
1931 fixed20_12 a;
1932
1933 a.full = dfixed_const(1000);
1934 line_time.full = dfixed_const(wm->active_time + wm->blank_time);
1935 line_time.full = dfixed_div(line_time, a);
1936 bpp.full = dfixed_const(wm->bytes_per_pixel);
1937 src_width.full = dfixed_const(wm->src_width);
1938 bandwidth.full = dfixed_mul(src_width, bpp);
1939 bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
1940 bandwidth.full = dfixed_div(bandwidth, line_time);
1941
1942 return dfixed_trunc(bandwidth);
1943}
1944
1945static u32 dce6_latency_watermark(struct dce6_wm_params *wm)
1946{
1947 /* First calcualte the latency in ns */
1948 u32 mc_latency = 2000; /* 2000 ns. */
1949 u32 available_bandwidth = dce6_available_bandwidth(wm);
1950 u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
1951 u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
1952 u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
1953 u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
1954 (wm->num_heads * cursor_line_pair_return_time);
1955 u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
1956 u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
1957 u32 tmp, dmif_size = 12288;
1958 fixed20_12 a, b, c;
1959
1960 if (wm->num_heads == 0)
1961 return 0;
1962
1963 a.full = dfixed_const(2);
1964 b.full = dfixed_const(1);
1965 if ((wm->vsc.full > a.full) ||
1966 ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
1967 (wm->vtaps >= 5) ||
1968 ((wm->vsc.full >= a.full) && wm->interlaced))
1969 max_src_lines_per_dst_line = 4;
1970 else
1971 max_src_lines_per_dst_line = 2;
1972
1973 a.full = dfixed_const(available_bandwidth);
1974 b.full = dfixed_const(wm->num_heads);
1975 a.full = dfixed_div(a, b);
1976
1977 b.full = dfixed_const(mc_latency + 512);
1978 c.full = dfixed_const(wm->disp_clk);
1979 b.full = dfixed_div(b, c);
1980
1981 c.full = dfixed_const(dmif_size);
1982 b.full = dfixed_div(c, b);
1983
1984 tmp = min(dfixed_trunc(a), dfixed_trunc(b));
1985
1986 b.full = dfixed_const(1000);
1987 c.full = dfixed_const(wm->disp_clk);
1988 b.full = dfixed_div(c, b);
1989 c.full = dfixed_const(wm->bytes_per_pixel);
1990 b.full = dfixed_mul(b, c);
1991
1992 lb_fill_bw = min(tmp, dfixed_trunc(b));
1993
1994 a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
1995 b.full = dfixed_const(1000);
1996 c.full = dfixed_const(lb_fill_bw);
1997 b.full = dfixed_div(c, b);
1998 a.full = dfixed_div(a, b);
1999 line_fill_time = dfixed_trunc(a);
2000
2001 if (line_fill_time < wm->active_time)
2002 return latency;
2003 else
2004 return latency + (line_fill_time - wm->active_time);
2005
2006}
2007
2008static bool dce6_average_bandwidth_vs_dram_bandwidth_for_display(struct dce6_wm_params *wm)
2009{
2010 if (dce6_average_bandwidth(wm) <=
2011 (dce6_dram_bandwidth_for_display(wm) / wm->num_heads))
2012 return true;
2013 else
2014 return false;
2015};
2016
2017static bool dce6_average_bandwidth_vs_available_bandwidth(struct dce6_wm_params *wm)
2018{
2019 if (dce6_average_bandwidth(wm) <=
2020 (dce6_available_bandwidth(wm) / wm->num_heads))
2021 return true;
2022 else
2023 return false;
2024};
2025
2026static bool dce6_check_latency_hiding(struct dce6_wm_params *wm)
2027{
2028 u32 lb_partitions = wm->lb_size / wm->src_width;
2029 u32 line_time = wm->active_time + wm->blank_time;
2030 u32 latency_tolerant_lines;
2031 u32 latency_hiding;
2032 fixed20_12 a;
2033
2034 a.full = dfixed_const(1);
2035 if (wm->vsc.full > a.full)
2036 latency_tolerant_lines = 1;
2037 else {
2038 if (lb_partitions <= (wm->vtaps + 1))
2039 latency_tolerant_lines = 1;
2040 else
2041 latency_tolerant_lines = 2;
2042 }
2043
2044 latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
2045
2046 if (dce6_latency_watermark(wm) <= latency_hiding)
2047 return true;
2048 else
2049 return false;
2050}
2051
2052static void dce6_program_watermarks(struct radeon_device *rdev,
2053 struct radeon_crtc *radeon_crtc,
2054 u32 lb_size, u32 num_heads)
2055{
2056 struct drm_display_mode *mode = &radeon_crtc->base.mode;
Alex Deucherc696e532012-05-03 10:43:25 -04002057 struct dce6_wm_params wm_low, wm_high;
2058 u32 dram_channels;
Alex Deucher43b3cd92012-03-20 17:18:00 -04002059 u32 pixel_period;
2060 u32 line_time = 0;
2061 u32 latency_watermark_a = 0, latency_watermark_b = 0;
2062 u32 priority_a_mark = 0, priority_b_mark = 0;
2063 u32 priority_a_cnt = PRIORITY_OFF;
2064 u32 priority_b_cnt = PRIORITY_OFF;
2065 u32 tmp, arb_control3;
2066 fixed20_12 a, b, c;
2067
2068 if (radeon_crtc->base.enabled && num_heads && mode) {
2069 pixel_period = 1000000 / (u32)mode->clock;
2070 line_time = min((u32)mode->crtc_htotal * pixel_period, (u32)65535);
2071 priority_a_cnt = 0;
2072 priority_b_cnt = 0;
2073
Alex Deucherca7db222012-03-20 17:18:30 -04002074 if (rdev->family == CHIP_ARUBA)
Alex Deucherc696e532012-05-03 10:43:25 -04002075 dram_channels = evergreen_get_number_of_dram_channels(rdev);
Alex Deucherca7db222012-03-20 17:18:30 -04002076 else
Alex Deucherc696e532012-05-03 10:43:25 -04002077 dram_channels = si_get_number_of_dram_channels(rdev);
2078
2079 /* watermark for high clocks */
2080 if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
2081 wm_high.yclk =
2082 radeon_dpm_get_mclk(rdev, false) * 10;
2083 wm_high.sclk =
2084 radeon_dpm_get_sclk(rdev, false) * 10;
2085 } else {
2086 wm_high.yclk = rdev->pm.current_mclk * 10;
2087 wm_high.sclk = rdev->pm.current_sclk * 10;
2088 }
2089
2090 wm_high.disp_clk = mode->clock;
2091 wm_high.src_width = mode->crtc_hdisplay;
2092 wm_high.active_time = mode->crtc_hdisplay * pixel_period;
2093 wm_high.blank_time = line_time - wm_high.active_time;
2094 wm_high.interlaced = false;
2095 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
2096 wm_high.interlaced = true;
2097 wm_high.vsc = radeon_crtc->vsc;
2098 wm_high.vtaps = 1;
2099 if (radeon_crtc->rmx_type != RMX_OFF)
2100 wm_high.vtaps = 2;
2101 wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
2102 wm_high.lb_size = lb_size;
2103 wm_high.dram_channels = dram_channels;
2104 wm_high.num_heads = num_heads;
2105
2106 /* watermark for low clocks */
2107 if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
2108 wm_low.yclk =
2109 radeon_dpm_get_mclk(rdev, true) * 10;
2110 wm_low.sclk =
2111 radeon_dpm_get_sclk(rdev, true) * 10;
2112 } else {
2113 wm_low.yclk = rdev->pm.current_mclk * 10;
2114 wm_low.sclk = rdev->pm.current_sclk * 10;
2115 }
2116
2117 wm_low.disp_clk = mode->clock;
2118 wm_low.src_width = mode->crtc_hdisplay;
2119 wm_low.active_time = mode->crtc_hdisplay * pixel_period;
2120 wm_low.blank_time = line_time - wm_low.active_time;
2121 wm_low.interlaced = false;
2122 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
2123 wm_low.interlaced = true;
2124 wm_low.vsc = radeon_crtc->vsc;
2125 wm_low.vtaps = 1;
2126 if (radeon_crtc->rmx_type != RMX_OFF)
2127 wm_low.vtaps = 2;
2128 wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
2129 wm_low.lb_size = lb_size;
2130 wm_low.dram_channels = dram_channels;
2131 wm_low.num_heads = num_heads;
Alex Deucher43b3cd92012-03-20 17:18:00 -04002132
2133 /* set for high clocks */
Alex Deucherc696e532012-05-03 10:43:25 -04002134 latency_watermark_a = min(dce6_latency_watermark(&wm_high), (u32)65535);
Alex Deucher43b3cd92012-03-20 17:18:00 -04002135 /* set for low clocks */
Alex Deucherc696e532012-05-03 10:43:25 -04002136 latency_watermark_b = min(dce6_latency_watermark(&wm_low), (u32)65535);
Alex Deucher43b3cd92012-03-20 17:18:00 -04002137
2138 /* possibly force display priority to high */
2139 /* should really do this at mode validation time... */
Alex Deucherc696e532012-05-03 10:43:25 -04002140 if (!dce6_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
2141 !dce6_average_bandwidth_vs_available_bandwidth(&wm_high) ||
2142 !dce6_check_latency_hiding(&wm_high) ||
2143 (rdev->disp_priority == 2)) {
2144 DRM_DEBUG_KMS("force priority to high\n");
2145 priority_a_cnt |= PRIORITY_ALWAYS_ON;
2146 priority_b_cnt |= PRIORITY_ALWAYS_ON;
2147 }
2148 if (!dce6_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
2149 !dce6_average_bandwidth_vs_available_bandwidth(&wm_low) ||
2150 !dce6_check_latency_hiding(&wm_low) ||
Alex Deucher43b3cd92012-03-20 17:18:00 -04002151 (rdev->disp_priority == 2)) {
2152 DRM_DEBUG_KMS("force priority to high\n");
2153 priority_a_cnt |= PRIORITY_ALWAYS_ON;
2154 priority_b_cnt |= PRIORITY_ALWAYS_ON;
2155 }
2156
2157 a.full = dfixed_const(1000);
2158 b.full = dfixed_const(mode->clock);
2159 b.full = dfixed_div(b, a);
2160 c.full = dfixed_const(latency_watermark_a);
2161 c.full = dfixed_mul(c, b);
2162 c.full = dfixed_mul(c, radeon_crtc->hsc);
2163 c.full = dfixed_div(c, a);
2164 a.full = dfixed_const(16);
2165 c.full = dfixed_div(c, a);
2166 priority_a_mark = dfixed_trunc(c);
2167 priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
2168
2169 a.full = dfixed_const(1000);
2170 b.full = dfixed_const(mode->clock);
2171 b.full = dfixed_div(b, a);
2172 c.full = dfixed_const(latency_watermark_b);
2173 c.full = dfixed_mul(c, b);
2174 c.full = dfixed_mul(c, radeon_crtc->hsc);
2175 c.full = dfixed_div(c, a);
2176 a.full = dfixed_const(16);
2177 c.full = dfixed_div(c, a);
2178 priority_b_mark = dfixed_trunc(c);
2179 priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
2180 }
2181
2182 /* select wm A */
2183 arb_control3 = RREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset);
2184 tmp = arb_control3;
2185 tmp &= ~LATENCY_WATERMARK_MASK(3);
2186 tmp |= LATENCY_WATERMARK_MASK(1);
2187 WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, tmp);
2188 WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
2189 (LATENCY_LOW_WATERMARK(latency_watermark_a) |
2190 LATENCY_HIGH_WATERMARK(line_time)));
2191 /* select wm B */
2192 tmp = RREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset);
2193 tmp &= ~LATENCY_WATERMARK_MASK(3);
2194 tmp |= LATENCY_WATERMARK_MASK(2);
2195 WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, tmp);
2196 WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
2197 (LATENCY_LOW_WATERMARK(latency_watermark_b) |
2198 LATENCY_HIGH_WATERMARK(line_time)));
2199 /* restore original selection */
2200 WREG32(DPG_PIPE_ARBITRATION_CONTROL3 + radeon_crtc->crtc_offset, arb_control3);
2201
2202 /* write the priority marks */
2203 WREG32(PRIORITY_A_CNT + radeon_crtc->crtc_offset, priority_a_cnt);
2204 WREG32(PRIORITY_B_CNT + radeon_crtc->crtc_offset, priority_b_cnt);
2205
Alex Deucher7178d2a2013-03-21 10:38:49 -04002206 /* save values for DPM */
2207 radeon_crtc->line_time = line_time;
2208 radeon_crtc->wm_high = latency_watermark_a;
2209 radeon_crtc->wm_low = latency_watermark_b;
Alex Deucher43b3cd92012-03-20 17:18:00 -04002210}
2211
2212void dce6_bandwidth_update(struct radeon_device *rdev)
2213{
2214 struct drm_display_mode *mode0 = NULL;
2215 struct drm_display_mode *mode1 = NULL;
2216 u32 num_heads = 0, lb_size;
2217 int i;
2218
2219 radeon_update_display_priority(rdev);
2220
2221 for (i = 0; i < rdev->num_crtc; i++) {
2222 if (rdev->mode_info.crtcs[i]->base.enabled)
2223 num_heads++;
2224 }
2225 for (i = 0; i < rdev->num_crtc; i += 2) {
2226 mode0 = &rdev->mode_info.crtcs[i]->base.mode;
2227 mode1 = &rdev->mode_info.crtcs[i+1]->base.mode;
2228 lb_size = dce6_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode0, mode1);
2229 dce6_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
2230 lb_size = dce6_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i+1], mode1, mode0);
2231 dce6_program_watermarks(rdev, rdev->mode_info.crtcs[i+1], lb_size, num_heads);
2232 }
2233}
2234
Alex Deucher0a96d722012-03-20 17:18:11 -04002235/*
2236 * Core functions
2237 */
Alex Deucher0a96d722012-03-20 17:18:11 -04002238static void si_tiling_mode_table_init(struct radeon_device *rdev)
2239{
2240 const u32 num_tile_mode_states = 32;
2241 u32 reg_offset, gb_tile_moden, split_equal_to_row_size;
2242
2243 switch (rdev->config.si.mem_row_size_in_kb) {
2244 case 1:
2245 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_1KB;
2246 break;
2247 case 2:
2248 default:
2249 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_2KB;
2250 break;
2251 case 4:
2252 split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_4KB;
2253 break;
2254 }
2255
2256 if ((rdev->family == CHIP_TAHITI) ||
2257 (rdev->family == CHIP_PITCAIRN)) {
2258 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
2259 switch (reg_offset) {
2260 case 0: /* non-AA compressed depth or any compressed stencil */
2261 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2262 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2263 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2264 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2265 NUM_BANKS(ADDR_SURF_16_BANK) |
2266 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2267 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2268 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2269 break;
2270 case 1: /* 2xAA/4xAA compressed depth only */
2271 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2272 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2273 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2274 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2275 NUM_BANKS(ADDR_SURF_16_BANK) |
2276 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2277 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2278 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2279 break;
2280 case 2: /* 8xAA compressed depth only */
2281 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2282 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2283 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2284 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2285 NUM_BANKS(ADDR_SURF_16_BANK) |
2286 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2287 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2288 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2289 break;
2290 case 3: /* 2xAA/4xAA compressed depth with stencil (for depth buffer) */
2291 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2292 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2293 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2294 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2295 NUM_BANKS(ADDR_SURF_16_BANK) |
2296 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2297 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2298 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2299 break;
2300 case 4: /* Maps w/ a dimension less than the 2D macro-tile dimensions (for mipmapped depth textures) */
2301 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2302 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2303 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2304 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2305 NUM_BANKS(ADDR_SURF_16_BANK) |
2306 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2307 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2308 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2309 break;
2310 case 5: /* Uncompressed 16bpp depth - and stencil buffer allocated with it */
2311 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2312 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2313 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2314 TILE_SPLIT(split_equal_to_row_size) |
2315 NUM_BANKS(ADDR_SURF_16_BANK) |
2316 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2317 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2318 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2319 break;
2320 case 6: /* Uncompressed 32bpp depth - and stencil buffer allocated with it */
2321 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2322 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2323 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2324 TILE_SPLIT(split_equal_to_row_size) |
2325 NUM_BANKS(ADDR_SURF_16_BANK) |
2326 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2327 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2328 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
2329 break;
2330 case 7: /* Uncompressed 8bpp stencil without depth (drivers typically do not use) */
2331 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2332 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2333 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2334 TILE_SPLIT(split_equal_to_row_size) |
2335 NUM_BANKS(ADDR_SURF_16_BANK) |
2336 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2337 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2338 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2339 break;
2340 case 8: /* 1D and 1D Array Surfaces */
2341 gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2342 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2343 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2344 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2345 NUM_BANKS(ADDR_SURF_16_BANK) |
2346 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2347 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2348 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2349 break;
2350 case 9: /* Displayable maps. */
2351 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2352 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2353 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2354 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2355 NUM_BANKS(ADDR_SURF_16_BANK) |
2356 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2357 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2358 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2359 break;
2360 case 10: /* Display 8bpp. */
2361 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2362 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2363 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2364 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2365 NUM_BANKS(ADDR_SURF_16_BANK) |
2366 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2367 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2368 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2369 break;
2370 case 11: /* Display 16bpp. */
2371 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2372 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2373 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2374 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2375 NUM_BANKS(ADDR_SURF_16_BANK) |
2376 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2377 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2378 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2379 break;
2380 case 12: /* Display 32bpp. */
2381 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2382 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2383 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2384 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2385 NUM_BANKS(ADDR_SURF_16_BANK) |
2386 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2387 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2388 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
2389 break;
2390 case 13: /* Thin. */
2391 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2392 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2393 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2394 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2395 NUM_BANKS(ADDR_SURF_16_BANK) |
2396 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2397 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2398 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2399 break;
2400 case 14: /* Thin 8 bpp. */
2401 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2402 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2403 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2404 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2405 NUM_BANKS(ADDR_SURF_16_BANK) |
2406 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2407 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2408 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
2409 break;
2410 case 15: /* Thin 16 bpp. */
2411 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2412 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2413 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2414 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2415 NUM_BANKS(ADDR_SURF_16_BANK) |
2416 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2417 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2418 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
2419 break;
2420 case 16: /* Thin 32 bpp. */
2421 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2422 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2423 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2424 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2425 NUM_BANKS(ADDR_SURF_16_BANK) |
2426 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2427 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2428 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
2429 break;
2430 case 17: /* Thin 64 bpp. */
2431 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2432 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2433 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2434 TILE_SPLIT(split_equal_to_row_size) |
2435 NUM_BANKS(ADDR_SURF_16_BANK) |
2436 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2437 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2438 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
2439 break;
2440 case 21: /* 8 bpp PRT. */
2441 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2442 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2443 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2444 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2445 NUM_BANKS(ADDR_SURF_16_BANK) |
2446 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2447 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2448 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2449 break;
2450 case 22: /* 16 bpp PRT */
2451 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2452 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2453 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2454 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2455 NUM_BANKS(ADDR_SURF_16_BANK) |
2456 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2457 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2458 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
2459 break;
2460 case 23: /* 32 bpp PRT */
2461 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2462 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2463 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2464 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2465 NUM_BANKS(ADDR_SURF_16_BANK) |
2466 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2467 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2468 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2469 break;
2470 case 24: /* 64 bpp PRT */
2471 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2472 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2473 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2474 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2475 NUM_BANKS(ADDR_SURF_16_BANK) |
2476 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2477 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2478 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2479 break;
2480 case 25: /* 128 bpp PRT */
2481 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2482 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2483 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2484 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_1KB) |
2485 NUM_BANKS(ADDR_SURF_8_BANK) |
2486 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2487 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2488 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
2489 break;
2490 default:
2491 gb_tile_moden = 0;
2492 break;
2493 }
Jerome Glisse64d7b8b2013-04-09 11:17:08 -04002494 rdev->config.si.tile_mode_array[reg_offset] = gb_tile_moden;
Alex Deucher0a96d722012-03-20 17:18:11 -04002495 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2496 }
Alex Deucherd0ae7fc2012-07-26 17:42:25 -04002497 } else if ((rdev->family == CHIP_VERDE) ||
Alex Deucher8b028592012-07-31 12:42:48 -04002498 (rdev->family == CHIP_OLAND) ||
2499 (rdev->family == CHIP_HAINAN)) {
Alex Deucher0a96d722012-03-20 17:18:11 -04002500 for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++) {
2501 switch (reg_offset) {
2502 case 0: /* non-AA compressed depth or any compressed stencil */
2503 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2504 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2505 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2506 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2507 NUM_BANKS(ADDR_SURF_16_BANK) |
2508 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2509 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2510 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
2511 break;
2512 case 1: /* 2xAA/4xAA compressed depth only */
2513 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2514 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2515 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2516 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2517 NUM_BANKS(ADDR_SURF_16_BANK) |
2518 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2519 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2520 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
2521 break;
2522 case 2: /* 8xAA compressed depth only */
2523 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2524 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2525 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2526 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2527 NUM_BANKS(ADDR_SURF_16_BANK) |
2528 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2529 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2530 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
2531 break;
2532 case 3: /* 2xAA/4xAA compressed depth with stencil (for depth buffer) */
2533 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2534 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2535 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2536 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2537 NUM_BANKS(ADDR_SURF_16_BANK) |
2538 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2539 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2540 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
2541 break;
2542 case 4: /* Maps w/ a dimension less than the 2D macro-tile dimensions (for mipmapped depth textures) */
2543 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2544 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2545 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2546 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2547 NUM_BANKS(ADDR_SURF_16_BANK) |
2548 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2549 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2550 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2551 break;
2552 case 5: /* Uncompressed 16bpp depth - and stencil buffer allocated with it */
2553 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2554 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2555 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2556 TILE_SPLIT(split_equal_to_row_size) |
2557 NUM_BANKS(ADDR_SURF_16_BANK) |
2558 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2559 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2560 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2561 break;
2562 case 6: /* Uncompressed 32bpp depth - and stencil buffer allocated with it */
2563 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2564 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2565 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2566 TILE_SPLIT(split_equal_to_row_size) |
2567 NUM_BANKS(ADDR_SURF_16_BANK) |
2568 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2569 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2570 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2571 break;
2572 case 7: /* Uncompressed 8bpp stencil without depth (drivers typically do not use) */
2573 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2574 MICRO_TILE_MODE(ADDR_SURF_DEPTH_MICRO_TILING) |
2575 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2576 TILE_SPLIT(split_equal_to_row_size) |
2577 NUM_BANKS(ADDR_SURF_16_BANK) |
2578 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2579 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2580 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
2581 break;
2582 case 8: /* 1D and 1D Array Surfaces */
2583 gb_tile_moden = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2584 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2585 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2586 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2587 NUM_BANKS(ADDR_SURF_16_BANK) |
2588 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2589 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2590 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2591 break;
2592 case 9: /* Displayable maps. */
2593 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2594 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2595 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2596 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2597 NUM_BANKS(ADDR_SURF_16_BANK) |
2598 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2599 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2600 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2601 break;
2602 case 10: /* Display 8bpp. */
2603 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2604 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2605 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2606 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2607 NUM_BANKS(ADDR_SURF_16_BANK) |
2608 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2609 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2610 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
2611 break;
2612 case 11: /* Display 16bpp. */
2613 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2614 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2615 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2616 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2617 NUM_BANKS(ADDR_SURF_16_BANK) |
2618 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2619 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2620 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2621 break;
2622 case 12: /* Display 32bpp. */
2623 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2624 MICRO_TILE_MODE(ADDR_SURF_DISPLAY_MICRO_TILING) |
2625 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2626 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2627 NUM_BANKS(ADDR_SURF_16_BANK) |
2628 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2629 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2630 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2631 break;
2632 case 13: /* Thin. */
2633 gb_tile_moden = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2634 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2635 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2636 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2637 NUM_BANKS(ADDR_SURF_16_BANK) |
2638 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2639 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2640 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2641 break;
2642 case 14: /* Thin 8 bpp. */
2643 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2644 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2645 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2646 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2647 NUM_BANKS(ADDR_SURF_16_BANK) |
2648 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2649 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2650 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2651 break;
2652 case 15: /* Thin 16 bpp. */
2653 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2654 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2655 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2656 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2657 NUM_BANKS(ADDR_SURF_16_BANK) |
2658 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2659 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2660 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2661 break;
2662 case 16: /* Thin 32 bpp. */
2663 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2664 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2665 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2666 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2667 NUM_BANKS(ADDR_SURF_16_BANK) |
2668 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2669 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2670 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2671 break;
2672 case 17: /* Thin 64 bpp. */
2673 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2674 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2675 PIPE_CONFIG(ADDR_SURF_P4_8x16) |
2676 TILE_SPLIT(split_equal_to_row_size) |
2677 NUM_BANKS(ADDR_SURF_16_BANK) |
2678 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2679 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2680 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2681 break;
2682 case 21: /* 8 bpp PRT. */
2683 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2684 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2685 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2686 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2687 NUM_BANKS(ADDR_SURF_16_BANK) |
2688 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2689 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2690 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2691 break;
2692 case 22: /* 16 bpp PRT */
2693 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2694 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2695 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2696 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2697 NUM_BANKS(ADDR_SURF_16_BANK) |
2698 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2699 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2700 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4));
2701 break;
2702 case 23: /* 32 bpp PRT */
2703 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2704 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2705 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2706 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2707 NUM_BANKS(ADDR_SURF_16_BANK) |
2708 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2709 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2710 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2711 break;
2712 case 24: /* 64 bpp PRT */
2713 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2714 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2715 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2716 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2717 NUM_BANKS(ADDR_SURF_16_BANK) |
2718 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2719 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2720 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2));
2721 break;
2722 case 25: /* 128 bpp PRT */
2723 gb_tile_moden = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2724 MICRO_TILE_MODE(ADDR_SURF_THIN_MICRO_TILING) |
2725 PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
2726 TILE_SPLIT(ADDR_SURF_TILE_SPLIT_1KB) |
2727 NUM_BANKS(ADDR_SURF_8_BANK) |
2728 BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2729 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2730 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1));
2731 break;
2732 default:
2733 gb_tile_moden = 0;
2734 break;
2735 }
Jerome Glisse64d7b8b2013-04-09 11:17:08 -04002736 rdev->config.si.tile_mode_array[reg_offset] = gb_tile_moden;
Alex Deucher0a96d722012-03-20 17:18:11 -04002737 WREG32(GB_TILE_MODE0 + (reg_offset * 4), gb_tile_moden);
2738 }
2739 } else
2740 DRM_ERROR("unknown asic: 0x%x\n", rdev->family);
2741}
2742
Alex Deucher1a8ca752012-06-01 18:58:22 -04002743static void si_select_se_sh(struct radeon_device *rdev,
2744 u32 se_num, u32 sh_num)
2745{
2746 u32 data = INSTANCE_BROADCAST_WRITES;
2747
2748 if ((se_num == 0xffffffff) && (sh_num == 0xffffffff))
Alex Deucher79b52d62013-04-18 16:26:36 -04002749 data |= SH_BROADCAST_WRITES | SE_BROADCAST_WRITES;
Alex Deucher1a8ca752012-06-01 18:58:22 -04002750 else if (se_num == 0xffffffff)
2751 data |= SE_BROADCAST_WRITES | SH_INDEX(sh_num);
2752 else if (sh_num == 0xffffffff)
2753 data |= SH_BROADCAST_WRITES | SE_INDEX(se_num);
2754 else
2755 data |= SH_INDEX(sh_num) | SE_INDEX(se_num);
2756 WREG32(GRBM_GFX_INDEX, data);
2757}
2758
2759static u32 si_create_bitmask(u32 bit_width)
2760{
2761 u32 i, mask = 0;
2762
2763 for (i = 0; i < bit_width; i++) {
2764 mask <<= 1;
2765 mask |= 1;
2766 }
2767 return mask;
2768}
2769
2770static u32 si_get_cu_enabled(struct radeon_device *rdev, u32 cu_per_sh)
2771{
2772 u32 data, mask;
2773
2774 data = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
2775 if (data & 1)
2776 data &= INACTIVE_CUS_MASK;
2777 else
2778 data = 0;
2779 data |= RREG32(GC_USER_SHADER_ARRAY_CONFIG);
2780
2781 data >>= INACTIVE_CUS_SHIFT;
2782
2783 mask = si_create_bitmask(cu_per_sh);
2784
2785 return ~data & mask;
2786}
2787
2788static void si_setup_spi(struct radeon_device *rdev,
2789 u32 se_num, u32 sh_per_se,
2790 u32 cu_per_sh)
2791{
2792 int i, j, k;
2793 u32 data, mask, active_cu;
2794
2795 for (i = 0; i < se_num; i++) {
2796 for (j = 0; j < sh_per_se; j++) {
2797 si_select_se_sh(rdev, i, j);
2798 data = RREG32(SPI_STATIC_THREAD_MGMT_3);
2799 active_cu = si_get_cu_enabled(rdev, cu_per_sh);
2800
2801 mask = 1;
2802 for (k = 0; k < 16; k++) {
2803 mask <<= k;
2804 if (active_cu & mask) {
2805 data &= ~mask;
2806 WREG32(SPI_STATIC_THREAD_MGMT_3, data);
2807 break;
2808 }
2809 }
2810 }
2811 }
2812 si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
2813}
2814
2815static u32 si_get_rb_disabled(struct radeon_device *rdev,
2816 u32 max_rb_num, u32 se_num,
2817 u32 sh_per_se)
2818{
2819 u32 data, mask;
2820
2821 data = RREG32(CC_RB_BACKEND_DISABLE);
2822 if (data & 1)
2823 data &= BACKEND_DISABLE_MASK;
2824 else
2825 data = 0;
2826 data |= RREG32(GC_USER_RB_BACKEND_DISABLE);
2827
2828 data >>= BACKEND_DISABLE_SHIFT;
2829
2830 mask = si_create_bitmask(max_rb_num / se_num / sh_per_se);
2831
2832 return data & mask;
2833}
2834
2835static void si_setup_rb(struct radeon_device *rdev,
2836 u32 se_num, u32 sh_per_se,
2837 u32 max_rb_num)
2838{
2839 int i, j;
2840 u32 data, mask;
2841 u32 disabled_rbs = 0;
2842 u32 enabled_rbs = 0;
2843
2844 for (i = 0; i < se_num; i++) {
2845 for (j = 0; j < sh_per_se; j++) {
2846 si_select_se_sh(rdev, i, j);
2847 data = si_get_rb_disabled(rdev, max_rb_num, se_num, sh_per_se);
2848 disabled_rbs |= data << ((i * sh_per_se + j) * TAHITI_RB_BITMAP_WIDTH_PER_SH);
2849 }
2850 }
2851 si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
2852
2853 mask = 1;
2854 for (i = 0; i < max_rb_num; i++) {
2855 if (!(disabled_rbs & mask))
2856 enabled_rbs |= mask;
2857 mask <<= 1;
2858 }
2859
2860 for (i = 0; i < se_num; i++) {
2861 si_select_se_sh(rdev, i, 0xffffffff);
2862 data = 0;
2863 for (j = 0; j < sh_per_se; j++) {
2864 switch (enabled_rbs & 3) {
2865 case 1:
2866 data |= (RASTER_CONFIG_RB_MAP_0 << (i * sh_per_se + j) * 2);
2867 break;
2868 case 2:
2869 data |= (RASTER_CONFIG_RB_MAP_3 << (i * sh_per_se + j) * 2);
2870 break;
2871 case 3:
2872 default:
2873 data |= (RASTER_CONFIG_RB_MAP_2 << (i * sh_per_se + j) * 2);
2874 break;
2875 }
2876 enabled_rbs >>= 2;
2877 }
2878 WREG32(PA_SC_RASTER_CONFIG, data);
2879 }
2880 si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
2881}
2882
Alex Deucher0a96d722012-03-20 17:18:11 -04002883static void si_gpu_init(struct radeon_device *rdev)
2884{
Alex Deucher0a96d722012-03-20 17:18:11 -04002885 u32 gb_addr_config = 0;
2886 u32 mc_shared_chmap, mc_arb_ramcfg;
Alex Deucher0a96d722012-03-20 17:18:11 -04002887 u32 sx_debug_1;
Alex Deucher0a96d722012-03-20 17:18:11 -04002888 u32 hdp_host_path_cntl;
2889 u32 tmp;
2890 int i, j;
2891
2892 switch (rdev->family) {
2893 case CHIP_TAHITI:
2894 rdev->config.si.max_shader_engines = 2;
Alex Deucher0a96d722012-03-20 17:18:11 -04002895 rdev->config.si.max_tile_pipes = 12;
Alex Deucher1a8ca752012-06-01 18:58:22 -04002896 rdev->config.si.max_cu_per_sh = 8;
2897 rdev->config.si.max_sh_per_se = 2;
Alex Deucher0a96d722012-03-20 17:18:11 -04002898 rdev->config.si.max_backends_per_se = 4;
2899 rdev->config.si.max_texture_channel_caches = 12;
2900 rdev->config.si.max_gprs = 256;
2901 rdev->config.si.max_gs_threads = 32;
2902 rdev->config.si.max_hw_contexts = 8;
2903
2904 rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
2905 rdev->config.si.sc_prim_fifo_size_backend = 0x100;
2906 rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
2907 rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher1a8ca752012-06-01 18:58:22 -04002908 gb_addr_config = TAHITI_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher0a96d722012-03-20 17:18:11 -04002909 break;
2910 case CHIP_PITCAIRN:
2911 rdev->config.si.max_shader_engines = 2;
Alex Deucher0a96d722012-03-20 17:18:11 -04002912 rdev->config.si.max_tile_pipes = 8;
Alex Deucher1a8ca752012-06-01 18:58:22 -04002913 rdev->config.si.max_cu_per_sh = 5;
2914 rdev->config.si.max_sh_per_se = 2;
Alex Deucher0a96d722012-03-20 17:18:11 -04002915 rdev->config.si.max_backends_per_se = 4;
2916 rdev->config.si.max_texture_channel_caches = 8;
2917 rdev->config.si.max_gprs = 256;
2918 rdev->config.si.max_gs_threads = 32;
2919 rdev->config.si.max_hw_contexts = 8;
2920
2921 rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
2922 rdev->config.si.sc_prim_fifo_size_backend = 0x100;
2923 rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
2924 rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher1a8ca752012-06-01 18:58:22 -04002925 gb_addr_config = TAHITI_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher0a96d722012-03-20 17:18:11 -04002926 break;
2927 case CHIP_VERDE:
2928 default:
2929 rdev->config.si.max_shader_engines = 1;
Alex Deucher0a96d722012-03-20 17:18:11 -04002930 rdev->config.si.max_tile_pipes = 4;
Alex Deucher468ef1a2013-05-21 13:35:19 -04002931 rdev->config.si.max_cu_per_sh = 5;
Alex Deucher1a8ca752012-06-01 18:58:22 -04002932 rdev->config.si.max_sh_per_se = 2;
Alex Deucher0a96d722012-03-20 17:18:11 -04002933 rdev->config.si.max_backends_per_se = 4;
2934 rdev->config.si.max_texture_channel_caches = 4;
2935 rdev->config.si.max_gprs = 256;
2936 rdev->config.si.max_gs_threads = 32;
2937 rdev->config.si.max_hw_contexts = 8;
2938
2939 rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
2940 rdev->config.si.sc_prim_fifo_size_backend = 0x40;
2941 rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
2942 rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher1a8ca752012-06-01 18:58:22 -04002943 gb_addr_config = VERDE_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher0a96d722012-03-20 17:18:11 -04002944 break;
Alex Deucherd0ae7fc2012-07-26 17:42:25 -04002945 case CHIP_OLAND:
2946 rdev->config.si.max_shader_engines = 1;
2947 rdev->config.si.max_tile_pipes = 4;
2948 rdev->config.si.max_cu_per_sh = 6;
2949 rdev->config.si.max_sh_per_se = 1;
2950 rdev->config.si.max_backends_per_se = 2;
2951 rdev->config.si.max_texture_channel_caches = 4;
2952 rdev->config.si.max_gprs = 256;
2953 rdev->config.si.max_gs_threads = 16;
2954 rdev->config.si.max_hw_contexts = 8;
2955
2956 rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
2957 rdev->config.si.sc_prim_fifo_size_backend = 0x40;
2958 rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
2959 rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
2960 gb_addr_config = VERDE_GB_ADDR_CONFIG_GOLDEN;
2961 break;
Alex Deucher8b028592012-07-31 12:42:48 -04002962 case CHIP_HAINAN:
2963 rdev->config.si.max_shader_engines = 1;
2964 rdev->config.si.max_tile_pipes = 4;
2965 rdev->config.si.max_cu_per_sh = 5;
2966 rdev->config.si.max_sh_per_se = 1;
2967 rdev->config.si.max_backends_per_se = 1;
2968 rdev->config.si.max_texture_channel_caches = 2;
2969 rdev->config.si.max_gprs = 256;
2970 rdev->config.si.max_gs_threads = 16;
2971 rdev->config.si.max_hw_contexts = 8;
2972
2973 rdev->config.si.sc_prim_fifo_size_frontend = 0x20;
2974 rdev->config.si.sc_prim_fifo_size_backend = 0x40;
2975 rdev->config.si.sc_hiz_tile_fifo_size = 0x30;
2976 rdev->config.si.sc_earlyz_tile_fifo_size = 0x130;
2977 gb_addr_config = HAINAN_GB_ADDR_CONFIG_GOLDEN;
2978 break;
Alex Deucher0a96d722012-03-20 17:18:11 -04002979 }
2980
2981 /* Initialize HDP */
2982 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
2983 WREG32((0x2c14 + j), 0x00000000);
2984 WREG32((0x2c18 + j), 0x00000000);
2985 WREG32((0x2c1c + j), 0x00000000);
2986 WREG32((0x2c20 + j), 0x00000000);
2987 WREG32((0x2c24 + j), 0x00000000);
2988 }
2989
2990 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
2991
2992 evergreen_fix_pci_max_read_req_size(rdev);
2993
2994 WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
2995
2996 mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
2997 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
2998
Alex Deucher0a96d722012-03-20 17:18:11 -04002999 rdev->config.si.num_tile_pipes = rdev->config.si.max_tile_pipes;
Alex Deucher0a96d722012-03-20 17:18:11 -04003000 rdev->config.si.mem_max_burst_length_bytes = 256;
3001 tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
3002 rdev->config.si.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
3003 if (rdev->config.si.mem_row_size_in_kb > 4)
3004 rdev->config.si.mem_row_size_in_kb = 4;
3005 /* XXX use MC settings? */
3006 rdev->config.si.shader_engine_tile_size = 32;
3007 rdev->config.si.num_gpus = 1;
3008 rdev->config.si.multi_gpu_tile_size = 64;
3009
Alex Deucher1a8ca752012-06-01 18:58:22 -04003010 /* fix up row size */
3011 gb_addr_config &= ~ROW_SIZE_MASK;
Alex Deucher0a96d722012-03-20 17:18:11 -04003012 switch (rdev->config.si.mem_row_size_in_kb) {
3013 case 1:
3014 default:
3015 gb_addr_config |= ROW_SIZE(0);
3016 break;
3017 case 2:
3018 gb_addr_config |= ROW_SIZE(1);
3019 break;
3020 case 4:
3021 gb_addr_config |= ROW_SIZE(2);
3022 break;
3023 }
3024
Alex Deucher0a96d722012-03-20 17:18:11 -04003025 /* setup tiling info dword. gb_addr_config is not adequate since it does
3026 * not have bank info, so create a custom tiling dword.
3027 * bits 3:0 num_pipes
3028 * bits 7:4 num_banks
3029 * bits 11:8 group_size
3030 * bits 15:12 row_size
3031 */
3032 rdev->config.si.tile_config = 0;
3033 switch (rdev->config.si.num_tile_pipes) {
3034 case 1:
3035 rdev->config.si.tile_config |= (0 << 0);
3036 break;
3037 case 2:
3038 rdev->config.si.tile_config |= (1 << 0);
3039 break;
3040 case 4:
3041 rdev->config.si.tile_config |= (2 << 0);
3042 break;
3043 case 8:
3044 default:
3045 /* XXX what about 12? */
3046 rdev->config.si.tile_config |= (3 << 0);
3047 break;
Christian Königdca571a2012-07-31 13:48:51 +02003048 }
3049 switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
3050 case 0: /* four banks */
Alex Deucher1a8ca752012-06-01 18:58:22 -04003051 rdev->config.si.tile_config |= 0 << 4;
Christian Königdca571a2012-07-31 13:48:51 +02003052 break;
3053 case 1: /* eight banks */
3054 rdev->config.si.tile_config |= 1 << 4;
3055 break;
3056 case 2: /* sixteen banks */
3057 default:
3058 rdev->config.si.tile_config |= 2 << 4;
3059 break;
3060 }
Alex Deucher0a96d722012-03-20 17:18:11 -04003061 rdev->config.si.tile_config |=
3062 ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
3063 rdev->config.si.tile_config |=
3064 ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
3065
Alex Deucher0a96d722012-03-20 17:18:11 -04003066 WREG32(GB_ADDR_CONFIG, gb_addr_config);
3067 WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
Alex Deucher7c1c7c12013-04-05 10:28:08 -04003068 WREG32(DMIF_ADDR_CALC, gb_addr_config);
Alex Deucher0a96d722012-03-20 17:18:11 -04003069 WREG32(HDP_ADDR_CONFIG, gb_addr_config);
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05003070 WREG32(DMA_TILING_CONFIG + DMA0_REGISTER_OFFSET, gb_addr_config);
3071 WREG32(DMA_TILING_CONFIG + DMA1_REGISTER_OFFSET, gb_addr_config);
Alex Deucher1df0d522013-04-26 18:03:44 -04003072 if (rdev->has_uvd) {
3073 WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
3074 WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
3075 WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
3076 }
Alex Deucher0a96d722012-03-20 17:18:11 -04003077
Alex Deucher0a96d722012-03-20 17:18:11 -04003078 si_tiling_mode_table_init(rdev);
3079
Alex Deucher1a8ca752012-06-01 18:58:22 -04003080 si_setup_rb(rdev, rdev->config.si.max_shader_engines,
3081 rdev->config.si.max_sh_per_se,
3082 rdev->config.si.max_backends_per_se);
3083
3084 si_setup_spi(rdev, rdev->config.si.max_shader_engines,
3085 rdev->config.si.max_sh_per_se,
3086 rdev->config.si.max_cu_per_sh);
3087
3088
Alex Deucher0a96d722012-03-20 17:18:11 -04003089 /* set HW defaults for 3D engine */
3090 WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
3091 ROQ_IB2_START(0x2b)));
3092 WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
3093
3094 sx_debug_1 = RREG32(SX_DEBUG_1);
3095 WREG32(SX_DEBUG_1, sx_debug_1);
3096
3097 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
3098
3099 WREG32(PA_SC_FIFO_SIZE, (SC_FRONTEND_PRIM_FIFO_SIZE(rdev->config.si.sc_prim_fifo_size_frontend) |
3100 SC_BACKEND_PRIM_FIFO_SIZE(rdev->config.si.sc_prim_fifo_size_backend) |
3101 SC_HIZ_TILE_FIFO_SIZE(rdev->config.si.sc_hiz_tile_fifo_size) |
3102 SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.si.sc_earlyz_tile_fifo_size)));
3103
3104 WREG32(VGT_NUM_INSTANCES, 1);
3105
3106 WREG32(CP_PERFMON_CNTL, 0);
3107
3108 WREG32(SQ_CONFIG, 0);
3109
3110 WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
3111 FORCE_EOV_MAX_REZ_CNT(255)));
3112
3113 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
3114 AUTO_INVLD_EN(ES_AND_GS_AUTO));
3115
3116 WREG32(VGT_GS_VERTEX_REUSE, 16);
3117 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
3118
3119 WREG32(CB_PERFCOUNTER0_SELECT0, 0);
3120 WREG32(CB_PERFCOUNTER0_SELECT1, 0);
3121 WREG32(CB_PERFCOUNTER1_SELECT0, 0);
3122 WREG32(CB_PERFCOUNTER1_SELECT1, 0);
3123 WREG32(CB_PERFCOUNTER2_SELECT0, 0);
3124 WREG32(CB_PERFCOUNTER2_SELECT1, 0);
3125 WREG32(CB_PERFCOUNTER3_SELECT0, 0);
3126 WREG32(CB_PERFCOUNTER3_SELECT1, 0);
3127
3128 tmp = RREG32(HDP_MISC_CNTL);
3129 tmp |= HDP_FLUSH_INVALIDATE_CACHE;
3130 WREG32(HDP_MISC_CNTL, tmp);
3131
3132 hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
3133 WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
3134
3135 WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
3136
3137 udelay(50);
3138}
Alex Deucherc476dde2012-03-20 17:18:12 -04003139
Alex Deucher48c0c902012-03-20 17:18:19 -04003140/*
Alex Deucher2ece2e82012-03-20 17:18:20 -04003141 * GPU scratch registers helpers function.
3142 */
3143static void si_scratch_init(struct radeon_device *rdev)
3144{
3145 int i;
3146
3147 rdev->scratch.num_reg = 7;
3148 rdev->scratch.reg_base = SCRATCH_REG0;
3149 for (i = 0; i < rdev->scratch.num_reg; i++) {
3150 rdev->scratch.free[i] = true;
3151 rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
3152 }
3153}
3154
3155void si_fence_ring_emit(struct radeon_device *rdev,
3156 struct radeon_fence *fence)
3157{
3158 struct radeon_ring *ring = &rdev->ring[fence->ring];
3159 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
3160
3161 /* flush read cache over gart */
3162 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
3163 radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
3164 radeon_ring_write(ring, 0);
3165 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
3166 radeon_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
3167 PACKET3_TC_ACTION_ENA |
3168 PACKET3_SH_KCACHE_ACTION_ENA |
3169 PACKET3_SH_ICACHE_ACTION_ENA);
3170 radeon_ring_write(ring, 0xFFFFFFFF);
3171 radeon_ring_write(ring, 0);
3172 radeon_ring_write(ring, 10); /* poll interval */
3173 /* EVENT_WRITE_EOP - flush caches, send int */
3174 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
3175 radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) | EVENT_INDEX(5));
3176 radeon_ring_write(ring, addr & 0xffffffff);
3177 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
3178 radeon_ring_write(ring, fence->seq);
3179 radeon_ring_write(ring, 0);
3180}
3181
3182/*
3183 * IB stuff
3184 */
3185void si_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
3186{
Christian König876dc9f2012-05-08 14:24:01 +02003187 struct radeon_ring *ring = &rdev->ring[ib->ring];
Alex Deucher2ece2e82012-03-20 17:18:20 -04003188 u32 header;
3189
Alex Deuchera85a7da42012-07-17 14:02:29 -04003190 if (ib->is_const_ib) {
3191 /* set switch buffer packet before const IB */
3192 radeon_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
3193 radeon_ring_write(ring, 0);
Christian König45df6802012-07-06 16:22:55 +02003194
Alex Deucher2ece2e82012-03-20 17:18:20 -04003195 header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
Alex Deuchera85a7da42012-07-17 14:02:29 -04003196 } else {
Alex Deucher89d35802012-07-17 14:02:31 -04003197 u32 next_rptr;
Alex Deuchera85a7da42012-07-17 14:02:29 -04003198 if (ring->rptr_save_reg) {
Alex Deucher89d35802012-07-17 14:02:31 -04003199 next_rptr = ring->wptr + 3 + 4 + 8;
Alex Deuchera85a7da42012-07-17 14:02:29 -04003200 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
3201 radeon_ring_write(ring, ((ring->rptr_save_reg -
3202 PACKET3_SET_CONFIG_REG_START) >> 2));
3203 radeon_ring_write(ring, next_rptr);
Alex Deucher89d35802012-07-17 14:02:31 -04003204 } else if (rdev->wb.enabled) {
3205 next_rptr = ring->wptr + 5 + 4 + 8;
3206 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
3207 radeon_ring_write(ring, (1 << 8));
3208 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
3209 radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xffffffff);
3210 radeon_ring_write(ring, next_rptr);
Alex Deuchera85a7da42012-07-17 14:02:29 -04003211 }
3212
Alex Deucher2ece2e82012-03-20 17:18:20 -04003213 header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
Alex Deuchera85a7da42012-07-17 14:02:29 -04003214 }
Alex Deucher2ece2e82012-03-20 17:18:20 -04003215
3216 radeon_ring_write(ring, header);
3217 radeon_ring_write(ring,
3218#ifdef __BIG_ENDIAN
3219 (2 << 0) |
3220#endif
3221 (ib->gpu_addr & 0xFFFFFFFC));
3222 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
Christian König4bf3dd92012-08-06 18:57:44 +02003223 radeon_ring_write(ring, ib->length_dw |
3224 (ib->vm ? (ib->vm->id << 24) : 0));
Alex Deucher2ece2e82012-03-20 17:18:20 -04003225
Alex Deuchera85a7da42012-07-17 14:02:29 -04003226 if (!ib->is_const_ib) {
3227 /* flush read cache over gart for this vmid */
3228 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
3229 radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
Christian König4bf3dd92012-08-06 18:57:44 +02003230 radeon_ring_write(ring, ib->vm ? ib->vm->id : 0);
Alex Deuchera85a7da42012-07-17 14:02:29 -04003231 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
3232 radeon_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
3233 PACKET3_TC_ACTION_ENA |
3234 PACKET3_SH_KCACHE_ACTION_ENA |
3235 PACKET3_SH_ICACHE_ACTION_ENA);
3236 radeon_ring_write(ring, 0xFFFFFFFF);
3237 radeon_ring_write(ring, 0);
3238 radeon_ring_write(ring, 10); /* poll interval */
3239 }
Alex Deucher2ece2e82012-03-20 17:18:20 -04003240}
3241
3242/*
Alex Deucher48c0c902012-03-20 17:18:19 -04003243 * CP.
3244 */
3245static void si_cp_enable(struct radeon_device *rdev, bool enable)
3246{
3247 if (enable)
3248 WREG32(CP_ME_CNTL, 0);
3249 else {
3250 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
3251 WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT));
3252 WREG32(SCRATCH_UMSK, 0);
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05003253 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
3254 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
3255 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
Alex Deucher48c0c902012-03-20 17:18:19 -04003256 }
3257 udelay(50);
3258}
3259
3260static int si_cp_load_microcode(struct radeon_device *rdev)
3261{
3262 const __be32 *fw_data;
3263 int i;
3264
3265 if (!rdev->me_fw || !rdev->pfp_fw)
3266 return -EINVAL;
3267
3268 si_cp_enable(rdev, false);
3269
3270 /* PFP */
3271 fw_data = (const __be32 *)rdev->pfp_fw->data;
3272 WREG32(CP_PFP_UCODE_ADDR, 0);
3273 for (i = 0; i < SI_PFP_UCODE_SIZE; i++)
3274 WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
3275 WREG32(CP_PFP_UCODE_ADDR, 0);
3276
3277 /* CE */
3278 fw_data = (const __be32 *)rdev->ce_fw->data;
3279 WREG32(CP_CE_UCODE_ADDR, 0);
3280 for (i = 0; i < SI_CE_UCODE_SIZE; i++)
3281 WREG32(CP_CE_UCODE_DATA, be32_to_cpup(fw_data++));
3282 WREG32(CP_CE_UCODE_ADDR, 0);
3283
3284 /* ME */
3285 fw_data = (const __be32 *)rdev->me_fw->data;
3286 WREG32(CP_ME_RAM_WADDR, 0);
3287 for (i = 0; i < SI_PM4_UCODE_SIZE; i++)
3288 WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
3289 WREG32(CP_ME_RAM_WADDR, 0);
3290
3291 WREG32(CP_PFP_UCODE_ADDR, 0);
3292 WREG32(CP_CE_UCODE_ADDR, 0);
3293 WREG32(CP_ME_RAM_WADDR, 0);
3294 WREG32(CP_ME_RAM_RADDR, 0);
3295 return 0;
3296}
3297
3298static int si_cp_start(struct radeon_device *rdev)
3299{
3300 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
3301 int r, i;
3302
3303 r = radeon_ring_lock(rdev, ring, 7 + 4);
3304 if (r) {
3305 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
3306 return r;
3307 }
3308 /* init the CP */
3309 radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
3310 radeon_ring_write(ring, 0x1);
3311 radeon_ring_write(ring, 0x0);
3312 radeon_ring_write(ring, rdev->config.si.max_hw_contexts - 1);
3313 radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
3314 radeon_ring_write(ring, 0);
3315 radeon_ring_write(ring, 0);
3316
3317 /* init the CE partitions */
3318 radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
3319 radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
3320 radeon_ring_write(ring, 0xc000);
3321 radeon_ring_write(ring, 0xe000);
3322 radeon_ring_unlock_commit(rdev, ring);
3323
3324 si_cp_enable(rdev, true);
3325
3326 r = radeon_ring_lock(rdev, ring, si_default_size + 10);
3327 if (r) {
3328 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
3329 return r;
3330 }
3331
3332 /* setup clear context state */
3333 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
3334 radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
3335
3336 for (i = 0; i < si_default_size; i++)
3337 radeon_ring_write(ring, si_default_state[i]);
3338
3339 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
3340 radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
3341
3342 /* set clear context state */
3343 radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
3344 radeon_ring_write(ring, 0);
3345
3346 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
3347 radeon_ring_write(ring, 0x00000316);
3348 radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
3349 radeon_ring_write(ring, 0x00000010); /* VGT_OUT_DEALLOC_CNTL */
3350
3351 radeon_ring_unlock_commit(rdev, ring);
3352
3353 for (i = RADEON_RING_TYPE_GFX_INDEX; i <= CAYMAN_RING_TYPE_CP2_INDEX; ++i) {
3354 ring = &rdev->ring[i];
3355 r = radeon_ring_lock(rdev, ring, 2);
3356
3357 /* clear the compute context state */
3358 radeon_ring_write(ring, PACKET3_COMPUTE(PACKET3_CLEAR_STATE, 0));
3359 radeon_ring_write(ring, 0);
3360
3361 radeon_ring_unlock_commit(rdev, ring);
3362 }
3363
3364 return 0;
3365}
3366
3367static void si_cp_fini(struct radeon_device *rdev)
3368{
Christian König45df6802012-07-06 16:22:55 +02003369 struct radeon_ring *ring;
Alex Deucher48c0c902012-03-20 17:18:19 -04003370 si_cp_enable(rdev, false);
Christian König45df6802012-07-06 16:22:55 +02003371
3372 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
3373 radeon_ring_fini(rdev, ring);
3374 radeon_scratch_free(rdev, ring->rptr_save_reg);
3375
3376 ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
3377 radeon_ring_fini(rdev, ring);
3378 radeon_scratch_free(rdev, ring->rptr_save_reg);
3379
3380 ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
3381 radeon_ring_fini(rdev, ring);
3382 radeon_scratch_free(rdev, ring->rptr_save_reg);
Alex Deucher48c0c902012-03-20 17:18:19 -04003383}
3384
3385static int si_cp_resume(struct radeon_device *rdev)
3386{
3387 struct radeon_ring *ring;
3388 u32 tmp;
3389 u32 rb_bufsz;
3390 int r;
3391
Alex Deucher811e4d52013-09-03 13:31:33 -04003392 si_enable_gui_idle_interrupt(rdev, false);
3393
Alex Deucher48c0c902012-03-20 17:18:19 -04003394 WREG32(CP_SEM_WAIT_TIMER, 0x0);
3395 WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
3396
3397 /* Set the write pointer delay */
3398 WREG32(CP_RB_WPTR_DELAY, 0);
3399
3400 WREG32(CP_DEBUG, 0);
3401 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
3402
3403 /* ring 0 - compute and gfx */
3404 /* Set ring buffer size */
3405 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Daniel Vetterb72a8922013-07-10 14:11:59 +02003406 rb_bufsz = order_base_2(ring->ring_size / 8);
3407 tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
Alex Deucher48c0c902012-03-20 17:18:19 -04003408#ifdef __BIG_ENDIAN
3409 tmp |= BUF_SWAP_32BIT;
3410#endif
3411 WREG32(CP_RB0_CNTL, tmp);
3412
3413 /* Initialize the ring buffer's read and write pointers */
3414 WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA);
3415 ring->wptr = 0;
3416 WREG32(CP_RB0_WPTR, ring->wptr);
3417
Adam Buchbinder48fc7f72012-09-19 21:48:00 -04003418 /* set the wb address whether it's enabled or not */
Alex Deucher48c0c902012-03-20 17:18:19 -04003419 WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
3420 WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
3421
3422 if (rdev->wb.enabled)
3423 WREG32(SCRATCH_UMSK, 0xff);
3424 else {
3425 tmp |= RB_NO_UPDATE;
3426 WREG32(SCRATCH_UMSK, 0);
3427 }
3428
3429 mdelay(1);
3430 WREG32(CP_RB0_CNTL, tmp);
3431
3432 WREG32(CP_RB0_BASE, ring->gpu_addr >> 8);
3433
3434 ring->rptr = RREG32(CP_RB0_RPTR);
3435
3436 /* ring1 - compute only */
3437 /* Set ring buffer size */
3438 ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
Daniel Vetterb72a8922013-07-10 14:11:59 +02003439 rb_bufsz = order_base_2(ring->ring_size / 8);
3440 tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
Alex Deucher48c0c902012-03-20 17:18:19 -04003441#ifdef __BIG_ENDIAN
3442 tmp |= BUF_SWAP_32BIT;
3443#endif
3444 WREG32(CP_RB1_CNTL, tmp);
3445
3446 /* Initialize the ring buffer's read and write pointers */
3447 WREG32(CP_RB1_CNTL, tmp | RB_RPTR_WR_ENA);
3448 ring->wptr = 0;
3449 WREG32(CP_RB1_WPTR, ring->wptr);
3450
Adam Buchbinder48fc7f72012-09-19 21:48:00 -04003451 /* set the wb address whether it's enabled or not */
Alex Deucher48c0c902012-03-20 17:18:19 -04003452 WREG32(CP_RB1_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFFFFFFFC);
3453 WREG32(CP_RB1_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET) & 0xFF);
3454
3455 mdelay(1);
3456 WREG32(CP_RB1_CNTL, tmp);
3457
3458 WREG32(CP_RB1_BASE, ring->gpu_addr >> 8);
3459
3460 ring->rptr = RREG32(CP_RB1_RPTR);
3461
3462 /* ring2 - compute only */
3463 /* Set ring buffer size */
3464 ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
Daniel Vetterb72a8922013-07-10 14:11:59 +02003465 rb_bufsz = order_base_2(ring->ring_size / 8);
3466 tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
Alex Deucher48c0c902012-03-20 17:18:19 -04003467#ifdef __BIG_ENDIAN
3468 tmp |= BUF_SWAP_32BIT;
3469#endif
3470 WREG32(CP_RB2_CNTL, tmp);
3471
3472 /* Initialize the ring buffer's read and write pointers */
3473 WREG32(CP_RB2_CNTL, tmp | RB_RPTR_WR_ENA);
3474 ring->wptr = 0;
3475 WREG32(CP_RB2_WPTR, ring->wptr);
3476
Adam Buchbinder48fc7f72012-09-19 21:48:00 -04003477 /* set the wb address whether it's enabled or not */
Alex Deucher48c0c902012-03-20 17:18:19 -04003478 WREG32(CP_RB2_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFFFFFFFC);
3479 WREG32(CP_RB2_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET) & 0xFF);
3480
3481 mdelay(1);
3482 WREG32(CP_RB2_CNTL, tmp);
3483
3484 WREG32(CP_RB2_BASE, ring->gpu_addr >> 8);
3485
3486 ring->rptr = RREG32(CP_RB2_RPTR);
3487
3488 /* start the rings */
3489 si_cp_start(rdev);
3490 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
3491 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = true;
3492 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = true;
3493 r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
3494 if (r) {
3495 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
3496 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
3497 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
3498 return r;
3499 }
3500 r = radeon_ring_test(rdev, CAYMAN_RING_TYPE_CP1_INDEX, &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX]);
3501 if (r) {
3502 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
3503 }
3504 r = radeon_ring_test(rdev, CAYMAN_RING_TYPE_CP2_INDEX, &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX]);
3505 if (r) {
3506 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
3507 }
3508
Alex Deucher811e4d52013-09-03 13:31:33 -04003509 si_enable_gui_idle_interrupt(rdev, true);
3510
Alex Deucher48c0c902012-03-20 17:18:19 -04003511 return 0;
3512}
3513
Christian König2483b4e2013-08-13 11:56:54 +02003514u32 si_gpu_check_soft_reset(struct radeon_device *rdev)
Alex Deucher014bb202013-01-18 19:36:20 -05003515{
3516 u32 reset_mask = 0;
3517 u32 tmp;
3518
3519 /* GRBM_STATUS */
3520 tmp = RREG32(GRBM_STATUS);
3521 if (tmp & (PA_BUSY | SC_BUSY |
3522 BCI_BUSY | SX_BUSY |
3523 TA_BUSY | VGT_BUSY |
3524 DB_BUSY | CB_BUSY |
3525 GDS_BUSY | SPI_BUSY |
3526 IA_BUSY | IA_BUSY_NO_DMA))
3527 reset_mask |= RADEON_RESET_GFX;
3528
3529 if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
3530 CP_BUSY | CP_COHERENCY_BUSY))
3531 reset_mask |= RADEON_RESET_CP;
3532
3533 if (tmp & GRBM_EE_BUSY)
3534 reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
3535
3536 /* GRBM_STATUS2 */
3537 tmp = RREG32(GRBM_STATUS2);
3538 if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
3539 reset_mask |= RADEON_RESET_RLC;
3540
3541 /* DMA_STATUS_REG 0 */
3542 tmp = RREG32(DMA_STATUS_REG + DMA0_REGISTER_OFFSET);
3543 if (!(tmp & DMA_IDLE))
3544 reset_mask |= RADEON_RESET_DMA;
3545
3546 /* DMA_STATUS_REG 1 */
3547 tmp = RREG32(DMA_STATUS_REG + DMA1_REGISTER_OFFSET);
3548 if (!(tmp & DMA_IDLE))
3549 reset_mask |= RADEON_RESET_DMA1;
3550
3551 /* SRBM_STATUS2 */
3552 tmp = RREG32(SRBM_STATUS2);
3553 if (tmp & DMA_BUSY)
3554 reset_mask |= RADEON_RESET_DMA;
3555
3556 if (tmp & DMA1_BUSY)
3557 reset_mask |= RADEON_RESET_DMA1;
3558
3559 /* SRBM_STATUS */
3560 tmp = RREG32(SRBM_STATUS);
3561
3562 if (tmp & IH_BUSY)
3563 reset_mask |= RADEON_RESET_IH;
3564
3565 if (tmp & SEM_BUSY)
3566 reset_mask |= RADEON_RESET_SEM;
3567
3568 if (tmp & GRBM_RQ_PENDING)
3569 reset_mask |= RADEON_RESET_GRBM;
3570
3571 if (tmp & VMC_BUSY)
3572 reset_mask |= RADEON_RESET_VMC;
3573
3574 if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
3575 MCC_BUSY | MCD_BUSY))
3576 reset_mask |= RADEON_RESET_MC;
3577
3578 if (evergreen_is_display_hung(rdev))
3579 reset_mask |= RADEON_RESET_DISPLAY;
3580
3581 /* VM_L2_STATUS */
3582 tmp = RREG32(VM_L2_STATUS);
3583 if (tmp & L2_BUSY)
3584 reset_mask |= RADEON_RESET_VMC;
3585
Alex Deucherd808fc82013-02-28 10:03:08 -05003586 /* Skip MC reset as it's mostly likely not hung, just busy */
3587 if (reset_mask & RADEON_RESET_MC) {
3588 DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
3589 reset_mask &= ~RADEON_RESET_MC;
3590 }
3591
Alex Deucher014bb202013-01-18 19:36:20 -05003592 return reset_mask;
3593}
3594
3595static void si_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
Alex Deucher06bc6df2013-01-03 13:15:30 -05003596{
3597 struct evergreen_mc_save save;
Alex Deucher1c534672013-01-18 15:08:38 -05003598 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
3599 u32 tmp;
Alex Deucher19fc42e2013-01-14 11:04:39 -05003600
Alex Deucher06bc6df2013-01-03 13:15:30 -05003601 if (reset_mask == 0)
Alex Deucher014bb202013-01-18 19:36:20 -05003602 return;
Alex Deucher06bc6df2013-01-03 13:15:30 -05003603
3604 dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
3605
Alex Deucher1c534672013-01-18 15:08:38 -05003606 evergreen_print_gpu_status_regs(rdev);
Alex Deucher06bc6df2013-01-03 13:15:30 -05003607 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
3608 RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
3609 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
3610 RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
3611
Alex Deuchera6f4ae82013-10-02 14:50:57 -04003612 /* disable PG/CG */
3613 si_fini_pg(rdev);
3614 si_fini_cg(rdev);
3615
3616 /* stop the rlc */
3617 si_rlc_stop(rdev);
3618
Alex Deucher1c534672013-01-18 15:08:38 -05003619 /* Disable CP parsing/prefetching */
3620 WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
3621
3622 if (reset_mask & RADEON_RESET_DMA) {
3623 /* dma0 */
3624 tmp = RREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET);
3625 tmp &= ~DMA_RB_ENABLE;
3626 WREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET, tmp);
Alex Deucher014bb202013-01-18 19:36:20 -05003627 }
3628 if (reset_mask & RADEON_RESET_DMA1) {
Alex Deucher1c534672013-01-18 15:08:38 -05003629 /* dma1 */
3630 tmp = RREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET);
3631 tmp &= ~DMA_RB_ENABLE;
3632 WREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET, tmp);
3633 }
3634
Alex Deucherf770d782013-01-23 19:00:25 -05003635 udelay(50);
3636
3637 evergreen_mc_stop(rdev, &save);
3638 if (evergreen_mc_wait_for_idle(rdev)) {
3639 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
3640 }
3641
Alex Deucher1c534672013-01-18 15:08:38 -05003642 if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE | RADEON_RESET_CP)) {
3643 grbm_soft_reset = SOFT_RESET_CB |
3644 SOFT_RESET_DB |
3645 SOFT_RESET_GDS |
3646 SOFT_RESET_PA |
3647 SOFT_RESET_SC |
3648 SOFT_RESET_BCI |
3649 SOFT_RESET_SPI |
3650 SOFT_RESET_SX |
3651 SOFT_RESET_TC |
3652 SOFT_RESET_TA |
3653 SOFT_RESET_VGT |
3654 SOFT_RESET_IA;
3655 }
3656
3657 if (reset_mask & RADEON_RESET_CP) {
3658 grbm_soft_reset |= SOFT_RESET_CP | SOFT_RESET_VGT;
3659
3660 srbm_soft_reset |= SOFT_RESET_GRBM;
3661 }
Alex Deucher06bc6df2013-01-03 13:15:30 -05003662
3663 if (reset_mask & RADEON_RESET_DMA)
Alex Deucher014bb202013-01-18 19:36:20 -05003664 srbm_soft_reset |= SOFT_RESET_DMA;
3665
3666 if (reset_mask & RADEON_RESET_DMA1)
3667 srbm_soft_reset |= SOFT_RESET_DMA1;
3668
3669 if (reset_mask & RADEON_RESET_DISPLAY)
3670 srbm_soft_reset |= SOFT_RESET_DC;
3671
3672 if (reset_mask & RADEON_RESET_RLC)
3673 grbm_soft_reset |= SOFT_RESET_RLC;
3674
3675 if (reset_mask & RADEON_RESET_SEM)
3676 srbm_soft_reset |= SOFT_RESET_SEM;
3677
3678 if (reset_mask & RADEON_RESET_IH)
3679 srbm_soft_reset |= SOFT_RESET_IH;
3680
3681 if (reset_mask & RADEON_RESET_GRBM)
3682 srbm_soft_reset |= SOFT_RESET_GRBM;
3683
3684 if (reset_mask & RADEON_RESET_VMC)
3685 srbm_soft_reset |= SOFT_RESET_VMC;
3686
3687 if (reset_mask & RADEON_RESET_MC)
3688 srbm_soft_reset |= SOFT_RESET_MC;
Alex Deucher1c534672013-01-18 15:08:38 -05003689
3690 if (grbm_soft_reset) {
3691 tmp = RREG32(GRBM_SOFT_RESET);
3692 tmp |= grbm_soft_reset;
3693 dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
3694 WREG32(GRBM_SOFT_RESET, tmp);
3695 tmp = RREG32(GRBM_SOFT_RESET);
3696
3697 udelay(50);
3698
3699 tmp &= ~grbm_soft_reset;
3700 WREG32(GRBM_SOFT_RESET, tmp);
3701 tmp = RREG32(GRBM_SOFT_RESET);
3702 }
3703
3704 if (srbm_soft_reset) {
3705 tmp = RREG32(SRBM_SOFT_RESET);
3706 tmp |= srbm_soft_reset;
3707 dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
3708 WREG32(SRBM_SOFT_RESET, tmp);
3709 tmp = RREG32(SRBM_SOFT_RESET);
3710
3711 udelay(50);
3712
3713 tmp &= ~srbm_soft_reset;
3714 WREG32(SRBM_SOFT_RESET, tmp);
3715 tmp = RREG32(SRBM_SOFT_RESET);
3716 }
Alex Deucher06bc6df2013-01-03 13:15:30 -05003717
3718 /* Wait a little for things to settle down */
3719 udelay(50);
3720
Alex Deucherc476dde2012-03-20 17:18:12 -04003721 evergreen_mc_resume(rdev, &save);
Alex Deucher1c534672013-01-18 15:08:38 -05003722 udelay(50);
Alex Deucher410a3412013-01-18 13:05:39 -05003723
Alex Deucher1c534672013-01-18 15:08:38 -05003724 evergreen_print_gpu_status_regs(rdev);
Alex Deucherc476dde2012-03-20 17:18:12 -04003725}
3726
Alex Deucher4a5c8ea2013-11-15 16:35:55 -05003727static void si_set_clk_bypass_mode(struct radeon_device *rdev)
3728{
3729 u32 tmp, i;
3730
3731 tmp = RREG32(CG_SPLL_FUNC_CNTL);
3732 tmp |= SPLL_BYPASS_EN;
3733 WREG32(CG_SPLL_FUNC_CNTL, tmp);
3734
3735 tmp = RREG32(CG_SPLL_FUNC_CNTL_2);
3736 tmp |= SPLL_CTLREQ_CHG;
3737 WREG32(CG_SPLL_FUNC_CNTL_2, tmp);
3738
3739 for (i = 0; i < rdev->usec_timeout; i++) {
3740 if (RREG32(SPLL_STATUS) & SPLL_CHG_STATUS)
3741 break;
3742 udelay(1);
3743 }
3744
3745 tmp = RREG32(CG_SPLL_FUNC_CNTL_2);
3746 tmp &= ~(SPLL_CTLREQ_CHG | SCLK_MUX_UPDATE);
3747 WREG32(CG_SPLL_FUNC_CNTL_2, tmp);
3748
3749 tmp = RREG32(MPLL_CNTL_MODE);
3750 tmp &= ~MPLL_MCLK_SEL;
3751 WREG32(MPLL_CNTL_MODE, tmp);
3752}
3753
3754static void si_spll_powerdown(struct radeon_device *rdev)
3755{
3756 u32 tmp;
3757
3758 tmp = RREG32(SPLL_CNTL_MODE);
3759 tmp |= SPLL_SW_DIR_CONTROL;
3760 WREG32(SPLL_CNTL_MODE, tmp);
3761
3762 tmp = RREG32(CG_SPLL_FUNC_CNTL);
3763 tmp |= SPLL_RESET;
3764 WREG32(CG_SPLL_FUNC_CNTL, tmp);
3765
3766 tmp = RREG32(CG_SPLL_FUNC_CNTL);
3767 tmp |= SPLL_SLEEP;
3768 WREG32(CG_SPLL_FUNC_CNTL, tmp);
3769
3770 tmp = RREG32(SPLL_CNTL_MODE);
3771 tmp &= ~SPLL_SW_DIR_CONTROL;
3772 WREG32(SPLL_CNTL_MODE, tmp);
3773}
3774
3775static void si_gpu_pci_config_reset(struct radeon_device *rdev)
3776{
3777 struct evergreen_mc_save save;
3778 u32 tmp, i;
3779
3780 dev_info(rdev->dev, "GPU pci config reset\n");
3781
3782 /* disable dpm? */
3783
3784 /* disable cg/pg */
3785 si_fini_pg(rdev);
3786 si_fini_cg(rdev);
3787
3788 /* Disable CP parsing/prefetching */
3789 WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
3790 /* dma0 */
3791 tmp = RREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET);
3792 tmp &= ~DMA_RB_ENABLE;
3793 WREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET, tmp);
3794 /* dma1 */
3795 tmp = RREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET);
3796 tmp &= ~DMA_RB_ENABLE;
3797 WREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET, tmp);
3798 /* XXX other engines? */
3799
3800 /* halt the rlc, disable cp internal ints */
3801 si_rlc_stop(rdev);
3802
3803 udelay(50);
3804
3805 /* disable mem access */
3806 evergreen_mc_stop(rdev, &save);
3807 if (evergreen_mc_wait_for_idle(rdev)) {
3808 dev_warn(rdev->dev, "Wait for MC idle timed out !\n");
3809 }
3810
3811 /* set mclk/sclk to bypass */
3812 si_set_clk_bypass_mode(rdev);
3813 /* powerdown spll */
3814 si_spll_powerdown(rdev);
3815 /* disable BM */
3816 pci_clear_master(rdev->pdev);
3817 /* reset */
3818 radeon_pci_config_reset(rdev);
3819 /* wait for asic to come out of reset */
3820 for (i = 0; i < rdev->usec_timeout; i++) {
3821 if (RREG32(CONFIG_MEMSIZE) != 0xffffffff)
3822 break;
3823 udelay(1);
3824 }
3825}
3826
Alex Deucherc476dde2012-03-20 17:18:12 -04003827int si_asic_reset(struct radeon_device *rdev)
3828{
Alex Deucher014bb202013-01-18 19:36:20 -05003829 u32 reset_mask;
3830
3831 reset_mask = si_gpu_check_soft_reset(rdev);
3832
3833 if (reset_mask)
3834 r600_set_bios_scratch_engine_hung(rdev, true);
3835
Alex Deucher4a5c8ea2013-11-15 16:35:55 -05003836 /* try soft reset */
Alex Deucher014bb202013-01-18 19:36:20 -05003837 si_gpu_soft_reset(rdev, reset_mask);
3838
3839 reset_mask = si_gpu_check_soft_reset(rdev);
3840
Alex Deucher4a5c8ea2013-11-15 16:35:55 -05003841 /* try pci config reset */
3842 if (reset_mask && radeon_hard_reset)
3843 si_gpu_pci_config_reset(rdev);
3844
3845 reset_mask = si_gpu_check_soft_reset(rdev);
3846
Alex Deucher014bb202013-01-18 19:36:20 -05003847 if (!reset_mask)
3848 r600_set_bios_scratch_engine_hung(rdev, false);
3849
3850 return 0;
Alex Deucherc476dde2012-03-20 17:18:12 -04003851}
3852
Alex Deucher123bc182013-01-24 11:37:19 -05003853/**
3854 * si_gfx_is_lockup - Check if the GFX engine is locked up
3855 *
3856 * @rdev: radeon_device pointer
3857 * @ring: radeon_ring structure holding ring information
3858 *
3859 * Check if the GFX engine is locked up.
3860 * Returns true if the engine appears to be locked up, false if not.
3861 */
3862bool si_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
3863{
3864 u32 reset_mask = si_gpu_check_soft_reset(rdev);
3865
3866 if (!(reset_mask & (RADEON_RESET_GFX |
3867 RADEON_RESET_COMPUTE |
3868 RADEON_RESET_CP))) {
3869 radeon_ring_lockup_update(ring);
3870 return false;
3871 }
3872 /* force CP activities */
3873 radeon_ring_force_activity(rdev, ring);
3874 return radeon_ring_test_lockup(rdev, ring);
3875}
3876
Alex Deucherd2800ee2012-03-20 17:18:13 -04003877/* MC */
3878static void si_mc_program(struct radeon_device *rdev)
3879{
3880 struct evergreen_mc_save save;
3881 u32 tmp;
3882 int i, j;
3883
3884 /* Initialize HDP */
3885 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
3886 WREG32((0x2c14 + j), 0x00000000);
3887 WREG32((0x2c18 + j), 0x00000000);
3888 WREG32((0x2c1c + j), 0x00000000);
3889 WREG32((0x2c20 + j), 0x00000000);
3890 WREG32((0x2c24 + j), 0x00000000);
3891 }
3892 WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
3893
3894 evergreen_mc_stop(rdev, &save);
3895 if (radeon_mc_wait_for_idle(rdev)) {
3896 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
3897 }
Alex Deucher51535502012-08-30 14:34:30 -04003898 if (!ASIC_IS_NODCE(rdev))
3899 /* Lockout access through VGA aperture*/
3900 WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
Alex Deucherd2800ee2012-03-20 17:18:13 -04003901 /* Update configuration */
3902 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
3903 rdev->mc.vram_start >> 12);
3904 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
3905 rdev->mc.vram_end >> 12);
3906 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR,
3907 rdev->vram_scratch.gpu_addr >> 12);
3908 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
3909 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
3910 WREG32(MC_VM_FB_LOCATION, tmp);
3911 /* XXX double check these! */
3912 WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
3913 WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
3914 WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
3915 WREG32(MC_VM_AGP_BASE, 0);
3916 WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
3917 WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
3918 if (radeon_mc_wait_for_idle(rdev)) {
3919 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
3920 }
3921 evergreen_mc_resume(rdev, &save);
Alex Deucher51535502012-08-30 14:34:30 -04003922 if (!ASIC_IS_NODCE(rdev)) {
3923 /* we need to own VRAM, so turn off the VGA renderer here
3924 * to stop it overwriting our objects */
3925 rv515_vga_render_disable(rdev);
3926 }
Alex Deucherd2800ee2012-03-20 17:18:13 -04003927}
3928
Alex Deucher1c491652013-04-09 12:45:26 -04003929void si_vram_gtt_location(struct radeon_device *rdev,
3930 struct radeon_mc *mc)
Alex Deucherd2800ee2012-03-20 17:18:13 -04003931{
3932 if (mc->mc_vram_size > 0xFFC0000000ULL) {
3933 /* leave room for at least 1024M GTT */
3934 dev_warn(rdev->dev, "limiting VRAM\n");
3935 mc->real_vram_size = 0xFFC0000000ULL;
3936 mc->mc_vram_size = 0xFFC0000000ULL;
3937 }
Alex Deucher9ed8b1f2013-04-08 11:13:01 -04003938 radeon_vram_location(rdev, &rdev->mc, 0);
Alex Deucherd2800ee2012-03-20 17:18:13 -04003939 rdev->mc.gtt_base_align = 0;
Alex Deucher9ed8b1f2013-04-08 11:13:01 -04003940 radeon_gtt_location(rdev, mc);
Alex Deucherd2800ee2012-03-20 17:18:13 -04003941}
3942
3943static int si_mc_init(struct radeon_device *rdev)
3944{
3945 u32 tmp;
3946 int chansize, numchan;
3947
3948 /* Get VRAM informations */
3949 rdev->mc.vram_is_ddr = true;
3950 tmp = RREG32(MC_ARB_RAMCFG);
3951 if (tmp & CHANSIZE_OVERRIDE) {
3952 chansize = 16;
3953 } else if (tmp & CHANSIZE_MASK) {
3954 chansize = 64;
3955 } else {
3956 chansize = 32;
3957 }
3958 tmp = RREG32(MC_SHARED_CHMAP);
3959 switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
3960 case 0:
3961 default:
3962 numchan = 1;
3963 break;
3964 case 1:
3965 numchan = 2;
3966 break;
3967 case 2:
3968 numchan = 4;
3969 break;
3970 case 3:
3971 numchan = 8;
3972 break;
3973 case 4:
3974 numchan = 3;
3975 break;
3976 case 5:
3977 numchan = 6;
3978 break;
3979 case 6:
3980 numchan = 10;
3981 break;
3982 case 7:
3983 numchan = 12;
3984 break;
3985 case 8:
3986 numchan = 16;
3987 break;
3988 }
3989 rdev->mc.vram_width = numchan * chansize;
3990 /* Could aper size report 0 ? */
3991 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
3992 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
3993 /* size in MB on si */
Alex Deucher0ca223b2013-12-03 09:24:30 -05003994 tmp = RREG32(CONFIG_MEMSIZE);
3995 /* some boards may have garbage in the upper 16 bits */
3996 if (tmp & 0xffff0000) {
3997 DRM_INFO("Probable bad vram size: 0x%08x\n", tmp);
3998 if (tmp & 0xffff)
3999 tmp &= 0xffff;
4000 }
4001 rdev->mc.mc_vram_size = tmp * 1024ULL * 1024ULL;
4002 rdev->mc.real_vram_size = rdev->mc.mc_vram_size;
Alex Deucherd2800ee2012-03-20 17:18:13 -04004003 rdev->mc.visible_vram_size = rdev->mc.aper_size;
4004 si_vram_gtt_location(rdev, &rdev->mc);
4005 radeon_update_bandwidth_info(rdev);
4006
4007 return 0;
4008}
4009
4010/*
4011 * GART
4012 */
4013void si_pcie_gart_tlb_flush(struct radeon_device *rdev)
4014{
4015 /* flush hdp cache */
4016 WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
4017
4018 /* bits 0-15 are the VM contexts0-15 */
4019 WREG32(VM_INVALIDATE_REQUEST, 1);
4020}
4021
Lauri Kasanen1109ca02012-08-31 13:43:50 -04004022static int si_pcie_gart_enable(struct radeon_device *rdev)
Alex Deucherd2800ee2012-03-20 17:18:13 -04004023{
4024 int r, i;
4025
4026 if (rdev->gart.robj == NULL) {
4027 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
4028 return -EINVAL;
4029 }
4030 r = radeon_gart_table_vram_pin(rdev);
4031 if (r)
4032 return r;
4033 radeon_gart_restore(rdev);
4034 /* Setup TLB control */
4035 WREG32(MC_VM_MX_L1_TLB_CNTL,
4036 (0xA << 7) |
4037 ENABLE_L1_TLB |
4038 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
4039 ENABLE_ADVANCED_DRIVER_MODEL |
4040 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
4041 /* Setup L2 cache */
4042 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
4043 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
4044 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
4045 EFFECTIVE_L2_QUEUE_SIZE(7) |
4046 CONTEXT1_IDENTITY_ACCESS_MODE(1));
4047 WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
4048 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
4049 L2_CACHE_BIGK_FRAGMENT_SIZE(0));
4050 /* setup context0 */
4051 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
4052 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
4053 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
4054 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
4055 (u32)(rdev->dummy_page.addr >> 12));
4056 WREG32(VM_CONTEXT0_CNTL2, 0);
4057 WREG32(VM_CONTEXT0_CNTL, (ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
4058 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT));
4059
4060 WREG32(0x15D4, 0);
4061 WREG32(0x15D8, 0);
4062 WREG32(0x15DC, 0);
4063
4064 /* empty context1-15 */
Alex Deucherd2800ee2012-03-20 17:18:13 -04004065 /* set vm size, must be a multiple of 4 */
4066 WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
Alex Deucherc21b3282012-06-28 17:53:07 -04004067 WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn);
Alex Deucher23d4f1f2012-10-08 09:45:46 -04004068 /* Assign the pt base to something valid for now; the pts used for
4069 * the VMs are determined by the application and setup and assigned
4070 * on the fly in the vm part of radeon_gart.c
4071 */
Alex Deucherd2800ee2012-03-20 17:18:13 -04004072 for (i = 1; i < 16; i++) {
4073 if (i < 8)
4074 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
4075 rdev->gart.table_addr >> 12);
4076 else
4077 WREG32(VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2),
4078 rdev->gart.table_addr >> 12);
4079 }
4080
4081 /* enable context1-15 */
4082 WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
4083 (u32)(rdev->dummy_page.addr >> 12));
Christian Königae133a12012-09-18 15:30:44 -04004084 WREG32(VM_CONTEXT1_CNTL2, 4);
Dmitry Cherkasovfa87e622012-09-17 19:36:19 +02004085 WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
Christian Königae133a12012-09-18 15:30:44 -04004086 RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
4087 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
4088 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
4089 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
4090 PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
4091 PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
4092 VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
4093 VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
4094 READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
4095 READ_PROTECTION_FAULT_ENABLE_DEFAULT |
4096 WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
4097 WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
Alex Deucherd2800ee2012-03-20 17:18:13 -04004098
4099 si_pcie_gart_tlb_flush(rdev);
4100 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
4101 (unsigned)(rdev->mc.gtt_size >> 20),
4102 (unsigned long long)rdev->gart.table_addr);
4103 rdev->gart.ready = true;
4104 return 0;
4105}
4106
Lauri Kasanen1109ca02012-08-31 13:43:50 -04004107static void si_pcie_gart_disable(struct radeon_device *rdev)
Alex Deucherd2800ee2012-03-20 17:18:13 -04004108{
4109 /* Disable all tables */
4110 WREG32(VM_CONTEXT0_CNTL, 0);
4111 WREG32(VM_CONTEXT1_CNTL, 0);
4112 /* Setup TLB control */
4113 WREG32(MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE_NOT_IN_SYS |
4114 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
4115 /* Setup L2 cache */
4116 WREG32(VM_L2_CNTL, ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
4117 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
4118 EFFECTIVE_L2_QUEUE_SIZE(7) |
4119 CONTEXT1_IDENTITY_ACCESS_MODE(1));
4120 WREG32(VM_L2_CNTL2, 0);
4121 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
4122 L2_CACHE_BIGK_FRAGMENT_SIZE(0));
4123 radeon_gart_table_vram_unpin(rdev);
4124}
4125
Lauri Kasanen1109ca02012-08-31 13:43:50 -04004126static void si_pcie_gart_fini(struct radeon_device *rdev)
Alex Deucherd2800ee2012-03-20 17:18:13 -04004127{
4128 si_pcie_gart_disable(rdev);
4129 radeon_gart_table_vram_free(rdev);
4130 radeon_gart_fini(rdev);
4131}
4132
Alex Deucher498dd8b2012-03-20 17:18:15 -04004133/* vm parser */
4134static bool si_vm_reg_valid(u32 reg)
4135{
4136 /* context regs are fine */
4137 if (reg >= 0x28000)
4138 return true;
4139
4140 /* check config regs */
4141 switch (reg) {
4142 case GRBM_GFX_INDEX:
Alex Deucherf418b882012-11-08 10:13:24 -05004143 case CP_STRMOUT_CNTL:
Alex Deucher498dd8b2012-03-20 17:18:15 -04004144 case VGT_VTX_VECT_EJECT_REG:
4145 case VGT_CACHE_INVALIDATION:
4146 case VGT_ESGS_RING_SIZE:
4147 case VGT_GSVS_RING_SIZE:
4148 case VGT_GS_VERTEX_REUSE:
4149 case VGT_PRIMITIVE_TYPE:
4150 case VGT_INDEX_TYPE:
4151 case VGT_NUM_INDICES:
4152 case VGT_NUM_INSTANCES:
4153 case VGT_TF_RING_SIZE:
4154 case VGT_HS_OFFCHIP_PARAM:
4155 case VGT_TF_MEMORY_BASE:
4156 case PA_CL_ENHANCE:
4157 case PA_SU_LINE_STIPPLE_VALUE:
4158 case PA_SC_LINE_STIPPLE_STATE:
4159 case PA_SC_ENHANCE:
4160 case SQC_CACHES:
4161 case SPI_STATIC_THREAD_MGMT_1:
4162 case SPI_STATIC_THREAD_MGMT_2:
4163 case SPI_STATIC_THREAD_MGMT_3:
4164 case SPI_PS_MAX_WAVE_ID:
4165 case SPI_CONFIG_CNTL:
4166 case SPI_CONFIG_CNTL_1:
4167 case TA_CNTL_AUX:
4168 return true;
4169 default:
4170 DRM_ERROR("Invalid register 0x%x in CS\n", reg);
4171 return false;
4172 }
4173}
4174
4175static int si_vm_packet3_ce_check(struct radeon_device *rdev,
4176 u32 *ib, struct radeon_cs_packet *pkt)
4177{
4178 switch (pkt->opcode) {
4179 case PACKET3_NOP:
4180 case PACKET3_SET_BASE:
4181 case PACKET3_SET_CE_DE_COUNTERS:
4182 case PACKET3_LOAD_CONST_RAM:
4183 case PACKET3_WRITE_CONST_RAM:
4184 case PACKET3_WRITE_CONST_RAM_OFFSET:
4185 case PACKET3_DUMP_CONST_RAM:
4186 case PACKET3_INCREMENT_CE_COUNTER:
4187 case PACKET3_WAIT_ON_DE_COUNTER:
4188 case PACKET3_CE_WRITE:
4189 break;
4190 default:
4191 DRM_ERROR("Invalid CE packet3: 0x%x\n", pkt->opcode);
4192 return -EINVAL;
4193 }
4194 return 0;
4195}
4196
Tom Stellarde5b9e752013-08-16 17:47:39 -04004197static int si_vm_packet3_cp_dma_check(u32 *ib, u32 idx)
4198{
4199 u32 start_reg, reg, i;
4200 u32 command = ib[idx + 4];
4201 u32 info = ib[idx + 1];
4202 u32 idx_value = ib[idx];
4203 if (command & PACKET3_CP_DMA_CMD_SAS) {
4204 /* src address space is register */
4205 if (((info & 0x60000000) >> 29) == 0) {
4206 start_reg = idx_value << 2;
4207 if (command & PACKET3_CP_DMA_CMD_SAIC) {
4208 reg = start_reg;
4209 if (!si_vm_reg_valid(reg)) {
4210 DRM_ERROR("CP DMA Bad SRC register\n");
4211 return -EINVAL;
4212 }
4213 } else {
4214 for (i = 0; i < (command & 0x1fffff); i++) {
4215 reg = start_reg + (4 * i);
4216 if (!si_vm_reg_valid(reg)) {
4217 DRM_ERROR("CP DMA Bad SRC register\n");
4218 return -EINVAL;
4219 }
4220 }
4221 }
4222 }
4223 }
4224 if (command & PACKET3_CP_DMA_CMD_DAS) {
4225 /* dst address space is register */
4226 if (((info & 0x00300000) >> 20) == 0) {
4227 start_reg = ib[idx + 2];
4228 if (command & PACKET3_CP_DMA_CMD_DAIC) {
4229 reg = start_reg;
4230 if (!si_vm_reg_valid(reg)) {
4231 DRM_ERROR("CP DMA Bad DST register\n");
4232 return -EINVAL;
4233 }
4234 } else {
4235 for (i = 0; i < (command & 0x1fffff); i++) {
4236 reg = start_reg + (4 * i);
4237 if (!si_vm_reg_valid(reg)) {
4238 DRM_ERROR("CP DMA Bad DST register\n");
4239 return -EINVAL;
4240 }
4241 }
4242 }
4243 }
4244 }
4245 return 0;
4246}
4247
Alex Deucher498dd8b2012-03-20 17:18:15 -04004248static int si_vm_packet3_gfx_check(struct radeon_device *rdev,
4249 u32 *ib, struct radeon_cs_packet *pkt)
4250{
Tom Stellarde5b9e752013-08-16 17:47:39 -04004251 int r;
Alex Deucher498dd8b2012-03-20 17:18:15 -04004252 u32 idx = pkt->idx + 1;
4253 u32 idx_value = ib[idx];
4254 u32 start_reg, end_reg, reg, i;
4255
4256 switch (pkt->opcode) {
4257 case PACKET3_NOP:
4258 case PACKET3_SET_BASE:
4259 case PACKET3_CLEAR_STATE:
4260 case PACKET3_INDEX_BUFFER_SIZE:
4261 case PACKET3_DISPATCH_DIRECT:
4262 case PACKET3_DISPATCH_INDIRECT:
4263 case PACKET3_ALLOC_GDS:
4264 case PACKET3_WRITE_GDS_RAM:
4265 case PACKET3_ATOMIC_GDS:
4266 case PACKET3_ATOMIC:
4267 case PACKET3_OCCLUSION_QUERY:
4268 case PACKET3_SET_PREDICATION:
4269 case PACKET3_COND_EXEC:
4270 case PACKET3_PRED_EXEC:
4271 case PACKET3_DRAW_INDIRECT:
4272 case PACKET3_DRAW_INDEX_INDIRECT:
4273 case PACKET3_INDEX_BASE:
4274 case PACKET3_DRAW_INDEX_2:
4275 case PACKET3_CONTEXT_CONTROL:
4276 case PACKET3_INDEX_TYPE:
4277 case PACKET3_DRAW_INDIRECT_MULTI:
4278 case PACKET3_DRAW_INDEX_AUTO:
4279 case PACKET3_DRAW_INDEX_IMMD:
4280 case PACKET3_NUM_INSTANCES:
4281 case PACKET3_DRAW_INDEX_MULTI_AUTO:
4282 case PACKET3_STRMOUT_BUFFER_UPDATE:
4283 case PACKET3_DRAW_INDEX_OFFSET_2:
4284 case PACKET3_DRAW_INDEX_MULTI_ELEMENT:
4285 case PACKET3_DRAW_INDEX_INDIRECT_MULTI:
4286 case PACKET3_MPEG_INDEX:
4287 case PACKET3_WAIT_REG_MEM:
4288 case PACKET3_MEM_WRITE:
4289 case PACKET3_PFP_SYNC_ME:
4290 case PACKET3_SURFACE_SYNC:
4291 case PACKET3_EVENT_WRITE:
4292 case PACKET3_EVENT_WRITE_EOP:
4293 case PACKET3_EVENT_WRITE_EOS:
4294 case PACKET3_SET_CONTEXT_REG:
4295 case PACKET3_SET_CONTEXT_REG_INDIRECT:
4296 case PACKET3_SET_SH_REG:
4297 case PACKET3_SET_SH_REG_OFFSET:
4298 case PACKET3_INCREMENT_DE_COUNTER:
4299 case PACKET3_WAIT_ON_CE_COUNTER:
4300 case PACKET3_WAIT_ON_AVAIL_BUFFER:
4301 case PACKET3_ME_WRITE:
4302 break;
4303 case PACKET3_COPY_DATA:
4304 if ((idx_value & 0xf00) == 0) {
4305 reg = ib[idx + 3] * 4;
4306 if (!si_vm_reg_valid(reg))
4307 return -EINVAL;
4308 }
4309 break;
4310 case PACKET3_WRITE_DATA:
4311 if ((idx_value & 0xf00) == 0) {
4312 start_reg = ib[idx + 1] * 4;
4313 if (idx_value & 0x10000) {
4314 if (!si_vm_reg_valid(start_reg))
4315 return -EINVAL;
4316 } else {
4317 for (i = 0; i < (pkt->count - 2); i++) {
4318 reg = start_reg + (4 * i);
4319 if (!si_vm_reg_valid(reg))
4320 return -EINVAL;
4321 }
4322 }
4323 }
4324 break;
4325 case PACKET3_COND_WRITE:
4326 if (idx_value & 0x100) {
4327 reg = ib[idx + 5] * 4;
4328 if (!si_vm_reg_valid(reg))
4329 return -EINVAL;
4330 }
4331 break;
4332 case PACKET3_COPY_DW:
4333 if (idx_value & 0x2) {
4334 reg = ib[idx + 3] * 4;
4335 if (!si_vm_reg_valid(reg))
4336 return -EINVAL;
4337 }
4338 break;
4339 case PACKET3_SET_CONFIG_REG:
4340 start_reg = (idx_value << 2) + PACKET3_SET_CONFIG_REG_START;
4341 end_reg = 4 * pkt->count + start_reg - 4;
4342 if ((start_reg < PACKET3_SET_CONFIG_REG_START) ||
4343 (start_reg >= PACKET3_SET_CONFIG_REG_END) ||
4344 (end_reg >= PACKET3_SET_CONFIG_REG_END)) {
4345 DRM_ERROR("bad PACKET3_SET_CONFIG_REG\n");
4346 return -EINVAL;
4347 }
4348 for (i = 0; i < pkt->count; i++) {
4349 reg = start_reg + (4 * i);
4350 if (!si_vm_reg_valid(reg))
4351 return -EINVAL;
4352 }
4353 break;
Alex Deucher5aa709b2012-12-03 19:42:37 -05004354 case PACKET3_CP_DMA:
Tom Stellarde5b9e752013-08-16 17:47:39 -04004355 r = si_vm_packet3_cp_dma_check(ib, idx);
4356 if (r)
4357 return r;
Alex Deucher5aa709b2012-12-03 19:42:37 -05004358 break;
Alex Deucher498dd8b2012-03-20 17:18:15 -04004359 default:
4360 DRM_ERROR("Invalid GFX packet3: 0x%x\n", pkt->opcode);
4361 return -EINVAL;
4362 }
4363 return 0;
4364}
4365
4366static int si_vm_packet3_compute_check(struct radeon_device *rdev,
4367 u32 *ib, struct radeon_cs_packet *pkt)
4368{
Tom Stellarde5b9e752013-08-16 17:47:39 -04004369 int r;
Alex Deucher498dd8b2012-03-20 17:18:15 -04004370 u32 idx = pkt->idx + 1;
4371 u32 idx_value = ib[idx];
4372 u32 start_reg, reg, i;
4373
4374 switch (pkt->opcode) {
4375 case PACKET3_NOP:
4376 case PACKET3_SET_BASE:
4377 case PACKET3_CLEAR_STATE:
4378 case PACKET3_DISPATCH_DIRECT:
4379 case PACKET3_DISPATCH_INDIRECT:
4380 case PACKET3_ALLOC_GDS:
4381 case PACKET3_WRITE_GDS_RAM:
4382 case PACKET3_ATOMIC_GDS:
4383 case PACKET3_ATOMIC:
4384 case PACKET3_OCCLUSION_QUERY:
4385 case PACKET3_SET_PREDICATION:
4386 case PACKET3_COND_EXEC:
4387 case PACKET3_PRED_EXEC:
4388 case PACKET3_CONTEXT_CONTROL:
4389 case PACKET3_STRMOUT_BUFFER_UPDATE:
4390 case PACKET3_WAIT_REG_MEM:
4391 case PACKET3_MEM_WRITE:
4392 case PACKET3_PFP_SYNC_ME:
4393 case PACKET3_SURFACE_SYNC:
4394 case PACKET3_EVENT_WRITE:
4395 case PACKET3_EVENT_WRITE_EOP:
4396 case PACKET3_EVENT_WRITE_EOS:
4397 case PACKET3_SET_CONTEXT_REG:
4398 case PACKET3_SET_CONTEXT_REG_INDIRECT:
4399 case PACKET3_SET_SH_REG:
4400 case PACKET3_SET_SH_REG_OFFSET:
4401 case PACKET3_INCREMENT_DE_COUNTER:
4402 case PACKET3_WAIT_ON_CE_COUNTER:
4403 case PACKET3_WAIT_ON_AVAIL_BUFFER:
4404 case PACKET3_ME_WRITE:
4405 break;
4406 case PACKET3_COPY_DATA:
4407 if ((idx_value & 0xf00) == 0) {
4408 reg = ib[idx + 3] * 4;
4409 if (!si_vm_reg_valid(reg))
4410 return -EINVAL;
4411 }
4412 break;
4413 case PACKET3_WRITE_DATA:
4414 if ((idx_value & 0xf00) == 0) {
4415 start_reg = ib[idx + 1] * 4;
4416 if (idx_value & 0x10000) {
4417 if (!si_vm_reg_valid(start_reg))
4418 return -EINVAL;
4419 } else {
4420 for (i = 0; i < (pkt->count - 2); i++) {
4421 reg = start_reg + (4 * i);
4422 if (!si_vm_reg_valid(reg))
4423 return -EINVAL;
4424 }
4425 }
4426 }
4427 break;
4428 case PACKET3_COND_WRITE:
4429 if (idx_value & 0x100) {
4430 reg = ib[idx + 5] * 4;
4431 if (!si_vm_reg_valid(reg))
4432 return -EINVAL;
4433 }
4434 break;
4435 case PACKET3_COPY_DW:
4436 if (idx_value & 0x2) {
4437 reg = ib[idx + 3] * 4;
4438 if (!si_vm_reg_valid(reg))
4439 return -EINVAL;
4440 }
4441 break;
Tom Stellarde5b9e752013-08-16 17:47:39 -04004442 case PACKET3_CP_DMA:
4443 r = si_vm_packet3_cp_dma_check(ib, idx);
4444 if (r)
4445 return r;
4446 break;
Alex Deucher498dd8b2012-03-20 17:18:15 -04004447 default:
4448 DRM_ERROR("Invalid Compute packet3: 0x%x\n", pkt->opcode);
4449 return -EINVAL;
4450 }
4451 return 0;
4452}
4453
4454int si_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
4455{
4456 int ret = 0;
4457 u32 idx = 0;
4458 struct radeon_cs_packet pkt;
4459
4460 do {
4461 pkt.idx = idx;
Ilija Hadzic4e872ae2013-01-02 18:27:48 -05004462 pkt.type = RADEON_CP_PACKET_GET_TYPE(ib->ptr[idx]);
4463 pkt.count = RADEON_CP_PACKET_GET_COUNT(ib->ptr[idx]);
Alex Deucher498dd8b2012-03-20 17:18:15 -04004464 pkt.one_reg_wr = 0;
4465 switch (pkt.type) {
Ilija Hadzic4e872ae2013-01-02 18:27:48 -05004466 case RADEON_PACKET_TYPE0:
Alex Deucher498dd8b2012-03-20 17:18:15 -04004467 dev_err(rdev->dev, "Packet0 not allowed!\n");
4468 ret = -EINVAL;
4469 break;
Ilija Hadzic4e872ae2013-01-02 18:27:48 -05004470 case RADEON_PACKET_TYPE2:
Alex Deucher498dd8b2012-03-20 17:18:15 -04004471 idx += 1;
4472 break;
Ilija Hadzic4e872ae2013-01-02 18:27:48 -05004473 case RADEON_PACKET_TYPE3:
4474 pkt.opcode = RADEON_CP_PACKET3_GET_OPCODE(ib->ptr[idx]);
Alex Deucher498dd8b2012-03-20 17:18:15 -04004475 if (ib->is_const_ib)
4476 ret = si_vm_packet3_ce_check(rdev, ib->ptr, &pkt);
4477 else {
Christian König876dc9f2012-05-08 14:24:01 +02004478 switch (ib->ring) {
Alex Deucher498dd8b2012-03-20 17:18:15 -04004479 case RADEON_RING_TYPE_GFX_INDEX:
4480 ret = si_vm_packet3_gfx_check(rdev, ib->ptr, &pkt);
4481 break;
4482 case CAYMAN_RING_TYPE_CP1_INDEX:
4483 case CAYMAN_RING_TYPE_CP2_INDEX:
4484 ret = si_vm_packet3_compute_check(rdev, ib->ptr, &pkt);
4485 break;
4486 default:
Christian König876dc9f2012-05-08 14:24:01 +02004487 dev_err(rdev->dev, "Non-PM4 ring %d !\n", ib->ring);
Alex Deucher498dd8b2012-03-20 17:18:15 -04004488 ret = -EINVAL;
4489 break;
4490 }
4491 }
4492 idx += pkt.count + 2;
4493 break;
4494 default:
4495 dev_err(rdev->dev, "Unknown packet type %d !\n", pkt.type);
4496 ret = -EINVAL;
4497 break;
4498 }
4499 if (ret)
4500 break;
4501 } while (idx < ib->length_dw);
4502
4503 return ret;
4504}
4505
Alex Deucherd2800ee2012-03-20 17:18:13 -04004506/*
4507 * vm
4508 */
4509int si_vm_init(struct radeon_device *rdev)
4510{
4511 /* number of VMs */
4512 rdev->vm_manager.nvm = 16;
4513 /* base offset of vram pages */
4514 rdev->vm_manager.vram_base_offset = 0;
4515
4516 return 0;
4517}
4518
4519void si_vm_fini(struct radeon_device *rdev)
4520{
4521}
4522
Alex Deucher82ffd922012-10-02 14:47:46 -04004523/**
Alex Deucherfbf6dc72013-06-13 18:47:58 -04004524 * si_vm_decode_fault - print human readable fault info
4525 *
4526 * @rdev: radeon_device pointer
4527 * @status: VM_CONTEXT1_PROTECTION_FAULT_STATUS register value
4528 * @addr: VM_CONTEXT1_PROTECTION_FAULT_ADDR register value
4529 *
4530 * Print human readable fault information (SI).
4531 */
4532static void si_vm_decode_fault(struct radeon_device *rdev,
4533 u32 status, u32 addr)
4534{
4535 u32 mc_id = (status & MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
4536 u32 vmid = (status & FAULT_VMID_MASK) >> FAULT_VMID_SHIFT;
4537 u32 protections = (status & PROTECTIONS_MASK) >> PROTECTIONS_SHIFT;
4538 char *block;
4539
4540 if (rdev->family == CHIP_TAHITI) {
4541 switch (mc_id) {
4542 case 160:
4543 case 144:
4544 case 96:
4545 case 80:
4546 case 224:
4547 case 208:
4548 case 32:
4549 case 16:
4550 block = "CB";
4551 break;
4552 case 161:
4553 case 145:
4554 case 97:
4555 case 81:
4556 case 225:
4557 case 209:
4558 case 33:
4559 case 17:
4560 block = "CB_FMASK";
4561 break;
4562 case 162:
4563 case 146:
4564 case 98:
4565 case 82:
4566 case 226:
4567 case 210:
4568 case 34:
4569 case 18:
4570 block = "CB_CMASK";
4571 break;
4572 case 163:
4573 case 147:
4574 case 99:
4575 case 83:
4576 case 227:
4577 case 211:
4578 case 35:
4579 case 19:
4580 block = "CB_IMMED";
4581 break;
4582 case 164:
4583 case 148:
4584 case 100:
4585 case 84:
4586 case 228:
4587 case 212:
4588 case 36:
4589 case 20:
4590 block = "DB";
4591 break;
4592 case 165:
4593 case 149:
4594 case 101:
4595 case 85:
4596 case 229:
4597 case 213:
4598 case 37:
4599 case 21:
4600 block = "DB_HTILE";
4601 break;
4602 case 167:
4603 case 151:
4604 case 103:
4605 case 87:
4606 case 231:
4607 case 215:
4608 case 39:
4609 case 23:
4610 block = "DB_STEN";
4611 break;
4612 case 72:
4613 case 68:
4614 case 64:
4615 case 8:
4616 case 4:
4617 case 0:
4618 case 136:
4619 case 132:
4620 case 128:
4621 case 200:
4622 case 196:
4623 case 192:
4624 block = "TC";
4625 break;
4626 case 112:
4627 case 48:
4628 block = "CP";
4629 break;
4630 case 49:
4631 case 177:
4632 case 50:
4633 case 178:
4634 block = "SH";
4635 break;
4636 case 53:
4637 case 190:
4638 block = "VGT";
4639 break;
4640 case 117:
4641 block = "IH";
4642 break;
4643 case 51:
4644 case 115:
4645 block = "RLC";
4646 break;
4647 case 119:
4648 case 183:
4649 block = "DMA0";
4650 break;
4651 case 61:
4652 block = "DMA1";
4653 break;
4654 case 248:
4655 case 120:
4656 block = "HDP";
4657 break;
4658 default:
4659 block = "unknown";
4660 break;
4661 }
4662 } else {
4663 switch (mc_id) {
4664 case 32:
4665 case 16:
4666 case 96:
4667 case 80:
4668 case 160:
4669 case 144:
4670 case 224:
4671 case 208:
4672 block = "CB";
4673 break;
4674 case 33:
4675 case 17:
4676 case 97:
4677 case 81:
4678 case 161:
4679 case 145:
4680 case 225:
4681 case 209:
4682 block = "CB_FMASK";
4683 break;
4684 case 34:
4685 case 18:
4686 case 98:
4687 case 82:
4688 case 162:
4689 case 146:
4690 case 226:
4691 case 210:
4692 block = "CB_CMASK";
4693 break;
4694 case 35:
4695 case 19:
4696 case 99:
4697 case 83:
4698 case 163:
4699 case 147:
4700 case 227:
4701 case 211:
4702 block = "CB_IMMED";
4703 break;
4704 case 36:
4705 case 20:
4706 case 100:
4707 case 84:
4708 case 164:
4709 case 148:
4710 case 228:
4711 case 212:
4712 block = "DB";
4713 break;
4714 case 37:
4715 case 21:
4716 case 101:
4717 case 85:
4718 case 165:
4719 case 149:
4720 case 229:
4721 case 213:
4722 block = "DB_HTILE";
4723 break;
4724 case 39:
4725 case 23:
4726 case 103:
4727 case 87:
4728 case 167:
4729 case 151:
4730 case 231:
4731 case 215:
4732 block = "DB_STEN";
4733 break;
4734 case 72:
4735 case 68:
4736 case 8:
4737 case 4:
4738 case 136:
4739 case 132:
4740 case 200:
4741 case 196:
4742 block = "TC";
4743 break;
4744 case 112:
4745 case 48:
4746 block = "CP";
4747 break;
4748 case 49:
4749 case 177:
4750 case 50:
4751 case 178:
4752 block = "SH";
4753 break;
4754 case 53:
4755 block = "VGT";
4756 break;
4757 case 117:
4758 block = "IH";
4759 break;
4760 case 51:
4761 case 115:
4762 block = "RLC";
4763 break;
4764 case 119:
4765 case 183:
4766 block = "DMA0";
4767 break;
4768 case 61:
4769 block = "DMA1";
4770 break;
4771 case 248:
4772 case 120:
4773 block = "HDP";
4774 break;
4775 default:
4776 block = "unknown";
4777 break;
4778 }
4779 }
4780
4781 printk("VM fault (0x%02x, vmid %d) at page %u, %s from %s (%d)\n",
4782 protections, vmid, addr,
4783 (status & MEMORY_CLIENT_RW_MASK) ? "write" : "read",
4784 block, mc_id);
4785}
4786
Alex Deucher498522b2012-10-02 14:43:38 -04004787void si_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
Alex Deucherd2800ee2012-03-20 17:18:13 -04004788{
Alex Deucher498522b2012-10-02 14:43:38 -04004789 struct radeon_ring *ring = &rdev->ring[ridx];
Alex Deucherd2800ee2012-03-20 17:18:13 -04004790
Christian Königee60e292012-08-09 16:21:08 +02004791 if (vm == NULL)
Alex Deucherd2800ee2012-03-20 17:18:13 -04004792 return;
4793
Alex Deucher76c44f22012-10-02 14:39:18 -04004794 /* write new base address */
4795 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
4796 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
4797 WRITE_DATA_DST_SEL(0)));
4798
Christian Königee60e292012-08-09 16:21:08 +02004799 if (vm->id < 8) {
Alex Deucher76c44f22012-10-02 14:39:18 -04004800 radeon_ring_write(ring,
4801 (VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2);
Christian Königee60e292012-08-09 16:21:08 +02004802 } else {
Alex Deucher76c44f22012-10-02 14:39:18 -04004803 radeon_ring_write(ring,
4804 (VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm->id - 8) << 2)) >> 2);
Christian Königee60e292012-08-09 16:21:08 +02004805 }
Alex Deucher76c44f22012-10-02 14:39:18 -04004806 radeon_ring_write(ring, 0);
Dmitry Cherkasovfa87e622012-09-17 19:36:19 +02004807 radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
Christian Königee60e292012-08-09 16:21:08 +02004808
Alex Deucherd2800ee2012-03-20 17:18:13 -04004809 /* flush hdp cache */
Alex Deucher76c44f22012-10-02 14:39:18 -04004810 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
4811 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
4812 WRITE_DATA_DST_SEL(0)));
4813 radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);
4814 radeon_ring_write(ring, 0);
Christian Königee60e292012-08-09 16:21:08 +02004815 radeon_ring_write(ring, 0x1);
4816
Alex Deucherd2800ee2012-03-20 17:18:13 -04004817 /* bits 0-15 are the VM contexts0-15 */
Alex Deucher76c44f22012-10-02 14:39:18 -04004818 radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
4819 radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
4820 WRITE_DATA_DST_SEL(0)));
4821 radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
4822 radeon_ring_write(ring, 0);
Alex Deucher498522b2012-10-02 14:43:38 -04004823 radeon_ring_write(ring, 1 << vm->id);
Christian König58f8cf52012-10-22 17:42:35 +02004824
4825 /* sync PFP to ME, otherwise we might get invalid PFP reads */
4826 radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
4827 radeon_ring_write(ring, 0x0);
Alex Deucherd2800ee2012-03-20 17:18:13 -04004828}
4829
Alex Deucher347e7592012-03-20 17:18:21 -04004830/*
Alex Deucherf8f84ac2013-03-07 12:56:35 -05004831 * Power and clock gating
4832 */
4833static void si_wait_for_rlc_serdes(struct radeon_device *rdev)
4834{
4835 int i;
4836
4837 for (i = 0; i < rdev->usec_timeout; i++) {
4838 if (RREG32(RLC_SERDES_MASTER_BUSY_0) == 0)
4839 break;
4840 udelay(1);
4841 }
4842
4843 for (i = 0; i < rdev->usec_timeout; i++) {
4844 if (RREG32(RLC_SERDES_MASTER_BUSY_1) == 0)
4845 break;
4846 udelay(1);
4847 }
4848}
4849
4850static void si_enable_gui_idle_interrupt(struct radeon_device *rdev,
4851 bool enable)
4852{
4853 u32 tmp = RREG32(CP_INT_CNTL_RING0);
4854 u32 mask;
4855 int i;
4856
4857 if (enable)
4858 tmp |= (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
4859 else
4860 tmp &= ~(CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
4861 WREG32(CP_INT_CNTL_RING0, tmp);
4862
4863 if (!enable) {
4864 /* read a gfx register */
4865 tmp = RREG32(DB_DEPTH_INFO);
4866
4867 mask = RLC_BUSY_STATUS | GFX_POWER_STATUS | GFX_CLOCK_STATUS | GFX_LS_STATUS;
4868 for (i = 0; i < rdev->usec_timeout; i++) {
4869 if ((RREG32(RLC_STAT) & mask) == (GFX_CLOCK_STATUS | GFX_POWER_STATUS))
4870 break;
4871 udelay(1);
4872 }
4873 }
4874}
4875
4876static void si_set_uvd_dcm(struct radeon_device *rdev,
4877 bool sw_mode)
4878{
4879 u32 tmp, tmp2;
4880
4881 tmp = RREG32(UVD_CGC_CTRL);
4882 tmp &= ~(CLK_OD_MASK | CG_DT_MASK);
4883 tmp |= DCM | CG_DT(1) | CLK_OD(4);
4884
4885 if (sw_mode) {
4886 tmp &= ~0x7ffff800;
4887 tmp2 = DYN_OR_EN | DYN_RR_EN | G_DIV_ID(7);
4888 } else {
4889 tmp |= 0x7ffff800;
4890 tmp2 = 0;
4891 }
4892
4893 WREG32(UVD_CGC_CTRL, tmp);
4894 WREG32_UVD_CTX(UVD_CGC_CTRL2, tmp2);
4895}
4896
Alex Deucher22c775c2013-07-23 09:41:05 -04004897void si_init_uvd_internal_cg(struct radeon_device *rdev)
Alex Deucherf8f84ac2013-03-07 12:56:35 -05004898{
4899 bool hw_mode = true;
4900
4901 if (hw_mode) {
4902 si_set_uvd_dcm(rdev, false);
4903 } else {
4904 u32 tmp = RREG32(UVD_CGC_CTRL);
4905 tmp &= ~DCM;
4906 WREG32(UVD_CGC_CTRL, tmp);
4907 }
4908}
4909
4910static u32 si_halt_rlc(struct radeon_device *rdev)
4911{
4912 u32 data, orig;
4913
4914 orig = data = RREG32(RLC_CNTL);
4915
4916 if (data & RLC_ENABLE) {
4917 data &= ~RLC_ENABLE;
4918 WREG32(RLC_CNTL, data);
4919
4920 si_wait_for_rlc_serdes(rdev);
4921 }
4922
4923 return orig;
4924}
4925
4926static void si_update_rlc(struct radeon_device *rdev, u32 rlc)
4927{
4928 u32 tmp;
4929
4930 tmp = RREG32(RLC_CNTL);
4931 if (tmp != rlc)
4932 WREG32(RLC_CNTL, rlc);
4933}
4934
4935static void si_enable_dma_pg(struct radeon_device *rdev, bool enable)
4936{
4937 u32 data, orig;
4938
4939 orig = data = RREG32(DMA_PG);
Alex Deuchere16866e2013-08-08 19:34:07 -04004940 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_SDMA))
Alex Deucherf8f84ac2013-03-07 12:56:35 -05004941 data |= PG_CNTL_ENABLE;
4942 else
4943 data &= ~PG_CNTL_ENABLE;
4944 if (orig != data)
4945 WREG32(DMA_PG, data);
4946}
4947
4948static void si_init_dma_pg(struct radeon_device *rdev)
4949{
4950 u32 tmp;
4951
4952 WREG32(DMA_PGFSM_WRITE, 0x00002000);
4953 WREG32(DMA_PGFSM_CONFIG, 0x100010ff);
4954
4955 for (tmp = 0; tmp < 5; tmp++)
4956 WREG32(DMA_PGFSM_WRITE, 0);
4957}
4958
4959static void si_enable_gfx_cgpg(struct radeon_device *rdev,
4960 bool enable)
4961{
4962 u32 tmp;
4963
Alex Deucher2b19d172013-09-04 16:58:29 -04004964 if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG)) {
Alex Deucherf8f84ac2013-03-07 12:56:35 -05004965 tmp = RLC_PUD(0x10) | RLC_PDD(0x10) | RLC_TTPD(0x10) | RLC_MSD(0x10);
4966 WREG32(RLC_TTOP_D, tmp);
4967
4968 tmp = RREG32(RLC_PG_CNTL);
4969 tmp |= GFX_PG_ENABLE;
4970 WREG32(RLC_PG_CNTL, tmp);
4971
4972 tmp = RREG32(RLC_AUTO_PG_CTRL);
4973 tmp |= AUTO_PG_EN;
4974 WREG32(RLC_AUTO_PG_CTRL, tmp);
4975 } else {
4976 tmp = RREG32(RLC_AUTO_PG_CTRL);
4977 tmp &= ~AUTO_PG_EN;
4978 WREG32(RLC_AUTO_PG_CTRL, tmp);
4979
4980 tmp = RREG32(DB_RENDER_CONTROL);
4981 }
4982}
4983
4984static void si_init_gfx_cgpg(struct radeon_device *rdev)
4985{
4986 u32 tmp;
4987
4988 WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
4989
4990 tmp = RREG32(RLC_PG_CNTL);
4991 tmp |= GFX_PG_SRC;
4992 WREG32(RLC_PG_CNTL, tmp);
4993
4994 WREG32(RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
4995
4996 tmp = RREG32(RLC_AUTO_PG_CTRL);
4997
4998 tmp &= ~GRBM_REG_SGIT_MASK;
4999 tmp |= GRBM_REG_SGIT(0x700);
5000 tmp &= ~PG_AFTER_GRBM_REG_ST_MASK;
5001 WREG32(RLC_AUTO_PG_CTRL, tmp);
5002}
5003
Alex Deucherba190312013-04-17 16:27:40 -04005004static u32 si_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh)
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005005{
5006 u32 mask = 0, tmp, tmp1;
5007 int i;
5008
5009 si_select_se_sh(rdev, se, sh);
5010 tmp = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
5011 tmp1 = RREG32(GC_USER_SHADER_ARRAY_CONFIG);
5012 si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
5013
5014 tmp &= 0xffff0000;
5015
5016 tmp |= tmp1;
5017 tmp >>= 16;
5018
5019 for (i = 0; i < rdev->config.si.max_cu_per_sh; i ++) {
5020 mask <<= 1;
5021 mask |= 1;
5022 }
5023
5024 return (~tmp) & mask;
5025}
5026
5027static void si_init_ao_cu_mask(struct radeon_device *rdev)
5028{
5029 u32 i, j, k, active_cu_number = 0;
5030 u32 mask, counter, cu_bitmap;
5031 u32 tmp = 0;
5032
5033 for (i = 0; i < rdev->config.si.max_shader_engines; i++) {
5034 for (j = 0; j < rdev->config.si.max_sh_per_se; j++) {
5035 mask = 1;
5036 cu_bitmap = 0;
5037 counter = 0;
5038 for (k = 0; k < rdev->config.si.max_cu_per_sh; k++) {
Alex Deucherba190312013-04-17 16:27:40 -04005039 if (si_get_cu_active_bitmap(rdev, i, j) & mask) {
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005040 if (counter < 2)
5041 cu_bitmap |= mask;
5042 counter++;
5043 }
5044 mask <<= 1;
5045 }
5046
5047 active_cu_number += counter;
5048 tmp |= (cu_bitmap << (i * 16 + j * 8));
5049 }
5050 }
5051
5052 WREG32(RLC_PG_AO_CU_MASK, tmp);
5053
5054 tmp = RREG32(RLC_MAX_PG_CU);
5055 tmp &= ~MAX_PU_CU_MASK;
5056 tmp |= MAX_PU_CU(active_cu_number);
5057 WREG32(RLC_MAX_PG_CU, tmp);
5058}
5059
5060static void si_enable_cgcg(struct radeon_device *rdev,
5061 bool enable)
5062{
5063 u32 data, orig, tmp;
5064
5065 orig = data = RREG32(RLC_CGCG_CGLS_CTRL);
5066
Alex Deuchere16866e2013-08-08 19:34:07 -04005067 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGCG)) {
Alex Deucher5594a552013-08-15 16:20:26 -04005068 si_enable_gui_idle_interrupt(rdev, true);
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005069
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005070 WREG32(RLC_GCPM_GENERAL_3, 0x00000080);
5071
5072 tmp = si_halt_rlc(rdev);
5073
5074 WREG32(RLC_SERDES_WR_MASTER_MASK_0, 0xffffffff);
5075 WREG32(RLC_SERDES_WR_MASTER_MASK_1, 0xffffffff);
5076 WREG32(RLC_SERDES_WR_CTRL, 0x00b000ff);
5077
5078 si_wait_for_rlc_serdes(rdev);
5079
5080 si_update_rlc(rdev, tmp);
5081
5082 WREG32(RLC_SERDES_WR_CTRL, 0x007000ff);
5083
5084 data |= CGCG_EN | CGLS_EN;
5085 } else {
Alex Deucher5594a552013-08-15 16:20:26 -04005086 si_enable_gui_idle_interrupt(rdev, false);
5087
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005088 RREG32(CB_CGTT_SCLK_CTRL);
5089 RREG32(CB_CGTT_SCLK_CTRL);
5090 RREG32(CB_CGTT_SCLK_CTRL);
5091 RREG32(CB_CGTT_SCLK_CTRL);
5092
5093 data &= ~(CGCG_EN | CGLS_EN);
5094 }
5095
5096 if (orig != data)
5097 WREG32(RLC_CGCG_CGLS_CTRL, data);
5098}
5099
5100static void si_enable_mgcg(struct radeon_device *rdev,
5101 bool enable)
5102{
5103 u32 data, orig, tmp = 0;
5104
Alex Deuchere16866e2013-08-08 19:34:07 -04005105 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGCG)) {
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005106 orig = data = RREG32(CGTS_SM_CTRL_REG);
5107 data = 0x96940200;
5108 if (orig != data)
5109 WREG32(CGTS_SM_CTRL_REG, data);
5110
Alex Deuchere16866e2013-08-08 19:34:07 -04005111 if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CP_LS) {
5112 orig = data = RREG32(CP_MEM_SLP_CNTL);
5113 data |= CP_MEM_LS_EN;
5114 if (orig != data)
5115 WREG32(CP_MEM_SLP_CNTL, data);
5116 }
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005117
5118 orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
5119 data &= 0xffffffc0;
5120 if (orig != data)
5121 WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
5122
5123 tmp = si_halt_rlc(rdev);
5124
5125 WREG32(RLC_SERDES_WR_MASTER_MASK_0, 0xffffffff);
5126 WREG32(RLC_SERDES_WR_MASTER_MASK_1, 0xffffffff);
5127 WREG32(RLC_SERDES_WR_CTRL, 0x00d000ff);
5128
5129 si_update_rlc(rdev, tmp);
5130 } else {
5131 orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
5132 data |= 0x00000003;
5133 if (orig != data)
5134 WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
5135
5136 data = RREG32(CP_MEM_SLP_CNTL);
5137 if (data & CP_MEM_LS_EN) {
5138 data &= ~CP_MEM_LS_EN;
5139 WREG32(CP_MEM_SLP_CNTL, data);
5140 }
5141 orig = data = RREG32(CGTS_SM_CTRL_REG);
5142 data |= LS_OVERRIDE | OVERRIDE;
5143 if (orig != data)
5144 WREG32(CGTS_SM_CTRL_REG, data);
5145
5146 tmp = si_halt_rlc(rdev);
5147
5148 WREG32(RLC_SERDES_WR_MASTER_MASK_0, 0xffffffff);
5149 WREG32(RLC_SERDES_WR_MASTER_MASK_1, 0xffffffff);
5150 WREG32(RLC_SERDES_WR_CTRL, 0x00e000ff);
5151
5152 si_update_rlc(rdev, tmp);
5153 }
5154}
5155
5156static void si_enable_uvd_mgcg(struct radeon_device *rdev,
5157 bool enable)
5158{
5159 u32 orig, data, tmp;
5160
Alex Deuchere16866e2013-08-08 19:34:07 -04005161 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_UVD_MGCG)) {
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005162 tmp = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
5163 tmp |= 0x3fff;
5164 WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, tmp);
5165
5166 orig = data = RREG32(UVD_CGC_CTRL);
5167 data |= DCM;
5168 if (orig != data)
5169 WREG32(UVD_CGC_CTRL, data);
5170
5171 WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_0, 0);
5172 WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_1, 0);
5173 } else {
5174 tmp = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
5175 tmp &= ~0x3fff;
5176 WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, tmp);
5177
5178 orig = data = RREG32(UVD_CGC_CTRL);
5179 data &= ~DCM;
5180 if (orig != data)
5181 WREG32(UVD_CGC_CTRL, data);
5182
5183 WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_0, 0xffffffff);
5184 WREG32_SMC(SMC_CG_IND_START + CG_CGTT_LOCAL_1, 0xffffffff);
5185 }
5186}
5187
5188static const u32 mc_cg_registers[] =
5189{
5190 MC_HUB_MISC_HUB_CG,
5191 MC_HUB_MISC_SIP_CG,
5192 MC_HUB_MISC_VM_CG,
5193 MC_XPB_CLK_GAT,
5194 ATC_MISC_CG,
5195 MC_CITF_MISC_WR_CG,
5196 MC_CITF_MISC_RD_CG,
5197 MC_CITF_MISC_VM_CG,
5198 VM_L2_CG,
5199};
5200
5201static void si_enable_mc_ls(struct radeon_device *rdev,
5202 bool enable)
5203{
5204 int i;
5205 u32 orig, data;
5206
5207 for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
5208 orig = data = RREG32(mc_cg_registers[i]);
Alex Deuchere16866e2013-08-08 19:34:07 -04005209 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_LS))
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005210 data |= MC_LS_ENABLE;
5211 else
5212 data &= ~MC_LS_ENABLE;
5213 if (data != orig)
5214 WREG32(mc_cg_registers[i], data);
5215 }
5216}
5217
Alex Deuchere16866e2013-08-08 19:34:07 -04005218static void si_enable_mc_mgcg(struct radeon_device *rdev,
5219 bool enable)
5220{
5221 int i;
5222 u32 orig, data;
5223
5224 for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
5225 orig = data = RREG32(mc_cg_registers[i]);
5226 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_MGCG))
5227 data |= MC_CG_ENABLE;
5228 else
5229 data &= ~MC_CG_ENABLE;
5230 if (data != orig)
5231 WREG32(mc_cg_registers[i], data);
5232 }
5233}
5234
5235static void si_enable_dma_mgcg(struct radeon_device *rdev,
5236 bool enable)
5237{
5238 u32 orig, data, offset;
5239 int i;
5240
5241 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_MGCG)) {
5242 for (i = 0; i < 2; i++) {
5243 if (i == 0)
5244 offset = DMA0_REGISTER_OFFSET;
5245 else
5246 offset = DMA1_REGISTER_OFFSET;
5247 orig = data = RREG32(DMA_POWER_CNTL + offset);
5248 data &= ~MEM_POWER_OVERRIDE;
5249 if (data != orig)
5250 WREG32(DMA_POWER_CNTL + offset, data);
5251 WREG32(DMA_CLK_CTRL + offset, 0x00000100);
5252 }
5253 } else {
5254 for (i = 0; i < 2; i++) {
5255 if (i == 0)
5256 offset = DMA0_REGISTER_OFFSET;
5257 else
5258 offset = DMA1_REGISTER_OFFSET;
5259 orig = data = RREG32(DMA_POWER_CNTL + offset);
5260 data |= MEM_POWER_OVERRIDE;
5261 if (data != orig)
5262 WREG32(DMA_POWER_CNTL + offset, data);
5263
5264 orig = data = RREG32(DMA_CLK_CTRL + offset);
5265 data = 0xff000000;
5266 if (data != orig)
5267 WREG32(DMA_CLK_CTRL + offset, data);
5268 }
5269 }
5270}
5271
5272static void si_enable_bif_mgls(struct radeon_device *rdev,
5273 bool enable)
5274{
5275 u32 orig, data;
5276
5277 orig = data = RREG32_PCIE(PCIE_CNTL2);
5278
5279 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_BIF_LS))
5280 data |= SLV_MEM_LS_EN | MST_MEM_LS_EN |
5281 REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN;
5282 else
5283 data &= ~(SLV_MEM_LS_EN | MST_MEM_LS_EN |
5284 REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN);
5285
5286 if (orig != data)
5287 WREG32_PCIE(PCIE_CNTL2, data);
5288}
5289
5290static void si_enable_hdp_mgcg(struct radeon_device *rdev,
5291 bool enable)
5292{
5293 u32 orig, data;
5294
5295 orig = data = RREG32(HDP_HOST_PATH_CNTL);
5296
5297 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_MGCG))
5298 data &= ~CLOCK_GATING_DIS;
5299 else
5300 data |= CLOCK_GATING_DIS;
5301
5302 if (orig != data)
5303 WREG32(HDP_HOST_PATH_CNTL, data);
5304}
5305
5306static void si_enable_hdp_ls(struct radeon_device *rdev,
5307 bool enable)
5308{
5309 u32 orig, data;
5310
5311 orig = data = RREG32(HDP_MEM_POWER_LS);
5312
5313 if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_LS))
5314 data |= HDP_LS_ENABLE;
5315 else
5316 data &= ~HDP_LS_ENABLE;
5317
5318 if (orig != data)
5319 WREG32(HDP_MEM_POWER_LS, data);
5320}
5321
Alex Deucher68e3a092013-12-18 14:11:40 -05005322static void si_update_cg(struct radeon_device *rdev,
5323 u32 block, bool enable)
Alex Deuchere16866e2013-08-08 19:34:07 -04005324{
5325 if (block & RADEON_CG_BLOCK_GFX) {
Alex Deucher811e4d52013-09-03 13:31:33 -04005326 si_enable_gui_idle_interrupt(rdev, false);
Alex Deuchere16866e2013-08-08 19:34:07 -04005327 /* order matters! */
5328 if (enable) {
5329 si_enable_mgcg(rdev, true);
5330 si_enable_cgcg(rdev, true);
5331 } else {
5332 si_enable_cgcg(rdev, false);
5333 si_enable_mgcg(rdev, false);
5334 }
Alex Deucher811e4d52013-09-03 13:31:33 -04005335 si_enable_gui_idle_interrupt(rdev, true);
Alex Deuchere16866e2013-08-08 19:34:07 -04005336 }
5337
5338 if (block & RADEON_CG_BLOCK_MC) {
5339 si_enable_mc_mgcg(rdev, enable);
5340 si_enable_mc_ls(rdev, enable);
5341 }
5342
5343 if (block & RADEON_CG_BLOCK_SDMA) {
5344 si_enable_dma_mgcg(rdev, enable);
5345 }
5346
5347 if (block & RADEON_CG_BLOCK_BIF) {
5348 si_enable_bif_mgls(rdev, enable);
5349 }
5350
5351 if (block & RADEON_CG_BLOCK_UVD) {
5352 if (rdev->has_uvd) {
5353 si_enable_uvd_mgcg(rdev, enable);
5354 }
5355 }
5356
5357 if (block & RADEON_CG_BLOCK_HDP) {
5358 si_enable_hdp_mgcg(rdev, enable);
5359 si_enable_hdp_ls(rdev, enable);
5360 }
5361}
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005362
5363static void si_init_cg(struct radeon_device *rdev)
5364{
Alex Deuchere16866e2013-08-08 19:34:07 -04005365 si_update_cg(rdev, (RADEON_CG_BLOCK_GFX |
5366 RADEON_CG_BLOCK_MC |
5367 RADEON_CG_BLOCK_SDMA |
5368 RADEON_CG_BLOCK_BIF |
5369 RADEON_CG_BLOCK_HDP), true);
Alex Deucherb2d70912013-07-27 17:53:25 -04005370 if (rdev->has_uvd) {
Alex Deuchere16866e2013-08-08 19:34:07 -04005371 si_update_cg(rdev, RADEON_CG_BLOCK_UVD, true);
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005372 si_init_uvd_internal_cg(rdev);
5373 }
5374}
5375
5376static void si_fini_cg(struct radeon_device *rdev)
5377{
Alex Deucher0116e1e2013-08-08 18:00:10 -04005378 if (rdev->has_uvd) {
Alex Deuchere16866e2013-08-08 19:34:07 -04005379 si_update_cg(rdev, RADEON_CG_BLOCK_UVD, false);
Alex Deucher0116e1e2013-08-08 18:00:10 -04005380 }
Alex Deuchere16866e2013-08-08 19:34:07 -04005381 si_update_cg(rdev, (RADEON_CG_BLOCK_GFX |
5382 RADEON_CG_BLOCK_MC |
5383 RADEON_CG_BLOCK_SDMA |
5384 RADEON_CG_BLOCK_BIF |
5385 RADEON_CG_BLOCK_HDP), false);
5386}
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005387
Alex Deucher59a82d02013-08-13 12:48:06 -04005388u32 si_get_csb_size(struct radeon_device *rdev)
5389{
5390 u32 count = 0;
5391 const struct cs_section_def *sect = NULL;
5392 const struct cs_extent_def *ext = NULL;
5393
5394 if (rdev->rlc.cs_data == NULL)
5395 return 0;
5396
5397 /* begin clear state */
5398 count += 2;
5399 /* context control state */
5400 count += 3;
5401
5402 for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
5403 for (ext = sect->section; ext->extent != NULL; ++ext) {
5404 if (sect->id == SECT_CONTEXT)
5405 count += 2 + ext->reg_count;
5406 else
5407 return 0;
5408 }
5409 }
5410 /* pa_sc_raster_config */
5411 count += 3;
5412 /* end clear state */
5413 count += 2;
5414 /* clear state */
5415 count += 2;
5416
5417 return count;
5418}
5419
5420void si_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer)
5421{
5422 u32 count = 0, i;
5423 const struct cs_section_def *sect = NULL;
5424 const struct cs_extent_def *ext = NULL;
5425
5426 if (rdev->rlc.cs_data == NULL)
5427 return;
5428 if (buffer == NULL)
5429 return;
5430
Alex Deucher6ba81e52013-10-23 18:27:10 -04005431 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
5432 buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
Alex Deucher59a82d02013-08-13 12:48:06 -04005433
Alex Deucher6ba81e52013-10-23 18:27:10 -04005434 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
5435 buffer[count++] = cpu_to_le32(0x80000000);
5436 buffer[count++] = cpu_to_le32(0x80000000);
Alex Deucher59a82d02013-08-13 12:48:06 -04005437
5438 for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
5439 for (ext = sect->section; ext->extent != NULL; ++ext) {
5440 if (sect->id == SECT_CONTEXT) {
Alex Deucher6ba81e52013-10-23 18:27:10 -04005441 buffer[count++] =
5442 cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
5443 buffer[count++] = cpu_to_le32(ext->reg_index - 0xa000);
Alex Deucher59a82d02013-08-13 12:48:06 -04005444 for (i = 0; i < ext->reg_count; i++)
Alex Deucher6ba81e52013-10-23 18:27:10 -04005445 buffer[count++] = cpu_to_le32(ext->extent[i]);
Alex Deucher59a82d02013-08-13 12:48:06 -04005446 } else {
5447 return;
5448 }
5449 }
5450 }
5451
Alex Deucher6ba81e52013-10-23 18:27:10 -04005452 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 1));
5453 buffer[count++] = cpu_to_le32(PA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
Alex Deucher59a82d02013-08-13 12:48:06 -04005454 switch (rdev->family) {
5455 case CHIP_TAHITI:
5456 case CHIP_PITCAIRN:
Alex Deucher6ba81e52013-10-23 18:27:10 -04005457 buffer[count++] = cpu_to_le32(0x2a00126a);
Alex Deucher59a82d02013-08-13 12:48:06 -04005458 break;
5459 case CHIP_VERDE:
Alex Deucher6ba81e52013-10-23 18:27:10 -04005460 buffer[count++] = cpu_to_le32(0x0000124a);
Alex Deucher59a82d02013-08-13 12:48:06 -04005461 break;
5462 case CHIP_OLAND:
Alex Deucher6ba81e52013-10-23 18:27:10 -04005463 buffer[count++] = cpu_to_le32(0x00000082);
Alex Deucher59a82d02013-08-13 12:48:06 -04005464 break;
5465 case CHIP_HAINAN:
Alex Deucher6ba81e52013-10-23 18:27:10 -04005466 buffer[count++] = cpu_to_le32(0x00000000);
Alex Deucher59a82d02013-08-13 12:48:06 -04005467 break;
5468 default:
Alex Deucher6ba81e52013-10-23 18:27:10 -04005469 buffer[count++] = cpu_to_le32(0x00000000);
Alex Deucher59a82d02013-08-13 12:48:06 -04005470 break;
5471 }
5472
Alex Deucher6ba81e52013-10-23 18:27:10 -04005473 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
5474 buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);
Alex Deucher59a82d02013-08-13 12:48:06 -04005475
Alex Deucher6ba81e52013-10-23 18:27:10 -04005476 buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
5477 buffer[count++] = cpu_to_le32(0);
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005478}
5479
5480static void si_init_pg(struct radeon_device *rdev)
5481{
Alex Deucher0116e1e2013-08-08 18:00:10 -04005482 if (rdev->pg_flags) {
5483 if (rdev->pg_flags & RADEON_PG_SUPPORT_SDMA) {
5484 si_init_dma_pg(rdev);
Alex Deucher0116e1e2013-08-08 18:00:10 -04005485 }
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005486 si_init_ao_cu_mask(rdev);
Alex Deucher2b19d172013-09-04 16:58:29 -04005487 if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG) {
Alex Deucher0116e1e2013-08-08 18:00:10 -04005488 si_init_gfx_cgpg(rdev);
Alex Deucher0116e1e2013-08-08 18:00:10 -04005489 }
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005490 si_enable_dma_pg(rdev, true);
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005491 si_enable_gfx_cgpg(rdev, true);
5492 } else {
5493 WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
5494 WREG32(RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
5495 }
5496}
5497
5498static void si_fini_pg(struct radeon_device *rdev)
5499{
Alex Deucher0116e1e2013-08-08 18:00:10 -04005500 if (rdev->pg_flags) {
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005501 si_enable_dma_pg(rdev, false);
5502 si_enable_gfx_cgpg(rdev, false);
5503 }
5504}
5505
5506/*
Alex Deucher347e7592012-03-20 17:18:21 -04005507 * RLC
5508 */
Alex Deucher866d83d2013-04-15 17:13:29 -04005509void si_rlc_reset(struct radeon_device *rdev)
Alex Deucherd719cef2013-02-15 16:49:59 -05005510{
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005511 u32 tmp = RREG32(GRBM_SOFT_RESET);
Alex Deucherd719cef2013-02-15 16:49:59 -05005512
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005513 tmp |= SOFT_RESET_RLC;
5514 WREG32(GRBM_SOFT_RESET, tmp);
5515 udelay(50);
5516 tmp &= ~SOFT_RESET_RLC;
5517 WREG32(GRBM_SOFT_RESET, tmp);
5518 udelay(50);
Alex Deucherd719cef2013-02-15 16:49:59 -05005519}
5520
Alex Deucher347e7592012-03-20 17:18:21 -04005521static void si_rlc_stop(struct radeon_device *rdev)
5522{
5523 WREG32(RLC_CNTL, 0);
Alex Deucherd719cef2013-02-15 16:49:59 -05005524
5525 si_enable_gui_idle_interrupt(rdev, false);
5526
5527 si_wait_for_rlc_serdes(rdev);
Alex Deucher347e7592012-03-20 17:18:21 -04005528}
5529
5530static void si_rlc_start(struct radeon_device *rdev)
5531{
5532 WREG32(RLC_CNTL, RLC_ENABLE);
Alex Deucherd719cef2013-02-15 16:49:59 -05005533
5534 si_enable_gui_idle_interrupt(rdev, true);
5535
5536 udelay(50);
5537}
5538
5539static bool si_lbpw_supported(struct radeon_device *rdev)
5540{
5541 u32 tmp;
5542
5543 /* Enable LBPW only for DDR3 */
5544 tmp = RREG32(MC_SEQ_MISC0);
5545 if ((tmp & 0xF0000000) == 0xB0000000)
5546 return true;
5547 return false;
5548}
5549
5550static void si_enable_lbpw(struct radeon_device *rdev, bool enable)
5551{
5552 u32 tmp;
5553
5554 tmp = RREG32(RLC_LB_CNTL);
5555 if (enable)
5556 tmp |= LOAD_BALANCE_ENABLE;
5557 else
5558 tmp &= ~LOAD_BALANCE_ENABLE;
5559 WREG32(RLC_LB_CNTL, tmp);
5560
5561 if (!enable) {
5562 si_select_se_sh(rdev, 0xffffffff, 0xffffffff);
5563 WREG32(SPI_LB_CU_MASK, 0x00ff);
5564 }
Alex Deucher347e7592012-03-20 17:18:21 -04005565}
5566
5567static int si_rlc_resume(struct radeon_device *rdev)
5568{
5569 u32 i;
5570 const __be32 *fw_data;
5571
5572 if (!rdev->rlc_fw)
5573 return -EINVAL;
5574
5575 si_rlc_stop(rdev);
5576
Alex Deucherf8f84ac2013-03-07 12:56:35 -05005577 si_rlc_reset(rdev);
5578
5579 si_init_pg(rdev);
5580
5581 si_init_cg(rdev);
5582
Alex Deucher347e7592012-03-20 17:18:21 -04005583 WREG32(RLC_RL_BASE, 0);
5584 WREG32(RLC_RL_SIZE, 0);
5585 WREG32(RLC_LB_CNTL, 0);
5586 WREG32(RLC_LB_CNTR_MAX, 0xffffffff);
5587 WREG32(RLC_LB_CNTR_INIT, 0);
Alex Deucherd719cef2013-02-15 16:49:59 -05005588 WREG32(RLC_LB_INIT_CU_MASK, 0xffffffff);
Alex Deucher347e7592012-03-20 17:18:21 -04005589
Alex Deucher347e7592012-03-20 17:18:21 -04005590 WREG32(RLC_MC_CNTL, 0);
5591 WREG32(RLC_UCODE_CNTL, 0);
5592
5593 fw_data = (const __be32 *)rdev->rlc_fw->data;
5594 for (i = 0; i < SI_RLC_UCODE_SIZE; i++) {
5595 WREG32(RLC_UCODE_ADDR, i);
5596 WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
5597 }
5598 WREG32(RLC_UCODE_ADDR, 0);
5599
Alex Deucherd719cef2013-02-15 16:49:59 -05005600 si_enable_lbpw(rdev, si_lbpw_supported(rdev));
5601
Alex Deucher347e7592012-03-20 17:18:21 -04005602 si_rlc_start(rdev);
5603
5604 return 0;
5605}
5606
Alex Deucher25a857f2012-03-20 17:18:22 -04005607static void si_enable_interrupts(struct radeon_device *rdev)
5608{
5609 u32 ih_cntl = RREG32(IH_CNTL);
5610 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
5611
5612 ih_cntl |= ENABLE_INTR;
5613 ih_rb_cntl |= IH_RB_ENABLE;
5614 WREG32(IH_CNTL, ih_cntl);
5615 WREG32(IH_RB_CNTL, ih_rb_cntl);
5616 rdev->ih.enabled = true;
5617}
5618
5619static void si_disable_interrupts(struct radeon_device *rdev)
5620{
5621 u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
5622 u32 ih_cntl = RREG32(IH_CNTL);
5623
5624 ih_rb_cntl &= ~IH_RB_ENABLE;
5625 ih_cntl &= ~ENABLE_INTR;
5626 WREG32(IH_RB_CNTL, ih_rb_cntl);
5627 WREG32(IH_CNTL, ih_cntl);
5628 /* set rptr, wptr to 0 */
5629 WREG32(IH_RB_RPTR, 0);
5630 WREG32(IH_RB_WPTR, 0);
5631 rdev->ih.enabled = false;
Alex Deucher25a857f2012-03-20 17:18:22 -04005632 rdev->ih.rptr = 0;
5633}
5634
5635static void si_disable_interrupt_state(struct radeon_device *rdev)
5636{
5637 u32 tmp;
5638
Alex Deucher811e4d52013-09-03 13:31:33 -04005639 tmp = RREG32(CP_INT_CNTL_RING0) &
5640 (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
5641 WREG32(CP_INT_CNTL_RING0, tmp);
Alex Deucher25a857f2012-03-20 17:18:22 -04005642 WREG32(CP_INT_CNTL_RING1, 0);
5643 WREG32(CP_INT_CNTL_RING2, 0);
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05005644 tmp = RREG32(DMA_CNTL + DMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
5645 WREG32(DMA_CNTL + DMA0_REGISTER_OFFSET, tmp);
5646 tmp = RREG32(DMA_CNTL + DMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
5647 WREG32(DMA_CNTL + DMA1_REGISTER_OFFSET, tmp);
Alex Deucher25a857f2012-03-20 17:18:22 -04005648 WREG32(GRBM_INT_CNTL, 0);
Alex Deucher51535502012-08-30 14:34:30 -04005649 if (rdev->num_crtc >= 2) {
5650 WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
5651 WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
5652 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005653 if (rdev->num_crtc >= 4) {
5654 WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
5655 WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
5656 }
5657 if (rdev->num_crtc >= 6) {
5658 WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
5659 WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
5660 }
5661
Alex Deucher51535502012-08-30 14:34:30 -04005662 if (rdev->num_crtc >= 2) {
5663 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
5664 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
5665 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005666 if (rdev->num_crtc >= 4) {
5667 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
5668 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
5669 }
5670 if (rdev->num_crtc >= 6) {
5671 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
5672 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
5673 }
5674
Alex Deucher51535502012-08-30 14:34:30 -04005675 if (!ASIC_IS_NODCE(rdev)) {
5676 WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
Alex Deucher25a857f2012-03-20 17:18:22 -04005677
Alex Deucher51535502012-08-30 14:34:30 -04005678 tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5679 WREG32(DC_HPD1_INT_CONTROL, tmp);
5680 tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5681 WREG32(DC_HPD2_INT_CONTROL, tmp);
5682 tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5683 WREG32(DC_HPD3_INT_CONTROL, tmp);
5684 tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5685 WREG32(DC_HPD4_INT_CONTROL, tmp);
5686 tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5687 WREG32(DC_HPD5_INT_CONTROL, tmp);
5688 tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
5689 WREG32(DC_HPD6_INT_CONTROL, tmp);
5690 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005691}
5692
5693static int si_irq_init(struct radeon_device *rdev)
5694{
5695 int ret = 0;
5696 int rb_bufsz;
5697 u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
5698
5699 /* allocate ring */
5700 ret = r600_ih_ring_alloc(rdev);
5701 if (ret)
5702 return ret;
5703
5704 /* disable irqs */
5705 si_disable_interrupts(rdev);
5706
5707 /* init rlc */
5708 ret = si_rlc_resume(rdev);
5709 if (ret) {
5710 r600_ih_ring_fini(rdev);
5711 return ret;
5712 }
5713
5714 /* setup interrupt control */
5715 /* set dummy read address to ring address */
5716 WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
5717 interrupt_cntl = RREG32(INTERRUPT_CNTL);
5718 /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
5719 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
5720 */
5721 interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
5722 /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
5723 interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
5724 WREG32(INTERRUPT_CNTL, interrupt_cntl);
5725
5726 WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
Daniel Vetterb72a8922013-07-10 14:11:59 +02005727 rb_bufsz = order_base_2(rdev->ih.ring_size / 4);
Alex Deucher25a857f2012-03-20 17:18:22 -04005728
5729 ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
5730 IH_WPTR_OVERFLOW_CLEAR |
5731 (rb_bufsz << 1));
5732
5733 if (rdev->wb.enabled)
5734 ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
5735
5736 /* set the writeback address whether it's enabled or not */
5737 WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
5738 WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
5739
5740 WREG32(IH_RB_CNTL, ih_rb_cntl);
5741
5742 /* set rptr, wptr to 0 */
5743 WREG32(IH_RB_RPTR, 0);
5744 WREG32(IH_RB_WPTR, 0);
5745
5746 /* Default settings for IH_CNTL (disabled at first) */
5747 ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10) | MC_VMID(0);
5748 /* RPTR_REARM only works if msi's are enabled */
5749 if (rdev->msi_enabled)
5750 ih_cntl |= RPTR_REARM;
5751 WREG32(IH_CNTL, ih_cntl);
5752
5753 /* force the active interrupt state to all disabled */
5754 si_disable_interrupt_state(rdev);
5755
Dave Airlie20998102012-04-03 11:53:05 +01005756 pci_set_master(rdev->pdev);
5757
Alex Deucher25a857f2012-03-20 17:18:22 -04005758 /* enable irqs */
5759 si_enable_interrupts(rdev);
5760
5761 return ret;
5762}
5763
5764int si_irq_set(struct radeon_device *rdev)
5765{
Alex Deucher811e4d52013-09-03 13:31:33 -04005766 u32 cp_int_cntl;
Alex Deucher25a857f2012-03-20 17:18:22 -04005767 u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0;
5768 u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
Alex Deucher51535502012-08-30 14:34:30 -04005769 u32 hpd1 = 0, hpd2 = 0, hpd3 = 0, hpd4 = 0, hpd5 = 0, hpd6 = 0;
Alex Deucher25a857f2012-03-20 17:18:22 -04005770 u32 grbm_int_cntl = 0;
5771 u32 grph1 = 0, grph2 = 0, grph3 = 0, grph4 = 0, grph5 = 0, grph6 = 0;
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05005772 u32 dma_cntl, dma_cntl1;
Alex Deuchera9e61412013-06-25 17:56:16 -04005773 u32 thermal_int = 0;
Alex Deucher25a857f2012-03-20 17:18:22 -04005774
5775 if (!rdev->irq.installed) {
5776 WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
5777 return -EINVAL;
5778 }
5779 /* don't enable anything if the ih is disabled */
5780 if (!rdev->ih.enabled) {
5781 si_disable_interrupts(rdev);
5782 /* force the active interrupt state to all disabled */
5783 si_disable_interrupt_state(rdev);
5784 return 0;
5785 }
5786
Alex Deucher811e4d52013-09-03 13:31:33 -04005787 cp_int_cntl = RREG32(CP_INT_CNTL_RING0) &
5788 (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
5789
Alex Deucher51535502012-08-30 14:34:30 -04005790 if (!ASIC_IS_NODCE(rdev)) {
5791 hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
5792 hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
5793 hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
5794 hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
5795 hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
5796 hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
5797 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005798
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05005799 dma_cntl = RREG32(DMA_CNTL + DMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
5800 dma_cntl1 = RREG32(DMA_CNTL + DMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
5801
Alex Deuchera9e61412013-06-25 17:56:16 -04005802 thermal_int = RREG32(CG_THERMAL_INT) &
5803 ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
5804
Alex Deucher25a857f2012-03-20 17:18:22 -04005805 /* enable CP interrupts on all rings */
Christian Koenig736fc372012-05-17 19:52:00 +02005806 if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005807 DRM_DEBUG("si_irq_set: sw int gfx\n");
5808 cp_int_cntl |= TIME_STAMP_INT_ENABLE;
5809 }
Christian Koenig736fc372012-05-17 19:52:00 +02005810 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005811 DRM_DEBUG("si_irq_set: sw int cp1\n");
5812 cp_int_cntl1 |= TIME_STAMP_INT_ENABLE;
5813 }
Christian Koenig736fc372012-05-17 19:52:00 +02005814 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005815 DRM_DEBUG("si_irq_set: sw int cp2\n");
5816 cp_int_cntl2 |= TIME_STAMP_INT_ENABLE;
5817 }
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05005818 if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
5819 DRM_DEBUG("si_irq_set: sw int dma\n");
5820 dma_cntl |= TRAP_ENABLE;
5821 }
5822
5823 if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
5824 DRM_DEBUG("si_irq_set: sw int dma1\n");
5825 dma_cntl1 |= TRAP_ENABLE;
5826 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005827 if (rdev->irq.crtc_vblank_int[0] ||
Christian Koenig736fc372012-05-17 19:52:00 +02005828 atomic_read(&rdev->irq.pflip[0])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005829 DRM_DEBUG("si_irq_set: vblank 0\n");
5830 crtc1 |= VBLANK_INT_MASK;
5831 }
5832 if (rdev->irq.crtc_vblank_int[1] ||
Christian Koenig736fc372012-05-17 19:52:00 +02005833 atomic_read(&rdev->irq.pflip[1])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005834 DRM_DEBUG("si_irq_set: vblank 1\n");
5835 crtc2 |= VBLANK_INT_MASK;
5836 }
5837 if (rdev->irq.crtc_vblank_int[2] ||
Christian Koenig736fc372012-05-17 19:52:00 +02005838 atomic_read(&rdev->irq.pflip[2])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005839 DRM_DEBUG("si_irq_set: vblank 2\n");
5840 crtc3 |= VBLANK_INT_MASK;
5841 }
5842 if (rdev->irq.crtc_vblank_int[3] ||
Christian Koenig736fc372012-05-17 19:52:00 +02005843 atomic_read(&rdev->irq.pflip[3])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005844 DRM_DEBUG("si_irq_set: vblank 3\n");
5845 crtc4 |= VBLANK_INT_MASK;
5846 }
5847 if (rdev->irq.crtc_vblank_int[4] ||
Christian Koenig736fc372012-05-17 19:52:00 +02005848 atomic_read(&rdev->irq.pflip[4])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005849 DRM_DEBUG("si_irq_set: vblank 4\n");
5850 crtc5 |= VBLANK_INT_MASK;
5851 }
5852 if (rdev->irq.crtc_vblank_int[5] ||
Christian Koenig736fc372012-05-17 19:52:00 +02005853 atomic_read(&rdev->irq.pflip[5])) {
Alex Deucher25a857f2012-03-20 17:18:22 -04005854 DRM_DEBUG("si_irq_set: vblank 5\n");
5855 crtc6 |= VBLANK_INT_MASK;
5856 }
5857 if (rdev->irq.hpd[0]) {
5858 DRM_DEBUG("si_irq_set: hpd 1\n");
5859 hpd1 |= DC_HPDx_INT_EN;
5860 }
5861 if (rdev->irq.hpd[1]) {
5862 DRM_DEBUG("si_irq_set: hpd 2\n");
5863 hpd2 |= DC_HPDx_INT_EN;
5864 }
5865 if (rdev->irq.hpd[2]) {
5866 DRM_DEBUG("si_irq_set: hpd 3\n");
5867 hpd3 |= DC_HPDx_INT_EN;
5868 }
5869 if (rdev->irq.hpd[3]) {
5870 DRM_DEBUG("si_irq_set: hpd 4\n");
5871 hpd4 |= DC_HPDx_INT_EN;
5872 }
5873 if (rdev->irq.hpd[4]) {
5874 DRM_DEBUG("si_irq_set: hpd 5\n");
5875 hpd5 |= DC_HPDx_INT_EN;
5876 }
5877 if (rdev->irq.hpd[5]) {
5878 DRM_DEBUG("si_irq_set: hpd 6\n");
5879 hpd6 |= DC_HPDx_INT_EN;
5880 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005881
5882 WREG32(CP_INT_CNTL_RING0, cp_int_cntl);
5883 WREG32(CP_INT_CNTL_RING1, cp_int_cntl1);
5884 WREG32(CP_INT_CNTL_RING2, cp_int_cntl2);
5885
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05005886 WREG32(DMA_CNTL + DMA0_REGISTER_OFFSET, dma_cntl);
5887 WREG32(DMA_CNTL + DMA1_REGISTER_OFFSET, dma_cntl1);
5888
Alex Deucher25a857f2012-03-20 17:18:22 -04005889 WREG32(GRBM_INT_CNTL, grbm_int_cntl);
5890
Alex Deuchera9e61412013-06-25 17:56:16 -04005891 if (rdev->irq.dpm_thermal) {
5892 DRM_DEBUG("dpm thermal\n");
5893 thermal_int |= THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW;
5894 }
5895
Alex Deucher51535502012-08-30 14:34:30 -04005896 if (rdev->num_crtc >= 2) {
5897 WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
5898 WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
5899 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005900 if (rdev->num_crtc >= 4) {
5901 WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
5902 WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
5903 }
5904 if (rdev->num_crtc >= 6) {
5905 WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
5906 WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
5907 }
5908
Alex Deucher51535502012-08-30 14:34:30 -04005909 if (rdev->num_crtc >= 2) {
5910 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, grph1);
5911 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, grph2);
5912 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005913 if (rdev->num_crtc >= 4) {
5914 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, grph3);
5915 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, grph4);
5916 }
5917 if (rdev->num_crtc >= 6) {
5918 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, grph5);
5919 WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, grph6);
5920 }
5921
Alex Deucher51535502012-08-30 14:34:30 -04005922 if (!ASIC_IS_NODCE(rdev)) {
5923 WREG32(DC_HPD1_INT_CONTROL, hpd1);
5924 WREG32(DC_HPD2_INT_CONTROL, hpd2);
5925 WREG32(DC_HPD3_INT_CONTROL, hpd3);
5926 WREG32(DC_HPD4_INT_CONTROL, hpd4);
5927 WREG32(DC_HPD5_INT_CONTROL, hpd5);
5928 WREG32(DC_HPD6_INT_CONTROL, hpd6);
5929 }
Alex Deucher25a857f2012-03-20 17:18:22 -04005930
Alex Deuchera9e61412013-06-25 17:56:16 -04005931 WREG32(CG_THERMAL_INT, thermal_int);
5932
Alex Deucher25a857f2012-03-20 17:18:22 -04005933 return 0;
5934}
5935
5936static inline void si_irq_ack(struct radeon_device *rdev)
5937{
5938 u32 tmp;
5939
Alex Deucher51535502012-08-30 14:34:30 -04005940 if (ASIC_IS_NODCE(rdev))
5941 return;
5942
Alex Deucher25a857f2012-03-20 17:18:22 -04005943 rdev->irq.stat_regs.evergreen.disp_int = RREG32(DISP_INTERRUPT_STATUS);
5944 rdev->irq.stat_regs.evergreen.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
5945 rdev->irq.stat_regs.evergreen.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
5946 rdev->irq.stat_regs.evergreen.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
5947 rdev->irq.stat_regs.evergreen.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
5948 rdev->irq.stat_regs.evergreen.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
5949 rdev->irq.stat_regs.evergreen.d1grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
5950 rdev->irq.stat_regs.evergreen.d2grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
5951 if (rdev->num_crtc >= 4) {
5952 rdev->irq.stat_regs.evergreen.d3grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
5953 rdev->irq.stat_regs.evergreen.d4grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
5954 }
5955 if (rdev->num_crtc >= 6) {
5956 rdev->irq.stat_regs.evergreen.d5grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
5957 rdev->irq.stat_regs.evergreen.d6grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
5958 }
5959
5960 if (rdev->irq.stat_regs.evergreen.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
5961 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
5962 if (rdev->irq.stat_regs.evergreen.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
5963 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
5964 if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT)
5965 WREG32(VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
5966 if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT)
5967 WREG32(VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
5968 if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
5969 WREG32(VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
5970 if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT)
5971 WREG32(VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
5972
5973 if (rdev->num_crtc >= 4) {
5974 if (rdev->irq.stat_regs.evergreen.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
5975 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
5976 if (rdev->irq.stat_regs.evergreen.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
5977 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
5978 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
5979 WREG32(VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
5980 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
5981 WREG32(VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
5982 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
5983 WREG32(VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
5984 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
5985 WREG32(VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
5986 }
5987
5988 if (rdev->num_crtc >= 6) {
5989 if (rdev->irq.stat_regs.evergreen.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
5990 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
5991 if (rdev->irq.stat_regs.evergreen.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
5992 WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
5993 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
5994 WREG32(VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
5995 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
5996 WREG32(VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
5997 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
5998 WREG32(VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
5999 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
6000 WREG32(VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
6001 }
6002
6003 if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
6004 tmp = RREG32(DC_HPD1_INT_CONTROL);
6005 tmp |= DC_HPDx_INT_ACK;
6006 WREG32(DC_HPD1_INT_CONTROL, tmp);
6007 }
6008 if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
6009 tmp = RREG32(DC_HPD2_INT_CONTROL);
6010 tmp |= DC_HPDx_INT_ACK;
6011 WREG32(DC_HPD2_INT_CONTROL, tmp);
6012 }
6013 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
6014 tmp = RREG32(DC_HPD3_INT_CONTROL);
6015 tmp |= DC_HPDx_INT_ACK;
6016 WREG32(DC_HPD3_INT_CONTROL, tmp);
6017 }
6018 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
6019 tmp = RREG32(DC_HPD4_INT_CONTROL);
6020 tmp |= DC_HPDx_INT_ACK;
6021 WREG32(DC_HPD4_INT_CONTROL, tmp);
6022 }
6023 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
6024 tmp = RREG32(DC_HPD5_INT_CONTROL);
6025 tmp |= DC_HPDx_INT_ACK;
6026 WREG32(DC_HPD5_INT_CONTROL, tmp);
6027 }
6028 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
6029 tmp = RREG32(DC_HPD5_INT_CONTROL);
6030 tmp |= DC_HPDx_INT_ACK;
6031 WREG32(DC_HPD6_INT_CONTROL, tmp);
6032 }
6033}
6034
6035static void si_irq_disable(struct radeon_device *rdev)
6036{
6037 si_disable_interrupts(rdev);
6038 /* Wait and acknowledge irq */
6039 mdelay(1);
6040 si_irq_ack(rdev);
6041 si_disable_interrupt_state(rdev);
6042}
6043
6044static void si_irq_suspend(struct radeon_device *rdev)
6045{
6046 si_irq_disable(rdev);
6047 si_rlc_stop(rdev);
6048}
6049
Alex Deucher9b136d52012-03-20 17:18:23 -04006050static void si_irq_fini(struct radeon_device *rdev)
6051{
6052 si_irq_suspend(rdev);
6053 r600_ih_ring_fini(rdev);
6054}
6055
Alex Deucher25a857f2012-03-20 17:18:22 -04006056static inline u32 si_get_ih_wptr(struct radeon_device *rdev)
6057{
6058 u32 wptr, tmp;
6059
6060 if (rdev->wb.enabled)
6061 wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
6062 else
6063 wptr = RREG32(IH_RB_WPTR);
6064
6065 if (wptr & RB_OVERFLOW) {
6066 /* When a ring buffer overflow happen start parsing interrupt
6067 * from the last not overwritten vector (wptr + 16). Hopefully
6068 * this should allow us to catchup.
6069 */
6070 dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
6071 wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
6072 rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
6073 tmp = RREG32(IH_RB_CNTL);
6074 tmp |= IH_WPTR_OVERFLOW_CLEAR;
6075 WREG32(IH_RB_CNTL, tmp);
6076 }
6077 return (wptr & rdev->ih.ptr_mask);
6078}
6079
6080/* SI IV Ring
6081 * Each IV ring entry is 128 bits:
6082 * [7:0] - interrupt source id
6083 * [31:8] - reserved
6084 * [59:32] - interrupt source data
6085 * [63:60] - reserved
6086 * [71:64] - RINGID
6087 * [79:72] - VMID
6088 * [127:80] - reserved
6089 */
6090int si_irq_process(struct radeon_device *rdev)
6091{
6092 u32 wptr;
6093 u32 rptr;
6094 u32 src_id, src_data, ring_id;
6095 u32 ring_index;
Alex Deucher25a857f2012-03-20 17:18:22 -04006096 bool queue_hotplug = false;
Alex Deuchera9e61412013-06-25 17:56:16 -04006097 bool queue_thermal = false;
Alex Deucherfbf6dc72013-06-13 18:47:58 -04006098 u32 status, addr;
Alex Deucher25a857f2012-03-20 17:18:22 -04006099
6100 if (!rdev->ih.enabled || rdev->shutdown)
6101 return IRQ_NONE;
6102
6103 wptr = si_get_ih_wptr(rdev);
Christian Koenigc20dc362012-05-16 21:45:24 +02006104
6105restart_ih:
6106 /* is somebody else already processing irqs? */
6107 if (atomic_xchg(&rdev->ih.lock, 1))
6108 return IRQ_NONE;
6109
Alex Deucher25a857f2012-03-20 17:18:22 -04006110 rptr = rdev->ih.rptr;
6111 DRM_DEBUG("si_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
6112
Alex Deucher25a857f2012-03-20 17:18:22 -04006113 /* Order reading of wptr vs. reading of IH ring data */
6114 rmb();
6115
6116 /* display interrupts */
6117 si_irq_ack(rdev);
6118
Alex Deucher25a857f2012-03-20 17:18:22 -04006119 while (rptr != wptr) {
6120 /* wptr/rptr are in bytes! */
6121 ring_index = rptr / 4;
6122 src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
6123 src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
6124 ring_id = le32_to_cpu(rdev->ih.ring[ring_index + 2]) & 0xff;
6125
6126 switch (src_id) {
6127 case 1: /* D1 vblank/vline */
6128 switch (src_data) {
6129 case 0: /* D1 vblank */
6130 if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT) {
6131 if (rdev->irq.crtc_vblank_int[0]) {
6132 drm_handle_vblank(rdev->ddev, 0);
6133 rdev->pm.vblank_sync = true;
6134 wake_up(&rdev->irq.vblank_queue);
6135 }
Christian Koenig736fc372012-05-17 19:52:00 +02006136 if (atomic_read(&rdev->irq.pflip[0]))
Alex Deucher25a857f2012-03-20 17:18:22 -04006137 radeon_crtc_handle_flip(rdev, 0);
6138 rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
6139 DRM_DEBUG("IH: D1 vblank\n");
6140 }
6141 break;
6142 case 1: /* D1 vline */
6143 if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT) {
6144 rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VLINE_INTERRUPT;
6145 DRM_DEBUG("IH: D1 vline\n");
6146 }
6147 break;
6148 default:
6149 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6150 break;
6151 }
6152 break;
6153 case 2: /* D2 vblank/vline */
6154 switch (src_data) {
6155 case 0: /* D2 vblank */
6156 if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT) {
6157 if (rdev->irq.crtc_vblank_int[1]) {
6158 drm_handle_vblank(rdev->ddev, 1);
6159 rdev->pm.vblank_sync = true;
6160 wake_up(&rdev->irq.vblank_queue);
6161 }
Christian Koenig736fc372012-05-17 19:52:00 +02006162 if (atomic_read(&rdev->irq.pflip[1]))
Alex Deucher25a857f2012-03-20 17:18:22 -04006163 radeon_crtc_handle_flip(rdev, 1);
6164 rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
6165 DRM_DEBUG("IH: D2 vblank\n");
6166 }
6167 break;
6168 case 1: /* D2 vline */
6169 if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT) {
6170 rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
6171 DRM_DEBUG("IH: D2 vline\n");
6172 }
6173 break;
6174 default:
6175 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6176 break;
6177 }
6178 break;
6179 case 3: /* D3 vblank/vline */
6180 switch (src_data) {
6181 case 0: /* D3 vblank */
6182 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT) {
6183 if (rdev->irq.crtc_vblank_int[2]) {
6184 drm_handle_vblank(rdev->ddev, 2);
6185 rdev->pm.vblank_sync = true;
6186 wake_up(&rdev->irq.vblank_queue);
6187 }
Christian Koenig736fc372012-05-17 19:52:00 +02006188 if (atomic_read(&rdev->irq.pflip[2]))
Alex Deucher25a857f2012-03-20 17:18:22 -04006189 radeon_crtc_handle_flip(rdev, 2);
6190 rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
6191 DRM_DEBUG("IH: D3 vblank\n");
6192 }
6193 break;
6194 case 1: /* D3 vline */
6195 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT) {
6196 rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
6197 DRM_DEBUG("IH: D3 vline\n");
6198 }
6199 break;
6200 default:
6201 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6202 break;
6203 }
6204 break;
6205 case 4: /* D4 vblank/vline */
6206 switch (src_data) {
6207 case 0: /* D4 vblank */
6208 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT) {
6209 if (rdev->irq.crtc_vblank_int[3]) {
6210 drm_handle_vblank(rdev->ddev, 3);
6211 rdev->pm.vblank_sync = true;
6212 wake_up(&rdev->irq.vblank_queue);
6213 }
Christian Koenig736fc372012-05-17 19:52:00 +02006214 if (atomic_read(&rdev->irq.pflip[3]))
Alex Deucher25a857f2012-03-20 17:18:22 -04006215 radeon_crtc_handle_flip(rdev, 3);
6216 rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
6217 DRM_DEBUG("IH: D4 vblank\n");
6218 }
6219 break;
6220 case 1: /* D4 vline */
6221 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT) {
6222 rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
6223 DRM_DEBUG("IH: D4 vline\n");
6224 }
6225 break;
6226 default:
6227 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6228 break;
6229 }
6230 break;
6231 case 5: /* D5 vblank/vline */
6232 switch (src_data) {
6233 case 0: /* D5 vblank */
6234 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT) {
6235 if (rdev->irq.crtc_vblank_int[4]) {
6236 drm_handle_vblank(rdev->ddev, 4);
6237 rdev->pm.vblank_sync = true;
6238 wake_up(&rdev->irq.vblank_queue);
6239 }
Christian Koenig736fc372012-05-17 19:52:00 +02006240 if (atomic_read(&rdev->irq.pflip[4]))
Alex Deucher25a857f2012-03-20 17:18:22 -04006241 radeon_crtc_handle_flip(rdev, 4);
6242 rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
6243 DRM_DEBUG("IH: D5 vblank\n");
6244 }
6245 break;
6246 case 1: /* D5 vline */
6247 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT) {
6248 rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
6249 DRM_DEBUG("IH: D5 vline\n");
6250 }
6251 break;
6252 default:
6253 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6254 break;
6255 }
6256 break;
6257 case 6: /* D6 vblank/vline */
6258 switch (src_data) {
6259 case 0: /* D6 vblank */
6260 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT) {
6261 if (rdev->irq.crtc_vblank_int[5]) {
6262 drm_handle_vblank(rdev->ddev, 5);
6263 rdev->pm.vblank_sync = true;
6264 wake_up(&rdev->irq.vblank_queue);
6265 }
Christian Koenig736fc372012-05-17 19:52:00 +02006266 if (atomic_read(&rdev->irq.pflip[5]))
Alex Deucher25a857f2012-03-20 17:18:22 -04006267 radeon_crtc_handle_flip(rdev, 5);
6268 rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
6269 DRM_DEBUG("IH: D6 vblank\n");
6270 }
6271 break;
6272 case 1: /* D6 vline */
6273 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT) {
6274 rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
6275 DRM_DEBUG("IH: D6 vline\n");
6276 }
6277 break;
6278 default:
6279 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6280 break;
6281 }
6282 break;
6283 case 42: /* HPD hotplug */
6284 switch (src_data) {
6285 case 0:
6286 if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
6287 rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_INTERRUPT;
6288 queue_hotplug = true;
6289 DRM_DEBUG("IH: HPD1\n");
6290 }
6291 break;
6292 case 1:
6293 if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
6294 rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_INTERRUPT;
6295 queue_hotplug = true;
6296 DRM_DEBUG("IH: HPD2\n");
6297 }
6298 break;
6299 case 2:
6300 if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
6301 rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
6302 queue_hotplug = true;
6303 DRM_DEBUG("IH: HPD3\n");
6304 }
6305 break;
6306 case 3:
6307 if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
6308 rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
6309 queue_hotplug = true;
6310 DRM_DEBUG("IH: HPD4\n");
6311 }
6312 break;
6313 case 4:
6314 if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
6315 rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
6316 queue_hotplug = true;
6317 DRM_DEBUG("IH: HPD5\n");
6318 }
6319 break;
6320 case 5:
6321 if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
6322 rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
6323 queue_hotplug = true;
6324 DRM_DEBUG("IH: HPD6\n");
6325 }
6326 break;
6327 default:
6328 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6329 break;
6330 }
6331 break;
Christian Königae133a12012-09-18 15:30:44 -04006332 case 146:
6333 case 147:
Alex Deucherfbf6dc72013-06-13 18:47:58 -04006334 addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
6335 status = RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS);
Christian Königae133a12012-09-18 15:30:44 -04006336 dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
6337 dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
Alex Deucherfbf6dc72013-06-13 18:47:58 -04006338 addr);
Christian Königae133a12012-09-18 15:30:44 -04006339 dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
Alex Deucherfbf6dc72013-06-13 18:47:58 -04006340 status);
6341 si_vm_decode_fault(rdev, status, addr);
Christian Königae133a12012-09-18 15:30:44 -04006342 /* reset addr and status */
6343 WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
6344 break;
Alex Deucher25a857f2012-03-20 17:18:22 -04006345 case 176: /* RINGID0 CP_INT */
6346 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
6347 break;
6348 case 177: /* RINGID1 CP_INT */
6349 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
6350 break;
6351 case 178: /* RINGID2 CP_INT */
6352 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
6353 break;
6354 case 181: /* CP EOP event */
6355 DRM_DEBUG("IH: CP EOP\n");
6356 switch (ring_id) {
6357 case 0:
6358 radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
6359 break;
6360 case 1:
6361 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
6362 break;
6363 case 2:
6364 radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
6365 break;
6366 }
6367 break;
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006368 case 224: /* DMA trap event */
6369 DRM_DEBUG("IH: DMA trap\n");
6370 radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
6371 break;
Alex Deuchera9e61412013-06-25 17:56:16 -04006372 case 230: /* thermal low to high */
6373 DRM_DEBUG("IH: thermal low to high\n");
6374 rdev->pm.dpm.thermal.high_to_low = false;
6375 queue_thermal = true;
6376 break;
6377 case 231: /* thermal high to low */
6378 DRM_DEBUG("IH: thermal high to low\n");
6379 rdev->pm.dpm.thermal.high_to_low = true;
6380 queue_thermal = true;
6381 break;
Alex Deucher25a857f2012-03-20 17:18:22 -04006382 case 233: /* GUI IDLE */
6383 DRM_DEBUG("IH: GUI idle\n");
Alex Deucher25a857f2012-03-20 17:18:22 -04006384 break;
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006385 case 244: /* DMA trap event */
6386 DRM_DEBUG("IH: DMA1 trap\n");
6387 radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
6388 break;
Alex Deucher25a857f2012-03-20 17:18:22 -04006389 default:
6390 DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
6391 break;
6392 }
6393
6394 /* wptr/rptr are in bytes! */
6395 rptr += 16;
6396 rptr &= rdev->ih.ptr_mask;
6397 }
Alex Deucher25a857f2012-03-20 17:18:22 -04006398 if (queue_hotplug)
6399 schedule_work(&rdev->hotplug_work);
Alex Deuchera9e61412013-06-25 17:56:16 -04006400 if (queue_thermal && rdev->pm.dpm_enabled)
6401 schedule_work(&rdev->pm.dpm.thermal.work);
Alex Deucher25a857f2012-03-20 17:18:22 -04006402 rdev->ih.rptr = rptr;
6403 WREG32(IH_RB_RPTR, rdev->ih.rptr);
Christian Koenigc20dc362012-05-16 21:45:24 +02006404 atomic_set(&rdev->ih.lock, 0);
6405
6406 /* make sure wptr hasn't changed while processing */
6407 wptr = si_get_ih_wptr(rdev);
6408 if (wptr != rptr)
6409 goto restart_ih;
6410
Alex Deucher25a857f2012-03-20 17:18:22 -04006411 return IRQ_HANDLED;
6412}
6413
Alex Deucher9b136d52012-03-20 17:18:23 -04006414/*
6415 * startup/shutdown callbacks
6416 */
6417static int si_startup(struct radeon_device *rdev)
6418{
6419 struct radeon_ring *ring;
6420 int r;
6421
Alex Deucherb9d305d2013-02-14 17:16:51 -05006422 /* enable pcie gen2/3 link */
6423 si_pcie_gen3_enable(rdev);
Alex Deuchere0bcf1652013-02-15 11:56:59 -05006424 /* enable aspm */
6425 si_program_aspm(rdev);
Alex Deucherb9d305d2013-02-14 17:16:51 -05006426
Alex Deuchere5903d32013-08-30 08:58:20 -04006427 /* scratch needs to be initialized before MC */
6428 r = r600_vram_scratch_init(rdev);
6429 if (r)
6430 return r;
6431
Alex Deucher6fab3feb2013-08-04 12:13:17 -04006432 si_mc_program(rdev);
6433
Alex Deucher6c7bcce2013-12-18 14:07:14 -05006434 if (!rdev->pm.dpm_enabled) {
6435 r = si_mc_load_microcode(rdev);
6436 if (r) {
6437 DRM_ERROR("Failed to load MC firmware!\n");
6438 return r;
6439 }
Alex Deucher9b136d52012-03-20 17:18:23 -04006440 }
6441
Alex Deucher9b136d52012-03-20 17:18:23 -04006442 r = si_pcie_gart_enable(rdev);
6443 if (r)
6444 return r;
6445 si_gpu_init(rdev);
6446
Alex Deucher9b136d52012-03-20 17:18:23 -04006447 /* allocate rlc buffers */
Alex Deucher1fd11772013-04-17 17:53:50 -04006448 if (rdev->family == CHIP_VERDE) {
6449 rdev->rlc.reg_list = verde_rlc_save_restore_register_list;
6450 rdev->rlc.reg_list_size =
6451 (u32)ARRAY_SIZE(verde_rlc_save_restore_register_list);
6452 }
6453 rdev->rlc.cs_data = si_cs_data;
6454 r = sumo_rlc_init(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006455 if (r) {
6456 DRM_ERROR("Failed to init rlc BOs!\n");
6457 return r;
6458 }
6459
6460 /* allocate wb buffer */
6461 r = radeon_wb_init(rdev);
6462 if (r)
6463 return r;
6464
6465 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
6466 if (r) {
6467 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
6468 return r;
6469 }
6470
6471 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
6472 if (r) {
6473 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
6474 return r;
6475 }
6476
6477 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
6478 if (r) {
6479 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
6480 return r;
6481 }
6482
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006483 r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
6484 if (r) {
6485 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
6486 return r;
6487 }
6488
6489 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
6490 if (r) {
6491 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
6492 return r;
6493 }
6494
Alex Deucher1df0d522013-04-26 18:03:44 -04006495 if (rdev->has_uvd) {
Christian Könige409b122013-08-13 11:56:53 +02006496 r = uvd_v2_2_resume(rdev);
Alex Deucher1df0d522013-04-26 18:03:44 -04006497 if (!r) {
6498 r = radeon_fence_driver_start_ring(rdev,
6499 R600_RING_TYPE_UVD_INDEX);
6500 if (r)
6501 dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
6502 }
Christian Königf2ba57b2013-04-08 12:41:29 +02006503 if (r)
Alex Deucher1df0d522013-04-26 18:03:44 -04006504 rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
Christian Königf2ba57b2013-04-08 12:41:29 +02006505 }
Christian Königf2ba57b2013-04-08 12:41:29 +02006506
Alex Deucher9b136d52012-03-20 17:18:23 -04006507 /* Enable IRQ */
Adis Hamziće49f3952013-06-02 16:47:54 +02006508 if (!rdev->irq.installed) {
6509 r = radeon_irq_kms_init(rdev);
6510 if (r)
6511 return r;
6512 }
6513
Alex Deucher9b136d52012-03-20 17:18:23 -04006514 r = si_irq_init(rdev);
6515 if (r) {
6516 DRM_ERROR("radeon: IH init failed (%d).\n", r);
6517 radeon_irq_kms_fini(rdev);
6518 return r;
6519 }
6520 si_irq_set(rdev);
6521
6522 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
6523 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
Christian König2e1e6da2013-08-13 11:56:52 +02006524 RADEON_CP_PACKET2);
Alex Deucher9b136d52012-03-20 17:18:23 -04006525 if (r)
6526 return r;
6527
6528 ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
6529 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP1_RPTR_OFFSET,
Christian König2e1e6da2013-08-13 11:56:52 +02006530 RADEON_CP_PACKET2);
Alex Deucher9b136d52012-03-20 17:18:23 -04006531 if (r)
6532 return r;
6533
6534 ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
6535 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP2_RPTR_OFFSET,
Christian König2e1e6da2013-08-13 11:56:52 +02006536 RADEON_CP_PACKET2);
Alex Deucher9b136d52012-03-20 17:18:23 -04006537 if (r)
6538 return r;
6539
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006540 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
6541 r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
Christian König2e1e6da2013-08-13 11:56:52 +02006542 DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0));
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006543 if (r)
6544 return r;
6545
6546 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
6547 r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
Christian König2e1e6da2013-08-13 11:56:52 +02006548 DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0, 0));
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006549 if (r)
6550 return r;
6551
Alex Deucher9b136d52012-03-20 17:18:23 -04006552 r = si_cp_load_microcode(rdev);
6553 if (r)
6554 return r;
6555 r = si_cp_resume(rdev);
6556 if (r)
6557 return r;
6558
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006559 r = cayman_dma_resume(rdev);
6560 if (r)
6561 return r;
6562
Alex Deucher1df0d522013-04-26 18:03:44 -04006563 if (rdev->has_uvd) {
6564 ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
6565 if (ring->ring_size) {
Christian König02c9f7f2013-08-13 11:56:51 +02006566 r = radeon_ring_init(rdev, ring, ring->ring_size, 0,
Christian König2e1e6da2013-08-13 11:56:52 +02006567 RADEON_CP_PACKET2);
Alex Deucher1df0d522013-04-26 18:03:44 -04006568 if (!r)
Christian Könige409b122013-08-13 11:56:53 +02006569 r = uvd_v1_0_init(rdev);
Alex Deucher1df0d522013-04-26 18:03:44 -04006570 if (r)
6571 DRM_ERROR("radeon: failed initializing UVD (%d).\n", r);
6572 }
Christian Königf2ba57b2013-04-08 12:41:29 +02006573 }
6574
Christian König2898c342012-07-05 11:55:34 +02006575 r = radeon_ib_pool_init(rdev);
6576 if (r) {
6577 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
Alex Deucher9b136d52012-03-20 17:18:23 -04006578 return r;
Christian König2898c342012-07-05 11:55:34 +02006579 }
Alex Deucher9b136d52012-03-20 17:18:23 -04006580
Christian Königc6105f22012-07-05 14:32:00 +02006581 r = radeon_vm_manager_init(rdev);
6582 if (r) {
6583 dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
Alex Deucher9b136d52012-03-20 17:18:23 -04006584 return r;
Christian Königc6105f22012-07-05 14:32:00 +02006585 }
Alex Deucher9b136d52012-03-20 17:18:23 -04006586
Alex Deucherb5306022013-07-31 16:51:33 -04006587 r = dce6_audio_init(rdev);
6588 if (r)
6589 return r;
6590
Alex Deucher9b136d52012-03-20 17:18:23 -04006591 return 0;
6592}
6593
6594int si_resume(struct radeon_device *rdev)
6595{
6596 int r;
6597
6598 /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
6599 * posting will perform necessary task to bring back GPU into good
6600 * shape.
6601 */
6602 /* post card */
6603 atom_asic_init(rdev->mode_info.atom_context);
6604
Alex Deucher205996c2013-03-01 17:08:42 -05006605 /* init golden registers */
6606 si_init_golden_registers(rdev);
6607
Alex Deucher6c7bcce2013-12-18 14:07:14 -05006608 radeon_pm_resume(rdev);
6609
Alex Deucher9b136d52012-03-20 17:18:23 -04006610 rdev->accel_working = true;
6611 r = si_startup(rdev);
6612 if (r) {
6613 DRM_ERROR("si startup failed on resume\n");
6614 rdev->accel_working = false;
6615 return r;
6616 }
6617
6618 return r;
6619
6620}
6621
6622int si_suspend(struct radeon_device *rdev)
6623{
Alex Deucher6c7bcce2013-12-18 14:07:14 -05006624 radeon_pm_suspend(rdev);
Alex Deucherb5306022013-07-31 16:51:33 -04006625 dce6_audio_fini(rdev);
Alex Deucherfa3daf92013-03-11 15:32:26 -04006626 radeon_vm_manager_fini(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006627 si_cp_enable(rdev, false);
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006628 cayman_dma_stop(rdev);
Alex Deucher1df0d522013-04-26 18:03:44 -04006629 if (rdev->has_uvd) {
Christian Könige409b122013-08-13 11:56:53 +02006630 uvd_v1_0_fini(rdev);
Alex Deucher1df0d522013-04-26 18:03:44 -04006631 radeon_uvd_suspend(rdev);
6632 }
Alex Deuchere16866e2013-08-08 19:34:07 -04006633 si_fini_pg(rdev);
6634 si_fini_cg(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006635 si_irq_suspend(rdev);
6636 radeon_wb_disable(rdev);
6637 si_pcie_gart_disable(rdev);
6638 return 0;
6639}
6640
6641/* Plan is to move initialization in that function and use
6642 * helper function so that radeon_device_init pretty much
6643 * do nothing more than calling asic specific function. This
6644 * should also allow to remove a bunch of callback function
6645 * like vram_info.
6646 */
6647int si_init(struct radeon_device *rdev)
6648{
6649 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
6650 int r;
6651
Alex Deucher9b136d52012-03-20 17:18:23 -04006652 /* Read BIOS */
6653 if (!radeon_get_bios(rdev)) {
6654 if (ASIC_IS_AVIVO(rdev))
6655 return -EINVAL;
6656 }
6657 /* Must be an ATOMBIOS */
6658 if (!rdev->is_atom_bios) {
6659 dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
6660 return -EINVAL;
6661 }
6662 r = radeon_atombios_init(rdev);
6663 if (r)
6664 return r;
6665
6666 /* Post card if necessary */
6667 if (!radeon_card_posted(rdev)) {
6668 if (!rdev->bios) {
6669 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
6670 return -EINVAL;
6671 }
6672 DRM_INFO("GPU not posted. posting now...\n");
6673 atom_asic_init(rdev->mode_info.atom_context);
6674 }
Alex Deucher205996c2013-03-01 17:08:42 -05006675 /* init golden registers */
6676 si_init_golden_registers(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006677 /* Initialize scratch registers */
6678 si_scratch_init(rdev);
6679 /* Initialize surface registers */
6680 radeon_surface_init(rdev);
6681 /* Initialize clocks */
6682 radeon_get_clock_info(rdev->ddev);
6683
6684 /* Fence driver */
6685 r = radeon_fence_driver_init(rdev);
6686 if (r)
6687 return r;
6688
6689 /* initialize memory controller */
6690 r = si_mc_init(rdev);
6691 if (r)
6692 return r;
6693 /* Memory manager */
6694 r = radeon_bo_init(rdev);
6695 if (r)
6696 return r;
6697
Alex Deucher01ac8792013-12-18 19:11:27 -05006698 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
6699 !rdev->rlc_fw || !rdev->mc_fw) {
6700 r = si_init_microcode(rdev);
6701 if (r) {
6702 DRM_ERROR("Failed to load firmware!\n");
6703 return r;
6704 }
6705 }
6706
Alex Deucher6c7bcce2013-12-18 14:07:14 -05006707 /* Initialize power management */
6708 radeon_pm_init(rdev);
6709
Alex Deucher9b136d52012-03-20 17:18:23 -04006710 ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
6711 ring->ring_obj = NULL;
6712 r600_ring_init(rdev, ring, 1024 * 1024);
6713
6714 ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
6715 ring->ring_obj = NULL;
6716 r600_ring_init(rdev, ring, 1024 * 1024);
6717
6718 ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
6719 ring->ring_obj = NULL;
6720 r600_ring_init(rdev, ring, 1024 * 1024);
6721
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006722 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
6723 ring->ring_obj = NULL;
6724 r600_ring_init(rdev, ring, 64 * 1024);
6725
6726 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
6727 ring->ring_obj = NULL;
6728 r600_ring_init(rdev, ring, 64 * 1024);
6729
Alex Deucher1df0d522013-04-26 18:03:44 -04006730 if (rdev->has_uvd) {
6731 r = radeon_uvd_init(rdev);
6732 if (!r) {
6733 ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
6734 ring->ring_obj = NULL;
6735 r600_ring_init(rdev, ring, 4096);
6736 }
Christian Königf2ba57b2013-04-08 12:41:29 +02006737 }
6738
Alex Deucher9b136d52012-03-20 17:18:23 -04006739 rdev->ih.ring_obj = NULL;
6740 r600_ih_ring_init(rdev, 64 * 1024);
6741
6742 r = r600_pcie_gart_init(rdev);
6743 if (r)
6744 return r;
6745
Alex Deucher9b136d52012-03-20 17:18:23 -04006746 rdev->accel_working = true;
Alex Deucher9b136d52012-03-20 17:18:23 -04006747 r = si_startup(rdev);
6748 if (r) {
6749 dev_err(rdev->dev, "disabling GPU acceleration\n");
6750 si_cp_fini(rdev);
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006751 cayman_dma_fini(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006752 si_irq_fini(rdev);
Alex Deucher1fd11772013-04-17 17:53:50 -04006753 sumo_rlc_fini(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006754 radeon_wb_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02006755 radeon_ib_pool_fini(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006756 radeon_vm_manager_fini(rdev);
6757 radeon_irq_kms_fini(rdev);
6758 si_pcie_gart_fini(rdev);
6759 rdev->accel_working = false;
6760 }
6761
6762 /* Don't start up if the MC ucode is missing.
6763 * The default clocks and voltages before the MC ucode
6764 * is loaded are not suffient for advanced operations.
6765 */
6766 if (!rdev->mc_fw) {
6767 DRM_ERROR("radeon: MC ucode required for NI+.\n");
6768 return -EINVAL;
6769 }
6770
6771 return 0;
6772}
6773
6774void si_fini(struct radeon_device *rdev)
6775{
Alex Deucher6c7bcce2013-12-18 14:07:14 -05006776 radeon_pm_fini(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006777 si_cp_fini(rdev);
Alex Deucher8c5fd7e2012-12-04 15:28:18 -05006778 cayman_dma_fini(rdev);
Alex Deucherf8f84ac2013-03-07 12:56:35 -05006779 si_fini_pg(rdev);
Alex Deuchere16866e2013-08-08 19:34:07 -04006780 si_fini_cg(rdev);
Alex Deuchere0bcf1652013-02-15 11:56:59 -05006781 si_irq_fini(rdev);
Alex Deucher1fd11772013-04-17 17:53:50 -04006782 sumo_rlc_fini(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006783 radeon_wb_fini(rdev);
6784 radeon_vm_manager_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02006785 radeon_ib_pool_fini(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006786 radeon_irq_kms_fini(rdev);
Christian König2858c002013-08-01 17:34:07 +02006787 if (rdev->has_uvd) {
Christian Könige409b122013-08-13 11:56:53 +02006788 uvd_v1_0_fini(rdev);
Alex Deucher1df0d522013-04-26 18:03:44 -04006789 radeon_uvd_fini(rdev);
Christian König2858c002013-08-01 17:34:07 +02006790 }
Alex Deucher9b136d52012-03-20 17:18:23 -04006791 si_pcie_gart_fini(rdev);
6792 r600_vram_scratch_fini(rdev);
6793 radeon_gem_fini(rdev);
Alex Deucher9b136d52012-03-20 17:18:23 -04006794 radeon_fence_driver_fini(rdev);
6795 radeon_bo_fini(rdev);
6796 radeon_atombios_fini(rdev);
6797 kfree(rdev->bios);
6798 rdev->bios = NULL;
6799}
6800
Marek Olšák6759a0a2012-08-09 16:34:17 +02006801/**
Alex Deucherd0418892013-01-24 10:35:23 -05006802 * si_get_gpu_clock_counter - return GPU clock counter snapshot
Marek Olšák6759a0a2012-08-09 16:34:17 +02006803 *
6804 * @rdev: radeon_device pointer
6805 *
6806 * Fetches a GPU clock counter snapshot (SI).
6807 * Returns the 64 bit clock counter snapshot.
6808 */
Alex Deucherd0418892013-01-24 10:35:23 -05006809uint64_t si_get_gpu_clock_counter(struct radeon_device *rdev)
Marek Olšák6759a0a2012-08-09 16:34:17 +02006810{
6811 uint64_t clock;
6812
6813 mutex_lock(&rdev->gpu_clock_mutex);
6814 WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
6815 clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
6816 ((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
6817 mutex_unlock(&rdev->gpu_clock_mutex);
6818 return clock;
6819}
Christian König2539eb02013-04-08 12:41:34 +02006820
Christian König2539eb02013-04-08 12:41:34 +02006821int si_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
6822{
Christian Königfacd1122013-04-29 11:55:02 +02006823 unsigned fb_div = 0, vclk_div = 0, dclk_div = 0;
Christian König2539eb02013-04-08 12:41:34 +02006824 int r;
6825
Christian König4ed10832013-04-18 15:25:58 +02006826 /* bypass vclk and dclk with bclk */
6827 WREG32_P(CG_UPLL_FUNC_CNTL_2,
6828 VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
6829 ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
6830
6831 /* put PLL in bypass mode */
6832 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK);
6833
6834 if (!vclk || !dclk) {
6835 /* keep the Bypass mode, put PLL to sleep */
6836 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
6837 return 0;
6838 }
6839
Christian Königfacd1122013-04-29 11:55:02 +02006840 r = radeon_uvd_calc_upll_dividers(rdev, vclk, dclk, 125000, 250000,
6841 16384, 0x03FFFFFF, 0, 128, 5,
6842 &fb_div, &vclk_div, &dclk_div);
6843 if (r)
6844 return r;
Christian König2539eb02013-04-08 12:41:34 +02006845
6846 /* set RESET_ANTI_MUX to 0 */
6847 WREG32_P(CG_UPLL_FUNC_CNTL_5, 0, ~RESET_ANTI_MUX_MASK);
6848
6849 /* set VCO_MODE to 1 */
6850 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_VCO_MODE_MASK, ~UPLL_VCO_MODE_MASK);
6851
6852 /* toggle UPLL_SLEEP to 1 then back to 0 */
6853 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
6854 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_SLEEP_MASK);
6855
6856 /* deassert UPLL_RESET */
6857 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
6858
6859 mdelay(1);
6860
Christian Königfacd1122013-04-29 11:55:02 +02006861 r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
Christian König2539eb02013-04-08 12:41:34 +02006862 if (r)
6863 return r;
6864
6865 /* assert UPLL_RESET again */
6866 WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
6867
6868 /* disable spread spectrum. */
6869 WREG32_P(CG_UPLL_SPREAD_SPECTRUM, 0, ~SSEN_MASK);
6870
6871 /* set feedback divider */
Christian Königfacd1122013-04-29 11:55:02 +02006872 WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(fb_div), ~UPLL_FB_DIV_MASK);
Christian König2539eb02013-04-08 12:41:34 +02006873
6874 /* set ref divider to 0 */
6875 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_REF_DIV_MASK);
6876
Christian Königfacd1122013-04-29 11:55:02 +02006877 if (fb_div < 307200)
Christian König2539eb02013-04-08 12:41:34 +02006878 WREG32_P(CG_UPLL_FUNC_CNTL_4, 0, ~UPLL_SPARE_ISPARE9);
6879 else
6880 WREG32_P(CG_UPLL_FUNC_CNTL_4, UPLL_SPARE_ISPARE9, ~UPLL_SPARE_ISPARE9);
6881
6882 /* set PDIV_A and PDIV_B */
6883 WREG32_P(CG_UPLL_FUNC_CNTL_2,
Christian Königfacd1122013-04-29 11:55:02 +02006884 UPLL_PDIV_A(vclk_div) | UPLL_PDIV_B(dclk_div),
Christian König2539eb02013-04-08 12:41:34 +02006885 ~(UPLL_PDIV_A_MASK | UPLL_PDIV_B_MASK));
6886
6887 /* give the PLL some time to settle */
6888 mdelay(15);
6889
6890 /* deassert PLL_RESET */
6891 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
6892
6893 mdelay(15);
6894
6895 /* switch from bypass mode to normal mode */
6896 WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
6897
Christian Königfacd1122013-04-29 11:55:02 +02006898 r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
Christian König2539eb02013-04-08 12:41:34 +02006899 if (r)
6900 return r;
6901
6902 /* switch VCLK and DCLK selection */
6903 WREG32_P(CG_UPLL_FUNC_CNTL_2,
6904 VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
6905 ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
6906
6907 mdelay(100);
6908
6909 return 0;
6910}
Alex Deucherb9d305d2013-02-14 17:16:51 -05006911
6912static void si_pcie_gen3_enable(struct radeon_device *rdev)
6913{
6914 struct pci_dev *root = rdev->pdev->bus->self;
6915 int bridge_pos, gpu_pos;
6916 u32 speed_cntl, mask, current_data_rate;
6917 int ret, i;
6918 u16 tmp16;
6919
6920 if (radeon_pcie_gen2 == 0)
6921 return;
6922
6923 if (rdev->flags & RADEON_IS_IGP)
6924 return;
6925
6926 if (!(rdev->flags & RADEON_IS_PCIE))
6927 return;
6928
6929 ret = drm_pcie_get_speed_cap_mask(rdev->ddev, &mask);
6930 if (ret != 0)
6931 return;
6932
6933 if (!(mask & (DRM_PCIE_SPEED_50 | DRM_PCIE_SPEED_80)))
6934 return;
6935
6936 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
6937 current_data_rate = (speed_cntl & LC_CURRENT_DATA_RATE_MASK) >>
6938 LC_CURRENT_DATA_RATE_SHIFT;
6939 if (mask & DRM_PCIE_SPEED_80) {
6940 if (current_data_rate == 2) {
6941 DRM_INFO("PCIE gen 3 link speeds already enabled\n");
6942 return;
6943 }
6944 DRM_INFO("enabling PCIE gen 3 link speeds, disable with radeon.pcie_gen2=0\n");
6945 } else if (mask & DRM_PCIE_SPEED_50) {
6946 if (current_data_rate == 1) {
6947 DRM_INFO("PCIE gen 2 link speeds already enabled\n");
6948 return;
6949 }
6950 DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
6951 }
6952
6953 bridge_pos = pci_pcie_cap(root);
6954 if (!bridge_pos)
6955 return;
6956
6957 gpu_pos = pci_pcie_cap(rdev->pdev);
6958 if (!gpu_pos)
6959 return;
6960
6961 if (mask & DRM_PCIE_SPEED_80) {
6962 /* re-try equalization if gen3 is not already enabled */
6963 if (current_data_rate != 2) {
6964 u16 bridge_cfg, gpu_cfg;
6965 u16 bridge_cfg2, gpu_cfg2;
6966 u32 max_lw, current_lw, tmp;
6967
6968 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
6969 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
6970
6971 tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
6972 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
6973
6974 tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
6975 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
6976
6977 tmp = RREG32_PCIE(PCIE_LC_STATUS1);
6978 max_lw = (tmp & LC_DETECTED_LINK_WIDTH_MASK) >> LC_DETECTED_LINK_WIDTH_SHIFT;
6979 current_lw = (tmp & LC_OPERATING_LINK_WIDTH_MASK) >> LC_OPERATING_LINK_WIDTH_SHIFT;
6980
6981 if (current_lw < max_lw) {
6982 tmp = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
6983 if (tmp & LC_RENEGOTIATION_SUPPORT) {
6984 tmp &= ~(LC_LINK_WIDTH_MASK | LC_UPCONFIGURE_DIS);
6985 tmp |= (max_lw << LC_LINK_WIDTH_SHIFT);
6986 tmp |= LC_UPCONFIGURE_SUPPORT | LC_RENEGOTIATE_EN | LC_RECONFIG_NOW;
6987 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, tmp);
6988 }
6989 }
6990
6991 for (i = 0; i < 10; i++) {
6992 /* check status */
6993 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_DEVSTA, &tmp16);
6994 if (tmp16 & PCI_EXP_DEVSTA_TRPND)
6995 break;
6996
6997 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
6998 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
6999
7000 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &bridge_cfg2);
7001 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &gpu_cfg2);
7002
7003 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
7004 tmp |= LC_SET_QUIESCE;
7005 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
7006
7007 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
7008 tmp |= LC_REDO_EQ;
7009 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
7010
7011 mdelay(100);
7012
7013 /* linkctl */
7014 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &tmp16);
7015 tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
7016 tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
7017 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
7018
7019 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, &tmp16);
7020 tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
7021 tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
7022 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
7023
7024 /* linkctl2 */
7025 pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &tmp16);
7026 tmp16 &= ~((1 << 4) | (7 << 9));
7027 tmp16 |= (bridge_cfg2 & ((1 << 4) | (7 << 9)));
7028 pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, tmp16);
7029
7030 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
7031 tmp16 &= ~((1 << 4) | (7 << 9));
7032 tmp16 |= (gpu_cfg2 & ((1 << 4) | (7 << 9)));
7033 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
7034
7035 tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
7036 tmp &= ~LC_SET_QUIESCE;
7037 WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
7038 }
7039 }
7040 }
7041
7042 /* set the link speed */
7043 speed_cntl |= LC_FORCE_EN_SW_SPEED_CHANGE | LC_FORCE_DIS_HW_SPEED_CHANGE;
7044 speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
7045 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
7046
7047 pci_read_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
7048 tmp16 &= ~0xf;
7049 if (mask & DRM_PCIE_SPEED_80)
7050 tmp16 |= 3; /* gen3 */
7051 else if (mask & DRM_PCIE_SPEED_50)
7052 tmp16 |= 2; /* gen2 */
7053 else
7054 tmp16 |= 1; /* gen1 */
7055 pci_write_config_word(rdev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
7056
7057 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
7058 speed_cntl |= LC_INITIATE_LINK_SPEED_CHANGE;
7059 WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
7060
7061 for (i = 0; i < rdev->usec_timeout; i++) {
7062 speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
7063 if ((speed_cntl & LC_INITIATE_LINK_SPEED_CHANGE) == 0)
7064 break;
7065 udelay(1);
7066 }
7067}
7068
Alex Deuchere0bcf1652013-02-15 11:56:59 -05007069static void si_program_aspm(struct radeon_device *rdev)
7070{
7071 u32 data, orig;
7072 bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
7073 bool disable_clkreq = false;
7074
Alex Deucher1294d4a2013-07-16 15:58:50 -04007075 if (radeon_aspm == 0)
7076 return;
7077
Alex Deuchere0bcf1652013-02-15 11:56:59 -05007078 if (!(rdev->flags & RADEON_IS_PCIE))
7079 return;
7080
7081 orig = data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
7082 data &= ~LC_XMIT_N_FTS_MASK;
7083 data |= LC_XMIT_N_FTS(0x24) | LC_XMIT_N_FTS_OVERRIDE_EN;
7084 if (orig != data)
7085 WREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL, data);
7086
7087 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL3);
7088 data |= LC_GO_TO_RECOVERY;
7089 if (orig != data)
7090 WREG32_PCIE_PORT(PCIE_LC_CNTL3, data);
7091
7092 orig = data = RREG32_PCIE(PCIE_P_CNTL);
7093 data |= P_IGNORE_EDB_ERR;
7094 if (orig != data)
7095 WREG32_PCIE(PCIE_P_CNTL, data);
7096
7097 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
7098 data &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
7099 data |= LC_PMI_TO_L1_DIS;
7100 if (!disable_l0s)
7101 data |= LC_L0S_INACTIVITY(7);
7102
7103 if (!disable_l1) {
7104 data |= LC_L1_INACTIVITY(7);
7105 data &= ~LC_PMI_TO_L1_DIS;
7106 if (orig != data)
7107 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
7108
7109 if (!disable_plloff_in_l1) {
7110 bool clk_req_support;
7111
7112 orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
7113 data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
7114 data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
7115 if (orig != data)
7116 WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
7117
7118 orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
7119 data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
7120 data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
7121 if (orig != data)
7122 WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
7123
7124 orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
7125 data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
7126 data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
7127 if (orig != data)
7128 WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
7129
7130 orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
7131 data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
7132 data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
7133 if (orig != data)
7134 WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
7135
7136 if ((rdev->family != CHIP_OLAND) && (rdev->family != CHIP_HAINAN)) {
7137 orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
7138 data &= ~PLL_RAMP_UP_TIME_0_MASK;
7139 if (orig != data)
7140 WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
7141
7142 orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
7143 data &= ~PLL_RAMP_UP_TIME_1_MASK;
7144 if (orig != data)
7145 WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
7146
7147 orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_2);
7148 data &= ~PLL_RAMP_UP_TIME_2_MASK;
7149 if (orig != data)
7150 WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_2, data);
7151
7152 orig = data = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_3);
7153 data &= ~PLL_RAMP_UP_TIME_3_MASK;
7154 if (orig != data)
7155 WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_3, data);
7156
7157 orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
7158 data &= ~PLL_RAMP_UP_TIME_0_MASK;
7159 if (orig != data)
7160 WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
7161
7162 orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
7163 data &= ~PLL_RAMP_UP_TIME_1_MASK;
7164 if (orig != data)
7165 WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
7166
7167 orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_2);
7168 data &= ~PLL_RAMP_UP_TIME_2_MASK;
7169 if (orig != data)
7170 WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_2, data);
7171
7172 orig = data = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_3);
7173 data &= ~PLL_RAMP_UP_TIME_3_MASK;
7174 if (orig != data)
7175 WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_3, data);
7176 }
7177 orig = data = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
7178 data &= ~LC_DYN_LANES_PWR_STATE_MASK;
7179 data |= LC_DYN_LANES_PWR_STATE(3);
7180 if (orig != data)
7181 WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
7182
7183 orig = data = RREG32_PIF_PHY0(PB0_PIF_CNTL);
7184 data &= ~LS2_EXIT_TIME_MASK;
7185 if ((rdev->family == CHIP_OLAND) || (rdev->family == CHIP_HAINAN))
7186 data |= LS2_EXIT_TIME(5);
7187 if (orig != data)
7188 WREG32_PIF_PHY0(PB0_PIF_CNTL, data);
7189
7190 orig = data = RREG32_PIF_PHY1(PB1_PIF_CNTL);
7191 data &= ~LS2_EXIT_TIME_MASK;
7192 if ((rdev->family == CHIP_OLAND) || (rdev->family == CHIP_HAINAN))
7193 data |= LS2_EXIT_TIME(5);
7194 if (orig != data)
7195 WREG32_PIF_PHY1(PB1_PIF_CNTL, data);
7196
7197 if (!disable_clkreq) {
7198 struct pci_dev *root = rdev->pdev->bus->self;
7199 u32 lnkcap;
7200
7201 clk_req_support = false;
7202 pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
7203 if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
7204 clk_req_support = true;
7205 } else {
7206 clk_req_support = false;
7207 }
7208
7209 if (clk_req_support) {
7210 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL2);
7211 data |= LC_ALLOW_PDWN_IN_L1 | LC_ALLOW_PDWN_IN_L23;
7212 if (orig != data)
7213 WREG32_PCIE_PORT(PCIE_LC_CNTL2, data);
7214
7215 orig = data = RREG32(THM_CLK_CNTL);
7216 data &= ~(CMON_CLK_SEL_MASK | TMON_CLK_SEL_MASK);
7217 data |= CMON_CLK_SEL(1) | TMON_CLK_SEL(1);
7218 if (orig != data)
7219 WREG32(THM_CLK_CNTL, data);
7220
7221 orig = data = RREG32(MISC_CLK_CNTL);
7222 data &= ~(DEEP_SLEEP_CLK_SEL_MASK | ZCLK_SEL_MASK);
7223 data |= DEEP_SLEEP_CLK_SEL(1) | ZCLK_SEL(1);
7224 if (orig != data)
7225 WREG32(MISC_CLK_CNTL, data);
7226
7227 orig = data = RREG32(CG_CLKPIN_CNTL);
7228 data &= ~BCLK_AS_XCLK;
7229 if (orig != data)
7230 WREG32(CG_CLKPIN_CNTL, data);
7231
7232 orig = data = RREG32(CG_CLKPIN_CNTL_2);
7233 data &= ~FORCE_BIF_REFCLK_EN;
7234 if (orig != data)
7235 WREG32(CG_CLKPIN_CNTL_2, data);
7236
7237 orig = data = RREG32(MPLL_BYPASSCLK_SEL);
7238 data &= ~MPLL_CLKOUT_SEL_MASK;
7239 data |= MPLL_CLKOUT_SEL(4);
7240 if (orig != data)
7241 WREG32(MPLL_BYPASSCLK_SEL, data);
7242
7243 orig = data = RREG32(SPLL_CNTL_MODE);
7244 data &= ~SPLL_REFCLK_SEL_MASK;
7245 if (orig != data)
7246 WREG32(SPLL_CNTL_MODE, data);
7247 }
7248 }
7249 } else {
7250 if (orig != data)
7251 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
7252 }
7253
7254 orig = data = RREG32_PCIE(PCIE_CNTL2);
7255 data |= SLV_MEM_LS_EN | MST_MEM_LS_EN | REPLAY_MEM_LS_EN;
7256 if (orig != data)
7257 WREG32_PCIE(PCIE_CNTL2, data);
7258
7259 if (!disable_l0s) {
7260 data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
7261 if((data & LC_N_FTS_MASK) == LC_N_FTS_MASK) {
7262 data = RREG32_PCIE(PCIE_LC_STATUS1);
7263 if ((data & LC_REVERSE_XMIT) && (data & LC_REVERSE_RCVR)) {
7264 orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
7265 data &= ~LC_L0S_INACTIVITY_MASK;
7266 if (orig != data)
7267 WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
7268 }
7269 }
7270 }
7271}