blob: 6a5d1177afab70c81dd517500c54a2992e4f0ab6 [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Dave Airlie
25 * Alex Deucher
26 * Jerome Glisse
27 */
28#include <linux/seq_file.h>
29#include "drmP.h"
30#include "drm.h"
31#include "radeon_reg.h"
32#include "radeon.h"
Dave Airliee024e112009-06-24 09:48:08 +100033#include "radeon_drm.h"
Dave Airlie551ebd82009-09-01 15:25:57 +100034#include "r100_track.h"
Jerome Glisse3ce0a232009-09-08 10:10:24 +100035#include "r300d.h"
Jerome Glisseca6ffc62009-10-01 10:20:52 +020036#include "rv350d.h"
Dave Airlie50f15302009-08-21 13:21:01 +100037#include "r300_reg_safe.h"
38
Jerome Glisse207bf9e2009-09-30 15:35:32 +020039/* This files gather functions specifics to: r300,r350,rv350,rv370,rv380 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +020040
41/*
42 * rv370,rv380 PCIE GART
43 */
Jerome Glisse207bf9e2009-09-30 15:35:32 +020044static int rv370_debugfs_pcie_gart_info_init(struct radeon_device *rdev);
45
Jerome Glisse771fe6b2009-06-05 14:42:42 +020046void rv370_pcie_gart_tlb_flush(struct radeon_device *rdev)
47{
48 uint32_t tmp;
49 int i;
50
51 /* Workaround HW bug do flush 2 times */
52 for (i = 0; i < 2; i++) {
53 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL);
54 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp | RADEON_PCIE_TX_GART_INVALIDATE_TLB);
55 (void)RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL);
56 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020057 }
Dave Airliede1b2892009-08-12 18:43:14 +100058 mb();
Jerome Glisse771fe6b2009-06-05 14:42:42 +020059}
60
Jerome Glisse4aac0472009-09-14 18:29:49 +020061int rv370_pcie_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr)
62{
63 void __iomem *ptr = (void *)rdev->gart.table.vram.ptr;
64
65 if (i < 0 || i > rdev->gart.num_gpu_pages) {
66 return -EINVAL;
67 }
68 addr = (lower_32_bits(addr) >> 8) |
69 ((upper_32_bits(addr) & 0xff) << 24) |
70 0xc;
71 /* on x86 we want this to be CPU endian, on powerpc
72 * on powerpc without HW swappers, it'll get swapped on way
73 * into VRAM - so no need for cpu_to_le32 on VRAM tables */
74 writel(addr, ((void __iomem *)ptr) + (i * 4));
75 return 0;
76}
77
78int rv370_pcie_gart_init(struct radeon_device *rdev)
79{
80 int r;
81
82 if (rdev->gart.table.vram.robj) {
83 WARN(1, "RV370 PCIE GART already initialized.\n");
84 return 0;
85 }
86 /* Initialize common gart structure */
87 r = radeon_gart_init(rdev);
88 if (r)
89 return r;
90 r = rv370_debugfs_pcie_gart_info_init(rdev);
91 if (r)
92 DRM_ERROR("Failed to register debugfs file for PCIE gart !\n");
93 rdev->gart.table_size = rdev->gart.num_gpu_pages * 4;
94 rdev->asic->gart_tlb_flush = &rv370_pcie_gart_tlb_flush;
95 rdev->asic->gart_set_page = &rv370_pcie_gart_set_page;
96 return radeon_gart_table_vram_alloc(rdev);
97}
98
Jerome Glisse771fe6b2009-06-05 14:42:42 +020099int rv370_pcie_gart_enable(struct radeon_device *rdev)
100{
101 uint32_t table_addr;
102 uint32_t tmp;
103 int r;
104
Jerome Glisse4aac0472009-09-14 18:29:49 +0200105 if (rdev->gart.table.vram.robj == NULL) {
106 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
107 return -EINVAL;
108 }
109 r = radeon_gart_table_vram_pin(rdev);
110 if (r)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200111 return r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200112 /* discard memory request outside of configured range */
113 tmp = RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD;
114 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp);
115 WREG32_PCIE(RADEON_PCIE_TX_GART_START_LO, rdev->mc.gtt_location);
Matt Turnera77f1712009-10-14 00:34:41 -0400116 tmp = rdev->mc.gtt_location + rdev->mc.gtt_size - RADEON_GPU_PAGE_SIZE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200117 WREG32_PCIE(RADEON_PCIE_TX_GART_END_LO, tmp);
118 WREG32_PCIE(RADEON_PCIE_TX_GART_START_HI, 0);
119 WREG32_PCIE(RADEON_PCIE_TX_GART_END_HI, 0);
120 table_addr = rdev->gart.table_addr;
121 WREG32_PCIE(RADEON_PCIE_TX_GART_BASE, table_addr);
122 /* FIXME: setup default page */
123 WREG32_PCIE(RADEON_PCIE_TX_DISCARD_RD_ADDR_LO, rdev->mc.vram_location);
124 WREG32_PCIE(RADEON_PCIE_TX_DISCARD_RD_ADDR_HI, 0);
125 /* Clear error */
126 WREG32_PCIE(0x18, 0);
127 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL);
128 tmp |= RADEON_PCIE_TX_GART_EN;
129 tmp |= RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD;
130 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp);
131 rv370_pcie_gart_tlb_flush(rdev);
132 DRM_INFO("PCIE GART of %uM enabled (table at 0x%08X).\n",
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000133 (unsigned)(rdev->mc.gtt_size >> 20), table_addr);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200134 rdev->gart.ready = true;
135 return 0;
136}
137
138void rv370_pcie_gart_disable(struct radeon_device *rdev)
139{
Jerome Glisse4c788672009-11-20 14:29:23 +0100140 u32 tmp;
141 int r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200142
143 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL);
144 tmp |= RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD;
145 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp & ~RADEON_PCIE_TX_GART_EN);
146 if (rdev->gart.table.vram.robj) {
Jerome Glisse4c788672009-11-20 14:29:23 +0100147 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
148 if (likely(r == 0)) {
149 radeon_bo_kunmap(rdev->gart.table.vram.robj);
150 radeon_bo_unpin(rdev->gart.table.vram.robj);
151 radeon_bo_unreserve(rdev->gart.table.vram.robj);
152 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200153 }
154}
155
Jerome Glisse4aac0472009-09-14 18:29:49 +0200156void rv370_pcie_gart_fini(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200157{
Jerome Glisse4aac0472009-09-14 18:29:49 +0200158 rv370_pcie_gart_disable(rdev);
159 radeon_gart_table_vram_free(rdev);
160 radeon_gart_fini(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200161}
162
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200163void r300_fence_ring_emit(struct radeon_device *rdev,
164 struct radeon_fence *fence)
165{
166 /* Who ever call radeon_fence_emit should call ring_lock and ask
167 * for enough space (today caller are ib schedule and buffer move) */
168 /* Write SC register so SC & US assert idle */
169 radeon_ring_write(rdev, PACKET0(0x43E0, 0));
170 radeon_ring_write(rdev, 0);
171 radeon_ring_write(rdev, PACKET0(0x43E4, 0));
172 radeon_ring_write(rdev, 0);
173 /* Flush 3D cache */
174 radeon_ring_write(rdev, PACKET0(0x4E4C, 0));
175 radeon_ring_write(rdev, (2 << 0));
176 radeon_ring_write(rdev, PACKET0(0x4F18, 0));
177 radeon_ring_write(rdev, (1 << 0));
178 /* Wait until IDLE & CLEAN */
179 radeon_ring_write(rdev, PACKET0(0x1720, 0));
180 radeon_ring_write(rdev, (1 << 17) | (1 << 16) | (1 << 9));
181 /* Emit fence sequence & fire IRQ */
182 radeon_ring_write(rdev, PACKET0(rdev->fence_drv.scratch_reg, 0));
183 radeon_ring_write(rdev, fence->seq);
184 radeon_ring_write(rdev, PACKET0(RADEON_GEN_INT_STATUS, 0));
185 radeon_ring_write(rdev, RADEON_SW_INT_FIRE);
186}
187
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200188int r300_copy_dma(struct radeon_device *rdev,
189 uint64_t src_offset,
190 uint64_t dst_offset,
191 unsigned num_pages,
192 struct radeon_fence *fence)
193{
194 uint32_t size;
195 uint32_t cur_size;
196 int i, num_loops;
197 int r = 0;
198
199 /* radeon pitch is /64 */
200 size = num_pages << PAGE_SHIFT;
201 num_loops = DIV_ROUND_UP(size, 0x1FFFFF);
202 r = radeon_ring_lock(rdev, num_loops * 4 + 64);
203 if (r) {
204 DRM_ERROR("radeon: moving bo (%d).\n", r);
205 return r;
206 }
207 /* Must wait for 2D idle & clean before DMA or hangs might happen */
Jerome Glisse068a1172009-06-17 13:28:30 +0200208 radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0 ));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200209 radeon_ring_write(rdev, (1 << 16));
210 for (i = 0; i < num_loops; i++) {
211 cur_size = size;
212 if (cur_size > 0x1FFFFF) {
213 cur_size = 0x1FFFFF;
214 }
215 size -= cur_size;
216 radeon_ring_write(rdev, PACKET0(0x720, 2));
217 radeon_ring_write(rdev, src_offset);
218 radeon_ring_write(rdev, dst_offset);
219 radeon_ring_write(rdev, cur_size | (1 << 31) | (1 << 30));
220 src_offset += cur_size;
221 dst_offset += cur_size;
222 }
223 radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0));
224 radeon_ring_write(rdev, RADEON_WAIT_DMA_GUI_IDLE);
225 if (fence) {
226 r = radeon_fence_emit(rdev, fence);
227 }
228 radeon_ring_unlock_commit(rdev);
229 return r;
230}
231
232void r300_ring_start(struct radeon_device *rdev)
233{
234 unsigned gb_tile_config;
235 int r;
236
237 /* Sub pixel 1/12 so we can have 4K rendering according to doc */
238 gb_tile_config = (R300_ENABLE_TILING | R300_TILE_SIZE_16);
Jerome Glisse068a1172009-06-17 13:28:30 +0200239 switch(rdev->num_gb_pipes) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200240 case 2:
241 gb_tile_config |= R300_PIPE_COUNT_R300;
242 break;
243 case 3:
244 gb_tile_config |= R300_PIPE_COUNT_R420_3P;
245 break;
246 case 4:
247 gb_tile_config |= R300_PIPE_COUNT_R420;
248 break;
249 case 1:
250 default:
251 gb_tile_config |= R300_PIPE_COUNT_RV350;
252 break;
253 }
254
255 r = radeon_ring_lock(rdev, 64);
256 if (r) {
257 return;
258 }
259 radeon_ring_write(rdev, PACKET0(RADEON_ISYNC_CNTL, 0));
260 radeon_ring_write(rdev,
261 RADEON_ISYNC_ANY2D_IDLE3D |
262 RADEON_ISYNC_ANY3D_IDLE2D |
263 RADEON_ISYNC_WAIT_IDLEGUI |
264 RADEON_ISYNC_CPSCRATCH_IDLEGUI);
265 radeon_ring_write(rdev, PACKET0(R300_GB_TILE_CONFIG, 0));
266 radeon_ring_write(rdev, gb_tile_config);
267 radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0));
268 radeon_ring_write(rdev,
269 RADEON_WAIT_2D_IDLECLEAN |
270 RADEON_WAIT_3D_IDLECLEAN);
271 radeon_ring_write(rdev, PACKET0(0x170C, 0));
272 radeon_ring_write(rdev, 1 << 31);
273 radeon_ring_write(rdev, PACKET0(R300_GB_SELECT, 0));
274 radeon_ring_write(rdev, 0);
275 radeon_ring_write(rdev, PACKET0(R300_GB_ENABLE, 0));
276 radeon_ring_write(rdev, 0);
277 radeon_ring_write(rdev, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
278 radeon_ring_write(rdev, R300_RB3D_DC_FLUSH | R300_RB3D_DC_FREE);
279 radeon_ring_write(rdev, PACKET0(R300_RB3D_ZCACHE_CTLSTAT, 0));
280 radeon_ring_write(rdev, R300_ZC_FLUSH | R300_ZC_FREE);
281 radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0));
282 radeon_ring_write(rdev,
283 RADEON_WAIT_2D_IDLECLEAN |
284 RADEON_WAIT_3D_IDLECLEAN);
285 radeon_ring_write(rdev, PACKET0(R300_GB_AA_CONFIG, 0));
286 radeon_ring_write(rdev, 0);
287 radeon_ring_write(rdev, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
288 radeon_ring_write(rdev, R300_RB3D_DC_FLUSH | R300_RB3D_DC_FREE);
289 radeon_ring_write(rdev, PACKET0(R300_RB3D_ZCACHE_CTLSTAT, 0));
290 radeon_ring_write(rdev, R300_ZC_FLUSH | R300_ZC_FREE);
291 radeon_ring_write(rdev, PACKET0(R300_GB_MSPOS0, 0));
292 radeon_ring_write(rdev,
293 ((6 << R300_MS_X0_SHIFT) |
294 (6 << R300_MS_Y0_SHIFT) |
295 (6 << R300_MS_X1_SHIFT) |
296 (6 << R300_MS_Y1_SHIFT) |
297 (6 << R300_MS_X2_SHIFT) |
298 (6 << R300_MS_Y2_SHIFT) |
299 (6 << R300_MSBD0_Y_SHIFT) |
300 (6 << R300_MSBD0_X_SHIFT)));
301 radeon_ring_write(rdev, PACKET0(R300_GB_MSPOS1, 0));
302 radeon_ring_write(rdev,
303 ((6 << R300_MS_X3_SHIFT) |
304 (6 << R300_MS_Y3_SHIFT) |
305 (6 << R300_MS_X4_SHIFT) |
306 (6 << R300_MS_Y4_SHIFT) |
307 (6 << R300_MS_X5_SHIFT) |
308 (6 << R300_MS_Y5_SHIFT) |
309 (6 << R300_MSBD1_SHIFT)));
310 radeon_ring_write(rdev, PACKET0(R300_GA_ENHANCE, 0));
311 radeon_ring_write(rdev, R300_GA_DEADLOCK_CNTL | R300_GA_FASTSYNC_CNTL);
312 radeon_ring_write(rdev, PACKET0(R300_GA_POLY_MODE, 0));
313 radeon_ring_write(rdev,
314 R300_FRONT_PTYPE_TRIANGE | R300_BACK_PTYPE_TRIANGE);
315 radeon_ring_write(rdev, PACKET0(R300_GA_ROUND_MODE, 0));
316 radeon_ring_write(rdev,
317 R300_GEOMETRY_ROUND_NEAREST |
318 R300_COLOR_ROUND_NEAREST);
319 radeon_ring_unlock_commit(rdev);
320}
321
322void r300_errata(struct radeon_device *rdev)
323{
324 rdev->pll_errata = 0;
325
326 if (rdev->family == CHIP_R300 &&
327 (RREG32(RADEON_CONFIG_CNTL) & RADEON_CFG_ATI_REV_ID_MASK) == RADEON_CFG_ATI_REV_A11) {
328 rdev->pll_errata |= CHIP_ERRATA_R300_CG;
329 }
330}
331
332int r300_mc_wait_for_idle(struct radeon_device *rdev)
333{
334 unsigned i;
335 uint32_t tmp;
336
337 for (i = 0; i < rdev->usec_timeout; i++) {
338 /* read MC_STATUS */
339 tmp = RREG32(0x0150);
340 if (tmp & (1 << 4)) {
341 return 0;
342 }
343 DRM_UDELAY(1);
344 }
345 return -1;
346}
347
348void r300_gpu_init(struct radeon_device *rdev)
349{
350 uint32_t gb_tile_config, tmp;
351
352 r100_hdp_reset(rdev);
353 /* FIXME: rv380 one pipes ? */
354 if ((rdev->family == CHIP_R300) || (rdev->family == CHIP_R350)) {
355 /* r300,r350 */
356 rdev->num_gb_pipes = 2;
357 } else {
358 /* rv350,rv370,rv380 */
359 rdev->num_gb_pipes = 1;
360 }
Alex Deucherf779b3e2009-08-19 19:11:39 -0400361 rdev->num_z_pipes = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200362 gb_tile_config = (R300_ENABLE_TILING | R300_TILE_SIZE_16);
363 switch (rdev->num_gb_pipes) {
364 case 2:
365 gb_tile_config |= R300_PIPE_COUNT_R300;
366 break;
367 case 3:
368 gb_tile_config |= R300_PIPE_COUNT_R420_3P;
369 break;
370 case 4:
371 gb_tile_config |= R300_PIPE_COUNT_R420;
372 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200373 default:
Jerome Glisse068a1172009-06-17 13:28:30 +0200374 case 1:
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200375 gb_tile_config |= R300_PIPE_COUNT_RV350;
376 break;
377 }
378 WREG32(R300_GB_TILE_CONFIG, gb_tile_config);
379
380 if (r100_gui_wait_for_idle(rdev)) {
381 printk(KERN_WARNING "Failed to wait GUI idle while "
382 "programming pipes. Bad things might happen.\n");
383 }
384
385 tmp = RREG32(0x170C);
386 WREG32(0x170C, tmp | (1 << 31));
387
388 WREG32(R300_RB2D_DSTCACHE_MODE,
389 R300_DC_AUTOFLUSH_ENABLE |
390 R300_DC_DC_DISABLE_IGNORE_PE);
391
392 if (r100_gui_wait_for_idle(rdev)) {
393 printk(KERN_WARNING "Failed to wait GUI idle while "
394 "programming pipes. Bad things might happen.\n");
395 }
396 if (r300_mc_wait_for_idle(rdev)) {
397 printk(KERN_WARNING "Failed to wait MC idle while "
398 "programming pipes. Bad things might happen.\n");
399 }
Alex Deucherf779b3e2009-08-19 19:11:39 -0400400 DRM_INFO("radeon: %d quad pipes, %d Z pipes initialized.\n",
401 rdev->num_gb_pipes, rdev->num_z_pipes);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200402}
403
404int r300_ga_reset(struct radeon_device *rdev)
405{
406 uint32_t tmp;
407 bool reinit_cp;
408 int i;
409
410 reinit_cp = rdev->cp.ready;
411 rdev->cp.ready = false;
412 for (i = 0; i < rdev->usec_timeout; i++) {
413 WREG32(RADEON_CP_CSQ_MODE, 0);
414 WREG32(RADEON_CP_CSQ_CNTL, 0);
415 WREG32(RADEON_RBBM_SOFT_RESET, 0x32005);
416 (void)RREG32(RADEON_RBBM_SOFT_RESET);
417 udelay(200);
418 WREG32(RADEON_RBBM_SOFT_RESET, 0);
419 /* Wait to prevent race in RBBM_STATUS */
420 mdelay(1);
421 tmp = RREG32(RADEON_RBBM_STATUS);
422 if (tmp & ((1 << 20) | (1 << 26))) {
423 DRM_ERROR("VAP & CP still busy (RBBM_STATUS=0x%08X)", tmp);
424 /* GA still busy soft reset it */
425 WREG32(0x429C, 0x200);
426 WREG32(R300_VAP_PVS_STATE_FLUSH_REG, 0);
427 WREG32(0x43E0, 0);
428 WREG32(0x43E4, 0);
429 WREG32(0x24AC, 0);
430 }
431 /* Wait to prevent race in RBBM_STATUS */
432 mdelay(1);
433 tmp = RREG32(RADEON_RBBM_STATUS);
434 if (!(tmp & ((1 << 20) | (1 << 26)))) {
435 break;
436 }
437 }
438 for (i = 0; i < rdev->usec_timeout; i++) {
439 tmp = RREG32(RADEON_RBBM_STATUS);
440 if (!(tmp & ((1 << 20) | (1 << 26)))) {
441 DRM_INFO("GA reset succeed (RBBM_STATUS=0x%08X)\n",
442 tmp);
443 if (reinit_cp) {
444 return r100_cp_init(rdev, rdev->cp.ring_size);
445 }
446 return 0;
447 }
448 DRM_UDELAY(1);
449 }
450 tmp = RREG32(RADEON_RBBM_STATUS);
451 DRM_ERROR("Failed to reset GA ! (RBBM_STATUS=0x%08X)\n", tmp);
452 return -1;
453}
454
455int r300_gpu_reset(struct radeon_device *rdev)
456{
457 uint32_t status;
458
459 /* reset order likely matter */
460 status = RREG32(RADEON_RBBM_STATUS);
461 /* reset HDP */
462 r100_hdp_reset(rdev);
463 /* reset rb2d */
464 if (status & ((1 << 17) | (1 << 18) | (1 << 27))) {
465 r100_rb2d_reset(rdev);
466 }
467 /* reset GA */
468 if (status & ((1 << 20) | (1 << 26))) {
469 r300_ga_reset(rdev);
470 }
471 /* reset CP */
472 status = RREG32(RADEON_RBBM_STATUS);
473 if (status & (1 << 16)) {
474 r100_cp_reset(rdev);
475 }
476 /* Check if GPU is idle */
477 status = RREG32(RADEON_RBBM_STATUS);
478 if (status & (1 << 31)) {
479 DRM_ERROR("Failed to reset GPU (RBBM_STATUS=0x%08X)\n", status);
480 return -1;
481 }
482 DRM_INFO("GPU reset succeed (RBBM_STATUS=0x%08X)\n", status);
483 return 0;
484}
485
486
487/*
488 * r300,r350,rv350,rv380 VRAM info
489 */
490void r300_vram_info(struct radeon_device *rdev)
491{
492 uint32_t tmp;
493
494 /* DDR for all card after R300 & IGP */
495 rdev->mc.vram_is_ddr = true;
496 tmp = RREG32(RADEON_MEM_CNTL);
497 if (tmp & R300_MEM_NUM_CHANNELS_MASK) {
498 rdev->mc.vram_width = 128;
499 } else {
500 rdev->mc.vram_width = 64;
501 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200502
Dave Airlie2a0f8912009-07-11 04:44:47 +1000503 r100_vram_init_sizes(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200504}
505
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200506void rv370_set_pcie_lanes(struct radeon_device *rdev, int lanes)
507{
508 uint32_t link_width_cntl, mask;
509
510 if (rdev->flags & RADEON_IS_IGP)
511 return;
512
513 if (!(rdev->flags & RADEON_IS_PCIE))
514 return;
515
516 /* FIXME wait for idle */
517
518 switch (lanes) {
519 case 0:
520 mask = RADEON_PCIE_LC_LINK_WIDTH_X0;
521 break;
522 case 1:
523 mask = RADEON_PCIE_LC_LINK_WIDTH_X1;
524 break;
525 case 2:
526 mask = RADEON_PCIE_LC_LINK_WIDTH_X2;
527 break;
528 case 4:
529 mask = RADEON_PCIE_LC_LINK_WIDTH_X4;
530 break;
531 case 8:
532 mask = RADEON_PCIE_LC_LINK_WIDTH_X8;
533 break;
534 case 12:
535 mask = RADEON_PCIE_LC_LINK_WIDTH_X12;
536 break;
537 case 16:
538 default:
539 mask = RADEON_PCIE_LC_LINK_WIDTH_X16;
540 break;
541 }
542
543 link_width_cntl = RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
544
545 if ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) ==
546 (mask << RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT))
547 return;
548
549 link_width_cntl &= ~(RADEON_PCIE_LC_LINK_WIDTH_MASK |
550 RADEON_PCIE_LC_RECONFIG_NOW |
551 RADEON_PCIE_LC_RECONFIG_LATER |
552 RADEON_PCIE_LC_SHORT_RECONFIG_EN);
553 link_width_cntl |= mask;
554 WREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
555 WREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL, (link_width_cntl |
556 RADEON_PCIE_LC_RECONFIG_NOW));
557
558 /* wait for lane set to complete */
559 link_width_cntl = RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
560 while (link_width_cntl == 0xffffffff)
561 link_width_cntl = RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
562
563}
564
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200565#if defined(CONFIG_DEBUG_FS)
566static int rv370_debugfs_pcie_gart_info(struct seq_file *m, void *data)
567{
568 struct drm_info_node *node = (struct drm_info_node *) m->private;
569 struct drm_device *dev = node->minor->dev;
570 struct radeon_device *rdev = dev->dev_private;
571 uint32_t tmp;
572
573 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL);
574 seq_printf(m, "PCIE_TX_GART_CNTL 0x%08x\n", tmp);
575 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_BASE);
576 seq_printf(m, "PCIE_TX_GART_BASE 0x%08x\n", tmp);
577 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_START_LO);
578 seq_printf(m, "PCIE_TX_GART_START_LO 0x%08x\n", tmp);
579 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_START_HI);
580 seq_printf(m, "PCIE_TX_GART_START_HI 0x%08x\n", tmp);
581 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_END_LO);
582 seq_printf(m, "PCIE_TX_GART_END_LO 0x%08x\n", tmp);
583 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_END_HI);
584 seq_printf(m, "PCIE_TX_GART_END_HI 0x%08x\n", tmp);
585 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_ERROR);
586 seq_printf(m, "PCIE_TX_GART_ERROR 0x%08x\n", tmp);
587 return 0;
588}
589
590static struct drm_info_list rv370_pcie_gart_info_list[] = {
591 {"rv370_pcie_gart_info", rv370_debugfs_pcie_gart_info, 0, NULL},
592};
593#endif
594
Jerome Glisse207bf9e2009-09-30 15:35:32 +0200595static int rv370_debugfs_pcie_gart_info_init(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200596{
597#if defined(CONFIG_DEBUG_FS)
598 return radeon_debugfs_add_files(rdev, rv370_pcie_gart_info_list, 1);
599#else
600 return 0;
601#endif
602}
603
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200604static int r300_packet0_check(struct radeon_cs_parser *p,
605 struct radeon_cs_packet *pkt,
606 unsigned idx, unsigned reg)
607{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200608 struct radeon_cs_reloc *reloc;
Dave Airlie551ebd82009-09-01 15:25:57 +1000609 struct r100_cs_track *track;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200610 volatile uint32_t *ib;
Dave Airliee024e112009-06-24 09:48:08 +1000611 uint32_t tmp, tile_flags = 0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200612 unsigned i;
613 int r;
Dave Airlie513bcb42009-09-23 16:56:27 +1000614 u32 idx_value;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200615
616 ib = p->ib->ptr;
Dave Airlie551ebd82009-09-01 15:25:57 +1000617 track = (struct r100_cs_track *)p->track;
Dave Airlie513bcb42009-09-23 16:56:27 +1000618 idx_value = radeon_get_ib_value(p, idx);
619
Jerome Glisse068a1172009-06-17 13:28:30 +0200620 switch(reg) {
Dave Airlie531369e2009-06-29 11:21:25 +1000621 case AVIVO_D1MODE_VLINE_START_END:
622 case RADEON_CRTC_GUI_TRIG_VLINE:
623 r = r100_cs_packet_parse_vline(p);
624 if (r) {
625 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
626 idx, reg);
627 r100_cs_dump_packet(p, pkt);
628 return r;
629 }
630 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200631 case RADEON_DST_PITCH_OFFSET:
632 case RADEON_SRC_PITCH_OFFSET:
Dave Airlie551ebd82009-09-01 15:25:57 +1000633 r = r100_reloc_pitch_offset(p, pkt, idx, reg);
634 if (r)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200635 return r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200636 break;
637 case R300_RB3D_COLOROFFSET0:
638 case R300_RB3D_COLOROFFSET1:
639 case R300_RB3D_COLOROFFSET2:
640 case R300_RB3D_COLOROFFSET3:
641 i = (reg - R300_RB3D_COLOROFFSET0) >> 2;
642 r = r100_cs_packet_next_reloc(p, &reloc);
643 if (r) {
644 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
645 idx, reg);
646 r100_cs_dump_packet(p, pkt);
647 return r;
648 }
649 track->cb[i].robj = reloc->robj;
Dave Airlie513bcb42009-09-23 16:56:27 +1000650 track->cb[i].offset = idx_value;
651 ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200652 break;
653 case R300_ZB_DEPTHOFFSET:
654 r = r100_cs_packet_next_reloc(p, &reloc);
655 if (r) {
656 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
657 idx, reg);
658 r100_cs_dump_packet(p, pkt);
659 return r;
660 }
661 track->zb.robj = reloc->robj;
Dave Airlie513bcb42009-09-23 16:56:27 +1000662 track->zb.offset = idx_value;
663 ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200664 break;
665 case R300_TX_OFFSET_0:
666 case R300_TX_OFFSET_0+4:
667 case R300_TX_OFFSET_0+8:
668 case R300_TX_OFFSET_0+12:
669 case R300_TX_OFFSET_0+16:
670 case R300_TX_OFFSET_0+20:
671 case R300_TX_OFFSET_0+24:
672 case R300_TX_OFFSET_0+28:
673 case R300_TX_OFFSET_0+32:
674 case R300_TX_OFFSET_0+36:
675 case R300_TX_OFFSET_0+40:
676 case R300_TX_OFFSET_0+44:
677 case R300_TX_OFFSET_0+48:
678 case R300_TX_OFFSET_0+52:
679 case R300_TX_OFFSET_0+56:
680 case R300_TX_OFFSET_0+60:
Jerome Glisse068a1172009-06-17 13:28:30 +0200681 i = (reg - R300_TX_OFFSET_0) >> 2;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200682 r = r100_cs_packet_next_reloc(p, &reloc);
683 if (r) {
684 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
685 idx, reg);
686 r100_cs_dump_packet(p, pkt);
687 return r;
688 }
Maciej Cencora6e726772009-12-15 23:13:08 +0100689
690 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
691 tile_flags |= R300_TXO_MACRO_TILE;
692 if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
693 tile_flags |= R300_TXO_MICRO_TILE;
694
695 tmp = idx_value + ((u32)reloc->lobj.gpu_offset);
696 tmp |= tile_flags;
697 ib[idx] = tmp;
Jerome Glisse068a1172009-06-17 13:28:30 +0200698 track->textures[i].robj = reloc->robj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200699 break;
700 /* Tracked registers */
Jerome Glisse068a1172009-06-17 13:28:30 +0200701 case 0x2084:
702 /* VAP_VF_CNTL */
Dave Airlie513bcb42009-09-23 16:56:27 +1000703 track->vap_vf_cntl = idx_value;
Jerome Glisse068a1172009-06-17 13:28:30 +0200704 break;
705 case 0x20B4:
706 /* VAP_VTX_SIZE */
Dave Airlie513bcb42009-09-23 16:56:27 +1000707 track->vtx_size = idx_value & 0x7F;
Jerome Glisse068a1172009-06-17 13:28:30 +0200708 break;
709 case 0x2134:
710 /* VAP_VF_MAX_VTX_INDX */
Dave Airlie513bcb42009-09-23 16:56:27 +1000711 track->max_indx = idx_value & 0x00FFFFFFUL;
Jerome Glisse068a1172009-06-17 13:28:30 +0200712 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200713 case 0x43E4:
714 /* SC_SCISSOR1 */
Dave Airlie513bcb42009-09-23 16:56:27 +1000715 track->maxy = ((idx_value >> 13) & 0x1FFF) + 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200716 if (p->rdev->family < CHIP_RV515) {
717 track->maxy -= 1440;
718 }
719 break;
720 case 0x4E00:
721 /* RB3D_CCTL */
Dave Airlie513bcb42009-09-23 16:56:27 +1000722 track->num_cb = ((idx_value >> 5) & 0x3) + 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200723 break;
724 case 0x4E38:
725 case 0x4E3C:
726 case 0x4E40:
727 case 0x4E44:
728 /* RB3D_COLORPITCH0 */
729 /* RB3D_COLORPITCH1 */
730 /* RB3D_COLORPITCH2 */
731 /* RB3D_COLORPITCH3 */
Dave Airliee024e112009-06-24 09:48:08 +1000732 r = r100_cs_packet_next_reloc(p, &reloc);
733 if (r) {
734 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
735 idx, reg);
736 r100_cs_dump_packet(p, pkt);
737 return r;
738 }
739
740 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
741 tile_flags |= R300_COLOR_TILE_ENABLE;
742 if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
743 tile_flags |= R300_COLOR_MICROTILE_ENABLE;
744
Dave Airlie513bcb42009-09-23 16:56:27 +1000745 tmp = idx_value & ~(0x7 << 16);
Dave Airliee024e112009-06-24 09:48:08 +1000746 tmp |= tile_flags;
747 ib[idx] = tmp;
748
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200749 i = (reg - 0x4E38) >> 2;
Dave Airlie513bcb42009-09-23 16:56:27 +1000750 track->cb[i].pitch = idx_value & 0x3FFE;
751 switch (((idx_value >> 21) & 0xF)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200752 case 9:
753 case 11:
754 case 12:
755 track->cb[i].cpp = 1;
756 break;
757 case 3:
758 case 4:
759 case 13:
760 case 15:
761 track->cb[i].cpp = 2;
762 break;
763 case 6:
764 track->cb[i].cpp = 4;
765 break;
766 case 10:
767 track->cb[i].cpp = 8;
768 break;
769 case 7:
770 track->cb[i].cpp = 16;
771 break;
772 default:
773 DRM_ERROR("Invalid color buffer format (%d) !\n",
Dave Airlie513bcb42009-09-23 16:56:27 +1000774 ((idx_value >> 21) & 0xF));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200775 return -EINVAL;
776 }
777 break;
778 case 0x4F00:
779 /* ZB_CNTL */
Dave Airlie513bcb42009-09-23 16:56:27 +1000780 if (idx_value & 2) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200781 track->z_enabled = true;
782 } else {
783 track->z_enabled = false;
784 }
785 break;
786 case 0x4F10:
787 /* ZB_FORMAT */
Dave Airlie513bcb42009-09-23 16:56:27 +1000788 switch ((idx_value & 0xF)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200789 case 0:
790 case 1:
791 track->zb.cpp = 2;
792 break;
793 case 2:
794 track->zb.cpp = 4;
795 break;
796 default:
797 DRM_ERROR("Invalid z buffer format (%d) !\n",
Dave Airlie513bcb42009-09-23 16:56:27 +1000798 (idx_value & 0xF));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200799 return -EINVAL;
800 }
801 break;
802 case 0x4F24:
803 /* ZB_DEPTHPITCH */
Dave Airliee024e112009-06-24 09:48:08 +1000804 r = r100_cs_packet_next_reloc(p, &reloc);
805 if (r) {
806 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
807 idx, reg);
808 r100_cs_dump_packet(p, pkt);
809 return r;
810 }
811
812 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
813 tile_flags |= R300_DEPTHMACROTILE_ENABLE;
814 if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
815 tile_flags |= R300_DEPTHMICROTILE_TILED;;
816
Dave Airlie513bcb42009-09-23 16:56:27 +1000817 tmp = idx_value & ~(0x7 << 16);
Dave Airliee024e112009-06-24 09:48:08 +1000818 tmp |= tile_flags;
819 ib[idx] = tmp;
820
Dave Airlie513bcb42009-09-23 16:56:27 +1000821 track->zb.pitch = idx_value & 0x3FFC;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200822 break;
Jerome Glisse068a1172009-06-17 13:28:30 +0200823 case 0x4104:
824 for (i = 0; i < 16; i++) {
825 bool enabled;
826
Dave Airlie513bcb42009-09-23 16:56:27 +1000827 enabled = !!(idx_value & (1 << i));
Jerome Glisse068a1172009-06-17 13:28:30 +0200828 track->textures[i].enabled = enabled;
829 }
830 break;
831 case 0x44C0:
832 case 0x44C4:
833 case 0x44C8:
834 case 0x44CC:
835 case 0x44D0:
836 case 0x44D4:
837 case 0x44D8:
838 case 0x44DC:
839 case 0x44E0:
840 case 0x44E4:
841 case 0x44E8:
842 case 0x44EC:
843 case 0x44F0:
844 case 0x44F4:
845 case 0x44F8:
846 case 0x44FC:
847 /* TX_FORMAT1_[0-15] */
848 i = (reg - 0x44C0) >> 2;
Dave Airlie513bcb42009-09-23 16:56:27 +1000849 tmp = (idx_value >> 25) & 0x3;
Jerome Glisse068a1172009-06-17 13:28:30 +0200850 track->textures[i].tex_coord_type = tmp;
Dave Airlie513bcb42009-09-23 16:56:27 +1000851 switch ((idx_value & 0x1F)) {
Dave Airlie551ebd82009-09-01 15:25:57 +1000852 case R300_TX_FORMAT_X8:
853 case R300_TX_FORMAT_Y4X4:
854 case R300_TX_FORMAT_Z3Y3X2:
Jerome Glisse068a1172009-06-17 13:28:30 +0200855 track->textures[i].cpp = 1;
856 break;
Dave Airlie551ebd82009-09-01 15:25:57 +1000857 case R300_TX_FORMAT_X16:
858 case R300_TX_FORMAT_Y8X8:
859 case R300_TX_FORMAT_Z5Y6X5:
860 case R300_TX_FORMAT_Z6Y5X5:
861 case R300_TX_FORMAT_W4Z4Y4X4:
862 case R300_TX_FORMAT_W1Z5Y5X5:
Dave Airlie551ebd82009-09-01 15:25:57 +1000863 case R300_TX_FORMAT_D3DMFT_CxV8U8:
864 case R300_TX_FORMAT_B8G8_B8G8:
865 case R300_TX_FORMAT_G8R8_G8B8:
Jerome Glisse068a1172009-06-17 13:28:30 +0200866 track->textures[i].cpp = 2;
867 break;
Dave Airlie551ebd82009-09-01 15:25:57 +1000868 case R300_TX_FORMAT_Y16X16:
869 case R300_TX_FORMAT_Z11Y11X10:
870 case R300_TX_FORMAT_Z10Y11X11:
871 case R300_TX_FORMAT_W8Z8Y8X8:
872 case R300_TX_FORMAT_W2Z10Y10X10:
873 case 0x17:
874 case R300_TX_FORMAT_FL_I32:
875 case 0x1e:
Jerome Glisse068a1172009-06-17 13:28:30 +0200876 track->textures[i].cpp = 4;
877 break;
Dave Airlie551ebd82009-09-01 15:25:57 +1000878 case R300_TX_FORMAT_W16Z16Y16X16:
879 case R300_TX_FORMAT_FL_R16G16B16A16:
880 case R300_TX_FORMAT_FL_I32A32:
Jerome Glisse068a1172009-06-17 13:28:30 +0200881 track->textures[i].cpp = 8;
882 break;
Dave Airlie551ebd82009-09-01 15:25:57 +1000883 case R300_TX_FORMAT_FL_R32G32B32A32:
Jerome Glisse068a1172009-06-17 13:28:30 +0200884 track->textures[i].cpp = 16;
885 break;
Dave Airlied785d782009-12-07 13:16:06 +1000886 case R300_TX_FORMAT_DXT1:
887 track->textures[i].cpp = 1;
888 track->textures[i].compress_format = R100_TRACK_COMP_DXT1;
889 break;
890 case R300_TX_FORMAT_DXT3:
891 case R300_TX_FORMAT_DXT5:
892 track->textures[i].cpp = 1;
893 track->textures[i].compress_format = R100_TRACK_COMP_DXT35;
894 break;
Jerome Glisse068a1172009-06-17 13:28:30 +0200895 default:
896 DRM_ERROR("Invalid texture format %u\n",
Dave Airlie513bcb42009-09-23 16:56:27 +1000897 (idx_value & 0x1F));
Jerome Glisse068a1172009-06-17 13:28:30 +0200898 return -EINVAL;
899 break;
900 }
901 break;
902 case 0x4400:
903 case 0x4404:
904 case 0x4408:
905 case 0x440C:
906 case 0x4410:
907 case 0x4414:
908 case 0x4418:
909 case 0x441C:
910 case 0x4420:
911 case 0x4424:
912 case 0x4428:
913 case 0x442C:
914 case 0x4430:
915 case 0x4434:
916 case 0x4438:
917 case 0x443C:
918 /* TX_FILTER0_[0-15] */
919 i = (reg - 0x4400) >> 2;
Dave Airlie513bcb42009-09-23 16:56:27 +1000920 tmp = idx_value & 0x7;
Jerome Glisse068a1172009-06-17 13:28:30 +0200921 if (tmp == 2 || tmp == 4 || tmp == 6) {
922 track->textures[i].roundup_w = false;
923 }
Dave Airlie513bcb42009-09-23 16:56:27 +1000924 tmp = (idx_value >> 3) & 0x7;
Jerome Glisse068a1172009-06-17 13:28:30 +0200925 if (tmp == 2 || tmp == 4 || tmp == 6) {
926 track->textures[i].roundup_h = false;
927 }
928 break;
929 case 0x4500:
930 case 0x4504:
931 case 0x4508:
932 case 0x450C:
933 case 0x4510:
934 case 0x4514:
935 case 0x4518:
936 case 0x451C:
937 case 0x4520:
938 case 0x4524:
939 case 0x4528:
940 case 0x452C:
941 case 0x4530:
942 case 0x4534:
943 case 0x4538:
944 case 0x453C:
945 /* TX_FORMAT2_[0-15] */
946 i = (reg - 0x4500) >> 2;
Dave Airlie513bcb42009-09-23 16:56:27 +1000947 tmp = idx_value & 0x3FFF;
Jerome Glisse068a1172009-06-17 13:28:30 +0200948 track->textures[i].pitch = tmp + 1;
949 if (p->rdev->family >= CHIP_RV515) {
Dave Airlie513bcb42009-09-23 16:56:27 +1000950 tmp = ((idx_value >> 15) & 1) << 11;
Jerome Glisse068a1172009-06-17 13:28:30 +0200951 track->textures[i].width_11 = tmp;
Dave Airlie513bcb42009-09-23 16:56:27 +1000952 tmp = ((idx_value >> 16) & 1) << 11;
Jerome Glisse068a1172009-06-17 13:28:30 +0200953 track->textures[i].height_11 = tmp;
954 }
955 break;
956 case 0x4480:
957 case 0x4484:
958 case 0x4488:
959 case 0x448C:
960 case 0x4490:
961 case 0x4494:
962 case 0x4498:
963 case 0x449C:
964 case 0x44A0:
965 case 0x44A4:
966 case 0x44A8:
967 case 0x44AC:
968 case 0x44B0:
969 case 0x44B4:
970 case 0x44B8:
971 case 0x44BC:
972 /* TX_FORMAT0_[0-15] */
973 i = (reg - 0x4480) >> 2;
Dave Airlie513bcb42009-09-23 16:56:27 +1000974 tmp = idx_value & 0x7FF;
Jerome Glisse068a1172009-06-17 13:28:30 +0200975 track->textures[i].width = tmp + 1;
Dave Airlie513bcb42009-09-23 16:56:27 +1000976 tmp = (idx_value >> 11) & 0x7FF;
Jerome Glisse068a1172009-06-17 13:28:30 +0200977 track->textures[i].height = tmp + 1;
Dave Airlie513bcb42009-09-23 16:56:27 +1000978 tmp = (idx_value >> 26) & 0xF;
Jerome Glisse068a1172009-06-17 13:28:30 +0200979 track->textures[i].num_levels = tmp;
Dave Airlie513bcb42009-09-23 16:56:27 +1000980 tmp = idx_value & (1 << 31);
Jerome Glisse068a1172009-06-17 13:28:30 +0200981 track->textures[i].use_pitch = !!tmp;
Dave Airlie513bcb42009-09-23 16:56:27 +1000982 tmp = (idx_value >> 22) & 0xF;
Jerome Glisse068a1172009-06-17 13:28:30 +0200983 track->textures[i].txdepth = tmp;
984 break;
Dave Airlie3f8befe2009-08-15 20:54:13 +1000985 case R300_ZB_ZPASS_ADDR:
986 r = r100_cs_packet_next_reloc(p, &reloc);
987 if (r) {
988 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
989 idx, reg);
990 r100_cs_dump_packet(p, pkt);
991 return r;
992 }
Dave Airlie513bcb42009-09-23 16:56:27 +1000993 ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
Dave Airlie3f8befe2009-08-15 20:54:13 +1000994 break;
Marek Olšák46c64d42009-12-17 06:02:28 +0100995 case 0x4e0c:
996 /* RB3D_COLOR_CHANNEL_MASK */
997 track->color_channel_mask = idx_value;
998 break;
999 case 0x4d1c:
1000 /* ZB_BW_CNTL */
1001 track->fastfill = !!(idx_value & (1 << 2));
1002 break;
1003 case 0x4e04:
1004 /* RB3D_BLENDCNTL */
1005 track->blend_read_enable = !!(idx_value & (1 << 2));
1006 break;
Dave Airlie3f8befe2009-08-15 20:54:13 +10001007 case 0x4be8:
1008 /* valid register only on RV530 */
1009 if (p->rdev->family == CHIP_RV530)
1010 break;
1011 /* fallthrough do not move */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001012 default:
Jerome Glisse068a1172009-06-17 13:28:30 +02001013 printk(KERN_ERR "Forbidden register 0x%04X in cs at %d\n",
1014 reg, idx);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001015 return -EINVAL;
1016 }
1017 return 0;
1018}
1019
1020static int r300_packet3_check(struct radeon_cs_parser *p,
1021 struct radeon_cs_packet *pkt)
1022{
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001023 struct radeon_cs_reloc *reloc;
Dave Airlie551ebd82009-09-01 15:25:57 +10001024 struct r100_cs_track *track;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001025 volatile uint32_t *ib;
1026 unsigned idx;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001027 int r;
1028
1029 ib = p->ib->ptr;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001030 idx = pkt->idx + 1;
Dave Airlie551ebd82009-09-01 15:25:57 +10001031 track = (struct r100_cs_track *)p->track;
Jerome Glisse068a1172009-06-17 13:28:30 +02001032 switch(pkt->opcode) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001033 case PACKET3_3D_LOAD_VBPNTR:
Dave Airlie513bcb42009-09-23 16:56:27 +10001034 r = r100_packet3_load_vbpntr(p, pkt, idx);
1035 if (r)
1036 return r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001037 break;
1038 case PACKET3_INDX_BUFFER:
1039 r = r100_cs_packet_next_reloc(p, &reloc);
1040 if (r) {
1041 DRM_ERROR("No reloc for packet3 %d\n", pkt->opcode);
1042 r100_cs_dump_packet(p, pkt);
1043 return r;
1044 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001045 ib[idx+1] = radeon_get_ib_value(p, idx + 1) + ((u32)reloc->lobj.gpu_offset);
Jerome Glisse068a1172009-06-17 13:28:30 +02001046 r = r100_cs_track_check_pkt3_indx_buffer(p, pkt, reloc->robj);
1047 if (r) {
1048 return r;
1049 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001050 break;
1051 /* Draw packet */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001052 case PACKET3_3D_DRAW_IMMD:
Jerome Glisse068a1172009-06-17 13:28:30 +02001053 /* Number of dwords is vtx_size * (num_vertices - 1)
1054 * PRIM_WALK must be equal to 3 vertex data in embedded
1055 * in cmd stream */
Dave Airlie513bcb42009-09-23 16:56:27 +10001056 if (((radeon_get_ib_value(p, idx + 1) >> 4) & 0x3) != 3) {
Jerome Glisse068a1172009-06-17 13:28:30 +02001057 DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n");
1058 return -EINVAL;
1059 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001060 track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1);
Jerome Glisse068a1172009-06-17 13:28:30 +02001061 track->immd_dwords = pkt->count - 1;
Dave Airlie551ebd82009-09-01 15:25:57 +10001062 r = r100_cs_track_check(p->rdev, track);
Jerome Glisse068a1172009-06-17 13:28:30 +02001063 if (r) {
1064 return r;
1065 }
1066 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001067 case PACKET3_3D_DRAW_IMMD_2:
Jerome Glisse068a1172009-06-17 13:28:30 +02001068 /* Number of dwords is vtx_size * (num_vertices - 1)
1069 * PRIM_WALK must be equal to 3 vertex data in embedded
1070 * in cmd stream */
Dave Airlie513bcb42009-09-23 16:56:27 +10001071 if (((radeon_get_ib_value(p, idx) >> 4) & 0x3) != 3) {
Jerome Glisse068a1172009-06-17 13:28:30 +02001072 DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n");
1073 return -EINVAL;
1074 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001075 track->vap_vf_cntl = radeon_get_ib_value(p, idx);
Jerome Glisse068a1172009-06-17 13:28:30 +02001076 track->immd_dwords = pkt->count;
Dave Airlie551ebd82009-09-01 15:25:57 +10001077 r = r100_cs_track_check(p->rdev, track);
Jerome Glisse068a1172009-06-17 13:28:30 +02001078 if (r) {
1079 return r;
1080 }
1081 break;
1082 case PACKET3_3D_DRAW_VBUF:
Dave Airlie513bcb42009-09-23 16:56:27 +10001083 track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1);
Dave Airlie551ebd82009-09-01 15:25:57 +10001084 r = r100_cs_track_check(p->rdev, track);
Jerome Glisse068a1172009-06-17 13:28:30 +02001085 if (r) {
1086 return r;
1087 }
1088 break;
1089 case PACKET3_3D_DRAW_VBUF_2:
Dave Airlie513bcb42009-09-23 16:56:27 +10001090 track->vap_vf_cntl = radeon_get_ib_value(p, idx);
Dave Airlie551ebd82009-09-01 15:25:57 +10001091 r = r100_cs_track_check(p->rdev, track);
Jerome Glisse068a1172009-06-17 13:28:30 +02001092 if (r) {
1093 return r;
1094 }
1095 break;
1096 case PACKET3_3D_DRAW_INDX:
Dave Airlie513bcb42009-09-23 16:56:27 +10001097 track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1);
Dave Airlie551ebd82009-09-01 15:25:57 +10001098 r = r100_cs_track_check(p->rdev, track);
Jerome Glisse068a1172009-06-17 13:28:30 +02001099 if (r) {
1100 return r;
1101 }
1102 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001103 case PACKET3_3D_DRAW_INDX_2:
Dave Airlie513bcb42009-09-23 16:56:27 +10001104 track->vap_vf_cntl = radeon_get_ib_value(p, idx);
Dave Airlie551ebd82009-09-01 15:25:57 +10001105 r = r100_cs_track_check(p->rdev, track);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001106 if (r) {
1107 return r;
1108 }
1109 break;
1110 case PACKET3_NOP:
1111 break;
1112 default:
1113 DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode);
1114 return -EINVAL;
1115 }
1116 return 0;
1117}
1118
1119int r300_cs_parse(struct radeon_cs_parser *p)
1120{
1121 struct radeon_cs_packet pkt;
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001122 struct r100_cs_track *track;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001123 int r;
1124
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001125 track = kzalloc(sizeof(*track), GFP_KERNEL);
1126 r100_cs_track_clear(p->rdev, track);
1127 p->track = track;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001128 do {
1129 r = r100_cs_packet_parse(p, &pkt, p->idx);
1130 if (r) {
1131 return r;
1132 }
1133 p->idx += pkt.count + 2;
1134 switch (pkt.type) {
1135 case PACKET_TYPE0:
1136 r = r100_cs_parse_packet0(p, &pkt,
Jerome Glisse068a1172009-06-17 13:28:30 +02001137 p->rdev->config.r300.reg_safe_bm,
1138 p->rdev->config.r300.reg_safe_bm_size,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001139 &r300_packet0_check);
1140 break;
1141 case PACKET_TYPE2:
1142 break;
1143 case PACKET_TYPE3:
1144 r = r300_packet3_check(p, &pkt);
1145 break;
1146 default:
1147 DRM_ERROR("Unknown packet type %d !\n", pkt.type);
1148 return -EINVAL;
1149 }
1150 if (r) {
1151 return r;
1152 }
1153 } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
1154 return 0;
1155}
Jerome Glisse068a1172009-06-17 13:28:30 +02001156
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001157void r300_set_reg_safe(struct radeon_device *rdev)
Jerome Glisse068a1172009-06-17 13:28:30 +02001158{
1159 rdev->config.r300.reg_safe_bm = r300_reg_safe_bm;
1160 rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(r300_reg_safe_bm);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001161}
1162
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001163void r300_mc_program(struct radeon_device *rdev)
1164{
1165 struct r100_mc_save save;
1166 int r;
1167
1168 r = r100_debugfs_mc_info_init(rdev);
1169 if (r) {
1170 dev_err(rdev->dev, "Failed to create r100_mc debugfs file.\n");
1171 }
1172
1173 /* Stops all mc clients */
1174 r100_mc_stop(rdev, &save);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001175 if (rdev->flags & RADEON_IS_AGP) {
1176 WREG32(R_00014C_MC_AGP_LOCATION,
1177 S_00014C_MC_AGP_START(rdev->mc.gtt_start >> 16) |
1178 S_00014C_MC_AGP_TOP(rdev->mc.gtt_end >> 16));
1179 WREG32(R_000170_AGP_BASE, lower_32_bits(rdev->mc.agp_base));
1180 WREG32(R_00015C_AGP_BASE_2,
1181 upper_32_bits(rdev->mc.agp_base) & 0xff);
1182 } else {
1183 WREG32(R_00014C_MC_AGP_LOCATION, 0x0FFFFFFF);
1184 WREG32(R_000170_AGP_BASE, 0);
1185 WREG32(R_00015C_AGP_BASE_2, 0);
1186 }
1187 /* Wait for mc idle */
1188 if (r300_mc_wait_for_idle(rdev))
1189 DRM_INFO("Failed to wait MC idle before programming MC.\n");
1190 /* Program MC, should be a 32bits limited address space */
1191 WREG32(R_000148_MC_FB_LOCATION,
1192 S_000148_MC_FB_START(rdev->mc.vram_start >> 16) |
1193 S_000148_MC_FB_TOP(rdev->mc.vram_end >> 16));
1194 r100_mc_resume(rdev, &save);
1195}
Jerome Glisseca6ffc62009-10-01 10:20:52 +02001196
1197void r300_clock_startup(struct radeon_device *rdev)
1198{
1199 u32 tmp;
1200
1201 if (radeon_dynclks != -1 && radeon_dynclks)
1202 radeon_legacy_set_clock_gating(rdev, 1);
1203 /* We need to force on some of the block */
1204 tmp = RREG32_PLL(R_00000D_SCLK_CNTL);
1205 tmp |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1);
1206 if ((rdev->family == CHIP_RV350) || (rdev->family == CHIP_RV380))
1207 tmp |= S_00000D_FORCE_VAP(1);
1208 WREG32_PLL(R_00000D_SCLK_CNTL, tmp);
1209}
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001210
1211static int r300_startup(struct radeon_device *rdev)
1212{
1213 int r;
1214
Alex Deucher92cde002009-12-04 10:55:12 -05001215 /* set common regs */
1216 r100_set_common_regs(rdev);
1217 /* program mc */
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001218 r300_mc_program(rdev);
1219 /* Resume clock */
1220 r300_clock_startup(rdev);
1221 /* Initialize GPU configuration (# pipes, ...) */
1222 r300_gpu_init(rdev);
1223 /* Initialize GART (initialize after TTM so we can allocate
1224 * memory through TTM but finalize after TTM) */
1225 if (rdev->flags & RADEON_IS_PCIE) {
1226 r = rv370_pcie_gart_enable(rdev);
1227 if (r)
1228 return r;
1229 }
Dave Airlie17e15b02009-11-05 15:36:53 +10001230
1231 if (rdev->family == CHIP_R300 ||
1232 rdev->family == CHIP_R350 ||
1233 rdev->family == CHIP_RV350)
1234 r100_enable_bm(rdev);
1235
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001236 if (rdev->flags & RADEON_IS_PCI) {
1237 r = r100_pci_gart_enable(rdev);
1238 if (r)
1239 return r;
1240 }
1241 /* Enable IRQ */
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001242 r100_irq_set(rdev);
1243 /* 1M ring buffer */
1244 r = r100_cp_init(rdev, 1024 * 1024);
1245 if (r) {
1246 dev_err(rdev->dev, "failled initializing CP (%d).\n", r);
1247 return r;
1248 }
1249 r = r100_wb_init(rdev);
1250 if (r)
1251 dev_err(rdev->dev, "failled initializing WB (%d).\n", r);
1252 r = r100_ib_init(rdev);
1253 if (r) {
1254 dev_err(rdev->dev, "failled initializing IB (%d).\n", r);
1255 return r;
1256 }
1257 return 0;
1258}
1259
1260int r300_resume(struct radeon_device *rdev)
1261{
1262 /* Make sur GART are not working */
1263 if (rdev->flags & RADEON_IS_PCIE)
1264 rv370_pcie_gart_disable(rdev);
1265 if (rdev->flags & RADEON_IS_PCI)
1266 r100_pci_gart_disable(rdev);
1267 /* Resume clock before doing reset */
1268 r300_clock_startup(rdev);
1269 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
1270 if (radeon_gpu_reset(rdev)) {
1271 dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
1272 RREG32(R_000E40_RBBM_STATUS),
1273 RREG32(R_0007C0_CP_STAT));
1274 }
1275 /* post */
1276 radeon_combios_asic_init(rdev->ddev);
1277 /* Resume clock after posting */
1278 r300_clock_startup(rdev);
Dave Airlie550e2d92009-12-09 14:15:38 +10001279 /* Initialize surface registers */
1280 radeon_surface_init(rdev);
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001281 return r300_startup(rdev);
1282}
1283
1284int r300_suspend(struct radeon_device *rdev)
1285{
1286 r100_cp_disable(rdev);
1287 r100_wb_disable(rdev);
1288 r100_irq_disable(rdev);
1289 if (rdev->flags & RADEON_IS_PCIE)
1290 rv370_pcie_gart_disable(rdev);
1291 if (rdev->flags & RADEON_IS_PCI)
1292 r100_pci_gart_disable(rdev);
1293 return 0;
1294}
1295
1296void r300_fini(struct radeon_device *rdev)
1297{
1298 r300_suspend(rdev);
1299 r100_cp_fini(rdev);
1300 r100_wb_fini(rdev);
1301 r100_ib_fini(rdev);
1302 radeon_gem_fini(rdev);
1303 if (rdev->flags & RADEON_IS_PCIE)
1304 rv370_pcie_gart_fini(rdev);
1305 if (rdev->flags & RADEON_IS_PCI)
1306 r100_pci_gart_fini(rdev);
1307 radeon_irq_kms_fini(rdev);
1308 radeon_fence_driver_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +01001309 radeon_bo_fini(rdev);
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001310 radeon_atombios_fini(rdev);
1311 kfree(rdev->bios);
1312 rdev->bios = NULL;
1313}
1314
1315int r300_init(struct radeon_device *rdev)
1316{
1317 int r;
1318
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001319 /* Disable VGA */
1320 r100_vga_render_disable(rdev);
1321 /* Initialize scratch registers */
1322 radeon_scratch_init(rdev);
1323 /* Initialize surface registers */
1324 radeon_surface_init(rdev);
1325 /* TODO: disable VGA need to use VGA request */
1326 /* BIOS*/
1327 if (!radeon_get_bios(rdev)) {
1328 if (ASIC_IS_AVIVO(rdev))
1329 return -EINVAL;
1330 }
1331 if (rdev->is_atom_bios) {
1332 dev_err(rdev->dev, "Expecting combios for RS400/RS480 GPU\n");
1333 return -EINVAL;
1334 } else {
1335 r = radeon_combios_init(rdev);
1336 if (r)
1337 return r;
1338 }
1339 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
1340 if (radeon_gpu_reset(rdev)) {
1341 dev_warn(rdev->dev,
1342 "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
1343 RREG32(R_000E40_RBBM_STATUS),
1344 RREG32(R_0007C0_CP_STAT));
1345 }
1346 /* check if cards are posted or not */
Dave Airlie72542d72009-12-01 14:06:31 +10001347 if (radeon_boot_test_post_card(rdev) == false)
1348 return -EINVAL;
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001349 /* Set asic errata */
1350 r300_errata(rdev);
1351 /* Initialize clocks */
1352 radeon_get_clock_info(rdev->ddev);
Rafał Miłecki62340772009-12-15 21:46:58 +01001353 /* Initialize power management */
1354 radeon_pm_init(rdev);
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001355 /* Get vram informations */
1356 r300_vram_info(rdev);
1357 /* Initialize memory controller (also test AGP) */
1358 r = r420_mc_init(rdev);
1359 if (r)
1360 return r;
1361 /* Fence driver */
1362 r = radeon_fence_driver_init(rdev);
1363 if (r)
1364 return r;
1365 r = radeon_irq_kms_init(rdev);
1366 if (r)
1367 return r;
1368 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +01001369 r = radeon_bo_init(rdev);
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001370 if (r)
1371 return r;
1372 if (rdev->flags & RADEON_IS_PCIE) {
1373 r = rv370_pcie_gart_init(rdev);
1374 if (r)
1375 return r;
1376 }
1377 if (rdev->flags & RADEON_IS_PCI) {
1378 r = r100_pci_gart_init(rdev);
1379 if (r)
1380 return r;
1381 }
1382 r300_set_reg_safe(rdev);
1383 rdev->accel_working = true;
1384 r = r300_startup(rdev);
1385 if (r) {
1386 /* Somethings want wront with the accel init stop accel */
1387 dev_err(rdev->dev, "Disabling GPU acceleration\n");
1388 r300_suspend(rdev);
1389 r100_cp_fini(rdev);
1390 r100_wb_fini(rdev);
1391 r100_ib_fini(rdev);
1392 if (rdev->flags & RADEON_IS_PCIE)
1393 rv370_pcie_gart_fini(rdev);
1394 if (rdev->flags & RADEON_IS_PCI)
1395 r100_pci_gart_fini(rdev);
1396 radeon_irq_kms_fini(rdev);
1397 rdev->accel_working = false;
1398 }
1399 return 0;
1400}