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_drm.h"
32 #include "radeon_reg.h"
39 #include <linux/firmware.h>
40 #include <linux/platform_device.h>
42 #include "r100_reg_safe.h"
43 #include "rn50_reg_safe.h"
46 #define FIRMWARE_R100 "radeon/R100_cp.bin"
47 #define FIRMWARE_R200 "radeon/R200_cp.bin"
48 #define FIRMWARE_R300 "radeon/R300_cp.bin"
49 #define FIRMWARE_R420 "radeon/R420_cp.bin"
50 #define FIRMWARE_RS690 "radeon/RS690_cp.bin"
51 #define FIRMWARE_RS600 "radeon/RS600_cp.bin"
52 #define FIRMWARE_R520 "radeon/R520_cp.bin"
54 MODULE_FIRMWARE(FIRMWARE_R100
);
55 MODULE_FIRMWARE(FIRMWARE_R200
);
56 MODULE_FIRMWARE(FIRMWARE_R300
);
57 MODULE_FIRMWARE(FIRMWARE_R420
);
58 MODULE_FIRMWARE(FIRMWARE_RS690
);
59 MODULE_FIRMWARE(FIRMWARE_RS600
);
60 MODULE_FIRMWARE(FIRMWARE_R520
);
62 #include "r100_track.h"
64 /* This files gather functions specifics to:
65 * r100,rv100,rs100,rv200,rs200,r200,rv250,rs300,rv280
68 /* hpd for digital panel detect/disconnect */
69 bool r100_hpd_sense(struct radeon_device
*rdev
, enum radeon_hpd_id hpd
)
71 bool connected
= false;
75 if (RREG32(RADEON_FP_GEN_CNTL
) & RADEON_FP_DETECT_SENSE
)
79 if (RREG32(RADEON_FP2_GEN_CNTL
) & RADEON_FP2_DETECT_SENSE
)
88 void r100_hpd_set_polarity(struct radeon_device
*rdev
,
89 enum radeon_hpd_id hpd
)
92 bool connected
= r100_hpd_sense(rdev
, hpd
);
96 tmp
= RREG32(RADEON_FP_GEN_CNTL
);
98 tmp
&= ~RADEON_FP_DETECT_INT_POL
;
100 tmp
|= RADEON_FP_DETECT_INT_POL
;
101 WREG32(RADEON_FP_GEN_CNTL
, tmp
);
104 tmp
= RREG32(RADEON_FP2_GEN_CNTL
);
106 tmp
&= ~RADEON_FP2_DETECT_INT_POL
;
108 tmp
|= RADEON_FP2_DETECT_INT_POL
;
109 WREG32(RADEON_FP2_GEN_CNTL
, tmp
);
116 void r100_hpd_init(struct radeon_device
*rdev
)
118 struct drm_device
*dev
= rdev
->ddev
;
119 struct drm_connector
*connector
;
121 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
122 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
123 switch (radeon_connector
->hpd
.hpd
) {
125 rdev
->irq
.hpd
[0] = true;
128 rdev
->irq
.hpd
[1] = true;
134 if (rdev
->irq
.installed
)
138 void r100_hpd_fini(struct radeon_device
*rdev
)
140 struct drm_device
*dev
= rdev
->ddev
;
141 struct drm_connector
*connector
;
143 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
144 struct radeon_connector
*radeon_connector
= to_radeon_connector(connector
);
145 switch (radeon_connector
->hpd
.hpd
) {
147 rdev
->irq
.hpd
[0] = false;
150 rdev
->irq
.hpd
[1] = false;
161 void r100_pci_gart_tlb_flush(struct radeon_device
*rdev
)
163 /* TODO: can we do somethings here ? */
164 /* It seems hw only cache one entry so we should discard this
165 * entry otherwise if first GPU GART read hit this entry it
166 * could end up in wrong address. */
169 int r100_pci_gart_init(struct radeon_device
*rdev
)
173 if (rdev
->gart
.table
.ram
.ptr
) {
174 WARN(1, "R100 PCI GART already initialized.\n");
177 /* Initialize common gart structure */
178 r
= radeon_gart_init(rdev
);
181 rdev
->gart
.table_size
= rdev
->gart
.num_gpu_pages
* 4;
182 rdev
->asic
->gart_tlb_flush
= &r100_pci_gart_tlb_flush
;
183 rdev
->asic
->gart_set_page
= &r100_pci_gart_set_page
;
184 return radeon_gart_table_ram_alloc(rdev
);
187 /* required on r1xx, r2xx, r300, r(v)350, r420/r481, rs400/rs480 */
188 void r100_enable_bm(struct radeon_device
*rdev
)
191 /* Enable bus mastering */
192 tmp
= RREG32(RADEON_BUS_CNTL
) & ~RADEON_BUS_MASTER_DIS
;
193 WREG32(RADEON_BUS_CNTL
, tmp
);
196 int r100_pci_gart_enable(struct radeon_device
*rdev
)
200 /* discard memory request outside of configured range */
201 tmp
= RREG32(RADEON_AIC_CNTL
) | RADEON_DIS_OUT_OF_PCI_GART_ACCESS
;
202 WREG32(RADEON_AIC_CNTL
, tmp
);
203 /* set address range for PCI address translate */
204 WREG32(RADEON_AIC_LO_ADDR
, rdev
->mc
.gtt_location
);
205 tmp
= rdev
->mc
.gtt_location
+ rdev
->mc
.gtt_size
- 1;
206 WREG32(RADEON_AIC_HI_ADDR
, tmp
);
207 /* set PCI GART page-table base address */
208 WREG32(RADEON_AIC_PT_BASE
, rdev
->gart
.table_addr
);
209 tmp
= RREG32(RADEON_AIC_CNTL
) | RADEON_PCIGART_TRANSLATE_EN
;
210 WREG32(RADEON_AIC_CNTL
, tmp
);
211 r100_pci_gart_tlb_flush(rdev
);
212 rdev
->gart
.ready
= true;
216 void r100_pci_gart_disable(struct radeon_device
*rdev
)
220 /* discard memory request outside of configured range */
221 tmp
= RREG32(RADEON_AIC_CNTL
) | RADEON_DIS_OUT_OF_PCI_GART_ACCESS
;
222 WREG32(RADEON_AIC_CNTL
, tmp
& ~RADEON_PCIGART_TRANSLATE_EN
);
223 WREG32(RADEON_AIC_LO_ADDR
, 0);
224 WREG32(RADEON_AIC_HI_ADDR
, 0);
227 int r100_pci_gart_set_page(struct radeon_device
*rdev
, int i
, uint64_t addr
)
229 if (i
< 0 || i
> rdev
->gart
.num_gpu_pages
) {
232 rdev
->gart
.table
.ram
.ptr
[i
] = cpu_to_le32(lower_32_bits(addr
));
236 void r100_pci_gart_fini(struct radeon_device
*rdev
)
238 r100_pci_gart_disable(rdev
);
239 radeon_gart_table_ram_free(rdev
);
240 radeon_gart_fini(rdev
);
243 int r100_irq_set(struct radeon_device
*rdev
)
247 if (!rdev
->irq
.installed
) {
248 WARN(1, "Can't enable IRQ/MSI because no handler is installed.\n");
249 WREG32(R_000040_GEN_INT_CNTL
, 0);
252 if (rdev
->irq
.sw_int
) {
253 tmp
|= RADEON_SW_INT_ENABLE
;
255 if (rdev
->irq
.crtc_vblank_int
[0]) {
256 tmp
|= RADEON_CRTC_VBLANK_MASK
;
258 if (rdev
->irq
.crtc_vblank_int
[1]) {
259 tmp
|= RADEON_CRTC2_VBLANK_MASK
;
261 if (rdev
->irq
.hpd
[0]) {
262 tmp
|= RADEON_FP_DETECT_MASK
;
264 if (rdev
->irq
.hpd
[1]) {
265 tmp
|= RADEON_FP2_DETECT_MASK
;
267 WREG32(RADEON_GEN_INT_CNTL
, tmp
);
271 void r100_irq_disable(struct radeon_device
*rdev
)
275 WREG32(R_000040_GEN_INT_CNTL
, 0);
276 /* Wait and acknowledge irq */
278 tmp
= RREG32(R_000044_GEN_INT_STATUS
);
279 WREG32(R_000044_GEN_INT_STATUS
, tmp
);
282 static inline uint32_t r100_irq_ack(struct radeon_device
*rdev
)
284 uint32_t irqs
= RREG32(RADEON_GEN_INT_STATUS
);
285 uint32_t irq_mask
= RADEON_SW_INT_TEST
|
286 RADEON_CRTC_VBLANK_STAT
| RADEON_CRTC2_VBLANK_STAT
|
287 RADEON_FP_DETECT_STAT
| RADEON_FP2_DETECT_STAT
;
290 WREG32(RADEON_GEN_INT_STATUS
, irqs
);
292 return irqs
& irq_mask
;
295 int r100_irq_process(struct radeon_device
*rdev
)
297 uint32_t status
, msi_rearm
;
298 bool queue_hotplug
= false;
300 status
= r100_irq_ack(rdev
);
304 if (rdev
->shutdown
) {
309 if (status
& RADEON_SW_INT_TEST
) {
310 radeon_fence_process(rdev
);
312 /* Vertical blank interrupts */
313 if (status
& RADEON_CRTC_VBLANK_STAT
) {
314 drm_handle_vblank(rdev
->ddev
, 0);
316 if (status
& RADEON_CRTC2_VBLANK_STAT
) {
317 drm_handle_vblank(rdev
->ddev
, 1);
319 if (status
& RADEON_FP_DETECT_STAT
) {
320 queue_hotplug
= true;
323 if (status
& RADEON_FP2_DETECT_STAT
) {
324 queue_hotplug
= true;
327 status
= r100_irq_ack(rdev
);
330 queue_work(rdev
->wq
, &rdev
->hotplug_work
);
331 if (rdev
->msi_enabled
) {
332 switch (rdev
->family
) {
335 msi_rearm
= RREG32(RADEON_AIC_CNTL
) & ~RS400_MSI_REARM
;
336 WREG32(RADEON_AIC_CNTL
, msi_rearm
);
337 WREG32(RADEON_AIC_CNTL
, msi_rearm
| RS400_MSI_REARM
);
340 msi_rearm
= RREG32(RADEON_MSI_REARM_EN
) & ~RV370_MSI_REARM_EN
;
341 WREG32(RADEON_MSI_REARM_EN
, msi_rearm
);
342 WREG32(RADEON_MSI_REARM_EN
, msi_rearm
| RV370_MSI_REARM_EN
);
349 u32
r100_get_vblank_counter(struct radeon_device
*rdev
, int crtc
)
352 return RREG32(RADEON_CRTC_CRNT_FRAME
);
354 return RREG32(RADEON_CRTC2_CRNT_FRAME
);
357 void r100_fence_ring_emit(struct radeon_device
*rdev
,
358 struct radeon_fence
*fence
)
360 /* Who ever call radeon_fence_emit should call ring_lock and ask
361 * for enough space (today caller are ib schedule and buffer move) */
362 /* Wait until IDLE & CLEAN */
363 radeon_ring_write(rdev
, PACKET0(0x1720, 0));
364 radeon_ring_write(rdev
, (1 << 16) | (1 << 17));
365 radeon_ring_write(rdev
, PACKET0(RADEON_HOST_PATH_CNTL
, 0));
366 radeon_ring_write(rdev
, rdev
->config
.r100
.hdp_cntl
|
367 RADEON_HDP_READ_BUFFER_INVALIDATE
);
368 radeon_ring_write(rdev
, PACKET0(RADEON_HOST_PATH_CNTL
, 0));
369 radeon_ring_write(rdev
, rdev
->config
.r100
.hdp_cntl
);
370 /* Emit fence sequence & fire IRQ */
371 radeon_ring_write(rdev
, PACKET0(rdev
->fence_drv
.scratch_reg
, 0));
372 radeon_ring_write(rdev
, fence
->seq
);
373 radeon_ring_write(rdev
, PACKET0(RADEON_GEN_INT_STATUS
, 0));
374 radeon_ring_write(rdev
, RADEON_SW_INT_FIRE
);
377 int r100_wb_init(struct radeon_device
*rdev
)
381 if (rdev
->wb
.wb_obj
== NULL
) {
382 r
= radeon_bo_create(rdev
, NULL
, RADEON_GPU_PAGE_SIZE
, true,
383 RADEON_GEM_DOMAIN_GTT
,
386 dev_err(rdev
->dev
, "(%d) create WB buffer failed\n", r
);
389 r
= radeon_bo_reserve(rdev
->wb
.wb_obj
, false);
390 if (unlikely(r
!= 0))
392 r
= radeon_bo_pin(rdev
->wb
.wb_obj
, RADEON_GEM_DOMAIN_GTT
,
395 dev_err(rdev
->dev
, "(%d) pin WB buffer failed\n", r
);
396 radeon_bo_unreserve(rdev
->wb
.wb_obj
);
399 r
= radeon_bo_kmap(rdev
->wb
.wb_obj
, (void **)&rdev
->wb
.wb
);
400 radeon_bo_unreserve(rdev
->wb
.wb_obj
);
402 dev_err(rdev
->dev
, "(%d) map WB buffer failed\n", r
);
406 WREG32(R_000774_SCRATCH_ADDR
, rdev
->wb
.gpu_addr
);
407 WREG32(R_00070C_CP_RB_RPTR_ADDR
,
408 S_00070C_RB_RPTR_ADDR((rdev
->wb
.gpu_addr
+ 1024) >> 2));
409 WREG32(R_000770_SCRATCH_UMSK
, 0xff);
413 void r100_wb_disable(struct radeon_device
*rdev
)
415 WREG32(R_000770_SCRATCH_UMSK
, 0);
418 void r100_wb_fini(struct radeon_device
*rdev
)
422 r100_wb_disable(rdev
);
423 if (rdev
->wb
.wb_obj
) {
424 r
= radeon_bo_reserve(rdev
->wb
.wb_obj
, false);
425 if (unlikely(r
!= 0)) {
426 dev_err(rdev
->dev
, "(%d) can't finish WB\n", r
);
429 radeon_bo_kunmap(rdev
->wb
.wb_obj
);
430 radeon_bo_unpin(rdev
->wb
.wb_obj
);
431 radeon_bo_unreserve(rdev
->wb
.wb_obj
);
432 radeon_bo_unref(&rdev
->wb
.wb_obj
);
434 rdev
->wb
.wb_obj
= NULL
;
438 int r100_copy_blit(struct radeon_device
*rdev
,
442 struct radeon_fence
*fence
)
445 uint32_t stride_bytes
= PAGE_SIZE
;
447 uint32_t stride_pixels
;
452 /* radeon limited to 16k stride */
453 stride_bytes
&= 0x3fff;
454 /* radeon pitch is /64 */
455 pitch
= stride_bytes
/ 64;
456 stride_pixels
= stride_bytes
/ 4;
457 num_loops
= DIV_ROUND_UP(num_pages
, 8191);
459 /* Ask for enough room for blit + flush + fence */
460 ndw
= 64 + (10 * num_loops
);
461 r
= radeon_ring_lock(rdev
, ndw
);
463 DRM_ERROR("radeon: moving bo (%d) asking for %u dw.\n", r
, ndw
);
466 while (num_pages
> 0) {
467 cur_pages
= num_pages
;
468 if (cur_pages
> 8191) {
471 num_pages
-= cur_pages
;
473 /* pages are in Y direction - height
474 page width in X direction - width */
475 radeon_ring_write(rdev
, PACKET3(PACKET3_BITBLT_MULTI
, 8));
476 radeon_ring_write(rdev
,
477 RADEON_GMC_SRC_PITCH_OFFSET_CNTL
|
478 RADEON_GMC_DST_PITCH_OFFSET_CNTL
|
479 RADEON_GMC_SRC_CLIPPING
|
480 RADEON_GMC_DST_CLIPPING
|
481 RADEON_GMC_BRUSH_NONE
|
482 (RADEON_COLOR_FORMAT_ARGB8888
<< 8) |
483 RADEON_GMC_SRC_DATATYPE_COLOR
|
485 RADEON_DP_SRC_SOURCE_MEMORY
|
486 RADEON_GMC_CLR_CMP_CNTL_DIS
|
487 RADEON_GMC_WR_MSK_DIS
);
488 radeon_ring_write(rdev
, (pitch
<< 22) | (src_offset
>> 10));
489 radeon_ring_write(rdev
, (pitch
<< 22) | (dst_offset
>> 10));
490 radeon_ring_write(rdev
, (0x1fff) | (0x1fff << 16));
491 radeon_ring_write(rdev
, 0);
492 radeon_ring_write(rdev
, (0x1fff) | (0x1fff << 16));
493 radeon_ring_write(rdev
, num_pages
);
494 radeon_ring_write(rdev
, num_pages
);
495 radeon_ring_write(rdev
, cur_pages
| (stride_pixels
<< 16));
497 radeon_ring_write(rdev
, PACKET0(RADEON_DSTCACHE_CTLSTAT
, 0));
498 radeon_ring_write(rdev
, RADEON_RB2D_DC_FLUSH_ALL
);
499 radeon_ring_write(rdev
, PACKET0(RADEON_WAIT_UNTIL
, 0));
500 radeon_ring_write(rdev
,
501 RADEON_WAIT_2D_IDLECLEAN
|
502 RADEON_WAIT_HOST_IDLECLEAN
|
503 RADEON_WAIT_DMA_GUI_IDLE
);
505 r
= radeon_fence_emit(rdev
, fence
);
507 radeon_ring_unlock_commit(rdev
);
511 static int r100_cp_wait_for_idle(struct radeon_device
*rdev
)
516 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
517 tmp
= RREG32(R_000E40_RBBM_STATUS
);
518 if (!G_000E40_CP_CMDSTRM_BUSY(tmp
)) {
526 void r100_ring_start(struct radeon_device
*rdev
)
530 r
= radeon_ring_lock(rdev
, 2);
534 radeon_ring_write(rdev
, PACKET0(RADEON_ISYNC_CNTL
, 0));
535 radeon_ring_write(rdev
,
536 RADEON_ISYNC_ANY2D_IDLE3D
|
537 RADEON_ISYNC_ANY3D_IDLE2D
|
538 RADEON_ISYNC_WAIT_IDLEGUI
|
539 RADEON_ISYNC_CPSCRATCH_IDLEGUI
);
540 radeon_ring_unlock_commit(rdev
);
544 /* Load the microcode for the CP */
545 static int r100_cp_init_microcode(struct radeon_device
*rdev
)
547 struct platform_device
*pdev
;
548 const char *fw_name
= NULL
;
553 pdev
= platform_device_register_simple("radeon_cp", 0, NULL
, 0);
556 printk(KERN_ERR
"radeon_cp: Failed to register firmware\n");
559 if ((rdev
->family
== CHIP_R100
) || (rdev
->family
== CHIP_RV100
) ||
560 (rdev
->family
== CHIP_RV200
) || (rdev
->family
== CHIP_RS100
) ||
561 (rdev
->family
== CHIP_RS200
)) {
562 DRM_INFO("Loading R100 Microcode\n");
563 fw_name
= FIRMWARE_R100
;
564 } else if ((rdev
->family
== CHIP_R200
) ||
565 (rdev
->family
== CHIP_RV250
) ||
566 (rdev
->family
== CHIP_RV280
) ||
567 (rdev
->family
== CHIP_RS300
)) {
568 DRM_INFO("Loading R200 Microcode\n");
569 fw_name
= FIRMWARE_R200
;
570 } else if ((rdev
->family
== CHIP_R300
) ||
571 (rdev
->family
== CHIP_R350
) ||
572 (rdev
->family
== CHIP_RV350
) ||
573 (rdev
->family
== CHIP_RV380
) ||
574 (rdev
->family
== CHIP_RS400
) ||
575 (rdev
->family
== CHIP_RS480
)) {
576 DRM_INFO("Loading R300 Microcode\n");
577 fw_name
= FIRMWARE_R300
;
578 } else if ((rdev
->family
== CHIP_R420
) ||
579 (rdev
->family
== CHIP_R423
) ||
580 (rdev
->family
== CHIP_RV410
)) {
581 DRM_INFO("Loading R400 Microcode\n");
582 fw_name
= FIRMWARE_R420
;
583 } else if ((rdev
->family
== CHIP_RS690
) ||
584 (rdev
->family
== CHIP_RS740
)) {
585 DRM_INFO("Loading RS690/RS740 Microcode\n");
586 fw_name
= FIRMWARE_RS690
;
587 } else if (rdev
->family
== CHIP_RS600
) {
588 DRM_INFO("Loading RS600 Microcode\n");
589 fw_name
= FIRMWARE_RS600
;
590 } else if ((rdev
->family
== CHIP_RV515
) ||
591 (rdev
->family
== CHIP_R520
) ||
592 (rdev
->family
== CHIP_RV530
) ||
593 (rdev
->family
== CHIP_R580
) ||
594 (rdev
->family
== CHIP_RV560
) ||
595 (rdev
->family
== CHIP_RV570
)) {
596 DRM_INFO("Loading R500 Microcode\n");
597 fw_name
= FIRMWARE_R520
;
600 err
= request_firmware(&rdev
->me_fw
, fw_name
, &pdev
->dev
);
601 platform_device_unregister(pdev
);
603 printk(KERN_ERR
"radeon_cp: Failed to load firmware \"%s\"\n",
605 } else if (rdev
->me_fw
->size
% 8) {
607 "radeon_cp: Bogus length %zu in firmware \"%s\"\n",
608 rdev
->me_fw
->size
, fw_name
);
610 release_firmware(rdev
->me_fw
);
616 static void r100_cp_load_microcode(struct radeon_device
*rdev
)
618 const __be32
*fw_data
;
621 if (r100_gui_wait_for_idle(rdev
)) {
622 printk(KERN_WARNING
"Failed to wait GUI idle while "
623 "programming pipes. Bad things might happen.\n");
627 size
= rdev
->me_fw
->size
/ 4;
628 fw_data
= (const __be32
*)&rdev
->me_fw
->data
[0];
629 WREG32(RADEON_CP_ME_RAM_ADDR
, 0);
630 for (i
= 0; i
< size
; i
+= 2) {
631 WREG32(RADEON_CP_ME_RAM_DATAH
,
632 be32_to_cpup(&fw_data
[i
]));
633 WREG32(RADEON_CP_ME_RAM_DATAL
,
634 be32_to_cpup(&fw_data
[i
+ 1]));
639 int r100_cp_init(struct radeon_device
*rdev
, unsigned ring_size
)
644 unsigned pre_write_timer
;
645 unsigned pre_write_limit
;
646 unsigned indirect2_start
;
647 unsigned indirect1_start
;
651 if (r100_debugfs_cp_init(rdev
)) {
652 DRM_ERROR("Failed to register debugfs file for CP !\n");
655 tmp
= RREG32(RADEON_CP_CSQ_STAT
);
656 if ((tmp
& (1 << 31))) {
657 DRM_INFO("radeon: cp busy (0x%08X) resetting\n", tmp
);
658 WREG32(RADEON_CP_CSQ_MODE
, 0);
659 WREG32(RADEON_CP_CSQ_CNTL
, 0);
660 WREG32(RADEON_RBBM_SOFT_RESET
, RADEON_SOFT_RESET_CP
);
661 tmp
= RREG32(RADEON_RBBM_SOFT_RESET
);
663 WREG32(RADEON_RBBM_SOFT_RESET
, 0);
664 tmp
= RREG32(RADEON_RBBM_SOFT_RESET
);
666 tmp
= RREG32(RADEON_CP_CSQ_STAT
);
667 if ((tmp
& (1 << 31))) {
668 DRM_INFO("radeon: cp reset failed (0x%08X)\n", tmp
);
671 DRM_INFO("radeon: cp idle (0x%08X)\n", tmp
);
675 r
= r100_cp_init_microcode(rdev
);
677 DRM_ERROR("Failed to load firmware!\n");
682 /* Align ring size */
683 rb_bufsz
= drm_order(ring_size
/ 8);
684 ring_size
= (1 << (rb_bufsz
+ 1)) * 4;
685 r100_cp_load_microcode(rdev
);
686 r
= radeon_ring_init(rdev
, ring_size
);
690 /* Each time the cp read 1024 bytes (16 dword/quadword) update
691 * the rptr copy in system ram */
693 /* cp will read 128bytes at a time (4 dwords) */
695 rdev
->cp
.align_mask
= 16 - 1;
696 /* Write to CP_RB_WPTR will be delayed for pre_write_timer clocks */
697 pre_write_timer
= 64;
698 /* Force CP_RB_WPTR write if written more than one time before the
702 /* Setup the cp cache like this (cache size is 96 dwords) :
706 * So ring cache size is 16dwords (> (2 * max_fetch = 2 * 4dwords))
707 * indirect1 cache size is 64dwords (> (2 * max_fetch = 2 * 4dwords))
708 * indirect2 cache size is 16dwords (> (2 * max_fetch = 2 * 4dwords))
709 * Idea being that most of the gpu cmd will be through indirect1 buffer
710 * so it gets the bigger cache.
712 indirect2_start
= 80;
713 indirect1_start
= 16;
715 WREG32(0x718, pre_write_timer
| (pre_write_limit
<< 28));
716 tmp
= (REG_SET(RADEON_RB_BUFSZ
, rb_bufsz
) |
717 REG_SET(RADEON_RB_BLKSZ
, rb_blksz
) |
718 REG_SET(RADEON_MAX_FETCH
, max_fetch
) |
719 RADEON_RB_NO_UPDATE
);
721 tmp
|= RADEON_BUF_SWAP_32BIT
;
723 WREG32(RADEON_CP_RB_CNTL
, tmp
);
725 /* Set ring address */
726 DRM_INFO("radeon: ring at 0x%016lX\n", (unsigned long)rdev
->cp
.gpu_addr
);
727 WREG32(RADEON_CP_RB_BASE
, rdev
->cp
.gpu_addr
);
728 /* Force read & write ptr to 0 */
729 WREG32(RADEON_CP_RB_CNTL
, tmp
| RADEON_RB_RPTR_WR_ENA
);
730 WREG32(RADEON_CP_RB_RPTR_WR
, 0);
731 WREG32(RADEON_CP_RB_WPTR
, 0);
732 WREG32(RADEON_CP_RB_CNTL
, tmp
);
734 rdev
->cp
.rptr
= RREG32(RADEON_CP_RB_RPTR
);
735 rdev
->cp
.wptr
= RREG32(RADEON_CP_RB_WPTR
);
736 /* Set cp mode to bus mastering & enable cp*/
737 WREG32(RADEON_CP_CSQ_MODE
,
738 REG_SET(RADEON_INDIRECT2_START
, indirect2_start
) |
739 REG_SET(RADEON_INDIRECT1_START
, indirect1_start
));
741 WREG32(0x744, 0x00004D4D);
742 WREG32(RADEON_CP_CSQ_CNTL
, RADEON_CSQ_PRIBM_INDBM
);
743 radeon_ring_start(rdev
);
744 r
= radeon_ring_test(rdev
);
746 DRM_ERROR("radeon: cp isn't working (%d).\n", r
);
749 rdev
->cp
.ready
= true;
753 void r100_cp_fini(struct radeon_device
*rdev
)
755 if (r100_cp_wait_for_idle(rdev
)) {
756 DRM_ERROR("Wait for CP idle timeout, shutting down CP.\n");
759 r100_cp_disable(rdev
);
760 radeon_ring_fini(rdev
);
761 DRM_INFO("radeon: cp finalized\n");
764 void r100_cp_disable(struct radeon_device
*rdev
)
767 rdev
->cp
.ready
= false;
768 WREG32(RADEON_CP_CSQ_MODE
, 0);
769 WREG32(RADEON_CP_CSQ_CNTL
, 0);
770 if (r100_gui_wait_for_idle(rdev
)) {
771 printk(KERN_WARNING
"Failed to wait GUI idle while "
772 "programming pipes. Bad things might happen.\n");
776 int r100_cp_reset(struct radeon_device
*rdev
)
782 reinit_cp
= rdev
->cp
.ready
;
783 rdev
->cp
.ready
= false;
784 WREG32(RADEON_CP_CSQ_MODE
, 0);
785 WREG32(RADEON_CP_CSQ_CNTL
, 0);
786 WREG32(RADEON_RBBM_SOFT_RESET
, RADEON_SOFT_RESET_CP
);
787 (void)RREG32(RADEON_RBBM_SOFT_RESET
);
789 WREG32(RADEON_RBBM_SOFT_RESET
, 0);
790 /* Wait to prevent race in RBBM_STATUS */
792 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
793 tmp
= RREG32(RADEON_RBBM_STATUS
);
794 if (!(tmp
& (1 << 16))) {
795 DRM_INFO("CP reset succeed (RBBM_STATUS=0x%08X)\n",
798 return r100_cp_init(rdev
, rdev
->cp
.ring_size
);
804 tmp
= RREG32(RADEON_RBBM_STATUS
);
805 DRM_ERROR("Failed to reset CP (RBBM_STATUS=0x%08X)!\n", tmp
);
809 void r100_cp_commit(struct radeon_device
*rdev
)
811 WREG32(RADEON_CP_RB_WPTR
, rdev
->cp
.wptr
);
812 (void)RREG32(RADEON_CP_RB_WPTR
);
819 int r100_cs_parse_packet0(struct radeon_cs_parser
*p
,
820 struct radeon_cs_packet
*pkt
,
821 const unsigned *auth
, unsigned n
,
822 radeon_packet0_check_t check
)
831 /* Check that register fall into register range
832 * determined by the number of entry (n) in the
833 * safe register bitmap.
835 if (pkt
->one_reg_wr
) {
836 if ((reg
>> 7) > n
) {
840 if (((reg
+ (pkt
->count
<< 2)) >> 7) > n
) {
844 for (i
= 0; i
<= pkt
->count
; i
++, idx
++) {
846 m
= 1 << ((reg
>> 2) & 31);
848 r
= check(p
, pkt
, idx
, reg
);
853 if (pkt
->one_reg_wr
) {
854 if (!(auth
[j
] & m
)) {
864 void r100_cs_dump_packet(struct radeon_cs_parser
*p
,
865 struct radeon_cs_packet
*pkt
)
867 volatile uint32_t *ib
;
873 for (i
= 0; i
<= (pkt
->count
+ 1); i
++, idx
++) {
874 DRM_INFO("ib[%d]=0x%08X\n", idx
, ib
[idx
]);
879 * r100_cs_packet_parse() - parse cp packet and point ib index to next packet
880 * @parser: parser structure holding parsing context.
881 * @pkt: where to store packet informations
883 * Assume that chunk_ib_index is properly set. Will return -EINVAL
884 * if packet is bigger than remaining ib size. or if packets is unknown.
886 int r100_cs_packet_parse(struct radeon_cs_parser
*p
,
887 struct radeon_cs_packet
*pkt
,
890 struct radeon_cs_chunk
*ib_chunk
= &p
->chunks
[p
->chunk_ib_idx
];
893 if (idx
>= ib_chunk
->length_dw
) {
894 DRM_ERROR("Can not parse packet at %d after CS end %d !\n",
895 idx
, ib_chunk
->length_dw
);
898 header
= radeon_get_ib_value(p
, idx
);
900 pkt
->type
= CP_PACKET_GET_TYPE(header
);
901 pkt
->count
= CP_PACKET_GET_COUNT(header
);
904 pkt
->reg
= CP_PACKET0_GET_REG(header
);
905 pkt
->one_reg_wr
= CP_PACKET0_GET_ONE_REG_WR(header
);
908 pkt
->opcode
= CP_PACKET3_GET_OPCODE(header
);
914 DRM_ERROR("Unknown packet type %d at %d !\n", pkt
->type
, idx
);
917 if ((pkt
->count
+ 1 + pkt
->idx
) >= ib_chunk
->length_dw
) {
918 DRM_ERROR("Packet (%d:%d:%d) end after CS buffer (%d) !\n",
919 pkt
->idx
, pkt
->type
, pkt
->count
, ib_chunk
->length_dw
);
926 * r100_cs_packet_next_vline() - parse userspace VLINE packet
927 * @parser: parser structure holding parsing context.
929 * Userspace sends a special sequence for VLINE waits.
930 * PACKET0 - VLINE_START_END + value
931 * PACKET0 - WAIT_UNTIL +_value
932 * RELOC (P3) - crtc_id in reloc.
934 * This function parses this and relocates the VLINE START END
935 * and WAIT UNTIL packets to the correct crtc.
936 * It also detects a switched off crtc and nulls out the
939 int r100_cs_packet_parse_vline(struct radeon_cs_parser
*p
)
941 struct drm_mode_object
*obj
;
942 struct drm_crtc
*crtc
;
943 struct radeon_crtc
*radeon_crtc
;
944 struct radeon_cs_packet p3reloc
, waitreloc
;
947 uint32_t header
, h_idx
, reg
;
948 volatile uint32_t *ib
;
952 /* parse the wait until */
953 r
= r100_cs_packet_parse(p
, &waitreloc
, p
->idx
);
957 /* check its a wait until and only 1 count */
958 if (waitreloc
.reg
!= RADEON_WAIT_UNTIL
||
959 waitreloc
.count
!= 0) {
960 DRM_ERROR("vline wait had illegal wait until segment\n");
965 if (radeon_get_ib_value(p
, waitreloc
.idx
+ 1) != RADEON_WAIT_CRTC_VLINE
) {
966 DRM_ERROR("vline wait had illegal wait until\n");
971 /* jump over the NOP */
972 r
= r100_cs_packet_parse(p
, &p3reloc
, p
->idx
+ waitreloc
.count
+ 2);
977 p
->idx
+= waitreloc
.count
+ 2;
978 p
->idx
+= p3reloc
.count
+ 2;
980 header
= radeon_get_ib_value(p
, h_idx
);
981 crtc_id
= radeon_get_ib_value(p
, h_idx
+ 5);
982 reg
= CP_PACKET0_GET_REG(header
);
983 mutex_lock(&p
->rdev
->ddev
->mode_config
.mutex
);
984 obj
= drm_mode_object_find(p
->rdev
->ddev
, crtc_id
, DRM_MODE_OBJECT_CRTC
);
986 DRM_ERROR("cannot find crtc %d\n", crtc_id
);
990 crtc
= obj_to_crtc(obj
);
991 radeon_crtc
= to_radeon_crtc(crtc
);
992 crtc_id
= radeon_crtc
->crtc_id
;
994 if (!crtc
->enabled
) {
995 /* if the CRTC isn't enabled - we need to nop out the wait until */
996 ib
[h_idx
+ 2] = PACKET2(0);
997 ib
[h_idx
+ 3] = PACKET2(0);
998 } else if (crtc_id
== 1) {
1000 case AVIVO_D1MODE_VLINE_START_END
:
1001 header
&= ~R300_CP_PACKET0_REG_MASK
;
1002 header
|= AVIVO_D2MODE_VLINE_START_END
>> 2;
1004 case RADEON_CRTC_GUI_TRIG_VLINE
:
1005 header
&= ~R300_CP_PACKET0_REG_MASK
;
1006 header
|= RADEON_CRTC2_GUI_TRIG_VLINE
>> 2;
1009 DRM_ERROR("unknown crtc reloc\n");
1014 ib
[h_idx
+ 3] |= RADEON_ENG_DISPLAY_SELECT_CRTC1
;
1017 mutex_unlock(&p
->rdev
->ddev
->mode_config
.mutex
);
1022 * r100_cs_packet_next_reloc() - parse next packet which should be reloc packet3
1023 * @parser: parser structure holding parsing context.
1024 * @data: pointer to relocation data
1025 * @offset_start: starting offset
1026 * @offset_mask: offset mask (to align start offset on)
1027 * @reloc: reloc informations
1029 * Check next packet is relocation packet3, do bo validation and compute
1030 * GPU offset using the provided start.
1032 int r100_cs_packet_next_reloc(struct radeon_cs_parser
*p
,
1033 struct radeon_cs_reloc
**cs_reloc
)
1035 struct radeon_cs_chunk
*relocs_chunk
;
1036 struct radeon_cs_packet p3reloc
;
1040 if (p
->chunk_relocs_idx
== -1) {
1041 DRM_ERROR("No relocation chunk !\n");
1045 relocs_chunk
= &p
->chunks
[p
->chunk_relocs_idx
];
1046 r
= r100_cs_packet_parse(p
, &p3reloc
, p
->idx
);
1050 p
->idx
+= p3reloc
.count
+ 2;
1051 if (p3reloc
.type
!= PACKET_TYPE3
|| p3reloc
.opcode
!= PACKET3_NOP
) {
1052 DRM_ERROR("No packet3 for relocation for packet at %d.\n",
1054 r100_cs_dump_packet(p
, &p3reloc
);
1057 idx
= radeon_get_ib_value(p
, p3reloc
.idx
+ 1);
1058 if (idx
>= relocs_chunk
->length_dw
) {
1059 DRM_ERROR("Relocs at %d after relocations chunk end %d !\n",
1060 idx
, relocs_chunk
->length_dw
);
1061 r100_cs_dump_packet(p
, &p3reloc
);
1064 /* FIXME: we assume reloc size is 4 dwords */
1065 *cs_reloc
= p
->relocs_ptr
[(idx
/ 4)];
1069 static int r100_get_vtx_size(uint32_t vtx_fmt
)
1073 /* ordered according to bits in spec */
1074 if (vtx_fmt
& RADEON_SE_VTX_FMT_W0
)
1076 if (vtx_fmt
& RADEON_SE_VTX_FMT_FPCOLOR
)
1078 if (vtx_fmt
& RADEON_SE_VTX_FMT_FPALPHA
)
1080 if (vtx_fmt
& RADEON_SE_VTX_FMT_PKCOLOR
)
1082 if (vtx_fmt
& RADEON_SE_VTX_FMT_FPSPEC
)
1084 if (vtx_fmt
& RADEON_SE_VTX_FMT_FPFOG
)
1086 if (vtx_fmt
& RADEON_SE_VTX_FMT_PKSPEC
)
1088 if (vtx_fmt
& RADEON_SE_VTX_FMT_ST0
)
1090 if (vtx_fmt
& RADEON_SE_VTX_FMT_ST1
)
1092 if (vtx_fmt
& RADEON_SE_VTX_FMT_Q1
)
1094 if (vtx_fmt
& RADEON_SE_VTX_FMT_ST2
)
1096 if (vtx_fmt
& RADEON_SE_VTX_FMT_Q2
)
1098 if (vtx_fmt
& RADEON_SE_VTX_FMT_ST3
)
1100 if (vtx_fmt
& RADEON_SE_VTX_FMT_Q3
)
1102 if (vtx_fmt
& RADEON_SE_VTX_FMT_Q0
)
1105 if (vtx_fmt
& (0x7 << 15))
1106 vtx_size
+= (vtx_fmt
>> 15) & 0x7;
1107 if (vtx_fmt
& RADEON_SE_VTX_FMT_N0
)
1109 if (vtx_fmt
& RADEON_SE_VTX_FMT_XY1
)
1111 if (vtx_fmt
& RADEON_SE_VTX_FMT_Z1
)
1113 if (vtx_fmt
& RADEON_SE_VTX_FMT_W1
)
1115 if (vtx_fmt
& RADEON_SE_VTX_FMT_N1
)
1117 if (vtx_fmt
& RADEON_SE_VTX_FMT_Z
)
1122 static int r100_packet0_check(struct radeon_cs_parser
*p
,
1123 struct radeon_cs_packet
*pkt
,
1124 unsigned idx
, unsigned reg
)
1126 struct radeon_cs_reloc
*reloc
;
1127 struct r100_cs_track
*track
;
1128 volatile uint32_t *ib
;
1136 track
= (struct r100_cs_track
*)p
->track
;
1138 idx_value
= radeon_get_ib_value(p
, idx
);
1141 case RADEON_CRTC_GUI_TRIG_VLINE
:
1142 r
= r100_cs_packet_parse_vline(p
);
1144 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1146 r100_cs_dump_packet(p
, pkt
);
1150 /* FIXME: only allow PACKET3 blit? easier to check for out of
1152 case RADEON_DST_PITCH_OFFSET
:
1153 case RADEON_SRC_PITCH_OFFSET
:
1154 r
= r100_reloc_pitch_offset(p
, pkt
, idx
, reg
);
1158 case RADEON_RB3D_DEPTHOFFSET
:
1159 r
= r100_cs_packet_next_reloc(p
, &reloc
);
1161 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1163 r100_cs_dump_packet(p
, pkt
);
1166 track
->zb
.robj
= reloc
->robj
;
1167 track
->zb
.offset
= idx_value
;
1168 ib
[idx
] = idx_value
+ ((u32
)reloc
->lobj
.gpu_offset
);
1170 case RADEON_RB3D_COLOROFFSET
:
1171 r
= r100_cs_packet_next_reloc(p
, &reloc
);
1173 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1175 r100_cs_dump_packet(p
, pkt
);
1178 track
->cb
[0].robj
= reloc
->robj
;
1179 track
->cb
[0].offset
= idx_value
;
1180 ib
[idx
] = idx_value
+ ((u32
)reloc
->lobj
.gpu_offset
);
1182 case RADEON_PP_TXOFFSET_0
:
1183 case RADEON_PP_TXOFFSET_1
:
1184 case RADEON_PP_TXOFFSET_2
:
1185 i
= (reg
- RADEON_PP_TXOFFSET_0
) / 24;
1186 r
= r100_cs_packet_next_reloc(p
, &reloc
);
1188 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1190 r100_cs_dump_packet(p
, pkt
);
1193 ib
[idx
] = idx_value
+ ((u32
)reloc
->lobj
.gpu_offset
);
1194 track
->textures
[i
].robj
= reloc
->robj
;
1196 case RADEON_PP_CUBIC_OFFSET_T0_0
:
1197 case RADEON_PP_CUBIC_OFFSET_T0_1
:
1198 case RADEON_PP_CUBIC_OFFSET_T0_2
:
1199 case RADEON_PP_CUBIC_OFFSET_T0_3
:
1200 case RADEON_PP_CUBIC_OFFSET_T0_4
:
1201 i
= (reg
- RADEON_PP_CUBIC_OFFSET_T0_0
) / 4;
1202 r
= r100_cs_packet_next_reloc(p
, &reloc
);
1204 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1206 r100_cs_dump_packet(p
, pkt
);
1209 track
->textures
[0].cube_info
[i
].offset
= idx_value
;
1210 ib
[idx
] = idx_value
+ ((u32
)reloc
->lobj
.gpu_offset
);
1211 track
->textures
[0].cube_info
[i
].robj
= reloc
->robj
;
1213 case RADEON_PP_CUBIC_OFFSET_T1_0
:
1214 case RADEON_PP_CUBIC_OFFSET_T1_1
:
1215 case RADEON_PP_CUBIC_OFFSET_T1_2
:
1216 case RADEON_PP_CUBIC_OFFSET_T1_3
:
1217 case RADEON_PP_CUBIC_OFFSET_T1_4
:
1218 i
= (reg
- RADEON_PP_CUBIC_OFFSET_T1_0
) / 4;
1219 r
= r100_cs_packet_next_reloc(p
, &reloc
);
1221 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1223 r100_cs_dump_packet(p
, pkt
);
1226 track
->textures
[1].cube_info
[i
].offset
= idx_value
;
1227 ib
[idx
] = idx_value
+ ((u32
)reloc
->lobj
.gpu_offset
);
1228 track
->textures
[1].cube_info
[i
].robj
= reloc
->robj
;
1230 case RADEON_PP_CUBIC_OFFSET_T2_0
:
1231 case RADEON_PP_CUBIC_OFFSET_T2_1
:
1232 case RADEON_PP_CUBIC_OFFSET_T2_2
:
1233 case RADEON_PP_CUBIC_OFFSET_T2_3
:
1234 case RADEON_PP_CUBIC_OFFSET_T2_4
:
1235 i
= (reg
- RADEON_PP_CUBIC_OFFSET_T2_0
) / 4;
1236 r
= r100_cs_packet_next_reloc(p
, &reloc
);
1238 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1240 r100_cs_dump_packet(p
, pkt
);
1243 track
->textures
[2].cube_info
[i
].offset
= idx_value
;
1244 ib
[idx
] = idx_value
+ ((u32
)reloc
->lobj
.gpu_offset
);
1245 track
->textures
[2].cube_info
[i
].robj
= reloc
->robj
;
1247 case RADEON_RE_WIDTH_HEIGHT
:
1248 track
->maxy
= ((idx_value
>> 16) & 0x7FF);
1250 case RADEON_RB3D_COLORPITCH
:
1251 r
= r100_cs_packet_next_reloc(p
, &reloc
);
1253 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1255 r100_cs_dump_packet(p
, pkt
);
1259 if (reloc
->lobj
.tiling_flags
& RADEON_TILING_MACRO
)
1260 tile_flags
|= RADEON_COLOR_TILE_ENABLE
;
1261 if (reloc
->lobj
.tiling_flags
& RADEON_TILING_MICRO
)
1262 tile_flags
|= RADEON_COLOR_MICROTILE_ENABLE
;
1264 tmp
= idx_value
& ~(0x7 << 16);
1268 track
->cb
[0].pitch
= idx_value
& RADEON_COLORPITCH_MASK
;
1270 case RADEON_RB3D_DEPTHPITCH
:
1271 track
->zb
.pitch
= idx_value
& RADEON_DEPTHPITCH_MASK
;
1273 case RADEON_RB3D_CNTL
:
1274 switch ((idx_value
>> RADEON_RB3D_COLOR_FORMAT_SHIFT
) & 0x1f) {
1280 track
->cb
[0].cpp
= 1;
1285 track
->cb
[0].cpp
= 2;
1288 track
->cb
[0].cpp
= 4;
1291 DRM_ERROR("Invalid color buffer format (%d) !\n",
1292 ((idx_value
>> RADEON_RB3D_COLOR_FORMAT_SHIFT
) & 0x1f));
1295 track
->z_enabled
= !!(idx_value
& RADEON_Z_ENABLE
);
1297 case RADEON_RB3D_ZSTENCILCNTL
:
1298 switch (idx_value
& 0xf) {
1314 case RADEON_RB3D_ZPASS_ADDR
:
1315 r
= r100_cs_packet_next_reloc(p
, &reloc
);
1317 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
1319 r100_cs_dump_packet(p
, pkt
);
1322 ib
[idx
] = idx_value
+ ((u32
)reloc
->lobj
.gpu_offset
);
1324 case RADEON_PP_CNTL
:
1326 uint32_t temp
= idx_value
>> 4;
1327 for (i
= 0; i
< track
->num_texture
; i
++)
1328 track
->textures
[i
].enabled
= !!(temp
& (1 << i
));
1331 case RADEON_SE_VF_CNTL
:
1332 track
->vap_vf_cntl
= idx_value
;
1334 case RADEON_SE_VTX_FMT
:
1335 track
->vtx_size
= r100_get_vtx_size(idx_value
);
1337 case RADEON_PP_TEX_SIZE_0
:
1338 case RADEON_PP_TEX_SIZE_1
:
1339 case RADEON_PP_TEX_SIZE_2
:
1340 i
= (reg
- RADEON_PP_TEX_SIZE_0
) / 8;
1341 track
->textures
[i
].width
= (idx_value
& RADEON_TEX_USIZE_MASK
) + 1;
1342 track
->textures
[i
].height
= ((idx_value
& RADEON_TEX_VSIZE_MASK
) >> RADEON_TEX_VSIZE_SHIFT
) + 1;
1344 case RADEON_PP_TEX_PITCH_0
:
1345 case RADEON_PP_TEX_PITCH_1
:
1346 case RADEON_PP_TEX_PITCH_2
:
1347 i
= (reg
- RADEON_PP_TEX_PITCH_0
) / 8;
1348 track
->textures
[i
].pitch
= idx_value
+ 32;
1350 case RADEON_PP_TXFILTER_0
:
1351 case RADEON_PP_TXFILTER_1
:
1352 case RADEON_PP_TXFILTER_2
:
1353 i
= (reg
- RADEON_PP_TXFILTER_0
) / 24;
1354 track
->textures
[i
].num_levels
= ((idx_value
& RADEON_MAX_MIP_LEVEL_MASK
)
1355 >> RADEON_MAX_MIP_LEVEL_SHIFT
);
1356 tmp
= (idx_value
>> 23) & 0x7;
1357 if (tmp
== 2 || tmp
== 6)
1358 track
->textures
[i
].roundup_w
= false;
1359 tmp
= (idx_value
>> 27) & 0x7;
1360 if (tmp
== 2 || tmp
== 6)
1361 track
->textures
[i
].roundup_h
= false;
1363 case RADEON_PP_TXFORMAT_0
:
1364 case RADEON_PP_TXFORMAT_1
:
1365 case RADEON_PP_TXFORMAT_2
:
1366 i
= (reg
- RADEON_PP_TXFORMAT_0
) / 24;
1367 if (idx_value
& RADEON_TXFORMAT_NON_POWER2
) {
1368 track
->textures
[i
].use_pitch
= 1;
1370 track
->textures
[i
].use_pitch
= 0;
1371 track
->textures
[i
].width
= 1 << ((idx_value
>> RADEON_TXFORMAT_WIDTH_SHIFT
) & RADEON_TXFORMAT_WIDTH_MASK
);
1372 track
->textures
[i
].height
= 1 << ((idx_value
>> RADEON_TXFORMAT_HEIGHT_SHIFT
) & RADEON_TXFORMAT_HEIGHT_MASK
);
1374 if (idx_value
& RADEON_TXFORMAT_CUBIC_MAP_ENABLE
)
1375 track
->textures
[i
].tex_coord_type
= 2;
1376 switch ((idx_value
& RADEON_TXFORMAT_FORMAT_MASK
)) {
1377 case RADEON_TXFORMAT_I8
:
1378 case RADEON_TXFORMAT_RGB332
:
1379 case RADEON_TXFORMAT_Y8
:
1380 track
->textures
[i
].cpp
= 1;
1382 case RADEON_TXFORMAT_AI88
:
1383 case RADEON_TXFORMAT_ARGB1555
:
1384 case RADEON_TXFORMAT_RGB565
:
1385 case RADEON_TXFORMAT_ARGB4444
:
1386 case RADEON_TXFORMAT_VYUY422
:
1387 case RADEON_TXFORMAT_YVYU422
:
1388 case RADEON_TXFORMAT_SHADOW16
:
1389 case RADEON_TXFORMAT_LDUDV655
:
1390 case RADEON_TXFORMAT_DUDV88
:
1391 track
->textures
[i
].cpp
= 2;
1393 case RADEON_TXFORMAT_ARGB8888
:
1394 case RADEON_TXFORMAT_RGBA8888
:
1395 case RADEON_TXFORMAT_SHADOW32
:
1396 case RADEON_TXFORMAT_LDUDUV8888
:
1397 track
->textures
[i
].cpp
= 4;
1399 case RADEON_TXFORMAT_DXT1
:
1400 track
->textures
[i
].cpp
= 1;
1401 track
->textures
[i
].compress_format
= R100_TRACK_COMP_DXT1
;
1403 case RADEON_TXFORMAT_DXT23
:
1404 case RADEON_TXFORMAT_DXT45
:
1405 track
->textures
[i
].cpp
= 1;
1406 track
->textures
[i
].compress_format
= R100_TRACK_COMP_DXT35
;
1409 track
->textures
[i
].cube_info
[4].width
= 1 << ((idx_value
>> 16) & 0xf);
1410 track
->textures
[i
].cube_info
[4].height
= 1 << ((idx_value
>> 20) & 0xf);
1412 case RADEON_PP_CUBIC_FACES_0
:
1413 case RADEON_PP_CUBIC_FACES_1
:
1414 case RADEON_PP_CUBIC_FACES_2
:
1416 i
= (reg
- RADEON_PP_CUBIC_FACES_0
) / 4;
1417 for (face
= 0; face
< 4; face
++) {
1418 track
->textures
[i
].cube_info
[face
].width
= 1 << ((tmp
>> (face
* 8)) & 0xf);
1419 track
->textures
[i
].cube_info
[face
].height
= 1 << ((tmp
>> ((face
* 8) + 4)) & 0xf);
1423 printk(KERN_ERR
"Forbidden register 0x%04X in cs at %d\n",
1430 int r100_cs_track_check_pkt3_indx_buffer(struct radeon_cs_parser
*p
,
1431 struct radeon_cs_packet
*pkt
,
1432 struct radeon_bo
*robj
)
1437 value
= radeon_get_ib_value(p
, idx
+ 2);
1438 if ((value
+ 1) > radeon_bo_size(robj
)) {
1439 DRM_ERROR("[drm] Buffer too small for PACKET3 INDX_BUFFER "
1440 "(need %u have %lu) !\n",
1442 radeon_bo_size(robj
));
1448 static int r100_packet3_check(struct radeon_cs_parser
*p
,
1449 struct radeon_cs_packet
*pkt
)
1451 struct radeon_cs_reloc
*reloc
;
1452 struct r100_cs_track
*track
;
1454 volatile uint32_t *ib
;
1459 track
= (struct r100_cs_track
*)p
->track
;
1460 switch (pkt
->opcode
) {
1461 case PACKET3_3D_LOAD_VBPNTR
:
1462 r
= r100_packet3_load_vbpntr(p
, pkt
, idx
);
1466 case PACKET3_INDX_BUFFER
:
1467 r
= r100_cs_packet_next_reloc(p
, &reloc
);
1469 DRM_ERROR("No reloc for packet3 %d\n", pkt
->opcode
);
1470 r100_cs_dump_packet(p
, pkt
);
1473 ib
[idx
+1] = radeon_get_ib_value(p
, idx
+1) + ((u32
)reloc
->lobj
.gpu_offset
);
1474 r
= r100_cs_track_check_pkt3_indx_buffer(p
, pkt
, reloc
->robj
);
1480 /* 3D_RNDR_GEN_INDX_PRIM on r100/r200 */
1481 r
= r100_cs_packet_next_reloc(p
, &reloc
);
1483 DRM_ERROR("No reloc for packet3 %d\n", pkt
->opcode
);
1484 r100_cs_dump_packet(p
, pkt
);
1487 ib
[idx
] = radeon_get_ib_value(p
, idx
) + ((u32
)reloc
->lobj
.gpu_offset
);
1488 track
->num_arrays
= 1;
1489 track
->vtx_size
= r100_get_vtx_size(radeon_get_ib_value(p
, idx
+ 2));
1491 track
->arrays
[0].robj
= reloc
->robj
;
1492 track
->arrays
[0].esize
= track
->vtx_size
;
1494 track
->max_indx
= radeon_get_ib_value(p
, idx
+1);
1496 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
+3);
1497 track
->immd_dwords
= pkt
->count
- 1;
1498 r
= r100_cs_track_check(p
->rdev
, track
);
1502 case PACKET3_3D_DRAW_IMMD
:
1503 if (((radeon_get_ib_value(p
, idx
+ 1) >> 4) & 0x3) != 3) {
1504 DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n");
1507 track
->vtx_size
= r100_get_vtx_size(radeon_get_ib_value(p
, idx
+ 0));
1508 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
+ 1);
1509 track
->immd_dwords
= pkt
->count
- 1;
1510 r
= r100_cs_track_check(p
->rdev
, track
);
1514 /* triggers drawing using in-packet vertex data */
1515 case PACKET3_3D_DRAW_IMMD_2
:
1516 if (((radeon_get_ib_value(p
, idx
) >> 4) & 0x3) != 3) {
1517 DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n");
1520 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
);
1521 track
->immd_dwords
= pkt
->count
;
1522 r
= r100_cs_track_check(p
->rdev
, track
);
1526 /* triggers drawing using in-packet vertex data */
1527 case PACKET3_3D_DRAW_VBUF_2
:
1528 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
);
1529 r
= r100_cs_track_check(p
->rdev
, track
);
1533 /* triggers drawing of vertex buffers setup elsewhere */
1534 case PACKET3_3D_DRAW_INDX_2
:
1535 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
);
1536 r
= r100_cs_track_check(p
->rdev
, track
);
1540 /* triggers drawing using indices to vertex buffer */
1541 case PACKET3_3D_DRAW_VBUF
:
1542 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
+ 1);
1543 r
= r100_cs_track_check(p
->rdev
, track
);
1547 /* triggers drawing of vertex buffers setup elsewhere */
1548 case PACKET3_3D_DRAW_INDX
:
1549 track
->vap_vf_cntl
= radeon_get_ib_value(p
, idx
+ 1);
1550 r
= r100_cs_track_check(p
->rdev
, track
);
1554 /* triggers drawing using indices to vertex buffer */
1558 DRM_ERROR("Packet3 opcode %x not supported\n", pkt
->opcode
);
1564 int r100_cs_parse(struct radeon_cs_parser
*p
)
1566 struct radeon_cs_packet pkt
;
1567 struct r100_cs_track
*track
;
1570 track
= kzalloc(sizeof(*track
), GFP_KERNEL
);
1571 r100_cs_track_clear(p
->rdev
, track
);
1574 r
= r100_cs_packet_parse(p
, &pkt
, p
->idx
);
1578 p
->idx
+= pkt
.count
+ 2;
1581 if (p
->rdev
->family
>= CHIP_R200
)
1582 r
= r100_cs_parse_packet0(p
, &pkt
,
1583 p
->rdev
->config
.r100
.reg_safe_bm
,
1584 p
->rdev
->config
.r100
.reg_safe_bm_size
,
1585 &r200_packet0_check
);
1587 r
= r100_cs_parse_packet0(p
, &pkt
,
1588 p
->rdev
->config
.r100
.reg_safe_bm
,
1589 p
->rdev
->config
.r100
.reg_safe_bm_size
,
1590 &r100_packet0_check
);
1595 r
= r100_packet3_check(p
, &pkt
);
1598 DRM_ERROR("Unknown packet type %d !\n",
1605 } while (p
->idx
< p
->chunks
[p
->chunk_ib_idx
].length_dw
);
1611 * Global GPU functions
1613 void r100_errata(struct radeon_device
*rdev
)
1615 rdev
->pll_errata
= 0;
1617 if (rdev
->family
== CHIP_RV200
|| rdev
->family
== CHIP_RS200
) {
1618 rdev
->pll_errata
|= CHIP_ERRATA_PLL_DUMMYREADS
;
1621 if (rdev
->family
== CHIP_RV100
||
1622 rdev
->family
== CHIP_RS100
||
1623 rdev
->family
== CHIP_RS200
) {
1624 rdev
->pll_errata
|= CHIP_ERRATA_PLL_DELAY
;
1628 /* Wait for vertical sync on primary CRTC */
1629 void r100_gpu_wait_for_vsync(struct radeon_device
*rdev
)
1631 uint32_t crtc_gen_cntl
, tmp
;
1634 crtc_gen_cntl
= RREG32(RADEON_CRTC_GEN_CNTL
);
1635 if ((crtc_gen_cntl
& RADEON_CRTC_DISP_REQ_EN_B
) ||
1636 !(crtc_gen_cntl
& RADEON_CRTC_EN
)) {
1639 /* Clear the CRTC_VBLANK_SAVE bit */
1640 WREG32(RADEON_CRTC_STATUS
, RADEON_CRTC_VBLANK_SAVE_CLEAR
);
1641 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
1642 tmp
= RREG32(RADEON_CRTC_STATUS
);
1643 if (tmp
& RADEON_CRTC_VBLANK_SAVE
) {
1650 /* Wait for vertical sync on secondary CRTC */
1651 void r100_gpu_wait_for_vsync2(struct radeon_device
*rdev
)
1653 uint32_t crtc2_gen_cntl
, tmp
;
1656 crtc2_gen_cntl
= RREG32(RADEON_CRTC2_GEN_CNTL
);
1657 if ((crtc2_gen_cntl
& RADEON_CRTC2_DISP_REQ_EN_B
) ||
1658 !(crtc2_gen_cntl
& RADEON_CRTC2_EN
))
1661 /* Clear the CRTC_VBLANK_SAVE bit */
1662 WREG32(RADEON_CRTC2_STATUS
, RADEON_CRTC2_VBLANK_SAVE_CLEAR
);
1663 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
1664 tmp
= RREG32(RADEON_CRTC2_STATUS
);
1665 if (tmp
& RADEON_CRTC2_VBLANK_SAVE
) {
1672 int r100_rbbm_fifo_wait_for_entry(struct radeon_device
*rdev
, unsigned n
)
1677 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
1678 tmp
= RREG32(RADEON_RBBM_STATUS
) & RADEON_RBBM_FIFOCNT_MASK
;
1687 int r100_gui_wait_for_idle(struct radeon_device
*rdev
)
1692 if (r100_rbbm_fifo_wait_for_entry(rdev
, 64)) {
1693 printk(KERN_WARNING
"radeon: wait for empty RBBM fifo failed !"
1694 " Bad things might happen.\n");
1696 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
1697 tmp
= RREG32(RADEON_RBBM_STATUS
);
1698 if (!(tmp
& (1 << 31))) {
1706 int r100_mc_wait_for_idle(struct radeon_device
*rdev
)
1711 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
1712 /* read MC_STATUS */
1713 tmp
= RREG32(0x0150);
1714 if (tmp
& (1 << 2)) {
1722 void r100_gpu_init(struct radeon_device
*rdev
)
1724 /* TODO: anythings to do here ? pipes ? */
1725 r100_hdp_reset(rdev
);
1728 void r100_hdp_reset(struct radeon_device
*rdev
)
1732 tmp
= RREG32(RADEON_HOST_PATH_CNTL
) & RADEON_HDP_APER_CNTL
;
1734 WREG32(RADEON_HOST_PATH_CNTL
, tmp
| RADEON_HDP_SOFT_RESET
| RADEON_HDP_READ_BUFFER_INVALIDATE
);
1735 (void)RREG32(RADEON_HOST_PATH_CNTL
);
1737 WREG32(RADEON_RBBM_SOFT_RESET
, 0);
1738 WREG32(RADEON_HOST_PATH_CNTL
, tmp
);
1739 (void)RREG32(RADEON_HOST_PATH_CNTL
);
1742 int r100_rb2d_reset(struct radeon_device
*rdev
)
1747 WREG32(RADEON_RBBM_SOFT_RESET
, RADEON_SOFT_RESET_E2
);
1748 (void)RREG32(RADEON_RBBM_SOFT_RESET
);
1750 WREG32(RADEON_RBBM_SOFT_RESET
, 0);
1751 /* Wait to prevent race in RBBM_STATUS */
1753 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
1754 tmp
= RREG32(RADEON_RBBM_STATUS
);
1755 if (!(tmp
& (1 << 26))) {
1756 DRM_INFO("RB2D reset succeed (RBBM_STATUS=0x%08X)\n",
1762 tmp
= RREG32(RADEON_RBBM_STATUS
);
1763 DRM_ERROR("Failed to reset RB2D (RBBM_STATUS=0x%08X)!\n", tmp
);
1767 int r100_gpu_reset(struct radeon_device
*rdev
)
1771 /* reset order likely matter */
1772 status
= RREG32(RADEON_RBBM_STATUS
);
1774 r100_hdp_reset(rdev
);
1776 if (status
& ((1 << 17) | (1 << 18) | (1 << 27))) {
1777 r100_rb2d_reset(rdev
);
1779 /* TODO: reset 3D engine */
1781 status
= RREG32(RADEON_RBBM_STATUS
);
1782 if (status
& (1 << 16)) {
1783 r100_cp_reset(rdev
);
1785 /* Check if GPU is idle */
1786 status
= RREG32(RADEON_RBBM_STATUS
);
1787 if (status
& (1 << 31)) {
1788 DRM_ERROR("Failed to reset GPU (RBBM_STATUS=0x%08X)\n", status
);
1791 DRM_INFO("GPU reset succeed (RBBM_STATUS=0x%08X)\n", status
);
1795 void r100_set_common_regs(struct radeon_device
*rdev
)
1797 /* set these so they don't interfere with anything */
1798 WREG32(RADEON_OV0_SCALE_CNTL
, 0);
1799 WREG32(RADEON_SUBPIC_CNTL
, 0);
1800 WREG32(RADEON_VIPH_CONTROL
, 0);
1801 WREG32(RADEON_I2C_CNTL_1
, 0);
1802 WREG32(RADEON_DVI_I2C_CNTL_1
, 0);
1803 WREG32(RADEON_CAP0_TRIG_CNTL
, 0);
1804 WREG32(RADEON_CAP1_TRIG_CNTL
, 0);
1810 static void r100_vram_get_type(struct radeon_device
*rdev
)
1814 rdev
->mc
.vram_is_ddr
= false;
1815 if (rdev
->flags
& RADEON_IS_IGP
)
1816 rdev
->mc
.vram_is_ddr
= true;
1817 else if (RREG32(RADEON_MEM_SDRAM_MODE_REG
) & RADEON_MEM_CFG_TYPE_DDR
)
1818 rdev
->mc
.vram_is_ddr
= true;
1819 if ((rdev
->family
== CHIP_RV100
) ||
1820 (rdev
->family
== CHIP_RS100
) ||
1821 (rdev
->family
== CHIP_RS200
)) {
1822 tmp
= RREG32(RADEON_MEM_CNTL
);
1823 if (tmp
& RV100_HALF_MODE
) {
1824 rdev
->mc
.vram_width
= 32;
1826 rdev
->mc
.vram_width
= 64;
1828 if (rdev
->flags
& RADEON_SINGLE_CRTC
) {
1829 rdev
->mc
.vram_width
/= 4;
1830 rdev
->mc
.vram_is_ddr
= true;
1832 } else if (rdev
->family
<= CHIP_RV280
) {
1833 tmp
= RREG32(RADEON_MEM_CNTL
);
1834 if (tmp
& RADEON_MEM_NUM_CHANNELS_MASK
) {
1835 rdev
->mc
.vram_width
= 128;
1837 rdev
->mc
.vram_width
= 64;
1841 rdev
->mc
.vram_width
= 128;
1845 static u32
r100_get_accessible_vram(struct radeon_device
*rdev
)
1850 aper_size
= RREG32(RADEON_CONFIG_APER_SIZE
);
1852 /* Set HDP_APER_CNTL only on cards that are known not to be broken,
1853 * that is has the 2nd generation multifunction PCI interface
1855 if (rdev
->family
== CHIP_RV280
||
1856 rdev
->family
>= CHIP_RV350
) {
1857 WREG32_P(RADEON_HOST_PATH_CNTL
, RADEON_HDP_APER_CNTL
,
1858 ~RADEON_HDP_APER_CNTL
);
1859 DRM_INFO("Generation 2 PCI interface, using max accessible memory\n");
1860 return aper_size
* 2;
1863 /* Older cards have all sorts of funny issues to deal with. First
1864 * check if it's a multifunction card by reading the PCI config
1865 * header type... Limit those to one aperture size
1867 pci_read_config_byte(rdev
->pdev
, 0xe, &byte
);
1869 DRM_INFO("Generation 1 PCI interface in multifunction mode\n");
1870 DRM_INFO("Limiting VRAM to one aperture\n");
1874 /* Single function older card. We read HDP_APER_CNTL to see how the BIOS
1875 * have set it up. We don't write this as it's broken on some ASICs but
1876 * we expect the BIOS to have done the right thing (might be too optimistic...)
1878 if (RREG32(RADEON_HOST_PATH_CNTL
) & RADEON_HDP_APER_CNTL
)
1879 return aper_size
* 2;
1883 void r100_vram_init_sizes(struct radeon_device
*rdev
)
1885 u64 config_aper_size
;
1888 config_aper_size
= RREG32(RADEON_CONFIG_APER_SIZE
);
1890 if (rdev
->flags
& RADEON_IS_IGP
) {
1892 /* read NB_TOM to get the amount of ram stolen for the GPU */
1893 tom
= RREG32(RADEON_NB_TOM
);
1894 rdev
->mc
.real_vram_size
= (((tom
>> 16) - (tom
& 0xffff) + 1) << 16);
1895 /* for IGPs we need to keep VRAM where it was put by the BIOS */
1896 rdev
->mc
.vram_location
= (tom
& 0xffff) << 16;
1897 WREG32(RADEON_CONFIG_MEMSIZE
, rdev
->mc
.real_vram_size
);
1898 rdev
->mc
.mc_vram_size
= rdev
->mc
.real_vram_size
;
1900 rdev
->mc
.real_vram_size
= RREG32(RADEON_CONFIG_MEMSIZE
);
1901 /* Some production boards of m6 will report 0
1904 if (rdev
->mc
.real_vram_size
== 0) {
1905 rdev
->mc
.real_vram_size
= 8192 * 1024;
1906 WREG32(RADEON_CONFIG_MEMSIZE
, rdev
->mc
.real_vram_size
);
1908 /* let driver place VRAM */
1909 rdev
->mc
.vram_location
= 0xFFFFFFFFUL
;
1910 /* Fix for RN50, M6, M7 with 8/16/32(??) MBs of VRAM -
1911 * Novell bug 204882 + along with lots of ubuntu ones */
1912 if (config_aper_size
> rdev
->mc
.real_vram_size
)
1913 rdev
->mc
.mc_vram_size
= config_aper_size
;
1915 rdev
->mc
.mc_vram_size
= rdev
->mc
.real_vram_size
;
1918 /* work out accessible VRAM */
1919 accessible
= r100_get_accessible_vram(rdev
);
1921 rdev
->mc
.aper_base
= drm_get_resource_start(rdev
->ddev
, 0);
1922 rdev
->mc
.aper_size
= drm_get_resource_len(rdev
->ddev
, 0);
1924 if (accessible
> rdev
->mc
.aper_size
)
1925 accessible
= rdev
->mc
.aper_size
;
1927 if (rdev
->mc
.mc_vram_size
> rdev
->mc
.aper_size
)
1928 rdev
->mc
.mc_vram_size
= rdev
->mc
.aper_size
;
1930 if (rdev
->mc
.real_vram_size
> rdev
->mc
.aper_size
)
1931 rdev
->mc
.real_vram_size
= rdev
->mc
.aper_size
;
1934 void r100_vga_set_state(struct radeon_device
*rdev
, bool state
)
1938 temp
= RREG32(RADEON_CONFIG_CNTL
);
1939 if (state
== false) {
1945 WREG32(RADEON_CONFIG_CNTL
, temp
);
1948 void r100_vram_info(struct radeon_device
*rdev
)
1950 r100_vram_get_type(rdev
);
1952 r100_vram_init_sizes(rdev
);
1957 * Indirect registers accessor
1959 void r100_pll_errata_after_index(struct radeon_device
*rdev
)
1961 if (!(rdev
->pll_errata
& CHIP_ERRATA_PLL_DUMMYREADS
)) {
1964 (void)RREG32(RADEON_CLOCK_CNTL_DATA
);
1965 (void)RREG32(RADEON_CRTC_GEN_CNTL
);
1968 static void r100_pll_errata_after_data(struct radeon_device
*rdev
)
1970 /* This workarounds is necessary on RV100, RS100 and RS200 chips
1971 * or the chip could hang on a subsequent access
1973 if (rdev
->pll_errata
& CHIP_ERRATA_PLL_DELAY
) {
1977 /* This function is required to workaround a hardware bug in some (all?)
1978 * revisions of the R300. This workaround should be called after every
1979 * CLOCK_CNTL_INDEX register access. If not, register reads afterward
1980 * may not be correct.
1982 if (rdev
->pll_errata
& CHIP_ERRATA_R300_CG
) {
1985 save
= RREG32(RADEON_CLOCK_CNTL_INDEX
);
1986 tmp
= save
& ~(0x3f | RADEON_PLL_WR_EN
);
1987 WREG32(RADEON_CLOCK_CNTL_INDEX
, tmp
);
1988 tmp
= RREG32(RADEON_CLOCK_CNTL_DATA
);
1989 WREG32(RADEON_CLOCK_CNTL_INDEX
, save
);
1993 uint32_t r100_pll_rreg(struct radeon_device
*rdev
, uint32_t reg
)
1997 WREG8(RADEON_CLOCK_CNTL_INDEX
, reg
& 0x3f);
1998 r100_pll_errata_after_index(rdev
);
1999 data
= RREG32(RADEON_CLOCK_CNTL_DATA
);
2000 r100_pll_errata_after_data(rdev
);
2004 void r100_pll_wreg(struct radeon_device
*rdev
, uint32_t reg
, uint32_t v
)
2006 WREG8(RADEON_CLOCK_CNTL_INDEX
, ((reg
& 0x3f) | RADEON_PLL_WR_EN
));
2007 r100_pll_errata_after_index(rdev
);
2008 WREG32(RADEON_CLOCK_CNTL_DATA
, v
);
2009 r100_pll_errata_after_data(rdev
);
2012 void r100_set_safe_registers(struct radeon_device
*rdev
)
2014 if (ASIC_IS_RN50(rdev
)) {
2015 rdev
->config
.r100
.reg_safe_bm
= rn50_reg_safe_bm
;
2016 rdev
->config
.r100
.reg_safe_bm_size
= ARRAY_SIZE(rn50_reg_safe_bm
);
2017 } else if (rdev
->family
< CHIP_R200
) {
2018 rdev
->config
.r100
.reg_safe_bm
= r100_reg_safe_bm
;
2019 rdev
->config
.r100
.reg_safe_bm_size
= ARRAY_SIZE(r100_reg_safe_bm
);
2021 r200_set_safe_registers(rdev
);
2028 #if defined(CONFIG_DEBUG_FS)
2029 static int r100_debugfs_rbbm_info(struct seq_file
*m
, void *data
)
2031 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
2032 struct drm_device
*dev
= node
->minor
->dev
;
2033 struct radeon_device
*rdev
= dev
->dev_private
;
2034 uint32_t reg
, value
;
2037 seq_printf(m
, "RBBM_STATUS 0x%08x\n", RREG32(RADEON_RBBM_STATUS
));
2038 seq_printf(m
, "RBBM_CMDFIFO_STAT 0x%08x\n", RREG32(0xE7C));
2039 seq_printf(m
, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT
));
2040 for (i
= 0; i
< 64; i
++) {
2041 WREG32(RADEON_RBBM_CMDFIFO_ADDR
, i
| 0x100);
2042 reg
= (RREG32(RADEON_RBBM_CMDFIFO_DATA
) - 1) >> 2;
2043 WREG32(RADEON_RBBM_CMDFIFO_ADDR
, i
);
2044 value
= RREG32(RADEON_RBBM_CMDFIFO_DATA
);
2045 seq_printf(m
, "[0x%03X] 0x%04X=0x%08X\n", i
, reg
, value
);
2050 static int r100_debugfs_cp_ring_info(struct seq_file
*m
, void *data
)
2052 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
2053 struct drm_device
*dev
= node
->minor
->dev
;
2054 struct radeon_device
*rdev
= dev
->dev_private
;
2056 unsigned count
, i
, j
;
2058 radeon_ring_free_size(rdev
);
2059 rdp
= RREG32(RADEON_CP_RB_RPTR
);
2060 wdp
= RREG32(RADEON_CP_RB_WPTR
);
2061 count
= (rdp
+ rdev
->cp
.ring_size
- wdp
) & rdev
->cp
.ptr_mask
;
2062 seq_printf(m
, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT
));
2063 seq_printf(m
, "CP_RB_WPTR 0x%08x\n", wdp
);
2064 seq_printf(m
, "CP_RB_RPTR 0x%08x\n", rdp
);
2065 seq_printf(m
, "%u free dwords in ring\n", rdev
->cp
.ring_free_dw
);
2066 seq_printf(m
, "%u dwords in ring\n", count
);
2067 for (j
= 0; j
<= count
; j
++) {
2068 i
= (rdp
+ j
) & rdev
->cp
.ptr_mask
;
2069 seq_printf(m
, "r[%04d]=0x%08x\n", i
, rdev
->cp
.ring
[i
]);
2075 static int r100_debugfs_cp_csq_fifo(struct seq_file
*m
, void *data
)
2077 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
2078 struct drm_device
*dev
= node
->minor
->dev
;
2079 struct radeon_device
*rdev
= dev
->dev_private
;
2080 uint32_t csq_stat
, csq2_stat
, tmp
;
2081 unsigned r_rptr
, r_wptr
, ib1_rptr
, ib1_wptr
, ib2_rptr
, ib2_wptr
;
2084 seq_printf(m
, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT
));
2085 seq_printf(m
, "CP_CSQ_MODE 0x%08x\n", RREG32(RADEON_CP_CSQ_MODE
));
2086 csq_stat
= RREG32(RADEON_CP_CSQ_STAT
);
2087 csq2_stat
= RREG32(RADEON_CP_CSQ2_STAT
);
2088 r_rptr
= (csq_stat
>> 0) & 0x3ff;
2089 r_wptr
= (csq_stat
>> 10) & 0x3ff;
2090 ib1_rptr
= (csq_stat
>> 20) & 0x3ff;
2091 ib1_wptr
= (csq2_stat
>> 0) & 0x3ff;
2092 ib2_rptr
= (csq2_stat
>> 10) & 0x3ff;
2093 ib2_wptr
= (csq2_stat
>> 20) & 0x3ff;
2094 seq_printf(m
, "CP_CSQ_STAT 0x%08x\n", csq_stat
);
2095 seq_printf(m
, "CP_CSQ2_STAT 0x%08x\n", csq2_stat
);
2096 seq_printf(m
, "Ring rptr %u\n", r_rptr
);
2097 seq_printf(m
, "Ring wptr %u\n", r_wptr
);
2098 seq_printf(m
, "Indirect1 rptr %u\n", ib1_rptr
);
2099 seq_printf(m
, "Indirect1 wptr %u\n", ib1_wptr
);
2100 seq_printf(m
, "Indirect2 rptr %u\n", ib2_rptr
);
2101 seq_printf(m
, "Indirect2 wptr %u\n", ib2_wptr
);
2102 /* FIXME: 0, 128, 640 depends on fifo setup see cp_init_kms
2103 * 128 = indirect1_start * 8 & 640 = indirect2_start * 8 */
2104 seq_printf(m
, "Ring fifo:\n");
2105 for (i
= 0; i
< 256; i
++) {
2106 WREG32(RADEON_CP_CSQ_ADDR
, i
<< 2);
2107 tmp
= RREG32(RADEON_CP_CSQ_DATA
);
2108 seq_printf(m
, "rfifo[%04d]=0x%08X\n", i
, tmp
);
2110 seq_printf(m
, "Indirect1 fifo:\n");
2111 for (i
= 256; i
<= 512; i
++) {
2112 WREG32(RADEON_CP_CSQ_ADDR
, i
<< 2);
2113 tmp
= RREG32(RADEON_CP_CSQ_DATA
);
2114 seq_printf(m
, "ib1fifo[%04d]=0x%08X\n", i
, tmp
);
2116 seq_printf(m
, "Indirect2 fifo:\n");
2117 for (i
= 640; i
< ib1_wptr
; i
++) {
2118 WREG32(RADEON_CP_CSQ_ADDR
, i
<< 2);
2119 tmp
= RREG32(RADEON_CP_CSQ_DATA
);
2120 seq_printf(m
, "ib2fifo[%04d]=0x%08X\n", i
, tmp
);
2125 static int r100_debugfs_mc_info(struct seq_file
*m
, void *data
)
2127 struct drm_info_node
*node
= (struct drm_info_node
*) m
->private;
2128 struct drm_device
*dev
= node
->minor
->dev
;
2129 struct radeon_device
*rdev
= dev
->dev_private
;
2132 tmp
= RREG32(RADEON_CONFIG_MEMSIZE
);
2133 seq_printf(m
, "CONFIG_MEMSIZE 0x%08x\n", tmp
);
2134 tmp
= RREG32(RADEON_MC_FB_LOCATION
);
2135 seq_printf(m
, "MC_FB_LOCATION 0x%08x\n", tmp
);
2136 tmp
= RREG32(RADEON_BUS_CNTL
);
2137 seq_printf(m
, "BUS_CNTL 0x%08x\n", tmp
);
2138 tmp
= RREG32(RADEON_MC_AGP_LOCATION
);
2139 seq_printf(m
, "MC_AGP_LOCATION 0x%08x\n", tmp
);
2140 tmp
= RREG32(RADEON_AGP_BASE
);
2141 seq_printf(m
, "AGP_BASE 0x%08x\n", tmp
);
2142 tmp
= RREG32(RADEON_HOST_PATH_CNTL
);
2143 seq_printf(m
, "HOST_PATH_CNTL 0x%08x\n", tmp
);
2144 tmp
= RREG32(0x01D0);
2145 seq_printf(m
, "AIC_CTRL 0x%08x\n", tmp
);
2146 tmp
= RREG32(RADEON_AIC_LO_ADDR
);
2147 seq_printf(m
, "AIC_LO_ADDR 0x%08x\n", tmp
);
2148 tmp
= RREG32(RADEON_AIC_HI_ADDR
);
2149 seq_printf(m
, "AIC_HI_ADDR 0x%08x\n", tmp
);
2150 tmp
= RREG32(0x01E4);
2151 seq_printf(m
, "AIC_TLB_ADDR 0x%08x\n", tmp
);
2155 static struct drm_info_list r100_debugfs_rbbm_list
[] = {
2156 {"r100_rbbm_info", r100_debugfs_rbbm_info
, 0, NULL
},
2159 static struct drm_info_list r100_debugfs_cp_list
[] = {
2160 {"r100_cp_ring_info", r100_debugfs_cp_ring_info
, 0, NULL
},
2161 {"r100_cp_csq_fifo", r100_debugfs_cp_csq_fifo
, 0, NULL
},
2164 static struct drm_info_list r100_debugfs_mc_info_list
[] = {
2165 {"r100_mc_info", r100_debugfs_mc_info
, 0, NULL
},
2169 int r100_debugfs_rbbm_init(struct radeon_device
*rdev
)
2171 #if defined(CONFIG_DEBUG_FS)
2172 return radeon_debugfs_add_files(rdev
, r100_debugfs_rbbm_list
, 1);
2178 int r100_debugfs_cp_init(struct radeon_device
*rdev
)
2180 #if defined(CONFIG_DEBUG_FS)
2181 return radeon_debugfs_add_files(rdev
, r100_debugfs_cp_list
, 2);
2187 int r100_debugfs_mc_info_init(struct radeon_device
*rdev
)
2189 #if defined(CONFIG_DEBUG_FS)
2190 return radeon_debugfs_add_files(rdev
, r100_debugfs_mc_info_list
, 1);
2196 int r100_set_surface_reg(struct radeon_device
*rdev
, int reg
,
2197 uint32_t tiling_flags
, uint32_t pitch
,
2198 uint32_t offset
, uint32_t obj_size
)
2200 int surf_index
= reg
* 16;
2203 /* r100/r200 divide by 16 */
2204 if (rdev
->family
< CHIP_R300
)
2209 if (rdev
->family
<= CHIP_RS200
) {
2210 if ((tiling_flags
& (RADEON_TILING_MACRO
|RADEON_TILING_MICRO
))
2211 == (RADEON_TILING_MACRO
|RADEON_TILING_MICRO
))
2212 flags
|= RADEON_SURF_TILE_COLOR_BOTH
;
2213 if (tiling_flags
& RADEON_TILING_MACRO
)
2214 flags
|= RADEON_SURF_TILE_COLOR_MACRO
;
2215 } else if (rdev
->family
<= CHIP_RV280
) {
2216 if (tiling_flags
& (RADEON_TILING_MACRO
))
2217 flags
|= R200_SURF_TILE_COLOR_MACRO
;
2218 if (tiling_flags
& RADEON_TILING_MICRO
)
2219 flags
|= R200_SURF_TILE_COLOR_MICRO
;
2221 if (tiling_flags
& RADEON_TILING_MACRO
)
2222 flags
|= R300_SURF_TILE_MACRO
;
2223 if (tiling_flags
& RADEON_TILING_MICRO
)
2224 flags
|= R300_SURF_TILE_MICRO
;
2227 if (tiling_flags
& RADEON_TILING_SWAP_16BIT
)
2228 flags
|= RADEON_SURF_AP0_SWP_16BPP
| RADEON_SURF_AP1_SWP_16BPP
;
2229 if (tiling_flags
& RADEON_TILING_SWAP_32BIT
)
2230 flags
|= RADEON_SURF_AP0_SWP_32BPP
| RADEON_SURF_AP1_SWP_32BPP
;
2232 DRM_DEBUG("writing surface %d %d %x %x\n", reg
, flags
, offset
, offset
+obj_size
-1);
2233 WREG32(RADEON_SURFACE0_INFO
+ surf_index
, flags
);
2234 WREG32(RADEON_SURFACE0_LOWER_BOUND
+ surf_index
, offset
);
2235 WREG32(RADEON_SURFACE0_UPPER_BOUND
+ surf_index
, offset
+ obj_size
- 1);
2239 void r100_clear_surface_reg(struct radeon_device
*rdev
, int reg
)
2241 int surf_index
= reg
* 16;
2242 WREG32(RADEON_SURFACE0_INFO
+ surf_index
, 0);
2245 void r100_bandwidth_update(struct radeon_device
*rdev
)
2247 fixed20_12 trcd_ff
, trp_ff
, tras_ff
, trbs_ff
, tcas_ff
;
2248 fixed20_12 sclk_ff
, mclk_ff
, sclk_eff_ff
, sclk_delay_ff
;
2249 fixed20_12 peak_disp_bw
, mem_bw
, pix_clk
, pix_clk2
, temp_ff
, crit_point_ff
;
2250 uint32_t temp
, data
, mem_trcd
, mem_trp
, mem_tras
;
2251 fixed20_12 memtcas_ff
[8] = {
2260 fixed20_12 memtcas_rs480_ff
[8] = {
2270 fixed20_12 memtcas2_ff
[8] = {
2280 fixed20_12 memtrbs
[8] = {
2290 fixed20_12 memtrbs_r4xx
[8] = {
2300 fixed20_12 min_mem_eff
;
2301 fixed20_12 mc_latency_sclk
, mc_latency_mclk
, k1
;
2302 fixed20_12 cur_latency_mclk
, cur_latency_sclk
;
2303 fixed20_12 disp_latency
, disp_latency_overhead
, disp_drain_rate
,
2304 disp_drain_rate2
, read_return_rate
;
2305 fixed20_12 time_disp1_drop_priority
;
2307 int cur_size
= 16; /* in octawords */
2308 int critical_point
= 0, critical_point2
;
2309 /* uint32_t read_return_rate, time_disp1_drop_priority; */
2310 int stop_req
, max_stop_req
;
2311 struct drm_display_mode
*mode1
= NULL
;
2312 struct drm_display_mode
*mode2
= NULL
;
2313 uint32_t pixel_bytes1
= 0;
2314 uint32_t pixel_bytes2
= 0;
2316 if (rdev
->mode_info
.crtcs
[0]->base
.enabled
) {
2317 mode1
= &rdev
->mode_info
.crtcs
[0]->base
.mode
;
2318 pixel_bytes1
= rdev
->mode_info
.crtcs
[0]->base
.fb
->bits_per_pixel
/ 8;
2320 if (!(rdev
->flags
& RADEON_SINGLE_CRTC
)) {
2321 if (rdev
->mode_info
.crtcs
[1]->base
.enabled
) {
2322 mode2
= &rdev
->mode_info
.crtcs
[1]->base
.mode
;
2323 pixel_bytes2
= rdev
->mode_info
.crtcs
[1]->base
.fb
->bits_per_pixel
/ 8;
2327 min_mem_eff
.full
= rfixed_const_8(0);
2329 if ((rdev
->disp_priority
== 2) && ASIC_IS_R300(rdev
)) {
2330 uint32_t mc_init_misc_lat_timer
= RREG32(R300_MC_INIT_MISC_LAT_TIMER
);
2331 mc_init_misc_lat_timer
&= ~(R300_MC_DISP1R_INIT_LAT_MASK
<< R300_MC_DISP1R_INIT_LAT_SHIFT
);
2332 mc_init_misc_lat_timer
&= ~(R300_MC_DISP0R_INIT_LAT_MASK
<< R300_MC_DISP0R_INIT_LAT_SHIFT
);
2333 /* check crtc enables */
2335 mc_init_misc_lat_timer
|= (1 << R300_MC_DISP1R_INIT_LAT_SHIFT
);
2337 mc_init_misc_lat_timer
|= (1 << R300_MC_DISP0R_INIT_LAT_SHIFT
);
2338 WREG32(R300_MC_INIT_MISC_LAT_TIMER
, mc_init_misc_lat_timer
);
2342 * determine is there is enough bw for current mode
2344 mclk_ff
.full
= rfixed_const(rdev
->clock
.default_mclk
);
2345 temp_ff
.full
= rfixed_const(100);
2346 mclk_ff
.full
= rfixed_div(mclk_ff
, temp_ff
);
2347 sclk_ff
.full
= rfixed_const(rdev
->clock
.default_sclk
);
2348 sclk_ff
.full
= rfixed_div(sclk_ff
, temp_ff
);
2350 temp
= (rdev
->mc
.vram_width
/ 8) * (rdev
->mc
.vram_is_ddr
? 2 : 1);
2351 temp_ff
.full
= rfixed_const(temp
);
2352 mem_bw
.full
= rfixed_mul(mclk_ff
, temp_ff
);
2356 peak_disp_bw
.full
= 0;
2358 temp_ff
.full
= rfixed_const(1000);
2359 pix_clk
.full
= rfixed_const(mode1
->clock
); /* convert to fixed point */
2360 pix_clk
.full
= rfixed_div(pix_clk
, temp_ff
);
2361 temp_ff
.full
= rfixed_const(pixel_bytes1
);
2362 peak_disp_bw
.full
+= rfixed_mul(pix_clk
, temp_ff
);
2365 temp_ff
.full
= rfixed_const(1000);
2366 pix_clk2
.full
= rfixed_const(mode2
->clock
); /* convert to fixed point */
2367 pix_clk2
.full
= rfixed_div(pix_clk2
, temp_ff
);
2368 temp_ff
.full
= rfixed_const(pixel_bytes2
);
2369 peak_disp_bw
.full
+= rfixed_mul(pix_clk2
, temp_ff
);
2372 mem_bw
.full
= rfixed_mul(mem_bw
, min_mem_eff
);
2373 if (peak_disp_bw
.full
>= mem_bw
.full
) {
2374 DRM_ERROR("You may not have enough display bandwidth for current mode\n"
2375 "If you have flickering problem, try to lower resolution, refresh rate, or color depth\n");
2378 /* Get values from the EXT_MEM_CNTL register...converting its contents. */
2379 temp
= RREG32(RADEON_MEM_TIMING_CNTL
);
2380 if ((rdev
->family
== CHIP_RV100
) || (rdev
->flags
& RADEON_IS_IGP
)) { /* RV100, M6, IGPs */
2381 mem_trcd
= ((temp
>> 2) & 0x3) + 1;
2382 mem_trp
= ((temp
& 0x3)) + 1;
2383 mem_tras
= ((temp
& 0x70) >> 4) + 1;
2384 } else if (rdev
->family
== CHIP_R300
||
2385 rdev
->family
== CHIP_R350
) { /* r300, r350 */
2386 mem_trcd
= (temp
& 0x7) + 1;
2387 mem_trp
= ((temp
>> 8) & 0x7) + 1;
2388 mem_tras
= ((temp
>> 11) & 0xf) + 4;
2389 } else if (rdev
->family
== CHIP_RV350
||
2390 rdev
->family
<= CHIP_RV380
) {
2392 mem_trcd
= (temp
& 0x7) + 3;
2393 mem_trp
= ((temp
>> 8) & 0x7) + 3;
2394 mem_tras
= ((temp
>> 11) & 0xf) + 6;
2395 } else if (rdev
->family
== CHIP_R420
||
2396 rdev
->family
== CHIP_R423
||
2397 rdev
->family
== CHIP_RV410
) {
2399 mem_trcd
= (temp
& 0xf) + 3;
2402 mem_trp
= ((temp
>> 8) & 0xf) + 3;
2405 mem_tras
= ((temp
>> 12) & 0x1f) + 6;
2408 } else { /* RV200, R200 */
2409 mem_trcd
= (temp
& 0x7) + 1;
2410 mem_trp
= ((temp
>> 8) & 0x7) + 1;
2411 mem_tras
= ((temp
>> 12) & 0xf) + 4;
2414 trcd_ff
.full
= rfixed_const(mem_trcd
);
2415 trp_ff
.full
= rfixed_const(mem_trp
);
2416 tras_ff
.full
= rfixed_const(mem_tras
);
2418 /* Get values from the MEM_SDRAM_MODE_REG register...converting its */
2419 temp
= RREG32(RADEON_MEM_SDRAM_MODE_REG
);
2420 data
= (temp
& (7 << 20)) >> 20;
2421 if ((rdev
->family
== CHIP_RV100
) || rdev
->flags
& RADEON_IS_IGP
) {
2422 if (rdev
->family
== CHIP_RS480
) /* don't think rs400 */
2423 tcas_ff
= memtcas_rs480_ff
[data
];
2425 tcas_ff
= memtcas_ff
[data
];
2427 tcas_ff
= memtcas2_ff
[data
];
2429 if (rdev
->family
== CHIP_RS400
||
2430 rdev
->family
== CHIP_RS480
) {
2431 /* extra cas latency stored in bits 23-25 0-4 clocks */
2432 data
= (temp
>> 23) & 0x7;
2434 tcas_ff
.full
+= rfixed_const(data
);
2437 if (ASIC_IS_R300(rdev
) && !(rdev
->flags
& RADEON_IS_IGP
)) {
2438 /* on the R300, Tcas is included in Trbs.
2440 temp
= RREG32(RADEON_MEM_CNTL
);
2441 data
= (R300_MEM_NUM_CHANNELS_MASK
& temp
);
2443 if (R300_MEM_USE_CD_CH_ONLY
& temp
) {
2444 temp
= RREG32(R300_MC_IND_INDEX
);
2445 temp
&= ~R300_MC_IND_ADDR_MASK
;
2446 temp
|= R300_MC_READ_CNTL_CD_mcind
;
2447 WREG32(R300_MC_IND_INDEX
, temp
);
2448 temp
= RREG32(R300_MC_IND_DATA
);
2449 data
= (R300_MEM_RBS_POSITION_C_MASK
& temp
);
2451 temp
= RREG32(R300_MC_READ_CNTL_AB
);
2452 data
= (R300_MEM_RBS_POSITION_A_MASK
& temp
);
2455 temp
= RREG32(R300_MC_READ_CNTL_AB
);
2456 data
= (R300_MEM_RBS_POSITION_A_MASK
& temp
);
2458 if (rdev
->family
== CHIP_RV410
||
2459 rdev
->family
== CHIP_R420
||
2460 rdev
->family
== CHIP_R423
)
2461 trbs_ff
= memtrbs_r4xx
[data
];
2463 trbs_ff
= memtrbs
[data
];
2464 tcas_ff
.full
+= trbs_ff
.full
;
2467 sclk_eff_ff
.full
= sclk_ff
.full
;
2469 if (rdev
->flags
& RADEON_IS_AGP
) {
2470 fixed20_12 agpmode_ff
;
2471 agpmode_ff
.full
= rfixed_const(radeon_agpmode
);
2472 temp_ff
.full
= rfixed_const_666(16);
2473 sclk_eff_ff
.full
-= rfixed_mul(agpmode_ff
, temp_ff
);
2475 /* TODO PCIE lanes may affect this - agpmode == 16?? */
2477 if (ASIC_IS_R300(rdev
)) {
2478 sclk_delay_ff
.full
= rfixed_const(250);
2480 if ((rdev
->family
== CHIP_RV100
) ||
2481 rdev
->flags
& RADEON_IS_IGP
) {
2482 if (rdev
->mc
.vram_is_ddr
)
2483 sclk_delay_ff
.full
= rfixed_const(41);
2485 sclk_delay_ff
.full
= rfixed_const(33);
2487 if (rdev
->mc
.vram_width
== 128)
2488 sclk_delay_ff
.full
= rfixed_const(57);
2490 sclk_delay_ff
.full
= rfixed_const(41);
2494 mc_latency_sclk
.full
= rfixed_div(sclk_delay_ff
, sclk_eff_ff
);
2496 if (rdev
->mc
.vram_is_ddr
) {
2497 if (rdev
->mc
.vram_width
== 32) {
2498 k1
.full
= rfixed_const(40);
2501 k1
.full
= rfixed_const(20);
2505 k1
.full
= rfixed_const(40);
2509 temp_ff
.full
= rfixed_const(2);
2510 mc_latency_mclk
.full
= rfixed_mul(trcd_ff
, temp_ff
);
2511 temp_ff
.full
= rfixed_const(c
);
2512 mc_latency_mclk
.full
+= rfixed_mul(tcas_ff
, temp_ff
);
2513 temp_ff
.full
= rfixed_const(4);
2514 mc_latency_mclk
.full
+= rfixed_mul(tras_ff
, temp_ff
);
2515 mc_latency_mclk
.full
+= rfixed_mul(trp_ff
, temp_ff
);
2516 mc_latency_mclk
.full
+= k1
.full
;
2518 mc_latency_mclk
.full
= rfixed_div(mc_latency_mclk
, mclk_ff
);
2519 mc_latency_mclk
.full
+= rfixed_div(temp_ff
, sclk_eff_ff
);
2522 HW cursor time assuming worst case of full size colour cursor.
2524 temp_ff
.full
= rfixed_const((2 * (cur_size
- (rdev
->mc
.vram_is_ddr
+ 1))));
2525 temp_ff
.full
+= trcd_ff
.full
;
2526 if (temp_ff
.full
< tras_ff
.full
)
2527 temp_ff
.full
= tras_ff
.full
;
2528 cur_latency_mclk
.full
= rfixed_div(temp_ff
, mclk_ff
);
2530 temp_ff
.full
= rfixed_const(cur_size
);
2531 cur_latency_sclk
.full
= rfixed_div(temp_ff
, sclk_eff_ff
);
2533 Find the total latency for the display data.
2535 disp_latency_overhead
.full
= rfixed_const(8);
2536 disp_latency_overhead
.full
= rfixed_div(disp_latency_overhead
, sclk_ff
);
2537 mc_latency_mclk
.full
+= disp_latency_overhead
.full
+ cur_latency_mclk
.full
;
2538 mc_latency_sclk
.full
+= disp_latency_overhead
.full
+ cur_latency_sclk
.full
;
2540 if (mc_latency_mclk
.full
> mc_latency_sclk
.full
)
2541 disp_latency
.full
= mc_latency_mclk
.full
;
2543 disp_latency
.full
= mc_latency_sclk
.full
;
2545 /* setup Max GRPH_STOP_REQ default value */
2546 if (ASIC_IS_RV100(rdev
))
2547 max_stop_req
= 0x5c;
2549 max_stop_req
= 0x7c;
2553 Set GRPH_BUFFER_CNTL register using h/w defined optimal values.
2554 GRPH_STOP_REQ <= MIN[ 0x7C, (CRTC_H_DISP + 1) * (bit depth) / 0x10 ]
2556 stop_req
= mode1
->hdisplay
* pixel_bytes1
/ 16;
2558 if (stop_req
> max_stop_req
)
2559 stop_req
= max_stop_req
;
2562 Find the drain rate of the display buffer.
2564 temp_ff
.full
= rfixed_const((16/pixel_bytes1
));
2565 disp_drain_rate
.full
= rfixed_div(pix_clk
, temp_ff
);
2568 Find the critical point of the display buffer.
2570 crit_point_ff
.full
= rfixed_mul(disp_drain_rate
, disp_latency
);
2571 crit_point_ff
.full
+= rfixed_const_half(0);
2573 critical_point
= rfixed_trunc(crit_point_ff
);
2575 if (rdev
->disp_priority
== 2) {
2580 The critical point should never be above max_stop_req-4. Setting
2581 GRPH_CRITICAL_CNTL = 0 will thus force high priority all the time.
2583 if (max_stop_req
- critical_point
< 4)
2586 if (critical_point
== 0 && mode2
&& rdev
->family
== CHIP_R300
) {
2587 /* some R300 cards have problem with this set to 0, when CRTC2 is enabled.*/
2588 critical_point
= 0x10;
2591 temp
= RREG32(RADEON_GRPH_BUFFER_CNTL
);
2592 temp
&= ~(RADEON_GRPH_STOP_REQ_MASK
);
2593 temp
|= (stop_req
<< RADEON_GRPH_STOP_REQ_SHIFT
);
2594 temp
&= ~(RADEON_GRPH_START_REQ_MASK
);
2595 if ((rdev
->family
== CHIP_R350
) &&
2596 (stop_req
> 0x15)) {
2599 temp
|= (stop_req
<< RADEON_GRPH_START_REQ_SHIFT
);
2600 temp
|= RADEON_GRPH_BUFFER_SIZE
;
2601 temp
&= ~(RADEON_GRPH_CRITICAL_CNTL
|
2602 RADEON_GRPH_CRITICAL_AT_SOF
|
2603 RADEON_GRPH_STOP_CNTL
);
2605 Write the result into the register.
2607 WREG32(RADEON_GRPH_BUFFER_CNTL
, ((temp
& ~RADEON_GRPH_CRITICAL_POINT_MASK
) |
2608 (critical_point
<< RADEON_GRPH_CRITICAL_POINT_SHIFT
)));
2611 if ((rdev
->family
== CHIP_RS400
) ||
2612 (rdev
->family
== CHIP_RS480
)) {
2613 /* attempt to program RS400 disp regs correctly ??? */
2614 temp
= RREG32(RS400_DISP1_REG_CNTL
);
2615 temp
&= ~(RS400_DISP1_START_REQ_LEVEL_MASK
|
2616 RS400_DISP1_STOP_REQ_LEVEL_MASK
);
2617 WREG32(RS400_DISP1_REQ_CNTL1
, (temp
|
2618 (critical_point
<< RS400_DISP1_START_REQ_LEVEL_SHIFT
) |
2619 (critical_point
<< RS400_DISP1_STOP_REQ_LEVEL_SHIFT
)));
2620 temp
= RREG32(RS400_DMIF_MEM_CNTL1
);
2621 temp
&= ~(RS400_DISP1_CRITICAL_POINT_START_MASK
|
2622 RS400_DISP1_CRITICAL_POINT_STOP_MASK
);
2623 WREG32(RS400_DMIF_MEM_CNTL1
, (temp
|
2624 (critical_point
<< RS400_DISP1_CRITICAL_POINT_START_SHIFT
) |
2625 (critical_point
<< RS400_DISP1_CRITICAL_POINT_STOP_SHIFT
)));
2629 DRM_DEBUG("GRPH_BUFFER_CNTL from to %x\n",
2630 /* (unsigned int)info->SavedReg->grph_buffer_cntl, */
2631 (unsigned int)RREG32(RADEON_GRPH_BUFFER_CNTL
));
2636 stop_req
= mode2
->hdisplay
* pixel_bytes2
/ 16;
2638 if (stop_req
> max_stop_req
)
2639 stop_req
= max_stop_req
;
2642 Find the drain rate of the display buffer.
2644 temp_ff
.full
= rfixed_const((16/pixel_bytes2
));
2645 disp_drain_rate2
.full
= rfixed_div(pix_clk2
, temp_ff
);
2647 grph2_cntl
= RREG32(RADEON_GRPH2_BUFFER_CNTL
);
2648 grph2_cntl
&= ~(RADEON_GRPH_STOP_REQ_MASK
);
2649 grph2_cntl
|= (stop_req
<< RADEON_GRPH_STOP_REQ_SHIFT
);
2650 grph2_cntl
&= ~(RADEON_GRPH_START_REQ_MASK
);
2651 if ((rdev
->family
== CHIP_R350
) &&
2652 (stop_req
> 0x15)) {
2655 grph2_cntl
|= (stop_req
<< RADEON_GRPH_START_REQ_SHIFT
);
2656 grph2_cntl
|= RADEON_GRPH_BUFFER_SIZE
;
2657 grph2_cntl
&= ~(RADEON_GRPH_CRITICAL_CNTL
|
2658 RADEON_GRPH_CRITICAL_AT_SOF
|
2659 RADEON_GRPH_STOP_CNTL
);
2661 if ((rdev
->family
== CHIP_RS100
) ||
2662 (rdev
->family
== CHIP_RS200
))
2663 critical_point2
= 0;
2665 temp
= (rdev
->mc
.vram_width
* rdev
->mc
.vram_is_ddr
+ 1)/128;
2666 temp_ff
.full
= rfixed_const(temp
);
2667 temp_ff
.full
= rfixed_mul(mclk_ff
, temp_ff
);
2668 if (sclk_ff
.full
< temp_ff
.full
)
2669 temp_ff
.full
= sclk_ff
.full
;
2671 read_return_rate
.full
= temp_ff
.full
;
2674 temp_ff
.full
= read_return_rate
.full
- disp_drain_rate
.full
;
2675 time_disp1_drop_priority
.full
= rfixed_div(crit_point_ff
, temp_ff
);
2677 time_disp1_drop_priority
.full
= 0;
2679 crit_point_ff
.full
= disp_latency
.full
+ time_disp1_drop_priority
.full
+ disp_latency
.full
;
2680 crit_point_ff
.full
= rfixed_mul(crit_point_ff
, disp_drain_rate2
);
2681 crit_point_ff
.full
+= rfixed_const_half(0);
2683 critical_point2
= rfixed_trunc(crit_point_ff
);
2685 if (rdev
->disp_priority
== 2) {
2686 critical_point2
= 0;
2689 if (max_stop_req
- critical_point2
< 4)
2690 critical_point2
= 0;
2694 if (critical_point2
== 0 && rdev
->family
== CHIP_R300
) {
2695 /* some R300 cards have problem with this set to 0 */
2696 critical_point2
= 0x10;
2699 WREG32(RADEON_GRPH2_BUFFER_CNTL
, ((grph2_cntl
& ~RADEON_GRPH_CRITICAL_POINT_MASK
) |
2700 (critical_point2
<< RADEON_GRPH_CRITICAL_POINT_SHIFT
)));
2702 if ((rdev
->family
== CHIP_RS400
) ||
2703 (rdev
->family
== CHIP_RS480
)) {
2705 /* attempt to program RS400 disp2 regs correctly ??? */
2706 temp
= RREG32(RS400_DISP2_REQ_CNTL1
);
2707 temp
&= ~(RS400_DISP2_START_REQ_LEVEL_MASK
|
2708 RS400_DISP2_STOP_REQ_LEVEL_MASK
);
2709 WREG32(RS400_DISP2_REQ_CNTL1
, (temp
|
2710 (critical_point2
<< RS400_DISP1_START_REQ_LEVEL_SHIFT
) |
2711 (critical_point2
<< RS400_DISP1_STOP_REQ_LEVEL_SHIFT
)));
2712 temp
= RREG32(RS400_DISP2_REQ_CNTL2
);
2713 temp
&= ~(RS400_DISP2_CRITICAL_POINT_START_MASK
|
2714 RS400_DISP2_CRITICAL_POINT_STOP_MASK
);
2715 WREG32(RS400_DISP2_REQ_CNTL2
, (temp
|
2716 (critical_point2
<< RS400_DISP2_CRITICAL_POINT_START_SHIFT
) |
2717 (critical_point2
<< RS400_DISP2_CRITICAL_POINT_STOP_SHIFT
)));
2719 WREG32(RS400_DISP2_REQ_CNTL1
, 0x105DC1CC);
2720 WREG32(RS400_DISP2_REQ_CNTL2
, 0x2749D000);
2721 WREG32(RS400_DMIF_MEM_CNTL1
, 0x29CA71DC);
2722 WREG32(RS400_DISP1_REQ_CNTL1
, 0x28FBC3AC);
2725 DRM_DEBUG("GRPH2_BUFFER_CNTL from to %x\n",
2726 (unsigned int)RREG32(RADEON_GRPH2_BUFFER_CNTL
));
2730 static inline void r100_cs_track_texture_print(struct r100_cs_track_texture
*t
)
2732 DRM_ERROR("pitch %d\n", t
->pitch
);
2733 DRM_ERROR("use_pitch %d\n", t
->use_pitch
);
2734 DRM_ERROR("width %d\n", t
->width
);
2735 DRM_ERROR("width_11 %d\n", t
->width_11
);
2736 DRM_ERROR("height %d\n", t
->height
);
2737 DRM_ERROR("height_11 %d\n", t
->height_11
);
2738 DRM_ERROR("num levels %d\n", t
->num_levels
);
2739 DRM_ERROR("depth %d\n", t
->txdepth
);
2740 DRM_ERROR("bpp %d\n", t
->cpp
);
2741 DRM_ERROR("coordinate type %d\n", t
->tex_coord_type
);
2742 DRM_ERROR("width round to power of 2 %d\n", t
->roundup_w
);
2743 DRM_ERROR("height round to power of 2 %d\n", t
->roundup_h
);
2744 DRM_ERROR("compress format %d\n", t
->compress_format
);
2747 static int r100_cs_track_cube(struct radeon_device
*rdev
,
2748 struct r100_cs_track
*track
, unsigned idx
)
2750 unsigned face
, w
, h
;
2751 struct radeon_bo
*cube_robj
;
2754 for (face
= 0; face
< 5; face
++) {
2755 cube_robj
= track
->textures
[idx
].cube_info
[face
].robj
;
2756 w
= track
->textures
[idx
].cube_info
[face
].width
;
2757 h
= track
->textures
[idx
].cube_info
[face
].height
;
2760 size
*= track
->textures
[idx
].cpp
;
2762 size
+= track
->textures
[idx
].cube_info
[face
].offset
;
2764 if (size
> radeon_bo_size(cube_robj
)) {
2765 DRM_ERROR("Cube texture offset greater than object size %lu %lu\n",
2766 size
, radeon_bo_size(cube_robj
));
2767 r100_cs_track_texture_print(&track
->textures
[idx
]);
2774 static int r100_track_compress_size(int compress_format
, int w
, int h
)
2776 int block_width
, block_height
, block_bytes
;
2777 int wblocks
, hblocks
;
2784 switch (compress_format
) {
2785 case R100_TRACK_COMP_DXT1
:
2790 case R100_TRACK_COMP_DXT35
:
2796 hblocks
= (h
+ block_height
- 1) / block_height
;
2797 wblocks
= (w
+ block_width
- 1) / block_width
;
2798 if (wblocks
< min_wblocks
)
2799 wblocks
= min_wblocks
;
2800 sz
= wblocks
* hblocks
* block_bytes
;
2804 static int r100_cs_track_texture_check(struct radeon_device
*rdev
,
2805 struct r100_cs_track
*track
)
2807 struct radeon_bo
*robj
;
2809 unsigned u
, i
, w
, h
;
2812 for (u
= 0; u
< track
->num_texture
; u
++) {
2813 if (!track
->textures
[u
].enabled
)
2815 robj
= track
->textures
[u
].robj
;
2817 DRM_ERROR("No texture bound to unit %u\n", u
);
2821 for (i
= 0; i
<= track
->textures
[u
].num_levels
; i
++) {
2822 if (track
->textures
[u
].use_pitch
) {
2823 if (rdev
->family
< CHIP_R300
)
2824 w
= (track
->textures
[u
].pitch
/ track
->textures
[u
].cpp
) / (1 << i
);
2826 w
= track
->textures
[u
].pitch
/ (1 << i
);
2828 w
= track
->textures
[u
].width
;
2829 if (rdev
->family
>= CHIP_RV515
)
2830 w
|= track
->textures
[u
].width_11
;
2832 if (track
->textures
[u
].roundup_w
)
2833 w
= roundup_pow_of_two(w
);
2835 h
= track
->textures
[u
].height
;
2836 if (rdev
->family
>= CHIP_RV515
)
2837 h
|= track
->textures
[u
].height_11
;
2839 if (track
->textures
[u
].roundup_h
)
2840 h
= roundup_pow_of_two(h
);
2841 if (track
->textures
[u
].compress_format
) {
2843 size
+= r100_track_compress_size(track
->textures
[u
].compress_format
, w
, h
);
2844 /* compressed textures are block based */
2848 size
*= track
->textures
[u
].cpp
;
2850 switch (track
->textures
[u
].tex_coord_type
) {
2854 size
*= (1 << track
->textures
[u
].txdepth
);
2857 if (track
->separate_cube
) {
2858 ret
= r100_cs_track_cube(rdev
, track
, u
);
2865 DRM_ERROR("Invalid texture coordinate type %u for unit "
2866 "%u\n", track
->textures
[u
].tex_coord_type
, u
);
2869 if (size
> radeon_bo_size(robj
)) {
2870 DRM_ERROR("Texture of unit %u needs %lu bytes but is "
2871 "%lu\n", u
, size
, radeon_bo_size(robj
));
2872 r100_cs_track_texture_print(&track
->textures
[u
]);
2879 int r100_cs_track_check(struct radeon_device
*rdev
, struct r100_cs_track
*track
)
2886 for (i
= 0; i
< track
->num_cb
; i
++) {
2887 if (track
->cb
[i
].robj
== NULL
) {
2888 if (!(track
->fastfill
|| track
->color_channel_mask
||
2889 track
->blend_read_enable
)) {
2892 DRM_ERROR("[drm] No buffer for color buffer %d !\n", i
);
2895 size
= track
->cb
[i
].pitch
* track
->cb
[i
].cpp
* track
->maxy
;
2896 size
+= track
->cb
[i
].offset
;
2897 if (size
> radeon_bo_size(track
->cb
[i
].robj
)) {
2898 DRM_ERROR("[drm] Buffer too small for color buffer %d "
2899 "(need %lu have %lu) !\n", i
, size
,
2900 radeon_bo_size(track
->cb
[i
].robj
));
2901 DRM_ERROR("[drm] color buffer %d (%u %u %u %u)\n",
2902 i
, track
->cb
[i
].pitch
, track
->cb
[i
].cpp
,
2903 track
->cb
[i
].offset
, track
->maxy
);
2907 if (track
->z_enabled
) {
2908 if (track
->zb
.robj
== NULL
) {
2909 DRM_ERROR("[drm] No buffer for z buffer !\n");
2912 size
= track
->zb
.pitch
* track
->zb
.cpp
* track
->maxy
;
2913 size
+= track
->zb
.offset
;
2914 if (size
> radeon_bo_size(track
->zb
.robj
)) {
2915 DRM_ERROR("[drm] Buffer too small for z buffer "
2916 "(need %lu have %lu) !\n", size
,
2917 radeon_bo_size(track
->zb
.robj
));
2918 DRM_ERROR("[drm] zbuffer (%u %u %u %u)\n",
2919 track
->zb
.pitch
, track
->zb
.cpp
,
2920 track
->zb
.offset
, track
->maxy
);
2924 prim_walk
= (track
->vap_vf_cntl
>> 4) & 0x3;
2925 nverts
= (track
->vap_vf_cntl
>> 16) & 0xFFFF;
2926 switch (prim_walk
) {
2928 for (i
= 0; i
< track
->num_arrays
; i
++) {
2929 size
= track
->arrays
[i
].esize
* track
->max_indx
* 4;
2930 if (track
->arrays
[i
].robj
== NULL
) {
2931 DRM_ERROR("(PW %u) Vertex array %u no buffer "
2932 "bound\n", prim_walk
, i
);
2935 if (size
> radeon_bo_size(track
->arrays
[i
].robj
)) {
2936 dev_err(rdev
->dev
, "(PW %u) Vertex array %u "
2937 "need %lu dwords have %lu dwords\n",
2938 prim_walk
, i
, size
>> 2,
2939 radeon_bo_size(track
->arrays
[i
].robj
)
2941 DRM_ERROR("Max indices %u\n", track
->max_indx
);
2947 for (i
= 0; i
< track
->num_arrays
; i
++) {
2948 size
= track
->arrays
[i
].esize
* (nverts
- 1) * 4;
2949 if (track
->arrays
[i
].robj
== NULL
) {
2950 DRM_ERROR("(PW %u) Vertex array %u no buffer "
2951 "bound\n", prim_walk
, i
);
2954 if (size
> radeon_bo_size(track
->arrays
[i
].robj
)) {
2955 dev_err(rdev
->dev
, "(PW %u) Vertex array %u "
2956 "need %lu dwords have %lu dwords\n",
2957 prim_walk
, i
, size
>> 2,
2958 radeon_bo_size(track
->arrays
[i
].robj
)
2965 size
= track
->vtx_size
* nverts
;
2966 if (size
!= track
->immd_dwords
) {
2967 DRM_ERROR("IMMD draw %u dwors but needs %lu dwords\n",
2968 track
->immd_dwords
, size
);
2969 DRM_ERROR("VAP_VF_CNTL.NUM_VERTICES %u, VTX_SIZE %u\n",
2970 nverts
, track
->vtx_size
);
2975 DRM_ERROR("[drm] Invalid primitive walk %d for VAP_VF_CNTL\n",
2979 return r100_cs_track_texture_check(rdev
, track
);
2982 void r100_cs_track_clear(struct radeon_device
*rdev
, struct r100_cs_track
*track
)
2986 if (rdev
->family
< CHIP_R300
) {
2988 if (rdev
->family
<= CHIP_RS200
)
2989 track
->num_texture
= 3;
2991 track
->num_texture
= 6;
2993 track
->separate_cube
= 1;
2996 track
->num_texture
= 16;
2998 track
->separate_cube
= 0;
3001 for (i
= 0; i
< track
->num_cb
; i
++) {
3002 track
->cb
[i
].robj
= NULL
;
3003 track
->cb
[i
].pitch
= 8192;
3004 track
->cb
[i
].cpp
= 16;
3005 track
->cb
[i
].offset
= 0;
3007 track
->z_enabled
= true;
3008 track
->zb
.robj
= NULL
;
3009 track
->zb
.pitch
= 8192;
3011 track
->zb
.offset
= 0;
3012 track
->vtx_size
= 0x7F;
3013 track
->immd_dwords
= 0xFFFFFFFFUL
;
3014 track
->num_arrays
= 11;
3015 track
->max_indx
= 0x00FFFFFFUL
;
3016 for (i
= 0; i
< track
->num_arrays
; i
++) {
3017 track
->arrays
[i
].robj
= NULL
;
3018 track
->arrays
[i
].esize
= 0x7F;
3020 for (i
= 0; i
< track
->num_texture
; i
++) {
3021 track
->textures
[i
].compress_format
= R100_TRACK_COMP_NONE
;
3022 track
->textures
[i
].pitch
= 16536;
3023 track
->textures
[i
].width
= 16536;
3024 track
->textures
[i
].height
= 16536;
3025 track
->textures
[i
].width_11
= 1 << 11;
3026 track
->textures
[i
].height_11
= 1 << 11;
3027 track
->textures
[i
].num_levels
= 12;
3028 if (rdev
->family
<= CHIP_RS200
) {
3029 track
->textures
[i
].tex_coord_type
= 0;
3030 track
->textures
[i
].txdepth
= 0;
3032 track
->textures
[i
].txdepth
= 16;
3033 track
->textures
[i
].tex_coord_type
= 1;
3035 track
->textures
[i
].cpp
= 64;
3036 track
->textures
[i
].robj
= NULL
;
3037 /* CS IB emission code makes sure texture unit are disabled */
3038 track
->textures
[i
].enabled
= false;
3039 track
->textures
[i
].roundup_w
= true;
3040 track
->textures
[i
].roundup_h
= true;
3041 if (track
->separate_cube
)
3042 for (face
= 0; face
< 5; face
++) {
3043 track
->textures
[i
].cube_info
[face
].robj
= NULL
;
3044 track
->textures
[i
].cube_info
[face
].width
= 16536;
3045 track
->textures
[i
].cube_info
[face
].height
= 16536;
3046 track
->textures
[i
].cube_info
[face
].offset
= 0;
3051 int r100_ring_test(struct radeon_device
*rdev
)
3058 r
= radeon_scratch_get(rdev
, &scratch
);
3060 DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r
);
3063 WREG32(scratch
, 0xCAFEDEAD);
3064 r
= radeon_ring_lock(rdev
, 2);
3066 DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r
);
3067 radeon_scratch_free(rdev
, scratch
);
3070 radeon_ring_write(rdev
, PACKET0(scratch
, 0));
3071 radeon_ring_write(rdev
, 0xDEADBEEF);
3072 radeon_ring_unlock_commit(rdev
);
3073 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
3074 tmp
= RREG32(scratch
);
3075 if (tmp
== 0xDEADBEEF) {
3080 if (i
< rdev
->usec_timeout
) {
3081 DRM_INFO("ring test succeeded in %d usecs\n", i
);
3083 DRM_ERROR("radeon: ring test failed (sracth(0x%04X)=0x%08X)\n",
3087 radeon_scratch_free(rdev
, scratch
);
3091 void r100_ring_ib_execute(struct radeon_device
*rdev
, struct radeon_ib
*ib
)
3093 radeon_ring_write(rdev
, PACKET0(RADEON_CP_IB_BASE
, 1));
3094 radeon_ring_write(rdev
, ib
->gpu_addr
);
3095 radeon_ring_write(rdev
, ib
->length_dw
);
3098 int r100_ib_test(struct radeon_device
*rdev
)
3100 struct radeon_ib
*ib
;
3106 r
= radeon_scratch_get(rdev
, &scratch
);
3108 DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r
);
3111 WREG32(scratch
, 0xCAFEDEAD);
3112 r
= radeon_ib_get(rdev
, &ib
);
3116 ib
->ptr
[0] = PACKET0(scratch
, 0);
3117 ib
->ptr
[1] = 0xDEADBEEF;
3118 ib
->ptr
[2] = PACKET2(0);
3119 ib
->ptr
[3] = PACKET2(0);
3120 ib
->ptr
[4] = PACKET2(0);
3121 ib
->ptr
[5] = PACKET2(0);
3122 ib
->ptr
[6] = PACKET2(0);
3123 ib
->ptr
[7] = PACKET2(0);
3125 r
= radeon_ib_schedule(rdev
, ib
);
3127 radeon_scratch_free(rdev
, scratch
);
3128 radeon_ib_free(rdev
, &ib
);
3131 r
= radeon_fence_wait(ib
->fence
, false);
3135 for (i
= 0; i
< rdev
->usec_timeout
; i
++) {
3136 tmp
= RREG32(scratch
);
3137 if (tmp
== 0xDEADBEEF) {
3142 if (i
< rdev
->usec_timeout
) {
3143 DRM_INFO("ib test succeeded in %u usecs\n", i
);
3145 DRM_ERROR("radeon: ib test failed (sracth(0x%04X)=0x%08X)\n",
3149 radeon_scratch_free(rdev
, scratch
);
3150 radeon_ib_free(rdev
, &ib
);
3154 void r100_ib_fini(struct radeon_device
*rdev
)
3156 radeon_ib_pool_fini(rdev
);
3159 int r100_ib_init(struct radeon_device
*rdev
)
3163 r
= radeon_ib_pool_init(rdev
);
3165 dev_err(rdev
->dev
, "failled initializing IB pool (%d).\n", r
);
3169 r
= r100_ib_test(rdev
);
3171 dev_err(rdev
->dev
, "failled testing IB (%d).\n", r
);
3178 void r100_mc_stop(struct radeon_device
*rdev
, struct r100_mc_save
*save
)
3180 /* Shutdown CP we shouldn't need to do that but better be safe than
3183 rdev
->cp
.ready
= false;
3184 WREG32(R_000740_CP_CSQ_CNTL
, 0);
3186 /* Save few CRTC registers */
3187 save
->GENMO_WT
= RREG8(R_0003C2_GENMO_WT
);
3188 save
->CRTC_EXT_CNTL
= RREG32(R_000054_CRTC_EXT_CNTL
);
3189 save
->CRTC_GEN_CNTL
= RREG32(R_000050_CRTC_GEN_CNTL
);
3190 save
->CUR_OFFSET
= RREG32(R_000260_CUR_OFFSET
);
3191 if (!(rdev
->flags
& RADEON_SINGLE_CRTC
)) {
3192 save
->CRTC2_GEN_CNTL
= RREG32(R_0003F8_CRTC2_GEN_CNTL
);
3193 save
->CUR2_OFFSET
= RREG32(R_000360_CUR2_OFFSET
);
3196 /* Disable VGA aperture access */
3197 WREG8(R_0003C2_GENMO_WT
, C_0003C2_VGA_RAM_EN
& save
->GENMO_WT
);
3198 /* Disable cursor, overlay, crtc */
3199 WREG32(R_000260_CUR_OFFSET
, save
->CUR_OFFSET
| S_000260_CUR_LOCK(1));
3200 WREG32(R_000054_CRTC_EXT_CNTL
, save
->CRTC_EXT_CNTL
|
3201 S_000054_CRTC_DISPLAY_DIS(1));
3202 WREG32(R_000050_CRTC_GEN_CNTL
,
3203 (C_000050_CRTC_CUR_EN
& save
->CRTC_GEN_CNTL
) |
3204 S_000050_CRTC_DISP_REQ_EN_B(1));
3205 WREG32(R_000420_OV0_SCALE_CNTL
,
3206 C_000420_OV0_OVERLAY_EN
& RREG32(R_000420_OV0_SCALE_CNTL
));
3207 WREG32(R_000260_CUR_OFFSET
, C_000260_CUR_LOCK
& save
->CUR_OFFSET
);
3208 if (!(rdev
->flags
& RADEON_SINGLE_CRTC
)) {
3209 WREG32(R_000360_CUR2_OFFSET
, save
->CUR2_OFFSET
|
3210 S_000360_CUR2_LOCK(1));
3211 WREG32(R_0003F8_CRTC2_GEN_CNTL
,
3212 (C_0003F8_CRTC2_CUR_EN
& save
->CRTC2_GEN_CNTL
) |
3213 S_0003F8_CRTC2_DISPLAY_DIS(1) |
3214 S_0003F8_CRTC2_DISP_REQ_EN_B(1));
3215 WREG32(R_000360_CUR2_OFFSET
,
3216 C_000360_CUR2_LOCK
& save
->CUR2_OFFSET
);
3220 void r100_mc_resume(struct radeon_device
*rdev
, struct r100_mc_save
*save
)
3222 /* Update base address for crtc */
3223 WREG32(R_00023C_DISPLAY_BASE_ADDR
, rdev
->mc
.vram_location
);
3224 if (!(rdev
->flags
& RADEON_SINGLE_CRTC
)) {
3225 WREG32(R_00033C_CRTC2_DISPLAY_BASE_ADDR
,
3226 rdev
->mc
.vram_location
);
3228 /* Restore CRTC registers */
3229 WREG8(R_0003C2_GENMO_WT
, save
->GENMO_WT
);
3230 WREG32(R_000054_CRTC_EXT_CNTL
, save
->CRTC_EXT_CNTL
);
3231 WREG32(R_000050_CRTC_GEN_CNTL
, save
->CRTC_GEN_CNTL
);
3232 if (!(rdev
->flags
& RADEON_SINGLE_CRTC
)) {
3233 WREG32(R_0003F8_CRTC2_GEN_CNTL
, save
->CRTC2_GEN_CNTL
);
3237 void r100_vga_render_disable(struct radeon_device
*rdev
)
3241 tmp
= RREG8(R_0003C2_GENMO_WT
);
3242 WREG8(R_0003C2_GENMO_WT
, C_0003C2_VGA_RAM_EN
& tmp
);
3245 static void r100_debugfs(struct radeon_device
*rdev
)
3249 r
= r100_debugfs_mc_info_init(rdev
);
3251 dev_warn(rdev
->dev
, "Failed to create r100_mc debugfs file.\n");
3254 static void r100_mc_program(struct radeon_device
*rdev
)
3256 struct r100_mc_save save
;
3258 /* Stops all mc clients */
3259 r100_mc_stop(rdev
, &save
);
3260 if (rdev
->flags
& RADEON_IS_AGP
) {
3261 WREG32(R_00014C_MC_AGP_LOCATION
,
3262 S_00014C_MC_AGP_START(rdev
->mc
.gtt_start
>> 16) |
3263 S_00014C_MC_AGP_TOP(rdev
->mc
.gtt_end
>> 16));
3264 WREG32(R_000170_AGP_BASE
, lower_32_bits(rdev
->mc
.agp_base
));
3265 if (rdev
->family
> CHIP_RV200
)
3266 WREG32(R_00015C_AGP_BASE_2
,
3267 upper_32_bits(rdev
->mc
.agp_base
) & 0xff);
3269 WREG32(R_00014C_MC_AGP_LOCATION
, 0x0FFFFFFF);
3270 WREG32(R_000170_AGP_BASE
, 0);
3271 if (rdev
->family
> CHIP_RV200
)
3272 WREG32(R_00015C_AGP_BASE_2
, 0);
3274 /* Wait for mc idle */
3275 if (r100_mc_wait_for_idle(rdev
))
3276 dev_warn(rdev
->dev
, "Wait for MC idle timeout.\n");
3277 /* Program MC, should be a 32bits limited address space */
3278 WREG32(R_000148_MC_FB_LOCATION
,
3279 S_000148_MC_FB_START(rdev
->mc
.vram_start
>> 16) |
3280 S_000148_MC_FB_TOP(rdev
->mc
.vram_end
>> 16));
3281 r100_mc_resume(rdev
, &save
);
3284 void r100_clock_startup(struct radeon_device
*rdev
)
3288 if (radeon_dynclks
!= -1 && radeon_dynclks
)
3289 radeon_legacy_set_clock_gating(rdev
, 1);
3290 /* We need to force on some of the block */
3291 tmp
= RREG32_PLL(R_00000D_SCLK_CNTL
);
3292 tmp
|= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1);
3293 if ((rdev
->family
== CHIP_RV250
) || (rdev
->family
== CHIP_RV280
))
3294 tmp
|= S_00000D_FORCE_DISP1(1) | S_00000D_FORCE_DISP2(1);
3295 WREG32_PLL(R_00000D_SCLK_CNTL
, tmp
);
3298 static int r100_startup(struct radeon_device
*rdev
)
3302 /* set common regs */
3303 r100_set_common_regs(rdev
);
3305 r100_mc_program(rdev
);
3307 r100_clock_startup(rdev
);
3308 /* Initialize GPU configuration (# pipes, ...) */
3309 r100_gpu_init(rdev
);
3310 /* Initialize GART (initialize after TTM so we can allocate
3311 * memory through TTM but finalize after TTM) */
3312 r100_enable_bm(rdev
);
3313 if (rdev
->flags
& RADEON_IS_PCI
) {
3314 r
= r100_pci_gart_enable(rdev
);
3320 rdev
->config
.r100
.hdp_cntl
= RREG32(RADEON_HOST_PATH_CNTL
);
3321 /* 1M ring buffer */
3322 r
= r100_cp_init(rdev
, 1024 * 1024);
3324 dev_err(rdev
->dev
, "failled initializing CP (%d).\n", r
);
3327 r
= r100_wb_init(rdev
);
3329 dev_err(rdev
->dev
, "failled initializing WB (%d).\n", r
);
3330 r
= r100_ib_init(rdev
);
3332 dev_err(rdev
->dev
, "failled initializing IB (%d).\n", r
);
3338 int r100_resume(struct radeon_device
*rdev
)
3340 /* Make sur GART are not working */
3341 if (rdev
->flags
& RADEON_IS_PCI
)
3342 r100_pci_gart_disable(rdev
);
3343 /* Resume clock before doing reset */
3344 r100_clock_startup(rdev
);
3345 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
3346 if (radeon_gpu_reset(rdev
)) {
3347 dev_warn(rdev
->dev
, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
3348 RREG32(R_000E40_RBBM_STATUS
),
3349 RREG32(R_0007C0_CP_STAT
));
3352 radeon_combios_asic_init(rdev
->ddev
);
3353 /* Resume clock after posting */
3354 r100_clock_startup(rdev
);
3355 /* Initialize surface registers */
3356 radeon_surface_init(rdev
);
3357 return r100_startup(rdev
);
3360 int r100_suspend(struct radeon_device
*rdev
)
3362 r100_cp_disable(rdev
);
3363 r100_wb_disable(rdev
);
3364 r100_irq_disable(rdev
);
3365 if (rdev
->flags
& RADEON_IS_PCI
)
3366 r100_pci_gart_disable(rdev
);
3370 void r100_fini(struct radeon_device
*rdev
)
3376 radeon_gem_fini(rdev
);
3377 if (rdev
->flags
& RADEON_IS_PCI
)
3378 r100_pci_gart_fini(rdev
);
3379 radeon_agp_fini(rdev
);
3380 radeon_irq_kms_fini(rdev
);
3381 radeon_fence_driver_fini(rdev
);
3382 radeon_bo_fini(rdev
);
3383 radeon_atombios_fini(rdev
);
3388 int r100_mc_init(struct radeon_device
*rdev
)
3393 /* Setup GPU memory space */
3394 rdev
->mc
.vram_location
= 0xFFFFFFFFUL
;
3395 rdev
->mc
.gtt_location
= 0xFFFFFFFFUL
;
3396 if (rdev
->flags
& RADEON_IS_IGP
) {
3397 tmp
= G_00015C_MC_FB_START(RREG32(R_00015C_NB_TOM
));
3398 rdev
->mc
.vram_location
= tmp
<< 16;
3400 if (rdev
->flags
& RADEON_IS_AGP
) {
3401 r
= radeon_agp_init(rdev
);
3403 radeon_agp_disable(rdev
);
3405 rdev
->mc
.gtt_location
= rdev
->mc
.agp_base
;
3408 r
= radeon_mc_setup(rdev
);
3414 int r100_init(struct radeon_device
*rdev
)
3418 /* Register debugfs file specific to this group of asics */
3421 r100_vga_render_disable(rdev
);
3422 /* Initialize scratch registers */
3423 radeon_scratch_init(rdev
);
3424 /* Initialize surface registers */
3425 radeon_surface_init(rdev
);
3426 /* TODO: disable VGA need to use VGA request */
3428 if (!radeon_get_bios(rdev
)) {
3429 if (ASIC_IS_AVIVO(rdev
))
3432 if (rdev
->is_atom_bios
) {
3433 dev_err(rdev
->dev
, "Expecting combios for RS400/RS480 GPU\n");
3436 r
= radeon_combios_init(rdev
);
3440 /* Reset gpu before posting otherwise ATOM will enter infinite loop */
3441 if (radeon_gpu_reset(rdev
)) {
3443 "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
3444 RREG32(R_000E40_RBBM_STATUS
),
3445 RREG32(R_0007C0_CP_STAT
));
3447 /* check if cards are posted or not */
3448 if (radeon_boot_test_post_card(rdev
) == false)
3450 /* Set asic errata */
3452 /* Initialize clocks */
3453 radeon_get_clock_info(rdev
->ddev
);
3454 /* Initialize power management */
3455 radeon_pm_init(rdev
);
3456 /* Get vram informations */
3457 r100_vram_info(rdev
);
3458 /* Initialize memory controller (also test AGP) */
3459 r
= r100_mc_init(rdev
);
3463 r
= radeon_fence_driver_init(rdev
);
3466 r
= radeon_irq_kms_init(rdev
);
3469 /* Memory manager */
3470 r
= radeon_bo_init(rdev
);
3473 if (rdev
->flags
& RADEON_IS_PCI
) {
3474 r
= r100_pci_gart_init(rdev
);
3478 r100_set_safe_registers(rdev
);
3479 rdev
->accel_working
= true;
3480 r
= r100_startup(rdev
);
3482 /* Somethings want wront with the accel init stop accel */
3483 dev_err(rdev
->dev
, "Disabling GPU acceleration\n");
3488 if (rdev
->flags
& RADEON_IS_PCI
)
3489 r100_pci_gart_fini(rdev
);
3490 radeon_irq_kms_fini(rdev
);
3491 rdev
->accel_working
= false;