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>
29 #include <linux/slab.h>
32 #include <drm/drm_crtc_helper.h>
33 #include "radeon_reg.h"
35 #include "radeon_asic.h"
36 #include <drm/radeon_drm.h>
37 #include "r100_track.h"
40 #include "r300_reg_safe.h"
42 /* This files gather functions specifics to: r300,r350,rv350,rv370,rv380
45 * - HOST_PATH_CNTL: r300 family seems to dislike write to HOST_PATH_CNTL
46 * using MMIO to flush host path read cache, this lead to HARDLOCKUP.
47 * However, scheduling such write to the ring seems harmless, i suspect
48 * the CP read collide with the flush somehow, or maybe the MC, hard to
49 * tell. (Jerome Glisse)
53 * rv370,rv380 PCIE GART
55 static int rv370_debugfs_pcie_gart_info_init(struct radeon_device
*rdev
);
57 void rv370_pcie_gart_tlb_flush(struct radeon_device
*rdev
)
62 /* Workaround HW bug do flush 2 times */
63 for (i
= 0; i
< 2; i
++) {
64 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL
);
65 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL
, tmp
| RADEON_PCIE_TX_GART_INVALIDATE_TLB
);
66 (void)RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL
);
67 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL
, tmp
);
72 #define R300_PTE_WRITEABLE (1 << 2)
73 #define R300_PTE_READABLE (1 << 3)
75 void rv370_pcie_gart_set_page(struct radeon_device
*rdev
, unsigned i
,
78 void __iomem
*ptr
= rdev
->gart
.ptr
;
80 addr
= (lower_32_bits(addr
) >> 8) |
81 ((upper_32_bits(addr
) & 0xff) << 24) |
82 R300_PTE_WRITEABLE
| R300_PTE_READABLE
;
83 /* on x86 we want this to be CPU endian, on powerpc
84 * on powerpc without HW swappers, it'll get swapped on way
85 * into VRAM - so no need for cpu_to_le32 on VRAM tables */
86 writel(addr
, ((void __iomem
*)ptr
) + (i
* 4));
89 int rv370_pcie_gart_init(struct radeon_device
*rdev
)
93 if (rdev
->gart
.robj
) {
94 WARN(1, "RV370 PCIE GART already initialized\n");
97 /* Initialize common gart structure */
98 r
= radeon_gart_init(rdev
);
101 r
= rv370_debugfs_pcie_gart_info_init(rdev
);
103 DRM_ERROR("Failed to register debugfs file for PCIE gart !\n");
104 rdev
->gart
.table_size
= rdev
->gart
.num_gpu_pages
* 4;
105 rdev
->asic
->gart
.tlb_flush
= &rv370_pcie_gart_tlb_flush
;
106 rdev
->asic
->gart
.set_page
= &rv370_pcie_gart_set_page
;
107 return radeon_gart_table_vram_alloc(rdev
);
110 int rv370_pcie_gart_enable(struct radeon_device
*rdev
)
116 if (rdev
->gart
.robj
== NULL
) {
117 dev_err(rdev
->dev
, "No VRAM object for PCIE GART.\n");
120 r
= radeon_gart_table_vram_pin(rdev
);
123 radeon_gart_restore(rdev
);
124 /* discard memory request outside of configured range */
125 tmp
= RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD
;
126 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL
, tmp
);
127 WREG32_PCIE(RADEON_PCIE_TX_GART_START_LO
, rdev
->mc
.gtt_start
);
128 tmp
= rdev
->mc
.gtt_end
& ~RADEON_GPU_PAGE_MASK
;
129 WREG32_PCIE(RADEON_PCIE_TX_GART_END_LO
, tmp
);
130 WREG32_PCIE(RADEON_PCIE_TX_GART_START_HI
, 0);
131 WREG32_PCIE(RADEON_PCIE_TX_GART_END_HI
, 0);
132 table_addr
= rdev
->gart
.table_addr
;
133 WREG32_PCIE(RADEON_PCIE_TX_GART_BASE
, table_addr
);
134 /* FIXME: setup default page */
135 WREG32_PCIE(RADEON_PCIE_TX_DISCARD_RD_ADDR_LO
, rdev
->mc
.vram_start
);
136 WREG32_PCIE(RADEON_PCIE_TX_DISCARD_RD_ADDR_HI
, 0);
138 WREG32_PCIE(RADEON_PCIE_TX_GART_ERROR
, 0);
139 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL
);
140 tmp
|= RADEON_PCIE_TX_GART_EN
;
141 tmp
|= RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD
;
142 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL
, tmp
);
143 rv370_pcie_gart_tlb_flush(rdev
);
144 DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
145 (unsigned)(rdev
->mc
.gtt_size
>> 20),
146 (unsigned long long)table_addr
);
147 rdev
->gart
.ready
= true;
151 void rv370_pcie_gart_disable(struct radeon_device
*rdev
)
155 WREG32_PCIE(RADEON_PCIE_TX_GART_START_LO
, 0);
156 WREG32_PCIE(RADEON_PCIE_TX_GART_END_LO
, 0);
157 WREG32_PCIE(RADEON_PCIE_TX_GART_START_HI
, 0);
158 WREG32_PCIE(RADEON_PCIE_TX_GART_END_HI
, 0);
159 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL
);
160 tmp
|= RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD
;
161 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL
, tmp
& ~RADEON_PCIE_TX_GART_EN
);
162 radeon_gart_table_vram_unpin(rdev
);
165 void rv370_pcie_gart_fini(struct radeon_device
*rdev
)
167 radeon_gart_fini(rdev
);
168 rv370_pcie_gart_disable(rdev
);
169 radeon_gart_table_vram_free(rdev
);
172 void r300_fence_ring_emit(struct radeon_device
*rdev
,
173 struct radeon_fence
*fence
)
175 struct radeon_ring
*ring
= &rdev
->ring
[fence
->ring
];
177 /* Who ever call radeon_fence_emit should call ring_lock and ask
178 * for enough space (today caller are ib schedule and buffer move) */
179 /* Write SC register so SC & US assert idle */
180 radeon_ring_write(ring
, PACKET0(R300_RE_SCISSORS_TL
, 0));
181 radeon_ring_write(ring
, 0);
182 radeon_ring_write(ring
, PACKET0(R300_RE_SCISSORS_BR
, 0));
183 radeon_ring_write(ring
, 0);
185 radeon_ring_write(ring
, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT
, 0));
186 radeon_ring_write(ring
, R300_RB3D_DC_FLUSH
);
187 radeon_ring_write(ring
, PACKET0(R300_RB3D_ZCACHE_CTLSTAT
, 0));
188 radeon_ring_write(ring
, R300_ZC_FLUSH
);
189 /* Wait until IDLE & CLEAN */
190 radeon_ring_write(ring
, PACKET0(RADEON_WAIT_UNTIL
, 0));
191 radeon_ring_write(ring
, (RADEON_WAIT_3D_IDLECLEAN
|
192 RADEON_WAIT_2D_IDLECLEAN
|
193 RADEON_WAIT_DMA_GUI_IDLE
));
194 radeon_ring_write(ring
, PACKET0(RADEON_HOST_PATH_CNTL
, 0));
195 radeon_ring_write(ring
, rdev
->config
.r300
.hdp_cntl
|
196 RADEON_HDP_READ_BUFFER_INVALIDATE
);
197 radeon_ring_write(ring
, PACKET0(RADEON_HOST_PATH_CNTL
, 0));
198 radeon_ring_write(ring
, rdev
->config
.r300
.hdp_cntl
);
199 /* Emit fence sequence & fire IRQ */
200 radeon_ring_write(ring
, PACKET0(rdev
->fence_drv
[fence
->ring
].scratch_reg
, 0));
201 radeon_ring_write(ring
, fence
->seq
);
202 radeon_ring_write(ring
, PACKET0(RADEON_GEN_INT_STATUS
, 0));
203 radeon_ring_write(ring
, RADEON_SW_INT_FIRE
);
206 void r300_ring_start(struct radeon_device
*rdev
, struct radeon_ring
*ring
)
208 unsigned gb_tile_config
;
211 /* Sub pixel 1/12 so we can have 4K rendering according to doc */
212 gb_tile_config
= (R300_ENABLE_TILING
| R300_TILE_SIZE_16
);
213 switch(rdev
->num_gb_pipes
) {
215 gb_tile_config
|= R300_PIPE_COUNT_R300
;
218 gb_tile_config
|= R300_PIPE_COUNT_R420_3P
;
221 gb_tile_config
|= R300_PIPE_COUNT_R420
;
225 gb_tile_config
|= R300_PIPE_COUNT_RV350
;
229 r
= radeon_ring_lock(rdev
, ring
, 64);
233 radeon_ring_write(ring
, PACKET0(RADEON_ISYNC_CNTL
, 0));
234 radeon_ring_write(ring
,
235 RADEON_ISYNC_ANY2D_IDLE3D
|
236 RADEON_ISYNC_ANY3D_IDLE2D
|
237 RADEON_ISYNC_WAIT_IDLEGUI
|
238 RADEON_ISYNC_CPSCRATCH_IDLEGUI
);
239 radeon_ring_write(ring
, PACKET0(R300_GB_TILE_CONFIG
, 0));
240 radeon_ring_write(ring
, gb_tile_config
);
241 radeon_ring_write(ring
, PACKET0(RADEON_WAIT_UNTIL
, 0));
242 radeon_ring_write(ring
,
243 RADEON_WAIT_2D_IDLECLEAN
|
244 RADEON_WAIT_3D_IDLECLEAN
);
245 radeon_ring_write(ring
, PACKET0(R300_DST_PIPE_CONFIG
, 0));
246 radeon_ring_write(ring
, R300_PIPE_AUTO_CONFIG
);
247 radeon_ring_write(ring
, PACKET0(R300_GB_SELECT
, 0));
248 radeon_ring_write(ring
, 0);
249 radeon_ring_write(ring
, PACKET0(R300_GB_ENABLE
, 0));
250 radeon_ring_write(ring
, 0);
251 radeon_ring_write(ring
, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT
, 0));
252 radeon_ring_write(ring
, R300_RB3D_DC_FLUSH
| R300_RB3D_DC_FREE
);
253 radeon_ring_write(ring
, PACKET0(R300_RB3D_ZCACHE_CTLSTAT
, 0));
254 radeon_ring_write(ring
, R300_ZC_FLUSH
| R300_ZC_FREE
);
255 radeon_ring_write(ring
, PACKET0(RADEON_WAIT_UNTIL
, 0));
256 radeon_ring_write(ring
,
257 RADEON_WAIT_2D_IDLECLEAN
|
258 RADEON_WAIT_3D_IDLECLEAN
);
259 radeon_ring_write(ring
, PACKET0(R300_GB_AA_CONFIG
, 0));
260 radeon_ring_write(ring
, 0);
261 radeon_ring_write(ring
, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT
, 0));
262 radeon_ring_write(ring
, R300_RB3D_DC_FLUSH
| R300_RB3D_DC_FREE
);
263 radeon_ring_write(ring
, PACKET0(R300_RB3D_ZCACHE_CTLSTAT
, 0));
264 radeon_ring_write(ring
, R300_ZC_FLUSH
| R300_ZC_FREE
);
265 radeon_ring_write(ring
, PACKET0(R300_GB_MSPOS0
, 0));
266 radeon_ring_write(ring
,
267 ((6 << R300_MS_X0_SHIFT
) |
268 (6 << R300_MS_Y0_SHIFT
) |
269 (6 << R300_MS_X1_SHIFT
) |
270 (6 << R300_MS_Y1_SHIFT
) |
271 (6 << R300_MS_X2_SHIFT
) |
272 (6 << R300_MS_Y2_SHIFT
) |
273 (6 << R300_MSBD0_Y_SHIFT
) |
274 (6 << R300_MSBD0_X_SHIFT
)));
275 radeon_ring_write(ring
, PACKET0(R300_GB_MSPOS1
, 0));
276 radeon_ring_write(ring
,
277 ((6 << R300_MS_X3_SHIFT
) |
278 (6 << R300_MS_Y3_SHIFT
) |
279 (6 << R300_MS_X4_SHIFT
) |
280 (6 << R300_MS_Y4_SHIFT
) |
281 (6 << R300_MS_X5_SHIFT
) |
282 (6 << R300_MS_Y5_SHIFT
) |
283 (6 << R300_MSBD1_SHIFT
)));
284 radeon_ring_write(ring
, PACKET0(R300_GA_ENHANCE
, 0));
285 radeon_ring_write(ring
, R300_GA_DEADLOCK_CNTL
| R300_GA_FASTSYNC_CNTL
);
286 radeon_ring_write(ring
, PACKET0(R300_GA_POLY_MODE
, 0));
287 radeon_ring_write(ring
,
288 R300_FRONT_PTYPE_TRIANGE
| R300_BACK_PTYPE_TRIANGE
);
289 radeon_ring_write(ring
, PACKET0(R300_GA_ROUND_MODE
, 0));
290 radeon_ring_write(ring
,
291 R300_GEOMETRY_ROUND_NEAREST
|
292 R300_COLOR_ROUND_NEAREST
);
293 radeon_ring_unlock_commit(rdev
, ring
);
296 static void r300_errata(struct radeon_device
*rdev
)
298 rdev
->pll_errata
= 0;
300 if (rdev
->family
== CHIP_R300
&&
301 (RREG32(RADEON_CONFIG_CNTL
) & RADEON_CFG_ATI_REV_ID_MASK
) == RADEON_CFG_ATI_REV_A11
) {
302 rdev
->pll_errata
|= CHIP_ERRATA_R300_CG
;
306 int r300_mc_wait_for_idle(struct radeon_device
*rdev
)
311 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
313 tmp
= RREG32(RADEON_MC_STATUS
);
314 if (tmp
& R300_MC_IDLE
) {
322 static void r300_gpu_init(struct radeon_device
*rdev
)
324 uint32_t gb_tile_config
, tmp
;
326 if ((rdev
->family
== CHIP_R300
&& rdev
->pdev
->device
!= 0x4144) ||
327 (rdev
->family
== CHIP_R350
&& rdev
->pdev
->device
!= 0x4148)) {
329 rdev
->num_gb_pipes
= 2;
331 /* rv350,rv370,rv380,r300 AD, r350 AH */
332 rdev
->num_gb_pipes
= 1;
334 rdev
->num_z_pipes
= 1;
335 gb_tile_config
= (R300_ENABLE_TILING
| R300_TILE_SIZE_16
);
336 switch (rdev
->num_gb_pipes
) {
338 gb_tile_config
|= R300_PIPE_COUNT_R300
;
341 gb_tile_config
|= R300_PIPE_COUNT_R420_3P
;
344 gb_tile_config
|= R300_PIPE_COUNT_R420
;
348 gb_tile_config
|= R300_PIPE_COUNT_RV350
;
351 WREG32(R300_GB_TILE_CONFIG
, gb_tile_config
);
353 if (r100_gui_wait_for_idle(rdev
)) {
354 printk(KERN_WARNING
"Failed to wait GUI idle while "
355 "programming pipes. Bad things might happen.\n");
358 tmp
= RREG32(R300_DST_PIPE_CONFIG
);
359 WREG32(R300_DST_PIPE_CONFIG
, tmp
| R300_PIPE_AUTO_CONFIG
);
361 WREG32(R300_RB2D_DSTCACHE_MODE
,
362 R300_DC_AUTOFLUSH_ENABLE
|
363 R300_DC_DC_DISABLE_IGNORE_PE
);
365 if (r100_gui_wait_for_idle(rdev
)) {
366 printk(KERN_WARNING
"Failed to wait GUI idle while "
367 "programming pipes. Bad things might happen.\n");
369 if (r300_mc_wait_for_idle(rdev
)) {
370 printk(KERN_WARNING
"Failed to wait MC idle while "
371 "programming pipes. Bad things might happen.\n");
373 DRM_INFO("radeon: %d quad pipes, %d Z pipes initialized.\n",
374 rdev
->num_gb_pipes
, rdev
->num_z_pipes
);
377 int r300_asic_reset(struct radeon_device
*rdev
)
379 struct r100_mc_save save
;
383 status
= RREG32(R_000E40_RBBM_STATUS
);
384 if (!G_000E40_GUI_ACTIVE(status
)) {
387 r100_mc_stop(rdev
, &save
);
388 status
= RREG32(R_000E40_RBBM_STATUS
);
389 dev_info(rdev
->dev
, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__
, __LINE__
, status
);
391 WREG32(RADEON_CP_CSQ_CNTL
, 0);
392 tmp
= RREG32(RADEON_CP_RB_CNTL
);
393 WREG32(RADEON_CP_RB_CNTL
, tmp
| RADEON_RB_RPTR_WR_ENA
);
394 WREG32(RADEON_CP_RB_RPTR_WR
, 0);
395 WREG32(RADEON_CP_RB_WPTR
, 0);
396 WREG32(RADEON_CP_RB_CNTL
, tmp
);
398 pci_save_state(rdev
->pdev
);
399 /* disable bus mastering */
400 r100_bm_disable(rdev
);
401 WREG32(R_0000F0_RBBM_SOFT_RESET
, S_0000F0_SOFT_RESET_VAP(1) |
402 S_0000F0_SOFT_RESET_GA(1));
403 RREG32(R_0000F0_RBBM_SOFT_RESET
);
405 WREG32(R_0000F0_RBBM_SOFT_RESET
, 0);
407 status
= RREG32(R_000E40_RBBM_STATUS
);
408 dev_info(rdev
->dev
, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__
, __LINE__
, status
);
409 /* resetting the CP seems to be problematic sometimes it end up
410 * hard locking the computer, but it's necessary for successful
411 * reset more test & playing is needed on R3XX/R4XX to find a
412 * reliable (if any solution)
414 WREG32(R_0000F0_RBBM_SOFT_RESET
, S_0000F0_SOFT_RESET_CP(1));
415 RREG32(R_0000F0_RBBM_SOFT_RESET
);
417 WREG32(R_0000F0_RBBM_SOFT_RESET
, 0);
419 status
= RREG32(R_000E40_RBBM_STATUS
);
420 dev_info(rdev
->dev
, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__
, __LINE__
, status
);
421 /* restore PCI & busmastering */
422 pci_restore_state(rdev
->pdev
);
423 r100_enable_bm(rdev
);
424 /* Check if GPU is idle */
425 if (G_000E40_GA_BUSY(status
) || G_000E40_VAP_BUSY(status
)) {
426 dev_err(rdev
->dev
, "failed to reset GPU\n");
429 dev_info(rdev
->dev
, "GPU reset succeed\n");
430 r100_mc_resume(rdev
, &save
);
435 * r300,r350,rv350,rv380 VRAM info
437 void r300_mc_init(struct radeon_device
*rdev
)
442 /* DDR for all card after R300 & IGP */
443 rdev
->mc
.vram_is_ddr
= true;
444 tmp
= RREG32(RADEON_MEM_CNTL
);
445 tmp
&= R300_MEM_NUM_CHANNELS_MASK
;
447 case 0: rdev
->mc
.vram_width
= 64; break;
448 case 1: rdev
->mc
.vram_width
= 128; break;
449 case 2: rdev
->mc
.vram_width
= 256; break;
450 default: rdev
->mc
.vram_width
= 128; break;
452 r100_vram_init_sizes(rdev
);
453 base
= rdev
->mc
.aper_base
;
454 if (rdev
->flags
& RADEON_IS_IGP
)
455 base
= (RREG32(RADEON_NB_TOM
) & 0xffff) << 16;
456 radeon_vram_location(rdev
, &rdev
->mc
, base
);
457 rdev
->mc
.gtt_base_align
= 0;
458 if (!(rdev
->flags
& RADEON_IS_AGP
))
459 radeon_gtt_location(rdev
, &rdev
->mc
);
460 radeon_update_bandwidth_info(rdev
);
463 void rv370_set_pcie_lanes(struct radeon_device
*rdev
, int lanes
)
465 uint32_t link_width_cntl
, mask
;
467 if (rdev
->flags
& RADEON_IS_IGP
)
470 if (!(rdev
->flags
& RADEON_IS_PCIE
))
473 /* FIXME wait for idle */
477 mask
= RADEON_PCIE_LC_LINK_WIDTH_X0
;
480 mask
= RADEON_PCIE_LC_LINK_WIDTH_X1
;
483 mask
= RADEON_PCIE_LC_LINK_WIDTH_X2
;
486 mask
= RADEON_PCIE_LC_LINK_WIDTH_X4
;
489 mask
= RADEON_PCIE_LC_LINK_WIDTH_X8
;
492 mask
= RADEON_PCIE_LC_LINK_WIDTH_X12
;
496 mask
= RADEON_PCIE_LC_LINK_WIDTH_X16
;
500 link_width_cntl
= RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL
);
502 if ((link_width_cntl
& RADEON_PCIE_LC_LINK_WIDTH_RD_MASK
) ==
503 (mask
<< RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT
))
506 link_width_cntl
&= ~(RADEON_PCIE_LC_LINK_WIDTH_MASK
|
507 RADEON_PCIE_LC_RECONFIG_NOW
|
508 RADEON_PCIE_LC_RECONFIG_LATER
|
509 RADEON_PCIE_LC_SHORT_RECONFIG_EN
);
510 link_width_cntl
|= mask
;
511 WREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL
, link_width_cntl
);
512 WREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL
, (link_width_cntl
|
513 RADEON_PCIE_LC_RECONFIG_NOW
));
515 /* wait for lane set to complete */
516 link_width_cntl
= RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL
);
517 while (link_width_cntl
== 0xffffffff)
518 link_width_cntl
= RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL
);
522 int rv370_get_pcie_lanes(struct radeon_device
*rdev
)
526 if (rdev
->flags
& RADEON_IS_IGP
)
529 if (!(rdev
->flags
& RADEON_IS_PCIE
))
532 /* FIXME wait for idle */
534 link_width_cntl
= RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL
);
536 switch ((link_width_cntl
& RADEON_PCIE_LC_LINK_WIDTH_RD_MASK
) >> RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT
) {
537 case RADEON_PCIE_LC_LINK_WIDTH_X0
:
539 case RADEON_PCIE_LC_LINK_WIDTH_X1
:
541 case RADEON_PCIE_LC_LINK_WIDTH_X2
:
543 case RADEON_PCIE_LC_LINK_WIDTH_X4
:
545 case RADEON_PCIE_LC_LINK_WIDTH_X8
:
547 case RADEON_PCIE_LC_LINK_WIDTH_X16
:
553 #if defined(CONFIG_DEBUG_FS)
554 static int rv370_debugfs_pcie_gart_info(struct seq_file
*m
, void *data
)
556 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
557 struct drm_device
*dev
= node
->minor
->dev
;
558 struct radeon_device
*rdev
= dev
->dev_private
;
561 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL
);
562 seq_printf(m
, "PCIE_TX_GART_CNTL 0x%08x\n", tmp
);
563 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_BASE
);
564 seq_printf(m
, "PCIE_TX_GART_BASE 0x%08x\n", tmp
);
565 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_START_LO
);
566 seq_printf(m
, "PCIE_TX_GART_START_LO 0x%08x\n", tmp
);
567 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_START_HI
);
568 seq_printf(m
, "PCIE_TX_GART_START_HI 0x%08x\n", tmp
);
569 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_END_LO
);
570 seq_printf(m
, "PCIE_TX_GART_END_LO 0x%08x\n", tmp
);
571 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_END_HI
);
572 seq_printf(m
, "PCIE_TX_GART_END_HI 0x%08x\n", tmp
);
573 tmp
= RREG32_PCIE(RADEON_PCIE_TX_GART_ERROR
);
574 seq_printf(m
, "PCIE_TX_GART_ERROR 0x%08x\n", tmp
);
578 static struct drm_info_list rv370_pcie_gart_info_list
[] = {
579 {"rv370_pcie_gart_info", rv370_debugfs_pcie_gart_info
, 0, NULL
},
583 static int rv370_debugfs_pcie_gart_info_init(struct radeon_device
*rdev
)
585 #if defined(CONFIG_DEBUG_FS)
586 return radeon_debugfs_add_files(rdev
, rv370_pcie_gart_info_list
, 1);
592 static int r300_packet0_check(struct radeon_cs_parser
*p
,
593 struct radeon_cs_packet
*pkt
,
594 unsigned idx
, unsigned reg
)
596 struct radeon_cs_reloc
*reloc
;
597 struct r100_cs_track
*track
;
598 volatile uint32_t *ib
;
599 uint32_t tmp
, tile_flags
= 0;
605 track
= (struct r100_cs_track
*)p
->track
;
606 idx_value
= radeon_get_ib_value(p
, idx
);
609 case AVIVO_D1MODE_VLINE_START_END
:
610 case RADEON_CRTC_GUI_TRIG_VLINE
:
611 r
= r100_cs_packet_parse_vline(p
);
613 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
615 radeon_cs_dump_packet(p
, pkt
);
619 case RADEON_DST_PITCH_OFFSET
:
620 case RADEON_SRC_PITCH_OFFSET
:
621 r
= r100_reloc_pitch_offset(p
, pkt
, idx
, reg
);
625 case R300_RB3D_COLOROFFSET0
:
626 case R300_RB3D_COLOROFFSET1
:
627 case R300_RB3D_COLOROFFSET2
:
628 case R300_RB3D_COLOROFFSET3
:
629 i
= (reg
- R300_RB3D_COLOROFFSET0
) >> 2;
630 r
= radeon_cs_packet_next_reloc(p
, &reloc
, 0);
632 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
634 radeon_cs_dump_packet(p
, pkt
);
637 track
->cb
[i
].robj
= reloc
->robj
;
638 track
->cb
[i
].offset
= idx_value
;
639 track
->cb_dirty
= true;
640 ib
[idx
] = idx_value
+ ((u32
)reloc
->gpu_offset
);
642 case R300_ZB_DEPTHOFFSET
:
643 r
= radeon_cs_packet_next_reloc(p
, &reloc
, 0);
645 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
647 radeon_cs_dump_packet(p
, pkt
);
650 track
->zb
.robj
= reloc
->robj
;
651 track
->zb
.offset
= idx_value
;
652 track
->zb_dirty
= true;
653 ib
[idx
] = idx_value
+ ((u32
)reloc
->gpu_offset
);
655 case R300_TX_OFFSET_0
:
656 case R300_TX_OFFSET_0
+4:
657 case R300_TX_OFFSET_0
+8:
658 case R300_TX_OFFSET_0
+12:
659 case R300_TX_OFFSET_0
+16:
660 case R300_TX_OFFSET_0
+20:
661 case R300_TX_OFFSET_0
+24:
662 case R300_TX_OFFSET_0
+28:
663 case R300_TX_OFFSET_0
+32:
664 case R300_TX_OFFSET_0
+36:
665 case R300_TX_OFFSET_0
+40:
666 case R300_TX_OFFSET_0
+44:
667 case R300_TX_OFFSET_0
+48:
668 case R300_TX_OFFSET_0
+52:
669 case R300_TX_OFFSET_0
+56:
670 case R300_TX_OFFSET_0
+60:
671 i
= (reg
- R300_TX_OFFSET_0
) >> 2;
672 r
= radeon_cs_packet_next_reloc(p
, &reloc
, 0);
674 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
676 radeon_cs_dump_packet(p
, pkt
);
680 if (p
->cs_flags
& RADEON_CS_KEEP_TILING_FLAGS
) {
681 ib
[idx
] = (idx_value
& 31) | /* keep the 1st 5 bits */
682 ((idx_value
& ~31) + (u32
)reloc
->gpu_offset
);
684 if (reloc
->tiling_flags
& RADEON_TILING_MACRO
)
685 tile_flags
|= R300_TXO_MACRO_TILE
;
686 if (reloc
->tiling_flags
& RADEON_TILING_MICRO
)
687 tile_flags
|= R300_TXO_MICRO_TILE
;
688 else if (reloc
->tiling_flags
& RADEON_TILING_MICRO_SQUARE
)
689 tile_flags
|= R300_TXO_MICRO_TILE_SQUARE
;
691 tmp
= idx_value
+ ((u32
)reloc
->gpu_offset
);
695 track
->textures
[i
].robj
= reloc
->robj
;
696 track
->tex_dirty
= true;
698 /* Tracked registers */
701 track
->vap_vf_cntl
= idx_value
;
705 track
->vtx_size
= idx_value
& 0x7F;
708 /* VAP_VF_MAX_VTX_INDX */
709 track
->max_indx
= idx_value
& 0x00FFFFFFUL
;
712 /* VAP_ALT_NUM_VERTICES - only valid on r500 */
713 if (p
->rdev
->family
< CHIP_RV515
)
715 track
->vap_alt_nverts
= idx_value
& 0xFFFFFF;
719 track
->maxy
= ((idx_value
>> 13) & 0x1FFF) + 1;
720 if (p
->rdev
->family
< CHIP_RV515
) {
723 track
->cb_dirty
= true;
724 track
->zb_dirty
= true;
728 if ((idx_value
& (1 << 10)) && /* CMASK_ENABLE */
729 p
->rdev
->cmask_filp
!= p
->filp
) {
730 DRM_ERROR("Invalid RB3D_CCTL: Cannot enable CMASK.\n");
733 track
->num_cb
= ((idx_value
>> 5) & 0x3) + 1;
734 track
->cb_dirty
= true;
740 /* RB3D_COLORPITCH0 */
741 /* RB3D_COLORPITCH1 */
742 /* RB3D_COLORPITCH2 */
743 /* RB3D_COLORPITCH3 */
744 if (!(p
->cs_flags
& RADEON_CS_KEEP_TILING_FLAGS
)) {
745 r
= radeon_cs_packet_next_reloc(p
, &reloc
, 0);
747 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
749 radeon_cs_dump_packet(p
, pkt
);
753 if (reloc
->tiling_flags
& RADEON_TILING_MACRO
)
754 tile_flags
|= R300_COLOR_TILE_ENABLE
;
755 if (reloc
->tiling_flags
& RADEON_TILING_MICRO
)
756 tile_flags
|= R300_COLOR_MICROTILE_ENABLE
;
757 else if (reloc
->tiling_flags
& RADEON_TILING_MICRO_SQUARE
)
758 tile_flags
|= R300_COLOR_MICROTILE_SQUARE_ENABLE
;
760 tmp
= idx_value
& ~(0x7 << 16);
764 i
= (reg
- 0x4E38) >> 2;
765 track
->cb
[i
].pitch
= idx_value
& 0x3FFE;
766 switch (((idx_value
>> 21) & 0xF)) {
770 track
->cb
[i
].cpp
= 1;
776 track
->cb
[i
].cpp
= 2;
779 if (p
->rdev
->family
< CHIP_RV515
) {
780 DRM_ERROR("Invalid color buffer format (%d)!\n",
781 ((idx_value
>> 21) & 0xF));
786 track
->cb
[i
].cpp
= 4;
789 track
->cb
[i
].cpp
= 8;
792 track
->cb
[i
].cpp
= 16;
795 DRM_ERROR("Invalid color buffer format (%d) !\n",
796 ((idx_value
>> 21) & 0xF));
799 track
->cb_dirty
= true;
804 track
->z_enabled
= true;
806 track
->z_enabled
= false;
808 track
->zb_dirty
= true;
812 switch ((idx_value
& 0xF)) {
821 DRM_ERROR("Invalid z buffer format (%d) !\n",
825 track
->zb_dirty
= true;
829 if (!(p
->cs_flags
& RADEON_CS_KEEP_TILING_FLAGS
)) {
830 r
= radeon_cs_packet_next_reloc(p
, &reloc
, 0);
832 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
834 radeon_cs_dump_packet(p
, pkt
);
838 if (reloc
->tiling_flags
& RADEON_TILING_MACRO
)
839 tile_flags
|= R300_DEPTHMACROTILE_ENABLE
;
840 if (reloc
->tiling_flags
& RADEON_TILING_MICRO
)
841 tile_flags
|= R300_DEPTHMICROTILE_TILED
;
842 else if (reloc
->tiling_flags
& RADEON_TILING_MICRO_SQUARE
)
843 tile_flags
|= R300_DEPTHMICROTILE_TILED_SQUARE
;
845 tmp
= idx_value
& ~(0x7 << 16);
849 track
->zb
.pitch
= idx_value
& 0x3FFC;
850 track
->zb_dirty
= true;
854 for (i
= 0; i
< 16; i
++) {
857 enabled
= !!(idx_value
& (1 << i
));
858 track
->textures
[i
].enabled
= enabled
;
860 track
->tex_dirty
= true;
878 /* TX_FORMAT1_[0-15] */
879 i
= (reg
- 0x44C0) >> 2;
880 tmp
= (idx_value
>> 25) & 0x3;
881 track
->textures
[i
].tex_coord_type
= tmp
;
882 switch ((idx_value
& 0x1F)) {
883 case R300_TX_FORMAT_X8
:
884 case R300_TX_FORMAT_Y4X4
:
885 case R300_TX_FORMAT_Z3Y3X2
:
886 track
->textures
[i
].cpp
= 1;
887 track
->textures
[i
].compress_format
= R100_TRACK_COMP_NONE
;
889 case R300_TX_FORMAT_X16
:
890 case R300_TX_FORMAT_FL_I16
:
891 case R300_TX_FORMAT_Y8X8
:
892 case R300_TX_FORMAT_Z5Y6X5
:
893 case R300_TX_FORMAT_Z6Y5X5
:
894 case R300_TX_FORMAT_W4Z4Y4X4
:
895 case R300_TX_FORMAT_W1Z5Y5X5
:
896 case R300_TX_FORMAT_D3DMFT_CxV8U8
:
897 case R300_TX_FORMAT_B8G8_B8G8
:
898 case R300_TX_FORMAT_G8R8_G8B8
:
899 track
->textures
[i
].cpp
= 2;
900 track
->textures
[i
].compress_format
= R100_TRACK_COMP_NONE
;
902 case R300_TX_FORMAT_Y16X16
:
903 case R300_TX_FORMAT_FL_I16A16
:
904 case R300_TX_FORMAT_Z11Y11X10
:
905 case R300_TX_FORMAT_Z10Y11X11
:
906 case R300_TX_FORMAT_W8Z8Y8X8
:
907 case R300_TX_FORMAT_W2Z10Y10X10
:
909 case R300_TX_FORMAT_FL_I32
:
911 track
->textures
[i
].cpp
= 4;
912 track
->textures
[i
].compress_format
= R100_TRACK_COMP_NONE
;
914 case R300_TX_FORMAT_W16Z16Y16X16
:
915 case R300_TX_FORMAT_FL_R16G16B16A16
:
916 case R300_TX_FORMAT_FL_I32A32
:
917 track
->textures
[i
].cpp
= 8;
918 track
->textures
[i
].compress_format
= R100_TRACK_COMP_NONE
;
920 case R300_TX_FORMAT_FL_R32G32B32A32
:
921 track
->textures
[i
].cpp
= 16;
922 track
->textures
[i
].compress_format
= R100_TRACK_COMP_NONE
;
924 case R300_TX_FORMAT_DXT1
:
925 track
->textures
[i
].cpp
= 1;
926 track
->textures
[i
].compress_format
= R100_TRACK_COMP_DXT1
;
928 case R300_TX_FORMAT_ATI2N
:
929 if (p
->rdev
->family
< CHIP_R420
) {
930 DRM_ERROR("Invalid texture format %u\n",
934 /* The same rules apply as for DXT3/5. */
936 case R300_TX_FORMAT_DXT3
:
937 case R300_TX_FORMAT_DXT5
:
938 track
->textures
[i
].cpp
= 1;
939 track
->textures
[i
].compress_format
= R100_TRACK_COMP_DXT35
;
942 DRM_ERROR("Invalid texture format %u\n",
946 track
->tex_dirty
= true;
964 /* TX_FILTER0_[0-15] */
965 i
= (reg
- 0x4400) >> 2;
966 tmp
= idx_value
& 0x7;
967 if (tmp
== 2 || tmp
== 4 || tmp
== 6) {
968 track
->textures
[i
].roundup_w
= false;
970 tmp
= (idx_value
>> 3) & 0x7;
971 if (tmp
== 2 || tmp
== 4 || tmp
== 6) {
972 track
->textures
[i
].roundup_h
= false;
974 track
->tex_dirty
= true;
992 /* TX_FORMAT2_[0-15] */
993 i
= (reg
- 0x4500) >> 2;
994 tmp
= idx_value
& 0x3FFF;
995 track
->textures
[i
].pitch
= tmp
+ 1;
996 if (p
->rdev
->family
>= CHIP_RV515
) {
997 tmp
= ((idx_value
>> 15) & 1) << 11;
998 track
->textures
[i
].width_11
= tmp
;
999 tmp
= ((idx_value
>> 16) & 1) << 11;
1000 track
->textures
[i
].height_11
= tmp
;
1003 if (idx_value
& (1 << 14)) {
1004 /* The same rules apply as for DXT1. */
1005 track
->textures
[i
].compress_format
=
1006 R100_TRACK_COMP_DXT1
;
1008 } else if (idx_value
& (1 << 14)) {
1009 DRM_ERROR("Forbidden bit TXFORMAT_MSB\n");
1012 track
->tex_dirty
= true;
1030 /* TX_FORMAT0_[0-15] */
1031 i
= (reg
- 0x4480) >> 2;
1032 tmp
= idx_value
& 0x7FF;
1033 track
->textures
[i
].width
= tmp
+ 1;
1034 tmp
= (idx_value
>> 11) & 0x7FF;
1035 track
->textures
[i
].height
= tmp
+ 1;
1036 tmp
= (idx_value
>> 26) & 0xF;
1037 track
->textures
[i
].num_levels
= tmp
;
1038 tmp
= idx_value
& (1 << 31);
1039 track
->textures
[i
].use_pitch
= !!tmp
;
1040 tmp
= (idx_value
>> 22) & 0xF;
1041 track
->textures
[i
].txdepth
= tmp
;
1042 track
->tex_dirty
= true;
1044 case R300_ZB_ZPASS_ADDR
:
1045 r
= radeon_cs_packet_next_reloc(p
, &reloc
, 0);
1047 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1049 radeon_cs_dump_packet(p
, pkt
);
1052 ib
[idx
] = idx_value
+ ((u32
)reloc
->gpu_offset
);
1055 /* RB3D_COLOR_CHANNEL_MASK */
1056 track
->color_channel_mask
= idx_value
;
1057 track
->cb_dirty
= true;
1061 /* r300c emits this register - we need to disable hyperz for it
1062 * without complaining */
1063 if (p
->rdev
->hyperz_filp
!= p
->filp
) {
1064 if (idx_value
& 0x1)
1065 ib
[idx
] = idx_value
& ~1;
1070 track
->zb_cb_clear
= !!(idx_value
& (1 << 5));
1071 track
->cb_dirty
= true;
1072 track
->zb_dirty
= true;
1073 if (p
->rdev
->hyperz_filp
!= p
->filp
) {
1074 if (idx_value
& (R300_HIZ_ENABLE
|
1075 R300_RD_COMP_ENABLE
|
1076 R300_WR_COMP_ENABLE
|
1077 R300_FAST_FILL_ENABLE
))
1082 /* RB3D_BLENDCNTL */
1083 track
->blend_read_enable
= !!(idx_value
& (1 << 2));
1084 track
->cb_dirty
= true;
1086 case R300_RB3D_AARESOLVE_OFFSET
:
1087 r
= radeon_cs_packet_next_reloc(p
, &reloc
, 0);
1089 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1091 radeon_cs_dump_packet(p
, pkt
);
1094 track
->aa
.robj
= reloc
->robj
;
1095 track
->aa
.offset
= idx_value
;
1096 track
->aa_dirty
= true;
1097 ib
[idx
] = idx_value
+ ((u32
)reloc
->gpu_offset
);
1099 case R300_RB3D_AARESOLVE_PITCH
:
1100 track
->aa
.pitch
= idx_value
& 0x3FFE;
1101 track
->aa_dirty
= true;
1103 case R300_RB3D_AARESOLVE_CTL
:
1104 track
->aaresolve
= idx_value
& 0x1;
1105 track
->aa_dirty
= true;
1107 case 0x4f30: /* ZB_MASK_OFFSET */
1108 case 0x4f34: /* ZB_ZMASK_PITCH */
1109 case 0x4f44: /* ZB_HIZ_OFFSET */
1110 case 0x4f54: /* ZB_HIZ_PITCH */
1111 if (idx_value
&& (p
->rdev
->hyperz_filp
!= p
->filp
))
1115 if (idx_value
&& (p
->rdev
->hyperz_filp
!= p
->filp
))
1117 /* GB_Z_PEQ_CONFIG */
1118 if (p
->rdev
->family
>= CHIP_RV350
)
1123 /* valid register only on RV530 */
1124 if (p
->rdev
->family
== CHIP_RV530
)
1126 /* fallthrough do not move */
1132 printk(KERN_ERR
"Forbidden register 0x%04X in cs at %d (val=%08x)\n",
1133 reg
, idx
, idx_value
);
1137 static int r300_packet3_check(struct radeon_cs_parser
*p
,
1138 struct radeon_cs_packet
*pkt
)
1140 struct radeon_cs_reloc
*reloc
;
1141 struct r100_cs_track
*track
;
1142 volatile uint32_t *ib
;
1148 track
= (struct r100_cs_track
*)p
->track
;
1149 switch(pkt
->opcode
) {
1150 case PACKET3_3D_LOAD_VBPNTR
:
1151 r
= r100_packet3_load_vbpntr(p
, pkt
, idx
);
1155 case PACKET3_INDX_BUFFER
:
1156 r
= radeon_cs_packet_next_reloc(p
, &reloc
, 0);
1158 DRM_ERROR("No reloc for packet3 %d\n", pkt
->opcode
);
1159 radeon_cs_dump_packet(p
, pkt
);
1162 ib
[idx
+1] = radeon_get_ib_value(p
, idx
+ 1) + ((u32
)reloc
->gpu_offset
);
1163 r
= r100_cs_track_check_pkt3_indx_buffer(p
, pkt
, reloc
->robj
);
1169 case PACKET3_3D_DRAW_IMMD
:
1170 /* Number of dwords is vtx_size * (num_vertices - 1)
1171 * PRIM_WALK must be equal to 3 vertex data in embedded
1173 if (((radeon_get_ib_value(p
, idx
+ 1) >> 4) & 0x3) != 3) {
1174 DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n");
1177 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
+ 1);
1178 track
->immd_dwords
= pkt
->count
- 1;
1179 r
= r100_cs_track_check(p
->rdev
, track
);
1184 case PACKET3_3D_DRAW_IMMD_2
:
1185 /* Number of dwords is vtx_size * (num_vertices - 1)
1186 * PRIM_WALK must be equal to 3 vertex data in embedded
1188 if (((radeon_get_ib_value(p
, idx
) >> 4) & 0x3) != 3) {
1189 DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n");
1192 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
);
1193 track
->immd_dwords
= pkt
->count
;
1194 r
= r100_cs_track_check(p
->rdev
, track
);
1199 case PACKET3_3D_DRAW_VBUF
:
1200 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
+ 1);
1201 r
= r100_cs_track_check(p
->rdev
, track
);
1206 case PACKET3_3D_DRAW_VBUF_2
:
1207 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
);
1208 r
= r100_cs_track_check(p
->rdev
, track
);
1213 case PACKET3_3D_DRAW_INDX
:
1214 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
+ 1);
1215 r
= r100_cs_track_check(p
->rdev
, track
);
1220 case PACKET3_3D_DRAW_INDX_2
:
1221 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
);
1222 r
= r100_cs_track_check(p
->rdev
, track
);
1227 case PACKET3_3D_CLEAR_HIZ
:
1228 case PACKET3_3D_CLEAR_ZMASK
:
1229 if (p
->rdev
->hyperz_filp
!= p
->filp
)
1232 case PACKET3_3D_CLEAR_CMASK
:
1233 if (p
->rdev
->cmask_filp
!= p
->filp
)
1239 DRM_ERROR("Packet3 opcode %x not supported\n", pkt
->opcode
);
1245 int r300_cs_parse(struct radeon_cs_parser
*p
)
1247 struct radeon_cs_packet pkt
;
1248 struct r100_cs_track
*track
;
1251 track
= kzalloc(sizeof(*track
), GFP_KERNEL
);
1254 r100_cs_track_clear(p
->rdev
, track
);
1257 r
= radeon_cs_packet_parse(p
, &pkt
, p
->idx
);
1261 p
->idx
+= pkt
.count
+ 2;
1263 case RADEON_PACKET_TYPE0
:
1264 r
= r100_cs_parse_packet0(p
, &pkt
,
1265 p
->rdev
->config
.r300
.reg_safe_bm
,
1266 p
->rdev
->config
.r300
.reg_safe_bm_size
,
1267 &r300_packet0_check
);
1269 case RADEON_PACKET_TYPE2
:
1271 case RADEON_PACKET_TYPE3
:
1272 r
= r300_packet3_check(p
, &pkt
);
1275 DRM_ERROR("Unknown packet type %d !\n", pkt
.type
);
1281 } while (p
->idx
< p
->chunks
[p
->chunk_ib_idx
].length_dw
);
1285 void r300_set_reg_safe(struct radeon_device
*rdev
)
1287 rdev
->config
.r300
.reg_safe_bm
= r300_reg_safe_bm
;
1288 rdev
->config
.r300
.reg_safe_bm_size
= ARRAY_SIZE(r300_reg_safe_bm
);
1291 void r300_mc_program(struct radeon_device
*rdev
)
1293 struct r100_mc_save save
;
1296 r
= r100_debugfs_mc_info_init(rdev
);
1298 dev_err(rdev
->dev
, "Failed to create r100_mc debugfs file.\n");
1301 /* Stops all mc clients */
1302 r100_mc_stop(rdev
, &save
);
1303 if (rdev
->flags
& RADEON_IS_AGP
) {
1304 WREG32(R_00014C_MC_AGP_LOCATION
,
1305 S_00014C_MC_AGP_START(rdev
->mc
.gtt_start
>> 16) |
1306 S_00014C_MC_AGP_TOP(rdev
->mc
.gtt_end
>> 16));
1307 WREG32(R_000170_AGP_BASE
, lower_32_bits(rdev
->mc
.agp_base
));
1308 WREG32(R_00015C_AGP_BASE_2
,
1309 upper_32_bits(rdev
->mc
.agp_base
) & 0xff);
1311 WREG32(R_00014C_MC_AGP_LOCATION
, 0x0FFFFFFF);
1312 WREG32(R_000170_AGP_BASE
, 0);
1313 WREG32(R_00015C_AGP_BASE_2
, 0);
1315 /* Wait for mc idle */
1316 if (r300_mc_wait_for_idle(rdev
))
1317 DRM_INFO("Failed to wait MC idle before programming MC.\n");
1318 /* Program MC, should be a 32bits limited address space */
1319 WREG32(R_000148_MC_FB_LOCATION
,
1320 S_000148_MC_FB_START(rdev
->mc
.vram_start
>> 16) |
1321 S_000148_MC_FB_TOP(rdev
->mc
.vram_end
>> 16));
1322 r100_mc_resume(rdev
, &save
);
1325 void r300_clock_startup(struct radeon_device
*rdev
)
1329 if (radeon_dynclks
!= -1 && radeon_dynclks
)
1330 radeon_legacy_set_clock_gating(rdev
, 1);
1331 /* We need to force on some of the block */
1332 tmp
= RREG32_PLL(R_00000D_SCLK_CNTL
);
1333 tmp
|= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1);
1334 if ((rdev
->family
== CHIP_RV350
) || (rdev
->family
== CHIP_RV380
))
1335 tmp
|= S_00000D_FORCE_VAP(1);
1336 WREG32_PLL(R_00000D_SCLK_CNTL
, tmp
);
1339 static int r300_startup(struct radeon_device
*rdev
)
1343 /* set common regs */
1344 r100_set_common_regs(rdev
);
1346 r300_mc_program(rdev
);
1348 r300_clock_startup(rdev
);
1349 /* Initialize GPU configuration (# pipes, ...) */
1350 r300_gpu_init(rdev
);
1351 /* Initialize GART (initialize after TTM so we can allocate
1352 * memory through TTM but finalize after TTM) */
1353 if (rdev
->flags
& RADEON_IS_PCIE
) {
1354 r
= rv370_pcie_gart_enable(rdev
);
1359 if (rdev
->family
== CHIP_R300
||
1360 rdev
->family
== CHIP_R350
||
1361 rdev
->family
== CHIP_RV350
)
1362 r100_enable_bm(rdev
);
1364 if (rdev
->flags
& RADEON_IS_PCI
) {
1365 r
= r100_pci_gart_enable(rdev
);
1370 /* allocate wb buffer */
1371 r
= radeon_wb_init(rdev
);
1375 r
= radeon_fence_driver_start_ring(rdev
, RADEON_RING_TYPE_GFX_INDEX
);
1377 dev_err(rdev
->dev
, "failed initializing CP fences (%d).\n", r
);
1382 if (!rdev
->irq
.installed
) {
1383 r
= radeon_irq_kms_init(rdev
);
1389 rdev
->config
.r300
.hdp_cntl
= RREG32(RADEON_HOST_PATH_CNTL
);
1390 /* 1M ring buffer */
1391 r
= r100_cp_init(rdev
, 1024 * 1024);
1393 dev_err(rdev
->dev
, "failed initializing CP (%d).\n", r
);
1397 r
= radeon_ib_pool_init(rdev
);
1399 dev_err(rdev
->dev
, "IB initialization failed (%d).\n", r
);
1406 int r300_resume(struct radeon_device
*rdev
)
1410 /* Make sur GART are not working */
1411 if (rdev
->flags
& RADEON_IS_PCIE
)
1412 rv370_pcie_gart_disable(rdev
);
1413 if (rdev
->flags
& RADEON_IS_PCI
)
1414 r100_pci_gart_disable(rdev
);
1415 /* Resume clock before doing reset */
1416 r300_clock_startup(rdev
);
1417 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
1418 if (radeon_asic_reset(rdev
)) {
1419 dev_warn(rdev
->dev
, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
1420 RREG32(R_000E40_RBBM_STATUS
),
1421 RREG32(R_0007C0_CP_STAT
));
1424 radeon_combios_asic_init(rdev
->ddev
);
1425 /* Resume clock after posting */
1426 r300_clock_startup(rdev
);
1427 /* Initialize surface registers */
1428 radeon_surface_init(rdev
);
1430 rdev
->accel_working
= true;
1431 r
= r300_startup(rdev
);
1433 rdev
->accel_working
= false;
1438 int r300_suspend(struct radeon_device
*rdev
)
1440 radeon_pm_suspend(rdev
);
1441 r100_cp_disable(rdev
);
1442 radeon_wb_disable(rdev
);
1443 r100_irq_disable(rdev
);
1444 if (rdev
->flags
& RADEON_IS_PCIE
)
1445 rv370_pcie_gart_disable(rdev
);
1446 if (rdev
->flags
& RADEON_IS_PCI
)
1447 r100_pci_gart_disable(rdev
);
1451 void r300_fini(struct radeon_device
*rdev
)
1453 radeon_pm_fini(rdev
);
1455 radeon_wb_fini(rdev
);
1456 radeon_ib_pool_fini(rdev
);
1457 radeon_gem_fini(rdev
);
1458 if (rdev
->flags
& RADEON_IS_PCIE
)
1459 rv370_pcie_gart_fini(rdev
);
1460 if (rdev
->flags
& RADEON_IS_PCI
)
1461 r100_pci_gart_fini(rdev
);
1462 radeon_agp_fini(rdev
);
1463 radeon_irq_kms_fini(rdev
);
1464 radeon_fence_driver_fini(rdev
);
1465 radeon_bo_fini(rdev
);
1466 radeon_atombios_fini(rdev
);
1471 int r300_init(struct radeon_device
*rdev
)
1476 r100_vga_render_disable(rdev
);
1477 /* Initialize scratch registers */
1478 radeon_scratch_init(rdev
);
1479 /* Initialize surface registers */
1480 radeon_surface_init(rdev
);
1481 /* TODO: disable VGA need to use VGA request */
1482 /* restore some register to sane defaults */
1483 r100_restore_sanity(rdev
);
1485 if (!radeon_get_bios(rdev
)) {
1486 if (ASIC_IS_AVIVO(rdev
))
1489 if (rdev
->is_atom_bios
) {
1490 dev_err(rdev
->dev
, "Expecting combios for RS400/RS480 GPU\n");
1493 r
= radeon_combios_init(rdev
);
1497 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
1498 if (radeon_asic_reset(rdev
)) {
1500 "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
1501 RREG32(R_000E40_RBBM_STATUS
),
1502 RREG32(R_0007C0_CP_STAT
));
1504 /* check if cards are posted or not */
1505 if (radeon_boot_test_post_card(rdev
) == false)
1507 /* Set asic errata */
1509 /* Initialize clocks */
1510 radeon_get_clock_info(rdev
->ddev
);
1511 /* initialize AGP */
1512 if (rdev
->flags
& RADEON_IS_AGP
) {
1513 r
= radeon_agp_init(rdev
);
1515 radeon_agp_disable(rdev
);
1518 /* initialize memory controller */
1521 r
= radeon_fence_driver_init(rdev
);
1524 /* Memory manager */
1525 r
= radeon_bo_init(rdev
);
1528 if (rdev
->flags
& RADEON_IS_PCIE
) {
1529 r
= rv370_pcie_gart_init(rdev
);
1533 if (rdev
->flags
& RADEON_IS_PCI
) {
1534 r
= r100_pci_gart_init(rdev
);
1538 r300_set_reg_safe(rdev
);
1540 /* Initialize power management */
1541 radeon_pm_init(rdev
);
1543 rdev
->accel_working
= true;
1544 r
= r300_startup(rdev
);
1546 /* Something went wrong with the accel init, so stop accel */
1547 dev_err(rdev
->dev
, "Disabling GPU acceleration\n");
1549 radeon_wb_fini(rdev
);
1550 radeon_ib_pool_fini(rdev
);
1551 radeon_irq_kms_fini(rdev
);
1552 if (rdev
->flags
& RADEON_IS_PCIE
)
1553 rv370_pcie_gart_fini(rdev
);
1554 if (rdev
->flags
& RADEON_IS_PCI
)
1555 r100_pci_gart_fini(rdev
);
1556 radeon_agp_fini(rdev
);
1557 rdev
->accel_working
= false;