2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
24 * Authors: Dave Airlie
28 #include <linux/seq_file.h>
31 #include "radeon_reg.h"
33 #include "radeon_drm.h"
34 #include "r100_track.h"
37 #include "r300_reg_safe.h"
39 /* This files gather functions specifics to: r300,r350,rv350,rv370,rv380 */
42 * rv370,rv380 PCIE GART
44 static int rv370_debugfs_pcie_gart_info_init(struct radeon_device
*rdev
);
46 void rv370_pcie_gart_tlb_flush(struct radeon_device
*rdev
)
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
);
61 int rv370_pcie_gart_set_page(struct radeon_device
*rdev
, int i
, uint64_t addr
)
63 void __iomem
*ptr
= (void *)rdev
->gart
.table
.vram
.ptr
;
65 if (i
< 0 || i
> rdev
->gart
.num_gpu_pages
) {
68 addr
= (lower_32_bits(addr
) >> 8) |
69 ((upper_32_bits(addr
) & 0xff) << 24) |
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));
78 int rv370_pcie_gart_init(struct radeon_device
*rdev
)
82 if (rdev
->gart
.table
.vram
.robj
) {
83 WARN(1, "RV370 PCIE GART already initialized.\n");
86 /* Initialize common gart structure */
87 r
= radeon_gart_init(rdev
);
90 r
= rv370_debugfs_pcie_gart_info_init(rdev
);
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
);
99 int rv370_pcie_gart_enable(struct radeon_device
*rdev
)
105 if (rdev
->gart
.table
.vram
.robj
== NULL
) {
106 dev_err(rdev
->dev
, "No VRAM object for PCIE GART.\n");
109 r
= radeon_gart_table_vram_pin(rdev
);
112 /* 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
);
116 tmp
= rdev
->mc
.gtt_location
+ rdev
->mc
.gtt_size
- 4096;
117 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);
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",
133 (unsigned)(rdev
->mc
.gtt_size
>> 20), table_addr
);
134 rdev
->gart
.ready
= true;
138 void rv370_pcie_gart_disable(struct radeon_device
*rdev
)
142 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL
);
143 tmp
|= RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD
;
144 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL
, tmp
& ~RADEON_PCIE_TX_GART_EN
);
145 if (rdev
->gart
.table
.vram
.robj
) {
146 radeon_object_kunmap(rdev
->gart
.table
.vram
.robj
);
147 radeon_object_unpin(rdev
->gart
.table
.vram
.robj
);
151 void rv370_pcie_gart_fini(struct radeon_device
*rdev
)
153 rv370_pcie_gart_disable(rdev
);
154 radeon_gart_table_vram_free(rdev
);
155 radeon_gart_fini(rdev
);
158 void r300_fence_ring_emit(struct radeon_device
*rdev
,
159 struct radeon_fence
*fence
)
161 /* Who ever call radeon_fence_emit should call ring_lock and ask
162 * for enough space (today caller are ib schedule and buffer move) */
163 /* Write SC register so SC & US assert idle */
164 radeon_ring_write(rdev
, PACKET0(0x43E0, 0));
165 radeon_ring_write(rdev
, 0);
166 radeon_ring_write(rdev
, PACKET0(0x43E4, 0));
167 radeon_ring_write(rdev
, 0);
169 radeon_ring_write(rdev
, PACKET0(0x4E4C, 0));
170 radeon_ring_write(rdev
, (2 << 0));
171 radeon_ring_write(rdev
, PACKET0(0x4F18, 0));
172 radeon_ring_write(rdev
, (1 << 0));
173 /* Wait until IDLE & CLEAN */
174 radeon_ring_write(rdev
, PACKET0(0x1720, 0));
175 radeon_ring_write(rdev
, (1 << 17) | (1 << 16) | (1 << 9));
176 /* Emit fence sequence & fire IRQ */
177 radeon_ring_write(rdev
, PACKET0(rdev
->fence_drv
.scratch_reg
, 0));
178 radeon_ring_write(rdev
, fence
->seq
);
179 radeon_ring_write(rdev
, PACKET0(RADEON_GEN_INT_STATUS
, 0));
180 radeon_ring_write(rdev
, RADEON_SW_INT_FIRE
);
183 int r300_copy_dma(struct radeon_device
*rdev
,
187 struct radeon_fence
*fence
)
194 /* radeon pitch is /64 */
195 size
= num_pages
<< PAGE_SHIFT
;
196 num_loops
= DIV_ROUND_UP(size
, 0x1FFFFF);
197 r
= radeon_ring_lock(rdev
, num_loops
* 4 + 64);
199 DRM_ERROR("radeon: moving bo (%d).\n", r
);
202 /* Must wait for 2D idle & clean before DMA or hangs might happen */
203 radeon_ring_write(rdev
, PACKET0(RADEON_WAIT_UNTIL
, 0 ));
204 radeon_ring_write(rdev
, (1 << 16));
205 for (i
= 0; i
< num_loops
; i
++) {
207 if (cur_size
> 0x1FFFFF) {
211 radeon_ring_write(rdev
, PACKET0(0x720, 2));
212 radeon_ring_write(rdev
, src_offset
);
213 radeon_ring_write(rdev
, dst_offset
);
214 radeon_ring_write(rdev
, cur_size
| (1 << 31) | (1 << 30));
215 src_offset
+= cur_size
;
216 dst_offset
+= cur_size
;
218 radeon_ring_write(rdev
, PACKET0(RADEON_WAIT_UNTIL
, 0));
219 radeon_ring_write(rdev
, RADEON_WAIT_DMA_GUI_IDLE
);
221 r
= radeon_fence_emit(rdev
, fence
);
223 radeon_ring_unlock_commit(rdev
);
227 void r300_ring_start(struct radeon_device
*rdev
)
229 unsigned gb_tile_config
;
232 /* Sub pixel 1/12 so we can have 4K rendering according to doc */
233 gb_tile_config
= (R300_ENABLE_TILING
| R300_TILE_SIZE_16
);
234 switch(rdev
->num_gb_pipes
) {
236 gb_tile_config
|= R300_PIPE_COUNT_R300
;
239 gb_tile_config
|= R300_PIPE_COUNT_R420_3P
;
242 gb_tile_config
|= R300_PIPE_COUNT_R420
;
246 gb_tile_config
|= R300_PIPE_COUNT_RV350
;
250 r
= radeon_ring_lock(rdev
, 64);
254 radeon_ring_write(rdev
, PACKET0(RADEON_ISYNC_CNTL
, 0));
255 radeon_ring_write(rdev
,
256 RADEON_ISYNC_ANY2D_IDLE3D
|
257 RADEON_ISYNC_ANY3D_IDLE2D
|
258 RADEON_ISYNC_WAIT_IDLEGUI
|
259 RADEON_ISYNC_CPSCRATCH_IDLEGUI
);
260 radeon_ring_write(rdev
, PACKET0(R300_GB_TILE_CONFIG
, 0));
261 radeon_ring_write(rdev
, gb_tile_config
);
262 radeon_ring_write(rdev
, PACKET0(RADEON_WAIT_UNTIL
, 0));
263 radeon_ring_write(rdev
,
264 RADEON_WAIT_2D_IDLECLEAN
|
265 RADEON_WAIT_3D_IDLECLEAN
);
266 radeon_ring_write(rdev
, PACKET0(0x170C, 0));
267 radeon_ring_write(rdev
, 1 << 31);
268 radeon_ring_write(rdev
, PACKET0(R300_GB_SELECT
, 0));
269 radeon_ring_write(rdev
, 0);
270 radeon_ring_write(rdev
, PACKET0(R300_GB_ENABLE
, 0));
271 radeon_ring_write(rdev
, 0);
272 radeon_ring_write(rdev
, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT
, 0));
273 radeon_ring_write(rdev
, R300_RB3D_DC_FLUSH
| R300_RB3D_DC_FREE
);
274 radeon_ring_write(rdev
, PACKET0(R300_RB3D_ZCACHE_CTLSTAT
, 0));
275 radeon_ring_write(rdev
, R300_ZC_FLUSH
| R300_ZC_FREE
);
276 radeon_ring_write(rdev
, PACKET0(RADEON_WAIT_UNTIL
, 0));
277 radeon_ring_write(rdev
,
278 RADEON_WAIT_2D_IDLECLEAN
|
279 RADEON_WAIT_3D_IDLECLEAN
);
280 radeon_ring_write(rdev
, PACKET0(R300_GB_AA_CONFIG
, 0));
281 radeon_ring_write(rdev
, 0);
282 radeon_ring_write(rdev
, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT
, 0));
283 radeon_ring_write(rdev
, R300_RB3D_DC_FLUSH
| R300_RB3D_DC_FREE
);
284 radeon_ring_write(rdev
, PACKET0(R300_RB3D_ZCACHE_CTLSTAT
, 0));
285 radeon_ring_write(rdev
, R300_ZC_FLUSH
| R300_ZC_FREE
);
286 radeon_ring_write(rdev
, PACKET0(R300_GB_MSPOS0
, 0));
287 radeon_ring_write(rdev
,
288 ((6 << R300_MS_X0_SHIFT
) |
289 (6 << R300_MS_Y0_SHIFT
) |
290 (6 << R300_MS_X1_SHIFT
) |
291 (6 << R300_MS_Y1_SHIFT
) |
292 (6 << R300_MS_X2_SHIFT
) |
293 (6 << R300_MS_Y2_SHIFT
) |
294 (6 << R300_MSBD0_Y_SHIFT
) |
295 (6 << R300_MSBD0_X_SHIFT
)));
296 radeon_ring_write(rdev
, PACKET0(R300_GB_MSPOS1
, 0));
297 radeon_ring_write(rdev
,
298 ((6 << R300_MS_X3_SHIFT
) |
299 (6 << R300_MS_Y3_SHIFT
) |
300 (6 << R300_MS_X4_SHIFT
) |
301 (6 << R300_MS_Y4_SHIFT
) |
302 (6 << R300_MS_X5_SHIFT
) |
303 (6 << R300_MS_Y5_SHIFT
) |
304 (6 << R300_MSBD1_SHIFT
)));
305 radeon_ring_write(rdev
, PACKET0(R300_GA_ENHANCE
, 0));
306 radeon_ring_write(rdev
, R300_GA_DEADLOCK_CNTL
| R300_GA_FASTSYNC_CNTL
);
307 radeon_ring_write(rdev
, PACKET0(R300_GA_POLY_MODE
, 0));
308 radeon_ring_write(rdev
,
309 R300_FRONT_PTYPE_TRIANGE
| R300_BACK_PTYPE_TRIANGE
);
310 radeon_ring_write(rdev
, PACKET0(R300_GA_ROUND_MODE
, 0));
311 radeon_ring_write(rdev
,
312 R300_GEOMETRY_ROUND_NEAREST
|
313 R300_COLOR_ROUND_NEAREST
);
314 radeon_ring_unlock_commit(rdev
);
317 void r300_errata(struct radeon_device
*rdev
)
319 rdev
->pll_errata
= 0;
321 if (rdev
->family
== CHIP_R300
&&
322 (RREG32(RADEON_CONFIG_CNTL
) & RADEON_CFG_ATI_REV_ID_MASK
) == RADEON_CFG_ATI_REV_A11
) {
323 rdev
->pll_errata
|= CHIP_ERRATA_R300_CG
;
327 int r300_mc_wait_for_idle(struct radeon_device
*rdev
)
332 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
334 tmp
= RREG32(0x0150);
335 if (tmp
& (1 << 4)) {
343 void r300_gpu_init(struct radeon_device
*rdev
)
345 uint32_t gb_tile_config
, tmp
;
347 r100_hdp_reset(rdev
);
348 /* FIXME: rv380 one pipes ? */
349 if ((rdev
->family
== CHIP_R300
) || (rdev
->family
== CHIP_R350
)) {
351 rdev
->num_gb_pipes
= 2;
353 /* rv350,rv370,rv380 */
354 rdev
->num_gb_pipes
= 1;
356 rdev
->num_z_pipes
= 1;
357 gb_tile_config
= (R300_ENABLE_TILING
| R300_TILE_SIZE_16
);
358 switch (rdev
->num_gb_pipes
) {
360 gb_tile_config
|= R300_PIPE_COUNT_R300
;
363 gb_tile_config
|= R300_PIPE_COUNT_R420_3P
;
366 gb_tile_config
|= R300_PIPE_COUNT_R420
;
370 gb_tile_config
|= R300_PIPE_COUNT_RV350
;
373 WREG32(R300_GB_TILE_CONFIG
, gb_tile_config
);
375 if (r100_gui_wait_for_idle(rdev
)) {
376 printk(KERN_WARNING
"Failed to wait GUI idle while "
377 "programming pipes. Bad things might happen.\n");
380 tmp
= RREG32(0x170C);
381 WREG32(0x170C, tmp
| (1 << 31));
383 WREG32(R300_RB2D_DSTCACHE_MODE
,
384 R300_DC_AUTOFLUSH_ENABLE
|
385 R300_DC_DC_DISABLE_IGNORE_PE
);
387 if (r100_gui_wait_for_idle(rdev
)) {
388 printk(KERN_WARNING
"Failed to wait GUI idle while "
389 "programming pipes. Bad things might happen.\n");
391 if (r300_mc_wait_for_idle(rdev
)) {
392 printk(KERN_WARNING
"Failed to wait MC idle while "
393 "programming pipes. Bad things might happen.\n");
395 DRM_INFO("radeon: %d quad pipes, %d Z pipes initialized.\n",
396 rdev
->num_gb_pipes
, rdev
->num_z_pipes
);
399 int r300_ga_reset(struct radeon_device
*rdev
)
405 reinit_cp
= rdev
->cp
.ready
;
406 rdev
->cp
.ready
= false;
407 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
408 WREG32(RADEON_CP_CSQ_MODE
, 0);
409 WREG32(RADEON_CP_CSQ_CNTL
, 0);
410 WREG32(RADEON_RBBM_SOFT_RESET
, 0x32005);
411 (void)RREG32(RADEON_RBBM_SOFT_RESET
);
413 WREG32(RADEON_RBBM_SOFT_RESET
, 0);
414 /* Wait to prevent race in RBBM_STATUS */
416 tmp
= RREG32(RADEON_RBBM_STATUS
);
417 if (tmp
& ((1 << 20) | (1 << 26))) {
418 DRM_ERROR("VAP & CP still busy (RBBM_STATUS=0x%08X)", tmp
);
419 /* GA still busy soft reset it */
420 WREG32(0x429C, 0x200);
421 WREG32(R300_VAP_PVS_STATE_FLUSH_REG
, 0);
426 /* Wait to prevent race in RBBM_STATUS */
428 tmp
= RREG32(RADEON_RBBM_STATUS
);
429 if (!(tmp
& ((1 << 20) | (1 << 26)))) {
433 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
434 tmp
= RREG32(RADEON_RBBM_STATUS
);
435 if (!(tmp
& ((1 << 20) | (1 << 26)))) {
436 DRM_INFO("GA reset succeed (RBBM_STATUS=0x%08X)\n",
439 return r100_cp_init(rdev
, rdev
->cp
.ring_size
);
445 tmp
= RREG32(RADEON_RBBM_STATUS
);
446 DRM_ERROR("Failed to reset GA ! (RBBM_STATUS=0x%08X)\n", tmp
);
450 int r300_gpu_reset(struct radeon_device
*rdev
)
454 /* reset order likely matter */
455 status
= RREG32(RADEON_RBBM_STATUS
);
457 r100_hdp_reset(rdev
);
459 if (status
& ((1 << 17) | (1 << 18) | (1 << 27))) {
460 r100_rb2d_reset(rdev
);
463 if (status
& ((1 << 20) | (1 << 26))) {
467 status
= RREG32(RADEON_RBBM_STATUS
);
468 if (status
& (1 << 16)) {
471 /* Check if GPU is idle */
472 status
= RREG32(RADEON_RBBM_STATUS
);
473 if (status
& (1 << 31)) {
474 DRM_ERROR("Failed to reset GPU (RBBM_STATUS=0x%08X)\n", status
);
477 DRM_INFO("GPU reset succeed (RBBM_STATUS=0x%08X)\n", status
);
483 * r300,r350,rv350,rv380 VRAM info
485 void r300_vram_info(struct radeon_device
*rdev
)
489 /* DDR for all card after R300 & IGP */
490 rdev
->mc
.vram_is_ddr
= true;
491 tmp
= RREG32(RADEON_MEM_CNTL
);
492 if (tmp
& R300_MEM_NUM_CHANNELS_MASK
) {
493 rdev
->mc
.vram_width
= 128;
495 rdev
->mc
.vram_width
= 64;
498 r100_vram_init_sizes(rdev
);
501 void rv370_set_pcie_lanes(struct radeon_device
*rdev
, int lanes
)
503 uint32_t link_width_cntl
, mask
;
505 if (rdev
->flags
& RADEON_IS_IGP
)
508 if (!(rdev
->flags
& RADEON_IS_PCIE
))
511 /* FIXME wait for idle */
515 mask
= RADEON_PCIE_LC_LINK_WIDTH_X0
;
518 mask
= RADEON_PCIE_LC_LINK_WIDTH_X1
;
521 mask
= RADEON_PCIE_LC_LINK_WIDTH_X2
;
524 mask
= RADEON_PCIE_LC_LINK_WIDTH_X4
;
527 mask
= RADEON_PCIE_LC_LINK_WIDTH_X8
;
530 mask
= RADEON_PCIE_LC_LINK_WIDTH_X12
;
534 mask
= RADEON_PCIE_LC_LINK_WIDTH_X16
;
538 link_width_cntl
= RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL
);
540 if ((link_width_cntl
& RADEON_PCIE_LC_LINK_WIDTH_RD_MASK
) ==
541 (mask
<< RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT
))
544 link_width_cntl
&= ~(RADEON_PCIE_LC_LINK_WIDTH_MASK
|
545 RADEON_PCIE_LC_RECONFIG_NOW
|
546 RADEON_PCIE_LC_RECONFIG_LATER
|
547 RADEON_PCIE_LC_SHORT_RECONFIG_EN
);
548 link_width_cntl
|= mask
;
549 WREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL
, link_width_cntl
);
550 WREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL
, (link_width_cntl
|
551 RADEON_PCIE_LC_RECONFIG_NOW
));
553 /* wait for lane set to complete */
554 link_width_cntl
= RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL
);
555 while (link_width_cntl
== 0xffffffff)
556 link_width_cntl
= RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL
);
560 #if defined(CONFIG_DEBUG_FS)
561 static int rv370_debugfs_pcie_gart_info(struct seq_file
*m
, void *data
)
563 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
564 struct drm_device
*dev
= node
->minor
->dev
;
565 struct radeon_device
*rdev
= dev
->dev_private
;
568 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL
);
569 seq_printf(m
, "PCIE_TX_GART_CNTL 0x%08x\n", tmp
);
570 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_BASE
);
571 seq_printf(m
, "PCIE_TX_GART_BASE 0x%08x\n", tmp
);
572 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_START_LO
);
573 seq_printf(m
, "PCIE_TX_GART_START_LO 0x%08x\n", tmp
);
574 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_START_HI
);
575 seq_printf(m
, "PCIE_TX_GART_START_HI 0x%08x\n", tmp
);
576 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_END_LO
);
577 seq_printf(m
, "PCIE_TX_GART_END_LO 0x%08x\n", tmp
);
578 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_END_HI
);
579 seq_printf(m
, "PCIE_TX_GART_END_HI 0x%08x\n", tmp
);
580 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_ERROR
);
581 seq_printf(m
, "PCIE_TX_GART_ERROR 0x%08x\n", tmp
);
585 static struct drm_info_list rv370_pcie_gart_info_list
[] = {
586 {"rv370_pcie_gart_info", rv370_debugfs_pcie_gart_info
, 0, NULL
},
590 static int rv370_debugfs_pcie_gart_info_init(struct radeon_device
*rdev
)
592 #if defined(CONFIG_DEBUG_FS)
593 return radeon_debugfs_add_files(rdev
, rv370_pcie_gart_info_list
, 1);
599 static int r300_packet0_check(struct radeon_cs_parser
*p
,
600 struct radeon_cs_packet
*pkt
,
601 unsigned idx
, unsigned reg
)
603 struct radeon_cs_reloc
*reloc
;
604 struct r100_cs_track
*track
;
605 volatile uint32_t *ib
;
606 uint32_t tmp
, tile_flags
= 0;
612 track
= (struct r100_cs_track
*)p
->track
;
613 idx_value
= radeon_get_ib_value(p
, idx
);
616 case AVIVO_D1MODE_VLINE_START_END
:
617 case RADEON_CRTC_GUI_TRIG_VLINE
:
618 r
= r100_cs_packet_parse_vline(p
);
620 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
622 r100_cs_dump_packet(p
, pkt
);
626 case RADEON_DST_PITCH_OFFSET
:
627 case RADEON_SRC_PITCH_OFFSET
:
628 r
= r100_reloc_pitch_offset(p
, pkt
, idx
, reg
);
632 case R300_RB3D_COLOROFFSET0
:
633 case R300_RB3D_COLOROFFSET1
:
634 case R300_RB3D_COLOROFFSET2
:
635 case R300_RB3D_COLOROFFSET3
:
636 i
= (reg
- R300_RB3D_COLOROFFSET0
) >> 2;
637 r
= r100_cs_packet_next_reloc(p
, &reloc
);
639 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
641 r100_cs_dump_packet(p
, pkt
);
644 track
->cb
[i
].robj
= reloc
->robj
;
645 track
->cb
[i
].offset
= idx_value
;
646 ib
[idx
] = idx_value
+ ((u32
)reloc
->lobj
.gpu_offset
);
648 case R300_ZB_DEPTHOFFSET
:
649 r
= r100_cs_packet_next_reloc(p
, &reloc
);
651 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
653 r100_cs_dump_packet(p
, pkt
);
656 track
->zb
.robj
= reloc
->robj
;
657 track
->zb
.offset
= idx_value
;
658 ib
[idx
] = idx_value
+ ((u32
)reloc
->lobj
.gpu_offset
);
660 case R300_TX_OFFSET_0
:
661 case R300_TX_OFFSET_0
+4:
662 case R300_TX_OFFSET_0
+8:
663 case R300_TX_OFFSET_0
+12:
664 case R300_TX_OFFSET_0
+16:
665 case R300_TX_OFFSET_0
+20:
666 case R300_TX_OFFSET_0
+24:
667 case R300_TX_OFFSET_0
+28:
668 case R300_TX_OFFSET_0
+32:
669 case R300_TX_OFFSET_0
+36:
670 case R300_TX_OFFSET_0
+40:
671 case R300_TX_OFFSET_0
+44:
672 case R300_TX_OFFSET_0
+48:
673 case R300_TX_OFFSET_0
+52:
674 case R300_TX_OFFSET_0
+56:
675 case R300_TX_OFFSET_0
+60:
676 i
= (reg
- R300_TX_OFFSET_0
) >> 2;
677 r
= r100_cs_packet_next_reloc(p
, &reloc
);
679 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
681 r100_cs_dump_packet(p
, pkt
);
684 ib
[idx
] = idx_value
+ ((u32
)reloc
->lobj
.gpu_offset
);
685 track
->textures
[i
].robj
= reloc
->robj
;
687 /* Tracked registers */
690 track
->vap_vf_cntl
= idx_value
;
694 track
->vtx_size
= idx_value
& 0x7F;
697 /* VAP_VF_MAX_VTX_INDX */
698 track
->max_indx
= idx_value
& 0x00FFFFFFUL
;
702 track
->maxy
= ((idx_value
>> 13) & 0x1FFF) + 1;
703 if (p
->rdev
->family
< CHIP_RV515
) {
709 track
->num_cb
= ((idx_value
>> 5) & 0x3) + 1;
715 /* RB3D_COLORPITCH0 */
716 /* RB3D_COLORPITCH1 */
717 /* RB3D_COLORPITCH2 */
718 /* RB3D_COLORPITCH3 */
719 r
= r100_cs_packet_next_reloc(p
, &reloc
);
721 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
723 r100_cs_dump_packet(p
, pkt
);
727 if (reloc
->lobj
.tiling_flags
& RADEON_TILING_MACRO
)
728 tile_flags
|= R300_COLOR_TILE_ENABLE
;
729 if (reloc
->lobj
.tiling_flags
& RADEON_TILING_MICRO
)
730 tile_flags
|= R300_COLOR_MICROTILE_ENABLE
;
732 tmp
= idx_value
& ~(0x7 << 16);
736 i
= (reg
- 0x4E38) >> 2;
737 track
->cb
[i
].pitch
= idx_value
& 0x3FFE;
738 switch (((idx_value
>> 21) & 0xF)) {
742 track
->cb
[i
].cpp
= 1;
748 track
->cb
[i
].cpp
= 2;
751 track
->cb
[i
].cpp
= 4;
754 track
->cb
[i
].cpp
= 8;
757 track
->cb
[i
].cpp
= 16;
760 DRM_ERROR("Invalid color buffer format (%d) !\n",
761 ((idx_value
>> 21) & 0xF));
768 track
->z_enabled
= true;
770 track
->z_enabled
= false;
775 switch ((idx_value
& 0xF)) {
784 DRM_ERROR("Invalid z buffer format (%d) !\n",
791 r
= r100_cs_packet_next_reloc(p
, &reloc
);
793 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
795 r100_cs_dump_packet(p
, pkt
);
799 if (reloc
->lobj
.tiling_flags
& RADEON_TILING_MACRO
)
800 tile_flags
|= R300_DEPTHMACROTILE_ENABLE
;
801 if (reloc
->lobj
.tiling_flags
& RADEON_TILING_MICRO
)
802 tile_flags
|= R300_DEPTHMICROTILE_TILED
;;
804 tmp
= idx_value
& ~(0x7 << 16);
808 track
->zb
.pitch
= idx_value
& 0x3FFC;
811 for (i
= 0; i
< 16; i
++) {
814 enabled
= !!(idx_value
& (1 << i
));
815 track
->textures
[i
].enabled
= enabled
;
834 /* TX_FORMAT1_[0-15] */
835 i
= (reg
- 0x44C0) >> 2;
836 tmp
= (idx_value
>> 25) & 0x3;
837 track
->textures
[i
].tex_coord_type
= tmp
;
838 switch ((idx_value
& 0x1F)) {
839 case R300_TX_FORMAT_X8
:
840 case R300_TX_FORMAT_Y4X4
:
841 case R300_TX_FORMAT_Z3Y3X2
:
842 track
->textures
[i
].cpp
= 1;
844 case R300_TX_FORMAT_X16
:
845 case R300_TX_FORMAT_Y8X8
:
846 case R300_TX_FORMAT_Z5Y6X5
:
847 case R300_TX_FORMAT_Z6Y5X5
:
848 case R300_TX_FORMAT_W4Z4Y4X4
:
849 case R300_TX_FORMAT_W1Z5Y5X5
:
850 case R300_TX_FORMAT_DXT1
:
851 case R300_TX_FORMAT_D3DMFT_CxV8U8
:
852 case R300_TX_FORMAT_B8G8_B8G8
:
853 case R300_TX_FORMAT_G8R8_G8B8
:
854 track
->textures
[i
].cpp
= 2;
856 case R300_TX_FORMAT_Y16X16
:
857 case R300_TX_FORMAT_Z11Y11X10
:
858 case R300_TX_FORMAT_Z10Y11X11
:
859 case R300_TX_FORMAT_W8Z8Y8X8
:
860 case R300_TX_FORMAT_W2Z10Y10X10
:
862 case R300_TX_FORMAT_FL_I32
:
864 case R300_TX_FORMAT_DXT3
:
865 case R300_TX_FORMAT_DXT5
:
866 track
->textures
[i
].cpp
= 4;
868 case R300_TX_FORMAT_W16Z16Y16X16
:
869 case R300_TX_FORMAT_FL_R16G16B16A16
:
870 case R300_TX_FORMAT_FL_I32A32
:
871 track
->textures
[i
].cpp
= 8;
873 case R300_TX_FORMAT_FL_R32G32B32A32
:
874 track
->textures
[i
].cpp
= 16;
877 DRM_ERROR("Invalid texture format %u\n",
899 /* TX_FILTER0_[0-15] */
900 i
= (reg
- 0x4400) >> 2;
901 tmp
= idx_value
& 0x7;
902 if (tmp
== 2 || tmp
== 4 || tmp
== 6) {
903 track
->textures
[i
].roundup_w
= false;
905 tmp
= (idx_value
>> 3) & 0x7;
906 if (tmp
== 2 || tmp
== 4 || tmp
== 6) {
907 track
->textures
[i
].roundup_h
= false;
926 /* TX_FORMAT2_[0-15] */
927 i
= (reg
- 0x4500) >> 2;
928 tmp
= idx_value
& 0x3FFF;
929 track
->textures
[i
].pitch
= tmp
+ 1;
930 if (p
->rdev
->family
>= CHIP_RV515
) {
931 tmp
= ((idx_value
>> 15) & 1) << 11;
932 track
->textures
[i
].width_11
= tmp
;
933 tmp
= ((idx_value
>> 16) & 1) << 11;
934 track
->textures
[i
].height_11
= tmp
;
953 /* TX_FORMAT0_[0-15] */
954 i
= (reg
- 0x4480) >> 2;
955 tmp
= idx_value
& 0x7FF;
956 track
->textures
[i
].width
= tmp
+ 1;
957 tmp
= (idx_value
>> 11) & 0x7FF;
958 track
->textures
[i
].height
= tmp
+ 1;
959 tmp
= (idx_value
>> 26) & 0xF;
960 track
->textures
[i
].num_levels
= tmp
;
961 tmp
= idx_value
& (1 << 31);
962 track
->textures
[i
].use_pitch
= !!tmp
;
963 tmp
= (idx_value
>> 22) & 0xF;
964 track
->textures
[i
].txdepth
= tmp
;
966 case R300_ZB_ZPASS_ADDR
:
967 r
= r100_cs_packet_next_reloc(p
, &reloc
);
969 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
971 r100_cs_dump_packet(p
, pkt
);
974 ib
[idx
] = idx_value
+ ((u32
)reloc
->lobj
.gpu_offset
);
977 /* valid register only on RV530 */
978 if (p
->rdev
->family
== CHIP_RV530
)
980 /* fallthrough do not move */
982 printk(KERN_ERR
"Forbidden register 0x%04X in cs at %d\n",
989 static int r300_packet3_check(struct radeon_cs_parser
*p
,
990 struct radeon_cs_packet
*pkt
)
992 struct radeon_cs_reloc
*reloc
;
993 struct r100_cs_track
*track
;
994 volatile uint32_t *ib
;
1000 track
= (struct r100_cs_track
*)p
->track
;
1001 switch(pkt
->opcode
) {
1002 case PACKET3_3D_LOAD_VBPNTR
:
1003 r
= r100_packet3_load_vbpntr(p
, pkt
, idx
);
1007 case PACKET3_INDX_BUFFER
:
1008 r
= r100_cs_packet_next_reloc(p
, &reloc
);
1010 DRM_ERROR("No reloc for packet3 %d\n", pkt
->opcode
);
1011 r100_cs_dump_packet(p
, pkt
);
1014 ib
[idx
+1] = radeon_get_ib_value(p
, idx
+ 1) + ((u32
)reloc
->lobj
.gpu_offset
);
1015 r
= r100_cs_track_check_pkt3_indx_buffer(p
, pkt
, reloc
->robj
);
1021 case PACKET3_3D_DRAW_IMMD
:
1022 /* Number of dwords is vtx_size * (num_vertices - 1)
1023 * PRIM_WALK must be equal to 3 vertex data in embedded
1025 if (((radeon_get_ib_value(p
, idx
+ 1) >> 4) & 0x3) != 3) {
1026 DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n");
1029 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
+ 1);
1030 track
->immd_dwords
= pkt
->count
- 1;
1031 r
= r100_cs_track_check(p
->rdev
, track
);
1036 case PACKET3_3D_DRAW_IMMD_2
:
1037 /* Number of dwords is vtx_size * (num_vertices - 1)
1038 * PRIM_WALK must be equal to 3 vertex data in embedded
1040 if (((radeon_get_ib_value(p
, idx
) >> 4) & 0x3) != 3) {
1041 DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n");
1044 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
);
1045 track
->immd_dwords
= pkt
->count
;
1046 r
= r100_cs_track_check(p
->rdev
, track
);
1051 case PACKET3_3D_DRAW_VBUF
:
1052 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
+ 1);
1053 r
= r100_cs_track_check(p
->rdev
, track
);
1058 case PACKET3_3D_DRAW_VBUF_2
:
1059 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
);
1060 r
= r100_cs_track_check(p
->rdev
, track
);
1065 case PACKET3_3D_DRAW_INDX
:
1066 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
+ 1);
1067 r
= r100_cs_track_check(p
->rdev
, track
);
1072 case PACKET3_3D_DRAW_INDX_2
:
1073 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
);
1074 r
= r100_cs_track_check(p
->rdev
, track
);
1082 DRM_ERROR("Packet3 opcode %x not supported\n", pkt
->opcode
);
1088 int r300_cs_parse(struct radeon_cs_parser
*p
)
1090 struct radeon_cs_packet pkt
;
1091 struct r100_cs_track
*track
;
1094 track
= kzalloc(sizeof(*track
), GFP_KERNEL
);
1095 r100_cs_track_clear(p
->rdev
, track
);
1098 r
= r100_cs_packet_parse(p
, &pkt
, p
->idx
);
1102 p
->idx
+= pkt
.count
+ 2;
1105 r
= r100_cs_parse_packet0(p
, &pkt
,
1106 p
->rdev
->config
.r300
.reg_safe_bm
,
1107 p
->rdev
->config
.r300
.reg_safe_bm_size
,
1108 &r300_packet0_check
);
1113 r
= r300_packet3_check(p
, &pkt
);
1116 DRM_ERROR("Unknown packet type %d !\n", pkt
.type
);
1122 } while (p
->idx
< p
->chunks
[p
->chunk_ib_idx
].length_dw
);
1126 void r300_set_reg_safe(struct radeon_device
*rdev
)
1128 rdev
->config
.r300
.reg_safe_bm
= r300_reg_safe_bm
;
1129 rdev
->config
.r300
.reg_safe_bm_size
= ARRAY_SIZE(r300_reg_safe_bm
);
1132 void r300_mc_program(struct radeon_device
*rdev
)
1134 struct r100_mc_save save
;
1137 r
= r100_debugfs_mc_info_init(rdev
);
1139 dev_err(rdev
->dev
, "Failed to create r100_mc debugfs file.\n");
1142 /* Stops all mc clients */
1143 r100_mc_stop(rdev
, &save
);
1144 if (rdev
->flags
& RADEON_IS_AGP
) {
1145 WREG32(R_00014C_MC_AGP_LOCATION
,
1146 S_00014C_MC_AGP_START(rdev
->mc
.gtt_start
>> 16) |
1147 S_00014C_MC_AGP_TOP(rdev
->mc
.gtt_end
>> 16));
1148 WREG32(R_000170_AGP_BASE
, lower_32_bits(rdev
->mc
.agp_base
));
1149 WREG32(R_00015C_AGP_BASE_2
,
1150 upper_32_bits(rdev
->mc
.agp_base
) & 0xff);
1152 WREG32(R_00014C_MC_AGP_LOCATION
, 0x0FFFFFFF);
1153 WREG32(R_000170_AGP_BASE
, 0);
1154 WREG32(R_00015C_AGP_BASE_2
, 0);
1156 /* Wait for mc idle */
1157 if (r300_mc_wait_for_idle(rdev
))
1158 DRM_INFO("Failed to wait MC idle before programming MC.\n");
1159 /* Program MC, should be a 32bits limited address space */
1160 WREG32(R_000148_MC_FB_LOCATION
,
1161 S_000148_MC_FB_START(rdev
->mc
.vram_start
>> 16) |
1162 S_000148_MC_FB_TOP(rdev
->mc
.vram_end
>> 16));
1163 r100_mc_resume(rdev
, &save
);
1166 void r300_clock_startup(struct radeon_device
*rdev
)
1170 if (radeon_dynclks
!= -1 && radeon_dynclks
)
1171 radeon_legacy_set_clock_gating(rdev
, 1);
1172 /* We need to force on some of the block */
1173 tmp
= RREG32_PLL(R_00000D_SCLK_CNTL
);
1174 tmp
|= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1);
1175 if ((rdev
->family
== CHIP_RV350
) || (rdev
->family
== CHIP_RV380
))
1176 tmp
|= S_00000D_FORCE_VAP(1);
1177 WREG32_PLL(R_00000D_SCLK_CNTL
, tmp
);
1180 static int r300_startup(struct radeon_device
*rdev
)
1184 r300_mc_program(rdev
);
1186 r300_clock_startup(rdev
);
1187 /* Initialize GPU configuration (# pipes, ...) */
1188 r300_gpu_init(rdev
);
1189 /* Initialize GART (initialize after TTM so we can allocate
1190 * memory through TTM but finalize after TTM) */
1191 if (rdev
->flags
& RADEON_IS_PCIE
) {
1192 r
= rv370_pcie_gart_enable(rdev
);
1196 if (rdev
->flags
& RADEON_IS_PCI
) {
1197 r
= r100_pci_gart_enable(rdev
);
1202 rdev
->irq
.sw_int
= true;
1204 /* 1M ring buffer */
1205 r
= r100_cp_init(rdev
, 1024 * 1024);
1207 dev_err(rdev
->dev
, "failled initializing CP (%d).\n", r
);
1210 r
= r100_wb_init(rdev
);
1212 dev_err(rdev
->dev
, "failled initializing WB (%d).\n", r
);
1213 r
= r100_ib_init(rdev
);
1215 dev_err(rdev
->dev
, "failled initializing IB (%d).\n", r
);
1221 int r300_resume(struct radeon_device
*rdev
)
1223 /* Make sur GART are not working */
1224 if (rdev
->flags
& RADEON_IS_PCIE
)
1225 rv370_pcie_gart_disable(rdev
);
1226 if (rdev
->flags
& RADEON_IS_PCI
)
1227 r100_pci_gart_disable(rdev
);
1228 /* Resume clock before doing reset */
1229 r300_clock_startup(rdev
);
1230 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
1231 if (radeon_gpu_reset(rdev
)) {
1232 dev_warn(rdev
->dev
, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
1233 RREG32(R_000E40_RBBM_STATUS
),
1234 RREG32(R_0007C0_CP_STAT
));
1237 radeon_combios_asic_init(rdev
->ddev
);
1238 /* Resume clock after posting */
1239 r300_clock_startup(rdev
);
1240 return r300_startup(rdev
);
1243 int r300_suspend(struct radeon_device
*rdev
)
1245 r100_cp_disable(rdev
);
1246 r100_wb_disable(rdev
);
1247 r100_irq_disable(rdev
);
1248 if (rdev
->flags
& RADEON_IS_PCIE
)
1249 rv370_pcie_gart_disable(rdev
);
1250 if (rdev
->flags
& RADEON_IS_PCI
)
1251 r100_pci_gart_disable(rdev
);
1255 void r300_fini(struct radeon_device
*rdev
)
1261 radeon_gem_fini(rdev
);
1262 if (rdev
->flags
& RADEON_IS_PCIE
)
1263 rv370_pcie_gart_fini(rdev
);
1264 if (rdev
->flags
& RADEON_IS_PCI
)
1265 r100_pci_gart_fini(rdev
);
1266 radeon_irq_kms_fini(rdev
);
1267 radeon_fence_driver_fini(rdev
);
1268 radeon_object_fini(rdev
);
1269 radeon_atombios_fini(rdev
);
1274 int r300_init(struct radeon_device
*rdev
)
1279 r100_vga_render_disable(rdev
);
1280 /* Initialize scratch registers */
1281 radeon_scratch_init(rdev
);
1282 /* Initialize surface registers */
1283 radeon_surface_init(rdev
);
1284 /* TODO: disable VGA need to use VGA request */
1286 if (!radeon_get_bios(rdev
)) {
1287 if (ASIC_IS_AVIVO(rdev
))
1290 if (rdev
->is_atom_bios
) {
1291 dev_err(rdev
->dev
, "Expecting combios for RS400/RS480 GPU\n");
1294 r
= radeon_combios_init(rdev
);
1298 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
1299 if (radeon_gpu_reset(rdev
)) {
1301 "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
1302 RREG32(R_000E40_RBBM_STATUS
),
1303 RREG32(R_0007C0_CP_STAT
));
1305 /* check if cards are posted or not */
1306 if (!radeon_card_posted(rdev
) && rdev
->bios
) {
1307 DRM_INFO("GPU not posted. posting now...\n");
1308 radeon_combios_asic_init(rdev
->ddev
);
1310 /* Set asic errata */
1312 /* Initialize clocks */
1313 radeon_get_clock_info(rdev
->ddev
);
1314 /* Get vram informations */
1315 r300_vram_info(rdev
);
1316 /* Initialize memory controller (also test AGP) */
1317 r
= r420_mc_init(rdev
);
1321 r
= radeon_fence_driver_init(rdev
);
1324 r
= radeon_irq_kms_init(rdev
);
1327 /* Memory manager */
1328 r
= radeon_object_init(rdev
);
1331 if (rdev
->flags
& RADEON_IS_PCIE
) {
1332 r
= rv370_pcie_gart_init(rdev
);
1336 if (rdev
->flags
& RADEON_IS_PCI
) {
1337 r
= r100_pci_gart_init(rdev
);
1341 r300_set_reg_safe(rdev
);
1342 rdev
->accel_working
= true;
1343 r
= r300_startup(rdev
);
1345 /* Somethings want wront with the accel init stop accel */
1346 dev_err(rdev
->dev
, "Disabling GPU acceleration\n");
1351 if (rdev
->flags
& RADEON_IS_PCIE
)
1352 rv370_pcie_gart_fini(rdev
);
1353 if (rdev
->flags
& RADEON_IS_PCI
)
1354 r100_pci_gart_fini(rdev
);
1355 radeon_irq_kms_fini(rdev
);
1356 rdev
->accel_working
= false;