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/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/seq_file.h>
111 #include <linux/types.h>
112 #include <linux/wait.h>
113 #include <linux/workqueue.h>
115 #include <asm/uaccess.h>
117 #include <drm/drm_vma_manager.h>
125 #include <drm/drm_os_linux.h>
126 #include <drm/drm_hashtab.h>
127 #include <drm/drm_mm.h>
130 * 4 debug categories are defined:
132 * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
133 * This is the category used by the DRM_DEBUG() macro.
135 * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
136 * This is the category used by the DRM_DEBUG_DRIVER() macro.
138 * KMS: used in the modesetting code.
139 * This is the category used by the DRM_DEBUG_KMS() macro.
141 * PRIME: used in the prime code.
142 * This is the category used by the DRM_DEBUG_PRIME() macro.
144 * Enabling verbose debug messages is done through the drm.debug parameter,
145 * each category being enabled by a bit.
147 * drm.debug=0x1 will enable CORE messages
148 * drm.debug=0x2 will enable DRIVER messages
149 * drm.debug=0x3 will enable CORE and DRIVER messages
151 * drm.debug=0xf will enable all messages
153 * An interesting feature is that it's possible to enable verbose logging at
154 * run-time by echoing the debug value in its sysfs node:
155 * # echo 0xf > /sys/module/drm/parameters/debug
157 #define DRM_UT_CORE 0x01
158 #define DRM_UT_DRIVER 0x02
159 #define DRM_UT_KMS 0x04
160 #define DRM_UT_PRIME 0x08
164 # define DRM_DEBUG_DEFAULT_ON 2
166 # define DRM_DEBUG_DEFAULT_ON 1
169 #endif /* DRM_DEBUG */
171 #define DRM_DEBUGBITS_DEBUG 0x1
172 #define DRM_DEBUGBITS_KMS 0x2
173 #define DRM_DEBUGBITS_FAILED_IOCTL 0x4
174 #define DRM_DEBUGBITS_VERBOSE 0x8
176 void drm_ut_debug_printk(unsigned int request_level,
178 const char *function_name,
179 const char *format, ...);
181 int drm_err(const char *func, const char *format, ...);
183 /***********************************************************************/
184 /** \name DRM template customization defaults */
187 /* driver capabilities and requirements mask */
188 #define DRIVER_USE_AGP 0x1
189 #define DRIVER_REQUIRE_AGP 0x2
190 #define DRIVER_PCI_DMA 0x8
191 #define DRIVER_SG 0x10
192 #define DRIVER_HAVE_DMA 0x20
193 #define DRIVER_HAVE_IRQ 0x40
194 #define DRIVER_IRQ_SHARED 0x80
195 #define DRIVER_DMA_QUEUE 0x200
196 #define DRIVER_GEM 0x1000
197 #define DRIVER_MODESET 0x2000
198 #define DRIVER_PRIME 0x4000
199 #define DRIVER_RENDER 0x8000
201 /***********************************************************************/
202 /** \name Begin the DRM... */
205 #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
206 also include looping detection. */
208 #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
209 #define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
210 #define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
212 #define DRM_MAP_HASH_OFFSET 0x10000000
214 #define DRM_GEM_MAPPING_MASK (3ULL << 62)
215 #define DRM_GEM_MAPPING_KEY (2ULL << 62) /* Non-canonical address form */
216 #define DRM_GEM_MAX_IDX 0x3fffff
217 #define DRM_GEM_MAPPING_IDX(o) (((o) >> 40) & DRM_GEM_MAX_IDX)
218 #define DRM_GEM_MAPPING_OFF(i) (((uint64_t)(i)) << 40)
219 #define DRM_GEM_MAPPING_MAPOFF(o) \
220 ((o) & ~(DRM_GEM_MAPPING_OFF(DRM_GEM_MAX_IDX) | DRM_GEM_MAPPING_KEY))
222 SYSCTL_DECL(_hw_drm);
224 #define DRM_ARRAY_SIZE(x) NELEM(x)
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_WAKEUP(w) wakeup((void *)w)
236 #define DRM_WAKEUP_INT(w) wakeup(w)
237 #define DRM_INIT_WAITQUEUE(queue) do {(void)(queue);} while (0)
239 #define DRM_CURPROC curthread
240 #define DRM_STRUCTPROC struct thread
241 #define DRM_CURRENTPID (curproc != NULL ? curproc->p_pid : -1)
242 #define DRM_LOCK(dev) lockmgr(&(dev)->struct_mutex, LK_EXCLUSIVE)
243 #define DRM_UNLOCK(dev) lockmgr(&(dev)->struct_mutex, LK_RELEASE)
244 #define DRM_LOCK_SLEEP(dev, chan, flags, msg, timeout) \
245 (lksleep((chan), &(dev)->struct_mutex, (flags), (msg), (timeout)))
246 #if defined(INVARIANTS)
247 #define DRM_LOCK_ASSERT(dev) KKASSERT(lockstatus(&(dev)->struct_mutex, curthread) != 0);
248 #define DRM_UNLOCK_ASSERT(dev) KKASSERT(lockstatus(&(dev)->struct_mutex, curthread) == 0);
250 #define DRM_LOCK_ASSERT(d)
251 #define DRM_UNLOCK_ASSERT(d)
254 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
256 #define DRM_IRQ_ARGS void *arg
257 typedef void irqreturn_t;
258 #define IRQ_HANDLED /* nothing */
259 #define IRQ_NONE /* nothing */
266 #define DRM_AGP_MEM struct agp_memory_info
268 #define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1)
270 /* DRM_SUSER returns true if the user is superuser */
271 #define DRM_SUSER(p) (priv_check(p, PRIV_DRIVER) == 0)
272 #define DRM_AGP_FIND_DEVICE() agp_find_device()
273 #define DRM_MTRR_WC MDF_WRITECOMBINE
275 /* DRM_READMEMORYBARRIER() prevents reordering of reads.
276 * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
277 * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
279 #define DRM_READMEMORYBARRIER() cpu_lfence()
280 #define DRM_WRITEMEMORYBARRIER() cpu_sfence()
281 #define DRM_MEMORYBARRIER() cpu_mfence()
283 #define DRM_VERIFYAREA_READ( uaddr, size ) \
284 (!useracc(__DECONST(caddr_t, uaddr), size, VM_PROT_READ))
286 #define DRM_COPY_TO_USER(user, kern, size) \
287 copyout(kern, user, size)
288 #define DRM_COPY_FROM_USER(kern, user, size) \
289 copyin(user, kern, size)
290 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
291 copyin(arg2, arg1, arg3)
292 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
293 copyout(arg2, arg1, arg3)
294 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
295 ((val) = fuword32(uaddr), 0)
297 #define drm_can_sleep() (DRM_HZ & 1)
299 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
300 (_map) = (_dev)->context_sareas[_ctx]; \
303 #define LOCK_TEST_WITH_RETURN(dev, file_priv) \
305 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
306 dev->lock.file_priv != file_priv) { \
307 DRM_ERROR("%s called without lock held\n", \
313 /* Returns -errno to shared code */
314 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
315 for ( ret = 0 ; !ret && !(condition) ; ) { \
317 lwkt_serialize_enter(&dev->irq_lock); \
318 if (!(condition)) { \
319 tsleep_interlock(&(queue), PCATCH); \
320 lwkt_serialize_exit(&dev->irq_lock); \
321 ret = -tsleep(&(queue), PCATCH | PINTERLOCKED, \
322 "drmwtq", (timeout)); \
324 lwkt_serialize_exit(&dev->irq_lock); \
329 int vm_phys_fictitious_reg_range(vm_paddr_t start, vm_paddr_t end,
330 vm_memattr_t memattr);
331 void vm_phys_fictitious_unreg_range(vm_paddr_t start, vm_paddr_t end);
332 vm_page_t vm_phys_fictitious_to_vm_page(vm_paddr_t pa);
334 /***********************************************************************/
335 /** \name Macros to make printk easier */
341 * \param fmt printf() like format string.
342 * \param arg arguments
344 #define DRM_ERROR(fmt, ...) \
345 kprintf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
346 DRM_CURRENTPID, __func__ , ##__VA_ARGS__)
348 #define DRM_INFO(fmt, ...) kprintf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
350 #define DRM_INFO_ONCE(fmt, ...) \
351 printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
353 #define DRM_DEBUG(fmt, ...) do { \
354 if ((drm_debug & DRM_DEBUGBITS_DEBUG) != 0) \
355 kprintf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
356 __func__ , ##__VA_ARGS__); \
359 #define DRM_DEBUG_VERBOSE(fmt, ...) do { \
360 if ((drm_debug & DRM_DEBUGBITS_VERBOSE) != 0) \
361 kprintf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
362 __func__ , ##__VA_ARGS__); \
365 #define DRM_DEBUG_KMS(fmt, ...) do { \
366 if ((drm_debug & DRM_DEBUGBITS_KMS) != 0) \
367 kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\
368 __func__ , ##__VA_ARGS__); \
371 #define DRM_DEBUG_DRIVER(fmt, ...) do { \
372 if ((drm_debug & DRM_DEBUGBITS_KMS) != 0) \
373 kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\
374 __func__ , ##__VA_ARGS__); \
377 #define DRM_LOG_KMS(fmt, ...) do { \
378 kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID, \
379 __func__ , ##__VA_ARGS__); \
382 #define dev_dbg(dev, fmt, ...) do { \
383 if ((drm_debug& DRM_DEBUGBITS_KMS) != 0) { \
384 device_printf((dev), "debug: " fmt, ## __VA_ARGS__); \
388 typedef struct drm_pci_id_list
396 struct drm_msi_blacklist_entry
403 * Ioctl function type.
405 * \param inode device inode.
406 * \param file_priv DRM file private pointer.
407 * \param cmd command.
408 * \param arg argument.
410 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
411 struct drm_file *file_priv);
413 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
416 #define DRM_IOCTL_NR(n) ((n) & 0xff)
419 #define DRM_MASTER 0x2
420 #define DRM_ROOT_ONLY 0x4
421 #define DRM_CONTROL_ALLOW 0x8
422 #define DRM_UNLOCKED 0x10
423 #define DRM_RENDER_ALLOW 0x20
425 struct drm_ioctl_desc {
429 unsigned int cmd_drv;
434 * Creates a driver or general drm_ioctl_desc array entry for the given
435 * ioctl, for use by drm_ioctl().
437 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
438 [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl}
440 typedef struct drm_magic_entry {
441 struct list_head head;
442 struct drm_hash_item hash_item;
443 struct drm_file *priv;
444 struct drm_magic_entry *next;
447 typedef struct drm_magic_head {
448 struct drm_magic_entry *head;
449 struct drm_magic_entry *tail;
452 typedef struct drm_buf {
453 int idx; /**< Index into master buflist */
454 int total; /**< Buffer size */
455 int order; /**< log-base-2(total) */
456 int used; /**< Amount of buffer in use (for DMA) */
457 unsigned long offset; /**< Byte offset (used internally) */
458 void *address; /**< Address of buffer */
459 unsigned long bus_address; /**< Bus address of buffer */
460 struct drm_buf *next; /**< Kernel-only: used for free list */
461 __volatile__ int waiting; /**< On kernel DMA queue */
462 __volatile__ int pending; /**< On hardware DMA queue */
463 struct drm_file *file_priv; /**< Private of holding file descr */
464 int context; /**< Kernel queue for this buffer */
465 int while_locked; /**< Dispatch this buffer while locked */
473 } list; /**< Which list we're on */
475 int dev_priv_size; /**< Size of buffer private storage */
476 void *dev_private; /**< Per-buffer private storage */
479 /** bufs is one longer than it has to be */
480 struct drm_waitlist {
481 int count; /**< Number of possible buffers */
482 struct drm_buf **bufs; /**< List of pointers to buffers */
483 struct drm_buf **rp; /**< Read pointer */
484 struct drm_buf **wp; /**< Write pointer */
485 struct drm_buf **end; /**< End pointer */
486 spinlock_t read_lock;
487 spinlock_t write_lock;
490 struct drm_freelist {
491 int initialized; /* Freelist in use */
492 atomic_t count; /* Number of free buffers */
493 drm_buf_t *next; /* End pointer */
495 wait_queue_head_t waiting; /**< Processes waiting on free bufs */
496 int low_mark; /* Low water mark */
497 int high_mark; /* High water mark */
500 typedef struct drm_dma_handle {
508 typedef struct drm_buf_entry {
513 drm_dma_handle_t **seglist;
516 struct drm_freelist freelist;
519 /* Event queued up for userspace to read */
520 struct drm_pending_event {
521 struct drm_event *event;
522 struct list_head link;
523 struct drm_file *file_priv;
524 pid_t pid; /* pid of requester, no guarantee it's valid by the time
525 we deliver the event, for tracing only */
526 void (*destroy)(struct drm_pending_event *event);
529 /* initial implementaton using a linked list - todo hashtab */
530 struct drm_prime_file_private {
531 struct list_head head;
534 #endif /* DUMBBELL_WIP */
537 /** File private data */
540 struct drm_device *dev;
543 /* true when the client has asked us to expose stereo 3D mode flags */
546 * true if client understands CRTC primary planes and cursor planes
549 unsigned universal_planes:1;
554 unsigned long ioctl_count;
555 struct list_head lhead;
558 /** Mapping of mm object handles to object pointers. */
559 struct idr object_idr;
560 /** Lock for synchronization of access to object_idr. */
561 struct lock table_lock;
566 struct drm_master *masterp;
569 * fbs - List of framebuffers associated with this file.
571 * Protected by fbs_lock. Note that the fbs list holds a reference on
572 * the fb object to prevent it from untimely disappearing.
574 struct list_head fbs;
575 struct lock fbs_lock;
577 wait_queue_head_t event_wait;
578 struct list_head event_list;
581 struct drm_prime_file_private prime;
586 atomic_t use_count; /**< Outstanding uses (+1) */
587 atomic_t finalization; /**< Finalization in progress */
588 atomic_t block_count; /**< Count of processes waiting */
589 atomic_t block_read; /**< Queue blocked for reads */
590 wait_queue_head_t read_queue; /**< Processes waiting on block_read */
591 atomic_t block_write; /**< Queue blocked for writes */
592 wait_queue_head_t write_queue; /**< Processes waiting on block_write */
593 atomic_t total_queued; /**< Total queued statistic */
594 atomic_t total_flushed; /**< Total flushes statistic */
595 atomic_t total_locks; /**< Total locks statistics */
596 enum drm_ctx_flags flags; /**< Context preserving and 2D-only */
597 struct drm_waitlist waitlist; /**< Pending buffers */
598 wait_queue_head_t flush_queue; /**< Processes waiting until flush */
604 struct drm_lock_data {
605 struct drm_hw_lock *hw_lock; /**< Hardware lock */
606 /** Private of lock holder's file (NULL=kernel) */
607 struct drm_file *file_priv;
608 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
609 unsigned long lock_time; /**< Time of last lock in jiffies */
612 /* This structure, in the struct drm_device, is always initialized while the
614 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
615 * when set marks that no further bufs may be allocated until device teardown
616 * occurs (when the last open of the device has closed). The high/low
617 * watermarks of bufs are only touched by the X Server, and thus not
618 * concurrently accessed, so no locking is needed.
620 typedef struct drm_device_dma {
622 struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
623 int buf_count; /**< total number of buffers */
624 struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
626 int page_count; /**< number of pages */
627 unsigned long *pagelist; /**< page list */
628 unsigned long byte_count;
630 _DRM_DMA_USE_AGP = 0x01,
631 _DRM_DMA_USE_SG = 0x02,
632 _DRM_DMA_USE_FB = 0x04,
633 _DRM_DMA_USE_PCI_RO = 0x08
638 typedef struct drm_agp_mem {
640 unsigned long bound; /* address */
642 struct drm_agp_mem *prev;
643 struct drm_agp_mem *next;
646 typedef struct drm_agp_head {
648 struct agp_info agp_info;
650 drm_agp_mem_t *memory;
656 int cant_use_aperture;
657 unsigned long page_mask;
660 typedef struct drm_sg_mem {
667 * Kernel side of a mapping
669 struct drm_local_map {
670 resource_size_t offset; /**< Requested physical address (0 for SAREA)*/
671 unsigned long size; /**< Requested physical size (bytes) */
672 enum drm_map_type type; /**< Type of memory to map */
673 enum drm_map_flags flags; /**< Flags */
674 void *handle; /**< User-space: "Handle" to pass to mmap() */
675 /**< Kernel-space: kernel-virtual address */
676 int mtrr; /**< MTRR slot used */
679 typedef struct drm_local_map drm_local_map_t;
684 struct drm_map_list {
685 struct list_head head; /**< list head */
686 struct drm_hash_item hash;
687 struct drm_local_map *map; /**< mapping */
689 struct drm_master *master;
690 struct drm_mm_node *file_offset_node; /**< fake offset */
694 * Context handle list
696 struct drm_ctx_list {
697 struct list_head head; /**< list head */
698 drm_context_t handle; /**< context handle */
699 struct drm_file *tag; /**< associated fd private data */
702 /* location of GART table */
703 #define DRM_ATI_GART_MAIN 1
704 #define DRM_ATI_GART_FB 2
706 #define DRM_ATI_GART_PCI 1
707 #define DRM_ATI_GART_PCIE 2
708 #define DRM_ATI_GART_IGP 3
710 struct drm_ati_pcigart_info {
711 int gart_table_location;
715 dma_addr_t table_mask;
716 dma_addr_t member_mask;
717 struct drm_dma_handle *table_handle;
718 drm_local_map_t mapping;
720 struct drm_dma_handle *dmah; /* handle for ATI PCIGART table */
724 * GEM specific mm private for tracking GEM objects
727 struct drm_vma_offset_manager vma_manager;
728 struct drm_mm offset_manager; /**< Offset mgmt for buffer objects */
729 struct drm_open_hash offset_hash; /**< User token hash table for maps */
730 struct unrhdr *idxunr;
733 struct drm_gem_object {
734 /** Reference count of this object */
735 struct kref refcount;
738 * handle_count - gem file_priv handle count of this object
740 * Each handle also holds a reference. Note that when the handle_count
741 * drops to 0 any global names (e.g. the id in the flink namespace) will
744 * Protected by dev->object_name_lock.
746 unsigned handle_count;
748 /** Related drm device */
749 struct drm_device *dev;
751 /** File representing the shmem storage: filp in Linux parlance */
754 /* Mapping info for this object */
755 struct drm_vma_offset_node vma_node;
757 struct drm_hash_item map_list;
760 * Size of the object, in bytes. Immutable over the object's
766 * Global name for this object, starts at 1. 0 means unnamed.
767 * Access is covered by the object_name_lock in the related drm_device
772 * Memory domains. These monitor which caches contain read/write data
773 * related to the object. When transitioning from one set of domains
774 * to another, the driver is called to ensure that caches are suitably
775 * flushed and invalidated
777 uint32_t read_domains;
778 uint32_t write_domain;
781 * While validating an exec operation, the
782 * new read/write domain values are computed here.
783 * They will be transferred to the above values
784 * at the point that any cache flushing occurs
786 uint32_t pending_read_domains;
787 uint32_t pending_write_domain;
790 /* dma buf exported from this GEM object */
791 struct dma_buf *export_dma_buf;
793 /* dma buf attachment backing this object */
794 struct dma_buf_attachment *import_attach;
795 #endif /* DUMBBELL_WIP */
798 #include "drm_crtc.h"
801 * struct drm_master - drm master structure
803 * @refcount: Refcount for this master object.
804 * @minor: Link back to minor char device we are master for. Immutable.
805 * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex.
806 * @unique_len: Length of unique field. Protected by drm_global_mutex.
807 * @unique_size: Amount allocated. Protected by drm_global_mutex.
808 * @magiclist: Hash of used authentication tokens. Protected by struct_mutex.
809 * @magicfree: List of used authentication tokens. Protected by struct_mutex.
810 * @lock: DRI lock information.
811 * @driver_priv: Pointer to driver-private information.
815 struct kref refcount; /* refcount for this master */
817 struct list_head head; /**< each minor contains a list of masters */
818 struct drm_minor *minor; /**< link back to minor we are a master for */
820 char *unique; /**< Unique identifier: e.g., busid */
821 int unique_len; /**< Length of unique field */
822 int unique_size; /**< amount allocated */
824 int blocked; /**< Blocked due to VC switch? */
826 struct drm_open_hash magiclist;
827 struct list_head magicfree;
828 struct drm_lock_data lock;
832 /* Size of ringbuffer for vblank timestamps. Just double-buffer
833 * in initial implementation.
835 #define DRM_VBLANKTIME_RBSIZE 2
837 /* Flags and return codes for get_vblank_timestamp() driver function. */
838 #define DRM_CALLED_FROM_VBLIRQ 1
839 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
840 #define DRM_VBLANKTIME_INVBL (1 << 1)
842 /* get_scanout_position() return flags */
843 #define DRM_SCANOUTPOS_VALID (1 << 0)
844 #define DRM_SCANOUTPOS_INVBL (1 << 1)
845 #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
848 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
851 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
854 * DRM driver structure. This structure represent the common code for
855 * a family of cards. There will one drm_device for each card present
859 int (*load)(struct drm_device *, unsigned long flags);
860 int (*use_msi)(struct drm_device *, unsigned long flags);
861 int (*firstopen)(struct drm_device *);
862 int (*open)(struct drm_device *, struct drm_file *);
863 void (*preclose)(struct drm_device *, struct drm_file *file_priv);
864 void (*postclose)(struct drm_device *, struct drm_file *);
865 void (*lastclose)(struct drm_device *);
866 int (*unload)(struct drm_device *);
867 void (*reclaim_buffers_locked)(struct drm_device *,
868 struct drm_file *file_priv);
869 int (*dma_ioctl)(struct drm_device *dev, void *data,
870 struct drm_file *file_priv);
871 void (*dma_ready)(struct drm_device *);
872 int (*dma_quiescent)(struct drm_device *);
873 int (*dma_flush_block_and_flush)(struct drm_device *, int context,
874 enum drm_lock_flags flags);
875 int (*dma_flush_unblock)(struct drm_device *, int context,
876 enum drm_lock_flags flags);
877 int (*context_ctor)(struct drm_device *dev, int context);
878 int (*context_dtor)(struct drm_device *dev, int context);
879 int (*kernel_context_switch)(struct drm_device *dev, int old,
881 int (*kernel_context_switch_unlock)(struct drm_device *dev);
882 void (*irq_preinstall)(struct drm_device *dev);
883 int (*irq_postinstall)(struct drm_device *dev);
884 void (*irq_uninstall)(struct drm_device *dev);
885 void (*irq_handler)(DRM_IRQ_ARGS);
887 u32 (*get_vblank_counter)(struct drm_device *dev, int crtc);
888 int (*enable_vblank)(struct drm_device *dev, int crtc);
889 void (*disable_vblank)(struct drm_device *dev, int crtc);
892 * Called by vblank timestamping code.
894 * Return the current display scanout position from a crtc, and an
895 * optional accurate ktime_get timestamp of when position was measured.
897 * \param dev DRM device.
898 * \param crtc Id of the crtc to query.
899 * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
900 * \param *vpos Target location for current vertical scanout position.
901 * \param *hpos Target location for current horizontal scanout position.
902 * \param *stime Target location for timestamp taken immediately before
903 * scanout position query. Can be NULL to skip timestamp.
904 * \param *etime Target location for timestamp taken immediately after
905 * scanout position query. Can be NULL to skip timestamp.
907 * Returns vpos as a positive number while in active scanout area.
908 * Returns vpos as a negative number inside vblank, counting the number
909 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
910 * until start of active scanout / end of vblank."
912 * \return Flags, or'ed together as follows:
914 * DRM_SCANOUTPOS_VALID = Query successful.
915 * DRM_SCANOUTPOS_INVBL = Inside vblank.
916 * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
917 * this flag means that returned position may be offset by a constant
918 * but unknown small number of scanlines wrt. real scanout position.
921 int (*get_scanout_position) (struct drm_device *dev, int crtc,
923 int *vpos, int *hpos, ktime_t *stime,
926 int (*get_vblank_timestamp)(struct drm_device *dev, int crtc,
927 int *max_error, struct timeval *vblank_time,
930 void (*gem_free_object)(struct drm_gem_object *obj);
931 int (*gem_open_object)(struct drm_gem_object *, struct drm_file *);
932 void (*gem_close_object)(struct drm_gem_object *, struct drm_file *);
934 struct cdev_pager_ops *gem_pager_ops;
936 int (*dumb_create)(struct drm_file *file_priv,
937 struct drm_device *dev, struct drm_mode_create_dumb *args);
938 int (*dumb_map_offset)(struct drm_file *file_priv,
939 struct drm_device *dev, uint32_t handle, uint64_t *offset);
940 int (*dumb_destroy)(struct drm_file *file_priv,
941 struct drm_device *dev, uint32_t handle);
943 int (*sysctl_init)(struct drm_device *dev,
944 struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
945 void (*sysctl_cleanup)(struct drm_device *dev);
947 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
950 * Called by \c drm_device_is_agp. Typically used to determine if a
951 * card is really attached to AGP or not.
953 * \param dev DRM device handle
956 * One of three values is returned depending on whether or not the
957 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
958 * (return of 1), or may or may not be AGP (return of 2).
960 int (*device_is_agp) (struct drm_device * dev);
965 const char *name; /* Simple driver name */
966 const char *desc; /* Longer driver name */
967 const char *date; /* Date of last major changes. */
971 const struct drm_ioctl_desc *ioctls;
976 * Info file list entry. This structure represents a debugfs or proc file to
977 * be created by the drm core
979 struct drm_info_list {
980 const char *name; /** file name */
981 int (*show)(struct seq_file*, void*); /** show callback */
982 u32 driver_features; /**< Required driver features for this entry */
987 * debugfs node structure. This structure represents a debugfs file.
989 struct drm_info_node {
990 struct list_head list;
991 struct drm_minor *minor;
992 const struct drm_info_list *info_ent;
997 * DRM minor structure. This structure represents a drm minor number.
1000 int index; /**< Minor device number */
1001 int type; /**< Control or render */
1002 device_t kdev; /**< OS device */
1003 struct drm_device *dev;
1005 struct drm_master *master; /* currently active master for this node */
1006 struct list_head master_list;
1007 struct drm_mode_group mode_group;
1010 struct drm_pending_vblank_event {
1011 struct drm_pending_event base;
1013 struct drm_event_vblank event;
1016 struct drm_sysctl_info {
1017 struct sysctl_ctx_list ctx;
1021 /* Length for the array of resource pointers for drm_get_resource_*. */
1022 #define DRM_MAX_PCI_RESOURCE 6
1024 struct drm_vblank_crtc {
1025 struct drm_device *dev; /* pointer to the drm_device */
1026 wait_queue_head_t queue; /**< VBLANK wait queue */
1027 struct timeval time[DRM_VBLANKTIME_RBSIZE]; /**< timestamp of current count */
1028 struct timer_list disable_timer; /* delayed disable timer */
1029 atomic_t count; /**< number of VBLANK interrupts */
1030 atomic_t refcount; /* number of users of vblank interruptsper crtc */
1031 u32 last; /* protected by dev->vbl_lock, used */
1032 /* for wraparound handling */
1033 u32 last_wait; /* Last vblank seqno waited per CRTC */
1034 unsigned int inmodeset; /* Display driver is setting mode */
1035 int crtc; /* crtc index */
1036 bool enabled; /* so we don't call enable more than
1041 * DRM device structure. This structure represent a complete card that
1042 * may contain multiple heads.
1045 drm_pci_id_list_t *id_entry; /* PCI ID, name, and chipset private */
1047 uint16_t pci_subdevice; /* PCI subsystem device id */
1048 uint16_t pci_subvendor; /* PCI subsystem vendor id */
1050 char *unique; /* Unique identifier: e.g., busid */
1051 int unique_len; /* Length of unique field */
1052 struct cdev *devnode; /* Device number for mknod */
1053 int if_version; /* Highest interface version set */
1055 int flags; /* Flags to open(2) */
1058 struct spinlock dma_lock; /* protects dev->dma */
1059 struct lwkt_serialize irq_lock; /* protects irq condition checks */
1060 struct lock dev_lock; /* protects everything else */
1064 struct lock struct_mutex; /**< For others */
1067 /** \name Usage Counters */
1069 int open_count; /* Outstanding files open */
1070 int buf_use; /* Buffers in use -- cannot alloc */
1074 /** \name Performance counters */
1076 unsigned long counters;
1077 enum drm_stat_type types[15];
1078 atomic_t counts[15];
1081 /* Authentication */
1082 struct drm_open_hash magiclist; /**< magic hash table */
1083 struct list_head magicfree;
1085 struct list_head filelist;
1087 /** \name Memory management */
1089 struct list_head maplist; /**< Linked list of regions */
1090 int map_count; /**< Number of mappable regions */
1091 struct drm_open_hash map_hash; /**< User token hash table for maps */
1093 /** \name Context handle management */
1095 struct list_head ctxlist; /**< Linked list of context handles */
1096 int ctx_count; /**< Number of context handles */
1097 struct lock ctxlist_mutex; /**< For ctxlist */
1103 struct drm_lock_data lock; /* Information on hardware lock */
1105 /* DMA queues (contexts) */
1106 drm_device_dma_t *dma; /* Optional pointer for DMA support */
1108 int irq; /* Interrupt used by board */
1109 int irq_type; /* IRQ type (MSI enabled or not) */
1110 int irqrid; /* Interrupt used by board */
1111 struct resource *irqr; /* Resource for interrupt used by board */
1112 void *irqh; /* Handle from bus_setup_intr */
1114 /* Storage of resource pointers for drm_get_resource_* */
1115 struct resource *pcir[DRM_MAX_PCI_RESOURCE];
1116 int pcirid[DRM_MAX_PCI_RESOURCE];
1123 /** \name Context support */
1125 int irq_enabled; /**< True if irq handler is enabled */
1126 __volatile__ long context_flag; /**< Context swapping flag */
1127 __volatile__ long interrupt_flag; /**< Interruption handler flag */
1128 __volatile__ long dma_flag; /**< DMA dispatch flag */
1129 wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
1130 int last_checked; /**< Last context checked for DMA */
1131 int last_context; /**< Last current context */
1132 unsigned long last_switch; /**< jiffies at last context switch */
1135 /** \name VBLANK IRQ support */
1139 * At load time, disabling the vblank interrupt won't be allowed since
1140 * old clients may not call the modeset ioctl and therefore misbehave.
1141 * Once the modeset ioctl *has* been called though, we can safely
1142 * disable them when unused.
1144 bool vblank_disable_allowed;
1146 /* array of size num_crtcs */
1147 struct drm_vblank_crtc *vblank;
1149 struct lock vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
1150 struct lock vbl_lock;
1151 struct timer_list vblank_disable_timer;
1153 u32 max_vblank_count; /**< size of vblank counter register */
1158 struct list_head vblank_event_list;
1159 struct lock event_lock;
1163 struct sigio *buf_sigio; /* Processes waiting for SIGIO */
1165 /* Sysctl support */
1166 struct drm_sysctl_info *sysctl;
1167 int sysctl_node_idx;
1170 drm_sg_mem_t *sg; /* Scatter gather memory */
1171 unsigned int num_crtcs; /**< Number of CRTCs on this device */
1173 unsigned long *ctx_bitmap;
1180 struct drm_agp_head *agp; /**< AGP data */
1182 struct device *dev; /**< Device structure */
1183 struct pci_dev *pdev; /**< PCI device structure */
1184 int pci_vendor; /**< PCI vendor id */
1185 int pci_device; /**< PCI device id */
1187 struct drm_driver *driver;
1188 struct drm_local_map *agp_buffer_map;
1189 unsigned int agp_buffer_token;
1190 struct drm_minor *control; /**< Control node for card */
1191 struct drm_minor *primary; /**< render type primary screen head */
1193 struct drm_mode_config mode_config; /**< Current mode config */
1195 /** \name GEM information */
1197 struct lock object_name_lock;
1198 struct idr object_name_idr;
1202 void *sysctl_private;
1203 char busid_str[128];
1206 int switch_power_state;
1208 atomic_t unplugged; /* device has been unplugged or gone away */
1211 #define DRM_SWITCH_POWER_ON 0
1212 #define DRM_SWITCH_POWER_OFF 1
1213 #define DRM_SWITCH_POWER_CHANGING 2
1214 #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
1216 static __inline__ int drm_core_check_feature(struct drm_device *dev,
1219 return ((dev->driver->driver_features & feature) ? 1 : 0);
1222 static inline int drm_device_is_unplugged(struct drm_device *dev)
1224 int ret = atomic_read(&dev->unplugged);
1229 static inline bool drm_is_primary_client(const struct drm_file *file_priv)
1231 return 0 /* file_priv->minor->type == DRM_MINOR_LEGACY */;
1235 static inline int drm_core_has_AGP(struct drm_device *dev)
1237 return drm_core_check_feature(dev, DRIVER_USE_AGP);
1240 #define drm_core_has_AGP(dev) (0)
1250 DMI_PRODUCT_VERSION,
1257 DMI_BOARD_ASSET_TAG,
1260 DMI_CHASSIS_VERSION,
1262 DMI_CHASSIS_ASSET_TAG,
1266 struct dmi_strmatch {
1271 struct dmi_system_id {
1272 int (*callback)(const struct dmi_system_id *);
1274 struct dmi_strmatch matches[4];
1276 #define DMI_MATCH(a, b) {(a), (b)}
1277 bool dmi_check_system(const struct dmi_system_id *);
1279 extern int drm_notyet_flag;
1280 extern unsigned int drm_debug;
1281 extern unsigned int drm_rnodes;
1282 extern unsigned int drm_universal_planes;
1284 extern unsigned int drm_vblank_offdelay;
1285 extern unsigned int drm_timestamp_precision;
1286 extern unsigned int drm_timestamp_monotonic;
1288 /* Device setup support (drm_drv.c) */
1289 int drm_probe(device_t kdev, drm_pci_id_list_t *idlist);
1290 int drm_attach(device_t kdev, drm_pci_id_list_t *idlist);
1291 int drm_create_cdevs(device_t kdev);
1293 d_ioctl_t drm_ioctl;
1294 extern int drm_lastclose(struct drm_device *dev);
1296 /* Device support (drm_fops.h) */
1297 extern struct lock drm_global_mutex;
1299 d_close_t drm_close;
1301 d_kqfilter_t drm_kqfilter;
1302 int drm_release(device_t kdev);
1305 d_mmap_single_t drm_mmap_single;
1306 extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
1308 void drm_cdevpriv_dtor(void *cd);
1310 void drm_event_wakeup(struct drm_pending_event *e);
1312 int drm_add_busid_modesetting(struct drm_device *dev,
1313 struct sysctl_ctx_list *ctx, struct sysctl_oid *top);
1315 /* File operations helpers (drm_fops.c) */
1316 extern int drm_open_helper(struct cdev *kdev, int flags, int fmt,
1318 struct drm_device *dev,
1320 extern struct drm_file *drm_find_file_by_proc(struct drm_device *dev,
1324 extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
1325 struct drm_file *file_priv, uint32_t handle, uint32_t flags,
1327 extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
1328 struct drm_file *file_priv, int prime_fd, uint32_t *handle);
1330 extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
1331 struct drm_file *file_priv);
1332 extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
1333 struct drm_file *file_priv);
1335 extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, vm_page_t *pages,
1336 dma_addr_t *addrs, int max_pages);
1337 #endif /* DUMBBELL_WIP */
1338 extern struct sg_table *drm_prime_pages_to_sg(vm_page_t *pages, int nr_pages);
1339 extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1341 int drm_gem_dumb_destroy(struct drm_file *file,
1342 struct drm_device *dev,
1346 void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
1347 void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
1348 int drm_prime_add_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t handle);
1349 int drm_prime_lookup_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t *handle);
1350 void drm_prime_remove_imported_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf);
1352 int drm_prime_add_dma_buf(struct drm_device *dev, struct drm_gem_object *obj);
1353 int drm_prime_lookup_obj(struct drm_device *dev, struct dma_buf *buf,
1354 struct drm_gem_object **obj);
1355 #endif /* DUMBBELL_WIP */
1357 /* Memory management support (drm_memory.h) */
1358 #include <drm/drm_memory.h>
1359 void drm_mem_init(void);
1360 void drm_mem_uninit(void);
1361 void *drm_ioremap_wc(struct drm_device *dev, drm_local_map_t *map);
1362 void *drm_ioremap(struct drm_device *dev, drm_local_map_t *map);
1363 void drm_ioremapfree(drm_local_map_t *map);
1364 int drm_mtrr_add(unsigned long offset, size_t size, int flags);
1365 int drm_mtrr_del(int handle, unsigned long offset, size_t size, int flags);
1367 int drm_ctxbitmap_init(struct drm_device *dev);
1368 void drm_ctxbitmap_cleanup(struct drm_device *dev);
1369 void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
1371 /* Locking IOCTL support (drm_lock.c) */
1372 int drm_lock_take(struct drm_lock_data *lock_data,
1373 unsigned int context);
1374 int drm_lock_transfer(struct drm_lock_data *lock_data,
1375 unsigned int context);
1376 int drm_lock_free(struct drm_lock_data *lock_data,
1377 unsigned int context);
1380 * These are exported to drivers so that they can implement fencing using
1381 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1384 unsigned long drm_get_resource_start(struct drm_device *dev,
1385 unsigned int resource);
1386 unsigned long drm_get_resource_len(struct drm_device *dev,
1387 unsigned int resource);
1388 void drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
1389 int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc *request);
1390 int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc *request);
1391 extern int drm_addmap(struct drm_device *dev, resource_size_t offset,
1392 unsigned int size, enum drm_map_type type,
1393 enum drm_map_flags flags, struct drm_local_map **map_ptr);
1395 /* DMA support (drm_dma.c) */
1396 int drm_dma_setup(struct drm_device *dev);
1397 void drm_dma_takedown(struct drm_device *dev);
1398 void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf);
1399 void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv);
1400 #define drm_core_reclaim_buffers drm_reclaim_buffers
1402 /* IRQ support (drm_irq.h) */
1403 extern int drm_irq_install(struct drm_device *dev, int irq);
1404 int drm_irq_uninstall(struct drm_device *dev);
1405 void drm_driver_irq_preinstall(struct drm_device *dev);
1406 void drm_driver_irq_postinstall(struct drm_device *dev);
1407 void drm_driver_irq_uninstall(struct drm_device *dev);
1409 extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1410 extern int drm_wait_vblank(struct drm_device *dev, void *data,
1411 struct drm_file *filp);
1412 extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1413 extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
1414 struct timeval *vblanktime);
1415 extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
1416 struct drm_pending_vblank_event *e);
1417 extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
1418 extern int drm_vblank_get(struct drm_device *dev, int crtc);
1419 extern void drm_vblank_put(struct drm_device *dev, int crtc);
1420 extern int drm_crtc_vblank_get(struct drm_crtc *crtc);
1421 extern void drm_crtc_vblank_put(struct drm_crtc *crtc);
1422 extern void drm_vblank_off(struct drm_device *dev, int crtc);
1423 extern void drm_vblank_on(struct drm_device *dev, int crtc);
1424 extern void drm_crtc_vblank_off(struct drm_crtc *crtc);
1425 extern void drm_crtc_vblank_on(struct drm_crtc *crtc);
1426 extern void drm_vblank_cleanup(struct drm_device *dev);
1428 extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
1429 struct timeval *tvblank, unsigned flags);
1430 extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
1431 int crtc, int *max_error,
1432 struct timeval *vblank_time,
1434 const struct drm_crtc *refcrtc,
1435 const struct drm_display_mode *mode);
1436 extern void drm_calc_timestamping_constants(struct drm_crtc *crtc,
1437 const struct drm_display_mode *mode);
1439 /* Modesetting support */
1440 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
1441 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
1442 extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1443 struct drm_file *file_priv);
1445 /* AGP/PCI Express/GART support (drm_agpsupport.c) */
1446 int drm_device_is_agp(struct drm_device *dev);
1447 int drm_device_is_pcie(struct drm_device *dev);
1448 drm_agp_head_t *drm_agp_init(void);
1449 int drm_agp_acquire(struct drm_device *dev);
1450 int drm_agp_release(struct drm_device *dev);
1451 int drm_agp_info(struct drm_device * dev, struct drm_agp_info *info);
1452 int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1453 void *drm_agp_allocate_memory(size_t pages, u32 type);
1454 int drm_agp_free_memory(void *handle);
1455 int drm_agp_bind_memory(void *handle, off_t start);
1456 int drm_agp_unbind_memory(void *handle);
1457 int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1458 int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1459 int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1460 int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1462 /* Scatter Gather Support (drm_scatter.h) */
1463 extern void drm_legacy_sg_cleanup(struct drm_device *dev);
1464 extern int drm_sg_alloc(struct drm_device *dev, void *data,
1465 struct drm_file *file_priv);
1467 /* Scatter Gather Support (drm_scatter.c) */
1468 void drm_sg_cleanup(drm_sg_mem_t *entry);
1470 /* sysctl support (drm_sysctl.h) */
1471 extern int drm_sysctl_init(struct drm_device *dev);
1472 extern int drm_sysctl_cleanup(struct drm_device *dev);
1474 /* ATI PCIGART support (ati_pcigart.c) */
1475 int drm_ati_pcigart_init(struct drm_device *dev,
1476 struct drm_ati_pcigart_info *gart_info);
1477 int drm_ati_pcigart_cleanup(struct drm_device *dev,
1478 struct drm_ati_pcigart_info *gart_info);
1480 /* Cache management (drm_memory.c) */
1481 void drm_clflush_pages(vm_page_t *pages, unsigned long num_pages);
1483 /* Locking IOCTL support (drm_drv.c) */
1484 int drm_lock(struct drm_device *dev, void *data,
1485 struct drm_file *file_priv);
1486 int drm_unlock(struct drm_device *dev, void *data,
1487 struct drm_file *file_priv);
1488 int drm_version(struct drm_device *dev, void *data,
1489 struct drm_file *file_priv);
1490 int drm_setversion(struct drm_device *dev, void *data,
1491 struct drm_file *file_priv);
1493 /* Misc. IOCTL support (drm_ioctl.c) */
1494 int drm_irq_by_busid(struct drm_device *dev, void *data,
1495 struct drm_file *file_priv);
1496 int drm_getunique(struct drm_device *dev, void *data,
1497 struct drm_file *file_priv);
1498 int drm_setunique(struct drm_device *dev, void *data,
1499 struct drm_file *file_priv);
1500 int drm_getmap(struct drm_device *dev, void *data,
1501 struct drm_file *file_priv);
1502 int drm_getclient(struct drm_device *dev, void *data,
1503 struct drm_file *file_priv);
1504 int drm_getstats(struct drm_device *dev, void *data,
1505 struct drm_file *file_priv);
1506 int drm_getcap(struct drm_device *dev, void *data,
1507 struct drm_file *file_priv);
1508 extern int drm_setclientcap(struct drm_device *dev, void *data,
1509 struct drm_file *file_priv);
1510 int drm_noop(struct drm_device *dev, void *data,
1511 struct drm_file *file_priv);
1513 /* Context IOCTL support (drm_context.c) */
1514 int drm_resctx(struct drm_device *dev, void *data,
1515 struct drm_file *file_priv);
1516 int drm_addctx(struct drm_device *dev, void *data,
1517 struct drm_file *file_priv);
1518 int drm_getctx(struct drm_device *dev, void *data,
1519 struct drm_file *file_priv);
1520 int drm_switchctx(struct drm_device *dev, void *data,
1521 struct drm_file *file_priv);
1522 int drm_newctx(struct drm_device *dev, void *data,
1523 struct drm_file *file_priv);
1524 int drm_rmctx(struct drm_device *dev, void *data,
1525 struct drm_file *file_priv);
1526 int drm_setsareactx(struct drm_device *dev, void *data,
1527 struct drm_file *file_priv);
1528 int drm_getsareactx(struct drm_device *dev, void *data,
1529 struct drm_file *file_priv);
1531 /* Authentication IOCTL support (drm_auth.c) */
1532 int drm_getmagic(struct drm_device *dev, void *data,
1533 struct drm_file *file_priv);
1534 int drm_authmagic(struct drm_device *dev, void *data,
1535 struct drm_file *file_priv);
1537 /* Cache management (drm_cache.c) */
1538 void drm_clflush_virt_range(void *addr, unsigned long length);
1540 /* Buffer management support (drm_bufs.c) */
1541 int drm_addmap_ioctl(struct drm_device *dev, void *data,
1542 struct drm_file *file_priv);
1543 int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1544 struct drm_file *file_priv);
1545 int drm_addbufs(struct drm_device *dev, void *data,
1546 struct drm_file *file_priv);
1547 int drm_infobufs(struct drm_device *dev, void *data,
1548 struct drm_file *file_priv);
1549 int drm_markbufs(struct drm_device *dev, void *data,
1550 struct drm_file *file_priv);
1551 int drm_freebufs(struct drm_device *dev, void *data,
1552 struct drm_file *file_priv);
1553 int drm_mapbufs(struct drm_device *dev, void *data,
1554 struct drm_file *file_priv);
1556 /* DMA support (drm_dma.c) */
1557 int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv);
1559 /* IRQ support (drm_irq.c) */
1560 int drm_control(struct drm_device *dev, void *data,
1561 struct drm_file *file_priv);
1563 /* AGP/GART support (drm_agpsupport.c) */
1564 int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1565 struct drm_file *file_priv);
1566 int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1567 struct drm_file *file_priv);
1568 int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1569 struct drm_file *file_priv);
1570 int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1571 struct drm_file *file_priv);
1572 int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1573 struct drm_file *file_priv);
1574 int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1575 struct drm_file *file_priv);
1576 int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1577 struct drm_file *file_priv);
1578 int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1579 struct drm_file *file_priv);
1581 /* Stub support (drm_stub.h) */
1582 extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1583 struct drm_file *file_priv);
1584 extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1585 struct drm_file *file_priv);
1587 /* Scatter Gather Support (drm_scatter.c) */
1588 int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1589 struct drm_file *file_priv);
1590 int drm_sg_free(struct drm_device *dev, void *data,
1591 struct drm_file *file_priv);
1593 /* consistent PCI memory functions (drm_pci.c) */
1594 extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1596 void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1598 /* sysfs support (drm_sysfs.c) */
1599 struct drm_sysfs_class;
1600 extern struct class *drm_sysfs_create(struct module *owner, char *name);
1601 extern void drm_sysfs_destroy(void);
1602 extern int drm_sysfs_device_add(struct drm_minor *minor);
1603 extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1604 extern void drm_sysfs_device_remove(struct drm_minor *minor);
1605 extern int drm_sysfs_connector_add(struct drm_connector *connector);
1606 extern void drm_sysfs_connector_remove(struct drm_connector *connector);
1608 /* Graphics Execution Manager library functions (drm_gem.c) */
1609 int drm_gem_init(struct drm_device *dev);
1610 void drm_gem_destroy(struct drm_device *dev);
1611 void drm_gem_object_release(struct drm_gem_object *obj);
1612 void drm_gem_object_free(struct kref *kref);
1613 int drm_gem_object_init(struct drm_device *dev,
1614 struct drm_gem_object *obj, size_t size);
1615 void drm_gem_private_object_init(struct drm_device *dev,
1616 struct drm_gem_object *obj, size_t size);
1617 void drm_gem_vm_open(struct vm_area_struct *vma);
1618 void drm_gem_vm_close(struct vm_area_struct *vma);
1619 int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
1620 struct vm_area_struct *vma);
1621 int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
1623 int i915_gem_pager_ctor(void *handle, vm_ooffset_t size, vm_prot_t prot,
1624 vm_ooffset_t foff, struct ucred *cred, u_short *color);
1625 void i915_gem_pager_dtor(void * handle);
1627 #include <drm/drm_global.h>
1630 drm_gem_object_reference(struct drm_gem_object *obj)
1632 kref_get(&obj->refcount);
1636 drm_gem_object_unreference(struct drm_gem_object *obj)
1639 kref_put(&obj->refcount, drm_gem_object_free);
1643 drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
1646 struct drm_device *dev = obj->dev;
1648 kref_put(&obj->refcount, drm_gem_object_free);
1653 int drm_gem_handle_create_tail(struct drm_file *file_priv,
1654 struct drm_gem_object *obj,
1656 int drm_gem_handle_create(struct drm_file *file_priv,
1657 struct drm_gem_object *obj,
1659 int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
1661 struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1662 struct drm_file *filp,
1664 int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1665 struct drm_file *file_priv);
1666 int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1667 struct drm_file *file_priv);
1668 int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1669 struct drm_file *file_priv);
1670 void drm_gem_open(struct drm_device *dev, struct drm_file *file_priv);
1671 void drm_gem_release(struct drm_device *dev, struct drm_file *file_priv);
1673 void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
1674 int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
1675 int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size);
1677 int drm_gem_mmap_single(struct drm_device *dev, vm_ooffset_t *offset,
1678 vm_size_t size, struct vm_object **obj_res, int nprot);
1679 void drm_gem_pager_dtr(void *obj);
1681 struct ttm_bo_device;
1682 int ttm_bo_mmap_single(struct ttm_bo_device *bdev, vm_ooffset_t *offset,
1683 vm_size_t size, struct vm_object **obj_res, int nprot);
1684 struct ttm_buffer_object;
1685 void ttm_bo_release_mmap(struct ttm_buffer_object *bo);
1687 void drm_device_lock_mtx(struct drm_device *dev);
1688 void drm_device_unlock_mtx(struct drm_device *dev);
1689 int drm_device_sleep_mtx(struct drm_device *dev, void *chan, int flags,
1690 const char *msg, int timeout);
1691 void drm_device_assert_mtx_locked(struct drm_device *dev);
1692 void drm_device_assert_mtx_unlocked(struct drm_device *dev);
1694 void drm_device_lock_struct(struct drm_device *dev);
1695 void drm_device_unlock_struct(struct drm_device *dev);
1696 int drm_device_sleep_struct(struct drm_device *dev, void *chan, int flags,
1697 const char *msg, int timeout);
1698 void drm_device_assert_struct_locked(struct drm_device *dev);
1699 void drm_device_assert_struct_unlocked(struct drm_device *dev);
1701 void drm_compat_locking_init(struct drm_device *dev);
1702 void drm_sleep_locking_init(struct drm_device *dev);
1704 /* XXX glue logic, should be done in drm_pci_init(), pending drm update */
1705 void drm_init_pdev(struct device *dev, struct pci_dev **pdev);
1706 void drm_fini_pdev(struct pci_dev **pdev);
1708 /* Inline replacements for drm_alloc and friends */
1709 static __inline__ void *
1710 drm_alloc(size_t size, struct malloc_type *area)
1712 return kmalloc(size, area, M_WAITOK | M_NULLOK);
1715 static __inline__ void *
1716 drm_calloc(size_t nmemb, size_t size, struct malloc_type *area)
1718 return kmalloc(size * nmemb, area, M_WAITOK | M_NULLOK | M_ZERO);
1721 static __inline__ void
1722 drm_free(void *pt, struct malloc_type *area)
1727 static __inline__ void
1728 drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
1730 map->handle = drm_ioremap_wc(dev, map);
1732 static __inline__ void
1733 drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
1735 map->handle = drm_ioremap(dev, map);
1737 static __inline__ void
1738 drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
1740 if ( map->handle && map->size )
1741 drm_ioremapfree(map);
1744 static __inline__ struct drm_local_map *
1745 drm_core_findmap(struct drm_device *dev, unsigned long offset)
1747 struct drm_map_list *_entry;
1749 list_for_each_entry(_entry, &dev->maplist, head) {
1750 if (offset == (unsigned long)_entry->map->handle)
1756 static __inline__ void drm_core_dropmap(struct drm_map *map)
1760 #include <drm/drm_mem_util.h>
1762 /* FreeBSD compatibility macros */
1763 #define VM_OBJECT_WLOCK(object) VM_OBJECT_LOCK(object)
1764 #define VM_OBJECT_WUNLOCK(object) VM_OBJECT_UNLOCK(object)
1766 #define DRM_PCIE_SPEED_25 1
1767 #define DRM_PCIE_SPEED_50 2
1768 #define DRM_PCIE_SPEED_80 4
1770 extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
1772 #define drm_can_sleep() (DRM_HZ & 1)
1774 #endif /* __KERNEL__ */
1775 #endif /* _DRM_P_H_ */