MASSIVE reorganization of the device operations vector. Change cdevsw
[dragonfly.git] / sys / dev / drm / drm_vm.h
... / ...
CommitLineData
1/*
2 * $FreeBSD: src/sys/dev/drm/drm_vm.h,v 1.6.2.1 2003/04/26 07:05:29 anholt Exp $
3 * $DragonFly: src/sys/dev/drm/Attic/drm_vm.h,v 1.4 2006/07/28 02:17:36 dillon Exp $
4 */
5
6#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
7static int DRM(dma_mmap)(dev_t kdev, vm_offset_t offset, vm_paddr_t *paddr,
8 int prot)
9#elif defined(__DragonFly__)
10static int DRM(dma_mmap)(struct dev_mmap_args *ap)
11#elif defined(__FreeBSD__)
12static int DRM(dma_mmap)(dev_t kdev, vm_offset_t offset, int prot)
13#elif defined(__NetBSD__)
14static paddr_t DRM(dma_mmap)(dev_t kdev, vm_offset_t offset, int prot)
15#endif
16{
17#ifdef __DragonFly__
18 dev_t kdev = ap->a_head.a_dev;
19 vm_offset_t offset = ap->a_offset;
20#endif
21 DRM_DEVICE;
22 drm_device_dma_t *dma = dev->dma;
23 unsigned long physical;
24 unsigned long page;
25
26 if (!dma) return -1; /* Error */
27 if (!dma->pagelist) return -1; /* Nothing allocated */
28
29 page = offset >> PAGE_SHIFT;
30 physical = dma->pagelist[page];
31
32 DRM_DEBUG("0x%08lx (page %lu) => 0x%08lx\n", (long)offset, page, physical);
33#if defined(__DragonFly__)
34 ap->a_result = physical;
35 return 0;
36#elif defined(__FreeBSD__) && __FreeBSD_version >= 500102
37 *paddr = physical;
38 return 0;
39#else
40 return atop(physical);
41#endif
42}
43
44#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
45int DRM(mmap)(dev_t kdev, vm_offset_t offset, vm_paddr_t *paddr,
46 int prot)
47#elif defined(__DragonFly__)
48int DRM(mmap)(struct dev_mmap_args *ap)
49#elif defined(__NetBSD__)
50paddr_t DRM(mmap)(dev_t kdev, off_t offset, int prot)
51#endif
52{
53 dev_t kdev = ap->a_head.a_dev;
54 DRM_DEVICE;
55 drm_local_map_t *map = NULL;
56 drm_map_list_entry_t *listentry=NULL;
57 drm_file_t *priv;
58
59 priv = DRM(find_file_by_proc)(dev, DRM_CURPROC);
60 if (!priv) {
61 DRM_DEBUG("can't find authenticator\n");
62 return EINVAL;
63 }
64
65 if (!priv->authenticated)
66 return DRM_ERR(EACCES);
67
68 if (dev->dma
69 && ap->a_offset >= 0
70 && ap->a_offset < ptoa(dev->dma->page_count))
71#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
72 return DRM(dma_mmap)(kdev, offset, paddr, prot);
73#elif defined(__DragonFly__)
74 return DRM(dma_mmap)(ap);
75#else
76 return DRM(dma_mmap)(kdev, ap->a_offset, ap->a_nprot);
77#endif
78
79 /* A sequential search of a linked list is
80 fine here because: 1) there will only be
81 about 5-10 entries in the list and, 2) a
82 DRI client only has to do this mapping
83 once, so it doesn't have to be optimized
84 for performance, even if the list was a
85 bit longer. */
86 TAILQ_FOREACH(listentry, dev->maplist, link) {
87 map = listentry->map;
88/* DRM_DEBUG("considering 0x%x..0x%x\n", map->offset, map->offset + map->size - 1);*/
89 if (ap->a_offset >= map->offset
90 && ap->a_offset < map->offset + map->size) break;
91 }
92
93 if (!listentry) {
94 DRM_DEBUG("can't find map\n");
95 return EINVAL;
96 }
97 if (((map->flags&_DRM_RESTRICTED) && DRM_SUSER(DRM_CURPROC))) {
98 DRM_DEBUG("restricted map\n");
99 return EINVAL;
100 }
101
102 switch (map->type) {
103 case _DRM_FRAME_BUFFER:
104 case _DRM_REGISTERS:
105 case _DRM_AGP:
106#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
107 *paddr = ap->a_offset;
108 return 0;
109#elif defined(__DragonFly__)
110 ap->a_result = atop(ap->a_offset);
111 return 0;
112#else
113 return atop(ap->a_offset);
114#endif
115 case _DRM_SCATTER_GATHER:
116 case _DRM_SHM:
117#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
118 *paddr = vtophys(ap->a_offset);
119 return 0;
120#elif defined(__DragonFly__)
121 ap->a_result = vtophys(ap->a_offset);
122 return 0;
123#else
124 return atop(vtophys(ap->a_offset));
125#endif
126 default:
127 return EINVAL; /* This should never happen. */
128 }
129 DRM_DEBUG("bailing out\n");
130
131 return EINVAL;
132}
133