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>
37 #if defined(_KERNEL) || defined(__KERNEL__)
39 typedef struct drm_device drm_device_t;
40 typedef struct drm_file drm_file_t;
42 #include <sys/param.h>
43 #include <sys/queue.h>
44 #include <sys/malloc.h>
45 #include <sys/kernel.h>
46 #include <sys/module.h>
47 #include <sys/systm.h>
52 #include <sys/fcntl.h>
54 #include <sys/filio.h>
55 #include <sys/sysctl.h>
57 #include <sys/signalvar.h>
61 #include <vm/vm_extern.h>
62 #include <vm/vm_map.h>
63 #include <vm/vm_param.h>
64 #include <machine/param.h>
65 #include <machine/pmap.h>
66 #include <machine/bus.h>
67 #include <machine/resource.h>
68 #include <machine/sysarch.h>
69 #include <sys/endian.h>
71 #if defined(__FreeBSD__)
73 #include <sys/memrange.h>
74 #include <pci/agpvar.h>
75 #include <sys/agpio.h>
76 #if __FreeBSD_version >= 500000
77 #include <sys/mutex.h>
78 #include <dev/pci/pcivar.h>
79 #include <sys/selinfo.h>
80 #else /* __FreeBSD_version >= 500000 */
81 #include <pci/pcivar.h>
82 #include <sys/select.h>
83 #endif /* __FreeBSD_version < 500000 */
84 #elif defined(__NetBSD__)
85 #include <machine/mtrr.h>
86 #include <sys/vnode.h>
87 #include <sys/select.h>
88 #include <sys/device.h>
89 #include <sys/resourcevar.h>
91 #include <sys/agpio.h>
92 #include <sys/ttycom.h>
94 #include <dev/pci/pcireg.h>
95 #include <dev/pci/pcivar.h>
96 #include <dev/pci/agpvar.h>
97 #elif defined(__OpenBSD__)
104 #include "drm_linux_list.h"
105 #include "drm_atomic.h"
111 #define DRM_DEBUG_DEFAULT_ON 1
112 #endif /* DRM_DEBUG */
115 #if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__)
116 #include <sys/file.h>
117 #include <sys/proc.h>
118 #include <machine/../linux/linux.h>
119 #include <machine/../linux/linux_proto.h>
121 /* Either it was defined when it shouldn't be (FreeBSD amd64) or it isn't
122 * supported on this OS yet.
128 #define DRM_HASH_SIZE 16 /* Size of key hash table */
129 #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
130 #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
132 #define DRM_MEM_DMA 0
133 #define DRM_MEM_SAREA 1
134 #define DRM_MEM_DRIVER 2
135 #define DRM_MEM_MAGIC 3
136 #define DRM_MEM_IOCTLS 4
137 #define DRM_MEM_MAPS 5
138 #define DRM_MEM_BUFS 6
139 #define DRM_MEM_SEGS 7
140 #define DRM_MEM_PAGES 8
141 #define DRM_MEM_FILES 9
142 #define DRM_MEM_QUEUES 10
143 #define DRM_MEM_CMDS 11
144 #define DRM_MEM_MAPPINGS 12
145 #define DRM_MEM_BUFLISTS 13
146 #define DRM_MEM_AGPLISTS 14
147 #define DRM_MEM_TOTALAGP 15
148 #define DRM_MEM_BOUNDAGP 16
149 #define DRM_MEM_CTXBITMAP 17
150 #define DRM_MEM_STUB 18
151 #define DRM_MEM_SGLISTS 19
153 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
155 /* Internal types and structures */
156 #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
157 #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
158 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
160 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
162 MALLOC_DECLARE(M_DRM);
164 #define __OS_HAS_AGP 1
166 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
167 #define DRM_DEV_UID 0
168 #define DRM_DEV_GID 0
170 #define wait_queue_head_t atomic_t
171 #define DRM_WAKEUP(w) wakeup((void *)w)
172 #define DRM_WAKEUP_INT(w) wakeup(w)
173 #define DRM_INIT_WAITQUEUE(queue) do {} while (0)
175 #if defined(__FreeBSD__) && __FreeBSD_version < 502109
176 #define bus_alloc_resource_any(dev, type, rid, flags) \
177 bus_alloc_resource(dev, type, rid, 0ul, ~0ul, 1, flags)
180 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
181 #define DRM_CURPROC curthread
182 #define DRM_STRUCTPROC struct thread
183 #define DRM_SPINTYPE struct mtx
184 #define DRM_SPININIT(l,name) mtx_init(&l, name, NULL, MTX_DEF)
185 #define DRM_SPINUNINIT(l) mtx_destroy(&l)
186 #define DRM_SPINLOCK(l) mtx_lock(l)
187 #define DRM_SPINUNLOCK(u) mtx_unlock(u);
188 #define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED)
189 #define DRM_CURRENTPID curthread->td_proc->p_pid
190 #define DRM_LOCK() mtx_lock(&dev->dev_lock)
191 #define DRM_UNLOCK() mtx_unlock(&dev->dev_lock)
192 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
193 #else /* __FreeBSD__ && __FreeBSD_version >= 500000 */
194 #define DRM_CURPROC curproc
195 #define DRM_STRUCTPROC struct proc
196 #define DRM_SPINTYPE struct simplelock
197 #define DRM_SPININIT(l,name)
198 #define DRM_SPINUNINIT(l)
199 #define DRM_SPINLOCK(l)
200 #define DRM_SPINUNLOCK(u)
201 #define DRM_SPINLOCK_ASSERT(l)
202 #define DRM_CURRENTPID curproc->p_pid
205 #define DRM_SYSCTL_HANDLER_ARGS SYSCTL_HANDLER_ARGS
206 #define spldrm() spltty()
207 #endif /* __NetBSD__ || __OpenBSD__ */
209 /* Currently our DRMFILE (filp) is a void * which is actually the pid
210 * of the current process. It should be a per-open unique pointer, but
211 * code for that is not yet written */
212 #define DRMFILE void *
213 #define DRM_IRQ_ARGS void *arg
214 typedef void irqreturn_t;
215 #define IRQ_HANDLED /* nothing */
216 #define IRQ_NONE /* nothing */
218 #if defined(__FreeBSD__)
220 drm_device_t *dev = kdev->si_drv1
221 #define DRM_IOCTL_ARGS struct cdev *kdev, u_long cmd, caddr_t data, \
222 int flags, DRM_STRUCTPROC *p, DRMFILE filp
224 #define PAGE_ALIGN(addr) round_page(addr)
225 #define DRM_SUSER(p) suser(p)
226 #define DRM_AGP_FIND_DEVICE() agp_find_device()
227 #define DRM_MTRR_WC MDF_WRITECOMBINE
228 #define jiffies ticks
230 #else /* __FreeBSD__ */
232 #if defined(__NetBSD__)
234 drm_device_t *dev = device_lookup(&drm_cd, minor(kdev))
235 #elif defined(__OpenBSD__)
237 drm_device_t *dev = (device_lookup(&drm_cd, \
238 minor(kdev)))->dv_cfdata->cf_driver->cd_devs[minor(kdev)]
239 #endif /* __OpenBSD__ */
240 #define DRM_IOCTL_ARGS dev_t kdev, u_long cmd, caddr_t data, \
241 int flags, DRM_STRUCTPROC *p, DRMFILE filp
243 #define CDEV_MAJOR 34
244 #define PAGE_ALIGN(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK)
245 #define DRM_SUSER(p) suser(p->p_ucred, &p->p_acflag)
246 #define DRM_AGP_FIND_DEVICE() agp_find_device(0)
247 #define DRM_MTRR_WC MTRR_TYPE_WC
248 #define jiffies hardclock_ticks
250 typedef drm_device_t *device_t;
251 extern struct cfdriver drm_cd;
252 #endif /* !__FreeBSD__ */
254 typedef unsigned long dma_addr_t;
255 typedef u_int32_t u32;
256 typedef u_int16_t u16;
259 /* DRM_READMEMORYBARRIER() prevents reordering of reads.
260 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
261 * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
263 #if defined(__i386__)
264 #define DRM_READMEMORYBARRIER() __asm __volatile( \
265 "lock; addl $0,0(%%esp)" : : : "memory");
266 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
267 #define DRM_MEMORYBARRIER() __asm __volatile( \
268 "lock; addl $0,0(%%esp)" : : : "memory");
269 #elif defined(__alpha__)
270 #define DRM_READMEMORYBARRIER() alpha_mb();
271 #define DRM_WRITEMEMORYBARRIER() alpha_wmb();
272 #define DRM_MEMORYBARRIER() alpha_mb();
273 #elif defined(__amd64__)
274 #define DRM_READMEMORYBARRIER() __asm __volatile( \
275 "lock; addl $0,0(%%rsp)" : : : "memory");
276 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
277 #define DRM_MEMORYBARRIER() __asm __volatile( \
278 "lock; addl $0,0(%%rsp)" : : : "memory");
282 #define DRM_READ8(map, offset) \
283 *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset))
284 #define DRM_READ16(map, offset) \
285 *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset))
286 #define DRM_READ32(map, offset) \
287 *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset))
288 #define DRM_WRITE8(map, offset, val) \
289 *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset)) = val
290 #define DRM_WRITE16(map, offset, val) \
291 *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset)) = val
292 #define DRM_WRITE32(map, offset, val) \
293 *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset)) = val
295 #define DRM_VERIFYAREA_READ( uaddr, size ) \
296 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
298 #else /* __FreeBSD__ */
300 typedef vaddr_t vm_offset_t;
302 #define DRM_READ8(map, offset) \
303 bus_space_read_1( (map)->bst, (map)->bsh, (offset))
304 #define DRM_READ16(map, offset) \
305 bus_space_read_2( (map)->bst, (map)->bsh, (offset))
306 #define DRM_READ32(map, offset) \
307 bus_space_read_4( (map)->bst, (map)->bsh, (offset))
308 #define DRM_WRITE8(map, offset, val) \
309 bus_space_write_1((map)->bst, (map)->bsh, (offset), (val))
310 #define DRM_WRITE16(map, offset, val) \
311 bus_space_write_2((map)->bst, (map)->bsh, (offset), (val))
312 #define DRM_WRITE32(map, offset, val) \
313 bus_space_write_4((map)->bst, (map)->bsh, (offset), (val))
315 #define DRM_VERIFYAREA_READ( uaddr, size ) \
316 (!uvm_useracc((caddr_t)uaddr, size, VM_PROT_READ))
317 #endif /* !__FreeBSD__ */
319 #define DRM_COPY_TO_USER_IOCTL(user, kern, size) \
320 if ( IOCPARM_LEN(cmd) != size) \
323 #define DRM_COPY_FROM_USER_IOCTL(kern, user, size) \
324 if ( IOCPARM_LEN(cmd) != size) \
327 #define DRM_COPY_TO_USER(user, kern, size) \
328 copyout(kern, user, size)
329 #define DRM_COPY_FROM_USER(kern, user, size) \
330 copyin(user, kern, size)
331 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
332 copyin(arg2, arg1, arg3)
333 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
334 copyout(arg2, arg1, arg3)
335 #if __FreeBSD_version > 500000
336 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
337 ((val) = fuword32(uaddr), 0)
339 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
340 ((val) = fuword(uaddr), 0)
343 #define cpu_to_le32(x) htole32(x)
344 #define le32_to_cpu(x) le32toh(x)
348 #define DRM_UDELAY(udelay) DELAY(udelay)
349 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
351 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
352 (_map) = (_dev)->context_sareas[_ctx]; \
355 #define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) \
357 if (_filp != (DRMFILE)(intptr_t)DRM_CURRENTPID) { \
358 DRM_ERROR("filp doesn't match curproc\n"); \
361 _priv = drm_find_file_by_proc(dev, DRM_CURPROC); \
362 if (_priv == NULL) { \
363 DRM_ERROR("can't find authenticator\n"); \
368 #define LOCK_TEST_WITH_RETURN(dev, filp) \
370 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
371 dev->lock.filp != filp) { \
372 DRM_ERROR("%s called without lock held\n", \
378 #define DRM_GETSAREA() \
380 drm_local_map_t *map; \
381 DRM_SPINLOCK_ASSERT(&dev->dev_lock); \
382 TAILQ_FOREACH(map, &dev->maplist, link) { \
383 if (map->type == _DRM_SHM && \
384 map->flags & _DRM_CONTAINS_LOCK) { \
385 dev_priv->sarea = map; \
391 #if defined(__FreeBSD__) && __FreeBSD_version > 500000
392 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
393 for ( ret = 0 ; !ret && !(condition) ; ) { \
395 mtx_lock(&dev->irq_lock); \
397 ret = msleep(&(queue), &dev->irq_lock, \
398 PZERO | PCATCH, "drmwtq", (timeout)); \
399 mtx_unlock(&dev->irq_lock); \
403 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
404 for ( ret = 0 ; !ret && !(condition) ; ) { \
407 ret = tsleep( &(queue), PZERO | PCATCH, \
408 "drmwtq", (timeout) ); \
413 #define DRM_ERROR(fmt, arg...) \
414 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
415 DRM_CURRENTPID, __func__ , ## arg)
417 #define DRM_INFO(fmt, arg...) printf("info: [" DRM_NAME "] " fmt , ## arg)
419 #define DRM_DEBUG(fmt, arg...) do { \
420 if (drm_debug_flag) \
421 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
422 __func__ , ## arg); \
425 typedef struct drm_pci_id_list
433 typedef struct drm_ioctl_desc {
434 int (*func)(DRM_IOCTL_ARGS);
439 typedef struct drm_magic_entry {
441 struct drm_file *priv;
442 struct drm_magic_entry *next;
445 typedef struct drm_magic_head {
446 struct drm_magic_entry *head;
447 struct drm_magic_entry *tail;
450 typedef struct drm_buf {
451 int idx; /* Index into master buflist */
452 int total; /* Buffer size */
453 int order; /* log-base-2(total) */
454 int used; /* Amount of buffer in use (for DMA) */
455 unsigned long offset; /* Byte offset (used internally) */
456 void *address; /* Address of buffer */
457 unsigned long bus_address; /* Bus address of buffer */
458 struct drm_buf *next; /* Kernel-only: used for free list */
459 __volatile__ int pending; /* On hardware DMA queue */
460 DRMFILE filp; /* Unique identifier of holding process */
461 int context; /* Kernel queue for this buffer */
469 } list; /* Which list we're on */
471 int dev_priv_size; /* Size of buffer private stoarge */
472 void *dev_private; /* Per-buffer private storage */
475 typedef struct drm_freelist {
476 int initialized; /* Freelist in use */
477 atomic_t count; /* Number of free buffers */
478 drm_buf_t *next; /* End pointer */
480 int low_mark; /* Low water mark */
481 int high_mark; /* High water mark */
484 typedef struct drm_dma_handle {
487 #if defined(__FreeBSD__)
490 #elif defined(__NetBSD__)
491 bus_dma_segment_t seg;
495 typedef struct drm_buf_entry {
500 drm_dma_handle_t **seglist;
503 drm_freelist_t freelist;
506 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
508 TAILQ_ENTRY(drm_file) link;
515 unsigned long ioctl_count;
519 typedef struct drm_lock_data {
520 drm_hw_lock_t *hw_lock; /* Hardware lock */
521 DRMFILE filp; /* Unique identifier of holding process (NULL is kernel)*/
522 int lock_queue; /* Queue of blocked processes */
523 unsigned long lock_time; /* Time of last lock in jiffies */
526 /* This structure, in the drm_device_t, is always initialized while the device
527 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
528 * when set marks that no further bufs may be allocated until device teardown
529 * occurs (when the last open of the device has closed). The high/low
530 * watermarks of bufs are only touched by the X Server, and thus not
531 * concurrently accessed, so no locking is needed.
533 typedef struct drm_device_dma {
534 drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
536 drm_buf_t **buflist; /* Vector of pointers info bufs */
539 unsigned long *pagelist;
540 unsigned long byte_count;
542 _DRM_DMA_USE_AGP = 0x01,
543 _DRM_DMA_USE_SG = 0x02
547 typedef struct drm_agp_mem {
549 unsigned long bound; /* address */
551 struct drm_agp_mem *prev;
552 struct drm_agp_mem *next;
555 typedef struct drm_agp_head {
557 struct agp_info info;
559 drm_agp_mem_t *memory;
565 int cant_use_aperture;
566 unsigned long page_mask;
569 typedef struct drm_sg_mem {
570 unsigned long handle;
573 drm_dma_handle_t *dmah; /* Handle to PCI memory for ATI PCIGART table */
576 typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
578 typedef struct drm_local_map {
579 unsigned long offset; /* Physical address (0 for SAREA)*/
580 unsigned long size; /* Physical size (bytes) */
581 drm_map_type_t type; /* Type of memory mapped */
582 drm_map_flags_t flags; /* Flags */
583 void *handle; /* User-space: "Handle" to pass to mmap */
584 /* Kernel-space: kernel-virtual address */
585 int mtrr; /* Boolean: MTRR used */
587 int rid; /* PCI resource ID for bus_space */
588 int kernel_owned; /* Boolean: 1 = initmapped, 0 = addmapped */
589 struct resource *bsr;
591 bus_space_handle_t bsh;
592 drm_dma_handle_t *dmah;
593 TAILQ_ENTRY(drm_local_map) link;
596 TAILQ_HEAD(drm_vbl_sig_list, drm_vbl_sig);
597 typedef struct drm_vbl_sig {
598 TAILQ_ENTRY(drm_vbl_sig) link;
599 unsigned int sequence;
605 * DRM device functions structure
608 #if defined(__NetBSD__) || defined(__OpenBSD__)
609 struct device device; /* softc is an extension of struct device */
612 /* Beginning of driver-config section */
613 int (*preinit)(struct drm_device *, unsigned long flags);
614 int (*postinit)(struct drm_device *, unsigned long flags);
615 void (*prerelease)(struct drm_device *, void *filp);
616 void (*pretakedown)(struct drm_device *);
617 int (*postcleanup)(struct drm_device *);
618 int (*presetup)(struct drm_device *);
619 int (*postsetup)(struct drm_device *);
620 int (*open_helper)(struct drm_device *, drm_file_t *);
621 void (*free_filp_priv)(struct drm_device *, drm_file_t *);
622 void (*release)(struct drm_device *, void *filp);
623 int (*dma_ioctl)(DRM_IOCTL_ARGS);
624 void (*dma_ready)(struct drm_device *);
625 int (*dma_quiescent)(struct drm_device *);
626 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
627 drm_lock_flags_t flags);
628 int (*dma_flush_unblock)(struct drm_device *, int context,
629 drm_lock_flags_t flags);
630 int (*context_ctor)(struct drm_device *dev, int context);
631 int (*context_dtor)(struct drm_device *dev, int context);
632 int (*kernel_context_switch)(struct drm_device *dev, int old,
634 int (*kernel_context_switch_unlock)(struct drm_device *dev);
635 void (*irq_preinstall)(drm_device_t *dev);
636 void (*irq_postinstall)(drm_device_t *dev);
637 void (*irq_uninstall)(drm_device_t *dev);
638 void (*irq_handler)(DRM_IRQ_ARGS);
639 int (*vblank_wait)(drm_device_t *dev, unsigned int *sequence);
642 * Called by \c drm_device_is_agp. Typically used to determine if a
643 * card is really attached to AGP or not.
645 * \param dev DRM device handle
648 * One of three values is returned depending on whether or not the
649 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
650 * (return of 1), or may or may not be AGP (return of 2).
652 int (*device_is_agp) (struct drm_device * dev);
655 drm_ioctl_desc_t *driver_ioctls;
656 int max_driver_ioctl;
662 int driver_patchlevel;
663 const char *driver_name; /* Simple driver name */
664 const char *driver_desc; /* Longer driver name */
665 const char *driver_date; /* Date of last major changes. */
668 unsigned require_agp :1;
671 unsigned use_pci_dma :1;
672 unsigned use_dma_queue :1;
674 unsigned use_vbl_irq :1;
675 unsigned use_mtrr :1;
676 /* End of driver-config section */
678 char *unique; /* Unique identifier: e.g., busid */
679 int unique_len; /* Length of unique field */
681 device_t device; /* Device instance from newbus */
683 struct cdev *devnode; /* Device number for mknod */
684 int if_version; /* Highest interface version set */
686 int flags; /* Flags to open(2) */
689 #if defined(__FreeBSD__) && __FreeBSD_version > 500000
690 struct mtx dma_lock; /* protects dev->dma */
691 struct mtx irq_lock; /* protects irq condition checks */
692 struct mtx dev_lock; /* protects everything else */
695 int open_count; /* Outstanding files open */
696 int buf_use; /* Buffers in use -- cannot alloc */
698 /* Performance counters */
699 unsigned long counters;
700 drm_stat_type_t types[15];
704 drm_file_list_t files;
705 drm_magic_head_t magiclist[DRM_HASH_SIZE];
707 /* Linked list of mappable regions. Protected by dev_lock */
708 drm_map_list_t maplist;
710 drm_local_map_t **context_sareas;
713 drm_lock_data_t lock; /* Information on hardware lock */
715 /* DMA queues (contexts) */
716 drm_device_dma_t *dma; /* Optional pointer for DMA support */
718 /* Context support */
719 int irq; /* Interrupt used by board */
720 int irq_enabled; /* True if the irq handler is enabled */
722 int irqrid; /* Interrupt used by board */
723 struct resource *irqr; /* Resource for interrupt used by board */
724 #elif defined(__NetBSD__) || defined(__OpenBSD__)
725 struct pci_attach_args pa;
727 void *irqh; /* Handle from bus_setup_intr */
734 atomic_t context_flag; /* Context swapping flag */
735 int last_context; /* Last current context */
736 int vbl_queue; /* vbl wait channel */
737 atomic_t vbl_received;
740 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
741 #elif defined(__NetBSD__)
746 struct drm_sysctl_info *sysctl;
749 drm_sg_mem_t *sg; /* Scatter gather memory */
750 atomic_t *ctx_bitmap;
752 drm_local_map_t *agp_buffer_map;
755 extern int drm_debug_flag;
757 /* Device setup support (drm_drv.c) */
759 int drm_probe(device_t nbdev, drm_pci_id_list_t *idlist);
760 int drm_attach(device_t nbdev, drm_pci_id_list_t *idlist);
761 int drm_detach(device_t nbdev);
768 #elif defined(__NetBSD__) || defined(__OpenBSD__)
769 int drm_probe(struct pci_attach_args *pa, drm_pci_id_list_t *idlist);
770 int drm_attach(struct pci_attach_args *pa, dev_t kdev, drm_pci_id_list_t *idlist);
771 dev_type_ioctl(drm_ioctl);
772 dev_type_open(drm_open);
773 dev_type_close(drm_close);
774 dev_type_read(drm_read);
775 dev_type_poll(drm_poll);
776 dev_type_mmap(drm_mmap);
779 /* File operations helpers (drm_fops.c) */
781 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
782 DRM_STRUCTPROC *p, drm_device_t *dev);
783 extern drm_file_t *drm_find_file_by_proc(drm_device_t *dev,
785 #elif defined(__NetBSD__) || defined(__OpenBSD__)
786 extern int drm_open_helper(dev_t kdev, int flags, int fmt,
787 DRM_STRUCTPROC *p, drm_device_t *dev);
788 extern drm_file_t *drm_find_file_by_proc(drm_device_t *dev,
790 #endif /* __NetBSD__ || __OpenBSD__ */
792 /* Memory management support (drm_memory.c) */
793 void drm_mem_init(void);
794 void drm_mem_uninit(void);
795 void *drm_alloc(size_t size, int area);
796 void *drm_calloc(size_t nmemb, size_t size, int area);
797 void *drm_realloc(void *oldpt, size_t oldsize, size_t size,
799 void drm_free(void *pt, size_t size, int area);
800 void *drm_ioremap(drm_device_t *dev, drm_local_map_t *map);
801 void drm_ioremapfree(drm_local_map_t *map);
802 int drm_mtrr_add(unsigned long offset, size_t size, int flags);
803 int drm_mtrr_del(unsigned long offset, size_t size, int flags);
805 int drm_context_switch(drm_device_t *dev, int old, int new);
806 int drm_context_switch_complete(drm_device_t *dev, int new);
808 int drm_ctxbitmap_init(drm_device_t *dev);
809 void drm_ctxbitmap_cleanup(drm_device_t *dev);
810 void drm_ctxbitmap_free(drm_device_t *dev, int ctx_handle);
811 int drm_ctxbitmap_next(drm_device_t *dev);
813 /* Locking IOCTL support (drm_lock.c) */
814 int drm_lock_take(__volatile__ unsigned int *lock,
815 unsigned int context);
816 int drm_lock_transfer(drm_device_t *dev,
817 __volatile__ unsigned int *lock,
818 unsigned int context);
819 int drm_lock_free(drm_device_t *dev,
820 __volatile__ unsigned int *lock,
821 unsigned int context);
823 /* Buffer management support (drm_bufs.c) */
824 unsigned long drm_get_resource_start(drm_device_t *dev, unsigned int resource);
825 unsigned long drm_get_resource_len(drm_device_t *dev, unsigned int resource);
826 int drm_initmap(drm_device_t *dev, unsigned long start, unsigned long len,
827 unsigned int resource, int type, int flags);
828 void drm_remove_map(drm_device_t *dev, drm_local_map_t *map);
829 int drm_order(unsigned long size);
831 /* DMA support (drm_dma.c) */
832 int drm_dma_setup(drm_device_t *dev);
833 void drm_dma_takedown(drm_device_t *dev);
834 void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf);
835 void drm_reclaim_buffers(drm_device_t *dev, DRMFILE filp);
837 /* IRQ support (drm_irq.c) */
838 int drm_irq_install(drm_device_t *dev);
839 int drm_irq_uninstall(drm_device_t *dev);
840 irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
841 void drm_driver_irq_preinstall(drm_device_t *dev);
842 void drm_driver_irq_postinstall(drm_device_t *dev);
843 void drm_driver_irq_uninstall(drm_device_t *dev);
844 int drm_vblank_wait(drm_device_t *dev, unsigned int *vbl_seq);
845 void drm_vbl_send_signals(drm_device_t *dev);
847 /* AGP/GART support (drm_agpsupport.c) */
848 int drm_device_is_agp(drm_device_t *dev);
849 drm_agp_head_t *drm_agp_init(void);
850 void drm_agp_uninit(void);
851 int drm_agp_release(drm_device_t *dev);
852 void *drm_agp_allocate_memory(size_t pages, u32 type);
853 int drm_agp_free_memory(void *handle);
854 int drm_agp_bind_memory(void *handle, off_t start);
855 int drm_agp_unbind_memory(void *handle);
857 /* Scatter Gather Support (drm_scatter.c) */
858 void drm_sg_cleanup(drm_sg_mem_t *entry);
861 /* sysctl support (drm_sysctl.h) */
862 extern int drm_sysctl_init(drm_device_t *dev);
863 extern int drm_sysctl_cleanup(drm_device_t *dev);
864 #endif /* __FreeBSD__ */
866 /* ATI PCIGART support (ati_pcigart.c) */
867 int drm_ati_pcigart_init(drm_device_t *dev, unsigned long *addr,
868 dma_addr_t *bus_addr);
869 int drm_ati_pcigart_cleanup(drm_device_t *dev, unsigned long addr,
870 dma_addr_t bus_addr);
872 /* Locking IOCTL support (drm_drv.c) */
873 int drm_lock(DRM_IOCTL_ARGS);
874 int drm_unlock(DRM_IOCTL_ARGS);
875 int drm_version(DRM_IOCTL_ARGS);
876 int drm_setversion(DRM_IOCTL_ARGS);
878 /* Misc. IOCTL support (drm_ioctl.c) */
879 int drm_irq_by_busid(DRM_IOCTL_ARGS);
880 int drm_getunique(DRM_IOCTL_ARGS);
881 int drm_setunique(DRM_IOCTL_ARGS);
882 int drm_getmap(DRM_IOCTL_ARGS);
883 int drm_getclient(DRM_IOCTL_ARGS);
884 int drm_getstats(DRM_IOCTL_ARGS);
885 int drm_noop(DRM_IOCTL_ARGS);
887 /* Context IOCTL support (drm_context.c) */
888 int drm_resctx(DRM_IOCTL_ARGS);
889 int drm_addctx(DRM_IOCTL_ARGS);
890 int drm_modctx(DRM_IOCTL_ARGS);
891 int drm_getctx(DRM_IOCTL_ARGS);
892 int drm_switchctx(DRM_IOCTL_ARGS);
893 int drm_newctx(DRM_IOCTL_ARGS);
894 int drm_rmctx(DRM_IOCTL_ARGS);
895 int drm_setsareactx(DRM_IOCTL_ARGS);
896 int drm_getsareactx(DRM_IOCTL_ARGS);
898 /* Drawable IOCTL support (drm_drawable.c) */
899 int drm_adddraw(DRM_IOCTL_ARGS);
900 int drm_rmdraw(DRM_IOCTL_ARGS);
902 /* Authentication IOCTL support (drm_auth.c) */
903 int drm_getmagic(DRM_IOCTL_ARGS);
904 int drm_authmagic(DRM_IOCTL_ARGS);
906 /* Buffer management support (drm_bufs.c) */
907 int drm_addmap(DRM_IOCTL_ARGS);
908 int drm_rmmap(DRM_IOCTL_ARGS);
909 int drm_addbufs(DRM_IOCTL_ARGS);
910 int drm_infobufs(DRM_IOCTL_ARGS);
911 int drm_markbufs(DRM_IOCTL_ARGS);
912 int drm_freebufs(DRM_IOCTL_ARGS);
913 int drm_mapbufs(DRM_IOCTL_ARGS);
915 /* DMA support (drm_dma.c) */
916 int drm_dma(DRM_IOCTL_ARGS);
918 /* IRQ support (drm_irq.c) */
919 int drm_control(DRM_IOCTL_ARGS);
920 int drm_wait_vblank(DRM_IOCTL_ARGS);
922 /* AGP/GART support (drm_agpsupport.c) */
923 int drm_agp_acquire(DRM_IOCTL_ARGS);
924 int drm_agp_release_ioctl(DRM_IOCTL_ARGS);
925 int drm_agp_enable(DRM_IOCTL_ARGS);
926 int drm_agp_info(DRM_IOCTL_ARGS);
927 int drm_agp_alloc(DRM_IOCTL_ARGS);
928 int drm_agp_free(DRM_IOCTL_ARGS);
929 int drm_agp_unbind(DRM_IOCTL_ARGS);
930 int drm_agp_bind(DRM_IOCTL_ARGS);
932 /* Scatter Gather Support (drm_scatter.c) */
933 int drm_sg_alloc(DRM_IOCTL_ARGS);
934 int drm_sg_free(DRM_IOCTL_ARGS);
936 /* consistent PCI memory functions (drm_pci.c) */
937 drm_dma_handle_t *drm_pci_alloc(drm_device_t *dev, size_t size, size_t align,
939 void drm_pci_free(drm_device_t *dev, drm_dma_handle_t *dmah);
941 /* Inline replacements for DRM_IOREMAP macros */
942 static __inline__ void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
944 map->handle = drm_ioremap(dev, map);
946 static __inline__ void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
948 if ( map->handle && map->size )
949 drm_ioremapfree(map);
952 static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev, unsigned long offset)
954 drm_local_map_t *map;
956 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
957 TAILQ_FOREACH(map, &dev->maplist, link) {
958 if (map->offset == offset)
964 static __inline__ void drm_core_dropmap(struct drm_map *map)
968 #endif /* __KERNEL__ */
969 #endif /* _DRM_P_H_ */