34 #include <linux/slab.h>
35 #include <linux/module.h>
41 #define R128_FIFO_DEBUG 0
43 #define FIRMWARE_NAME "r128/r128_cce.bin"
58 printk(
"GUI_STAT = 0x%08x\n",
60 printk(
"PM4_STAT = 0x%08x\n",
62 printk(
"PM4_BUFFER_DL_WPTR = 0x%08x\n",
64 printk(
"PM4_BUFFER_DL_RPTR = 0x%08x\n",
66 printk(
"PM4_MICRO_CNTL = 0x%08x\n",
68 printk(
"PM4_BUFFER_CNTL = 0x%08x\n",
92 DRM_ERROR(
"failed!\n");
103 if (slots >= entries)
109 DRM_ERROR(
"failed!\n");
118 ret = r128_do_wait_for_fifo(dev_priv, 64);
124 r128_do_pixcache_flush(dev_priv);
131 DRM_ERROR(
"failed!\n");
150 pdev = platform_device_register_simple(
"r128_cce", 0,
NULL, 0);
153 return PTR_ERR(pdev);
163 if (fw->
size != 256 * 8) {
165 "r128_cce: Bogus length %zu in firmware \"%s\"\n",
171 r128_do_wait_for_idle(dev_priv);
175 for (i = 0; i < 256; i++) {
212 return r128_do_pixcache_flush(dev_priv);
219 DRM_ERROR(
"failed!\n");
220 r128_status(dev_priv);
229 r128_do_wait_for_idle(dev_priv);
269 u32 clock_cntl_index, mclk_cntl, gen_reset_cntl;
271 r128_do_pixcache_flush(dev_priv);
292 r128_do_cce_reset(dev_priv);
303 static void r128_cce_init_ring_buffer(
struct drm_device *
dev,
316 ring_start = dev_priv->
cce_ring->offset - dev->agp->base;
319 ring_start = dev_priv->
cce_ring->offset -
320 (
unsigned long)dev->sg->virtual;
349 if (dev->dev_private) {
350 DRM_DEBUG(
"called when already initialized\n");
355 if (dev_priv ==
NULL)
360 if (dev_priv->
is_pci && !dev->sg) {
361 DRM_ERROR(
"PCI GART memory not allocated!\n");
362 dev->dev_private = (
void *)dev_priv;
370 DRM_DEBUG(
"TIMEOUT problem!\n");
371 dev->dev_private = (
void *)dev_priv;
390 DRM_DEBUG(
"Bad cce_mode!\n");
391 dev->dev_private = (
void *)dev_priv;
456 if (!dev_priv->
sarea) {
457 DRM_ERROR(
"could not find sarea!\n");
458 dev->dev_private = (
void *)dev_priv;
464 if (!dev_priv->
mmio) {
465 DRM_ERROR(
"could not find mmio region!\n");
466 dev->dev_private = (
void *)dev_priv;
472 DRM_ERROR(
"could not find cce ring region!\n");
473 dev->dev_private = (
void *)dev_priv;
479 DRM_ERROR(
"could not find ring read pointer!\n");
480 dev->dev_private = (
void *)dev_priv;
485 dev->agp_buffer_map = drm_core_findmap(dev, init->
buffers_offset);
486 if (!dev->agp_buffer_map) {
487 DRM_ERROR(
"could not find dma buffer region!\n");
488 dev->dev_private = (
void *)dev_priv;
497 DRM_ERROR(
"could not find agp texture region!\n");
498 dev->dev_private = (
void *)dev_priv;
515 !dev->agp_buffer_map->handle) {
516 DRM_ERROR(
"Could not ioremap agp regions!\n");
517 dev->dev_private = (
void *)dev_priv;
525 (
void *)(
unsigned long)dev_priv->
cce_ring->offset;
527 (
void *)(
unsigned long)dev_priv->
ring_rptr->offset;
528 dev->agp_buffer_map->handle =
529 (
void *)(
unsigned long)dev->agp_buffer_map->offset;
559 dev_priv->
gart_info.gart_table_location = DRM_ATI_GART_MAIN;
563 dev_priv->
gart_info.gart_reg_if = DRM_ATI_GART_PCI;
565 DRM_ERROR(
"failed to init PCI GART!\n");
566 dev->dev_private = (
void *)dev_priv;
575 r128_cce_init_ring_buffer(dev, dev_priv);
576 rc = r128_cce_load_microcode(dev_priv);
578 dev->dev_private = (
void *)dev_priv;
580 r128_do_engine_reset(dev);
583 DRM_ERROR(
"Failed to load firmware!\n");
597 if (dev->irq_enabled)
600 if (dev->dev_private) {
609 if (dev->agp_buffer_map !=
NULL) {
611 dev->agp_buffer_map =
NULL;
620 (
"failed to cleanup PCI GART!\n");
623 kfree(dev->dev_private);
624 dev->dev_private =
NULL;
636 LOCK_TEST_WITH_RETURN(dev, file_priv);
638 switch (init->
func) {
640 return r128_do_init_cce(dev, init);
641 case R128_CLEANUP_CCE:
653 LOCK_TEST_WITH_RETURN(dev, file_priv);
658 DRM_DEBUG(
"while CCE running\n");
662 r128_do_cce_start(dev_priv);
677 LOCK_TEST_WITH_RETURN(dev, file_priv);
685 r128_do_cce_flush(dev_priv);
700 r128_do_cce_stop(dev_priv);
703 r128_do_engine_reset(dev);
715 LOCK_TEST_WITH_RETURN(dev, file_priv);
719 r128_do_cce_reset(dev_priv);
732 LOCK_TEST_WITH_RETURN(dev, file_priv);
737 r128_do_cce_flush(dev_priv);
746 LOCK_TEST_WITH_RETURN(dev, file_priv);
750 return r128_do_engine_reset(dev);
761 #define R128_BUFFER_USED 0xffffffff
762 #define R128_BUFFER_FREE 0
765 static int r128_freelist_init(
struct drm_device *dev)
767 struct drm_device_dma *
dma = dev->dma;
780 for (i = 0; i < dma->buf_count; i++) {
781 buf = dma->buflist[
i];
782 buf_priv = buf->dev_private;
810 static struct drm_buf *r128_freelist_get(
struct drm_device * dev)
812 struct drm_device_dma *
dma = dev->dma;
820 for (i = 0; i < dma->buf_count; i++) {
821 buf = dma->buflist[
i];
822 buf_priv = buf->dev_private;
830 for (i = 0; i < dma->buf_count; i++) {
831 buf = dma->buflist[
i];
832 buf_priv = buf->dev_private;
833 if (buf->pending && buf_priv->
age <= done_age) {
844 DRM_DEBUG(
"returning NULL!\n");
850 struct drm_device_dma *dma = dev->dma;
853 for (i = 0; i < dma->buf_count; i++) {
854 struct drm_buf *buf = dma->buflist[
i];
870 r128_update_ring_snapshot(dev_priv);
871 if (ring->
space >= n)
877 DRM_ERROR(
"failed!\n");
881 static int r128_cce_get_buffers(
struct drm_device *dev,
882 struct drm_file *file_priv,
889 buf = r128_freelist_get(dev);
893 buf->file_priv = file_priv;
909 struct drm_device_dma *dma = dev->dma;
913 LOCK_TEST_WITH_RETURN(dev, file_priv);
918 DRM_ERROR(
"Process %d trying to send %d buffers via drmDMA\n",
926 DRM_ERROR(
"Process %d trying to get %d buffers (of %d max)\n",
934 ret = r128_cce_get_buffers(dev, file_priv, d);