blob: 8a9a75d1cb00f810277dcec248925b8134c5b1e6 [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 Deucherb9952a82011-03-02 20:07:33 -050037extern void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save);
38extern void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save);
39extern int evergreen_mc_wait_for_idle(struct radeon_device *rdev);
Alex Deucher755d8192011-03-02 20:07:34 -050040extern void evergreen_mc_program(struct radeon_device *rdev);
41extern void evergreen_irq_suspend(struct radeon_device *rdev);
42extern int evergreen_mc_init(struct radeon_device *rdev);
Alex Deucherd054ac12011-09-01 17:46:15 +000043extern void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev);
Ilija Hadzicb07759b2011-09-20 10:22:58 -040044extern void evergreen_pcie_gen2_enable(struct radeon_device *rdev);
Alex Deucherc420c742012-03-20 17:18:39 -040045extern void si_rlc_fini(struct radeon_device *rdev);
46extern int si_rlc_init(struct radeon_device *rdev);
Alex Deucherb9952a82011-03-02 20:07:33 -050047
Alex Deucher0af62b02011-01-06 21:19:31 -050048#define EVERGREEN_PFP_UCODE_SIZE 1120
49#define EVERGREEN_PM4_UCODE_SIZE 1376
50#define EVERGREEN_RLC_UCODE_SIZE 768
51#define BTC_MC_UCODE_SIZE 6024
52
Alex Deucher9b8253c2011-03-02 20:07:28 -050053#define CAYMAN_PFP_UCODE_SIZE 2176
54#define CAYMAN_PM4_UCODE_SIZE 2176
55#define CAYMAN_RLC_UCODE_SIZE 1024
56#define CAYMAN_MC_UCODE_SIZE 6037
57
Alex Deucherc420c742012-03-20 17:18:39 -040058#define ARUBA_RLC_UCODE_SIZE 1536
59
Alex Deucher0af62b02011-01-06 21:19:31 -050060/* Firmware Names */
61MODULE_FIRMWARE("radeon/BARTS_pfp.bin");
62MODULE_FIRMWARE("radeon/BARTS_me.bin");
63MODULE_FIRMWARE("radeon/BARTS_mc.bin");
64MODULE_FIRMWARE("radeon/BTC_rlc.bin");
65MODULE_FIRMWARE("radeon/TURKS_pfp.bin");
66MODULE_FIRMWARE("radeon/TURKS_me.bin");
67MODULE_FIRMWARE("radeon/TURKS_mc.bin");
68MODULE_FIRMWARE("radeon/CAICOS_pfp.bin");
69MODULE_FIRMWARE("radeon/CAICOS_me.bin");
70MODULE_FIRMWARE("radeon/CAICOS_mc.bin");
Alex Deucher9b8253c2011-03-02 20:07:28 -050071MODULE_FIRMWARE("radeon/CAYMAN_pfp.bin");
72MODULE_FIRMWARE("radeon/CAYMAN_me.bin");
73MODULE_FIRMWARE("radeon/CAYMAN_mc.bin");
74MODULE_FIRMWARE("radeon/CAYMAN_rlc.bin");
Alex Deucherc420c742012-03-20 17:18:39 -040075MODULE_FIRMWARE("radeon/ARUBA_pfp.bin");
76MODULE_FIRMWARE("radeon/ARUBA_me.bin");
77MODULE_FIRMWARE("radeon/ARUBA_rlc.bin");
Alex Deucher0af62b02011-01-06 21:19:31 -050078
79#define BTC_IO_MC_REGS_SIZE 29
80
81static const u32 barts_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
82 {0x00000077, 0xff010100},
83 {0x00000078, 0x00000000},
84 {0x00000079, 0x00001434},
85 {0x0000007a, 0xcc08ec08},
86 {0x0000007b, 0x00040000},
87 {0x0000007c, 0x000080c0},
88 {0x0000007d, 0x09000000},
89 {0x0000007e, 0x00210404},
90 {0x00000081, 0x08a8e800},
91 {0x00000082, 0x00030444},
92 {0x00000083, 0x00000000},
93 {0x00000085, 0x00000001},
94 {0x00000086, 0x00000002},
95 {0x00000087, 0x48490000},
96 {0x00000088, 0x20244647},
97 {0x00000089, 0x00000005},
98 {0x0000008b, 0x66030000},
99 {0x0000008c, 0x00006603},
100 {0x0000008d, 0x00000100},
101 {0x0000008f, 0x00001c0a},
102 {0x00000090, 0xff000001},
103 {0x00000094, 0x00101101},
104 {0x00000095, 0x00000fff},
105 {0x00000096, 0x00116fff},
106 {0x00000097, 0x60010000},
107 {0x00000098, 0x10010000},
108 {0x00000099, 0x00006000},
109 {0x0000009a, 0x00001000},
110 {0x0000009f, 0x00946a00}
111};
112
113static const u32 turks_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
114 {0x00000077, 0xff010100},
115 {0x00000078, 0x00000000},
116 {0x00000079, 0x00001434},
117 {0x0000007a, 0xcc08ec08},
118 {0x0000007b, 0x00040000},
119 {0x0000007c, 0x000080c0},
120 {0x0000007d, 0x09000000},
121 {0x0000007e, 0x00210404},
122 {0x00000081, 0x08a8e800},
123 {0x00000082, 0x00030444},
124 {0x00000083, 0x00000000},
125 {0x00000085, 0x00000001},
126 {0x00000086, 0x00000002},
127 {0x00000087, 0x48490000},
128 {0x00000088, 0x20244647},
129 {0x00000089, 0x00000005},
130 {0x0000008b, 0x66030000},
131 {0x0000008c, 0x00006603},
132 {0x0000008d, 0x00000100},
133 {0x0000008f, 0x00001c0a},
134 {0x00000090, 0xff000001},
135 {0x00000094, 0x00101101},
136 {0x00000095, 0x00000fff},
137 {0x00000096, 0x00116fff},
138 {0x00000097, 0x60010000},
139 {0x00000098, 0x10010000},
140 {0x00000099, 0x00006000},
141 {0x0000009a, 0x00001000},
142 {0x0000009f, 0x00936a00}
143};
144
145static const u32 caicos_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
146 {0x00000077, 0xff010100},
147 {0x00000078, 0x00000000},
148 {0x00000079, 0x00001434},
149 {0x0000007a, 0xcc08ec08},
150 {0x0000007b, 0x00040000},
151 {0x0000007c, 0x000080c0},
152 {0x0000007d, 0x09000000},
153 {0x0000007e, 0x00210404},
154 {0x00000081, 0x08a8e800},
155 {0x00000082, 0x00030444},
156 {0x00000083, 0x00000000},
157 {0x00000085, 0x00000001},
158 {0x00000086, 0x00000002},
159 {0x00000087, 0x48490000},
160 {0x00000088, 0x20244647},
161 {0x00000089, 0x00000005},
162 {0x0000008b, 0x66030000},
163 {0x0000008c, 0x00006603},
164 {0x0000008d, 0x00000100},
165 {0x0000008f, 0x00001c0a},
166 {0x00000090, 0xff000001},
167 {0x00000094, 0x00101101},
168 {0x00000095, 0x00000fff},
169 {0x00000096, 0x00116fff},
170 {0x00000097, 0x60010000},
171 {0x00000098, 0x10010000},
172 {0x00000099, 0x00006000},
173 {0x0000009a, 0x00001000},
174 {0x0000009f, 0x00916a00}
175};
176
Alex Deucher9b8253c2011-03-02 20:07:28 -0500177static const u32 cayman_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
178 {0x00000077, 0xff010100},
179 {0x00000078, 0x00000000},
180 {0x00000079, 0x00001434},
181 {0x0000007a, 0xcc08ec08},
182 {0x0000007b, 0x00040000},
183 {0x0000007c, 0x000080c0},
184 {0x0000007d, 0x09000000},
185 {0x0000007e, 0x00210404},
186 {0x00000081, 0x08a8e800},
187 {0x00000082, 0x00030444},
188 {0x00000083, 0x00000000},
189 {0x00000085, 0x00000001},
190 {0x00000086, 0x00000002},
191 {0x00000087, 0x48490000},
192 {0x00000088, 0x20244647},
193 {0x00000089, 0x00000005},
194 {0x0000008b, 0x66030000},
195 {0x0000008c, 0x00006603},
196 {0x0000008d, 0x00000100},
197 {0x0000008f, 0x00001c0a},
198 {0x00000090, 0xff000001},
199 {0x00000094, 0x00101101},
200 {0x00000095, 0x00000fff},
201 {0x00000096, 0x00116fff},
202 {0x00000097, 0x60010000},
203 {0x00000098, 0x10010000},
204 {0x00000099, 0x00006000},
205 {0x0000009a, 0x00001000},
206 {0x0000009f, 0x00976b00}
207};
208
Alex Deucher755d8192011-03-02 20:07:34 -0500209int ni_mc_load_microcode(struct radeon_device *rdev)
Alex Deucher0af62b02011-01-06 21:19:31 -0500210{
211 const __be32 *fw_data;
212 u32 mem_type, running, blackout = 0;
213 u32 *io_mc_regs;
Alex Deucher9b8253c2011-03-02 20:07:28 -0500214 int i, ucode_size, regs_size;
Alex Deucher0af62b02011-01-06 21:19:31 -0500215
216 if (!rdev->mc_fw)
217 return -EINVAL;
218
219 switch (rdev->family) {
220 case CHIP_BARTS:
221 io_mc_regs = (u32 *)&barts_io_mc_regs;
Alex Deucher9b8253c2011-03-02 20:07:28 -0500222 ucode_size = BTC_MC_UCODE_SIZE;
223 regs_size = BTC_IO_MC_REGS_SIZE;
Alex Deucher0af62b02011-01-06 21:19:31 -0500224 break;
225 case CHIP_TURKS:
226 io_mc_regs = (u32 *)&turks_io_mc_regs;
Alex Deucher9b8253c2011-03-02 20:07:28 -0500227 ucode_size = BTC_MC_UCODE_SIZE;
228 regs_size = BTC_IO_MC_REGS_SIZE;
Alex Deucher0af62b02011-01-06 21:19:31 -0500229 break;
230 case CHIP_CAICOS:
231 default:
232 io_mc_regs = (u32 *)&caicos_io_mc_regs;
Alex Deucher9b8253c2011-03-02 20:07:28 -0500233 ucode_size = BTC_MC_UCODE_SIZE;
234 regs_size = BTC_IO_MC_REGS_SIZE;
235 break;
236 case CHIP_CAYMAN:
237 io_mc_regs = (u32 *)&cayman_io_mc_regs;
238 ucode_size = CAYMAN_MC_UCODE_SIZE;
239 regs_size = BTC_IO_MC_REGS_SIZE;
Alex Deucher0af62b02011-01-06 21:19:31 -0500240 break;
241 }
242
243 mem_type = (RREG32(MC_SEQ_MISC0) & MC_SEQ_MISC0_GDDR5_MASK) >> MC_SEQ_MISC0_GDDR5_SHIFT;
244 running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
245
246 if ((mem_type == MC_SEQ_MISC0_GDDR5_VALUE) && (running == 0)) {
247 if (running) {
248 blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
249 WREG32(MC_SHARED_BLACKOUT_CNTL, 1);
250 }
251
252 /* reset the engine and set to writable */
253 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
254 WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
255
256 /* load mc io regs */
Alex Deucher9b8253c2011-03-02 20:07:28 -0500257 for (i = 0; i < regs_size; i++) {
Alex Deucher0af62b02011-01-06 21:19:31 -0500258 WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
259 WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
260 }
261 /* load the MC ucode */
262 fw_data = (const __be32 *)rdev->mc_fw->data;
Alex Deucher9b8253c2011-03-02 20:07:28 -0500263 for (i = 0; i < ucode_size; i++)
Alex Deucher0af62b02011-01-06 21:19:31 -0500264 WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
265
266 /* put the engine back into the active state */
267 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
268 WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
269 WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
270
271 /* wait for training to complete */
Alex Deucher0e2c9782011-11-02 18:08:25 -0400272 for (i = 0; i < rdev->usec_timeout; i++) {
273 if (RREG32(MC_IO_PAD_CNTL_D0) & MEM_FALL_OUT_CMD)
274 break;
275 udelay(1);
276 }
Alex Deucher0af62b02011-01-06 21:19:31 -0500277
278 if (running)
279 WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
280 }
281
282 return 0;
283}
284
285int ni_init_microcode(struct radeon_device *rdev)
286{
287 struct platform_device *pdev;
288 const char *chip_name;
289 const char *rlc_chip_name;
290 size_t pfp_req_size, me_req_size, rlc_req_size, mc_req_size;
291 char fw_name[30];
292 int err;
293
294 DRM_DEBUG("\n");
295
296 pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
297 err = IS_ERR(pdev);
298 if (err) {
299 printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
300 return -EINVAL;
301 }
302
303 switch (rdev->family) {
304 case CHIP_BARTS:
305 chip_name = "BARTS";
306 rlc_chip_name = "BTC";
Alex Deucher9b8253c2011-03-02 20:07:28 -0500307 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
308 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
309 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
310 mc_req_size = BTC_MC_UCODE_SIZE * 4;
Alex Deucher0af62b02011-01-06 21:19:31 -0500311 break;
312 case CHIP_TURKS:
313 chip_name = "TURKS";
314 rlc_chip_name = "BTC";
Alex Deucher9b8253c2011-03-02 20:07:28 -0500315 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
316 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
317 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
318 mc_req_size = BTC_MC_UCODE_SIZE * 4;
Alex Deucher0af62b02011-01-06 21:19:31 -0500319 break;
320 case CHIP_CAICOS:
321 chip_name = "CAICOS";
322 rlc_chip_name = "BTC";
Alex Deucher9b8253c2011-03-02 20:07:28 -0500323 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
324 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
325 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
326 mc_req_size = BTC_MC_UCODE_SIZE * 4;
327 break;
328 case CHIP_CAYMAN:
329 chip_name = "CAYMAN";
330 rlc_chip_name = "CAYMAN";
331 pfp_req_size = CAYMAN_PFP_UCODE_SIZE * 4;
332 me_req_size = CAYMAN_PM4_UCODE_SIZE * 4;
333 rlc_req_size = CAYMAN_RLC_UCODE_SIZE * 4;
334 mc_req_size = CAYMAN_MC_UCODE_SIZE * 4;
Alex Deucher0af62b02011-01-06 21:19:31 -0500335 break;
Alex Deucherc420c742012-03-20 17:18:39 -0400336 case CHIP_ARUBA:
337 chip_name = "ARUBA";
338 rlc_chip_name = "ARUBA";
339 /* pfp/me same size as CAYMAN */
340 pfp_req_size = CAYMAN_PFP_UCODE_SIZE * 4;
341 me_req_size = CAYMAN_PM4_UCODE_SIZE * 4;
342 rlc_req_size = ARUBA_RLC_UCODE_SIZE * 4;
343 mc_req_size = 0;
344 break;
Alex Deucher0af62b02011-01-06 21:19:31 -0500345 default: BUG();
346 }
347
Alex Deucher0af62b02011-01-06 21:19:31 -0500348 DRM_INFO("Loading %s Microcode\n", chip_name);
349
350 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
351 err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
352 if (err)
353 goto out;
354 if (rdev->pfp_fw->size != pfp_req_size) {
355 printk(KERN_ERR
356 "ni_cp: Bogus length %zu in firmware \"%s\"\n",
357 rdev->pfp_fw->size, fw_name);
358 err = -EINVAL;
359 goto out;
360 }
361
362 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
363 err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
364 if (err)
365 goto out;
366 if (rdev->me_fw->size != me_req_size) {
367 printk(KERN_ERR
368 "ni_cp: Bogus length %zu in firmware \"%s\"\n",
369 rdev->me_fw->size, fw_name);
370 err = -EINVAL;
371 }
372
373 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
374 err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
375 if (err)
376 goto out;
377 if (rdev->rlc_fw->size != rlc_req_size) {
378 printk(KERN_ERR
379 "ni_rlc: Bogus length %zu in firmware \"%s\"\n",
380 rdev->rlc_fw->size, fw_name);
381 err = -EINVAL;
382 }
383
Alex Deucherc420c742012-03-20 17:18:39 -0400384 /* no MC ucode on TN */
385 if (!(rdev->flags & RADEON_IS_IGP)) {
386 snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
387 err = request_firmware(&rdev->mc_fw, fw_name, &pdev->dev);
388 if (err)
389 goto out;
390 if (rdev->mc_fw->size != mc_req_size) {
391 printk(KERN_ERR
392 "ni_mc: Bogus length %zu in firmware \"%s\"\n",
393 rdev->mc_fw->size, fw_name);
394 err = -EINVAL;
395 }
Alex Deucher0af62b02011-01-06 21:19:31 -0500396 }
397out:
398 platform_device_unregister(pdev);
399
400 if (err) {
401 if (err != -EINVAL)
402 printk(KERN_ERR
403 "ni_cp: Failed to load firmware \"%s\"\n",
404 fw_name);
405 release_firmware(rdev->pfp_fw);
406 rdev->pfp_fw = NULL;
407 release_firmware(rdev->me_fw);
408 rdev->me_fw = NULL;
409 release_firmware(rdev->rlc_fw);
410 rdev->rlc_fw = NULL;
411 release_firmware(rdev->mc_fw);
412 rdev->mc_fw = NULL;
413 }
414 return err;
415}
416
Alex Deucherfecf1d02011-03-02 20:07:29 -0500417/*
418 * Core functions
419 */
Alex Deucherfecf1d02011-03-02 20:07:29 -0500420static void cayman_gpu_init(struct radeon_device *rdev)
421{
Alex Deucherfecf1d02011-03-02 20:07:29 -0500422 u32 gb_addr_config = 0;
423 u32 mc_shared_chmap, mc_arb_ramcfg;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500424 u32 cgts_tcc_disable;
425 u32 sx_debug_1;
426 u32 smx_dc_ctl0;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500427 u32 cgts_sm_ctrl_reg;
428 u32 hdp_host_path_cntl;
429 u32 tmp;
Alex Deucher416a2bd2012-05-31 19:00:25 -0400430 u32 disabled_rb_mask;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500431 int i, j;
432
433 switch (rdev->family) {
434 case CHIP_CAYMAN:
Alex Deucherfecf1d02011-03-02 20:07:29 -0500435 rdev->config.cayman.max_shader_engines = 2;
436 rdev->config.cayman.max_pipes_per_simd = 4;
437 rdev->config.cayman.max_tile_pipes = 8;
438 rdev->config.cayman.max_simds_per_se = 12;
439 rdev->config.cayman.max_backends_per_se = 4;
440 rdev->config.cayman.max_texture_channel_caches = 8;
441 rdev->config.cayman.max_gprs = 256;
442 rdev->config.cayman.max_threads = 256;
443 rdev->config.cayman.max_gs_threads = 32;
444 rdev->config.cayman.max_stack_entries = 512;
445 rdev->config.cayman.sx_num_of_sets = 8;
446 rdev->config.cayman.sx_max_export_size = 256;
447 rdev->config.cayman.sx_max_export_pos_size = 64;
448 rdev->config.cayman.sx_max_export_smx_size = 192;
449 rdev->config.cayman.max_hw_contexts = 8;
450 rdev->config.cayman.sq_num_cf_insts = 2;
451
452 rdev->config.cayman.sc_prim_fifo_size = 0x100;
453 rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30;
454 rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -0400455 gb_addr_config = CAYMAN_GB_ADDR_CONFIG_GOLDEN;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500456 break;
Alex Deucher7b76e472012-03-20 17:18:36 -0400457 case CHIP_ARUBA:
458 default:
459 rdev->config.cayman.max_shader_engines = 1;
460 rdev->config.cayman.max_pipes_per_simd = 4;
461 rdev->config.cayman.max_tile_pipes = 2;
462 if ((rdev->pdev->device == 0x9900) ||
Alex Deucherd430f7d2012-06-05 09:50:28 -0400463 (rdev->pdev->device == 0x9901) ||
464 (rdev->pdev->device == 0x9905) ||
465 (rdev->pdev->device == 0x9906) ||
466 (rdev->pdev->device == 0x9907) ||
467 (rdev->pdev->device == 0x9908) ||
468 (rdev->pdev->device == 0x9909) ||
469 (rdev->pdev->device == 0x9910) ||
470 (rdev->pdev->device == 0x9917)) {
Alex Deucher7b76e472012-03-20 17:18:36 -0400471 rdev->config.cayman.max_simds_per_se = 6;
472 rdev->config.cayman.max_backends_per_se = 2;
473 } else if ((rdev->pdev->device == 0x9903) ||
Alex Deucherd430f7d2012-06-05 09:50:28 -0400474 (rdev->pdev->device == 0x9904) ||
475 (rdev->pdev->device == 0x990A) ||
476 (rdev->pdev->device == 0x9913) ||
477 (rdev->pdev->device == 0x9918)) {
Alex Deucher7b76e472012-03-20 17:18:36 -0400478 rdev->config.cayman.max_simds_per_se = 4;
479 rdev->config.cayman.max_backends_per_se = 2;
Alex Deucherd430f7d2012-06-05 09:50:28 -0400480 } else if ((rdev->pdev->device == 0x9919) ||
481 (rdev->pdev->device == 0x9990) ||
482 (rdev->pdev->device == 0x9991) ||
483 (rdev->pdev->device == 0x9994) ||
484 (rdev->pdev->device == 0x99A0)) {
Alex Deucher7b76e472012-03-20 17:18:36 -0400485 rdev->config.cayman.max_simds_per_se = 3;
486 rdev->config.cayman.max_backends_per_se = 1;
487 } else {
488 rdev->config.cayman.max_simds_per_se = 2;
489 rdev->config.cayman.max_backends_per_se = 1;
490 }
491 rdev->config.cayman.max_texture_channel_caches = 2;
492 rdev->config.cayman.max_gprs = 256;
493 rdev->config.cayman.max_threads = 256;
494 rdev->config.cayman.max_gs_threads = 32;
495 rdev->config.cayman.max_stack_entries = 512;
496 rdev->config.cayman.sx_num_of_sets = 8;
497 rdev->config.cayman.sx_max_export_size = 256;
498 rdev->config.cayman.sx_max_export_pos_size = 64;
499 rdev->config.cayman.sx_max_export_smx_size = 192;
500 rdev->config.cayman.max_hw_contexts = 8;
501 rdev->config.cayman.sq_num_cf_insts = 2;
502
503 rdev->config.cayman.sc_prim_fifo_size = 0x40;
504 rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30;
505 rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130;
Alex Deucher416a2bd2012-05-31 19:00:25 -0400506 gb_addr_config = ARUBA_GB_ADDR_CONFIG_GOLDEN;
Alex Deucher7b76e472012-03-20 17:18:36 -0400507 break;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500508 }
509
510 /* Initialize HDP */
511 for (i = 0, j = 0; i < 32; i++, j += 0x18) {
512 WREG32((0x2c14 + j), 0x00000000);
513 WREG32((0x2c18 + j), 0x00000000);
514 WREG32((0x2c1c + j), 0x00000000);
515 WREG32((0x2c20 + j), 0x00000000);
516 WREG32((0x2c24 + j), 0x00000000);
517 }
518
519 WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
520
Alex Deucherd054ac12011-09-01 17:46:15 +0000521 evergreen_fix_pci_max_read_req_size(rdev);
522
Alex Deucherfecf1d02011-03-02 20:07:29 -0500523 mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
524 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
525
Alex Deucherfecf1d02011-03-02 20:07:29 -0500526 tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
527 rdev->config.cayman.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
528 if (rdev->config.cayman.mem_row_size_in_kb > 4)
529 rdev->config.cayman.mem_row_size_in_kb = 4;
530 /* XXX use MC settings? */
531 rdev->config.cayman.shader_engine_tile_size = 32;
532 rdev->config.cayman.num_gpus = 1;
533 rdev->config.cayman.multi_gpu_tile_size = 64;
534
Alex Deucherfecf1d02011-03-02 20:07:29 -0500535 tmp = (gb_addr_config & NUM_PIPES_MASK) >> NUM_PIPES_SHIFT;
536 rdev->config.cayman.num_tile_pipes = (1 << tmp);
537 tmp = (gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT;
538 rdev->config.cayman.mem_max_burst_length_bytes = (tmp + 1) * 256;
539 tmp = (gb_addr_config & NUM_SHADER_ENGINES_MASK) >> NUM_SHADER_ENGINES_SHIFT;
540 rdev->config.cayman.num_shader_engines = tmp + 1;
541 tmp = (gb_addr_config & NUM_GPUS_MASK) >> NUM_GPUS_SHIFT;
542 rdev->config.cayman.num_gpus = tmp + 1;
543 tmp = (gb_addr_config & MULTI_GPU_TILE_SIZE_MASK) >> MULTI_GPU_TILE_SIZE_SHIFT;
544 rdev->config.cayman.multi_gpu_tile_size = 1 << tmp;
545 tmp = (gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT;
546 rdev->config.cayman.mem_row_size_in_kb = 1 << tmp;
547
Alex Deucher416a2bd2012-05-31 19:00:25 -0400548
Alex Deucherfecf1d02011-03-02 20:07:29 -0500549 /* setup tiling info dword. gb_addr_config is not adequate since it does
550 * not have bank info, so create a custom tiling dword.
551 * bits 3:0 num_pipes
552 * bits 7:4 num_banks
553 * bits 11:8 group_size
554 * bits 15:12 row_size
555 */
556 rdev->config.cayman.tile_config = 0;
557 switch (rdev->config.cayman.num_tile_pipes) {
558 case 1:
559 default:
560 rdev->config.cayman.tile_config |= (0 << 0);
561 break;
562 case 2:
563 rdev->config.cayman.tile_config |= (1 << 0);
564 break;
565 case 4:
566 rdev->config.cayman.tile_config |= (2 << 0);
567 break;
568 case 8:
569 rdev->config.cayman.tile_config |= (3 << 0);
570 break;
571 }
Alex Deucher7b76e472012-03-20 17:18:36 -0400572
573 /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */
574 if (rdev->flags & RADEON_IS_IGP)
Alex Deucher1f73cca2012-05-24 22:55:15 -0400575 rdev->config.cayman.tile_config |= 1 << 4;
Alex Deucher29d65402012-05-31 18:53:36 -0400576 else {
Alex Deucher5b23c902012-07-31 11:05:11 -0400577 switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
578 case 0: /* four banks */
Alex Deucher29d65402012-05-31 18:53:36 -0400579 rdev->config.cayman.tile_config |= 0 << 4;
Alex Deucher5b23c902012-07-31 11:05:11 -0400580 break;
581 case 1: /* eight banks */
582 rdev->config.cayman.tile_config |= 1 << 4;
583 break;
584 case 2: /* sixteen banks */
585 default:
586 rdev->config.cayman.tile_config |= 2 << 4;
587 break;
588 }
Alex Deucher29d65402012-05-31 18:53:36 -0400589 }
Alex Deucherfecf1d02011-03-02 20:07:29 -0500590 rdev->config.cayman.tile_config |=
Dave Airliecde50832011-05-19 14:14:41 +1000591 ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500592 rdev->config.cayman.tile_config |=
593 ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
594
Alex Deucher416a2bd2012-05-31 19:00:25 -0400595 tmp = 0;
596 for (i = (rdev->config.cayman.max_shader_engines - 1); i >= 0; i--) {
597 u32 rb_disable_bitmap;
598
599 WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
600 WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
601 rb_disable_bitmap = (RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000) >> 16;
602 tmp <<= 4;
603 tmp |= rb_disable_bitmap;
604 }
605 /* enabled rb are just the one not disabled :) */
606 disabled_rb_mask = tmp;
607
608 WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
609 WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
610
Alex Deucherfecf1d02011-03-02 20:07:29 -0500611 WREG32(GB_ADDR_CONFIG, gb_addr_config);
612 WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
613 WREG32(HDP_ADDR_CONFIG, gb_addr_config);
Alex Deucherf60cbd12012-12-04 15:27:33 -0500614 WREG32(DMA_TILING_CONFIG + DMA0_REGISTER_OFFSET, gb_addr_config);
615 WREG32(DMA_TILING_CONFIG + DMA1_REGISTER_OFFSET, gb_addr_config);
Alex Deucherfecf1d02011-03-02 20:07:29 -0500616
Alex Deucher416a2bd2012-05-31 19:00:25 -0400617 tmp = gb_addr_config & NUM_PIPES_MASK;
618 tmp = r6xx_remap_render_backend(rdev, tmp,
619 rdev->config.cayman.max_backends_per_se *
620 rdev->config.cayman.max_shader_engines,
621 CAYMAN_MAX_BACKENDS, disabled_rb_mask);
622 WREG32(GB_BACKEND_MAP, tmp);
Alex Deucherfecf1d02011-03-02 20:07:29 -0500623
Alex Deucher416a2bd2012-05-31 19:00:25 -0400624 cgts_tcc_disable = 0xffff0000;
625 for (i = 0; i < rdev->config.cayman.max_texture_channel_caches; i++)
626 cgts_tcc_disable &= ~(1 << (16 + i));
Alex Deucherfecf1d02011-03-02 20:07:29 -0500627 WREG32(CGTS_TCC_DISABLE, cgts_tcc_disable);
628 WREG32(CGTS_SYS_TCC_DISABLE, cgts_tcc_disable);
Alex Deucherfecf1d02011-03-02 20:07:29 -0500629 WREG32(CGTS_USER_SYS_TCC_DISABLE, cgts_tcc_disable);
630 WREG32(CGTS_USER_TCC_DISABLE, cgts_tcc_disable);
631
632 /* reprogram the shader complex */
633 cgts_sm_ctrl_reg = RREG32(CGTS_SM_CTRL_REG);
634 for (i = 0; i < 16; i++)
635 WREG32(CGTS_SM_CTRL_REG, OVERRIDE);
636 WREG32(CGTS_SM_CTRL_REG, cgts_sm_ctrl_reg);
637
638 /* set HW defaults for 3D engine */
639 WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
640
641 sx_debug_1 = RREG32(SX_DEBUG_1);
642 sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS;
643 WREG32(SX_DEBUG_1, sx_debug_1);
644
645 smx_dc_ctl0 = RREG32(SMX_DC_CTL0);
646 smx_dc_ctl0 &= ~NUMBER_OF_SETS(0x1ff);
Dave Airlie285e0422011-05-09 14:54:33 +1000647 smx_dc_ctl0 |= NUMBER_OF_SETS(rdev->config.cayman.sx_num_of_sets);
Alex Deucherfecf1d02011-03-02 20:07:29 -0500648 WREG32(SMX_DC_CTL0, smx_dc_ctl0);
649
650 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4) | CRC_SIMD_ID_WADDR_DISABLE);
651
652 /* need to be explicitly zero-ed */
653 WREG32(VGT_OFFCHIP_LDS_BASE, 0);
654 WREG32(SQ_LSTMP_RING_BASE, 0);
655 WREG32(SQ_HSTMP_RING_BASE, 0);
656 WREG32(SQ_ESTMP_RING_BASE, 0);
657 WREG32(SQ_GSTMP_RING_BASE, 0);
658 WREG32(SQ_VSTMP_RING_BASE, 0);
659 WREG32(SQ_PSTMP_RING_BASE, 0);
660
661 WREG32(TA_CNTL_AUX, DISABLE_CUBE_ANISO);
662
Dave Airlie285e0422011-05-09 14:54:33 +1000663 WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.cayman.sx_max_export_size / 4) - 1) |
664 POSITION_BUFFER_SIZE((rdev->config.cayman.sx_max_export_pos_size / 4) - 1) |
665 SMX_BUFFER_SIZE((rdev->config.cayman.sx_max_export_smx_size / 4) - 1)));
Alex Deucherfecf1d02011-03-02 20:07:29 -0500666
Dave Airlie285e0422011-05-09 14:54:33 +1000667 WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.cayman.sc_prim_fifo_size) |
668 SC_HIZ_TILE_FIFO_SIZE(rdev->config.cayman.sc_hiz_tile_fifo_size) |
669 SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.cayman.sc_earlyz_tile_fifo_size)));
Alex Deucherfecf1d02011-03-02 20:07:29 -0500670
671
672 WREG32(VGT_NUM_INSTANCES, 1);
673
674 WREG32(CP_PERFMON_CNTL, 0);
675
Dave Airlie285e0422011-05-09 14:54:33 +1000676 WREG32(SQ_MS_FIFO_SIZES, (CACHE_FIFO_SIZE(16 * rdev->config.cayman.sq_num_cf_insts) |
Alex Deucherfecf1d02011-03-02 20:07:29 -0500677 FETCH_FIFO_HIWATER(0x4) |
678 DONE_FIFO_HIWATER(0xe0) |
679 ALU_UPDATE_FIFO_HIWATER(0x8)));
680
681 WREG32(SQ_GPR_RESOURCE_MGMT_1, NUM_CLAUSE_TEMP_GPRS(4));
682 WREG32(SQ_CONFIG, (VC_ENABLE |
683 EXPORT_SRC_C |
684 GFX_PRIO(0) |
685 CS1_PRIO(0) |
686 CS2_PRIO(1)));
687 WREG32(SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, DYN_GPR_ENABLE);
688
689 WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
690 FORCE_EOV_MAX_REZ_CNT(255)));
691
692 WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
693 AUTO_INVLD_EN(ES_AND_GS_AUTO));
694
695 WREG32(VGT_GS_VERTEX_REUSE, 16);
696 WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
697
698 WREG32(CB_PERF_CTR0_SEL_0, 0);
699 WREG32(CB_PERF_CTR0_SEL_1, 0);
700 WREG32(CB_PERF_CTR1_SEL_0, 0);
701 WREG32(CB_PERF_CTR1_SEL_1, 0);
702 WREG32(CB_PERF_CTR2_SEL_0, 0);
703 WREG32(CB_PERF_CTR2_SEL_1, 0);
704 WREG32(CB_PERF_CTR3_SEL_0, 0);
705 WREG32(CB_PERF_CTR3_SEL_1, 0);
706
Dave Airlie0b65f832011-05-19 14:14:42 +1000707 tmp = RREG32(HDP_MISC_CNTL);
708 tmp |= HDP_FLUSH_INVALIDATE_CACHE;
709 WREG32(HDP_MISC_CNTL, tmp);
710
Alex Deucherfecf1d02011-03-02 20:07:29 -0500711 hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
712 WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
713
714 WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
715
716 udelay(50);
717}
718
Alex Deucherfa8198e2011-03-02 20:07:30 -0500719/*
720 * GART
721 */
722void cayman_pcie_gart_tlb_flush(struct radeon_device *rdev)
723{
724 /* flush hdp cache */
725 WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
726
727 /* bits 0-7 are the VM contexts0-7 */
728 WREG32(VM_INVALIDATE_REQUEST, 1);
729}
730
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400731static int cayman_pcie_gart_enable(struct radeon_device *rdev)
Alex Deucherfa8198e2011-03-02 20:07:30 -0500732{
Jerome Glisse721604a2012-01-05 22:11:05 -0500733 int i, r;
Alex Deucherfa8198e2011-03-02 20:07:30 -0500734
Jerome Glissec9a1be92011-11-03 11:16:49 -0400735 if (rdev->gart.robj == NULL) {
Alex Deucherfa8198e2011-03-02 20:07:30 -0500736 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
737 return -EINVAL;
738 }
739 r = radeon_gart_table_vram_pin(rdev);
740 if (r)
741 return r;
742 radeon_gart_restore(rdev);
743 /* Setup TLB control */
Jerome Glisse721604a2012-01-05 22:11:05 -0500744 WREG32(MC_VM_MX_L1_TLB_CNTL,
745 (0xA << 7) |
746 ENABLE_L1_TLB |
Alex Deucherfa8198e2011-03-02 20:07:30 -0500747 ENABLE_L1_FRAGMENT_PROCESSING |
748 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
Jerome Glisse721604a2012-01-05 22:11:05 -0500749 ENABLE_ADVANCED_DRIVER_MODEL |
Alex Deucherfa8198e2011-03-02 20:07:30 -0500750 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
751 /* Setup L2 cache */
752 WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
753 ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
754 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
755 EFFECTIVE_L2_QUEUE_SIZE(7) |
756 CONTEXT1_IDENTITY_ACCESS_MODE(1));
757 WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
758 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
759 L2_CACHE_BIGK_FRAGMENT_SIZE(6));
760 /* setup context0 */
761 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
762 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
763 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
764 WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
765 (u32)(rdev->dummy_page.addr >> 12));
766 WREG32(VM_CONTEXT0_CNTL2, 0);
767 WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
768 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
Jerome Glisse721604a2012-01-05 22:11:05 -0500769
770 WREG32(0x15D4, 0);
771 WREG32(0x15D8, 0);
772 WREG32(0x15DC, 0);
773
774 /* empty context1-7 */
Alex Deucher23d4f1f2012-10-08 09:45:46 -0400775 /* Assign the pt base to something valid for now; the pts used for
776 * the VMs are determined by the application and setup and assigned
777 * on the fly in the vm part of radeon_gart.c
778 */
Jerome Glisse721604a2012-01-05 22:11:05 -0500779 for (i = 1; i < 8; i++) {
780 WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR + (i << 2), 0);
Alex Deucherc1a7ca02012-10-08 12:15:13 -0400781 WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR + (i << 2), rdev->vm_manager.max_pfn);
Jerome Glisse721604a2012-01-05 22:11:05 -0500782 WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
783 rdev->gart.table_addr >> 12);
784 }
785
786 /* enable context1-7 */
787 WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
788 (u32)(rdev->dummy_page.addr >> 12));
Christian Königae133a12012-09-18 15:30:44 -0400789 WREG32(VM_CONTEXT1_CNTL2, 4);
Dmitry Cherkasovfa87e622012-09-17 19:36:19 +0200790 WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
Christian Königae133a12012-09-18 15:30:44 -0400791 RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
792 RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
793 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
794 DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
795 PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
796 PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
797 VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
798 VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
799 READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
800 READ_PROTECTION_FAULT_ENABLE_DEFAULT |
801 WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
802 WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
Alex Deucherfa8198e2011-03-02 20:07:30 -0500803
804 cayman_pcie_gart_tlb_flush(rdev);
Tormod Voldenfcf4de52011-08-31 21:54:07 +0000805 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
806 (unsigned)(rdev->mc.gtt_size >> 20),
807 (unsigned long long)rdev->gart.table_addr);
Alex Deucherfa8198e2011-03-02 20:07:30 -0500808 rdev->gart.ready = true;
809 return 0;
810}
811
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400812static void cayman_pcie_gart_disable(struct radeon_device *rdev)
Alex Deucherfa8198e2011-03-02 20:07:30 -0500813{
Alex Deucherfa8198e2011-03-02 20:07:30 -0500814 /* Disable all tables */
815 WREG32(VM_CONTEXT0_CNTL, 0);
816 WREG32(VM_CONTEXT1_CNTL, 0);
817 /* Setup TLB control */
818 WREG32(MC_VM_MX_L1_TLB_CNTL, ENABLE_L1_FRAGMENT_PROCESSING |
819 SYSTEM_ACCESS_MODE_NOT_IN_SYS |
820 SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
821 /* Setup L2 cache */
822 WREG32(VM_L2_CNTL, ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
823 ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
824 EFFECTIVE_L2_QUEUE_SIZE(7) |
825 CONTEXT1_IDENTITY_ACCESS_MODE(1));
826 WREG32(VM_L2_CNTL2, 0);
827 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
828 L2_CACHE_BIGK_FRAGMENT_SIZE(6));
Jerome Glissec9a1be92011-11-03 11:16:49 -0400829 radeon_gart_table_vram_unpin(rdev);
Alex Deucherfa8198e2011-03-02 20:07:30 -0500830}
831
Lauri Kasanen1109ca02012-08-31 13:43:50 -0400832static void cayman_pcie_gart_fini(struct radeon_device *rdev)
Alex Deucherfa8198e2011-03-02 20:07:30 -0500833{
834 cayman_pcie_gart_disable(rdev);
835 radeon_gart_table_vram_free(rdev);
836 radeon_gart_fini(rdev);
837}
838
Alex Deucher1b370782011-11-17 20:13:28 -0500839void cayman_cp_int_cntl_setup(struct radeon_device *rdev,
840 int ring, u32 cp_int_cntl)
841{
842 u32 srbm_gfx_cntl = RREG32(SRBM_GFX_CNTL) & ~3;
843
844 WREG32(SRBM_GFX_CNTL, srbm_gfx_cntl | (ring & 3));
845 WREG32(CP_INT_CNTL, cp_int_cntl);
846}
847
Alex Deucher0c88a022011-03-02 20:07:31 -0500848/*
849 * CP.
850 */
Alex Deucherb40e7e12011-11-17 14:57:50 -0500851void cayman_fence_ring_emit(struct radeon_device *rdev,
852 struct radeon_fence *fence)
853{
854 struct radeon_ring *ring = &rdev->ring[fence->ring];
855 u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
856
Jerome Glisse721604a2012-01-05 22:11:05 -0500857 /* flush read cache over gart for this vmid */
858 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
859 radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
860 radeon_ring_write(ring, 0);
Alex Deucherb40e7e12011-11-17 14:57:50 -0500861 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
862 radeon_ring_write(ring, PACKET3_TC_ACTION_ENA | PACKET3_SH_ACTION_ENA);
863 radeon_ring_write(ring, 0xFFFFFFFF);
864 radeon_ring_write(ring, 0);
865 radeon_ring_write(ring, 10); /* poll interval */
866 /* EVENT_WRITE_EOP - flush caches, send int */
867 radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
868 radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5));
869 radeon_ring_write(ring, addr & 0xffffffff);
870 radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
871 radeon_ring_write(ring, fence->seq);
872 radeon_ring_write(ring, 0);
873}
874
Jerome Glisse721604a2012-01-05 22:11:05 -0500875void cayman_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
876{
Christian König876dc9f2012-05-08 14:24:01 +0200877 struct radeon_ring *ring = &rdev->ring[ib->ring];
Jerome Glisse721604a2012-01-05 22:11:05 -0500878
879 /* set to DX10/11 mode */
880 radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0));
881 radeon_ring_write(ring, 1);
Christian König45df6802012-07-06 16:22:55 +0200882
883 if (ring->rptr_save_reg) {
884 uint32_t next_rptr = ring->wptr + 3 + 4 + 8;
885 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
886 radeon_ring_write(ring, ((ring->rptr_save_reg -
887 PACKET3_SET_CONFIG_REG_START) >> 2));
888 radeon_ring_write(ring, next_rptr);
889 }
890
Jerome Glisse721604a2012-01-05 22:11:05 -0500891 radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
892 radeon_ring_write(ring,
893#ifdef __BIG_ENDIAN
894 (2 << 0) |
895#endif
896 (ib->gpu_addr & 0xFFFFFFFC));
897 radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
Christian König4bf3dd92012-08-06 18:57:44 +0200898 radeon_ring_write(ring, ib->length_dw |
899 (ib->vm ? (ib->vm->id << 24) : 0));
Jerome Glisse721604a2012-01-05 22:11:05 -0500900
901 /* flush read cache over gart for this vmid */
902 radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
903 radeon_ring_write(ring, (CP_COHER_CNTL2 - PACKET3_SET_CONFIG_REG_START) >> 2);
Christian König4bf3dd92012-08-06 18:57:44 +0200904 radeon_ring_write(ring, ib->vm ? ib->vm->id : 0);
Jerome Glisse721604a2012-01-05 22:11:05 -0500905 radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
906 radeon_ring_write(ring, PACKET3_TC_ACTION_ENA | PACKET3_SH_ACTION_ENA);
907 radeon_ring_write(ring, 0xFFFFFFFF);
908 radeon_ring_write(ring, 0);
909 radeon_ring_write(ring, 10); /* poll interval */
910}
911
Alex Deucher0c88a022011-03-02 20:07:31 -0500912static void cayman_cp_enable(struct radeon_device *rdev, bool enable)
913{
914 if (enable)
915 WREG32(CP_ME_CNTL, 0);
916 else {
Dave Airlie38f1cff2011-03-16 11:34:41 +1000917 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
Alex Deucher0c88a022011-03-02 20:07:31 -0500918 WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT));
919 WREG32(SCRATCH_UMSK, 0);
Alex Deucherf60cbd12012-12-04 15:27:33 -0500920 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
Alex Deucher0c88a022011-03-02 20:07:31 -0500921 }
922}
923
924static int cayman_cp_load_microcode(struct radeon_device *rdev)
925{
926 const __be32 *fw_data;
927 int i;
928
929 if (!rdev->me_fw || !rdev->pfp_fw)
930 return -EINVAL;
931
932 cayman_cp_enable(rdev, false);
933
934 fw_data = (const __be32 *)rdev->pfp_fw->data;
935 WREG32(CP_PFP_UCODE_ADDR, 0);
936 for (i = 0; i < CAYMAN_PFP_UCODE_SIZE; i++)
937 WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
938 WREG32(CP_PFP_UCODE_ADDR, 0);
939
940 fw_data = (const __be32 *)rdev->me_fw->data;
941 WREG32(CP_ME_RAM_WADDR, 0);
942 for (i = 0; i < CAYMAN_PM4_UCODE_SIZE; i++)
943 WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
944
945 WREG32(CP_PFP_UCODE_ADDR, 0);
946 WREG32(CP_ME_RAM_WADDR, 0);
947 WREG32(CP_ME_RAM_RADDR, 0);
948 return 0;
949}
950
951static int cayman_cp_start(struct radeon_device *rdev)
952{
Christian Könige32eb502011-10-23 12:56:27 +0200953 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucher0c88a022011-03-02 20:07:31 -0500954 int r, i;
955
Christian Könige32eb502011-10-23 12:56:27 +0200956 r = radeon_ring_lock(rdev, ring, 7);
Alex Deucher0c88a022011-03-02 20:07:31 -0500957 if (r) {
958 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
959 return r;
960 }
Christian Könige32eb502011-10-23 12:56:27 +0200961 radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
962 radeon_ring_write(ring, 0x1);
963 radeon_ring_write(ring, 0x0);
964 radeon_ring_write(ring, rdev->config.cayman.max_hw_contexts - 1);
965 radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
966 radeon_ring_write(ring, 0);
967 radeon_ring_write(ring, 0);
968 radeon_ring_unlock_commit(rdev, ring);
Alex Deucher0c88a022011-03-02 20:07:31 -0500969
970 cayman_cp_enable(rdev, true);
971
Christian Könige32eb502011-10-23 12:56:27 +0200972 r = radeon_ring_lock(rdev, ring, cayman_default_size + 19);
Alex Deucher0c88a022011-03-02 20:07:31 -0500973 if (r) {
974 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
975 return r;
976 }
977
978 /* setup clear context state */
Christian Könige32eb502011-10-23 12:56:27 +0200979 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
980 radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
Alex Deucher0c88a022011-03-02 20:07:31 -0500981
982 for (i = 0; i < cayman_default_size; i++)
Christian Könige32eb502011-10-23 12:56:27 +0200983 radeon_ring_write(ring, cayman_default_state[i]);
Alex Deucher0c88a022011-03-02 20:07:31 -0500984
Christian Könige32eb502011-10-23 12:56:27 +0200985 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
986 radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
Alex Deucher0c88a022011-03-02 20:07:31 -0500987
988 /* set clear context state */
Christian Könige32eb502011-10-23 12:56:27 +0200989 radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
990 radeon_ring_write(ring, 0);
Alex Deucher0c88a022011-03-02 20:07:31 -0500991
992 /* SQ_VTX_BASE_VTX_LOC */
Christian Könige32eb502011-10-23 12:56:27 +0200993 radeon_ring_write(ring, 0xc0026f00);
994 radeon_ring_write(ring, 0x00000000);
995 radeon_ring_write(ring, 0x00000000);
996 radeon_ring_write(ring, 0x00000000);
Alex Deucher0c88a022011-03-02 20:07:31 -0500997
998 /* Clear consts */
Christian Könige32eb502011-10-23 12:56:27 +0200999 radeon_ring_write(ring, 0xc0036f00);
1000 radeon_ring_write(ring, 0x00000bc4);
1001 radeon_ring_write(ring, 0xffffffff);
1002 radeon_ring_write(ring, 0xffffffff);
1003 radeon_ring_write(ring, 0xffffffff);
Alex Deucher0c88a022011-03-02 20:07:31 -05001004
Christian Könige32eb502011-10-23 12:56:27 +02001005 radeon_ring_write(ring, 0xc0026900);
1006 radeon_ring_write(ring, 0x00000316);
1007 radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
1008 radeon_ring_write(ring, 0x00000010); /* */
Alex Deucher9b91d182011-03-02 20:07:39 -05001009
Christian Könige32eb502011-10-23 12:56:27 +02001010 radeon_ring_unlock_commit(rdev, ring);
Alex Deucher0c88a022011-03-02 20:07:31 -05001011
1012 /* XXX init other rings */
1013
1014 return 0;
1015}
1016
Alex Deucher755d8192011-03-02 20:07:34 -05001017static void cayman_cp_fini(struct radeon_device *rdev)
1018{
Christian König45df6802012-07-06 16:22:55 +02001019 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucher755d8192011-03-02 20:07:34 -05001020 cayman_cp_enable(rdev, false);
Christian König45df6802012-07-06 16:22:55 +02001021 radeon_ring_fini(rdev, ring);
1022 radeon_scratch_free(rdev, ring->rptr_save_reg);
Alex Deucher755d8192011-03-02 20:07:34 -05001023}
1024
Lauri Kasanen1109ca02012-08-31 13:43:50 -04001025static int cayman_cp_resume(struct radeon_device *rdev)
Alex Deucher0c88a022011-03-02 20:07:31 -05001026{
Christian Königb90ca982012-07-04 21:36:53 +02001027 static const int ridx[] = {
1028 RADEON_RING_TYPE_GFX_INDEX,
1029 CAYMAN_RING_TYPE_CP1_INDEX,
1030 CAYMAN_RING_TYPE_CP2_INDEX
1031 };
1032 static const unsigned cp_rb_cntl[] = {
1033 CP_RB0_CNTL,
1034 CP_RB1_CNTL,
1035 CP_RB2_CNTL,
1036 };
1037 static const unsigned cp_rb_rptr_addr[] = {
1038 CP_RB0_RPTR_ADDR,
1039 CP_RB1_RPTR_ADDR,
1040 CP_RB2_RPTR_ADDR
1041 };
1042 static const unsigned cp_rb_rptr_addr_hi[] = {
1043 CP_RB0_RPTR_ADDR_HI,
1044 CP_RB1_RPTR_ADDR_HI,
1045 CP_RB2_RPTR_ADDR_HI
1046 };
1047 static const unsigned cp_rb_base[] = {
1048 CP_RB0_BASE,
1049 CP_RB1_BASE,
1050 CP_RB2_BASE
1051 };
Christian Könige32eb502011-10-23 12:56:27 +02001052 struct radeon_ring *ring;
Christian Königb90ca982012-07-04 21:36:53 +02001053 int i, r;
Alex Deucher0c88a022011-03-02 20:07:31 -05001054
1055 /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */
1056 WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP |
1057 SOFT_RESET_PA |
1058 SOFT_RESET_SH |
1059 SOFT_RESET_VGT |
Jerome Glissea49a50d2011-08-24 20:00:17 +00001060 SOFT_RESET_SPI |
Alex Deucher0c88a022011-03-02 20:07:31 -05001061 SOFT_RESET_SX));
1062 RREG32(GRBM_SOFT_RESET);
1063 mdelay(15);
1064 WREG32(GRBM_SOFT_RESET, 0);
1065 RREG32(GRBM_SOFT_RESET);
1066
Christian König15d33322011-09-15 19:02:22 +02001067 WREG32(CP_SEM_WAIT_TIMER, 0x0);
Alex Deucher11ef3f1f2012-01-20 14:47:43 -05001068 WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
Alex Deucher0c88a022011-03-02 20:07:31 -05001069
1070 /* Set the write pointer delay */
1071 WREG32(CP_RB_WPTR_DELAY, 0);
1072
1073 WREG32(CP_DEBUG, (1 << 27));
1074
Adam Buchbinder48fc7f72012-09-19 21:48:00 -04001075 /* set the wb address whether it's enabled or not */
Alex Deucher0c88a022011-03-02 20:07:31 -05001076 WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
Christian Königb90ca982012-07-04 21:36:53 +02001077 WREG32(SCRATCH_UMSK, 0xff);
Alex Deucher0c88a022011-03-02 20:07:31 -05001078
Christian Königb90ca982012-07-04 21:36:53 +02001079 for (i = 0; i < 3; ++i) {
1080 uint32_t rb_cntl;
1081 uint64_t addr;
1082
1083 /* Set ring buffer size */
1084 ring = &rdev->ring[ridx[i]];
1085 rb_cntl = drm_order(ring->ring_size / 8);
1086 rb_cntl |= drm_order(RADEON_GPU_PAGE_SIZE/8) << 8;
1087#ifdef __BIG_ENDIAN
1088 rb_cntl |= BUF_SWAP_32BIT;
1089#endif
1090 WREG32(cp_rb_cntl[i], rb_cntl);
1091
Adam Buchbinder48fc7f72012-09-19 21:48:00 -04001092 /* set the wb address whether it's enabled or not */
Christian Königb90ca982012-07-04 21:36:53 +02001093 addr = rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET;
1094 WREG32(cp_rb_rptr_addr[i], addr & 0xFFFFFFFC);
1095 WREG32(cp_rb_rptr_addr_hi[i], upper_32_bits(addr) & 0xFF);
Alex Deucher0c88a022011-03-02 20:07:31 -05001096 }
1097
Christian Königb90ca982012-07-04 21:36:53 +02001098 /* set the rb base addr, this causes an internal reset of ALL rings */
1099 for (i = 0; i < 3; ++i) {
1100 ring = &rdev->ring[ridx[i]];
1101 WREG32(cp_rb_base[i], ring->gpu_addr >> 8);
1102 }
Alex Deucher0c88a022011-03-02 20:07:31 -05001103
Christian Königb90ca982012-07-04 21:36:53 +02001104 for (i = 0; i < 3; ++i) {
1105 /* Initialize the ring buffer's read and write pointers */
1106 ring = &rdev->ring[ridx[i]];
1107 WREG32_P(cp_rb_cntl[i], RB_RPTR_WR_ENA, ~RB_RPTR_WR_ENA);
Alex Deucher0c88a022011-03-02 20:07:31 -05001108
Christian Königb90ca982012-07-04 21:36:53 +02001109 ring->rptr = ring->wptr = 0;
1110 WREG32(ring->rptr_reg, ring->rptr);
1111 WREG32(ring->wptr_reg, ring->wptr);
Alex Deucher0c88a022011-03-02 20:07:31 -05001112
Christian Königb90ca982012-07-04 21:36:53 +02001113 mdelay(1);
1114 WREG32_P(cp_rb_cntl[i], 0, ~RB_RPTR_WR_ENA);
1115 }
Alex Deucher0c88a022011-03-02 20:07:31 -05001116
1117 /* start the rings */
1118 cayman_cp_start(rdev);
Christian Könige32eb502011-10-23 12:56:27 +02001119 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
1120 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
1121 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
Alex Deucher0c88a022011-03-02 20:07:31 -05001122 /* this only test cp0 */
Alex Deucherf7128122012-02-23 17:53:45 -05001123 r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
Alex Deucher0c88a022011-03-02 20:07:31 -05001124 if (r) {
Christian Könige32eb502011-10-23 12:56:27 +02001125 rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
1126 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
1127 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
Alex Deucher0c88a022011-03-02 20:07:31 -05001128 return r;
1129 }
1130
1131 return 0;
1132}
1133
Alex Deucherf60cbd12012-12-04 15:27:33 -05001134/*
1135 * DMA
1136 * Starting with R600, the GPU has an asynchronous
1137 * DMA engine. The programming model is very similar
1138 * to the 3D engine (ring buffer, IBs, etc.), but the
1139 * DMA controller has it's own packet format that is
1140 * different form the PM4 format used by the 3D engine.
1141 * It supports copying data, writing embedded data,
1142 * solid fills, and a number of other things. It also
1143 * has support for tiling/detiling of buffers.
1144 * Cayman and newer support two asynchronous DMA engines.
1145 */
1146/**
1147 * cayman_dma_ring_ib_execute - Schedule an IB on the DMA engine
1148 *
1149 * @rdev: radeon_device pointer
1150 * @ib: IB object to schedule
1151 *
1152 * Schedule an IB in the DMA ring (cayman-SI).
1153 */
1154void cayman_dma_ring_ib_execute(struct radeon_device *rdev,
1155 struct radeon_ib *ib)
1156{
1157 struct radeon_ring *ring = &rdev->ring[ib->ring];
1158
1159 if (rdev->wb.enabled) {
1160 u32 next_rptr = ring->wptr + 4;
1161 while ((next_rptr & 7) != 5)
1162 next_rptr++;
1163 next_rptr += 3;
1164 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 1));
1165 radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
1166 radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr) & 0xff);
1167 radeon_ring_write(ring, next_rptr);
1168 }
1169
1170 /* The indirect buffer packet must end on an 8 DW boundary in the DMA ring.
1171 * Pad as necessary with NOPs.
1172 */
1173 while ((ring->wptr & 7) != 5)
1174 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
1175 radeon_ring_write(ring, DMA_IB_PACKET(DMA_PACKET_INDIRECT_BUFFER, ib->vm ? ib->vm->id : 0, 0));
1176 radeon_ring_write(ring, (ib->gpu_addr & 0xFFFFFFE0));
1177 radeon_ring_write(ring, (ib->length_dw << 12) | (upper_32_bits(ib->gpu_addr) & 0xFF));
1178
1179}
1180
1181/**
1182 * cayman_dma_stop - stop the async dma engines
1183 *
1184 * @rdev: radeon_device pointer
1185 *
1186 * Stop the async dma engines (cayman-SI).
1187 */
1188void cayman_dma_stop(struct radeon_device *rdev)
1189{
1190 u32 rb_cntl;
1191
1192 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
1193
1194 /* dma0 */
1195 rb_cntl = RREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET);
1196 rb_cntl &= ~DMA_RB_ENABLE;
1197 WREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET, rb_cntl);
1198
1199 /* dma1 */
1200 rb_cntl = RREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET);
1201 rb_cntl &= ~DMA_RB_ENABLE;
1202 WREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET, rb_cntl);
1203
1204 rdev->ring[R600_RING_TYPE_DMA_INDEX].ready = false;
1205 rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX].ready = false;
1206}
1207
1208/**
1209 * cayman_dma_resume - setup and start the async dma engines
1210 *
1211 * @rdev: radeon_device pointer
1212 *
1213 * Set up the DMA ring buffers and enable them. (cayman-SI).
1214 * Returns 0 for success, error for failure.
1215 */
1216int cayman_dma_resume(struct radeon_device *rdev)
1217{
1218 struct radeon_ring *ring;
1219 u32 rb_cntl, dma_cntl;
1220 u32 rb_bufsz;
1221 u32 reg_offset, wb_offset;
1222 int i, r;
1223
1224 /* Reset dma */
1225 WREG32(SRBM_SOFT_RESET, SOFT_RESET_DMA | SOFT_RESET_DMA1);
1226 RREG32(SRBM_SOFT_RESET);
1227 udelay(50);
1228 WREG32(SRBM_SOFT_RESET, 0);
1229
1230 for (i = 0; i < 2; i++) {
1231 if (i == 0) {
1232 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
1233 reg_offset = DMA0_REGISTER_OFFSET;
1234 wb_offset = R600_WB_DMA_RPTR_OFFSET;
1235 } else {
1236 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
1237 reg_offset = DMA1_REGISTER_OFFSET;
1238 wb_offset = CAYMAN_WB_DMA1_RPTR_OFFSET;
1239 }
1240
1241 WREG32(DMA_SEM_INCOMPLETE_TIMER_CNTL + reg_offset, 0);
1242 WREG32(DMA_SEM_WAIT_FAIL_TIMER_CNTL + reg_offset, 0);
1243
1244 /* Set ring buffer size in dwords */
1245 rb_bufsz = drm_order(ring->ring_size / 4);
1246 rb_cntl = rb_bufsz << 1;
1247#ifdef __BIG_ENDIAN
1248 rb_cntl |= DMA_RB_SWAP_ENABLE | DMA_RPTR_WRITEBACK_SWAP_ENABLE;
1249#endif
1250 WREG32(DMA_RB_CNTL + reg_offset, rb_cntl);
1251
1252 /* Initialize the ring buffer's read and write pointers */
1253 WREG32(DMA_RB_RPTR + reg_offset, 0);
1254 WREG32(DMA_RB_WPTR + reg_offset, 0);
1255
1256 /* set the wb address whether it's enabled or not */
1257 WREG32(DMA_RB_RPTR_ADDR_HI + reg_offset,
1258 upper_32_bits(rdev->wb.gpu_addr + wb_offset) & 0xFF);
1259 WREG32(DMA_RB_RPTR_ADDR_LO + reg_offset,
1260 ((rdev->wb.gpu_addr + wb_offset) & 0xFFFFFFFC));
1261
1262 if (rdev->wb.enabled)
1263 rb_cntl |= DMA_RPTR_WRITEBACK_ENABLE;
1264
1265 WREG32(DMA_RB_BASE + reg_offset, ring->gpu_addr >> 8);
1266
1267 /* enable DMA IBs */
1268 WREG32(DMA_IB_CNTL + reg_offset, DMA_IB_ENABLE | CMD_VMID_FORCE);
1269
1270 dma_cntl = RREG32(DMA_CNTL + reg_offset);
1271 dma_cntl &= ~CTXEMPTY_INT_ENABLE;
1272 WREG32(DMA_CNTL + reg_offset, dma_cntl);
1273
1274 ring->wptr = 0;
1275 WREG32(DMA_RB_WPTR + reg_offset, ring->wptr << 2);
1276
1277 ring->rptr = RREG32(DMA_RB_RPTR + reg_offset) >> 2;
1278
1279 WREG32(DMA_RB_CNTL + reg_offset, rb_cntl | DMA_RB_ENABLE);
1280
1281 ring->ready = true;
1282
1283 r = radeon_ring_test(rdev, ring->idx, ring);
1284 if (r) {
1285 ring->ready = false;
1286 return r;
1287 }
1288 }
1289
1290 radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
1291
1292 return 0;
1293}
1294
1295/**
1296 * cayman_dma_fini - tear down the async dma engines
1297 *
1298 * @rdev: radeon_device pointer
1299 *
1300 * Stop the async dma engines and free the rings (cayman-SI).
1301 */
1302void cayman_dma_fini(struct radeon_device *rdev)
1303{
1304 cayman_dma_stop(rdev);
1305 radeon_ring_fini(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX]);
1306 radeon_ring_fini(rdev, &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX]);
1307}
1308
Alex Deucherb9952a82011-03-02 20:07:33 -05001309static int cayman_gpu_soft_reset(struct radeon_device *rdev)
1310{
1311 struct evergreen_mc_save save;
Jerome Glisse64c56e82013-01-02 17:30:35 -05001312 u32 grbm_reset = 0, tmp;
Alex Deucherb9952a82011-03-02 20:07:33 -05001313
1314 if (!(RREG32(GRBM_STATUS) & GUI_ACTIVE))
1315 return 0;
1316
1317 dev_info(rdev->dev, "GPU softreset \n");
Jerome Glisse64c56e82013-01-02 17:30:35 -05001318 dev_info(rdev->dev, " GRBM_STATUS = 0x%08X\n",
Alex Deucherb9952a82011-03-02 20:07:33 -05001319 RREG32(GRBM_STATUS));
Jerome Glisse64c56e82013-01-02 17:30:35 -05001320 dev_info(rdev->dev, " GRBM_STATUS_SE0 = 0x%08X\n",
Alex Deucherb9952a82011-03-02 20:07:33 -05001321 RREG32(GRBM_STATUS_SE0));
Jerome Glisse64c56e82013-01-02 17:30:35 -05001322 dev_info(rdev->dev, " GRBM_STATUS_SE1 = 0x%08X\n",
Alex Deucherb9952a82011-03-02 20:07:33 -05001323 RREG32(GRBM_STATUS_SE1));
Jerome Glisse64c56e82013-01-02 17:30:35 -05001324 dev_info(rdev->dev, " SRBM_STATUS = 0x%08X\n",
Alex Deucherb9952a82011-03-02 20:07:33 -05001325 RREG32(SRBM_STATUS));
Jerome Glisse440a7cd2012-06-27 12:25:01 -04001326 dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n",
1327 RREG32(CP_STALLED_STAT1));
1328 dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n",
1329 RREG32(CP_STALLED_STAT2));
1330 dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n",
1331 RREG32(CP_BUSY_STAT));
1332 dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n",
1333 RREG32(CP_STAT));
Jerome Glisseeaaa6982013-01-02 15:12:15 -05001334 dev_info(rdev->dev, " R_00D034_DMA_STATUS_REG = 0x%08X\n",
1335 RREG32(DMA_STATUS_REG));
Jerome Glisse721604a2012-01-05 22:11:05 -05001336 dev_info(rdev->dev, " VM_CONTEXT0_PROTECTION_FAULT_ADDR 0x%08X\n",
1337 RREG32(0x14F8));
1338 dev_info(rdev->dev, " VM_CONTEXT0_PROTECTION_FAULT_STATUS 0x%08X\n",
1339 RREG32(0x14D8));
1340 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
1341 RREG32(0x14FC));
1342 dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
1343 RREG32(0x14DC));
1344
Alex Deucherb9952a82011-03-02 20:07:33 -05001345 evergreen_mc_stop(rdev, &save);
1346 if (evergreen_mc_wait_for_idle(rdev)) {
1347 dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
1348 }
Jerome Glisse64c56e82013-01-02 17:30:35 -05001349
Alex Deucherb9952a82011-03-02 20:07:33 -05001350 /* Disable CP parsing/prefetching */
1351 WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT);
1352
Jerome Glisse64c56e82013-01-02 17:30:35 -05001353 /* dma0 */
1354 tmp = RREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET);
1355 tmp &= ~DMA_RB_ENABLE;
1356 WREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET, tmp);
1357
1358 /* dma1 */
1359 tmp = RREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET);
1360 tmp &= ~DMA_RB_ENABLE;
1361 WREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET, tmp);
1362
1363 /* Reset dma */
1364 WREG32(SRBM_SOFT_RESET, SOFT_RESET_DMA | SOFT_RESET_DMA1);
1365 RREG32(SRBM_SOFT_RESET);
1366 udelay(50);
1367 WREG32(SRBM_SOFT_RESET, 0);
1368
Alex Deucherb9952a82011-03-02 20:07:33 -05001369 /* reset all the gfx blocks */
1370 grbm_reset = (SOFT_RESET_CP |
1371 SOFT_RESET_CB |
1372 SOFT_RESET_DB |
1373 SOFT_RESET_GDS |
1374 SOFT_RESET_PA |
1375 SOFT_RESET_SC |
1376 SOFT_RESET_SPI |
1377 SOFT_RESET_SH |
1378 SOFT_RESET_SX |
1379 SOFT_RESET_TC |
1380 SOFT_RESET_TA |
1381 SOFT_RESET_VGT |
1382 SOFT_RESET_IA);
1383
1384 dev_info(rdev->dev, " GRBM_SOFT_RESET=0x%08X\n", grbm_reset);
1385 WREG32(GRBM_SOFT_RESET, grbm_reset);
1386 (void)RREG32(GRBM_SOFT_RESET);
1387 udelay(50);
1388 WREG32(GRBM_SOFT_RESET, 0);
1389 (void)RREG32(GRBM_SOFT_RESET);
1390 /* Wait a little for things to settle down */
1391 udelay(50);
Jerome Glisse721604a2012-01-05 22:11:05 -05001392
Jerome Glisse64c56e82013-01-02 17:30:35 -05001393 dev_info(rdev->dev, " GRBM_STATUS = 0x%08X\n",
Alex Deucherb9952a82011-03-02 20:07:33 -05001394 RREG32(GRBM_STATUS));
Jerome Glisse64c56e82013-01-02 17:30:35 -05001395 dev_info(rdev->dev, " GRBM_STATUS_SE0 = 0x%08X\n",
Alex Deucherb9952a82011-03-02 20:07:33 -05001396 RREG32(GRBM_STATUS_SE0));
Jerome Glisse64c56e82013-01-02 17:30:35 -05001397 dev_info(rdev->dev, " GRBM_STATUS_SE1 = 0x%08X\n",
Alex Deucherb9952a82011-03-02 20:07:33 -05001398 RREG32(GRBM_STATUS_SE1));
Jerome Glisse64c56e82013-01-02 17:30:35 -05001399 dev_info(rdev->dev, " SRBM_STATUS = 0x%08X\n",
Alex Deucherb9952a82011-03-02 20:07:33 -05001400 RREG32(SRBM_STATUS));
Jerome Glisse440a7cd2012-06-27 12:25:01 -04001401 dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n",
1402 RREG32(CP_STALLED_STAT1));
1403 dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n",
1404 RREG32(CP_STALLED_STAT2));
1405 dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n",
1406 RREG32(CP_BUSY_STAT));
1407 dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n",
1408 RREG32(CP_STAT));
Jerome Glisseeaaa6982013-01-02 15:12:15 -05001409 dev_info(rdev->dev, " R_00D034_DMA_STATUS_REG = 0x%08X\n",
1410 RREG32(DMA_STATUS_REG));
Alex Deucherb9952a82011-03-02 20:07:33 -05001411 evergreen_mc_resume(rdev, &save);
1412 return 0;
1413}
1414
1415int cayman_asic_reset(struct radeon_device *rdev)
1416{
1417 return cayman_gpu_soft_reset(rdev);
1418}
1419
Alex Deucherf60cbd12012-12-04 15:27:33 -05001420/**
1421 * cayman_dma_is_lockup - Check if the DMA engine is locked up
1422 *
1423 * @rdev: radeon_device pointer
1424 * @ring: radeon_ring structure holding ring information
1425 *
1426 * Check if the async DMA engine is locked up (cayman-SI).
1427 * Returns true if the engine appears to be locked up, false if not.
1428 */
1429bool cayman_dma_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
1430{
1431 u32 dma_status_reg;
1432
1433 if (ring->idx == R600_RING_TYPE_DMA_INDEX)
1434 dma_status_reg = RREG32(DMA_STATUS_REG + DMA0_REGISTER_OFFSET);
1435 else
1436 dma_status_reg = RREG32(DMA_STATUS_REG + DMA1_REGISTER_OFFSET);
1437 if (dma_status_reg & DMA_IDLE) {
1438 radeon_ring_lockup_update(ring);
1439 return false;
1440 }
1441 /* force ring activities */
1442 radeon_ring_force_activity(rdev, ring);
1443 return radeon_ring_test_lockup(rdev, ring);
1444}
1445
Alex Deucher755d8192011-03-02 20:07:34 -05001446static int cayman_startup(struct radeon_device *rdev)
1447{
Christian Könige32eb502011-10-23 12:56:27 +02001448 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucher755d8192011-03-02 20:07:34 -05001449 int r;
1450
Ilija Hadzicb07759b2011-09-20 10:22:58 -04001451 /* enable pcie gen2 link */
1452 evergreen_pcie_gen2_enable(rdev);
1453
Alex Deucherc420c742012-03-20 17:18:39 -04001454 if (rdev->flags & RADEON_IS_IGP) {
1455 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
1456 r = ni_init_microcode(rdev);
1457 if (r) {
1458 DRM_ERROR("Failed to load firmware!\n");
1459 return r;
1460 }
1461 }
1462 } else {
1463 if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw || !rdev->mc_fw) {
1464 r = ni_init_microcode(rdev);
1465 if (r) {
1466 DRM_ERROR("Failed to load firmware!\n");
1467 return r;
1468 }
1469 }
1470
1471 r = ni_mc_load_microcode(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001472 if (r) {
Alex Deucherc420c742012-03-20 17:18:39 -04001473 DRM_ERROR("Failed to load MC firmware!\n");
Alex Deucher755d8192011-03-02 20:07:34 -05001474 return r;
1475 }
1476 }
Alex Deucher755d8192011-03-02 20:07:34 -05001477
Alex Deucher16cdf042011-10-28 10:30:02 -04001478 r = r600_vram_scratch_init(rdev);
1479 if (r)
1480 return r;
1481
Alex Deucher755d8192011-03-02 20:07:34 -05001482 evergreen_mc_program(rdev);
1483 r = cayman_pcie_gart_enable(rdev);
1484 if (r)
1485 return r;
1486 cayman_gpu_init(rdev);
1487
Alex Deuchercb92d452011-05-25 16:39:00 -04001488 r = evergreen_blit_init(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001489 if (r) {
Ilija Hadzicfb3d9e92011-10-12 23:29:41 -04001490 r600_blit_fini(rdev);
Alex Deucher27cd7762012-02-23 17:53:42 -05001491 rdev->asic->copy.copy = NULL;
Alex Deucher755d8192011-03-02 20:07:34 -05001492 dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
1493 }
Alex Deucher755d8192011-03-02 20:07:34 -05001494
Alex Deucherc420c742012-03-20 17:18:39 -04001495 /* allocate rlc buffers */
1496 if (rdev->flags & RADEON_IS_IGP) {
1497 r = si_rlc_init(rdev);
1498 if (r) {
1499 DRM_ERROR("Failed to init rlc BOs!\n");
1500 return r;
1501 }
1502 }
1503
Alex Deucher755d8192011-03-02 20:07:34 -05001504 /* allocate wb buffer */
1505 r = radeon_wb_init(rdev);
1506 if (r)
1507 return r;
1508
Jerome Glisse30eb77f2011-11-20 20:45:34 +00001509 r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
1510 if (r) {
1511 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
1512 return r;
1513 }
1514
1515 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
1516 if (r) {
1517 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
1518 return r;
1519 }
1520
1521 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
1522 if (r) {
1523 dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
1524 return r;
1525 }
1526
Alex Deucherf60cbd12012-12-04 15:27:33 -05001527 r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
1528 if (r) {
1529 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
1530 return r;
1531 }
1532
1533 r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
1534 if (r) {
1535 dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
1536 return r;
1537 }
1538
Alex Deucher755d8192011-03-02 20:07:34 -05001539 /* Enable IRQ */
1540 r = r600_irq_init(rdev);
1541 if (r) {
1542 DRM_ERROR("radeon: IH init failed (%d).\n", r);
1543 radeon_irq_kms_fini(rdev);
1544 return r;
1545 }
1546 evergreen_irq_set(rdev);
1547
Christian Könige32eb502011-10-23 12:56:27 +02001548 r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
Alex Deucher78c55602011-11-17 14:25:56 -05001549 CP_RB0_RPTR, CP_RB0_WPTR,
1550 0, 0xfffff, RADEON_CP_PACKET2);
Alex Deucher755d8192011-03-02 20:07:34 -05001551 if (r)
1552 return r;
Alex Deucherf60cbd12012-12-04 15:27:33 -05001553
1554 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
1555 r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
1556 DMA_RB_RPTR + DMA0_REGISTER_OFFSET,
1557 DMA_RB_WPTR + DMA0_REGISTER_OFFSET,
1558 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
1559 if (r)
1560 return r;
1561
1562 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
1563 r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
1564 DMA_RB_RPTR + DMA1_REGISTER_OFFSET,
1565 DMA_RB_WPTR + DMA1_REGISTER_OFFSET,
1566 2, 0x3fffc, DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
1567 if (r)
1568 return r;
1569
Alex Deucher755d8192011-03-02 20:07:34 -05001570 r = cayman_cp_load_microcode(rdev);
1571 if (r)
1572 return r;
1573 r = cayman_cp_resume(rdev);
1574 if (r)
1575 return r;
1576
Alex Deucherf60cbd12012-12-04 15:27:33 -05001577 r = cayman_dma_resume(rdev);
1578 if (r)
1579 return r;
1580
Christian König2898c342012-07-05 11:55:34 +02001581 r = radeon_ib_pool_init(rdev);
1582 if (r) {
1583 dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
Jerome Glisseb15ba512011-11-15 11:48:34 -05001584 return r;
Christian König2898c342012-07-05 11:55:34 +02001585 }
Jerome Glisseb15ba512011-11-15 11:48:34 -05001586
Christian Königc6105f22012-07-05 14:32:00 +02001587 r = radeon_vm_manager_init(rdev);
1588 if (r) {
1589 dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
Jerome Glisse721604a2012-01-05 22:11:05 -05001590 return r;
Christian Königc6105f22012-07-05 14:32:00 +02001591 }
Jerome Glisse721604a2012-01-05 22:11:05 -05001592
Rafał Miłecki6b53a052012-06-11 12:34:01 +02001593 r = r600_audio_init(rdev);
1594 if (r)
1595 return r;
1596
Alex Deucher755d8192011-03-02 20:07:34 -05001597 return 0;
1598}
1599
1600int cayman_resume(struct radeon_device *rdev)
1601{
1602 int r;
1603
1604 /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
1605 * posting will perform necessary task to bring back GPU into good
1606 * shape.
1607 */
1608 /* post card */
1609 atom_asic_init(rdev->mode_info.atom_context);
1610
Jerome Glisseb15ba512011-11-15 11:48:34 -05001611 rdev->accel_working = true;
Alex Deucher755d8192011-03-02 20:07:34 -05001612 r = cayman_startup(rdev);
1613 if (r) {
1614 DRM_ERROR("cayman startup failed on resume\n");
Jerome Glisse6b7746e2012-02-20 17:57:20 -05001615 rdev->accel_working = false;
Alex Deucher755d8192011-03-02 20:07:34 -05001616 return r;
1617 }
Alex Deucher755d8192011-03-02 20:07:34 -05001618 return r;
Alex Deucher755d8192011-03-02 20:07:34 -05001619}
1620
1621int cayman_suspend(struct radeon_device *rdev)
1622{
Rafał Miłecki6b53a052012-06-11 12:34:01 +02001623 r600_audio_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001624 cayman_cp_enable(rdev, false);
Alex Deucherf60cbd12012-12-04 15:27:33 -05001625 cayman_dma_stop(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001626 evergreen_irq_suspend(rdev);
1627 radeon_wb_disable(rdev);
1628 cayman_pcie_gart_disable(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001629 return 0;
1630}
1631
1632/* Plan is to move initialization in that function and use
1633 * helper function so that radeon_device_init pretty much
1634 * do nothing more than calling asic specific function. This
1635 * should also allow to remove a bunch of callback function
1636 * like vram_info.
1637 */
1638int cayman_init(struct radeon_device *rdev)
1639{
Christian Könige32eb502011-10-23 12:56:27 +02001640 struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
Alex Deucher755d8192011-03-02 20:07:34 -05001641 int r;
1642
Alex Deucher755d8192011-03-02 20:07:34 -05001643 /* Read BIOS */
1644 if (!radeon_get_bios(rdev)) {
1645 if (ASIC_IS_AVIVO(rdev))
1646 return -EINVAL;
1647 }
1648 /* Must be an ATOMBIOS */
1649 if (!rdev->is_atom_bios) {
1650 dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
1651 return -EINVAL;
1652 }
1653 r = radeon_atombios_init(rdev);
1654 if (r)
1655 return r;
1656
1657 /* Post card if necessary */
1658 if (!radeon_card_posted(rdev)) {
1659 if (!rdev->bios) {
1660 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
1661 return -EINVAL;
1662 }
1663 DRM_INFO("GPU not posted. posting now...\n");
1664 atom_asic_init(rdev->mode_info.atom_context);
1665 }
1666 /* Initialize scratch registers */
1667 r600_scratch_init(rdev);
1668 /* Initialize surface registers */
1669 radeon_surface_init(rdev);
1670 /* Initialize clocks */
1671 radeon_get_clock_info(rdev->ddev);
1672 /* Fence driver */
Jerome Glisse30eb77f2011-11-20 20:45:34 +00001673 r = radeon_fence_driver_init(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001674 if (r)
1675 return r;
1676 /* initialize memory controller */
1677 r = evergreen_mc_init(rdev);
1678 if (r)
1679 return r;
1680 /* Memory manager */
1681 r = radeon_bo_init(rdev);
1682 if (r)
1683 return r;
1684
1685 r = radeon_irq_kms_init(rdev);
1686 if (r)
1687 return r;
1688
Christian Könige32eb502011-10-23 12:56:27 +02001689 ring->ring_obj = NULL;
1690 r600_ring_init(rdev, ring, 1024 * 1024);
Alex Deucher755d8192011-03-02 20:07:34 -05001691
Alex Deucherf60cbd12012-12-04 15:27:33 -05001692 ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
1693 ring->ring_obj = NULL;
1694 r600_ring_init(rdev, ring, 64 * 1024);
1695
1696 ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
1697 ring->ring_obj = NULL;
1698 r600_ring_init(rdev, ring, 64 * 1024);
1699
Alex Deucher755d8192011-03-02 20:07:34 -05001700 rdev->ih.ring_obj = NULL;
1701 r600_ih_ring_init(rdev, 64 * 1024);
1702
1703 r = r600_pcie_gart_init(rdev);
1704 if (r)
1705 return r;
1706
1707 rdev->accel_working = true;
1708 r = cayman_startup(rdev);
1709 if (r) {
1710 dev_err(rdev->dev, "disabling GPU acceleration\n");
1711 cayman_cp_fini(rdev);
Alex Deucherf60cbd12012-12-04 15:27:33 -05001712 cayman_dma_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001713 r600_irq_fini(rdev);
Alex Deucherc420c742012-03-20 17:18:39 -04001714 if (rdev->flags & RADEON_IS_IGP)
1715 si_rlc_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001716 radeon_wb_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02001717 radeon_ib_pool_fini(rdev);
Jerome Glisse721604a2012-01-05 22:11:05 -05001718 radeon_vm_manager_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001719 radeon_irq_kms_fini(rdev);
1720 cayman_pcie_gart_fini(rdev);
1721 rdev->accel_working = false;
1722 }
Alex Deucher755d8192011-03-02 20:07:34 -05001723
1724 /* Don't start up if the MC ucode is missing.
1725 * The default clocks and voltages before the MC ucode
1726 * is loaded are not suffient for advanced operations.
Alex Deucherc420c742012-03-20 17:18:39 -04001727 *
1728 * We can skip this check for TN, because there is no MC
1729 * ucode.
Alex Deucher755d8192011-03-02 20:07:34 -05001730 */
Alex Deucherc420c742012-03-20 17:18:39 -04001731 if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
Alex Deucher755d8192011-03-02 20:07:34 -05001732 DRM_ERROR("radeon: MC ucode required for NI+.\n");
1733 return -EINVAL;
1734 }
1735
1736 return 0;
1737}
1738
1739void cayman_fini(struct radeon_device *rdev)
1740{
Ilija Hadzicfb3d9e92011-10-12 23:29:41 -04001741 r600_blit_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001742 cayman_cp_fini(rdev);
Alex Deucherf60cbd12012-12-04 15:27:33 -05001743 cayman_dma_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001744 r600_irq_fini(rdev);
Alex Deucherc420c742012-03-20 17:18:39 -04001745 if (rdev->flags & RADEON_IS_IGP)
1746 si_rlc_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001747 radeon_wb_fini(rdev);
Jerome Glisse721604a2012-01-05 22:11:05 -05001748 radeon_vm_manager_fini(rdev);
Christian König2898c342012-07-05 11:55:34 +02001749 radeon_ib_pool_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001750 radeon_irq_kms_fini(rdev);
1751 cayman_pcie_gart_fini(rdev);
Alex Deucher16cdf042011-10-28 10:30:02 -04001752 r600_vram_scratch_fini(rdev);
Alex Deucher755d8192011-03-02 20:07:34 -05001753 radeon_gem_fini(rdev);
1754 radeon_fence_driver_fini(rdev);
1755 radeon_bo_fini(rdev);
1756 radeon_atombios_fini(rdev);
1757 kfree(rdev->bios);
1758 rdev->bios = NULL;
1759}
1760
Jerome Glisse721604a2012-01-05 22:11:05 -05001761/*
1762 * vm
1763 */
1764int cayman_vm_init(struct radeon_device *rdev)
1765{
1766 /* number of VMs */
1767 rdev->vm_manager.nvm = 8;
1768 /* base offset of vram pages */
Alex Deuchere71270f2012-03-20 17:18:38 -04001769 if (rdev->flags & RADEON_IS_IGP) {
1770 u64 tmp = RREG32(FUS_MC_VM_FB_OFFSET);
1771 tmp <<= 22;
1772 rdev->vm_manager.vram_base_offset = tmp;
1773 } else
1774 rdev->vm_manager.vram_base_offset = 0;
Jerome Glisse721604a2012-01-05 22:11:05 -05001775 return 0;
1776}
1777
1778void cayman_vm_fini(struct radeon_device *rdev)
1779{
1780}
1781
Christian Königdce34bf2012-09-17 19:36:18 +02001782#define R600_ENTRY_VALID (1 << 0)
Jerome Glisse721604a2012-01-05 22:11:05 -05001783#define R600_PTE_SYSTEM (1 << 1)
1784#define R600_PTE_SNOOPED (1 << 2)
1785#define R600_PTE_READABLE (1 << 5)
1786#define R600_PTE_WRITEABLE (1 << 6)
1787
Christian König089a7862012-08-11 11:54:05 +02001788uint32_t cayman_vm_page_flags(struct radeon_device *rdev, uint32_t flags)
Jerome Glisse721604a2012-01-05 22:11:05 -05001789{
1790 uint32_t r600_flags = 0;
Christian Königdce34bf2012-09-17 19:36:18 +02001791 r600_flags |= (flags & RADEON_VM_PAGE_VALID) ? R600_ENTRY_VALID : 0;
Jerome Glisse721604a2012-01-05 22:11:05 -05001792 r600_flags |= (flags & RADEON_VM_PAGE_READABLE) ? R600_PTE_READABLE : 0;
1793 r600_flags |= (flags & RADEON_VM_PAGE_WRITEABLE) ? R600_PTE_WRITEABLE : 0;
1794 if (flags & RADEON_VM_PAGE_SYSTEM) {
1795 r600_flags |= R600_PTE_SYSTEM;
1796 r600_flags |= (flags & RADEON_VM_PAGE_SNOOPED) ? R600_PTE_SNOOPED : 0;
1797 }
1798 return r600_flags;
1799}
1800
Alex Deucher7a083292012-08-31 13:51:21 -04001801/**
1802 * cayman_vm_set_page - update the page tables using the CP
1803 *
1804 * @rdev: radeon_device pointer
Christian Königdce34bf2012-09-17 19:36:18 +02001805 * @pe: addr of the page entry
1806 * @addr: dst addr to write into pe
1807 * @count: number of page entries to update
1808 * @incr: increase next addr by incr bytes
1809 * @flags: access flags
Alex Deucher7a083292012-08-31 13:51:21 -04001810 *
1811 * Update the page tables using the CP (cayman-si).
1812 */
Christian Königdce34bf2012-09-17 19:36:18 +02001813void cayman_vm_set_page(struct radeon_device *rdev, uint64_t pe,
1814 uint64_t addr, unsigned count,
1815 uint32_t incr, uint32_t flags)
Jerome Glisse721604a2012-01-05 22:11:05 -05001816{
Christian König2a6f1ab2012-08-11 15:00:30 +02001817 struct radeon_ring *ring = &rdev->ring[rdev->asic->vm.pt_ring_index];
Christian Königdce34bf2012-09-17 19:36:18 +02001818 uint32_t r600_flags = cayman_vm_page_flags(rdev, flags);
Alex Deucher3b6b59b2012-10-22 12:19:01 -04001819 uint64_t value;
1820 unsigned ndw;
Jerome Glisse721604a2012-01-05 22:11:05 -05001821
Alex Deucher3b6b59b2012-10-22 12:19:01 -04001822 if (rdev->asic->vm.pt_ring_index == RADEON_RING_TYPE_GFX_INDEX) {
1823 while (count) {
1824 ndw = 1 + count * 2;
1825 if (ndw > 0x3FFF)
1826 ndw = 0x3FFF;
Christian König089a7862012-08-11 11:54:05 +02001827
Alex Deucher3b6b59b2012-10-22 12:19:01 -04001828 radeon_ring_write(ring, PACKET3(PACKET3_ME_WRITE, ndw));
1829 radeon_ring_write(ring, pe);
1830 radeon_ring_write(ring, upper_32_bits(pe) & 0xff);
1831 for (; ndw > 1; ndw -= 2, --count, pe += 8) {
1832 if (flags & RADEON_VM_PAGE_SYSTEM) {
1833 value = radeon_vm_map_gart(rdev, addr);
1834 value &= 0xFFFFFFFFFFFFF000ULL;
1835 } else if (flags & RADEON_VM_PAGE_VALID) {
1836 value = addr;
1837 } else {
1838 value = 0;
1839 }
Christian Königf9fdffa2012-10-22 17:42:36 +02001840 addr += incr;
Alex Deucher3b6b59b2012-10-22 12:19:01 -04001841 value |= r600_flags;
1842 radeon_ring_write(ring, value);
1843 radeon_ring_write(ring, upper_32_bits(value));
Christian Königf9fdffa2012-10-22 17:42:36 +02001844 }
Alex Deucher3b6b59b2012-10-22 12:19:01 -04001845 }
1846 } else {
1847 while (count) {
1848 ndw = count * 2;
1849 if (ndw > 0xFFFFE)
1850 ndw = 0xFFFFE;
Christian Königf9fdffa2012-10-22 17:42:36 +02001851
Alex Deucher3b6b59b2012-10-22 12:19:01 -04001852 /* for non-physically contiguous pages (system) */
1853 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_WRITE, 0, 0, ndw));
1854 radeon_ring_write(ring, pe);
1855 radeon_ring_write(ring, upper_32_bits(pe) & 0xff);
1856 for (; ndw > 0; ndw -= 2, --count, pe += 8) {
1857 if (flags & RADEON_VM_PAGE_SYSTEM) {
1858 value = radeon_vm_map_gart(rdev, addr);
1859 value &= 0xFFFFFFFFFFFFF000ULL;
1860 } else if (flags & RADEON_VM_PAGE_VALID) {
1861 value = addr;
1862 } else {
1863 value = 0;
1864 }
1865 addr += incr;
1866 value |= r600_flags;
1867 radeon_ring_write(ring, value);
1868 radeon_ring_write(ring, upper_32_bits(value));
1869 }
Christian König2a6f1ab2012-08-11 15:00:30 +02001870 }
Christian König2a6f1ab2012-08-11 15:00:30 +02001871 }
Jerome Glisse721604a2012-01-05 22:11:05 -05001872}
Christian König9b40e5d2012-08-08 12:22:43 +02001873
Alex Deucher7a083292012-08-31 13:51:21 -04001874/**
1875 * cayman_vm_flush - vm flush using the CP
1876 *
1877 * @rdev: radeon_device pointer
1878 *
1879 * Update the page table base and flush the VM TLB
1880 * using the CP (cayman-si).
1881 */
Alex Deucher498522b2012-10-02 14:43:38 -04001882void cayman_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
Christian König9b40e5d2012-08-08 12:22:43 +02001883{
Alex Deucher498522b2012-10-02 14:43:38 -04001884 struct radeon_ring *ring = &rdev->ring[ridx];
Christian König9b40e5d2012-08-08 12:22:43 +02001885
Christian Königee60e292012-08-09 16:21:08 +02001886 if (vm == NULL)
Christian König9b40e5d2012-08-08 12:22:43 +02001887 return;
1888
Christian Königee60e292012-08-09 16:21:08 +02001889 radeon_ring_write(ring, PACKET0(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2), 0));
Dmitry Cherkasovfa87e622012-09-17 19:36:19 +02001890 radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
Christian Königee60e292012-08-09 16:21:08 +02001891
Christian König9b40e5d2012-08-08 12:22:43 +02001892 /* flush hdp cache */
1893 radeon_ring_write(ring, PACKET0(HDP_MEM_COHERENCY_FLUSH_CNTL, 0));
1894 radeon_ring_write(ring, 0x1);
1895
1896 /* bits 0-7 are the VM contexts0-7 */
1897 radeon_ring_write(ring, PACKET0(VM_INVALIDATE_REQUEST, 0));
Alex Deucher498522b2012-10-02 14:43:38 -04001898 radeon_ring_write(ring, 1 << vm->id);
Christian König58f8cf52012-10-22 17:42:35 +02001899
1900 /* sync PFP to ME, otherwise we might get invalid PFP reads */
1901 radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
1902 radeon_ring_write(ring, 0x0);
Alex Deucher0af62b02011-01-06 21:19:31 -05001903}
Alex Deucherf60cbd12012-12-04 15:27:33 -05001904
1905void cayman_dma_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)
1906{
1907 struct radeon_ring *ring = &rdev->ring[ridx];
1908
1909 if (vm == NULL)
1910 return;
1911
1912 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0));
1913 radeon_ring_write(ring, (0xf << 16) | ((VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm->id << 2)) >> 2));
1914 radeon_ring_write(ring, vm->pd_gpu_addr >> 12);
1915
1916 /* flush hdp cache */
1917 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0));
1918 radeon_ring_write(ring, (0xf << 16) | (HDP_MEM_COHERENCY_FLUSH_CNTL >> 2));
1919 radeon_ring_write(ring, 1);
1920
1921 /* bits 0-7 are the VM contexts0-7 */
1922 radeon_ring_write(ring, DMA_PACKET(DMA_PACKET_SRBM_WRITE, 0, 0, 0));
1923 radeon_ring_write(ring, (0xf << 16) | (VM_INVALIDATE_REQUEST >> 2));
1924 radeon_ring_write(ring, 1 << vm->id);
1925}
1926