1 /** 2 * \file drm_memory.c 3 * Memory management wrappers for DRM 4 * 5 * \author Rickard E. (Rik) Faith <faith@valinux.com> 6 * \author Gareth Hughes <gareth@valinux.com> 7 */ 8 9 /* 10 * Created: Thu Feb 4 14:00:34 1999 by faith@valinux.com 11 * 12 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 13 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 14 * All Rights Reserved. 15 * 16 * Permission is hereby granted, free of charge, to any person obtaining a 17 * copy of this software and associated documentation files (the "Software"), 18 * to deal in the Software without restriction, including without limitation 19 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 20 * and/or sell copies of the Software, and to permit persons to whom the 21 * Software is furnished to do so, subject to the following conditions: 22 * 23 * The above copyright notice and this permission notice (including the next 24 * paragraph) shall be included in all copies or substantial portions of the 25 * Software. 26 * 27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 30 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 31 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 32 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 33 * OTHER DEALINGS IN THE SOFTWARE. 34 */ 35 36 #include <sys/cdefs.h> 37 #include <dev/drm2/drmP.h> 38 39 #define vunmap(handle) 40 41 #if __OS_HAS_AGP 42 static void *agp_remap(unsigned long offset, unsigned long size, 43 struct drm_device * dev) 44 { 45 /* 46 * FIXME Linux<->FreeBSD: Not implemented. This is never called 47 * on FreeBSD anyway, because drm_agp_mem->cant_use_aperture is 48 * set to 0. 49 */ 50 return NULL; 51 } 52 53 /** Wrapper around agp_free_memory() */ 54 void drm_free_agp(DRM_AGP_MEM * handle, int pages) 55 { 56 device_t agpdev; 57 58 agpdev = agp_find_device(); 59 if (!agpdev || !handle) 60 return; 61 62 agp_free_memory(agpdev, handle); 63 } 64 EXPORT_SYMBOL(drm_free_agp); 65 66 /** Wrapper around agp_bind_memory() */ 67 int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start) 68 { 69 device_t agpdev; 70 71 agpdev = agp_find_device(); 72 if (!agpdev || !handle) 73 return -EINVAL; 74 75 return -agp_bind_memory(agpdev, handle, start * PAGE_SIZE); 76 } 77 78 /** Wrapper around agp_unbind_memory() */ 79 int drm_unbind_agp(DRM_AGP_MEM * handle) 80 { 81 device_t agpdev; 82 83 agpdev = agp_find_device(); 84 if (!agpdev || !handle) 85 return -EINVAL; 86 87 return -agp_unbind_memory(agpdev, handle); 88 } 89 EXPORT_SYMBOL(drm_unbind_agp); 90 91 #else /* __OS_HAS_AGP */ 92 static inline void *agp_remap(unsigned long offset, unsigned long size, 93 struct drm_device * dev) 94 { 95 return NULL; 96 } 97 98 #endif /* agp */ 99 100 void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev) 101 { 102 if (drm_core_has_AGP(dev) && 103 dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP) 104 map->handle = agp_remap(map->offset, map->size, dev); 105 else 106 map->handle = pmap_mapdev(map->offset, map->size); 107 } 108 EXPORT_SYMBOL(drm_core_ioremap); 109 110 void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev) 111 { 112 if (drm_core_has_AGP(dev) && 113 dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP) 114 map->handle = agp_remap(map->offset, map->size, dev); 115 else 116 map->handle = pmap_mapdev_attr(map->offset, map->size, 117 VM_MEMATTR_WRITE_COMBINING); 118 } 119 EXPORT_SYMBOL(drm_core_ioremap_wc); 120 121 void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev) 122 { 123 if (!map->handle || !map->size) 124 return; 125 126 if (drm_core_has_AGP(dev) && 127 dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP) 128 vunmap(map->handle); 129 else 130 pmap_unmapdev(map->handle, map->size); 131 } 132 EXPORT_SYMBOL(drm_core_ioremapfree); 133