drmP.h revision 1.12 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) ALIGN(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 #if defined(__FreeBSD__)
353
354 #define DRM_READ8(map, offset) \
355 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \
356 (vm_offset_t)(offset))
357 #define DRM_READ16(map, offset) \
358 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \
359 (vm_offset_t)(offset))
360 #define DRM_READ32(map, offset) \
361 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \
362 (vm_offset_t)(offset))
363 #define DRM_WRITE8(map, offset, val) \
364 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \
365 (vm_offset_t)(offset)) = val
366 #define DRM_WRITE16(map, offset, val) \
367 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \
368 (vm_offset_t)(offset)) = val
369 #define DRM_WRITE32(map, offset, val) \
370 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \
371 (vm_offset_t)(offset)) = val
372
373 #define DRM_VERIFYAREA_READ( uaddr, size ) \
374 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
375
376 #elif defined(__NetBSD__)
377
378 typedef vaddr_t vm_offset_t;
379
380 #define DRM_READ8(map, offset) \
381 bus_space_read_1( (map)->bst, (map)->bsh, (offset))
382 #define DRM_READ16(map, offset) \
383 bus_space_read_2( (map)->bst, (map)->bsh, (offset))
384 #define DRM_READ32(map, offset) \
385 bus_space_read_4( (map)->bst, (map)->bsh, (offset))
386 #define DRM_WRITE8(map, offset, val) \
387 bus_space_write_1((map)->bst, (map)->bsh, (offset), (val))
388 #define DRM_WRITE16(map, offset, val) \
389 bus_space_write_2((map)->bst, (map)->bsh, (offset), (val))
390 #define DRM_WRITE32(map, offset, val) \
391 bus_space_write_4((map)->bst, (map)->bsh, (offset), (val))
392
393 #define DRM_VERIFYAREA_READ( uaddr, size ) \
394 (!uvm_map_checkprot(&(curproc->p_vmspace->vm_map), \
395 (vaddr_t)uaddr, (vaddr_t)uaddr+size, UVM_PROT_READ))
396
397 #endif
398
399 #define DRM_COPY_TO_USER(user, kern, size) \
400 copyout(kern, user, size)
401 #define DRM_COPY_FROM_USER(kern, user, size) \
402 copyin(user, kern, size)
403 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
404 copyin(arg2, arg1, arg3)
405 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
406 copyout(arg2, arg1, arg3)
407 #if defined(__FreeBSD__)
408 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
409 ((val) = fuword32(uaddr), 0)
410 #else
411 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
412 ((val) = fuword(uaddr), 0)
413 #endif
414
415 #define cpu_to_le32(x) htole32(x)
416 #define le32_to_cpu(x) le32toh(x)
417
418 #define DRM_HZ hz
419 #define DRM_UDELAY(udelay) DELAY(udelay)
420 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
421
422 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
423 (_map) = (_dev)->context_sareas[_ctx]; \
424 } while(0)
425
426 #define LOCK_TEST_WITH_RETURN(dev, file_priv) \
427 do { \
428 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
429 dev->lock.file_priv != file_priv) { \
430 DRM_ERROR("%s called without lock held\n", \
431 __FUNCTION__); \
432 return EINVAL; \
433 } \
434 } while (0)
435
436 /* Returns -errno to shared code */
437 #if defined(__FreeBSD__)
438 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
439 for ( ret = 0 ; !ret && !(condition) ; ) { \
440 DRM_UNLOCK(); \
441 mtx_lock(&dev->irq_lock); \
442 if (!(condition)) \
443 ret = -mtx_sleep(&(queue), &dev->irq_lock, \
444 PCATCH, "drmwtq", (timeout)); \
445 mtx_unlock(&dev->irq_lock); \
446 DRM_LOCK(); \
447 }
448 #elif defined(__NetBSD__)
449 /* Returns -errno to shared code */
450 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
451 for ( ret = 0 ; !ret && !(condition) ; ) { \
452 DRM_UNLOCK(); \
453 mutex_enter(&dev->irq_lock); \
454 if (!(condition)) \
455 ret = -mtsleep(&(queue), PCATCH, \
456 "drmwtq", (timeout), &dev->irq_lock); \
457 mutex_exit(&dev->irq_lock); \
458 DRM_LOCK(); \
459 }
460 #endif
461
462 #define DRM_ERROR(fmt, ...) \
463 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
464 DRM_CURRENTPID, __func__ , ##__VA_ARGS__)
465
466 #define DRM_INFO(fmt, ...) printf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
467
468 #define DRM_DEBUG(fmt, ...) do { \
469 if (drm_debug_flag) \
470 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
471 __func__ , ##__VA_ARGS__); \
472 } while (0)
473
474 typedef struct drm_pci_id_list
475 {
476 int vendor;
477 int device;
478 long driver_private;
479 #if defined(__NetBSD__)
480 const char *name;
481 #else
482 char *name;
483 #endif
484 } drm_pci_id_list_t;
485
486 struct drm_msi_blacklist_entry
487 {
488 int vendor;
489 int device;
490 };
491
492 #define DRM_AUTH 0x1
493 #define DRM_MASTER 0x2
494 #define DRM_ROOT_ONLY 0x4
495 typedef struct drm_ioctl_desc {
496 unsigned long cmd;
497 int (*func)(struct drm_device *dev, void *data,
498 struct drm_file *file_priv);
499 int flags;
500 } drm_ioctl_desc_t;
501 /**
502 * Creates a driver or general drm_ioctl_desc array entry for the given
503 * ioctl, for use by drm_ioctl().
504 */
505 #define DRM_IOCTL_DEF(ioctl, func, flags) \
506 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
507
508 typedef struct drm_magic_entry {
509 drm_magic_t magic;
510 struct drm_file *priv;
511 struct drm_magic_entry *next;
512 } drm_magic_entry_t;
513
514 typedef struct drm_magic_head {
515 struct drm_magic_entry *head;
516 struct drm_magic_entry *tail;
517 } drm_magic_head_t;
518
519 typedef struct drm_buf {
520 int idx; /* Index into master buflist */
521 int total; /* Buffer size */
522 int order; /* log-base-2(total) */
523 int used; /* Amount of buffer in use (for DMA) */
524 unsigned long offset; /* Byte offset (used internally) */
525 void *address; /* Address of buffer */
526 unsigned long bus_address; /* Bus address of buffer */
527 struct drm_buf *next; /* Kernel-only: used for free list */
528 __volatile__ int pending; /* On hardware DMA queue */
529 struct drm_file *file_priv; /* Unique identifier of holding process */
530 int context; /* Kernel queue for this buffer */
531 enum {
532 DRM_LIST_NONE = 0,
533 DRM_LIST_FREE = 1,
534 DRM_LIST_WAIT = 2,
535 DRM_LIST_PEND = 3,
536 DRM_LIST_PRIO = 4,
537 DRM_LIST_RECLAIM = 5
538 } list; /* Which list we're on */
539
540 int dev_priv_size; /* Size of buffer private stoarge */
541 void *dev_private; /* Per-buffer private storage */
542 } drm_buf_t;
543
544 typedef struct drm_freelist {
545 int initialized; /* Freelist in use */
546 atomic_t count; /* Number of free buffers */
547 drm_buf_t *next; /* End pointer */
548
549 int low_mark; /* Low water mark */
550 int high_mark; /* High water mark */
551 } drm_freelist_t;
552
553 typedef struct drm_dma_handle {
554 void *vaddr;
555 bus_addr_t busaddr;
556 bus_dma_tag_t tag;
557 bus_dmamap_t map;
558 #if defined(__NetBSD__)
559 size_t size;
560 size_t nsegs;
561 bus_dma_segment_t segs[1];
562 #endif
563 } drm_dma_handle_t;
564
565 typedef struct drm_buf_entry {
566 int buf_size;
567 int buf_count;
568 drm_buf_t *buflist;
569 int seg_count;
570 drm_dma_handle_t **seglist;
571 int page_order;
572
573 drm_freelist_t freelist;
574 } drm_buf_entry_t;
575
576 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
577 struct drm_file {
578 TAILQ_ENTRY(drm_file) link;
579 struct drm_device *dev;
580 int authenticated;
581 int master;
582 int minor;
583 pid_t pid;
584 uid_t uid;
585 #if defined(__NetBSD__)
586 int refs;
587 #endif
588 drm_magic_t magic;
589 unsigned long ioctl_count;
590 void *driver_priv;
591 };
592
593 typedef struct drm_lock_data {
594 struct drm_hw_lock *hw_lock; /* Hardware lock */
595 struct drm_file *file_priv; /* Unique identifier of holding process (NULL is kernel)*/
596 int lock_queue; /* Queue of blocked processes */
597 unsigned long lock_time; /* Time of last lock in jiffies */
598 } drm_lock_data_t;
599
600 /* This structure, in the struct drm_device, is always initialized while the
601 * device
602 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
603 * when set marks that no further bufs may be allocated until device teardown
604 * occurs (when the last open of the device has closed). The high/low
605 * watermarks of bufs are only touched by the X Server, and thus not
606 * concurrently accessed, so no locking is needed.
607 */
608 typedef struct drm_device_dma {
609 drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
610 int buf_count;
611 drm_buf_t **buflist; /* Vector of pointers info bufs */
612 int seg_count;
613 int page_count;
614 unsigned long *pagelist;
615 unsigned long byte_count;
616 enum {
617 _DRM_DMA_USE_AGP = 0x01,
618 _DRM_DMA_USE_SG = 0x02
619 } flags;
620 } drm_device_dma_t;
621
622 typedef struct drm_agp_mem {
623 void *handle;
624 unsigned long bound; /* address */
625 int pages;
626 struct drm_agp_mem *prev;
627 struct drm_agp_mem *next;
628 } drm_agp_mem_t;
629
630 typedef struct drm_agp_head {
631 device_t agpdev;
632 struct agp_info info;
633 const char *chipset;
634 drm_agp_mem_t *memory;
635 unsigned long mode;
636 int enabled;
637 int acquired;
638 unsigned long base;
639 int mtrr;
640 int cant_use_aperture;
641 unsigned long page_mask;
642 } drm_agp_head_t;
643
644 typedef struct drm_sg_mem {
645 unsigned long handle;
646 void *virtual;
647 int pages;
648 dma_addr_t *busaddr;
649 struct drm_dma_handle *sg_dmah; /* Handle for sg_pages */
650 struct drm_dma_handle *dmah; /* Handle to PCI memory */
651 /* for ATI PCIGART table */
652 } drm_sg_mem_t;
653
654 typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
655
656 typedef struct drm_local_map {
657 unsigned long offset; /* Physical address (0 for SAREA)*/
658 unsigned long size; /* Physical size (bytes) */
659 enum drm_map_type type; /* Type of memory mapped */
660 enum drm_map_flags flags; /* Flags */
661 void *handle; /* User-space: "Handle" to pass to mmap */
662 /* Kernel-space: kernel-virtual address */
663 int mtrr; /* Boolean: MTRR used */
664 /* Private data */
665 int rid; /* PCI resource ID for bus_space */
666 #if defined(__FreeBSD__)
667 struct resource *bsr;
668 #endif
669 bus_space_tag_t bst;
670 bus_space_handle_t bsh;
671 drm_dma_handle_t *dmah;
672 #if defined(__NetBSD__)
673 int *cnt;
674 bus_size_t mapsize;
675 #endif
676 TAILQ_ENTRY(drm_local_map) link;
677 } drm_local_map_t;
678
679 TAILQ_HEAD(drm_vbl_sig_list, drm_vbl_sig);
680 typedef struct drm_vbl_sig {
681 TAILQ_ENTRY(drm_vbl_sig) link;
682 unsigned int sequence;
683 int signo;
684 int pid;
685 } drm_vbl_sig_t;
686
687 struct drm_vblank_info {
688 wait_queue_head_t queue; /* vblank wait queue */
689 atomic_t count; /* number of VBLANK interrupts */
690 /* (driver must alloc the right number of counters) */
691 struct drm_vbl_sig_list sigs; /* signal list to send on VBLANK */
692 atomic_t refcount; /* number of users of vblank interrupts */
693 u32 last; /* protected by dev->vbl_lock, used */
694 /* for wraparound handling */
695 int enabled; /* so we don't call enable more than */
696 /* once per disable */
697 int inmodeset; /* Display driver is setting mode */
698 };
699
700 /* location of GART table */
701 #define DRM_ATI_GART_MAIN 1
702 #define DRM_ATI_GART_FB 2
703
704 #define DRM_ATI_GART_PCI 1
705 #define DRM_ATI_GART_PCIE 2
706 #define DRM_ATI_GART_IGP 3
707
708 struct drm_ati_pcigart_info {
709 int gart_table_location;
710 int gart_reg_if;
711 void *addr;
712 dma_addr_t bus_addr;
713 dma_addr_t table_mask;
714 dma_addr_t member_mask;
715 struct drm_dma_handle *table_handle;
716 drm_local_map_t mapping;
717 int table_size;
718 };
719
720 #ifndef DMA_BIT_MASK
721 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
722 #endif
723
724 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
725
726 struct drm_driver_info {
727 int (*load)(struct drm_device *, unsigned long flags);
728 int (*firstopen)(struct drm_device *);
729 int (*open)(struct drm_device *, struct drm_file *);
730 void (*preclose)(struct drm_device *, struct drm_file *file_priv);
731 void (*postclose)(struct drm_device *, struct drm_file *);
732 void (*lastclose)(struct drm_device *);
733 int (*unload)(struct drm_device *);
734 void (*reclaim_buffers_locked)(struct drm_device *,
735 struct drm_file *file_priv);
736 int (*dma_ioctl)(struct drm_device *dev, void *data,
737 struct drm_file *file_priv);
738 void (*dma_ready)(struct drm_device *);
739 int (*dma_quiescent)(struct drm_device *);
740 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
741 enum drm_lock_flags flags);
742 int (*dma_flush_unblock)(struct drm_device *, int context,
743 enum drm_lock_flags flags);
744 int (*context_ctor)(struct drm_device *dev, int context);
745 int (*context_dtor)(struct drm_device *dev, int context);
746 int (*kernel_context_switch)(struct drm_device *dev, int old,
747 int new);
748 int (*kernel_context_switch_unlock)(struct drm_device *dev);
749 void (*irq_preinstall)(struct drm_device *dev);
750 int (*irq_postinstall)(struct drm_device *dev);
751 void (*irq_uninstall)(struct drm_device *dev);
752 irqreturn_t (*irq_handler)(DRM_IRQ_ARGS);
753 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc);
754 int (*enable_vblank)(struct drm_device *dev, int crtc);
755 void (*disable_vblank)(struct drm_device *dev, int crtc);
756
757 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
758
759 /**
760 * Called by \c drm_device_is_agp. Typically used to determine if a
761 * card is really attached to AGP or not.
762 *
763 * \param dev DRM device handle
764 *
765 * \returns
766 * One of three values is returned depending on whether or not the
767 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
768 * (return of 1), or may or may not be AGP (return of 2).
769 */
770 int (*device_is_agp) (struct drm_device * dev);
771
772 drm_ioctl_desc_t *ioctls;
773 int max_ioctl;
774
775 int buf_priv_size;
776
777 int major;
778 int minor;
779 int patchlevel;
780 const char *name; /* Simple driver name */
781 const char *desc; /* Longer driver name */
782 const char *date; /* Date of last major changes. */
783
784 u32 driver_features;
785 };
786
787 /* Length for the array of resource pointers for drm_get_resource_*. */
788 #define DRM_MAX_PCI_RESOURCE 6
789
790 #if defined(__NetBSD__)
791 typedef struct {
792 int mapped;
793 int maptype;
794 bus_addr_t base;
795 bus_size_t size;
796 bus_space_handle_t bsh;
797 int flags;
798 void * vaddr;
799 } pci_map_data_t;
800 #endif
801
802 /**
803 * DRM device functions structure
804 */
805 struct drm_device {
806 struct drm_driver_info *driver;
807 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
808
809 u_int16_t pci_device; /* PCI device id */
810 u_int16_t pci_vendor; /* PCI vendor id */
811
812 char *unique; /* Unique identifier: e.g., busid */
813 int unique_len; /* Length of unique field */
814 device_t device; /* Device instance from newbus */
815 #if defined(__FreeBSD__)
816 struct cdev *devnode; /* Device number for mknod */
817 #endif
818 int if_version; /* Highest interface version set */
819
820 int flags; /* Flags to open(2) */
821
822 /* Locks */
823 DRM_SPINTYPE vbl_lock; /* protects vblank operations */
824 DRM_SPINTYPE dma_lock; /* protects dev->dma */
825 DRM_SPINTYPE irq_lock; /* protects irq condition checks */
826 DRM_SPINTYPE dev_lock; /* protects everything else */
827 DRM_SPINTYPE drw_lock;
828
829 /* Usage Counters */
830 int open_count; /* Outstanding files open */
831 int buf_use; /* Buffers in use -- cannot alloc */
832
833 /* Performance counters */
834 unsigned long counters;
835 enum drm_stat_type types[15];
836 atomic_t counts[15];
837
838 /* Authentication */
839 drm_file_list_t files;
840 drm_magic_head_t magiclist[DRM_HASH_SIZE];
841
842 /* Linked list of mappable regions. Protected by dev_lock */
843 drm_map_list_t maplist;
844
845 drm_local_map_t **context_sareas;
846 int max_context;
847
848 drm_lock_data_t lock; /* Information on hardware lock */
849
850 /* DMA queues (contexts) */
851 drm_device_dma_t *dma; /* Optional pointer for DMA support */
852
853 /* Context support */
854 int irq; /* Interrupt used by board */
855 int irq_enabled; /* True if the irq handler is enabled */
856 int msi_enabled; /* MSI enabled */
857 #if defined(__FreeBSD__)
858 int irqrid; /* Interrupt used by board */
859 struct resource *irqr; /* Resource for interrupt used by board */
860
861 /* Storage of resource pointers for drm_get_resource_* */
862 struct resource *pcir[DRM_MAX_PCI_RESOURCE];
863 int pcirid[DRM_MAX_PCI_RESOURCE];
864 #elif defined(__NetBSD__)
865 struct pci_attach_args pa;
866 pci_map_data_t pci_map_data[DRM_MAX_PCI_RESOURCE];
867 pci_map_data_t agp_map_data[DRM_MAX_PCI_RESOURCE];
868 dev_t kdev;
869 #endif
870 void *irqh; /* Handle from bus_setup_intr */
871
872 int pci_domain;
873 int pci_bus;
874 int pci_slot;
875 int pci_func;
876
877 atomic_t context_flag; /* Context swapping flag */
878 int last_context; /* Last current context */
879
880 int vblank_disable_allowed;
881 atomic_t vbl_signal_pending; /* number of signals pending on all crtcs */
882 struct callout vblank_disable_timer;
883 u32 max_vblank_count; /* size of vblank counter register */
884 struct drm_vblank_info *vblank; /* per crtc vblank info */
885 int num_crtcs;
886
887 #if defined(__FreeBSD__)
888 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
889 #elif defined(__NetBSD__)
890 pid_t buf_pgid;
891 #endif
892
893 /* Sysctl support */
894 struct drm_sysctl_info *sysctl;
895
896 drm_agp_head_t *agp;
897 drm_sg_mem_t *sg; /* Scatter gather memory */
898 atomic_t *ctx_bitmap;
899 void *dev_private;
900 unsigned int agp_buffer_token;
901 drm_local_map_t *agp_buffer_map;
902
903 #if defined(__FreeBSD__)
904 struct unrhdr *drw_unrhdr;
905 #elif defined(__NetBSD__)
906 int drw_no;
907 #endif
908 /* RB tree of drawable infos */
909 RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head;
910 };
911
912 static __inline__ int drm_core_check_feature(struct drm_device *dev,
913 int feature)
914 {
915 return ((dev->driver->driver_features & feature) ? 1 : 0);
916 }
917
918 #if __OS_HAS_AGP
919 static inline int drm_core_has_AGP(struct drm_device *dev)
920 {
921 return drm_core_check_feature(dev, DRIVER_USE_AGP);
922 }
923 #else
924 #define drm_core_has_AGP(dev) (0)
925 #endif
926
927 extern int drm_debug_flag;
928
929 /* Device setup support (drm_drv.c) */
930 #if defined(__FreeBSD__)
931 int drm_probe(device_t kdev, drm_pci_id_list_t *idlist);
932 int drm_attach(device_t kdev, drm_pci_id_list_t *idlist);
933 void drm_close(void *data);
934 int drm_detach(device_t kdev);
935 d_ioctl_t drm_ioctl;
936 d_open_t drm_open;
937 d_read_t drm_read;
938 d_poll_t drm_poll;
939 d_mmap_t drm_mmap;
940 #elif defined(__NetBSD__)
941 int drm_probe(struct pci_attach_args *pa, drm_pci_id_list_t *idlist);
942 void drm_attach(device_t kdev, struct pci_attach_args *pa, drm_pci_id_list_t *idlist);
943 int drm_detach(device_t self, int flags);
944 int drm_activate(device_t self, devact_t act);
945 dev_type_ioctl(drm_ioctl);
946 dev_type_open(drm_open);
947 dev_type_close(drm_close);
948 dev_type_read(drm_read);
949 dev_type_poll(drm_poll);
950 dev_type_mmap(drm_mmap);
951 #endif
952 extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
953
954 int drm_close_pid(struct drm_device *dev, struct drm_file *priv, pid_t pid);
955
956 /* File operations helpers (drm_fops.c) */
957 #if defined(__FreeBSD__)
958 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
959 DRM_STRUCTPROC *p,
960 struct drm_device *dev);
961 #elif defined(__NetBSD__)
962 extern struct drm_file *drm_find_file_by_proc(struct drm_device *dev,
963 struct proc *p);
964 extern int drm_open_helper(dev_t kdev, int flags, int fmt,
965 struct proc *p, struct drm_device *dev);
966 #endif
967
968 /* Memory management support (drm_memory.c) */
969 void drm_mem_init(void);
970 void drm_mem_uninit(void);
971 void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map);
972 void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map);
973 void drm_ioremapfree(drm_local_map_t *map);
974 #if defined(__FreeBSD__)
975 int drm_mtrr_add(unsigned long offset, size_t size, int flags);
976 int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
977 #elif defined(__NetBSD__)
978 int drm_mtrr_add(unsigned long offset, size_t size, int flags);
979 int drm_mtrr_del(unsigned long offset, size_t size, int flags);
980 #endif
981
982 int drm_context_switch(struct drm_device *dev, int old, int new);
983 int drm_context_switch_complete(struct drm_device *dev, int new);
984
985 int drm_ctxbitmap_init(struct drm_device *dev);
986 void drm_ctxbitmap_cleanup(struct drm_device *dev);
987 void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
988 int drm_ctxbitmap_next(struct drm_device *dev);
989
990 /* Locking IOCTL support (drm_lock.c) */
991 int drm_lock_take(struct drm_lock_data *lock_data,
992 unsigned int context);
993 int drm_lock_transfer(struct drm_lock_data *lock_data,
994 unsigned int context);
995 int drm_lock_free(struct drm_lock_data *lock_data,
996 unsigned int context);
997
998 /* Buffer management support (drm_bufs.c) */
999 unsigned long drm_get_resource_start(struct drm_device *dev,
1000 unsigned int resource);
1001 unsigned long drm_get_resource_len(struct drm_device *dev,
1002 unsigned int resource);
1003 void drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
1004 int drm_order(unsigned long size);
1005 int drm_addmap(struct drm_device *dev, unsigned long offset,
1006 unsigned long size,
1007 enum drm_map_type type, enum drm_map_flags flags,
1008 drm_local_map_t **map_ptr);
1009 int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request);
1010 int drm_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request);
1011 int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request);
1012
1013 /* DMA support (drm_dma.c) */
1014 int drm_dma_setup(struct drm_device *dev);
1015 void drm_dma_takedown(struct drm_device *dev);
1016 void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf);
1017 void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv);
1018 #define drm_core_reclaim_buffers drm_reclaim_buffers
1019
1020 /* IRQ support (drm_irq.c) */
1021 int drm_irq_install(struct drm_device *dev);
1022 int drm_irq_uninstall(struct drm_device *dev);
1023 irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
1024 void drm_driver_irq_preinstall(struct drm_device *dev);
1025 void drm_driver_irq_postinstall(struct drm_device *dev);
1026 void drm_driver_irq_uninstall(struct drm_device *dev);
1027 void drm_handle_vblank(struct drm_device *dev, int crtc);
1028 u32 drm_vblank_count(struct drm_device *dev, int crtc);
1029 int drm_vblank_get(struct drm_device *dev, int crtc);
1030 void drm_vblank_put(struct drm_device *dev, int crtc);
1031 void drm_vblank_cleanup(struct drm_device *dev);
1032 int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
1033 int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1034 void drm_vbl_send_signals(struct drm_device *dev, int crtc);
1035 int drm_modeset_ctl(struct drm_device *dev, void *data,
1036 struct drm_file *file_priv);
1037
1038 /* AGP/PCI Express/GART support (drm_agpsupport.c) */
1039 int drm_device_is_agp(struct drm_device *dev);
1040 int drm_device_is_pcie(struct drm_device *dev);
1041 drm_agp_head_t *drm_agp_init(struct drm_device *dev);
1042 int drm_agp_acquire(struct drm_device *dev);
1043 int drm_agp_release(struct drm_device *dev);
1044 int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info);
1045 int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1046 void *drm_agp_allocate_memory(size_t pages, u32 type);
1047 int drm_agp_free_memory(void *handle);
1048 int drm_agp_bind_memory(void *handle, off_t start);
1049 int drm_agp_unbind_memory(void *handle);
1050 int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1051 int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1052 int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1053 int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1054
1055 /* Scatter Gather Support (drm_scatter.c) */
1056 void drm_sg_cleanup(drm_sg_mem_t *entry);
1057 int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
1058
1059 /* sysctl support (drm_sysctl.h) */
1060 extern int drm_sysctl_init(struct drm_device *dev);
1061 extern int drm_sysctl_cleanup(struct drm_device *dev);
1062
1063 /* ATI PCIGART support (ati_pcigart.c) */
1064 int drm_ati_pcigart_init(struct drm_device *dev,
1065 struct drm_ati_pcigart_info *gart_info);
1066 int drm_ati_pcigart_cleanup(struct drm_device *dev,
1067 struct drm_ati_pcigart_info *gart_info);
1068
1069 /* Locking IOCTL support (drm_drv.c) */
1070 int drm_lock(struct drm_device *dev, void *data,
1071 struct drm_file *file_priv);
1072 int drm_unlock(struct drm_device *dev, void *data,
1073 struct drm_file *file_priv);
1074 int drm_version(struct drm_device *dev, void *data,
1075 struct drm_file *file_priv);
1076 int drm_setversion(struct drm_device *dev, void *data,
1077 struct drm_file *file_priv);
1078
1079 /* Misc. IOCTL support (drm_ioctl.c) */
1080 int drm_irq_by_busid(struct drm_device *dev, void *data,
1081 struct drm_file *file_priv);
1082 int drm_getunique(struct drm_device *dev, void *data,
1083 struct drm_file *file_priv);
1084 int drm_setunique(struct drm_device *dev, void *data,
1085 struct drm_file *file_priv);
1086 int drm_getmap(struct drm_device *dev, void *data,
1087 struct drm_file *file_priv);
1088 int drm_getclient(struct drm_device *dev, void *data,
1089 struct drm_file *file_priv);
1090 int drm_getstats(struct drm_device *dev, void *data,
1091 struct drm_file *file_priv);
1092 int drm_noop(struct drm_device *dev, void *data,
1093 struct drm_file *file_priv);
1094
1095 /* Context IOCTL support (drm_context.c) */
1096 int drm_resctx(struct drm_device *dev, void *data,
1097 struct drm_file *file_priv);
1098 int drm_addctx(struct drm_device *dev, void *data,
1099 struct drm_file *file_priv);
1100 int drm_modctx(struct drm_device *dev, void *data,
1101 struct drm_file *file_priv);
1102 int drm_getctx(struct drm_device *dev, void *data,
1103 struct drm_file *file_priv);
1104 int drm_switchctx(struct drm_device *dev, void *data,
1105 struct drm_file *file_priv);
1106 int drm_newctx(struct drm_device *dev, void *data,
1107 struct drm_file *file_priv);
1108 int drm_rmctx(struct drm_device *dev, void *data,
1109 struct drm_file *file_priv);
1110 int drm_setsareactx(struct drm_device *dev, void *data,
1111 struct drm_file *file_priv);
1112 int drm_getsareactx(struct drm_device *dev, void *data,
1113 struct drm_file *file_priv);
1114
1115 /* Drawable IOCTL support (drm_drawable.c) */
1116 int drm_adddraw(struct drm_device *dev, void *data,
1117 struct drm_file *file_priv);
1118 int drm_rmdraw(struct drm_device *dev, void *data,
1119 struct drm_file *file_priv);
1120 int drm_update_draw(struct drm_device *dev, void *data,
1121 struct drm_file *file_priv);
1122 struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
1123 int handle);
1124
1125 /* Drawable support (drm_drawable.c) */
1126 void drm_drawable_free_all(struct drm_device *dev);
1127
1128 /* Authentication IOCTL support (drm_auth.c) */
1129 int drm_getmagic(struct drm_device *dev, void *data,
1130 struct drm_file *file_priv);
1131 int drm_authmagic(struct drm_device *dev, void *data,
1132 struct drm_file *file_priv);
1133
1134 /* Buffer management support (drm_bufs.c) */
1135 int drm_addmap_ioctl(struct drm_device *dev, void *data,
1136 struct drm_file *file_priv);
1137 int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1138 struct drm_file *file_priv);
1139 int drm_addbufs(struct drm_device *dev, void *data,
1140 struct drm_file *file_priv);
1141 int drm_infobufs(struct drm_device *dev, void *data,
1142 struct drm_file *file_priv);
1143 int drm_markbufs(struct drm_device *dev, void *data,
1144 struct drm_file *file_priv);
1145 int drm_freebufs(struct drm_device *dev, void *data,
1146 struct drm_file *file_priv);
1147 int drm_mapbufs(struct drm_device *dev, void *data,
1148 struct drm_file *file_priv);
1149
1150 /* DMA support (drm_dma.c) */
1151 int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv);
1152
1153 /* IRQ support (drm_irq.c) */
1154 int drm_control(struct drm_device *dev, void *data,
1155 struct drm_file *file_priv);
1156 int drm_wait_vblank(struct drm_device *dev, void *data,
1157 struct drm_file *file_priv);
1158
1159 /* AGP/GART support (drm_agpsupport.c) */
1160 int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1161 struct drm_file *file_priv);
1162 int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1163 struct drm_file *file_priv);
1164 int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1165 struct drm_file *file_priv);
1166 int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1167 struct drm_file *file_priv);
1168 int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1169 struct drm_file *file_priv);
1170 int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1171 struct drm_file *file_priv);
1172 int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1173 struct drm_file *file_priv);
1174 int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1175 struct drm_file *file_priv);
1176
1177 /* Scatter Gather Support (drm_scatter.c) */
1178 int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1179 struct drm_file *file_priv);
1180 int drm_sg_free(struct drm_device *dev, void *data,
1181 struct drm_file *file_priv);
1182
1183 /* consistent PCI memory functions (drm_pci.c) */
1184 drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1185 size_t align, dma_addr_t maxaddr);
1186 void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1187
1188 /* Inline replacements for drm_alloc and friends */
1189 static __inline__ void *
1190 drm_alloc(size_t size, struct malloc_type *area)
1191 {
1192 return malloc(size, area, M_NOWAIT);
1193 }
1194
1195 static __inline__ void *
1196 drm_calloc(size_t nmemb, size_t size, struct malloc_type *area)
1197 {
1198 return malloc(size * nmemb, area, M_NOWAIT | M_ZERO);
1199 }
1200
1201 static __inline__ void *
1202 drm_realloc(void *oldpt, size_t oldsize, size_t size,
1203 struct malloc_type *area)
1204 {
1205 #if defined(__FreeBSD__)
1206 return reallocf(oldpt, size, area, M_NOWAIT);
1207 #elif defined(__NetBSD__)
1208 void *pt;
1209
1210 pt = malloc(size, area, M_NOWAIT);
1211 if (pt == NULL)
1212 return NULL;
1213 if (oldpt && oldsize) {
1214 memcpy(pt, oldpt, oldsize);
1215 free(oldpt, area);
1216 }
1217 return pt;
1218 #endif
1219 }
1220
1221 static __inline__ void
1222 drm_free(void *pt, size_t size, struct malloc_type *area)
1223 {
1224 free(pt, area);
1225 }
1226
1227 /* Inline replacements for DRM_IOREMAP macros */
1228 static __inline__ void
1229 drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
1230 {
1231 map->handle = drm_ioremap_wc(dev, map);
1232 }
1233 static __inline__ void
1234 drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
1235 {
1236 map->handle = drm_ioremap(dev, map);
1237 }
1238 static __inline__ void
1239 drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
1240 {
1241 if ( map->handle && map->size )
1242 drm_ioremapfree(map);
1243 }
1244
1245 static __inline__ struct drm_local_map *
1246 drm_core_findmap(struct drm_device *dev, unsigned long offset)
1247 {
1248 drm_local_map_t *map;
1249
1250 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
1251 TAILQ_FOREACH(map, &dev->maplist, link) {
1252 if (map->offset == offset)
1253 return map;
1254 }
1255 return NULL;
1256 }
1257
1258 static __inline__ void drm_core_dropmap(struct drm_map *map)
1259 {
1260 }
1261
1262 #endif /* __KERNEL__ */
1263 #endif /* _DRM_P_H_ */
1264