2 * Copyright 2003 Eric Anholt
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * ERIC ANHOLT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #if defined(__FreeBSD__) && __FreeBSD_version >= 500102
28 int drm_mmap(struct cdev *kdev, vm_offset_t offset, vm_paddr_t *paddr,
30 #elif defined(__FreeBSD__)
31 int drm_mmap(dev_t kdev, vm_offset_t offset, int prot)
32 #elif defined(__NetBSD__) || defined(__OpenBSD__)
33 paddr_t drm_mmap(dev_t kdev, off_t offset, int prot)
42 priv = drm_find_file_by_proc(dev, DRM_CURPROC);
45 DRM_ERROR("can't find authenticator\n");
49 if (!priv->authenticated)
50 return DRM_ERR(EACCES);
52 if (dev->dma && offset >= 0 && offset < ptoa(dev->dma->page_count)) {
53 drm_device_dma_t *dma = dev->dma;
55 DRM_SPINLOCK(&dev->dma_lock);
57 if (dma->pagelist != NULL) {
58 unsigned long page = offset >> PAGE_SHIFT;
59 unsigned long phys = dma->pagelist[page];
61 #if defined(__FreeBSD__) && __FreeBSD_version >= 500102
63 DRM_SPINUNLOCK(&dev->dma_lock);
69 DRM_SPINUNLOCK(&dev->dma_lock);
72 DRM_SPINUNLOCK(&dev->dma_lock);
75 /* A sequential search of a linked list is
76 fine here because: 1) there will only be
77 about 5-10 entries in the list and, 2) a
78 DRI client only has to do this mapping
79 once, so it doesn't have to be optimized
80 for performance, even if the list was a
83 TAILQ_FOREACH(map, &dev->maplist, link) {
84 if (offset >= map->offset && offset < map->offset + map->size)
90 DRM_DEBUG("can't find map\n");
93 if (((map->flags&_DRM_RESTRICTED) && !DRM_SUSER(DRM_CURPROC))) {
95 DRM_DEBUG("restricted map\n");
102 case _DRM_FRAME_BUFFER:
105 #if defined(__FreeBSD__) && __FreeBSD_version >= 500102
111 case _DRM_SCATTER_GATHER:
113 #if defined(__FreeBSD__) && __FreeBSD_version >= 500102
114 *paddr = vtophys(offset);
117 return atop(vtophys(offset));
120 return -1; /* This should never happen. */
122 DRM_DEBUG("bailing out\n");