3 * Private header for Direct Rendering Manager
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
10 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
11 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
12 * Copyright (c) 2009-2010, Code Aurora Forum.
13 * All rights reserved.
15 * Permission is hereby granted, free of charge, to any person obtaining a
16 * copy of this software and associated documentation files (the "Software"),
17 * to deal in the Software without restriction, including without limitation
18 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19 * and/or sell copies of the Software, and to permit persons to whom the
20 * Software is furnished to do so, subject to the following conditions:
22 * The above copyright notice and this permission notice (including the next
23 * paragraph) shall be included in all copies or substantial portions of the
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
29 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
30 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
31 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32 * OTHER DEALINGS IN THE SOFTWARE.
38 #if defined(_KERNEL) || defined(__KERNEL__)
40 #include <sys/param.h>
41 #include <sys/queue.h>
42 #include <sys/malloc.h>
43 #include <sys/kernel.h>
45 #include <sys/module.h>
46 #include <sys/systm.h>
47 #include <sys/device.h>
48 #include <sys/sglist.h>
53 #include <sys/spinlock.h>
54 #include <sys/spinlock2.h>
55 #include <sys/fcntl.h>
57 #include <sys/filio.h>
58 #include <sys/sysctl.h>
60 #include <sys/queue.h>
61 #include <sys/signalvar.h>
64 #include <sys/taskqueue.h>
68 #include <vm/vm_extern.h>
69 #include <vm/vm_kern.h>
70 #include <vm/vm_map.h>
71 #include <vm/vm_object.h>
72 #include <vm/vm_page2.h>
73 #include <vm/vm_pager.h>
74 #include <vm/vm_param.h>
75 #include <machine/param.h>
76 #include <machine/pmap.h>
77 #if defined(__i386__) || defined(__amd64__)
78 #include <machine/specialreg.h>
80 #include <machine/sysarch.h>
81 #include <sys/endian.h>
84 #include <sys/memrange.h>
85 #include <dev/agp/agpvar.h>
86 #include <sys/agpio.h>
87 #include <sys/mutex.h>
89 MALLOC_DECLARE(M_DRM);
91 #include <uapi_drm/drm.h>
92 #include <uapi_drm/drm_sarea.h>
94 #include <linux/atomic.h>
95 #include <linux/bug.h>
96 #include <linux/err.h>
97 #include <linux/idr.h>
98 #include <linux/pci.h>
99 #include <linux/jiffies.h>
100 #include <linux/kernel.h>
101 #include <linux/kref.h>
102 #include <linux/list.h>
103 #include <linux/mm.h>
104 #include <linux/moduleparam.h>
105 #include <linux/mutex.h>
106 #include <linux/slab.h>
107 #include <linux/scatterlist.h>
108 #include <linux/timer.h>
110 #include <linux/types.h>
111 #include <linux/wait.h>
112 #include <linux/workqueue.h>
114 #include <asm/uaccess.h>
116 #include <drm/drm_vma_manager.h>
121 #include <drm/drm_os_linux.h>
122 #include <drm/drm_hashtab.h>
123 #include <drm/drm_mm.h>
125 #define DRM_UT_CORE 0x01
126 #define DRM_UT_DRIVER 0x02
127 #define DRM_UT_KMS 0x04
128 #define DRM_UT_PRIME 0x08
133 # define DRM_DEBUG_DEFAULT_ON 2
135 # define DRM_DEBUG_DEFAULT_ON 1
138 #endif /* DRM_DEBUG */
140 #define DRM_DEBUGBITS_DEBUG 0x1
141 #define DRM_DEBUGBITS_KMS 0x2
142 #define DRM_DEBUGBITS_FAILED_IOCTL 0x4
143 #define DRM_DEBUGBITS_VERBOSE 0x8
148 /***********************************************************************/
149 /** \name DRM template customization defaults */
152 /* driver capabilities and requirements mask */
153 #define DRIVER_USE_AGP 0x1
154 #define DRIVER_REQUIRE_AGP 0x2
155 #define DRIVER_PCI_DMA 0x8
156 #define DRIVER_SG 0x10
157 #define DRIVER_HAVE_DMA 0x20
158 #define DRIVER_HAVE_IRQ 0x40
159 #define DRIVER_IRQ_SHARED 0x80
160 #define DRIVER_IRQ_VBL 0x100
161 #define DRIVER_DMA_QUEUE 0x200
162 #define DRIVER_FB_DMA 0x400
163 #define DRIVER_IRQ_VBL2 0x800
164 #define DRIVER_GEM 0x1000
165 #define DRIVER_MODESET 0x2000
166 #define DRIVER_PRIME 0x4000
168 /***********************************************************************/
169 /** \name Begin the DRM... */
172 #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
173 #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
174 #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
176 #define DRM_GEM_MAPPING_MASK (3ULL << 62)
177 #define DRM_GEM_MAPPING_KEY (2ULL << 62) /* Non-canonical address form */
178 #define DRM_GEM_MAX_IDX 0x3fffff
179 #define DRM_GEM_MAPPING_IDX(o) (((o) >> 40) & DRM_GEM_MAX_IDX)
180 #define DRM_GEM_MAPPING_OFF(i) (((uint64_t)(i)) << 40)
181 #define DRM_GEM_MAPPING_MAPOFF(o) \
182 ((o) & ~(DRM_GEM_MAPPING_OFF(DRM_GEM_MAX_IDX) | DRM_GEM_MAPPING_KEY))
184 SYSCTL_DECL(_hw_drm);
186 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
188 /***********************************************************************/
189 /** \name Internal types and structures */
192 #define DRM_ARRAY_SIZE(x) NELEM(x)
193 #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
194 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
196 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
198 #define __OS_HAS_AGP 1
200 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
201 #define DRM_DEV_UID 0
202 #define DRM_DEV_GID 0
204 #define DRM_WAKEUP(w) wakeup((void *)w)
205 #define DRM_WAKEUP_INT(w) wakeup(w)
206 #define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0)
208 #define DRM_CURPROC curthread
209 #define DRM_STRUCTPROC struct thread
210 #define DRM_CURRENTPID (curproc != NULL ? curproc->p_pid : -1)
211 #define DRM_LOCK(dev) lockmgr(&(dev)->struct_mutex, LK_EXCLUSIVE)
212 #define DRM_UNLOCK(dev) lockmgr(&(dev)->struct_mutex, LK_RELEASE)
213 #define DRM_LOCK_SLEEP(dev, chan, flags, msg, timeout) \
214 (lksleep((chan), &(dev)->struct_mutex, (flags), (msg), (timeout)))
215 #if defined(INVARIANTS)
216 #define DRM_LOCK_ASSERT(dev) KKASSERT(lockstatus(&(dev)->struct_mutex, curthread) != 0);
217 #define DRM_UNLOCK_ASSERT(dev) KKASSERT(lockstatus(&(dev)->struct_mutex, curthread) == 0);
219 #define DRM_LOCK_ASSERT(d)
220 #define DRM_UNLOCK_ASSERT(d)
223 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
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 #define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1)
239 /* DRM_SUSER returns true if the user is superuser */
240 #define DRM_SUSER(p) (priv_check(p, PRIV_DRIVER) == 0)
241 #define DRM_AGP_FIND_DEVICE() agp_find_device()
242 #define DRM_MTRR_WC MDF_WRITECOMBINE
244 /* DRM_READMEMORYBARRIER() prevents reordering of reads.
245 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
246 * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
248 #define DRM_READMEMORYBARRIER() cpu_lfence()
249 #define DRM_WRITEMEMORYBARRIER() cpu_sfence()
250 #define DRM_MEMORYBARRIER() cpu_mfence()
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 drm_can_sleep() (DRM_HZ & 1)
268 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
269 (_map) = (_dev)->context_sareas[_ctx]; \
272 #define LOCK_TEST_WITH_RETURN(dev, file_priv) \
274 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
275 dev->lock.file_priv != file_priv) { \
276 DRM_ERROR("%s called without lock held\n", \
282 /* Returns -errno to shared code */
283 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
284 for ( ret = 0 ; !ret && !(condition) ; ) { \
286 lwkt_serialize_enter(&dev->irq_lock); \
287 if (!(condition)) { \
288 tsleep_interlock(&(queue), PCATCH); \
289 lwkt_serialize_exit(&dev->irq_lock); \
290 ret = -tsleep(&(queue), PCATCH | PINTERLOCKED, \
291 "drmwtq", (timeout)); \
293 lwkt_serialize_exit(&dev->irq_lock); \
299 vm_page_unhold_pages(vm_page_t *ma, int count)
303 for (i = 0; i < count; i++)
304 vm_page_unhold(ma[i]);
307 int vm_phys_fictitious_reg_range(vm_paddr_t start, vm_paddr_t end,
308 vm_memattr_t memattr);
309 void vm_phys_fictitious_unreg_range(vm_paddr_t start, vm_paddr_t end);
310 vm_page_t vm_phys_fictitious_to_vm_page(vm_paddr_t pa);
312 /***********************************************************************/
313 /** \name Macros to make printk easier */
319 * \param fmt printf() like format string.
320 * \param arg arguments
322 #define DRM_ERROR(fmt, ...) \
323 kprintf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
324 DRM_CURRENTPID, __func__ , ##__VA_ARGS__)
326 #define DRM_INFO(fmt, ...) kprintf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
328 #define DRM_INFO_ONCE(fmt, ...) \
329 printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
331 #define DRM_DEBUG(fmt, ...) do { \
332 if ((drm_debug & DRM_DEBUGBITS_DEBUG) != 0) \
333 kprintf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
334 __func__ , ##__VA_ARGS__); \
337 #define DRM_DEBUG_VERBOSE(fmt, ...) do { \
338 if ((drm_debug & DRM_DEBUGBITS_VERBOSE) != 0) \
339 kprintf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
340 __func__ , ##__VA_ARGS__); \
343 #define DRM_DEBUG_KMS(fmt, ...) do { \
344 if ((drm_debug & DRM_DEBUGBITS_KMS) != 0) \
345 kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\
346 __func__ , ##__VA_ARGS__); \
349 #define DRM_DEBUG_DRIVER(fmt, ...) do { \
350 if ((drm_debug & DRM_DEBUGBITS_KMS) != 0) \
351 kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\
352 __func__ , ##__VA_ARGS__); \
355 #define DRM_LOG_KMS(fmt, ...) do { \
356 kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID, \
357 __func__ , ##__VA_ARGS__); \
360 #define dev_dbg(dev, fmt, ...) do { \
361 if ((drm_debug& DRM_DEBUGBITS_KMS) != 0) { \
362 device_printf((dev), "debug: " fmt, ## __VA_ARGS__); \
366 typedef struct drm_pci_id_list
374 struct drm_msi_blacklist_entry
381 * Ioctl function type.
383 * \param inode device inode.
384 * \param file_priv DRM file private pointer.
385 * \param cmd command.
386 * \param arg argument.
388 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
389 struct drm_file *file_priv);
391 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
394 #define DRM_IOCTL_NR(n) ((n) & 0xff)
397 #define DRM_MASTER 0x2
398 #define DRM_ROOT_ONLY 0x4
399 #define DRM_CONTROL_ALLOW 0x8
400 #define DRM_UNLOCKED 0x10
402 struct drm_ioctl_desc {
404 int (*func)(struct drm_device *dev, void *data,
405 struct drm_file *file_priv);
407 unsigned int cmd_drv;
411 * Creates a driver or general drm_ioctl_desc array entry for the given
412 * ioctl, for use by drm_ioctl().
414 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
415 [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl}
417 typedef struct drm_magic_entry {
418 struct list_head head;
419 struct drm_hash_item hash_item;
420 struct drm_file *priv;
421 struct drm_magic_entry *next;
424 typedef struct drm_magic_head {
425 struct drm_magic_entry *head;
426 struct drm_magic_entry *tail;
429 typedef struct drm_buf {
430 int idx; /**< Index into master buflist */
431 int total; /**< Buffer size */
432 int order; /**< log-base-2(total) */
433 int used; /**< Amount of buffer in use (for DMA) */
434 unsigned long offset; /**< Byte offset (used internally) */
435 void *address; /**< Address of buffer */
436 unsigned long bus_address; /**< Bus address of buffer */
437 struct drm_buf *next; /**< Kernel-only: used for free list */
438 __volatile__ int waiting; /**< On kernel DMA queue */
439 __volatile__ int pending; /**< On hardware DMA queue */
440 struct drm_file *file_priv; /**< Private of holding file descr */
441 int context; /**< Kernel queue for this buffer */
442 int while_locked; /**< Dispatch this buffer while locked */
450 } list; /**< Which list we're on */
452 int dev_priv_size; /**< Size of buffer private storage */
453 void *dev_private; /**< Per-buffer private storage */
456 struct drm_freelist {
457 int initialized; /* Freelist in use */
458 atomic_t count; /* Number of free buffers */
459 drm_buf_t *next; /* End pointer */
461 wait_queue_head_t waiting; /**< Processes waiting on free bufs */
462 int low_mark; /* Low water mark */
463 int high_mark; /* High water mark */
466 typedef struct drm_dma_handle {
474 typedef struct drm_buf_entry {
479 drm_dma_handle_t **seglist;
482 struct drm_freelist freelist;
485 /* Event queued up for userspace to read */
486 struct drm_pending_event {
487 struct drm_event *event;
488 struct list_head link;
489 struct drm_file *file_priv;
490 pid_t pid; /* pid of requester, no guarantee it's valid by the time
491 we deliver the event, for tracing only */
492 void (*destroy)(struct drm_pending_event *event);
495 /* initial implementaton using a linked list - todo hashtab */
496 struct drm_prime_file_private {
497 struct list_head head;
500 #endif /* DUMBBELL_WIP */
503 /** File private data */
506 struct drm_device *dev;
511 unsigned long ioctl_count;
512 struct list_head lhead;
515 /** Mapping of mm object handles to object pointers. */
516 struct idr object_idr;
517 /** Lock for synchronization of access to object_idr. */
518 struct lock table_lock;
523 struct drm_master *masterp;
525 /* true when the client has asked us to expose stereo 3D mode flags */
529 * fbs - List of framebuffers associated with this file.
531 * Protected by fbs_lock. Note that the fbs list holds a reference on
532 * the fb object to prevent it from untimely disappearing.
534 struct list_head fbs;
535 struct lock fbs_lock;
537 wait_queue_head_t event_wait;
538 struct list_head event_list;
541 struct drm_prime_file_private prime;
547 struct drm_lock_data {
548 struct drm_hw_lock *hw_lock; /**< Hardware lock */
549 /** Private of lock holder's file (NULL=kernel) */
550 struct drm_file *file_priv;
551 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
552 unsigned long lock_time; /**< Time of last lock in jiffies */
555 /* This structure, in the struct drm_device, is always initialized while the
557 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
558 * when set marks that no further bufs may be allocated until device teardown
559 * occurs (when the last open of the device has closed). The high/low
560 * watermarks of bufs are only touched by the X Server, and thus not
561 * concurrently accessed, so no locking is needed.
563 typedef struct drm_device_dma {
565 struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
566 int buf_count; /**< total number of buffers */
567 struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
569 int page_count; /**< number of pages */
570 unsigned long *pagelist; /**< page list */
571 unsigned long byte_count;
573 _DRM_DMA_USE_AGP = 0x01,
574 _DRM_DMA_USE_SG = 0x02,
575 _DRM_DMA_USE_FB = 0x04,
576 _DRM_DMA_USE_PCI_RO = 0x08
581 typedef struct drm_agp_mem {
583 unsigned long bound; /* address */
585 struct drm_agp_mem *prev;
586 struct drm_agp_mem *next;
589 typedef struct drm_agp_head {
591 struct agp_info agp_info;
593 drm_agp_mem_t *memory;
599 int cant_use_aperture;
600 unsigned long page_mask;
603 typedef struct drm_sg_mem {
610 * Kernel side of a mapping
612 struct drm_local_map {
613 resource_size_t offset; /**< Requested physical address (0 for SAREA)*/
614 unsigned long size; /**< Requested physical size (bytes) */
615 enum drm_map_type type; /**< Type of memory to map */
616 enum drm_map_flags flags; /**< Flags */
617 void *handle; /**< User-space: "Handle" to pass to mmap() */
618 /**< Kernel-space: kernel-virtual address */
619 int mtrr; /**< MTRR slot used */
622 typedef struct drm_local_map drm_local_map_t;
627 struct drm_map_list {
628 struct list_head head; /**< list head */
629 struct drm_hash_item hash;
630 struct drm_local_map *map; /**< mapping */
632 struct drm_master *master;
633 struct drm_mm_node *file_offset_node; /**< fake offset */
637 * Context handle list
639 struct drm_ctx_list {
640 struct list_head head; /**< list head */
641 drm_context_t handle; /**< context handle */
642 struct drm_file *tag; /**< associated fd private data */
645 struct drm_vblank_info {
646 wait_queue_head_t queue; /* vblank wait queue */
647 atomic_t count; /* number of VBLANK interrupts */
648 /* (driver must alloc the right number of counters) */
649 atomic_t refcount; /* number of users of vblank interrupts */
650 u32 last; /* protected by dev->vbl_lock, used */
651 /* for wraparound handling */
652 int enabled; /* so we don't call enable more than */
653 /* once per disable */
654 int inmodeset; /* Display driver is setting mode */
657 /* location of GART table */
658 #define DRM_ATI_GART_MAIN 1
659 #define DRM_ATI_GART_FB 2
661 #define DRM_ATI_GART_PCI 1
662 #define DRM_ATI_GART_PCIE 2
663 #define DRM_ATI_GART_IGP 3
665 struct drm_ati_pcigart_info {
666 int gart_table_location;
670 dma_addr_t table_mask;
671 dma_addr_t member_mask;
672 struct drm_dma_handle *table_handle;
673 drm_local_map_t mapping;
675 struct drm_dma_handle *dmah; /* handle for ATI PCIGART table */
679 * GEM specific mm private for tracking GEM objects
682 struct drm_vma_offset_manager vma_manager;
683 struct drm_mm offset_manager; /**< Offset mgmt for buffer objects */
684 struct drm_open_hash offset_hash; /**< User token hash table for maps */
685 struct unrhdr *idxunr;
688 struct drm_gem_object {
689 /** Reference count of this object */
690 struct kref refcount;
692 /** Handle count of this object. Each handle also holds a reference */
693 atomic_t handle_count; /* number of handles on this object */
695 /** Related drm device */
696 struct drm_device *dev;
698 /** File representing the shmem storage: filp in Linux parlance */
701 /* Mapping info for this object */
702 struct drm_vma_offset_node vma_node;
704 struct drm_hash_item map_list;
707 * Size of the object, in bytes. Immutable over the object's
713 * Global name for this object, starts at 1. 0 means unnamed.
714 * Access is covered by the object_name_lock in the related drm_device
719 * Memory domains. These monitor which caches contain read/write data
720 * related to the object. When transitioning from one set of domains
721 * to another, the driver is called to ensure that caches are suitably
722 * flushed and invalidated
724 uint32_t read_domains;
725 uint32_t write_domain;
728 * While validating an exec operation, the
729 * new read/write domain values are computed here.
730 * They will be transferred to the above values
731 * at the point that any cache flushing occurs
733 uint32_t pending_read_domains;
734 uint32_t pending_write_domain;
737 /* dma buf exported from this GEM object */
738 struct dma_buf *export_dma_buf;
740 /* dma buf attachment backing this object */
741 struct dma_buf_attachment *import_attach;
742 #endif /* DUMBBELL_WIP */
745 #include "drm_crtc.h"
747 /* per-master structure */
750 struct kref refcount; /* refcount for this master */
752 struct list_head head; /**< each minor contains a list of masters */
753 struct drm_minor *minor; /**< link back to minor we are a master for */
755 char *unique; /**< Unique identifier: e.g., busid */
756 int unique_len; /**< Length of unique field */
757 int unique_size; /**< amount allocated */
759 int blocked; /**< Blocked due to VC switch? */
761 /** \name Authentication */
763 struct drm_open_hash magiclist;
764 struct list_head magicfree;
767 struct drm_lock_data lock; /**< Information on hardware lock */
769 void *driver_priv; /**< Private structure for driver to use */
772 /* Size of ringbuffer for vblank timestamps. Just double-buffer
773 * in initial implementation.
775 #define DRM_VBLANKTIME_RBSIZE 2
777 /* Flags and return codes for get_vblank_timestamp() driver function. */
778 #define DRM_CALLED_FROM_VBLIRQ 1
779 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
780 #define DRM_VBLANKTIME_INVBL (1 << 1)
782 /* get_scanout_position() return flags */
783 #define DRM_SCANOUTPOS_VALID (1 << 0)
784 #define DRM_SCANOUTPOS_INVBL (1 << 1)
785 #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
788 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
791 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
794 int (*load)(struct drm_device *, unsigned long flags);
795 int (*use_msi)(struct drm_device *, unsigned long flags);
796 int (*firstopen)(struct drm_device *);
797 int (*open)(struct drm_device *, struct drm_file *);
798 void (*preclose)(struct drm_device *, struct drm_file *file_priv);
799 void (*postclose)(struct drm_device *, struct drm_file *);
800 void (*lastclose)(struct drm_device *);
801 int (*unload)(struct drm_device *);
802 void (*reclaim_buffers_locked)(struct drm_device *,
803 struct drm_file *file_priv);
804 int (*dma_ioctl)(struct drm_device *dev, void *data,
805 struct drm_file *file_priv);
806 void (*dma_ready)(struct drm_device *);
807 int (*dma_quiescent)(struct drm_device *);
808 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
809 enum drm_lock_flags flags);
810 int (*dma_flush_unblock)(struct drm_device *, int context,
811 enum drm_lock_flags flags);
812 int (*context_ctor)(struct drm_device *dev, int context);
813 int (*context_dtor)(struct drm_device *dev, int context);
814 int (*kernel_context_switch)(struct drm_device *dev, int old,
816 int (*kernel_context_switch_unlock)(struct drm_device *dev);
817 void (*irq_preinstall)(struct drm_device *dev);
818 int (*irq_postinstall)(struct drm_device *dev);
819 void (*irq_uninstall)(struct drm_device *dev);
820 void (*irq_handler)(DRM_IRQ_ARGS);
822 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc);
823 int (*enable_vblank)(struct drm_device *dev, int crtc);
824 void (*disable_vblank)(struct drm_device *dev, int crtc);
827 * Called by vblank timestamping code.
829 * Return the current display scanout position from a crtc, and an
830 * optional accurate ktime_get timestamp of when position was measured.
832 * \param dev DRM device.
833 * \param crtc Id of the crtc to query.
834 * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
835 * \param *vpos Target location for current vertical scanout position.
836 * \param *hpos Target location for current horizontal scanout position.
837 * \param *stime Target location for timestamp taken immediately before
838 * scanout position query. Can be NULL to skip timestamp.
839 * \param *etime Target location for timestamp taken immediately after
840 * scanout position query. Can be NULL to skip timestamp.
842 * Returns vpos as a positive number while in active scanout area.
843 * Returns vpos as a negative number inside vblank, counting the number
844 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
845 * until start of active scanout / end of vblank."
847 * \return Flags, or'ed together as follows:
849 * DRM_SCANOUTPOS_VALID = Query successful.
850 * DRM_SCANOUTPOS_INVBL = Inside vblank.
851 * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
852 * this flag means that returned position may be offset by a constant
853 * but unknown small number of scanlines wrt. real scanout position.
856 int (*get_scanout_position) (struct drm_device *dev, int crtc,
858 int *vpos, int *hpos, ktime_t *stime,
861 int (*get_vblank_timestamp)(struct drm_device *dev, int crtc,
862 int *max_error, struct timeval *vblank_time,
865 void (*gem_free_object)(struct drm_gem_object *obj);
866 int (*gem_open_object)(struct drm_gem_object *, struct drm_file *);
867 void (*gem_close_object)(struct drm_gem_object *, struct drm_file *);
869 struct cdev_pager_ops *gem_pager_ops;
871 int (*dumb_create)(struct drm_file *file_priv,
872 struct drm_device *dev, struct drm_mode_create_dumb *args);
873 int (*dumb_map_offset)(struct drm_file *file_priv,
874 struct drm_device *dev, uint32_t handle, uint64_t *offset);
875 int (*dumb_destroy)(struct drm_file *file_priv,
876 struct drm_device *dev, uint32_t handle);
878 int (*sysctl_init)(struct drm_device *dev,
879 struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
880 void (*sysctl_cleanup)(struct drm_device *dev);
882 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
885 * Called by \c drm_device_is_agp. Typically used to determine if a
886 * card is really attached to AGP or not.
888 * \param dev DRM device handle
891 * One of three values is returned depending on whether or not the
892 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
893 * (return of 1), or may or may not be AGP (return of 2).
895 int (*device_is_agp) (struct drm_device * dev);
902 const char *name; /* Simple driver name */
903 const char *desc; /* Longer driver name */
904 const char *date; /* Date of last major changes. */
908 struct drm_ioctl_desc *ioctls;
913 * DRM minor structure. This structure represents a drm minor number.
916 int index; /**< Minor device number */
917 int type; /**< Control or render */
918 device_t kdev; /**< OS device */
919 struct drm_device *dev;
921 struct drm_master *master; /* currently active master for this node */
922 struct list_head master_list;
923 struct drm_mode_group mode_group;
926 /* mode specified on the command line */
927 struct drm_cmdline_mode {
929 bool refresh_specified;
938 enum drm_connector_force force;
942 struct drm_pending_vblank_event {
943 struct drm_pending_event base;
945 struct drm_event_vblank event;
948 struct drm_sysctl_info {
949 struct sysctl_ctx_list ctx;
953 /* Length for the array of resource pointers for drm_get_resource_*. */
954 #define DRM_MAX_PCI_RESOURCE 6
956 struct drm_vblank_crtc {
957 wait_queue_head_t queue; /**< VBLANK wait queue */
958 struct timeval time[DRM_VBLANKTIME_RBSIZE]; /**< timestamp of current count */
959 atomic_t count; /**< number of VBLANK interrupts */
960 atomic_t refcount; /* number of users of vblank interruptsper crtc */
961 u32 last; /* protected by dev->vbl_lock, used */
962 /* for wraparound handling */
963 u32 last_wait; /* Last vblank seqno waited per CRTC */
964 unsigned int inmodeset; /* Display driver is setting mode */
965 bool enabled; /* so we don't call enable more than
970 * DRM device structure. This structure represent a complete card that
971 * may contain multiple heads.
974 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
976 uint16_t pci_subdevice; /* PCI subsystem device id */
977 uint16_t pci_subvendor; /* PCI subsystem vendor id */
979 char *unique; /* Unique identifier: e.g., busid */
980 int unique_len; /* Length of unique field */
981 struct cdev *devnode; /* Device number for mknod */
982 int if_version; /* Highest interface version set */
984 int flags; /* Flags to open(2) */
987 struct spinlock dma_lock; /* protects dev->dma */
988 struct lwkt_serialize irq_lock; /* protects irq condition checks */
989 struct lock dev_lock; /* protects everything else */
993 struct lock struct_mutex; /**< For others */
996 /** \name Usage Counters */
998 int open_count; /* Outstanding files open */
999 int buf_use; /* Buffers in use -- cannot alloc */
1003 /** \name Performance counters */
1005 unsigned long counters;
1006 enum drm_stat_type types[15];
1007 atomic_t counts[15];
1010 /* Authentication */
1011 struct drm_open_hash magiclist; /**< magic hash table */
1012 struct list_head magicfree;
1014 struct list_head filelist;
1016 /** \name Memory management */
1018 struct list_head maplist; /**< Linked list of regions */
1019 int map_count; /**< Number of mappable regions */
1020 struct drm_open_hash map_hash; /**< User token hash table for maps */
1022 /** \name Context handle management */
1024 struct list_head ctxlist; /**< Linked list of context handles */
1025 int ctx_count; /**< Number of context handles */
1026 struct lock ctxlist_mutex; /**< For ctxlist */
1032 struct drm_lock_data lock; /* Information on hardware lock */
1034 /* DMA queues (contexts) */
1035 drm_device_dma_t *dma; /* Optional pointer for DMA support */
1037 int irq; /* Interrupt used by board */
1038 int irq_type; /* IRQ type (MSI enabled or not) */
1039 int irqrid; /* Interrupt used by board */
1040 struct resource *irqr; /* Resource for interrupt used by board */
1041 void *irqh; /* Handle from bus_setup_intr */
1043 /* Storage of resource pointers for drm_get_resource_* */
1044 struct resource *pcir[DRM_MAX_PCI_RESOURCE];
1045 int pcirid[DRM_MAX_PCI_RESOURCE];
1052 /** \name Context support */
1054 int irq_enabled; /**< True if irq handler is enabled */
1055 __volatile__ long context_flag; /**< Context swapping flag */
1056 __volatile__ long interrupt_flag; /**< Interruption handler flag */
1057 __volatile__ long dma_flag; /**< DMA dispatch flag */
1058 wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
1059 int last_checked; /**< Last context checked for DMA */
1060 int last_context; /**< Last current context */
1061 unsigned long last_switch; /**< jiffies at last context switch */
1064 /** \name VBLANK IRQ support */
1068 * At load time, disabling the vblank interrupt won't be allowed since
1069 * old clients may not call the modeset ioctl and therefore misbehave.
1070 * Once the modeset ioctl *has* been called though, we can safely
1071 * disable them when unused.
1073 bool vblank_disable_allowed;
1075 /* array of size num_crtcs */
1076 struct drm_vblank_crtc *vblank;
1078 struct lock vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
1079 struct lock vbl_lock;
1080 struct timer_list vblank_disable_timer;
1082 u32 max_vblank_count; /**< size of vblank counter register */
1087 struct list_head vblank_event_list;
1088 struct lock event_lock;
1092 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
1094 /* Sysctl support */
1095 struct drm_sysctl_info *sysctl;
1096 int sysctl_node_idx;
1099 drm_sg_mem_t *sg; /* Scatter gather memory */
1100 unsigned int num_crtcs; /**< Number of CRTCs on this device */
1102 unsigned long *ctx_bitmap;
1109 struct drm_agp_head *agp; /**< AGP data */
1111 struct device *dev; /**< Device structure */
1112 struct pci_dev *pdev; /**< PCI device structure */
1113 int pci_vendor; /**< PCI vendor id */
1114 int pci_device; /**< PCI device id */
1116 struct drm_driver *driver;
1117 struct drm_local_map *agp_buffer_map;
1118 unsigned int agp_buffer_token;
1119 struct drm_minor *control; /**< Control node for card */
1120 struct drm_minor *primary; /**< render type primary screen head */
1122 struct drm_mode_config mode_config; /**< Current mode config */
1124 /** \name GEM information */
1126 struct lock object_name_lock;
1127 struct idr object_name_idr;
1131 void *sysctl_private;
1132 char busid_str[128];
1135 int switch_power_state;
1137 atomic_t unplugged; /* device has been unplugged or gone away */
1140 #define DRM_SWITCH_POWER_ON 0
1141 #define DRM_SWITCH_POWER_OFF 1
1142 #define DRM_SWITCH_POWER_CHANGING 2
1144 static __inline__ int drm_core_check_feature(struct drm_device *dev,
1147 return ((dev->driver->driver_features & feature) ? 1 : 0);
1150 static inline int drm_device_is_unplugged(struct drm_device *dev)
1152 int ret = atomic_read(&dev->unplugged);
1158 static inline int drm_core_has_AGP(struct drm_device *dev)
1160 return drm_core_check_feature(dev, DRIVER_USE_AGP);
1163 #define drm_core_has_AGP(dev) (0)
1173 DMI_PRODUCT_VERSION,
1180 DMI_BOARD_ASSET_TAG,
1183 DMI_CHASSIS_VERSION,
1185 DMI_CHASSIS_ASSET_TAG,
1189 struct dmi_strmatch {
1194 struct dmi_system_id {
1195 int (*callback)(const struct dmi_system_id *);
1197 struct dmi_strmatch matches[4];
1199 #define DMI_MATCH(a, b) {(a), (b)}
1200 bool dmi_check_system(const struct dmi_system_id *);
1202 extern int drm_notyet_flag;
1203 extern int drm_debug;
1205 extern unsigned int drm_vblank_offdelay;
1206 extern unsigned int drm_timestamp_precision;
1207 extern unsigned int drm_timestamp_monotonic;
1209 /* Device setup support (drm_drv.c) */
1210 int drm_probe(device_t kdev, drm_pci_id_list_t *idlist);
1211 int drm_attach(device_t kdev, drm_pci_id_list_t *idlist);
1212 int drm_create_cdevs(device_t kdev);
1214 d_ioctl_t drm_ioctl;
1215 extern int drm_lastclose(struct drm_device *dev);
1217 /* Device support (drm_fops.h) */
1218 extern struct lock drm_global_mutex;
1220 d_close_t drm_close;
1222 d_kqfilter_t drm_kqfilter;
1223 int drm_release(device_t kdev);
1226 d_mmap_single_t drm_mmap_single;
1227 extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
1229 void drm_cdevpriv_dtor(void *cd);
1231 void drm_event_wakeup(struct drm_pending_event *e);
1233 int drm_add_busid_modesetting(struct drm_device *dev,
1234 struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
1236 /* File operations helpers (drm_fops.c) */
1237 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
1239 struct drm_device *dev,
1241 extern struct drm_file *drm_find_file_by_proc(struct drm_device *dev,
1245 extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
1246 struct drm_file *file_priv, uint32_t handle, uint32_t flags,
1248 extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
1249 struct drm_file *file_priv, int prime_fd, uint32_t *handle);
1251 extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
1252 struct drm_file *file_priv);
1253 extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
1254 struct drm_file *file_priv);
1256 extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, vm_page_t *pages,
1257 dma_addr_t *addrs, int max_pages);
1258 #endif /* DUMBBELL_WIP */
1259 extern struct sg_table *drm_prime_pages_to_sg(vm_page_t *pages, int nr_pages);
1260 extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1262 int drm_gem_dumb_destroy(struct drm_file *file,
1263 struct drm_device *dev,
1267 void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
1268 void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
1269 int drm_prime_add_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t handle);
1270 int drm_prime_lookup_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t *handle);
1271 void drm_prime_remove_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf);
1273 int drm_prime_add_dma_buf(struct drm_device *dev, struct drm_gem_object *obj);
1274 int drm_prime_lookup_obj(struct drm_device *dev, struct dma_buf *buf,
1275 struct drm_gem_object **obj);
1276 #endif /* DUMBBELL_WIP */
1278 /* Memory management support (drm_memory.h) */
1279 #include <drm/drm_memory.h>
1280 void drm_mem_init(void);
1281 void drm_mem_uninit(void);
1282 void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map);
1283 void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map);
1284 void drm_ioremapfree(drm_local_map_t *map);
1285 int drm_mtrr_add(unsigned long offset, size_t size, int flags);
1286 int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
1288 int drm_ctxbitmap_init(struct drm_device *dev);
1289 void drm_ctxbitmap_cleanup(struct drm_device *dev);
1290 void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
1292 /* Locking IOCTL support (drm_lock.c) */
1293 int drm_lock_take(struct drm_lock_data *lock_data,
1294 unsigned int context);
1295 int drm_lock_transfer(struct drm_lock_data *lock_data,
1296 unsigned int context);
1297 int drm_lock_free(struct drm_lock_data *lock_data,
1298 unsigned int context);
1301 * These are exported to drivers so that they can implement fencing using
1302 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1305 unsigned long drm_get_resource_start(struct drm_device *dev,
1306 unsigned int resource);
1307 unsigned long drm_get_resource_len(struct drm_device *dev,
1308 unsigned int resource);
1309 void drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
1310 int drm_order(unsigned long size);
1311 int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request);
1312 int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request);
1313 extern int drm_addmap(struct drm_device *dev, resource_size_t offset,
1314 unsigned int size, enum drm_map_type type,
1315 enum drm_map_flags flags, struct drm_local_map **map_ptr);
1317 /* DMA support (drm_dma.c) */
1318 int drm_dma_setup(struct drm_device *dev);
1319 void drm_dma_takedown(struct drm_device *dev);
1320 void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf);
1321 void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv);
1322 #define drm_core_reclaim_buffers drm_reclaim_buffers
1324 /* IRQ support (drm_irq.h) */
1325 int drm_irq_install(struct drm_device *dev);
1326 int drm_irq_uninstall(struct drm_device *dev);
1327 void drm_driver_irq_preinstall(struct drm_device *dev);
1328 void drm_driver_irq_postinstall(struct drm_device *dev);
1329 void drm_driver_irq_uninstall(struct drm_device *dev);
1331 extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1332 extern int drm_wait_vblank(struct drm_device *dev, void *data,
1333 struct drm_file *filp);
1334 extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1335 extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
1336 struct timeval *vblanktime);
1337 extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
1338 struct drm_pending_vblank_event *e);
1339 extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
1340 extern int drm_vblank_get(struct drm_device *dev, int crtc);
1341 extern void drm_vblank_put(struct drm_device *dev, int crtc);
1342 extern void drm_vblank_off(struct drm_device *dev, int crtc);
1343 extern void drm_vblank_cleanup(struct drm_device *dev);
1344 extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
1345 struct timeval *tvblank, unsigned flags);
1346 extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
1347 int crtc, int *max_error,
1348 struct timeval *vblank_time,
1350 const struct drm_crtc *refcrtc,
1351 const struct drm_display_mode *mode);
1352 extern void drm_calc_timestamping_constants(struct drm_crtc *crtc,
1353 const struct drm_display_mode *mode);
1355 /* Modesetting support */
1356 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
1357 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
1358 extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1359 struct drm_file *file_priv);
1361 /* AGP/PCI Express/GART support (drm_agpsupport.c) */
1362 int drm_device_is_agp(struct drm_device *dev);
1363 int drm_device_is_pcie(struct drm_device *dev);
1364 drm_agp_head_t *drm_agp_init(void);
1365 int drm_agp_acquire(struct drm_device *dev);
1366 int drm_agp_release(struct drm_device *dev);
1367 int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info);
1368 int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1369 void *drm_agp_allocate_memory(size_t pages, u32 type);
1370 int drm_agp_free_memory(void *handle);
1371 int drm_agp_bind_memory(void *handle, off_t start);
1372 int drm_agp_unbind_memory(void *handle);
1373 int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1374 int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1375 int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1376 int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1378 /* Scatter Gather Support (drm_scatter.c) */
1379 void drm_sg_cleanup(drm_sg_mem_t *entry);
1380 int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
1382 /* sysctl support (drm_sysctl.h) */
1383 extern int drm_sysctl_init(struct drm_device *dev);
1384 extern int drm_sysctl_cleanup(struct drm_device *dev);
1386 /* ATI PCIGART support (ati_pcigart.c) */
1387 int drm_ati_pcigart_init(struct drm_device *dev,
1388 struct drm_ati_pcigart_info *gart_info);
1389 int drm_ati_pcigart_cleanup(struct drm_device *dev,
1390 struct drm_ati_pcigart_info *gart_info);
1392 /* Cache management (drm_memory.c) */
1393 void drm_clflush_pages(vm_page_t *pages, unsigned long num_pages);
1395 /* Locking IOCTL support (drm_drv.c) */
1396 int drm_lock(struct drm_device *dev, void *data,
1397 struct drm_file *file_priv);
1398 int drm_unlock(struct drm_device *dev, void *data,
1399 struct drm_file *file_priv);
1400 int drm_version(struct drm_device *dev, void *data,
1401 struct drm_file *file_priv);
1402 int drm_setversion(struct drm_device *dev, void *data,
1403 struct drm_file *file_priv);
1405 /* Misc. IOCTL support (drm_ioctl.c) */
1406 int drm_irq_by_busid(struct drm_device *dev, void *data,
1407 struct drm_file *file_priv);
1408 int drm_getunique(struct drm_device *dev, void *data,
1409 struct drm_file *file_priv);
1410 int drm_setunique(struct drm_device *dev, void *data,
1411 struct drm_file *file_priv);
1412 int drm_getmap(struct drm_device *dev, void *data,
1413 struct drm_file *file_priv);
1414 int drm_getclient(struct drm_device *dev, void *data,
1415 struct drm_file *file_priv);
1416 int drm_getstats(struct drm_device *dev, void *data,
1417 struct drm_file *file_priv);
1418 int drm_getcap(struct drm_device *dev, void *data,
1419 struct drm_file *file_priv);
1420 extern int drm_setclientcap(struct drm_device *dev, void *data,
1421 struct drm_file *file_priv);
1422 int drm_noop(struct drm_device *dev, void *data,
1423 struct drm_file *file_priv);
1425 /* Context IOCTL support (drm_context.c) */
1426 int drm_resctx(struct drm_device *dev, void *data,
1427 struct drm_file *file_priv);
1428 int drm_addctx(struct drm_device *dev, void *data,
1429 struct drm_file *file_priv);
1430 int drm_getctx(struct drm_device *dev, void *data,
1431 struct drm_file *file_priv);
1432 int drm_switchctx(struct drm_device *dev, void *data,
1433 struct drm_file *file_priv);
1434 int drm_newctx(struct drm_device *dev, void *data,
1435 struct drm_file *file_priv);
1436 int drm_rmctx(struct drm_device *dev, void *data,
1437 struct drm_file *file_priv);
1438 int drm_setsareactx(struct drm_device *dev, void *data,
1439 struct drm_file *file_priv);
1440 int drm_getsareactx(struct drm_device *dev, void *data,
1441 struct drm_file *file_priv);
1443 /* Authentication IOCTL support (drm_auth.c) */
1444 int drm_getmagic(struct drm_device *dev, void *data,
1445 struct drm_file *file_priv);
1446 int drm_authmagic(struct drm_device *dev, void *data,
1447 struct drm_file *file_priv);
1449 /* Cache management (drm_cache.c) */
1450 void drm_clflush_virt_range(char *addr, unsigned long length);
1452 /* Buffer management support (drm_bufs.c) */
1453 int drm_addmap_ioctl(struct drm_device *dev, void *data,
1454 struct drm_file *file_priv);
1455 int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1456 struct drm_file *file_priv);
1457 int drm_addbufs(struct drm_device *dev, void *data,
1458 struct drm_file *file_priv);
1459 int drm_infobufs(struct drm_device *dev, void *data,
1460 struct drm_file *file_priv);
1461 int drm_markbufs(struct drm_device *dev, void *data,
1462 struct drm_file *file_priv);
1463 int drm_freebufs(struct drm_device *dev, void *data,
1464 struct drm_file *file_priv);
1465 int drm_mapbufs(struct drm_device *dev, void *data,
1466 struct drm_file *file_priv);
1468 /* DMA support (drm_dma.c) */
1469 int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv);
1471 /* IRQ support (drm_irq.c) */
1472 int drm_control(struct drm_device *dev, void *data,
1473 struct drm_file *file_priv);
1475 /* AGP/GART support (drm_agpsupport.c) */
1476 int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1477 struct drm_file *file_priv);
1478 int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1479 struct drm_file *file_priv);
1480 int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1481 struct drm_file *file_priv);
1482 int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1483 struct drm_file *file_priv);
1484 int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1485 struct drm_file *file_priv);
1486 int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1487 struct drm_file *file_priv);
1488 int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1489 struct drm_file *file_priv);
1490 int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1491 struct drm_file *file_priv);
1493 /* Stub support (drm_stub.h) */
1494 extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1495 struct drm_file *file_priv);
1496 extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1497 struct drm_file *file_priv);
1499 /* Scatter Gather Support (drm_scatter.c) */
1500 int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1501 struct drm_file *file_priv);
1502 int drm_sg_free(struct drm_device *dev, void *data,
1503 struct drm_file *file_priv);
1505 /* consistent PCI memory functions (drm_pci.c) */
1506 extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1508 void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1510 /* sysfs support (drm_sysfs.c) */
1511 struct drm_sysfs_class;
1512 extern struct class *drm_sysfs_create(struct module *owner, char *name);
1513 extern void drm_sysfs_destroy(void);
1514 extern int drm_sysfs_device_add(struct drm_minor *minor);
1515 extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1516 extern void drm_sysfs_device_remove(struct drm_minor *minor);
1517 extern int drm_sysfs_connector_add(struct drm_connector *connector);
1518 extern void drm_sysfs_connector_remove(struct drm_connector *connector);
1520 /* Graphics Execution Manager library functions (drm_gem.c) */
1521 int drm_gem_init(struct drm_device *dev);
1522 void drm_gem_destroy(struct drm_device *dev);
1523 void drm_gem_object_release(struct drm_gem_object *obj);
1524 void drm_gem_object_free(struct kref *kref);
1525 int drm_gem_object_init(struct drm_device *dev,
1526 struct drm_gem_object *obj, size_t size);
1527 void drm_gem_private_object_init(struct drm_device *dev,
1528 struct drm_gem_object *obj, size_t size);
1530 int i915_gem_pager_ctor(void *handle, vm_ooffset_t size, vm_prot_t prot,
1531 vm_ooffset_t foff, struct ucred *cred, u_short *color);
1532 void i915_gem_pager_dtor(void * handle);
1534 #include <drm/drm_global.h>
1537 drm_gem_object_reference(struct drm_gem_object *obj)
1539 kref_get(&obj->refcount);
1543 drm_gem_object_unreference(struct drm_gem_object *obj)
1546 kref_put(&obj->refcount, drm_gem_object_free);
1550 drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
1553 struct drm_device *dev = obj->dev;
1555 kref_put(&obj->refcount, drm_gem_object_free);
1560 int drm_gem_handle_create(struct drm_file *file_priv,
1561 struct drm_gem_object *obj,
1563 int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
1566 drm_gem_object_handle_reference(struct drm_gem_object *obj)
1568 drm_gem_object_reference(obj);
1569 atomic_inc(&obj->handle_count);
1572 struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1573 struct drm_file *filp,
1575 int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1576 struct drm_file *file_priv);
1577 int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1578 struct drm_file *file_priv);
1579 int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1580 struct drm_file *file_priv);
1581 void drm_gem_open(struct drm_device *dev, struct drm_file *file_priv);
1582 void drm_gem_release(struct drm_device *dev, struct drm_file *file_priv);
1584 void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
1585 int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
1586 int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size);
1588 int drm_gem_mmap_single(struct drm_device *dev, vm_ooffset_t *offset,
1589 vm_size_t size, struct vm_object **obj_res, int nprot);
1590 void drm_gem_pager_dtr(void *obj);
1592 struct ttm_bo_device;
1593 int ttm_bo_mmap_single(struct ttm_bo_device *bdev, vm_ooffset_t *offset,
1594 vm_size_t size, struct vm_object **obj_res, int nprot);
1595 struct ttm_buffer_object;
1596 void ttm_bo_release_mmap(struct ttm_buffer_object *bo);
1598 void drm_device_lock_mtx(struct drm_device *dev);
1599 void drm_device_unlock_mtx(struct drm_device *dev);
1600 int drm_device_sleep_mtx(struct drm_device *dev, void *chan, int flags,
1601 const char *msg, int timeout);
1602 void drm_device_assert_mtx_locked(struct drm_device *dev);
1603 void drm_device_assert_mtx_unlocked(struct drm_device *dev);
1605 void drm_device_lock_struct(struct drm_device *dev);
1606 void drm_device_unlock_struct(struct drm_device *dev);
1607 int drm_device_sleep_struct(struct drm_device *dev, void *chan, int flags,
1608 const char *msg, int timeout);
1609 void drm_device_assert_struct_locked(struct drm_device *dev);
1610 void drm_device_assert_struct_unlocked(struct drm_device *dev);
1612 void drm_compat_locking_init(struct drm_device *dev);
1613 void drm_sleep_locking_init(struct drm_device *dev);
1616 bool drm_mode_parse_command_line_for_connector(const char *mode_option,
1617 struct drm_connector *connector, struct drm_cmdline_mode *mode);
1618 struct drm_display_mode *drm_mode_create_from_cmdline_mode(
1619 struct drm_device *dev, struct drm_cmdline_mode *cmd);
1621 /* Inline replacements for drm_alloc and friends */
1622 static __inline__ void *
1623 drm_alloc(size_t size, struct malloc_type *area)
1625 return kmalloc(size, area, M_WAITOK | M_NULLOK);
1628 static __inline__ void *
1629 drm_calloc(size_t nmemb, size_t size, struct malloc_type *area)
1631 return kmalloc(size * nmemb, area, M_WAITOK | M_NULLOK | M_ZERO);
1634 static __inline__ void
1635 drm_free(void *pt, struct malloc_type *area)
1640 static __inline__ void
1641 drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
1643 map->handle = drm_ioremap_wc(dev, map);
1645 static __inline__ void
1646 drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
1648 map->handle = drm_ioremap(dev, map);
1650 static __inline__ void
1651 drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
1653 if ( map->handle && map->size )
1654 drm_ioremapfree(map);
1657 static __inline__ struct drm_local_map *
1658 drm_core_findmap(struct drm_device *dev, unsigned long offset)
1660 struct drm_map_list *_entry;
1662 list_for_each_entry(_entry, &dev->maplist, head) {
1663 if (offset == (unsigned long)_entry->map->handle)
1669 static __inline__ void drm_core_dropmap(struct drm_map *map)
1673 #include <drm/drm_mem_util.h>
1675 /* FreeBSD compatibility macros */
1676 #define VM_OBJECT_WLOCK(object) VM_OBJECT_LOCK(object)
1677 #define VM_OBJECT_WUNLOCK(object) VM_OBJECT_UNLOCK(object)
1679 #define DRM_PCIE_SPEED_25 1
1680 #define DRM_PCIE_SPEED_50 2
1681 #define DRM_PCIE_SPEED_80 4
1683 extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
1685 #define drm_can_sleep() (DRM_HZ & 1)
1687 #endif /* __KERNEL__ */
1688 #endif /* _DRM_P_H_ */