1 /* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*-
2 * Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com
5 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
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:
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
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.
29 * Rickard E. (Rik) Faith <faith@valinux.com>
30 * Gareth Hughes <gareth@valinux.com>
32 * $DragonFly: src/sys/dev/drm/drmP.h,v 1.5 2008/04/05 18:12:29 hasso Exp $
38 #if defined(_KERNEL) || defined(__KERNEL__)
40 typedef struct drm_device drm_device_t;
41 typedef struct drm_file drm_file_t;
43 #include <sys/param.h>
44 #include <sys/queue.h>
45 #include <sys/malloc.h>
46 #include <sys/kernel.h>
47 #include <sys/module.h>
48 #include <sys/systm.h>
51 #if __FreeBSD_version >= 700000
56 #include <sys/fcntl.h>
58 #include <sys/filio.h>
59 #include <sys/sysctl.h>
61 #include <sys/signalvar.h>
64 #include <sys/taskqueue.h>
67 #include <vm/vm_extern.h>
68 #include <vm/vm_map.h>
69 #include <vm/vm_param.h>
70 #include <machine/param.h>
71 #include <machine/pmap.h>
74 #include <sys/resource.h>
76 #include <machine/bus.h>
77 #include <machine/resource.h>
79 #include <machine/sysarch.h>
80 #include <sys/endian.h>
82 #if defined(__FreeBSD__) || defined(__DragonFly__)
84 #include <sys/memrange.h>
85 #if __FreeBSD_version >= 800004 || defined(__DragonFly__)
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 #if defined(__DragonFly__)
92 #include <sys/thread2.h>
93 #include <sys/device.h>
95 #include <bus/pci/pcivar.h>
96 #include <sys/selinfo.h>
97 #elif __FreeBSD_version >= 500000
98 #include <sys/mutex.h>
99 #include <dev/pci/pcivar.h>
100 #include <sys/selinfo.h>
101 #else /* __FreeBSD_version >= 500000 */
102 #include <pci/pcivar.h>
103 #include <sys/select.h>
104 #endif /* __FreeBSD_version < 500000 */
105 #elif defined(__NetBSD__)
106 #include <machine/mtrr.h>
107 #include <sys/vnode.h>
108 #include <sys/select.h>
109 #include <sys/device.h>
110 #include <sys/resourcevar.h>
112 #include <sys/agpio.h>
113 #include <sys/ttycom.h>
115 #include <dev/pci/pcireg.h>
116 #include <dev/pci/pcivar.h>
117 #include <dev/pci/agpvar.h>
118 #elif defined(__OpenBSD__)
125 #include "drm_linux_list.h"
126 #include "drm_atomic.h"
127 #include "drm_internal.h"
133 #define DRM_DEBUG_DEFAULT_ON 1
134 #endif /* DRM_DEBUG */
137 #if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__)
138 #include <sys/file.h>
139 #include <sys/proc.h>
140 #include <machine/../linux/linux.h>
141 #include <machine/../linux/linux_proto.h>
143 /* Either it was defined when it shouldn't be (FreeBSD amd64) or it isn't
144 * supported on this OS yet.
150 #define DRM_HASH_SIZE 16 /* Size of key hash table */
151 #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
152 #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
154 #define DRM_MEM_DMA 0
155 #define DRM_MEM_SAREA 1
156 #define DRM_MEM_DRIVER 2
157 #define DRM_MEM_MAGIC 3
158 #define DRM_MEM_IOCTLS 4
159 #define DRM_MEM_MAPS 5
160 #define DRM_MEM_BUFS 6
161 #define DRM_MEM_SEGS 7
162 #define DRM_MEM_PAGES 8
163 #define DRM_MEM_FILES 9
164 #define DRM_MEM_QUEUES 10
165 #define DRM_MEM_CMDS 11
166 #define DRM_MEM_MAPPINGS 12
167 #define DRM_MEM_BUFLISTS 13
168 #define DRM_MEM_AGPLISTS 14
169 #define DRM_MEM_TOTALAGP 15
170 #define DRM_MEM_BOUNDAGP 16
171 #define DRM_MEM_CTXBITMAP 17
172 #define DRM_MEM_STUB 18
173 #define DRM_MEM_SGLISTS 19
174 #define DRM_MEM_DRAWABLE 20
176 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
178 /* Internal types and structures */
179 #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
180 #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
181 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
183 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
185 MALLOC_DECLARE(M_DRM);
187 #define __OS_HAS_AGP 1
189 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
190 #define DRM_DEV_UID 0
191 #define DRM_DEV_GID 0
193 #define wait_queue_head_t atomic_t
194 #define DRM_WAKEUP(w) wakeup((void *)w)
195 #define DRM_WAKEUP_INT(w) wakeup(w)
196 #define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0)
198 #if defined(__FreeBSD__) && __FreeBSD_version < 502109
199 #define bus_alloc_resource_any(dev, type, rid, flags) \
200 bus_alloc_resource(dev, type, rid, 0ul, ~0ul, 1, flags)
203 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
204 #define DRM_CURPROC curthread
205 #define DRM_STRUCTPROC struct thread
206 #define DRM_SPINTYPE struct mtx
207 #define DRM_SPININIT(l,name) mtx_init(l, name, NULL, MTX_DEF)
208 #define DRM_SPINUNINIT(l) mtx_destroy(l)
209 #define DRM_SPINLOCK(l) mtx_lock(l)
210 #define DRM_SPINUNLOCK(u) mtx_unlock(u)
211 #define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \
215 #define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mtx_unlock(u)
216 #define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED)
217 #define DRM_CURRENTPID curthread->td_proc->p_pid
218 #define DRM_LOCK() mtx_lock(&dev->dev_lock)
219 #define DRM_UNLOCK() mtx_unlock(&dev->dev_lock)
220 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
221 #elif defined(__DragonFly__)
222 #define DRM_CURPROC curthread
223 #define DRM_STRUCTPROC struct thread
224 #define DRM_SPINTYPE struct lock
225 #define DRM_SPININIT(l,name) lockinit(l, name, 0, LK_CANRECURSE)
226 #define DRM_SPINUNINIT(l)
227 #define DRM_SPINLOCK(l) lockmgr(l, LK_EXCLUSIVE|LK_RETRY)
228 #define DRM_SPINUNLOCK(u) lockmgr(u, LK_RELEASE);
229 #define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \
233 #define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) DRM_SPINUNLOCK(u)
234 #define DRM_SPINLOCK_ASSERT(l)
235 #define DRM_CURRENTPID curthread->td_proc->p_pid
236 #define DRM_LOCK() DRM_SPINLOCK(&dev->dev_lock)
237 #define DRM_UNLOCK() DRM_SPINUNLOCK(&dev->dev_lock)
238 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
239 #else /* __FreeBSD__ && __FreeBSD_version >= 500000 || __DragonFly__ */
240 #define DRM_CURPROC curproc
241 #define DRM_STRUCTPROC struct proc
242 #define DRM_SPINTYPE struct simplelock
243 #define DRM_SPININIT(l,name)
244 #define DRM_SPINUNINIT(l)
245 #define DRM_SPINLOCK(l)
246 #define DRM_SPINUNLOCK(u)
247 #define DRM_SPINLOCK_ASSERT(l)
248 #define DRM_CURRENTPID curproc->p_pid
251 #define DRM_SYSCTL_HANDLER_ARGS SYSCTL_HANDLER_ARGS
252 #define spldrm() spltty()
253 #endif /* __NetBSD__ || __OpenBSD__ */
255 #define DRM_IRQ_ARGS void *arg
256 typedef void irqreturn_t;
257 #define IRQ_HANDLED /* nothing */
258 #define IRQ_NONE /* nothing */
265 #define DRM_AGP_MEM struct agp_memory_info
267 #if defined(__FreeBSD__) || defined(__DragonFly__)
268 #define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1)
269 #elif defined(__NetBSD__)
270 #define drm_get_device_from_kdev(_kdev) device_lookup(&drm_cd, minor(_kdev))
271 #elif defined(__OpenBSD__)
272 #define drm_get_device_from_kdev(_kdev) device_lookup(&drm_cd, \
273 minor(_kdev)))->dv_cfdata->cf_driver->cd_devs[minor(_kdev)]
276 #if defined(__FreeBSD__) || defined(__DragonFly__)
277 #define PAGE_ALIGN(addr) round_page(addr)
278 /* DRM_SUSER returns true if the user is superuser */
279 #if __FreeBSD_version >= 700000
280 #define DRM_SUSER(p) (priv_check(p, PRIV_DRIVER) == 0)
282 #define DRM_SUSER(p) (suser(p) == 0)
284 #define DRM_AGP_FIND_DEVICE() agp_find_device()
285 #define DRM_MTRR_WC MDF_WRITECOMBINE
286 #define jiffies ticks
288 #else /* __FreeBSD__ || __DragonFly__ */
290 #define CDEV_MAJOR 34
291 #define PAGE_ALIGN(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK)
292 /* DRM_SUSER returns true if the user is superuser */
293 #define DRM_SUSER(p) (suser(p->p_ucred, &p->p_acflag) == 0)
294 #define DRM_AGP_FIND_DEVICE() agp_find_device(0)
295 #define DRM_MTRR_WC MTRR_TYPE_WC
296 #define jiffies hardclock_ticks
298 typedef drm_device_t *device_t;
299 extern struct cfdriver drm_cd;
300 #endif /* !__FreeBSD__ && !__DragonFly__ */
302 /* Capabilities taken from src/sys/dev/pci/pcireg.h. */
304 #define PCIY_AGP 0x02
308 #define PCIY_EXPRESS 0x10
311 typedef unsigned long dma_addr_t;
312 typedef u_int64_t u64;
313 typedef u_int32_t u32;
314 typedef u_int16_t u16;
317 /* DRM_READMEMORYBARRIER() prevents reordering of reads.
318 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
319 * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
321 #if defined(__i386__)
322 #define DRM_READMEMORYBARRIER() __asm __volatile( \
323 "lock; addl $0,0(%%esp)" : : : "memory");
324 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
325 #define DRM_MEMORYBARRIER() __asm __volatile( \
326 "lock; addl $0,0(%%esp)" : : : "memory");
327 #elif defined(__alpha__)
328 #define DRM_READMEMORYBARRIER() alpha_mb();
329 #define DRM_WRITEMEMORYBARRIER() alpha_wmb();
330 #define DRM_MEMORYBARRIER() alpha_mb();
331 #elif defined(__amd64__)
332 #define DRM_READMEMORYBARRIER() __asm __volatile( \
333 "lock; addl $0,0(%%rsp)" : : : "memory");
334 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
335 #define DRM_MEMORYBARRIER() __asm __volatile( \
336 "lock; addl $0,0(%%rsp)" : : : "memory");
339 #if defined(__FreeBSD__) || defined(__DragonFly__)
340 #define DRM_READ8(map, offset) \
341 *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset))
342 #define DRM_READ16(map, offset) \
343 *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset))
344 #define DRM_READ32(map, offset) \
345 *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset))
346 #define DRM_WRITE8(map, offset, val) \
347 *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset)) = val
348 #define DRM_WRITE16(map, offset, val) \
349 *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset)) = val
350 #define DRM_WRITE32(map, offset, val) \
351 *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset)) = val
353 #define DRM_VERIFYAREA_READ( uaddr, size ) \
354 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
356 #else /* __FreeBSD__ || __DragonFly__ */
358 typedef vaddr_t vm_offset_t;
360 #define DRM_READ8(map, offset) \
361 bus_space_read_1( (map)->bst, (map)->bsh, (offset))
362 #define DRM_READ16(map, offset) \
363 bus_space_read_2( (map)->bst, (map)->bsh, (offset))
364 #define DRM_READ32(map, offset) \
365 bus_space_read_4( (map)->bst, (map)->bsh, (offset))
366 #define DRM_WRITE8(map, offset, val) \
367 bus_space_write_1((map)->bst, (map)->bsh, (offset), (val))
368 #define DRM_WRITE16(map, offset, val) \
369 bus_space_write_2((map)->bst, (map)->bsh, (offset), (val))
370 #define DRM_WRITE32(map, offset, val) \
371 bus_space_write_4((map)->bst, (map)->bsh, (offset), (val))
373 #define DRM_VERIFYAREA_READ( uaddr, size ) \
374 (!uvm_useracc((caddr_t)uaddr, size, VM_PROT_READ))
375 #endif /* !__FreeBSD__ && !__DragonFly__ */
377 #define DRM_COPY_TO_USER(user, kern, size) \
378 copyout(kern, user, size)
379 #define DRM_COPY_FROM_USER(kern, user, size) \
380 copyin(user, kern, size)
381 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
382 copyin(arg2, arg1, arg3)
383 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
384 copyout(arg2, arg1, arg3)
385 #if __FreeBSD_version > 500000
386 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
387 ((val) = fuword32(uaddr), 0)
389 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
390 ((val) = fuword(uaddr), 0)
393 #define cpu_to_le32(x) htole32(x)
394 #define le32_to_cpu(x) le32toh(x)
397 #define DRM_UDELAY(udelay) DELAY(udelay)
398 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
400 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
401 (_map) = (_dev)->context_sareas[_ctx]; \
404 #define LOCK_TEST_WITH_RETURN(dev, file_priv) \
406 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
407 dev->lock.file_priv != file_priv) { \
408 DRM_ERROR("%s called without lock held\n", \
414 #if defined(__FreeBSD__) && __FreeBSD_version > 500000
415 /* Returns -errno to shared code */
416 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
417 for ( ret = 0 ; !ret && !(condition) ; ) { \
419 mtx_lock(&dev->irq_lock); \
421 ret = -mtx_sleep(&(queue), &dev->irq_lock, \
422 PZERO | PCATCH, "drmwtq", (timeout)); \
423 mtx_unlock(&dev->irq_lock); \
426 #elif defined(__DragonFly__)
427 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
428 for ( ret = 0 ; !ret && !(condition) ; ) { \
430 lwkt_serialize_enter(&dev->irq_lock); \
431 if (!(condition)) { \
433 tsleep_interlock(&(queue)); \
434 lwkt_serialize_exit(&dev->irq_lock); \
435 ret = -tsleep(&(queue), PCATCH, \
436 "drmwtq", (timeout)); \
439 lwkt_serialize_exit(&dev->irq_lock); \
444 /* Returns -errno to shared code */
445 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
446 for ( ret = 0 ; !ret && !(condition) ; ) { \
449 ret = -tsleep( &(queue), PZERO | PCATCH, \
450 "drmwtq", (timeout) ); \
456 #define TAILQ_FOREACH_SAFE TAILQ_FOREACH_MUTABLE
457 #define printf kprintf
458 #define snprintf ksnprintf
459 #define sscanf ksscanf
460 #define malloc kmalloc
461 #define realloc krealloc
464 free(void *addr, struct malloc_type *type)
471 #define DRM_ERROR(fmt, arg...) \
472 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
473 DRM_CURRENTPID, __func__ , ## arg)
475 #define DRM_INFO(fmt, arg...) printf("info: [" DRM_NAME "] " fmt , ## arg)
477 #define DRM_DEBUG(fmt, arg...) do { \
478 if (drm_debug_flag) \
479 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
480 __func__ , ## arg); \
483 typedef struct drm_pci_id_list
492 #define DRM_MASTER 0x2
493 #define DRM_ROOT_ONLY 0x4
494 typedef struct drm_ioctl_desc {
496 int (*func)(drm_device_t *dev, void *data, struct drm_file *file_priv);
500 * Creates a driver or general drm_ioctl_desc array entry for the given
501 * ioctl, for use by drm_ioctl().
503 #define DRM_IOCTL_DEF(ioctl, func, flags) \
504 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
506 typedef struct drm_magic_entry {
508 struct drm_file *priv;
509 struct drm_magic_entry *next;
512 typedef struct drm_magic_head {
513 struct drm_magic_entry *head;
514 struct drm_magic_entry *tail;
517 typedef struct drm_buf {
518 int idx; /* Index into master buflist */
519 int total; /* Buffer size */
520 int order; /* log-base-2(total) */
521 int used; /* Amount of buffer in use (for DMA) */
522 unsigned long offset; /* Byte offset (used internally) */
523 void *address; /* Address of buffer */
524 unsigned long bus_address; /* Bus address of buffer */
525 struct drm_buf *next; /* Kernel-only: used for free list */
526 __volatile__ int pending; /* On hardware DMA queue */
527 struct drm_file *file_priv; /* Unique identifier of holding process */
528 int context; /* Kernel queue for this buffer */
536 } list; /* Which list we're on */
538 int dev_priv_size; /* Size of buffer private stoarge */
539 void *dev_private; /* Per-buffer private storage */
542 typedef struct drm_freelist {
543 int initialized; /* Freelist in use */
544 atomic_t count; /* Number of free buffers */
545 drm_buf_t *next; /* End pointer */
547 int low_mark; /* Low water mark */
548 int high_mark; /* High water mark */
551 typedef struct drm_dma_handle {
554 #if defined(__FreeBSD__) || defined(__DragonFly__)
557 #elif defined(__NetBSD__)
558 bus_dma_segment_t seg;
562 typedef struct drm_buf_entry {
567 drm_dma_handle_t **seglist;
570 drm_freelist_t freelist;
573 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
575 TAILQ_ENTRY(drm_file) link;
583 unsigned long ioctl_count;
587 typedef struct drm_lock_data {
588 drm_hw_lock_t *hw_lock; /* Hardware lock */
589 struct drm_file *file_priv; /* Unique identifier of holding process (NULL is kernel)*/
590 int lock_queue; /* Queue of blocked processes */
591 unsigned long lock_time; /* Time of last lock in jiffies */
594 /* This structure, in the drm_device_t, is always initialized while the device
595 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
596 * when set marks that no further bufs may be allocated until device teardown
597 * occurs (when the last open of the device has closed). The high/low
598 * watermarks of bufs are only touched by the X Server, and thus not
599 * concurrently accessed, so no locking is needed.
601 typedef struct drm_device_dma {
602 drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
604 drm_buf_t **buflist; /* Vector of pointers info bufs */
607 unsigned long *pagelist;
608 unsigned long byte_count;
610 _DRM_DMA_USE_AGP = 0x01,
611 _DRM_DMA_USE_SG = 0x02
615 typedef struct drm_agp_mem {
617 unsigned long bound; /* address */
619 struct drm_agp_mem *prev;
620 struct drm_agp_mem *next;
623 typedef struct drm_agp_head {
625 struct agp_info info;
627 drm_agp_mem_t *memory;
633 int cant_use_aperture;
634 unsigned long page_mask;
637 typedef struct drm_sg_mem {
638 unsigned long handle;
642 drm_dma_handle_t *dmah; /* Handle to PCI memory for ATI PCIGART table */
645 typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
647 typedef struct drm_local_map {
648 unsigned long offset; /* Physical address (0 for SAREA)*/
649 unsigned long size; /* Physical size (bytes) */
650 drm_map_type_t type; /* Type of memory mapped */
651 drm_map_flags_t flags; /* Flags */
652 void *handle; /* User-space: "Handle" to pass to mmap */
653 /* Kernel-space: kernel-virtual address */
654 int mtrr; /* Boolean: MTRR used */
656 int rid; /* PCI resource ID for bus_space */
657 struct resource *bsr;
659 bus_space_handle_t bsh;
660 drm_dma_handle_t *dmah;
661 TAILQ_ENTRY(drm_local_map) link;
664 TAILQ_HEAD(drm_vbl_sig_list, drm_vbl_sig);
665 typedef struct drm_vbl_sig {
666 TAILQ_ENTRY(drm_vbl_sig) link;
667 unsigned int sequence;
672 /* location of GART table */
673 #define DRM_ATI_GART_MAIN 1
674 #define DRM_ATI_GART_FB 2
676 #define DRM_ATI_GART_PCI 1
677 #define DRM_ATI_GART_PCIE 2
678 #define DRM_ATI_GART_IGP 3
680 struct drm_ati_pcigart_info {
681 int gart_table_location;
685 drm_local_map_t mapping;
689 struct drm_driver_info {
690 int (*load)(struct drm_device *, unsigned long flags);
691 int (*firstopen)(struct drm_device *);
692 int (*open)(struct drm_device *, drm_file_t *);
693 void (*preclose)(struct drm_device *, struct drm_file *file_priv);
694 void (*postclose)(struct drm_device *, drm_file_t *);
695 void (*lastclose)(struct drm_device *);
696 int (*unload)(struct drm_device *);
697 void (*reclaim_buffers_locked)(struct drm_device *,
698 struct drm_file *file_priv);
699 int (*dma_ioctl)(drm_device_t *dev, void *data, struct drm_file *file_priv);
700 void (*dma_ready)(struct drm_device *);
701 int (*dma_quiescent)(struct drm_device *);
702 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
703 drm_lock_flags_t flags);
704 int (*dma_flush_unblock)(struct drm_device *, int context,
705 drm_lock_flags_t flags);
706 int (*context_ctor)(struct drm_device *dev, int context);
707 int (*context_dtor)(struct drm_device *dev, int context);
708 int (*kernel_context_switch)(struct drm_device *dev, int old,
710 int (*kernel_context_switch_unlock)(struct drm_device *dev);
711 void (*irq_preinstall)(drm_device_t *dev);
712 void (*irq_postinstall)(drm_device_t *dev);
713 void (*irq_uninstall)(drm_device_t *dev);
714 void (*irq_handler)(DRM_IRQ_ARGS);
715 int (*vblank_wait)(drm_device_t *dev, unsigned int *sequence);
716 int (*vblank_wait2)(drm_device_t *dev, unsigned int *sequence);
718 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
721 * Called by \c drm_device_is_agp. Typically used to determine if a
722 * card is really attached to AGP or not.
724 * \param dev DRM device handle
727 * One of three values is returned depending on whether or not the
728 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
729 * (return of 1), or may or may not be AGP (return of 2).
731 int (*device_is_agp) (struct drm_device * dev);
733 drm_ioctl_desc_t *ioctls;
741 const char *name; /* Simple driver name */
742 const char *desc; /* Longer driver name */
743 const char *date; /* Date of last major changes. */
746 unsigned require_agp :1;
749 unsigned use_pci_dma :1;
750 unsigned use_dma_queue :1;
752 unsigned use_vbl_irq :1;
753 unsigned use_vbl_irq2 :1;
754 unsigned use_mtrr :1;
757 /* Length for the array of resource pointers for drm_get_resource_*. */
758 #define DRM_MAX_PCI_RESOURCE 3
761 * DRM device functions structure
764 #if defined(__NetBSD__) || defined(__OpenBSD__)
765 struct device device; /* softc is an extension of struct device */
768 struct drm_driver_info driver;
769 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
771 u_int16_t pci_device; /* PCI device id */
772 u_int16_t pci_vendor; /* PCI vendor id */
774 char *unique; /* Unique identifier: e.g., busid */
775 int unique_len; /* Length of unique field */
776 #if defined(__FreeBSD__) || defined(__DragonFly__)
777 device_t device; /* Device instance from newbus */
779 struct cdev *devnode; /* Device number for mknod */
780 int if_version; /* Highest interface version set */
782 int flags; /* Flags to open(2) */
785 #if defined(__FreeBSD__) && __FreeBSD_version > 500000
786 struct mtx dma_lock; /* protects dev->dma */
787 struct mtx irq_lock; /* protects irq condition checks */
788 struct mtx dev_lock; /* protects everything else */
789 #elif defined(__DragonFly__)
790 struct lock dma_lock; /* protects dev->dma */
791 struct lwkt_serialize irq_lock; /* protects irq condition checks */
792 struct lock dev_lock; /* protects everything else */
794 DRM_SPINTYPE drw_lock;
797 int open_count; /* Outstanding files open */
798 int buf_use; /* Buffers in use -- cannot alloc */
800 /* Performance counters */
801 unsigned long counters;
802 drm_stat_type_t types[15];
806 drm_file_list_t files;
807 drm_magic_head_t magiclist[DRM_HASH_SIZE];
809 /* Linked list of mappable regions. Protected by dev_lock */
810 drm_map_list_t maplist;
812 drm_local_map_t **context_sareas;
815 drm_lock_data_t lock; /* Information on hardware lock */
817 /* DMA queues (contexts) */
818 drm_device_dma_t *dma; /* Optional pointer for DMA support */
820 /* Context support */
821 int irq; /* Interrupt used by board */
822 int irq_enabled; /* True if the irq handler is enabled */
823 #if defined(__FreeBSD__) || defined(__DragonFly__)
824 int irqrid; /* Interrupt used by board */
825 struct resource *irqr; /* Resource for interrupt used by board */
826 #elif defined(__NetBSD__) || defined(__OpenBSD__)
827 struct pci_attach_args pa;
829 void *irqh; /* Handle from bus_setup_intr */
831 /* Storage of resource pointers for drm_get_resource_* */
832 struct resource *pcir[DRM_MAX_PCI_RESOURCE];
833 int pcirid[DRM_MAX_PCI_RESOURCE];
840 atomic_t context_flag; /* Context swapping flag */
841 int last_context; /* Last current context */
842 int vbl_queue; /* vbl wait channel */
843 atomic_t vbl_received;
844 atomic_t vbl_received2;
846 #if defined(__FreeBSD__) || defined(__DragonFly__)
847 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
848 #elif defined(__NetBSD__)
853 struct drm_sysctl_info *sysctl;
856 drm_sg_mem_t *sg; /* Scatter gather memory */
857 atomic_t *ctx_bitmap;
859 unsigned int agp_buffer_token;
860 drm_local_map_t *agp_buffer_map;
863 struct unrhdr *drw_unrhdr;
865 /* RB tree of drawable infos */
866 RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head;
868 struct task locked_task;
869 void (*locked_task_call)(drm_device_t *dev);
872 extern int drm_debug_flag;
874 /* Device setup support (drm_drv.c) */
875 #if defined(__FreeBSD__) || defined(__DragonFly__)
876 int drm_probe(device_t nbdev, drm_pci_id_list_t *idlist);
877 int drm_attach(device_t nbdev, drm_pci_id_list_t *idlist);
878 int drm_detach(device_t nbdev);
885 #elif defined(__NetBSD__) || defined(__OpenBSD__)
886 int drm_probe(struct pci_attach_args *pa, drm_pci_id_list_t *idlist);
887 int drm_attach(struct pci_attach_args *pa, dev_t kdev, drm_pci_id_list_t *idlist);
888 dev_type_ioctl(drm_ioctl);
889 dev_type_open(drm_open);
890 dev_type_close(drm_close);
891 dev_type_read(drm_read);
892 dev_type_poll(drm_poll);
893 dev_type_mmap(drm_mmap);
895 extern drm_local_map_t *drm_getsarea(drm_device_t *dev);
897 /* File operations helpers (drm_fops.c) */
898 #if defined(__FreeBSD__) || defined(__DragonFly__)
899 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
900 DRM_STRUCTPROC *p, drm_device_t *dev);
901 extern drm_file_t *drm_find_file_by_proc(drm_device_t *dev,
903 #elif defined(__NetBSD__) || defined(__OpenBSD__)
904 extern int drm_open_helper(dev_t kdev, int flags, int fmt,
905 DRM_STRUCTPROC *p, drm_device_t *dev);
906 extern drm_file_t *drm_find_file_by_proc(drm_device_t *dev,
908 #endif /* __NetBSD__ || __OpenBSD__ */
910 /* Memory management support (drm_memory.c) */
911 void drm_mem_init(void);
912 void drm_mem_uninit(void);
913 void *drm_alloc(size_t size, int area);
914 void *drm_calloc(size_t nmemb, size_t size, int area);
915 void *drm_realloc(void *oldpt, size_t oldsize, size_t size,
917 void drm_free(void *pt, size_t size, int area);
918 void *drm_ioremap(drm_device_t *dev, drm_local_map_t *map);
919 void drm_ioremapfree(drm_local_map_t *map);
920 int drm_mtrr_add(unsigned long offset, size_t size, int flags);
921 int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
923 int drm_context_switch(drm_device_t *dev, int old, int new);
924 int drm_context_switch_complete(drm_device_t *dev, int new);
926 int drm_ctxbitmap_init(drm_device_t *dev);
927 void drm_ctxbitmap_cleanup(drm_device_t *dev);
928 void drm_ctxbitmap_free(drm_device_t *dev, int ctx_handle);
929 int drm_ctxbitmap_next(drm_device_t *dev);
931 /* Locking IOCTL support (drm_lock.c) */
932 int drm_lock_take(__volatile__ unsigned int *lock,
933 unsigned int context);
934 int drm_lock_transfer(drm_device_t *dev,
935 __volatile__ unsigned int *lock,
936 unsigned int context);
937 int drm_lock_free(drm_device_t *dev,
938 __volatile__ unsigned int *lock,
939 unsigned int context);
941 /* Buffer management support (drm_bufs.c) */
942 unsigned long drm_get_resource_start(drm_device_t *dev, unsigned int resource);
943 unsigned long drm_get_resource_len(drm_device_t *dev, unsigned int resource);
944 void drm_rmmap(drm_device_t *dev, drm_local_map_t *map);
945 int drm_order(unsigned long size);
946 int drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size,
947 drm_map_type_t type, drm_map_flags_t flags,
948 drm_local_map_t **map_ptr);
949 int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request);
950 int drm_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request);
951 int drm_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request);
953 /* DMA support (drm_dma.c) */
954 int drm_dma_setup(drm_device_t *dev);
955 void drm_dma_takedown(drm_device_t *dev);
956 void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf);
957 void drm_reclaim_buffers(drm_device_t *dev, struct drm_file *file_priv);
958 #define drm_core_reclaim_buffers drm_reclaim_buffers
960 /* IRQ support (drm_irq.c) */
961 int drm_irq_install(drm_device_t *dev);
962 int drm_irq_uninstall(drm_device_t *dev);
963 irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
964 void drm_driver_irq_preinstall(drm_device_t *dev);
965 void drm_driver_irq_postinstall(drm_device_t *dev);
966 void drm_driver_irq_uninstall(drm_device_t *dev);
967 int drm_vblank_wait(drm_device_t *dev, unsigned int *vbl_seq);
968 void drm_vbl_send_signals(drm_device_t *dev);
970 /* AGP/PCI Express/GART support (drm_agpsupport.c) */
971 int drm_device_is_agp(drm_device_t *dev);
972 int drm_device_is_pcie(drm_device_t *dev);
973 drm_agp_head_t *drm_agp_init(void);
974 int drm_agp_acquire(drm_device_t *dev);
975 int drm_agp_release(drm_device_t *dev);
976 int drm_agp_info(drm_device_t * dev, drm_agp_info_t *info);
977 int drm_agp_enable(drm_device_t *dev, drm_agp_mode_t mode);
978 void *drm_agp_allocate_memory(size_t pages, u32 type);
979 int drm_agp_free_memory(void *handle);
980 int drm_agp_bind_memory(void *handle, off_t start);
981 int drm_agp_unbind_memory(void *handle);
982 int drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request);
983 int drm_agp_free(drm_device_t *dev, drm_agp_buffer_t *request);
984 int drm_agp_bind(drm_device_t *dev, drm_agp_binding_t *request);
985 int drm_agp_unbind(drm_device_t *dev, drm_agp_binding_t *request);
987 /* Scatter Gather Support (drm_scatter.c) */
988 void drm_sg_cleanup(drm_sg_mem_t *entry);
989 int drm_sg_alloc(drm_device_t * dev, drm_scatter_gather_t * request);
991 #if defined(__FreeBSD__) || defined(__DragonFly__)
992 /* sysctl support (drm_sysctl.h) */
993 extern int drm_sysctl_init(drm_device_t *dev);
994 extern int drm_sysctl_cleanup(drm_device_t *dev);
995 #endif /* __FreeBSD__ || __DragonFly__ */
997 /* ATI PCIGART support (ati_pcigart.c) */
998 int drm_ati_pcigart_init(drm_device_t *dev,
999 struct drm_ati_pcigart_info *gart_info);
1000 int drm_ati_pcigart_cleanup(drm_device_t *dev,
1001 struct drm_ati_pcigart_info *gart_info);
1003 /* Locking IOCTL support (drm_drv.c) */
1004 int drm_lock(drm_device_t *dev, void *data, struct drm_file *file_priv);
1005 int drm_unlock(drm_device_t *dev, void *data, struct drm_file *file_priv);
1006 int drm_version(drm_device_t *dev, void *data, struct drm_file *file_priv);
1007 int drm_setversion(drm_device_t *dev, void *data, struct drm_file *file_priv);
1009 /* Misc. IOCTL support (drm_ioctl.c) */
1010 int drm_irq_by_busid(drm_device_t *dev, void *data, struct drm_file *file_priv);
1011 int drm_getunique(drm_device_t *dev, void *data, struct drm_file *file_priv);
1012 int drm_setunique(drm_device_t *dev, void *data, struct drm_file *file_priv);
1013 int drm_getmap(drm_device_t *dev, void *data, struct drm_file *file_priv);
1014 int drm_getclient(drm_device_t *dev, void *data, struct drm_file *file_priv);
1015 int drm_getstats(drm_device_t *dev, void *data, struct drm_file *file_priv);
1016 int drm_noop(drm_device_t *dev, void *data, struct drm_file *file_priv);
1018 /* Context IOCTL support (drm_context.c) */
1019 int drm_resctx(drm_device_t *dev, void *data, struct drm_file *file_priv);
1020 int drm_addctx(drm_device_t *dev, void *data, struct drm_file *file_priv);
1021 int drm_modctx(drm_device_t *dev, void *data, struct drm_file *file_priv);
1022 int drm_getctx(drm_device_t *dev, void *data, struct drm_file *file_priv);
1023 int drm_switchctx(drm_device_t *dev, void *data, struct drm_file *file_priv);
1024 int drm_newctx(drm_device_t *dev, void *data, struct drm_file *file_priv);
1025 int drm_rmctx(drm_device_t *dev, void *data, struct drm_file *file_priv);
1026 int drm_setsareactx(drm_device_t *dev, void *data, struct drm_file *file_priv);
1027 int drm_getsareactx(drm_device_t *dev, void *data, struct drm_file *file_priv);
1029 /* Drawable IOCTL support (drm_drawable.c) */
1030 int drm_adddraw(drm_device_t *dev, void *data, struct drm_file *file_priv);
1031 int drm_rmdraw(drm_device_t *dev, void *data, struct drm_file *file_priv);
1032 int drm_update_draw(drm_device_t *dev, void *data, struct drm_file *file_priv);
1033 struct drm_drawable_info *drm_get_drawable_info(drm_device_t *dev, int handle);
1035 /* Authentication IOCTL support (drm_auth.c) */
1036 int drm_getmagic(drm_device_t *dev, void *data, struct drm_file *file_priv);
1037 int drm_authmagic(drm_device_t *dev, void *data, struct drm_file *file_priv);
1039 /* Buffer management support (drm_bufs.c) */
1040 int drm_addmap_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
1041 int drm_rmmap_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
1042 int drm_addbufs_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
1043 int drm_infobufs(drm_device_t *dev, void *data, struct drm_file *file_priv);
1044 int drm_markbufs(drm_device_t *dev, void *data, struct drm_file *file_priv);
1045 int drm_freebufs(drm_device_t *dev, void *data, struct drm_file *file_priv);
1046 int drm_mapbufs(drm_device_t *dev, void *data, struct drm_file *file_priv);
1048 /* DMA support (drm_dma.c) */
1049 int drm_dma(drm_device_t *dev, void *data, struct drm_file *file_priv);
1051 /* IRQ support (drm_irq.c) */
1052 int drm_control(drm_device_t *dev, void *data, struct drm_file *file_priv);
1053 int drm_wait_vblank(drm_device_t *dev, void *data, struct drm_file *file_priv);
1054 void drm_locked_tasklet(drm_device_t *dev,
1055 void (*tasklet)(drm_device_t *dev));
1057 /* AGP/GART support (drm_agpsupport.c) */
1058 int drm_agp_acquire_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
1059 int drm_agp_release_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
1060 int drm_agp_enable_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
1061 int drm_agp_info_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
1062 int drm_agp_alloc_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
1063 int drm_agp_free_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
1064 int drm_agp_unbind_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
1065 int drm_agp_bind_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
1067 /* Scatter Gather Support (drm_scatter.c) */
1068 int drm_sg_alloc_ioctl(drm_device_t *dev, void *data, struct drm_file *file_priv);
1069 int drm_sg_free(drm_device_t *dev, void *data, struct drm_file *file_priv);
1071 /* consistent PCI memory functions (drm_pci.c) */
1072 drm_dma_handle_t *drm_pci_alloc(drm_device_t *dev, size_t size, size_t align,
1073 dma_addr_t maxaddr);
1074 void drm_pci_free(drm_device_t *dev, drm_dma_handle_t *dmah);
1076 /* Inline replacements for DRM_IOREMAP macros */
1077 static __inline__ void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
1079 map->handle = drm_ioremap(dev, map);
1081 static __inline__ void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
1083 if ( map->handle && map->size )
1084 drm_ioremapfree(map);
1087 static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev, unsigned long offset)
1089 drm_local_map_t *map;
1091 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
1092 TAILQ_FOREACH(map, &dev->maplist, link) {
1093 if (map->offset == offset)
1099 static __inline__ void drm_core_dropmap(struct drm_map *map)
1103 #endif /* __KERNEL__ */
1104 #endif /* _DRM_P_H_ */