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__)
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>
53 #include <sys/fcntl.h>
55 #include <sys/filio.h>
56 #include <sys/sysctl.h>
58 #include <sys/signalvar.h>
60 #include <sys/event.h>
62 #include <sys/taskqueue.h>
65 #include <vm/vm_extern.h>
66 #include <vm/vm_map.h>
67 #include <vm/vm_param.h>
68 #include <machine/param.h>
69 #include <machine/pmap.h>
71 #include <sys/resource.h>
72 #include <machine/specialreg.h>
73 #include <machine/sysarch.h>
74 #include <sys/endian.h>
77 #include <sys/memrange.h>
78 #include <dev/agp/agpvar.h>
79 #include <sys/device.h>
80 #include <sys/agpio.h>
81 #include <sys/spinlock.h>
82 #include <sys/spinlock2.h>
83 #include <bus/pci/pcivar.h>
84 #include <bus/pci/pcireg.h>
85 #include <sys/selinfo.h>
88 #include "dev/drm/drm.h"
89 #include "dev/drm/drm_linux_list.h"
90 #include "dev/drm/drm_atomic.h"
91 #include "dev/drm/drm_internal.h"
96 #define DRM_DEBUG_DEFAULT_ON 1
97 #endif /* DRM_DEBUG */
99 #if defined(DRM_LINUX) && DRM_LINUX && !defined(__x86_64__) && !defined(__DragonFly__) /* XXX */
100 #include <sys/file.h>
101 #include <sys/proc.h>
102 #include <machine/../linux/linux.h>
103 #include <machine/../linux/linux_proto.h>
105 /* Either it was defined when it shouldn't be (FreeBSD amd64) or it isn't
106 * supported on this OS yet.
112 /* driver capabilities and requirements mask */
113 #define DRIVER_USE_AGP 0x1
114 #define DRIVER_REQUIRE_AGP 0x2
115 #define DRIVER_USE_MTRR 0x4
116 #define DRIVER_PCI_DMA 0x8
117 #define DRIVER_SG 0x10
118 #define DRIVER_HAVE_DMA 0x20
119 #define DRIVER_HAVE_IRQ 0x40
120 #define DRIVER_DMA_QUEUE 0x100
123 #define DRM_HASH_SIZE 16 /* Size of key hash table */
124 #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
125 #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
127 MALLOC_DECLARE(DRM_MEM_DMA);
128 MALLOC_DECLARE(DRM_MEM_SAREA);
129 MALLOC_DECLARE(DRM_MEM_DRIVER);
130 MALLOC_DECLARE(DRM_MEM_MAGIC);
131 MALLOC_DECLARE(DRM_MEM_IOCTLS);
132 MALLOC_DECLARE(DRM_MEM_MAPS);
133 MALLOC_DECLARE(DRM_MEM_BUFS);
134 MALLOC_DECLARE(DRM_MEM_SEGS);
135 MALLOC_DECLARE(DRM_MEM_PAGES);
136 MALLOC_DECLARE(DRM_MEM_FILES);
137 MALLOC_DECLARE(DRM_MEM_QUEUES);
138 MALLOC_DECLARE(DRM_MEM_CMDS);
139 MALLOC_DECLARE(DRM_MEM_MAPPINGS);
140 MALLOC_DECLARE(DRM_MEM_BUFLISTS);
141 MALLOC_DECLARE(DRM_MEM_AGPLISTS);
142 MALLOC_DECLARE(DRM_MEM_CTXBITMAP);
143 MALLOC_DECLARE(DRM_MEM_SGLISTS);
144 MALLOC_DECLARE(DRM_MEM_DRAWABLE);
146 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
148 /* Internal types and structures */
149 #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
150 #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
151 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
153 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
155 #define __OS_HAS_AGP 1
157 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
158 #define DRM_DEV_UID 0
159 #define DRM_DEV_GID 0
161 #define wait_queue_head_t atomic_t
162 #define DRM_WAKEUP(w) wakeup((void *)w)
163 #define DRM_WAKEUP_INT(w) wakeup(w)
164 #define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0)
166 #define DRM_CURPROC curthread
167 #define DRM_STRUCTPROC struct thread
168 #define DRM_SPINTYPE struct lock
169 #define DRM_SPININIT(l,name) lockinit(l, name, 0, LK_CANRECURSE)
170 #define DRM_SPINUNINIT(l)
171 #define DRM_SPINLOCK(l) lockmgr(l, LK_EXCLUSIVE|LK_RETRY|LK_CANRECURSE)
172 #define DRM_SPINUNLOCK(u) lockmgr(u, LK_RELEASE)
173 #define DRM_SPINLOCK_IRQSAVE(l, irqflags) do { \
177 #define DRM_SPINUNLOCK_IRQRESTORE(u, irqflags) DRM_SPINUNLOCK(u)
178 #define DRM_SPINLOCK_ASSERT(l)
179 #define DRM_CURRENTPID curthread->td_proc->p_pid
180 #define DRM_LOCK() DRM_SPINLOCK(&dev->dev_lock)
181 #define DRM_UNLOCK() DRM_SPINUNLOCK(&dev->dev_lock)
182 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
184 #define DRM_IRQ_ARGS void *arg
185 typedef void irqreturn_t;
186 #define IRQ_HANDLED /* nothing */
187 #define IRQ_NONE /* nothing */
194 #define DRM_AGP_MEM struct agp_memory_info
196 #define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1)
198 #define PAGE_ALIGN(addr) round_page(addr)
199 /* DRM_SUSER returns true if the user is superuser */
200 #define DRM_SUSER(p) (priv_check(p, PRIV_DRIVER) == 0)
201 #define DRM_AGP_FIND_DEVICE() agp_find_device()
202 #define DRM_MTRR_WC MDF_WRITECOMBINE
203 #define jiffies ticks
205 typedef unsigned long dma_addr_t;
206 typedef u_int64_t u64;
207 typedef u_int32_t u32;
208 typedef u_int16_t u16;
211 /* DRM_READMEMORYBARRIER() prevents reordering of reads.
212 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
213 * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
215 #if defined(__i386__)
216 #define DRM_READMEMORYBARRIER() __asm __volatile( \
217 "lock; addl $0,0(%%esp)" : : : "memory");
218 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
219 #define DRM_MEMORYBARRIER() __asm __volatile( \
220 "lock; addl $0,0(%%esp)" : : : "memory");
221 #elif defined(__alpha__)
222 #define DRM_READMEMORYBARRIER() alpha_mb();
223 #define DRM_WRITEMEMORYBARRIER() alpha_wmb();
224 #define DRM_MEMORYBARRIER() alpha_mb();
225 #elif defined(__x86_64__)
226 #define DRM_READMEMORYBARRIER() __asm __volatile( \
227 "lock; addl $0,0(%%rsp)" : : : "memory");
228 #define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory");
229 #define DRM_MEMORYBARRIER() __asm __volatile( \
230 "lock; addl $0,0(%%rsp)" : : : "memory");
233 #define DRM_READ8(map, offset) \
234 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \
235 (vm_offset_t)(offset))
236 #define DRM_READ16(map, offset) \
237 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \
238 (vm_offset_t)(offset))
239 #define DRM_READ32(map, offset) \
240 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \
241 (vm_offset_t)(offset))
242 #define DRM_WRITE8(map, offset, val) \
243 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \
244 (vm_offset_t)(offset)) = val
245 #define DRM_WRITE16(map, offset, val) \
246 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \
247 (vm_offset_t)(offset)) = val
248 #define DRM_WRITE32(map, offset, val) \
249 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \
250 (vm_offset_t)(offset)) = val
252 #define DRM_VERIFYAREA_READ( uaddr, size ) \
253 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
255 #define DRM_COPY_TO_USER(user, kern, size) \
256 copyout(kern, user, size)
257 #define DRM_COPY_FROM_USER(kern, user, size) \
258 copyin(user, kern, size)
259 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
260 copyin(arg2, arg1, arg3)
261 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
262 copyout(arg2, arg1, arg3)
263 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
264 ((val) = fuword32(uaddr), 0)
266 #define cpu_to_le32(x) htole32(x)
267 #define le32_to_cpu(x) le32toh(x)
270 #define DRM_UDELAY(udelay) DELAY(udelay)
271 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
273 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
274 (_map) = (_dev)->context_sareas[_ctx]; \
277 #define LOCK_TEST_WITH_RETURN(dev, file_priv) \
279 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
280 dev->lock.file_priv != file_priv) { \
281 DRM_ERROR("%s called without lock held\n", \
287 /* Returns -errno to shared code */
288 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
289 for ( ret = 0 ; !ret && !(condition) ; ) { \
291 lwkt_serialize_enter(&dev->irq_lock); \
292 if (!(condition)) { \
293 tsleep_interlock(&(queue), PCATCH); \
294 lwkt_serialize_exit(&dev->irq_lock); \
295 ret = -tsleep(&(queue), PCATCH | PINTERLOCKED, \
296 "drmwtq", (timeout)); \
298 lwkt_serialize_exit(&dev->irq_lock); \
303 #define printf kprintf
304 #define snprintf ksnprintf
305 #define sscanf ksscanf
306 #define malloc kmalloc
307 #define realloc krealloc
308 #define reallocf krealloc /* XXX XXX XXX */
311 free(void *addr, struct malloc_type *type)
317 #define DRM_ERROR(fmt, ...) \
318 printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
319 DRM_CURRENTPID, __func__ , ##__VA_ARGS__)
321 #define DRM_INFO(fmt, ...) printf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
323 #define DRM_DEBUG(fmt, ...) do { \
324 if (drm_debug_flag) \
325 printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
326 __func__ , ##__VA_ARGS__); \
329 typedef struct drm_pci_id_list
337 struct drm_msi_blacklist_entry
344 #define DRM_MASTER 0x2
345 #define DRM_ROOT_ONLY 0x4
346 typedef struct drm_ioctl_desc {
348 int (*func)(struct drm_device *dev, void *data,
349 struct drm_file *file_priv);
353 * Creates a driver or general drm_ioctl_desc array entry for the given
354 * ioctl, for use by drm_ioctl().
356 #define DRM_IOCTL_DEF(ioctl, func, flags) \
357 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
359 typedef struct drm_magic_entry {
361 struct drm_file *priv;
362 struct drm_magic_entry *next;
365 typedef struct drm_magic_head {
366 struct drm_magic_entry *head;
367 struct drm_magic_entry *tail;
370 typedef struct drm_buf {
371 int idx; /* Index into master buflist */
372 int total; /* Buffer size */
373 int order; /* log-base-2(total) */
374 int used; /* Amount of buffer in use (for DMA) */
375 unsigned long offset; /* Byte offset (used internally) */
376 void *address; /* Address of buffer */
377 unsigned long bus_address; /* Bus address of buffer */
378 struct drm_buf *next; /* Kernel-only: used for free list */
379 __volatile__ int pending; /* On hardware DMA queue */
380 struct drm_file *file_priv; /* Unique identifier of holding process */
381 int context; /* Kernel queue for this buffer */
389 } list; /* Which list we're on */
391 int dev_priv_size; /* Size of buffer private stoarge */
392 void *dev_private; /* Per-buffer private storage */
395 typedef struct drm_freelist {
396 int initialized; /* Freelist in use */
397 atomic_t count; /* Number of free buffers */
398 drm_buf_t *next; /* End pointer */
400 int low_mark; /* Low water mark */
401 int high_mark; /* High water mark */
404 typedef struct drm_dma_handle {
411 typedef struct drm_buf_entry {
416 drm_dma_handle_t **seglist;
419 drm_freelist_t freelist;
422 typedef TAILQ_HEAD(drm_file_list, drm_file) drm_file_list_t;
424 TAILQ_ENTRY(drm_file) link;
425 struct drm_device *dev;
433 unsigned long ioctl_count;
437 typedef struct drm_lock_data {
438 struct drm_hw_lock *hw_lock; /* Hardware lock */
439 struct drm_file *file_priv; /* Unique identifier of holding process (NULL is kernel)*/
440 int lock_queue; /* Queue of blocked processes */
441 unsigned long lock_time; /* Time of last lock in jiffies */
444 /* This structure, in the struct drm_device, is always initialized while the
446 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
447 * when set marks that no further bufs may be allocated until device teardown
448 * occurs (when the last open of the device has closed). The high/low
449 * watermarks of bufs are only touched by the X Server, and thus not
450 * concurrently accessed, so no locking is needed.
452 typedef struct drm_device_dma {
453 drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
455 drm_buf_t **buflist; /* Vector of pointers info bufs */
458 unsigned long *pagelist;
459 unsigned long byte_count;
461 _DRM_DMA_USE_AGP = 0x01,
462 _DRM_DMA_USE_SG = 0x02
466 typedef struct drm_agp_mem {
468 unsigned long bound; /* address */
470 struct drm_agp_mem *prev;
471 struct drm_agp_mem *next;
474 typedef struct drm_agp_head {
476 struct agp_info info;
478 drm_agp_mem_t *memory;
484 int cant_use_aperture;
485 unsigned long page_mask;
488 typedef struct drm_sg_mem {
489 unsigned long handle;
493 struct drm_dma_handle *dmah; /* Handle to PCI memory */
496 typedef TAILQ_HEAD(drm_map_list, drm_local_map) drm_map_list_t;
498 typedef struct drm_local_map {
499 unsigned long offset; /* Physical address (0 for SAREA)*/
500 unsigned long size; /* Physical size (bytes) */
501 enum drm_map_type type; /* Type of memory mapped */
502 enum drm_map_flags flags; /* Flags */
503 void *handle; /* User-space: "Handle" to pass to mmap */
504 /* Kernel-space: kernel-virtual address */
505 int mtrr; /* Boolean: MTRR used */
507 int rid; /* PCI resource ID for bus_space */
508 struct resource *bsr;
510 bus_space_handle_t bsh;
511 drm_dma_handle_t *dmah;
512 TAILQ_ENTRY(drm_local_map) link;
515 struct drm_vblank_info {
516 wait_queue_head_t queue; /* vblank wait queue */
517 atomic_t count; /* number of VBLANK interrupts */
518 /* (driver must alloc the right number of counters) */
519 atomic_t refcount; /* number of users of vblank interrupts */
520 u32 last; /* protected by dev->vbl_lock, used */
521 /* for wraparound handling */
522 int enabled; /* so we don't call enable more than */
523 /* once per disable */
524 int inmodeset; /* Display driver is setting mode */
527 /* location of GART table */
528 #define DRM_ATI_GART_MAIN 1
529 #define DRM_ATI_GART_FB 2
531 #define DRM_ATI_GART_PCI 1
532 #define DRM_ATI_GART_PCIE 2
533 #define DRM_ATI_GART_IGP 3
535 struct drm_ati_pcigart_info {
536 int gart_table_location;
540 dma_addr_t table_mask;
541 dma_addr_t member_mask;
542 struct drm_dma_handle *table_handle;
543 drm_local_map_t mapping;
545 struct drm_dma_handle *dmah; /* handle for ATI PCIGART table */
549 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
552 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
554 struct drm_driver_info {
555 int (*load)(struct drm_device *, unsigned long flags);
556 int (*firstopen)(struct drm_device *);
557 int (*open)(struct drm_device *, struct drm_file *);
558 void (*preclose)(struct drm_device *, struct drm_file *file_priv);
559 void (*postclose)(struct drm_device *, struct drm_file *);
560 void (*lastclose)(struct drm_device *);
561 int (*unload)(struct drm_device *);
562 void (*reclaim_buffers_locked)(struct drm_device *,
563 struct drm_file *file_priv);
564 int (*dma_ioctl)(struct drm_device *dev, void *data,
565 struct drm_file *file_priv);
566 void (*dma_ready)(struct drm_device *);
567 int (*dma_quiescent)(struct drm_device *);
568 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
569 enum drm_lock_flags flags);
570 int (*dma_flush_unblock)(struct drm_device *, int context,
571 enum drm_lock_flags flags);
572 int (*context_ctor)(struct drm_device *dev, int context);
573 int (*context_dtor)(struct drm_device *dev, int context);
574 int (*kernel_context_switch)(struct drm_device *dev, int old,
576 int (*kernel_context_switch_unlock)(struct drm_device *dev);
577 void (*irq_preinstall)(struct drm_device *dev);
578 int (*irq_postinstall)(struct drm_device *dev);
579 void (*irq_uninstall)(struct drm_device *dev);
580 void (*irq_handler)(DRM_IRQ_ARGS);
581 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc);
582 int (*enable_vblank)(struct drm_device *dev, int crtc);
583 void (*disable_vblank)(struct drm_device *dev, int crtc);
585 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
588 * Called by \c drm_device_is_agp. Typically used to determine if a
589 * card is really attached to AGP or not.
591 * \param dev DRM device handle
594 * One of three values is returned depending on whether or not the
595 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
596 * (return of 1), or may or may not be AGP (return of 2).
598 int (*device_is_agp) (struct drm_device * dev);
600 drm_ioctl_desc_t *ioctls;
608 const char *name; /* Simple driver name */
609 const char *desc; /* Longer driver name */
610 const char *date; /* Date of last major changes. */
615 /* Length for the array of resource pointers for drm_get_resource_*. */
616 #define DRM_MAX_PCI_RESOURCE 6
619 * DRM device functions structure
622 struct drm_driver_info *driver;
623 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
625 u_int16_t pci_device; /* PCI device id */
626 u_int16_t pci_vendor; /* PCI vendor id */
628 char *unique; /* Unique identifier: e.g., busid */
629 int unique_len; /* Length of unique field */
630 device_t device; /* Device instance from newbus */
631 struct cdev *devnode; /* Device number for mknod */
632 int if_version; /* Highest interface version set */
634 int flags; /* Flags to open(2) */
637 DRM_SPINTYPE vbl_lock; /* protects vblank operations */
638 DRM_SPINTYPE dma_lock; /* protects dev->dma */
639 struct lwkt_serialize irq_lock; /* protects irq condition checks */
640 DRM_SPINTYPE dev_lock; /* protects everything else */
641 DRM_SPINTYPE drw_lock;
644 int open_count; /* Outstanding files open */
645 int buf_use; /* Buffers in use -- cannot alloc */
647 /* Performance counters */
648 unsigned long counters;
649 enum drm_stat_type types[15];
653 drm_file_list_t files;
654 drm_magic_head_t magiclist[DRM_HASH_SIZE];
656 /* Linked list of mappable regions. Protected by dev_lock */
657 drm_map_list_t maplist;
659 drm_local_map_t **context_sareas;
662 drm_lock_data_t lock; /* Information on hardware lock */
664 /* DMA queues (contexts) */
665 drm_device_dma_t *dma; /* Optional pointer for DMA support */
667 /* Context support */
668 int irq; /* Interrupt used by board */
669 int irq_enabled; /* True if the irq handler is enabled */
670 int msi_enabled; /* MSI enabled */
671 int irqrid; /* Interrupt used by board */
672 struct resource *irqr; /* Resource for interrupt used by board */
673 void *irqh; /* Handle from bus_setup_intr */
675 /* Storage of resource pointers for drm_get_resource_* */
676 struct resource *pcir[DRM_MAX_PCI_RESOURCE];
677 int pcirid[DRM_MAX_PCI_RESOURCE];
684 atomic_t context_flag; /* Context swapping flag */
685 int last_context; /* Last current context */
687 int vblank_disable_allowed;
688 struct callout vblank_disable_timer;
689 u32 max_vblank_count; /* size of vblank counter register */
690 struct drm_vblank_info *vblank; /* per crtc vblank info */
693 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
696 struct drm_sysctl_info *sysctl;
699 drm_sg_mem_t *sg; /* Scatter gather memory */
700 atomic_t *ctx_bitmap;
702 unsigned int agp_buffer_token;
703 drm_local_map_t *agp_buffer_map;
705 /* RB tree of drawable infos */
706 RB_HEAD(drawable_tree, bsd_drm_drawable_info) drw_head;
709 static __inline__ int drm_core_check_feature(struct drm_device *dev,
712 return ((dev->driver->driver_features & feature) ? 1 : 0);
716 static inline int drm_core_has_AGP(struct drm_device *dev)
718 return drm_core_check_feature(dev, DRIVER_USE_AGP);
721 #define drm_core_has_AGP(dev) (0)
724 extern int drm_debug_flag;
726 /* Device setup support (drm_drv.c) */
727 int drm_probe(device_t kdev, drm_pci_id_list_t *idlist);
728 int drm_attach(device_t kdev, drm_pci_id_list_t *idlist);
729 int drm_detach(device_t kdev);
735 d_kqfilter_t drm_kqfilter;
737 extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
739 /* File operations helpers (drm_fops.c) */
740 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
742 struct drm_device *dev);
743 extern struct drm_file *drm_find_file_by_proc(struct drm_device *dev,
746 /* Memory management support (drm_memory.c) */
747 void drm_mem_init(void);
748 void drm_mem_uninit(void);
749 void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map);
750 void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map);
751 void drm_ioremapfree(drm_local_map_t *map);
752 int drm_mtrr_add(unsigned long offset, size_t size, int flags);
753 int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
755 int drm_context_switch(struct drm_device *dev, int old, int new);
756 int drm_context_switch_complete(struct drm_device *dev, int new);
758 int drm_ctxbitmap_init(struct drm_device *dev);
759 void drm_ctxbitmap_cleanup(struct drm_device *dev);
760 void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
761 int drm_ctxbitmap_next(struct drm_device *dev);
763 /* Locking IOCTL support (drm_lock.c) */
764 int drm_lock_take(struct drm_lock_data *lock_data,
765 unsigned int context);
766 int drm_lock_transfer(struct drm_lock_data *lock_data,
767 unsigned int context);
768 int drm_lock_free(struct drm_lock_data *lock_data,
769 unsigned int context);
771 /* Buffer management support (drm_bufs.c) */
772 unsigned long drm_get_resource_start(struct drm_device *dev,
773 unsigned int resource);
774 unsigned long drm_get_resource_len(struct drm_device *dev,
775 unsigned int resource);
776 void drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
777 int drm_order(unsigned long size);
778 int drm_addmap(struct drm_device *dev, unsigned long offset,
780 enum drm_map_type type, enum drm_map_flags flags,
781 drm_local_map_t **map_ptr);
782 int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request);
783 int drm_addbufs_sg(struct drm_device *dev, struct drm_buf_desc *request);
784 int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request);
786 /* DMA support (drm_dma.c) */
787 int drm_dma_setup(struct drm_device *dev);
788 void drm_dma_takedown(struct drm_device *dev);
789 void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf);
790 void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv);
791 #define drm_core_reclaim_buffers drm_reclaim_buffers
793 /* IRQ support (drm_irq.c) */
794 int drm_irq_install(struct drm_device *dev);
795 int drm_irq_uninstall(struct drm_device *dev);
796 irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
797 void drm_driver_irq_preinstall(struct drm_device *dev);
798 void drm_driver_irq_postinstall(struct drm_device *dev);
799 void drm_driver_irq_uninstall(struct drm_device *dev);
800 void drm_handle_vblank(struct drm_device *dev, int crtc);
801 u32 drm_vblank_count(struct drm_device *dev, int crtc);
802 int drm_vblank_get(struct drm_device *dev, int crtc);
803 void drm_vblank_put(struct drm_device *dev, int crtc);
804 void drm_vblank_cleanup(struct drm_device *dev);
805 int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
806 int drm_vblank_init(struct drm_device *dev, int num_crtcs);
807 int drm_modeset_ctl(struct drm_device *dev, void *data,
808 struct drm_file *file_priv);
810 /* AGP/PCI Express/GART support (drm_agpsupport.c) */
811 int drm_device_is_agp(struct drm_device *dev);
812 int drm_device_is_pcie(struct drm_device *dev);
813 drm_agp_head_t *drm_agp_init(void);
814 int drm_agp_acquire(struct drm_device *dev);
815 int drm_agp_release(struct drm_device *dev);
816 int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info);
817 int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
818 void *drm_agp_allocate_memory(size_t pages, u32 type);
819 int drm_agp_free_memory(void *handle);
820 int drm_agp_bind_memory(void *handle, off_t start);
821 int drm_agp_unbind_memory(void *handle);
822 int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
823 int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
824 int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
825 int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
827 /* Scatter Gather Support (drm_scatter.c) */
828 void drm_sg_cleanup(drm_sg_mem_t *entry);
829 int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
831 /* sysctl support (drm_sysctl.h) */
832 extern int drm_sysctl_init(struct drm_device *dev);
833 extern int drm_sysctl_cleanup(struct drm_device *dev);
835 /* ATI PCIGART support (ati_pcigart.c) */
836 int drm_ati_pcigart_init(struct drm_device *dev,
837 struct drm_ati_pcigart_info *gart_info);
838 int drm_ati_pcigart_cleanup(struct drm_device *dev,
839 struct drm_ati_pcigart_info *gart_info);
841 /* Locking IOCTL support (drm_drv.c) */
842 int drm_lock(struct drm_device *dev, void *data,
843 struct drm_file *file_priv);
844 int drm_unlock(struct drm_device *dev, void *data,
845 struct drm_file *file_priv);
846 int drm_version(struct drm_device *dev, void *data,
847 struct drm_file *file_priv);
848 int drm_setversion(struct drm_device *dev, void *data,
849 struct drm_file *file_priv);
851 /* Misc. IOCTL support (drm_ioctl.c) */
852 int drm_irq_by_busid(struct drm_device *dev, void *data,
853 struct drm_file *file_priv);
854 int drm_getunique(struct drm_device *dev, void *data,
855 struct drm_file *file_priv);
856 int drm_setunique(struct drm_device *dev, void *data,
857 struct drm_file *file_priv);
858 int drm_getmap(struct drm_device *dev, void *data,
859 struct drm_file *file_priv);
860 int drm_getclient(struct drm_device *dev, void *data,
861 struct drm_file *file_priv);
862 int drm_getstats(struct drm_device *dev, void *data,
863 struct drm_file *file_priv);
864 int drm_noop(struct drm_device *dev, void *data,
865 struct drm_file *file_priv);
867 /* Context IOCTL support (drm_context.c) */
868 int drm_resctx(struct drm_device *dev, void *data,
869 struct drm_file *file_priv);
870 int drm_addctx(struct drm_device *dev, void *data,
871 struct drm_file *file_priv);
872 int drm_modctx(struct drm_device *dev, void *data,
873 struct drm_file *file_priv);
874 int drm_getctx(struct drm_device *dev, void *data,
875 struct drm_file *file_priv);
876 int drm_switchctx(struct drm_device *dev, void *data,
877 struct drm_file *file_priv);
878 int drm_newctx(struct drm_device *dev, void *data,
879 struct drm_file *file_priv);
880 int drm_rmctx(struct drm_device *dev, void *data,
881 struct drm_file *file_priv);
882 int drm_setsareactx(struct drm_device *dev, void *data,
883 struct drm_file *file_priv);
884 int drm_getsareactx(struct drm_device *dev, void *data,
885 struct drm_file *file_priv);
887 /* Drawable IOCTL support (drm_drawable.c) */
888 int drm_adddraw(struct drm_device *dev, void *data,
889 struct drm_file *file_priv);
890 int drm_rmdraw(struct drm_device *dev, void *data,
891 struct drm_file *file_priv);
892 int drm_update_draw(struct drm_device *dev, void *data,
893 struct drm_file *file_priv);
894 struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
897 /* Drawable support (drm_drawable.c) */
898 void drm_drawable_free_all(struct drm_device *dev);
900 /* Authentication IOCTL support (drm_auth.c) */
901 int drm_getmagic(struct drm_device *dev, void *data,
902 struct drm_file *file_priv);
903 int drm_authmagic(struct drm_device *dev, void *data,
904 struct drm_file *file_priv);
906 /* Buffer management support (drm_bufs.c) */
907 int drm_addmap_ioctl(struct drm_device *dev, void *data,
908 struct drm_file *file_priv);
909 int drm_rmmap_ioctl(struct drm_device *dev, void *data,
910 struct drm_file *file_priv);
911 int drm_addbufs(struct drm_device *dev, void *data,
912 struct drm_file *file_priv);
913 int drm_infobufs(struct drm_device *dev, void *data,
914 struct drm_file *file_priv);
915 int drm_markbufs(struct drm_device *dev, void *data,
916 struct drm_file *file_priv);
917 int drm_freebufs(struct drm_device *dev, void *data,
918 struct drm_file *file_priv);
919 int drm_mapbufs(struct drm_device *dev, void *data,
920 struct drm_file *file_priv);
922 /* DMA support (drm_dma.c) */
923 int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv);
925 /* IRQ support (drm_irq.c) */
926 int drm_control(struct drm_device *dev, void *data,
927 struct drm_file *file_priv);
928 int drm_wait_vblank(struct drm_device *dev, void *data,
929 struct drm_file *file_priv);
931 /* AGP/GART support (drm_agpsupport.c) */
932 int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
933 struct drm_file *file_priv);
934 int drm_agp_release_ioctl(struct drm_device *dev, void *data,
935 struct drm_file *file_priv);
936 int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
937 struct drm_file *file_priv);
938 int drm_agp_info_ioctl(struct drm_device *dev, void *data,
939 struct drm_file *file_priv);
940 int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
941 struct drm_file *file_priv);
942 int drm_agp_free_ioctl(struct drm_device *dev, void *data,
943 struct drm_file *file_priv);
944 int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
945 struct drm_file *file_priv);
946 int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
947 struct drm_file *file_priv);
949 /* Scatter Gather Support (drm_scatter.c) */
950 int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
951 struct drm_file *file_priv);
952 int drm_sg_free(struct drm_device *dev, void *data,
953 struct drm_file *file_priv);
955 /* consistent PCI memory functions (drm_pci.c) */
956 drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
957 size_t align, dma_addr_t maxaddr);
958 void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
960 /* Inline replacements for drm_alloc and friends */
961 static __inline__ void *
962 drm_alloc(size_t size, struct malloc_type *area)
964 return malloc(size, area, M_NOWAIT);
967 static __inline__ void *
968 drm_calloc(size_t nmemb, size_t size, struct malloc_type *area)
970 return malloc(size * nmemb, area, M_NOWAIT | M_ZERO);
973 static __inline__ void *
974 drm_realloc(void *oldpt, size_t oldsize, size_t size,
975 struct malloc_type *area)
977 return reallocf(oldpt, size, area, M_NOWAIT);
980 static __inline__ void
981 drm_free(void *pt, size_t size, struct malloc_type *area)
986 /* Inline replacements for DRM_IOREMAP macros */
987 static __inline__ void
988 drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
990 map->handle = drm_ioremap_wc(dev, map);
992 static __inline__ void
993 drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
995 map->handle = drm_ioremap(dev, map);
997 static __inline__ void
998 drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
1000 if ( map->handle && map->size )
1001 drm_ioremapfree(map);
1004 static __inline__ struct drm_local_map *
1005 drm_core_findmap(struct drm_device *dev, unsigned long offset)
1007 drm_local_map_t *map;
1009 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
1010 TAILQ_FOREACH(map, &dev->maplist, link) {
1011 if (map->offset == offset)
1017 static __inline__ void drm_core_dropmap(struct drm_map *map)
1021 #endif /* __KERNEL__ */
1022 #endif /* _DRM_P_H_ */