1 /* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*-
2 * Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com
4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
28 * Rickard E. (Rik) Faith <faith@valinux.com>
29 * Gareth Hughes <gareth@valinux.com>
36 #if defined(_KERNEL) || defined(__KERNEL__)
38 typedef struct drm_device drm_device_t;
39 typedef struct drm_file drm_file_t;
41 #include <sys/param.h>
42 #include <sys/queue.h>
43 #include <sys/malloc.h>
44 #include <sys/kernel.h>
45 #include <sys/module.h>
46 #include <sys/systm.h>
51 #include <sys/fcntl.h>
53 #include <sys/filio.h>
54 #include <sys/sysctl.h>
56 #include <sys/signalvar.h>
60 #include <vm/vm_extern.h>
61 #include <vm/vm_map.h>
62 #include <vm/vm_param.h>
63 #include <machine/param.h>
64 #include <machine/pmap.h>
65 #include <machine/bus.h>
66 #include <machine/resource.h>
67 #include <machine/sysarch.h>
68 #include <sys/endian.h>
70 #if defined(__FreeBSD__)
72 #include <sys/memrange.h>
73 #include <pci/agpvar.h>
74 #include <sys/agpio.h>
75 #if __FreeBSD_version >= 500000
76 #include <sys/mutex.h>
77 #include <dev/pci/pcivar.h>
78 #include <sys/selinfo.h>
79 #else /* __FreeBSD_version >= 500000 */
80 #include <pci/pcivar.h>
81 #include <sys/select.h>
82 #endif /* __FreeBSD_version < 500000 */
83 #elif defined(__NetBSD__)
84 #include <machine/mtrr.h>
85 #include <sys/vnode.h>
86 #include <sys/select.h>
87 #include <sys/device.h>
88 #include <sys/resourcevar.h>
90 #include <sys/agpio.h>
91 #include <sys/ttycom.h>
93 #include <dev/pci/pcireg.h>
94 #include <dev/pci/pcivar.h>
95 #include <dev/pci/agpvar.h>
96 #elif defined(__OpenBSD__)
103 #include "drm_linux_list.h"
104 #include "drm_atomic.h"
110 #define DRM_DEBUG_DEFAULT_ON 1
111 #endif /* DRM_DEBUG */
114 #if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__)
115 #include <sys/file.h>
116 #include <sys/proc.h>
117 #include <machine/../linux/linux.h>
118 #include <machine/../linux/linux_proto.h>
120 /* Either it was defined when it shouldn't be (FreeBSD amd64) or it isn't
121 * supported on this OS yet.
127 #define DRM_HASH_SIZE 16 /* Size of key hash table */
128 #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
129 #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
131 #define DRM_MEM_DMA 0
132 #define DRM_MEM_SAREA 1
133 #define DRM_MEM_DRIVER 2
134 #define DRM_MEM_MAGIC 3
135 #define DRM_MEM_IOCTLS 4
136 #define DRM_MEM_MAPS 5
137 #define DRM_MEM_BUFS 6
138 #define DRM_MEM_SEGS 7
139 #define DRM_MEM_PAGES 8
140 #define DRM_MEM_FILES 9
141 #define DRM_MEM_QUEUES 10
142 #define DRM_MEM_CMDS 11
143 #define DRM_MEM_MAPPINGS 12
144 #define DRM_MEM_BUFLISTS 13
145 #define DRM_MEM_AGPLISTS 14
146 #define DRM_MEM_TOTALAGP 15
147 #define DRM_MEM_BOUNDAGP 16
148 #define DRM_MEM_CTXBITMAP 17
149 #define DRM_MEM_STUB 18
150 #define DRM_MEM_SGLISTS 19
152 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
154 /* Internal types and structures */
155 #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
156 #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
157 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
159 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
161 MALLOC_DECLARE(M_DRM);
163 #define __OS_HAS_AGP 1
165 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
166 #define DRM_DEV_UID 0
167 #define DRM_DEV_GID 0
169 #define wait_queue_head_t atomic_t
170 #define DRM_WAKEUP(w) wakeup((void *)w)
171 #define DRM_WAKEUP_INT(w) wakeup(w)
172 #define DRM_INIT_WAITQUEUE(queue) do {} while (0)
174 #if defined(__FreeBSD__) && __FreeBSD_version < 502109
175 #define bus_alloc_resource_any(dev, type, rid, flags) \
176 bus_alloc_resource(dev, type, rid, 0ul, ~0ul, 1, flags)
179 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
180 #define DRM_CURPROC curthread
181 #define DRM_STRUCTPROC struct thread
182 #define DRM_SPINTYPE struct mtx
183 #define DRM_SPININIT(l,name) mtx_init(&l, name, NULL, MTX_DEF)
184 #define DRM_SPINUNINIT(l) mtx_destroy(&l)
185 #define DRM_SPINLOCK(l) mtx_lock(l)
186 #define DRM_SPINUNLOCK(u) mtx_unlock(u);
187 #define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED)
188 #define DRM_CURRENTPID curthread->td_proc->p_pid
189 #define DRM_LOCK() mtx_lock(&dev->dev_lock)
190 #define DRM_UNLOCK() mtx_unlock(&dev->dev_lock)
191 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
192 #else /* __FreeBSD__ && __FreeBSD_version >= 500000 */
193 #define DRM_CURPROC curproc
194 #define DRM_STRUCTPROC struct proc
195 #define DRM_SPINTYPE struct simplelock
196 #define DRM_SPININIT(l,name)
197 #define DRM_SPINUNINIT(l)
198 #define DRM_SPINLOCK(l)
199 #define DRM_SPINUNLOCK(u)
200 #define DRM_SPINLOCK_ASSERT(l)
201 #define DRM_CURRENTPID curproc->p_pid
204 #define DRM_SYSCTL_HANDLER_ARGS SYSCTL_HANDLER_ARGS
205 #define spldrm() spltty()
206 #endif /* __NetBSD__ || __OpenBSD__ */
208 /* Currently our DRMFILE (filp) is a void * which is actually the pid
209 * of the current process. It should be a per-open unique pointer, but
210 * code for that is not yet written */
211 #define DRMFILE void *
212 #define DRM_IRQ_ARGS void *arg
213 typedef void irqreturn_t;
214 #define IRQ_HANDLED /* nothing */
215 #define IRQ_NONE /* nothing */
217 #if defined(__FreeBSD__)
219 drm_device_t *dev = kdev->si_drv1
220 #define DRM_IOCTL_ARGS struct cdev *kdev, u_long cmd, caddr_t data, \
221 int flags, DRM_STRUCTPROC *p, DRMFILE filp
223 #define PAGE_ALIGN(addr) round_page(addr)
224 #define DRM_SUSER(p) suser(p)
225 #define DRM_AGP_FIND_DEVICE() agp_find_device()
226 #define DRM_MTRR_WC MDF_WRITECOMBINE
227 #define jiffies ticks
229 #else /* __FreeBSD__ */
231 #if defined(__NetBSD__)
233 drm_device_t *dev = device_lookup(&drm_cd, minor(kdev))
234 #elif defined(__OpenBSD__)
236 drm_device_t *dev = (device_lookup(&drm_cd, \
237 minor(kdev)))->dv_cfdata->cf_driver->cd_devs[minor(kdev)]
238 #endif /* __OpenBSD__ */
239 #define DRM_IOCTL_ARGS dev_t kdev, u_long cmd, caddr_t data, \
240 int flags, DRM_STRUCTPROC *p, DRMFILE filp
242 #define CDEV_MAJOR 34
243 #define PAGE_ALIGN(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK)
244 #define DRM_SUSER(p) suser(p->p_ucred, &p->p_acflag)
245 #define DRM_AGP_FIND_DEVICE() agp_find_device(0)
246 #define DRM_MTRR_WC MTRR_TYPE_WC
247 #define jiffies hardclock_ticks
249 typedef drm_device_t *device_t;
250 extern struct cfdriver drm_cd;
251 #endif /* !__FreeBSD__ */
253 typedef unsigned long dma_addr_t;
254 typedef u_int32_t u32;
255 typedef u_int16_t u16;
258 /* DRM_READMEMORYBARRIER() prevents reordering of reads.
259 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
260 * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
262 #if defined(__i386__)
263 #define DRM_READMEMORYBARRIER() __asm __volatile( \
264 "lock; addl $0,0(%%esp)" : : : "memory");
265 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
266 #define DRM_MEMORYBARRIER() __asm __volatile( \
267 "lock; addl $0,0(%%esp)" : : : "memory");
268 #elif defined(__alpha__)
269 #define DRM_READMEMORYBARRIER() alpha_mb();
270 #define DRM_WRITEMEMORYBARRIER() alpha_wmb();
271 #define DRM_MEMORYBARRIER() alpha_mb();
272 #elif defined(__amd64__)
273 #define DRM_READMEMORYBARRIER() __asm __volatile( \
274 "lock; addl $0,0(%%rsp)" : : : "memory");
275 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
276 #define DRM_MEMORYBARRIER() __asm __volatile( \
277 "lock; addl $0,0(%%rsp)" : : : "memory");
281 #define DRM_READ8(map, offset) \
282 *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset))
283 #define DRM_READ16(map, offset) \
284 *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset))
285 #define DRM_READ32(map, offset) \
286 *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset))
287 #define DRM_WRITE8(map, offset, val) \
288 *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset)) = val
289 #define DRM_WRITE16(map, offset, val) \
290 *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset)) = val
291 #define DRM_WRITE32(map, offset, val) \
292 *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset)) = val
294 #define DRM_VERIFYAREA_READ( uaddr, size ) \
295 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
297 #else /* __FreeBSD__ */
299 typedef vaddr_t vm_offset_t;
301 #define DRM_READ8(map, offset) \
302 bus_space_read_1( (map)->bst, (map)->bsh, (offset))
303 #define DRM_READ16(map, offset) \
304 bus_space_read_2( (map)->bst, (map)->bsh, (offset))
305 #define DRM_READ32(map, offset) \
306 bus_space_read_4( (map)->bst, (map)->bsh, (offset))
307 #define DRM_WRITE8(map, offset, val) \
308 bus_space_write_1((map)->bst, (map)->bsh, (offset), (val))
309 #define DRM_WRITE16(map, offset, val) \
310 bus_space_write_2((map)->bst, (map)->bsh, (offset), (val))
311 #define DRM_WRITE32(map, offset, val) \
312 bus_space_write_4((map)->bst, (map)->bsh, (offset), (val))
314 #define DRM_VERIFYAREA_READ( uaddr, size ) \
315 (!uvm_useracc((caddr_t)uaddr, size, VM_PROT_READ))
316 #endif /* !__FreeBSD__ */
318 #define DRM_COPY_TO_USER_IOCTL(user, kern, size) \
319 if ( IOCPARM_LEN(cmd) != size) \
322 #define DRM_COPY_FROM_USER_IOCTL(kern, user, size) \
323 if ( IOCPARM_LEN(cmd) != size) \
326 #define DRM_COPY_TO_USER(user, kern, size) \
327 copyout(kern, user, size)
328 #define DRM_COPY_FROM_USER(kern, user, size) \
329 copyin(user, kern, size)
330 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
331 copyin(arg2, arg1, arg3)
332 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
333 copyout(arg2, arg1, arg3)
334 #if __FreeBSD_version > 500000
335 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
336 ((val) = fuword32(uaddr), 0)
338 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
339 ((val) = fuword(uaddr), 0)
342 #define cpu_to_le32(x) htole32(x)
343 #define le32_to_cpu(x) le32toh(x)
347 #define DRM_UDELAY(udelay) DELAY(udelay)
348 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
350 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
351 (_map) = (_dev)->context_sareas[_ctx]; \
354 #define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) \
356 if (_filp != (DRMFILE)(intptr_t)DRM_CURRENTPID) { \
357 DRM_ERROR("filp doesn't match curproc\n"); \
360 _priv = drm_find_file_by_proc(dev, DRM_CURPROC); \
361 if (_priv == NULL) { \
362 DRM_ERROR("can't find authenticator\n"); \
367 #define LOCK_TEST_WITH_RETURN(dev, filp) \
369 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
370 dev->lock.filp != filp) { \
371 DRM_ERROR("%s called without lock held\n", \
377 #define DRM_GETSAREA() \
379 drm_local_map_t *map; \
380 DRM_SPINLOCK_ASSERT(&dev->dev_lock); \
381 TAILQ_FOREACH(map, &dev->maplist, link) { \
382 if (map->type == _DRM_SHM && \
383 map->flags & _DRM_CONTAINS_LOCK) { \
384 dev_priv->sarea = map; \
390 #if defined(__FreeBSD__) && __FreeBSD_version > 500000
391 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
392 for ( ret = 0 ; !ret && !(condition) ; ) { \
394 mtx_lock(&dev->irq_lock); \
396 ret = msleep(&(queue), &dev->irq_lock, \
397 PZERO | PCATCH, "drmwtq", (timeout)); \
398 mtx_unlock(&dev->irq_lock); \
402 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
403 for ( ret = 0 ; !ret && !(condition) ; ) { \
406 ret = tsleep( &(queue), PZERO | PCATCH, \
407 "drmwtq", (timeout) ); \
412 #define DRM_ERROR(fmt, arg...) \
413 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
414 DRM_CURRENTPID, __func__ , ## arg)
416 #define DRM_INFO(fmt, arg...) printf("info: [" DRM_NAME "] " fmt , ## arg)
418 #define DRM_DEBUG(fmt, arg...) do { \
419 if (drm_debug_flag) \
420 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
421 __func__ , ## arg); \
424 typedef struct drm_pci_id_list
432 typedef struct drm_ioctl_desc {
433 int (*func)(DRM_IOCTL_ARGS);
438 typedef struct drm_magic_entry {
440 struct drm_file *priv;
441 struct drm_magic_entry *next;
444 typedef struct drm_magic_head {
445 struct drm_magic_entry *head;
446 struct drm_magic_entry *tail;
449 typedef struct drm_buf {
450 int idx; /* Index into master buflist */
451 int total; /* Buffer size */
452 int order; /* log-base-2(total) */
453 int used; /* Amount of buffer in use (for DMA) */
454 unsigned long offset; /* Byte offset (used internally) */
455 void *address; /* Address of buffer */
456 unsigned long bus_address; /* Bus address of buffer */
457 struct drm_buf *next; /* Kernel-only: used for free list */
458 __volatile__ int pending; /* On hardware DMA queue */
459 DRMFILE filp; /* Unique identifier of holding process */
460 int context; /* Kernel queue for this buffer */
468 } list; /* Which list we're on */
470 int dev_priv_size; /* Size of buffer private stoarge */
471 void *dev_private; /* Per-buffer private storage */
474 typedef struct drm_freelist {
475 int initialized; /* Freelist in use */
476 atomic_t count; /* Number of free buffers */
477 drm_buf_t *next; /* End pointer */
479 int low_mark; /* Low water mark */
480 int high_mark; /* High water mark */
483 typedef struct drm_buf_entry {
489 vm_offset_t *seglist;
490 dma_addr_t *seglist_bus;
492 drm_freelist_t freelist;
495 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
497 TAILQ_ENTRY(drm_file) link;
504 unsigned long ioctl_count;
508 typedef struct drm_lock_data {
509 drm_hw_lock_t *hw_lock; /* Hardware lock */
510 DRMFILE filp; /* Unique identifier of holding process (NULL is kernel)*/
511 int lock_queue; /* Queue of blocked processes */
512 unsigned long lock_time; /* Time of last lock in jiffies */
515 /* This structure, in the drm_device_t, is always initialized while the device
516 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
517 * when set marks that no further bufs may be allocated until device teardown
518 * occurs (when the last open of the device has closed). The high/low
519 * watermarks of bufs are only touched by the X Server, and thus not
520 * concurrently accessed, so no locking is needed.
522 typedef struct drm_device_dma {
523 drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
525 drm_buf_t **buflist; /* Vector of pointers info bufs */
528 unsigned long *pagelist;
529 unsigned long byte_count;
531 _DRM_DMA_USE_AGP = 0x01,
532 _DRM_DMA_USE_SG = 0x02
536 typedef struct drm_agp_mem {
538 unsigned long bound; /* address */
540 struct drm_agp_mem *prev;
541 struct drm_agp_mem *next;
544 typedef struct drm_agp_head {
546 struct agp_info info;
548 drm_agp_mem_t *memory;
554 int cant_use_aperture;
555 unsigned long page_mask;
558 typedef struct drm_sg_mem {
559 unsigned long handle;
565 typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
567 typedef struct drm_local_map {
568 unsigned long offset; /* Physical address (0 for SAREA)*/
569 unsigned long size; /* Physical size (bytes) */
570 drm_map_type_t type; /* Type of memory mapped */
571 drm_map_flags_t flags; /* Flags */
572 void *handle; /* User-space: "Handle" to pass to mmap */
573 /* Kernel-space: kernel-virtual address */
574 int mtrr; /* Boolean: MTRR used */
576 int rid; /* PCI resource ID for bus_space */
577 int kernel_owned; /* Boolean: 1 = initmapped, 0 = addmapped */
578 struct resource *bsr;
580 bus_space_handle_t bsh;
581 TAILQ_ENTRY(drm_local_map) link;
584 TAILQ_HEAD(drm_vbl_sig_list, drm_vbl_sig);
585 typedef struct drm_vbl_sig {
586 TAILQ_ENTRY(drm_vbl_sig) link;
587 unsigned int sequence;
593 * DRM device functions structure
596 #if defined(__NetBSD__) || defined(__OpenBSD__)
597 struct device device; /* softc is an extension of struct device */
600 /* Beginning of driver-config section */
601 int (*preinit)(struct drm_device *, unsigned long flags);
602 int (*postinit)(struct drm_device *, unsigned long flags);
603 void (*prerelease)(struct drm_device *, void *filp);
604 void (*pretakedown)(struct drm_device *);
605 int (*postcleanup)(struct drm_device *);
606 int (*presetup)(struct drm_device *);
607 int (*postsetup)(struct drm_device *);
608 int (*open_helper)(struct drm_device *, drm_file_t *);
609 void (*free_filp_priv)(struct drm_device *, drm_file_t *);
610 void (*release)(struct drm_device *, void *filp);
611 int (*dma_ioctl)(DRM_IOCTL_ARGS);
612 void (*dma_ready)(struct drm_device *);
613 int (*dma_quiescent)(struct drm_device *);
614 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
615 drm_lock_flags_t flags);
616 int (*dma_flush_unblock)(struct drm_device *, int context,
617 drm_lock_flags_t flags);
618 int (*context_ctor)(struct drm_device *dev, int context);
619 int (*context_dtor)(struct drm_device *dev, int context);
620 int (*kernel_context_switch)(struct drm_device *dev, int old,
622 int (*kernel_context_switch_unlock)(struct drm_device *dev);
623 void (*irq_preinstall)(drm_device_t *dev);
624 void (*irq_postinstall)(drm_device_t *dev);
625 void (*irq_uninstall)(drm_device_t *dev);
626 void (*irq_handler)(DRM_IRQ_ARGS);
627 int (*vblank_wait)(drm_device_t *dev, unsigned int *sequence);
629 drm_ioctl_desc_t *driver_ioctls;
630 int max_driver_ioctl;
636 int driver_patchlevel;
637 const char *driver_name; /* Simple driver name */
638 const char *driver_desc; /* Longer driver name */
639 const char *driver_date; /* Date of last major changes. */
642 unsigned require_agp :1;
645 unsigned use_pci_dma :1;
646 unsigned use_dma_queue :1;
648 unsigned use_vbl_irq :1;
649 unsigned use_mtrr :1;
650 /* End of driver-config section */
652 char *unique; /* Unique identifier: e.g., busid */
653 int unique_len; /* Length of unique field */
655 device_t device; /* Device instance from newbus */
657 struct cdev *devnode; /* Device number for mknod */
658 int if_version; /* Highest interface version set */
660 int flags; /* Flags to open(2) */
663 #if defined(__FreeBSD__) && __FreeBSD_version > 500000
664 struct mtx dma_lock; /* protects dev->dma */
665 struct mtx irq_lock; /* protects irq condition checks */
666 struct mtx dev_lock; /* protects everything else */
669 int open_count; /* Outstanding files open */
670 int buf_use; /* Buffers in use -- cannot alloc */
672 /* Performance counters */
673 unsigned long counters;
674 drm_stat_type_t types[15];
678 drm_file_list_t files;
679 drm_magic_head_t magiclist[DRM_HASH_SIZE];
681 /* Linked list of mappable regions. Protected by dev_lock */
682 drm_map_list_t maplist;
684 drm_local_map_t **context_sareas;
687 drm_lock_data_t lock; /* Information on hardware lock */
689 /* DMA queues (contexts) */
690 drm_device_dma_t *dma; /* Optional pointer for DMA support */
692 /* Context support */
693 int irq; /* Interrupt used by board */
694 int irq_enabled; /* True if the irq handler is enabled */
696 int irqrid; /* Interrupt used by board */
697 struct resource *irqr; /* Resource for interrupt used by board */
698 #elif defined(__NetBSD__) || defined(__OpenBSD__)
699 struct pci_attach_args pa;
700 pci_intr_handle_t ih;
702 void *irqh; /* Handle from bus_setup_intr */
709 atomic_t context_flag; /* Context swapping flag */
710 int last_context; /* Last current context */
711 int vbl_queue; /* vbl wait channel */
712 atomic_t vbl_received;
715 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
716 #elif defined(__NetBSD__)
721 struct drm_sysctl_info *sysctl;
724 drm_sg_mem_t *sg; /* Scatter gather memory */
725 atomic_t *ctx_bitmap;
727 drm_local_map_t *agp_buffer_map;
730 extern int drm_debug_flag;
732 /* Device setup support (drm_drv.c) */
734 int drm_probe(device_t nbdev, drm_pci_id_list_t *idlist);
735 int drm_attach(device_t nbdev, drm_pci_id_list_t *idlist);
736 int drm_detach(device_t nbdev);
743 #elif defined(__NetBSD__) || defined(__OpenBSD__)
744 int drm_probe(struct pci_attach_args *pa, drm_pci_id_list_t *idlist);
745 int drm_attach(struct pci_attach_args *pa, dev_t kdev, drm_pci_id_list_t *idlist);
746 dev_type_ioctl(drm_ioctl);
747 dev_type_open(drm_open);
748 dev_type_close(drm_close);
749 dev_type_read(drm_read);
750 dev_type_poll(drm_poll);
751 dev_type_mmap(drm_mmap);
754 /* File operations helpers (drm_fops.c) */
756 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
757 DRM_STRUCTPROC *p, drm_device_t *dev);
758 extern drm_file_t *drm_find_file_by_proc(drm_device_t *dev,
760 #elif defined(__NetBSD__) || defined(__OpenBSD__)
761 extern int drm_open_helper(dev_t kdev, int flags, int fmt,
762 DRM_STRUCTPROC *p, drm_device_t *dev);
763 extern drm_file_t *drm_find_file_by_proc(drm_device_t *dev,
765 #endif /* __NetBSD__ || __OpenBSD__ */
767 /* Memory management support (drm_memory.c) */
768 void drm_mem_init(void);
769 void drm_mem_uninit(void);
770 void *drm_alloc(size_t size, int area);
771 void *drm_calloc(size_t nmemb, size_t size, int area);
772 void *drm_realloc(void *oldpt, size_t oldsize, size_t size,
774 void drm_free(void *pt, size_t size, int area);
775 void *drm_ioremap(drm_device_t *dev, drm_local_map_t *map);
776 void drm_ioremapfree(drm_local_map_t *map);
777 int drm_mtrr_add(unsigned long offset, size_t size, int flags);
778 int drm_mtrr_del(unsigned long offset, size_t size, int flags);
780 int drm_context_switch(drm_device_t *dev, int old, int new);
781 int drm_context_switch_complete(drm_device_t *dev, int new);
783 int drm_ctxbitmap_init(drm_device_t *dev);
784 void drm_ctxbitmap_cleanup(drm_device_t *dev);
785 void drm_ctxbitmap_free(drm_device_t *dev, int ctx_handle);
786 int drm_ctxbitmap_next(drm_device_t *dev);
788 /* Locking IOCTL support (drm_lock.c) */
789 int drm_lock_take(__volatile__ unsigned int *lock,
790 unsigned int context);
791 int drm_lock_transfer(drm_device_t *dev,
792 __volatile__ unsigned int *lock,
793 unsigned int context);
794 int drm_lock_free(drm_device_t *dev,
795 __volatile__ unsigned int *lock,
796 unsigned int context);
798 /* Buffer management support (drm_bufs.c) */
799 unsigned long drm_get_resource_start(drm_device_t *dev, unsigned int resource);
800 unsigned long drm_get_resource_len(drm_device_t *dev, unsigned int resource);
801 int drm_initmap(drm_device_t *dev, unsigned long start, unsigned long len,
802 unsigned int resource, int type, int flags);
803 void drm_remove_map(drm_device_t *dev, drm_local_map_t *map);
804 int drm_order(unsigned long size);
806 /* DMA support (drm_dma.c) */
807 int drm_dma_setup(drm_device_t *dev);
808 void drm_dma_takedown(drm_device_t *dev);
809 void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf);
810 void drm_reclaim_buffers(drm_device_t *dev, DRMFILE filp);
812 /* IRQ support (drm_irq.c) */
813 int drm_irq_install(drm_device_t *dev);
814 int drm_irq_uninstall(drm_device_t *dev);
815 irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
816 void drm_driver_irq_preinstall(drm_device_t *dev);
817 void drm_driver_irq_postinstall(drm_device_t *dev);
818 void drm_driver_irq_uninstall(drm_device_t *dev);
819 int drm_vblank_wait(drm_device_t *dev, unsigned int *vbl_seq);
820 void drm_vbl_send_signals(drm_device_t *dev);
822 /* AGP/GART support (drm_agpsupport.c) */
823 int drm_device_is_agp(drm_device_t *dev);
824 drm_agp_head_t *drm_agp_init(void);
825 void drm_agp_uninit(void);
826 void drm_agp_do_release(void);
827 void *drm_agp_allocate_memory(size_t pages, u32 type);
828 int drm_agp_free_memory(void *handle);
829 int drm_agp_bind_memory(void *handle, off_t start);
830 int drm_agp_unbind_memory(void *handle);
832 /* Scatter Gather Support (drm_scatter.c) */
833 void drm_sg_cleanup(drm_sg_mem_t *entry);
836 /* sysctl support (drm_sysctl.h) */
837 extern int drm_sysctl_init(drm_device_t *dev);
838 extern int drm_sysctl_cleanup(drm_device_t *dev);
839 #endif /* __FreeBSD__ */
841 /* ATI PCIGART support (ati_pcigart.c) */
842 int drm_ati_pcigart_init(drm_device_t *dev, unsigned long *addr,
843 dma_addr_t *bus_addr);
844 int drm_ati_pcigart_cleanup(drm_device_t *dev, unsigned long addr,
845 dma_addr_t bus_addr);
847 /* Locking IOCTL support (drm_drv.c) */
848 int drm_lock(DRM_IOCTL_ARGS);
849 int drm_unlock(DRM_IOCTL_ARGS);
850 int drm_version(DRM_IOCTL_ARGS);
851 int drm_setversion(DRM_IOCTL_ARGS);
853 /* Misc. IOCTL support (drm_ioctl.c) */
854 int drm_irq_by_busid(DRM_IOCTL_ARGS);
855 int drm_getunique(DRM_IOCTL_ARGS);
856 int drm_setunique(DRM_IOCTL_ARGS);
857 int drm_getmap(DRM_IOCTL_ARGS);
858 int drm_getclient(DRM_IOCTL_ARGS);
859 int drm_getstats(DRM_IOCTL_ARGS);
860 int drm_noop(DRM_IOCTL_ARGS);
862 /* Context IOCTL support (drm_context.c) */
863 int drm_resctx(DRM_IOCTL_ARGS);
864 int drm_addctx(DRM_IOCTL_ARGS);
865 int drm_modctx(DRM_IOCTL_ARGS);
866 int drm_getctx(DRM_IOCTL_ARGS);
867 int drm_switchctx(DRM_IOCTL_ARGS);
868 int drm_newctx(DRM_IOCTL_ARGS);
869 int drm_rmctx(DRM_IOCTL_ARGS);
870 int drm_setsareactx(DRM_IOCTL_ARGS);
871 int drm_getsareactx(DRM_IOCTL_ARGS);
873 /* Drawable IOCTL support (drm_drawable.c) */
874 int drm_adddraw(DRM_IOCTL_ARGS);
875 int drm_rmdraw(DRM_IOCTL_ARGS);
877 /* Authentication IOCTL support (drm_auth.c) */
878 int drm_getmagic(DRM_IOCTL_ARGS);
879 int drm_authmagic(DRM_IOCTL_ARGS);
881 /* Buffer management support (drm_bufs.c) */
882 int drm_addmap(DRM_IOCTL_ARGS);
883 int drm_rmmap(DRM_IOCTL_ARGS);
884 int drm_addbufs(DRM_IOCTL_ARGS);
885 int drm_infobufs(DRM_IOCTL_ARGS);
886 int drm_markbufs(DRM_IOCTL_ARGS);
887 int drm_freebufs(DRM_IOCTL_ARGS);
888 int drm_mapbufs(DRM_IOCTL_ARGS);
890 /* DMA support (drm_dma.c) */
891 int drm_dma(DRM_IOCTL_ARGS);
893 /* IRQ support (drm_irq.c) */
894 int drm_control(DRM_IOCTL_ARGS);
895 int drm_wait_vblank(DRM_IOCTL_ARGS);
897 /* AGP/GART support (drm_agpsupport.c) */
898 int drm_agp_acquire(DRM_IOCTL_ARGS);
899 int drm_agp_release(DRM_IOCTL_ARGS);
900 int drm_agp_enable(DRM_IOCTL_ARGS);
901 int drm_agp_info(DRM_IOCTL_ARGS);
902 int drm_agp_alloc(DRM_IOCTL_ARGS);
903 int drm_agp_free(DRM_IOCTL_ARGS);
904 int drm_agp_unbind(DRM_IOCTL_ARGS);
905 int drm_agp_bind(DRM_IOCTL_ARGS);
907 /* Scatter Gather Support (drm_scatter.c) */
908 int drm_sg_alloc(DRM_IOCTL_ARGS);
909 int drm_sg_free(DRM_IOCTL_ARGS);
911 /* consistent PCI memory functions (drm_pci.c) */
912 void *drm_pci_alloc(drm_device_t *dev, size_t size, size_t align,
913 dma_addr_t maxaddr, dma_addr_t *busaddr);
914 void drm_pci_free(drm_device_t *dev, size_t size, void *vaddr,
917 /* Inline replacements for DRM_IOREMAP macros */
918 static __inline__ void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
920 map->handle = drm_ioremap(dev, map);
922 static __inline__ void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
924 if ( map->handle && map->size )
925 drm_ioremapfree(map);
928 static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev, unsigned long offset)
930 drm_local_map_t *map;
932 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
933 TAILQ_FOREACH(map, &dev->maplist, link) {
934 if (map->offset == offset)
940 static __inline__ void drm_core_dropmap(struct drm_map *map)
944 #endif /* __KERNEL__ */
945 #endif /* _DRM_P_H_ */