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