3 * Memory management wrappers for DRM
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
10 * Created: Thu Feb 4 14:00:34 1999 by faith@valinux.com
12 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
13 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
14 * All Rights Reserved.
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:
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
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.
36 #include <sys/cdefs.h>
37 #include <dev/drm2/drmP.h>
39 #define vunmap(handle)
42 static void *agp_remap(unsigned long offset, unsigned long size,
43 struct drm_device * dev)
46 * FIXME Linux<->FreeBSD: Not implemented. This is never called
47 * on FreeBSD anyway, because drm_agp_mem->cant_use_aperture is
53 /** Wrapper around agp_free_memory() */
54 void drm_free_agp(DRM_AGP_MEM * handle, int pages)
58 agpdev = agp_find_device();
59 if (!agpdev || !handle)
62 agp_free_memory(agpdev, handle);
64 EXPORT_SYMBOL(drm_free_agp);
66 /** Wrapper around agp_bind_memory() */
67 int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start)
71 agpdev = agp_find_device();
72 if (!agpdev || !handle)
75 return -agp_bind_memory(agpdev, handle, start * PAGE_SIZE);
78 /** Wrapper around agp_unbind_memory() */
79 int drm_unbind_agp(DRM_AGP_MEM * handle)
83 agpdev = agp_find_device();
84 if (!agpdev || !handle)
87 return -agp_unbind_memory(agpdev, handle);
89 EXPORT_SYMBOL(drm_unbind_agp);
91 #else /* __OS_HAS_AGP */
92 static inline void *agp_remap(unsigned long offset, unsigned long size,
93 struct drm_device * dev)
100 void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
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);
106 map->handle = pmap_mapdev(map->offset, map->size);
108 EXPORT_SYMBOL(drm_core_ioremap);
110 void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
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);
116 map->handle = pmap_mapdev_attr(map->offset, map->size,
117 VM_MEMATTR_WRITE_COMBINING);
119 EXPORT_SYMBOL(drm_core_ioremap_wc);
121 void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
123 if (!map->handle || !map->size)
126 if (drm_core_has_AGP(dev) &&
127 dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
130 pmap_unmapdev(map->handle, map->size);
132 EXPORT_SYMBOL(drm_core_ioremapfree);