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