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