From 5d96c74ff1fe9b2d37e22dbea9882791aae389bf Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 28 Jun 2005 20:58:34 +0000 Subject: - Remove drm_initmap and replace its usage with drm_addmap. This reduces code duplication, and it also hands you the map pointer so you don't need to re-find it. - Remove the permanent maps flag. Instead, for register and framebuffer maps, we always check whether there's already a map of that type and offset around. Move the Radeon map initialization into presetup (first open) so it happens again after every takedown. - Remove the split cleanup of maps between driver takedown (last close) and cleanup (module unload). Instead, always tear down maps on takedown, and drivers can recreate them on first open. - Make MGA always use addmap, instead of allocating consistent memory in the PCI case and then faking up a map for it, which accomplished nearly the same thing, in a different order. Note that the maps are exposed to the user again: we may want to expose a flag to avoid this, but it's not a security concern, and saves us a lot of code. - Remove rmmaps in the MGA driver. Since the function is only called during takedown anyway, we can let them die a natural death. - Make removal of maps happen in one function, which is called by both drm_takedown and drm_rmmap_ioctl. Reviewed by: idr (previous revision) Tested on: mga (old/new/pci dma), radeon, savage --- linux-core/drm_drv.c | 92 ++++++---------------------------------------------- 1 file changed, 10 insertions(+), 82 deletions(-) (limited to 'linux-core/drm_drv.c') diff --git a/linux-core/drm_drv.c b/linux-core/drm_drv.c index 6ed5ce1e..d72d1c37 100644 --- a/linux-core/drm_drv.c +++ b/linux-core/drm_drv.c @@ -135,9 +135,7 @@ drm_ioctl_desc_t drm_ioctls[] = { int drm_takedown(drm_device_t * dev) { drm_magic_entry_t *pt, *next; - drm_map_t *map; drm_map_list_t *r_list; - struct list_head *list, *list_next; drm_vma_entry_t *vma, *vma_next; int i; @@ -145,6 +143,7 @@ int drm_takedown(drm_device_t * dev) if (dev->driver->pretakedown) dev->driver->pretakedown(dev); + DRM_DEBUG("driver pretakedown completed\n"); if (dev->unique) { drm_free(dev->unique, strlen(dev->unique) + 1, DRM_MEM_DRIVER); @@ -195,6 +194,10 @@ int drm_takedown(drm_device_t * dev) dev->agp->acquired = 0; dev->agp->enabled = 0; } + if (drm_core_check_feature(dev, DRIVER_SG) && dev->sg) { + drm_sg_cleanup(dev->sg); + dev->sg = NULL; + } /* Clear vma list (only built for debugging) */ if (dev->vmalist) { @@ -206,45 +209,10 @@ int drm_takedown(drm_device_t * dev) } if (dev->maplist) { - list_for_each_safe(list, list_next, &dev->maplist->head) { - r_list = (drm_map_list_t *) list; - - if ((map = r_list->map)) { - drm_dma_handle_t dmah; - - switch (map->type) { - case _DRM_REGISTERS: - case _DRM_FRAME_BUFFER: - continue; - - case _DRM_SHM: - vfree(map->handle); - break; - - case _DRM_AGP: - /* Do nothing here, because this is all - * handled in the AGP/GART driver. - */ - break; - case _DRM_SCATTER_GATHER: - /* Handle it */ - if (drm_core_check_feature - (dev, DRIVER_SG) && dev->sg) { - drm_sg_cleanup(dev->sg); - dev->sg = NULL; - } - break; - case _DRM_CONSISTENT: - dmah.vaddr = map->handle; - dmah.busaddr = map->offset; - dmah.size = map->size; - __drm_pci_free(dev, &dmah); - break; - } - drm_free(map, sizeof(*map), DRM_MEM_MAPS); - } - list_del(list); - drm_free(r_list, sizeof(*r_list), DRM_MEM_MAPS); + while (!list_empty(&dev->maplist->head)) { + struct list_head *list = dev->maplist->head.next; + r_list = list_entry(list, drm_map_list_t, head); + drm_rmmap_locked(dev, r_list->map); } } @@ -275,6 +243,7 @@ int drm_takedown(drm_device_t * dev) } up(&dev->struct_sem); + DRM_DEBUG("takedown completed\n"); return 0; } @@ -368,9 +337,6 @@ EXPORT_SYMBOL(drm_init); */ static void __exit drm_cleanup(drm_device_t * dev) { - drm_map_t *map; - drm_map_list_t *r_list; - struct list_head *list, *list_next; DRM_DEBUG("\n"); if (!dev) { @@ -381,44 +347,6 @@ static void __exit drm_cleanup(drm_device_t * dev) drm_takedown(dev); if (dev->maplist) { - list_for_each_safe(list, list_next, &dev->maplist->head) { - r_list = (drm_map_list_t *) list; - - if ((map = r_list->map)) { - switch (map->type) { - case _DRM_REGISTERS: - drm_ioremapfree(map->handle, map->size, - dev); - break; - - case _DRM_FRAME_BUFFER: - if (drm_core_has_MTRR(dev)) { - if (map->mtrr >= 0) { - int retcode; - retcode = - mtrr_del(map->mtrr, - map-> - offset, - map->size); - DRM_DEBUG - ("mtrr_del=%d\n", - retcode); - } - } - break; - - case _DRM_SHM: - case _DRM_AGP: - case _DRM_SCATTER_GATHER: - case _DRM_CONSISTENT: - DRM_DEBUG("Extra maplist item\n"); - break; - } - drm_free(map, sizeof(*map), DRM_MEM_MAPS); - } - list_del(list); - drm_free(r_list, sizeof(*r_list), DRM_MEM_MAPS); - } drm_free(dev->maplist, sizeof(*dev->maplist), DRM_MEM_MAPS); dev->maplist = NULL; } -- cgit v1.2.3