xref: /freebsd/sys/dev/drm2/drm_memory.c (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
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 __FBSDID("$FreeBSD$");
38 
39 #include <dev/drm2/drmP.h>
40 
41 #define	vunmap(handle)
42 
43 #if __OS_HAS_AGP
44 static void *agp_remap(unsigned long offset, unsigned long size,
45 		       struct drm_device * dev)
46 {
47 	/*
48 	 * FIXME Linux<->FreeBSD: Not implemented. This is never called
49 	 * on FreeBSD anyway, because drm_agp_mem->cant_use_aperture is
50 	 * set to 0.
51 	 */
52 	return NULL;
53 }
54 
55 /** Wrapper around agp_free_memory() */
56 void drm_free_agp(DRM_AGP_MEM * handle, int pages)
57 {
58 	device_t agpdev;
59 
60 	agpdev = agp_find_device();
61 	if (!agpdev || !handle)
62 		return;
63 
64 	agp_free_memory(agpdev, handle);
65 }
66 EXPORT_SYMBOL(drm_free_agp);
67 
68 /** Wrapper around agp_bind_memory() */
69 int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start)
70 {
71 	device_t agpdev;
72 
73 	agpdev = agp_find_device();
74 	if (!agpdev || !handle)
75 		return -EINVAL;
76 
77 	return -agp_bind_memory(agpdev, handle, start * PAGE_SIZE);
78 }
79 
80 /** Wrapper around agp_unbind_memory() */
81 int drm_unbind_agp(DRM_AGP_MEM * handle)
82 {
83 	device_t agpdev;
84 
85 	agpdev = agp_find_device();
86 	if (!agpdev || !handle)
87 		return -EINVAL;
88 
89 	return -agp_unbind_memory(agpdev, handle);
90 }
91 EXPORT_SYMBOL(drm_unbind_agp);
92 
93 #else  /*  __OS_HAS_AGP  */
94 static inline void *agp_remap(unsigned long offset, unsigned long size,
95 			      struct drm_device * dev)
96 {
97 	return NULL;
98 }
99 
100 #endif				/* agp */
101 
102 void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
103 {
104 	if (drm_core_has_AGP(dev) &&
105 	    dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
106 		map->handle = agp_remap(map->offset, map->size, dev);
107 	else
108 		map->handle = pmap_mapdev(map->offset, map->size);
109 }
110 EXPORT_SYMBOL(drm_core_ioremap);
111 
112 void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
113 {
114 	if (drm_core_has_AGP(dev) &&
115 	    dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
116 		map->handle = agp_remap(map->offset, map->size, dev);
117 	else
118 		map->handle = pmap_mapdev_attr(map->offset, map->size,
119 		    VM_MEMATTR_WRITE_COMBINING);
120 }
121 EXPORT_SYMBOL(drm_core_ioremap_wc);
122 
123 void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
124 {
125 	if (!map->handle || !map->size)
126 		return;
127 
128 	if (drm_core_has_AGP(dev) &&
129 	    dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
130 		vunmap(map->handle);
131 	else
132 		pmap_unmapdev(map->handle, map->size);
133 }
134 EXPORT_SYMBOL(drm_core_ioremapfree);
135