32 #include <linux/module.h>
39 #define RADEON_FIFO_DEBUG 0
42 #define FIRMWARE_R100 "radeon/R100_cp.bin"
43 #define FIRMWARE_R200 "radeon/R200_cp.bin"
44 #define FIRMWARE_R300 "radeon/R300_cp.bin"
45 #define FIRMWARE_R420 "radeon/R420_cp.bin"
46 #define FIRMWARE_RS690 "radeon/RS690_cp.bin"
47 #define FIRMWARE_RS600 "radeon/RS600_cp.bin"
48 #define FIRMWARE_R520 "radeon/R520_cp.bin"
68 val = *(((
volatile u32 *)
173 return RS690_READ_MCIND(dev_priv, addr);
175 return RS600_READ_MCIND(dev_priv, addr);
177 return RS480_READ_MCIND(dev_priv, addr);
244 u32 agp_base_lo = agp_base & 0xffffffff;
245 u32 r6xx_agp_base = (agp_base >> 22) & 0x3ffff;
295 static int RADEON_READ_PLL(
struct drm_device *
dev,
int addr)
309 #if RADEON_FIFO_DEBUG
312 printk(
"%s:\n", __func__);
313 printk(
"RBBM_STATUS = 0x%08x\n",
315 printk(
"CP_RB_RTPR = 0x%08x\n",
317 printk(
"CP_RB_WTPR = 0x%08x\n",
319 printk(
"AIC_CNTL = 0x%08x\n",
321 printk(
"AIC_STAT = 0x%08x\n",
323 printk(
"AIC_PT_BASE = 0x%08x\n",
325 printk(
"TLB_ADDR = 0x%08x\n",
327 printk(
"TLB_DATA = 0x%08x\n",
360 #if RADEON_FIFO_DEBUG
361 DRM_ERROR(
"failed!\n");
362 radeon_status(dev_priv);
376 if (slots >= entries)
380 DRM_DEBUG(
"wait for fifo failed status : 0x%08X 0x%08X\n",
384 #if RADEON_FIFO_DEBUG
385 DRM_ERROR(
"failed!\n");
386 radeon_status(dev_priv);
397 ret = radeon_do_wait_for_fifo(dev_priv, 64);
404 radeon_do_pixcache_flush(dev_priv);
409 DRM_DEBUG(
"wait idle failed status : 0x%08X 0x%08X\n",
413 #if RADEON_FIFO_DEBUG
414 DRM_ERROR(
"failed!\n");
415 radeon_status(dev_priv);
423 uint32_t gb_tile_config, gb_pipe_sel = 0;
427 if ((z_pipe_sel & 3) == 3)
437 dev_priv->
num_gb_pipes = ((gb_pipe_sel >> 12) & 0x3) + 1;
439 if ((dev->pdev->device == 0x5e4c) ||
440 (dev->pdev->device == 0x5e4f))
445 dev->pdev->device != 0x4144) ||
447 dev->pdev->device != 0x4148)) {
471 radeon_do_wait_for_idle(dev_priv);
493 pdev = platform_device_register_simple(
"radeon_cp", 0,
NULL, 0);
505 DRM_INFO(
"Loading R100 Microcode\n");
511 DRM_INFO(
"Loading R200 Microcode\n");
519 DRM_INFO(
"Loading R300 Microcode\n");
524 DRM_INFO(
"Loading R400 Microcode\n");
528 DRM_INFO(
"Loading RS690/RS740 Microcode\n");
531 DRM_INFO(
"Loading RS600 Microcode\n");
539 DRM_INFO(
"Loading R500 Microcode\n");
548 }
else if (dev_priv->
me_fw->size % 8) {
550 "radeon_cp: Bogus length %zu in firmware \"%s\"\n",
551 dev_priv->
me_fw->size, fw_name);
564 radeon_do_wait_for_idle(dev_priv);
566 if (dev_priv->
me_fw) {
567 size = dev_priv->
me_fw->size / 4;
568 fw_data = (
const __be32 *)&dev_priv->
me_fw->data[0];
570 for (i = 0; i <
size; i += 2) {
610 return radeon_do_wait_for_idle(dev_priv);
620 radeon_do_wait_for_idle(dev_priv);
685 radeon_do_wait_for_idle(dev_priv);
695 static int radeon_do_engine_reset(
struct drm_device * dev)
698 u32 clock_cntl_index = 0, mclk_cntl = 0, rbbm_soft_reset;
701 radeon_do_pixcache_flush(dev_priv);
746 radeon_init_pipes(dev);
749 radeon_do_cp_reset(dev_priv);
760 static void radeon_cp_init_ring_buffer(
struct drm_device * dev,
762 struct drm_file *file_priv)
765 u32 ring_start, cur_read_ptr;
773 radeon_write_fb_location(dev_priv,
786 ring_start = (dev_priv->
cp_ring->offset
791 ring_start = (dev_priv->
cp_ring->offset
792 - (
unsigned long)dev->sg->virtual
816 - ((
unsigned long) dev->sg->virtual)
859 master_priv = file_priv->master->driver_priv;
866 radeon_do_wait_for_idle(dev_priv);
895 if (val == 0xdeadbeef)
900 if (tmp < dev_priv->usec_timeout) {
902 DRM_INFO(
"writeback test succeeded in %d usecs\n", tmp);
905 DRM_INFO(
"writeback test failed\n");
909 DRM_INFO(
"writeback forced off\n");
926 DRM_DEBUG(
"programming igp gart %08X %08lX %08X\n",
948 temp = dev_priv->
gart_info.bus_addr & 0xfffff000;
998 DRM_DEBUG(
"programming igp gart %08X %08lX %08X\n",
1006 for (i = 0; i < 19; i++)
1019 for (i = 1; i < 8; i++)
1072 DRM_DEBUG(
"programming pcie %08X %08lX %08X\n",
1104 radeon_set_igpgart(dev_priv, on);
1109 rs600_set_igpgart(dev_priv, on);
1114 radeon_set_pciegart(dev_priv, on);
1146 struct drm_ati_pcigart_info *gart_info = &dev_priv->
gart_info;
1155 if (i >= 2 * RADEON_MAX_SURFACES)
1165 vp->
lower = gart_info->bus_addr;
1166 vp->
upper = vp->
lower + gart_info->table_size;
1185 struct drm_file *file_priv)
1194 DRM_ERROR(
"Cannot initialise DRM on this card\nThis card requires a new X.org DDX for 3D\n");
1195 radeon_do_cleanup_cp(dev);
1200 DRM_DEBUG(
"Forcing AGP card to PCI mode\n");
1204 DRM_DEBUG(
"Restoring AGP flag\n");
1209 DRM_ERROR(
"PCI GART memory not allocated!\n");
1210 radeon_do_cleanup_cp(dev);
1217 DRM_DEBUG(
"TIMEOUT problem!\n");
1218 radeon_do_cleanup_cp(dev);
1226 switch(init->
func) {
1227 case RADEON_INIT_R200_CP:
1230 case RADEON_INIT_R300_CP:
1246 DRM_DEBUG(
"BAD cp_mode (%x)!\n", init->
cp_mode);
1247 radeon_do_cleanup_cp(dev);
1314 if (!master_priv->
sarea) {
1315 DRM_ERROR(
"could not find sarea!\n");
1316 radeon_do_cleanup_cp(dev);
1322 DRM_ERROR(
"could not find cp ring region!\n");
1323 radeon_do_cleanup_cp(dev);
1328 DRM_ERROR(
"could not find ring read pointer!\n");
1329 radeon_do_cleanup_cp(dev);
1333 dev->agp_buffer_map = drm_core_findmap(dev, init->
buffers_offset);
1334 if (!dev->agp_buffer_map) {
1335 DRM_ERROR(
"could not find dma buffer region!\n");
1336 radeon_do_cleanup_cp(dev);
1344 DRM_ERROR(
"could not find GART texture region!\n");
1345 radeon_do_cleanup_cp(dev);
1355 if (!dev_priv->
cp_ring->handle ||
1357 !dev->agp_buffer_map->handle) {
1358 DRM_ERROR(
"could not find ioremap agp regions!\n");
1359 radeon_do_cleanup_cp(dev);
1366 (
void *)(
unsigned long)dev_priv->
cp_ring->offset;
1368 (
void *)(
unsigned long)dev_priv->
ring_rptr->offset;
1369 dev->agp_buffer_map->handle =
1370 (
void *)(
unsigned long)dev->agp_buffer_map->offset;
1372 DRM_DEBUG(
"dev_priv->cp_ring->handle %p\n",
1374 DRM_DEBUG(
"dev_priv->ring_rptr->handle %p\n",
1376 DRM_DEBUG(
"dev->agp_buffer_map->handle %p\n",
1377 dev->agp_buffer_map->handle);
1403 DRM_INFO(
"Setting GART location based on new memory map\n");
1411 base = dev->agp->base;
1415 DRM_INFO(
"Can't use AGP base @0x%08lx, won't fit\n",
1424 if (base < dev_priv->fb_location ||
1425 ((base + dev_priv->
gart_size) & 0xfffffffful) < base)
1431 DRM_INFO(
"GART aligned down from 0x%08x to 0x%08x\n",
1434 DRM_INFO(
"Setting GART location based on old memory map\n");
1447 - (
unsigned long)dev->sg->virtual
1450 DRM_DEBUG(
"dev_priv->gart_size %d\n", dev_priv->
gart_size);
1451 DRM_DEBUG(
"dev_priv->gart_vm_start 0x%x\n", dev_priv->
gart_vm_start);
1452 DRM_DEBUG(
"dev_priv->gart_buffers_offset 0x%lx\n",
1473 radeon_set_pcigart(dev_priv, 0);
1495 dev_priv->
gart_info.gart_reg_if = DRM_ATI_GART_PCIE;
1497 dev_priv->
gart_info.gart_reg_if = DRM_ATI_GART_PCI;
1498 dev_priv->
gart_info.gart_table_location =
1501 DRM_DEBUG(
"Setting phys_pci_gart to %p %08lX\n",
1506 dev_priv->
gart_info.gart_reg_if = DRM_ATI_GART_IGP;
1508 dev_priv->
gart_info.gart_reg_if = DRM_ATI_GART_PCI;
1509 dev_priv->
gart_info.gart_table_location =
1515 (
"Cannot use PCI Express without GART in FB memory\n");
1516 radeon_do_cleanup_cp(dev);
1530 DRM_ERROR(
"failed to init PCI GART!\n");
1531 radeon_do_cleanup_cp(dev);
1535 ret = radeon_setup_pcigart_surface(dev_priv);
1537 DRM_ERROR(
"failed to setup GART surface!\n");
1542 radeon_do_cleanup_cp(dev);
1547 radeon_set_pcigart(dev_priv, 1);
1550 if (!dev_priv->
me_fw) {
1551 int err = radeon_cp_init_microcode(dev_priv);
1553 DRM_ERROR(
"Failed to load firmware!\n");
1554 radeon_do_cleanup_cp(dev);
1558 radeon_cp_load_microcode(dev_priv);
1559 radeon_cp_init_ring_buffer(dev, dev_priv, file_priv);
1563 radeon_do_engine_reset(dev);
1564 radeon_test_writeback(dev_priv);
1569 static int radeon_do_cleanup_cp(
struct drm_device * dev)
1578 if (dev->irq_enabled)
1591 if (dev->agp_buffer_map !=
NULL) {
1593 dev->agp_buffer_map =
NULL;
1601 radeon_set_pcigart(dev_priv, 0);
1606 DRM_ERROR(
"failed to cleanup PCI GART!\n");
1610 if (dev_priv->
gart_info.gart_table_location == DRM_ATI_GART_FB)
1629 static int radeon_do_resume_cp(
struct drm_device *dev,
struct drm_file *file_priv)
1634 DRM_ERROR(
"Called with no initialization\n");
1638 DRM_DEBUG(
"Starting radeon_do_resume_cp()\n");
1643 radeon_set_pcigart(dev_priv, 0);
1648 radeon_set_pcigart(dev_priv, 1);
1651 radeon_cp_load_microcode(dev_priv);
1652 radeon_cp_init_ring_buffer(dev, dev_priv, file_priv);
1655 radeon_do_engine_reset(dev);
1658 DRM_DEBUG(
"radeon_do_resume_cp() complete\n");
1668 LOCK_TEST_WITH_RETURN(dev, file_priv);
1670 if (init->
func == RADEON_INIT_R300_CP)
1673 switch (init->
func) {
1674 case RADEON_INIT_CP:
1675 case RADEON_INIT_R200_CP:
1676 case RADEON_INIT_R300_CP:
1677 return radeon_do_init_cp(dev, init, file_priv);
1678 case RADEON_INIT_R600_CP:
1680 case RADEON_CLEANUP_CP:
1684 return radeon_do_cleanup_cp(dev);
1695 LOCK_TEST_WITH_RETURN(dev, file_priv);
1698 DRM_DEBUG(
"while CP running\n");
1702 DRM_DEBUG(
"called with bogus CP mode (%d)\n",
1710 radeon_do_cp_start(dev_priv);
1725 LOCK_TEST_WITH_RETURN(dev, file_priv);
1734 radeon_do_cp_flush(dev_priv);
1756 radeon_do_cp_stop(dev_priv);
1762 radeon_do_engine_reset(dev);
1777 DRM_DEBUG(
"radeon_do_cp_idle %d\n", ret);
1781 tsleep(&ret, PZERO,
"rdnrel", 1);
1786 DRM_DEBUG(
"radeon_do_cp_idle %d\n", ret);
1790 tsleep(&ret, PZERO,
"rdnrel", 1);
1798 radeon_do_cp_stop(dev_priv);
1799 radeon_do_engine_reset(dev);
1808 if (dev_priv->
mmio) {
1827 radeon_do_cleanup_cp(dev);
1842 LOCK_TEST_WITH_RETURN(dev, file_priv);
1845 DRM_DEBUG(
"called before init done\n");
1852 radeon_do_cp_reset(dev_priv);
1865 LOCK_TEST_WITH_RETURN(dev, file_priv);
1883 return radeon_do_resume_cp(dev, file_priv);
1891 LOCK_TEST_WITH_RETURN(dev, file_priv);
1896 return radeon_do_engine_reset(dev);
1933 struct drm_device_dma *
dma = dev->dma;
1936 struct drm_buf *
buf;
1940 if (++dev_priv->
last_buf >= dma->buf_count)
1947 DRM_DEBUG(
"done_age = %d\n", done_age);
1948 for (i = 0; i < dma->buf_count; i++) {
1949 buf = dma->buflist[
start];
1950 buf_priv = buf->dev_private;
1951 if (buf->file_priv ==
NULL || (buf->pending &&
1954 dev_priv->
stats.requested_bufs++;
1958 if (++start >= dma->buf_count)
1964 dev_priv->
stats.freelist_loops++;
1973 struct drm_device_dma *
dma = dev->dma;
1978 for (i = 0; i < dma->buf_count; i++) {
1979 struct drm_buf *
buf = dma->buflist[
i];
1999 if (ring->
space <= 0)
2001 if (ring->
space > n)
2006 if (head != last_head)
2014 #if RADEON_FIFO_DEBUG
2015 radeon_status(dev_priv);
2016 DRM_ERROR(
"failed!\n");
2021 static int radeon_cp_get_buffers(
struct drm_device *dev,
2022 struct drm_file *file_priv,
2026 struct drm_buf *
buf;
2033 buf->file_priv = file_priv;
2039 sizeof(buf->total)))
2049 struct drm_device_dma *
dma = dev->dma;
2053 LOCK_TEST_WITH_RETURN(dev, file_priv);
2058 DRM_ERROR(
"Process %d trying to send %d buffers via drmDMA\n",
2066 DRM_ERROR(
"Process %d trying to get %d buffers (of %d max)\n",
2074 ret = radeon_cp_get_buffers(dev, file_priv, d);
2086 if (dev_priv ==
NULL)
2089 dev->dev_private = (
void *)dev_priv;
2114 if (drm_pci_device_is_agp(dev))
2116 else if (pci_is_pcie(dev->pdev))
2133 DRM_DEBUG(
"%s card detected\n",
2141 unsigned long sareapage;
2144 master_priv = kzalloc(
sizeof(*master_priv),
GFP_KERNEL);
2151 &master_priv->
sarea);
2153 DRM_ERROR(
"SAREA setup failed\n");
2160 master->driver_priv = master_priv;
2176 if (master_priv->
sarea)
2181 master->driver_priv =
NULL;
2190 drm_local_map_t *
map;
2215 dev->dev_private =
NULL;
2233 for (i = 0; i < num_p2; i++)