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