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 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
28 #if defined(__FreeBSD__) && __FreeBSD_version >= 500102
29 static int DRM(dma_mmap)(struct cdev *kdev, vm_offset_t offset, vm_paddr_t *paddr,
31 #elif defined(__FreeBSD__)
32 static int DRM(dma_mmap)(dev_t kdev, vm_offset_t offset, int prot)
33 #elif defined(__NetBSD__)
34 static paddr_t DRM(dma_mmap)(dev_t kdev, vm_offset_t offset, int prot)
38 drm_device_dma_t *dma = dev->dma;
39 unsigned long physical;
42 if (dma == NULL || dma->pagelist == NULL)
45 page = offset >> PAGE_SHIFT;
46 physical = dma->pagelist[page];
48 DRM_DEBUG("0x%08lx (page %lu) => 0x%08lx\n", (long)offset, page, physical);
49 #if defined(__FreeBSD__) && __FreeBSD_version >= 500102
53 return atop(physical);
57 #if defined(__FreeBSD__) && __FreeBSD_version >= 500102
58 int DRM(mmap)(struct cdev *kdev, vm_offset_t offset, vm_paddr_t *paddr,
60 #elif defined(__FreeBSD__)
61 int DRM(mmap)(dev_t kdev, vm_offset_t offset, int prot)
62 #elif defined(__NetBSD__)
63 paddr_t DRM(mmap)(dev_t kdev, off_t offset, int prot)
67 drm_local_map_t *map = NULL;
68 drm_map_list_entry_t *listentry = NULL;
71 DRM_GET_PRIV_WITH_RETURN(priv, (DRMFILE)(uintptr_t)DRM_CURRENTPID);
73 if (!priv->authenticated)
74 return DRM_ERR(EACCES);
78 && offset < ptoa(dev->dma->page_count))
79 #if defined(__FreeBSD__) && __FreeBSD_version >= 500102
80 return DRM(dma_mmap)(kdev, offset, paddr, prot);
82 return DRM(dma_mmap)(kdev, offset, prot);
85 /* A sequential search of a linked list is
86 fine here because: 1) there will only be
87 about 5-10 entries in the list and, 2) a
88 DRI client only has to do this mapping
89 once, so it doesn't have to be optimized
90 for performance, even if the list was a
92 TAILQ_FOREACH(listentry, dev->maplist, link) {
94 /* DRM_DEBUG("considering 0x%x..0x%x\n", map->offset, map->offset + map->size - 1);*/
95 if (offset >= map->offset
96 && offset < map->offset + map->size) break;
100 DRM_DEBUG("can't find map\n");
103 if (((map->flags&_DRM_RESTRICTED) && DRM_SUSER(DRM_CURPROC))) {
104 DRM_DEBUG("restricted map\n");
109 case _DRM_FRAME_BUFFER:
112 #if defined(__FreeBSD__) && __FreeBSD_version >= 500102
118 case _DRM_SCATTER_GATHER:
120 #if defined(__FreeBSD__) && __FreeBSD_version >= 500102
121 *paddr = vtophys(offset);
124 return atop(vtophys(offset));
127 return -1; /* This should never happen. */
129 DRM_DEBUG("bailing out\n");