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