Fri Aug 7 22:51:05 2009 UTC ()
remove some netbsd specific code that does nothing.


(mrg)
diff -r1.12 -r1.13 src/sys/external/bsd/drm/dist/bsd-core/drmP.h
diff -r1.5 -r1.6 src/sys/external/bsd/drm/dist/bsd-core/drm_fops.c

cvs diff -r1.12 -r1.13 src/sys/external/bsd/drm/dist/bsd-core/drmP.h (switch to unified diff)

--- src/sys/external/bsd/drm/dist/bsd-core/drmP.h 2009/06/20 01:07:09 1.12
+++ src/sys/external/bsd/drm/dist/bsd-core/drmP.h 2009/08/07 22:51:04 1.13
@@ -1,1263 +1,1260 @@ @@ -1,1263 +1,1260 @@
1/* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*- 1/* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*-
2 * Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com 2 * Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com
3 */ 3 */
4/*- 4/*-
5 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 5 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a 9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"), 10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation 11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the 13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions: 14 * Software is furnished to do so, subject to the following conditions:
15 * 15 *
16 * The above copyright notice and this permission notice (including the next 16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the 17 * paragraph) shall be included in all copies or substantial portions of the
18 * Software. 18 * Software.
19 * 19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 23 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE. 26 * OTHER DEALINGS IN THE SOFTWARE.
27 * 27 *
28 * Authors: 28 * Authors:
29 * Rickard E. (Rik) Faith <faith@valinux.com> 29 * Rickard E. (Rik) Faith <faith@valinux.com>
30 * Gareth Hughes <gareth@valinux.com> 30 * Gareth Hughes <gareth@valinux.com>
31 * 31 *
32 */ 32 */
33 33
34#ifndef _DRM_P_H_ 34#ifndef _DRM_P_H_
35#define _DRM_P_H_ 35#define _DRM_P_H_
36 36
37#if defined(_KERNEL) || defined(__KERNEL__) 37#if defined(_KERNEL) || defined(__KERNEL__)
38 38
39struct drm_device; 39struct drm_device;
40struct drm_file; 40struct drm_file;
41 41
42#if defined(__NetBSD__) && defined(_KERNEL_OPT) 42#if defined(__NetBSD__) && defined(_KERNEL_OPT)
43#include "opt_drm.h" 43#include "opt_drm.h"
44#endif 44#endif
45 45
46#include <sys/param.h> 46#include <sys/param.h>
47#include <sys/queue.h> 47#include <sys/queue.h>
48#include <sys/malloc.h> 48#include <sys/malloc.h>
49#include <sys/kernel.h> 49#include <sys/kernel.h>
50#include <sys/module.h> 50#include <sys/module.h>
51#include <sys/systm.h> 51#include <sys/systm.h>
52#include <sys/conf.h> 52#include <sys/conf.h>
53#include <sys/stat.h> 53#include <sys/stat.h>
54#if __FreeBSD_version >= 700000 54#if __FreeBSD_version >= 700000
55#include <sys/priv.h> 55#include <sys/priv.h>
56#endif 56#endif
57#include <sys/proc.h> 57#include <sys/proc.h>
58#include <sys/lock.h> 58#include <sys/lock.h>
59#include <sys/fcntl.h> 59#include <sys/fcntl.h>
60#include <sys/uio.h> 60#include <sys/uio.h>
61#include <sys/filio.h> 61#include <sys/filio.h>
62#include <sys/sysctl.h> 62#include <sys/sysctl.h>
63#include <sys/bus.h> 63#include <sys/bus.h>
64#include <sys/signalvar.h> 64#include <sys/signalvar.h>
65#include <sys/poll.h> 65#include <sys/poll.h>
66#include <sys/tree.h> 66#include <sys/tree.h>
67#ifdef __FreeBSD__ 67#ifdef __FreeBSD__
68#include <vm/vm.h> 68#include <vm/vm.h>
69#include <vm/pmap.h> 69#include <vm/pmap.h>
70#include <vm/vm_extern.h> 70#include <vm/vm_extern.h>
71#include <vm/vm_map.h> 71#include <vm/vm_map.h>
72#include <vm/vm_param.h> 72#include <vm/vm_param.h>
73#include <machine/resource.h> 73#include <machine/resource.h>
74#include <machine/param.h> 74#include <machine/param.h>
75#endif 75#endif
76#include <machine/pmap.h> 76#include <machine/pmap.h>
77#include <machine/bus.h> 77#include <machine/bus.h>
78#include <machine/specialreg.h> 78#include <machine/specialreg.h>
79#include <machine/sysarch.h> 79#include <machine/sysarch.h>
80#include <sys/endian.h> 80#include <sys/endian.h>
81#include <sys/mman.h> 81#include <sys/mman.h>
82#if defined( __FreeBSD__) 82#if defined( __FreeBSD__)
83#include <sys/rman.h> 83#include <sys/rman.h>
84#include <sys/memrange.h> 84#include <sys/memrange.h>
85#if __FreeBSD_version >= 800004 85#if __FreeBSD_version >= 800004
86#include <dev/agp/agpvar.h> 86#include <dev/agp/agpvar.h>
87#else /* __FreeBSD_version >= 800004 */ 87#else /* __FreeBSD_version >= 800004 */
88#include <pci/agpvar.h> 88#include <pci/agpvar.h>
89#endif /* __FreeBSD_version >= 800004 */ 89#endif /* __FreeBSD_version >= 800004 */
90#include <sys/agpio.h> 90#include <sys/agpio.h>
91#include <sys/mutex.h> 91#include <sys/mutex.h>
92#include <dev/pci/pcivar.h> 92#include <dev/pci/pcivar.h>
93#include <dev/pci/pcireg.h> 93#include <dev/pci/pcireg.h>
94#include <sys/selinfo.h> 94#include <sys/selinfo.h>
95#include <sys/bus.h> 95#include <sys/bus.h>
96#elif defined(__NetBSD__) 96#elif defined(__NetBSD__)
97#include <machine/mtrr.h> 97#include <machine/mtrr.h>
98#include <sys/vnode.h> 98#include <sys/vnode.h>
99#include <sys/select.h> 99#include <sys/select.h>
100#include <sys/device.h> 100#include <sys/device.h>
101#include <sys/resourcevar.h> 101#include <sys/resourcevar.h>
102#include <sys/agpio.h> 102#include <sys/agpio.h>
103#include <sys/ttycom.h> 103#include <sys/ttycom.h>
104#include <sys/mman.h> 104#include <sys/mman.h>
105#include <sys/kauth.h> 105#include <sys/kauth.h>
106#include <sys/types.h> 106#include <sys/types.h>
107#include <sys/file.h> 107#include <sys/file.h>
108#include <sys/atomic.h> 108#include <sys/atomic.h>
109#include <sys/workqueue.h> 109#include <sys/workqueue.h>
110#include <uvm/uvm.h> 110#include <uvm/uvm.h>
111#include <dev/pci/pcireg.h> 111#include <dev/pci/pcireg.h>
112#include <dev/pci/pcivar.h> 112#include <dev/pci/pcivar.h>
113#include <dev/pci/agpvar.h> 113#include <dev/pci/agpvar.h>
114#endif 114#endif
115 115
116#include "drm.h" 116#include "drm.h"
117#include "drm_linux_list.h" 117#include "drm_linux_list.h"
118#include "drm_atomic.h" 118#include "drm_atomic.h"
119#include "drm_internal.h" 119#include "drm_internal.h"
120 120
121#ifdef __FreeBSD__ 121#ifdef __FreeBSD__
122#include <opt_drm.h> 122#include <opt_drm.h>
123#endif 123#endif
124 124
125#ifdef DRM_DEBUG 125#ifdef DRM_DEBUG
126#undef DRM_DEBUG 126#undef DRM_DEBUG
127#define DRM_DEBUG_DEFAULT_ON 1 127#define DRM_DEBUG_DEFAULT_ON 1
128#endif /* DRM_DEBUG */ 128#endif /* DRM_DEBUG */
129 129
130#ifdef __FreeBSD__ 130#ifdef __FreeBSD__
131#define DRM_KASSERT(x,y) KASSERT(x,y) 131#define DRM_KASSERT(x,y) KASSERT(x,y)
132#else 132#else
133#define DRM_KASSERT(x,y) KASSERT(x) 133#define DRM_KASSERT(x,y) KASSERT(x)
134#define device_get_softc(x) device_private(x) 134#define device_get_softc(x) device_private(x)
135#define callout_deactivate(x) callout_stop(x) 135#define callout_deactivate(x) callout_stop(x)
136#define callout_drain(x) callout_stop(x) 136#define callout_drain(x) callout_stop(x)
137#endif 137#endif
138 138
139#if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__) 139#if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__)
140#include <sys/file.h> 140#include <sys/file.h>
141#include <sys/proc.h> 141#include <sys/proc.h>
142#include <machine/../linux/linux.h> 142#include <machine/../linux/linux.h>
143#include <machine/../linux/linux_proto.h> 143#include <machine/../linux/linux_proto.h>
144#else 144#else
145/* Either it was defined when it shouldn't be (FreeBSD amd64) or it isn't 145/* Either it was defined when it shouldn't be (FreeBSD amd64) or it isn't
146 * supported on this OS yet. 146 * supported on this OS yet.
147 */ 147 */
148#undef DRM_LINUX 148#undef DRM_LINUX
149#define DRM_LINUX 0 149#define DRM_LINUX 0
150#endif 150#endif
151 151
152/* driver capabilities and requirements mask */ 152/* driver capabilities and requirements mask */
153#define DRIVER_USE_AGP 0x1 153#define DRIVER_USE_AGP 0x1
154#define DRIVER_REQUIRE_AGP 0x2 154#define DRIVER_REQUIRE_AGP 0x2
155#define DRIVER_USE_MTRR 0x4 155#define DRIVER_USE_MTRR 0x4
156#define DRIVER_PCI_DMA 0x8 156#define DRIVER_PCI_DMA 0x8
157#define DRIVER_SG 0x10 157#define DRIVER_SG 0x10
158#define DRIVER_HAVE_DMA 0x20 158#define DRIVER_HAVE_DMA 0x20
159#define DRIVER_HAVE_IRQ 0x40 159#define DRIVER_HAVE_IRQ 0x40
160#define DRIVER_DMA_QUEUE 0x100 160#define DRIVER_DMA_QUEUE 0x100
161 161
162 162
163#define DRM_HASH_SIZE 16 /* Size of key hash table */ 163#define DRM_HASH_SIZE 16 /* Size of key hash table */
164#define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */ 164#define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
165#define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */ 165#define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
166 166
167MALLOC_DECLARE(DRM_MEM_DMA); 167MALLOC_DECLARE(DRM_MEM_DMA);
168MALLOC_DECLARE(DRM_MEM_SAREA); 168MALLOC_DECLARE(DRM_MEM_SAREA);
169MALLOC_DECLARE(DRM_MEM_DRIVER); 169MALLOC_DECLARE(DRM_MEM_DRIVER);
170MALLOC_DECLARE(DRM_MEM_MAGIC); 170MALLOC_DECLARE(DRM_MEM_MAGIC);
171MALLOC_DECLARE(DRM_MEM_IOCTLS); 171MALLOC_DECLARE(DRM_MEM_IOCTLS);
172MALLOC_DECLARE(DRM_MEM_MAPS); 172MALLOC_DECLARE(DRM_MEM_MAPS);
173MALLOC_DECLARE(DRM_MEM_BUFS); 173MALLOC_DECLARE(DRM_MEM_BUFS);
174MALLOC_DECLARE(DRM_MEM_SEGS); 174MALLOC_DECLARE(DRM_MEM_SEGS);
175MALLOC_DECLARE(DRM_MEM_PAGES); 175MALLOC_DECLARE(DRM_MEM_PAGES);
176MALLOC_DECLARE(DRM_MEM_FILES); 176MALLOC_DECLARE(DRM_MEM_FILES);
177MALLOC_DECLARE(DRM_MEM_QUEUES); 177MALLOC_DECLARE(DRM_MEM_QUEUES);
178MALLOC_DECLARE(DRM_MEM_CMDS); 178MALLOC_DECLARE(DRM_MEM_CMDS);
179MALLOC_DECLARE(DRM_MEM_MAPPINGS); 179MALLOC_DECLARE(DRM_MEM_MAPPINGS);
180MALLOC_DECLARE(DRM_MEM_BUFLISTS); 180MALLOC_DECLARE(DRM_MEM_BUFLISTS);
181MALLOC_DECLARE(DRM_MEM_AGPLISTS); 181MALLOC_DECLARE(DRM_MEM_AGPLISTS);
182MALLOC_DECLARE(DRM_MEM_CTXBITMAP); 182MALLOC_DECLARE(DRM_MEM_CTXBITMAP);
183MALLOC_DECLARE(DRM_MEM_SGLISTS); 183MALLOC_DECLARE(DRM_MEM_SGLISTS);
184MALLOC_DECLARE(DRM_MEM_DRAWABLE); 184MALLOC_DECLARE(DRM_MEM_DRAWABLE);
185 185
186#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8) 186#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
187 187
188 /* Internal types and structures */ 188 /* Internal types and structures */
189#define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) 189#define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
190#define DRM_MIN(a,b) ((a)<(b)?(a):(b)) 190#define DRM_MIN(a,b) ((a)<(b)?(a):(b))
191#define DRM_MAX(a,b) ((a)>(b)?(a):(b)) 191#define DRM_MAX(a,b) ((a)>(b)?(a):(b))
192 192
193#define DRM_IF_VERSION(maj, min) (maj << 16 | min) 193#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
194 194
195#define __OS_HAS_AGP 1 195#define __OS_HAS_AGP 1
196 196
197#define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) 197#define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
198#define DRM_DEV_UID 0 198#define DRM_DEV_UID 0
199#define DRM_DEV_GID 0 199#define DRM_DEV_GID 0
200 200
201#define wait_queue_head_t atomic_t 201#define wait_queue_head_t atomic_t
202#define DRM_WAKEUP(w) wakeup((void *)w) 202#define DRM_WAKEUP(w) wakeup((void *)w)
203#define DRM_WAKEUP_INT(w) wakeup(w) 203#define DRM_WAKEUP_INT(w) wakeup(w)
204#define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0) 204#define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0)
205 205
206#if defined(__FreeBSD__) 206#if defined(__FreeBSD__)
207#define DRM_CDEV struct cdev * 207#define DRM_CDEV struct cdev *
208#define DRM_CURPROC curthread 208#define DRM_CURPROC curthread
209#define DRM_STRUCTPROC struct thread 209#define DRM_STRUCTPROC struct thread
210#define DRM_STRUCTCDEVPROC struct thread 210#define DRM_STRUCTCDEVPROC struct thread
211#define DRM_CDEVPROC_REAL(p) (p) 211#define DRM_CDEVPROC_REAL(p) (p)
212#define DRM_IOCTL_DATA caddr_t 212#define DRM_IOCTL_DATA caddr_t
213#define DRM_SPINTYPE struct mtx 213#define DRM_SPINTYPE struct mtx
214#define DRM_SPININIT(l,name) mtx_init(l, name, NULL, MTX_DEF) 214#define DRM_SPININIT(l,name) mtx_init(l, name, NULL, MTX_DEF)
215#define DRM_SPINUNINIT(l) mtx_destroy(l) 215#define DRM_SPINUNINIT(l) mtx_destroy(l)
216#define DRM_SPINLOCK(l) mtx_lock(l) 216#define DRM_SPINLOCK(l) mtx_lock(l)
217#define DRM_SPINUNLOCK(u) mtx_unlock(u) 217#define DRM_SPINUNLOCK(u) mtx_unlock(u)
218#define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \ 218#define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \
219 mtx_lock(l); \ 219 mtx_lock(l); \
220 (void)irqflags; \ 220 (void)irqflags; \
221} while (0) 221} while (0)
222#define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mtx_unlock(u) 222#define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mtx_unlock(u)
223#define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED) 223#define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED)
224#define DRM_CURRENTPID curthread->td_proc->p_pid 224#define DRM_CURRENTPID curthread->td_proc->p_pid
225#define DRM_LOCK() mtx_lock(&dev->dev_lock) 225#define DRM_LOCK() mtx_lock(&dev->dev_lock)
226#define DRM_UNLOCK() mtx_unlock(&dev->dev_lock) 226#define DRM_UNLOCK() mtx_unlock(&dev->dev_lock)
227#define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS) 227#define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
228#elif defined(__NetBSD__) 228#elif defined(__NetBSD__)
229#define DRM_CDEV dev_t 229#define DRM_CDEV dev_t
230#define DRM_CURPROC curproc 230#define DRM_CURPROC curproc
231#define DRM_STRUCTPROC struct proc 231#define DRM_STRUCTPROC struct proc
232#define DRM_STRUCTCDEVPROC struct lwp 232#define DRM_STRUCTCDEVPROC struct lwp
233#define DRM_CDEVPROC_REAL(l) (l)->l_proc 233#define DRM_CDEVPROC_REAL(l) (l)->l_proc
234#define DRM_IOCTL_DATA void * 234#define DRM_IOCTL_DATA void *
235#define DRM_SPINTYPE kmutex_t 235#define DRM_SPINTYPE kmutex_t
236#define DRM_SPININIT(l,name) mutex_init(l, MUTEX_DEFAULT, /*IPL_NONE*/ IPL_VM) 236#define DRM_SPININIT(l,name) mutex_init(l, MUTEX_DEFAULT, /*IPL_NONE*/ IPL_VM)
237#define DRM_SPINUNINIT(l) mutex_destroy(l) 237#define DRM_SPINUNINIT(l) mutex_destroy(l)
238#define DRM_SPINLOCK(l) mutex_enter(l) 238#define DRM_SPINLOCK(l) mutex_enter(l)
239#define DRM_SPINUNLOCK(u) mutex_exit(u) 239#define DRM_SPINUNLOCK(u) mutex_exit(u)
240#define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \ 240#define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \
241 mutex_enter(l); \ 241 mutex_enter(l); \
242 (void)irqflags; \ 242 (void)irqflags; \
243} while (0) 243} while (0)
244#define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mutex_exit(u) 244#define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mutex_exit(u)
245#define DRM_SPINLOCK_ASSERT(l) mutex_owned(l) 245#define DRM_SPINLOCK_ASSERT(l) mutex_owned(l)
246#define DRM_CURRENTPID curproc->p_pid 246#define DRM_CURRENTPID curproc->p_pid
247#define DRM_LOCK() DRM_SPINLOCK(&dev->dev_lock) 247#define DRM_LOCK() DRM_SPINLOCK(&dev->dev_lock)
248#define DRM_UNLOCK() DRM_SPINUNLOCK(&dev->dev_lock) 248#define DRM_UNLOCK() DRM_SPINUNLOCK(&dev->dev_lock)
249#define DRM_SYSCTL_HANDLER_ARGS (SYSCTLFN_ARGS) 249#define DRM_SYSCTL_HANDLER_ARGS (SYSCTLFN_ARGS)
250#define vslock(addr, len) uvm_vslock(curproc->p_vmspace, addr, len, VM_PROT_READ | VM_PROT_WRITE) 250#define vslock(addr, len) uvm_vslock(curproc->p_vmspace, addr, len, VM_PROT_READ | VM_PROT_WRITE)
251#define vsunlock(addr, len) uvm_vsunlock(curproc->p_vmspace, addr, len) 251#define vsunlock(addr, len) uvm_vsunlock(curproc->p_vmspace, addr, len)
252#endif 252#endif
253 253
254#define DRM_IRQ_ARGS void *arg 254#define DRM_IRQ_ARGS void *arg
255#if defined(__FreeBSD__) 255#if defined(__FreeBSD__)
256typedef void irqreturn_t; 256typedef void irqreturn_t;
257#define IRQ_HANDLED /* nothing */ 257#define IRQ_HANDLED /* nothing */
258#define IRQ_NONE /* nothing */ 258#define IRQ_NONE /* nothing */
259#elif defined(__NetBSD__) 259#elif defined(__NetBSD__)
260typedef int irqreturn_t; 260typedef int irqreturn_t;
261#define IRQ_HANDLED 1 261#define IRQ_HANDLED 1
262#define IRQ_NONE 0 262#define IRQ_NONE 0
263#endif 263#endif
264 264
265enum { 265enum {
266 DRM_IS_NOT_AGP, 266 DRM_IS_NOT_AGP,
267 DRM_IS_AGP, 267 DRM_IS_AGP,
268 DRM_MIGHT_BE_AGP 268 DRM_MIGHT_BE_AGP
269}; 269};
270#define DRM_AGP_MEM struct agp_memory_info 270#define DRM_AGP_MEM struct agp_memory_info
271 271
272#if defined(__FreeBSD__) 272#if defined(__FreeBSD__)
273#define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1) 273#define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1)
274#elif defined(__NetBSD__) 274#elif defined(__NetBSD__)
275#define drm_get_device_from_kdev(_kdev) ((minor(_kdev) < DRM_MAXUNITS) ? \ 275#define drm_get_device_from_kdev(_kdev) ((minor(_kdev) < DRM_MAXUNITS) ? \
276 drm_units[minor(_kdev)] : NULL) 276 drm_units[minor(_kdev)] : NULL)
277#endif 277#endif
278 278
279#if defined(__FreeBSD__) 279#if defined(__FreeBSD__)
280#define PAGE_ALIGN(addr) round_page(addr) 280#define PAGE_ALIGN(addr) round_page(addr)
281/* DRM_SUSER returns true if the user is superuser */ 281/* DRM_SUSER returns true if the user is superuser */
282#if __FreeBSD_version >= 700000 282#if __FreeBSD_version >= 700000
283#define DRM_SUSER(p) (priv_check(p, PRIV_DRIVER) == 0) 283#define DRM_SUSER(p) (priv_check(p, PRIV_DRIVER) == 0)
284#else 284#else
285#define DRM_SUSER(p) (suser(p) == 0) 285#define DRM_SUSER(p) (suser(p) == 0)
286#endif 286#endif
287#define DRM_AGP_FIND_DEVICE() agp_find_device() 287#define DRM_AGP_FIND_DEVICE() agp_find_device()
288#define DRM_MTRR_WC MDF_WRITECOMBINE 288#define DRM_MTRR_WC MDF_WRITECOMBINE
289#define jiffies ticks 289#define jiffies ticks
290 290
291#elif defined(__NetBSD__) 291#elif defined(__NetBSD__)
292 292
293#define PAGE_ALIGN(addr) ALIGN(addr) 293#define PAGE_ALIGN(addr) ALIGN(addr)
294#define DRM_SUSER(p) (kauth_cred_getsvuid((p)->p_cred) == 0) 294#define DRM_SUSER(p) (kauth_cred_getsvuid((p)->p_cred) == 0)
295#define DRM_AGP_FIND_DEVICE() agp_find_device(0) 295#define DRM_AGP_FIND_DEVICE() agp_find_device(0)
296#define DRM_MTRR_WC MTRR_TYPE_WC 296#define DRM_MTRR_WC MTRR_TYPE_WC
297#define jiffies hardclock_ticks 297#define jiffies hardclock_ticks
298 298
299#define DRM_MAXUNITS 128 299#define DRM_MAXUNITS 128
300extern struct drm_device *drm_units[]; 300extern struct drm_device *drm_units[];
301 301
302#endif 302#endif
303 303
304/* Capabilities taken from src/sys/dev/pci/pcireg.h. */ 304/* Capabilities taken from src/sys/dev/pci/pcireg.h. */
305#ifndef PCIY_AGP 305#ifndef PCIY_AGP
306#define PCIY_AGP 0x02 306#define PCIY_AGP 0x02
307#endif 307#endif
308 308
309#ifndef PCIY_EXPRESS 309#ifndef PCIY_EXPRESS
310#define PCIY_EXPRESS 0x10 310#define PCIY_EXPRESS 0x10
311#endif 311#endif
312 312
313typedef unsigned long dma_addr_t; 313typedef unsigned long dma_addr_t;
314#if defined(__FreeBSD__) 314#if defined(__FreeBSD__)
315typedef u_int64_t u64; 315typedef u_int64_t u64;
316typedef u_int32_t u32; 316typedef u_int32_t u32;
317typedef u_int16_t u16; 317typedef u_int16_t u16;
318typedef u_int8_t u8; 318typedef u_int8_t u8;
319#else 319#else
320typedef uint64_t u64; 320typedef uint64_t u64;
321typedef uint32_t u32; 321typedef uint32_t u32;
322typedef uint16_t u16; 322typedef uint16_t u16;
323typedef uint8_t u8; 323typedef uint8_t u8;
324#endif 324#endif
325 325
326/* DRM_READMEMORYBARRIER() prevents reordering of reads. 326/* DRM_READMEMORYBARRIER() prevents reordering of reads.
327 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes. 327 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
328 * DRM_MEMORYBARRIER() prevents reordering of reads and writes. 328 * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
329 */ 329 */
330#if defined(__NetBSD__) 330#if defined(__NetBSD__)
331#define DRM_READMEMORYBARRIER() membar_consumer() 331#define DRM_READMEMORYBARRIER() membar_consumer()
332#define DRM_WRITEMEMORYBARRIER() membar_producer() 332#define DRM_WRITEMEMORYBARRIER() membar_producer()
333#define DRM_MEMORYBARRIER() membar_sync() 333#define DRM_MEMORYBARRIER() membar_sync()
334#elif defined(__i386__) 334#elif defined(__i386__)
335#define DRM_READMEMORYBARRIER() __asm __volatile( \ 335#define DRM_READMEMORYBARRIER() __asm __volatile( \
336 "lock; addl $0,0(%%esp)" : : : "memory"); 336 "lock; addl $0,0(%%esp)" : : : "memory");
337#define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory"); 337#define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
338#define DRM_MEMORYBARRIER() __asm __volatile( \ 338#define DRM_MEMORYBARRIER() __asm __volatile( \
339 "lock; addl $0,0(%%esp)" : : : "memory"); 339 "lock; addl $0,0(%%esp)" : : : "memory");
340#elif defined(__alpha__) 340#elif defined(__alpha__)
341#define DRM_READMEMORYBARRIER() alpha_mb(); 341#define DRM_READMEMORYBARRIER() alpha_mb();
342#define DRM_WRITEMEMORYBARRIER() alpha_wmb(); 342#define DRM_WRITEMEMORYBARRIER() alpha_wmb();
343#define DRM_MEMORYBARRIER() alpha_mb(); 343#define DRM_MEMORYBARRIER() alpha_mb();
344#elif defined(__amd64__) 344#elif defined(__amd64__)
345#define DRM_READMEMORYBARRIER() __asm __volatile( \ 345#define DRM_READMEMORYBARRIER() __asm __volatile( \
346 "lock; addl $0,0(%%rsp)" : : : "memory"); 346 "lock; addl $0,0(%%rsp)" : : : "memory");
347#define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory"); 347#define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
348#define DRM_MEMORYBARRIER() __asm __volatile( \ 348#define DRM_MEMORYBARRIER() __asm __volatile( \
349 "lock; addl $0,0(%%rsp)" : : : "memory"); 349 "lock; addl $0,0(%%rsp)" : : : "memory");
350#endif 350#endif
351 351
352#if defined(__FreeBSD__) 352#if defined(__FreeBSD__)
353 353
354#define DRM_READ8(map, offset) \ 354#define DRM_READ8(map, offset) \
355 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \ 355 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \
356 (vm_offset_t)(offset)) 356 (vm_offset_t)(offset))
357#define DRM_READ16(map, offset) \ 357#define DRM_READ16(map, offset) \
358 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \ 358 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \
359 (vm_offset_t)(offset)) 359 (vm_offset_t)(offset))
360#define DRM_READ32(map, offset) \ 360#define DRM_READ32(map, offset) \
361 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \ 361 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \
362 (vm_offset_t)(offset)) 362 (vm_offset_t)(offset))
363#define DRM_WRITE8(map, offset, val) \ 363#define DRM_WRITE8(map, offset, val) \
364 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \ 364 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \
365 (vm_offset_t)(offset)) = val 365 (vm_offset_t)(offset)) = val
366#define DRM_WRITE16(map, offset, val) \ 366#define DRM_WRITE16(map, offset, val) \
367 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \ 367 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \
368 (vm_offset_t)(offset)) = val 368 (vm_offset_t)(offset)) = val
369#define DRM_WRITE32(map, offset, val) \ 369#define DRM_WRITE32(map, offset, val) \
370 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \ 370 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \
371 (vm_offset_t)(offset)) = val 371 (vm_offset_t)(offset)) = val
372 372
373#define DRM_VERIFYAREA_READ( uaddr, size ) \ 373#define DRM_VERIFYAREA_READ( uaddr, size ) \
374 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ)) 374 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
375 375
376#elif defined(__NetBSD__) 376#elif defined(__NetBSD__)
377 377
378typedef vaddr_t vm_offset_t; 378typedef vaddr_t vm_offset_t;
379 379
380#define DRM_READ8(map, offset) \ 380#define DRM_READ8(map, offset) \
381 bus_space_read_1( (map)->bst, (map)->bsh, (offset)) 381 bus_space_read_1( (map)->bst, (map)->bsh, (offset))
382#define DRM_READ16(map, offset) \ 382#define DRM_READ16(map, offset) \
383 bus_space_read_2( (map)->bst, (map)->bsh, (offset)) 383 bus_space_read_2( (map)->bst, (map)->bsh, (offset))
384#define DRM_READ32(map, offset) \ 384#define DRM_READ32(map, offset) \
385 bus_space_read_4( (map)->bst, (map)->bsh, (offset)) 385 bus_space_read_4( (map)->bst, (map)->bsh, (offset))
386#define DRM_WRITE8(map, offset, val) \ 386#define DRM_WRITE8(map, offset, val) \
387 bus_space_write_1((map)->bst, (map)->bsh, (offset), (val)) 387 bus_space_write_1((map)->bst, (map)->bsh, (offset), (val))
388#define DRM_WRITE16(map, offset, val) \ 388#define DRM_WRITE16(map, offset, val) \
389 bus_space_write_2((map)->bst, (map)->bsh, (offset), (val)) 389 bus_space_write_2((map)->bst, (map)->bsh, (offset), (val))
390#define DRM_WRITE32(map, offset, val) \ 390#define DRM_WRITE32(map, offset, val) \
391 bus_space_write_4((map)->bst, (map)->bsh, (offset), (val)) 391 bus_space_write_4((map)->bst, (map)->bsh, (offset), (val))
392 392
393#define DRM_VERIFYAREA_READ( uaddr, size ) \ 393#define DRM_VERIFYAREA_READ( uaddr, size ) \
394 (!uvm_map_checkprot(&(curproc->p_vmspace->vm_map), \ 394 (!uvm_map_checkprot(&(curproc->p_vmspace->vm_map), \
395 (vaddr_t)uaddr, (vaddr_t)uaddr+size, UVM_PROT_READ)) 395 (vaddr_t)uaddr, (vaddr_t)uaddr+size, UVM_PROT_READ))
396 396
397#endif 397#endif
398 398
399#define DRM_COPY_TO_USER(user, kern, size) \ 399#define DRM_COPY_TO_USER(user, kern, size) \
400 copyout(kern, user, size) 400 copyout(kern, user, size)
401#define DRM_COPY_FROM_USER(kern, user, size) \ 401#define DRM_COPY_FROM_USER(kern, user, size) \
402 copyin(user, kern, size) 402 copyin(user, kern, size)
403#define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \ 403#define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
404 copyin(arg2, arg1, arg3) 404 copyin(arg2, arg1, arg3)
405#define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \ 405#define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
406 copyout(arg2, arg1, arg3) 406 copyout(arg2, arg1, arg3)
407#if defined(__FreeBSD__) 407#if defined(__FreeBSD__)
408#define DRM_GET_USER_UNCHECKED(val, uaddr) \ 408#define DRM_GET_USER_UNCHECKED(val, uaddr) \
409 ((val) = fuword32(uaddr), 0) 409 ((val) = fuword32(uaddr), 0)
410#else 410#else
411#define DRM_GET_USER_UNCHECKED(val, uaddr) \ 411#define DRM_GET_USER_UNCHECKED(val, uaddr) \
412 ((val) = fuword(uaddr), 0) 412 ((val) = fuword(uaddr), 0)
413#endif 413#endif
414 414
415#define cpu_to_le32(x) htole32(x) 415#define cpu_to_le32(x) htole32(x)
416#define le32_to_cpu(x) le32toh(x) 416#define le32_to_cpu(x) le32toh(x)
417 417
418#define DRM_HZ hz 418#define DRM_HZ hz
419#define DRM_UDELAY(udelay) DELAY(udelay) 419#define DRM_UDELAY(udelay) DELAY(udelay)
420#define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */ 420#define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
421 421
422#define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \ 422#define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
423 (_map) = (_dev)->context_sareas[_ctx]; \ 423 (_map) = (_dev)->context_sareas[_ctx]; \
424} while(0) 424} while(0)
425 425
426#define LOCK_TEST_WITH_RETURN(dev, file_priv) \ 426#define LOCK_TEST_WITH_RETURN(dev, file_priv) \
427do { \ 427do { \
428 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \ 428 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
429 dev->lock.file_priv != file_priv) { \ 429 dev->lock.file_priv != file_priv) { \
430 DRM_ERROR("%s called without lock held\n", \ 430 DRM_ERROR("%s called without lock held\n", \
431 __FUNCTION__); \ 431 __FUNCTION__); \
432 return EINVAL; \ 432 return EINVAL; \
433 } \ 433 } \
434} while (0) 434} while (0)
435 435
436/* Returns -errno to shared code */ 436/* Returns -errno to shared code */
437#if defined(__FreeBSD__) 437#if defined(__FreeBSD__)
438#define DRM_WAIT_ON( ret, queue, timeout, condition ) \ 438#define DRM_WAIT_ON( ret, queue, timeout, condition ) \
439for ( ret = 0 ; !ret && !(condition) ; ) { \ 439for ( ret = 0 ; !ret && !(condition) ; ) { \
440 DRM_UNLOCK(); \ 440 DRM_UNLOCK(); \
441 mtx_lock(&dev->irq_lock); \ 441 mtx_lock(&dev->irq_lock); \
442 if (!(condition)) \ 442 if (!(condition)) \
443 ret = -mtx_sleep(&(queue), &dev->irq_lock, \ 443 ret = -mtx_sleep(&(queue), &dev->irq_lock, \
444 PCATCH, "drmwtq", (timeout)); \ 444 PCATCH, "drmwtq", (timeout)); \
445 mtx_unlock(&dev->irq_lock); \ 445 mtx_unlock(&dev->irq_lock); \
446 DRM_LOCK(); \ 446 DRM_LOCK(); \
447} 447}
448#elif defined(__NetBSD__) 448#elif defined(__NetBSD__)
449/* Returns -errno to shared code */ 449/* Returns -errno to shared code */
450#define DRM_WAIT_ON( ret, queue, timeout, condition ) \ 450#define DRM_WAIT_ON( ret, queue, timeout, condition ) \
451for ( ret = 0 ; !ret && !(condition) ; ) { \ 451for ( ret = 0 ; !ret && !(condition) ; ) { \
452 DRM_UNLOCK(); \ 452 DRM_UNLOCK(); \
453 mutex_enter(&dev->irq_lock); \ 453 mutex_enter(&dev->irq_lock); \
454 if (!(condition)) \ 454 if (!(condition)) \
455 ret = -mtsleep(&(queue), PCATCH, \ 455 ret = -mtsleep(&(queue), PCATCH, \
456 "drmwtq", (timeout), &dev->irq_lock); \ 456 "drmwtq", (timeout), &dev->irq_lock); \
457 mutex_exit(&dev->irq_lock); \ 457 mutex_exit(&dev->irq_lock); \
458 DRM_LOCK(); \ 458 DRM_LOCK(); \
459} 459}
460#endif 460#endif
461 461
462#define DRM_ERROR(fmt, ...) \ 462#define DRM_ERROR(fmt, ...) \
463 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \ 463 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
464 DRM_CURRENTPID, __func__ , ##__VA_ARGS__) 464 DRM_CURRENTPID, __func__ , ##__VA_ARGS__)
465 465
466#define DRM_INFO(fmt, ...) printf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__) 466#define DRM_INFO(fmt, ...) printf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
467 467
468#define DRM_DEBUG(fmt, ...) do { \ 468#define DRM_DEBUG(fmt, ...) do { \
469 if (drm_debug_flag) \ 469 if (drm_debug_flag) \
470 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \ 470 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
471 __func__ , ##__VA_ARGS__); \ 471 __func__ , ##__VA_ARGS__); \
472} while (0) 472} while (0)
473 473
474typedef struct drm_pci_id_list 474typedef struct drm_pci_id_list
475{ 475{
476 int vendor; 476 int vendor;
477 int device; 477 int device;
478 long driver_private; 478 long driver_private;
479#if defined(__NetBSD__) 479#if defined(__NetBSD__)
480 const char *name; 480 const char *name;
481#else 481#else
482 char *name; 482 char *name;
483#endif 483#endif
484} drm_pci_id_list_t; 484} drm_pci_id_list_t;
485 485
486struct drm_msi_blacklist_entry 486struct drm_msi_blacklist_entry
487{ 487{
488 int vendor; 488 int vendor;
489 int device; 489 int device;
490}; 490};
491 491
492#define DRM_AUTH 0x1 492#define DRM_AUTH 0x1
493#define DRM_MASTER 0x2 493#define DRM_MASTER 0x2
494#define DRM_ROOT_ONLY 0x4 494#define DRM_ROOT_ONLY 0x4
495typedef struct drm_ioctl_desc { 495typedef struct drm_ioctl_desc {
496 unsigned long cmd; 496 unsigned long cmd;
497 int (*func)(struct drm_device *dev, void *data, 497 int (*func)(struct drm_device *dev, void *data,
498 struct drm_file *file_priv); 498 struct drm_file *file_priv);
499 int flags; 499 int flags;
500} drm_ioctl_desc_t; 500} drm_ioctl_desc_t;
501/** 501/**
502 * Creates a driver or general drm_ioctl_desc array entry for the given 502 * Creates a driver or general drm_ioctl_desc array entry for the given
503 * ioctl, for use by drm_ioctl(). 503 * ioctl, for use by drm_ioctl().
504 */ 504 */
505#define DRM_IOCTL_DEF(ioctl, func, flags) \ 505#define DRM_IOCTL_DEF(ioctl, func, flags) \
506 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags} 506 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
507 507
508typedef struct drm_magic_entry { 508typedef struct drm_magic_entry {
509 drm_magic_t magic; 509 drm_magic_t magic;
510 struct drm_file *priv; 510 struct drm_file *priv;
511 struct drm_magic_entry *next; 511 struct drm_magic_entry *next;
512} drm_magic_entry_t; 512} drm_magic_entry_t;
513 513
514typedef struct drm_magic_head { 514typedef struct drm_magic_head {
515 struct drm_magic_entry *head; 515 struct drm_magic_entry *head;
516 struct drm_magic_entry *tail; 516 struct drm_magic_entry *tail;
517} drm_magic_head_t; 517} drm_magic_head_t;
518 518
519typedef struct drm_buf { 519typedef struct drm_buf {
520 int idx; /* Index into master buflist */ 520 int idx; /* Index into master buflist */
521 int total; /* Buffer size */ 521 int total; /* Buffer size */
522 int order; /* log-base-2(total) */ 522 int order; /* log-base-2(total) */
523 int used; /* Amount of buffer in use (for DMA) */ 523 int used; /* Amount of buffer in use (for DMA) */
524 unsigned long offset; /* Byte offset (used internally) */ 524 unsigned long offset; /* Byte offset (used internally) */
525 void *address; /* Address of buffer */ 525 void *address; /* Address of buffer */
526 unsigned long bus_address; /* Bus address of buffer */ 526 unsigned long bus_address; /* Bus address of buffer */
527 struct drm_buf *next; /* Kernel-only: used for free list */ 527 struct drm_buf *next; /* Kernel-only: used for free list */
528 __volatile__ int pending; /* On hardware DMA queue */ 528 __volatile__ int pending; /* On hardware DMA queue */
529 struct drm_file *file_priv; /* Unique identifier of holding process */ 529 struct drm_file *file_priv; /* Unique identifier of holding process */
530 int context; /* Kernel queue for this buffer */ 530 int context; /* Kernel queue for this buffer */
531 enum { 531 enum {
532 DRM_LIST_NONE = 0, 532 DRM_LIST_NONE = 0,
533 DRM_LIST_FREE = 1, 533 DRM_LIST_FREE = 1,
534 DRM_LIST_WAIT = 2, 534 DRM_LIST_WAIT = 2,
535 DRM_LIST_PEND = 3, 535 DRM_LIST_PEND = 3,
536 DRM_LIST_PRIO = 4, 536 DRM_LIST_PRIO = 4,
537 DRM_LIST_RECLAIM = 5 537 DRM_LIST_RECLAIM = 5
538 } list; /* Which list we're on */ 538 } list; /* Which list we're on */
539 539
540 int dev_priv_size; /* Size of buffer private stoarge */ 540 int dev_priv_size; /* Size of buffer private stoarge */
541 void *dev_private; /* Per-buffer private storage */ 541 void *dev_private; /* Per-buffer private storage */
542} drm_buf_t; 542} drm_buf_t;
543 543
544typedef struct drm_freelist { 544typedef struct drm_freelist {
545 int initialized; /* Freelist in use */ 545 int initialized; /* Freelist in use */
546 atomic_t count; /* Number of free buffers */ 546 atomic_t count; /* Number of free buffers */
547 drm_buf_t *next; /* End pointer */ 547 drm_buf_t *next; /* End pointer */
548 548
549 int low_mark; /* Low water mark */ 549 int low_mark; /* Low water mark */
550 int high_mark; /* High water mark */ 550 int high_mark; /* High water mark */
551} drm_freelist_t; 551} drm_freelist_t;
552 552
553typedef struct drm_dma_handle { 553typedef struct drm_dma_handle {
554 void *vaddr; 554 void *vaddr;
555 bus_addr_t busaddr; 555 bus_addr_t busaddr;
556 bus_dma_tag_t tag; 556 bus_dma_tag_t tag;
557 bus_dmamap_t map; 557 bus_dmamap_t map;
558#if defined(__NetBSD__) 558#if defined(__NetBSD__)
559 size_t size; 559 size_t size;
560 size_t nsegs; 560 size_t nsegs;
561 bus_dma_segment_t segs[1]; 561 bus_dma_segment_t segs[1];
562#endif 562#endif
563} drm_dma_handle_t; 563} drm_dma_handle_t;
564 564
565typedef struct drm_buf_entry { 565typedef struct drm_buf_entry {
566 int buf_size; 566 int buf_size;
567 int buf_count; 567 int buf_count;
568 drm_buf_t *buflist; 568 drm_buf_t *buflist;
569 int seg_count; 569 int seg_count;
570 drm_dma_handle_t **seglist; 570 drm_dma_handle_t **seglist;
571 int page_order; 571 int page_order;
572 572
573 drm_freelist_t freelist; 573 drm_freelist_t freelist;
574} drm_buf_entry_t; 574} drm_buf_entry_t;
575 575
576typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t; 576typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
577struct drm_file { 577struct drm_file {
578 TAILQ_ENTRY(drm_file) link; 578 TAILQ_ENTRY(drm_file) link;
579 struct drm_device *dev; 579 struct drm_device *dev;
580 int authenticated; 580 int authenticated;
581 int master; 581 int master;
582 int minor; 582 int minor;
583 pid_t pid; 583 pid_t pid;
584 uid_t uid; 584 uid_t uid;
585#if defined(__NetBSD__) 
586 int refs; 
587#endif 
588 drm_magic_t magic; 585 drm_magic_t magic;
589 unsigned long ioctl_count; 586 unsigned long ioctl_count;
590 void *driver_priv; 587 void *driver_priv;
591}; 588};
592 589
593typedef struct drm_lock_data { 590typedef struct drm_lock_data {
594 struct drm_hw_lock *hw_lock; /* Hardware lock */ 591 struct drm_hw_lock *hw_lock; /* Hardware lock */
595 struct drm_file *file_priv; /* Unique identifier of holding process (NULL is kernel)*/ 592 struct drm_file *file_priv; /* Unique identifier of holding process (NULL is kernel)*/
596 int lock_queue; /* Queue of blocked processes */ 593 int lock_queue; /* Queue of blocked processes */
597 unsigned long lock_time; /* Time of last lock in jiffies */ 594 unsigned long lock_time; /* Time of last lock in jiffies */
598} drm_lock_data_t; 595} drm_lock_data_t;
599 596
600/* This structure, in the struct drm_device, is always initialized while the 597/* This structure, in the struct drm_device, is always initialized while the
601 * device 598 * device
602 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which 599 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
603 * when set marks that no further bufs may be allocated until device teardown 600 * when set marks that no further bufs may be allocated until device teardown
604 * occurs (when the last open of the device has closed). The high/low 601 * occurs (when the last open of the device has closed). The high/low
605 * watermarks of bufs are only touched by the X Server, and thus not 602 * watermarks of bufs are only touched by the X Server, and thus not
606 * concurrently accessed, so no locking is needed. 603 * concurrently accessed, so no locking is needed.
607 */ 604 */
608typedef struct drm_device_dma { 605typedef struct drm_device_dma {
609 drm_buf_entry_t bufs[DRM_MAX_ORDER+1]; 606 drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
610 int buf_count; 607 int buf_count;
611 drm_buf_t **buflist; /* Vector of pointers info bufs */ 608 drm_buf_t **buflist; /* Vector of pointers info bufs */
612 int seg_count; 609 int seg_count;
613 int page_count; 610 int page_count;
614 unsigned long *pagelist; 611 unsigned long *pagelist;
615 unsigned long byte_count; 612 unsigned long byte_count;
616 enum { 613 enum {
617 _DRM_DMA_USE_AGP = 0x01, 614 _DRM_DMA_USE_AGP = 0x01,
618 _DRM_DMA_USE_SG = 0x02 615 _DRM_DMA_USE_SG = 0x02
619 } flags; 616 } flags;
620} drm_device_dma_t; 617} drm_device_dma_t;
621 618
622typedef struct drm_agp_mem { 619typedef struct drm_agp_mem {
623 void *handle; 620 void *handle;
624 unsigned long bound; /* address */ 621 unsigned long bound; /* address */
625 int pages; 622 int pages;
626 struct drm_agp_mem *prev; 623 struct drm_agp_mem *prev;
627 struct drm_agp_mem *next; 624 struct drm_agp_mem *next;
628} drm_agp_mem_t; 625} drm_agp_mem_t;
629 626
630typedef struct drm_agp_head { 627typedef struct drm_agp_head {
631 device_t agpdev; 628 device_t agpdev;
632 struct agp_info info; 629 struct agp_info info;
633 const char *chipset; 630 const char *chipset;
634 drm_agp_mem_t *memory; 631 drm_agp_mem_t *memory;
635 unsigned long mode; 632 unsigned long mode;
636 int enabled; 633 int enabled;
637 int acquired; 634 int acquired;
638 unsigned long base; 635 unsigned long base;
639 int mtrr; 636 int mtrr;
640 int cant_use_aperture; 637 int cant_use_aperture;
641 unsigned long page_mask; 638 unsigned long page_mask;
642} drm_agp_head_t; 639} drm_agp_head_t;
643 640
644typedef struct drm_sg_mem { 641typedef struct drm_sg_mem {
645 unsigned long handle; 642 unsigned long handle;
646 void *virtual; 643 void *virtual;
647 int pages; 644 int pages;
648 dma_addr_t *busaddr; 645 dma_addr_t *busaddr;
649 struct drm_dma_handle *sg_dmah; /* Handle for sg_pages */ 646 struct drm_dma_handle *sg_dmah; /* Handle for sg_pages */
650 struct drm_dma_handle *dmah; /* Handle to PCI memory */ 647 struct drm_dma_handle *dmah; /* Handle to PCI memory */
651 /* for ATI PCIGART table */ 648 /* for ATI PCIGART table */
652} drm_sg_mem_t; 649} drm_sg_mem_t;
653 650
654typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t; 651typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
655 652
656typedef struct drm_local_map { 653typedef struct drm_local_map {
657 unsigned long offset; /* Physical address (0 for SAREA)*/ 654 unsigned long offset; /* Physical address (0 for SAREA)*/
658 unsigned long size; /* Physical size (bytes) */ 655 unsigned long size; /* Physical size (bytes) */
659 enum drm_map_type type; /* Type of memory mapped */ 656 enum drm_map_type type; /* Type of memory mapped */
660 enum drm_map_flags flags; /* Flags */ 657 enum drm_map_flags flags; /* Flags */
661 void *handle; /* User-space: "Handle" to pass to mmap */ 658 void *handle; /* User-space: "Handle" to pass to mmap */
662 /* Kernel-space: kernel-virtual address */ 659 /* Kernel-space: kernel-virtual address */
663 int mtrr; /* Boolean: MTRR used */ 660 int mtrr; /* Boolean: MTRR used */
664 /* Private data */ 661 /* Private data */
665 int rid; /* PCI resource ID for bus_space */ 662 int rid; /* PCI resource ID for bus_space */
666#if defined(__FreeBSD__) 663#if defined(__FreeBSD__)
667 struct resource *bsr; 664 struct resource *bsr;
668#endif 665#endif
669 bus_space_tag_t bst; 666 bus_space_tag_t bst;
670 bus_space_handle_t bsh; 667 bus_space_handle_t bsh;
671 drm_dma_handle_t *dmah; 668 drm_dma_handle_t *dmah;
672#if defined(__NetBSD__) 669#if defined(__NetBSD__)
673 int *cnt; 670 int *cnt;
674 bus_size_t mapsize; 671 bus_size_t mapsize;
675#endif 672#endif
676 TAILQ_ENTRY(drm_local_map) link; 673 TAILQ_ENTRY(drm_local_map) link;
677} drm_local_map_t; 674} drm_local_map_t;
678 675
679TAILQ_HEAD(drm_vbl_sig_list, drm_vbl_sig); 676TAILQ_HEAD(drm_vbl_sig_list, drm_vbl_sig);
680typedef struct drm_vbl_sig { 677typedef struct drm_vbl_sig {
681 TAILQ_ENTRY(drm_vbl_sig) link; 678 TAILQ_ENTRY(drm_vbl_sig) link;
682 unsigned int sequence; 679 unsigned int sequence;
683 int signo; 680 int signo;
684 int pid; 681 int pid;
685} drm_vbl_sig_t; 682} drm_vbl_sig_t;
686 683
687struct drm_vblank_info { 684struct drm_vblank_info {
688 wait_queue_head_t queue; /* vblank wait queue */ 685 wait_queue_head_t queue; /* vblank wait queue */
689 atomic_t count; /* number of VBLANK interrupts */ 686 atomic_t count; /* number of VBLANK interrupts */
690 /* (driver must alloc the right number of counters) */ 687 /* (driver must alloc the right number of counters) */
691 struct drm_vbl_sig_list sigs; /* signal list to send on VBLANK */ 688 struct drm_vbl_sig_list sigs; /* signal list to send on VBLANK */
692 atomic_t refcount; /* number of users of vblank interrupts */ 689 atomic_t refcount; /* number of users of vblank interrupts */
693 u32 last; /* protected by dev->vbl_lock, used */ 690 u32 last; /* protected by dev->vbl_lock, used */
694 /* for wraparound handling */ 691 /* for wraparound handling */
695 int enabled; /* so we don't call enable more than */ 692 int enabled; /* so we don't call enable more than */
696 /* once per disable */ 693 /* once per disable */
697 int inmodeset; /* Display driver is setting mode */ 694 int inmodeset; /* Display driver is setting mode */
698}; 695};
699 696
700/* location of GART table */ 697/* location of GART table */
701#define DRM_ATI_GART_MAIN 1 698#define DRM_ATI_GART_MAIN 1
702#define DRM_ATI_GART_FB 2 699#define DRM_ATI_GART_FB 2
703 700
704#define DRM_ATI_GART_PCI 1 701#define DRM_ATI_GART_PCI 1
705#define DRM_ATI_GART_PCIE 2 702#define DRM_ATI_GART_PCIE 2
706#define DRM_ATI_GART_IGP 3 703#define DRM_ATI_GART_IGP 3
707 704
708struct drm_ati_pcigart_info { 705struct drm_ati_pcigart_info {
709 int gart_table_location; 706 int gart_table_location;
710 int gart_reg_if; 707 int gart_reg_if;
711 void *addr; 708 void *addr;
712 dma_addr_t bus_addr; 709 dma_addr_t bus_addr;
713 dma_addr_t table_mask; 710 dma_addr_t table_mask;
714 dma_addr_t member_mask; 711 dma_addr_t member_mask;
715 struct drm_dma_handle *table_handle; 712 struct drm_dma_handle *table_handle;
716 drm_local_map_t mapping; 713 drm_local_map_t mapping;
717 int table_size; 714 int table_size;
718}; 715};
719 716
720#ifndef DMA_BIT_MASK 717#ifndef DMA_BIT_MASK
721#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1) 718#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
722#endif 719#endif
723 720
724#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) 721#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
725 722
726struct drm_driver_info { 723struct drm_driver_info {
727 int (*load)(struct drm_device *, unsigned long flags); 724 int (*load)(struct drm_device *, unsigned long flags);
728 int (*firstopen)(struct drm_device *); 725 int (*firstopen)(struct drm_device *);
729 int (*open)(struct drm_device *, struct drm_file *); 726 int (*open)(struct drm_device *, struct drm_file *);
730 void (*preclose)(struct drm_device *, struct drm_file *file_priv); 727 void (*preclose)(struct drm_device *, struct drm_file *file_priv);
731 void (*postclose)(struct drm_device *, struct drm_file *); 728 void (*postclose)(struct drm_device *, struct drm_file *);
732 void (*lastclose)(struct drm_device *); 729 void (*lastclose)(struct drm_device *);
733 int (*unload)(struct drm_device *); 730 int (*unload)(struct drm_device *);
734 void (*reclaim_buffers_locked)(struct drm_device *, 731 void (*reclaim_buffers_locked)(struct drm_device *,
735 struct drm_file *file_priv); 732 struct drm_file *file_priv);
736 int (*dma_ioctl)(struct drm_device *dev, void *data, 733 int (*dma_ioctl)(struct drm_device *dev, void *data,
737 struct drm_file *file_priv); 734 struct drm_file *file_priv);
738 void (*dma_ready)(struct drm_device *); 735 void (*dma_ready)(struct drm_device *);
739 int (*dma_quiescent)(struct drm_device *); 736 int (*dma_quiescent)(struct drm_device *);
740 int (*dma_flush_block_and_flush)(struct drm_device *, int context, 737 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
741 enum drm_lock_flags flags); 738 enum drm_lock_flags flags);
742 int (*dma_flush_unblock)(struct drm_device *, int context, 739 int (*dma_flush_unblock)(struct drm_device *, int context,
743 enum drm_lock_flags flags); 740 enum drm_lock_flags flags);
744 int (*context_ctor)(struct drm_device *dev, int context); 741 int (*context_ctor)(struct drm_device *dev, int context);
745 int (*context_dtor)(struct drm_device *dev, int context); 742 int (*context_dtor)(struct drm_device *dev, int context);
746 int (*kernel_context_switch)(struct drm_device *dev, int old, 743 int (*kernel_context_switch)(struct drm_device *dev, int old,
747 int new); 744 int new);
748 int (*kernel_context_switch_unlock)(struct drm_device *dev); 745 int (*kernel_context_switch_unlock)(struct drm_device *dev);
749 void (*irq_preinstall)(struct drm_device *dev); 746 void (*irq_preinstall)(struct drm_device *dev);
750 int (*irq_postinstall)(struct drm_device *dev); 747 int (*irq_postinstall)(struct drm_device *dev);
751 void (*irq_uninstall)(struct drm_device *dev); 748 void (*irq_uninstall)(struct drm_device *dev);
752 irqreturn_t (*irq_handler)(DRM_IRQ_ARGS); 749 irqreturn_t (*irq_handler)(DRM_IRQ_ARGS);
753 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc); 750 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc);
754 int (*enable_vblank)(struct drm_device *dev, int crtc); 751 int (*enable_vblank)(struct drm_device *dev, int crtc);
755 void (*disable_vblank)(struct drm_device *dev, int crtc); 752 void (*disable_vblank)(struct drm_device *dev, int crtc);
756 753
757 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */ 754 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
758 755
759 /** 756 /**
760 * Called by \c drm_device_is_agp. Typically used to determine if a 757 * Called by \c drm_device_is_agp. Typically used to determine if a
761 * card is really attached to AGP or not. 758 * card is really attached to AGP or not.
762 * 759 *
763 * \param dev DRM device handle 760 * \param dev DRM device handle
764 * 761 *
765 * \returns  762 * \returns
766 * One of three values is returned depending on whether or not the 763 * One of three values is returned depending on whether or not the
767 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP 764 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
768 * (return of 1), or may or may not be AGP (return of 2). 765 * (return of 1), or may or may not be AGP (return of 2).
769 */ 766 */
770 int (*device_is_agp) (struct drm_device * dev); 767 int (*device_is_agp) (struct drm_device * dev);
771 768
772 drm_ioctl_desc_t *ioctls; 769 drm_ioctl_desc_t *ioctls;
773 int max_ioctl; 770 int max_ioctl;
774 771
775 int buf_priv_size; 772 int buf_priv_size;
776 773
777 int major; 774 int major;
778 int minor; 775 int minor;
779 int patchlevel; 776 int patchlevel;
780 const char *name; /* Simple driver name */ 777 const char *name; /* Simple driver name */
781 const char *desc; /* Longer driver name */ 778 const char *desc; /* Longer driver name */
782 const char *date; /* Date of last major changes. */ 779 const char *date; /* Date of last major changes. */
783 780
784 u32 driver_features; 781 u32 driver_features;
785}; 782};
786 783
787/* Length for the array of resource pointers for drm_get_resource_*. */ 784/* Length for the array of resource pointers for drm_get_resource_*. */
788#define DRM_MAX_PCI_RESOURCE 6 785#define DRM_MAX_PCI_RESOURCE 6
789 786
790#if defined(__NetBSD__) 787#if defined(__NetBSD__)
791typedef struct { 788typedef struct {
792 int mapped; 789 int mapped;
793 int maptype; 790 int maptype;
794 bus_addr_t base; 791 bus_addr_t base;
795 bus_size_t size; 792 bus_size_t size;
796 bus_space_handle_t bsh; 793 bus_space_handle_t bsh;
797 int flags; 794 int flags;
798 void * vaddr; 795 void * vaddr;
799} pci_map_data_t; 796} pci_map_data_t;
800#endif 797#endif
801 798
802/**  799/**
803 * DRM device functions structure 800 * DRM device functions structure
804 */ 801 */
805struct drm_device { 802struct drm_device {
806 struct drm_driver_info *driver; 803 struct drm_driver_info *driver;
807 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */ 804 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
808 805
809 u_int16_t pci_device; /* PCI device id */ 806 u_int16_t pci_device; /* PCI device id */
810 u_int16_t pci_vendor; /* PCI vendor id */ 807 u_int16_t pci_vendor; /* PCI vendor id */
811 808
812 char *unique; /* Unique identifier: e.g., busid */ 809 char *unique; /* Unique identifier: e.g., busid */
813 int unique_len; /* Length of unique field */ 810 int unique_len; /* Length of unique field */
814 device_t device; /* Device instance from newbus */ 811 device_t device; /* Device instance from newbus */
815#if defined(__FreeBSD__) 812#if defined(__FreeBSD__)
816 struct cdev *devnode; /* Device number for mknod */ 813 struct cdev *devnode; /* Device number for mknod */
817#endif 814#endif
818 int if_version; /* Highest interface version set */ 815 int if_version; /* Highest interface version set */
819 816
820 int flags; /* Flags to open(2) */ 817 int flags; /* Flags to open(2) */
821 818
822 /* Locks */ 819 /* Locks */
823 DRM_SPINTYPE vbl_lock; /* protects vblank operations */ 820 DRM_SPINTYPE vbl_lock; /* protects vblank operations */
824 DRM_SPINTYPE dma_lock; /* protects dev->dma */ 821 DRM_SPINTYPE dma_lock; /* protects dev->dma */
825 DRM_SPINTYPE irq_lock; /* protects irq condition checks */ 822 DRM_SPINTYPE irq_lock; /* protects irq condition checks */
826 DRM_SPINTYPE dev_lock; /* protects everything else */ 823 DRM_SPINTYPE dev_lock; /* protects everything else */
827 DRM_SPINTYPE drw_lock; 824 DRM_SPINTYPE drw_lock;
828 825
829 /* Usage Counters */ 826 /* Usage Counters */
830 int open_count; /* Outstanding files open */ 827 int open_count; /* Outstanding files open */
831 int buf_use; /* Buffers in use -- cannot alloc */ 828 int buf_use; /* Buffers in use -- cannot alloc */
832 829
833 /* Performance counters */ 830 /* Performance counters */
834 unsigned long counters; 831 unsigned long counters;
835 enum drm_stat_type types[15]; 832 enum drm_stat_type types[15];
836 atomic_t counts[15]; 833 atomic_t counts[15];
837 834
838 /* Authentication */ 835 /* Authentication */
839 drm_file_list_t files; 836 drm_file_list_t files;
840 drm_magic_head_t magiclist[DRM_HASH_SIZE]; 837 drm_magic_head_t magiclist[DRM_HASH_SIZE];
841 838
842 /* Linked list of mappable regions. Protected by dev_lock */ 839 /* Linked list of mappable regions. Protected by dev_lock */
843 drm_map_list_t maplist; 840 drm_map_list_t maplist;
844 841
845 drm_local_map_t **context_sareas; 842 drm_local_map_t **context_sareas;
846 int max_context; 843 int max_context;
847 844
848 drm_lock_data_t lock; /* Information on hardware lock */ 845 drm_lock_data_t lock; /* Information on hardware lock */
849 846
850 /* DMA queues (contexts) */ 847 /* DMA queues (contexts) */
851 drm_device_dma_t *dma; /* Optional pointer for DMA support */ 848 drm_device_dma_t *dma; /* Optional pointer for DMA support */
852 849
853 /* Context support */ 850 /* Context support */
854 int irq; /* Interrupt used by board */ 851 int irq; /* Interrupt used by board */
855 int irq_enabled; /* True if the irq handler is enabled */ 852 int irq_enabled; /* True if the irq handler is enabled */
856 int msi_enabled; /* MSI enabled */ 853 int msi_enabled; /* MSI enabled */
857#if defined(__FreeBSD__) 854#if defined(__FreeBSD__)
858 int irqrid; /* Interrupt used by board */ 855 int irqrid; /* Interrupt used by board */
859 struct resource *irqr; /* Resource for interrupt used by board */ 856 struct resource *irqr; /* Resource for interrupt used by board */
860 857
861 /* Storage of resource pointers for drm_get_resource_* */ 858 /* Storage of resource pointers for drm_get_resource_* */
862 struct resource *pcir[DRM_MAX_PCI_RESOURCE]; 859 struct resource *pcir[DRM_MAX_PCI_RESOURCE];
863 int pcirid[DRM_MAX_PCI_RESOURCE]; 860 int pcirid[DRM_MAX_PCI_RESOURCE];
864#elif defined(__NetBSD__) 861#elif defined(__NetBSD__)
865 struct pci_attach_args pa; 862 struct pci_attach_args pa;
866 pci_map_data_t pci_map_data[DRM_MAX_PCI_RESOURCE]; 863 pci_map_data_t pci_map_data[DRM_MAX_PCI_RESOURCE];
867 pci_map_data_t agp_map_data[DRM_MAX_PCI_RESOURCE]; 864 pci_map_data_t agp_map_data[DRM_MAX_PCI_RESOURCE];
868 dev_t kdev; 865 dev_t kdev;
869#endif 866#endif
870 void *irqh; /* Handle from bus_setup_intr */ 867 void *irqh; /* Handle from bus_setup_intr */
871 868
872 int pci_domain; 869 int pci_domain;
873 int pci_bus; 870 int pci_bus;
874 int pci_slot; 871 int pci_slot;
875 int pci_func; 872 int pci_func;
876 873
877 atomic_t context_flag; /* Context swapping flag */ 874 atomic_t context_flag; /* Context swapping flag */
878 int last_context; /* Last current context */ 875 int last_context; /* Last current context */
879 876
880 int vblank_disable_allowed; 877 int vblank_disable_allowed;
881 atomic_t vbl_signal_pending; /* number of signals pending on all crtcs */ 878 atomic_t vbl_signal_pending; /* number of signals pending on all crtcs */
882 struct callout vblank_disable_timer; 879 struct callout vblank_disable_timer;
883 u32 max_vblank_count; /* size of vblank counter register */ 880 u32 max_vblank_count; /* size of vblank counter register */
884 struct drm_vblank_info *vblank; /* per crtc vblank info */ 881 struct drm_vblank_info *vblank; /* per crtc vblank info */
885 int num_crtcs; 882 int num_crtcs;
886 883
887#if defined(__FreeBSD__) 884#if defined(__FreeBSD__)
888 struct sigio *buf_sigio; /* Processes waiting for SIGIO */ 885 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
889#elif defined(__NetBSD__) 886#elif defined(__NetBSD__)
890 pid_t buf_pgid; 887 pid_t buf_pgid;
891#endif 888#endif
892 889
893 /* Sysctl support */ 890 /* Sysctl support */
894 struct drm_sysctl_info *sysctl; 891 struct drm_sysctl_info *sysctl;
895 892
896 drm_agp_head_t *agp; 893 drm_agp_head_t *agp;
897 drm_sg_mem_t *sg; /* Scatter gather memory */ 894 drm_sg_mem_t *sg; /* Scatter gather memory */
898 atomic_t *ctx_bitmap; 895 atomic_t *ctx_bitmap;
899 void *dev_private; 896 void *dev_private;
900 unsigned int agp_buffer_token; 897 unsigned int agp_buffer_token;
901 drm_local_map_t *agp_buffer_map; 898 drm_local_map_t *agp_buffer_map;
902 899
903#if defined(__FreeBSD__) 900#if defined(__FreeBSD__)
904 struct unrhdr *drw_unrhdr; 901 struct unrhdr *drw_unrhdr;
905#elif defined(__NetBSD__) 902#elif defined(__NetBSD__)
906 int drw_no; 903 int drw_no;
907#endif 904#endif
908 /* RB tree of drawable infos */ 905 /* RB tree of drawable infos */
909 RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head; 906 RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head;
910}; 907};
911 908
912static __inline__ int drm_core_check_feature(struct drm_device *dev, 909static __inline__ int drm_core_check_feature(struct drm_device *dev,
913 int feature) 910 int feature)
914{ 911{
915 return ((dev->driver->driver_features & feature) ? 1 : 0); 912 return ((dev->driver->driver_features & feature) ? 1 : 0);
916} 913}
917 914
918#if __OS_HAS_AGP 915#if __OS_HAS_AGP
919static inline int drm_core_has_AGP(struct drm_device *dev) 916static inline int drm_core_has_AGP(struct drm_device *dev)
920{ 917{
921 return drm_core_check_feature(dev, DRIVER_USE_AGP); 918 return drm_core_check_feature(dev, DRIVER_USE_AGP);
922} 919}
923#else 920#else
924#define drm_core_has_AGP(dev) (0) 921#define drm_core_has_AGP(dev) (0)
925#endif 922#endif
926 923
927extern int drm_debug_flag; 924extern int drm_debug_flag;
928 925
929/* Device setup support (drm_drv.c) */ 926/* Device setup support (drm_drv.c) */
930#if defined(__FreeBSD__) 927#if defined(__FreeBSD__)
931int drm_probe(device_t kdev, drm_pci_id_list_t *idlist); 928int drm_probe(device_t kdev, drm_pci_id_list_t *idlist);
932int drm_attach(device_t kdev, drm_pci_id_list_t *idlist); 929int drm_attach(device_t kdev, drm_pci_id_list_t *idlist);
933void drm_close(void *data); 930void drm_close(void *data);
934int drm_detach(device_t kdev); 931int drm_detach(device_t kdev);
935d_ioctl_t drm_ioctl; 932d_ioctl_t drm_ioctl;
936d_open_t drm_open; 933d_open_t drm_open;
937d_read_t drm_read; 934d_read_t drm_read;
938d_poll_t drm_poll; 935d_poll_t drm_poll;
939d_mmap_t drm_mmap; 936d_mmap_t drm_mmap;
940#elif defined(__NetBSD__) 937#elif defined(__NetBSD__)
941int drm_probe(struct pci_attach_args *pa, drm_pci_id_list_t *idlist); 938int drm_probe(struct pci_attach_args *pa, drm_pci_id_list_t *idlist);
942void drm_attach(device_t kdev, struct pci_attach_args *pa, drm_pci_id_list_t *idlist); 939void drm_attach(device_t kdev, struct pci_attach_args *pa, drm_pci_id_list_t *idlist);
943int drm_detach(device_t self, int flags); 940int drm_detach(device_t self, int flags);
944int drm_activate(device_t self, devact_t act); 941int drm_activate(device_t self, devact_t act);
945dev_type_ioctl(drm_ioctl); 942dev_type_ioctl(drm_ioctl);
946dev_type_open(drm_open); 943dev_type_open(drm_open);
947dev_type_close(drm_close); 944dev_type_close(drm_close);
948dev_type_read(drm_read); 945dev_type_read(drm_read);
949dev_type_poll(drm_poll); 946dev_type_poll(drm_poll);
950dev_type_mmap(drm_mmap); 947dev_type_mmap(drm_mmap);
951#endif 948#endif
952extern drm_local_map_t *drm_getsarea(struct drm_device *dev); 949extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
953 950
954int drm_close_pid(struct drm_device *dev, struct drm_file *priv, pid_t pid); 951int drm_close_pid(struct drm_device *dev, struct drm_file *priv, pid_t pid);
955 952
956/* File operations helpers (drm_fops.c) */ 953/* File operations helpers (drm_fops.c) */
957#if defined(__FreeBSD__) 954#if defined(__FreeBSD__)
958extern int drm_open_helper(struct cdev *kdev, int flags, int fmt, 955extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
959 DRM_STRUCTPROC *p, 956 DRM_STRUCTPROC *p,
960 struct drm_device *dev); 957 struct drm_device *dev);
961#elif defined(__NetBSD__) 958#elif defined(__NetBSD__)
962extern struct drm_file *drm_find_file_by_proc(struct drm_device *dev, 959extern struct drm_file *drm_find_file_by_proc(struct drm_device *dev,
963 struct proc *p); 960 struct proc *p);
964extern int drm_open_helper(dev_t kdev, int flags, int fmt, 961extern int drm_open_helper(dev_t kdev, int flags, int fmt,
965 struct proc *p, struct drm_device *dev); 962 struct proc *p, struct drm_device *dev);
966#endif 963#endif
967 964
968/* Memory management support (drm_memory.c) */ 965/* Memory management support (drm_memory.c) */
969void drm_mem_init(void); 966void drm_mem_init(void);
970void drm_mem_uninit(void); 967void drm_mem_uninit(void);
971void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map); 968void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map);
972void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map); 969void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map);
973void drm_ioremapfree(drm_local_map_t *map); 970void drm_ioremapfree(drm_local_map_t *map);
974#if defined(__FreeBSD__) 971#if defined(__FreeBSD__)
975int drm_mtrr_add(unsigned long offset, size_t size, int flags); 972int drm_mtrr_add(unsigned long offset, size_t size, int flags);
976int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags); 973int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
977#elif defined(__NetBSD__) 974#elif defined(__NetBSD__)
978int drm_mtrr_add(unsigned long offset, size_t size, int flags); 975int drm_mtrr_add(unsigned long offset, size_t size, int flags);
979int drm_mtrr_del(unsigned long offset, size_t size, int flags); 976int drm_mtrr_del(unsigned long offset, size_t size, int flags);
980#endif 977#endif
981 978
982int drm_context_switch(struct drm_device *dev, int old, int new); 979int drm_context_switch(struct drm_device *dev, int old, int new);
983int drm_context_switch_complete(struct drm_device *dev, int new); 980int drm_context_switch_complete(struct drm_device *dev, int new);
984 981
985int drm_ctxbitmap_init(struct drm_device *dev); 982int drm_ctxbitmap_init(struct drm_device *dev);
986void drm_ctxbitmap_cleanup(struct drm_device *dev); 983void drm_ctxbitmap_cleanup(struct drm_device *dev);
987void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle); 984void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
988int drm_ctxbitmap_next(struct drm_device *dev); 985int drm_ctxbitmap_next(struct drm_device *dev);
989 986
990/* Locking IOCTL support (drm_lock.c) */ 987/* Locking IOCTL support (drm_lock.c) */
991int drm_lock_take(struct drm_lock_data *lock_data, 988int drm_lock_take(struct drm_lock_data *lock_data,
992 unsigned int context); 989 unsigned int context);
993int drm_lock_transfer(struct drm_lock_data *lock_data, 990int drm_lock_transfer(struct drm_lock_data *lock_data,
994 unsigned int context); 991 unsigned int context);
995int drm_lock_free(struct drm_lock_data *lock_data, 992int drm_lock_free(struct drm_lock_data *lock_data,
996 unsigned int context); 993 unsigned int context);
997 994
998/* Buffer management support (drm_bufs.c) */ 995/* Buffer management support (drm_bufs.c) */
999unsigned long drm_get_resource_start(struct drm_device *dev, 996unsigned long drm_get_resource_start(struct drm_device *dev,
1000 unsigned int resource); 997 unsigned int resource);
1001unsigned long drm_get_resource_len(struct drm_device *dev, 998unsigned long drm_get_resource_len(struct drm_device *dev,
1002 unsigned int resource); 999 unsigned int resource);
1003void drm_rmmap(struct drm_device *dev, drm_local_map_t *map); 1000void drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
1004int drm_order(unsigned long size); 1001int drm_order(unsigned long size);
1005int drm_addmap(struct drm_device *dev, unsigned long offset, 1002int drm_addmap(struct drm_device *dev, unsigned long offset,
1006 unsigned long size, 1003 unsigned long size,
1007 enum drm_map_type type, enum drm_map_flags flags, 1004 enum drm_map_type type, enum drm_map_flags flags,
1008 drm_local_map_t **map_ptr); 1005 drm_local_map_t **map_ptr);
1009int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request); 1006int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request);
1010int drm_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request); 1007int drm_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request);
1011int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request); 1008int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request);
1012 1009
1013/* DMA support (drm_dma.c) */ 1010/* DMA support (drm_dma.c) */
1014int drm_dma_setup(struct drm_device *dev); 1011int drm_dma_setup(struct drm_device *dev);
1015void drm_dma_takedown(struct drm_device *dev); 1012void drm_dma_takedown(struct drm_device *dev);
1016void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf); 1013void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf);
1017void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv); 1014void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv);
1018#define drm_core_reclaim_buffers drm_reclaim_buffers 1015#define drm_core_reclaim_buffers drm_reclaim_buffers
1019 1016
1020/* IRQ support (drm_irq.c) */ 1017/* IRQ support (drm_irq.c) */
1021int drm_irq_install(struct drm_device *dev); 1018int drm_irq_install(struct drm_device *dev);
1022int drm_irq_uninstall(struct drm_device *dev); 1019int drm_irq_uninstall(struct drm_device *dev);
1023irqreturn_t drm_irq_handler(DRM_IRQ_ARGS); 1020irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
1024void drm_driver_irq_preinstall(struct drm_device *dev); 1021void drm_driver_irq_preinstall(struct drm_device *dev);
1025void drm_driver_irq_postinstall(struct drm_device *dev); 1022void drm_driver_irq_postinstall(struct drm_device *dev);
1026void drm_driver_irq_uninstall(struct drm_device *dev); 1023void drm_driver_irq_uninstall(struct drm_device *dev);
1027void drm_handle_vblank(struct drm_device *dev, int crtc); 1024void drm_handle_vblank(struct drm_device *dev, int crtc);
1028u32 drm_vblank_count(struct drm_device *dev, int crtc); 1025u32 drm_vblank_count(struct drm_device *dev, int crtc);
1029int drm_vblank_get(struct drm_device *dev, int crtc); 1026int drm_vblank_get(struct drm_device *dev, int crtc);
1030void drm_vblank_put(struct drm_device *dev, int crtc); 1027void drm_vblank_put(struct drm_device *dev, int crtc);
1031void drm_vblank_cleanup(struct drm_device *dev); 1028void drm_vblank_cleanup(struct drm_device *dev);
1032int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq); 1029int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
1033int drm_vblank_init(struct drm_device *dev, int num_crtcs); 1030int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1034void drm_vbl_send_signals(struct drm_device *dev, int crtc); 1031void drm_vbl_send_signals(struct drm_device *dev, int crtc);
1035int drm_modeset_ctl(struct drm_device *dev, void *data, 1032int drm_modeset_ctl(struct drm_device *dev, void *data,
1036 struct drm_file *file_priv); 1033 struct drm_file *file_priv);
1037 1034
1038/* AGP/PCI Express/GART support (drm_agpsupport.c) */ 1035/* AGP/PCI Express/GART support (drm_agpsupport.c) */
1039int drm_device_is_agp(struct drm_device *dev); 1036int drm_device_is_agp(struct drm_device *dev);
1040int drm_device_is_pcie(struct drm_device *dev); 1037int drm_device_is_pcie(struct drm_device *dev);
1041drm_agp_head_t *drm_agp_init(struct drm_device *dev); 1038drm_agp_head_t *drm_agp_init(struct drm_device *dev);
1042int drm_agp_acquire(struct drm_device *dev); 1039int drm_agp_acquire(struct drm_device *dev);
1043int drm_agp_release(struct drm_device *dev); 1040int drm_agp_release(struct drm_device *dev);
1044int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info); 1041int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info);
1045int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode); 1042int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1046void *drm_agp_allocate_memory(size_t pages, u32 type); 1043void *drm_agp_allocate_memory(size_t pages, u32 type);
1047int drm_agp_free_memory(void *handle); 1044int drm_agp_free_memory(void *handle);
1048int drm_agp_bind_memory(void *handle, off_t start); 1045int drm_agp_bind_memory(void *handle, off_t start);
1049int drm_agp_unbind_memory(void *handle); 1046int drm_agp_unbind_memory(void *handle);
1050int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request); 1047int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1051int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request); 1048int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1052int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request); 1049int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1053int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request); 1050int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1054 1051
1055/* Scatter Gather Support (drm_scatter.c) */ 1052/* Scatter Gather Support (drm_scatter.c) */
1056void drm_sg_cleanup(drm_sg_mem_t *entry); 1053void drm_sg_cleanup(drm_sg_mem_t *entry);
1057int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request); 1054int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
1058 1055
1059/* sysctl support (drm_sysctl.h) */ 1056/* sysctl support (drm_sysctl.h) */
1060extern int drm_sysctl_init(struct drm_device *dev); 1057extern int drm_sysctl_init(struct drm_device *dev);
1061extern int drm_sysctl_cleanup(struct drm_device *dev); 1058extern int drm_sysctl_cleanup(struct drm_device *dev);
1062 1059
1063/* ATI PCIGART support (ati_pcigart.c) */ 1060/* ATI PCIGART support (ati_pcigart.c) */
1064int drm_ati_pcigart_init(struct drm_device *dev, 1061int drm_ati_pcigart_init(struct drm_device *dev,
1065 struct drm_ati_pcigart_info *gart_info); 1062 struct drm_ati_pcigart_info *gart_info);
1066int drm_ati_pcigart_cleanup(struct drm_device *dev, 1063int drm_ati_pcigart_cleanup(struct drm_device *dev,
1067 struct drm_ati_pcigart_info *gart_info); 1064 struct drm_ati_pcigart_info *gart_info);
1068 1065
1069/* Locking IOCTL support (drm_drv.c) */ 1066/* Locking IOCTL support (drm_drv.c) */
1070int drm_lock(struct drm_device *dev, void *data, 1067int drm_lock(struct drm_device *dev, void *data,
1071 struct drm_file *file_priv); 1068 struct drm_file *file_priv);
1072int drm_unlock(struct drm_device *dev, void *data, 1069int drm_unlock(struct drm_device *dev, void *data,
1073 struct drm_file *file_priv); 1070 struct drm_file *file_priv);
1074int drm_version(struct drm_device *dev, void *data, 1071int drm_version(struct drm_device *dev, void *data,
1075 struct drm_file *file_priv); 1072 struct drm_file *file_priv);
1076int drm_setversion(struct drm_device *dev, void *data, 1073int drm_setversion(struct drm_device *dev, void *data,
1077 struct drm_file *file_priv); 1074 struct drm_file *file_priv);
1078 1075
1079/* Misc. IOCTL support (drm_ioctl.c) */ 1076/* Misc. IOCTL support (drm_ioctl.c) */
1080int drm_irq_by_busid(struct drm_device *dev, void *data, 1077int drm_irq_by_busid(struct drm_device *dev, void *data,
1081 struct drm_file *file_priv); 1078 struct drm_file *file_priv);
1082int drm_getunique(struct drm_device *dev, void *data, 1079int drm_getunique(struct drm_device *dev, void *data,
1083 struct drm_file *file_priv); 1080 struct drm_file *file_priv);
1084int drm_setunique(struct drm_device *dev, void *data, 1081int drm_setunique(struct drm_device *dev, void *data,
1085 struct drm_file *file_priv); 1082 struct drm_file *file_priv);
1086int drm_getmap(struct drm_device *dev, void *data, 1083int drm_getmap(struct drm_device *dev, void *data,
1087 struct drm_file *file_priv); 1084 struct drm_file *file_priv);
1088int drm_getclient(struct drm_device *dev, void *data, 1085int drm_getclient(struct drm_device *dev, void *data,
1089 struct drm_file *file_priv); 1086 struct drm_file *file_priv);
1090int drm_getstats(struct drm_device *dev, void *data, 1087int drm_getstats(struct drm_device *dev, void *data,
1091 struct drm_file *file_priv); 1088 struct drm_file *file_priv);
1092int drm_noop(struct drm_device *dev, void *data, 1089int drm_noop(struct drm_device *dev, void *data,
1093 struct drm_file *file_priv); 1090 struct drm_file *file_priv);
1094 1091
1095/* Context IOCTL support (drm_context.c) */ 1092/* Context IOCTL support (drm_context.c) */
1096int drm_resctx(struct drm_device *dev, void *data, 1093int drm_resctx(struct drm_device *dev, void *data,
1097 struct drm_file *file_priv); 1094 struct drm_file *file_priv);
1098int drm_addctx(struct drm_device *dev, void *data, 1095int drm_addctx(struct drm_device *dev, void *data,
1099 struct drm_file *file_priv); 1096 struct drm_file *file_priv);
1100int drm_modctx(struct drm_device *dev, void *data, 1097int drm_modctx(struct drm_device *dev, void *data,
1101 struct drm_file *file_priv); 1098 struct drm_file *file_priv);
1102int drm_getctx(struct drm_device *dev, void *data, 1099int drm_getctx(struct drm_device *dev, void *data,
1103 struct drm_file *file_priv); 1100 struct drm_file *file_priv);
1104int drm_switchctx(struct drm_device *dev, void *data, 1101int drm_switchctx(struct drm_device *dev, void *data,
1105 struct drm_file *file_priv); 1102 struct drm_file *file_priv);
1106int drm_newctx(struct drm_device *dev, void *data, 1103int drm_newctx(struct drm_device *dev, void *data,
1107 struct drm_file *file_priv); 1104 struct drm_file *file_priv);
1108int drm_rmctx(struct drm_device *dev, void *data, 1105int drm_rmctx(struct drm_device *dev, void *data,
1109 struct drm_file *file_priv); 1106 struct drm_file *file_priv);
1110int drm_setsareactx(struct drm_device *dev, void *data, 1107int drm_setsareactx(struct drm_device *dev, void *data,
1111 struct drm_file *file_priv); 1108 struct drm_file *file_priv);
1112int drm_getsareactx(struct drm_device *dev, void *data, 1109int drm_getsareactx(struct drm_device *dev, void *data,
1113 struct drm_file *file_priv); 1110 struct drm_file *file_priv);
1114 1111
1115/* Drawable IOCTL support (drm_drawable.c) */ 1112/* Drawable IOCTL support (drm_drawable.c) */
1116int drm_adddraw(struct drm_device *dev, void *data, 1113int drm_adddraw(struct drm_device *dev, void *data,
1117 struct drm_file *file_priv); 1114 struct drm_file *file_priv);
1118int drm_rmdraw(struct drm_device *dev, void *data, 1115int drm_rmdraw(struct drm_device *dev, void *data,
1119 struct drm_file *file_priv); 1116 struct drm_file *file_priv);
1120int drm_update_draw(struct drm_device *dev, void *data, 1117int drm_update_draw(struct drm_device *dev, void *data,
1121 struct drm_file *file_priv); 1118 struct drm_file *file_priv);
1122struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev, 1119struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
1123 int handle); 1120 int handle);
1124 1121
1125/* Drawable support (drm_drawable.c) */ 1122/* Drawable support (drm_drawable.c) */
1126void drm_drawable_free_all(struct drm_device *dev); 1123void drm_drawable_free_all(struct drm_device *dev);
1127 1124
1128/* Authentication IOCTL support (drm_auth.c) */ 1125/* Authentication IOCTL support (drm_auth.c) */
1129int drm_getmagic(struct drm_device *dev, void *data, 1126int drm_getmagic(struct drm_device *dev, void *data,
1130 struct drm_file *file_priv); 1127 struct drm_file *file_priv);
1131int drm_authmagic(struct drm_device *dev, void *data, 1128int drm_authmagic(struct drm_device *dev, void *data,
1132 struct drm_file *file_priv); 1129 struct drm_file *file_priv);
1133 1130
1134/* Buffer management support (drm_bufs.c) */ 1131/* Buffer management support (drm_bufs.c) */
1135int drm_addmap_ioctl(struct drm_device *dev, void *data, 1132int drm_addmap_ioctl(struct drm_device *dev, void *data,
1136 struct drm_file *file_priv); 1133 struct drm_file *file_priv);
1137int drm_rmmap_ioctl(struct drm_device *dev, void *data, 1134int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1138 struct drm_file *file_priv); 1135 struct drm_file *file_priv);
1139int drm_addbufs(struct drm_device *dev, void *data, 1136int drm_addbufs(struct drm_device *dev, void *data,
1140 struct drm_file *file_priv); 1137 struct drm_file *file_priv);
1141int drm_infobufs(struct drm_device *dev, void *data, 1138int drm_infobufs(struct drm_device *dev, void *data,
1142 struct drm_file *file_priv); 1139 struct drm_file *file_priv);
1143int drm_markbufs(struct drm_device *dev, void *data, 1140int drm_markbufs(struct drm_device *dev, void *data,
1144 struct drm_file *file_priv); 1141 struct drm_file *file_priv);
1145int drm_freebufs(struct drm_device *dev, void *data, 1142int drm_freebufs(struct drm_device *dev, void *data,
1146 struct drm_file *file_priv); 1143 struct drm_file *file_priv);
1147int drm_mapbufs(struct drm_device *dev, void *data, 1144int drm_mapbufs(struct drm_device *dev, void *data,
1148 struct drm_file *file_priv); 1145 struct drm_file *file_priv);
1149 1146
1150/* DMA support (drm_dma.c) */ 1147/* DMA support (drm_dma.c) */
1151int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv); 1148int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv);
1152 1149
1153/* IRQ support (drm_irq.c) */ 1150/* IRQ support (drm_irq.c) */
1154int drm_control(struct drm_device *dev, void *data, 1151int drm_control(struct drm_device *dev, void *data,
1155 struct drm_file *file_priv); 1152 struct drm_file *file_priv);
1156int drm_wait_vblank(struct drm_device *dev, void *data, 1153int drm_wait_vblank(struct drm_device *dev, void *data,
1157 struct drm_file *file_priv); 1154 struct drm_file *file_priv);
1158 1155
1159/* AGP/GART support (drm_agpsupport.c) */ 1156/* AGP/GART support (drm_agpsupport.c) */
1160int drm_agp_acquire_ioctl(struct drm_device *dev, void *data, 1157int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1161 struct drm_file *file_priv); 1158 struct drm_file *file_priv);
1162int drm_agp_release_ioctl(struct drm_device *dev, void *data, 1159int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1163 struct drm_file *file_priv); 1160 struct drm_file *file_priv);
1164int drm_agp_enable_ioctl(struct drm_device *dev, void *data, 1161int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1165 struct drm_file *file_priv); 1162 struct drm_file *file_priv);
1166int drm_agp_info_ioctl(struct drm_device *dev, void *data, 1163int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1167 struct drm_file *file_priv); 1164 struct drm_file *file_priv);
1168int drm_agp_alloc_ioctl(struct drm_device *dev, void *data, 1165int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1169 struct drm_file *file_priv); 1166 struct drm_file *file_priv);
1170int drm_agp_free_ioctl(struct drm_device *dev, void *data, 1167int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1171 struct drm_file *file_priv); 1168 struct drm_file *file_priv);
1172int drm_agp_unbind_ioctl(struct drm_device *dev, void *data, 1169int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1173 struct drm_file *file_priv); 1170 struct drm_file *file_priv);
1174int drm_agp_bind_ioctl(struct drm_device *dev, void *data, 1171int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1175 struct drm_file *file_priv); 1172 struct drm_file *file_priv);
1176 1173
1177/* Scatter Gather Support (drm_scatter.c) */ 1174/* Scatter Gather Support (drm_scatter.c) */
1178int drm_sg_alloc_ioctl(struct drm_device *dev, void *data, 1175int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1179 struct drm_file *file_priv); 1176 struct drm_file *file_priv);
1180int drm_sg_free(struct drm_device *dev, void *data, 1177int drm_sg_free(struct drm_device *dev, void *data,
1181 struct drm_file *file_priv); 1178 struct drm_file *file_priv);
1182 1179
1183/* consistent PCI memory functions (drm_pci.c) */ 1180/* consistent PCI memory functions (drm_pci.c) */
1184drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size, 1181drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1185 size_t align, dma_addr_t maxaddr); 1182 size_t align, dma_addr_t maxaddr);
1186void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah); 1183void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1187 1184
1188/* Inline replacements for drm_alloc and friends */ 1185/* Inline replacements for drm_alloc and friends */
1189static __inline__ void * 1186static __inline__ void *
1190drm_alloc(size_t size, struct malloc_type *area) 1187drm_alloc(size_t size, struct malloc_type *area)
1191{ 1188{
1192 return malloc(size, area, M_NOWAIT); 1189 return malloc(size, area, M_NOWAIT);
1193} 1190}
1194 1191
1195static __inline__ void * 1192static __inline__ void *
1196drm_calloc(size_t nmemb, size_t size, struct malloc_type *area) 1193drm_calloc(size_t nmemb, size_t size, struct malloc_type *area)
1197{ 1194{
1198 return malloc(size * nmemb, area, M_NOWAIT | M_ZERO); 1195 return malloc(size * nmemb, area, M_NOWAIT | M_ZERO);
1199} 1196}
1200 1197
1201static __inline__ void * 1198static __inline__ void *
1202drm_realloc(void *oldpt, size_t oldsize, size_t size, 1199drm_realloc(void *oldpt, size_t oldsize, size_t size,
1203 struct malloc_type *area) 1200 struct malloc_type *area)
1204{ 1201{
1205#if defined(__FreeBSD__) 1202#if defined(__FreeBSD__)
1206 return reallocf(oldpt, size, area, M_NOWAIT); 1203 return reallocf(oldpt, size, area, M_NOWAIT);
1207#elif defined(__NetBSD__) 1204#elif defined(__NetBSD__)
1208 void *pt; 1205 void *pt;
1209 1206
1210 pt = malloc(size, area, M_NOWAIT); 1207 pt = malloc(size, area, M_NOWAIT);
1211 if (pt == NULL) 1208 if (pt == NULL)
1212 return NULL; 1209 return NULL;
1213 if (oldpt && oldsize) { 1210 if (oldpt && oldsize) {
1214 memcpy(pt, oldpt, oldsize); 1211 memcpy(pt, oldpt, oldsize);
1215 free(oldpt, area); 1212 free(oldpt, area);
1216 } 1213 }
1217 return pt; 1214 return pt;
1218#endif 1215#endif
1219} 1216}
1220 1217
1221static __inline__ void 1218static __inline__ void
1222drm_free(void *pt, size_t size, struct malloc_type *area) 1219drm_free(void *pt, size_t size, struct malloc_type *area)
1223{ 1220{
1224 free(pt, area); 1221 free(pt, area);
1225} 1222}
1226 1223
1227/* Inline replacements for DRM_IOREMAP macros */ 1224/* Inline replacements for DRM_IOREMAP macros */
1228static __inline__ void 1225static __inline__ void
1229drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev) 1226drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
1230{ 1227{
1231 map->handle = drm_ioremap_wc(dev, map); 1228 map->handle = drm_ioremap_wc(dev, map);
1232} 1229}
1233static __inline__ void 1230static __inline__ void
1234drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev) 1231drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
1235{ 1232{
1236 map->handle = drm_ioremap(dev, map); 1233 map->handle = drm_ioremap(dev, map);
1237} 1234}
1238static __inline__ void 1235static __inline__ void
1239drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev) 1236drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
1240{ 1237{
1241 if ( map->handle && map->size ) 1238 if ( map->handle && map->size )
1242 drm_ioremapfree(map); 1239 drm_ioremapfree(map);
1243} 1240}
1244 1241
1245static __inline__ struct drm_local_map * 1242static __inline__ struct drm_local_map *
1246drm_core_findmap(struct drm_device *dev, unsigned long offset) 1243drm_core_findmap(struct drm_device *dev, unsigned long offset)
1247{ 1244{
1248 drm_local_map_t *map; 1245 drm_local_map_t *map;
1249 1246
1250 DRM_SPINLOCK_ASSERT(&dev->dev_lock); 1247 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
1251 TAILQ_FOREACH(map, &dev->maplist, link) { 1248 TAILQ_FOREACH(map, &dev->maplist, link) {
1252 if (map->offset == offset) 1249 if (map->offset == offset)
1253 return map; 1250 return map;
1254 } 1251 }
1255 return NULL; 1252 return NULL;
1256} 1253}
1257 1254
1258static __inline__ void drm_core_dropmap(struct drm_map *map) 1255static __inline__ void drm_core_dropmap(struct drm_map *map)
1259{ 1256{
1260} 1257}
1261 1258
1262#endif /* __KERNEL__ */ 1259#endif /* __KERNEL__ */
1263#endif /* _DRM_P_H_ */ 1260#endif /* _DRM_P_H_ */

cvs diff -r1.5 -r1.6 src/sys/external/bsd/drm/dist/bsd-core/drm_fops.c (switch to unified diff)

--- src/sys/external/bsd/drm/dist/bsd-core/drm_fops.c 2009/06/20 01:07:09 1.5
+++ src/sys/external/bsd/drm/dist/bsd-core/drm_fops.c 2009/08/07 22:51:04 1.6
@@ -1,180 +1,177 @@ @@ -1,180 +1,177 @@
1/*- 1/*-
2 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 2 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
3 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 3 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
4 * All Rights Reserved. 4 * All Rights Reserved.
5 * 5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a 6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"), 7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation 8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the 10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions: 11 * Software is furnished to do so, subject to the following conditions:
12 * 12 *
13 * The above copyright notice and this permission notice (including the next 13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the 14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software. 15 * Software.
16 * 16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE. 23 * OTHER DEALINGS IN THE SOFTWARE.
24 * 24 *
25 * Authors: 25 * Authors:
26 * Rickard E. (Rik) Faith <faith@valinux.com> 26 * Rickard E. (Rik) Faith <faith@valinux.com>
27 * Daryll Strauss <daryll@valinux.com> 27 * Daryll Strauss <daryll@valinux.com>
28 * Gareth Hughes <gareth@valinux.com> 28 * Gareth Hughes <gareth@valinux.com>
29 * 29 *
30 */ 30 */
31 31
32/** @file drm_fops.c 32/** @file drm_fops.c
33 * Support code for dealing with the file privates associated with each 33 * Support code for dealing with the file privates associated with each
34 * open of the DRM device. 34 * open of the DRM device.
35 */ 35 */
36 36
37#include "drmP.h" 37#include "drmP.h"
38 38
39#if defined(__NetBSD__) 39#if defined(__NetBSD__)
40struct drm_file * 40struct drm_file *
41drm_find_file_by_proc(struct drm_device *dev, struct proc *p) 41drm_find_file_by_proc(struct drm_device *dev, struct proc *p)
42{ 42{
43 uid_t uid = kauth_cred_getsvuid(p->p_cred); 43 uid_t uid = kauth_cred_getsvuid(p->p_cred);
44 pid_t pid = p->p_pid; 44 pid_t pid = p->p_pid;
45 struct drm_file *priv; 45 struct drm_file *priv;
46 46
47 DRM_SPINLOCK_ASSERT(&dev->dev_lock); 47 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
48 48
49 TAILQ_FOREACH(priv, &dev->files, link) { 49 TAILQ_FOREACH(priv, &dev->files, link) {
50 if (priv->pid == pid && priv->uid == uid) 50 if (priv->pid == pid && priv->uid == uid)
51 return priv; 51 return priv;
52 } 52 }
53 53
54 return NULL; 54 return NULL;
55} 55}
56 56
57/* drm_open_helper is called whenever a process opens /dev/drm. */ 57/* drm_open_helper is called whenever a process opens /dev/drm. */
58int drm_open_helper(dev_t kdev, int flags, int fmt, struct proc *p, 58int drm_open_helper(dev_t kdev, int flags, int fmt, struct proc *p,
59 struct drm_device *dev) 59 struct drm_device *dev)
60{ 60{
61 int m = minor(kdev); 61 int m = minor(kdev);
62 struct drm_file *priv; 62 struct drm_file *priv;
63 int retcode; 63 int retcode;
64 64
65 if (flags & O_EXCL) 65 if (flags & O_EXCL)
66 return EBUSY; /* No exclusive opens */ 66 return EBUSY; /* No exclusive opens */
67 dev->flags = flags; 67 dev->flags = flags;
68 68
69 DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID, m); 69 DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID, m);
70 70
71 DRM_LOCK(); 71 DRM_LOCK();
72 priv = drm_find_file_by_proc(dev, p); 72 priv = drm_find_file_by_proc(dev, p);
73 if (priv) { 73 if (!priv) {
74 priv->refs++; 
75 } else { 
76 priv = malloc(sizeof(*priv), DRM_MEM_FILES, M_NOWAIT | M_ZERO); 74 priv = malloc(sizeof(*priv), DRM_MEM_FILES, M_NOWAIT | M_ZERO);
77 if (priv == NULL) { 75 if (priv == NULL) {
78 DRM_UNLOCK(); 76 DRM_UNLOCK();
79 return ENOMEM; 77 return ENOMEM;
80 } 78 }
81 priv->uid = kauth_cred_getsvuid(p->p_cred); 79 priv->uid = kauth_cred_getsvuid(p->p_cred);
82 priv->pid = p->p_pid; 80 priv->pid = p->p_pid;
83 81
84 priv->refs = 1; 
85 priv->minor = m; 82 priv->minor = m;
86 priv->ioctl_count = 0; 83 priv->ioctl_count = 0;
87 84
88 /* for compatibility root is always authenticated */ 85 /* for compatibility root is always authenticated */
89 priv->authenticated = DRM_SUSER(p); 86 priv->authenticated = DRM_SUSER(p);
90 87
91 if (dev->driver->open) { 88 if (dev->driver->open) {
92 /* shared code returns -errno */ 89 /* shared code returns -errno */
93 retcode = -dev->driver->open(dev, priv); 90 retcode = -dev->driver->open(dev, priv);
94 if (retcode != 0) { 91 if (retcode != 0) {
95 free(priv, DRM_MEM_FILES); 92 free(priv, DRM_MEM_FILES);
96 DRM_UNLOCK(); 93 DRM_UNLOCK();
97 return retcode; 94 return retcode;
98 } 95 }
99 } 96 }
100 97
101 /* first opener automatically becomes master */ 98 /* first opener automatically becomes master */
102 priv->master = TAILQ_EMPTY(&dev->files); 99 priv->master = TAILQ_EMPTY(&dev->files);
103 100
104 TAILQ_INSERT_TAIL(&dev->files, priv, link); 101 TAILQ_INSERT_TAIL(&dev->files, priv, link);
105 } 102 }
106 DRM_UNLOCK(); 103 DRM_UNLOCK();
107 104
108 return 0; 105 return 0;
109} 106}
110 107
111#elif defined(__FreeBSD__) 108#elif defined(__FreeBSD__)
112 109
113/* drm_open_helper is called whenever a process opens /dev/drm. */ 110/* drm_open_helper is called whenever a process opens /dev/drm. */
114int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p, 111int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p,
115 struct drm_device *dev) 112 struct drm_device *dev)
116{ 113{
117 struct drm_file *priv; 114 struct drm_file *priv;
118 int m = minor(kdev); 115 int m = minor(kdev);
119 int retcode; 116 int retcode;
120 117
121 if (flags & O_EXCL) 118 if (flags & O_EXCL)
122 return EBUSY; /* No exclusive opens */ 119 return EBUSY; /* No exclusive opens */
123 dev->flags = flags; 120 dev->flags = flags;
124 121
125 DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID, m); 122 DRM_DEBUG("pid = %d, minor = %d\n", DRM_CURRENTPID, m);
126 123
127 priv = malloc(sizeof(*priv), DRM_MEM_FILES, M_NOWAIT | M_ZERO); 124 priv = malloc(sizeof(*priv), DRM_MEM_FILES, M_NOWAIT | M_ZERO);
128 if (priv == NULL) { 125 if (priv == NULL) {
129 return ENOMEM; 126 return ENOMEM;
130 } 127 }
131 128
132 retcode = devfs_set_cdevpriv(priv, drm_close); 129 retcode = devfs_set_cdevpriv(priv, drm_close);
133 if (retcode != 0) { 130 if (retcode != 0) {
134 free(priv, DRM_MEM_FILES); 131 free(priv, DRM_MEM_FILES);
135 return retcode; 132 return retcode;
136 } 133 }
137 134
138 DRM_LOCK(); 135 DRM_LOCK();
139 priv->dev = dev; 136 priv->dev = dev;
140 priv->uid = p->td_ucred->cr_svuid; 137 priv->uid = p->td_ucred->cr_svuid;
141 priv->pid = p->td_proc->p_pid; 138 priv->pid = p->td_proc->p_pid;
142 priv->minor = m; 139 priv->minor = m;
143 priv->ioctl_count = 0; 140 priv->ioctl_count = 0;
144 141
145 /* for compatibility root is always authenticated */ 142 /* for compatibility root is always authenticated */
146 priv->authenticated = DRM_SUSER(p); 143 priv->authenticated = DRM_SUSER(p);
147 144
148 if (dev->driver->open) { 145 if (dev->driver->open) {
149 /* shared code returns -errno */ 146 /* shared code returns -errno */
150 retcode = -dev->driver->open(dev, priv); 147 retcode = -dev->driver->open(dev, priv);
151 if (retcode != 0) { 148 if (retcode != 0) {
152 devfs_clear_cdevpriv(); 149 devfs_clear_cdevpriv();
153 free(priv, DRM_MEM_FILES); 150 free(priv, DRM_MEM_FILES);
154 DRM_UNLOCK(); 151 DRM_UNLOCK();
155 return retcode; 152 return retcode;
156 } 153 }
157 } 154 }
158 155
159 /* first opener automatically becomes master */ 156 /* first opener automatically becomes master */
160 priv->master = TAILQ_EMPTY(&dev->files); 157 priv->master = TAILQ_EMPTY(&dev->files);
161 158
162 TAILQ_INSERT_TAIL(&dev->files, priv, link); 159 TAILQ_INSERT_TAIL(&dev->files, priv, link);
163 DRM_UNLOCK(); 160 DRM_UNLOCK();
164 kdev->si_drv1 = dev; 161 kdev->si_drv1 = dev;
165 return 0; 162 return 0;
166} 163}
167#endif 164#endif
168 165
169/* The drm_read and drm_poll are stubs to prevent spurious errors 166/* The drm_read and drm_poll are stubs to prevent spurious errors
170 * on older X Servers (4.3.0 and earlier) */ 167 * on older X Servers (4.3.0 and earlier) */
171 168
172int drm_read(DRM_CDEV kdev, struct uio *uio, int ioflag) 169int drm_read(DRM_CDEV kdev, struct uio *uio, int ioflag)
173{ 170{
174 return 0; 171 return 0;
175} 172}
176 173
177int drm_poll(DRM_CDEV kdev, int events, DRM_STRUCTCDEVPROC *p) 174int drm_poll(DRM_CDEV kdev, int events, DRM_STRUCTCDEVPROC *p)
178{ 175{
179 return 0; 176 return 0;
180} 177}