blob: 7436b91699d0fd09ec2af763576fd13d096e135a [file] [log] [blame]
Alex Deucher0af62b02011-01-06 21:19:31 -05001/*
2 * Copyright 2010 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Alex Deucher
23 */
24#include <linux/firmware.h>
25#include <linux/platform_device.h>
26#include <linux/slab.h>
Paul Gortmakere0cd3602011-08-30 11:04:30 -040027#include <linux/module.h>
David Howells760285e2012-10-02 18:01:07 +010028#include <drm/drmP.h>
Alex Deucher0af62b02011-01-06 21:19:31 -050029#include "radeon.h"
30#include "radeon_asic.h"
David Howells760285e2012-10-02 18:01:07 +010031#include <drm/radeon_drm.h>
Alex Deucher0af62b02011-01-06 21:19:31 -050032#include "nid.h"
33#include "atom.h"
34#include "ni_reg.h"
Alex Deucher0c88a022011-03-02 20:07:31 -050035#include "cayman_blit_shaders.h"
Alex Deucher0af62b02011-01-06 21:19:31 -050036
Alex Deucher168757e2013-01-18 19:17:22 -050037extern bool evergreen_is_display_hung(struct radeon_device *rdev);
Alex Deucher187e3592013-01-18 14:51:38 -050038extern void evergreen_print_gpu_status_regs(struct radeon_device *rdev);
Alex Deucherb9952a82011-03-02 20:07:33 -050039extern void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save);
40extern void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save);
41extern int evergreen_mc_wait_for_idle(struct radeon_device *rdev);
Alex Deucher755d8192011-03-02 20:07:34 -050042extern void evergreen_mc_program(struct radeon_device *rdev);
43extern void evergreen_irq_suspend(struct radeon_device *rdev);
44extern int evergreen_mc_init(struct radeon_device *rdev);
Alex Deucherd054ac12011-09-01 17:46:15 +000045extern void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev);
Ilija Hadzicb07759b2011-09-20 10:22:58 -040046extern void evergreen_pcie_gen2_enable(struct radeon_device *rdev);
Alex Deucherc420c742012-03-20 17:18:39 -040047extern void si_rlc_fini(struct radeon_device *rdev);
48extern int si_rlc_init(struct radeon_device *rdev);
Alex Deucherb9952a82011-03-02 20:07:33 -050049
Alex Deucher0af62b02011-01-06 21:19:31 -050050#define EVERGREEN_PFP_UCODE_SIZE 1120
51#define EVERGREEN_PM4_UCODE_SIZE 1376
52#define EVERGREEN_RLC_UCODE_SIZE 768
53#define BTC_MC_UCODE_SIZE 6024
54
Alex Deucher9b8253c2011-03-02 20:07:28 -050055#define CAYMAN_PFP_UCODE_SIZE 2176
56#define CAYMAN_PM4_UCODE_SIZE 2176
57#define CAYMAN_RLC_UCODE_SIZE 1024
58#define CAYMAN_MC_UCODE_SIZE 6037
59
Alex Deucherc420c742012-03-20 17:18:39 -040060#define ARUBA_RLC_UCODE_SIZE 1536
61
Alex Deucher0af62b02011-01-06 21:19:31 -050062/* Firmware Names */
63MODULE_FIRMWARE("radeon/BARTS_pfp.bin");
64MODULE_FIRMWARE("radeon/BARTS_me.bin");
65MODULE_FIRMWARE("radeon/BARTS_mc.bin");
66MODULE_FIRMWARE("radeon/BTC_rlc.bin");
67MODULE_FIRMWARE("radeon/TURKS_pfp.bin");
68MODULE_FIRMWARE("radeon/TURKS_me.bin");
69MODULE_FIRMWARE("radeon/TURKS_mc.bin");
70MODULE_FIRMWARE("radeon/CAICOS_pfp.bin");
71MODULE_FIRMWARE("radeon/CAICOS_me.bin");
72MODULE_FIRMWARE("radeon/CAICOS_mc.bin");
Alex Deucher9b8253c2011-03-02 20:07:28 -050073MODULE_FIRMWARE("radeon/CAYMAN_pfp.bin");
74MODULE_FIRMWARE("radeon/CAYMAN_me.bin");
75MODULE_FIRMWARE("radeon/CAYMAN_mc.bin");
76MODULE_FIRMWARE("radeon/CAYMAN_rlc.bin");
Alex Deucherc420c742012-03-20 17:18:39 -040077MODULE_FIRMWARE("radeon/ARUBA_pfp.bin");
78MODULE_FIRMWARE("radeon/ARUBA_me.bin");
79MODULE_FIRMWARE("radeon/ARUBA_rlc.bin");
Alex Deucher0af62b02011-01-06 21:19:31 -050080
Alex Deuchera2c96a22013-02-28 17:58:36 -050081
82static const u32 cayman_golden_registers2[] =
83{
84 0x3e5c, 0xffffffff, 0x00000000,
85 0x3e48, 0xffffffff, 0x00000000,
86 0x3e4c, 0xffffffff, 0x00000000,
87 0x3e64, 0xffffffff, 0x00000000,
88 0x3e50, 0xffffffff, 0x00000000,
89 0x3e60, 0xffffffff, 0x00000000
90};
91
92static const u32 cayman_golden_registers[] =
93{
94 0x5eb4, 0xffffffff, 0x00000002,
95 0x5e78, 0x8f311ff1, 0x001000f0,
96 0x3f90, 0xffff0000, 0xff000000,
97 0x9148, 0xffff0000, 0xff000000,
98 0x3f94, 0xffff0000, 0xff000000,
99 0x914c, 0xffff0000, 0xff000000,
100 0xc78, 0x00000080, 0x00000080,
101 0xbd4, 0x70073777, 0x00011003,
102 0xd02c, 0xbfffff1f, 0x08421000,
103 0xd0b8, 0x73773777, 0x02011003,
104 0x5bc0, 0x00200000, 0x50100000,
105 0x98f8, 0x33773777, 0x02011003,
106 0x98fc, 0xffffffff, 0x76541032,
107 0x7030, 0x31000311, 0x00000011,
108 0x2f48, 0x33773777, 0x42010001,
109 0x6b28, 0x00000010, 0x00000012,
110 0x7728, 0x00000010, 0x00000012,
111 0x10328, 0x00000010, 0x00000012,
112 0x10f28, 0x00000010, 0x00000012,
113 0x11b28, 0x00000010, 0x00000012,
114 0x12728, 0x00000010, 0x00000012,
115 0x240c, 0x000007ff, 0x00000000,
116 0x8a14, 0xf000001f, 0x00000007,
117 0x8b24, 0x3fff3fff, 0x00ff0fff,
118 0x8b10, 0x0000ff0f, 0x00000000,
119 0x28a4c, 0x07ffffff, 0x06000000,
120 0x10c, 0x00000001, 0x00010003,
121 0xa02c, 0xffffffff, 0x0000009b,
122 0x913c, 0x0000010f, 0x01000100,
123 0x8c04, 0xf8ff00ff, 0x40600060,
124 0x28350, 0x00000f01, 0x00000000,
125 0x9508, 0x3700001f, 0x00000002,
126 0x960c, 0xffffffff, 0x54763210,
127 0x88c4, 0x001f3ae3, 0x00000082,
128 0x88d0, 0xffffffff, 0x0f40df40,
129 0x88d4, 0x0000001f, 0x00000010,
130 0x8974, 0xffffffff, 0x00000000
131};
132
133static const u32 dvst_golden_registers2[] =
134{
135 0x8f8, 0xffffffff, 0,
136 0x8fc, 0x00380000, 0,
137 0x8f8, 0xffffffff, 1,
138 0x8fc, 0x0e000000, 0
139};
140
141static const u32 dvst_golden_registers[] =
142{
143 0x690, 0x3fff3fff, 0x20c00033,
144 0x918c, 0x0fff0fff, 0x00010006,
145 0x91a8, 0x0fff0fff, 0x00010006,
146 0x9150, 0xffffdfff, 0x6e944040,
147 0x917c, 0x0fff0fff, 0x00030002,
148 0x9198, 0x0fff0fff, 0x00030002,
149 0x915c, 0x0fff0fff, 0x00010000,
150 0x3f90, 0xffff0001, 0xff000000,
151 0x9178, 0x0fff0fff, 0x00070000,
152 0x9194, 0x0fff0fff, 0x00070000,
153 0x9148, 0xffff0001, 0xff000000,
154 0x9190, 0x0fff0fff, 0x00090008,
155 0x91ac, 0x0fff0fff, 0x00090008,
156 0x3f94, 0xffff0000, 0xff000000,
157 0x914c, 0xffff0000, 0xff000000,
158 0x929c, 0x00000fff, 0x00000001,
159 0x55e4, 0xff607fff, 0xfc000100,
160 0x8a18, 0xff000fff, 0x00000100,
161 0x8b28, 0xff000fff, 0x00000100,
162 0x9144, 0xfffc0fff, 0x00000100,
163 0x6ed8, 0x00010101, 0x00010000,
164 0x9830, 0xffffffff, 0x00000000,
165 0x9834, 0xf00fffff, 0x00000400,
166 0x9838, 0xfffffffe, 0x00000000,
167 0xd0c0, 0xff000fff, 0x00000100,
168 0xd02c, 0xbfffff1f, 0x08421000,
169 0xd0b8, 0x73773777, 0x12010001,
170 0x5bb0, 0x000000f0, 0x00000070,
171 0x98f8, 0x73773777, 0x12010001,
172 0x98fc, 0xffffffff, 0x00000010,
173 0x9b7c, 0x00ff0000, 0x00fc0000,
174 0x8030, 0x00001f0f, 0x0000100a,
175 0x2f48, 0x73773777, 0x12010001,
176 0x2408, 0x00030000, 0x000c007f,
177 0x8a14, 0xf000003f, 0x00000007,
178 0x8b24, 0x3fff3fff, 0x00ff0fff,
179 0x8b10, 0x0000ff0f, 0x00000000,
180 0x28a4c, 0x07ffffff, 0x06000000,
181 0x4d8, 0x00000fff, 0x00000100,
182 0xa008, 0xffffffff, 0x00010000,
183 0x913c, 0xffff03ff, 0x01000100,
184 0x8c00, 0x000000ff, 0x00000003,
185 0x8c04, 0xf8ff00ff, 0x40600060,
186 0x8cf0, 0x1fff1fff, 0x08e00410,
187 0x28350, 0x00000f01, 0x00000000,
188 0x9508, 0xf700071f, 0x00000002,
189 0x960c, 0xffffffff, 0x54763210,
190 0x20ef8, 0x01ff01ff, 0x00000002,
191 0x20e98, 0xfffffbff, 0x00200000,
192 0x2015c, 0xffffffff, 0x00000f40,
193 0x88c4, 0x001f3ae3, 0x00000082,
194 0x8978, 0x3fffffff, 0x04050140,
195 0x88d4, 0x0000001f, 0x00000010,
196 0x8974, 0xffffffff, 0x00000000
197};
198
199static const u32 scrapper_golden_registers[] =
200{
201 0x690, 0x3fff3fff, 0x20c00033,
202 0x918c, 0x0fff0fff, 0x00010006,
203 0x918c, 0x0fff0fff, 0x00010006,
204 0x91a8, 0x0fff0fff, 0x00010006,
205 0x91a8, 0x0fff0fff, 0x00010006,
206 0x9150, 0xffffdfff, 0x6e944040,
207 0x9150, 0xffffdfff, 0x6e944040,
208 0x917c, 0x0fff0fff, 0x00030002,
209 0x917c, 0x0fff0fff, 0x00030002,
210 0x9198, 0x0fff0fff, 0x00030002,
211 0x9198, 0x0fff0fff, 0x00030002,
212 0x915c, 0x0fff0fff, 0x00010000,
213 0x915c, 0x0fff0fff, 0x00010000,
214 0x3f90, 0xffff0001, 0xff000000,
215 0x3f90, 0xffff0001, 0xff000000,
216 0x9178, 0x0fff0fff, 0x00070000,
217 0x9178, 0x0fff0fff, 0x00070000,
218 0x9194, 0x0fff0fff, 0x00070000,
219 0x9194, 0x0fff0fff, 0x00070000,
220 0x9148, 0xffff0001, 0xff000000,
221 0x9148, 0xffff0001, 0xff000000,
222 0x9190, 0x0fff0fff, 0x00090008,
223 0x9190, 0x0fff0fff, 0x00090008,
224 0x91ac, 0x0fff0fff, 0x00090008,
225 0x91ac, 0x0fff0fff, 0x00090008,
226 0x3f94, 0xffff0000, 0xff000000,
227 0x3f94, 0xffff0000, 0xff000000,
228 0x914c, 0xffff0000, 0xff000000,
229 0x914c, 0xffff0000, 0xff000000,
230 0x929c, 0x00000fff, 0x00000001,
231 0x929c, 0x00000fff, 0x00000001,
232 0x55e4, 0xff607fff, 0xfc000100,
233 0x8a18, 0xff000fff, 0x00000100,
234 0x8a18, 0xff000fff, 0x00000100,
235 0x8b28, 0xff000fff, 0x00000100,
236 0x8b28, 0xff000fff, 0x00000100,
237 0x9144, 0xfffc0fff, 0x00000100,
238 0x9144, 0xfffc0fff, 0x00000100,
239 0x6ed8, 0x00010101, 0x00010000,
240 0x9830, 0xffffffff, 0x00000000,
241 0x9830, 0xffffffff, 0x00000000,
242 0x9834, 0xf00fffff, 0x00000400,
243 0x9834, 0xf00fffff, 0x00000400,
244 0x9838, 0xfffffffe, 0x00000000,
245 0x9838, 0xfffffffe, 0x00000000,
246 0xd0c0, 0xff000fff, 0x00000100,
247 0xd02c, 0xbfffff1f, 0x08421000,
248 0xd02c, 0xbfffff1f, 0x08421000,
249 0xd0b8, 0x73773777, 0x12010001,
250 0xd0b8, 0x73773777, 0x12010001,
251 0x5bb0, 0x000000f0, 0x00000070,
252 0x98f8, 0x73773777, 0x12010001,
253 0x98f8, 0x73773777, 0x12010001,
254 0x98fc, 0xffffffff, 0x00000010,
255 0x98fc, 0xffffffff, 0x00000010,
256 0x9b7c, 0x00ff0000, 0x00fc0000,
257 0x9b7c, 0x00ff0000, 0x00fc0000,
258 0x8030, 0x00001f0f, 0x0000100a,
259 0x8030, 0x00001f0f, 0x0000100a,
260 0x2f48, 0x73773777, 0x12010001,
261 0x2f48, 0x73773777, 0x12010001,
262 0x2408, 0x00030000, 0x000c007f,
263 0x8a14, 0xf000003f, 0x00000007,
264 0x8a14, 0xf000003f, 0x00000007,
265 0x8b24, 0x3fff3fff, 0x00ff0fff,
266 0x8b24, 0x3fff3fff, 0x00ff0fff,
267 0x8b10, 0x0000ff0f, 0x00000000,
268 0x8b10, 0x0000ff0f, 0x00000000,
269 0x28a4c, 0x07ffffff, 0x06000000,
270 0x28a4c, 0x07ffffff, 0x06000000,
271 0x4d8, 0x00000fff, 0x00000100,
272 0x4d8, 0x00000fff, 0x00000100,
273 0xa008, 0xffffffff, 0x00010000,
274 0xa008, 0xffffffff, 0x00010000,
275 0x913c, 0xffff03ff, 0x01000100,
276 0x913c, 0xffff03ff, 0x01000100,
277 0x90e8, 0x001fffff, 0x010400c0,
278 0x8c00, 0x000000ff, 0x00000003,
279 0x8c00, 0x000000ff, 0x00000003,
280 0x8c04, 0xf8ff00ff, 0x40600060,
281 0x8c04, 0xf8ff00ff, 0x40600060,
282 0x8c30, 0x0000000f, 0x00040005,
283 0x8cf0, 0x1fff1fff, 0x08e00410,
284 0x8cf0, 0x1fff1fff, 0x08e00410,
285 0x900c, 0x00ffffff, 0x0017071f,
286 0x28350, 0x00000f01, 0x00000000,
287 0x28350, 0x00000f01, 0x00000000,
288 0x9508, 0xf700071f, 0x00000002,
289 0x9508, 0xf700071f, 0x00000002,
290 0x9688, 0x00300000, 0x0017000f,
291 0x960c, 0xffffffff, 0x54763210,
292 0x960c, 0xffffffff, 0x54763210,
293 0x20ef8, 0x01ff01ff, 0x00000002,
294 0x20e98, 0xfffffbff, 0x00200000,
295 0x2015c, 0xffffffff, 0x00000f40,
296 0x88c4, 0x001f3ae3, 0x00000082,
297 0x88c4, 0x001f3ae3, 0x00000082,
298 0x8978, 0x3fffffff, 0x04050140,
299 0x8978, 0x3fffffff, 0x04050140,
300 0x88d4, 0x0000001f, 0x00000010,
301 0x88d4, 0x0000001f, 0x00000010,
302 0x8974, 0xffffffff, 0x00000000,
303 0x8974, 0xffffffff, 0x00000000
304};
305
306static void ni_init_golden_registers(struct radeon_device *rdev)
307{
308 switch (rdev->family) {
309 case CHIP_CAYMAN:
310 radeon_program_register_sequence(rdev,
311 cayman_golden_registers,
312 (const u32)ARRAY_SIZE(cayman_golden_registers));
313 radeon_program_register_sequence(rdev,
314 cayman_golden_registers2,
315 (const u32)ARRAY_SIZE(cayman_golden_registers2));
316 break;
317 case CHIP_ARUBA:
318 if ((rdev->pdev->device == 0x9900) ||
319 (rdev->pdev->device == 0x9901) ||
320 (rdev->pdev->device == 0x9903) ||
321 (rdev->pdev->device == 0x9904) ||
322 (rdev->pdev->device == 0x9905) ||
323 (rdev->pdev->device == 0x9906) ||
324 (rdev->pdev->device == 0x9907) ||
325 (rdev->pdev->device == 0x9908) ||
326 (rdev->pdev->device == 0x9909) ||
327 (rdev->pdev->device == 0x990A) ||
328 (rdev->pdev->device == 0x990B) ||
329 (rdev->pdev->device == 0x990C) ||
330 (rdev->pdev->device == 0x990D) ||
331 (rdev->pdev->device == 0x990E) ||
332 (rdev->pdev->device == 0x990F) ||
333 (rdev->pdev->device == 0x9910) ||
334 (rdev->pdev->device == 0x9913) ||
335 (rdev->pdev->device == 0x9917) ||
336 (rdev->pdev->device == 0x9918)) {
337 radeon_program_register_sequence(rdev,
338 dvst_golden_registers,
339 (const u32)ARRAY_SIZE(dvst_golden_registers));
340 radeon_program_register_sequence(rdev,
341 dvst_golden_registers2,
342 (const u32)ARRAY_SIZE(dvst_golden_registers2));
343 } else {
344 radeon_program_register_sequence(rdev,
345 scrapper_golden_registers,
346 (const u32)ARRAY_SIZE(scrapper_golden_registers));
347 radeon_program_register_sequence(rdev,
348 dvst_golden_registers2,
349 (const u32)ARRAY_SIZE(dvst_golden_registers2));
350 }
351 break;
352 default:
353 break;
354 }
355}
356
Alex Deucher0af62b02011-01-06 21:19:31 -0500357#define BTC_IO_MC_REGS_SIZE 29
358
359static const u32 barts_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
360 {0x00000077, 0xff010100},
361 {0x00000078, 0x00000000},
362 {0x00000079, 0x00001434},
363 {0x0000007a, 0xcc08ec08},
364 {0x0000007b, 0x00040000},
365 {0x0000007c, 0x000080c0},
366 {0x0000007d, 0x09000000},
367 {0x0000007e, 0x00210404},
368 {0x00000081, 0x08a8e800},
369 {0x00000082, 0x00030444},
370 {0x00000083, 0x00000000},
371 {0x00000085, 0x00000001},
372 {0x00000086, 0x00000002},
373 {0x00000087, 0x48490000},
374 {0x00000088, 0x20244647},
375 {0x00000089, 0x00000005},
376 {0x0000008b, 0x66030000},
377 {0x0000008c, 0x00006603},
378 {0x0000008d, 0x00000100},
379 {0x0000008f, 0x00001c0a},
380 {0x00000090, 0xff000001},
381 {0x00000094, 0x00101101},
382 {0x00000095, 0x00000fff},
383 {0x00000096, 0x00116fff},
384 {0x00000097, 0x60010000},
385 {0x00000098, 0x10010000},
386 {0x00000099, 0x00006000},
387 {0x0000009a, 0x00001000},
388 {0x0000009f, 0x00946a00}
389};
390
391static const u32 turks_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
392 {0x00000077, 0xff010100},
393 {0x00000078, 0x00000000},
394 {0x00000079, 0x00001434},
395 {0x0000007a, 0xcc08ec08},
396 {0x0000007b, 0x00040000},
397 {0x0000007c, 0x000080c0},
398 {0x0000007d, 0x09000000},
399 {0x0000007e, 0x00210404},
400 {0x00000081, 0x08a8e800},
401 {0x00000082, 0x00030444},
402 {0x00000083, 0x00000000},
403 {0x00000085, 0x00000001},
404 {0x00000086, 0x00000002},
405 {0x00000087, 0x48490000},
406 {0x00000088, 0x20244647},
407 {0x00000089, 0x00000005},
408 {0x0000008b, 0x66030000},
409 {0x0000008c, 0x00006603},
410 {0x0000008d, 0x00000100},
411 {0x0000008f, 0x00001c0a},
412 {0x00000090, 0xff000001},
413 {0x00000094, 0x00101101},
414 {0x00000095, 0x00000fff},
415 {0x00000096, 0x00116fff},
416 {0x00000097, 0x60010000},
417 {0x00000098, 0x10010000},
418 {0x00000099, 0x00006000},
419 {0x0000009a, 0x00001000},
420 {0x0000009f, 0x00936a00}
421};
422
423static const u32 caicos_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
424 {0x00000077, 0xff010100},
425 {0x00000078, 0x00000000},
426 {0x00000079, 0x00001434},
427 {0x0000007a, 0xcc08ec08},
428 {0x0000007b, 0x00040000},
429 {0x0000007c, 0x000080c0},
430 {0x0000007d, 0x09000000},
431 {0x0000007e, 0x00210404},
432 {0x00000081, 0x08a8e800},
433 {0x00000082, 0x00030444},
434 {0x00000083, 0x00000000},
435 {0x00000085, 0x00000001},
436 {0x00000086, 0x00000002},
437 {0x00000087, 0x48490000},
438 {0x00000088, 0x20244647},
439 {0x00000089, 0x00000005},
440 {0x0000008b, 0x66030000},
441 {0x0000008c, 0x00006603},
442 {0x0000008d, 0x00000100},
443 {0x0000008f, 0x00001c0a},
444 {0x00000090, 0xff000001},
445 {0x00000094, 0x00101101},
446 {0x00000095, 0x00000fff},
447 {0x00000096, 0x00116fff},
448 {0x00000097, 0x60010000},
449 {0x00000098, 0x10010000},
450 {0x00000099, 0x00006000},
451 {0x0000009a, 0x00001000},
452 {0x0000009f, 0x00916a00}
453};
454
Alex Deucher9b8253c2011-03-02 20:07:28 -0500455static const u32 cayman_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
456 {0x00000077, 0xff010100},
457 {0x00000078, 0x00000000},
458 {0x00000079, 0x00001434},
459 {0x0000007a, 0xcc08ec08},
460 {0x0000007b, 0x00040000},
461 {0x0000007c, 0x000080c0},
462 {0x0000007d, 0x09000000},
463 {0x0000007e, 0x00210404},
464 {0x00000081, 0x08a8e800},
465 {0x00000082, 0x00030444},
466 {0x00000083, 0x00000000},
467 {0x00000085, 0x00000001},
468 {0x00000086, 0x00000002},
469 {0x00000087, 0x48490000},
470 {0x00000088, 0x20244647},
471 {0x00000089, 0x00000005},
472 {0x0000008b, 0x66030000},
473 {0x0000008c, 0x00006603},
474 {0x0000008d, 0x00000100},
475 {0x0000008f, 0x00001c0a},
476 {0x00000090, 0xff000001},
477 {0x00000094, 0x00101101},
478 {0x00000095, 0x00000fff},
479 {0x00000096, 0x00116fff},
480 {0x00000097, 0x60010000},
481 {0x00000098, 0x10010000},
482 {0x00000099, 0x00006000},
483 {0x0000009a, 0x00001000},
484 {0x0000009f, 0x00976b00}
485};
486
Alex Deucher755d8192011-03-02 20:07:34 -0500487int ni_mc_load_microcode(struct radeon_device *rdev)
Alex Deucher0af62b02011-01-06 21:19:31 -0500488{
489 const __be32 *fw_data;
490 u32 mem_type, running, blackout = 0;
491 u32 *io_mc_regs;
Alex Deucher9b8253c2011-03-02 20:07:28 -0500492 int i, ucode_size, regs_size;
Alex Deucher0af62b02011-01-06 21:19:31 -0500493
494 if (!rdev->mc_fw)
495 return -EINVAL;
496
497 switch (rdev->family) {
498 case CHIP_BARTS:
499 io_mc_regs = (u32 *)&barts_io_mc_regs;
Alex Deucher9b8253c2011-03-02 20:07:28 -0500500 ucode_size = BTC_MC_UCODE_SIZE;
501 regs_size = BTC_IO_MC_REGS_SIZE;
Alex Deucher0af62b02011-01-06 21:19:31 -0500502 break;
503 case CHIP_TURKS:
504 io_mc_regs = (u32 *)&turks_io_mc_regs;
Alex Deucher9b8253c2011-03-02 20:07:28 -0500505 ucode_size = BTC_MC_UCODE_SIZE;
506 regs_size = BTC_IO_MC_REGS_SIZE;
Alex Deucher0af62b02011-01-06 21:19:31 -0500507 break;
508 case CHIP_CAICOS:
509 default:
510 io_mc_regs = (u32 *)&caicos_io_mc_regs;
Alex Deucher9b8253c2011-03-02 20:07:28 -0500511 ucode_size = BTC_MC_UCODE_SIZE;
512 regs_size = BTC_IO_MC_REGS_SIZE;
513 break;
514 case CHIP_CAYMAN:
515 io_mc_regs = (u32 *)&cayman_io_mc_regs;
516 ucode_size = CAYMAN_MC_UCODE_SIZE;
517 regs_size = BTC_IO_MC_REGS_SIZE;
Alex Deucher0af62b02011-01-06 21:19:31 -0500518 break;
519 }
520
521 mem_type = (RREG32(MC_SEQ_MISC0) & MC_SEQ_MISC0_GDDR5_MASK) >> MC_SEQ_MISC0_GDDR5_SHIFT;
522 running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
523
524 if ((mem_type == MC_SEQ_MISC0_GDDR5_VALUE) && (running == 0)) {
525 if (running) {
526 blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
527 WREG32(MC_SHARED_BLACKOUT_CNTL, 1);
528 }
529
530 /* reset the engine and set to writable */
531 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
532 WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
533
534 /* load mc io regs */
Alex Deucher9b8253c2011-03-02 20:07:28 -0500535 for (i = 0; i < regs_size; i++) {
Alex Deucher0af62b02011-01-06 21:19:31 -0500536 WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
537 WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
538 }
539 /* load the MC ucode */
540 fw_data = (const __be32 *)rdev->mc_fw->data;
Alex Deucher9b8253c2011-03-02 20:07:28 -0500541 for (i = 0; i < ucode_size; i++)
Alex Deucher0af62b02011-01-06 21:19:31 -0500542 WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
543
544 /* put the engine back into the active state */
545 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
546 WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
547 WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
548
549 /* wait for training to complete */
Alex Deucher0e2c9782011-11-02 18:08:25 -0400550 for (i = 0; i < rdev->usec_timeout; i++) {
551 if (RREG32(MC_IO_PAD_CNTL_D0) & MEM_FALL_OUT_CMD)
552 break;
553 udelay(1);
554 }
Alex Deucher0af62b02011-01-06 21:19:31 -0500555
556 if (running)
557 WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
558 }
559
560 return 0;
561}
562
563int ni_init_microcode(struct radeon_device *rdev)
564{
565 struct platform_device *pdev;
566 const char *chip_name;
567 const char *rlc_chip_name;
568 size_t pfp_req_size, me_req_size, rlc_req_size, mc_req_size;
569 char fw_name[30];
570 int err;
571
572 DRM_DEBUG("\n");
573
574 pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
575 err = IS_ERR(pdev);
576 if (err) {
577 printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
578 return -EINVAL;
579 }
580
581 switch (rdev->family) {
582 case CHIP_BARTS:
583 chip_name = "BARTS";
584 rlc_chip_name = "BTC";
Alex Deucher9b8253c2011-03-02 20:07:28 -0500585 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
586 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
587 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
588 mc_req_size = BTC_MC_UCODE_SIZE * 4;
Alex Deucher0af62b02011-01-06 21:19:31 -0500589 break;
590 case CHIP_TURKS:
591 chip_name = "TURKS";
592 rlc_chip_name = "BTC";
Alex Deucher9b8253c2011-03-02 20:07:28 -0500593 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
594 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
595 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
596 mc_req_size = BTC_MC_UCODE_SIZE * 4;
Alex Deucher0af62b02011-01-06 21:19:31 -0500597 break;
598 case CHIP_CAICOS:
599 chip_name = "CAICOS";
600 rlc_chip_name = "BTC";
Alex Deucher9b8253c2011-03-02 20:07:28 -0500601 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
602 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
603 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
604 mc_req_size = BTC_MC_UCODE_SIZE * 4;
605 break;
606 case CHIP_CAYMAN:
607 chip_name = "CAYMAN";
608 rlc_chip_name = "CAYMAN";
609 pfp_req_size = CAYMAN_PFP_UCODE_SIZE * 4;
610 me_req_size = CAYMAN_PM4_UCODE_SIZE * 4;
611 rlc_req_size = CAYMAN_RLC_UCODE_SIZE * 4;
612 mc_req_size = CAYMAN_MC_UCODE_SIZE * 4;
Alex Deucher0af62b02011-01-06 21:19:31 -0500613 break;
Alex Deucherc420c742012-03-20 17:18:39 -0400614 case CHIP_ARUBA:
615 chip_name = "ARUBA";
616 rlc_chip_name = "ARUBA";
617 /* pfp/me same size as CAYMAN */
618 pfp_req_size = CAYMAN_PFP_UCODE_SIZE * 4;
619 me_req_size = CAYMAN_PM4_UCODE_SIZE * 4;
620 rlc_req_size = ARUBA_RLC_UCODE_SIZE * 4;
621 mc_req_size = 0;
622 break;
Alex Deucher0af62b02011-01-06 21:19:31 -0500623 default: BUG();
624 }
625
Alex Deucher0af62b02011-01-06 21:19:31 -0500626 DRM_INFO("Loading %s Microcode\n", chip_name);
627
628 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
629 err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
630 if (err)
631 goto out;
632 if (rdev->pfp_fw->size != pfp_req_size) {
633 printk(KERN_ERR
634 "ni_cp: Bogus length %zu in firmware \"%s\"\n",
635 rdev->pfp_fw->size, fw_name);
636 err = -EINVAL;
637 goto out;
638 }
639
640 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
641 err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
642 if (err)
643 goto out;
644 if (rdev->me_fw->size != me_req_size) {
645 printk(KERN_ERR
646 "ni_cp: Bogus length %zu in firmware \"%s\"\n",
647 rdev->me_fw->size, fw_name);
648 err = -EINVAL;
649 }
650
651 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
652 err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
653 if (err)
654 goto out;
655 if (rdev->rlc_fw->size != rlc_req_size) {
656 printk(KERN_ERR
657 "ni_rlc: Bogus length %zu in firmware \"%s\"\n",
658 rdev->rlc_fw->size, fw_name);
659 err = -EINVAL;
660 }
661
Alex Deucherc420c742012-03-20 17:18:39 -0400662 /* no MC ucode on TN */
663 if (!(rdev->flags & RADEON_IS_IGP)) {
664 snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
665 err = request_firmware(&rdev->mc_fw, fw_name, &pdev->dev);
666 if (err)
667 goto out;
668 if (rdev->mc_fw->size != mc_req_size) {
669 printk(KERN_ERR
670 "ni_mc: Bogus length %zu in firmware \"%s\"\n",
671 rdev->mc_fw->size, fw_name);
672 err = -EINVAL;
673 }
Alex Deucher0af62b02011-01-06 21:19:31 -0500674 }
675out:
676 platform_device_unregister(pdev);
677
678 if (err) {
679 if (err != -EINVAL)
680 printk(KERN_ERR
681 "ni_cp: Failed to load firmware \"%s\"\n",
682 fw_name);
683 release_firmware(rdev->pfp_fw);
684 rdev->pfp_fw = NULL;
685 release_firmware(rdev->me_fw);
686 rdev->me_fw = NULL;
687 release_firmware(rdev->rlc_fw);
688 rdev->rlc_fw = NULL;
689 release_firmware(rdev->mc_fw);
690 rdev->mc_fw = NULL;
691 }
692 return err;
693}
694
Alex Deucherfecf1d02011-03-02 20:07:29 -0500695/*
696 * Core functions
697 */
Alex Deucherfecf1d02011-03-02 20:07:29 -0500698static void cayman_gpu_init(struct radeon_device *rdev)
699{
Alex Deucherfecf1d02011-03-02 20:07:29 -0500700 u32 gb_addr_config = 0;
701 u32 mc_shared_chmap, mc_arb_ramcfg;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500702 u32 cgts_tcc_disable;
703 u32 sx_debug_1;
704 u32 smx_dc_ctl0;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500705 u32 cgts_sm_ctrl_reg;
706 u32 hdp_host_path_cntl;
707 u32 tmp;
Alex Deucher416a2bd2012-05-31 19:00:25 -0400708 u32 disabled_rb_mask;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500709 int i, j;
710
711 switch (rdev->family) {
712 case CHIP_CAYMAN:
Alex Deucherfecf1d02011-03-02 20:07:29 -0500713 rdev->config.cayman.max_shader_engines = 2;
714 rdev->config.cayman.max_pipes_per_simd = 4;
715 rdev->config.cayman.max_tile_pipes = 8;
716 rdev->config.cayman.max_simds_per_se = 12;
717 rdev->config.cayman.max_backends_per_se = 4;
718 rdev->config.cayman.max_texture_channel_caches = 8;
719 rdev->config.cayman.max_gprs = 256;
720 rdev->config.cayman.max_threads = 256;
721 rdev->config.cayman.max_gs_threads = 32;
722 rdev->config.cayman.max_stack_entries = 512;
723 rdev->config.cayman.sx_num_of_sets = 8;
724 rdev->config.cayman.sx_max_export_size = 256;
725 rdev->config.cayman.sx_max_export_pos_size = 64;
726 rdev->config.cayman.sx_max_export_smx_size = 192;
727 rdev->config.cayman.max_hw_contexts = 8;
728 rdev->config.cayman.sq_num_cf_insts = 2;
729
730 rdev->config.cayman.sc_prim_fifo_size = 0x100;
731 rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30;
732 rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -0400733 gb_addr_config = CAYMAN_GB_ADDR_CONFIG_GOLDEN;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500734 break;
Alex Deucher7b76e472012-03-20 17:18:36 -0400735 case CHIP_ARUBA:
736 default:
737 rdev->config.cayman.max_shader_engines = 1;
738 rdev->config.cayman.max_pipes_per_simd = 4;
739 rdev->config.cayman.max_tile_pipes = 2;
740 if ((rdev->pdev->device == 0x9900) ||
Alex Deucherd430f7d2012-06-05 09:50:28 -0400741 (rdev->pdev->device == 0x9901) ||
742 (rdev->pdev->device == 0x9905) ||
743 (rdev->pdev->device == 0x9906) ||
744 (rdev->pdev->device == 0x9907) ||
745 (rdev->pdev->device == 0x9908) ||
746 (rdev->pdev->device == 0x9909) ||
Alex Deuchere4d17062013-03-08 13:44:15 -0500747 (rdev->pdev->device == 0x990B) ||
748 (rdev->pdev->device == 0x990C) ||
749 (rdev->pdev->device == 0x990F) ||
Alex Deucherd430f7d2012-06-05 09:50:28 -0400750 (rdev->pdev->device == 0x9910) ||
Alex Deuchere4d17062013-03-08 13:44:15 -0500751 (rdev->pdev->device == 0x9917) ||
752 (rdev->pdev->device == 0x9999)) {
Alex Deucher7b76e472012-03-20 17:18:36 -0400753 rdev->config.cayman.max_simds_per_se = 6;
754 rdev->config.cayman.max_backends_per_se = 2;
755 } else if ((rdev->pdev->device == 0x9903) ||
Alex Deucherd430f7d2012-06-05 09:50:28 -0400756 (rdev->pdev->device == 0x9904) ||
757 (rdev->pdev->device == 0x990A) ||
Alex Deuchere4d17062013-03-08 13:44:15 -0500758 (rdev->pdev->device == 0x990D) ||
759 (rdev->pdev->device == 0x990E) ||
Alex Deucherd430f7d2012-06-05 09:50:28 -0400760 (rdev->pdev->device == 0x9913) ||
761 (rdev->pdev->device == 0x9918)) {
Alex Deucher7b76e472012-03-20 17:18:36 -0400762 rdev->config.cayman.max_simds_per_se = 4;
763 rdev->config.cayman.max_backends_per_se = 2;
Alex Deucherd430f7d2012-06-05 09:50:28 -0400764 } else if ((rdev->pdev->device == 0x9919) ||
765 (rdev->pdev->device == 0x9990) ||
766 (rdev->pdev->device == 0x9991) ||
767 (rdev->pdev->device == 0x9994) ||
Alex Deuchere4d17062013-03-08 13:44:15 -0500768 (rdev->pdev->device == 0x9995) ||
769 (rdev->pdev->device == 0x9996) ||
770 (rdev->pdev->device == 0x999A) ||
Alex Deucherd430f7d2012-06-05 09:50:28 -0400771 (rdev->pdev->device == 0x99A0)) {
Alex Deucher7b76e472012-03-20 17:18:36 -0400772 rdev->config.cayman.max_simds_per_se = 3;
773 rdev->config.cayman.max_backends_per_se = 1;
774 } else {
775 rdev->config.cayman.max_simds_per_se = 2;
776 rdev->config.cayman.max_backends_per_se = 1;
777 }
778 rdev->config.cayman.max_texture_channel_caches = 2;
779 rdev->config.cayman.max_gprs = 256;
780 rdev->config.cayman.max_threads = 256;
781 rdev->config.cayman.max_gs_threads = 32;
782 rdev->config.cayman.max_stack_entries = 512;
783 rdev->config.cayman.sx_num_of_sets = 8;
784 rdev->config.cayman.sx_max_export_size = 256;
785 rdev->config.cayman.sx_max_export_pos_size = 64;
786 rdev->config.cayman.sx_max_export_smx_size = 192;
787 rdev->config.cayman.max_hw_contexts = 8;
788 rdev->config.cayman.sq_num_cf_insts = 2;
789
790 rdev->config.cayman.sc_prim_fifo_size = 0x40;
791 rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30;
792 rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -0400793 gb_addr_config = ARUBA_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher7b76e472012-03-20 17:18:36 -0400794 break;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500795 }
796
797 /* Initialize HDP */
798 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
799 WREG32((0x2c14 + j), 0x00000000);
800 WREG32((0x2c18 + j), 0x00000000);
801 WREG32((0x2c1c + j), 0x00000000);
802 WREG32((0x2c20 + j), 0x00000000);
803 WREG32((0x2c24 + j), 0x00000000);
804 }
805
806 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
807
Alex Deucherd054ac12011-09-01 17:46:15 +0000808 evergreen_fix_pci_max_read_req_size(rdev);
809
Alex Deucherfecf1d02011-03-02 20:07:29 -0500810 mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
811 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
812
Alex Deucherfecf1d02011-03-02 20:07:29 -0500813 tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
814 rdev->config.cayman.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
815 if (rdev->config.cayman.mem_row_size_in_kb > 4)
816 rdev->config.cayman.mem_row_size_in_kb = 4;
817 /* XXX use MC settings? */
818 rdev->config.cayman.shader_engine_tile_size = 32;
819 rdev->config.cayman.num_gpus = 1;
820 rdev->config.cayman.multi_gpu_tile_size = 64;
821
Alex Deucherfecf1d02011-03-02 20:07:29 -0500822 tmp = (gb_addr_config & NUM_PIPES_MASK) >> NUM_PIPES_SHIFT;
823 rdev->config.cayman.num_tile_pipes = (1 << tmp);
824 tmp = (gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT;
825 rdev->config.cayman.mem_max_burst_length_bytes = (tmp + 1) * 256;
826 tmp = (gb_addr_config & NUM_SHADER_ENGINES_MASK) >> NUM_SHADER_ENGINES_SHIFT;
827 rdev->config.cayman.num_shader_engines = tmp + 1;
828 tmp = (gb_addr_config & NUM_GPUS_MASK) >> NUM_GPUS_SHIFT;
829 rdev->config.cayman.num_gpus = tmp + 1;
830 tmp = (gb_addr_config & MULTI_GPU_TILE_SIZE_MASK) >> MULTI_GPU_TILE_SIZE_SHIFT;
831 rdev->config.cayman.multi_gpu_tile_size = 1 << tmp;
832 tmp = (gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT;
833 rdev->config.cayman.mem_row_size_in_kb = 1 << tmp;
834
Alex Deucher416a2bd2012-05-31 19:00:25 -0400835
Alex Deucherfecf1d02011-03-02 20:07:29 -0500836 /* setup tiling info dword. gb_addr_config is not adequate since it does
837 * not have bank info, so create a custom tiling dword.
838 * bits 3:0 num_pipes
839 * bits 7:4 num_banks
840 * bits 11:8 group_size
841 * bits 15:12 row_size
842 */
843 rdev->config.cayman.tile_config = 0;
844 switch (rdev->config.cayman.num_tile_pipes) {
845 case 1:
846 default:
847 rdev->config.cayman.tile_config |= (0 << 0);
848 break;
849 case 2:
850 rdev->config.cayman.tile_config |= (1 << 0);
851 break;
852 case 4:
853 rdev->config.cayman.tile_config |= (2 << 0);
854 break;
855 case 8:
856 rdev->config.cayman.tile_config |= (3 << 0);
857 break;
858 }
Alex Deucher7b76e472012-03-20 17:18:36 -0400859
860 /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */
861 if (rdev->flags & RADEON_IS_IGP)
Alex Deucher1f73cca2012-05-24 22:55:15 -0400862 rdev->config.cayman.tile_config |= 1 << 4;
Alex Deucher29d65402012-05-31 18:53:36 -0400863 else {
Alex Deucher5b23c902012-07-31 11:05:11 -0400864 switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
865 case 0: /* four banks */
Alex Deucher29d65402012-05-31 18:53:36 -0400866 rdev->config.cayman.tile_config |= 0 << 4;
Alex Deucher5b23c902012-07-31 11:05:11 -0400867 break;
868 case 1: /* eight banks */
869 rdev->config.cayman.tile_config |= 1 << 4;
870 break;
871 case 2: /* sixteen banks */
872 default:
873 rdev->config.cayman.tile_config |= 2 << 4;
874 break;
875 }
Alex Deucher29d65402012-05-31 18:53:36 -0400876 }
Alex Deucherfecf1d02011-03-02 20:07:29 -0500877 rdev->config.cayman.tile_config |=
Dave Airliecde50832011-05-19 14:14:41 +1000878 ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500879 rdev->config.cayman.tile_config |=
880 ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
881
Alex Deucher416a2bd2012-05-31 19:00:25 -0400882 tmp = 0;
883 for (i = (rdev->config.cayman.max_shader_engines - 1); i >= 0; i--) {
884 u32 rb_disable_bitmap;
885
886 WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
887 WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
888 rb_disable_bitmap = (RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000) >> 16;
889 tmp <<= 4;
890 tmp |= rb_disable_bitmap;
891 }
892 /* enabled rb are just the one not disabled :) */
893 disabled_rb_mask = tmp;
Alex Deuchercedb6552013-04-09 10:13:22 -0400894 tmp = 0;
895 for (i = 0; i < (rdev->config.cayman.max_backends_per_se * rdev->config.cayman.max_shader_engines); i++)
896 tmp |= (1 << i);
897 /* if all the backends are disabled, fix it up here */
898 if ((disabled_rb_mask & tmp) == tmp) {
899 for (i = 0; i < (rdev->config.cayman.max_backends_per_se * rdev->config.cayman.max_shader_engines); i++)
900 disabled_rb_mask &= ~(1 << i);
901 }
Alex Deucher416a2bd2012-05-31 19:00:25 -0400902
903 WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
904 WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
905
Alex Deucherfecf1d02011-03-02 20:07:29 -0500906 WREG32(GB_ADDR_CONFIG, gb_addr_config);
907 WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
Alex Deucher7c1c7c12013-04-05 10:28:08 -0400908 if (ASIC_IS_DCE6(rdev))
909 WREG32(DMIF_ADDR_CALC, gb_addr_config);
Alex Deucherfecf1d02011-03-02 20:07:29 -0500910 WREG32(HDP_ADDR_CONFIG, gb_addr_config);
Alex Deucherf60cbd12012-12-04 15:27:33 -0500911 WREG32(DMA_TILING_CONFIG + DMA0_REGISTER_OFFSET, gb_addr_config);
912 WREG32(DMA_TILING_CONFIG + DMA1_REGISTER_OFFSET, gb_addr_config);
Christian König9a210592013-04-08 12:41:37 +0200913 WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
914 WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
915 WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
Alex Deucherfecf1d02011-03-02 20:07:29 -0500916
Alex Deucher8f612b22013-03-11 19:28:39 -0400917 if ((rdev->config.cayman.max_backends_per_se == 1) &&
918 (rdev->flags & RADEON_IS_IGP)) {
919 if ((disabled_rb_mask & 3) == 1) {
920 /* RB0 disabled, RB1 enabled */
921 tmp = 0x11111111;
922 } else {
923 /* RB1 disabled, RB0 enabled */
924 tmp = 0x00000000;
925 }
926 } else {
927 tmp = gb_addr_config & NUM_PIPES_MASK;
928 tmp = r6xx_remap_render_backend(rdev, tmp,
929 rdev->config.cayman.max_backends_per_se *
930 rdev->config.cayman.max_shader_engines,
931 CAYMAN_MAX_BACKENDS, disabled_rb_mask);
932 }
Alex Deucher416a2bd2012-05-31 19:00:25 -0400933 WREG32(GB_BACKEND_MAP, tmp);
Alex Deucherfecf1d02011-03-02 20:07:29 -0500934
Alex Deucher416a2bd2012-05-31 19:00:25 -0400935 cgts_tcc_disable = 0xffff0000;
936 for (i = 0; i < rdev->config.cayman.max_texture_channel_caches; i++)
937 cgts_tcc_disable &= ~(1 << (16 + i));
Alex Deucherfecf1d02011-03-02 20:07:29 -0500938 WREG32(CGTS_TCC_DISABLE, cgts_tcc_disable);
939 WREG32(CGTS_SYS_TCC_DISABLE, cgts_tcc_disable);
Alex Deucherfecf1d02011-03-02 20:07:29 -0500940 WREG32(CGTS_USER_SYS_TCC_DISABLE, cgts_tcc_disable);
941 WREG32(CGTS_USER_TCC_DISABLE, cgts_tcc_disable);
942
943 /* reprogram the shader complex */
944 cgts_sm_ctrl_reg = RREG32(CGTS_SM_CTRL_REG);
945 for (i = 0; i < 16; i++)
946 WREG32(CGTS_SM_CTRL_REG, OVERRIDE);
947 WREG32(CGTS_SM_CTRL_REG, cgts_sm_ctrl_reg);
948
949 /* set HW defaults for 3D engine */
950 WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
951
952 sx_debug_1 = RREG32(SX_DEBUG_1);
953 sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS;
954 WREG32(SX_DEBUG_1, sx_debug_1);
955
956 smx_dc_ctl0 = RREG32(SMX_DC_CTL0);
957 smx_dc_ctl0 &= ~NUMBER_OF_SETS(0x1ff);
Dave Airlie285e0422011-05-09 14:54:33 +1000958 smx_dc_ctl0 |= NUMBER_OF_SETS(rdev->config.cayman.sx_num_of_sets);
Alex Deucherfecf1d02011-03-02 20:07:29 -0500959 WREG32(SMX_DC_CTL0, smx_dc_ctl0);
960
961 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4) | CRC_SIMD_ID_WADDR_DISABLE);
962
963 /* need to be explicitly zero-ed */
964 WREG32(VGT_OFFCHIP_LDS_BASE, 0);
965 WREG32(SQ_LSTMP_RING_BASE, 0);
966 WREG32(SQ_HSTMP_RING_BASE, 0);
967 WREG32(SQ_ESTMP_RING_BASE, 0);
968 WREG32(SQ_GSTMP_RING_BASE, 0);
969 WREG32(SQ_VSTMP_RING_BASE, 0);
970 WREG32(SQ_PSTMP_RING_BASE, 0);
971
972 WREG32(TA_CNTL_AUX, DISABLE_CUBE_ANISO);
973
Dave Airlie285e0422011-05-09 14:54:33 +1000974 WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.cayman.sx_max_export_size / 4) - 1) |
975 POSITION_BUFFER_SIZE((rdev->config.cayman.sx_max_export_pos_size / 4) - 1) |
976 SMX_BUFFER_SIZE((rdev->config.cayman.sx_max_export_smx_size / 4) - 1)));
Alex Deucherfecf1d02011-03-02 20:07:29 -0500977
Dave Airlie285e0422011-05-09 14:54:33 +1000978 WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.cayman.sc_prim_fifo_size) |
979 SC_HIZ_TILE_FIFO_SIZE(rdev->config.cayman.sc_hiz_tile_fifo_size) |
980 SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.cayman.sc_earlyz_tile_fifo_size)));
Alex Deucherfecf1d02011-03-02 20:07:29 -0500981
982
983 WREG32(VGT_NUM_INSTANCES, 1);
984
985 WREG32(CP_PERFMON_CNTL, 0);
986
Dave Airlie285e0422011-05-09 14:54:33 +1000987 WREG32(SQ_MS_FIFO_SIZES, (CACHE_FIFO_SIZE(16 * rdev->config.cayman.sq_num_cf_insts) |
Alex Deucherfecf1d02011-03-02 20:07:29 -0500988 FETCH_FIFO_HIWATER(0x4) |
989 DONE_FIFO_HIWATER(0xe0) |
990 ALU_UPDATE_FIFO_HIWATER(0x8)));
991
992 WREG32(SQ_GPR_RESOURCE_MGMT_1, NUM_CLAUSE_TEMP_GPRS(4));
993 WREG32(SQ_CONFIG, (VC_ENABLE |
994 EXPORT_SRC_C |
995 GFX_PRIO(0) |
996 CS1_PRIO(0) |
997 CS2_PRIO(1)));
998 WREG32(SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, DYN_GPR_ENABLE);
999
1000 WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
1001 FORCE_EOV_MAX_REZ_CNT(255)));
1002
1003 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
1004 AUTO_INVLD_EN(ES_AND_GS_AUTO));
1005
1006 WREG32(VGT_GS_VERTEX_REUSE, 16);
1007 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
1008
1009 WREG32(CB_PERF_CTR0_SEL_0, 0);
1010 WREG32(CB_PERF_CTR0_SEL_1, 0);
1011 WREG32(CB_PERF_CTR1_SEL_0, 0);
1012 WREG32(CB_PERF_CTR1_SEL_1, 0);
1013 WREG32(CB_PERF_CTR2_SEL_0, 0);
1014 WREG32(CB_PERF_CTR2_SEL_1, 0);
1015 WREG32(CB_PERF_CTR3_SEL_0, 0);
1016 WREG32(CB_PERF_CTR3_SEL_1, 0);
1017
Dave Airlie0b65f832011-05-19 14:14:42 +10001018 tmp = RREG32(HDP_MISC_CNTL);
1019 tmp |= HDP_FLUSH_INVALIDATE_CACHE;
1020 WREG32(HDP_MISC_CNTL, tmp);
1021
Alex Deucherfecf1d02011-03-02 20:07:29 -05001022 hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
1023 WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
1024
1025 WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
1026
1027 udelay(50);
1028}
1029
Alex Deucherfa8198e2011-03-02 20:07:30 -05001030/*
1031 * GART
1032 */
1033void cayman_pcie_gart_tlb_flush(struct radeon_device *rdev)
1034{
1035 /* flush hdp cache */
1036 WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
1037
1038 /* bits 0-7 are the VM contexts0-7 */
1039 WREG32(VM_INVALIDATE_REQUEST, 1);
1040}
1041
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001042static int cayman_pcie_gart_enable(struct radeon_device *rdev)
Alex Deucherfa8198e2011-03-02 20:07:30 -05001043{
Jerome Glisse721604a2012-01-05 22:11:05 -05001044 int i, r;
Alex Deucherfa8198e2011-03-02 20:07:30 -05001045
Jerome Glissec9a1be92011-11-03 11:16:49 -04001046 if (rdev->gart.robj == NULL) {
Alex Deucherfa8198e2011-03-02 20:07:30 -05001047 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
1048 return -EINVAL;
1049 }
1050 r = radeon_gart_table_vram_pin(rdev);
1051 if (r)
1052 return r;
1053 radeon_gart_restore(rdev);
1054 /* Setup TLB control */
Jerome Glisse721604a2012-01-05 22:11:05 -05001055 WREG32(MC_VM_MX_L1_TLB_CNTL,
1056 (0xA << 7) |
1057 ENABLE_L1_TLB |
Alex Deucherfa8198e2011-03-02 20:07:30 -05001058 ENABLE_L1_FRAGMENT_PROCESSING |
1059 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
Jerome Glisse721604a2012-01-05 22:11:05 -05001060 ENABLE_ADVANCED_DRIVER_MODEL |
Alex Deucherfa8198e2011-03-02 20:07:30 -05001061 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
1062 /* Setup L2 cache */
1063 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
1064 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
1065 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
1066 EFFECTIVE_L2_QUEUE_SIZE(7) |
1067 CONTEXT1_IDENTITY_ACCESS_MODE(1));
1068 WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
1069 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
1070 L2_CACHE_BIGK_FRAGMENT_SIZE(6));
1071 /* setup context0 */
1072 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
1073 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
1074 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
1075 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
1076 (u32)(rdev->dummy_page.addr >> 12));
1077 WREG32(VM_CONTEXT0_CNTL2, 0);
1078 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
1079 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
Jerome Glisse721604a2012-01-05 22:11:05 -05001080
1081 WREG32(0x15D4, 0);
1082 WREG32(0x15D8, 0);
1083 WREG32(0x15DC, 0);
1084
1085 /* empty context1-7 */
Alex Deucher23d4f1f2012-10-08 09:45:46 -04001086 /* Assign the pt base to something valid for now; the pts used for
1087 * the VMs are determined by the application and setup and assigned
1088 * on the fly in the vm part of radeon_gart.c
1089 */
Jerome Glisse721604a2012-01-05 22:11:05 -05001090 for (i = 1; i < 8; i++) {
1091 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR + (i << 2), 0);
Alex Deucherc1a7ca02012-10-08 12:15:13 -04001092 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR + (i << 2), rdev->vm_manager.max_pfn);
Jerome Glisse721604a2012-01-05 22:11:05 -05001093 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
1094 rdev->gart.table_addr >> 12);
1095 }
1096
1097 /* enable context1-7 */
1098 WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
1099 (u32)(rdev->dummy_page.addr >> 12));
Christian Königae133a12012-09-18 15:30:44 -04001100 WREG32(VM_CONTEXT1_CNTL2, 4);
Dmitry Cherkasovfa87e622012-09-17 19:36:19 +02001101 WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
Christian Königae133a12012-09-18 15:30:44 -04001102 RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
1103 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
1104 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
1105 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
1106 PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
1107 PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
1108 VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
1109 VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
1110 READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
1111 READ_PROTECTION_FAULT_ENABLE_DEFAULT |
1112 WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
1113 WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
Alex Deucherfa8198e2011-03-02 20:07:30 -05001114
1115 cayman_pcie_gart_tlb_flush(rdev);
Tormod Voldenfcf4de52011-08-31 21:54:07 +00001116 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
1117 (unsigned)(rdev->mc.gtt_size >> 20),
1118 (unsigned long long)rdev->gart.table_addr);
Alex Deucherfa8198e2011-03-02 20:07:30 -05001119 rdev->gart.ready = true;
1120 return 0;
1121}
1122
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001123static void cayman_pcie_gart_disable(struct radeon_device *rdev)
Alex Deucherfa8198e2011-03-02 20:07:30 -05001124{
Alex Deucherfa8198e2011-03-02 20:07:30 -05001125 /* Disable all tables */
1126 WREG32(VM_CONTEXT0_CNTL, 0);
1127 WREG32(VM_CONTEXT1_CNTL, 0);
1128 /* Setup TLB control */
1129 WREG32(MC_VM_MX_L1_TLB_CNTL, ENABLE_L1_FRAGMENT_PROCESSING |
1130 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
1131 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
1132 /* Setup L2 cache */
1133 WREG32(VM_L2_CNTL, ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
1134 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
1135 EFFECTIVE_L2_QUEUE_SIZE(7) |
1136 CONTEXT1_IDENTITY_ACCESS_MODE(1));
1137 WREG32(VM_L2_CNTL2, 0);
1138 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
1139 L2_CACHE_BIGK_FRAGMENT_SIZE(6));
Jerome Glissec9a1be92011-11-03 11:16:49 -04001140 radeon_gart_table_vram_unpin(rdev);
Alex Deucherfa8198e2011-03-02 20:07:30 -05001141}
1142
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001143static void cayman_pcie_gart_fini(struct radeon_device *rdev)
Alex Deucherfa8198e2011-03-02 20:07:30 -05001144{
1145 cayman_pcie_gart_disable(rdev);
1146 radeon_gart_table_vram_free(rdev);
1147 radeon_gart_fini(rdev);
1148}
1149
Alex Deucher1b370782011-11-17 20:13:28 -05001150void cayman_cp_int_cntl_setup(struct radeon_device *rdev,
1151 int ring, u32 cp_int_cntl)
1152{
1153 u32 srbm_gfx_cntl = RREG32(SRBM_GFX_CNTL) & ~3;
1154
1155 WREG32(SRBM_GFX_CNTL, srbm_gfx_cntl | (ring & 3));
1156 WREG32(CP_INT_CNTL, cp_int_cntl);
1157}
1158
Alex Deucher0c88a022011-03-02 20:07:31 -05001159/*
1160 * CP.
1161 */
Alex Deucherb40e7e12011-11-17 14:57:50 -05001162void cayman_fence_ring_emit(struct radeon_device *rdev,
1163 struct radeon_fence *fence)
1164{
1165 struct radeon_ring *ring = &rdev->ring[fence->ring];
1166 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
1167
Jerome Glisse721604a2012-01-05 22:11:05 -05001168 /* flush read cache over gart for this vmid */
1169 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
1170 radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
1171 radeon_ring_write(ring, 0);
Alex Deucherb40e7e12011-11-17 14:57:50 -05001172 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
1173 radeon_ring_write(ring, PACKET3_TC_ACTION_ENA | PACKET3_SH_ACTION_ENA);
1174 radeon_ring_write(ring, 0xFFFFFFFF);
1175 radeon_ring_write(ring, 0);
1176 radeon_ring_write(ring, 10); /* poll interval */
1177 /* EVENT_WRITE_EOP - flush caches, send int */
1178 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
1179 radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5));
1180 radeon_ring_write(ring, addr & 0xffffffff);
1181 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
1182 radeon_ring_write(ring, fence->seq);
1183 radeon_ring_write(ring, 0);
1184}
1185
Jerome Glisse721604a2012-01-05 22:11:05 -05001186void cayman_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
1187{
Christian König876dc9f2012-05-08 14:24:01 +02001188 struct radeon_ring *ring = &rdev->ring[ib->ring];
Jerome Glisse721604a2012-01-05 22:11:05 -05001189
1190 /* set to DX10/11 mode */
1191 radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0));
1192 radeon_ring_write(ring, 1);
Christian König45df6802012-07-06 16:22:55 +02001193
1194 if (ring->rptr_save_reg) {
1195 uint32_t next_rptr = ring->wptr + 3 + 4 + 8;
1196 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
1197 radeon_ring_write(ring, ((ring->rptr_save_reg -
1198 PACKET3_SET_CONFIG_REG_START) >> 2));
1199 radeon_ring_write(ring, next_rptr);
1200 }
1201
Jerome Glisse721604a2012-01-05 22:11:05 -05001202 radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
1203 radeon_ring_write(ring,
1204#ifdef __BIG_ENDIAN
1205 (2 << 0) |
1206#endif
1207 (ib->gpu_addr & 0xFFFFFFFC));
1208 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
Christian König4bf3dd92012-08-06 18:57:44 +02001209 radeon_ring_write(ring, ib->length_dw |
1210 (ib->vm ? (ib->vm->id << 24) : 0));
Jerome Glisse721604a2012-01-05 22:11:05 -05001211
1212 /* flush read cache over gart for this vmid */
1213 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
1214 radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
Christian König4bf3dd92012-08-06 18:57:44 +02001215 radeon_ring_write(ring, ib->vm ? ib->vm->id : 0);
Jerome Glisse721604a2012-01-05 22:11:05 -05001216 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
1217 radeon_ring_write(ring, PACKET3_TC_ACTION_ENA | PACKET3_SH_ACTION_ENA);
1218 radeon_ring_write(ring, 0xFFFFFFFF);
1219 radeon_ring_write(ring, 0);
1220 radeon_ring_write(ring, 10); /* poll interval */
1221}
1222
Christian Königf2ba57b2013-04-08 12:41:29 +02001223void cayman_uvd_semaphore_emit(struct radeon_device *rdev,
1224 struct radeon_ring *ring,
1225 struct radeon_semaphore *semaphore,
1226 bool emit_wait)
1227{
1228 uint64_t addr = semaphore->gpu_addr;
1229
1230 radeon_ring_write(ring, PACKET0(UVD_SEMA_ADDR_LOW, 0));
1231 radeon_ring_write(ring, (addr >> 3) & 0x000FFFFF);
1232
1233 radeon_ring_write(ring, PACKET0(UVD_SEMA_ADDR_HIGH, 0));
1234 radeon_ring_write(ring, (addr >> 23) & 0x000FFFFF);
1235
1236 radeon_ring_write(ring, PACKET0(UVD_SEMA_CMD, 0));
1237 radeon_ring_write(ring, 0x80 | (emit_wait ? 1 : 0));
1238}
1239
Alex Deucher0c88a022011-03-02 20:07:31 -05001240static void cayman_cp_enable(struct radeon_device *rdev, bool enable)
1241{
1242 if (enable)
1243 WREG32(CP_ME_CNTL, 0);
1244 else {
Dave Airlie38f1cff2011-03-16 11:34:41 +10001245 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
Alex Deucher0c88a022011-03-02 20:07:31 -05001246 WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT));
1247 WREG32(SCRATCH_UMSK, 0);
Alex Deucherf60cbd12012-12-04 15:27:33 -05001248 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
Alex Deucher0c88a022011-03-02 20:07:31 -05001249 }
1250}
1251
1252static int cayman_cp_load_microcode(struct radeon_device *rdev)
1253{
1254 const __be32 *fw_data;
1255 int i;
1256
1257 if (!rdev->me_fw || !rdev->pfp_fw)
1258 return -EINVAL;
1259
1260 cayman_cp_enable(rdev, false);
1261
1262 fw_data = (const __be32 *)rdev->pfp_fw->data;
1263 WREG32(CP_PFP_UCODE_ADDR, 0);
1264 for (i = 0; i < CAYMAN_PFP_UCODE_SIZE; i++)
1265 WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
1266 WREG32(CP_PFP_UCODE_ADDR, 0);
1267
1268 fw_data = (const __be32 *)rdev->me_fw->data;
1269 WREG32(CP_ME_RAM_WADDR, 0);
1270 for (i = 0; i < CAYMAN_PM4_UCODE_SIZE; i++)
1271 WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
1272
1273 WREG32(CP_PFP_UCODE_ADDR, 0);
1274 WREG32(CP_ME_RAM_WADDR, 0);
1275 WREG32(CP_ME_RAM_RADDR, 0);
1276 return 0;
1277}
1278
1279static int cayman_cp_start(struct radeon_device *rdev)
1280{
Christian Könige32eb502011-10-23 12:56:27 +02001281 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucher0c88a022011-03-02 20:07:31 -05001282 int r, i;
1283
Christian Könige32eb502011-10-23 12:56:27 +02001284 r = radeon_ring_lock(rdev, ring, 7);
Alex Deucher0c88a022011-03-02 20:07:31 -05001285 if (r) {
1286 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
1287 return r;
1288 }
Christian Könige32eb502011-10-23 12:56:27 +02001289 radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
1290 radeon_ring_write(ring, 0x1);
1291 radeon_ring_write(ring, 0x0);
1292 radeon_ring_write(ring, rdev->config.cayman.max_hw_contexts - 1);
1293 radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
1294 radeon_ring_write(ring, 0);
1295 radeon_ring_write(ring, 0);
1296 radeon_ring_unlock_commit(rdev, ring);
Alex Deucher0c88a022011-03-02 20:07:31 -05001297
1298 cayman_cp_enable(rdev, true);
1299
Christian Könige32eb502011-10-23 12:56:27 +02001300 r = radeon_ring_lock(rdev, ring, cayman_default_size + 19);
Alex Deucher0c88a022011-03-02 20:07:31 -05001301 if (r) {
1302 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
1303 return r;
1304 }
1305
1306 /* setup clear context state */
Christian Könige32eb502011-10-23 12:56:27 +02001307 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
1308 radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
Alex Deucher0c88a022011-03-02 20:07:31 -05001309
1310 for (i = 0; i < cayman_default_size; i++)
Christian Könige32eb502011-10-23 12:56:27 +02001311 radeon_ring_write(ring, cayman_default_state[i]);
Alex Deucher0c88a022011-03-02 20:07:31 -05001312
Christian Könige32eb502011-10-23 12:56:27 +02001313 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
1314 radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
Alex Deucher0c88a022011-03-02 20:07:31 -05001315
1316 /* set clear context state */
Christian Könige32eb502011-10-23 12:56:27 +02001317 radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
1318 radeon_ring_write(ring, 0);
Alex Deucher0c88a022011-03-02 20:07:31 -05001319
1320 /* SQ_VTX_BASE_VTX_LOC */
Christian Könige32eb502011-10-23 12:56:27 +02001321 radeon_ring_write(ring, 0xc0026f00);
1322 radeon_ring_write(ring, 0x00000000);
1323 radeon_ring_write(ring, 0x00000000);
1324 radeon_ring_write(ring, 0x00000000);
Alex Deucher0c88a022011-03-02 20:07:31 -05001325
1326 /* Clear consts */
Christian Könige32eb502011-10-23 12:56:27 +02001327 radeon_ring_write(ring, 0xc0036f00);
1328 radeon_ring_write(ring, 0x00000bc4);
1329 radeon_ring_write(ring, 0xffffffff);
1330 radeon_ring_write(ring, 0xffffffff);
1331 radeon_ring_write(ring, 0xffffffff);
Alex Deucher0c88a022011-03-02 20:07:31 -05001332
Christian Könige32eb502011-10-23 12:56:27 +02001333 radeon_ring_write(ring, 0xc0026900);
1334 radeon_ring_write(ring, 0x00000316);
1335 radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
1336 radeon_ring_write(ring, 0x00000010); /* */
Alex Deucher9b91d182011-03-02 20:07:39 -05001337
Christian Könige32eb502011-10-23 12:56:27 +02001338 radeon_ring_unlock_commit(rdev, ring);
Alex Deucher0c88a022011-03-02 20:07:31 -05001339
1340 /* XXX init other rings */
1341
1342 return 0;
1343}
1344
Alex Deucher755d8192011-03-02 20:07:34 -05001345static void cayman_cp_fini(struct radeon_device *rdev)
1346{
Christian König45df6802012-07-06 16:22:55 +02001347 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucher755d8192011-03-02 20:07:34 -05001348 cayman_cp_enable(rdev, false);
Christian König45df6802012-07-06 16:22:55 +02001349 radeon_ring_fini(rdev, ring);
1350 radeon_scratch_free(rdev, ring->rptr_save_reg);
Alex Deucher755d8192011-03-02 20:07:34 -05001351}
1352
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001353static int cayman_cp_resume(struct radeon_device *rdev)
Alex Deucher0c88a022011-03-02 20:07:31 -05001354{
Christian Königb90ca982012-07-04 21:36:53 +02001355 static const int ridx[] = {
1356 RADEON_RING_TYPE_GFX_INDEX,
1357 CAYMAN_RING_TYPE_CP1_INDEX,
1358 CAYMAN_RING_TYPE_CP2_INDEX
1359 };
1360 static const unsigned cp_rb_cntl[] = {
1361 CP_RB0_CNTL,
1362 CP_RB1_CNTL,
1363 CP_RB2_CNTL,
1364 };
1365 static const unsigned cp_rb_rptr_addr[] = {
1366 CP_RB0_RPTR_ADDR,
1367 CP_RB1_RPTR_ADDR,
1368 CP_RB2_RPTR_ADDR
1369 };
1370 static const unsigned cp_rb_rptr_addr_hi[] = {
1371 CP_RB0_RPTR_ADDR_HI,
1372 CP_RB1_RPTR_ADDR_HI,
1373 CP_RB2_RPTR_ADDR_HI
1374 };
1375 static const unsigned cp_rb_base[] = {
1376 CP_RB0_BASE,
1377 CP_RB1_BASE,
1378 CP_RB2_BASE
1379 };
Christian Könige32eb502011-10-23 12:56:27 +02001380 struct radeon_ring *ring;
Christian Königb90ca982012-07-04 21:36:53 +02001381 int i, r;
Alex Deucher0c88a022011-03-02 20:07:31 -05001382
1383 /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */
1384 WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP |
1385 SOFT_RESET_PA |
1386 SOFT_RESET_SH |
1387 SOFT_RESET_VGT |
Jerome Glissea49a50d2011-08-24 20:00:17 +00001388 SOFT_RESET_SPI |
Alex Deucher0c88a022011-03-02 20:07:31 -05001389 SOFT_RESET_SX));
1390 RREG32(GRBM_SOFT_RESET);
1391 mdelay(15);
1392 WREG32(GRBM_SOFT_RESET, 0);
1393 RREG32(GRBM_SOFT_RESET);
1394
Christian König15d33322011-09-15 19:02:22 +02001395 WREG32(CP_SEM_WAIT_TIMER, 0x0);
Alex Deucher11ef3f1f2012-01-20 14:47:43 -05001396 WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
Alex Deucher0c88a022011-03-02 20:07:31 -05001397
1398 /* Set the write pointer delay */
1399 WREG32(CP_RB_WPTR_DELAY, 0);
1400
1401 WREG32(CP_DEBUG, (1 << 27));
1402
Adam Buchbinder48fc7f72012-09-19 21:48:00 -04001403 /* set the wb address whether it's enabled or not */
Alex Deucher0c88a022011-03-02 20:07:31 -05001404 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
Christian Königb90ca982012-07-04 21:36:53 +02001405 WREG32(SCRATCH_UMSK, 0xff);
Alex Deucher0c88a022011-03-02 20:07:31 -05001406
Christian Königb90ca982012-07-04 21:36:53 +02001407 for (i = 0; i < 3; ++i) {
1408 uint32_t rb_cntl;
1409 uint64_t addr;
1410
1411 /* Set ring buffer size */
1412 ring = &rdev->ring[ridx[i]];
1413 rb_cntl = drm_order(ring->ring_size / 8);
1414 rb_cntl |= drm_order(RADEON_GPU_PAGE_SIZE/8) << 8;
1415#ifdef __BIG_ENDIAN
1416 rb_cntl |= BUF_SWAP_32BIT;
1417#endif
1418 WREG32(cp_rb_cntl[i], rb_cntl);
1419
Adam Buchbinder48fc7f72012-09-19 21:48:00 -04001420 /* set the wb address whether it's enabled or not */
Christian Königb90ca982012-07-04 21:36:53 +02001421 addr = rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET;
1422 WREG32(cp_rb_rptr_addr[i], addr & 0xFFFFFFFC);
1423 WREG32(cp_rb_rptr_addr_hi[i], upper_32_bits(addr) & 0xFF);
Alex Deucher0c88a022011-03-02 20:07:31 -05001424 }
1425
Christian Königb90ca982012-07-04 21:36:53 +02001426 /* set the rb base addr, this causes an internal reset of ALL rings */
1427 for (i = 0; i < 3; ++i) {
1428 ring = &rdev->ring[ridx[i]];
1429 WREG32(cp_rb_base[i], ring->gpu_addr >> 8);
1430 }
Alex Deucher0c88a022011-03-02 20:07:31 -05001431
Christian Königb90ca982012-07-04 21:36:53 +02001432 for (i = 0; i < 3; ++i) {
1433 /* Initialize the ring buffer's read and write pointers */
1434 ring = &rdev->ring[ridx[i]];
1435 WREG32_P(cp_rb_cntl[i], RB_RPTR_WR_ENA, ~RB_RPTR_WR_ENA);
Alex Deucher0c88a022011-03-02 20:07:31 -05001436
Christian Königb90ca982012-07-04 21:36:53 +02001437 ring->rptr = ring->wptr = 0;
1438 WREG32(ring->rptr_reg, ring->rptr);
1439 WREG32(ring->wptr_reg, ring->wptr);
Alex Deucher0c88a022011-03-02 20:07:31 -05001440
Christian Königb90ca982012-07-04 21:36:53 +02001441 mdelay(1);
1442 WREG32_P(cp_rb_cntl[i], 0, ~RB_RPTR_WR_ENA);
1443 }
Alex Deucher0c88a022011-03-02 20:07:31 -05001444
1445 /* start the rings */
1446 cayman_cp_start(rdev);
Christian Könige32eb502011-10-23 12:56:27 +02001447 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
1448 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
1449 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
Alex Deucher0c88a022011-03-02 20:07:31 -05001450 /* this only test cp0 */
Alex Deucherf7128122012-02-23 17:53:45 -05001451 r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
Alex Deucher0c88a022011-03-02 20:07:31 -05001452 if (r) {
Christian Könige32eb502011-10-23 12:56:27 +02001453 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
1454 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
1455 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
Alex Deucher0c88a022011-03-02 20:07:31 -05001456 return r;
1457 }
1458
1459 return 0;
1460}
1461
Alex Deucherf60cbd12012-12-04 15:27:33 -05001462/*
1463 * DMA
1464 * Starting with R600, the GPU has an asynchronous
1465 * DMA engine. The programming model is very similar
1466 * to the 3D engine (ring buffer, IBs, etc.), but the
1467 * DMA controller has it's own packet format that is
1468 * different form the PM4 format used by the 3D engine.
1469 * It supports copying data, writing embedded data,
1470 * solid fills, and a number of other things. It also
1471 * has support for tiling/detiling of buffers.
1472 * Cayman and newer support two asynchronous DMA engines.
1473 */
1474/**
1475 * cayman_dma_ring_ib_execute - Schedule an IB on the DMA engine
1476 *
1477 * @rdev: radeon_device pointer
1478 * @ib: IB object to schedule
1479 *
1480 * Schedule an IB in the DMA ring (cayman-SI).
1481 */
1482void cayman_dma_ring_ib_execute(struct radeon_device *rdev,
1483 struct radeon_ib *ib)
1484{
1485 struct radeon_ring *ring = &rdev->ring[ib->ring];
1486
1487 if (rdev->wb.enabled) {
1488 u32 next_rptr = ring->wptr + 4;
1489 while ((next_rptr & 7) != 5)
1490 next_rptr++;
1491 next_rptr += 3;
1492 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 1));
1493 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
1494 radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xff);
1495 radeon_ring_write(ring, next_rptr);
1496 }
1497
1498 /* The indirect buffer packet must end on an 8 DW boundary in the DMA ring.
1499 * Pad as necessary with NOPs.
1500 */
1501 while ((ring->wptr & 7) != 5)
1502 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
1503 radeon_ring_write(ring, DMA_IB_PACKET(DMA_PACKET_INDIRECT_BUFFER, ib->vm ? ib->vm->id : 0, 0));
1504 radeon_ring_write(ring, (ib->gpu_addr & 0xFFFFFFE0));
1505 radeon_ring_write(ring, (ib->length_dw << 12) | (upper_32_bits(ib->gpu_addr) & 0xFF));
1506
1507}
1508
1509/**
1510 * cayman_dma_stop - stop the async dma engines
1511 *
1512 * @rdev: radeon_device pointer
1513 *
1514 * Stop the async dma engines (cayman-SI).
1515 */
1516void cayman_dma_stop(struct radeon_device *rdev)
1517{
1518 u32 rb_cntl;
1519
1520 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
1521
1522 /* dma0 */
1523 rb_cntl = RREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET);
1524 rb_cntl &= ~DMA_RB_ENABLE;
1525 WREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET, rb_cntl);
1526
1527 /* dma1 */
1528 rb_cntl = RREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET);
1529 rb_cntl &= ~DMA_RB_ENABLE;
1530 WREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET, rb_cntl);
1531
1532 rdev->ring[R600_RING_TYPE_DMA_INDEX].ready = false;
1533 rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX].ready = false;
1534}
1535
1536/**
1537 * cayman_dma_resume - setup and start the async dma engines
1538 *
1539 * @rdev: radeon_device pointer
1540 *
1541 * Set up the DMA ring buffers and enable them. (cayman-SI).
1542 * Returns 0 for success, error for failure.
1543 */
1544int cayman_dma_resume(struct radeon_device *rdev)
1545{
1546 struct radeon_ring *ring;
Michel Dänzerb3dfcb22013-01-24 19:02:01 +01001547 u32 rb_cntl, dma_cntl, ib_cntl;
Alex Deucherf60cbd12012-12-04 15:27:33 -05001548 u32 rb_bufsz;
1549 u32 reg_offset, wb_offset;
1550 int i, r;
1551
1552 /* Reset dma */
1553 WREG32(SRBM_SOFT_RESET, SOFT_RESET_DMA | SOFT_RESET_DMA1);
1554 RREG32(SRBM_SOFT_RESET);
1555 udelay(50);
1556 WREG32(SRBM_SOFT_RESET, 0);
1557
1558 for (i = 0; i < 2; i++) {
1559 if (i == 0) {
1560 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
1561 reg_offset = DMA0_REGISTER_OFFSET;
1562 wb_offset = R600_WB_DMA_RPTR_OFFSET;
1563 } else {
1564 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
1565 reg_offset = DMA1_REGISTER_OFFSET;
1566 wb_offset = CAYMAN_WB_DMA1_RPTR_OFFSET;
1567 }
1568
1569 WREG32(DMA_SEM_INCOMPLETE_TIMER_CNTL + reg_offset, 0);
1570 WREG32(DMA_SEM_WAIT_FAIL_TIMER_CNTL + reg_offset, 0);
1571
1572 /* Set ring buffer size in dwords */
1573 rb_bufsz = drm_order(ring->ring_size / 4);
1574 rb_cntl = rb_bufsz << 1;
1575#ifdef __BIG_ENDIAN
1576 rb_cntl |= DMA_RB_SWAP_ENABLE | DMA_RPTR_WRITEBACK_SWAP_ENABLE;
1577#endif
1578 WREG32(DMA_RB_CNTL + reg_offset, rb_cntl);
1579
1580 /* Initialize the ring buffer's read and write pointers */
1581 WREG32(DMA_RB_RPTR + reg_offset, 0);
1582 WREG32(DMA_RB_WPTR + reg_offset, 0);
1583
1584 /* set the wb address whether it's enabled or not */
1585 WREG32(DMA_RB_RPTR_ADDR_HI + reg_offset,
1586 upper_32_bits(rdev->wb.gpu_addr + wb_offset) & 0xFF);
1587 WREG32(DMA_RB_RPTR_ADDR_LO + reg_offset,
1588 ((rdev->wb.gpu_addr + wb_offset) & 0xFFFFFFFC));
1589
1590 if (rdev->wb.enabled)
1591 rb_cntl |= DMA_RPTR_WRITEBACK_ENABLE;
1592
1593 WREG32(DMA_RB_BASE + reg_offset, ring->gpu_addr >> 8);
1594
1595 /* enable DMA IBs */
Michel Dänzerb3dfcb22013-01-24 19:02:01 +01001596 ib_cntl = DMA_IB_ENABLE | CMD_VMID_FORCE;
1597#ifdef __BIG_ENDIAN
1598 ib_cntl |= DMA_IB_SWAP_ENABLE;
1599#endif
1600 WREG32(DMA_IB_CNTL + reg_offset, ib_cntl);
Alex Deucherf60cbd12012-12-04 15:27:33 -05001601
1602 dma_cntl = RREG32(DMA_CNTL + reg_offset);
1603 dma_cntl &= ~CTXEMPTY_INT_ENABLE;
1604 WREG32(DMA_CNTL + reg_offset, dma_cntl);
1605
1606 ring->wptr = 0;
1607 WREG32(DMA_RB_WPTR + reg_offset, ring->wptr << 2);
1608
1609 ring->rptr = RREG32(DMA_RB_RPTR + reg_offset) >> 2;
1610
1611 WREG32(DMA_RB_CNTL + reg_offset, rb_cntl | DMA_RB_ENABLE);
1612
1613 ring->ready = true;
1614
1615 r = radeon_ring_test(rdev, ring->idx, ring);
1616 if (r) {
1617 ring->ready = false;
1618 return r;
1619 }
1620 }
1621
1622 radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
1623
1624 return 0;
1625}
1626
1627/**
1628 * cayman_dma_fini - tear down the async dma engines
1629 *
1630 * @rdev: radeon_device pointer
1631 *
1632 * Stop the async dma engines and free the rings (cayman-SI).
1633 */
1634void cayman_dma_fini(struct radeon_device *rdev)
1635{
1636 cayman_dma_stop(rdev);
1637 radeon_ring_fini(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX]);
1638 radeon_ring_fini(rdev, &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX]);
1639}
1640
Alex Deucher168757e2013-01-18 19:17:22 -05001641static u32 cayman_gpu_check_soft_reset(struct radeon_device *rdev)
1642{
1643 u32 reset_mask = 0;
1644 u32 tmp;
1645
1646 /* GRBM_STATUS */
1647 tmp = RREG32(GRBM_STATUS);
1648 if (tmp & (PA_BUSY | SC_BUSY |
1649 SH_BUSY | SX_BUSY |
1650 TA_BUSY | VGT_BUSY |
1651 DB_BUSY | CB_BUSY |
1652 GDS_BUSY | SPI_BUSY |
1653 IA_BUSY | IA_BUSY_NO_DMA))
1654 reset_mask |= RADEON_RESET_GFX;
1655
1656 if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
1657 CP_BUSY | CP_COHERENCY_BUSY))
1658 reset_mask |= RADEON_RESET_CP;
1659
1660 if (tmp & GRBM_EE_BUSY)
1661 reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
1662
1663 /* DMA_STATUS_REG 0 */
1664 tmp = RREG32(DMA_STATUS_REG + DMA0_REGISTER_OFFSET);
1665 if (!(tmp & DMA_IDLE))
1666 reset_mask |= RADEON_RESET_DMA;
1667
1668 /* DMA_STATUS_REG 1 */
1669 tmp = RREG32(DMA_STATUS_REG + DMA1_REGISTER_OFFSET);
1670 if (!(tmp & DMA_IDLE))
1671 reset_mask |= RADEON_RESET_DMA1;
1672
1673 /* SRBM_STATUS2 */
1674 tmp = RREG32(SRBM_STATUS2);
1675 if (tmp & DMA_BUSY)
1676 reset_mask |= RADEON_RESET_DMA;
1677
1678 if (tmp & DMA1_BUSY)
1679 reset_mask |= RADEON_RESET_DMA1;
1680
1681 /* SRBM_STATUS */
1682 tmp = RREG32(SRBM_STATUS);
1683 if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
1684 reset_mask |= RADEON_RESET_RLC;
1685
1686 if (tmp & IH_BUSY)
1687 reset_mask |= RADEON_RESET_IH;
1688
1689 if (tmp & SEM_BUSY)
1690 reset_mask |= RADEON_RESET_SEM;
1691
1692 if (tmp & GRBM_RQ_PENDING)
1693 reset_mask |= RADEON_RESET_GRBM;
1694
1695 if (tmp & VMC_BUSY)
1696 reset_mask |= RADEON_RESET_VMC;
1697
1698 if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
1699 MCC_BUSY | MCD_BUSY))
1700 reset_mask |= RADEON_RESET_MC;
1701
1702 if (evergreen_is_display_hung(rdev))
1703 reset_mask |= RADEON_RESET_DISPLAY;
1704
1705 /* VM_L2_STATUS */
1706 tmp = RREG32(VM_L2_STATUS);
1707 if (tmp & L2_BUSY)
1708 reset_mask |= RADEON_RESET_VMC;
1709
Alex Deucherd808fc82013-02-28 10:03:08 -05001710 /* Skip MC reset as it's mostly likely not hung, just busy */
1711 if (reset_mask & RADEON_RESET_MC) {
1712 DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
1713 reset_mask &= ~RADEON_RESET_MC;
1714 }
1715
Alex Deucher168757e2013-01-18 19:17:22 -05001716 return reset_mask;
1717}
1718
1719static void cayman_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
Alex Deucher271d6fed2013-01-03 12:48:05 -05001720{
1721 struct evergreen_mc_save save;
Alex Deucher187e3592013-01-18 14:51:38 -05001722 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
1723 u32 tmp;
Alex Deucher19fc42e2013-01-14 11:04:39 -05001724
Alex Deucher271d6fed2013-01-03 12:48:05 -05001725 if (reset_mask == 0)
Alex Deucher168757e2013-01-18 19:17:22 -05001726 return;
Alex Deucher271d6fed2013-01-03 12:48:05 -05001727
1728 dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
1729
Alex Deucher187e3592013-01-18 14:51:38 -05001730 evergreen_print_gpu_status_regs(rdev);
Alex Deucher271d6fed2013-01-03 12:48:05 -05001731 dev_info(rdev->dev, " VM_CONTEXT0_PROTECTION_FAULT_ADDR 0x%08X\n",
1732 RREG32(0x14F8));
1733 dev_info(rdev->dev, " VM_CONTEXT0_PROTECTION_FAULT_STATUS 0x%08X\n",
1734 RREG32(0x14D8));
1735 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
1736 RREG32(0x14FC));
1737 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
1738 RREG32(0x14DC));
1739
Alex Deucher187e3592013-01-18 14:51:38 -05001740 /* Disable CP parsing/prefetching */
1741 WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT);
1742
1743 if (reset_mask & RADEON_RESET_DMA) {
1744 /* dma0 */
1745 tmp = RREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET);
1746 tmp &= ~DMA_RB_ENABLE;
1747 WREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET, tmp);
Alex Deucher168757e2013-01-18 19:17:22 -05001748 }
Alex Deucher187e3592013-01-18 14:51:38 -05001749
Alex Deucher168757e2013-01-18 19:17:22 -05001750 if (reset_mask & RADEON_RESET_DMA1) {
Alex Deucher187e3592013-01-18 14:51:38 -05001751 /* dma1 */
1752 tmp = RREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET);
1753 tmp &= ~DMA_RB_ENABLE;
1754 WREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET, tmp);
1755 }
1756
Alex Deucher90fb8772013-01-23 18:59:17 -05001757 udelay(50);
1758
1759 evergreen_mc_stop(rdev, &save);
1760 if (evergreen_mc_wait_for_idle(rdev)) {
1761 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
1762 }
1763
Alex Deucher187e3592013-01-18 14:51:38 -05001764 if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE)) {
1765 grbm_soft_reset = SOFT_RESET_CB |
1766 SOFT_RESET_DB |
1767 SOFT_RESET_GDS |
1768 SOFT_RESET_PA |
1769 SOFT_RESET_SC |
1770 SOFT_RESET_SPI |
1771 SOFT_RESET_SH |
1772 SOFT_RESET_SX |
1773 SOFT_RESET_TC |
1774 SOFT_RESET_TA |
1775 SOFT_RESET_VGT |
1776 SOFT_RESET_IA;
1777 }
1778
1779 if (reset_mask & RADEON_RESET_CP) {
1780 grbm_soft_reset |= SOFT_RESET_CP | SOFT_RESET_VGT;
1781
1782 srbm_soft_reset |= SOFT_RESET_GRBM;
1783 }
Alex Deucher271d6fed2013-01-03 12:48:05 -05001784
1785 if (reset_mask & RADEON_RESET_DMA)
Alex Deucher168757e2013-01-18 19:17:22 -05001786 srbm_soft_reset |= SOFT_RESET_DMA;
1787
1788 if (reset_mask & RADEON_RESET_DMA1)
1789 srbm_soft_reset |= SOFT_RESET_DMA1;
1790
1791 if (reset_mask & RADEON_RESET_DISPLAY)
1792 srbm_soft_reset |= SOFT_RESET_DC;
1793
1794 if (reset_mask & RADEON_RESET_RLC)
1795 srbm_soft_reset |= SOFT_RESET_RLC;
1796
1797 if (reset_mask & RADEON_RESET_SEM)
1798 srbm_soft_reset |= SOFT_RESET_SEM;
1799
1800 if (reset_mask & RADEON_RESET_IH)
1801 srbm_soft_reset |= SOFT_RESET_IH;
1802
1803 if (reset_mask & RADEON_RESET_GRBM)
1804 srbm_soft_reset |= SOFT_RESET_GRBM;
1805
1806 if (reset_mask & RADEON_RESET_VMC)
1807 srbm_soft_reset |= SOFT_RESET_VMC;
1808
Alex Deucher24178ec2013-01-24 15:00:17 -05001809 if (!(rdev->flags & RADEON_IS_IGP)) {
1810 if (reset_mask & RADEON_RESET_MC)
1811 srbm_soft_reset |= SOFT_RESET_MC;
1812 }
Alex Deucher187e3592013-01-18 14:51:38 -05001813
1814 if (grbm_soft_reset) {
1815 tmp = RREG32(GRBM_SOFT_RESET);
1816 tmp |= grbm_soft_reset;
1817 dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
1818 WREG32(GRBM_SOFT_RESET, tmp);
1819 tmp = RREG32(GRBM_SOFT_RESET);
1820
1821 udelay(50);
1822
1823 tmp &= ~grbm_soft_reset;
1824 WREG32(GRBM_SOFT_RESET, tmp);
1825 tmp = RREG32(GRBM_SOFT_RESET);
1826 }
1827
1828 if (srbm_soft_reset) {
1829 tmp = RREG32(SRBM_SOFT_RESET);
1830 tmp |= srbm_soft_reset;
1831 dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
1832 WREG32(SRBM_SOFT_RESET, tmp);
1833 tmp = RREG32(SRBM_SOFT_RESET);
1834
1835 udelay(50);
1836
1837 tmp &= ~srbm_soft_reset;
1838 WREG32(SRBM_SOFT_RESET, tmp);
1839 tmp = RREG32(SRBM_SOFT_RESET);
1840 }
Alex Deucher271d6fed2013-01-03 12:48:05 -05001841
1842 /* Wait a little for things to settle down */
1843 udelay(50);
1844
Alex Deucherb9952a82011-03-02 20:07:33 -05001845 evergreen_mc_resume(rdev, &save);
Alex Deucher187e3592013-01-18 14:51:38 -05001846 udelay(50);
Alex Deucher410a3412013-01-18 13:05:39 -05001847
Alex Deucher187e3592013-01-18 14:51:38 -05001848 evergreen_print_gpu_status_regs(rdev);
Alex Deucherb9952a82011-03-02 20:07:33 -05001849}
1850
1851int cayman_asic_reset(struct radeon_device *rdev)
1852{
Alex Deucher168757e2013-01-18 19:17:22 -05001853 u32 reset_mask;
1854
1855 reset_mask = cayman_gpu_check_soft_reset(rdev);
1856
1857 if (reset_mask)
1858 r600_set_bios_scratch_engine_hung(rdev, true);
1859
1860 cayman_gpu_soft_reset(rdev, reset_mask);
1861
1862 reset_mask = cayman_gpu_check_soft_reset(rdev);
1863
1864 if (!reset_mask)
1865 r600_set_bios_scratch_engine_hung(rdev, false);
1866
1867 return 0;
Alex Deucherb9952a82011-03-02 20:07:33 -05001868}
1869
Alex Deucherf60cbd12012-12-04 15:27:33 -05001870/**
Alex Deucher123bc182013-01-24 11:37:19 -05001871 * cayman_gfx_is_lockup - Check if the GFX engine is locked up
1872 *
1873 * @rdev: radeon_device pointer
1874 * @ring: radeon_ring structure holding ring information
1875 *
1876 * Check if the GFX engine is locked up.
1877 * Returns true if the engine appears to be locked up, false if not.
1878 */
1879bool cayman_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
1880{
1881 u32 reset_mask = cayman_gpu_check_soft_reset(rdev);
1882
1883 if (!(reset_mask & (RADEON_RESET_GFX |
1884 RADEON_RESET_COMPUTE |
1885 RADEON_RESET_CP))) {
1886 radeon_ring_lockup_update(ring);
1887 return false;
1888 }
1889 /* force CP activities */
1890 radeon_ring_force_activity(rdev, ring);
1891 return radeon_ring_test_lockup(rdev, ring);
1892}
1893
1894/**
Alex Deucherf60cbd12012-12-04 15:27:33 -05001895 * cayman_dma_is_lockup - Check if the DMA engine is locked up
1896 *
1897 * @rdev: radeon_device pointer
1898 * @ring: radeon_ring structure holding ring information
1899 *
Alex Deucher123bc182013-01-24 11:37:19 -05001900 * Check if the async DMA engine is locked up.
Alex Deucherf60cbd12012-12-04 15:27:33 -05001901 * Returns true if the engine appears to be locked up, false if not.
1902 */
1903bool cayman_dma_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
1904{
Alex Deucher123bc182013-01-24 11:37:19 -05001905 u32 reset_mask = cayman_gpu_check_soft_reset(rdev);
1906 u32 mask;
Alex Deucherf60cbd12012-12-04 15:27:33 -05001907
1908 if (ring->idx == R600_RING_TYPE_DMA_INDEX)
Alex Deucher123bc182013-01-24 11:37:19 -05001909 mask = RADEON_RESET_DMA;
Alex Deucherf60cbd12012-12-04 15:27:33 -05001910 else
Alex Deucher123bc182013-01-24 11:37:19 -05001911 mask = RADEON_RESET_DMA1;
1912
1913 if (!(reset_mask & mask)) {
Alex Deucherf60cbd12012-12-04 15:27:33 -05001914 radeon_ring_lockup_update(ring);
1915 return false;
1916 }
1917 /* force ring activities */
1918 radeon_ring_force_activity(rdev, ring);
1919 return radeon_ring_test_lockup(rdev, ring);
1920}
1921
Alex Deucher755d8192011-03-02 20:07:34 -05001922static int cayman_startup(struct radeon_device *rdev)
1923{
Christian Könige32eb502011-10-23 12:56:27 +02001924 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucher755d8192011-03-02 20:07:34 -05001925 int r;
1926
Ilija Hadzicb07759b2011-09-20 10:22:58 -04001927 /* enable pcie gen2 link */
1928 evergreen_pcie_gen2_enable(rdev);
1929
Alex Deucherc420c742012-03-20 17:18:39 -04001930 if (rdev->flags & RADEON_IS_IGP) {
1931 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
1932 r = ni_init_microcode(rdev);
1933 if (r) {
1934 DRM_ERROR("Failed to load firmware!\n");
1935 return r;
1936 }
1937 }
1938 } else {
1939 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw || !rdev->mc_fw) {
1940 r = ni_init_microcode(rdev);
1941 if (r) {
1942 DRM_ERROR("Failed to load firmware!\n");
1943 return r;
1944 }
1945 }
1946
1947 r = ni_mc_load_microcode(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001948 if (r) {
Alex Deucherc420c742012-03-20 17:18:39 -04001949 DRM_ERROR("Failed to load MC firmware!\n");
Alex Deucher755d8192011-03-02 20:07:34 -05001950 return r;
1951 }
1952 }
Alex Deucher755d8192011-03-02 20:07:34 -05001953
Alex Deucher16cdf042011-10-28 10:30:02 -04001954 r = r600_vram_scratch_init(rdev);
1955 if (r)
1956 return r;
1957
Alex Deucher755d8192011-03-02 20:07:34 -05001958 evergreen_mc_program(rdev);
1959 r = cayman_pcie_gart_enable(rdev);
1960 if (r)
1961 return r;
1962 cayman_gpu_init(rdev);
1963
Alex Deuchercb92d452011-05-25 16:39:00 -04001964 r = evergreen_blit_init(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001965 if (r) {
Ilija Hadzicfb3d9e92011-10-12 23:29:41 -04001966 r600_blit_fini(rdev);
Alex Deucher27cd7762012-02-23 17:53:42 -05001967 rdev->asic->copy.copy = NULL;
Alex Deucher755d8192011-03-02 20:07:34 -05001968 dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
1969 }
Alex Deucher755d8192011-03-02 20:07:34 -05001970
Alex Deucherc420c742012-03-20 17:18:39 -04001971 /* allocate rlc buffers */
1972 if (rdev->flags & RADEON_IS_IGP) {
1973 r = si_rlc_init(rdev);
1974 if (r) {
1975 DRM_ERROR("Failed to init rlc BOs!\n");
1976 return r;
1977 }
1978 }
1979
Alex Deucher755d8192011-03-02 20:07:34 -05001980 /* allocate wb buffer */
1981 r = radeon_wb_init(rdev);
1982 if (r)
1983 return r;
1984
Jerome Glisse30eb77f2011-11-20 20:45:34 +00001985 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
1986 if (r) {
1987 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
1988 return r;
1989 }
1990
Christian Königf2ba57b2013-04-08 12:41:29 +02001991 r = rv770_uvd_resume(rdev);
1992 if (!r) {
1993 r = radeon_fence_driver_start_ring(rdev,
1994 R600_RING_TYPE_UVD_INDEX);
1995 if (r)
1996 dev_err(rdev->dev, "UVD fences init error (%d).\n", r);
1997 }
1998 if (r)
1999 rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
2000
Jerome Glisse30eb77f2011-11-20 20:45:34 +00002001 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
2002 if (r) {
2003 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
2004 return r;
2005 }
2006
2007 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
2008 if (r) {
2009 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
2010 return r;
2011 }
2012
Alex Deucherf60cbd12012-12-04 15:27:33 -05002013 r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
2014 if (r) {
2015 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
2016 return r;
2017 }
2018
2019 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
2020 if (r) {
2021 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
2022 return r;
2023 }
2024
Alex Deucher755d8192011-03-02 20:07:34 -05002025 /* Enable IRQ */
2026 r = r600_irq_init(rdev);
2027 if (r) {
2028 DRM_ERROR("radeon: IH init failed (%d).\n", r);
2029 radeon_irq_kms_fini(rdev);
2030 return r;
2031 }
2032 evergreen_irq_set(rdev);
2033
Christian Könige32eb502011-10-23 12:56:27 +02002034 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
Alex Deucher78c55602011-11-17 14:25:56 -05002035 CP_RB0_RPTR, CP_RB0_WPTR,
2036 0, 0xfffff, RADEON_CP_PACKET2);
Alex Deucher755d8192011-03-02 20:07:34 -05002037 if (r)
2038 return r;
Alex Deucherf60cbd12012-12-04 15:27:33 -05002039
2040 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
2041 r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
2042 DMA_RB_RPTR + DMA0_REGISTER_OFFSET,
2043 DMA_RB_WPTR + DMA0_REGISTER_OFFSET,
2044 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
2045 if (r)
2046 return r;
2047
2048 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
2049 r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
2050 DMA_RB_RPTR + DMA1_REGISTER_OFFSET,
2051 DMA_RB_WPTR + DMA1_REGISTER_OFFSET,
2052 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
2053 if (r)
2054 return r;
2055
Alex Deucher755d8192011-03-02 20:07:34 -05002056 r = cayman_cp_load_microcode(rdev);
2057 if (r)
2058 return r;
2059 r = cayman_cp_resume(rdev);
2060 if (r)
2061 return r;
2062
Alex Deucherf60cbd12012-12-04 15:27:33 -05002063 r = cayman_dma_resume(rdev);
2064 if (r)
2065 return r;
2066
Christian Königf2ba57b2013-04-08 12:41:29 +02002067 ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
2068 if (ring->ring_size) {
2069 r = radeon_ring_init(rdev, ring, ring->ring_size,
2070 R600_WB_UVD_RPTR_OFFSET,
2071 UVD_RBC_RB_RPTR, UVD_RBC_RB_WPTR,
2072 0, 0xfffff, RADEON_CP_PACKET2);
2073 if (!r)
2074 r = r600_uvd_init(rdev);
2075 if (r)
2076 DRM_ERROR("radeon: failed initializing UVD (%d).\n", r);
2077 }
2078
Christian König2898c342012-07-05 11:55:34 +02002079 r = radeon_ib_pool_init(rdev);
2080 if (r) {
2081 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
Jerome Glisseb15ba512011-11-15 11:48:34 -05002082 return r;
Christian König2898c342012-07-05 11:55:34 +02002083 }
Jerome Glisseb15ba512011-11-15 11:48:34 -05002084
Christian Königc6105f22012-07-05 14:32:00 +02002085 r = radeon_vm_manager_init(rdev);
2086 if (r) {
2087 dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
Jerome Glisse721604a2012-01-05 22:11:05 -05002088 return r;
Christian Königc6105f22012-07-05 14:32:00 +02002089 }
Jerome Glisse721604a2012-01-05 22:11:05 -05002090
Rafał Miłecki6b53a052012-06-11 12:34:01 +02002091 r = r600_audio_init(rdev);
2092 if (r)
2093 return r;
2094
Alex Deucher755d8192011-03-02 20:07:34 -05002095 return 0;
2096}
2097
2098int cayman_resume(struct radeon_device *rdev)
2099{
2100 int r;
2101
2102 /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
2103 * posting will perform necessary task to bring back GPU into good
2104 * shape.
2105 */
2106 /* post card */
2107 atom_asic_init(rdev->mode_info.atom_context);
2108
Alex Deuchera2c96a22013-02-28 17:58:36 -05002109 /* init golden registers */
2110 ni_init_golden_registers(rdev);
2111
Jerome Glisseb15ba512011-11-15 11:48:34 -05002112 rdev->accel_working = true;
Alex Deucher755d8192011-03-02 20:07:34 -05002113 r = cayman_startup(rdev);
2114 if (r) {
2115 DRM_ERROR("cayman startup failed on resume\n");
Jerome Glisse6b7746e2012-02-20 17:57:20 -05002116 rdev->accel_working = false;
Alex Deucher755d8192011-03-02 20:07:34 -05002117 return r;
2118 }
Alex Deucher755d8192011-03-02 20:07:34 -05002119 return r;
Alex Deucher755d8192011-03-02 20:07:34 -05002120}
2121
2122int cayman_suspend(struct radeon_device *rdev)
2123{
Rafał Miłecki6b53a052012-06-11 12:34:01 +02002124 r600_audio_fini(rdev);
Alex Deucherfa3daf92013-03-11 15:32:26 -04002125 radeon_vm_manager_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05002126 cayman_cp_enable(rdev, false);
Alex Deucherf60cbd12012-12-04 15:27:33 -05002127 cayman_dma_stop(rdev);
Christian Königf2ba57b2013-04-08 12:41:29 +02002128 r600_uvd_rbc_stop(rdev);
2129 radeon_uvd_suspend(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05002130 evergreen_irq_suspend(rdev);
2131 radeon_wb_disable(rdev);
2132 cayman_pcie_gart_disable(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05002133 return 0;
2134}
2135
2136/* Plan is to move initialization in that function and use
2137 * helper function so that radeon_device_init pretty much
2138 * do nothing more than calling asic specific function. This
2139 * should also allow to remove a bunch of callback function
2140 * like vram_info.
2141 */
2142int cayman_init(struct radeon_device *rdev)
2143{
Christian Könige32eb502011-10-23 12:56:27 +02002144 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucher755d8192011-03-02 20:07:34 -05002145 int r;
2146
Alex Deucher755d8192011-03-02 20:07:34 -05002147 /* Read BIOS */
2148 if (!radeon_get_bios(rdev)) {
2149 if (ASIC_IS_AVIVO(rdev))
2150 return -EINVAL;
2151 }
2152 /* Must be an ATOMBIOS */
2153 if (!rdev->is_atom_bios) {
2154 dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
2155 return -EINVAL;
2156 }
2157 r = radeon_atombios_init(rdev);
2158 if (r)
2159 return r;
2160
2161 /* Post card if necessary */
2162 if (!radeon_card_posted(rdev)) {
2163 if (!rdev->bios) {
2164 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
2165 return -EINVAL;
2166 }
2167 DRM_INFO("GPU not posted. posting now...\n");
2168 atom_asic_init(rdev->mode_info.atom_context);
2169 }
Alex Deuchera2c96a22013-02-28 17:58:36 -05002170 /* init golden registers */
2171 ni_init_golden_registers(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05002172 /* Initialize scratch registers */
2173 r600_scratch_init(rdev);
2174 /* Initialize surface registers */
2175 radeon_surface_init(rdev);
2176 /* Initialize clocks */
2177 radeon_get_clock_info(rdev->ddev);
2178 /* Fence driver */
Jerome Glisse30eb77f2011-11-20 20:45:34 +00002179 r = radeon_fence_driver_init(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05002180 if (r)
2181 return r;
2182 /* initialize memory controller */
2183 r = evergreen_mc_init(rdev);
2184 if (r)
2185 return r;
2186 /* Memory manager */
2187 r = radeon_bo_init(rdev);
2188 if (r)
2189 return r;
2190
2191 r = radeon_irq_kms_init(rdev);
2192 if (r)
2193 return r;
2194
Christian Könige32eb502011-10-23 12:56:27 +02002195 ring->ring_obj = NULL;
2196 r600_ring_init(rdev, ring, 1024 * 1024);
Alex Deucher755d8192011-03-02 20:07:34 -05002197
Alex Deucherf60cbd12012-12-04 15:27:33 -05002198 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
2199 ring->ring_obj = NULL;
2200 r600_ring_init(rdev, ring, 64 * 1024);
2201
2202 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
2203 ring->ring_obj = NULL;
2204 r600_ring_init(rdev, ring, 64 * 1024);
2205
Christian Königf2ba57b2013-04-08 12:41:29 +02002206 r = radeon_uvd_init(rdev);
2207 if (!r) {
2208 ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
2209 ring->ring_obj = NULL;
2210 r600_ring_init(rdev, ring, 4096);
2211 }
2212
Alex Deucher755d8192011-03-02 20:07:34 -05002213 rdev->ih.ring_obj = NULL;
2214 r600_ih_ring_init(rdev, 64 * 1024);
2215
2216 r = r600_pcie_gart_init(rdev);
2217 if (r)
2218 return r;
2219
2220 rdev->accel_working = true;
2221 r = cayman_startup(rdev);
2222 if (r) {
2223 dev_err(rdev->dev, "disabling GPU acceleration\n");
2224 cayman_cp_fini(rdev);
Alex Deucherf60cbd12012-12-04 15:27:33 -05002225 cayman_dma_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05002226 r600_irq_fini(rdev);
Alex Deucherc420c742012-03-20 17:18:39 -04002227 if (rdev->flags & RADEON_IS_IGP)
2228 si_rlc_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05002229 radeon_wb_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02002230 radeon_ib_pool_fini(rdev);
Jerome Glisse721604a2012-01-05 22:11:05 -05002231 radeon_vm_manager_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05002232 radeon_irq_kms_fini(rdev);
2233 cayman_pcie_gart_fini(rdev);
2234 rdev->accel_working = false;
2235 }
Alex Deucher755d8192011-03-02 20:07:34 -05002236
2237 /* Don't start up if the MC ucode is missing.
2238 * The default clocks and voltages before the MC ucode
2239 * is loaded are not suffient for advanced operations.
Alex Deucherc420c742012-03-20 17:18:39 -04002240 *
2241 * We can skip this check for TN, because there is no MC
2242 * ucode.
Alex Deucher755d8192011-03-02 20:07:34 -05002243 */
Alex Deucherc420c742012-03-20 17:18:39 -04002244 if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
Alex Deucher755d8192011-03-02 20:07:34 -05002245 DRM_ERROR("radeon: MC ucode required for NI+.\n");
2246 return -EINVAL;
2247 }
2248
2249 return 0;
2250}
2251
2252void cayman_fini(struct radeon_device *rdev)
2253{
Ilija Hadzicfb3d9e92011-10-12 23:29:41 -04002254 r600_blit_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05002255 cayman_cp_fini(rdev);
Alex Deucherf60cbd12012-12-04 15:27:33 -05002256 cayman_dma_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05002257 r600_irq_fini(rdev);
Alex Deucherc420c742012-03-20 17:18:39 -04002258 if (rdev->flags & RADEON_IS_IGP)
2259 si_rlc_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05002260 radeon_wb_fini(rdev);
Jerome Glisse721604a2012-01-05 22:11:05 -05002261 radeon_vm_manager_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02002262 radeon_ib_pool_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05002263 radeon_irq_kms_fini(rdev);
Christian Königf2ba57b2013-04-08 12:41:29 +02002264 radeon_uvd_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05002265 cayman_pcie_gart_fini(rdev);
Alex Deucher16cdf042011-10-28 10:30:02 -04002266 r600_vram_scratch_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05002267 radeon_gem_fini(rdev);
2268 radeon_fence_driver_fini(rdev);
2269 radeon_bo_fini(rdev);
2270 radeon_atombios_fini(rdev);
2271 kfree(rdev->bios);
2272 rdev->bios = NULL;
2273}
2274
Jerome Glisse721604a2012-01-05 22:11:05 -05002275/*
2276 * vm
2277 */
2278int cayman_vm_init(struct radeon_device *rdev)
2279{
2280 /* number of VMs */
2281 rdev->vm_manager.nvm = 8;
2282 /* base offset of vram pages */
Alex Deuchere71270f2012-03-20 17:18:38 -04002283 if (rdev->flags & RADEON_IS_IGP) {
2284 u64 tmp = RREG32(FUS_MC_VM_FB_OFFSET);
2285 tmp <<= 22;
2286 rdev->vm_manager.vram_base_offset = tmp;
2287 } else
2288 rdev->vm_manager.vram_base_offset = 0;
Jerome Glisse721604a2012-01-05 22:11:05 -05002289 return 0;
2290}
2291
2292void cayman_vm_fini(struct radeon_device *rdev)
2293{
2294}
2295
Christian Königdce34bf2012-09-17 19:36:18 +02002296#define R600_ENTRY_VALID (1 << 0)
Jerome Glisse721604a2012-01-05 22:11:05 -05002297#define R600_PTE_SYSTEM (1 << 1)
2298#define R600_PTE_SNOOPED (1 << 2)
2299#define R600_PTE_READABLE (1 << 5)
2300#define R600_PTE_WRITEABLE (1 << 6)
2301
Christian König089a7862012-08-11 11:54:05 +02002302uint32_t cayman_vm_page_flags(struct radeon_device *rdev, uint32_t flags)
Jerome Glisse721604a2012-01-05 22:11:05 -05002303{
2304 uint32_t r600_flags = 0;
Christian Königdce34bf2012-09-17 19:36:18 +02002305 r600_flags |= (flags & RADEON_VM_PAGE_VALID) ? R600_ENTRY_VALID : 0;
Jerome Glisse721604a2012-01-05 22:11:05 -05002306 r600_flags |= (flags & RADEON_VM_PAGE_READABLE) ? R600_PTE_READABLE : 0;
2307 r600_flags |= (flags & RADEON_VM_PAGE_WRITEABLE) ? R600_PTE_WRITEABLE : 0;
2308 if (flags & RADEON_VM_PAGE_SYSTEM) {
2309 r600_flags |= R600_PTE_SYSTEM;
2310 r600_flags |= (flags & RADEON_VM_PAGE_SNOOPED) ? R600_PTE_SNOOPED : 0;
2311 }
2312 return r600_flags;
2313}
2314
Alex Deucher7a083292012-08-31 13:51:21 -04002315/**
2316 * cayman_vm_set_page - update the page tables using the CP
2317 *
2318 * @rdev: radeon_device pointer
Alex Deucher43f12142013-02-01 17:32:42 +01002319 * @ib: indirect buffer to fill with commands
Christian Königdce34bf2012-09-17 19:36:18 +02002320 * @pe: addr of the page entry
2321 * @addr: dst addr to write into pe
2322 * @count: number of page entries to update
2323 * @incr: increase next addr by incr bytes
2324 * @flags: access flags
Alex Deucher7a083292012-08-31 13:51:21 -04002325 *
Alex Deucher43f12142013-02-01 17:32:42 +01002326 * Update the page tables using the CP (cayman/TN).
Alex Deucher7a083292012-08-31 13:51:21 -04002327 */
Alex Deucher43f12142013-02-01 17:32:42 +01002328void cayman_vm_set_page(struct radeon_device *rdev,
2329 struct radeon_ib *ib,
2330 uint64_t pe,
Christian Königdce34bf2012-09-17 19:36:18 +02002331 uint64_t addr, unsigned count,
2332 uint32_t incr, uint32_t flags)
Jerome Glisse721604a2012-01-05 22:11:05 -05002333{
Christian Königdce34bf2012-09-17 19:36:18 +02002334 uint32_t r600_flags = cayman_vm_page_flags(rdev, flags);
Alex Deucher3b6b59b2012-10-22 12:19:01 -04002335 uint64_t value;
2336 unsigned ndw;
Jerome Glisse721604a2012-01-05 22:11:05 -05002337
Alex Deucher3b6b59b2012-10-22 12:19:01 -04002338 if (rdev->asic->vm.pt_ring_index == RADEON_RING_TYPE_GFX_INDEX) {
2339 while (count) {
2340 ndw = 1 + count * 2;
2341 if (ndw > 0x3FFF)
2342 ndw = 0x3FFF;
Christian König089a7862012-08-11 11:54:05 +02002343
Alex Deucher43f12142013-02-01 17:32:42 +01002344 ib->ptr[ib->length_dw++] = PACKET3(PACKET3_ME_WRITE, ndw);
2345 ib->ptr[ib->length_dw++] = pe;
2346 ib->ptr[ib->length_dw++] = upper_32_bits(pe) & 0xff;
Alex Deucher3b6b59b2012-10-22 12:19:01 -04002347 for (; ndw > 1; ndw -= 2, --count, pe += 8) {
2348 if (flags & RADEON_VM_PAGE_SYSTEM) {
2349 value = radeon_vm_map_gart(rdev, addr);
2350 value &= 0xFFFFFFFFFFFFF000ULL;
2351 } else if (flags & RADEON_VM_PAGE_VALID) {
2352 value = addr;
2353 } else {
2354 value = 0;
2355 }
Christian Königf9fdffa2012-10-22 17:42:36 +02002356 addr += incr;
Alex Deucher3b6b59b2012-10-22 12:19:01 -04002357 value |= r600_flags;
Alex Deucher43f12142013-02-01 17:32:42 +01002358 ib->ptr[ib->length_dw++] = value;
2359 ib->ptr[ib->length_dw++] = upper_32_bits(value);
Christian Königf9fdffa2012-10-22 17:42:36 +02002360 }
Alex Deucher3b6b59b2012-10-22 12:19:01 -04002361 }
2362 } else {
Alex Deucher2ab91ad2013-04-16 10:42:15 -04002363 if ((flags & RADEON_VM_PAGE_SYSTEM) ||
2364 (count == 1)) {
2365 while (count) {
2366 ndw = count * 2;
2367 if (ndw > 0xFFFFE)
2368 ndw = 0xFFFFE;
Christian Königf9fdffa2012-10-22 17:42:36 +02002369
Alex Deucher2ab91ad2013-04-16 10:42:15 -04002370 /* for non-physically contiguous pages (system) */
2371 ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_WRITE, 0, 0, ndw);
2372 ib->ptr[ib->length_dw++] = pe;
2373 ib->ptr[ib->length_dw++] = upper_32_bits(pe) & 0xff;
2374 for (; ndw > 0; ndw -= 2, --count, pe += 8) {
2375 if (flags & RADEON_VM_PAGE_SYSTEM) {
2376 value = radeon_vm_map_gart(rdev, addr);
2377 value &= 0xFFFFFFFFFFFFF000ULL;
2378 } else if (flags & RADEON_VM_PAGE_VALID) {
2379 value = addr;
2380 } else {
2381 value = 0;
2382 }
2383 addr += incr;
2384 value |= r600_flags;
2385 ib->ptr[ib->length_dw++] = value;
2386 ib->ptr[ib->length_dw++] = upper_32_bits(value);
Alex Deucher3b6b59b2012-10-22 12:19:01 -04002387 }
Alex Deucher2ab91ad2013-04-16 10:42:15 -04002388 }
2389 while (ib->length_dw & 0x7)
2390 ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0);
2391 } else {
2392 while (count) {
2393 ndw = count * 2;
2394 if (ndw > 0xFFFFE)
2395 ndw = 0xFFFFE;
2396
2397 if (flags & RADEON_VM_PAGE_VALID)
2398 value = addr;
2399 else
2400 value = 0;
2401 /* for physically contiguous pages (vram) */
2402 ib->ptr[ib->length_dw++] = DMA_PTE_PDE_PACKET(ndw);
2403 ib->ptr[ib->length_dw++] = pe; /* dst addr */
2404 ib->ptr[ib->length_dw++] = upper_32_bits(pe) & 0xff;
2405 ib->ptr[ib->length_dw++] = r600_flags; /* mask */
2406 ib->ptr[ib->length_dw++] = 0;
2407 ib->ptr[ib->length_dw++] = value; /* value */
Alex Deucher43f12142013-02-01 17:32:42 +01002408 ib->ptr[ib->length_dw++] = upper_32_bits(value);
Alex Deucher2ab91ad2013-04-16 10:42:15 -04002409 ib->ptr[ib->length_dw++] = incr; /* increment size */
2410 ib->ptr[ib->length_dw++] = 0;
2411 pe += ndw * 4;
2412 addr += (ndw / 2) * incr;
2413 count -= ndw / 2;
Alex Deucher3b6b59b2012-10-22 12:19:01 -04002414 }
Christian König2a6f1ab2012-08-11 15:00:30 +02002415 }
Alex Deucher43f12142013-02-01 17:32:42 +01002416 while (ib->length_dw & 0x7)
2417 ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0);
Christian König2a6f1ab2012-08-11 15:00:30 +02002418 }
Jerome Glisse721604a2012-01-05 22:11:05 -05002419}
Christian König9b40e5d2012-08-08 12:22:43 +02002420
Alex Deucher7a083292012-08-31 13:51:21 -04002421/**
2422 * cayman_vm_flush - vm flush using the CP
2423 *
2424 * @rdev: radeon_device pointer
2425 *
2426 * Update the page table base and flush the VM TLB
2427 * using the CP (cayman-si).
2428 */
Alex Deucher498522b2012-10-02 14:43:38 -04002429void cayman_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
Christian König9b40e5d2012-08-08 12:22:43 +02002430{
Alex Deucher498522b2012-10-02 14:43:38 -04002431 struct radeon_ring *ring = &rdev->ring[ridx];
Christian König9b40e5d2012-08-08 12:22:43 +02002432
Christian Königee60e292012-08-09 16:21:08 +02002433 if (vm == NULL)
Christian König9b40e5d2012-08-08 12:22:43 +02002434 return;
2435
Christian Königee60e292012-08-09 16:21:08 +02002436 radeon_ring_write(ring, PACKET0(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2), 0));
Dmitry Cherkasovfa87e622012-09-17 19:36:19 +02002437 radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
Christian Königee60e292012-08-09 16:21:08 +02002438
Christian König9b40e5d2012-08-08 12:22:43 +02002439 /* flush hdp cache */
2440 radeon_ring_write(ring, PACKET0(HDP_MEM_COHERENCY_FLUSH_CNTL, 0));
2441 radeon_ring_write(ring, 0x1);
2442
2443 /* bits 0-7 are the VM contexts0-7 */
2444 radeon_ring_write(ring, PACKET0(VM_INVALIDATE_REQUEST, 0));
Alex Deucher498522b2012-10-02 14:43:38 -04002445 radeon_ring_write(ring, 1 << vm->id);
Christian König58f8cf52012-10-22 17:42:35 +02002446
2447 /* sync PFP to ME, otherwise we might get invalid PFP reads */
2448 radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
2449 radeon_ring_write(ring, 0x0);
Alex Deucher0af62b02011-01-06 21:19:31 -05002450}
Alex Deucherf60cbd12012-12-04 15:27:33 -05002451
2452void cayman_dma_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
2453{
2454 struct radeon_ring *ring = &rdev->ring[ridx];
2455
2456 if (vm == NULL)
2457 return;
2458
2459 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0));
2460 radeon_ring_write(ring, (0xf << 16) | ((VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2));
2461 radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
2462
2463 /* flush hdp cache */
2464 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0));
2465 radeon_ring_write(ring, (0xf << 16) | (HDP_MEM_COHERENCY_FLUSH_CNTL >> 2));
2466 radeon_ring_write(ring, 1);
2467
2468 /* bits 0-7 are the VM contexts0-7 */
2469 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0));
2470 radeon_ring_write(ring, (0xf << 16) | (VM_INVALIDATE_REQUEST >> 2));
2471 radeon_ring_write(ring, 1 << vm->id);
2472}
2473