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>
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>
53 #include <sys/fcntl.h>
55 #include <sys/filio.h>
56 #include <sys/sysctl.h>
58 #include <sys/signalvar.h>
62 #include <vm/vm_extern.h>
63 #include <vm/vm_map.h>
64 #include <vm/vm_param.h>
65 #include <machine/param.h>
66 #include <machine/pmap.h>
67 #include <machine/bus.h>
68 #include <machine/resource.h>
69 #include <machine/sysarch.h>
70 #include <sys/endian.h>
72 #if defined(__FreeBSD__)
74 #include <sys/memrange.h>
75 #include <pci/agpvar.h>
76 #include <sys/agpio.h>
77 #if __FreeBSD_version >= 500000
78 #include <sys/mutex.h>
79 #include <dev/pci/pcivar.h>
80 #include <sys/selinfo.h>
81 #else /* __FreeBSD_version >= 500000 */
82 #include <pci/pcivar.h>
83 #include <sys/select.h>
84 #endif /* __FreeBSD_version < 500000 */
85 #elif defined(__NetBSD__)
86 #include <machine/mtrr.h>
87 #include <sys/vnode.h>
88 #include <sys/select.h>
89 #include <sys/device.h>
90 #include <sys/resourcevar.h>
92 #include <sys/agpio.h>
93 #include <sys/ttycom.h>
95 #include <dev/pci/pcireg.h>
96 #include <dev/pci/pcivar.h>
97 #include <dev/pci/agpvar.h>
98 #elif defined(__OpenBSD__)
104 #include "dev/drm/drm.h"
105 #include "dev/drm/drm_linux_list.h"
106 #include "dev/drm/drm_atomic.h"
112 #define DRM_DEBUG_DEFAULT_ON 1
113 #endif /* DRM_DEBUG */
116 #if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__)
117 #include <sys/file.h>
118 #include <sys/proc.h>
119 #include <machine/../linux/linux.h>
120 #include <machine/../linux/linux_proto.h>
122 /* Either it was defined when it shouldn't be (FreeBSD amd64) or it isn't
123 * supported on this OS yet.
129 #define DRM_HASH_SIZE 16 /* Size of key hash table */
130 #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
131 #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
133 #define DRM_MEM_DMA 0
134 #define DRM_MEM_SAREA 1
135 #define DRM_MEM_DRIVER 2
136 #define DRM_MEM_MAGIC 3
137 #define DRM_MEM_IOCTLS 4
138 #define DRM_MEM_MAPS 5
139 #define DRM_MEM_BUFS 6
140 #define DRM_MEM_SEGS 7
141 #define DRM_MEM_PAGES 8
142 #define DRM_MEM_FILES 9
143 #define DRM_MEM_QUEUES 10
144 #define DRM_MEM_CMDS 11
145 #define DRM_MEM_MAPPINGS 12
146 #define DRM_MEM_BUFLISTS 13
147 #define DRM_MEM_AGPLISTS 14
148 #define DRM_MEM_TOTALAGP 15
149 #define DRM_MEM_BOUNDAGP 16
150 #define DRM_MEM_CTXBITMAP 17
151 #define DRM_MEM_STUB 18
152 #define DRM_MEM_SGLISTS 19
154 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
156 /* Internal types and structures */
157 #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
158 #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
159 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
161 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
163 MALLOC_DECLARE(M_DRM);
165 #define __OS_HAS_AGP 1
167 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
168 #define DRM_DEV_UID 0
169 #define DRM_DEV_GID 0
171 #define wait_queue_head_t atomic_t
172 #define DRM_WAKEUP(w) wakeup((void *)w)
173 #define DRM_WAKEUP_INT(w) wakeup(w)
174 #define DRM_INIT_WAITQUEUE(queue) do {} while (0)
176 #if defined(__FreeBSD__) && __FreeBSD_version < 502109
177 #define bus_alloc_resource_any(dev, type, rid, flags) \
178 bus_alloc_resource(dev, type, rid, 0ul, ~0ul, 1, flags)
181 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
182 #define DRM_CURPROC curthread
183 #define DRM_STRUCTPROC struct thread
184 #define DRM_SPINTYPE struct mtx
185 #define DRM_SPININIT(l,name) mtx_init(&l, name, NULL, MTX_DEF)
186 #define DRM_SPINUNINIT(l) mtx_destroy(&l)
187 #define DRM_SPINLOCK(l) mtx_lock(l)
188 #define DRM_SPINUNLOCK(u) mtx_unlock(u);
189 #define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED)
190 #define DRM_CURRENTPID curthread->td_proc->p_pid
191 #define DRM_LOCK() mtx_lock(&dev->dev_lock)
192 #define DRM_UNLOCK() mtx_unlock(&dev->dev_lock)
193 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
194 #else /* __FreeBSD__ && __FreeBSD_version >= 500000 */
195 #define DRM_CURPROC curproc
196 #define DRM_STRUCTPROC struct proc
197 #define DRM_SPINTYPE struct simplelock
198 #define DRM_SPININIT(l,name)
199 #define DRM_SPINUNINIT(l)
200 #define DRM_SPINLOCK(l)
201 #define DRM_SPINUNLOCK(u)
202 #define DRM_SPINLOCK_ASSERT(l)
203 #define DRM_CURRENTPID curproc->p_pid
206 #define DRM_SYSCTL_HANDLER_ARGS SYSCTL_HANDLER_ARGS
207 #define spldrm() spltty()
208 #endif /* __NetBSD__ || __OpenBSD__ */
210 /* Currently our DRMFILE (filp) is a void * which is actually the pid
211 * of the current process. It should be a per-open unique pointer, but
212 * code for that is not yet written */
213 #define DRMFILE void *
214 #define DRM_IRQ_ARGS void *arg
215 typedef void irqreturn_t;
216 #define IRQ_HANDLED /* nothing */
217 #define IRQ_NONE /* nothing */
219 #if defined(__FreeBSD__)
221 drm_device_t *dev = kdev->si_drv1
222 #define DRM_IOCTL_ARGS struct cdev *kdev, u_long cmd, caddr_t data, \
223 int flags, DRM_STRUCTPROC *p, DRMFILE filp
225 #define PAGE_ALIGN(addr) round_page(addr)
226 #define DRM_SUSER(p) suser(p)
227 #define DRM_AGP_FIND_DEVICE() agp_find_device()
228 #define DRM_MTRR_WC MDF_WRITECOMBINE
229 #define jiffies ticks
231 #else /* __FreeBSD__ */
233 #if defined(__NetBSD__)
235 drm_device_t *dev = device_lookup(&drm_cd, minor(kdev))
236 #elif defined(__OpenBSD__)
238 drm_device_t *dev = (device_lookup(&drm_cd, \
239 minor(kdev)))->dv_cfdata->cf_driver->cd_devs[minor(kdev)]
240 #endif /* __OpenBSD__ */
241 #define DRM_IOCTL_ARGS dev_t kdev, u_long cmd, caddr_t data, \
242 int flags, DRM_STRUCTPROC *p, DRMFILE filp
244 #define CDEV_MAJOR 34
245 #define PAGE_ALIGN(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK)
246 #define DRM_SUSER(p) suser(p->p_ucred, &p->p_acflag)
247 #define DRM_AGP_FIND_DEVICE() agp_find_device(0)
248 #define DRM_MTRR_WC MTRR_TYPE_WC
249 #define jiffies hardclock_ticks
251 typedef drm_device_t *device_t;
252 extern struct cfdriver drm_cd;
253 #endif /* !__FreeBSD__ */
255 typedef unsigned long dma_addr_t;
256 typedef u_int32_t u32;
257 typedef u_int16_t u16;
260 /* DRM_READMEMORYBARRIER() prevents reordering of reads.
261 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
262 * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
264 #if defined(__i386__)
265 #define DRM_READMEMORYBARRIER() __asm __volatile( \
266 "lock; addl $0,0(%%esp)" : : : "memory");
267 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
268 #define DRM_MEMORYBARRIER() __asm __volatile( \
269 "lock; addl $0,0(%%esp)" : : : "memory");
270 #elif defined(__alpha__)
271 #define DRM_READMEMORYBARRIER() alpha_mb();
272 #define DRM_WRITEMEMORYBARRIER() alpha_wmb();
273 #define DRM_MEMORYBARRIER() alpha_mb();
274 #elif defined(__amd64__)
275 #define DRM_READMEMORYBARRIER() __asm __volatile( \
276 "lock; addl $0,0(%%rsp)" : : : "memory");
277 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
278 #define DRM_MEMORYBARRIER() __asm __volatile( \
279 "lock; addl $0,0(%%rsp)" : : : "memory");
283 #define DRM_READ8(map, offset) \
284 *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset))
285 #define DRM_READ16(map, offset) \
286 *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset))
287 #define DRM_READ32(map, offset) \
288 *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset))
289 #define DRM_WRITE8(map, offset, val) \
290 *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset)) = val
291 #define DRM_WRITE16(map, offset, val) \
292 *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset)) = val
293 #define DRM_WRITE32(map, offset, val) \
294 *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset)) = val
296 #define DRM_VERIFYAREA_READ( uaddr, size ) \
297 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
299 #else /* __FreeBSD__ */
301 typedef vaddr_t vm_offset_t;
303 #define DRM_READ8(map, offset) \
304 bus_space_read_1( (map)->bst, (map)->bsh, (offset))
305 #define DRM_READ16(map, offset) \
306 bus_space_read_2( (map)->bst, (map)->bsh, (offset))
307 #define DRM_READ32(map, offset) \
308 bus_space_read_4( (map)->bst, (map)->bsh, (offset))
309 #define DRM_WRITE8(map, offset, val) \
310 bus_space_write_1((map)->bst, (map)->bsh, (offset), (val))
311 #define DRM_WRITE16(map, offset, val) \
312 bus_space_write_2((map)->bst, (map)->bsh, (offset), (val))
313 #define DRM_WRITE32(map, offset, val) \
314 bus_space_write_4((map)->bst, (map)->bsh, (offset), (val))
316 #define DRM_VERIFYAREA_READ( uaddr, size ) \
317 (!uvm_useracc((caddr_t)uaddr, size, VM_PROT_READ))
318 #endif /* !__FreeBSD__ */
320 #define DRM_COPY_TO_USER_IOCTL(user, kern, size) \
321 if ( IOCPARM_LEN(cmd) != size) \
324 #define DRM_COPY_FROM_USER_IOCTL(kern, user, size) \
325 if ( IOCPARM_LEN(cmd) != size) \
328 #define DRM_COPY_TO_USER(user, kern, size) \
329 copyout(kern, user, size)
330 #define DRM_COPY_FROM_USER(kern, user, size) \
331 copyin(user, kern, size)
332 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
333 copyin(arg2, arg1, arg3)
334 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
335 copyout(arg2, arg1, arg3)
336 #if __FreeBSD_version > 500000
337 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
338 ((val) = fuword32(uaddr), 0)
340 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
341 ((val) = fuword(uaddr), 0)
344 #define cpu_to_le32(x) htole32(x)
345 #define le32_to_cpu(x) le32toh(x)
349 #define DRM_UDELAY(udelay) DELAY(udelay)
350 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
352 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
353 (_map) = (_dev)->context_sareas[_ctx]; \
356 #define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) \
358 if (_filp != (DRMFILE)(intptr_t)DRM_CURRENTPID) { \
359 DRM_ERROR("filp doesn't match curproc\n"); \
362 _priv = drm_find_file_by_proc(dev, DRM_CURPROC); \
363 if (_priv == NULL) { \
364 DRM_ERROR("can't find authenticator\n"); \
369 #define LOCK_TEST_WITH_RETURN(dev, filp) \
371 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
372 dev->lock.filp != filp) { \
373 DRM_ERROR("%s called without lock held\n", \
379 #define DRM_GETSAREA() \
381 drm_local_map_t *map; \
382 DRM_SPINLOCK_ASSERT(&dev->dev_lock); \
383 TAILQ_FOREACH(map, &dev->maplist, link) { \
384 if (map->type == _DRM_SHM && \
385 map->flags & _DRM_CONTAINS_LOCK) { \
386 dev_priv->sarea = map; \
392 #if defined(__FreeBSD__) && __FreeBSD_version > 500000
393 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
394 for ( ret = 0 ; !ret && !(condition) ; ) { \
396 mtx_lock(&dev->irq_lock); \
398 ret = msleep(&(queue), &dev->irq_lock, \
399 PZERO | PCATCH, "drmwtq", (timeout)); \
400 mtx_unlock(&dev->irq_lock); \
404 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
405 for ( ret = 0 ; !ret && !(condition) ; ) { \
408 ret = tsleep( &(queue), PZERO | PCATCH, \
409 "drmwtq", (timeout) ); \
414 #define DRM_ERROR(fmt, arg...) \
415 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
416 DRM_CURRENTPID, __func__ , ## arg)
418 #define DRM_INFO(fmt, arg...) printf("info: [" DRM_NAME "] " fmt , ## arg)
420 #define DRM_DEBUG(fmt, arg...) do { \
421 if (drm_debug_flag) \
422 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
423 __func__ , ## arg); \
426 typedef struct drm_pci_id_list
434 typedef struct drm_ioctl_desc {
435 int (*func)(DRM_IOCTL_ARGS);
440 typedef struct drm_magic_entry {
442 struct drm_file *priv;
443 struct drm_magic_entry *next;
446 typedef struct drm_magic_head {
447 struct drm_magic_entry *head;
448 struct drm_magic_entry *tail;
451 typedef struct drm_buf {
452 int idx; /* Index into master buflist */
453 int total; /* Buffer size */
454 int order; /* log-base-2(total) */
455 int used; /* Amount of buffer in use (for DMA) */
456 unsigned long offset; /* Byte offset (used internally) */
457 void *address; /* Address of buffer */
458 unsigned long bus_address; /* Bus address of buffer */
459 struct drm_buf *next; /* Kernel-only: used for free list */
460 __volatile__ int pending; /* On hardware DMA queue */
461 DRMFILE filp; /* Unique identifier of holding process */
462 int context; /* Kernel queue for this buffer */
470 } list; /* Which list we're on */
472 int dev_priv_size; /* Size of buffer private stoarge */
473 void *dev_private; /* Per-buffer private storage */
476 typedef struct drm_freelist {
477 int initialized; /* Freelist in use */
478 atomic_t count; /* Number of free buffers */
479 drm_buf_t *next; /* End pointer */
481 int low_mark; /* Low water mark */
482 int high_mark; /* High water mark */
485 typedef struct drm_buf_entry {
491 vm_offset_t *seglist;
492 dma_addr_t *seglist_bus;
494 drm_freelist_t freelist;
497 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
499 TAILQ_ENTRY(drm_file) link;
506 unsigned long ioctl_count;
510 typedef struct drm_lock_data {
511 drm_hw_lock_t *hw_lock; /* Hardware lock */
512 DRMFILE filp; /* Unique identifier of holding process (NULL is kernel)*/
513 int lock_queue; /* Queue of blocked processes */
514 unsigned long lock_time; /* Time of last lock in jiffies */
517 /* This structure, in the drm_device_t, is always initialized while the device
518 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
519 * when set marks that no further bufs may be allocated until device teardown
520 * occurs (when the last open of the device has closed). The high/low
521 * watermarks of bufs are only touched by the X Server, and thus not
522 * concurrently accessed, so no locking is needed.
524 typedef struct drm_device_dma {
525 drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
527 drm_buf_t **buflist; /* Vector of pointers info bufs */
530 unsigned long *pagelist;
531 unsigned long byte_count;
533 _DRM_DMA_USE_AGP = 0x01,
534 _DRM_DMA_USE_SG = 0x02
538 typedef struct drm_agp_mem {
540 unsigned long bound; /* address */
542 struct drm_agp_mem *prev;
543 struct drm_agp_mem *next;
546 typedef struct drm_agp_head {
548 struct agp_info info;
550 drm_agp_mem_t *memory;
556 int cant_use_aperture;
557 unsigned long page_mask;
560 typedef struct drm_sg_mem {
561 unsigned long handle;
567 typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
569 typedef struct drm_local_map {
570 unsigned long offset; /* Physical address (0 for SAREA)*/
571 unsigned long size; /* Physical size (bytes) */
572 drm_map_type_t type; /* Type of memory mapped */
573 drm_map_flags_t flags; /* Flags */
574 void *handle; /* User-space: "Handle" to pass to mmap */
575 /* Kernel-space: kernel-virtual address */
576 int mtrr; /* Boolean: MTRR used */
578 int rid; /* PCI resource ID for bus_space */
579 int kernel_owned; /* Boolean: 1 = initmapped, 0 = addmapped */
580 struct resource *bsr;
582 bus_space_handle_t bsh;
583 TAILQ_ENTRY(drm_local_map) link;
586 TAILQ_HEAD(drm_vbl_sig_list, drm_vbl_sig);
587 typedef struct drm_vbl_sig {
588 TAILQ_ENTRY(drm_vbl_sig) link;
589 unsigned int sequence;
595 * DRM device functions structure
598 #if defined(__NetBSD__) || defined(__OpenBSD__)
599 struct device device; /* softc is an extension of struct device */
602 /* Beginning of driver-config section */
603 int (*preinit)(struct drm_device *, unsigned long flags);
604 int (*postinit)(struct drm_device *, unsigned long flags);
605 void (*prerelease)(struct drm_device *, void *filp);
606 void (*pretakedown)(struct drm_device *);
607 int (*postcleanup)(struct drm_device *);
608 int (*presetup)(struct drm_device *);
609 int (*postsetup)(struct drm_device *);
610 int (*open_helper)(struct drm_device *, drm_file_t *);
611 void (*free_filp_priv)(struct drm_device *, drm_file_t *);
612 void (*release)(struct drm_device *, void *filp);
613 int (*dma_ioctl)(DRM_IOCTL_ARGS);
614 void (*dma_ready)(struct drm_device *);
615 int (*dma_quiescent)(struct drm_device *);
616 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
617 drm_lock_flags_t flags);
618 int (*dma_flush_unblock)(struct drm_device *, int context,
619 drm_lock_flags_t flags);
620 int (*context_ctor)(struct drm_device *dev, int context);
621 int (*context_dtor)(struct drm_device *dev, int context);
622 int (*kernel_context_switch)(struct drm_device *dev, int old,
624 int (*kernel_context_switch_unlock)(struct drm_device *dev);
625 void (*irq_preinstall)(drm_device_t *dev);
626 void (*irq_postinstall)(drm_device_t *dev);
627 void (*irq_uninstall)(drm_device_t *dev);
628 void (*irq_handler)(DRM_IRQ_ARGS);
629 int (*vblank_wait)(drm_device_t *dev, unsigned int *sequence);
631 drm_ioctl_desc_t *driver_ioctls;
632 int max_driver_ioctl;
638 int driver_patchlevel;
639 const char *driver_name; /* Simple driver name */
640 const char *driver_desc; /* Longer driver name */
641 const char *driver_date; /* Date of last major changes. */
644 unsigned require_agp :1;
647 unsigned use_pci_dma :1;
648 unsigned use_dma_queue :1;
650 unsigned use_vbl_irq :1;
651 unsigned use_mtrr :1;
652 /* End of driver-config section */
654 char *unique; /* Unique identifier: e.g., busid */
655 int unique_len; /* Length of unique field */
657 device_t device; /* Device instance from newbus */
659 struct cdev *devnode; /* Device number for mknod */
660 int if_version; /* Highest interface version set */
662 int flags; /* Flags to open(2) */
665 #if defined(__FreeBSD__) && __FreeBSD_version > 500000
666 struct mtx dma_lock; /* protects dev->dma */
667 struct mtx irq_lock; /* protects irq condition checks */
668 struct mtx dev_lock; /* protects everything else */
671 int open_count; /* Outstanding files open */
672 int buf_use; /* Buffers in use -- cannot alloc */
674 /* Performance counters */
675 unsigned long counters;
676 drm_stat_type_t types[15];
680 drm_file_list_t files;
681 drm_magic_head_t magiclist[DRM_HASH_SIZE];
683 /* Linked list of mappable regions. Protected by dev_lock */
684 drm_map_list_t maplist;
686 drm_local_map_t **context_sareas;
689 drm_lock_data_t lock; /* Information on hardware lock */
691 /* DMA queues (contexts) */
692 drm_device_dma_t *dma; /* Optional pointer for DMA support */
694 /* Context support */
695 int irq; /* Interrupt used by board */
696 int irq_enabled; /* True if the irq handler is enabled */
698 int irqrid; /* Interrupt used by board */
699 struct resource *irqr; /* Resource for interrupt used by board */
700 #elif defined(__NetBSD__) || defined(__OpenBSD__)
701 struct pci_attach_args pa;
702 pci_intr_handle_t ih;
704 void *irqh; /* Handle from bus_setup_intr */
711 atomic_t context_flag; /* Context swapping flag */
712 int last_context; /* Last current context */
713 int vbl_queue; /* vbl wait channel */
714 atomic_t vbl_received;
717 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
718 #elif defined(__NetBSD__)
723 struct drm_sysctl_info *sysctl;
726 drm_sg_mem_t *sg; /* Scatter gather memory */
727 atomic_t *ctx_bitmap;
729 drm_local_map_t *agp_buffer_map;
732 extern int drm_debug_flag;
734 /* Device setup support (drm_drv.c) */
736 int drm_probe(device_t nbdev, drm_pci_id_list_t *idlist);
737 int drm_attach(device_t nbdev, drm_pci_id_list_t *idlist);
738 int drm_detach(device_t nbdev);
745 #elif defined(__NetBSD__) || defined(__OpenBSD__)
746 int drm_probe(struct pci_attach_args *pa, drm_pci_id_list_t *idlist);
747 int drm_attach(struct pci_attach_args *pa, dev_t kdev, drm_pci_id_list_t *idlist);
748 dev_type_ioctl(drm_ioctl);
749 dev_type_open(drm_open);
750 dev_type_close(drm_close);
751 dev_type_read(drm_read);
752 dev_type_poll(drm_poll);
753 dev_type_mmap(drm_mmap);
756 /* File operations helpers (drm_fops.c) */
758 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
759 DRM_STRUCTPROC *p, drm_device_t *dev);
760 extern drm_file_t *drm_find_file_by_proc(drm_device_t *dev,
762 #elif defined(__NetBSD__) || defined(__OpenBSD__)
763 extern int drm_open_helper(dev_t kdev, int flags, int fmt,
764 DRM_STRUCTPROC *p, drm_device_t *dev);
765 extern drm_file_t *drm_find_file_by_proc(drm_device_t *dev,
767 #endif /* __NetBSD__ || __OpenBSD__ */
769 /* Memory management support (drm_memory.c) */
770 void drm_mem_init(void);
771 void drm_mem_uninit(void);
772 void *drm_alloc(size_t size, int area);
773 void *drm_calloc(size_t nmemb, size_t size, int area);
774 void *drm_realloc(void *oldpt, size_t oldsize, size_t size,
776 void drm_free(void *pt, size_t size, int area);
777 void *drm_ioremap(drm_device_t *dev, drm_local_map_t *map);
778 void drm_ioremapfree(drm_local_map_t *map);
779 int drm_mtrr_add(unsigned long offset, size_t size, int flags);
780 int drm_mtrr_del(unsigned long offset, size_t size, int flags);
782 int drm_context_switch(drm_device_t *dev, int old, int new);
783 int drm_context_switch_complete(drm_device_t *dev, int new);
785 int drm_ctxbitmap_init(drm_device_t *dev);
786 void drm_ctxbitmap_cleanup(drm_device_t *dev);
787 void drm_ctxbitmap_free(drm_device_t *dev, int ctx_handle);
788 int drm_ctxbitmap_next(drm_device_t *dev);
790 /* Locking IOCTL support (drm_lock.c) */
791 int drm_lock_take(__volatile__ unsigned int *lock,
792 unsigned int context);
793 int drm_lock_transfer(drm_device_t *dev,
794 __volatile__ unsigned int *lock,
795 unsigned int context);
796 int drm_lock_free(drm_device_t *dev,
797 __volatile__ unsigned int *lock,
798 unsigned int context);
800 /* Buffer management support (drm_bufs.c) */
801 unsigned long drm_get_resource_start(drm_device_t *dev, unsigned int resource);
802 unsigned long drm_get_resource_len(drm_device_t *dev, unsigned int resource);
803 int drm_initmap(drm_device_t *dev, unsigned long start, unsigned long len,
804 unsigned int resource, int type, int flags);
805 void drm_remove_map(drm_device_t *dev, drm_local_map_t *map);
806 int drm_order(unsigned long size);
808 /* DMA support (drm_dma.c) */
809 int drm_dma_setup(drm_device_t *dev);
810 void drm_dma_takedown(drm_device_t *dev);
811 void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf);
812 void drm_reclaim_buffers(drm_device_t *dev, DRMFILE filp);
814 /* IRQ support (drm_irq.c) */
815 int drm_irq_install(drm_device_t *dev);
816 int drm_irq_uninstall(drm_device_t *dev);
817 irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
818 void drm_driver_irq_preinstall(drm_device_t *dev);
819 void drm_driver_irq_postinstall(drm_device_t *dev);
820 void drm_driver_irq_uninstall(drm_device_t *dev);
821 int drm_vblank_wait(drm_device_t *dev, unsigned int *vbl_seq);
822 void drm_vbl_send_signals(drm_device_t *dev);
824 /* AGP/GART support (drm_agpsupport.c) */
825 int drm_device_is_agp(drm_device_t *dev);
826 drm_agp_head_t *drm_agp_init(void);
827 void drm_agp_uninit(void);
828 void drm_agp_do_release(void);
829 void *drm_agp_allocate_memory(size_t pages, u32 type);
830 int drm_agp_free_memory(void *handle);
831 int drm_agp_bind_memory(void *handle, off_t start);
832 int drm_agp_unbind_memory(void *handle);
834 /* Scatter Gather Support (drm_scatter.c) */
835 void drm_sg_cleanup(drm_sg_mem_t *entry);
838 /* sysctl support (drm_sysctl.h) */
839 extern int drm_sysctl_init(drm_device_t *dev);
840 extern int drm_sysctl_cleanup(drm_device_t *dev);
841 #endif /* __FreeBSD__ */
843 /* ATI PCIGART support (ati_pcigart.c) */
844 int drm_ati_pcigart_init(drm_device_t *dev, unsigned long *addr,
845 dma_addr_t *bus_addr);
846 int drm_ati_pcigart_cleanup(drm_device_t *dev, unsigned long addr,
847 dma_addr_t bus_addr);
849 /* Locking IOCTL support (drm_drv.c) */
850 int drm_lock(DRM_IOCTL_ARGS);
851 int drm_unlock(DRM_IOCTL_ARGS);
852 int drm_version(DRM_IOCTL_ARGS);
853 int drm_setversion(DRM_IOCTL_ARGS);
855 /* Misc. IOCTL support (drm_ioctl.c) */
856 int drm_irq_by_busid(DRM_IOCTL_ARGS);
857 int drm_getunique(DRM_IOCTL_ARGS);
858 int drm_setunique(DRM_IOCTL_ARGS);
859 int drm_getmap(DRM_IOCTL_ARGS);
860 int drm_getclient(DRM_IOCTL_ARGS);
861 int drm_getstats(DRM_IOCTL_ARGS);
862 int drm_noop(DRM_IOCTL_ARGS);
864 /* Context IOCTL support (drm_context.c) */
865 int drm_resctx(DRM_IOCTL_ARGS);
866 int drm_addctx(DRM_IOCTL_ARGS);
867 int drm_modctx(DRM_IOCTL_ARGS);
868 int drm_getctx(DRM_IOCTL_ARGS);
869 int drm_switchctx(DRM_IOCTL_ARGS);
870 int drm_newctx(DRM_IOCTL_ARGS);
871 int drm_rmctx(DRM_IOCTL_ARGS);
872 int drm_setsareactx(DRM_IOCTL_ARGS);
873 int drm_getsareactx(DRM_IOCTL_ARGS);
875 /* Drawable IOCTL support (drm_drawable.c) */
876 int drm_adddraw(DRM_IOCTL_ARGS);
877 int drm_rmdraw(DRM_IOCTL_ARGS);
879 /* Authentication IOCTL support (drm_auth.c) */
880 int drm_getmagic(DRM_IOCTL_ARGS);
881 int drm_authmagic(DRM_IOCTL_ARGS);
883 /* Buffer management support (drm_bufs.c) */
884 int drm_addmap(DRM_IOCTL_ARGS);
885 int drm_rmmap(DRM_IOCTL_ARGS);
886 int drm_addbufs(DRM_IOCTL_ARGS);
887 int drm_infobufs(DRM_IOCTL_ARGS);
888 int drm_markbufs(DRM_IOCTL_ARGS);
889 int drm_freebufs(DRM_IOCTL_ARGS);
890 int drm_mapbufs(DRM_IOCTL_ARGS);
892 /* DMA support (drm_dma.c) */
893 int drm_dma(DRM_IOCTL_ARGS);
895 /* IRQ support (drm_irq.c) */
896 int drm_control(DRM_IOCTL_ARGS);
897 int drm_wait_vblank(DRM_IOCTL_ARGS);
899 /* AGP/GART support (drm_agpsupport.c) */
900 int drm_agp_acquire(DRM_IOCTL_ARGS);
901 int drm_agp_release(DRM_IOCTL_ARGS);
902 int drm_agp_enable(DRM_IOCTL_ARGS);
903 int drm_agp_info(DRM_IOCTL_ARGS);
904 int drm_agp_alloc(DRM_IOCTL_ARGS);
905 int drm_agp_free(DRM_IOCTL_ARGS);
906 int drm_agp_unbind(DRM_IOCTL_ARGS);
907 int drm_agp_bind(DRM_IOCTL_ARGS);
909 /* Scatter Gather Support (drm_scatter.c) */
910 int drm_sg_alloc(DRM_IOCTL_ARGS);
911 int drm_sg_free(DRM_IOCTL_ARGS);
913 /* consistent PCI memory functions (drm_pci.c) */
914 void *drm_pci_alloc(drm_device_t *dev, size_t size, size_t align,
915 dma_addr_t maxaddr, dma_addr_t *busaddr);
916 void drm_pci_free(drm_device_t *dev, size_t size, void *vaddr,
919 /* Inline replacements for DRM_IOREMAP macros */
920 static __inline__ void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
922 map->handle = drm_ioremap(dev, map);
924 static __inline__ void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
926 if ( map->handle && map->size )
927 drm_ioremapfree(map);
930 static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev, unsigned long offset)
932 drm_local_map_t *map;
934 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
935 TAILQ_FOREACH(map, &dev->maplist, link) {
936 if (map->offset == offset)
942 static __inline__ void drm_core_dropmap(struct drm_map *map)
946 #endif /* __KERNEL__ */
947 #endif /* _DRM_P_H_ */