FreeBSD/Linux Kernel Cross Reference
sys/dev/drm/drm_vm.h
1 /*-
2 * Copyright 2003 Eric Anholt
3 * All Rights Reserved.
4 *
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:
11 *
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
14 * Software.
15 *
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.
23 *
24 *
25 * $FreeBSD$
26 */
27
28 #if defined(__FreeBSD__) && __FreeBSD_version >= 500102
29 static int DRM(dma_mmap)(struct cdev *kdev, vm_offset_t offset, vm_paddr_t *paddr,
30 int prot)
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)
35 #endif
36 {
37 DRM_DEVICE;
38 drm_device_dma_t *dma = dev->dma;
39 unsigned long physical;
40 unsigned long page;
41
42 if (dma == NULL || dma->pagelist == NULL)
43 return -1;
44
45 page = offset >> PAGE_SHIFT;
46 physical = dma->pagelist[page];
47
48 DRM_DEBUG("0x%08lx (page %lu) => 0x%08lx\n", (long)offset, page, physical);
49 #if defined(__FreeBSD__) && __FreeBSD_version >= 500102
50 *paddr = physical;
51 return 0;
52 #else
53 return atop(physical);
54 #endif
55 }
56
57 #if defined(__FreeBSD__) && __FreeBSD_version >= 500102
58 int DRM(mmap)(struct cdev *kdev, vm_offset_t offset, vm_paddr_t *paddr,
59 int prot)
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)
64 #endif
65 {
66 DRM_DEVICE;
67 drm_local_map_t *map = NULL;
68 drm_map_list_entry_t *listentry = NULL;
69 drm_file_t *priv;
70
71 DRM_GET_PRIV_WITH_RETURN(priv, (DRMFILE)(uintptr_t)DRM_CURRENTPID);
72
73 if (!priv->authenticated)
74 return DRM_ERR(EACCES);
75
76 if (dev->dma
77 && offset >= 0
78 && offset < ptoa(dev->dma->page_count))
79 #if defined(__FreeBSD__) && __FreeBSD_version >= 500102
80 return DRM(dma_mmap)(kdev, offset, paddr, prot);
81 #else
82 return DRM(dma_mmap)(kdev, offset, prot);
83 #endif
84
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
91 bit longer. */
92 TAILQ_FOREACH(listentry, dev->maplist, link) {
93 map = listentry->map;
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;
97 }
98
99 if (!listentry) {
100 DRM_DEBUG("can't find map\n");
101 return -1;
102 }
103 if (((map->flags&_DRM_RESTRICTED) && DRM_SUSER(DRM_CURPROC))) {
104 DRM_DEBUG("restricted map\n");
105 return -1;
106 }
107
108 switch (map->type) {
109 case _DRM_FRAME_BUFFER:
110 case _DRM_REGISTERS:
111 case _DRM_AGP:
112 #if defined(__FreeBSD__) && __FreeBSD_version >= 500102
113 *paddr = offset;
114 return 0;
115 #else
116 return atop(offset);
117 #endif
118 case _DRM_SCATTER_GATHER:
119 case _DRM_SHM:
120 #if defined(__FreeBSD__) && __FreeBSD_version >= 500102
121 *paddr = vtophys(offset);
122 return 0;
123 #else
124 return atop(vtophys(offset));
125 #endif
126 default:
127 return -1; /* This should never happen. */
128 }
129 DRM_DEBUG("bailing out\n");
130
131 return -1;
132 }
133
Cache object: 1a43b9bd46c58b675f50b7998b1d4946
|