blob: e77c9273bc9cc2a994428005de8020399fd4cdc6 [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
81#define BTC_IO_MC_REGS_SIZE 29
82
83static const u32 barts_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
84 {0x00000077, 0xff010100},
85 {0x00000078, 0x00000000},
86 {0x00000079, 0x00001434},
87 {0x0000007a, 0xcc08ec08},
88 {0x0000007b, 0x00040000},
89 {0x0000007c, 0x000080c0},
90 {0x0000007d, 0x09000000},
91 {0x0000007e, 0x00210404},
92 {0x00000081, 0x08a8e800},
93 {0x00000082, 0x00030444},
94 {0x00000083, 0x00000000},
95 {0x00000085, 0x00000001},
96 {0x00000086, 0x00000002},
97 {0x00000087, 0x48490000},
98 {0x00000088, 0x20244647},
99 {0x00000089, 0x00000005},
100 {0x0000008b, 0x66030000},
101 {0x0000008c, 0x00006603},
102 {0x0000008d, 0x00000100},
103 {0x0000008f, 0x00001c0a},
104 {0x00000090, 0xff000001},
105 {0x00000094, 0x00101101},
106 {0x00000095, 0x00000fff},
107 {0x00000096, 0x00116fff},
108 {0x00000097, 0x60010000},
109 {0x00000098, 0x10010000},
110 {0x00000099, 0x00006000},
111 {0x0000009a, 0x00001000},
112 {0x0000009f, 0x00946a00}
113};
114
115static const u32 turks_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
116 {0x00000077, 0xff010100},
117 {0x00000078, 0x00000000},
118 {0x00000079, 0x00001434},
119 {0x0000007a, 0xcc08ec08},
120 {0x0000007b, 0x00040000},
121 {0x0000007c, 0x000080c0},
122 {0x0000007d, 0x09000000},
123 {0x0000007e, 0x00210404},
124 {0x00000081, 0x08a8e800},
125 {0x00000082, 0x00030444},
126 {0x00000083, 0x00000000},
127 {0x00000085, 0x00000001},
128 {0x00000086, 0x00000002},
129 {0x00000087, 0x48490000},
130 {0x00000088, 0x20244647},
131 {0x00000089, 0x00000005},
132 {0x0000008b, 0x66030000},
133 {0x0000008c, 0x00006603},
134 {0x0000008d, 0x00000100},
135 {0x0000008f, 0x00001c0a},
136 {0x00000090, 0xff000001},
137 {0x00000094, 0x00101101},
138 {0x00000095, 0x00000fff},
139 {0x00000096, 0x00116fff},
140 {0x00000097, 0x60010000},
141 {0x00000098, 0x10010000},
142 {0x00000099, 0x00006000},
143 {0x0000009a, 0x00001000},
144 {0x0000009f, 0x00936a00}
145};
146
147static const u32 caicos_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
148 {0x00000077, 0xff010100},
149 {0x00000078, 0x00000000},
150 {0x00000079, 0x00001434},
151 {0x0000007a, 0xcc08ec08},
152 {0x0000007b, 0x00040000},
153 {0x0000007c, 0x000080c0},
154 {0x0000007d, 0x09000000},
155 {0x0000007e, 0x00210404},
156 {0x00000081, 0x08a8e800},
157 {0x00000082, 0x00030444},
158 {0x00000083, 0x00000000},
159 {0x00000085, 0x00000001},
160 {0x00000086, 0x00000002},
161 {0x00000087, 0x48490000},
162 {0x00000088, 0x20244647},
163 {0x00000089, 0x00000005},
164 {0x0000008b, 0x66030000},
165 {0x0000008c, 0x00006603},
166 {0x0000008d, 0x00000100},
167 {0x0000008f, 0x00001c0a},
168 {0x00000090, 0xff000001},
169 {0x00000094, 0x00101101},
170 {0x00000095, 0x00000fff},
171 {0x00000096, 0x00116fff},
172 {0x00000097, 0x60010000},
173 {0x00000098, 0x10010000},
174 {0x00000099, 0x00006000},
175 {0x0000009a, 0x00001000},
176 {0x0000009f, 0x00916a00}
177};
178
Alex Deucher9b8253c2011-03-02 20:07:28 -0500179static const u32 cayman_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
180 {0x00000077, 0xff010100},
181 {0x00000078, 0x00000000},
182 {0x00000079, 0x00001434},
183 {0x0000007a, 0xcc08ec08},
184 {0x0000007b, 0x00040000},
185 {0x0000007c, 0x000080c0},
186 {0x0000007d, 0x09000000},
187 {0x0000007e, 0x00210404},
188 {0x00000081, 0x08a8e800},
189 {0x00000082, 0x00030444},
190 {0x00000083, 0x00000000},
191 {0x00000085, 0x00000001},
192 {0x00000086, 0x00000002},
193 {0x00000087, 0x48490000},
194 {0x00000088, 0x20244647},
195 {0x00000089, 0x00000005},
196 {0x0000008b, 0x66030000},
197 {0x0000008c, 0x00006603},
198 {0x0000008d, 0x00000100},
199 {0x0000008f, 0x00001c0a},
200 {0x00000090, 0xff000001},
201 {0x00000094, 0x00101101},
202 {0x00000095, 0x00000fff},
203 {0x00000096, 0x00116fff},
204 {0x00000097, 0x60010000},
205 {0x00000098, 0x10010000},
206 {0x00000099, 0x00006000},
207 {0x0000009a, 0x00001000},
208 {0x0000009f, 0x00976b00}
209};
210
Alex Deucher755d8192011-03-02 20:07:34 -0500211int ni_mc_load_microcode(struct radeon_device *rdev)
Alex Deucher0af62b02011-01-06 21:19:31 -0500212{
213 const __be32 *fw_data;
214 u32 mem_type, running, blackout = 0;
215 u32 *io_mc_regs;
Alex Deucher9b8253c2011-03-02 20:07:28 -0500216 int i, ucode_size, regs_size;
Alex Deucher0af62b02011-01-06 21:19:31 -0500217
218 if (!rdev->mc_fw)
219 return -EINVAL;
220
221 switch (rdev->family) {
222 case CHIP_BARTS:
223 io_mc_regs = (u32 *)&barts_io_mc_regs;
Alex Deucher9b8253c2011-03-02 20:07:28 -0500224 ucode_size = BTC_MC_UCODE_SIZE;
225 regs_size = BTC_IO_MC_REGS_SIZE;
Alex Deucher0af62b02011-01-06 21:19:31 -0500226 break;
227 case CHIP_TURKS:
228 io_mc_regs = (u32 *)&turks_io_mc_regs;
Alex Deucher9b8253c2011-03-02 20:07:28 -0500229 ucode_size = BTC_MC_UCODE_SIZE;
230 regs_size = BTC_IO_MC_REGS_SIZE;
Alex Deucher0af62b02011-01-06 21:19:31 -0500231 break;
232 case CHIP_CAICOS:
233 default:
234 io_mc_regs = (u32 *)&caicos_io_mc_regs;
Alex Deucher9b8253c2011-03-02 20:07:28 -0500235 ucode_size = BTC_MC_UCODE_SIZE;
236 regs_size = BTC_IO_MC_REGS_SIZE;
237 break;
238 case CHIP_CAYMAN:
239 io_mc_regs = (u32 *)&cayman_io_mc_regs;
240 ucode_size = CAYMAN_MC_UCODE_SIZE;
241 regs_size = BTC_IO_MC_REGS_SIZE;
Alex Deucher0af62b02011-01-06 21:19:31 -0500242 break;
243 }
244
245 mem_type = (RREG32(MC_SEQ_MISC0) & MC_SEQ_MISC0_GDDR5_MASK) >> MC_SEQ_MISC0_GDDR5_SHIFT;
246 running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
247
248 if ((mem_type == MC_SEQ_MISC0_GDDR5_VALUE) && (running == 0)) {
249 if (running) {
250 blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
251 WREG32(MC_SHARED_BLACKOUT_CNTL, 1);
252 }
253
254 /* reset the engine and set to writable */
255 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
256 WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
257
258 /* load mc io regs */
Alex Deucher9b8253c2011-03-02 20:07:28 -0500259 for (i = 0; i < regs_size; i++) {
Alex Deucher0af62b02011-01-06 21:19:31 -0500260 WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
261 WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
262 }
263 /* load the MC ucode */
264 fw_data = (const __be32 *)rdev->mc_fw->data;
Alex Deucher9b8253c2011-03-02 20:07:28 -0500265 for (i = 0; i < ucode_size; i++)
Alex Deucher0af62b02011-01-06 21:19:31 -0500266 WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
267
268 /* put the engine back into the active state */
269 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
270 WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
271 WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
272
273 /* wait for training to complete */
Alex Deucher0e2c9782011-11-02 18:08:25 -0400274 for (i = 0; i < rdev->usec_timeout; i++) {
275 if (RREG32(MC_IO_PAD_CNTL_D0) & MEM_FALL_OUT_CMD)
276 break;
277 udelay(1);
278 }
Alex Deucher0af62b02011-01-06 21:19:31 -0500279
280 if (running)
281 WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
282 }
283
284 return 0;
285}
286
287int ni_init_microcode(struct radeon_device *rdev)
288{
289 struct platform_device *pdev;
290 const char *chip_name;
291 const char *rlc_chip_name;
292 size_t pfp_req_size, me_req_size, rlc_req_size, mc_req_size;
293 char fw_name[30];
294 int err;
295
296 DRM_DEBUG("\n");
297
298 pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
299 err = IS_ERR(pdev);
300 if (err) {
301 printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
302 return -EINVAL;
303 }
304
305 switch (rdev->family) {
306 case CHIP_BARTS:
307 chip_name = "BARTS";
308 rlc_chip_name = "BTC";
Alex Deucher9b8253c2011-03-02 20:07:28 -0500309 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
310 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
311 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
312 mc_req_size = BTC_MC_UCODE_SIZE * 4;
Alex Deucher0af62b02011-01-06 21:19:31 -0500313 break;
314 case CHIP_TURKS:
315 chip_name = "TURKS";
316 rlc_chip_name = "BTC";
Alex Deucher9b8253c2011-03-02 20:07:28 -0500317 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
318 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
319 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
320 mc_req_size = BTC_MC_UCODE_SIZE * 4;
Alex Deucher0af62b02011-01-06 21:19:31 -0500321 break;
322 case CHIP_CAICOS:
323 chip_name = "CAICOS";
324 rlc_chip_name = "BTC";
Alex Deucher9b8253c2011-03-02 20:07:28 -0500325 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
326 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
327 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
328 mc_req_size = BTC_MC_UCODE_SIZE * 4;
329 break;
330 case CHIP_CAYMAN:
331 chip_name = "CAYMAN";
332 rlc_chip_name = "CAYMAN";
333 pfp_req_size = CAYMAN_PFP_UCODE_SIZE * 4;
334 me_req_size = CAYMAN_PM4_UCODE_SIZE * 4;
335 rlc_req_size = CAYMAN_RLC_UCODE_SIZE * 4;
336 mc_req_size = CAYMAN_MC_UCODE_SIZE * 4;
Alex Deucher0af62b02011-01-06 21:19:31 -0500337 break;
Alex Deucherc420c742012-03-20 17:18:39 -0400338 case CHIP_ARUBA:
339 chip_name = "ARUBA";
340 rlc_chip_name = "ARUBA";
341 /* pfp/me same size as CAYMAN */
342 pfp_req_size = CAYMAN_PFP_UCODE_SIZE * 4;
343 me_req_size = CAYMAN_PM4_UCODE_SIZE * 4;
344 rlc_req_size = ARUBA_RLC_UCODE_SIZE * 4;
345 mc_req_size = 0;
346 break;
Alex Deucher0af62b02011-01-06 21:19:31 -0500347 default: BUG();
348 }
349
Alex Deucher0af62b02011-01-06 21:19:31 -0500350 DRM_INFO("Loading %s Microcode\n", chip_name);
351
352 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
353 err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
354 if (err)
355 goto out;
356 if (rdev->pfp_fw->size != pfp_req_size) {
357 printk(KERN_ERR
358 "ni_cp: Bogus length %zu in firmware \"%s\"\n",
359 rdev->pfp_fw->size, fw_name);
360 err = -EINVAL;
361 goto out;
362 }
363
364 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
365 err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
366 if (err)
367 goto out;
368 if (rdev->me_fw->size != me_req_size) {
369 printk(KERN_ERR
370 "ni_cp: Bogus length %zu in firmware \"%s\"\n",
371 rdev->me_fw->size, fw_name);
372 err = -EINVAL;
373 }
374
375 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
376 err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
377 if (err)
378 goto out;
379 if (rdev->rlc_fw->size != rlc_req_size) {
380 printk(KERN_ERR
381 "ni_rlc: Bogus length %zu in firmware \"%s\"\n",
382 rdev->rlc_fw->size, fw_name);
383 err = -EINVAL;
384 }
385
Alex Deucherc420c742012-03-20 17:18:39 -0400386 /* no MC ucode on TN */
387 if (!(rdev->flags & RADEON_IS_IGP)) {
388 snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
389 err = request_firmware(&rdev->mc_fw, fw_name, &pdev->dev);
390 if (err)
391 goto out;
392 if (rdev->mc_fw->size != mc_req_size) {
393 printk(KERN_ERR
394 "ni_mc: Bogus length %zu in firmware \"%s\"\n",
395 rdev->mc_fw->size, fw_name);
396 err = -EINVAL;
397 }
Alex Deucher0af62b02011-01-06 21:19:31 -0500398 }
399out:
400 platform_device_unregister(pdev);
401
402 if (err) {
403 if (err != -EINVAL)
404 printk(KERN_ERR
405 "ni_cp: Failed to load firmware \"%s\"\n",
406 fw_name);
407 release_firmware(rdev->pfp_fw);
408 rdev->pfp_fw = NULL;
409 release_firmware(rdev->me_fw);
410 rdev->me_fw = NULL;
411 release_firmware(rdev->rlc_fw);
412 rdev->rlc_fw = NULL;
413 release_firmware(rdev->mc_fw);
414 rdev->mc_fw = NULL;
415 }
416 return err;
417}
418
Alex Deucherfecf1d02011-03-02 20:07:29 -0500419/*
420 * Core functions
421 */
Alex Deucherfecf1d02011-03-02 20:07:29 -0500422static void cayman_gpu_init(struct radeon_device *rdev)
423{
Alex Deucherfecf1d02011-03-02 20:07:29 -0500424 u32 gb_addr_config = 0;
425 u32 mc_shared_chmap, mc_arb_ramcfg;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500426 u32 cgts_tcc_disable;
427 u32 sx_debug_1;
428 u32 smx_dc_ctl0;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500429 u32 cgts_sm_ctrl_reg;
430 u32 hdp_host_path_cntl;
431 u32 tmp;
Alex Deucher416a2bd2012-05-31 19:00:25 -0400432 u32 disabled_rb_mask;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500433 int i, j;
434
435 switch (rdev->family) {
436 case CHIP_CAYMAN:
Alex Deucherfecf1d02011-03-02 20:07:29 -0500437 rdev->config.cayman.max_shader_engines = 2;
438 rdev->config.cayman.max_pipes_per_simd = 4;
439 rdev->config.cayman.max_tile_pipes = 8;
440 rdev->config.cayman.max_simds_per_se = 12;
441 rdev->config.cayman.max_backends_per_se = 4;
442 rdev->config.cayman.max_texture_channel_caches = 8;
443 rdev->config.cayman.max_gprs = 256;
444 rdev->config.cayman.max_threads = 256;
445 rdev->config.cayman.max_gs_threads = 32;
446 rdev->config.cayman.max_stack_entries = 512;
447 rdev->config.cayman.sx_num_of_sets = 8;
448 rdev->config.cayman.sx_max_export_size = 256;
449 rdev->config.cayman.sx_max_export_pos_size = 64;
450 rdev->config.cayman.sx_max_export_smx_size = 192;
451 rdev->config.cayman.max_hw_contexts = 8;
452 rdev->config.cayman.sq_num_cf_insts = 2;
453
454 rdev->config.cayman.sc_prim_fifo_size = 0x100;
455 rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30;
456 rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -0400457 gb_addr_config = CAYMAN_GB_ADDR_CONFIG_GOLDEN;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500458 break;
Alex Deucher7b76e472012-03-20 17:18:36 -0400459 case CHIP_ARUBA:
460 default:
461 rdev->config.cayman.max_shader_engines = 1;
462 rdev->config.cayman.max_pipes_per_simd = 4;
463 rdev->config.cayman.max_tile_pipes = 2;
464 if ((rdev->pdev->device == 0x9900) ||
Alex Deucherd430f7d2012-06-05 09:50:28 -0400465 (rdev->pdev->device == 0x9901) ||
466 (rdev->pdev->device == 0x9905) ||
467 (rdev->pdev->device == 0x9906) ||
468 (rdev->pdev->device == 0x9907) ||
469 (rdev->pdev->device == 0x9908) ||
470 (rdev->pdev->device == 0x9909) ||
471 (rdev->pdev->device == 0x9910) ||
472 (rdev->pdev->device == 0x9917)) {
Alex Deucher7b76e472012-03-20 17:18:36 -0400473 rdev->config.cayman.max_simds_per_se = 6;
474 rdev->config.cayman.max_backends_per_se = 2;
475 } else if ((rdev->pdev->device == 0x9903) ||
Alex Deucherd430f7d2012-06-05 09:50:28 -0400476 (rdev->pdev->device == 0x9904) ||
477 (rdev->pdev->device == 0x990A) ||
478 (rdev->pdev->device == 0x9913) ||
479 (rdev->pdev->device == 0x9918)) {
Alex Deucher7b76e472012-03-20 17:18:36 -0400480 rdev->config.cayman.max_simds_per_se = 4;
481 rdev->config.cayman.max_backends_per_se = 2;
Alex Deucherd430f7d2012-06-05 09:50:28 -0400482 } else if ((rdev->pdev->device == 0x9919) ||
483 (rdev->pdev->device == 0x9990) ||
484 (rdev->pdev->device == 0x9991) ||
485 (rdev->pdev->device == 0x9994) ||
486 (rdev->pdev->device == 0x99A0)) {
Alex Deucher7b76e472012-03-20 17:18:36 -0400487 rdev->config.cayman.max_simds_per_se = 3;
488 rdev->config.cayman.max_backends_per_se = 1;
489 } else {
490 rdev->config.cayman.max_simds_per_se = 2;
491 rdev->config.cayman.max_backends_per_se = 1;
492 }
493 rdev->config.cayman.max_texture_channel_caches = 2;
494 rdev->config.cayman.max_gprs = 256;
495 rdev->config.cayman.max_threads = 256;
496 rdev->config.cayman.max_gs_threads = 32;
497 rdev->config.cayman.max_stack_entries = 512;
498 rdev->config.cayman.sx_num_of_sets = 8;
499 rdev->config.cayman.sx_max_export_size = 256;
500 rdev->config.cayman.sx_max_export_pos_size = 64;
501 rdev->config.cayman.sx_max_export_smx_size = 192;
502 rdev->config.cayman.max_hw_contexts = 8;
503 rdev->config.cayman.sq_num_cf_insts = 2;
504
505 rdev->config.cayman.sc_prim_fifo_size = 0x40;
506 rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30;
507 rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -0400508 gb_addr_config = ARUBA_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher7b76e472012-03-20 17:18:36 -0400509 break;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500510 }
511
512 /* Initialize HDP */
513 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
514 WREG32((0x2c14 + j), 0x00000000);
515 WREG32((0x2c18 + j), 0x00000000);
516 WREG32((0x2c1c + j), 0x00000000);
517 WREG32((0x2c20 + j), 0x00000000);
518 WREG32((0x2c24 + j), 0x00000000);
519 }
520
521 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
522
Alex Deucherd054ac12011-09-01 17:46:15 +0000523 evergreen_fix_pci_max_read_req_size(rdev);
524
Alex Deucherfecf1d02011-03-02 20:07:29 -0500525 mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
526 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
527
Alex Deucherfecf1d02011-03-02 20:07:29 -0500528 tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
529 rdev->config.cayman.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
530 if (rdev->config.cayman.mem_row_size_in_kb > 4)
531 rdev->config.cayman.mem_row_size_in_kb = 4;
532 /* XXX use MC settings? */
533 rdev->config.cayman.shader_engine_tile_size = 32;
534 rdev->config.cayman.num_gpus = 1;
535 rdev->config.cayman.multi_gpu_tile_size = 64;
536
Alex Deucherfecf1d02011-03-02 20:07:29 -0500537 tmp = (gb_addr_config & NUM_PIPES_MASK) >> NUM_PIPES_SHIFT;
538 rdev->config.cayman.num_tile_pipes = (1 << tmp);
539 tmp = (gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT;
540 rdev->config.cayman.mem_max_burst_length_bytes = (tmp + 1) * 256;
541 tmp = (gb_addr_config & NUM_SHADER_ENGINES_MASK) >> NUM_SHADER_ENGINES_SHIFT;
542 rdev->config.cayman.num_shader_engines = tmp + 1;
543 tmp = (gb_addr_config & NUM_GPUS_MASK) >> NUM_GPUS_SHIFT;
544 rdev->config.cayman.num_gpus = tmp + 1;
545 tmp = (gb_addr_config & MULTI_GPU_TILE_SIZE_MASK) >> MULTI_GPU_TILE_SIZE_SHIFT;
546 rdev->config.cayman.multi_gpu_tile_size = 1 << tmp;
547 tmp = (gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT;
548 rdev->config.cayman.mem_row_size_in_kb = 1 << tmp;
549
Alex Deucher416a2bd2012-05-31 19:00:25 -0400550
Alex Deucherfecf1d02011-03-02 20:07:29 -0500551 /* setup tiling info dword. gb_addr_config is not adequate since it does
552 * not have bank info, so create a custom tiling dword.
553 * bits 3:0 num_pipes
554 * bits 7:4 num_banks
555 * bits 11:8 group_size
556 * bits 15:12 row_size
557 */
558 rdev->config.cayman.tile_config = 0;
559 switch (rdev->config.cayman.num_tile_pipes) {
560 case 1:
561 default:
562 rdev->config.cayman.tile_config |= (0 << 0);
563 break;
564 case 2:
565 rdev->config.cayman.tile_config |= (1 << 0);
566 break;
567 case 4:
568 rdev->config.cayman.tile_config |= (2 << 0);
569 break;
570 case 8:
571 rdev->config.cayman.tile_config |= (3 << 0);
572 break;
573 }
Alex Deucher7b76e472012-03-20 17:18:36 -0400574
575 /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */
576 if (rdev->flags & RADEON_IS_IGP)
Alex Deucher1f73cca2012-05-24 22:55:15 -0400577 rdev->config.cayman.tile_config |= 1 << 4;
Alex Deucher29d65402012-05-31 18:53:36 -0400578 else {
Alex Deucher5b23c902012-07-31 11:05:11 -0400579 switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
580 case 0: /* four banks */
Alex Deucher29d65402012-05-31 18:53:36 -0400581 rdev->config.cayman.tile_config |= 0 << 4;
Alex Deucher5b23c902012-07-31 11:05:11 -0400582 break;
583 case 1: /* eight banks */
584 rdev->config.cayman.tile_config |= 1 << 4;
585 break;
586 case 2: /* sixteen banks */
587 default:
588 rdev->config.cayman.tile_config |= 2 << 4;
589 break;
590 }
Alex Deucher29d65402012-05-31 18:53:36 -0400591 }
Alex Deucherfecf1d02011-03-02 20:07:29 -0500592 rdev->config.cayman.tile_config |=
Dave Airliecde50832011-05-19 14:14:41 +1000593 ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500594 rdev->config.cayman.tile_config |=
595 ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
596
Alex Deucher416a2bd2012-05-31 19:00:25 -0400597 tmp = 0;
598 for (i = (rdev->config.cayman.max_shader_engines - 1); i >= 0; i--) {
599 u32 rb_disable_bitmap;
600
601 WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
602 WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
603 rb_disable_bitmap = (RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000) >> 16;
604 tmp <<= 4;
605 tmp |= rb_disable_bitmap;
606 }
607 /* enabled rb are just the one not disabled :) */
608 disabled_rb_mask = tmp;
609
610 WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
611 WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
612
Alex Deucherfecf1d02011-03-02 20:07:29 -0500613 WREG32(GB_ADDR_CONFIG, gb_addr_config);
614 WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
615 WREG32(HDP_ADDR_CONFIG, gb_addr_config);
Alex Deucherf60cbd12012-12-04 15:27:33 -0500616 WREG32(DMA_TILING_CONFIG + DMA0_REGISTER_OFFSET, gb_addr_config);
617 WREG32(DMA_TILING_CONFIG + DMA1_REGISTER_OFFSET, gb_addr_config);
Alex Deucherfecf1d02011-03-02 20:07:29 -0500618
Alex Deucher416a2bd2012-05-31 19:00:25 -0400619 tmp = gb_addr_config & NUM_PIPES_MASK;
620 tmp = r6xx_remap_render_backend(rdev, tmp,
621 rdev->config.cayman.max_backends_per_se *
622 rdev->config.cayman.max_shader_engines,
623 CAYMAN_MAX_BACKENDS, disabled_rb_mask);
624 WREG32(GB_BACKEND_MAP, tmp);
Alex Deucherfecf1d02011-03-02 20:07:29 -0500625
Alex Deucher416a2bd2012-05-31 19:00:25 -0400626 cgts_tcc_disable = 0xffff0000;
627 for (i = 0; i < rdev->config.cayman.max_texture_channel_caches; i++)
628 cgts_tcc_disable &= ~(1 << (16 + i));
Alex Deucherfecf1d02011-03-02 20:07:29 -0500629 WREG32(CGTS_TCC_DISABLE, cgts_tcc_disable);
630 WREG32(CGTS_SYS_TCC_DISABLE, cgts_tcc_disable);
Alex Deucherfecf1d02011-03-02 20:07:29 -0500631 WREG32(CGTS_USER_SYS_TCC_DISABLE, cgts_tcc_disable);
632 WREG32(CGTS_USER_TCC_DISABLE, cgts_tcc_disable);
633
634 /* reprogram the shader complex */
635 cgts_sm_ctrl_reg = RREG32(CGTS_SM_CTRL_REG);
636 for (i = 0; i < 16; i++)
637 WREG32(CGTS_SM_CTRL_REG, OVERRIDE);
638 WREG32(CGTS_SM_CTRL_REG, cgts_sm_ctrl_reg);
639
640 /* set HW defaults for 3D engine */
641 WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
642
643 sx_debug_1 = RREG32(SX_DEBUG_1);
644 sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS;
645 WREG32(SX_DEBUG_1, sx_debug_1);
646
647 smx_dc_ctl0 = RREG32(SMX_DC_CTL0);
648 smx_dc_ctl0 &= ~NUMBER_OF_SETS(0x1ff);
Dave Airlie285e0422011-05-09 14:54:33 +1000649 smx_dc_ctl0 |= NUMBER_OF_SETS(rdev->config.cayman.sx_num_of_sets);
Alex Deucherfecf1d02011-03-02 20:07:29 -0500650 WREG32(SMX_DC_CTL0, smx_dc_ctl0);
651
652 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4) | CRC_SIMD_ID_WADDR_DISABLE);
653
654 /* need to be explicitly zero-ed */
655 WREG32(VGT_OFFCHIP_LDS_BASE, 0);
656 WREG32(SQ_LSTMP_RING_BASE, 0);
657 WREG32(SQ_HSTMP_RING_BASE, 0);
658 WREG32(SQ_ESTMP_RING_BASE, 0);
659 WREG32(SQ_GSTMP_RING_BASE, 0);
660 WREG32(SQ_VSTMP_RING_BASE, 0);
661 WREG32(SQ_PSTMP_RING_BASE, 0);
662
663 WREG32(TA_CNTL_AUX, DISABLE_CUBE_ANISO);
664
Dave Airlie285e0422011-05-09 14:54:33 +1000665 WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.cayman.sx_max_export_size / 4) - 1) |
666 POSITION_BUFFER_SIZE((rdev->config.cayman.sx_max_export_pos_size / 4) - 1) |
667 SMX_BUFFER_SIZE((rdev->config.cayman.sx_max_export_smx_size / 4) - 1)));
Alex Deucherfecf1d02011-03-02 20:07:29 -0500668
Dave Airlie285e0422011-05-09 14:54:33 +1000669 WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.cayman.sc_prim_fifo_size) |
670 SC_HIZ_TILE_FIFO_SIZE(rdev->config.cayman.sc_hiz_tile_fifo_size) |
671 SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.cayman.sc_earlyz_tile_fifo_size)));
Alex Deucherfecf1d02011-03-02 20:07:29 -0500672
673
674 WREG32(VGT_NUM_INSTANCES, 1);
675
676 WREG32(CP_PERFMON_CNTL, 0);
677
Dave Airlie285e0422011-05-09 14:54:33 +1000678 WREG32(SQ_MS_FIFO_SIZES, (CACHE_FIFO_SIZE(16 * rdev->config.cayman.sq_num_cf_insts) |
Alex Deucherfecf1d02011-03-02 20:07:29 -0500679 FETCH_FIFO_HIWATER(0x4) |
680 DONE_FIFO_HIWATER(0xe0) |
681 ALU_UPDATE_FIFO_HIWATER(0x8)));
682
683 WREG32(SQ_GPR_RESOURCE_MGMT_1, NUM_CLAUSE_TEMP_GPRS(4));
684 WREG32(SQ_CONFIG, (VC_ENABLE |
685 EXPORT_SRC_C |
686 GFX_PRIO(0) |
687 CS1_PRIO(0) |
688 CS2_PRIO(1)));
689 WREG32(SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, DYN_GPR_ENABLE);
690
691 WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
692 FORCE_EOV_MAX_REZ_CNT(255)));
693
694 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
695 AUTO_INVLD_EN(ES_AND_GS_AUTO));
696
697 WREG32(VGT_GS_VERTEX_REUSE, 16);
698 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
699
700 WREG32(CB_PERF_CTR0_SEL_0, 0);
701 WREG32(CB_PERF_CTR0_SEL_1, 0);
702 WREG32(CB_PERF_CTR1_SEL_0, 0);
703 WREG32(CB_PERF_CTR1_SEL_1, 0);
704 WREG32(CB_PERF_CTR2_SEL_0, 0);
705 WREG32(CB_PERF_CTR2_SEL_1, 0);
706 WREG32(CB_PERF_CTR3_SEL_0, 0);
707 WREG32(CB_PERF_CTR3_SEL_1, 0);
708
Dave Airlie0b65f832011-05-19 14:14:42 +1000709 tmp = RREG32(HDP_MISC_CNTL);
710 tmp |= HDP_FLUSH_INVALIDATE_CACHE;
711 WREG32(HDP_MISC_CNTL, tmp);
712
Alex Deucherfecf1d02011-03-02 20:07:29 -0500713 hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
714 WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
715
716 WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
717
718 udelay(50);
719}
720
Alex Deucherfa8198e2011-03-02 20:07:30 -0500721/*
722 * GART
723 */
724void cayman_pcie_gart_tlb_flush(struct radeon_device *rdev)
725{
726 /* flush hdp cache */
727 WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
728
729 /* bits 0-7 are the VM contexts0-7 */
730 WREG32(VM_INVALIDATE_REQUEST, 1);
731}
732
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400733static int cayman_pcie_gart_enable(struct radeon_device *rdev)
Alex Deucherfa8198e2011-03-02 20:07:30 -0500734{
Jerome Glisse721604a2012-01-05 22:11:05 -0500735 int i, r;
Alex Deucherfa8198e2011-03-02 20:07:30 -0500736
Jerome Glissec9a1be92011-11-03 11:16:49 -0400737 if (rdev->gart.robj == NULL) {
Alex Deucherfa8198e2011-03-02 20:07:30 -0500738 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
739 return -EINVAL;
740 }
741 r = radeon_gart_table_vram_pin(rdev);
742 if (r)
743 return r;
744 radeon_gart_restore(rdev);
745 /* Setup TLB control */
Jerome Glisse721604a2012-01-05 22:11:05 -0500746 WREG32(MC_VM_MX_L1_TLB_CNTL,
747 (0xA << 7) |
748 ENABLE_L1_TLB |
Alex Deucherfa8198e2011-03-02 20:07:30 -0500749 ENABLE_L1_FRAGMENT_PROCESSING |
750 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
Jerome Glisse721604a2012-01-05 22:11:05 -0500751 ENABLE_ADVANCED_DRIVER_MODEL |
Alex Deucherfa8198e2011-03-02 20:07:30 -0500752 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
753 /* Setup L2 cache */
754 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
755 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
756 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
757 EFFECTIVE_L2_QUEUE_SIZE(7) |
758 CONTEXT1_IDENTITY_ACCESS_MODE(1));
759 WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
760 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
761 L2_CACHE_BIGK_FRAGMENT_SIZE(6));
762 /* setup context0 */
763 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
764 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
765 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
766 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
767 (u32)(rdev->dummy_page.addr >> 12));
768 WREG32(VM_CONTEXT0_CNTL2, 0);
769 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
770 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
Jerome Glisse721604a2012-01-05 22:11:05 -0500771
772 WREG32(0x15D4, 0);
773 WREG32(0x15D8, 0);
774 WREG32(0x15DC, 0);
775
776 /* empty context1-7 */
Alex Deucher23d4f1f2012-10-08 09:45:46 -0400777 /* Assign the pt base to something valid for now; the pts used for
778 * the VMs are determined by the application and setup and assigned
779 * on the fly in the vm part of radeon_gart.c
780 */
Jerome Glisse721604a2012-01-05 22:11:05 -0500781 for (i = 1; i < 8; i++) {
782 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR + (i << 2), 0);
Alex Deucherc1a7ca02012-10-08 12:15:13 -0400783 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR + (i << 2), rdev->vm_manager.max_pfn);
Jerome Glisse721604a2012-01-05 22:11:05 -0500784 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
785 rdev->gart.table_addr >> 12);
786 }
787
788 /* enable context1-7 */
789 WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
790 (u32)(rdev->dummy_page.addr >> 12));
Christian Königae133a12012-09-18 15:30:44 -0400791 WREG32(VM_CONTEXT1_CNTL2, 4);
Dmitry Cherkasovfa87e622012-09-17 19:36:19 +0200792 WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
Christian Königae133a12012-09-18 15:30:44 -0400793 RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
794 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
795 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
796 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
797 PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
798 PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
799 VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
800 VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
801 READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
802 READ_PROTECTION_FAULT_ENABLE_DEFAULT |
803 WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
804 WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
Alex Deucherfa8198e2011-03-02 20:07:30 -0500805
806 cayman_pcie_gart_tlb_flush(rdev);
Tormod Voldenfcf4de52011-08-31 21:54:07 +0000807 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
808 (unsigned)(rdev->mc.gtt_size >> 20),
809 (unsigned long long)rdev->gart.table_addr);
Alex Deucherfa8198e2011-03-02 20:07:30 -0500810 rdev->gart.ready = true;
811 return 0;
812}
813
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400814static void cayman_pcie_gart_disable(struct radeon_device *rdev)
Alex Deucherfa8198e2011-03-02 20:07:30 -0500815{
Alex Deucherfa8198e2011-03-02 20:07:30 -0500816 /* Disable all tables */
817 WREG32(VM_CONTEXT0_CNTL, 0);
818 WREG32(VM_CONTEXT1_CNTL, 0);
819 /* Setup TLB control */
820 WREG32(MC_VM_MX_L1_TLB_CNTL, ENABLE_L1_FRAGMENT_PROCESSING |
821 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
822 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
823 /* Setup L2 cache */
824 WREG32(VM_L2_CNTL, ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
825 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
826 EFFECTIVE_L2_QUEUE_SIZE(7) |
827 CONTEXT1_IDENTITY_ACCESS_MODE(1));
828 WREG32(VM_L2_CNTL2, 0);
829 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
830 L2_CACHE_BIGK_FRAGMENT_SIZE(6));
Jerome Glissec9a1be92011-11-03 11:16:49 -0400831 radeon_gart_table_vram_unpin(rdev);
Alex Deucherfa8198e2011-03-02 20:07:30 -0500832}
833
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400834static void cayman_pcie_gart_fini(struct radeon_device *rdev)
Alex Deucherfa8198e2011-03-02 20:07:30 -0500835{
836 cayman_pcie_gart_disable(rdev);
837 radeon_gart_table_vram_free(rdev);
838 radeon_gart_fini(rdev);
839}
840
Alex Deucher1b370782011-11-17 20:13:28 -0500841void cayman_cp_int_cntl_setup(struct radeon_device *rdev,
842 int ring, u32 cp_int_cntl)
843{
844 u32 srbm_gfx_cntl = RREG32(SRBM_GFX_CNTL) & ~3;
845
846 WREG32(SRBM_GFX_CNTL, srbm_gfx_cntl | (ring & 3));
847 WREG32(CP_INT_CNTL, cp_int_cntl);
848}
849
Alex Deucher0c88a022011-03-02 20:07:31 -0500850/*
851 * CP.
852 */
Alex Deucherb40e7e12011-11-17 14:57:50 -0500853void cayman_fence_ring_emit(struct radeon_device *rdev,
854 struct radeon_fence *fence)
855{
856 struct radeon_ring *ring = &rdev->ring[fence->ring];
857 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
858
Jerome Glisse721604a2012-01-05 22:11:05 -0500859 /* flush read cache over gart for this vmid */
860 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
861 radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
862 radeon_ring_write(ring, 0);
Alex Deucherb40e7e12011-11-17 14:57:50 -0500863 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
864 radeon_ring_write(ring, PACKET3_TC_ACTION_ENA | PACKET3_SH_ACTION_ENA);
865 radeon_ring_write(ring, 0xFFFFFFFF);
866 radeon_ring_write(ring, 0);
867 radeon_ring_write(ring, 10); /* poll interval */
868 /* EVENT_WRITE_EOP - flush caches, send int */
869 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
870 radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5));
871 radeon_ring_write(ring, addr & 0xffffffff);
872 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
873 radeon_ring_write(ring, fence->seq);
874 radeon_ring_write(ring, 0);
875}
876
Jerome Glisse721604a2012-01-05 22:11:05 -0500877void cayman_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
878{
Christian König876dc9f2012-05-08 14:24:01 +0200879 struct radeon_ring *ring = &rdev->ring[ib->ring];
Jerome Glisse721604a2012-01-05 22:11:05 -0500880
881 /* set to DX10/11 mode */
882 radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0));
883 radeon_ring_write(ring, 1);
Christian König45df6802012-07-06 16:22:55 +0200884
885 if (ring->rptr_save_reg) {
886 uint32_t next_rptr = ring->wptr + 3 + 4 + 8;
887 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
888 radeon_ring_write(ring, ((ring->rptr_save_reg -
889 PACKET3_SET_CONFIG_REG_START) >> 2));
890 radeon_ring_write(ring, next_rptr);
891 }
892
Jerome Glisse721604a2012-01-05 22:11:05 -0500893 radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
894 radeon_ring_write(ring,
895#ifdef __BIG_ENDIAN
896 (2 << 0) |
897#endif
898 (ib->gpu_addr & 0xFFFFFFFC));
899 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
Christian König4bf3dd92012-08-06 18:57:44 +0200900 radeon_ring_write(ring, ib->length_dw |
901 (ib->vm ? (ib->vm->id << 24) : 0));
Jerome Glisse721604a2012-01-05 22:11:05 -0500902
903 /* flush read cache over gart for this vmid */
904 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
905 radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
Christian König4bf3dd92012-08-06 18:57:44 +0200906 radeon_ring_write(ring, ib->vm ? ib->vm->id : 0);
Jerome Glisse721604a2012-01-05 22:11:05 -0500907 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
908 radeon_ring_write(ring, PACKET3_TC_ACTION_ENA | PACKET3_SH_ACTION_ENA);
909 radeon_ring_write(ring, 0xFFFFFFFF);
910 radeon_ring_write(ring, 0);
911 radeon_ring_write(ring, 10); /* poll interval */
912}
913
Alex Deucher0c88a022011-03-02 20:07:31 -0500914static void cayman_cp_enable(struct radeon_device *rdev, bool enable)
915{
916 if (enable)
917 WREG32(CP_ME_CNTL, 0);
918 else {
Dave Airlie38f1cff2011-03-16 11:34:41 +1000919 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
Alex Deucher0c88a022011-03-02 20:07:31 -0500920 WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT));
921 WREG32(SCRATCH_UMSK, 0);
Alex Deucherf60cbd12012-12-04 15:27:33 -0500922 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
Alex Deucher0c88a022011-03-02 20:07:31 -0500923 }
924}
925
926static int cayman_cp_load_microcode(struct radeon_device *rdev)
927{
928 const __be32 *fw_data;
929 int i;
930
931 if (!rdev->me_fw || !rdev->pfp_fw)
932 return -EINVAL;
933
934 cayman_cp_enable(rdev, false);
935
936 fw_data = (const __be32 *)rdev->pfp_fw->data;
937 WREG32(CP_PFP_UCODE_ADDR, 0);
938 for (i = 0; i < CAYMAN_PFP_UCODE_SIZE; i++)
939 WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
940 WREG32(CP_PFP_UCODE_ADDR, 0);
941
942 fw_data = (const __be32 *)rdev->me_fw->data;
943 WREG32(CP_ME_RAM_WADDR, 0);
944 for (i = 0; i < CAYMAN_PM4_UCODE_SIZE; i++)
945 WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
946
947 WREG32(CP_PFP_UCODE_ADDR, 0);
948 WREG32(CP_ME_RAM_WADDR, 0);
949 WREG32(CP_ME_RAM_RADDR, 0);
950 return 0;
951}
952
953static int cayman_cp_start(struct radeon_device *rdev)
954{
Christian Könige32eb502011-10-23 12:56:27 +0200955 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucher0c88a022011-03-02 20:07:31 -0500956 int r, i;
957
Christian Könige32eb502011-10-23 12:56:27 +0200958 r = radeon_ring_lock(rdev, ring, 7);
Alex Deucher0c88a022011-03-02 20:07:31 -0500959 if (r) {
960 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
961 return r;
962 }
Christian Könige32eb502011-10-23 12:56:27 +0200963 radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
964 radeon_ring_write(ring, 0x1);
965 radeon_ring_write(ring, 0x0);
966 radeon_ring_write(ring, rdev->config.cayman.max_hw_contexts - 1);
967 radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
968 radeon_ring_write(ring, 0);
969 radeon_ring_write(ring, 0);
970 radeon_ring_unlock_commit(rdev, ring);
Alex Deucher0c88a022011-03-02 20:07:31 -0500971
972 cayman_cp_enable(rdev, true);
973
Christian Könige32eb502011-10-23 12:56:27 +0200974 r = radeon_ring_lock(rdev, ring, cayman_default_size + 19);
Alex Deucher0c88a022011-03-02 20:07:31 -0500975 if (r) {
976 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
977 return r;
978 }
979
980 /* setup clear context state */
Christian Könige32eb502011-10-23 12:56:27 +0200981 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
982 radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
Alex Deucher0c88a022011-03-02 20:07:31 -0500983
984 for (i = 0; i < cayman_default_size; i++)
Christian Könige32eb502011-10-23 12:56:27 +0200985 radeon_ring_write(ring, cayman_default_state[i]);
Alex Deucher0c88a022011-03-02 20:07:31 -0500986
Christian Könige32eb502011-10-23 12:56:27 +0200987 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
988 radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
Alex Deucher0c88a022011-03-02 20:07:31 -0500989
990 /* set clear context state */
Christian Könige32eb502011-10-23 12:56:27 +0200991 radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
992 radeon_ring_write(ring, 0);
Alex Deucher0c88a022011-03-02 20:07:31 -0500993
994 /* SQ_VTX_BASE_VTX_LOC */
Christian Könige32eb502011-10-23 12:56:27 +0200995 radeon_ring_write(ring, 0xc0026f00);
996 radeon_ring_write(ring, 0x00000000);
997 radeon_ring_write(ring, 0x00000000);
998 radeon_ring_write(ring, 0x00000000);
Alex Deucher0c88a022011-03-02 20:07:31 -0500999
1000 /* Clear consts */
Christian Könige32eb502011-10-23 12:56:27 +02001001 radeon_ring_write(ring, 0xc0036f00);
1002 radeon_ring_write(ring, 0x00000bc4);
1003 radeon_ring_write(ring, 0xffffffff);
1004 radeon_ring_write(ring, 0xffffffff);
1005 radeon_ring_write(ring, 0xffffffff);
Alex Deucher0c88a022011-03-02 20:07:31 -05001006
Christian Könige32eb502011-10-23 12:56:27 +02001007 radeon_ring_write(ring, 0xc0026900);
1008 radeon_ring_write(ring, 0x00000316);
1009 radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
1010 radeon_ring_write(ring, 0x00000010); /* */
Alex Deucher9b91d182011-03-02 20:07:39 -05001011
Christian Könige32eb502011-10-23 12:56:27 +02001012 radeon_ring_unlock_commit(rdev, ring);
Alex Deucher0c88a022011-03-02 20:07:31 -05001013
1014 /* XXX init other rings */
1015
1016 return 0;
1017}
1018
Alex Deucher755d8192011-03-02 20:07:34 -05001019static void cayman_cp_fini(struct radeon_device *rdev)
1020{
Christian König45df6802012-07-06 16:22:55 +02001021 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucher755d8192011-03-02 20:07:34 -05001022 cayman_cp_enable(rdev, false);
Christian König45df6802012-07-06 16:22:55 +02001023 radeon_ring_fini(rdev, ring);
1024 radeon_scratch_free(rdev, ring->rptr_save_reg);
Alex Deucher755d8192011-03-02 20:07:34 -05001025}
1026
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001027static int cayman_cp_resume(struct radeon_device *rdev)
Alex Deucher0c88a022011-03-02 20:07:31 -05001028{
Christian Königb90ca982012-07-04 21:36:53 +02001029 static const int ridx[] = {
1030 RADEON_RING_TYPE_GFX_INDEX,
1031 CAYMAN_RING_TYPE_CP1_INDEX,
1032 CAYMAN_RING_TYPE_CP2_INDEX
1033 };
1034 static const unsigned cp_rb_cntl[] = {
1035 CP_RB0_CNTL,
1036 CP_RB1_CNTL,
1037 CP_RB2_CNTL,
1038 };
1039 static const unsigned cp_rb_rptr_addr[] = {
1040 CP_RB0_RPTR_ADDR,
1041 CP_RB1_RPTR_ADDR,
1042 CP_RB2_RPTR_ADDR
1043 };
1044 static const unsigned cp_rb_rptr_addr_hi[] = {
1045 CP_RB0_RPTR_ADDR_HI,
1046 CP_RB1_RPTR_ADDR_HI,
1047 CP_RB2_RPTR_ADDR_HI
1048 };
1049 static const unsigned cp_rb_base[] = {
1050 CP_RB0_BASE,
1051 CP_RB1_BASE,
1052 CP_RB2_BASE
1053 };
Christian Könige32eb502011-10-23 12:56:27 +02001054 struct radeon_ring *ring;
Christian Königb90ca982012-07-04 21:36:53 +02001055 int i, r;
Alex Deucher0c88a022011-03-02 20:07:31 -05001056
1057 /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */
1058 WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP |
1059 SOFT_RESET_PA |
1060 SOFT_RESET_SH |
1061 SOFT_RESET_VGT |
Jerome Glissea49a50d2011-08-24 20:00:17 +00001062 SOFT_RESET_SPI |
Alex Deucher0c88a022011-03-02 20:07:31 -05001063 SOFT_RESET_SX));
1064 RREG32(GRBM_SOFT_RESET);
1065 mdelay(15);
1066 WREG32(GRBM_SOFT_RESET, 0);
1067 RREG32(GRBM_SOFT_RESET);
1068
Christian König15d33322011-09-15 19:02:22 +02001069 WREG32(CP_SEM_WAIT_TIMER, 0x0);
Alex Deucher11ef3f1f2012-01-20 14:47:43 -05001070 WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
Alex Deucher0c88a022011-03-02 20:07:31 -05001071
1072 /* Set the write pointer delay */
1073 WREG32(CP_RB_WPTR_DELAY, 0);
1074
1075 WREG32(CP_DEBUG, (1 << 27));
1076
Adam Buchbinder48fc7f72012-09-19 21:48:00 -04001077 /* set the wb address whether it's enabled or not */
Alex Deucher0c88a022011-03-02 20:07:31 -05001078 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
Christian Königb90ca982012-07-04 21:36:53 +02001079 WREG32(SCRATCH_UMSK, 0xff);
Alex Deucher0c88a022011-03-02 20:07:31 -05001080
Christian Königb90ca982012-07-04 21:36:53 +02001081 for (i = 0; i < 3; ++i) {
1082 uint32_t rb_cntl;
1083 uint64_t addr;
1084
1085 /* Set ring buffer size */
1086 ring = &rdev->ring[ridx[i]];
1087 rb_cntl = drm_order(ring->ring_size / 8);
1088 rb_cntl |= drm_order(RADEON_GPU_PAGE_SIZE/8) << 8;
1089#ifdef __BIG_ENDIAN
1090 rb_cntl |= BUF_SWAP_32BIT;
1091#endif
1092 WREG32(cp_rb_cntl[i], rb_cntl);
1093
Adam Buchbinder48fc7f72012-09-19 21:48:00 -04001094 /* set the wb address whether it's enabled or not */
Christian Königb90ca982012-07-04 21:36:53 +02001095 addr = rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET;
1096 WREG32(cp_rb_rptr_addr[i], addr & 0xFFFFFFFC);
1097 WREG32(cp_rb_rptr_addr_hi[i], upper_32_bits(addr) & 0xFF);
Alex Deucher0c88a022011-03-02 20:07:31 -05001098 }
1099
Christian Königb90ca982012-07-04 21:36:53 +02001100 /* set the rb base addr, this causes an internal reset of ALL rings */
1101 for (i = 0; i < 3; ++i) {
1102 ring = &rdev->ring[ridx[i]];
1103 WREG32(cp_rb_base[i], ring->gpu_addr >> 8);
1104 }
Alex Deucher0c88a022011-03-02 20:07:31 -05001105
Christian Königb90ca982012-07-04 21:36:53 +02001106 for (i = 0; i < 3; ++i) {
1107 /* Initialize the ring buffer's read and write pointers */
1108 ring = &rdev->ring[ridx[i]];
1109 WREG32_P(cp_rb_cntl[i], RB_RPTR_WR_ENA, ~RB_RPTR_WR_ENA);
Alex Deucher0c88a022011-03-02 20:07:31 -05001110
Christian Königb90ca982012-07-04 21:36:53 +02001111 ring->rptr = ring->wptr = 0;
1112 WREG32(ring->rptr_reg, ring->rptr);
1113 WREG32(ring->wptr_reg, ring->wptr);
Alex Deucher0c88a022011-03-02 20:07:31 -05001114
Christian Königb90ca982012-07-04 21:36:53 +02001115 mdelay(1);
1116 WREG32_P(cp_rb_cntl[i], 0, ~RB_RPTR_WR_ENA);
1117 }
Alex Deucher0c88a022011-03-02 20:07:31 -05001118
1119 /* start the rings */
1120 cayman_cp_start(rdev);
Christian Könige32eb502011-10-23 12:56:27 +02001121 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
1122 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
1123 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
Alex Deucher0c88a022011-03-02 20:07:31 -05001124 /* this only test cp0 */
Alex Deucherf7128122012-02-23 17:53:45 -05001125 r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
Alex Deucher0c88a022011-03-02 20:07:31 -05001126 if (r) {
Christian Könige32eb502011-10-23 12:56:27 +02001127 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
1128 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
1129 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
Alex Deucher0c88a022011-03-02 20:07:31 -05001130 return r;
1131 }
1132
1133 return 0;
1134}
1135
Alex Deucherf60cbd12012-12-04 15:27:33 -05001136/*
1137 * DMA
1138 * Starting with R600, the GPU has an asynchronous
1139 * DMA engine. The programming model is very similar
1140 * to the 3D engine (ring buffer, IBs, etc.), but the
1141 * DMA controller has it's own packet format that is
1142 * different form the PM4 format used by the 3D engine.
1143 * It supports copying data, writing embedded data,
1144 * solid fills, and a number of other things. It also
1145 * has support for tiling/detiling of buffers.
1146 * Cayman and newer support two asynchronous DMA engines.
1147 */
1148/**
1149 * cayman_dma_ring_ib_execute - Schedule an IB on the DMA engine
1150 *
1151 * @rdev: radeon_device pointer
1152 * @ib: IB object to schedule
1153 *
1154 * Schedule an IB in the DMA ring (cayman-SI).
1155 */
1156void cayman_dma_ring_ib_execute(struct radeon_device *rdev,
1157 struct radeon_ib *ib)
1158{
1159 struct radeon_ring *ring = &rdev->ring[ib->ring];
1160
1161 if (rdev->wb.enabled) {
1162 u32 next_rptr = ring->wptr + 4;
1163 while ((next_rptr & 7) != 5)
1164 next_rptr++;
1165 next_rptr += 3;
1166 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 1));
1167 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
1168 radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xff);
1169 radeon_ring_write(ring, next_rptr);
1170 }
1171
1172 /* The indirect buffer packet must end on an 8 DW boundary in the DMA ring.
1173 * Pad as necessary with NOPs.
1174 */
1175 while ((ring->wptr & 7) != 5)
1176 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
1177 radeon_ring_write(ring, DMA_IB_PACKET(DMA_PACKET_INDIRECT_BUFFER, ib->vm ? ib->vm->id : 0, 0));
1178 radeon_ring_write(ring, (ib->gpu_addr & 0xFFFFFFE0));
1179 radeon_ring_write(ring, (ib->length_dw << 12) | (upper_32_bits(ib->gpu_addr) & 0xFF));
1180
1181}
1182
1183/**
1184 * cayman_dma_stop - stop the async dma engines
1185 *
1186 * @rdev: radeon_device pointer
1187 *
1188 * Stop the async dma engines (cayman-SI).
1189 */
1190void cayman_dma_stop(struct radeon_device *rdev)
1191{
1192 u32 rb_cntl;
1193
1194 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
1195
1196 /* dma0 */
1197 rb_cntl = RREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET);
1198 rb_cntl &= ~DMA_RB_ENABLE;
1199 WREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET, rb_cntl);
1200
1201 /* dma1 */
1202 rb_cntl = RREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET);
1203 rb_cntl &= ~DMA_RB_ENABLE;
1204 WREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET, rb_cntl);
1205
1206 rdev->ring[R600_RING_TYPE_DMA_INDEX].ready = false;
1207 rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX].ready = false;
1208}
1209
1210/**
1211 * cayman_dma_resume - setup and start the async dma engines
1212 *
1213 * @rdev: radeon_device pointer
1214 *
1215 * Set up the DMA ring buffers and enable them. (cayman-SI).
1216 * Returns 0 for success, error for failure.
1217 */
1218int cayman_dma_resume(struct radeon_device *rdev)
1219{
1220 struct radeon_ring *ring;
Michel Dänzerb3dfcb22013-01-24 19:02:01 +01001221 u32 rb_cntl, dma_cntl, ib_cntl;
Alex Deucherf60cbd12012-12-04 15:27:33 -05001222 u32 rb_bufsz;
1223 u32 reg_offset, wb_offset;
1224 int i, r;
1225
1226 /* Reset dma */
1227 WREG32(SRBM_SOFT_RESET, SOFT_RESET_DMA | SOFT_RESET_DMA1);
1228 RREG32(SRBM_SOFT_RESET);
1229 udelay(50);
1230 WREG32(SRBM_SOFT_RESET, 0);
1231
1232 for (i = 0; i < 2; i++) {
1233 if (i == 0) {
1234 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
1235 reg_offset = DMA0_REGISTER_OFFSET;
1236 wb_offset = R600_WB_DMA_RPTR_OFFSET;
1237 } else {
1238 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
1239 reg_offset = DMA1_REGISTER_OFFSET;
1240 wb_offset = CAYMAN_WB_DMA1_RPTR_OFFSET;
1241 }
1242
1243 WREG32(DMA_SEM_INCOMPLETE_TIMER_CNTL + reg_offset, 0);
1244 WREG32(DMA_SEM_WAIT_FAIL_TIMER_CNTL + reg_offset, 0);
1245
1246 /* Set ring buffer size in dwords */
1247 rb_bufsz = drm_order(ring->ring_size / 4);
1248 rb_cntl = rb_bufsz << 1;
1249#ifdef __BIG_ENDIAN
1250 rb_cntl |= DMA_RB_SWAP_ENABLE | DMA_RPTR_WRITEBACK_SWAP_ENABLE;
1251#endif
1252 WREG32(DMA_RB_CNTL + reg_offset, rb_cntl);
1253
1254 /* Initialize the ring buffer's read and write pointers */
1255 WREG32(DMA_RB_RPTR + reg_offset, 0);
1256 WREG32(DMA_RB_WPTR + reg_offset, 0);
1257
1258 /* set the wb address whether it's enabled or not */
1259 WREG32(DMA_RB_RPTR_ADDR_HI + reg_offset,
1260 upper_32_bits(rdev->wb.gpu_addr + wb_offset) & 0xFF);
1261 WREG32(DMA_RB_RPTR_ADDR_LO + reg_offset,
1262 ((rdev->wb.gpu_addr + wb_offset) & 0xFFFFFFFC));
1263
1264 if (rdev->wb.enabled)
1265 rb_cntl |= DMA_RPTR_WRITEBACK_ENABLE;
1266
1267 WREG32(DMA_RB_BASE + reg_offset, ring->gpu_addr >> 8);
1268
1269 /* enable DMA IBs */
Michel Dänzerb3dfcb22013-01-24 19:02:01 +01001270 ib_cntl = DMA_IB_ENABLE | CMD_VMID_FORCE;
1271#ifdef __BIG_ENDIAN
1272 ib_cntl |= DMA_IB_SWAP_ENABLE;
1273#endif
1274 WREG32(DMA_IB_CNTL + reg_offset, ib_cntl);
Alex Deucherf60cbd12012-12-04 15:27:33 -05001275
1276 dma_cntl = RREG32(DMA_CNTL + reg_offset);
1277 dma_cntl &= ~CTXEMPTY_INT_ENABLE;
1278 WREG32(DMA_CNTL + reg_offset, dma_cntl);
1279
1280 ring->wptr = 0;
1281 WREG32(DMA_RB_WPTR + reg_offset, ring->wptr << 2);
1282
1283 ring->rptr = RREG32(DMA_RB_RPTR + reg_offset) >> 2;
1284
1285 WREG32(DMA_RB_CNTL + reg_offset, rb_cntl | DMA_RB_ENABLE);
1286
1287 ring->ready = true;
1288
1289 r = radeon_ring_test(rdev, ring->idx, ring);
1290 if (r) {
1291 ring->ready = false;
1292 return r;
1293 }
1294 }
1295
1296 radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
1297
1298 return 0;
1299}
1300
1301/**
1302 * cayman_dma_fini - tear down the async dma engines
1303 *
1304 * @rdev: radeon_device pointer
1305 *
1306 * Stop the async dma engines and free the rings (cayman-SI).
1307 */
1308void cayman_dma_fini(struct radeon_device *rdev)
1309{
1310 cayman_dma_stop(rdev);
1311 radeon_ring_fini(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX]);
1312 radeon_ring_fini(rdev, &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX]);
1313}
1314
Alex Deucher168757e2013-01-18 19:17:22 -05001315static u32 cayman_gpu_check_soft_reset(struct radeon_device *rdev)
1316{
1317 u32 reset_mask = 0;
1318 u32 tmp;
1319
1320 /* GRBM_STATUS */
1321 tmp = RREG32(GRBM_STATUS);
1322 if (tmp & (PA_BUSY | SC_BUSY |
1323 SH_BUSY | SX_BUSY |
1324 TA_BUSY | VGT_BUSY |
1325 DB_BUSY | CB_BUSY |
1326 GDS_BUSY | SPI_BUSY |
1327 IA_BUSY | IA_BUSY_NO_DMA))
1328 reset_mask |= RADEON_RESET_GFX;
1329
1330 if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
1331 CP_BUSY | CP_COHERENCY_BUSY))
1332 reset_mask |= RADEON_RESET_CP;
1333
1334 if (tmp & GRBM_EE_BUSY)
1335 reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
1336
1337 /* DMA_STATUS_REG 0 */
1338 tmp = RREG32(DMA_STATUS_REG + DMA0_REGISTER_OFFSET);
1339 if (!(tmp & DMA_IDLE))
1340 reset_mask |= RADEON_RESET_DMA;
1341
1342 /* DMA_STATUS_REG 1 */
1343 tmp = RREG32(DMA_STATUS_REG + DMA1_REGISTER_OFFSET);
1344 if (!(tmp & DMA_IDLE))
1345 reset_mask |= RADEON_RESET_DMA1;
1346
1347 /* SRBM_STATUS2 */
1348 tmp = RREG32(SRBM_STATUS2);
1349 if (tmp & DMA_BUSY)
1350 reset_mask |= RADEON_RESET_DMA;
1351
1352 if (tmp & DMA1_BUSY)
1353 reset_mask |= RADEON_RESET_DMA1;
1354
1355 /* SRBM_STATUS */
1356 tmp = RREG32(SRBM_STATUS);
1357 if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
1358 reset_mask |= RADEON_RESET_RLC;
1359
1360 if (tmp & IH_BUSY)
1361 reset_mask |= RADEON_RESET_IH;
1362
1363 if (tmp & SEM_BUSY)
1364 reset_mask |= RADEON_RESET_SEM;
1365
1366 if (tmp & GRBM_RQ_PENDING)
1367 reset_mask |= RADEON_RESET_GRBM;
1368
1369 if (tmp & VMC_BUSY)
1370 reset_mask |= RADEON_RESET_VMC;
1371
1372 if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
1373 MCC_BUSY | MCD_BUSY))
1374 reset_mask |= RADEON_RESET_MC;
1375
1376 if (evergreen_is_display_hung(rdev))
1377 reset_mask |= RADEON_RESET_DISPLAY;
1378
1379 /* VM_L2_STATUS */
1380 tmp = RREG32(VM_L2_STATUS);
1381 if (tmp & L2_BUSY)
1382 reset_mask |= RADEON_RESET_VMC;
1383
Alex Deucherd808fc82013-02-28 10:03:08 -05001384 /* Skip MC reset as it's mostly likely not hung, just busy */
1385 if (reset_mask & RADEON_RESET_MC) {
1386 DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
1387 reset_mask &= ~RADEON_RESET_MC;
1388 }
1389
Alex Deucher168757e2013-01-18 19:17:22 -05001390 return reset_mask;
1391}
1392
1393static void cayman_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
Alex Deucher271d6fed2013-01-03 12:48:05 -05001394{
1395 struct evergreen_mc_save save;
Alex Deucher187e3592013-01-18 14:51:38 -05001396 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
1397 u32 tmp;
Alex Deucher19fc42e2013-01-14 11:04:39 -05001398
Alex Deucher271d6fed2013-01-03 12:48:05 -05001399 if (reset_mask == 0)
Alex Deucher168757e2013-01-18 19:17:22 -05001400 return;
Alex Deucher271d6fed2013-01-03 12:48:05 -05001401
1402 dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
1403
Alex Deucher187e3592013-01-18 14:51:38 -05001404 evergreen_print_gpu_status_regs(rdev);
Alex Deucher271d6fed2013-01-03 12:48:05 -05001405 dev_info(rdev->dev, " VM_CONTEXT0_PROTECTION_FAULT_ADDR 0x%08X\n",
1406 RREG32(0x14F8));
1407 dev_info(rdev->dev, " VM_CONTEXT0_PROTECTION_FAULT_STATUS 0x%08X\n",
1408 RREG32(0x14D8));
1409 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
1410 RREG32(0x14FC));
1411 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
1412 RREG32(0x14DC));
1413
Alex Deucher187e3592013-01-18 14:51:38 -05001414 /* Disable CP parsing/prefetching */
1415 WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT);
1416
1417 if (reset_mask & RADEON_RESET_DMA) {
1418 /* dma0 */
1419 tmp = RREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET);
1420 tmp &= ~DMA_RB_ENABLE;
1421 WREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET, tmp);
Alex Deucher168757e2013-01-18 19:17:22 -05001422 }
Alex Deucher187e3592013-01-18 14:51:38 -05001423
Alex Deucher168757e2013-01-18 19:17:22 -05001424 if (reset_mask & RADEON_RESET_DMA1) {
Alex Deucher187e3592013-01-18 14:51:38 -05001425 /* dma1 */
1426 tmp = RREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET);
1427 tmp &= ~DMA_RB_ENABLE;
1428 WREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET, tmp);
1429 }
1430
Alex Deucher90fb8772013-01-23 18:59:17 -05001431 udelay(50);
1432
1433 evergreen_mc_stop(rdev, &save);
1434 if (evergreen_mc_wait_for_idle(rdev)) {
1435 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
1436 }
1437
Alex Deucher187e3592013-01-18 14:51:38 -05001438 if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE)) {
1439 grbm_soft_reset = SOFT_RESET_CB |
1440 SOFT_RESET_DB |
1441 SOFT_RESET_GDS |
1442 SOFT_RESET_PA |
1443 SOFT_RESET_SC |
1444 SOFT_RESET_SPI |
1445 SOFT_RESET_SH |
1446 SOFT_RESET_SX |
1447 SOFT_RESET_TC |
1448 SOFT_RESET_TA |
1449 SOFT_RESET_VGT |
1450 SOFT_RESET_IA;
1451 }
1452
1453 if (reset_mask & RADEON_RESET_CP) {
1454 grbm_soft_reset |= SOFT_RESET_CP | SOFT_RESET_VGT;
1455
1456 srbm_soft_reset |= SOFT_RESET_GRBM;
1457 }
Alex Deucher271d6fed2013-01-03 12:48:05 -05001458
1459 if (reset_mask & RADEON_RESET_DMA)
Alex Deucher168757e2013-01-18 19:17:22 -05001460 srbm_soft_reset |= SOFT_RESET_DMA;
1461
1462 if (reset_mask & RADEON_RESET_DMA1)
1463 srbm_soft_reset |= SOFT_RESET_DMA1;
1464
1465 if (reset_mask & RADEON_RESET_DISPLAY)
1466 srbm_soft_reset |= SOFT_RESET_DC;
1467
1468 if (reset_mask & RADEON_RESET_RLC)
1469 srbm_soft_reset |= SOFT_RESET_RLC;
1470
1471 if (reset_mask & RADEON_RESET_SEM)
1472 srbm_soft_reset |= SOFT_RESET_SEM;
1473
1474 if (reset_mask & RADEON_RESET_IH)
1475 srbm_soft_reset |= SOFT_RESET_IH;
1476
1477 if (reset_mask & RADEON_RESET_GRBM)
1478 srbm_soft_reset |= SOFT_RESET_GRBM;
1479
1480 if (reset_mask & RADEON_RESET_VMC)
1481 srbm_soft_reset |= SOFT_RESET_VMC;
1482
Alex Deucher24178ec2013-01-24 15:00:17 -05001483 if (!(rdev->flags & RADEON_IS_IGP)) {
1484 if (reset_mask & RADEON_RESET_MC)
1485 srbm_soft_reset |= SOFT_RESET_MC;
1486 }
Alex Deucher187e3592013-01-18 14:51:38 -05001487
1488 if (grbm_soft_reset) {
1489 tmp = RREG32(GRBM_SOFT_RESET);
1490 tmp |= grbm_soft_reset;
1491 dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
1492 WREG32(GRBM_SOFT_RESET, tmp);
1493 tmp = RREG32(GRBM_SOFT_RESET);
1494
1495 udelay(50);
1496
1497 tmp &= ~grbm_soft_reset;
1498 WREG32(GRBM_SOFT_RESET, tmp);
1499 tmp = RREG32(GRBM_SOFT_RESET);
1500 }
1501
1502 if (srbm_soft_reset) {
1503 tmp = RREG32(SRBM_SOFT_RESET);
1504 tmp |= srbm_soft_reset;
1505 dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
1506 WREG32(SRBM_SOFT_RESET, tmp);
1507 tmp = RREG32(SRBM_SOFT_RESET);
1508
1509 udelay(50);
1510
1511 tmp &= ~srbm_soft_reset;
1512 WREG32(SRBM_SOFT_RESET, tmp);
1513 tmp = RREG32(SRBM_SOFT_RESET);
1514 }
Alex Deucher271d6fed2013-01-03 12:48:05 -05001515
1516 /* Wait a little for things to settle down */
1517 udelay(50);
1518
Alex Deucherb9952a82011-03-02 20:07:33 -05001519 evergreen_mc_resume(rdev, &save);
Alex Deucher187e3592013-01-18 14:51:38 -05001520 udelay(50);
Alex Deucher410a3412013-01-18 13:05:39 -05001521
Alex Deucher187e3592013-01-18 14:51:38 -05001522 evergreen_print_gpu_status_regs(rdev);
Alex Deucherb9952a82011-03-02 20:07:33 -05001523}
1524
1525int cayman_asic_reset(struct radeon_device *rdev)
1526{
Alex Deucher168757e2013-01-18 19:17:22 -05001527 u32 reset_mask;
1528
1529 reset_mask = cayman_gpu_check_soft_reset(rdev);
1530
1531 if (reset_mask)
1532 r600_set_bios_scratch_engine_hung(rdev, true);
1533
1534 cayman_gpu_soft_reset(rdev, reset_mask);
1535
1536 reset_mask = cayman_gpu_check_soft_reset(rdev);
1537
1538 if (!reset_mask)
1539 r600_set_bios_scratch_engine_hung(rdev, false);
1540
1541 return 0;
Alex Deucherb9952a82011-03-02 20:07:33 -05001542}
1543
Alex Deucherf60cbd12012-12-04 15:27:33 -05001544/**
Alex Deucher123bc182013-01-24 11:37:19 -05001545 * cayman_gfx_is_lockup - Check if the GFX engine is locked up
1546 *
1547 * @rdev: radeon_device pointer
1548 * @ring: radeon_ring structure holding ring information
1549 *
1550 * Check if the GFX engine is locked up.
1551 * Returns true if the engine appears to be locked up, false if not.
1552 */
1553bool cayman_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
1554{
1555 u32 reset_mask = cayman_gpu_check_soft_reset(rdev);
1556
1557 if (!(reset_mask & (RADEON_RESET_GFX |
1558 RADEON_RESET_COMPUTE |
1559 RADEON_RESET_CP))) {
1560 radeon_ring_lockup_update(ring);
1561 return false;
1562 }
1563 /* force CP activities */
1564 radeon_ring_force_activity(rdev, ring);
1565 return radeon_ring_test_lockup(rdev, ring);
1566}
1567
1568/**
Alex Deucherf60cbd12012-12-04 15:27:33 -05001569 * cayman_dma_is_lockup - Check if the DMA engine is locked up
1570 *
1571 * @rdev: radeon_device pointer
1572 * @ring: radeon_ring structure holding ring information
1573 *
Alex Deucher123bc182013-01-24 11:37:19 -05001574 * Check if the async DMA engine is locked up.
Alex Deucherf60cbd12012-12-04 15:27:33 -05001575 * Returns true if the engine appears to be locked up, false if not.
1576 */
1577bool cayman_dma_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
1578{
Alex Deucher123bc182013-01-24 11:37:19 -05001579 u32 reset_mask = cayman_gpu_check_soft_reset(rdev);
1580 u32 mask;
Alex Deucherf60cbd12012-12-04 15:27:33 -05001581
1582 if (ring->idx == R600_RING_TYPE_DMA_INDEX)
Alex Deucher123bc182013-01-24 11:37:19 -05001583 mask = RADEON_RESET_DMA;
Alex Deucherf60cbd12012-12-04 15:27:33 -05001584 else
Alex Deucher123bc182013-01-24 11:37:19 -05001585 mask = RADEON_RESET_DMA1;
1586
1587 if (!(reset_mask & mask)) {
Alex Deucherf60cbd12012-12-04 15:27:33 -05001588 radeon_ring_lockup_update(ring);
1589 return false;
1590 }
1591 /* force ring activities */
1592 radeon_ring_force_activity(rdev, ring);
1593 return radeon_ring_test_lockup(rdev, ring);
1594}
1595
Alex Deucher755d8192011-03-02 20:07:34 -05001596static int cayman_startup(struct radeon_device *rdev)
1597{
Christian Könige32eb502011-10-23 12:56:27 +02001598 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucher755d8192011-03-02 20:07:34 -05001599 int r;
1600
Ilija Hadzicb07759b2011-09-20 10:22:58 -04001601 /* enable pcie gen2 link */
1602 evergreen_pcie_gen2_enable(rdev);
1603
Alex Deucherc420c742012-03-20 17:18:39 -04001604 if (rdev->flags & RADEON_IS_IGP) {
1605 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
1606 r = ni_init_microcode(rdev);
1607 if (r) {
1608 DRM_ERROR("Failed to load firmware!\n");
1609 return r;
1610 }
1611 }
1612 } else {
1613 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw || !rdev->mc_fw) {
1614 r = ni_init_microcode(rdev);
1615 if (r) {
1616 DRM_ERROR("Failed to load firmware!\n");
1617 return r;
1618 }
1619 }
1620
1621 r = ni_mc_load_microcode(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001622 if (r) {
Alex Deucherc420c742012-03-20 17:18:39 -04001623 DRM_ERROR("Failed to load MC firmware!\n");
Alex Deucher755d8192011-03-02 20:07:34 -05001624 return r;
1625 }
1626 }
Alex Deucher755d8192011-03-02 20:07:34 -05001627
Alex Deucher16cdf042011-10-28 10:30:02 -04001628 r = r600_vram_scratch_init(rdev);
1629 if (r)
1630 return r;
1631
Alex Deucher755d8192011-03-02 20:07:34 -05001632 evergreen_mc_program(rdev);
1633 r = cayman_pcie_gart_enable(rdev);
1634 if (r)
1635 return r;
1636 cayman_gpu_init(rdev);
1637
Alex Deuchercb92d452011-05-25 16:39:00 -04001638 r = evergreen_blit_init(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001639 if (r) {
Ilija Hadzicfb3d9e92011-10-12 23:29:41 -04001640 r600_blit_fini(rdev);
Alex Deucher27cd7762012-02-23 17:53:42 -05001641 rdev->asic->copy.copy = NULL;
Alex Deucher755d8192011-03-02 20:07:34 -05001642 dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
1643 }
Alex Deucher755d8192011-03-02 20:07:34 -05001644
Alex Deucherc420c742012-03-20 17:18:39 -04001645 /* allocate rlc buffers */
1646 if (rdev->flags & RADEON_IS_IGP) {
1647 r = si_rlc_init(rdev);
1648 if (r) {
1649 DRM_ERROR("Failed to init rlc BOs!\n");
1650 return r;
1651 }
1652 }
1653
Alex Deucher755d8192011-03-02 20:07:34 -05001654 /* allocate wb buffer */
1655 r = radeon_wb_init(rdev);
1656 if (r)
1657 return r;
1658
Jerome Glisse30eb77f2011-11-20 20:45:34 +00001659 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
1660 if (r) {
1661 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
1662 return r;
1663 }
1664
1665 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
1666 if (r) {
1667 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
1668 return r;
1669 }
1670
1671 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
1672 if (r) {
1673 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
1674 return r;
1675 }
1676
Alex Deucherf60cbd12012-12-04 15:27:33 -05001677 r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
1678 if (r) {
1679 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
1680 return r;
1681 }
1682
1683 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
1684 if (r) {
1685 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
1686 return r;
1687 }
1688
Alex Deucher755d8192011-03-02 20:07:34 -05001689 /* Enable IRQ */
1690 r = r600_irq_init(rdev);
1691 if (r) {
1692 DRM_ERROR("radeon: IH init failed (%d).\n", r);
1693 radeon_irq_kms_fini(rdev);
1694 return r;
1695 }
1696 evergreen_irq_set(rdev);
1697
Christian Könige32eb502011-10-23 12:56:27 +02001698 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
Alex Deucher78c55602011-11-17 14:25:56 -05001699 CP_RB0_RPTR, CP_RB0_WPTR,
1700 0, 0xfffff, RADEON_CP_PACKET2);
Alex Deucher755d8192011-03-02 20:07:34 -05001701 if (r)
1702 return r;
Alex Deucherf60cbd12012-12-04 15:27:33 -05001703
1704 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
1705 r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
1706 DMA_RB_RPTR + DMA0_REGISTER_OFFSET,
1707 DMA_RB_WPTR + DMA0_REGISTER_OFFSET,
1708 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
1709 if (r)
1710 return r;
1711
1712 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
1713 r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
1714 DMA_RB_RPTR + DMA1_REGISTER_OFFSET,
1715 DMA_RB_WPTR + DMA1_REGISTER_OFFSET,
1716 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
1717 if (r)
1718 return r;
1719
Alex Deucher755d8192011-03-02 20:07:34 -05001720 r = cayman_cp_load_microcode(rdev);
1721 if (r)
1722 return r;
1723 r = cayman_cp_resume(rdev);
1724 if (r)
1725 return r;
1726
Alex Deucherf60cbd12012-12-04 15:27:33 -05001727 r = cayman_dma_resume(rdev);
1728 if (r)
1729 return r;
1730
Christian König2898c342012-07-05 11:55:34 +02001731 r = radeon_ib_pool_init(rdev);
1732 if (r) {
1733 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
Jerome Glisseb15ba512011-11-15 11:48:34 -05001734 return r;
Christian König2898c342012-07-05 11:55:34 +02001735 }
Jerome Glisseb15ba512011-11-15 11:48:34 -05001736
Christian Königc6105f22012-07-05 14:32:00 +02001737 r = radeon_vm_manager_init(rdev);
1738 if (r) {
1739 dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
Jerome Glisse721604a2012-01-05 22:11:05 -05001740 return r;
Christian Königc6105f22012-07-05 14:32:00 +02001741 }
Jerome Glisse721604a2012-01-05 22:11:05 -05001742
Rafał Miłecki6b53a052012-06-11 12:34:01 +02001743 r = r600_audio_init(rdev);
1744 if (r)
1745 return r;
1746
Alex Deucher755d8192011-03-02 20:07:34 -05001747 return 0;
1748}
1749
1750int cayman_resume(struct radeon_device *rdev)
1751{
1752 int r;
1753
1754 /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
1755 * posting will perform necessary task to bring back GPU into good
1756 * shape.
1757 */
1758 /* post card */
1759 atom_asic_init(rdev->mode_info.atom_context);
1760
Jerome Glisseb15ba512011-11-15 11:48:34 -05001761 rdev->accel_working = true;
Alex Deucher755d8192011-03-02 20:07:34 -05001762 r = cayman_startup(rdev);
1763 if (r) {
1764 DRM_ERROR("cayman startup failed on resume\n");
Jerome Glisse6b7746e2012-02-20 17:57:20 -05001765 rdev->accel_working = false;
Alex Deucher755d8192011-03-02 20:07:34 -05001766 return r;
1767 }
Alex Deucher755d8192011-03-02 20:07:34 -05001768 return r;
Alex Deucher755d8192011-03-02 20:07:34 -05001769}
1770
1771int cayman_suspend(struct radeon_device *rdev)
1772{
Rafał Miłecki6b53a052012-06-11 12:34:01 +02001773 r600_audio_fini(rdev);
Alex Deucherfa3daf92013-03-11 15:32:26 -04001774 radeon_vm_manager_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001775 cayman_cp_enable(rdev, false);
Alex Deucherf60cbd12012-12-04 15:27:33 -05001776 cayman_dma_stop(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001777 evergreen_irq_suspend(rdev);
1778 radeon_wb_disable(rdev);
1779 cayman_pcie_gart_disable(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001780 return 0;
1781}
1782
1783/* Plan is to move initialization in that function and use
1784 * helper function so that radeon_device_init pretty much
1785 * do nothing more than calling asic specific function. This
1786 * should also allow to remove a bunch of callback function
1787 * like vram_info.
1788 */
1789int cayman_init(struct radeon_device *rdev)
1790{
Christian Könige32eb502011-10-23 12:56:27 +02001791 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucher755d8192011-03-02 20:07:34 -05001792 int r;
1793
Alex Deucher755d8192011-03-02 20:07:34 -05001794 /* Read BIOS */
1795 if (!radeon_get_bios(rdev)) {
1796 if (ASIC_IS_AVIVO(rdev))
1797 return -EINVAL;
1798 }
1799 /* Must be an ATOMBIOS */
1800 if (!rdev->is_atom_bios) {
1801 dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
1802 return -EINVAL;
1803 }
1804 r = radeon_atombios_init(rdev);
1805 if (r)
1806 return r;
1807
1808 /* Post card if necessary */
1809 if (!radeon_card_posted(rdev)) {
1810 if (!rdev->bios) {
1811 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
1812 return -EINVAL;
1813 }
1814 DRM_INFO("GPU not posted. posting now...\n");
1815 atom_asic_init(rdev->mode_info.atom_context);
1816 }
1817 /* Initialize scratch registers */
1818 r600_scratch_init(rdev);
1819 /* Initialize surface registers */
1820 radeon_surface_init(rdev);
1821 /* Initialize clocks */
1822 radeon_get_clock_info(rdev->ddev);
1823 /* Fence driver */
Jerome Glisse30eb77f2011-11-20 20:45:34 +00001824 r = radeon_fence_driver_init(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001825 if (r)
1826 return r;
1827 /* initialize memory controller */
1828 r = evergreen_mc_init(rdev);
1829 if (r)
1830 return r;
1831 /* Memory manager */
1832 r = radeon_bo_init(rdev);
1833 if (r)
1834 return r;
1835
1836 r = radeon_irq_kms_init(rdev);
1837 if (r)
1838 return r;
1839
Christian Könige32eb502011-10-23 12:56:27 +02001840 ring->ring_obj = NULL;
1841 r600_ring_init(rdev, ring, 1024 * 1024);
Alex Deucher755d8192011-03-02 20:07:34 -05001842
Alex Deucherf60cbd12012-12-04 15:27:33 -05001843 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
1844 ring->ring_obj = NULL;
1845 r600_ring_init(rdev, ring, 64 * 1024);
1846
1847 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
1848 ring->ring_obj = NULL;
1849 r600_ring_init(rdev, ring, 64 * 1024);
1850
Alex Deucher755d8192011-03-02 20:07:34 -05001851 rdev->ih.ring_obj = NULL;
1852 r600_ih_ring_init(rdev, 64 * 1024);
1853
1854 r = r600_pcie_gart_init(rdev);
1855 if (r)
1856 return r;
1857
1858 rdev->accel_working = true;
1859 r = cayman_startup(rdev);
1860 if (r) {
1861 dev_err(rdev->dev, "disabling GPU acceleration\n");
1862 cayman_cp_fini(rdev);
Alex Deucherf60cbd12012-12-04 15:27:33 -05001863 cayman_dma_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001864 r600_irq_fini(rdev);
Alex Deucherc420c742012-03-20 17:18:39 -04001865 if (rdev->flags & RADEON_IS_IGP)
1866 si_rlc_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001867 radeon_wb_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02001868 radeon_ib_pool_fini(rdev);
Jerome Glisse721604a2012-01-05 22:11:05 -05001869 radeon_vm_manager_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001870 radeon_irq_kms_fini(rdev);
1871 cayman_pcie_gart_fini(rdev);
1872 rdev->accel_working = false;
1873 }
Alex Deucher755d8192011-03-02 20:07:34 -05001874
1875 /* Don't start up if the MC ucode is missing.
1876 * The default clocks and voltages before the MC ucode
1877 * is loaded are not suffient for advanced operations.
Alex Deucherc420c742012-03-20 17:18:39 -04001878 *
1879 * We can skip this check for TN, because there is no MC
1880 * ucode.
Alex Deucher755d8192011-03-02 20:07:34 -05001881 */
Alex Deucherc420c742012-03-20 17:18:39 -04001882 if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
Alex Deucher755d8192011-03-02 20:07:34 -05001883 DRM_ERROR("radeon: MC ucode required for NI+.\n");
1884 return -EINVAL;
1885 }
1886
1887 return 0;
1888}
1889
1890void cayman_fini(struct radeon_device *rdev)
1891{
Ilija Hadzicfb3d9e92011-10-12 23:29:41 -04001892 r600_blit_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001893 cayman_cp_fini(rdev);
Alex Deucherf60cbd12012-12-04 15:27:33 -05001894 cayman_dma_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001895 r600_irq_fini(rdev);
Alex Deucherc420c742012-03-20 17:18:39 -04001896 if (rdev->flags & RADEON_IS_IGP)
1897 si_rlc_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001898 radeon_wb_fini(rdev);
Jerome Glisse721604a2012-01-05 22:11:05 -05001899 radeon_vm_manager_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02001900 radeon_ib_pool_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001901 radeon_irq_kms_fini(rdev);
1902 cayman_pcie_gart_fini(rdev);
Alex Deucher16cdf042011-10-28 10:30:02 -04001903 r600_vram_scratch_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001904 radeon_gem_fini(rdev);
1905 radeon_fence_driver_fini(rdev);
1906 radeon_bo_fini(rdev);
1907 radeon_atombios_fini(rdev);
1908 kfree(rdev->bios);
1909 rdev->bios = NULL;
1910}
1911
Jerome Glisse721604a2012-01-05 22:11:05 -05001912/*
1913 * vm
1914 */
1915int cayman_vm_init(struct radeon_device *rdev)
1916{
1917 /* number of VMs */
1918 rdev->vm_manager.nvm = 8;
1919 /* base offset of vram pages */
Alex Deuchere71270f2012-03-20 17:18:38 -04001920 if (rdev->flags & RADEON_IS_IGP) {
1921 u64 tmp = RREG32(FUS_MC_VM_FB_OFFSET);
1922 tmp <<= 22;
1923 rdev->vm_manager.vram_base_offset = tmp;
1924 } else
1925 rdev->vm_manager.vram_base_offset = 0;
Jerome Glisse721604a2012-01-05 22:11:05 -05001926 return 0;
1927}
1928
1929void cayman_vm_fini(struct radeon_device *rdev)
1930{
1931}
1932
Christian Königdce34bf2012-09-17 19:36:18 +02001933#define R600_ENTRY_VALID (1 << 0)
Jerome Glisse721604a2012-01-05 22:11:05 -05001934#define R600_PTE_SYSTEM (1 << 1)
1935#define R600_PTE_SNOOPED (1 << 2)
1936#define R600_PTE_READABLE (1 << 5)
1937#define R600_PTE_WRITEABLE (1 << 6)
1938
Christian König089a7862012-08-11 11:54:05 +02001939uint32_t cayman_vm_page_flags(struct radeon_device *rdev, uint32_t flags)
Jerome Glisse721604a2012-01-05 22:11:05 -05001940{
1941 uint32_t r600_flags = 0;
Christian Königdce34bf2012-09-17 19:36:18 +02001942 r600_flags |= (flags & RADEON_VM_PAGE_VALID) ? R600_ENTRY_VALID : 0;
Jerome Glisse721604a2012-01-05 22:11:05 -05001943 r600_flags |= (flags & RADEON_VM_PAGE_READABLE) ? R600_PTE_READABLE : 0;
1944 r600_flags |= (flags & RADEON_VM_PAGE_WRITEABLE) ? R600_PTE_WRITEABLE : 0;
1945 if (flags & RADEON_VM_PAGE_SYSTEM) {
1946 r600_flags |= R600_PTE_SYSTEM;
1947 r600_flags |= (flags & RADEON_VM_PAGE_SNOOPED) ? R600_PTE_SNOOPED : 0;
1948 }
1949 return r600_flags;
1950}
1951
Alex Deucher7a083292012-08-31 13:51:21 -04001952/**
1953 * cayman_vm_set_page - update the page tables using the CP
1954 *
1955 * @rdev: radeon_device pointer
Alex Deucher43f12142013-02-01 17:32:42 +01001956 * @ib: indirect buffer to fill with commands
Christian Königdce34bf2012-09-17 19:36:18 +02001957 * @pe: addr of the page entry
1958 * @addr: dst addr to write into pe
1959 * @count: number of page entries to update
1960 * @incr: increase next addr by incr bytes
1961 * @flags: access flags
Alex Deucher7a083292012-08-31 13:51:21 -04001962 *
Alex Deucher43f12142013-02-01 17:32:42 +01001963 * Update the page tables using the CP (cayman/TN).
Alex Deucher7a083292012-08-31 13:51:21 -04001964 */
Alex Deucher43f12142013-02-01 17:32:42 +01001965void cayman_vm_set_page(struct radeon_device *rdev,
1966 struct radeon_ib *ib,
1967 uint64_t pe,
Christian Königdce34bf2012-09-17 19:36:18 +02001968 uint64_t addr, unsigned count,
1969 uint32_t incr, uint32_t flags)
Jerome Glisse721604a2012-01-05 22:11:05 -05001970{
Christian Königdce34bf2012-09-17 19:36:18 +02001971 uint32_t r600_flags = cayman_vm_page_flags(rdev, flags);
Alex Deucher3b6b59b2012-10-22 12:19:01 -04001972 uint64_t value;
1973 unsigned ndw;
Jerome Glisse721604a2012-01-05 22:11:05 -05001974
Alex Deucher3b6b59b2012-10-22 12:19:01 -04001975 if (rdev->asic->vm.pt_ring_index == RADEON_RING_TYPE_GFX_INDEX) {
1976 while (count) {
1977 ndw = 1 + count * 2;
1978 if (ndw > 0x3FFF)
1979 ndw = 0x3FFF;
Christian König089a7862012-08-11 11:54:05 +02001980
Alex Deucher43f12142013-02-01 17:32:42 +01001981 ib->ptr[ib->length_dw++] = PACKET3(PACKET3_ME_WRITE, ndw);
1982 ib->ptr[ib->length_dw++] = pe;
1983 ib->ptr[ib->length_dw++] = upper_32_bits(pe) & 0xff;
Alex Deucher3b6b59b2012-10-22 12:19:01 -04001984 for (; ndw > 1; ndw -= 2, --count, pe += 8) {
1985 if (flags & RADEON_VM_PAGE_SYSTEM) {
1986 value = radeon_vm_map_gart(rdev, addr);
1987 value &= 0xFFFFFFFFFFFFF000ULL;
1988 } else if (flags & RADEON_VM_PAGE_VALID) {
1989 value = addr;
1990 } else {
1991 value = 0;
1992 }
Christian Königf9fdffa2012-10-22 17:42:36 +02001993 addr += incr;
Alex Deucher3b6b59b2012-10-22 12:19:01 -04001994 value |= r600_flags;
Alex Deucher43f12142013-02-01 17:32:42 +01001995 ib->ptr[ib->length_dw++] = value;
1996 ib->ptr[ib->length_dw++] = upper_32_bits(value);
Christian Königf9fdffa2012-10-22 17:42:36 +02001997 }
Alex Deucher3b6b59b2012-10-22 12:19:01 -04001998 }
1999 } else {
2000 while (count) {
2001 ndw = count * 2;
2002 if (ndw > 0xFFFFE)
2003 ndw = 0xFFFFE;
Christian Königf9fdffa2012-10-22 17:42:36 +02002004
Alex Deucher3b6b59b2012-10-22 12:19:01 -04002005 /* for non-physically contiguous pages (system) */
Alex Deucher43f12142013-02-01 17:32:42 +01002006 ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_WRITE, 0, 0, ndw);
2007 ib->ptr[ib->length_dw++] = pe;
2008 ib->ptr[ib->length_dw++] = upper_32_bits(pe) & 0xff;
Alex Deucher3b6b59b2012-10-22 12:19:01 -04002009 for (; ndw > 0; ndw -= 2, --count, pe += 8) {
2010 if (flags & RADEON_VM_PAGE_SYSTEM) {
2011 value = radeon_vm_map_gart(rdev, addr);
2012 value &= 0xFFFFFFFFFFFFF000ULL;
2013 } else if (flags & RADEON_VM_PAGE_VALID) {
2014 value = addr;
2015 } else {
2016 value = 0;
2017 }
2018 addr += incr;
2019 value |= r600_flags;
Alex Deucher43f12142013-02-01 17:32:42 +01002020 ib->ptr[ib->length_dw++] = value;
2021 ib->ptr[ib->length_dw++] = upper_32_bits(value);
Alex Deucher3b6b59b2012-10-22 12:19:01 -04002022 }
Christian König2a6f1ab2012-08-11 15:00:30 +02002023 }
Alex Deucher43f12142013-02-01 17:32:42 +01002024 while (ib->length_dw & 0x7)
2025 ib->ptr[ib->length_dw++] = DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0);
Christian König2a6f1ab2012-08-11 15:00:30 +02002026 }
Jerome Glisse721604a2012-01-05 22:11:05 -05002027}
Christian König9b40e5d2012-08-08 12:22:43 +02002028
Alex Deucher7a083292012-08-31 13:51:21 -04002029/**
2030 * cayman_vm_flush - vm flush using the CP
2031 *
2032 * @rdev: radeon_device pointer
2033 *
2034 * Update the page table base and flush the VM TLB
2035 * using the CP (cayman-si).
2036 */
Alex Deucher498522b2012-10-02 14:43:38 -04002037void cayman_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
Christian König9b40e5d2012-08-08 12:22:43 +02002038{
Alex Deucher498522b2012-10-02 14:43:38 -04002039 struct radeon_ring *ring = &rdev->ring[ridx];
Christian König9b40e5d2012-08-08 12:22:43 +02002040
Christian Königee60e292012-08-09 16:21:08 +02002041 if (vm == NULL)
Christian König9b40e5d2012-08-08 12:22:43 +02002042 return;
2043
Christian Königee60e292012-08-09 16:21:08 +02002044 radeon_ring_write(ring, PACKET0(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2), 0));
Dmitry Cherkasovfa87e622012-09-17 19:36:19 +02002045 radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
Christian Königee60e292012-08-09 16:21:08 +02002046
Christian König9b40e5d2012-08-08 12:22:43 +02002047 /* flush hdp cache */
2048 radeon_ring_write(ring, PACKET0(HDP_MEM_COHERENCY_FLUSH_CNTL, 0));
2049 radeon_ring_write(ring, 0x1);
2050
2051 /* bits 0-7 are the VM contexts0-7 */
2052 radeon_ring_write(ring, PACKET0(VM_INVALIDATE_REQUEST, 0));
Alex Deucher498522b2012-10-02 14:43:38 -04002053 radeon_ring_write(ring, 1 << vm->id);
Christian König58f8cf52012-10-22 17:42:35 +02002054
2055 /* sync PFP to ME, otherwise we might get invalid PFP reads */
2056 radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
2057 radeon_ring_write(ring, 0x0);
Alex Deucher0af62b02011-01-06 21:19:31 -05002058}
Alex Deucherf60cbd12012-12-04 15:27:33 -05002059
2060void cayman_dma_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
2061{
2062 struct radeon_ring *ring = &rdev->ring[ridx];
2063
2064 if (vm == NULL)
2065 return;
2066
2067 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0));
2068 radeon_ring_write(ring, (0xf << 16) | ((VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2));
2069 radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
2070
2071 /* flush hdp cache */
2072 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0));
2073 radeon_ring_write(ring, (0xf << 16) | (HDP_MEM_COHERENCY_FLUSH_CNTL >> 2));
2074 radeon_ring_write(ring, 1);
2075
2076 /* bits 0-7 are the VM contexts0-7 */
2077 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0));
2078 radeon_ring_write(ring, (0xf << 16) | (VM_INVALIDATE_REQUEST >> 2));
2079 radeon_ring_write(ring, 1 << vm->id);
2080}
2081