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>
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
40 #if defined(_KERNEL) || defined(__KERNEL__)
42 typedef struct drm_device drm_device_t;
43 typedef struct drm_file drm_file_t;
45 #include <sys/param.h>
46 #include <sys/queue.h>
47 #include <sys/malloc.h>
48 #include <sys/kernel.h>
49 #include <sys/module.h>
50 #include <sys/systm.h>
55 #include <sys/fcntl.h>
57 #include <sys/filio.h>
58 #include <sys/sysctl.h>
60 #include <sys/signalvar.h>
64 #include <vm/vm_extern.h>
65 #include <vm/vm_map.h>
66 #include <vm/vm_param.h>
67 #include <machine/param.h>
68 #include <machine/pmap.h>
69 #include <machine/bus.h>
70 #include <machine/resource.h>
71 #include <machine/sysarch.h>
72 #include <sys/endian.h>
74 #if defined(__FreeBSD__)
76 #include <sys/memrange.h>
77 #include <pci/agpvar.h>
78 #include <sys/agpio.h>
79 #if __FreeBSD_version >= 500000
80 #include <sys/mutex.h>
81 #include <dev/pci/pcivar.h>
82 #include <sys/selinfo.h>
83 #else /* __FreeBSD_version >= 500000 */
84 #include <pci/pcivar.h>
85 #include <sys/select.h>
86 #endif /* __FreeBSD_version < 500000 */
87 #elif defined(__NetBSD__)
88 #include <machine/mtrr.h>
89 #include <sys/vnode.h>
90 #include <sys/select.h>
91 #include <sys/device.h>
92 #include <sys/resourcevar.h>
94 #include <sys/agpio.h>
95 #include <sys/ttycom.h>
97 #include <dev/pci/pcireg.h>
98 #include <dev/pci/pcivar.h>
99 #include <dev/pci/agpvar.h>
100 #elif defined(__OpenBSD__)
106 #include "dev/drm/drm.h"
107 #include "dev/drm/drm_linux_list.h"
108 #include "dev/drm/drm_atomic.h"
114 #define DRM_DEBUG_DEFAULT_ON 1
115 #endif /* DRM_DEBUG */
118 #if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__)
119 #include <sys/file.h>
120 #include <sys/proc.h>
121 #include <machine/../linux/linux.h>
122 #include <machine/../linux/linux_proto.h>
124 /* Either it was defined when it shouldn't be (FreeBSD amd64) or it isn't
125 * supported on this OS yet.
131 #define DRM_HASH_SIZE 16 /* Size of key hash table */
132 #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
133 #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
135 #define DRM_MEM_DMA 0
136 #define DRM_MEM_SAREA 1
137 #define DRM_MEM_DRIVER 2
138 #define DRM_MEM_MAGIC 3
139 #define DRM_MEM_IOCTLS 4
140 #define DRM_MEM_MAPS 5
141 #define DRM_MEM_BUFS 6
142 #define DRM_MEM_SEGS 7
143 #define DRM_MEM_PAGES 8
144 #define DRM_MEM_FILES 9
145 #define DRM_MEM_QUEUES 10
146 #define DRM_MEM_CMDS 11
147 #define DRM_MEM_MAPPINGS 12
148 #define DRM_MEM_BUFLISTS 13
149 #define DRM_MEM_AGPLISTS 14
150 #define DRM_MEM_TOTALAGP 15
151 #define DRM_MEM_BOUNDAGP 16
152 #define DRM_MEM_CTXBITMAP 17
153 #define DRM_MEM_STUB 18
154 #define DRM_MEM_SGLISTS 19
156 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
158 /* Internal types and structures */
159 #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
160 #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
161 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
163 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
165 MALLOC_DECLARE(M_DRM);
167 #define __OS_HAS_AGP 1
169 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
170 #define DRM_DEV_UID 0
171 #define DRM_DEV_GID 0
173 #define wait_queue_head_t atomic_t
174 #define DRM_WAKEUP(w) wakeup((void *)w)
175 #define DRM_WAKEUP_INT(w) wakeup(w)
176 #define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0)
178 #if defined(__FreeBSD__) && __FreeBSD_version < 502109
179 #define bus_alloc_resource_any(dev, type, rid, flags) \
180 bus_alloc_resource(dev, type, rid, 0ul, ~0ul, 1, flags)
183 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
184 #define DRM_CURPROC curthread
185 #define DRM_STRUCTPROC struct thread
186 #define DRM_SPINTYPE struct mtx
187 #define DRM_SPININIT(l,name) mtx_init(&l, name, NULL, MTX_DEF)
188 #define DRM_SPINUNINIT(l) mtx_destroy(&l)
189 #define DRM_SPINLOCK(l) mtx_lock(l)
190 #define DRM_SPINUNLOCK(u) mtx_unlock(u);
191 #define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED)
192 #define DRM_CURRENTPID curthread->td_proc->p_pid
193 #define DRM_LOCK() mtx_lock(&dev->dev_lock)
194 #define DRM_UNLOCK() mtx_unlock(&dev->dev_lock)
195 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
196 #else /* __FreeBSD__ && __FreeBSD_version >= 500000 */
197 #define DRM_CURPROC curproc
198 #define DRM_STRUCTPROC struct proc
199 #define DRM_SPINTYPE struct simplelock
200 #define DRM_SPININIT(l,name)
201 #define DRM_SPINUNINIT(l)
202 #define DRM_SPINLOCK(l)
203 #define DRM_SPINUNLOCK(u)
204 #define DRM_SPINLOCK_ASSERT(l)
205 #define DRM_CURRENTPID curproc->p_pid
208 #define DRM_SYSCTL_HANDLER_ARGS SYSCTL_HANDLER_ARGS
209 #define spldrm() spltty()
210 #endif /* __NetBSD__ || __OpenBSD__ */
212 /* Currently our DRMFILE (filp) is a void * which is actually the pid
213 * of the current process. It should be a per-open unique pointer, but
214 * code for that is not yet written */
215 #define DRMFILE void *
216 #define DRM_IRQ_ARGS void *arg
217 typedef void irqreturn_t;
218 #define IRQ_HANDLED /* nothing */
219 #define IRQ_NONE /* nothing */
226 #define DRM_AGP_MEM struct agp_memory_info
228 #if defined(__FreeBSD__)
230 drm_device_t *dev = kdev->si_drv1
231 #define DRM_IOCTL_ARGS struct cdev *kdev, u_long cmd, caddr_t data, \
232 int flags, DRM_STRUCTPROC *p, DRMFILE filp
234 #define PAGE_ALIGN(addr) round_page(addr)
235 /* DRM_SUSER returns true if the user is superuser */
236 #define DRM_SUSER(p) (suser(p) == 0)
237 #define DRM_AGP_FIND_DEVICE() agp_find_device()
238 #define DRM_MTRR_WC MDF_WRITECOMBINE
239 #define jiffies ticks
241 #else /* __FreeBSD__ */
243 #if defined(__NetBSD__)
245 drm_device_t *dev = device_lookup(&drm_cd, minor(kdev))
246 #elif defined(__OpenBSD__)
248 drm_device_t *dev = (device_lookup(&drm_cd, \
249 minor(kdev)))->dv_cfdata->cf_driver->cd_devs[minor(kdev)]
250 #endif /* __OpenBSD__ */
251 #define DRM_IOCTL_ARGS dev_t kdev, u_long cmd, caddr_t data, \
252 int flags, DRM_STRUCTPROC *p, DRMFILE filp
254 #define CDEV_MAJOR 34
255 #define PAGE_ALIGN(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK)
256 /* DRM_SUSER returns true if the user is superuser */
257 #define DRM_SUSER(p) (suser(p->p_ucred, &p->p_acflag) == 0)
258 #define DRM_AGP_FIND_DEVICE() agp_find_device(0)
259 #define DRM_MTRR_WC MTRR_TYPE_WC
260 #define jiffies hardclock_ticks
262 typedef drm_device_t *device_t;
263 extern struct cfdriver drm_cd;
264 #endif /* !__FreeBSD__ */
266 /* Capabilities taken from src/sys/dev/pci/pcireg.h. */
268 #define PCIY_AGP 0x02
272 #define PCIY_EXPRESS 0x10
275 typedef unsigned long dma_addr_t;
276 typedef u_int64_t u64;
277 typedef u_int32_t u32;
278 typedef u_int16_t u16;
281 /* DRM_READMEMORYBARRIER() prevents reordering of reads.
282 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
283 * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
285 #if defined(__i386__)
286 #define DRM_READMEMORYBARRIER() __asm __volatile( \
287 "lock; addl $0,0(%%esp)" : : : "memory");
288 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
289 #define DRM_MEMORYBARRIER() __asm __volatile( \
290 "lock; addl $0,0(%%esp)" : : : "memory");
291 #elif defined(__alpha__)
292 #define DRM_READMEMORYBARRIER() alpha_mb();
293 #define DRM_WRITEMEMORYBARRIER() alpha_wmb();
294 #define DRM_MEMORYBARRIER() alpha_mb();
295 #elif defined(__amd64__)
296 #define DRM_READMEMORYBARRIER() __asm __volatile( \
297 "lock; addl $0,0(%%rsp)" : : : "memory");
298 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
299 #define DRM_MEMORYBARRIER() __asm __volatile( \
300 "lock; addl $0,0(%%rsp)" : : : "memory");
304 #define DRM_READ8(map, offset) \
305 *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset))
306 #define DRM_READ16(map, offset) \
307 *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset))
308 #define DRM_READ32(map, offset) \
309 *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset))
310 #define DRM_WRITE8(map, offset, val) \
311 *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset)) = val
312 #define DRM_WRITE16(map, offset, val) \
313 *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset)) = val
314 #define DRM_WRITE32(map, offset, val) \
315 *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset)) = val
317 #define DRM_VERIFYAREA_READ( uaddr, size ) \
318 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
320 #else /* __FreeBSD__ */
322 typedef vaddr_t vm_offset_t;
324 #define DRM_READ8(map, offset) \
325 bus_space_read_1( (map)->bst, (map)->bsh, (offset))
326 #define DRM_READ16(map, offset) \
327 bus_space_read_2( (map)->bst, (map)->bsh, (offset))
328 #define DRM_READ32(map, offset) \
329 bus_space_read_4( (map)->bst, (map)->bsh, (offset))
330 #define DRM_WRITE8(map, offset, val) \
331 bus_space_write_1((map)->bst, (map)->bsh, (offset), (val))
332 #define DRM_WRITE16(map, offset, val) \
333 bus_space_write_2((map)->bst, (map)->bsh, (offset), (val))
334 #define DRM_WRITE32(map, offset, val) \
335 bus_space_write_4((map)->bst, (map)->bsh, (offset), (val))
337 #define DRM_VERIFYAREA_READ( uaddr, size ) \
338 (!uvm_useracc((caddr_t)uaddr, size, VM_PROT_READ))
339 #endif /* !__FreeBSD__ */
341 #define DRM_COPY_TO_USER_IOCTL(user, kern, size) \
342 if ( IOCPARM_LEN(cmd) != size) \
345 #define DRM_COPY_FROM_USER_IOCTL(kern, user, size) \
346 if ( IOCPARM_LEN(cmd) != size) \
349 #define DRM_COPY_TO_USER(user, kern, size) \
350 copyout(kern, user, size)
351 #define DRM_COPY_FROM_USER(kern, user, size) \
352 copyin(user, kern, size)
353 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
354 copyin(arg2, arg1, arg3)
355 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
356 copyout(arg2, arg1, arg3)
357 #if __FreeBSD_version > 500000
358 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
359 ((val) = fuword32(uaddr), 0)
361 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
362 ((val) = fuword(uaddr), 0)
365 #define cpu_to_le32(x) htole32(x)
366 #define le32_to_cpu(x) le32toh(x)
370 #define DRM_UDELAY(udelay) DELAY(udelay)
371 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
373 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
374 (_map) = (_dev)->context_sareas[_ctx]; \
377 #define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) \
379 if (_filp != (DRMFILE)(intptr_t)DRM_CURRENTPID) { \
380 DRM_ERROR("filp doesn't match curproc\n"); \
383 _priv = drm_find_file_by_proc(dev, DRM_CURPROC); \
384 if (_priv == NULL) { \
385 DRM_ERROR("can't find authenticator\n"); \
390 #define LOCK_TEST_WITH_RETURN(dev, filp) \
392 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
393 dev->lock.filp != filp) { \
394 DRM_ERROR("%s called without lock held\n", \
400 #define DRM_GETSAREA() \
402 drm_local_map_t *map; \
403 DRM_SPINLOCK_ASSERT(&dev->dev_lock); \
404 TAILQ_FOREACH(map, &dev->maplist, link) { \
405 if (map->type == _DRM_SHM && \
406 map->flags & _DRM_CONTAINS_LOCK) { \
407 dev_priv->sarea = map; \
413 #if defined(__FreeBSD__) && __FreeBSD_version > 500000
414 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
415 for ( ret = 0 ; !ret && !(condition) ; ) { \
417 mtx_lock(&dev->irq_lock); \
419 ret = msleep(&(queue), &dev->irq_lock, \
420 PZERO | PCATCH, "drmwtq", (timeout)); \
421 mtx_unlock(&dev->irq_lock); \
425 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
426 for ( ret = 0 ; !ret && !(condition) ; ) { \
429 ret = tsleep( &(queue), PZERO | PCATCH, \
430 "drmwtq", (timeout) ); \
435 #define DRM_ERROR(fmt, arg...) \
436 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
437 DRM_CURRENTPID, __func__ , ## arg)
439 #define DRM_INFO(fmt, arg...) printf("info: [" DRM_NAME "] " fmt , ## arg)
441 #define DRM_DEBUG(fmt, arg...) do { \
442 if (drm_debug_flag) \
443 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
444 __func__ , ## arg); \
447 typedef struct drm_pci_id_list
456 #define DRM_MASTER 0x2
457 #define DRM_ROOT_ONLY 0x4
458 typedef struct drm_ioctl_desc {
459 int (*func)(DRM_IOCTL_ARGS);
463 typedef struct drm_magic_entry {
465 struct drm_file *priv;
466 struct drm_magic_entry *next;
469 typedef struct drm_magic_head {
470 struct drm_magic_entry *head;
471 struct drm_magic_entry *tail;
474 typedef struct drm_buf {
475 int idx; /* Index into master buflist */
476 int total; /* Buffer size */
477 int order; /* log-base-2(total) */
478 int used; /* Amount of buffer in use (for DMA) */
479 unsigned long offset; /* Byte offset (used internally) */
480 void *address; /* Address of buffer */
481 unsigned long bus_address; /* Bus address of buffer */
482 struct drm_buf *next; /* Kernel-only: used for free list */
483 __volatile__ int pending; /* On hardware DMA queue */
484 DRMFILE filp; /* Unique identifier of holding process */
485 int context; /* Kernel queue for this buffer */
493 } list; /* Which list we're on */
495 int dev_priv_size; /* Size of buffer private stoarge */
496 void *dev_private; /* Per-buffer private storage */
499 typedef struct drm_freelist {
500 int initialized; /* Freelist in use */
501 atomic_t count; /* Number of free buffers */
502 drm_buf_t *next; /* End pointer */
504 int low_mark; /* Low water mark */
505 int high_mark; /* High water mark */
508 typedef struct drm_dma_handle {
511 #if defined(__FreeBSD__)
514 #elif defined(__NetBSD__)
515 bus_dma_segment_t seg;
519 typedef struct drm_buf_entry {
524 drm_dma_handle_t **seglist;
527 drm_freelist_t freelist;
530 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
532 TAILQ_ENTRY(drm_file) link;
540 unsigned long ioctl_count;
544 typedef struct drm_lock_data {
545 drm_hw_lock_t *hw_lock; /* Hardware lock */
546 DRMFILE filp; /* Unique identifier of holding process (NULL is kernel)*/
547 int lock_queue; /* Queue of blocked processes */
548 unsigned long lock_time; /* Time of last lock in jiffies */
551 /* This structure, in the drm_device_t, is always initialized while the device
552 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
553 * when set marks that no further bufs may be allocated until device teardown
554 * occurs (when the last open of the device has closed). The high/low
555 * watermarks of bufs are only touched by the X Server, and thus not
556 * concurrently accessed, so no locking is needed.
558 typedef struct drm_device_dma {
559 drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
561 drm_buf_t **buflist; /* Vector of pointers info bufs */
564 unsigned long *pagelist;
565 unsigned long byte_count;
567 _DRM_DMA_USE_AGP = 0x01,
568 _DRM_DMA_USE_SG = 0x02
572 typedef struct drm_agp_mem {
574 unsigned long bound; /* address */
576 struct drm_agp_mem *prev;
577 struct drm_agp_mem *next;
580 typedef struct drm_agp_head {
582 struct agp_info info;
584 drm_agp_mem_t *memory;
590 int cant_use_aperture;
591 unsigned long page_mask;
594 typedef struct drm_sg_mem {
595 unsigned long handle;
599 drm_dma_handle_t *dmah; /* Handle to PCI memory for ATI PCIGART table */
602 typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
604 typedef struct drm_local_map {
605 unsigned long offset; /* Physical address (0 for SAREA)*/
606 unsigned long size; /* Physical size (bytes) */
607 drm_map_type_t type; /* Type of memory mapped */
608 drm_map_flags_t flags; /* Flags */
609 void *handle; /* User-space: "Handle" to pass to mmap */
610 /* Kernel-space: kernel-virtual address */
611 int mtrr; /* Boolean: MTRR used */
613 int rid; /* PCI resource ID for bus_space */
614 struct resource *bsr;
616 bus_space_handle_t bsh;
617 drm_dma_handle_t *dmah;
618 TAILQ_ENTRY(drm_local_map) link;
621 TAILQ_HEAD(drm_vbl_sig_list, drm_vbl_sig);
622 typedef struct drm_vbl_sig {
623 TAILQ_ENTRY(drm_vbl_sig) link;
624 unsigned int sequence;
629 /* location of GART table */
630 #define DRM_ATI_GART_MAIN 1
631 #define DRM_ATI_GART_FB 2
633 typedef struct ati_pcigart_info {
634 int gart_table_location;
638 drm_local_map_t mapping;
639 } drm_ati_pcigart_info;
641 struct drm_driver_info {
642 int (*load)(struct drm_device *, unsigned long flags);
643 int (*firstopen)(struct drm_device *);
644 int (*open)(struct drm_device *, drm_file_t *);
645 void (*preclose)(struct drm_device *, void *filp);
646 void (*postclose)(struct drm_device *, drm_file_t *);
647 void (*lastclose)(struct drm_device *);
648 int (*unload)(struct drm_device *);
649 void (*reclaim_buffers_locked)(struct drm_device *, void *filp);
650 int (*dma_ioctl)(DRM_IOCTL_ARGS);
651 void (*dma_ready)(struct drm_device *);
652 int (*dma_quiescent)(struct drm_device *);
653 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
654 drm_lock_flags_t flags);
655 int (*dma_flush_unblock)(struct drm_device *, int context,
656 drm_lock_flags_t flags);
657 int (*context_ctor)(struct drm_device *dev, int context);
658 int (*context_dtor)(struct drm_device *dev, int context);
659 int (*kernel_context_switch)(struct drm_device *dev, int old,
661 int (*kernel_context_switch_unlock)(struct drm_device *dev);
662 void (*irq_preinstall)(drm_device_t *dev);
663 void (*irq_postinstall)(drm_device_t *dev);
664 void (*irq_uninstall)(drm_device_t *dev);
665 void (*irq_handler)(DRM_IRQ_ARGS);
666 int (*vblank_wait)(drm_device_t *dev, unsigned int *sequence);
668 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
671 * Called by \c drm_device_is_agp. Typically used to determine if a
672 * card is really attached to AGP or not.
674 * \param dev DRM device handle
677 * One of three values is returned depending on whether or not the
678 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
679 * (return of 1), or may or may not be AGP (return of 2).
681 int (*device_is_agp) (struct drm_device * dev);
683 drm_ioctl_desc_t *ioctls;
691 const char *name; /* Simple driver name */
692 const char *desc; /* Longer driver name */
693 const char *date; /* Date of last major changes. */
696 unsigned require_agp :1;
699 unsigned use_pci_dma :1;
700 unsigned use_dma_queue :1;
702 unsigned use_vbl_irq :1;
703 unsigned use_mtrr :1;
706 /* Length for the array of resource pointers for drm_get_resource_*. */
707 #define DRM_MAX_PCI_RESOURCE 3
710 * DRM device functions structure
713 #if defined(__NetBSD__) || defined(__OpenBSD__)
714 struct device device; /* softc is an extension of struct device */
717 struct drm_driver_info driver;
718 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
720 u_int16_t pci_device; /* PCI device id */
721 u_int16_t pci_vendor; /* PCI vendor id */
723 char *unique; /* Unique identifier: e.g., busid */
724 int unique_len; /* Length of unique field */
726 device_t device; /* Device instance from newbus */
728 struct cdev *devnode; /* Device number for mknod */
729 int if_version; /* Highest interface version set */
731 int flags; /* Flags to open(2) */
734 #if defined(__FreeBSD__) && __FreeBSD_version > 500000
735 struct mtx dma_lock; /* protects dev->dma */
736 struct mtx irq_lock; /* protects irq condition checks */
737 struct mtx dev_lock; /* protects everything else */
740 int open_count; /* Outstanding files open */
741 int buf_use; /* Buffers in use -- cannot alloc */
743 /* Performance counters */
744 unsigned long counters;
745 drm_stat_type_t types[15];
749 drm_file_list_t files;
750 drm_magic_head_t magiclist[DRM_HASH_SIZE];
752 /* Linked list of mappable regions. Protected by dev_lock */
753 drm_map_list_t maplist;
755 drm_local_map_t **context_sareas;
758 drm_lock_data_t lock; /* Information on hardware lock */
760 /* DMA queues (contexts) */
761 drm_device_dma_t *dma; /* Optional pointer for DMA support */
763 /* Context support */
764 int irq; /* Interrupt used by board */
765 int irq_enabled; /* True if the irq handler is enabled */
767 int irqrid; /* Interrupt used by board */
768 struct resource *irqr; /* Resource for interrupt used by board */
769 #elif defined(__NetBSD__) || defined(__OpenBSD__)
770 struct pci_attach_args pa;
772 void *irqh; /* Handle from bus_setup_intr */
774 /* Storage of resource pointers for drm_get_resource_* */
775 struct resource *pcir[DRM_MAX_PCI_RESOURCE];
776 int pcirid[DRM_MAX_PCI_RESOURCE];
783 atomic_t context_flag; /* Context swapping flag */
784 int last_context; /* Last current context */
785 int vbl_queue; /* vbl wait channel */
786 atomic_t vbl_received;
789 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
790 #elif defined(__NetBSD__)
795 struct drm_sysctl_info *sysctl;
798 drm_sg_mem_t *sg; /* Scatter gather memory */
799 atomic_t *ctx_bitmap;
801 unsigned int agp_buffer_token;
802 drm_local_map_t *agp_buffer_map;
805 extern int drm_debug_flag;
807 /* Device setup support (drm_drv.c) */
809 int drm_probe(device_t nbdev, drm_pci_id_list_t *idlist);
810 int drm_attach(device_t nbdev, drm_pci_id_list_t *idlist);
811 int drm_detach(device_t nbdev);
818 #elif defined(__NetBSD__) || defined(__OpenBSD__)
819 int drm_probe(struct pci_attach_args *pa, drm_pci_id_list_t *idlist);
820 int drm_attach(struct pci_attach_args *pa, dev_t kdev, drm_pci_id_list_t *idlist);
821 dev_type_ioctl(drm_ioctl);
822 dev_type_open(drm_open);
823 dev_type_close(drm_close);
824 dev_type_read(drm_read);
825 dev_type_poll(drm_poll);
826 dev_type_mmap(drm_mmap);
829 /* File operations helpers (drm_fops.c) */
831 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
832 DRM_STRUCTPROC *p, drm_device_t *dev);
833 extern drm_file_t *drm_find_file_by_proc(drm_device_t *dev,
835 #elif defined(__NetBSD__) || defined(__OpenBSD__)
836 extern int drm_open_helper(dev_t kdev, int flags, int fmt,
837 DRM_STRUCTPROC *p, drm_device_t *dev);
838 extern drm_file_t *drm_find_file_by_proc(drm_device_t *dev,
840 #endif /* __NetBSD__ || __OpenBSD__ */
842 /* Memory management support (drm_memory.c) */
843 void drm_mem_init(void);
844 void drm_mem_uninit(void);
845 void *drm_alloc(size_t size, int area);
846 void *drm_calloc(size_t nmemb, size_t size, int area);
847 void *drm_realloc(void *oldpt, size_t oldsize, size_t size,
849 void drm_free(void *pt, size_t size, int area);
850 void *drm_ioremap(drm_device_t *dev, drm_local_map_t *map);
851 void drm_ioremapfree(drm_local_map_t *map);
852 int drm_mtrr_add(unsigned long offset, size_t size, int flags);
853 int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
855 int drm_context_switch(drm_device_t *dev, int old, int new);
856 int drm_context_switch_complete(drm_device_t *dev, int new);
858 int drm_ctxbitmap_init(drm_device_t *dev);
859 void drm_ctxbitmap_cleanup(drm_device_t *dev);
860 void drm_ctxbitmap_free(drm_device_t *dev, int ctx_handle);
861 int drm_ctxbitmap_next(drm_device_t *dev);
863 /* Locking IOCTL support (drm_lock.c) */
864 int drm_lock_take(__volatile__ unsigned int *lock,
865 unsigned int context);
866 int drm_lock_transfer(drm_device_t *dev,
867 __volatile__ unsigned int *lock,
868 unsigned int context);
869 int drm_lock_free(drm_device_t *dev,
870 __volatile__ unsigned int *lock,
871 unsigned int context);
873 /* Buffer management support (drm_bufs.c) */
874 unsigned long drm_get_resource_start(drm_device_t *dev, unsigned int resource);
875 unsigned long drm_get_resource_len(drm_device_t *dev, unsigned int resource);
876 void drm_rmmap(drm_device_t *dev, drm_local_map_t *map);
877 int drm_order(unsigned long size);
878 int drm_addmap(drm_device_t * dev, unsigned long offset, unsigned long size,
879 drm_map_type_t type, drm_map_flags_t flags,
880 drm_local_map_t **map_ptr);
881 int drm_addbufs_pci(drm_device_t *dev, drm_buf_desc_t *request);
882 int drm_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request);
883 int drm_addbufs_agp(drm_device_t *dev, drm_buf_desc_t *request);
885 /* DMA support (drm_dma.c) */
886 int drm_dma_setup(drm_device_t *dev);
887 void drm_dma_takedown(drm_device_t *dev);
888 void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf);
889 void drm_reclaim_buffers(drm_device_t *dev, DRMFILE filp);
890 #define drm_core_reclaim_buffers drm_reclaim_buffers
892 /* IRQ support (drm_irq.c) */
893 int drm_irq_install(drm_device_t *dev);
894 int drm_irq_uninstall(drm_device_t *dev);
895 irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
896 void drm_driver_irq_preinstall(drm_device_t *dev);
897 void drm_driver_irq_postinstall(drm_device_t *dev);
898 void drm_driver_irq_uninstall(drm_device_t *dev);
899 int drm_vblank_wait(drm_device_t *dev, unsigned int *vbl_seq);
900 void drm_vbl_send_signals(drm_device_t *dev);
902 /* AGP/PCI Express/GART support (drm_agpsupport.c) */
903 int drm_device_is_agp(drm_device_t *dev);
904 int drm_device_is_pcie(drm_device_t *dev);
905 drm_agp_head_t *drm_agp_init(void);
906 int drm_agp_acquire(drm_device_t *dev);
907 int drm_agp_release(drm_device_t *dev);
908 int drm_agp_info(drm_device_t * dev, drm_agp_info_t *info);
909 int drm_agp_enable(drm_device_t *dev, drm_agp_mode_t mode);
910 void *drm_agp_allocate_memory(size_t pages, u32 type);
911 int drm_agp_free_memory(void *handle);
912 int drm_agp_bind_memory(void *handle, off_t start);
913 int drm_agp_unbind_memory(void *handle);
914 int drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request);
915 int drm_agp_free(drm_device_t *dev, drm_agp_buffer_t *request);
916 int drm_agp_bind(drm_device_t *dev, drm_agp_binding_t *request);
917 int drm_agp_unbind(drm_device_t *dev, drm_agp_binding_t *request);
919 /* Scatter Gather Support (drm_scatter.c) */
920 void drm_sg_cleanup(drm_sg_mem_t *entry);
923 /* sysctl support (drm_sysctl.h) */
924 extern int drm_sysctl_init(drm_device_t *dev);
925 extern int drm_sysctl_cleanup(drm_device_t *dev);
926 #endif /* __FreeBSD__ */
928 /* ATI PCIGART support (ati_pcigart.c) */
929 int drm_ati_pcigart_init(drm_device_t *dev,
930 drm_ati_pcigart_info *gart_info);
931 int drm_ati_pcigart_cleanup(drm_device_t *dev,
932 drm_ati_pcigart_info *gart_info);
934 /* Locking IOCTL support (drm_drv.c) */
935 int drm_lock(DRM_IOCTL_ARGS);
936 int drm_unlock(DRM_IOCTL_ARGS);
937 int drm_version(DRM_IOCTL_ARGS);
938 int drm_setversion(DRM_IOCTL_ARGS);
940 /* Misc. IOCTL support (drm_ioctl.c) */
941 int drm_irq_by_busid(DRM_IOCTL_ARGS);
942 int drm_getunique(DRM_IOCTL_ARGS);
943 int drm_setunique(DRM_IOCTL_ARGS);
944 int drm_getmap(DRM_IOCTL_ARGS);
945 int drm_getclient(DRM_IOCTL_ARGS);
946 int drm_getstats(DRM_IOCTL_ARGS);
947 int drm_noop(DRM_IOCTL_ARGS);
949 /* Context IOCTL support (drm_context.c) */
950 int drm_resctx(DRM_IOCTL_ARGS);
951 int drm_addctx(DRM_IOCTL_ARGS);
952 int drm_modctx(DRM_IOCTL_ARGS);
953 int drm_getctx(DRM_IOCTL_ARGS);
954 int drm_switchctx(DRM_IOCTL_ARGS);
955 int drm_newctx(DRM_IOCTL_ARGS);
956 int drm_rmctx(DRM_IOCTL_ARGS);
957 int drm_setsareactx(DRM_IOCTL_ARGS);
958 int drm_getsareactx(DRM_IOCTL_ARGS);
960 /* Drawable IOCTL support (drm_drawable.c) */
961 int drm_adddraw(DRM_IOCTL_ARGS);
962 int drm_rmdraw(DRM_IOCTL_ARGS);
964 /* Authentication IOCTL support (drm_auth.c) */
965 int drm_getmagic(DRM_IOCTL_ARGS);
966 int drm_authmagic(DRM_IOCTL_ARGS);
968 /* Buffer management support (drm_bufs.c) */
969 int drm_addmap_ioctl(DRM_IOCTL_ARGS);
970 int drm_rmmap_ioctl(DRM_IOCTL_ARGS);
971 int drm_addbufs_ioctl(DRM_IOCTL_ARGS);
972 int drm_infobufs(DRM_IOCTL_ARGS);
973 int drm_markbufs(DRM_IOCTL_ARGS);
974 int drm_freebufs(DRM_IOCTL_ARGS);
975 int drm_mapbufs(DRM_IOCTL_ARGS);
977 /* DMA support (drm_dma.c) */
978 int drm_dma(DRM_IOCTL_ARGS);
980 /* IRQ support (drm_irq.c) */
981 int drm_control(DRM_IOCTL_ARGS);
982 int drm_wait_vblank(DRM_IOCTL_ARGS);
984 /* AGP/GART support (drm_agpsupport.c) */
985 int drm_agp_acquire_ioctl(DRM_IOCTL_ARGS);
986 int drm_agp_release_ioctl(DRM_IOCTL_ARGS);
987 int drm_agp_enable_ioctl(DRM_IOCTL_ARGS);
988 int drm_agp_info_ioctl(DRM_IOCTL_ARGS);
989 int drm_agp_alloc_ioctl(DRM_IOCTL_ARGS);
990 int drm_agp_free_ioctl(DRM_IOCTL_ARGS);
991 int drm_agp_unbind_ioctl(DRM_IOCTL_ARGS);
992 int drm_agp_bind_ioctl(DRM_IOCTL_ARGS);
994 /* Scatter Gather Support (drm_scatter.c) */
995 int drm_sg_alloc(DRM_IOCTL_ARGS);
996 int drm_sg_free(DRM_IOCTL_ARGS);
998 /* consistent PCI memory functions (drm_pci.c) */
999 drm_dma_handle_t *drm_pci_alloc(drm_device_t *dev, size_t size, size_t align,
1000 dma_addr_t maxaddr);
1001 void drm_pci_free(drm_device_t *dev, drm_dma_handle_t *dmah);
1003 /* Inline replacements for DRM_IOREMAP macros */
1004 static __inline__ void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
1006 map->handle = drm_ioremap(dev, map);
1008 static __inline__ void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
1010 if ( map->handle && map->size )
1011 drm_ioremapfree(map);
1014 static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev, unsigned long offset)
1016 drm_local_map_t *map;
1018 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
1019 TAILQ_FOREACH(map, &dev->maplist, link) {
1020 if (map->offset == offset)
1026 static __inline__ void drm_core_dropmap(struct drm_map *map)
1030 #endif /* __KERNEL__ */
1031 #endif /* _DRM_P_H_ */