xref: /freebsd/sys/dev/drm2/drm_memory.c (revision 685dc743)
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 #include <dev/drm2/drmP.h>
38592ffb21SWarner Losh 
39592ffb21SWarner Losh #define	vunmap(handle)
40592ffb21SWarner Losh 
41592ffb21SWarner Losh #if __OS_HAS_AGP
agp_remap(unsigned long offset,unsigned long size,struct drm_device * dev)42592ffb21SWarner Losh static void *agp_remap(unsigned long offset, unsigned long size,
43592ffb21SWarner Losh 		       struct drm_device * dev)
44592ffb21SWarner Losh {
45592ffb21SWarner Losh 	/*
46592ffb21SWarner Losh 	 * FIXME Linux<->FreeBSD: Not implemented. This is never called
47592ffb21SWarner Losh 	 * on FreeBSD anyway, because drm_agp_mem->cant_use_aperture is
48592ffb21SWarner Losh 	 * set to 0.
49592ffb21SWarner Losh 	 */
50592ffb21SWarner Losh 	return NULL;
51592ffb21SWarner Losh }
52592ffb21SWarner Losh 
53592ffb21SWarner Losh /** Wrapper around agp_free_memory() */
drm_free_agp(DRM_AGP_MEM * handle,int pages)54592ffb21SWarner Losh void drm_free_agp(DRM_AGP_MEM * handle, int pages)
55592ffb21SWarner Losh {
56592ffb21SWarner Losh 	device_t agpdev;
57592ffb21SWarner Losh 
58592ffb21SWarner Losh 	agpdev = agp_find_device();
59592ffb21SWarner Losh 	if (!agpdev || !handle)
60592ffb21SWarner Losh 		return;
61592ffb21SWarner Losh 
62592ffb21SWarner Losh 	agp_free_memory(agpdev, handle);
63592ffb21SWarner Losh }
64592ffb21SWarner Losh EXPORT_SYMBOL(drm_free_agp);
65592ffb21SWarner Losh 
66592ffb21SWarner Losh /** Wrapper around agp_bind_memory() */
drm_bind_agp(DRM_AGP_MEM * handle,unsigned int start)67592ffb21SWarner Losh int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start)
68592ffb21SWarner Losh {
69592ffb21SWarner Losh 	device_t agpdev;
70592ffb21SWarner Losh 
71592ffb21SWarner Losh 	agpdev = agp_find_device();
72592ffb21SWarner Losh 	if (!agpdev || !handle)
73592ffb21SWarner Losh 		return -EINVAL;
74592ffb21SWarner Losh 
75592ffb21SWarner Losh 	return -agp_bind_memory(agpdev, handle, start * PAGE_SIZE);
76592ffb21SWarner Losh }
77592ffb21SWarner Losh 
78592ffb21SWarner Losh /** Wrapper around agp_unbind_memory() */
drm_unbind_agp(DRM_AGP_MEM * handle)79592ffb21SWarner Losh int drm_unbind_agp(DRM_AGP_MEM * handle)
80592ffb21SWarner Losh {
81592ffb21SWarner Losh 	device_t agpdev;
82592ffb21SWarner Losh 
83592ffb21SWarner Losh 	agpdev = agp_find_device();
84592ffb21SWarner Losh 	if (!agpdev || !handle)
85592ffb21SWarner Losh 		return -EINVAL;
86592ffb21SWarner Losh 
87592ffb21SWarner Losh 	return -agp_unbind_memory(agpdev, handle);
88592ffb21SWarner Losh }
89592ffb21SWarner Losh EXPORT_SYMBOL(drm_unbind_agp);
90592ffb21SWarner Losh 
91592ffb21SWarner Losh #else  /*  __OS_HAS_AGP  */
agp_remap(unsigned long offset,unsigned long size,struct drm_device * dev)92592ffb21SWarner Losh static inline void *agp_remap(unsigned long offset, unsigned long size,
93592ffb21SWarner Losh 			      struct drm_device * dev)
94592ffb21SWarner Losh {
95592ffb21SWarner Losh 	return NULL;
96592ffb21SWarner Losh }
97592ffb21SWarner Losh 
98592ffb21SWarner Losh #endif				/* agp */
99592ffb21SWarner Losh 
drm_core_ioremap(struct drm_local_map * map,struct drm_device * dev)100592ffb21SWarner Losh void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
101592ffb21SWarner Losh {
102592ffb21SWarner Losh 	if (drm_core_has_AGP(dev) &&
103592ffb21SWarner Losh 	    dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
104592ffb21SWarner Losh 		map->handle = agp_remap(map->offset, map->size, dev);
105592ffb21SWarner Losh 	else
106592ffb21SWarner Losh 		map->handle = pmap_mapdev(map->offset, map->size);
107592ffb21SWarner Losh }
108592ffb21SWarner Losh EXPORT_SYMBOL(drm_core_ioremap);
109592ffb21SWarner Losh 
drm_core_ioremap_wc(struct drm_local_map * map,struct drm_device * dev)110592ffb21SWarner Losh void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
111592ffb21SWarner Losh {
112592ffb21SWarner Losh 	if (drm_core_has_AGP(dev) &&
113592ffb21SWarner Losh 	    dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
114592ffb21SWarner Losh 		map->handle = agp_remap(map->offset, map->size, dev);
115592ffb21SWarner Losh 	else
116592ffb21SWarner Losh 		map->handle = pmap_mapdev_attr(map->offset, map->size,
117592ffb21SWarner Losh 		    VM_MEMATTR_WRITE_COMBINING);
118592ffb21SWarner Losh }
119592ffb21SWarner Losh EXPORT_SYMBOL(drm_core_ioremap_wc);
120592ffb21SWarner Losh 
drm_core_ioremapfree(struct drm_local_map * map,struct drm_device * dev)121592ffb21SWarner Losh void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
122592ffb21SWarner Losh {
123592ffb21SWarner Losh 	if (!map->handle || !map->size)
124592ffb21SWarner Losh 		return;
125592ffb21SWarner Losh 
126592ffb21SWarner Losh 	if (drm_core_has_AGP(dev) &&
127592ffb21SWarner Losh 	    dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
128592ffb21SWarner Losh 		vunmap(map->handle);
129592ffb21SWarner Losh 	else
1307ae99f80SJohn Baldwin 		pmap_unmapdev(map->handle, map->size);
131592ffb21SWarner Losh }
132592ffb21SWarner Losh EXPORT_SYMBOL(drm_core_ioremapfree);
133