42 #define MGA_DEFAULT_USEC_TIMEOUT 10000
43 #define MGA_FREELIST_DEBUG 0
45 #define MINIMAL_CLEANUP 0
46 #define FULL_CLEANUP 1
47 static int mga_do_cleanup_dma(
struct drm_device *
dev,
int full_cleanup);
69 DRM_ERROR(
"failed!\n");
70 DRM_INFO(
" status=0x%08x\n", status);
121 DRM_DEBUG(
" bailing out...\n");
148 DRM_DEBUG(
" head = 0x%06lx\n", (
unsigned long)(head - dev_priv->
primary->offset));
149 DRM_DEBUG(
" tail = 0x%06lx\n", (
unsigned long)(tail - dev_priv->
primary->offset));
150 DRM_DEBUG(
" space = 0x%06x\n", primary->
space);
155 DRM_DEBUG(
"done.\n");
181 if (head == dev_priv->
primary->offset)
186 DRM_DEBUG(
" head = 0x%06lx\n", (
unsigned long)(head - dev_priv->
primary->offset));
187 DRM_DEBUG(
" tail = 0x%06x\n", primary->
tail);
188 DRM_DEBUG(
" wrap = %d\n", primary->
last_wrap);
189 DRM_DEBUG(
" space = 0x%06x\n", primary->
space);
195 DRM_DEBUG(
"done.\n");
206 DRM_DEBUG(
" wrap = %d\n", sarea_priv->
last_wrap);
212 DRM_DEBUG(
"done.\n");
219 #define MGA_BUFFER_USED (~0)
220 #define MGA_BUFFER_FREE 0
222 #if MGA_FREELIST_DEBUG
229 DRM_INFO(
"current dispatch: last=0x%x done=0x%x\n",
233 DRM_INFO(
"current freelist:\n");
235 for (entry = dev_priv->
head->
next; entry; entry = entry->
next) {
236 DRM_INFO(
" %p idx=%2d age=0x%x 0x%06lx\n",
246 struct drm_device_dma *
dma = dev->dma;
251 DRM_DEBUG(
"count=%d\n", dma->buf_count);
259 for (i = 0; i < dma->buf_count; i++) {
260 buf = dma->buflist[
i];
261 buf_priv = buf->dev_private;
287 static void mga_freelist_cleanup(
struct drm_device *dev)
294 entry = dev_priv->
head;
307 static void mga_freelist_reset(
struct drm_device *dev)
309 struct drm_device_dma *dma = dev->dma;
314 for (i = 0; i < dma->buf_count; i++) {
315 buf = dma->buflist[
i];
316 buf_priv = buf->dev_private;
322 static struct drm_buf *mga_freelist_get(
struct drm_device * dev)
334 DRM_DEBUG(
" tail=0x%06lx %d\n",
338 DRM_DEBUG(
" head=0x%06lx %d\n",
339 (
unsigned long)(head - dev_priv->
primary->offset), wrap);
343 next = dev_priv->
tail;
351 DRM_DEBUG(
"returning NULL!\n");
361 DRM_DEBUG(
"age=0x%06lx wrap=%d\n",
367 head = dev_priv->
head;
371 prev = dev_priv->
tail;
399 dev->dev_private = (
void *)dev_priv;
440 static int mga_do_agp_dma_bootstrap(
struct drm_device *dev,
450 const unsigned agp_size = (dma_bs->
agp_size << 20);
458 err = drm_agp_acquire(dev);
460 DRM_ERROR(
"Unable to acquire AGP: %d\n", err);
466 DRM_ERROR(
"Unable to get AGP info: %d\n", err);
471 err = drm_agp_enable(dev,
mode);
473 DRM_ERROR(
"Unable to enable AGP (mode = 0x%lx)\n",
mode.mode);
482 if (
mode.mode & 0x02)
489 agp_req.size = agp_size;
491 err = drm_agp_alloc(dev, &agp_req);
494 DRM_ERROR(
"Unable to allocate %uMB AGP memory\n",
502 bind_req.handle = agp_req.handle;
504 err = drm_agp_bind(dev, &bind_req);
506 DRM_ERROR(
"Unable to bind AGP memory: %d\n", err);
520 DRM_ERROR(
"Unable to map WARP microcode: %d\n", err);
528 DRM_ERROR(
"Unable to map primary DMA region: %d\n", err);
536 DRM_ERROR(
"Unable to map secondary DMA region: %d\n", err);
543 req.flags = _DRM_AGP_BUFFER;
546 err = drm_addbufs_agp(dev, &
req);
548 DRM_ERROR(
"Unable to add secondary DMA buffers: %d\n", err);
553 struct drm_map_list *
_entry;
554 unsigned long agp_token = 0;
557 if (_entry->map == dev->agp_buffer_map)
558 agp_token = _entry->user_token;
563 dev->agp_buffer_token = agp_token;
570 DRM_ERROR(
"Unable to map AGP texture region %d\n", err);
578 if (!dev_priv->
warp->handle ||
579 !dev_priv->
primary->handle || !dev->agp_buffer_map->handle) {
580 DRM_ERROR(
"failed to ioremap agp regions! (%p, %p, %p)\n",
582 dev->agp_buffer_map->handle);
589 DRM_INFO(
"Initialized card for AGP DMA.\n");
593 static int mga_do_agp_dma_bootstrap(
struct drm_device *dev,
614 static int mga_do_pci_dma_bootstrap(
struct drm_device *dev,
620 unsigned int primary_size;
621 unsigned int bin_count;
626 DRM_ERROR(
"dev->dma is NULL\n");
640 DRM_ERROR(
"Unable to create mapping for WARP microcode: %d\n",
650 for (primary_size = dma_bs->
primary_size; primary_size != 0;
651 primary_size >>= 1) {
660 DRM_ERROR(
"Unable to allocate primary DMA region: %d\n", err);
665 DRM_INFO(
"Primary DMA buffer size reduced from %u to %u.\n",
667 (
unsigned)dev_priv->
primary->size);
674 req.count = bin_count;
682 if (bin_count == 0) {
683 DRM_ERROR(
"Unable to add secondary DMA buffers: %d\n", err);
688 DRM_INFO(
"Secondary PCI DMA buffer bin count reduced from %u "
699 DRM_INFO(
"Initialized card for PCI DMA.\n");
703 static int mga_do_dma_bootstrap(
struct drm_device *dev,
706 const int is_agp = (dma_bs->
agp_mode != 0) && drm_pci_device_is_agp(dev);
719 DRM_ERROR(
"Unable to map MMIO region: %d\n", err);
727 DRM_ERROR(
"Unable to map status region: %d\n", err);
737 err = mga_do_agp_dma_bootstrap(dev, dma_bs);
755 err = mga_do_pci_dma_bootstrap(dev, dma_bs);
761 struct drm_file *file_priv)
765 static const int modes[] = { 0, 1, 2, 2, 4, 4, 4, 4 };
769 err = mga_do_dma_bootstrap(dev, bootstrap);
794 dev_priv = dev->dev_private;
818 if (!dev_priv->
sarea) {
819 DRM_ERROR(
"failed to find sarea!\n");
830 DRM_ERROR(
"failed to find status page!\n");
834 if (!dev_priv->
mmio) {
835 DRM_ERROR(
"failed to find mmio region!\n");
839 if (!dev_priv->
warp) {
840 DRM_ERROR(
"failed to find warp microcode region!\n");
845 DRM_ERROR(
"failed to find primary dma region!\n");
849 dev->agp_buffer_map =
851 if (!dev->agp_buffer_map) {
852 DRM_ERROR(
"failed to find dma buffer region!\n");
865 if (!dev_priv->
warp->handle ||
868 ((dev->agp_buffer_map ==
NULL) ||
869 (dev->agp_buffer_map->handle ==
NULL)))) {
870 DRM_ERROR(
"failed to ioremap agp regions!\n");
876 DRM_ERROR(
"failed to install WARP ucode!: %d\n", ret);
882 DRM_ERROR(
"failed to init WARP engine!: %d\n", ret);
919 if (mga_freelist_init(dev, dev_priv) < 0) {
920 DRM_ERROR(
"could not initialize freelist\n");
927 static int mga_do_cleanup_dma(
struct drm_device *dev,
int full_cleanup)
936 if (dev->irq_enabled)
939 if (dev->dev_private) {
950 if (dev->agp_buffer_map !=
NULL)
960 drm_agp_unbind(dev, &unbind_req);
963 drm_agp_free(dev, &free_req);
970 if ((dev->agp !=
NULL) && dev->agp->acquired)
971 err = drm_agp_release(dev);
979 dev->agp_buffer_map =
NULL;
993 mga_freelist_cleanup(dev);
1000 struct drm_file *file_priv)
1005 LOCK_TEST_WITH_RETURN(dev, file_priv);
1007 switch (init->
func) {
1009 err = mga_do_init_dma(dev, init);
1013 case MGA_CLEANUP_DMA:
1025 struct drm_file *file_priv)
1030 LOCK_TEST_WITH_RETURN(dev, file_priv);
1032 DRM_DEBUG(
"%s%s%s\n",
1046 DRM_INFO(
"-EBUSY\n");
1057 struct drm_file *file_priv)
1061 LOCK_TEST_WITH_RETURN(dev, file_priv);
1063 return mga_do_dma_reset(dev_priv);
1070 static int mga_dma_get_buffers(
struct drm_device *dev,
1071 struct drm_file *file_priv,
struct drm_dma *
d)
1073 struct drm_buf *
buf;
1077 buf = mga_freelist_get(dev);
1081 buf->file_priv = file_priv;
1084 &buf->idx,
sizeof(buf->idx)))
1087 &buf->total,
sizeof(buf->total)))
1096 struct drm_file *file_priv)
1098 struct drm_device_dma *dma = dev->dma;
1103 LOCK_TEST_WITH_RETURN(dev, file_priv);
1108 DRM_ERROR(
"Process %d trying to send %d buffers via drmDMA\n",
1116 DRM_ERROR(
"Process %d trying to get %d buffers (of %d max)\n",
1126 ret = mga_dma_get_buffers(dev, file_priv, d);
1136 kfree(dev->dev_private);
1137 dev->dev_private =
NULL;