blob: 748335c5fa84eacf383aa508a9a6ebc314949915 [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 Glissecafe6602010-01-07 12:39:21 +010039/* This files gather functions specifics to: r300,r350,rv350,rv370,rv380
40 *
41 * GPU Errata:
42 * - HOST_PATH_CNTL: r300 family seems to dislike write to HOST_PATH_CNTL
43 * using MMIO to flush host path read cache, this lead to HARDLOCKUP.
44 * However, scheduling such write to the ring seems harmless, i suspect
45 * the CP read collide with the flush somehow, or maybe the MC, hard to
46 * tell. (Jerome Glisse)
47 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +020048
49/*
50 * rv370,rv380 PCIE GART
51 */
Jerome Glisse207bf9e2009-09-30 15:35:32 +020052static int rv370_debugfs_pcie_gart_info_init(struct radeon_device *rdev);
53
Jerome Glisse771fe6b2009-06-05 14:42:42 +020054void rv370_pcie_gart_tlb_flush(struct radeon_device *rdev)
55{
56 uint32_t tmp;
57 int i;
58
59 /* Workaround HW bug do flush 2 times */
60 for (i = 0; i < 2; i++) {
61 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL);
62 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp | RADEON_PCIE_TX_GART_INVALIDATE_TLB);
63 (void)RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL);
64 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020065 }
Dave Airliede1b2892009-08-12 18:43:14 +100066 mb();
Jerome Glisse771fe6b2009-06-05 14:42:42 +020067}
68
Jerome Glisse4aac0472009-09-14 18:29:49 +020069int rv370_pcie_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr)
70{
71 void __iomem *ptr = (void *)rdev->gart.table.vram.ptr;
72
73 if (i < 0 || i > rdev->gart.num_gpu_pages) {
74 return -EINVAL;
75 }
76 addr = (lower_32_bits(addr) >> 8) |
77 ((upper_32_bits(addr) & 0xff) << 24) |
78 0xc;
79 /* on x86 we want this to be CPU endian, on powerpc
80 * on powerpc without HW swappers, it'll get swapped on way
81 * into VRAM - so no need for cpu_to_le32 on VRAM tables */
82 writel(addr, ((void __iomem *)ptr) + (i * 4));
83 return 0;
84}
85
86int rv370_pcie_gart_init(struct radeon_device *rdev)
87{
88 int r;
89
90 if (rdev->gart.table.vram.robj) {
91 WARN(1, "RV370 PCIE GART already initialized.\n");
92 return 0;
93 }
94 /* Initialize common gart structure */
95 r = radeon_gart_init(rdev);
96 if (r)
97 return r;
98 r = rv370_debugfs_pcie_gart_info_init(rdev);
99 if (r)
100 DRM_ERROR("Failed to register debugfs file for PCIE gart !\n");
101 rdev->gart.table_size = rdev->gart.num_gpu_pages * 4;
102 rdev->asic->gart_tlb_flush = &rv370_pcie_gart_tlb_flush;
103 rdev->asic->gart_set_page = &rv370_pcie_gart_set_page;
104 return radeon_gart_table_vram_alloc(rdev);
105}
106
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200107int rv370_pcie_gart_enable(struct radeon_device *rdev)
108{
109 uint32_t table_addr;
110 uint32_t tmp;
111 int r;
112
Jerome Glisse4aac0472009-09-14 18:29:49 +0200113 if (rdev->gart.table.vram.robj == NULL) {
114 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
115 return -EINVAL;
116 }
117 r = radeon_gart_table_vram_pin(rdev);
118 if (r)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200119 return r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200120 /* discard memory request outside of configured range */
121 tmp = RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD;
122 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp);
123 WREG32_PCIE(RADEON_PCIE_TX_GART_START_LO, rdev->mc.gtt_location);
Matt Turnera77f1712009-10-14 00:34:41 -0400124 tmp = rdev->mc.gtt_location + rdev->mc.gtt_size - RADEON_GPU_PAGE_SIZE;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200125 WREG32_PCIE(RADEON_PCIE_TX_GART_END_LO, tmp);
126 WREG32_PCIE(RADEON_PCIE_TX_GART_START_HI, 0);
127 WREG32_PCIE(RADEON_PCIE_TX_GART_END_HI, 0);
128 table_addr = rdev->gart.table_addr;
129 WREG32_PCIE(RADEON_PCIE_TX_GART_BASE, table_addr);
130 /* FIXME: setup default page */
131 WREG32_PCIE(RADEON_PCIE_TX_DISCARD_RD_ADDR_LO, rdev->mc.vram_location);
132 WREG32_PCIE(RADEON_PCIE_TX_DISCARD_RD_ADDR_HI, 0);
133 /* Clear error */
134 WREG32_PCIE(0x18, 0);
135 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL);
136 tmp |= RADEON_PCIE_TX_GART_EN;
137 tmp |= RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD;
138 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp);
139 rv370_pcie_gart_tlb_flush(rdev);
140 DRM_INFO("PCIE GART of %uM enabled (table at 0x%08X).\n",
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000141 (unsigned)(rdev->mc.gtt_size >> 20), table_addr);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200142 rdev->gart.ready = true;
143 return 0;
144}
145
146void rv370_pcie_gart_disable(struct radeon_device *rdev)
147{
Jerome Glisse4c788672009-11-20 14:29:23 +0100148 u32 tmp;
149 int r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200150
151 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL);
152 tmp |= RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD;
153 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp & ~RADEON_PCIE_TX_GART_EN);
154 if (rdev->gart.table.vram.robj) {
Jerome Glisse4c788672009-11-20 14:29:23 +0100155 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
156 if (likely(r == 0)) {
157 radeon_bo_kunmap(rdev->gart.table.vram.robj);
158 radeon_bo_unpin(rdev->gart.table.vram.robj);
159 radeon_bo_unreserve(rdev->gart.table.vram.robj);
160 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200161 }
162}
163
Jerome Glisse4aac0472009-09-14 18:29:49 +0200164void rv370_pcie_gart_fini(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200165{
Jerome Glisse4aac0472009-09-14 18:29:49 +0200166 rv370_pcie_gart_disable(rdev);
167 radeon_gart_table_vram_free(rdev);
168 radeon_gart_fini(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200169}
170
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200171void r300_fence_ring_emit(struct radeon_device *rdev,
172 struct radeon_fence *fence)
173{
174 /* Who ever call radeon_fence_emit should call ring_lock and ask
175 * for enough space (today caller are ib schedule and buffer move) */
176 /* Write SC register so SC & US assert idle */
Alex Deucher4612dc92010-02-05 01:58:28 -0500177 radeon_ring_write(rdev, PACKET0(R300_RE_SCISSORS_TL, 0));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200178 radeon_ring_write(rdev, 0);
Alex Deucher4612dc92010-02-05 01:58:28 -0500179 radeon_ring_write(rdev, PACKET0(R300_RE_SCISSORS_BR, 0));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200180 radeon_ring_write(rdev, 0);
181 /* Flush 3D cache */
Alex Deucher4612dc92010-02-05 01:58:28 -0500182 radeon_ring_write(rdev, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
183 radeon_ring_write(rdev, R300_RB3D_DC_FLUSH);
184 radeon_ring_write(rdev, PACKET0(R300_RB3D_ZCACHE_CTLSTAT, 0));
185 radeon_ring_write(rdev, R300_ZC_FLUSH);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200186 /* Wait until IDLE & CLEAN */
Alex Deucher4612dc92010-02-05 01:58:28 -0500187 radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0));
188 radeon_ring_write(rdev, (RADEON_WAIT_3D_IDLECLEAN |
189 RADEON_WAIT_2D_IDLECLEAN |
190 RADEON_WAIT_DMA_GUI_IDLE));
Jerome Glissecafe6602010-01-07 12:39:21 +0100191 radeon_ring_write(rdev, PACKET0(RADEON_HOST_PATH_CNTL, 0));
192 radeon_ring_write(rdev, rdev->config.r300.hdp_cntl |
193 RADEON_HDP_READ_BUFFER_INVALIDATE);
194 radeon_ring_write(rdev, PACKET0(RADEON_HOST_PATH_CNTL, 0));
195 radeon_ring_write(rdev, rdev->config.r300.hdp_cntl);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200196 /* Emit fence sequence & fire IRQ */
197 radeon_ring_write(rdev, PACKET0(rdev->fence_drv.scratch_reg, 0));
198 radeon_ring_write(rdev, fence->seq);
199 radeon_ring_write(rdev, PACKET0(RADEON_GEN_INT_STATUS, 0));
200 radeon_ring_write(rdev, RADEON_SW_INT_FIRE);
201}
202
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200203int r300_copy_dma(struct radeon_device *rdev,
204 uint64_t src_offset,
205 uint64_t dst_offset,
206 unsigned num_pages,
207 struct radeon_fence *fence)
208{
209 uint32_t size;
210 uint32_t cur_size;
211 int i, num_loops;
212 int r = 0;
213
214 /* radeon pitch is /64 */
215 size = num_pages << PAGE_SHIFT;
216 num_loops = DIV_ROUND_UP(size, 0x1FFFFF);
217 r = radeon_ring_lock(rdev, num_loops * 4 + 64);
218 if (r) {
219 DRM_ERROR("radeon: moving bo (%d).\n", r);
220 return r;
221 }
222 /* Must wait for 2D idle & clean before DMA or hangs might happen */
Jerome Glisse068a1172009-06-17 13:28:30 +0200223 radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0 ));
Alex Deucher4612dc92010-02-05 01:58:28 -0500224 radeon_ring_write(rdev, RADEON_WAIT_2D_IDLECLEAN);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200225 for (i = 0; i < num_loops; i++) {
226 cur_size = size;
227 if (cur_size > 0x1FFFFF) {
228 cur_size = 0x1FFFFF;
229 }
230 size -= cur_size;
231 radeon_ring_write(rdev, PACKET0(0x720, 2));
232 radeon_ring_write(rdev, src_offset);
233 radeon_ring_write(rdev, dst_offset);
234 radeon_ring_write(rdev, cur_size | (1 << 31) | (1 << 30));
235 src_offset += cur_size;
236 dst_offset += cur_size;
237 }
238 radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0));
239 radeon_ring_write(rdev, RADEON_WAIT_DMA_GUI_IDLE);
240 if (fence) {
241 r = radeon_fence_emit(rdev, fence);
242 }
243 radeon_ring_unlock_commit(rdev);
244 return r;
245}
246
247void r300_ring_start(struct radeon_device *rdev)
248{
249 unsigned gb_tile_config;
250 int r;
251
252 /* Sub pixel 1/12 so we can have 4K rendering according to doc */
253 gb_tile_config = (R300_ENABLE_TILING | R300_TILE_SIZE_16);
Jerome Glisse068a1172009-06-17 13:28:30 +0200254 switch(rdev->num_gb_pipes) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200255 case 2:
256 gb_tile_config |= R300_PIPE_COUNT_R300;
257 break;
258 case 3:
259 gb_tile_config |= R300_PIPE_COUNT_R420_3P;
260 break;
261 case 4:
262 gb_tile_config |= R300_PIPE_COUNT_R420;
263 break;
264 case 1:
265 default:
266 gb_tile_config |= R300_PIPE_COUNT_RV350;
267 break;
268 }
269
270 r = radeon_ring_lock(rdev, 64);
271 if (r) {
272 return;
273 }
274 radeon_ring_write(rdev, PACKET0(RADEON_ISYNC_CNTL, 0));
275 radeon_ring_write(rdev,
276 RADEON_ISYNC_ANY2D_IDLE3D |
277 RADEON_ISYNC_ANY3D_IDLE2D |
278 RADEON_ISYNC_WAIT_IDLEGUI |
279 RADEON_ISYNC_CPSCRATCH_IDLEGUI);
280 radeon_ring_write(rdev, PACKET0(R300_GB_TILE_CONFIG, 0));
281 radeon_ring_write(rdev, gb_tile_config);
282 radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0));
283 radeon_ring_write(rdev,
284 RADEON_WAIT_2D_IDLECLEAN |
285 RADEON_WAIT_3D_IDLECLEAN);
Alex Deucher4612dc92010-02-05 01:58:28 -0500286 radeon_ring_write(rdev, PACKET0(R300_DST_PIPE_CONFIG, 0));
287 radeon_ring_write(rdev, R300_PIPE_AUTO_CONFIG);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200288 radeon_ring_write(rdev, PACKET0(R300_GB_SELECT, 0));
289 radeon_ring_write(rdev, 0);
290 radeon_ring_write(rdev, PACKET0(R300_GB_ENABLE, 0));
291 radeon_ring_write(rdev, 0);
292 radeon_ring_write(rdev, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
293 radeon_ring_write(rdev, R300_RB3D_DC_FLUSH | R300_RB3D_DC_FREE);
294 radeon_ring_write(rdev, PACKET0(R300_RB3D_ZCACHE_CTLSTAT, 0));
295 radeon_ring_write(rdev, R300_ZC_FLUSH | R300_ZC_FREE);
296 radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0));
297 radeon_ring_write(rdev,
298 RADEON_WAIT_2D_IDLECLEAN |
299 RADEON_WAIT_3D_IDLECLEAN);
300 radeon_ring_write(rdev, PACKET0(R300_GB_AA_CONFIG, 0));
301 radeon_ring_write(rdev, 0);
302 radeon_ring_write(rdev, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
303 radeon_ring_write(rdev, R300_RB3D_DC_FLUSH | R300_RB3D_DC_FREE);
304 radeon_ring_write(rdev, PACKET0(R300_RB3D_ZCACHE_CTLSTAT, 0));
305 radeon_ring_write(rdev, R300_ZC_FLUSH | R300_ZC_FREE);
306 radeon_ring_write(rdev, PACKET0(R300_GB_MSPOS0, 0));
307 radeon_ring_write(rdev,
308 ((6 << R300_MS_X0_SHIFT) |
309 (6 << R300_MS_Y0_SHIFT) |
310 (6 << R300_MS_X1_SHIFT) |
311 (6 << R300_MS_Y1_SHIFT) |
312 (6 << R300_MS_X2_SHIFT) |
313 (6 << R300_MS_Y2_SHIFT) |
314 (6 << R300_MSBD0_Y_SHIFT) |
315 (6 << R300_MSBD0_X_SHIFT)));
316 radeon_ring_write(rdev, PACKET0(R300_GB_MSPOS1, 0));
317 radeon_ring_write(rdev,
318 ((6 << R300_MS_X3_SHIFT) |
319 (6 << R300_MS_Y3_SHIFT) |
320 (6 << R300_MS_X4_SHIFT) |
321 (6 << R300_MS_Y4_SHIFT) |
322 (6 << R300_MS_X5_SHIFT) |
323 (6 << R300_MS_Y5_SHIFT) |
324 (6 << R300_MSBD1_SHIFT)));
325 radeon_ring_write(rdev, PACKET0(R300_GA_ENHANCE, 0));
326 radeon_ring_write(rdev, R300_GA_DEADLOCK_CNTL | R300_GA_FASTSYNC_CNTL);
327 radeon_ring_write(rdev, PACKET0(R300_GA_POLY_MODE, 0));
328 radeon_ring_write(rdev,
329 R300_FRONT_PTYPE_TRIANGE | R300_BACK_PTYPE_TRIANGE);
330 radeon_ring_write(rdev, PACKET0(R300_GA_ROUND_MODE, 0));
331 radeon_ring_write(rdev,
332 R300_GEOMETRY_ROUND_NEAREST |
333 R300_COLOR_ROUND_NEAREST);
334 radeon_ring_unlock_commit(rdev);
335}
336
337void r300_errata(struct radeon_device *rdev)
338{
339 rdev->pll_errata = 0;
340
341 if (rdev->family == CHIP_R300 &&
342 (RREG32(RADEON_CONFIG_CNTL) & RADEON_CFG_ATI_REV_ID_MASK) == RADEON_CFG_ATI_REV_A11) {
343 rdev->pll_errata |= CHIP_ERRATA_R300_CG;
344 }
345}
346
347int r300_mc_wait_for_idle(struct radeon_device *rdev)
348{
349 unsigned i;
350 uint32_t tmp;
351
352 for (i = 0; i < rdev->usec_timeout; i++) {
353 /* read MC_STATUS */
Alex Deucher4612dc92010-02-05 01:58:28 -0500354 tmp = RREG32(RADEON_MC_STATUS);
355 if (tmp & R300_MC_IDLE) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200356 return 0;
357 }
358 DRM_UDELAY(1);
359 }
360 return -1;
361}
362
363void r300_gpu_init(struct radeon_device *rdev)
364{
365 uint32_t gb_tile_config, tmp;
366
367 r100_hdp_reset(rdev);
368 /* FIXME: rv380 one pipes ? */
369 if ((rdev->family == CHIP_R300) || (rdev->family == CHIP_R350)) {
370 /* r300,r350 */
371 rdev->num_gb_pipes = 2;
372 } else {
373 /* rv350,rv370,rv380 */
374 rdev->num_gb_pipes = 1;
375 }
Alex Deucherf779b3e2009-08-19 19:11:39 -0400376 rdev->num_z_pipes = 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200377 gb_tile_config = (R300_ENABLE_TILING | R300_TILE_SIZE_16);
378 switch (rdev->num_gb_pipes) {
379 case 2:
380 gb_tile_config |= R300_PIPE_COUNT_R300;
381 break;
382 case 3:
383 gb_tile_config |= R300_PIPE_COUNT_R420_3P;
384 break;
385 case 4:
386 gb_tile_config |= R300_PIPE_COUNT_R420;
387 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200388 default:
Jerome Glisse068a1172009-06-17 13:28:30 +0200389 case 1:
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200390 gb_tile_config |= R300_PIPE_COUNT_RV350;
391 break;
392 }
393 WREG32(R300_GB_TILE_CONFIG, gb_tile_config);
394
395 if (r100_gui_wait_for_idle(rdev)) {
396 printk(KERN_WARNING "Failed to wait GUI idle while "
397 "programming pipes. Bad things might happen.\n");
398 }
399
Alex Deucher4612dc92010-02-05 01:58:28 -0500400 tmp = RREG32(R300_DST_PIPE_CONFIG);
401 WREG32(R300_DST_PIPE_CONFIG, tmp | R300_PIPE_AUTO_CONFIG);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200402
403 WREG32(R300_RB2D_DSTCACHE_MODE,
404 R300_DC_AUTOFLUSH_ENABLE |
405 R300_DC_DC_DISABLE_IGNORE_PE);
406
407 if (r100_gui_wait_for_idle(rdev)) {
408 printk(KERN_WARNING "Failed to wait GUI idle while "
409 "programming pipes. Bad things might happen.\n");
410 }
411 if (r300_mc_wait_for_idle(rdev)) {
412 printk(KERN_WARNING "Failed to wait MC idle while "
413 "programming pipes. Bad things might happen.\n");
414 }
Alex Deucherf779b3e2009-08-19 19:11:39 -0400415 DRM_INFO("radeon: %d quad pipes, %d Z pipes initialized.\n",
416 rdev->num_gb_pipes, rdev->num_z_pipes);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200417}
418
419int r300_ga_reset(struct radeon_device *rdev)
420{
421 uint32_t tmp;
422 bool reinit_cp;
423 int i;
424
425 reinit_cp = rdev->cp.ready;
426 rdev->cp.ready = false;
427 for (i = 0; i < rdev->usec_timeout; i++) {
428 WREG32(RADEON_CP_CSQ_MODE, 0);
429 WREG32(RADEON_CP_CSQ_CNTL, 0);
430 WREG32(RADEON_RBBM_SOFT_RESET, 0x32005);
431 (void)RREG32(RADEON_RBBM_SOFT_RESET);
432 udelay(200);
433 WREG32(RADEON_RBBM_SOFT_RESET, 0);
434 /* Wait to prevent race in RBBM_STATUS */
435 mdelay(1);
436 tmp = RREG32(RADEON_RBBM_STATUS);
437 if (tmp & ((1 << 20) | (1 << 26))) {
438 DRM_ERROR("VAP & CP still busy (RBBM_STATUS=0x%08X)", tmp);
439 /* GA still busy soft reset it */
440 WREG32(0x429C, 0x200);
441 WREG32(R300_VAP_PVS_STATE_FLUSH_REG, 0);
Alex Deucher4612dc92010-02-05 01:58:28 -0500442 WREG32(R300_RE_SCISSORS_TL, 0);
443 WREG32(R300_RE_SCISSORS_BR, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200444 WREG32(0x24AC, 0);
445 }
446 /* Wait to prevent race in RBBM_STATUS */
447 mdelay(1);
448 tmp = RREG32(RADEON_RBBM_STATUS);
449 if (!(tmp & ((1 << 20) | (1 << 26)))) {
450 break;
451 }
452 }
453 for (i = 0; i < rdev->usec_timeout; i++) {
454 tmp = RREG32(RADEON_RBBM_STATUS);
455 if (!(tmp & ((1 << 20) | (1 << 26)))) {
456 DRM_INFO("GA reset succeed (RBBM_STATUS=0x%08X)\n",
457 tmp);
458 if (reinit_cp) {
459 return r100_cp_init(rdev, rdev->cp.ring_size);
460 }
461 return 0;
462 }
463 DRM_UDELAY(1);
464 }
465 tmp = RREG32(RADEON_RBBM_STATUS);
466 DRM_ERROR("Failed to reset GA ! (RBBM_STATUS=0x%08X)\n", tmp);
467 return -1;
468}
469
470int r300_gpu_reset(struct radeon_device *rdev)
471{
472 uint32_t status;
473
474 /* reset order likely matter */
475 status = RREG32(RADEON_RBBM_STATUS);
476 /* reset HDP */
477 r100_hdp_reset(rdev);
478 /* reset rb2d */
479 if (status & ((1 << 17) | (1 << 18) | (1 << 27))) {
480 r100_rb2d_reset(rdev);
481 }
482 /* reset GA */
483 if (status & ((1 << 20) | (1 << 26))) {
484 r300_ga_reset(rdev);
485 }
486 /* reset CP */
487 status = RREG32(RADEON_RBBM_STATUS);
488 if (status & (1 << 16)) {
489 r100_cp_reset(rdev);
490 }
491 /* Check if GPU is idle */
492 status = RREG32(RADEON_RBBM_STATUS);
Alex Deucher4612dc92010-02-05 01:58:28 -0500493 if (status & RADEON_RBBM_ACTIVE) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200494 DRM_ERROR("Failed to reset GPU (RBBM_STATUS=0x%08X)\n", status);
495 return -1;
496 }
497 DRM_INFO("GPU reset succeed (RBBM_STATUS=0x%08X)\n", status);
498 return 0;
499}
500
501
502/*
503 * r300,r350,rv350,rv380 VRAM info
504 */
505void r300_vram_info(struct radeon_device *rdev)
506{
507 uint32_t tmp;
508
509 /* DDR for all card after R300 & IGP */
510 rdev->mc.vram_is_ddr = true;
Dave Airlie5ff55712010-02-05 13:57:03 +1000511
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200512 tmp = RREG32(RADEON_MEM_CNTL);
Dave Airlie5ff55712010-02-05 13:57:03 +1000513 tmp &= R300_MEM_NUM_CHANNELS_MASK;
514 switch (tmp) {
515 case 0: rdev->mc.vram_width = 64; break;
516 case 1: rdev->mc.vram_width = 128; break;
517 case 2: rdev->mc.vram_width = 256; break;
518 default: rdev->mc.vram_width = 128; break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200519 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200520
Dave Airlie2a0f8912009-07-11 04:44:47 +1000521 r100_vram_init_sizes(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200522}
523
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200524void rv370_set_pcie_lanes(struct radeon_device *rdev, int lanes)
525{
526 uint32_t link_width_cntl, mask;
527
528 if (rdev->flags & RADEON_IS_IGP)
529 return;
530
531 if (!(rdev->flags & RADEON_IS_PCIE))
532 return;
533
534 /* FIXME wait for idle */
535
536 switch (lanes) {
537 case 0:
538 mask = RADEON_PCIE_LC_LINK_WIDTH_X0;
539 break;
540 case 1:
541 mask = RADEON_PCIE_LC_LINK_WIDTH_X1;
542 break;
543 case 2:
544 mask = RADEON_PCIE_LC_LINK_WIDTH_X2;
545 break;
546 case 4:
547 mask = RADEON_PCIE_LC_LINK_WIDTH_X4;
548 break;
549 case 8:
550 mask = RADEON_PCIE_LC_LINK_WIDTH_X8;
551 break;
552 case 12:
553 mask = RADEON_PCIE_LC_LINK_WIDTH_X12;
554 break;
555 case 16:
556 default:
557 mask = RADEON_PCIE_LC_LINK_WIDTH_X16;
558 break;
559 }
560
561 link_width_cntl = RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
562
563 if ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) ==
564 (mask << RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT))
565 return;
566
567 link_width_cntl &= ~(RADEON_PCIE_LC_LINK_WIDTH_MASK |
568 RADEON_PCIE_LC_RECONFIG_NOW |
569 RADEON_PCIE_LC_RECONFIG_LATER |
570 RADEON_PCIE_LC_SHORT_RECONFIG_EN);
571 link_width_cntl |= mask;
572 WREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
573 WREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL, (link_width_cntl |
574 RADEON_PCIE_LC_RECONFIG_NOW));
575
576 /* wait for lane set to complete */
577 link_width_cntl = RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
578 while (link_width_cntl == 0xffffffff)
579 link_width_cntl = RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
580
581}
582
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200583#if defined(CONFIG_DEBUG_FS)
584static int rv370_debugfs_pcie_gart_info(struct seq_file *m, void *data)
585{
586 struct drm_info_node *node = (struct drm_info_node *) m->private;
587 struct drm_device *dev = node->minor->dev;
588 struct radeon_device *rdev = dev->dev_private;
589 uint32_t tmp;
590
591 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL);
592 seq_printf(m, "PCIE_TX_GART_CNTL 0x%08x\n", tmp);
593 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_BASE);
594 seq_printf(m, "PCIE_TX_GART_BASE 0x%08x\n", tmp);
595 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_START_LO);
596 seq_printf(m, "PCIE_TX_GART_START_LO 0x%08x\n", tmp);
597 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_START_HI);
598 seq_printf(m, "PCIE_TX_GART_START_HI 0x%08x\n", tmp);
599 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_END_LO);
600 seq_printf(m, "PCIE_TX_GART_END_LO 0x%08x\n", tmp);
601 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_END_HI);
602 seq_printf(m, "PCIE_TX_GART_END_HI 0x%08x\n", tmp);
603 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_ERROR);
604 seq_printf(m, "PCIE_TX_GART_ERROR 0x%08x\n", tmp);
605 return 0;
606}
607
608static struct drm_info_list rv370_pcie_gart_info_list[] = {
609 {"rv370_pcie_gart_info", rv370_debugfs_pcie_gart_info, 0, NULL},
610};
611#endif
612
Jerome Glisse207bf9e2009-09-30 15:35:32 +0200613static int rv370_debugfs_pcie_gart_info_init(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200614{
615#if defined(CONFIG_DEBUG_FS)
616 return radeon_debugfs_add_files(rdev, rv370_pcie_gart_info_list, 1);
617#else
618 return 0;
619#endif
620}
621
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200622static int r300_packet0_check(struct radeon_cs_parser *p,
623 struct radeon_cs_packet *pkt,
624 unsigned idx, unsigned reg)
625{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200626 struct radeon_cs_reloc *reloc;
Dave Airlie551ebd82009-09-01 15:25:57 +1000627 struct r100_cs_track *track;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200628 volatile uint32_t *ib;
Dave Airliee024e112009-06-24 09:48:08 +1000629 uint32_t tmp, tile_flags = 0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200630 unsigned i;
631 int r;
Dave Airlie513bcb42009-09-23 16:56:27 +1000632 u32 idx_value;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200633
634 ib = p->ib->ptr;
Dave Airlie551ebd82009-09-01 15:25:57 +1000635 track = (struct r100_cs_track *)p->track;
Dave Airlie513bcb42009-09-23 16:56:27 +1000636 idx_value = radeon_get_ib_value(p, idx);
637
Jerome Glisse068a1172009-06-17 13:28:30 +0200638 switch(reg) {
Dave Airlie531369e62009-06-29 11:21:25 +1000639 case AVIVO_D1MODE_VLINE_START_END:
640 case RADEON_CRTC_GUI_TRIG_VLINE:
641 r = r100_cs_packet_parse_vline(p);
642 if (r) {
643 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
644 idx, reg);
645 r100_cs_dump_packet(p, pkt);
646 return r;
647 }
648 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200649 case RADEON_DST_PITCH_OFFSET:
650 case RADEON_SRC_PITCH_OFFSET:
Dave Airlie551ebd82009-09-01 15:25:57 +1000651 r = r100_reloc_pitch_offset(p, pkt, idx, reg);
652 if (r)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200653 return r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200654 break;
655 case R300_RB3D_COLOROFFSET0:
656 case R300_RB3D_COLOROFFSET1:
657 case R300_RB3D_COLOROFFSET2:
658 case R300_RB3D_COLOROFFSET3:
659 i = (reg - R300_RB3D_COLOROFFSET0) >> 2;
660 r = r100_cs_packet_next_reloc(p, &reloc);
661 if (r) {
662 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
663 idx, reg);
664 r100_cs_dump_packet(p, pkt);
665 return r;
666 }
667 track->cb[i].robj = reloc->robj;
Dave Airlie513bcb42009-09-23 16:56:27 +1000668 track->cb[i].offset = idx_value;
669 ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200670 break;
671 case R300_ZB_DEPTHOFFSET:
672 r = r100_cs_packet_next_reloc(p, &reloc);
673 if (r) {
674 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
675 idx, reg);
676 r100_cs_dump_packet(p, pkt);
677 return r;
678 }
679 track->zb.robj = reloc->robj;
Dave Airlie513bcb42009-09-23 16:56:27 +1000680 track->zb.offset = idx_value;
681 ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200682 break;
683 case R300_TX_OFFSET_0:
684 case R300_TX_OFFSET_0+4:
685 case R300_TX_OFFSET_0+8:
686 case R300_TX_OFFSET_0+12:
687 case R300_TX_OFFSET_0+16:
688 case R300_TX_OFFSET_0+20:
689 case R300_TX_OFFSET_0+24:
690 case R300_TX_OFFSET_0+28:
691 case R300_TX_OFFSET_0+32:
692 case R300_TX_OFFSET_0+36:
693 case R300_TX_OFFSET_0+40:
694 case R300_TX_OFFSET_0+44:
695 case R300_TX_OFFSET_0+48:
696 case R300_TX_OFFSET_0+52:
697 case R300_TX_OFFSET_0+56:
698 case R300_TX_OFFSET_0+60:
Jerome Glisse068a1172009-06-17 13:28:30 +0200699 i = (reg - R300_TX_OFFSET_0) >> 2;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200700 r = r100_cs_packet_next_reloc(p, &reloc);
701 if (r) {
702 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
703 idx, reg);
704 r100_cs_dump_packet(p, pkt);
705 return r;
706 }
Maciej Cencora6e726772009-12-15 23:13:08 +0100707
708 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
709 tile_flags |= R300_TXO_MACRO_TILE;
710 if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
711 tile_flags |= R300_TXO_MICRO_TILE;
712
713 tmp = idx_value + ((u32)reloc->lobj.gpu_offset);
714 tmp |= tile_flags;
715 ib[idx] = tmp;
Jerome Glisse068a1172009-06-17 13:28:30 +0200716 track->textures[i].robj = reloc->robj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200717 break;
718 /* Tracked registers */
Jerome Glisse068a1172009-06-17 13:28:30 +0200719 case 0x2084:
720 /* VAP_VF_CNTL */
Dave Airlie513bcb42009-09-23 16:56:27 +1000721 track->vap_vf_cntl = idx_value;
Jerome Glisse068a1172009-06-17 13:28:30 +0200722 break;
723 case 0x20B4:
724 /* VAP_VTX_SIZE */
Dave Airlie513bcb42009-09-23 16:56:27 +1000725 track->vtx_size = idx_value & 0x7F;
Jerome Glisse068a1172009-06-17 13:28:30 +0200726 break;
727 case 0x2134:
728 /* VAP_VF_MAX_VTX_INDX */
Dave Airlie513bcb42009-09-23 16:56:27 +1000729 track->max_indx = idx_value & 0x00FFFFFFUL;
Jerome Glisse068a1172009-06-17 13:28:30 +0200730 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200731 case 0x43E4:
732 /* SC_SCISSOR1 */
Dave Airlie513bcb42009-09-23 16:56:27 +1000733 track->maxy = ((idx_value >> 13) & 0x1FFF) + 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200734 if (p->rdev->family < CHIP_RV515) {
735 track->maxy -= 1440;
736 }
737 break;
738 case 0x4E00:
739 /* RB3D_CCTL */
Dave Airlie513bcb42009-09-23 16:56:27 +1000740 track->num_cb = ((idx_value >> 5) & 0x3) + 1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200741 break;
742 case 0x4E38:
743 case 0x4E3C:
744 case 0x4E40:
745 case 0x4E44:
746 /* RB3D_COLORPITCH0 */
747 /* RB3D_COLORPITCH1 */
748 /* RB3D_COLORPITCH2 */
749 /* RB3D_COLORPITCH3 */
Dave Airliee024e112009-06-24 09:48:08 +1000750 r = r100_cs_packet_next_reloc(p, &reloc);
751 if (r) {
752 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
753 idx, reg);
754 r100_cs_dump_packet(p, pkt);
755 return r;
756 }
757
758 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
759 tile_flags |= R300_COLOR_TILE_ENABLE;
760 if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
761 tile_flags |= R300_COLOR_MICROTILE_ENABLE;
762
Dave Airlie513bcb42009-09-23 16:56:27 +1000763 tmp = idx_value & ~(0x7 << 16);
Dave Airliee024e112009-06-24 09:48:08 +1000764 tmp |= tile_flags;
765 ib[idx] = tmp;
766
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200767 i = (reg - 0x4E38) >> 2;
Dave Airlie513bcb42009-09-23 16:56:27 +1000768 track->cb[i].pitch = idx_value & 0x3FFE;
769 switch (((idx_value >> 21) & 0xF)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200770 case 9:
771 case 11:
772 case 12:
773 track->cb[i].cpp = 1;
774 break;
775 case 3:
776 case 4:
777 case 13:
778 case 15:
779 track->cb[i].cpp = 2;
780 break;
781 case 6:
782 track->cb[i].cpp = 4;
783 break;
784 case 10:
785 track->cb[i].cpp = 8;
786 break;
787 case 7:
788 track->cb[i].cpp = 16;
789 break;
790 default:
791 DRM_ERROR("Invalid color buffer format (%d) !\n",
Dave Airlie513bcb42009-09-23 16:56:27 +1000792 ((idx_value >> 21) & 0xF));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200793 return -EINVAL;
794 }
795 break;
796 case 0x4F00:
797 /* ZB_CNTL */
Dave Airlie513bcb42009-09-23 16:56:27 +1000798 if (idx_value & 2) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200799 track->z_enabled = true;
800 } else {
801 track->z_enabled = false;
802 }
803 break;
804 case 0x4F10:
805 /* ZB_FORMAT */
Dave Airlie513bcb42009-09-23 16:56:27 +1000806 switch ((idx_value & 0xF)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200807 case 0:
808 case 1:
809 track->zb.cpp = 2;
810 break;
811 case 2:
812 track->zb.cpp = 4;
813 break;
814 default:
815 DRM_ERROR("Invalid z buffer format (%d) !\n",
Dave Airlie513bcb42009-09-23 16:56:27 +1000816 (idx_value & 0xF));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200817 return -EINVAL;
818 }
819 break;
820 case 0x4F24:
821 /* ZB_DEPTHPITCH */
Dave Airliee024e112009-06-24 09:48:08 +1000822 r = r100_cs_packet_next_reloc(p, &reloc);
823 if (r) {
824 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
825 idx, reg);
826 r100_cs_dump_packet(p, pkt);
827 return r;
828 }
829
830 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
831 tile_flags |= R300_DEPTHMACROTILE_ENABLE;
832 if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
833 tile_flags |= R300_DEPTHMICROTILE_TILED;;
834
Dave Airlie513bcb42009-09-23 16:56:27 +1000835 tmp = idx_value & ~(0x7 << 16);
Dave Airliee024e112009-06-24 09:48:08 +1000836 tmp |= tile_flags;
837 ib[idx] = tmp;
838
Dave Airlie513bcb42009-09-23 16:56:27 +1000839 track->zb.pitch = idx_value & 0x3FFC;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200840 break;
Jerome Glisse068a1172009-06-17 13:28:30 +0200841 case 0x4104:
842 for (i = 0; i < 16; i++) {
843 bool enabled;
844
Dave Airlie513bcb42009-09-23 16:56:27 +1000845 enabled = !!(idx_value & (1 << i));
Jerome Glisse068a1172009-06-17 13:28:30 +0200846 track->textures[i].enabled = enabled;
847 }
848 break;
849 case 0x44C0:
850 case 0x44C4:
851 case 0x44C8:
852 case 0x44CC:
853 case 0x44D0:
854 case 0x44D4:
855 case 0x44D8:
856 case 0x44DC:
857 case 0x44E0:
858 case 0x44E4:
859 case 0x44E8:
860 case 0x44EC:
861 case 0x44F0:
862 case 0x44F4:
863 case 0x44F8:
864 case 0x44FC:
865 /* TX_FORMAT1_[0-15] */
866 i = (reg - 0x44C0) >> 2;
Dave Airlie513bcb42009-09-23 16:56:27 +1000867 tmp = (idx_value >> 25) & 0x3;
Jerome Glisse068a1172009-06-17 13:28:30 +0200868 track->textures[i].tex_coord_type = tmp;
Dave Airlie513bcb42009-09-23 16:56:27 +1000869 switch ((idx_value & 0x1F)) {
Dave Airlie551ebd82009-09-01 15:25:57 +1000870 case R300_TX_FORMAT_X8:
871 case R300_TX_FORMAT_Y4X4:
872 case R300_TX_FORMAT_Z3Y3X2:
Jerome Glisse068a1172009-06-17 13:28:30 +0200873 track->textures[i].cpp = 1;
874 break;
Dave Airlie551ebd82009-09-01 15:25:57 +1000875 case R300_TX_FORMAT_X16:
876 case R300_TX_FORMAT_Y8X8:
877 case R300_TX_FORMAT_Z5Y6X5:
878 case R300_TX_FORMAT_Z6Y5X5:
879 case R300_TX_FORMAT_W4Z4Y4X4:
880 case R300_TX_FORMAT_W1Z5Y5X5:
Dave Airlie551ebd82009-09-01 15:25:57 +1000881 case R300_TX_FORMAT_D3DMFT_CxV8U8:
882 case R300_TX_FORMAT_B8G8_B8G8:
883 case R300_TX_FORMAT_G8R8_G8B8:
Jerome Glisse068a1172009-06-17 13:28:30 +0200884 track->textures[i].cpp = 2;
885 break;
Dave Airlie551ebd82009-09-01 15:25:57 +1000886 case R300_TX_FORMAT_Y16X16:
887 case R300_TX_FORMAT_Z11Y11X10:
888 case R300_TX_FORMAT_Z10Y11X11:
889 case R300_TX_FORMAT_W8Z8Y8X8:
890 case R300_TX_FORMAT_W2Z10Y10X10:
891 case 0x17:
892 case R300_TX_FORMAT_FL_I32:
893 case 0x1e:
Jerome Glisse068a1172009-06-17 13:28:30 +0200894 track->textures[i].cpp = 4;
895 break;
Dave Airlie551ebd82009-09-01 15:25:57 +1000896 case R300_TX_FORMAT_W16Z16Y16X16:
897 case R300_TX_FORMAT_FL_R16G16B16A16:
898 case R300_TX_FORMAT_FL_I32A32:
Jerome Glisse068a1172009-06-17 13:28:30 +0200899 track->textures[i].cpp = 8;
900 break;
Dave Airlie551ebd82009-09-01 15:25:57 +1000901 case R300_TX_FORMAT_FL_R32G32B32A32:
Jerome Glisse068a1172009-06-17 13:28:30 +0200902 track->textures[i].cpp = 16;
903 break;
Dave Airlied785d782009-12-07 13:16:06 +1000904 case R300_TX_FORMAT_DXT1:
905 track->textures[i].cpp = 1;
906 track->textures[i].compress_format = R100_TRACK_COMP_DXT1;
907 break;
Marek Olšák512889f2009-12-19 00:23:00 +0100908 case R300_TX_FORMAT_ATI2N:
909 if (p->rdev->family < CHIP_R420) {
910 DRM_ERROR("Invalid texture format %u\n",
911 (idx_value & 0x1F));
912 return -EINVAL;
913 }
914 /* The same rules apply as for DXT3/5. */
915 /* Pass through. */
Dave Airlied785d782009-12-07 13:16:06 +1000916 case R300_TX_FORMAT_DXT3:
917 case R300_TX_FORMAT_DXT5:
918 track->textures[i].cpp = 1;
919 track->textures[i].compress_format = R100_TRACK_COMP_DXT35;
920 break;
Jerome Glisse068a1172009-06-17 13:28:30 +0200921 default:
922 DRM_ERROR("Invalid texture format %u\n",
Dave Airlie513bcb42009-09-23 16:56:27 +1000923 (idx_value & 0x1F));
Jerome Glisse068a1172009-06-17 13:28:30 +0200924 return -EINVAL;
925 break;
926 }
927 break;
928 case 0x4400:
929 case 0x4404:
930 case 0x4408:
931 case 0x440C:
932 case 0x4410:
933 case 0x4414:
934 case 0x4418:
935 case 0x441C:
936 case 0x4420:
937 case 0x4424:
938 case 0x4428:
939 case 0x442C:
940 case 0x4430:
941 case 0x4434:
942 case 0x4438:
943 case 0x443C:
944 /* TX_FILTER0_[0-15] */
945 i = (reg - 0x4400) >> 2;
Dave Airlie513bcb42009-09-23 16:56:27 +1000946 tmp = idx_value & 0x7;
Jerome Glisse068a1172009-06-17 13:28:30 +0200947 if (tmp == 2 || tmp == 4 || tmp == 6) {
948 track->textures[i].roundup_w = false;
949 }
Dave Airlie513bcb42009-09-23 16:56:27 +1000950 tmp = (idx_value >> 3) & 0x7;
Jerome Glisse068a1172009-06-17 13:28:30 +0200951 if (tmp == 2 || tmp == 4 || tmp == 6) {
952 track->textures[i].roundup_h = false;
953 }
954 break;
955 case 0x4500:
956 case 0x4504:
957 case 0x4508:
958 case 0x450C:
959 case 0x4510:
960 case 0x4514:
961 case 0x4518:
962 case 0x451C:
963 case 0x4520:
964 case 0x4524:
965 case 0x4528:
966 case 0x452C:
967 case 0x4530:
968 case 0x4534:
969 case 0x4538:
970 case 0x453C:
971 /* TX_FORMAT2_[0-15] */
972 i = (reg - 0x4500) >> 2;
Dave Airlie513bcb42009-09-23 16:56:27 +1000973 tmp = idx_value & 0x3FFF;
Jerome Glisse068a1172009-06-17 13:28:30 +0200974 track->textures[i].pitch = tmp + 1;
975 if (p->rdev->family >= CHIP_RV515) {
Dave Airlie513bcb42009-09-23 16:56:27 +1000976 tmp = ((idx_value >> 15) & 1) << 11;
Jerome Glisse068a1172009-06-17 13:28:30 +0200977 track->textures[i].width_11 = tmp;
Dave Airlie513bcb42009-09-23 16:56:27 +1000978 tmp = ((idx_value >> 16) & 1) << 11;
Jerome Glisse068a1172009-06-17 13:28:30 +0200979 track->textures[i].height_11 = tmp;
Marek Olšák512889f2009-12-19 00:23:00 +0100980
981 /* ATI1N */
982 if (idx_value & (1 << 14)) {
983 /* The same rules apply as for DXT1. */
984 track->textures[i].compress_format =
985 R100_TRACK_COMP_DXT1;
986 }
987 } else if (idx_value & (1 << 14)) {
988 DRM_ERROR("Forbidden bit TXFORMAT_MSB\n");
989 return -EINVAL;
Jerome Glisse068a1172009-06-17 13:28:30 +0200990 }
991 break;
992 case 0x4480:
993 case 0x4484:
994 case 0x4488:
995 case 0x448C:
996 case 0x4490:
997 case 0x4494:
998 case 0x4498:
999 case 0x449C:
1000 case 0x44A0:
1001 case 0x44A4:
1002 case 0x44A8:
1003 case 0x44AC:
1004 case 0x44B0:
1005 case 0x44B4:
1006 case 0x44B8:
1007 case 0x44BC:
1008 /* TX_FORMAT0_[0-15] */
1009 i = (reg - 0x4480) >> 2;
Dave Airlie513bcb42009-09-23 16:56:27 +10001010 tmp = idx_value & 0x7FF;
Jerome Glisse068a1172009-06-17 13:28:30 +02001011 track->textures[i].width = tmp + 1;
Dave Airlie513bcb42009-09-23 16:56:27 +10001012 tmp = (idx_value >> 11) & 0x7FF;
Jerome Glisse068a1172009-06-17 13:28:30 +02001013 track->textures[i].height = tmp + 1;
Dave Airlie513bcb42009-09-23 16:56:27 +10001014 tmp = (idx_value >> 26) & 0xF;
Jerome Glisse068a1172009-06-17 13:28:30 +02001015 track->textures[i].num_levels = tmp;
Dave Airlie513bcb42009-09-23 16:56:27 +10001016 tmp = idx_value & (1 << 31);
Jerome Glisse068a1172009-06-17 13:28:30 +02001017 track->textures[i].use_pitch = !!tmp;
Dave Airlie513bcb42009-09-23 16:56:27 +10001018 tmp = (idx_value >> 22) & 0xF;
Jerome Glisse068a1172009-06-17 13:28:30 +02001019 track->textures[i].txdepth = tmp;
1020 break;
Dave Airlie3f8befe2009-08-15 20:54:13 +10001021 case R300_ZB_ZPASS_ADDR:
1022 r = r100_cs_packet_next_reloc(p, &reloc);
1023 if (r) {
1024 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1025 idx, reg);
1026 r100_cs_dump_packet(p, pkt);
1027 return r;
1028 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001029 ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
Dave Airlie3f8befe2009-08-15 20:54:13 +10001030 break;
Marek Olšák46c64d42009-12-17 06:02:28 +01001031 case 0x4e0c:
1032 /* RB3D_COLOR_CHANNEL_MASK */
1033 track->color_channel_mask = idx_value;
1034 break;
1035 case 0x4d1c:
1036 /* ZB_BW_CNTL */
1037 track->fastfill = !!(idx_value & (1 << 2));
1038 break;
1039 case 0x4e04:
1040 /* RB3D_BLENDCNTL */
1041 track->blend_read_enable = !!(idx_value & (1 << 2));
1042 break;
Dave Airlie3f8befe2009-08-15 20:54:13 +10001043 case 0x4be8:
1044 /* valid register only on RV530 */
1045 if (p->rdev->family == CHIP_RV530)
1046 break;
1047 /* fallthrough do not move */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001048 default:
Jerome Glisse068a1172009-06-17 13:28:30 +02001049 printk(KERN_ERR "Forbidden register 0x%04X in cs at %d\n",
1050 reg, idx);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001051 return -EINVAL;
1052 }
1053 return 0;
1054}
1055
1056static int r300_packet3_check(struct radeon_cs_parser *p,
1057 struct radeon_cs_packet *pkt)
1058{
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001059 struct radeon_cs_reloc *reloc;
Dave Airlie551ebd82009-09-01 15:25:57 +10001060 struct r100_cs_track *track;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001061 volatile uint32_t *ib;
1062 unsigned idx;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001063 int r;
1064
1065 ib = p->ib->ptr;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001066 idx = pkt->idx + 1;
Dave Airlie551ebd82009-09-01 15:25:57 +10001067 track = (struct r100_cs_track *)p->track;
Jerome Glisse068a1172009-06-17 13:28:30 +02001068 switch(pkt->opcode) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001069 case PACKET3_3D_LOAD_VBPNTR:
Dave Airlie513bcb42009-09-23 16:56:27 +10001070 r = r100_packet3_load_vbpntr(p, pkt, idx);
1071 if (r)
1072 return r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001073 break;
1074 case PACKET3_INDX_BUFFER:
1075 r = r100_cs_packet_next_reloc(p, &reloc);
1076 if (r) {
1077 DRM_ERROR("No reloc for packet3 %d\n", pkt->opcode);
1078 r100_cs_dump_packet(p, pkt);
1079 return r;
1080 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001081 ib[idx+1] = radeon_get_ib_value(p, idx + 1) + ((u32)reloc->lobj.gpu_offset);
Jerome Glisse068a1172009-06-17 13:28:30 +02001082 r = r100_cs_track_check_pkt3_indx_buffer(p, pkt, reloc->robj);
1083 if (r) {
1084 return r;
1085 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001086 break;
1087 /* Draw packet */
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001088 case PACKET3_3D_DRAW_IMMD:
Jerome Glisse068a1172009-06-17 13:28:30 +02001089 /* Number of dwords is vtx_size * (num_vertices - 1)
1090 * PRIM_WALK must be equal to 3 vertex data in embedded
1091 * in cmd stream */
Dave Airlie513bcb42009-09-23 16:56:27 +10001092 if (((radeon_get_ib_value(p, idx + 1) >> 4) & 0x3) != 3) {
Jerome Glisse068a1172009-06-17 13:28:30 +02001093 DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n");
1094 return -EINVAL;
1095 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001096 track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1);
Jerome Glisse068a1172009-06-17 13:28:30 +02001097 track->immd_dwords = pkt->count - 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_IMMD_2:
Jerome Glisse068a1172009-06-17 13:28:30 +02001104 /* Number of dwords is vtx_size * (num_vertices - 1)
1105 * PRIM_WALK must be equal to 3 vertex data in embedded
1106 * in cmd stream */
Dave Airlie513bcb42009-09-23 16:56:27 +10001107 if (((radeon_get_ib_value(p, idx) >> 4) & 0x3) != 3) {
Jerome Glisse068a1172009-06-17 13:28:30 +02001108 DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n");
1109 return -EINVAL;
1110 }
Dave Airlie513bcb42009-09-23 16:56:27 +10001111 track->vap_vf_cntl = radeon_get_ib_value(p, idx);
Jerome Glisse068a1172009-06-17 13:28:30 +02001112 track->immd_dwords = pkt->count;
Dave Airlie551ebd82009-09-01 15:25:57 +10001113 r = r100_cs_track_check(p->rdev, track);
Jerome Glisse068a1172009-06-17 13:28:30 +02001114 if (r) {
1115 return r;
1116 }
1117 break;
1118 case PACKET3_3D_DRAW_VBUF:
Dave Airlie513bcb42009-09-23 16:56:27 +10001119 track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1);
Dave Airlie551ebd82009-09-01 15:25:57 +10001120 r = r100_cs_track_check(p->rdev, track);
Jerome Glisse068a1172009-06-17 13:28:30 +02001121 if (r) {
1122 return r;
1123 }
1124 break;
1125 case PACKET3_3D_DRAW_VBUF_2:
Dave Airlie513bcb42009-09-23 16:56:27 +10001126 track->vap_vf_cntl = radeon_get_ib_value(p, idx);
Dave Airlie551ebd82009-09-01 15:25:57 +10001127 r = r100_cs_track_check(p->rdev, track);
Jerome Glisse068a1172009-06-17 13:28:30 +02001128 if (r) {
1129 return r;
1130 }
1131 break;
1132 case PACKET3_3D_DRAW_INDX:
Dave Airlie513bcb42009-09-23 16:56:27 +10001133 track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1);
Dave Airlie551ebd82009-09-01 15:25:57 +10001134 r = r100_cs_track_check(p->rdev, track);
Jerome Glisse068a1172009-06-17 13:28:30 +02001135 if (r) {
1136 return r;
1137 }
1138 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001139 case PACKET3_3D_DRAW_INDX_2:
Dave Airlie513bcb42009-09-23 16:56:27 +10001140 track->vap_vf_cntl = radeon_get_ib_value(p, idx);
Dave Airlie551ebd82009-09-01 15:25:57 +10001141 r = r100_cs_track_check(p->rdev, track);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001142 if (r) {
1143 return r;
1144 }
1145 break;
1146 case PACKET3_NOP:
1147 break;
1148 default:
1149 DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode);
1150 return -EINVAL;
1151 }
1152 return 0;
1153}
1154
1155int r300_cs_parse(struct radeon_cs_parser *p)
1156{
1157 struct radeon_cs_packet pkt;
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001158 struct r100_cs_track *track;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001159 int r;
1160
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001161 track = kzalloc(sizeof(*track), GFP_KERNEL);
1162 r100_cs_track_clear(p->rdev, track);
1163 p->track = track;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001164 do {
1165 r = r100_cs_packet_parse(p, &pkt, p->idx);
1166 if (r) {
1167 return r;
1168 }
1169 p->idx += pkt.count + 2;
1170 switch (pkt.type) {
1171 case PACKET_TYPE0:
1172 r = r100_cs_parse_packet0(p, &pkt,
Jerome Glisse068a1172009-06-17 13:28:30 +02001173 p->rdev->config.r300.reg_safe_bm,
1174 p->rdev->config.r300.reg_safe_bm_size,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001175 &r300_packet0_check);
1176 break;
1177 case PACKET_TYPE2:
1178 break;
1179 case PACKET_TYPE3:
1180 r = r300_packet3_check(p, &pkt);
1181 break;
1182 default:
1183 DRM_ERROR("Unknown packet type %d !\n", pkt.type);
1184 return -EINVAL;
1185 }
1186 if (r) {
1187 return r;
1188 }
1189 } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
1190 return 0;
1191}
Jerome Glisse068a1172009-06-17 13:28:30 +02001192
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001193void r300_set_reg_safe(struct radeon_device *rdev)
Jerome Glisse068a1172009-06-17 13:28:30 +02001194{
1195 rdev->config.r300.reg_safe_bm = r300_reg_safe_bm;
1196 rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(r300_reg_safe_bm);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001197}
1198
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001199void r300_mc_program(struct radeon_device *rdev)
1200{
1201 struct r100_mc_save save;
1202 int r;
1203
1204 r = r100_debugfs_mc_info_init(rdev);
1205 if (r) {
1206 dev_err(rdev->dev, "Failed to create r100_mc debugfs file.\n");
1207 }
1208
1209 /* Stops all mc clients */
1210 r100_mc_stop(rdev, &save);
Jerome Glisse9f022dd2009-09-11 15:35:22 +02001211 if (rdev->flags & RADEON_IS_AGP) {
1212 WREG32(R_00014C_MC_AGP_LOCATION,
1213 S_00014C_MC_AGP_START(rdev->mc.gtt_start >> 16) |
1214 S_00014C_MC_AGP_TOP(rdev->mc.gtt_end >> 16));
1215 WREG32(R_000170_AGP_BASE, lower_32_bits(rdev->mc.agp_base));
1216 WREG32(R_00015C_AGP_BASE_2,
1217 upper_32_bits(rdev->mc.agp_base) & 0xff);
1218 } else {
1219 WREG32(R_00014C_MC_AGP_LOCATION, 0x0FFFFFFF);
1220 WREG32(R_000170_AGP_BASE, 0);
1221 WREG32(R_00015C_AGP_BASE_2, 0);
1222 }
1223 /* Wait for mc idle */
1224 if (r300_mc_wait_for_idle(rdev))
1225 DRM_INFO("Failed to wait MC idle before programming MC.\n");
1226 /* Program MC, should be a 32bits limited address space */
1227 WREG32(R_000148_MC_FB_LOCATION,
1228 S_000148_MC_FB_START(rdev->mc.vram_start >> 16) |
1229 S_000148_MC_FB_TOP(rdev->mc.vram_end >> 16));
1230 r100_mc_resume(rdev, &save);
1231}
Jerome Glisseca6ffc62009-10-01 10:20:52 +02001232
1233void r300_clock_startup(struct radeon_device *rdev)
1234{
1235 u32 tmp;
1236
1237 if (radeon_dynclks != -1 && radeon_dynclks)
1238 radeon_legacy_set_clock_gating(rdev, 1);
1239 /* We need to force on some of the block */
1240 tmp = RREG32_PLL(R_00000D_SCLK_CNTL);
1241 tmp |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1);
1242 if ((rdev->family == CHIP_RV350) || (rdev->family == CHIP_RV380))
1243 tmp |= S_00000D_FORCE_VAP(1);
1244 WREG32_PLL(R_00000D_SCLK_CNTL, tmp);
1245}
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001246
1247static int r300_startup(struct radeon_device *rdev)
1248{
1249 int r;
1250
Alex Deucher92cde002009-12-04 10:55:12 -05001251 /* set common regs */
1252 r100_set_common_regs(rdev);
1253 /* program mc */
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001254 r300_mc_program(rdev);
1255 /* Resume clock */
1256 r300_clock_startup(rdev);
1257 /* Initialize GPU configuration (# pipes, ...) */
1258 r300_gpu_init(rdev);
1259 /* Initialize GART (initialize after TTM so we can allocate
1260 * memory through TTM but finalize after TTM) */
1261 if (rdev->flags & RADEON_IS_PCIE) {
1262 r = rv370_pcie_gart_enable(rdev);
1263 if (r)
1264 return r;
1265 }
Dave Airlie17e15b02009-11-05 15:36:53 +10001266
1267 if (rdev->family == CHIP_R300 ||
1268 rdev->family == CHIP_R350 ||
1269 rdev->family == CHIP_RV350)
1270 r100_enable_bm(rdev);
1271
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001272 if (rdev->flags & RADEON_IS_PCI) {
1273 r = r100_pci_gart_enable(rdev);
1274 if (r)
1275 return r;
1276 }
1277 /* Enable IRQ */
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001278 r100_irq_set(rdev);
Jerome Glissecafe6602010-01-07 12:39:21 +01001279 rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001280 /* 1M ring buffer */
1281 r = r100_cp_init(rdev, 1024 * 1024);
1282 if (r) {
1283 dev_err(rdev->dev, "failled initializing CP (%d).\n", r);
1284 return r;
1285 }
1286 r = r100_wb_init(rdev);
1287 if (r)
1288 dev_err(rdev->dev, "failled initializing WB (%d).\n", r);
1289 r = r100_ib_init(rdev);
1290 if (r) {
1291 dev_err(rdev->dev, "failled initializing IB (%d).\n", r);
1292 return r;
1293 }
1294 return 0;
1295}
1296
1297int r300_resume(struct radeon_device *rdev)
1298{
1299 /* Make sur GART are not working */
1300 if (rdev->flags & RADEON_IS_PCIE)
1301 rv370_pcie_gart_disable(rdev);
1302 if (rdev->flags & RADEON_IS_PCI)
1303 r100_pci_gart_disable(rdev);
1304 /* Resume clock before doing reset */
1305 r300_clock_startup(rdev);
1306 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
1307 if (radeon_gpu_reset(rdev)) {
1308 dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
1309 RREG32(R_000E40_RBBM_STATUS),
1310 RREG32(R_0007C0_CP_STAT));
1311 }
1312 /* post */
1313 radeon_combios_asic_init(rdev->ddev);
1314 /* Resume clock after posting */
1315 r300_clock_startup(rdev);
Dave Airlie550e2d92009-12-09 14:15:38 +10001316 /* Initialize surface registers */
1317 radeon_surface_init(rdev);
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001318 return r300_startup(rdev);
1319}
1320
1321int r300_suspend(struct radeon_device *rdev)
1322{
1323 r100_cp_disable(rdev);
1324 r100_wb_disable(rdev);
1325 r100_irq_disable(rdev);
1326 if (rdev->flags & RADEON_IS_PCIE)
1327 rv370_pcie_gart_disable(rdev);
1328 if (rdev->flags & RADEON_IS_PCI)
1329 r100_pci_gart_disable(rdev);
1330 return 0;
1331}
1332
1333void r300_fini(struct radeon_device *rdev)
1334{
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001335 r100_cp_fini(rdev);
1336 r100_wb_fini(rdev);
1337 r100_ib_fini(rdev);
1338 radeon_gem_fini(rdev);
1339 if (rdev->flags & RADEON_IS_PCIE)
1340 rv370_pcie_gart_fini(rdev);
1341 if (rdev->flags & RADEON_IS_PCI)
1342 r100_pci_gart_fini(rdev);
Jerome Glissed0269ed2010-01-07 16:08:32 +01001343 radeon_agp_fini(rdev);
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001344 radeon_irq_kms_fini(rdev);
1345 radeon_fence_driver_fini(rdev);
Jerome Glisse4c788672009-11-20 14:29:23 +01001346 radeon_bo_fini(rdev);
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001347 radeon_atombios_fini(rdev);
1348 kfree(rdev->bios);
1349 rdev->bios = NULL;
1350}
1351
1352int r300_init(struct radeon_device *rdev)
1353{
1354 int r;
1355
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001356 /* Disable VGA */
1357 r100_vga_render_disable(rdev);
1358 /* Initialize scratch registers */
1359 radeon_scratch_init(rdev);
1360 /* Initialize surface registers */
1361 radeon_surface_init(rdev);
1362 /* TODO: disable VGA need to use VGA request */
1363 /* BIOS*/
1364 if (!radeon_get_bios(rdev)) {
1365 if (ASIC_IS_AVIVO(rdev))
1366 return -EINVAL;
1367 }
1368 if (rdev->is_atom_bios) {
1369 dev_err(rdev->dev, "Expecting combios for RS400/RS480 GPU\n");
1370 return -EINVAL;
1371 } else {
1372 r = radeon_combios_init(rdev);
1373 if (r)
1374 return r;
1375 }
1376 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
1377 if (radeon_gpu_reset(rdev)) {
1378 dev_warn(rdev->dev,
1379 "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
1380 RREG32(R_000E40_RBBM_STATUS),
1381 RREG32(R_0007C0_CP_STAT));
1382 }
1383 /* check if cards are posted or not */
Dave Airlie72542d72009-12-01 14:06:31 +10001384 if (radeon_boot_test_post_card(rdev) == false)
1385 return -EINVAL;
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001386 /* Set asic errata */
1387 r300_errata(rdev);
1388 /* Initialize clocks */
1389 radeon_get_clock_info(rdev->ddev);
Rafał Miłecki62340772009-12-15 21:46:58 +01001390 /* Initialize power management */
1391 radeon_pm_init(rdev);
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001392 /* Get vram informations */
1393 r300_vram_info(rdev);
1394 /* Initialize memory controller (also test AGP) */
1395 r = r420_mc_init(rdev);
1396 if (r)
1397 return r;
1398 /* Fence driver */
1399 r = radeon_fence_driver_init(rdev);
1400 if (r)
1401 return r;
1402 r = radeon_irq_kms_init(rdev);
1403 if (r)
1404 return r;
1405 /* Memory manager */
Jerome Glisse4c788672009-11-20 14:29:23 +01001406 r = radeon_bo_init(rdev);
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001407 if (r)
1408 return r;
1409 if (rdev->flags & RADEON_IS_PCIE) {
1410 r = rv370_pcie_gart_init(rdev);
1411 if (r)
1412 return r;
1413 }
1414 if (rdev->flags & RADEON_IS_PCI) {
1415 r = r100_pci_gart_init(rdev);
1416 if (r)
1417 return r;
1418 }
1419 r300_set_reg_safe(rdev);
1420 rdev->accel_working = true;
1421 r = r300_startup(rdev);
1422 if (r) {
1423 /* Somethings want wront with the accel init stop accel */
1424 dev_err(rdev->dev, "Disabling GPU acceleration\n");
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001425 r100_cp_fini(rdev);
1426 r100_wb_fini(rdev);
1427 r100_ib_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01001428 radeon_irq_kms_fini(rdev);
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001429 if (rdev->flags & RADEON_IS_PCIE)
1430 rv370_pcie_gart_fini(rdev);
1431 if (rdev->flags & RADEON_IS_PCI)
1432 r100_pci_gart_fini(rdev);
Jerome Glisse655efd32010-02-02 11:51:45 +01001433 radeon_agp_fini(rdev);
Jerome Glisse207bf9e2009-09-30 15:35:32 +02001434 rdev->accel_working = false;
1435 }
1436 return 0;
1437}