drmP.h revision 1.10.2.5 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) ALIGN(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 #if defined(__FreeBSD__)
361
362 #define DRM_READ8(map, offset) \
363 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \
364 (vm_offset_t)(offset))
365 #define DRM_READ16(map, offset) \
366 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \
367 (vm_offset_t)(offset))
368 #define DRM_READ32(map, offset) \
369 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \
370 (vm_offset_t)(offset))
371 #define DRM_WRITE8(map, offset, val) \
372 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \
373 (vm_offset_t)(offset)) = val
374 #define DRM_WRITE16(map, offset, val) \
375 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \
376 (vm_offset_t)(offset)) = val
377 #define DRM_WRITE32(map, offset, val) \
378 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \
379 (vm_offset_t)(offset)) = val
380
381 #define DRM_VERIFYAREA_READ( uaddr, size ) \
382 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
383
384 #elif defined(__NetBSD__)
385
386 typedef vaddr_t vm_offset_t;
387
388 #define DRM_READ8(map, offset) \
389 bus_space_read_1( (map)->bst, (map)->bsh, (offset))
390 #define DRM_READ16(map, offset) \
391 bus_space_read_2( (map)->bst, (map)->bsh, (offset))
392 #define DRM_READ32(map, offset) \
393 bus_space_read_4( (map)->bst, (map)->bsh, (offset))
394 #define DRM_WRITE8(map, offset, val) \
395 bus_space_write_1((map)->bst, (map)->bsh, (offset), (val))
396 #define DRM_WRITE16(map, offset, val) \
397 bus_space_write_2((map)->bst, (map)->bsh, (offset), (val))
398 #define DRM_WRITE32(map, offset, val) \
399 bus_space_write_4((map)->bst, (map)->bsh, (offset), (val))
400
401 #define DRM_VERIFYAREA_READ( uaddr, size ) \
402 (!uvm_map_checkprot(&(curproc->p_vmspace->vm_map), \
403 (vaddr_t)uaddr, (vaddr_t)uaddr+size, UVM_PROT_READ))
404
405 #endif
406
407 #define DRM_COPY_TO_USER(user, kern, size) \
408 copyout(kern, user, size)
409 #define DRM_COPY_FROM_USER(kern, user, size) \
410 copyin(user, kern, size)
411 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
412 copyin(arg2, arg1, arg3)
413 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
414 copyout(arg2, arg1, arg3)
415 #if defined(__FreeBSD__)
416 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
417 ((val) = fuword32(uaddr), 0)
418 #else
419 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
420 ((val) = fuword(uaddr), 0)
421 #endif
422
423 #define cpu_to_le32(x) htole32(x)
424 #define le32_to_cpu(x) le32toh(x)
425
426 #define DRM_HZ hz
427 #define DRM_UDELAY(udelay) DELAY(udelay)
428 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
429
430 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
431 (_map) = (_dev)->context_sareas[_ctx]; \
432 } while(0)
433
434 #define LOCK_TEST_WITH_RETURN(dev, file_priv) \
435 do { \
436 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
437 dev->lock.file_priv != file_priv) { \
438 DRM_ERROR("%s called without lock held\n", \
439 __FUNCTION__); \
440 return EINVAL; \
441 } \
442 } while (0)
443
444 /* Returns -errno to shared code */
445 #if defined(__FreeBSD__)
446 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
447 for ( ret = 0 ; !ret && !(condition) ; ) { \
448 DRM_UNLOCK(); \
449 mtx_lock(&dev->irq_lock); \
450 if (!(condition)) \
451 ret = -mtx_sleep(&(queue), &dev->irq_lock, \
452 PCATCH, "drmwtq", (timeout)); \
453 mtx_unlock(&dev->irq_lock); \
454 DRM_LOCK(); \
455 }
456 #elif defined(__NetBSD__)
457 /* Returns -errno to shared code */
458 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
459 for ( ret = 0 ; !ret && !(condition) ; ) { \
460 DRM_UNLOCK(); \
461 mutex_enter(&dev->irq_lock); \
462 if (!(condition)) \
463 ret = -mtsleep(&(queue), PCATCH, \
464 "drmwtq", (timeout), &dev->irq_lock); \
465 mutex_exit(&dev->irq_lock); \
466 DRM_LOCK(); \
467 }
468 #endif
469
470 #define DRM_ERROR(fmt, ...) \
471 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
472 DRM_CURRENTPID, __func__ , ##__VA_ARGS__)
473
474 #define DRM_INFO(fmt, ...) printf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
475
476 #define DRM_DEBUG(fmt, ...) do { \
477 if (drm_debug_flag) \
478 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
479 __func__ , ##__VA_ARGS__); \
480 } while (0)
481
482 typedef struct drm_pci_id_list
483 {
484 int vendor;
485 int device;
486 long driver_private;
487 #if defined(__NetBSD__)
488 const char *name;
489 #else
490 char *name;
491 #endif
492 } drm_pci_id_list_t;
493
494 struct drm_msi_blacklist_entry
495 {
496 int vendor;
497 int device;
498 };
499
500 #define DRM_AUTH 0x1
501 #define DRM_MASTER 0x2
502 #define DRM_ROOT_ONLY 0x4
503 typedef struct drm_ioctl_desc {
504 unsigned long cmd;
505 int (*func)(struct drm_device *dev, void *data,
506 struct drm_file *file_priv);
507 int flags;
508 } drm_ioctl_desc_t;
509 /**
510 * Creates a driver or general drm_ioctl_desc array entry for the given
511 * ioctl, for use by drm_ioctl().
512 */
513 #define DRM_IOCTL_DEF(ioctl, func, flags) \
514 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
515
516 typedef struct drm_magic_entry {
517 drm_magic_t magic;
518 struct drm_file *priv;
519 struct drm_magic_entry *next;
520 } drm_magic_entry_t;
521
522 typedef struct drm_magic_head {
523 struct drm_magic_entry *head;
524 struct drm_magic_entry *tail;
525 } drm_magic_head_t;
526
527 typedef struct drm_buf {
528 int idx; /* Index into master buflist */
529 int total; /* Buffer size */
530 int order; /* log-base-2(total) */
531 int used; /* Amount of buffer in use (for DMA) */
532 unsigned long offset; /* Byte offset (used internally) */
533 void *address; /* Address of buffer */
534 unsigned long bus_address; /* Bus address of buffer */
535 struct drm_buf *next; /* Kernel-only: used for free list */
536 __volatile__ int pending; /* On hardware DMA queue */
537 struct drm_file *file_priv; /* Unique identifier of holding process */
538 int context; /* Kernel queue for this buffer */
539 enum {
540 DRM_LIST_NONE = 0,
541 DRM_LIST_FREE = 1,
542 DRM_LIST_WAIT = 2,
543 DRM_LIST_PEND = 3,
544 DRM_LIST_PRIO = 4,
545 DRM_LIST_RECLAIM = 5
546 } list; /* Which list we're on */
547
548 int dev_priv_size; /* Size of buffer private stoarge */
549 void *dev_private; /* Per-buffer private storage */
550 } drm_buf_t;
551
552 typedef struct drm_freelist {
553 int initialized; /* Freelist in use */
554 atomic_t count; /* Number of free buffers */
555 drm_buf_t *next; /* End pointer */
556
557 int low_mark; /* Low water mark */
558 int high_mark; /* High water mark */
559 } drm_freelist_t;
560
561 typedef struct drm_dma_handle {
562 void *vaddr;
563 bus_addr_t busaddr;
564 bus_dma_tag_t tag;
565 bus_dmamap_t map;
566 #if defined(__NetBSD__)
567 size_t size;
568 size_t nsegs;
569 bus_dma_segment_t segs[1];
570 #endif
571 } drm_dma_handle_t;
572
573 typedef struct drm_buf_entry {
574 int buf_size;
575 int buf_count;
576 drm_buf_t *buflist;
577 int seg_count;
578 drm_dma_handle_t **seglist;
579 int page_order;
580
581 drm_freelist_t freelist;
582 } drm_buf_entry_t;
583
584 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
585 struct drm_file {
586 TAILQ_ENTRY(drm_file) link;
587 struct drm_device *dev;
588 int authenticated;
589 int master;
590 int minor;
591 pid_t pid;
592 uid_t uid;
593 drm_magic_t magic;
594 unsigned long ioctl_count;
595 void *driver_priv;
596 };
597
598 typedef struct drm_lock_data {
599 struct drm_hw_lock *hw_lock; /* Hardware lock */
600 struct drm_file *file_priv; /* Unique identifier of holding process (NULL is kernel)*/
601 int lock_queue; /* Queue of blocked processes */
602 unsigned long lock_time; /* Time of last lock in jiffies */
603 } drm_lock_data_t;
604
605 /* This structure, in the struct drm_device, is always initialized while the
606 * device
607 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
608 * when set marks that no further bufs may be allocated until device teardown
609 * occurs (when the last open of the device has closed). The high/low
610 * watermarks of bufs are only touched by the X Server, and thus not
611 * concurrently accessed, so no locking is needed.
612 */
613 typedef struct drm_device_dma {
614 drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
615 int buf_count;
616 drm_buf_t **buflist; /* Vector of pointers info bufs */
617 int seg_count;
618 int page_count;
619 unsigned long *pagelist;
620 unsigned long byte_count;
621 enum {
622 _DRM_DMA_USE_AGP = 0x01,
623 _DRM_DMA_USE_SG = 0x02
624 } flags;
625 } drm_device_dma_t;
626
627 typedef struct drm_agp_mem {
628 void *handle;
629 unsigned long bound; /* address */
630 int pages;
631 struct drm_agp_mem *prev;
632 struct drm_agp_mem *next;
633 } drm_agp_mem_t;
634
635 typedef struct drm_agp_head {
636 device_t agpdev;
637 struct agp_info info;
638 const char *chipset;
639 drm_agp_mem_t *memory;
640 unsigned long mode;
641 int enabled;
642 int acquired;
643 unsigned long base;
644 int mtrr;
645 int cant_use_aperture;
646 unsigned long page_mask;
647 } drm_agp_head_t;
648
649 typedef struct drm_sg_mem {
650 unsigned long handle;
651 void *virtual;
652 int pages;
653 dma_addr_t *busaddr;
654 struct drm_dma_handle *sg_dmah; /* Handle for sg_pages */
655 struct drm_dma_handle *dmah; /* Handle to PCI memory */
656 /* for ATI PCIGART table */
657 } drm_sg_mem_t;
658
659 typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
660
661 typedef struct drm_local_map {
662 unsigned long offset; /* Physical address (0 for SAREA)*/
663 unsigned long size; /* Physical size (bytes) */
664 enum drm_map_type type; /* Type of memory mapped */
665 enum drm_map_flags flags; /* Flags */
666 void *handle; /* User-space: "Handle" to pass to mmap */
667 /* Kernel-space: kernel-virtual address */
668 int mtrr; /* Boolean: MTRR used */
669 /* Private data */
670 int rid; /* PCI resource ID for bus_space */
671 #if defined(__FreeBSD__)
672 struct resource *bsr;
673 #endif
674 bus_space_tag_t bst;
675 bus_space_handle_t bsh;
676 drm_dma_handle_t *dmah;
677 #if defined(__NetBSD__)
678 int *cnt;
679 bus_size_t mapsize;
680 #endif
681 TAILQ_ENTRY(drm_local_map) link;
682 } drm_local_map_t;
683
684 TAILQ_HEAD(drm_vbl_sig_list, drm_vbl_sig);
685 typedef struct drm_vbl_sig {
686 TAILQ_ENTRY(drm_vbl_sig) link;
687 unsigned int sequence;
688 int signo;
689 int pid;
690 } drm_vbl_sig_t;
691
692 struct drm_vblank_info {
693 wait_queue_head_t queue; /* vblank wait queue */
694 atomic_t count; /* number of VBLANK interrupts */
695 /* (driver must alloc the right number of counters) */
696 struct drm_vbl_sig_list sigs; /* signal list to send on VBLANK */
697 atomic_t refcount; /* number of users of vblank interrupts */
698 u32 last; /* protected by dev->vbl_lock, used */
699 /* for wraparound handling */
700 int enabled; /* so we don't call enable more than */
701 /* once per disable */
702 int inmodeset; /* Display driver is setting mode */
703 };
704
705 /* location of GART table */
706 #define DRM_ATI_GART_MAIN 1
707 #define DRM_ATI_GART_FB 2
708
709 #define DRM_ATI_GART_PCI 1
710 #define DRM_ATI_GART_PCIE 2
711 #define DRM_ATI_GART_IGP 3
712
713 struct drm_ati_pcigart_info {
714 int gart_table_location;
715 int gart_reg_if;
716 void *addr;
717 dma_addr_t bus_addr;
718 dma_addr_t table_mask;
719 dma_addr_t member_mask;
720 struct drm_dma_handle *table_handle;
721 drm_local_map_t mapping;
722 int table_size;
723 };
724
725 #ifndef DMA_BIT_MASK
726 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
727 #endif
728
729 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
730
731 struct drm_driver_info {
732 int (*load)(struct drm_device *, unsigned long flags);
733 int (*firstopen)(struct drm_device *);
734 int (*open)(struct drm_device *, struct drm_file *);
735 void (*preclose)(struct drm_device *, struct drm_file *file_priv);
736 void (*postclose)(struct drm_device *, struct drm_file *);
737 void (*lastclose)(struct drm_device *);
738 int (*unload)(struct drm_device *);
739 void (*reclaim_buffers_locked)(struct drm_device *,
740 struct drm_file *file_priv);
741 int (*dma_ioctl)(struct drm_device *dev, void *data,
742 struct drm_file *file_priv);
743 void (*dma_ready)(struct drm_device *);
744 int (*dma_quiescent)(struct drm_device *);
745 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
746 enum drm_lock_flags flags);
747 int (*dma_flush_unblock)(struct drm_device *, int context,
748 enum drm_lock_flags flags);
749 int (*context_ctor)(struct drm_device *dev, int context);
750 int (*context_dtor)(struct drm_device *dev, int context);
751 int (*kernel_context_switch)(struct drm_device *dev, int old,
752 int new);
753 int (*kernel_context_switch_unlock)(struct drm_device *dev);
754 void (*irq_preinstall)(struct drm_device *dev);
755 int (*irq_postinstall)(struct drm_device *dev);
756 void (*irq_uninstall)(struct drm_device *dev);
757 irqreturn_t (*irq_handler)(DRM_IRQ_ARGS);
758 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc);
759 int (*enable_vblank)(struct drm_device *dev, int crtc);
760 void (*disable_vblank)(struct drm_device *dev, int crtc);
761
762 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
763
764 /**
765 * Called by \c drm_device_is_agp. Typically used to determine if a
766 * card is really attached to AGP or not.
767 *
768 * \param dev DRM device handle
769 *
770 * \returns
771 * One of three values is returned depending on whether or not the
772 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
773 * (return of 1), or may or may not be AGP (return of 2).
774 */
775 int (*device_is_agp) (struct drm_device * dev);
776
777 drm_ioctl_desc_t *ioctls;
778 int max_ioctl;
779
780 int buf_priv_size;
781
782 int major;
783 int minor;
784 int patchlevel;
785 const char *name; /* Simple driver name */
786 const char *desc; /* Longer driver name */
787 const char *date; /* Date of last major changes. */
788
789 u32 driver_features;
790 };
791
792 /* Length for the array of resource pointers for drm_get_resource_*. */
793 #define DRM_MAX_PCI_RESOURCE 6
794
795 #if defined(__NetBSD__)
796 typedef struct {
797 int mapped;
798 int maptype;
799 bus_addr_t base;
800 bus_size_t size;
801 bus_space_handle_t bsh;
802 int flags;
803 void * vaddr;
804 } pci_map_data_t;
805 #endif
806
807 /**
808 * DRM device functions structure
809 */
810 struct drm_device {
811 struct drm_driver_info *driver;
812 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
813
814 u_int16_t pci_device; /* PCI device id */
815 u_int16_t pci_vendor; /* PCI vendor id */
816
817 char *unique; /* Unique identifier: e.g., busid */
818 int unique_len; /* Length of unique field */
819 device_t device; /* Device instance from newbus */
820 #if defined(__FreeBSD__)
821 struct cdev *devnode; /* Device number for mknod */
822 #endif
823 int if_version; /* Highest interface version set */
824
825 int flags; /* Flags to open(2) */
826
827 /* Locks */
828 DRM_SPINTYPE vbl_lock; /* protects vblank operations */
829 DRM_SPINTYPE dma_lock; /* protects dev->dma */
830 DRM_SPINTYPE irq_lock; /* protects irq condition checks */
831 DRM_SPINTYPE dev_lock; /* protects everything else */
832 DRM_SPINTYPE drw_lock;
833
834 /* Usage Counters */
835 int open_count; /* Outstanding files open */
836 int buf_use; /* Buffers in use -- cannot alloc */
837
838 /* Performance counters */
839 unsigned long counters;
840 enum drm_stat_type types[15];
841 atomic_t counts[15];
842
843 /* Authentication */
844 drm_file_list_t files;
845 drm_magic_head_t magiclist[DRM_HASH_SIZE];
846
847 /* Linked list of mappable regions. Protected by dev_lock */
848 drm_map_list_t maplist;
849
850 drm_local_map_t **context_sareas;
851 int max_context;
852
853 drm_lock_data_t lock; /* Information on hardware lock */
854
855 /* DMA queues (contexts) */
856 drm_device_dma_t *dma; /* Optional pointer for DMA support */
857
858 /* Context support */
859 int irq; /* Interrupt used by board */
860 int irq_enabled; /* True if the irq handler is enabled */
861 int msi_enabled; /* MSI enabled */
862 #if defined(__FreeBSD__)
863 int irqrid; /* Interrupt used by board */
864 struct resource *irqr; /* Resource for interrupt used by board */
865
866 /* Storage of resource pointers for drm_get_resource_* */
867 struct resource *pcir[DRM_MAX_PCI_RESOURCE];
868 int pcirid[DRM_MAX_PCI_RESOURCE];
869 #elif defined(__NetBSD__)
870 struct pci_attach_args pa;
871 pci_map_data_t pci_map_data[DRM_MAX_PCI_RESOURCE];
872 pci_map_data_t agp_map_data[DRM_MAX_PCI_RESOURCE];
873 dev_t kdev;
874 #endif
875 void *irqh; /* Handle from bus_setup_intr */
876
877 int pci_domain;
878 int pci_bus;
879 int pci_slot;
880 int pci_func;
881
882 atomic_t context_flag; /* Context swapping flag */
883 int last_context; /* Last current context */
884
885 int vblank_disable_allowed;
886 atomic_t vbl_signal_pending; /* number of signals pending on all crtcs */
887 struct callout vblank_disable_timer;
888 u32 max_vblank_count; /* size of vblank counter register */
889 struct drm_vblank_info *vblank; /* per crtc vblank info */
890 int num_crtcs;
891
892 #if defined(__FreeBSD__)
893 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
894 #elif defined(__NetBSD__)
895 pid_t buf_pgid;
896 #endif
897
898 /* Sysctl support */
899 struct drm_sysctl_info *sysctl;
900
901 drm_agp_head_t *agp;
902 drm_sg_mem_t *sg; /* Scatter gather memory */
903 atomic_t *ctx_bitmap;
904 void *dev_private;
905 unsigned int agp_buffer_token;
906 drm_local_map_t *agp_buffer_map;
907
908 #if defined(__FreeBSD__)
909 struct unrhdr *drw_unrhdr;
910 #elif defined(__NetBSD__)
911 int drw_no;
912 #endif
913 /* RB tree of drawable infos */
914 RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head;
915 };
916
917 static __inline__ int drm_core_check_feature(struct drm_device *dev,
918 int feature)
919 {
920 return ((dev->driver->driver_features & feature) ? 1 : 0);
921 }
922
923 #if __OS_HAS_AGP
924 static inline int drm_core_has_AGP(struct drm_device *dev)
925 {
926 return drm_core_check_feature(dev, DRIVER_USE_AGP);
927 }
928 #else
929 #define drm_core_has_AGP(dev) (0)
930 #endif
931
932 extern int drm_debug_flag;
933
934 /* Device setup support (drm_drv.c) */
935 #if defined(__FreeBSD__)
936 int drm_probe(device_t kdev, drm_pci_id_list_t *idlist);
937 int drm_attach(device_t kdev, drm_pci_id_list_t *idlist);
938 void drm_close(void *data);
939 int drm_detach(device_t kdev);
940 d_ioctl_t drm_ioctl;
941 d_open_t drm_open;
942 d_read_t drm_read;
943 d_poll_t drm_poll;
944 d_mmap_t drm_mmap;
945 #elif defined(__NetBSD__)
946 int drm_probe(struct pci_attach_args *pa, drm_pci_id_list_t *idlist);
947 void drm_attach(device_t kdev, struct pci_attach_args *pa, drm_pci_id_list_t *idlist);
948 int drm_detach(device_t self, int flags);
949 int drm_activate(device_t self, devact_t act);
950 dev_type_ioctl(drm_ioctl);
951 dev_type_open(drm_open);
952 dev_type_close(drm_close);
953 dev_type_read(drm_read);
954 dev_type_poll(drm_poll);
955 dev_type_mmap(drm_mmap);
956 #endif
957 extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
958
959 int drm_close_pid(struct drm_device *dev, struct drm_file *priv, pid_t pid);
960
961 /* File operations helpers (drm_fops.c) */
962 #if defined(__FreeBSD__)
963 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
964 DRM_STRUCTPROC *p,
965 struct drm_device *dev);
966 #elif defined(__NetBSD__)
967 extern struct drm_file *drm_find_file_by_proc(struct drm_device *dev,
968 struct proc *p);
969 extern int drm_open_helper(dev_t kdev, int flags, int fmt,
970 struct proc *p, struct drm_device *dev);
971 #endif
972
973 /* Memory management support (drm_memory.c) */
974 void drm_mem_init(void);
975 void drm_mem_uninit(void);
976 void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map);
977 void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map);
978 void drm_ioremapfree(drm_local_map_t *map);
979 int drm_mtrr_add(unsigned long offset, size_t size, int flags);
980 int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
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