diff options
author | Owain Ainsworth <oga@cvs.openbsd.org> | 2009-02-15 20:03:20 +0000 |
---|---|---|
committer | Owain Ainsworth <oga@cvs.openbsd.org> | 2009-02-15 20:03:20 +0000 |
commit | 08caec05d0bcf4a66e28f3a384967a407b73ded9 (patch) | |
tree | e7568719a4681aa57bfaa810335dfc23bb155b25 | |
parent | d89a715085865454fa49dd0fde0f0078228514e0 (diff) |
convert drm_scatter code over to using the new dmamem api.
removes the custom code in there, so shrinks the kernel by a few bytes.
Convert other code to deal with data structure changes.
-rw-r--r-- | sys/dev/pci/drm/ati_pcigart.c | 5 | ||||
-rw-r--r-- | sys/dev/pci/drm/drmP.h | 23 | ||||
-rw-r--r-- | sys/dev/pci/drm/drm_drv.c | 8 | ||||
-rw-r--r-- | sys/dev/pci/drm/drm_scatter.c | 132 | ||||
-rw-r--r-- | sys/dev/pci/drm/r128_cce.c | 5 | ||||
-rw-r--r-- | sys/dev/pci/drm/radeon_cp.c | 20 |
6 files changed, 44 insertions, 149 deletions
diff --git a/sys/dev/pci/drm/ati_pcigart.c b/sys/dev/pci/drm/ati_pcigart.c index 0d849848e90..de1a1f7eded 100644 --- a/sys/dev/pci/drm/ati_pcigart.c +++ b/sys/dev/pci/drm/ati_pcigart.c @@ -99,14 +99,15 @@ drm_ati_pcigart_init(struct drm_device *dev, pci_gart = (u_int32_t *) gart_info->addr; max_pages = (gart_info->table_size / sizeof(u_int32_t)); - pages = (dev->sg->pages <= max_pages) ? dev->sg->pages : max_pages; + pages = (dev->sg->mem->map->dm_nsegs <= max_pages) ? + dev->sg->mem->map->dm_nsegs : max_pages; memset(pci_gart, 0, max_pages * sizeof(u32)); KASSERT(PAGE_SIZE >= ATI_PCIGART_PAGE_SIZE); for (i = 0; i < pages; i++) { - entry_addr = dev->sg->busaddr[i]; + entry_addr = dev->sg->mem->map->dm_segs[i].ds_addr; for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) { page_base = (u_int32_t)entry_addr & ATI_PCIGART_PAGE_MASK; diff --git a/sys/dev/pci/drm/drmP.h b/sys/dev/pci/drm/drmP.h index 432bbab3149..a455d26bb78 100644 --- a/sys/dev/pci/drm/drmP.h +++ b/sys/dev/pci/drm/drmP.h @@ -383,24 +383,11 @@ struct drm_agp_head { int mtrr; }; -struct drm_sg_dmamem { - bus_dma_tag_t sg_tag; - bus_dmamap_t sg_map; - bus_dma_segment_t *sg_segs; - int sg_nsegs; - size_t sg_size; - caddr_t sg_kva; +struct drm_sg_mem { + struct drm_dmamem *mem; + unsigned long handle; }; -typedef struct drm_sg_mem { - unsigned long handle; - void *virtual; - int pages; - dma_addr_t *busaddr; - drm_dma_handle_t *dmah; /* Handle to PCI memory for ATI PCIGART table */ - struct drm_sg_dmamem *mem; -} drm_sg_mem_t; - typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t; typedef struct drm_local_map { @@ -552,7 +539,7 @@ struct drm_device { pid_t buf_pgid; struct drm_agp_head *agp; - drm_sg_mem_t *sg; /* Scatter gather memory */ + struct drm_sg_mem *sg; /* Scatter gather memory */ atomic_t *ctx_bitmap; void *dev_private; drm_local_map_t *agp_buffer_map; @@ -676,7 +663,7 @@ int drm_agp_bind(struct drm_device *, struct drm_agp_binding *); int drm_agp_unbind(struct drm_device *, struct drm_agp_binding *); /* Scatter Gather Support (drm_scatter.c) */ -void drm_sg_cleanup(drm_sg_mem_t *); +void drm_sg_cleanup(struct drm_device *, struct drm_sg_mem *); int drm_sg_alloc(struct drm_device *, struct drm_scatter_gather *); /* ATI PCIGART support (ati_pcigart.c) */ diff --git a/sys/dev/pci/drm/drm_drv.c b/sys/dev/pci/drm/drm_drv.c index 29602748281..a862478b9c3 100644 --- a/sys/dev/pci/drm/drm_drv.c +++ b/sys/dev/pci/drm/drm_drv.c @@ -321,11 +321,11 @@ drm_lastclose(struct drm_device *dev) } if (dev->sg != NULL) { - drm_sg_mem_t *sg = dev->sg; + struct drm_sg_mem *sg = dev->sg; dev->sg = NULL; DRM_UNLOCK(); - drm_sg_cleanup(sg); + drm_sg_cleanup(dev, sg); DRM_LOCK(); } @@ -781,8 +781,8 @@ drmmmap(dev_t kdev, off_t offset, int prot) break; /* XXX unify all the bus_dmamem_mmap bits */ case _DRM_SCATTER_GATHER: - return (bus_dmamem_mmap(dev->dmat, dev->sg->mem->sg_segs, - dev->sg->mem->sg_nsegs, map->offset - dev->sg->handle + + return (bus_dmamem_mmap(dev->dmat, dev->sg->mem->segs, + dev->sg->mem->nsegs, map->offset - dev->sg->handle + offset, prot, BUS_DMA_NOWAIT)); case _DRM_SHM: case _DRM_CONSISTENT: diff --git a/sys/dev/pci/drm/drm_scatter.c b/sys/dev/pci/drm/drm_scatter.c index a34ae5f9533..14e9ba2ac9d 100644 --- a/sys/dev/pci/drm/drm_scatter.c +++ b/sys/dev/pci/drm/drm_scatter.c @@ -35,72 +35,52 @@ */ #include "drmP.h" -struct drm_sg_dmamem *drm_sg_dmamem_alloc(bus_dma_tag_t, size_t); -void drm_sg_dmamem_free(struct drm_sg_dmamem *); - void -drm_sg_cleanup(drm_sg_mem_t *entry) +drm_sg_cleanup(struct drm_device *dev, struct drm_sg_mem *entry) { - if (entry != NULL) { - if (entry->mem != NULL) - drm_sg_dmamem_free(entry->mem); - drm_free(entry->busaddr, - sizeof(*entry->busaddr) * entry->pages, DRM_MEM_SGLISTS); - drm_free(entry, sizeof(entry), DRM_MEM_SGLISTS); - } + if (entry == NULL) + return; + + drm_dmamem_free(dev->dmat, entry->mem); + drm_free(entry, sizeof(entry), DRM_MEM_SGLISTS); } int drm_sg_alloc(struct drm_device * dev, struct drm_scatter_gather *request) { - drm_sg_mem_t *entry; - unsigned long pages; - int i; + struct drm_sg_mem *entry; + bus_size_t size; + unsigned long pages; if (dev->sg != NULL) - return EINVAL; + return (EINVAL); entry = drm_calloc(1, sizeof(*entry), DRM_MEM_SGLISTS); if (entry == NULL) - return ENOMEM; + return (ENOMEM); pages = round_page(request->size) / PAGE_SIZE; - DRM_DEBUG("sg size=%ld pages=%ld\n", request->size, pages); + size = pages << PAGE_SHIFT; - entry->pages = pages; - - entry->busaddr = drm_calloc(pages, sizeof(*entry->busaddr), - DRM_MEM_SGLISTS); - if (entry->busaddr == NULL) { - drm_sg_cleanup(entry); - return ENOMEM; - } - - if ((entry->mem = drm_sg_dmamem_alloc(dev->dmat, pages)) == NULL) { - drm_sg_cleanup(entry); - return ENOMEM; - } - - entry->handle = (unsigned long)entry->mem->sg_kva; + DRM_DEBUG("sg size=%ld pages=%ld\n", request->size, pages); - for (i = 0; i < pages; i++) - entry->busaddr[i] = entry->mem->sg_map->dm_segs[i].ds_addr; + if ((entry->mem = drm_dmamem_alloc(dev->dmat, size, PAGE_SIZE, pages, + PAGE_SIZE, 0, 0)) == NULL) + return (ENOMEM); + request->handle = entry->handle = (unsigned long)entry->mem->kva; DRM_DEBUG("sg alloc handle = %08lx\n", entry->handle); - entry->virtual = (void *)entry->handle; - request->handle = entry->handle; - DRM_LOCK(); if (dev->sg) { DRM_UNLOCK(); - drm_sg_cleanup(entry); + drm_sg_cleanup(dev, entry); return EINVAL; } dev->sg = entry; DRM_UNLOCK(); - return 0; + return (0); } int @@ -120,7 +100,7 @@ int drm_sg_free(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_scatter_gather *request = data; - drm_sg_mem_t *entry; + struct drm_sg_mem *entry; DRM_LOCK(); entry = dev->sg; @@ -132,77 +112,7 @@ drm_sg_free(struct drm_device *dev, void *data, struct drm_file *file_priv) DRM_DEBUG("sg free virtual = 0x%lx\n", entry->handle); - drm_sg_cleanup(entry); + drm_sg_cleanup(dev, entry); return 0; } - -/* - * allocate `pages' pages of dma memory for use in - * scatter/gather - */ -struct drm_sg_dmamem* -drm_sg_dmamem_alloc(bus_dma_tag_t dmat, size_t pages) -{ - struct drm_sg_dmamem *dsd = NULL; - bus_size_t size = pages << PAGE_SHIFT; - int ret = 0; - - dsd = drm_calloc(1, sizeof(*dsd), DRM_MEM_SGLISTS); - if (dsd == NULL) - return (NULL); - - dsd->sg_segs = drm_calloc(pages, sizeof(*dsd->sg_segs), - DRM_MEM_SGLISTS); - if (dsd->sg_segs == NULL) - goto dsdfree; - - dsd->sg_tag = dmat; - dsd->sg_size = size; - - if (bus_dmamap_create(dmat, size, pages, PAGE_SIZE, 0, - BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &dsd->sg_map) != 0) - goto segsfree; - - if ((ret = bus_dmamem_alloc(dmat, size, PAGE_SIZE, 0, - dsd->sg_segs, pages, &dsd->sg_nsegs, BUS_DMA_NOWAIT)) != 0) - goto destroy; - - if (bus_dmamem_map(dmat, dsd->sg_segs, dsd->sg_nsegs, size, - &dsd->sg_kva, BUS_DMA_NOWAIT) != 0) - goto free; - - if (bus_dmamap_load(dmat, dsd->sg_map, dsd->sg_kva, size, - NULL, BUS_DMA_NOWAIT) != 0) - goto unmap; - - bzero(dsd->sg_kva, size); - - return (dsd); - -unmap: - bus_dmamem_unmap(dmat, dsd->sg_kva, size); -free: - bus_dmamem_free(dmat, dsd->sg_segs, dsd->sg_nsegs); -destroy: - bus_dmamap_destroy(dmat, dsd->sg_map); -segsfree: - drm_free(dsd->sg_segs, sizeof(*dsd->sg_segs) * pages, DRM_MEM_SGLISTS); - -dsdfree: - drm_free(dsd, sizeof(*dsd), DRM_MEM_SGLISTS); - - return (NULL); -} - -void -drm_sg_dmamem_free(struct drm_sg_dmamem *mem) -{ - bus_dmamap_unload(mem->sg_tag, mem->sg_map); - bus_dmamem_unmap(mem->sg_tag, mem->sg_kva, mem->sg_size); - bus_dmamem_free(mem->sg_tag, mem->sg_segs, mem->sg_nsegs); - bus_dmamap_destroy(mem->sg_tag, mem->sg_map); - drm_free(mem->sg_segs, sizeof(*mem->sg_segs) * - (mem->sg_size >> PAGE_SHIFT), DRM_MEM_SGLISTS); - drm_free(mem, sizeof(*mem), DRM_MEM_SGLISTS); -} diff --git a/sys/dev/pci/drm/r128_cce.c b/sys/dev/pci/drm/r128_cce.c index 2f3f8bd05ac..8b029bb1322 100644 --- a/sys/dev/pci/drm/r128_cce.c +++ b/sys/dev/pci/drm/r128_cce.c @@ -324,8 +324,7 @@ static void r128_cce_init_ring_buffer(struct drm_device * dev, ring_start = dev_priv->cce_ring->offset - dev->agp->base; else #endif - ring_start = dev_priv->cce_ring->offset - - (unsigned long)dev->sg->virtual; + ring_start = dev_priv->cce_ring->offset - dev->sg->handle; R128_WRITE(R128_PM4_BUFFER_OFFSET, ring_start | R128_AGP_OFFSET); @@ -518,7 +517,7 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init) dev_priv->cce_buffers_offset = dev->agp->base; else #endif - dev_priv->cce_buffers_offset = (unsigned long)dev->sg->virtual; + dev_priv->cce_buffers_offset = dev->sg->handle; dev_priv->ring.start = (u32 *) dev_priv->cce_ring->handle; dev_priv->ring.end = ((u32 *) dev_priv->cce_ring->handle diff --git a/sys/dev/pci/drm/radeon_cp.c b/sys/dev/pci/drm/radeon_cp.c index 777ea593765..c894ade0e57 100644 --- a/sys/dev/pci/drm/radeon_cp.c +++ b/sys/dev/pci/drm/radeon_cp.c @@ -634,9 +634,8 @@ radeon_cp_init_ring_buffer(struct drm_device *dev, + dev_priv->gart_vm_start); } else #endif - ring_start = (dev_priv->cp_ring->offset - - (unsigned long)dev->sg->virtual - + dev_priv->gart_vm_start); + ring_start = (dev_priv->cp_ring->offset - dev->sg->handle + + dev_priv->gart_vm_start); RADEON_WRITE(RADEON_CP_RB_BASE, ring_start); @@ -660,14 +659,14 @@ radeon_cp_init_ring_buffer(struct drm_device *dev, struct drm_sg_mem *entry = dev->sg; unsigned long tmp_ofs, page_ofs; - tmp_ofs = dev_priv->ring_rptr->offset - - (unsigned long)dev->sg->virtual; + tmp_ofs = dev_priv->ring_rptr->offset - dev->sg->handle; page_ofs = tmp_ofs >> PAGE_SHIFT; - RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR, entry->busaddr[page_ofs]); + RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR, + entry->mem->map->dm_segs[page_ofs].ds_addr); DRM_DEBUG("ring rptr: offset=0x%08lx handle=0x%08lx\n", - (unsigned long)entry->busaddr[page_ofs], - entry->handle + tmp_ofs); + (unsigned long)entry->mem->map->dm_segs[page_ofs].ds_addr, + entry->handle + tmp_ofs); } /* Set ring buffer size */ @@ -1188,9 +1187,8 @@ radeon_do_init_cp(struct drm_device *dev, drm_radeon_init_t *init) + dev_priv->gart_vm_start); else #endif - dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset - - (unsigned long)dev->sg->virtual - + dev_priv->gart_vm_start); + dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset - + dev->sg->handle + dev_priv->gart_vm_start); DRM_DEBUG("dev_priv->gart_size %d\n", dev_priv->gart_size); DRM_DEBUG("dev_priv->gart_vm_start 0x%x\n", dev_priv->gart_vm_start); |