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>
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/capability.h>
97 #include <linux/err.h>
98 #include <linux/idr.h>
99 #include <linux/pci.h>
100 #include <linux/jiffies.h>
101 #include <linux/kernel.h>
102 #include <linux/kref.h>
103 #include <linux/list.h>
104 #include <linux/mm.h>
105 #include <linux/moduleparam.h>
106 #include <linux/mutex.h>
107 #include <linux/slab.h>
108 #include <linux/scatterlist.h>
109 #include <linux/timer.h>
111 #include <linux/seq_file.h>
112 #include <linux/types.h>
113 #include <linux/wait.h>
114 #include <linux/workqueue.h>
116 #include <asm/uaccess.h>
118 #include <drm/drm_vma_manager.h>
126 #include <drm/drm_os_linux.h>
127 #include <drm/drm_hashtab.h>
128 #include <drm/drm_mm.h>
131 * 4 debug categories are defined:
133 * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
134 * This is the category used by the DRM_DEBUG() macro.
136 * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
137 * This is the category used by the DRM_DEBUG_DRIVER() macro.
139 * KMS: used in the modesetting code.
140 * This is the category used by the DRM_DEBUG_KMS() macro.
142 * PRIME: used in the prime code.
143 * This is the category used by the DRM_DEBUG_PRIME() macro.
145 * Enabling verbose debug messages is done through the drm.debug parameter,
146 * each category being enabled by a bit.
148 * drm.debug=0x1 will enable CORE messages
149 * drm.debug=0x2 will enable DRIVER messages
150 * drm.debug=0x3 will enable CORE and DRIVER messages
152 * drm.debug=0xf will enable all messages
154 * An interesting feature is that it's possible to enable verbose logging at
155 * run-time by echoing the debug value in its sysfs node:
156 * # echo 0xf > /sys/module/drm/parameters/debug
158 #define DRM_UT_CORE 0x01
159 #define DRM_UT_DRIVER 0x02
160 #define DRM_UT_KMS 0x04
161 #define DRM_UT_PRIME 0x08
165 # define DRM_DEBUG_DEFAULT_ON 2
167 # define DRM_DEBUG_DEFAULT_ON 1
170 #endif /* DRM_DEBUG */
172 #define DRM_DEBUGBITS_DEBUG 0x1
173 #define DRM_DEBUGBITS_KMS 0x2
174 #define DRM_DEBUGBITS_FAILED_IOCTL 0x4
175 #define DRM_DEBUGBITS_VERBOSE 0x8
177 void drm_ut_debug_printk(unsigned int request_level,
179 const char *function_name,
180 const char *format, ...);
182 int drm_err(const char *func, const char *format, ...);
184 /***********************************************************************/
185 /** \name DRM template customization defaults */
188 /* driver capabilities and requirements mask */
189 #define DRIVER_USE_AGP 0x1
190 #define DRIVER_REQUIRE_AGP 0x2
191 #define DRIVER_PCI_DMA 0x8
192 #define DRIVER_SG 0x10
193 #define DRIVER_HAVE_DMA 0x20
194 #define DRIVER_HAVE_IRQ 0x40
195 #define DRIVER_IRQ_SHARED 0x80
196 #define DRIVER_DMA_QUEUE 0x200
197 #define DRIVER_GEM 0x1000
198 #define DRIVER_MODESET 0x2000
199 #define DRIVER_PRIME 0x4000
200 #define DRIVER_RENDER 0x8000
202 /***********************************************************************/
203 /** \name Begin the DRM... */
206 #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
207 also include looping detection. */
209 #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
210 #define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
211 #define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
213 #define DRM_MAP_HASH_OFFSET 0x10000000
215 #define DRM_GEM_MAPPING_MASK (3ULL << 62)
216 #define DRM_GEM_MAPPING_KEY (2ULL << 62) /* Non-canonical address form */
217 #define DRM_GEM_MAX_IDX 0x3fffff
218 #define DRM_GEM_MAPPING_IDX(o) (((o) >> 40) & DRM_GEM_MAX_IDX)
219 #define DRM_GEM_MAPPING_OFF(i) (((uint64_t)(i)) << 40)
220 #define DRM_GEM_MAPPING_MAPOFF(o) \
221 ((o) & ~(DRM_GEM_MAPPING_OFF(DRM_GEM_MAX_IDX) | DRM_GEM_MAPPING_KEY))
223 SYSCTL_DECL(_hw_drm);
225 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
227 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
229 #define __OS_HAS_AGP 1
231 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
232 #define DRM_DEV_UID 0
233 #define DRM_DEV_GID 0
235 #define DRM_CURPROC curthread
236 #define DRM_STRUCTPROC struct thread
237 #define DRM_CURRENTPID (curproc != NULL ? curproc->p_pid : -1)
238 #define DRM_LOCK(dev) lockmgr(&(dev)->struct_mutex, LK_EXCLUSIVE)
239 #define DRM_UNLOCK(dev) lockmgr(&(dev)->struct_mutex, LK_RELEASE)
240 #define DRM_LOCK_SLEEP(dev, chan, flags, msg, timeout) \
241 (lksleep((chan), &(dev)->struct_mutex, (flags), (msg), (timeout)))
242 #if defined(INVARIANTS)
243 #define DRM_LOCK_ASSERT(dev) KKASSERT(lockstatus(&(dev)->struct_mutex, curthread) != 0);
244 #define DRM_UNLOCK_ASSERT(dev) KKASSERT(lockstatus(&(dev)->struct_mutex, curthread) == 0);
246 #define DRM_LOCK_ASSERT(d)
247 #define DRM_UNLOCK_ASSERT(d)
250 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
252 typedef void irqreturn_t;
253 #define IRQ_HANDLED /* nothing */
254 #define IRQ_NONE /* nothing */
261 #define DRM_AGP_MEM struct agp_memory_info
263 #define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1)
265 #define DRM_AGP_FIND_DEVICE() agp_find_device()
266 #define DRM_MTRR_WC MDF_WRITECOMBINE
268 #define LOCK_TEST_WITH_RETURN(dev, file_priv) \
270 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
271 dev->lock.file_priv != file_priv) { \
272 DRM_ERROR("%s called without lock held\n", \
278 /* Returns -errno to shared code */
279 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
280 for ( ret = 0 ; !ret && !(condition) ; ) { \
282 lwkt_serialize_enter(&dev->irq_lock); \
283 if (!(condition)) { \
284 tsleep_interlock(&(queue), PCATCH); \
285 lwkt_serialize_exit(&dev->irq_lock); \
286 ret = -tsleep(&(queue), PCATCH | PINTERLOCKED, \
287 "drmwtq", (timeout)); \
289 lwkt_serialize_exit(&dev->irq_lock); \
294 int vm_phys_fictitious_reg_range(vm_paddr_t start, vm_paddr_t end,
295 vm_memattr_t memattr);
296 void vm_phys_fictitious_unreg_range(vm_paddr_t start, vm_paddr_t end);
297 vm_page_t vm_phys_fictitious_to_vm_page(vm_paddr_t pa);
299 /***********************************************************************/
300 /** \name Macros to make printk easier */
306 * \param fmt printf() like format string.
307 * \param arg arguments
309 #define DRM_ERROR(fmt, ...) \
310 kprintf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
311 DRM_CURRENTPID, __func__ , ##__VA_ARGS__)
313 #define DRM_INFO(fmt, ...) kprintf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
315 #define DRM_INFO_ONCE(fmt, ...) \
316 printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
318 #define DRM_DEBUG(fmt, ...) do { \
319 if ((drm_debug & DRM_DEBUGBITS_DEBUG) != 0) \
320 kprintf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
321 __func__ , ##__VA_ARGS__); \
324 #define DRM_DEBUG_VERBOSE(fmt, ...) do { \
325 if ((drm_debug & DRM_DEBUGBITS_VERBOSE) != 0) \
326 kprintf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
327 __func__ , ##__VA_ARGS__); \
330 #define DRM_DEBUG_KMS(fmt, ...) do { \
331 if ((drm_debug & DRM_DEBUGBITS_KMS) != 0) \
332 kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\
333 __func__ , ##__VA_ARGS__); \
336 #define DRM_DEBUG_DRIVER(fmt, ...) do { \
337 if ((drm_debug & DRM_DEBUGBITS_KMS) != 0) \
338 kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\
339 __func__ , ##__VA_ARGS__); \
342 #define DRM_LOG_KMS(fmt, ...) do { \
343 kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID, \
344 __func__ , ##__VA_ARGS__); \
347 #define dev_dbg(dev, fmt, ...) do { \
348 if ((drm_debug& DRM_DEBUGBITS_KMS) != 0) { \
349 device_printf((dev), "debug: " fmt, ## __VA_ARGS__); \
353 typedef struct drm_pci_id_list
361 struct drm_msi_blacklist_entry
368 * Ioctl function type.
370 * \param inode device inode.
371 * \param file_priv DRM file private pointer.
372 * \param cmd command.
373 * \param arg argument.
375 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
376 struct drm_file *file_priv);
378 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
381 #define DRM_IOCTL_NR(n) ((n) & 0xff)
384 #define DRM_MASTER 0x2
385 #define DRM_ROOT_ONLY 0x4
386 #define DRM_CONTROL_ALLOW 0x8
387 #define DRM_UNLOCKED 0x10
388 #define DRM_RENDER_ALLOW 0x20
390 struct drm_ioctl_desc {
394 unsigned int cmd_drv;
399 * Creates a driver or general drm_ioctl_desc array entry for the given
400 * ioctl, for use by drm_ioctl().
402 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
403 [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl}
405 typedef struct drm_magic_entry {
406 struct list_head head;
407 struct drm_hash_item hash_item;
408 struct drm_file *priv;
409 struct drm_magic_entry *next;
412 typedef struct drm_magic_head {
413 struct drm_magic_entry *head;
414 struct drm_magic_entry *tail;
417 typedef struct drm_buf {
418 int idx; /**< Index into master buflist */
419 int total; /**< Buffer size */
420 int order; /**< log-base-2(total) */
421 int used; /**< Amount of buffer in use (for DMA) */
422 unsigned long offset; /**< Byte offset (used internally) */
423 void *address; /**< Address of buffer */
424 unsigned long bus_address; /**< Bus address of buffer */
425 struct drm_buf *next; /**< Kernel-only: used for free list */
426 __volatile__ int waiting; /**< On kernel DMA queue */
427 __volatile__ int pending; /**< On hardware DMA queue */
428 struct drm_file *file_priv; /**< Private of holding file descr */
429 int context; /**< Kernel queue for this buffer */
430 int while_locked; /**< Dispatch this buffer while locked */
438 } list; /**< Which list we're on */
440 int dev_priv_size; /**< Size of buffer private storage */
441 void *dev_private; /**< Per-buffer private storage */
444 /** bufs is one longer than it has to be */
445 struct drm_waitlist {
446 int count; /**< Number of possible buffers */
447 struct drm_buf **bufs; /**< List of pointers to buffers */
448 struct drm_buf **rp; /**< Read pointer */
449 struct drm_buf **wp; /**< Write pointer */
450 struct drm_buf **end; /**< End pointer */
451 spinlock_t read_lock;
452 spinlock_t write_lock;
455 struct drm_freelist {
456 int initialized; /* Freelist in use */
457 atomic_t count; /* Number of free buffers */
458 drm_buf_t *next; /* End pointer */
460 wait_queue_head_t waiting; /**< Processes waiting on free bufs */
461 int low_mark; /* Low water mark */
462 int high_mark; /* High water mark */
465 typedef struct drm_dma_handle {
473 typedef struct drm_buf_entry {
478 drm_dma_handle_t **seglist;
481 struct drm_freelist freelist;
484 /* Event queued up for userspace to read */
485 struct drm_pending_event {
486 struct drm_event *event;
487 struct list_head link;
488 struct drm_file *file_priv;
489 pid_t pid; /* pid of requester, no guarantee it's valid by the time
490 we deliver the event, for tracing only */
491 void (*destroy)(struct drm_pending_event *event);
494 /* initial implementaton using a linked list - todo hashtab */
495 struct drm_prime_file_private {
496 struct list_head head;
499 #endif /* DUMBBELL_WIP */
502 /** File private data */
505 struct drm_device *dev;
508 /* true when the client has asked us to expose stereo 3D mode flags */
511 * true if client understands CRTC primary planes and cursor planes
514 unsigned universal_planes:1;
519 unsigned long ioctl_count;
520 struct list_head lhead;
523 /** Mapping of mm object handles to object pointers. */
524 struct idr object_idr;
525 /** Lock for synchronization of access to object_idr. */
526 struct lock table_lock;
531 struct drm_master *masterp;
534 * fbs - List of framebuffers associated with this file.
536 * Protected by fbs_lock. Note that the fbs list holds a reference on
537 * the fb object to prevent it from untimely disappearing.
539 struct list_head fbs;
540 struct lock fbs_lock;
542 wait_queue_head_t event_wait;
543 struct list_head event_list;
546 struct drm_prime_file_private prime;
551 atomic_t use_count; /**< Outstanding uses (+1) */
552 atomic_t finalization; /**< Finalization in progress */
553 atomic_t block_count; /**< Count of processes waiting */
554 atomic_t block_read; /**< Queue blocked for reads */
555 wait_queue_head_t read_queue; /**< Processes waiting on block_read */
556 atomic_t block_write; /**< Queue blocked for writes */
557 wait_queue_head_t write_queue; /**< Processes waiting on block_write */
558 atomic_t total_queued; /**< Total queued statistic */
559 atomic_t total_flushed; /**< Total flushes statistic */
560 atomic_t total_locks; /**< Total locks statistics */
561 enum drm_ctx_flags flags; /**< Context preserving and 2D-only */
562 struct drm_waitlist waitlist; /**< Pending buffers */
563 wait_queue_head_t flush_queue; /**< Processes waiting until flush */
569 struct drm_lock_data {
570 struct drm_hw_lock *hw_lock; /**< Hardware lock */
571 /** Private of lock holder's file (NULL=kernel) */
572 struct drm_file *file_priv;
573 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
574 unsigned long lock_time; /**< Time of last lock in jiffies */
577 /* This structure, in the struct drm_device, is always initialized while the
579 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
580 * when set marks that no further bufs may be allocated until device teardown
581 * occurs (when the last open of the device has closed). The high/low
582 * watermarks of bufs are only touched by the X Server, and thus not
583 * concurrently accessed, so no locking is needed.
585 typedef struct drm_device_dma {
587 struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
588 int buf_count; /**< total number of buffers */
589 struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
591 int page_count; /**< number of pages */
592 unsigned long *pagelist; /**< page list */
593 unsigned long byte_count;
595 _DRM_DMA_USE_AGP = 0x01,
596 _DRM_DMA_USE_SG = 0x02,
597 _DRM_DMA_USE_FB = 0x04,
598 _DRM_DMA_USE_PCI_RO = 0x08
603 typedef struct drm_agp_mem {
605 unsigned long bound; /* address */
607 struct drm_agp_mem *prev;
608 struct drm_agp_mem *next;
611 typedef struct drm_agp_head {
613 struct agp_info agp_info;
615 drm_agp_mem_t *memory;
621 int cant_use_aperture;
622 unsigned long page_mask;
625 typedef struct drm_sg_mem {
632 * Kernel side of a mapping
634 struct drm_local_map {
635 resource_size_t offset; /**< Requested physical address (0 for SAREA)*/
636 unsigned long size; /**< Requested physical size (bytes) */
637 enum drm_map_type type; /**< Type of memory to map */
638 enum drm_map_flags flags; /**< Flags */
639 void *handle; /**< User-space: "Handle" to pass to mmap() */
640 /**< Kernel-space: kernel-virtual address */
641 int mtrr; /**< MTRR slot used */
644 typedef struct drm_local_map drm_local_map_t;
649 struct drm_map_list {
650 struct list_head head; /**< list head */
651 struct drm_hash_item hash;
652 struct drm_local_map *map; /**< mapping */
654 struct drm_master *master;
655 struct drm_mm_node *file_offset_node; /**< fake offset */
659 * Context handle list
661 struct drm_ctx_list {
662 struct list_head head; /**< list head */
663 drm_context_t handle; /**< context handle */
664 struct drm_file *tag; /**< associated fd private data */
667 /* location of GART table */
668 #define DRM_ATI_GART_MAIN 1
669 #define DRM_ATI_GART_FB 2
671 #define DRM_ATI_GART_PCI 1
672 #define DRM_ATI_GART_PCIE 2
673 #define DRM_ATI_GART_IGP 3
675 struct drm_ati_pcigart_info {
676 int gart_table_location;
680 dma_addr_t table_mask;
681 dma_addr_t member_mask;
682 struct drm_dma_handle *table_handle;
683 drm_local_map_t mapping;
685 struct drm_dma_handle *dmah; /* handle for ATI PCIGART table */
689 * GEM specific mm private for tracking GEM objects
692 struct drm_vma_offset_manager vma_manager;
693 struct drm_mm offset_manager; /**< Offset mgmt for buffer objects */
694 struct drm_open_hash offset_hash; /**< User token hash table for maps */
695 struct unrhdr *idxunr;
698 struct drm_gem_object {
699 /** Reference count of this object */
700 struct kref refcount;
703 * handle_count - gem file_priv handle count of this object
705 * Each handle also holds a reference. Note that when the handle_count
706 * drops to 0 any global names (e.g. the id in the flink namespace) will
709 * Protected by dev->object_name_lock.
711 unsigned handle_count;
713 /** Related drm device */
714 struct drm_device *dev;
716 /** File representing the shmem storage: filp in Linux parlance */
719 /* Mapping info for this object */
720 struct drm_vma_offset_node vma_node;
722 struct drm_hash_item map_list;
725 * Size of the object, in bytes. Immutable over the object's
731 * Global name for this object, starts at 1. 0 means unnamed.
732 * Access is covered by the object_name_lock in the related drm_device
737 * Memory domains. These monitor which caches contain read/write data
738 * related to the object. When transitioning from one set of domains
739 * to another, the driver is called to ensure that caches are suitably
740 * flushed and invalidated
742 uint32_t read_domains;
743 uint32_t write_domain;
746 * While validating an exec operation, the
747 * new read/write domain values are computed here.
748 * They will be transferred to the above values
749 * at the point that any cache flushing occurs
751 uint32_t pending_read_domains;
752 uint32_t pending_write_domain;
755 /* dma buf exported from this GEM object */
756 struct dma_buf *export_dma_buf;
758 /* dma buf attachment backing this object */
759 struct dma_buf_attachment *import_attach;
760 #endif /* DUMBBELL_WIP */
763 #include "drm_crtc.h"
766 * struct drm_master - drm master structure
768 * @refcount: Refcount for this master object.
769 * @minor: Link back to minor char device we are master for. Immutable.
770 * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex.
771 * @unique_len: Length of unique field. Protected by drm_global_mutex.
772 * @unique_size: Amount allocated. Protected by drm_global_mutex.
773 * @magiclist: Hash of used authentication tokens. Protected by struct_mutex.
774 * @magicfree: List of used authentication tokens. Protected by struct_mutex.
775 * @lock: DRI lock information.
776 * @driver_priv: Pointer to driver-private information.
780 struct kref refcount; /* refcount for this master */
782 struct list_head head; /**< each minor contains a list of masters */
783 struct drm_minor *minor; /**< link back to minor we are a master for */
785 char *unique; /**< Unique identifier: e.g., busid */
786 int unique_len; /**< Length of unique field */
787 int unique_size; /**< amount allocated */
789 int blocked; /**< Blocked due to VC switch? */
791 struct drm_open_hash magiclist;
792 struct list_head magicfree;
793 struct drm_lock_data lock;
797 /* Size of ringbuffer for vblank timestamps. Just double-buffer
798 * in initial implementation.
800 #define DRM_VBLANKTIME_RBSIZE 2
802 /* Flags and return codes for get_vblank_timestamp() driver function. */
803 #define DRM_CALLED_FROM_VBLIRQ 1
804 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
805 #define DRM_VBLANKTIME_INVBL (1 << 1)
807 /* get_scanout_position() return flags */
808 #define DRM_SCANOUTPOS_VALID (1 << 0)
809 #define DRM_SCANOUTPOS_INVBL (1 << 1)
810 #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
813 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
816 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
819 * DRM driver structure. This structure represent the common code for
820 * a family of cards. There will one drm_device for each card present
824 int (*load)(struct drm_device *, unsigned long flags);
825 int (*use_msi)(struct drm_device *, unsigned long flags);
826 int (*firstopen)(struct drm_device *);
827 int (*open)(struct drm_device *, struct drm_file *);
828 void (*preclose)(struct drm_device *, struct drm_file *file_priv);
829 void (*postclose)(struct drm_device *, struct drm_file *);
830 void (*lastclose)(struct drm_device *);
831 int (*unload)(struct drm_device *);
832 void (*reclaim_buffers_locked)(struct drm_device *,
833 struct drm_file *file_priv);
834 int (*dma_ioctl)(struct drm_device *dev, void *data,
835 struct drm_file *file_priv);
836 void (*dma_ready)(struct drm_device *);
837 int (*dma_quiescent)(struct drm_device *);
838 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
839 enum drm_lock_flags flags);
840 int (*dma_flush_unblock)(struct drm_device *, int context,
841 enum drm_lock_flags flags);
842 int (*context_ctor)(struct drm_device *dev, int context);
843 int (*context_dtor)(struct drm_device *dev, int context);
844 int (*kernel_context_switch)(struct drm_device *dev, int old,
846 int (*kernel_context_switch_unlock)(struct drm_device *dev);
847 void (*irq_preinstall)(struct drm_device *dev);
848 int (*irq_postinstall)(struct drm_device *dev);
849 void (*irq_uninstall)(struct drm_device *dev);
850 void (*irq_handler)(void *arg);
852 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc);
853 int (*enable_vblank)(struct drm_device *dev, int crtc);
854 void (*disable_vblank)(struct drm_device *dev, int crtc);
857 * Called by vblank timestamping code.
859 * Return the current display scanout position from a crtc, and an
860 * optional accurate ktime_get timestamp of when position was measured.
862 * \param dev DRM device.
863 * \param crtc Id of the crtc to query.
864 * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
865 * \param *vpos Target location for current vertical scanout position.
866 * \param *hpos Target location for current horizontal scanout position.
867 * \param *stime Target location for timestamp taken immediately before
868 * scanout position query. Can be NULL to skip timestamp.
869 * \param *etime Target location for timestamp taken immediately after
870 * scanout position query. Can be NULL to skip timestamp.
872 * Returns vpos as a positive number while in active scanout area.
873 * Returns vpos as a negative number inside vblank, counting the number
874 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
875 * until start of active scanout / end of vblank."
877 * \return Flags, or'ed together as follows:
879 * DRM_SCANOUTPOS_VALID = Query successful.
880 * DRM_SCANOUTPOS_INVBL = Inside vblank.
881 * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
882 * this flag means that returned position may be offset by a constant
883 * but unknown small number of scanlines wrt. real scanout position.
886 int (*get_scanout_position) (struct drm_device *dev, int crtc,
888 int *vpos, int *hpos, ktime_t *stime,
891 int (*get_vblank_timestamp)(struct drm_device *dev, int crtc,
892 int *max_error, struct timeval *vblank_time,
895 void (*gem_free_object)(struct drm_gem_object *obj);
896 int (*gem_open_object)(struct drm_gem_object *, struct drm_file *);
897 void (*gem_close_object)(struct drm_gem_object *, struct drm_file *);
899 struct cdev_pager_ops *gem_pager_ops;
901 int (*dumb_create)(struct drm_file *file_priv,
902 struct drm_device *dev, struct drm_mode_create_dumb *args);
903 int (*dumb_map_offset)(struct drm_file *file_priv,
904 struct drm_device *dev, uint32_t handle, uint64_t *offset);
905 int (*dumb_destroy)(struct drm_file *file_priv,
906 struct drm_device *dev, uint32_t handle);
908 int (*sysctl_init)(struct drm_device *dev,
909 struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
910 void (*sysctl_cleanup)(struct drm_device *dev);
912 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
915 * Called by \c drm_device_is_agp. Typically used to determine if a
916 * card is really attached to AGP or not.
918 * \param dev DRM device handle
921 * One of three values is returned depending on whether or not the
922 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
923 * (return of 1), or may or may not be AGP (return of 2).
925 int (*device_is_agp) (struct drm_device * dev);
930 const char *name; /* Simple driver name */
931 const char *desc; /* Longer driver name */
932 const char *date; /* Date of last major changes. */
936 const struct drm_ioctl_desc *ioctls;
941 * Info file list entry. This structure represents a debugfs or proc file to
942 * be created by the drm core
944 struct drm_info_list {
945 const char *name; /** file name */
946 int (*show)(struct seq_file*, void*); /** show callback */
947 u32 driver_features; /**< Required driver features for this entry */
952 * debugfs node structure. This structure represents a debugfs file.
954 struct drm_info_node {
955 struct list_head list;
956 struct drm_minor *minor;
957 const struct drm_info_list *info_ent;
962 * DRM minor structure. This structure represents a drm minor number.
965 int index; /**< Minor device number */
966 int type; /**< Control or render */
967 device_t kdev; /**< OS device */
968 struct drm_device *dev;
970 struct drm_master *master; /* currently active master for this node */
971 struct list_head master_list;
972 struct drm_mode_group mode_group;
975 struct drm_pending_vblank_event {
976 struct drm_pending_event base;
978 struct drm_event_vblank event;
981 struct drm_sysctl_info {
982 struct sysctl_ctx_list ctx;
986 /* Length for the array of resource pointers for drm_get_resource_*. */
987 #define DRM_MAX_PCI_RESOURCE 6
989 struct drm_vblank_crtc {
990 struct drm_device *dev; /* pointer to the drm_device */
991 wait_queue_head_t queue; /**< VBLANK wait queue */
992 struct timeval time[DRM_VBLANKTIME_RBSIZE]; /**< timestamp of current count */
993 struct timer_list disable_timer; /* delayed disable timer */
994 atomic_t count; /**< number of VBLANK interrupts */
995 atomic_t refcount; /* number of users of vblank interruptsper crtc */
996 u32 last; /* protected by dev->vbl_lock, used */
997 /* for wraparound handling */
998 u32 last_wait; /* Last vblank seqno waited per CRTC */
999 unsigned int inmodeset; /* Display driver is setting mode */
1000 int crtc; /* crtc index */
1001 bool enabled; /* so we don't call enable more than
1006 * DRM device structure. This structure represent a complete card that
1007 * may contain multiple heads.
1010 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
1012 uint16_t pci_subdevice; /* PCI subsystem device id */
1013 uint16_t pci_subvendor; /* PCI subsystem vendor id */
1015 char *unique; /* Unique identifier: e.g., busid */
1016 int unique_len; /* Length of unique field */
1017 struct cdev *devnode; /* Device number for mknod */
1018 int if_version; /* Highest interface version set */
1020 int flags; /* Flags to open(2) */
1023 struct spinlock dma_lock; /* protects dev->dma */
1024 struct lwkt_serialize irq_lock; /* protects irq condition checks */
1025 struct lock dev_lock; /* protects everything else */
1029 struct lock struct_mutex; /**< For others */
1032 /** \name Usage Counters */
1034 int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
1035 int buf_use; /* Buffers in use -- cannot alloc */
1039 /** \name Performance counters */
1041 unsigned long counters;
1042 enum drm_stat_type types[15];
1043 atomic_t counts[15];
1046 /* Authentication */
1047 struct drm_open_hash magiclist; /**< magic hash table */
1048 struct list_head magicfree;
1050 struct list_head filelist;
1052 /** \name Memory management */
1054 struct list_head maplist; /**< Linked list of regions */
1055 int map_count; /**< Number of mappable regions */
1056 struct drm_open_hash map_hash; /**< User token hash table for maps */
1058 /** \name Context handle management */
1060 struct list_head ctxlist; /**< Linked list of context handles */
1061 int ctx_count; /**< Number of context handles */
1062 struct lock ctxlist_mutex; /**< For ctxlist */
1068 struct drm_lock_data lock; /* Information on hardware lock */
1070 /* DMA queues (contexts) */
1071 drm_device_dma_t *dma; /* Optional pointer for DMA support */
1073 int irq; /* Interrupt used by board */
1074 int irq_type; /* IRQ type (MSI enabled or not) */
1075 int irqrid; /* Interrupt used by board */
1076 struct resource *irqr; /* Resource for interrupt used by board */
1077 void *irqh; /* Handle from bus_setup_intr */
1079 /* Storage of resource pointers for drm_get_resource_* */
1080 struct resource *pcir[DRM_MAX_PCI_RESOURCE];
1081 int pcirid[DRM_MAX_PCI_RESOURCE];
1088 /** \name Context support */
1090 int irq_enabled; /**< True if irq handler is enabled */
1091 __volatile__ long context_flag; /**< Context swapping flag */
1092 __volatile__ long interrupt_flag; /**< Interruption handler flag */
1093 __volatile__ long dma_flag; /**< DMA dispatch flag */
1094 wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
1095 int last_checked; /**< Last context checked for DMA */
1096 int last_context; /**< Last current context */
1097 unsigned long last_switch; /**< jiffies at last context switch */
1100 /** \name VBLANK IRQ support */
1104 * At load time, disabling the vblank interrupt won't be allowed since
1105 * old clients may not call the modeset ioctl and therefore misbehave.
1106 * Once the modeset ioctl *has* been called though, we can safely
1107 * disable them when unused.
1109 bool vblank_disable_allowed;
1111 /* array of size num_crtcs */
1112 struct drm_vblank_crtc *vblank;
1114 struct lock vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
1115 struct lock vbl_lock;
1116 struct timer_list vblank_disable_timer;
1118 u32 max_vblank_count; /**< size of vblank counter register */
1123 struct list_head vblank_event_list;
1124 struct lock event_lock;
1128 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
1130 /* Sysctl support */
1131 struct drm_sysctl_info *sysctl;
1132 int sysctl_node_idx;
1135 drm_sg_mem_t *sg; /* Scatter gather memory */
1136 unsigned int num_crtcs; /**< Number of CRTCs on this device */
1138 unsigned long *ctx_bitmap;
1145 struct drm_agp_head *agp; /**< AGP data */
1147 struct device *dev; /**< Device structure */
1148 struct pci_dev *pdev; /**< PCI device structure */
1149 int pci_vendor; /**< PCI vendor id */
1150 int pci_device; /**< PCI device id */
1152 struct drm_driver *driver;
1153 struct drm_local_map *agp_buffer_map;
1154 unsigned int agp_buffer_token;
1155 struct drm_minor *control; /**< Control node for card */
1156 struct drm_minor *primary; /**< render type primary screen head */
1158 struct drm_mode_config mode_config; /**< Current mode config */
1160 /** \name GEM information */
1162 struct lock object_name_lock;
1163 struct idr object_name_idr;
1167 void *sysctl_private;
1168 char busid_str[128];
1171 int switch_power_state;
1173 atomic_t unplugged; /* device has been unplugged or gone away */
1176 #define DRM_SWITCH_POWER_ON 0
1177 #define DRM_SWITCH_POWER_OFF 1
1178 #define DRM_SWITCH_POWER_CHANGING 2
1179 #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
1181 static __inline__ int drm_core_check_feature(struct drm_device *dev,
1184 return ((dev->driver->driver_features & feature) ? 1 : 0);
1187 static inline int drm_device_is_unplugged(struct drm_device *dev)
1189 int ret = atomic_read(&dev->unplugged);
1194 static inline bool drm_is_primary_client(const struct drm_file *file_priv)
1196 return 0 /* file_priv->minor->type == DRM_MINOR_LEGACY */;
1200 static inline int drm_core_has_AGP(struct drm_device *dev)
1202 return drm_core_check_feature(dev, DRIVER_USE_AGP);
1205 #define drm_core_has_AGP(dev) (0)
1208 extern int drm_notyet_flag;
1209 extern unsigned int drm_debug;
1210 extern unsigned int drm_rnodes;
1211 extern unsigned int drm_universal_planes;
1213 extern unsigned int drm_vblank_offdelay;
1214 extern unsigned int drm_timestamp_precision;
1215 extern unsigned int drm_timestamp_monotonic;
1217 /* Device setup support (drm_drv.c) */
1218 int drm_probe(device_t kdev, drm_pci_id_list_t *idlist);
1219 int drm_attach(device_t kdev, drm_pci_id_list_t *idlist);
1220 int drm_create_cdevs(device_t kdev);
1222 d_ioctl_t drm_ioctl;
1223 extern int drm_lastclose(struct drm_device *dev);
1225 /* Device support (drm_fops.h) */
1226 extern struct lock drm_global_mutex;
1228 d_close_t drm_close;
1230 d_kqfilter_t drm_kqfilter;
1231 int drm_release(device_t kdev);
1234 d_mmap_single_t drm_mmap_single;
1235 extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
1237 void drm_cdevpriv_dtor(void *cd);
1239 void drm_event_wakeup(struct drm_pending_event *e);
1241 int drm_add_busid_modesetting(struct drm_device *dev,
1242 struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
1244 /* File operations helpers (drm_fops.c) */
1245 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
1247 struct drm_device *dev,
1249 extern struct drm_file *drm_find_file_by_proc(struct drm_device *dev,
1253 extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
1254 struct drm_file *file_priv, uint32_t handle, uint32_t flags,
1256 extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
1257 struct drm_file *file_priv, int prime_fd, uint32_t *handle);
1259 extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
1260 struct drm_file *file_priv);
1261 extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
1262 struct drm_file *file_priv);
1264 extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, vm_page_t *pages,
1265 dma_addr_t *addrs, int max_pages);
1266 #endif /* DUMBBELL_WIP */
1267 extern struct sg_table *drm_prime_pages_to_sg(vm_page_t *pages, int nr_pages);
1268 extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1270 int drm_gem_dumb_destroy(struct drm_file *file,
1271 struct drm_device *dev,
1275 void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
1276 void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
1277 int drm_prime_add_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t handle);
1278 int drm_prime_lookup_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t *handle);
1279 void drm_prime_remove_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf);
1281 int drm_prime_add_dma_buf(struct drm_device *dev, struct drm_gem_object *obj);
1282 int drm_prime_lookup_obj(struct drm_device *dev, struct dma_buf *buf,
1283 struct drm_gem_object **obj);
1284 #endif /* DUMBBELL_WIP */
1286 /* Memory management support (drm_memory.h) */
1287 #include <drm/drm_memory.h>
1288 void drm_mem_init(void);
1289 void drm_mem_uninit(void);
1290 void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map);
1291 void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map);
1292 void drm_ioremapfree(drm_local_map_t *map);
1293 int drm_mtrr_add(unsigned long offset, size_t size, int flags);
1294 int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
1296 int drm_ctxbitmap_init(struct drm_device *dev);
1297 void drm_ctxbitmap_cleanup(struct drm_device *dev);
1298 void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
1300 /* Locking IOCTL support (drm_lock.c) */
1301 int drm_lock_take(struct drm_lock_data *lock_data,
1302 unsigned int context);
1303 int drm_lock_transfer(struct drm_lock_data *lock_data,
1304 unsigned int context);
1305 int drm_lock_free(struct drm_lock_data *lock_data,
1306 unsigned int context);
1309 * These are exported to drivers so that they can implement fencing using
1310 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1313 unsigned long drm_get_resource_start(struct drm_device *dev,
1314 unsigned int resource);
1315 unsigned long drm_get_resource_len(struct drm_device *dev,
1316 unsigned int resource);
1317 void drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
1318 int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request);
1319 int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request);
1320 extern int drm_addmap(struct drm_device *dev, resource_size_t offset,
1321 unsigned int size, enum drm_map_type type,
1322 enum drm_map_flags flags, struct drm_local_map **map_ptr);
1324 /* DMA support (drm_dma.c) */
1325 int drm_dma_setup(struct drm_device *dev);
1326 void drm_dma_takedown(struct drm_device *dev);
1327 void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf);
1328 void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv);
1329 #define drm_core_reclaim_buffers drm_reclaim_buffers
1331 /* IRQ support (drm_irq.h) */
1332 extern int drm_irq_install(struct drm_device *dev, int irq);
1333 int drm_irq_uninstall(struct drm_device *dev);
1334 void drm_driver_irq_preinstall(struct drm_device *dev);
1335 void drm_driver_irq_postinstall(struct drm_device *dev);
1336 void drm_driver_irq_uninstall(struct drm_device *dev);
1338 extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1339 extern int drm_wait_vblank(struct drm_device *dev, void *data,
1340 struct drm_file *filp);
1341 extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1342 extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
1343 struct timeval *vblanktime);
1344 extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
1345 struct drm_pending_vblank_event *e);
1346 extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
1347 extern int drm_vblank_get(struct drm_device *dev, int crtc);
1348 extern void drm_vblank_put(struct drm_device *dev, int crtc);
1349 extern int drm_crtc_vblank_get(struct drm_crtc *crtc);
1350 extern void drm_crtc_vblank_put(struct drm_crtc *crtc);
1351 extern void drm_vblank_off(struct drm_device *dev, int crtc);
1352 extern void drm_vblank_on(struct drm_device *dev, int crtc);
1353 extern void drm_crtc_vblank_off(struct drm_crtc *crtc);
1354 extern void drm_crtc_vblank_on(struct drm_crtc *crtc);
1355 extern void drm_vblank_cleanup(struct drm_device *dev);
1357 extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
1358 struct timeval *tvblank, unsigned flags);
1359 extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
1360 int crtc, int *max_error,
1361 struct timeval *vblank_time,
1363 const struct drm_crtc *refcrtc,
1364 const struct drm_display_mode *mode);
1365 extern void drm_calc_timestamping_constants(struct drm_crtc *crtc,
1366 const struct drm_display_mode *mode);
1368 /* Modesetting support */
1369 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
1370 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
1371 extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1372 struct drm_file *file_priv);
1374 /* AGP/PCI Express/GART support (drm_agpsupport.c) */
1375 int drm_device_is_agp(struct drm_device *dev);
1376 int drm_device_is_pcie(struct drm_device *dev);
1377 drm_agp_head_t *drm_agp_init(void);
1378 int drm_agp_acquire(struct drm_device *dev);
1379 int drm_agp_release(struct drm_device *dev);
1380 int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info);
1381 int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1382 void *drm_agp_allocate_memory(size_t pages, u32 type);
1383 int drm_agp_free_memory(void *handle);
1384 int drm_agp_bind_memory(void *handle, off_t start);
1385 int drm_agp_unbind_memory(void *handle);
1386 int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1387 int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1388 int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1389 int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1391 /* Scatter Gather Support (drm_scatter.h) */
1392 extern void drm_legacy_sg_cleanup(struct drm_device *dev);
1393 extern int drm_sg_alloc(struct drm_device *dev, void *data,
1394 struct drm_file *file_priv);
1396 /* Scatter Gather Support (drm_scatter.c) */
1397 void drm_sg_cleanup(drm_sg_mem_t *entry);
1399 /* sysctl support (drm_sysctl.h) */
1400 extern int drm_sysctl_init(struct drm_device *dev);
1401 extern int drm_sysctl_cleanup(struct drm_device *dev);
1403 /* ATI PCIGART support (ati_pcigart.c) */
1404 int drm_ati_pcigart_init(struct drm_device *dev,
1405 struct drm_ati_pcigart_info *gart_info);
1406 int drm_ati_pcigart_cleanup(struct drm_device *dev,
1407 struct drm_ati_pcigart_info *gart_info);
1409 /* Cache management (drm_memory.c) */
1410 void drm_clflush_pages(vm_page_t *pages, unsigned long num_pages);
1412 /* Locking IOCTL support (drm_drv.c) */
1413 int drm_lock(struct drm_device *dev, void *data,
1414 struct drm_file *file_priv);
1415 int drm_unlock(struct drm_device *dev, void *data,
1416 struct drm_file *file_priv);
1417 int drm_version(struct drm_device *dev, void *data,
1418 struct drm_file *file_priv);
1419 int drm_setversion(struct drm_device *dev, void *data,
1420 struct drm_file *file_priv);
1422 /* Misc. IOCTL support (drm_ioctl.c) */
1423 int drm_irq_by_busid(struct drm_device *dev, void *data,
1424 struct drm_file *file_priv);
1425 int drm_getunique(struct drm_device *dev, void *data,
1426 struct drm_file *file_priv);
1427 int drm_setunique(struct drm_device *dev, void *data,
1428 struct drm_file *file_priv);
1429 int drm_getmap(struct drm_device *dev, void *data,
1430 struct drm_file *file_priv);
1431 int drm_getclient(struct drm_device *dev, void *data,
1432 struct drm_file *file_priv);
1433 int drm_getstats(struct drm_device *dev, void *data,
1434 struct drm_file *file_priv);
1435 int drm_getcap(struct drm_device *dev, void *data,
1436 struct drm_file *file_priv);
1437 extern int drm_setclientcap(struct drm_device *dev, void *data,
1438 struct drm_file *file_priv);
1439 int drm_noop(struct drm_device *dev, void *data,
1440 struct drm_file *file_priv);
1442 /* Context IOCTL support (drm_context.c) */
1443 int drm_resctx(struct drm_device *dev, void *data,
1444 struct drm_file *file_priv);
1445 int drm_addctx(struct drm_device *dev, void *data,
1446 struct drm_file *file_priv);
1447 int drm_getctx(struct drm_device *dev, void *data,
1448 struct drm_file *file_priv);
1449 int drm_switchctx(struct drm_device *dev, void *data,
1450 struct drm_file *file_priv);
1451 int drm_newctx(struct drm_device *dev, void *data,
1452 struct drm_file *file_priv);
1453 int drm_rmctx(struct drm_device *dev, void *data,
1454 struct drm_file *file_priv);
1455 int drm_setsareactx(struct drm_device *dev, void *data,
1456 struct drm_file *file_priv);
1457 int drm_getsareactx(struct drm_device *dev, void *data,
1458 struct drm_file *file_priv);
1460 /* Authentication IOCTL support (drm_auth.c) */
1461 int drm_getmagic(struct drm_device *dev, void *data,
1462 struct drm_file *file_priv);
1463 int drm_authmagic(struct drm_device *dev, void *data,
1464 struct drm_file *file_priv);
1466 /* Cache management (drm_cache.c) */
1467 void drm_clflush_virt_range(void *addr, unsigned long length);
1469 /* Buffer management support (drm_bufs.c) */
1470 int drm_addmap_ioctl(struct drm_device *dev, void *data,
1471 struct drm_file *file_priv);
1472 int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1473 struct drm_file *file_priv);
1474 int drm_addbufs(struct drm_device *dev, void *data,
1475 struct drm_file *file_priv);
1476 int drm_infobufs(struct drm_device *dev, void *data,
1477 struct drm_file *file_priv);
1478 int drm_markbufs(struct drm_device *dev, void *data,
1479 struct drm_file *file_priv);
1480 int drm_freebufs(struct drm_device *dev, void *data,
1481 struct drm_file *file_priv);
1482 int drm_mapbufs(struct drm_device *dev, void *data,
1483 struct drm_file *file_priv);
1485 /* DMA support (drm_dma.c) */
1486 int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv);
1488 /* IRQ support (drm_irq.c) */
1489 int drm_control(struct drm_device *dev, void *data,
1490 struct drm_file *file_priv);
1492 /* AGP/GART support (drm_agpsupport.c) */
1493 int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1494 struct drm_file *file_priv);
1495 int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1496 struct drm_file *file_priv);
1497 int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1498 struct drm_file *file_priv);
1499 int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1500 struct drm_file *file_priv);
1501 int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1502 struct drm_file *file_priv);
1503 int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1504 struct drm_file *file_priv);
1505 int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1506 struct drm_file *file_priv);
1507 int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1508 struct drm_file *file_priv);
1510 /* Stub support (drm_stub.h) */
1511 extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1512 struct drm_file *file_priv);
1513 extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1514 struct drm_file *file_priv);
1516 /* Scatter Gather Support (drm_scatter.c) */
1517 int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1518 struct drm_file *file_priv);
1519 int drm_sg_free(struct drm_device *dev, void *data,
1520 struct drm_file *file_priv);
1522 /* consistent PCI memory functions (drm_pci.c) */
1523 extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1525 void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1527 /* sysfs support (drm_sysfs.c) */
1528 struct drm_sysfs_class;
1529 extern struct class *drm_sysfs_create(struct module *owner, char *name);
1530 extern void drm_sysfs_destroy(void);
1531 extern int drm_sysfs_device_add(struct drm_minor *minor);
1532 extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1533 extern void drm_sysfs_device_remove(struct drm_minor *minor);
1534 extern int drm_sysfs_connector_add(struct drm_connector *connector);
1535 extern void drm_sysfs_connector_remove(struct drm_connector *connector);
1537 /* Graphics Execution Manager library functions (drm_gem.c) */
1538 int drm_gem_init(struct drm_device *dev);
1539 void drm_gem_destroy(struct drm_device *dev);
1540 void drm_gem_object_release(struct drm_gem_object *obj);
1541 void drm_gem_object_free(struct kref *kref);
1542 int drm_gem_object_init(struct drm_device *dev,
1543 struct drm_gem_object *obj, size_t size);
1544 void drm_gem_private_object_init(struct drm_device *dev,
1545 struct drm_gem_object *obj, size_t size);
1546 void drm_gem_vm_open(struct vm_area_struct *vma);
1547 void drm_gem_vm_close(struct vm_area_struct *vma);
1548 int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
1549 struct vm_area_struct *vma);
1550 int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
1552 int i915_gem_pager_ctor(void *handle, vm_ooffset_t size, vm_prot_t prot,
1553 vm_ooffset_t foff, struct ucred *cred, u_short *color);
1554 void i915_gem_pager_dtor(void * handle);
1556 #include <drm/drm_global.h>
1559 drm_gem_object_reference(struct drm_gem_object *obj)
1561 kref_get(&obj->refcount);
1565 drm_gem_object_unreference(struct drm_gem_object *obj)
1568 kref_put(&obj->refcount, drm_gem_object_free);
1572 drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
1575 struct drm_device *dev = obj->dev;
1577 kref_put(&obj->refcount, drm_gem_object_free);
1582 int drm_gem_handle_create_tail(struct drm_file *file_priv,
1583 struct drm_gem_object *obj,
1585 int drm_gem_handle_create(struct drm_file *file_priv,
1586 struct drm_gem_object *obj,
1588 int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
1590 struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1591 struct drm_file *filp,
1593 int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1594 struct drm_file *file_priv);
1595 int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1596 struct drm_file *file_priv);
1597 int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1598 struct drm_file *file_priv);
1599 void drm_gem_open(struct drm_device *dev, struct drm_file *file_priv);
1600 void drm_gem_release(struct drm_device *dev, struct drm_file *file_priv);
1602 void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
1603 int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
1604 int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size);
1606 int drm_gem_mmap_single(struct drm_device *dev, vm_ooffset_t *offset,
1607 vm_size_t size, struct vm_object **obj_res, int nprot);
1608 void drm_gem_pager_dtr(void *obj);
1610 struct ttm_bo_device;
1611 int ttm_bo_mmap_single(struct ttm_bo_device *bdev, vm_ooffset_t *offset,
1612 vm_size_t size, struct vm_object **obj_res, int nprot);
1613 struct ttm_buffer_object;
1614 void ttm_bo_release_mmap(struct ttm_buffer_object *bo);
1616 void drm_device_lock_mtx(struct drm_device *dev);
1617 void drm_device_unlock_mtx(struct drm_device *dev);
1618 int drm_device_sleep_mtx(struct drm_device *dev, void *chan, int flags,
1619 const char *msg, int timeout);
1620 void drm_device_assert_mtx_locked(struct drm_device *dev);
1621 void drm_device_assert_mtx_unlocked(struct drm_device *dev);
1623 void drm_device_lock_struct(struct drm_device *dev);
1624 void drm_device_unlock_struct(struct drm_device *dev);
1625 int drm_device_sleep_struct(struct drm_device *dev, void *chan, int flags,
1626 const char *msg, int timeout);
1627 void drm_device_assert_struct_locked(struct drm_device *dev);
1628 void drm_device_assert_struct_unlocked(struct drm_device *dev);
1630 void drm_compat_locking_init(struct drm_device *dev);
1631 void drm_sleep_locking_init(struct drm_device *dev);
1633 /* XXX glue logic, should be done in drm_pci_init(), pending drm update */
1634 void drm_init_pdev(struct device *dev, struct pci_dev **pdev);
1635 void drm_fini_pdev(struct pci_dev **pdev);
1637 /* Inline replacements for drm_alloc and friends */
1638 static __inline__ void *
1639 drm_alloc(size_t size, struct malloc_type *area)
1641 return kmalloc(size, area, M_WAITOK | M_NULLOK);
1644 static __inline__ void *
1645 drm_calloc(size_t nmemb, size_t size, struct malloc_type *area)
1647 return kmalloc(size * nmemb, area, M_WAITOK | M_NULLOK | M_ZERO);
1650 static __inline__ void
1651 drm_free(void *pt, struct malloc_type *area)
1656 static __inline__ void
1657 drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
1659 map->handle = drm_ioremap_wc(dev, map);
1661 static __inline__ void
1662 drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
1664 map->handle = drm_ioremap(dev, map);
1666 static __inline__ void
1667 drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
1669 if ( map->handle && map->size )
1670 drm_ioremapfree(map);
1673 static __inline__ struct drm_local_map *
1674 drm_core_findmap(struct drm_device *dev, unsigned long offset)
1676 struct drm_map_list *_entry;
1678 list_for_each_entry(_entry, &dev->maplist, head) {
1679 if (offset == (unsigned long)_entry->map->handle)
1685 static __inline__ void drm_core_dropmap(struct drm_map *map)
1689 #include <drm/drm_mem_util.h>
1691 /* FreeBSD compatibility macros */
1692 #define VM_OBJECT_WLOCK(object) VM_OBJECT_LOCK(object)
1693 #define VM_OBJECT_WUNLOCK(object) VM_OBJECT_UNLOCK(object)
1695 #define DRM_PCIE_SPEED_25 1
1696 #define DRM_PCIE_SPEED_50 2
1697 #define DRM_PCIE_SPEED_80 4
1699 extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
1702 #define drm_can_sleep() (HZ & 1)
1704 #endif /* __KERNEL__ */
1705 #endif /* _DRM_P_H_ */