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__)
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>
50 #if __FreeBSD_version >= 700000
55 #include <sys/fcntl.h>
57 #include <sys/filio.h>
58 #include <sys/sysctl.h>
60 #include <sys/signalvar.h>
63 #include <sys/taskqueue.h>
66 #include <vm/vm_extern.h>
67 #include <vm/vm_map.h>
68 #include <vm/vm_param.h>
69 #include <machine/param.h>
70 #include <machine/pmap.h>
71 #include <machine/bus.h>
72 #include <machine/resource.h>
73 #include <machine/sysarch.h>
74 #include <sys/endian.h>
76 #if defined(__FreeBSD__)
78 #include <sys/memrange.h>
79 #if __FreeBSD_version >= 800004
80 #include <dev/agp/agpvar.h>
81 #else /* __FreeBSD_version >= 800004 */
82 #include <pci/agpvar.h>
83 #endif /* __FreeBSD_version >= 800004 */
84 #include <sys/agpio.h>
85 #if __FreeBSD_version >= 500000
86 #include <sys/mutex.h>
87 #include <dev/pci/pcivar.h>
88 #include <sys/selinfo.h>
89 #else /* __FreeBSD_version >= 500000 */
90 #include <pci/pcivar.h>
91 #include <sys/select.h>
92 #endif /* __FreeBSD_version < 500000 */
93 #elif defined(__NetBSD__)
94 #include <machine/mtrr.h>
95 #include <sys/vnode.h>
96 #include <sys/select.h>
97 #include <sys/device.h>
98 #include <sys/resourcevar.h>
100 #include <sys/agpio.h>
101 #include <sys/ttycom.h>
103 #include <dev/pci/pcireg.h>
104 #include <dev/pci/pcivar.h>
105 #include <dev/pci/agpvar.h>
106 #elif defined(__OpenBSD__)
113 #include "drm_linux_list.h"
114 #include "drm_atomic.h"
115 #include "drm_internal.h"
121 #define DRM_DEBUG_DEFAULT_ON 1
122 #endif /* DRM_DEBUG */
125 #if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__)
126 #include <sys/file.h>
127 #include <sys/proc.h>
128 #include <machine/../linux/linux.h>
129 #include <machine/../linux/linux_proto.h>
131 /* Either it was defined when it shouldn't be (FreeBSD amd64) or it isn't
132 * supported on this OS yet.
138 #define DRM_HASH_SIZE 16 /* Size of key hash table */
139 #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
140 #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
142 #define DRM_MEM_DMA 0
143 #define DRM_MEM_SAREA 1
144 #define DRM_MEM_DRIVER 2
145 #define DRM_MEM_MAGIC 3
146 #define DRM_MEM_IOCTLS 4
147 #define DRM_MEM_MAPS 5
148 #define DRM_MEM_BUFS 6
149 #define DRM_MEM_SEGS 7
150 #define DRM_MEM_PAGES 8
151 #define DRM_MEM_FILES 9
152 #define DRM_MEM_QUEUES 10
153 #define DRM_MEM_CMDS 11
154 #define DRM_MEM_MAPPINGS 12
155 #define DRM_MEM_BUFLISTS 13
156 #define DRM_MEM_AGPLISTS 14
157 #define DRM_MEM_TOTALAGP 15
158 #define DRM_MEM_BOUNDAGP 16
159 #define DRM_MEM_CTXBITMAP 17
160 #define DRM_MEM_STUB 18
161 #define DRM_MEM_SGLISTS 19
162 #define DRM_MEM_DRAWABLE 20
164 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
166 /* Internal types and structures */
167 #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
168 #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
169 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
171 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
173 MALLOC_DECLARE(M_DRM);
175 #define __OS_HAS_AGP 1
177 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
178 #define DRM_DEV_UID 0
179 #define DRM_DEV_GID 0
181 #define wait_queue_head_t atomic_t
182 #define DRM_WAKEUP(w) wakeup((void *)w)
183 #define DRM_WAKEUP_INT(w) wakeup(w)
184 #define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0)
186 #if defined(__FreeBSD__) && __FreeBSD_version < 502109
187 #define bus_alloc_resource_any(dev, type, rid, flags) \
188 bus_alloc_resource(dev, type, rid, 0ul, ~0ul, 1, flags)
191 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
192 #define DRM_CURPROC curthread
193 #define DRM_STRUCTPROC struct thread
194 #define DRM_SPINTYPE struct mtx
195 #define DRM_SPININIT(l,name) mtx_init(l, name, NULL, MTX_DEF)
196 #define DRM_SPINUNINIT(l) mtx_destroy(l)
197 #define DRM_SPINLOCK(l) mtx_lock(l)
198 #define DRM_SPINUNLOCK(u) mtx_unlock(u)
199 #define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \
203 #define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) mtx_unlock(u)
204 #define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED)
205 #define DRM_CURRENTPID curthread->td_proc->p_pid
206 #define DRM_LOCK() mtx_lock(&dev->dev_lock)
207 #define DRM_UNLOCK() mtx_unlock(&dev->dev_lock)
208 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
209 #else /* __FreeBSD__ && __FreeBSD_version >= 500000 */
210 #define DRM_CURPROC curproc
211 #define DRM_STRUCTPROC struct proc
212 #define DRM_SPINTYPE struct simplelock
213 #define DRM_SPININIT(l,name)
214 #define DRM_SPINUNINIT(l)
215 #define DRM_SPINLOCK(l)
216 #define DRM_SPINUNLOCK(u)
217 #define DRM_SPINLOCK_ASSERT(l)
218 #define DRM_CURRENTPID curproc->p_pid
221 #define DRM_SYSCTL_HANDLER_ARGS SYSCTL_HANDLER_ARGS
222 #define spldrm() spltty()
223 #endif /* __NetBSD__ || __OpenBSD__ */
225 #define DRM_IRQ_ARGS void *arg
226 typedef void irqreturn_t;
227 #define IRQ_HANDLED /* nothing */
228 #define IRQ_NONE /* nothing */
235 #define DRM_AGP_MEM struct agp_memory_info
237 #if defined(__FreeBSD__)
238 #define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1)
239 #elif defined(__NetBSD__)
240 #define drm_get_device_from_kdev(_kdev) device_lookup(&drm_cd, minor(_kdev))
241 #elif defined(__OpenBSD__)
242 #define drm_get_device_from_kdev(_kdev) device_lookup(&drm_cd, \
243 minor(_kdev)))->dv_cfdata->cf_driver->cd_devs[minor(_kdev)]
246 #if defined(__FreeBSD__)
247 #define PAGE_ALIGN(addr) round_page(addr)
248 /* DRM_SUSER returns true if the user is superuser */
249 #if __FreeBSD_version >= 700000
250 #define DRM_SUSER(p) (priv_check(p, PRIV_DRIVER) == 0)
252 #define DRM_SUSER(p) (suser(p) == 0)
254 #define DRM_AGP_FIND_DEVICE() agp_find_device()
255 #define DRM_MTRR_WC MDF_WRITECOMBINE
256 #define jiffies ticks
258 #else /* __FreeBSD__ */
260 #define CDEV_MAJOR 34
261 #define PAGE_ALIGN(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK)
262 /* DRM_SUSER returns true if the user is superuser */
263 #define DRM_SUSER(p) (suser(p->p_ucred, &p->p_acflag) == 0)
264 #define DRM_AGP_FIND_DEVICE() agp_find_device(0)
265 #define DRM_MTRR_WC MTRR_TYPE_WC
266 #define jiffies hardclock_ticks
268 typedef struct drm_device *device_t;
269 extern struct cfdriver drm_cd;
270 #endif /* !__FreeBSD__ */
272 /* Capabilities taken from src/sys/dev/pci/pcireg.h. */
274 #define PCIY_AGP 0x02
278 #define PCIY_EXPRESS 0x10
281 typedef unsigned long dma_addr_t;
282 typedef u_int64_t u64;
283 typedef u_int32_t u32;
284 typedef u_int16_t u16;
287 /* DRM_READMEMORYBARRIER() prevents reordering of reads.
288 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
289 * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
291 #if defined(__i386__)
292 #define DRM_READMEMORYBARRIER() __asm __volatile( \
293 "lock; addl $0,0(%%esp)" : : : "memory");
294 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
295 #define DRM_MEMORYBARRIER() __asm __volatile( \
296 "lock; addl $0,0(%%esp)" : : : "memory");
297 #elif defined(__alpha__)
298 #define DRM_READMEMORYBARRIER() alpha_mb();
299 #define DRM_WRITEMEMORYBARRIER() alpha_wmb();
300 #define DRM_MEMORYBARRIER() alpha_mb();
301 #elif defined(__amd64__)
302 #define DRM_READMEMORYBARRIER() __asm __volatile( \
303 "lock; addl $0,0(%%rsp)" : : : "memory");
304 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
305 #define DRM_MEMORYBARRIER() __asm __volatile( \
306 "lock; addl $0,0(%%rsp)" : : : "memory");
310 #define DRM_READ8(map, offset) \
311 *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset))
312 #define DRM_READ16(map, offset) \
313 *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset))
314 #define DRM_READ32(map, offset) \
315 *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset))
316 #define DRM_WRITE8(map, offset, val) \
317 *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset)) = val
318 #define DRM_WRITE16(map, offset, val) \
319 *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset)) = val
320 #define DRM_WRITE32(map, offset, val) \
321 *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset)) = val
323 #define DRM_VERIFYAREA_READ( uaddr, size ) \
324 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
326 #else /* __FreeBSD__ */
328 typedef vaddr_t vm_offset_t;
330 #define DRM_READ8(map, offset) \
331 bus_space_read_1( (map)->bst, (map)->bsh, (offset))
332 #define DRM_READ16(map, offset) \
333 bus_space_read_2( (map)->bst, (map)->bsh, (offset))
334 #define DRM_READ32(map, offset) \
335 bus_space_read_4( (map)->bst, (map)->bsh, (offset))
336 #define DRM_WRITE8(map, offset, val) \
337 bus_space_write_1((map)->bst, (map)->bsh, (offset), (val))
338 #define DRM_WRITE16(map, offset, val) \
339 bus_space_write_2((map)->bst, (map)->bsh, (offset), (val))
340 #define DRM_WRITE32(map, offset, val) \
341 bus_space_write_4((map)->bst, (map)->bsh, (offset), (val))
343 #define DRM_VERIFYAREA_READ( uaddr, size ) \
344 (!uvm_useracc((caddr_t)uaddr, size, VM_PROT_READ))
345 #endif /* !__FreeBSD__ */
347 #define DRM_COPY_TO_USER(user, kern, size) \
348 copyout(kern, user, size)
349 #define DRM_COPY_FROM_USER(kern, user, size) \
350 copyin(user, kern, size)
351 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
352 copyin(arg2, arg1, arg3)
353 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
354 copyout(arg2, arg1, arg3)
355 #if __FreeBSD_version > 500000
356 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
357 ((val) = fuword32(uaddr), 0)
359 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
360 ((val) = fuword(uaddr), 0)
363 #define cpu_to_le32(x) htole32(x)
364 #define le32_to_cpu(x) le32toh(x)
367 #define DRM_UDELAY(udelay) DELAY(udelay)
368 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
370 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
371 (_map) = (_dev)->context_sareas[_ctx]; \
374 #define LOCK_TEST_WITH_RETURN(dev, file_priv) \
376 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
377 dev->lock.file_priv != file_priv) { \
378 DRM_ERROR("%s called without lock held\n", \
384 #if defined(__FreeBSD__) && __FreeBSD_version > 500000
385 /* Returns -errno to shared code */
386 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
387 for ( ret = 0 ; !ret && !(condition) ; ) { \
389 mtx_lock(&dev->irq_lock); \
391 ret = -mtx_sleep(&(queue), &dev->irq_lock, \
392 PZERO | PCATCH, "drmwtq", (timeout)); \
393 mtx_unlock(&dev->irq_lock); \
397 /* Returns -errno to shared code */
398 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
399 for ( ret = 0 ; !ret && !(condition) ; ) { \
402 ret = -tsleep( &(queue), PZERO | PCATCH, \
403 "drmwtq", (timeout) ); \
408 #define DRM_ERROR(fmt, arg...) \
409 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
410 DRM_CURRENTPID, __func__ , ## arg)
412 #define DRM_INFO(fmt, arg...) printf("info: [" DRM_NAME "] " fmt , ## arg)
414 #define DRM_DEBUG(fmt, arg...) do { \
415 if (drm_debug_flag) \
416 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
417 __func__ , ## arg); \
420 typedef struct drm_pci_id_list
429 #define DRM_MASTER 0x2
430 #define DRM_ROOT_ONLY 0x4
431 typedef struct drm_ioctl_desc {
433 int (*func)(struct drm_device *dev, void *data,
434 struct drm_file *file_priv);
438 * Creates a driver or general drm_ioctl_desc array entry for the given
439 * ioctl, for use by drm_ioctl().
441 #define DRM_IOCTL_DEF(ioctl, func, flags) \
442 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
444 typedef struct drm_magic_entry {
446 struct drm_file *priv;
447 struct drm_magic_entry *next;
450 typedef struct drm_magic_head {
451 struct drm_magic_entry *head;
452 struct drm_magic_entry *tail;
455 typedef struct drm_buf {
456 int idx; /* Index into master buflist */
457 int total; /* Buffer size */
458 int order; /* log-base-2(total) */
459 int used; /* Amount of buffer in use (for DMA) */
460 unsigned long offset; /* Byte offset (used internally) */
461 void *address; /* Address of buffer */
462 unsigned long bus_address; /* Bus address of buffer */
463 struct drm_buf *next; /* Kernel-only: used for free list */
464 __volatile__ int pending; /* On hardware DMA queue */
465 struct drm_file *file_priv; /* Unique identifier of holding process */
466 int context; /* Kernel queue for this buffer */
474 } list; /* Which list we're on */
476 int dev_priv_size; /* Size of buffer private stoarge */
477 void *dev_private; /* Per-buffer private storage */
480 typedef struct drm_freelist {
481 int initialized; /* Freelist in use */
482 atomic_t count; /* Number of free buffers */
483 drm_buf_t *next; /* End pointer */
485 int low_mark; /* Low water mark */
486 int high_mark; /* High water mark */
489 typedef struct drm_dma_handle {
492 #if defined(__FreeBSD__)
495 #elif defined(__NetBSD__)
496 bus_dma_segment_t seg;
500 typedef struct drm_buf_entry {
505 drm_dma_handle_t **seglist;
508 drm_freelist_t freelist;
511 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
513 TAILQ_ENTRY(drm_file) link;
521 unsigned long ioctl_count;
525 typedef struct drm_lock_data {
526 drm_hw_lock_t *hw_lock; /* Hardware lock */
527 struct drm_file *file_priv; /* Unique identifier of holding process (NULL is kernel)*/
528 int lock_queue; /* Queue of blocked processes */
529 unsigned long lock_time; /* Time of last lock in jiffies */
532 /* This structure, in the struct drm_device, is always initialized while the
534 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
535 * when set marks that no further bufs may be allocated until device teardown
536 * occurs (when the last open of the device has closed). The high/low
537 * watermarks of bufs are only touched by the X Server, and thus not
538 * concurrently accessed, so no locking is needed.
540 typedef struct drm_device_dma {
541 drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
543 drm_buf_t **buflist; /* Vector of pointers info bufs */
546 unsigned long *pagelist;
547 unsigned long byte_count;
549 _DRM_DMA_USE_AGP = 0x01,
550 _DRM_DMA_USE_SG = 0x02
554 typedef struct drm_agp_mem {
556 unsigned long bound; /* address */
558 struct drm_agp_mem *prev;
559 struct drm_agp_mem *next;
562 typedef struct drm_agp_head {
564 struct agp_info info;
566 drm_agp_mem_t *memory;
572 int cant_use_aperture;
573 unsigned long page_mask;
576 typedef struct drm_sg_mem {
577 unsigned long handle;
581 drm_dma_handle_t *dmah; /* Handle to PCI memory for ATI PCIGART table */
584 typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
586 typedef struct drm_local_map {
587 unsigned long offset; /* Physical address (0 for SAREA)*/
588 unsigned long size; /* Physical size (bytes) */
589 drm_map_type_t type; /* Type of memory mapped */
590 drm_map_flags_t flags; /* Flags */
591 void *handle; /* User-space: "Handle" to pass to mmap */
592 /* Kernel-space: kernel-virtual address */
593 int mtrr; /* Boolean: MTRR used */
595 int rid; /* PCI resource ID for bus_space */
596 struct resource *bsr;
598 bus_space_handle_t bsh;
599 drm_dma_handle_t *dmah;
600 TAILQ_ENTRY(drm_local_map) link;
603 TAILQ_HEAD(drm_vbl_sig_list, drm_vbl_sig);
604 typedef struct drm_vbl_sig {
605 TAILQ_ENTRY(drm_vbl_sig) link;
606 unsigned int sequence;
611 /* location of GART table */
612 #define DRM_ATI_GART_MAIN 1
613 #define DRM_ATI_GART_FB 2
615 #define DRM_ATI_GART_PCI 1
616 #define DRM_ATI_GART_PCIE 2
617 #define DRM_ATI_GART_IGP 3
619 struct drm_ati_pcigart_info {
620 int gart_table_location;
624 dma_addr_t table_mask;
625 dma_addr_t member_mask;
626 struct drm_dma_handle *table_handle;
627 drm_local_map_t mapping;
632 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
635 #define upper_32_bits(_val) (((u64)(_val)) >> 32)
637 struct drm_driver_info {
638 int (*load)(struct drm_device *, unsigned long flags);
639 int (*firstopen)(struct drm_device *);
640 int (*open)(struct drm_device *, drm_file_t *);
641 void (*preclose)(struct drm_device *, struct drm_file *file_priv);
642 void (*postclose)(struct drm_device *, drm_file_t *);
643 void (*lastclose)(struct drm_device *);
644 int (*unload)(struct drm_device *);
645 void (*reclaim_buffers_locked)(struct drm_device *,
646 struct drm_file *file_priv);
647 int (*dma_ioctl)(struct drm_device *dev, void *data,
648 struct drm_file *file_priv);
649 void (*dma_ready)(struct drm_device *);
650 int (*dma_quiescent)(struct drm_device *);
651 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
652 drm_lock_flags_t flags);
653 int (*dma_flush_unblock)(struct drm_device *, int context,
654 drm_lock_flags_t flags);
655 int (*context_ctor)(struct drm_device *dev, int context);
656 int (*context_dtor)(struct drm_device *dev, int context);
657 int (*kernel_context_switch)(struct drm_device *dev, int old,
659 int (*kernel_context_switch_unlock)(struct drm_device *dev);
660 void (*irq_preinstall)(struct drm_device *dev);
661 int (*irq_postinstall)(struct drm_device *dev);
662 void (*irq_uninstall)(struct drm_device *dev);
663 void (*irq_handler)(DRM_IRQ_ARGS);
664 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc);
665 int (*enable_vblank)(struct drm_device *dev, int crtc);
666 void (*disable_vblank)(struct drm_device *dev, int crtc);
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_vbl_irq2 :1;
704 unsigned use_mtrr :1;
707 /* Length for the array of resource pointers for drm_get_resource_*. */
708 #define DRM_MAX_PCI_RESOURCE 3
711 * DRM device functions structure
714 #if defined(__NetBSD__) || defined(__OpenBSD__)
715 struct device device; /* softc is an extension of struct device */
718 struct drm_driver_info driver;
719 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
721 u_int16_t pci_device; /* PCI device id */
722 u_int16_t pci_vendor; /* PCI vendor id */
724 char *unique; /* Unique identifier: e.g., busid */
725 int unique_len; /* Length of unique field */
727 device_t device; /* Device instance from newbus */
729 struct cdev *devnode; /* Device number for mknod */
730 int if_version; /* Highest interface version set */
732 int flags; /* Flags to open(2) */
735 #if defined(__FreeBSD__) && __FreeBSD_version > 500000
736 struct mtx dma_lock; /* protects dev->dma */
737 struct mtx irq_lock; /* protects irq condition checks */
738 struct mtx dev_lock; /* protects everything else */
740 DRM_SPINTYPE drw_lock;
743 int open_count; /* Outstanding files open */
744 int buf_use; /* Buffers in use -- cannot alloc */
746 /* Performance counters */
747 unsigned long counters;
748 drm_stat_type_t types[15];
752 drm_file_list_t files;
753 drm_magic_head_t magiclist[DRM_HASH_SIZE];
755 /* Linked list of mappable regions. Protected by dev_lock */
756 drm_map_list_t maplist;
758 drm_local_map_t **context_sareas;
761 drm_lock_data_t lock; /* Information on hardware lock */
763 /* DMA queues (contexts) */
764 drm_device_dma_t *dma; /* Optional pointer for DMA support */
766 /* Context support */
767 int irq; /* Interrupt used by board */
768 int irq_enabled; /* True if the irq handler is enabled */
770 int irqrid; /* Interrupt used by board */
771 struct resource *irqr; /* Resource for interrupt used by board */
772 #elif defined(__NetBSD__) || defined(__OpenBSD__)
773 struct pci_attach_args pa;
775 void *irqh; /* Handle from bus_setup_intr */
777 /* Storage of resource pointers for drm_get_resource_* */
778 struct resource *pcir[DRM_MAX_PCI_RESOURCE];
779 int pcirid[DRM_MAX_PCI_RESOURCE];
786 atomic_t context_flag; /* Context swapping flag */
787 int last_context; /* Last current context */
788 wait_queue_head_t *vbl_queue; /* vblank wait queue */
789 atomic_t *_vblank_count; /* number of VBLANK interrupts */
790 /* (driver must alloc the right number of counters) */
792 struct drm_vbl_sig_list *vbl_sigs; /* signal list to send on VBLANK */
793 atomic_t vbl_signal_pending; /* number of signals pending on all crtcs*/
794 atomic_t *vblank_refcount; /* number of users of vblank interrupts per crtc */
795 u32 *last_vblank; /* protected by dev->vbl_lock, used */
796 /* for wraparound handling */
798 u32 *vblank_offset; /* used to track how many vblanks */
799 int *vblank_enabled; /* so we don't call enable more than */
800 /* once per disable */
801 u32 *vblank_premodeset; /* were lost during modeset */
802 struct callout vblank_disable_timer;
803 unsigned long max_vblank_count; /* size of vblank counter register */
805 atomic_t vbl_received;
806 atomic_t vbl_received2;
809 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
810 #elif defined(__NetBSD__)
815 struct drm_sysctl_info *sysctl;
818 drm_sg_mem_t *sg; /* Scatter gather memory */
819 atomic_t *ctx_bitmap;
821 unsigned int agp_buffer_token;
822 drm_local_map_t *agp_buffer_map;
824 struct unrhdr *drw_unrhdr;
825 /* RB tree of drawable infos */
826 RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head;
828 struct task locked_task;
829 void (*locked_task_call)(struct drm_device *dev);
832 extern int drm_debug_flag;
834 /* Device setup support (drm_drv.c) */
836 int drm_probe(device_t nbdev, drm_pci_id_list_t *idlist);
837 int drm_attach(device_t nbdev, drm_pci_id_list_t *idlist);
838 int drm_detach(device_t nbdev);
845 #elif defined(__NetBSD__) || defined(__OpenBSD__)
846 int drm_probe(struct pci_attach_args *pa, drm_pci_id_list_t *idlist);
847 int drm_attach(struct pci_attach_args *pa, dev_t kdev, drm_pci_id_list_t *idlist);
848 dev_type_ioctl(drm_ioctl);
849 dev_type_open(drm_open);
850 dev_type_close(drm_close);
851 dev_type_read(drm_read);
852 dev_type_poll(drm_poll);
853 dev_type_mmap(drm_mmap);
855 extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
857 /* File operations helpers (drm_fops.c) */
859 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
861 struct drm_device *dev);
862 extern drm_file_t *drm_find_file_by_proc(struct drm_device *dev,
864 #elif defined(__NetBSD__) || defined(__OpenBSD__)
865 extern int drm_open_helper(dev_t kdev, int flags, int fmt,
867 struct drm_device *dev);
868 extern drm_file_t *drm_find_file_by_proc(struct drm_device *dev,
870 #endif /* __NetBSD__ || __OpenBSD__ */
872 /* Memory management support (drm_memory.c) */
873 void drm_mem_init(void);
874 void drm_mem_uninit(void);
875 void *drm_alloc(size_t size, int area);
876 void *drm_calloc(size_t nmemb, size_t size, int area);
877 void *drm_realloc(void *oldpt, size_t oldsize, size_t size,
879 void drm_free(void *pt, size_t size, int area);
880 void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map);
881 void drm_ioremapfree(drm_local_map_t *map);
882 int drm_mtrr_add(unsigned long offset, size_t size, int flags);
883 int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
885 int drm_context_switch(struct drm_device *dev, int old, int new);
886 int drm_context_switch_complete(struct drm_device *dev, int new);
888 int drm_ctxbitmap_init(struct drm_device *dev);
889 void drm_ctxbitmap_cleanup(struct drm_device *dev);
890 void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
891 int drm_ctxbitmap_next(struct drm_device *dev);
893 /* Locking IOCTL support (drm_lock.c) */
894 int drm_lock_take(__volatile__ unsigned int *lock,
895 unsigned int context);
896 int drm_lock_transfer(struct drm_device *dev,
897 __volatile__ unsigned int *lock,
898 unsigned int context);
899 int drm_lock_free(struct drm_device *dev,
900 __volatile__ unsigned int *lock,
901 unsigned int context);
903 /* Buffer management support (drm_bufs.c) */
904 unsigned long drm_get_resource_start(struct drm_device *dev,
905 unsigned int resource);
906 unsigned long drm_get_resource_len(struct drm_device *dev,
907 unsigned int resource);
908 void drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
909 int drm_order(unsigned long size);
910 int drm_addmap(struct drm_device *dev, unsigned long offset,
912 drm_map_type_t type, drm_map_flags_t flags,
913 drm_local_map_t **map_ptr);
914 int drm_addbufs_pci(struct drm_device *dev, drm_buf_desc_t *request);
915 int drm_addbufs_sg(struct drm_device *dev, drm_buf_desc_t *request);
916 int drm_addbufs_agp(struct drm_device *dev, drm_buf_desc_t *request);
918 /* DMA support (drm_dma.c) */
919 int drm_dma_setup(struct drm_device *dev);
920 void drm_dma_takedown(struct drm_device *dev);
921 void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf);
922 void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv);
923 #define drm_core_reclaim_buffers drm_reclaim_buffers
925 /* IRQ support (drm_irq.c) */
926 int drm_irq_install(struct drm_device *dev);
927 int drm_irq_uninstall(struct drm_device *dev);
928 irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
929 void drm_driver_irq_preinstall(struct drm_device *dev);
930 void drm_driver_irq_postinstall(struct drm_device *dev);
931 void drm_driver_irq_uninstall(struct drm_device *dev);
932 void drm_handle_vblank(struct drm_device *dev, int crtc);
933 u32 drm_vblank_count(struct drm_device *dev, int crtc);
934 int drm_vblank_get(struct drm_device *dev, int crtc);
935 void drm_vblank_put(struct drm_device *dev, int crtc);
936 void drm_update_vblank_count(struct drm_device *dev, int crtc);
937 int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
938 int drm_vblank_init(struct drm_device *dev, int num_crtcs);
939 void drm_vbl_send_signals(struct drm_device *dev, int crtc);
940 int drm_modeset_ctl(struct drm_device *dev, void *data,
941 struct drm_file *file_priv);
943 /* AGP/PCI Express/GART support (drm_agpsupport.c) */
944 int drm_device_is_agp(struct drm_device *dev);
945 int drm_device_is_pcie(struct drm_device *dev);
946 drm_agp_head_t *drm_agp_init(void);
947 int drm_agp_acquire(struct drm_device *dev);
948 int drm_agp_release(struct drm_device *dev);
949 int drm_agp_info(struct drm_device * dev, drm_agp_info_t *info);
950 int drm_agp_enable(struct drm_device *dev, drm_agp_mode_t mode);
951 void *drm_agp_allocate_memory(size_t pages, u32 type);
952 int drm_agp_free_memory(void *handle);
953 int drm_agp_bind_memory(void *handle, off_t start);
954 int drm_agp_unbind_memory(void *handle);
955 int drm_agp_alloc(struct drm_device *dev, drm_agp_buffer_t *request);
956 int drm_agp_free(struct drm_device *dev, drm_agp_buffer_t *request);
957 int drm_agp_bind(struct drm_device *dev, drm_agp_binding_t *request);
958 int drm_agp_unbind(struct drm_device *dev, drm_agp_binding_t *request);
960 /* Scatter Gather Support (drm_scatter.c) */
961 void drm_sg_cleanup(drm_sg_mem_t *entry);
962 int drm_sg_alloc(struct drm_device *dev, drm_scatter_gather_t * request);
965 /* sysctl support (drm_sysctl.h) */
966 extern int drm_sysctl_init(struct drm_device *dev);
967 extern int drm_sysctl_cleanup(struct drm_device *dev);
968 #endif /* __FreeBSD__ */
970 /* ATI PCIGART support (ati_pcigart.c) */
971 int drm_ati_pcigart_init(struct drm_device *dev,
972 struct drm_ati_pcigart_info *gart_info);
973 int drm_ati_pcigart_cleanup(struct drm_device *dev,
974 struct drm_ati_pcigart_info *gart_info);
976 /* Locking IOCTL support (drm_drv.c) */
977 int drm_lock(struct drm_device *dev, void *data,
978 struct drm_file *file_priv);
979 int drm_unlock(struct drm_device *dev, void *data,
980 struct drm_file *file_priv);
981 int drm_version(struct drm_device *dev, void *data,
982 struct drm_file *file_priv);
983 int drm_setversion(struct drm_device *dev, void *data,
984 struct drm_file *file_priv);
986 /* Misc. IOCTL support (drm_ioctl.c) */
987 int drm_irq_by_busid(struct drm_device *dev, void *data,
988 struct drm_file *file_priv);
989 int drm_getunique(struct drm_device *dev, void *data,
990 struct drm_file *file_priv);
991 int drm_setunique(struct drm_device *dev, void *data,
992 struct drm_file *file_priv);
993 int drm_getmap(struct drm_device *dev, void *data,
994 struct drm_file *file_priv);
995 int drm_getclient(struct drm_device *dev, void *data,
996 struct drm_file *file_priv);
997 int drm_getstats(struct drm_device *dev, void *data,
998 struct drm_file *file_priv);
999 int drm_noop(struct drm_device *dev, void *data,
1000 struct drm_file *file_priv);
1002 /* Context IOCTL support (drm_context.c) */
1003 int drm_resctx(struct drm_device *dev, void *data,
1004 struct drm_file *file_priv);
1005 int drm_addctx(struct drm_device *dev, void *data,
1006 struct drm_file *file_priv);
1007 int drm_modctx(struct drm_device *dev, void *data,
1008 struct drm_file *file_priv);
1009 int drm_getctx(struct drm_device *dev, void *data,
1010 struct drm_file *file_priv);
1011 int drm_switchctx(struct drm_device *dev, void *data,
1012 struct drm_file *file_priv);
1013 int drm_newctx(struct drm_device *dev, void *data,
1014 struct drm_file *file_priv);
1015 int drm_rmctx(struct drm_device *dev, void *data,
1016 struct drm_file *file_priv);
1017 int drm_setsareactx(struct drm_device *dev, void *data,
1018 struct drm_file *file_priv);
1019 int drm_getsareactx(struct drm_device *dev, void *data,
1020 struct drm_file *file_priv);
1022 /* Drawable IOCTL support (drm_drawable.c) */
1023 int drm_adddraw(struct drm_device *dev, void *data,
1024 struct drm_file *file_priv);
1025 int drm_rmdraw(struct drm_device *dev, void *data,
1026 struct drm_file *file_priv);
1027 int drm_update_draw(struct drm_device *dev, void *data,
1028 struct drm_file *file_priv);
1029 struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
1032 /* Authentication IOCTL support (drm_auth.c) */
1033 int drm_getmagic(struct drm_device *dev, void *data,
1034 struct drm_file *file_priv);
1035 int drm_authmagic(struct drm_device *dev, void *data,
1036 struct drm_file *file_priv);
1038 /* Buffer management support (drm_bufs.c) */
1039 int drm_addmap_ioctl(struct drm_device *dev, void *data,
1040 struct drm_file *file_priv);
1041 int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1042 struct drm_file *file_priv);
1043 int drm_addbufs_ioctl(struct drm_device *dev, void *data,
1044 struct drm_file *file_priv);
1045 int drm_infobufs(struct drm_device *dev, void *data,
1046 struct drm_file *file_priv);
1047 int drm_markbufs(struct drm_device *dev, void *data,
1048 struct drm_file *file_priv);
1049 int drm_freebufs(struct drm_device *dev, void *data,
1050 struct drm_file *file_priv);
1051 int drm_mapbufs(struct drm_device *dev, void *data,
1052 struct drm_file *file_priv);
1054 /* DMA support (drm_dma.c) */
1055 int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv);
1057 /* IRQ support (drm_irq.c) */
1058 int drm_control(struct drm_device *dev, void *data, struct drm_file *file_priv);
1059 int drm_wait_vblank(struct drm_device *dev, void *data,
1060 struct drm_file *file_priv);
1061 void drm_locked_tasklet(struct drm_device *dev,
1062 void (*tasklet)(struct drm_device *dev));
1064 /* AGP/GART support (drm_agpsupport.c) */
1065 int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1066 struct drm_file *file_priv);
1067 int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1068 struct drm_file *file_priv);
1069 int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1070 struct drm_file *file_priv);
1071 int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1072 struct drm_file *file_priv);
1073 int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1074 struct drm_file *file_priv);
1075 int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1076 struct drm_file *file_priv);
1077 int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1078 struct drm_file *file_priv);
1079 int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1080 struct drm_file *file_priv);
1082 /* Scatter Gather Support (drm_scatter.c) */
1083 int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1084 struct drm_file *file_priv);
1085 int drm_sg_free(struct drm_device *dev, void *data,
1086 struct drm_file *file_priv);
1088 /* consistent PCI memory functions (drm_pci.c) */
1089 drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1090 size_t align, dma_addr_t maxaddr);
1091 void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1093 /* Inline replacements for DRM_IOREMAP macros */
1094 static __inline__ void
1095 drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
1097 map->handle = drm_ioremap(dev, map);
1099 static __inline__ void
1100 drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
1102 if ( map->handle && map->size )
1103 drm_ioremapfree(map);
1106 static __inline__ struct drm_local_map *
1107 drm_core_findmap(struct drm_device *dev, unsigned long offset)
1109 drm_local_map_t *map;
1111 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
1112 TAILQ_FOREACH(map, &dev->maplist, link) {
1113 if (map->offset == offset)
1119 static __inline__ void drm_core_dropmap(struct drm_map *map)
1123 #endif /* __KERNEL__ */
1124 #endif /* _DRM_P_H_ */