OSDN Git Service

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