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