xref: /freebsd/sys/dev/drm2/drm_memory.c (revision 7ae99f80b6661760c5de3edd330b279f04b092a2)
1592ffb21SWarner Losh /**
2592ffb21SWarner Losh  * \file drm_memory.c
3592ffb21SWarner Losh  * Memory management wrappers for DRM
4592ffb21SWarner Losh  *
5592ffb21SWarner Losh  * \author Rickard E. (Rik) Faith <faith@valinux.com>
6592ffb21SWarner Losh  * \author Gareth Hughes <gareth@valinux.com>
7592ffb21SWarner Losh  */
8592ffb21SWarner Losh 
9592ffb21SWarner Losh /*
10592ffb21SWarner Losh  * Created: Thu Feb  4 14:00:34 1999 by faith@valinux.com
11592ffb21SWarner Losh  *
12592ffb21SWarner Losh  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
13592ffb21SWarner Losh  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
14592ffb21SWarner Losh  * All Rights Reserved.
15592ffb21SWarner Losh  *
16592ffb21SWarner Losh  * Permission is hereby granted, free of charge, to any person obtaining a
17592ffb21SWarner Losh  * copy of this software and associated documentation files (the "Software"),
18592ffb21SWarner Losh  * to deal in the Software without restriction, including without limitation
19592ffb21SWarner Losh  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
20592ffb21SWarner Losh  * and/or sell copies of the Software, and to permit persons to whom the
21592ffb21SWarner Losh  * Software is furnished to do so, subject to the following conditions:
22592ffb21SWarner Losh  *
23592ffb21SWarner Losh  * The above copyright notice and this permission notice (including the next
24592ffb21SWarner Losh  * paragraph) shall be included in all copies or substantial portions of the
25592ffb21SWarner Losh  * Software.
26592ffb21SWarner Losh  *
27592ffb21SWarner Losh  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28592ffb21SWarner Losh  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29592ffb21SWarner Losh  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
30592ffb21SWarner Losh  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
31592ffb21SWarner Losh  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
32592ffb21SWarner Losh  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33592ffb21SWarner Losh  * OTHER DEALINGS IN THE SOFTWARE.
34592ffb21SWarner Losh  */
35592ffb21SWarner Losh 
36592ffb21SWarner Losh #include <sys/cdefs.h>
37592ffb21SWarner Losh __FBSDID("$FreeBSD$");
38592ffb21SWarner Losh 
39592ffb21SWarner Losh #include <dev/drm2/drmP.h>
40592ffb21SWarner Losh 
41592ffb21SWarner Losh #define	vunmap(handle)
42592ffb21SWarner Losh 
43592ffb21SWarner Losh #if __OS_HAS_AGP
44592ffb21SWarner Losh static void *agp_remap(unsigned long offset, unsigned long size,
45592ffb21SWarner Losh 		       struct drm_device * dev)
46592ffb21SWarner Losh {
47592ffb21SWarner Losh 	/*
48592ffb21SWarner Losh 	 * FIXME Linux<->FreeBSD: Not implemented. This is never called
49592ffb21SWarner Losh 	 * on FreeBSD anyway, because drm_agp_mem->cant_use_aperture is
50592ffb21SWarner Losh 	 * set to 0.
51592ffb21SWarner Losh 	 */
52592ffb21SWarner Losh 	return NULL;
53592ffb21SWarner Losh }
54592ffb21SWarner Losh 
55592ffb21SWarner Losh /** Wrapper around agp_free_memory() */
56592ffb21SWarner Losh void drm_free_agp(DRM_AGP_MEM * handle, int pages)
57592ffb21SWarner Losh {
58592ffb21SWarner Losh 	device_t agpdev;
59592ffb21SWarner Losh 
60592ffb21SWarner Losh 	agpdev = agp_find_device();
61592ffb21SWarner Losh 	if (!agpdev || !handle)
62592ffb21SWarner Losh 		return;
63592ffb21SWarner Losh 
64592ffb21SWarner Losh 	agp_free_memory(agpdev, handle);
65592ffb21SWarner Losh }
66592ffb21SWarner Losh EXPORT_SYMBOL(drm_free_agp);
67592ffb21SWarner Losh 
68592ffb21SWarner Losh /** Wrapper around agp_bind_memory() */
69592ffb21SWarner Losh int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start)
70592ffb21SWarner Losh {
71592ffb21SWarner Losh 	device_t agpdev;
72592ffb21SWarner Losh 
73592ffb21SWarner Losh 	agpdev = agp_find_device();
74592ffb21SWarner Losh 	if (!agpdev || !handle)
75592ffb21SWarner Losh 		return -EINVAL;
76592ffb21SWarner Losh 
77592ffb21SWarner Losh 	return -agp_bind_memory(agpdev, handle, start * PAGE_SIZE);
78592ffb21SWarner Losh }
79592ffb21SWarner Losh 
80592ffb21SWarner Losh /** Wrapper around agp_unbind_memory() */
81592ffb21SWarner Losh int drm_unbind_agp(DRM_AGP_MEM * handle)
82592ffb21SWarner Losh {
83592ffb21SWarner Losh 	device_t agpdev;
84592ffb21SWarner Losh 
85592ffb21SWarner Losh 	agpdev = agp_find_device();
86592ffb21SWarner Losh 	if (!agpdev || !handle)
87592ffb21SWarner Losh 		return -EINVAL;
88592ffb21SWarner Losh 
89592ffb21SWarner Losh 	return -agp_unbind_memory(agpdev, handle);
90592ffb21SWarner Losh }
91592ffb21SWarner Losh EXPORT_SYMBOL(drm_unbind_agp);
92592ffb21SWarner Losh 
93592ffb21SWarner Losh #else  /*  __OS_HAS_AGP  */
94592ffb21SWarner Losh static inline void *agp_remap(unsigned long offset, unsigned long size,
95592ffb21SWarner Losh 			      struct drm_device * dev)
96592ffb21SWarner Losh {
97592ffb21SWarner Losh 	return NULL;
98592ffb21SWarner Losh }
99592ffb21SWarner Losh 
100592ffb21SWarner Losh #endif				/* agp */
101592ffb21SWarner Losh 
102592ffb21SWarner Losh void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
103592ffb21SWarner Losh {
104592ffb21SWarner Losh 	if (drm_core_has_AGP(dev) &&
105592ffb21SWarner Losh 	    dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
106592ffb21SWarner Losh 		map->handle = agp_remap(map->offset, map->size, dev);
107592ffb21SWarner Losh 	else
108592ffb21SWarner Losh 		map->handle = pmap_mapdev(map->offset, map->size);
109592ffb21SWarner Losh }
110592ffb21SWarner Losh EXPORT_SYMBOL(drm_core_ioremap);
111592ffb21SWarner Losh 
112592ffb21SWarner Losh void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
113592ffb21SWarner Losh {
114592ffb21SWarner Losh 	if (drm_core_has_AGP(dev) &&
115592ffb21SWarner Losh 	    dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
116592ffb21SWarner Losh 		map->handle = agp_remap(map->offset, map->size, dev);
117592ffb21SWarner Losh 	else
118592ffb21SWarner Losh 		map->handle = pmap_mapdev_attr(map->offset, map->size,
119592ffb21SWarner Losh 		    VM_MEMATTR_WRITE_COMBINING);
120592ffb21SWarner Losh }
121592ffb21SWarner Losh EXPORT_SYMBOL(drm_core_ioremap_wc);
122592ffb21SWarner Losh 
123592ffb21SWarner Losh void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
124592ffb21SWarner Losh {
125592ffb21SWarner Losh 	if (!map->handle || !map->size)
126592ffb21SWarner Losh 		return;
127592ffb21SWarner Losh 
128592ffb21SWarner Losh 	if (drm_core_has_AGP(dev) &&
129592ffb21SWarner Losh 	    dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
130592ffb21SWarner Losh 		vunmap(map->handle);
131592ffb21SWarner Losh 	else
132*7ae99f80SJohn Baldwin 		pmap_unmapdev(map->handle, map->size);
133592ffb21SWarner Losh }
134592ffb21SWarner Losh EXPORT_SYMBOL(drm_core_ioremapfree);
135