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/fs.h>
103 #include <linux/kref.h>
104 #include <linux/list.h>
105 #include <linux/mm.h>
106 #include <linux/moduleparam.h>
107 #include <linux/mutex.h>
108 #include <linux/slab.h>
109 #include <linux/scatterlist.h>
110 #include <linux/timer.h>
112 #include <linux/seq_file.h>
113 #include <linux/types.h>
114 #include <linux/wait.h>
115 #include <linux/workqueue.h>
117 #include <asm/uaccess.h>
119 #include <drm/drm_vma_manager.h>
127 #include <drm/drm_os_linux.h>
128 #include <drm/drm_hashtab.h>
129 #include <drm/drm_mm.h>
132 * 4 debug categories are defined:
134 * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
135 * This is the category used by the DRM_DEBUG() macro.
137 * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
138 * This is the category used by the DRM_DEBUG_DRIVER() macro.
140 * KMS: used in the modesetting code.
141 * This is the category used by the DRM_DEBUG_KMS() macro.
143 * PRIME: used in the prime code.
144 * This is the category used by the DRM_DEBUG_PRIME() macro.
146 * Enabling verbose debug messages is done through the drm.debug parameter,
147 * each category being enabled by a bit.
149 * drm.debug=0x1 will enable CORE messages
150 * drm.debug=0x2 will enable DRIVER messages
151 * drm.debug=0x3 will enable CORE and DRIVER messages
153 * drm.debug=0xf will enable all messages
155 * An interesting feature is that it's possible to enable verbose logging at
156 * run-time by echoing the debug value in its sysfs node:
157 * # echo 0xf > /sys/module/drm/parameters/debug
159 #define DRM_UT_CORE 0x01
160 #define DRM_UT_DRIVER 0x02
161 #define DRM_UT_KMS 0x04
162 #define DRM_UT_PRIME 0x08
164 void drm_ut_debug_printk(const char *function_name
,
165 const char *format
, ...);
167 int drm_err(const char *func
, const char *format
, ...);
169 /***********************************************************************/
170 /** \name DRM template customization defaults */
173 /* driver capabilities and requirements mask */
174 #define DRIVER_USE_AGP 0x1
175 #define DRIVER_REQUIRE_AGP 0x2
176 #define DRIVER_PCI_DMA 0x8
177 #define DRIVER_SG 0x10
178 #define DRIVER_HAVE_DMA 0x20
179 #define DRIVER_HAVE_IRQ 0x40
180 #define DRIVER_IRQ_SHARED 0x80
181 #define DRIVER_DMA_QUEUE 0x200
182 #define DRIVER_GEM 0x1000
183 #define DRIVER_MODESET 0x2000
184 #define DRIVER_PRIME 0x4000
185 #define DRIVER_RENDER 0x8000
187 /***********************************************************************/
188 /** \name Begin the DRM... */
191 #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
192 also include looping detection. */
194 #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
196 #define DRM_MAP_HASH_OFFSET 0x10000000
200 /***********************************************************************/
201 /** \name Macros to make printk easier */
207 * \param fmt printf() like format string.
208 * \param arg arguments
210 #define DRM_ERROR(fmt, ...) \
211 kprintf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \
212 DRM_CURRENTPID, __func__ , ##__VA_ARGS__)
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_MAX(a,b) ((a)>(b)?(a):(b))
226 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
228 #define __OS_HAS_AGP 1
230 #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
231 #define DRM_DEV_UID 0
232 #define DRM_DEV_GID 0
234 #define DRM_CURPROC curthread
235 #define DRM_STRUCTPROC struct thread
236 #define DRM_CURRENTPID (curproc != NULL ? curproc->p_pid : -1)
237 #define DRM_LOCK(dev) lockmgr(&(dev)->struct_mutex, LK_EXCLUSIVE)
238 #define DRM_UNLOCK(dev) lockmgr(&(dev)->struct_mutex, LK_RELEASE)
239 #define DRM_LOCK_SLEEP(dev, chan, flags, msg, timeout) \
240 (lksleep((chan), &(dev)->struct_mutex, (flags), (msg), (timeout)))
241 #if defined(INVARIANTS)
242 #define DRM_LOCK_ASSERT(dev) KKASSERT(lockstatus(&(dev)->struct_mutex, curthread) != 0);
243 #define DRM_UNLOCK_ASSERT(dev) KKASSERT(lockstatus(&(dev)->struct_mutex, curthread) == 0);
245 #define DRM_LOCK_ASSERT(d)
246 #define DRM_UNLOCK_ASSERT(d)
249 #define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS)
251 typedef void irqreturn_t
;
252 #define IRQ_HANDLED /* nothing */
253 #define IRQ_NONE /* nothing */
260 #define DRM_AGP_MEM struct agp_memory_info
262 #define drm_get_device_from_kdev(_kdev) (_kdev->si_drv1)
264 #define DRM_AGP_FIND_DEVICE() agp_find_device()
265 #define DRM_MTRR_WC MDF_WRITECOMBINE
267 #define LOCK_TEST_WITH_RETURN(dev, file_priv) \
269 if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \
270 dev->lock.file_priv != file_priv) { \
271 DRM_ERROR("%s called without lock held\n", \
277 /* Returns -errno to shared code */
278 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
279 for ( ret = 0 ; !ret && !(condition) ; ) { \
281 lwkt_serialize_enter(&dev->irq_lock); \
282 if (!(condition)) { \
283 tsleep_interlock(&(queue), PCATCH); \
284 lwkt_serialize_exit(&dev->irq_lock); \
285 ret = -tsleep(&(queue), PCATCH | PINTERLOCKED, \
286 "drmwtq", (timeout)); \
288 lwkt_serialize_exit(&dev->irq_lock); \
293 int vm_phys_fictitious_reg_range(vm_paddr_t start
, vm_paddr_t end
,
294 vm_memattr_t memattr
);
295 void vm_phys_fictitious_unreg_range(vm_paddr_t start
, vm_paddr_t end
);
296 vm_page_t
vm_phys_fictitious_to_vm_page(vm_paddr_t pa
);
298 /***********************************************************************/
299 /** \name Macros to make printk easier */
303 #define DRM_INFO(fmt, ...) kprintf("info: [" DRM_NAME "] " fmt , ##__VA_ARGS__)
305 #define DRM_INFO_ONCE(fmt, ...) \
306 printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
308 #define DRM_DEBUGBITS_DEBUG 0x1
309 #define DRM_DEBUGBITS_KMS 0x2
310 #define DRM_DEBUGBITS_FAILED_IOCTL 0x4
311 #define DRM_DEBUGBITS_VERBOSE 0x8
313 #define DRM_DEBUG(fmt, ...) do { \
314 if ((drm_debug & DRM_DEBUGBITS_DEBUG) != 0) \
315 kprintf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
316 __func__ , ##__VA_ARGS__); \
319 #define DRM_DEBUG_VERBOSE(fmt, ...) do { \
320 if ((drm_debug & DRM_DEBUGBITS_VERBOSE) != 0) \
321 kprintf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \
322 __func__ , ##__VA_ARGS__); \
325 #define DRM_DEBUG_KMS(fmt, ...) do { \
326 if ((drm_debug & DRM_DEBUGBITS_KMS) != 0) \
327 kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\
328 __func__ , ##__VA_ARGS__); \
331 #define DRM_DEBUG_DRIVER(fmt, ...) do { \
332 if ((drm_debug & DRM_DEBUGBITS_KMS) != 0) \
333 kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID,\
334 __func__ , ##__VA_ARGS__); \
337 #define DRM_LOG_KMS(fmt, ...) do { \
338 kprintf("[" DRM_NAME ":KMS:pid%d:%s] " fmt, DRM_CURRENTPID, \
339 __func__ , ##__VA_ARGS__); \
342 #define dev_dbg(dev, fmt, ...) do { \
343 if ((drm_debug& DRM_DEBUGBITS_KMS) != 0) { \
344 device_printf((dev), "debug: " fmt, ## __VA_ARGS__); \
348 typedef struct drm_pci_id_list
356 struct drm_msi_blacklist_entry
363 * Ioctl function type.
365 * \param inode device inode.
366 * \param file_priv DRM file private pointer.
367 * \param cmd command.
368 * \param arg argument.
370 typedef int drm_ioctl_t(struct drm_device
*dev
, void *data
,
371 struct drm_file
*file_priv
);
373 typedef int drm_ioctl_compat_t(struct file
*filp
, unsigned int cmd
,
376 #define DRM_IOCTL_NR(n) ((n) & 0xff)
379 #define DRM_MASTER 0x2
380 #define DRM_ROOT_ONLY 0x4
381 #define DRM_CONTROL_ALLOW 0x8
382 #define DRM_UNLOCKED 0x10
383 #define DRM_RENDER_ALLOW 0x20
385 struct drm_ioctl_desc
{
389 unsigned int cmd_drv
;
394 * Creates a driver or general drm_ioctl_desc array entry for the given
395 * ioctl, for use by drm_ioctl().
397 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
398 [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl}
400 typedef struct drm_magic_entry
{
401 struct list_head head
;
402 struct drm_hash_item hash_item
;
403 struct drm_file
*priv
;
404 struct drm_magic_entry
*next
;
407 typedef struct drm_magic_head
{
408 struct drm_magic_entry
*head
;
409 struct drm_magic_entry
*tail
;
412 typedef struct drm_buf
{
413 int idx
; /**< Index into master buflist */
414 int total
; /**< Buffer size */
415 int order
; /**< log-base-2(total) */
416 int used
; /**< Amount of buffer in use (for DMA) */
417 unsigned long offset
; /**< Byte offset (used internally) */
418 void *address
; /**< Address of buffer */
419 unsigned long bus_address
; /**< Bus address of buffer */
420 struct drm_buf
*next
; /**< Kernel-only: used for free list */
421 __volatile__
int waiting
; /**< On kernel DMA queue */
422 __volatile__
int pending
; /**< On hardware DMA queue */
423 struct drm_file
*file_priv
; /**< Private of holding file descr */
424 int context
; /**< Kernel queue for this buffer */
425 int while_locked
; /**< Dispatch this buffer while locked */
433 } list
; /**< Which list we're on */
435 int dev_priv_size
; /**< Size of buffer private storage */
436 void *dev_private
; /**< Per-buffer private storage */
439 /** bufs is one longer than it has to be */
440 struct drm_waitlist
{
441 int count
; /**< Number of possible buffers */
442 struct drm_buf
**bufs
; /**< List of pointers to buffers */
443 struct drm_buf
**rp
; /**< Read pointer */
444 struct drm_buf
**wp
; /**< Write pointer */
445 struct drm_buf
**end
; /**< End pointer */
446 spinlock_t read_lock
;
447 spinlock_t write_lock
;
450 typedef struct drm_dma_handle
{
458 typedef struct drm_buf_entry
{
464 struct drm_dma_handle
**seglist
;
466 int low_mark
; /**< Low water mark */
467 int high_mark
; /**< High water mark */
470 /* Event queued up for userspace to read */
471 struct drm_pending_event
{
472 struct drm_event
*event
;
473 struct list_head link
;
474 struct drm_file
*file_priv
;
475 pid_t pid
; /* pid of requester, no guarantee it's valid by the time
476 we deliver the event, for tracing only */
477 void (*destroy
)(struct drm_pending_event
*event
);
480 /* initial implementaton using a linked list - todo hashtab */
481 struct drm_prime_file_private
{
482 struct list_head head
;
485 #endif /* DUMBBELL_WIP */
488 /** File private data */
491 struct drm_device
*dev
;
494 /* true when the client has asked us to expose stereo 3D mode flags */
497 * true if client understands CRTC primary planes and cursor planes
500 unsigned universal_planes
:1;
505 unsigned long ioctl_count
;
506 struct list_head lhead
;
509 /** Mapping of mm object handles to object pointers. */
510 struct idr object_idr
;
511 /** Lock for synchronization of access to object_idr. */
512 struct lock table_lock
;
517 struct drm_master
*masterp
;
520 * fbs - List of framebuffers associated with this file.
522 * Protected by fbs_lock. Note that the fbs list holds a reference on
523 * the fb object to prevent it from untimely disappearing.
525 struct list_head fbs
;
526 struct lock fbs_lock
;
528 wait_queue_head_t event_wait
;
529 struct list_head event_list
;
532 struct drm_prime_file_private prime
;
537 atomic_t use_count
; /**< Outstanding uses (+1) */
538 atomic_t finalization
; /**< Finalization in progress */
539 atomic_t block_count
; /**< Count of processes waiting */
540 atomic_t block_read
; /**< Queue blocked for reads */
541 wait_queue_head_t read_queue
; /**< Processes waiting on block_read */
542 atomic_t block_write
; /**< Queue blocked for writes */
543 wait_queue_head_t write_queue
; /**< Processes waiting on block_write */
544 atomic_t total_queued
; /**< Total queued statistic */
545 atomic_t total_flushed
; /**< Total flushes statistic */
546 atomic_t total_locks
; /**< Total locks statistics */
547 enum drm_ctx_flags flags
; /**< Context preserving and 2D-only */
548 struct drm_waitlist waitlist
; /**< Pending buffers */
549 wait_queue_head_t flush_queue
; /**< Processes waiting until flush */
555 struct drm_lock_data
{
556 struct drm_hw_lock
*hw_lock
; /**< Hardware lock */
557 /** Private of lock holder's file (NULL=kernel) */
558 struct drm_file
*file_priv
;
559 wait_queue_head_t lock_queue
; /**< Queue of blocked processes */
560 unsigned long lock_time
; /**< Time of last lock in jiffies */
563 /* This structure, in the struct drm_device, is always initialized while the
565 * is open. dev->dma_lock protects the incrementing of dev->buf_use, which
566 * when set marks that no further bufs may be allocated until device teardown
567 * occurs (when the last open of the device has closed). The high/low
568 * watermarks of bufs are only touched by the X Server, and thus not
569 * concurrently accessed, so no locking is needed.
571 typedef struct drm_device_dma
{
573 struct drm_buf_entry bufs
[DRM_MAX_ORDER
+ 1]; /**< buffers, grouped by their size order */
574 int buf_count
; /**< total number of buffers */
575 struct drm_buf
**buflist
; /**< Vector of pointers into drm_device_dma::bufs */
577 int page_count
; /**< number of pages */
578 unsigned long *pagelist
; /**< page list */
579 unsigned long byte_count
;
581 _DRM_DMA_USE_AGP
= 0x01,
582 _DRM_DMA_USE_SG
= 0x02,
583 _DRM_DMA_USE_FB
= 0x04,
584 _DRM_DMA_USE_PCI_RO
= 0x08
589 typedef struct drm_agp_mem
{
591 unsigned long bound
; /* address */
593 struct drm_agp_mem
*prev
;
594 struct drm_agp_mem
*next
;
597 typedef struct drm_agp_head
{
599 struct agp_info agp_info
;
601 drm_agp_mem_t
*memory
;
607 int cant_use_aperture
;
608 unsigned long page_mask
;
611 typedef struct drm_sg_mem
{
618 * Kernel side of a mapping
620 struct drm_local_map
{
621 resource_size_t offset
; /**< Requested physical address (0 for SAREA)*/
622 unsigned long size
; /**< Requested physical size (bytes) */
623 enum drm_map_type type
; /**< Type of memory to map */
624 enum drm_map_flags flags
; /**< Flags */
625 void *handle
; /**< User-space: "Handle" to pass to mmap() */
626 /**< Kernel-space: kernel-virtual address */
627 int mtrr
; /**< MTRR slot used */
630 typedef struct drm_local_map drm_local_map_t
;
635 struct drm_map_list
{
636 struct list_head head
; /**< list head */
637 struct drm_hash_item hash
;
638 struct drm_local_map
*map
; /**< mapping */
640 struct drm_master
*master
;
641 struct drm_mm_node
*file_offset_node
; /**< fake offset */
644 /* location of GART table */
645 #define DRM_ATI_GART_MAIN 1
646 #define DRM_ATI_GART_FB 2
648 #define DRM_ATI_GART_PCI 1
649 #define DRM_ATI_GART_PCIE 2
650 #define DRM_ATI_GART_IGP 3
652 struct drm_ati_pcigart_info
{
653 int gart_table_location
;
657 dma_addr_t table_mask
;
658 dma_addr_t member_mask
;
659 struct drm_dma_handle
*table_handle
;
660 drm_local_map_t mapping
;
662 struct drm_dma_handle
*dmah
; /* handle for ATI PCIGART table */
666 * GEM specific mm private for tracking GEM objects
669 struct drm_vma_offset_manager vma_manager
;
670 struct drm_mm offset_manager
; /**< Offset mgmt for buffer objects */
671 struct drm_open_hash offset_hash
; /**< User token hash table for maps */
672 struct unrhdr
*idxunr
;
675 struct drm_gem_object
{
676 /** Reference count of this object */
677 struct kref refcount
;
680 * handle_count - gem file_priv handle count of this object
682 * Each handle also holds a reference. Note that when the handle_count
683 * drops to 0 any global names (e.g. the id in the flink namespace) will
686 * Protected by dev->object_name_lock.
688 unsigned handle_count
;
690 /** Related drm device */
691 struct drm_device
*dev
;
693 /** File representing the shmem storage: filp in Linux parlance */
696 /* Mapping info for this object */
697 struct drm_vma_offset_node vma_node
;
699 struct drm_hash_item map_list
;
702 * Size of the object, in bytes. Immutable over the object's
708 * Global name for this object, starts at 1. 0 means unnamed.
709 * Access is covered by the object_name_lock in the related drm_device
714 * Memory domains. These monitor which caches contain read/write data
715 * related to the object. When transitioning from one set of domains
716 * to another, the driver is called to ensure that caches are suitably
717 * flushed and invalidated
719 uint32_t read_domains
;
720 uint32_t write_domain
;
723 * While validating an exec operation, the
724 * new read/write domain values are computed here.
725 * They will be transferred to the above values
726 * at the point that any cache flushing occurs
728 uint32_t pending_read_domains
;
729 uint32_t pending_write_domain
;
732 /* dma buf exported from this GEM object */
733 struct dma_buf
*export_dma_buf
;
735 /* dma buf attachment backing this object */
736 struct dma_buf_attachment
*import_attach
;
737 #endif /* DUMBBELL_WIP */
740 #include "drm_crtc.h"
743 * struct drm_master - drm master structure
745 * @refcount: Refcount for this master object.
746 * @minor: Link back to minor char device we are master for. Immutable.
747 * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex.
748 * @unique_len: Length of unique field. Protected by drm_global_mutex.
749 * @unique_size: Amount allocated. Protected by drm_global_mutex.
750 * @magiclist: Hash of used authentication tokens. Protected by struct_mutex.
751 * @magicfree: List of used authentication tokens. Protected by struct_mutex.
752 * @lock: DRI lock information.
753 * @driver_priv: Pointer to driver-private information.
757 struct kref refcount
; /* refcount for this master */
759 struct list_head head
; /**< each minor contains a list of masters */
760 struct drm_minor
*minor
; /**< link back to minor we are a master for */
762 char *unique
; /**< Unique identifier: e.g., busid */
763 int unique_len
; /**< Length of unique field */
764 int unique_size
; /**< amount allocated */
766 int blocked
; /**< Blocked due to VC switch? */
768 struct drm_open_hash magiclist
;
769 struct list_head magicfree
;
770 struct drm_lock_data lock
;
774 /* Size of ringbuffer for vblank timestamps. Just double-buffer
775 * in initial implementation.
777 #define DRM_VBLANKTIME_RBSIZE 2
779 /* Flags and return codes for get_vblank_timestamp() driver function. */
780 #define DRM_CALLED_FROM_VBLIRQ 1
781 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
782 #define DRM_VBLANKTIME_INVBL (1 << 1)
784 /* get_scanout_position() return flags */
785 #define DRM_SCANOUTPOS_VALID (1 << 0)
786 #define DRM_SCANOUTPOS_INVBL (1 << 1)
787 #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
790 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : (1ULL<<(n)) - 1)
793 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
796 * DRM driver structure. This structure represent the common code for
797 * a family of cards. There will one drm_device for each card present
801 int (*load
)(struct drm_device
*, unsigned long flags
);
802 int (*use_msi
)(struct drm_device
*, unsigned long flags
);
803 int (*firstopen
)(struct drm_device
*);
804 int (*open
)(struct drm_device
*, struct drm_file
*);
805 void (*preclose
)(struct drm_device
*, struct drm_file
*file_priv
);
806 void (*postclose
)(struct drm_device
*, struct drm_file
*);
807 void (*lastclose
)(struct drm_device
*);
808 int (*unload
)(struct drm_device
*);
809 void (*reclaim_buffers_locked
)(struct drm_device
*,
810 struct drm_file
*file_priv
);
811 int (*dma_ioctl
)(struct drm_device
*dev
, void *data
,
812 struct drm_file
*file_priv
);
813 void (*dma_ready
)(struct drm_device
*);
814 int (*dma_quiescent
)(struct drm_device
*);
815 int (*dma_flush_block_and_flush
)(struct drm_device
*, int context
,
816 enum drm_lock_flags flags
);
817 int (*dma_flush_unblock
)(struct drm_device
*, int context
,
818 enum drm_lock_flags flags
);
819 int (*context_ctor
)(struct drm_device
*dev
, int context
);
820 int (*context_dtor
)(struct drm_device
*dev
, int context
);
821 int (*kernel_context_switch
)(struct drm_device
*dev
, int old
,
823 int (*kernel_context_switch_unlock
)(struct drm_device
*dev
);
824 void (*irq_preinstall
)(struct drm_device
*dev
);
825 int (*irq_postinstall
)(struct drm_device
*dev
);
826 void (*irq_uninstall
)(struct drm_device
*dev
);
827 void (*irq_handler
)(void *arg
);
829 u32 (*get_vblank_counter
)(struct drm_device
*dev
, int crtc
);
830 int (*enable_vblank
)(struct drm_device
*dev
, int crtc
);
831 void (*disable_vblank
)(struct drm_device
*dev
, int crtc
);
834 * Called by vblank timestamping code.
836 * Return the current display scanout position from a crtc, and an
837 * optional accurate ktime_get timestamp of when position was measured.
839 * \param dev DRM device.
840 * \param crtc Id of the crtc to query.
841 * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
842 * \param *vpos Target location for current vertical scanout position.
843 * \param *hpos Target location for current horizontal scanout position.
844 * \param *stime Target location for timestamp taken immediately before
845 * scanout position query. Can be NULL to skip timestamp.
846 * \param *etime Target location for timestamp taken immediately after
847 * scanout position query. Can be NULL to skip timestamp.
849 * Returns vpos as a positive number while in active scanout area.
850 * Returns vpos as a negative number inside vblank, counting the number
851 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
852 * until start of active scanout / end of vblank."
854 * \return Flags, or'ed together as follows:
856 * DRM_SCANOUTPOS_VALID = Query successful.
857 * DRM_SCANOUTPOS_INVBL = Inside vblank.
858 * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
859 * this flag means that returned position may be offset by a constant
860 * but unknown small number of scanlines wrt. real scanout position.
863 int (*get_scanout_position
) (struct drm_device
*dev
, int crtc
,
865 int *vpos
, int *hpos
, ktime_t
*stime
,
868 int (*get_vblank_timestamp
)(struct drm_device
*dev
, int crtc
,
869 int *max_error
, struct timeval
*vblank_time
,
872 void (*gem_free_object
)(struct drm_gem_object
*obj
);
873 int (*gem_open_object
)(struct drm_gem_object
*, struct drm_file
*);
874 void (*gem_close_object
)(struct drm_gem_object
*, struct drm_file
*);
876 struct cdev_pager_ops
*gem_pager_ops
;
878 int (*dumb_create
)(struct drm_file
*file_priv
,
879 struct drm_device
*dev
, struct drm_mode_create_dumb
*args
);
880 int (*dumb_map_offset
)(struct drm_file
*file_priv
,
881 struct drm_device
*dev
, uint32_t handle
, uint64_t *offset
);
882 int (*dumb_destroy
)(struct drm_file
*file_priv
,
883 struct drm_device
*dev
, uint32_t handle
);
885 int (*sysctl_init
)(struct drm_device
*dev
,
886 struct sysctl_ctx_list
*ctx
, struct sysctl_oid
*top
);
887 void (*sysctl_cleanup
)(struct drm_device
*dev
);
889 drm_pci_id_list_t
*id_entry
; /* PCI ID, name, and chipset private */
892 * Called by \c drm_device_is_agp. Typically used to determine if a
893 * card is really attached to AGP or not.
895 * \param dev DRM device handle
898 * One of three values is returned depending on whether or not the
899 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
900 * (return of 1), or may or may not be AGP (return of 2).
902 int (*device_is_agp
) (struct drm_device
* dev
);
907 const char *name
; /* Simple driver name */
908 const char *desc
; /* Longer driver name */
909 const char *date
; /* Date of last major changes. */
913 const struct drm_ioctl_desc
*ioctls
;
918 * Info file list entry. This structure represents a debugfs or proc file to
919 * be created by the drm core
921 struct drm_info_list
{
922 const char *name
; /** file name */
923 int (*show
)(struct seq_file
*, void*); /** show callback */
924 u32 driver_features
; /**< Required driver features for this entry */
929 * debugfs node structure. This structure represents a debugfs file.
931 struct drm_info_node
{
932 struct list_head list
;
933 struct drm_minor
*minor
;
934 const struct drm_info_list
*info_ent
;
939 * DRM minor structure. This structure represents a drm minor number.
942 int index
; /**< Minor device number */
943 int type
; /**< Control or render */
944 device_t kdev
; /**< OS device */
945 struct drm_device
*dev
;
947 struct drm_master
*master
; /* currently active master for this node */
948 struct list_head master_list
;
949 struct drm_mode_group mode_group
;
952 struct drm_pending_vblank_event
{
953 struct drm_pending_event base
;
955 struct drm_event_vblank event
;
958 struct drm_sysctl_info
{
959 struct sysctl_ctx_list ctx
;
963 /* Length for the array of resource pointers for drm_get_resource_*. */
964 #define DRM_MAX_PCI_RESOURCE 6
966 struct drm_vblank_crtc
{
967 struct drm_device
*dev
; /* pointer to the drm_device */
968 wait_queue_head_t queue
; /**< VBLANK wait queue */
969 struct timeval time
[DRM_VBLANKTIME_RBSIZE
]; /**< timestamp of current count */
970 struct timer_list disable_timer
; /* delayed disable timer */
971 atomic_t count
; /**< number of VBLANK interrupts */
972 atomic_t refcount
; /* number of users of vblank interruptsper crtc */
973 u32 last
; /* protected by dev->vbl_lock, used */
974 /* for wraparound handling */
975 u32 last_wait
; /* Last vblank seqno waited per CRTC */
976 unsigned int inmodeset
; /* Display driver is setting mode */
977 int crtc
; /* crtc index */
978 bool enabled
; /* so we don't call enable more than
983 * DRM device structure. This structure represent a complete card that
984 * may contain multiple heads.
987 drm_pci_id_list_t
*id_entry
; /* PCI ID, name, and chipset private */
989 uint16_t pci_subdevice
; /* PCI subsystem device id */
990 uint16_t pci_subvendor
; /* PCI subsystem vendor id */
992 char *unique
; /* Unique identifier: e.g., busid */
993 int unique_len
; /* Length of unique field */
994 struct cdev
*devnode
; /* Device number for mknod */
995 int if_version
; /* Highest interface version set */
997 int flags
; /* Flags to open(2) */
1000 struct spinlock dma_lock
; /* protects dev->dma */
1001 struct lwkt_serialize irq_lock
; /* protects irq condition checks */
1002 struct lock dev_lock
; /* protects everything else */
1006 struct lock struct_mutex
; /**< For others */
1007 struct lock master_mutex
; /**< For drm_minor::master */
1010 /** \name Usage Counters */
1012 int open_count
; /**< Outstanding files open, protected by drm_global_mutex. */
1013 struct spinlock buf_lock
; /**< For drm_device::buf_use and a few other things. */
1014 int buf_use
; /**< Buffers in use -- cannot alloc */
1015 atomic_t buf_alloc
; /**< Buffer allocation in progress */
1019 /** \name Performance counters */
1021 unsigned long counters
;
1022 enum drm_stat_type types
[15];
1023 atomic_t counts
[15];
1026 /* Authentication */
1027 struct drm_open_hash magiclist
; /**< magic hash table */
1028 struct list_head magicfree
;
1030 struct list_head filelist
;
1032 /** \name Memory management */
1034 struct list_head maplist
; /**< Linked list of regions */
1035 int map_count
; /**< Number of mappable regions */
1036 struct drm_open_hash map_hash
; /**< User token hash table for maps */
1038 /** \name Context handle management */
1040 struct list_head ctxlist
; /**< Linked list of context handles */
1041 int ctx_count
; /**< Number of context handles */
1042 struct lock ctxlist_mutex
; /**< For ctxlist */
1048 struct drm_lock_data lock
; /* Information on hardware lock */
1050 /* DMA queues (contexts) */
1051 drm_device_dma_t
*dma
; /* Optional pointer for DMA support */
1053 int irq
; /* Interrupt used by board */
1054 int irq_type
; /* IRQ type (MSI enabled or not) */
1055 int irqrid
; /* Interrupt used by board */
1056 struct resource
*irqr
; /* Resource for interrupt used by board */
1057 void *irqh
; /* Handle from bus_setup_intr */
1059 /* Storage of resource pointers for drm_get_resource_* */
1060 struct resource
*pcir
[DRM_MAX_PCI_RESOURCE
];
1061 int pcirid
[DRM_MAX_PCI_RESOURCE
];
1068 /** \name Context support */
1070 int irq_enabled
; /**< True if irq handler is enabled */
1071 __volatile__
long context_flag
; /**< Context swapping flag */
1072 __volatile__
long interrupt_flag
; /**< Interruption handler flag */
1073 __volatile__
long dma_flag
; /**< DMA dispatch flag */
1074 wait_queue_head_t context_wait
; /**< Processes waiting on ctx switch */
1075 int last_checked
; /**< Last context checked for DMA */
1076 int last_context
; /**< Last current context */
1077 unsigned long last_switch
; /**< jiffies at last context switch */
1080 /** \name VBLANK IRQ support */
1084 * At load time, disabling the vblank interrupt won't be allowed since
1085 * old clients may not call the modeset ioctl and therefore misbehave.
1086 * Once the modeset ioctl *has* been called though, we can safely
1087 * disable them when unused.
1089 bool vblank_disable_allowed
;
1091 /* array of size num_crtcs */
1092 struct drm_vblank_crtc
*vblank
;
1094 struct lock vblank_time_lock
; /**< Protects vblank count and time updates during vblank enable/disable */
1095 struct lock vbl_lock
;
1096 struct timer_list vblank_disable_timer
;
1098 u32 max_vblank_count
; /**< size of vblank counter register */
1103 struct list_head vblank_event_list
;
1104 struct lock event_lock
;
1108 struct sigio
*buf_sigio
; /* Processes waiting for SIGIO */
1110 /* Sysctl support */
1111 struct drm_sysctl_info
*sysctl
;
1112 int sysctl_node_idx
;
1115 drm_sg_mem_t
*sg
; /* Scatter gather memory */
1116 unsigned int num_crtcs
; /**< Number of CRTCs on this device */
1118 unsigned long *ctx_bitmap
;
1125 struct drm_agp_head
*agp
; /**< AGP data */
1127 struct device
*dev
; /**< Device structure */
1128 struct pci_dev
*pdev
; /**< PCI device structure */
1129 int pci_vendor
; /**< PCI vendor id */
1130 int pci_device
; /**< PCI device id */
1132 struct drm_driver
*driver
;
1133 struct drm_local_map
*agp_buffer_map
;
1134 unsigned int agp_buffer_token
;
1135 struct drm_minor
*control
; /**< Control node for card */
1136 struct drm_minor
*primary
; /**< render type primary screen head */
1138 struct drm_mode_config mode_config
; /**< Current mode config */
1140 /** \name GEM information */
1142 struct lock object_name_lock
;
1143 struct idr object_name_idr
;
1147 void *sysctl_private
;
1148 char busid_str
[128];
1151 int switch_power_state
;
1153 atomic_t unplugged
; /* device has been unplugged or gone away */
1156 #define DRM_SWITCH_POWER_ON 0
1157 #define DRM_SWITCH_POWER_OFF 1
1158 #define DRM_SWITCH_POWER_CHANGING 2
1159 #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
1161 static __inline__
int drm_core_check_feature(struct drm_device
*dev
,
1164 return ((dev
->driver
->driver_features
& feature
) ? 1 : 0);
1167 static inline void drm_device_set_unplugged(struct drm_device
*dev
)
1170 atomic_set(&dev
->unplugged
, 1);
1173 static inline int drm_device_is_unplugged(struct drm_device
*dev
)
1175 int ret
= atomic_read(&dev
->unplugged
);
1180 static inline bool drm_is_primary_client(const struct drm_file
*file_priv
)
1182 return 0 /* file_priv->minor->type == DRM_MINOR_LEGACY */;
1186 * drm_is_master() - Check whether a DRM open-file is DRM-Master
1187 * @file: DRM open-file context
1189 * This checks whether a DRM open-file context is owner of the master context
1190 * attached to it. If a file owns a master context, it's called DRM-Master.
1191 * Per DRM device, only one such file can be DRM-Master at a time.
1193 * Returns: True if the file is DRM-Master, otherwise false.
1195 static inline bool drm_is_master(const struct drm_file
*file
)
1198 return file
->master
&& file
->master
== file
->minor
->master
;
1204 /******************************************************************/
1205 /** \name Internal function definitions */
1209 static inline int drm_core_has_AGP(struct drm_device
*dev
)
1211 return drm_core_check_feature(dev
, DRIVER_USE_AGP
);
1214 #define drm_core_has_AGP(dev) (0)
1217 extern int drm_notyet_flag
;
1218 extern unsigned int drm_rnodes
;
1219 extern unsigned int drm_universal_planes
;
1221 extern unsigned int drm_vblank_offdelay
;
1222 extern unsigned int drm_timestamp_precision
;
1223 extern unsigned int drm_timestamp_monotonic
;
1225 /* Driver support (drm_drv.h) */
1226 int drm_probe(device_t kdev
, drm_pci_id_list_t
*idlist
);
1227 int drm_attach(device_t kdev
, drm_pci_id_list_t
*idlist
);
1228 int drm_create_cdevs(device_t kdev
);
1229 d_ioctl_t drm_ioctl
;
1230 extern int drm_lastclose(struct drm_device
*dev
);
1231 extern bool drm_ioctl_flags(unsigned int nr
, unsigned int *flags
);
1233 /* Device support (drm_fops.h) */
1234 extern struct lock drm_global_mutex
;
1236 d_close_t drm_close
;
1238 d_kqfilter_t drm_kqfilter
;
1239 int drm_release(device_t kdev
);
1242 d_mmap_single_t drm_mmap_single
;
1243 extern drm_local_map_t
*drm_getsarea(struct drm_device
*dev
);
1245 void drm_cdevpriv_dtor(void *cd
);
1247 int drm_add_busid_modesetting(struct drm_device
*dev
,
1248 struct sysctl_ctx_list
*ctx
, struct sysctl_oid
*top
);
1250 /* File operations helpers (drm_fops.c) */
1251 extern int drm_open_helper(struct cdev
*kdev
, int flags
, int fmt
,
1253 struct drm_device
*dev
,
1255 extern struct drm_file
*drm_find_file_by_proc(struct drm_device
*dev
,
1259 extern int drm_gem_prime_handle_to_fd(struct drm_device
*dev
,
1260 struct drm_file
*file_priv
, uint32_t handle
, uint32_t flags
,
1262 extern int drm_gem_prime_fd_to_handle(struct drm_device
*dev
,
1263 struct drm_file
*file_priv
, int prime_fd
, uint32_t *handle
);
1265 extern int drm_prime_handle_to_fd_ioctl(struct drm_device
*dev
, void *data
,
1266 struct drm_file
*file_priv
);
1267 extern int drm_prime_fd_to_handle_ioctl(struct drm_device
*dev
, void *data
,
1268 struct drm_file
*file_priv
);
1270 extern int drm_prime_sg_to_page_addr_arrays(struct sg_table
*sgt
, vm_page_t
*pages
,
1271 dma_addr_t
*addrs
, int max_pages
);
1272 #endif /* DUMBBELL_WIP */
1273 extern struct sg_table
*drm_prime_pages_to_sg(vm_page_t
*pages
, int nr_pages
);
1274 extern void drm_prime_gem_destroy(struct drm_gem_object
*obj
, struct sg_table
*sg
);
1276 int drm_gem_dumb_destroy(struct drm_file
*file
,
1277 struct drm_device
*dev
,
1281 void drm_prime_init_file_private(struct drm_prime_file_private
*prime_fpriv
);
1282 void drm_prime_destroy_file_private(struct drm_prime_file_private
*prime_fpriv
);
1283 int drm_prime_add_imported_buf_handle(struct drm_prime_file_private
*prime_fpriv
, struct dma_buf
*dma_buf
, uint32_t handle
);
1284 int drm_prime_lookup_imported_buf_handle(struct drm_prime_file_private
*prime_fpriv
, struct dma_buf
*dma_buf
, uint32_t *handle
);
1285 void drm_prime_remove_imported_buf_handle(struct drm_prime_file_private
*prime_fpriv
, struct dma_buf
*dma_buf
);
1287 int drm_prime_add_dma_buf(struct drm_device
*dev
, struct drm_gem_object
*obj
);
1288 int drm_prime_lookup_obj(struct drm_device
*dev
, struct dma_buf
*buf
,
1289 struct drm_gem_object
**obj
);
1290 #endif /* DUMBBELL_WIP */
1292 /* Memory management support (drm_memory.h) */
1293 #include <drm/drm_memory.h>
1294 void drm_mem_init(void);
1295 void drm_mem_uninit(void);
1296 void *drm_ioremap_wc(struct drm_device
*dev
, drm_local_map_t
*map
);
1297 void *drm_ioremap(struct drm_device
*dev
, drm_local_map_t
*map
);
1298 void drm_ioremapfree(drm_local_map_t
*map
);
1299 int drm_mtrr_add(unsigned long offset
, size_t size
, int flags
);
1300 int drm_mtrr_del(int handle
, unsigned long offset
, size_t size
, int flags
);
1302 /* Locking IOCTL support (drm_lock.c) */
1303 int drm_lock_take(struct drm_lock_data
*lock_data
,
1304 unsigned int context
);
1305 int drm_lock_transfer(struct drm_lock_data
*lock_data
,
1306 unsigned int context
);
1307 int drm_lock_free(struct drm_lock_data
*lock_data
,
1308 unsigned int context
);
1311 * These are exported to drivers so that they can implement fencing using
1312 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1315 unsigned long drm_get_resource_start(struct drm_device
*dev
,
1316 unsigned int resource
);
1317 unsigned long drm_get_resource_len(struct drm_device
*dev
,
1318 unsigned int resource
);
1320 /* DMA support (drm_dma.c) */
1321 int drm_dma_setup(struct drm_device
*dev
);
1322 void drm_dma_takedown(struct drm_device
*dev
);
1323 void drm_free_buffer(struct drm_device
*dev
, drm_buf_t
*buf
);
1324 void drm_reclaim_buffers(struct drm_device
*dev
, struct drm_file
*file_priv
);
1325 #define drm_core_reclaim_buffers drm_reclaim_buffers
1327 /* IRQ support (drm_irq.h) */
1328 extern int drm_irq_install(struct drm_device
*dev
, int irq
);
1329 int drm_irq_uninstall(struct drm_device
*dev
);
1330 void drm_driver_irq_preinstall(struct drm_device
*dev
);
1331 void drm_driver_irq_postinstall(struct drm_device
*dev
);
1332 void drm_driver_irq_uninstall(struct drm_device
*dev
);
1334 extern int drm_vblank_init(struct drm_device
*dev
, int num_crtcs
);
1335 extern int drm_wait_vblank(struct drm_device
*dev
, void *data
,
1336 struct drm_file
*filp
);
1337 extern u32
drm_vblank_count(struct drm_device
*dev
, int crtc
);
1338 extern u32
drm_vblank_count_and_time(struct drm_device
*dev
, int crtc
,
1339 struct timeval
*vblanktime
);
1340 extern void drm_send_vblank_event(struct drm_device
*dev
, int crtc
,
1341 struct drm_pending_vblank_event
*e
);
1342 extern bool drm_handle_vblank(struct drm_device
*dev
, int crtc
);
1343 extern int drm_vblank_get(struct drm_device
*dev
, int crtc
);
1344 extern void drm_vblank_put(struct drm_device
*dev
, int crtc
);
1345 extern int drm_crtc_vblank_get(struct drm_crtc
*crtc
);
1346 extern void drm_crtc_vblank_put(struct drm_crtc
*crtc
);
1347 extern void drm_vblank_off(struct drm_device
*dev
, int crtc
);
1348 extern void drm_vblank_on(struct drm_device
*dev
, int crtc
);
1349 extern void drm_crtc_vblank_off(struct drm_crtc
*crtc
);
1350 extern void drm_crtc_vblank_on(struct drm_crtc
*crtc
);
1351 extern void drm_vblank_cleanup(struct drm_device
*dev
);
1353 extern u32
drm_get_last_vbltimestamp(struct drm_device
*dev
, int crtc
,
1354 struct timeval
*tvblank
, unsigned flags
);
1355 extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device
*dev
,
1356 int crtc
, int *max_error
,
1357 struct timeval
*vblank_time
,
1359 const struct drm_crtc
*refcrtc
,
1360 const struct drm_display_mode
*mode
);
1361 extern void drm_calc_timestamping_constants(struct drm_crtc
*crtc
,
1362 const struct drm_display_mode
*mode
);
1364 /* Modesetting support */
1365 extern void drm_vblank_pre_modeset(struct drm_device
*dev
, int crtc
);
1366 extern void drm_vblank_post_modeset(struct drm_device
*dev
, int crtc
);
1367 extern int drm_modeset_ctl(struct drm_device
*dev
, void *data
,
1368 struct drm_file
*file_priv
);
1370 /* AGP/PCI Express/GART support (drm_agpsupport.c) */
1371 int drm_device_is_agp(struct drm_device
*dev
);
1372 int drm_device_is_pcie(struct drm_device
*dev
);
1373 drm_agp_head_t
*drm_agp_init(void);
1374 int drm_agp_acquire(struct drm_device
*dev
);
1375 int drm_agp_release(struct drm_device
*dev
);
1376 int drm_agp_info(struct drm_device
* dev
, struct drm_agp_info
*info
);
1377 int drm_agp_enable(struct drm_device
*dev
, struct drm_agp_mode mode
);
1378 void *drm_agp_allocate_memory(size_t pages
, u32 type
);
1379 int drm_agp_free_memory(void *handle
);
1380 int drm_agp_bind_memory(void *handle
, off_t start
);
1381 int drm_agp_unbind_memory(void *handle
);
1382 int drm_agp_alloc(struct drm_device
*dev
, struct drm_agp_buffer
*request
);
1383 int drm_agp_free(struct drm_device
*dev
, struct drm_agp_buffer
*request
);
1384 int drm_agp_bind(struct drm_device
*dev
, struct drm_agp_binding
*request
);
1385 int drm_agp_unbind(struct drm_device
*dev
, struct drm_agp_binding
*request
);
1387 /* Scatter Gather Support (drm_scatter.h) */
1388 extern void drm_legacy_sg_cleanup(struct drm_device
*dev
);
1389 extern int drm_sg_alloc(struct drm_device
*dev
, void *data
,
1390 struct drm_file
*file_priv
);
1392 /* Scatter Gather Support (drm_scatter.c) */
1393 void drm_sg_cleanup(drm_sg_mem_t
*entry
);
1395 /* sysctl support (drm_sysctl.h) */
1396 extern int drm_sysctl_init(struct drm_device
*dev
);
1397 extern int drm_sysctl_cleanup(struct drm_device
*dev
);
1399 /* ATI PCIGART support (ati_pcigart.c) */
1400 int drm_ati_pcigart_init(struct drm_device
*dev
,
1401 struct drm_ati_pcigart_info
*gart_info
);
1402 int drm_ati_pcigart_cleanup(struct drm_device
*dev
,
1403 struct drm_ati_pcigart_info
*gart_info
);
1405 /* Cache management (drm_memory.c) */
1406 void drm_clflush_pages(vm_page_t
*pages
, unsigned long num_pages
);
1408 /* Locking IOCTL support (drm_drv.c) */
1409 int drm_lock(struct drm_device
*dev
, void *data
,
1410 struct drm_file
*file_priv
);
1411 int drm_unlock(struct drm_device
*dev
, void *data
,
1412 struct drm_file
*file_priv
);
1413 int drm_setversion(struct drm_device
*dev
, void *data
,
1414 struct drm_file
*file_priv
);
1417 * These are exported to drivers so that they can implement fencing using
1418 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1421 extern int drm_i_have_hw_lock(struct drm_device
*dev
, struct drm_file
*file_priv
);
1423 /* Buffer management support (drm_bufs.h) */
1424 extern int drm_addbufs_agp(struct drm_device
*dev
, struct drm_buf_desc
* request
);
1425 extern int drm_addbufs_pci(struct drm_device
*dev
, struct drm_buf_desc
* request
);
1426 extern int drm_addmap(struct drm_device
*dev
, resource_size_t offset
,
1427 unsigned int size
, enum drm_map_type type
,
1428 enum drm_map_flags flags
, struct drm_local_map
**map_ptr
);
1429 extern int drm_addmap_ioctl(struct drm_device
*dev
, void *data
,
1430 struct drm_file
*file_priv
);
1431 void drm_rmmap(struct drm_device
*dev
, drm_local_map_t
*map
);
1432 int drm_rmmap_ioctl(struct drm_device
*dev
, void *data
,
1433 struct drm_file
*file_priv
);
1434 int drm_addbufs(struct drm_device
*dev
, void *data
,
1435 struct drm_file
*file_priv
);
1436 int drm_infobufs(struct drm_device
*dev
, void *data
,
1437 struct drm_file
*file_priv
);
1438 int drm_markbufs(struct drm_device
*dev
, void *data
,
1439 struct drm_file
*file_priv
);
1440 int drm_freebufs(struct drm_device
*dev
, void *data
,
1441 struct drm_file
*file_priv
);
1442 int drm_mapbufs(struct drm_device
*dev
, void *data
,
1443 struct drm_file
*file_priv
);
1444 extern int drm_dma_ioctl(struct drm_device
*dev
, void *data
,
1445 struct drm_file
*file_priv
);
1447 /* Misc. IOCTL support (drm_ioctl.c) */
1448 int drm_irq_by_busid(struct drm_device
*dev
, void *data
,
1449 struct drm_file
*file_priv
);
1450 int drm_getunique(struct drm_device
*dev
, void *data
,
1451 struct drm_file
*file_priv
);
1452 int drm_setunique(struct drm_device
*dev
, void *data
,
1453 struct drm_file
*file_priv
);
1454 int drm_getmap(struct drm_device
*dev
, void *data
,
1455 struct drm_file
*file_priv
);
1456 int drm_getclient(struct drm_device
*dev
, void *data
,
1457 struct drm_file
*file_priv
);
1458 int drm_getstats(struct drm_device
*dev
, void *data
,
1459 struct drm_file
*file_priv
);
1460 int drm_getcap(struct drm_device
*dev
, void *data
,
1461 struct drm_file
*file_priv
);
1462 extern int drm_setclientcap(struct drm_device
*dev
, void *data
,
1463 struct drm_file
*file_priv
);
1464 int drm_noop(struct drm_device
*dev
, void *data
,
1465 struct drm_file
*file_priv
);
1467 /* Authentication IOCTL support (drm_auth.c) */
1468 int drm_getmagic(struct drm_device
*dev
, void *data
,
1469 struct drm_file
*file_priv
);
1470 int drm_authmagic(struct drm_device
*dev
, void *data
,
1471 struct drm_file
*file_priv
);
1473 /* Cache management (drm_cache.c) */
1474 void drm_clflush_virt_range(void *addr
, unsigned long length
);
1476 /* DMA support (drm_dma.c) */
1477 int drm_dma(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
);
1479 /* IRQ support (drm_irq.c) */
1480 int drm_control(struct drm_device
*dev
, void *data
,
1481 struct drm_file
*file_priv
);
1483 /* AGP/GART support (drm_agpsupport.c) */
1484 int drm_agp_acquire_ioctl(struct drm_device
*dev
, void *data
,
1485 struct drm_file
*file_priv
);
1486 int drm_agp_release_ioctl(struct drm_device
*dev
, void *data
,
1487 struct drm_file
*file_priv
);
1488 int drm_agp_enable_ioctl(struct drm_device
*dev
, void *data
,
1489 struct drm_file
*file_priv
);
1490 int drm_agp_info_ioctl(struct drm_device
*dev
, void *data
,
1491 struct drm_file
*file_priv
);
1492 int drm_agp_alloc_ioctl(struct drm_device
*dev
, void *data
,
1493 struct drm_file
*file_priv
);
1494 int drm_agp_free_ioctl(struct drm_device
*dev
, void *data
,
1495 struct drm_file
*file_priv
);
1496 int drm_agp_unbind_ioctl(struct drm_device
*dev
, void *data
,
1497 struct drm_file
*file_priv
);
1498 int drm_agp_bind_ioctl(struct drm_device
*dev
, void *data
,
1499 struct drm_file
*file_priv
);
1501 /* Stub support (drm_stub.h) */
1502 extern int drm_setmaster_ioctl(struct drm_device
*dev
, void *data
,
1503 struct drm_file
*file_priv
);
1504 extern int drm_dropmaster_ioctl(struct drm_device
*dev
, void *data
,
1505 struct drm_file
*file_priv
);
1507 extern void drm_put_dev(struct drm_device
*dev
);
1508 extern void drm_unplug_dev(struct drm_device
*dev
);
1509 extern unsigned int drm_debug
;
1511 /* Scatter Gather Support (drm_scatter.c) */
1512 int drm_sg_alloc_ioctl(struct drm_device
*dev
, void *data
,
1513 struct drm_file
*file_priv
);
1514 int drm_sg_free(struct drm_device
*dev
, void *data
,
1515 struct drm_file
*file_priv
);
1517 /* consistent PCI memory functions (drm_pci.c) */
1518 extern drm_dma_handle_t
*drm_pci_alloc(struct drm_device
*dev
, size_t size
,
1520 void drm_pci_free(struct drm_device
*dev
, drm_dma_handle_t
*dmah
);
1522 /* sysfs support (drm_sysfs.c) */
1523 struct drm_sysfs_class
;
1524 extern struct class *drm_sysfs_create(struct module
*owner
, char *name
);
1525 extern void drm_sysfs_destroy(void);
1526 extern int drm_sysfs_device_add(struct drm_minor
*minor
);
1527 extern void drm_sysfs_hotplug_event(struct drm_device
*dev
);
1528 extern void drm_sysfs_device_remove(struct drm_minor
*minor
);
1529 extern int drm_sysfs_connector_add(struct drm_connector
*connector
);
1530 extern void drm_sysfs_connector_remove(struct drm_connector
*connector
);
1532 /* Graphics Execution Manager library functions (drm_gem.c) */
1533 int drm_gem_init(struct drm_device
*dev
);
1534 void drm_gem_destroy(struct drm_device
*dev
);
1535 void drm_gem_object_release(struct drm_gem_object
*obj
);
1536 void drm_gem_object_free(struct kref
*kref
);
1537 int drm_gem_object_init(struct drm_device
*dev
,
1538 struct drm_gem_object
*obj
, size_t size
);
1539 void drm_gem_private_object_init(struct drm_device
*dev
,
1540 struct drm_gem_object
*obj
, size_t size
);
1541 void drm_gem_vm_open(struct vm_area_struct
*vma
);
1542 void drm_gem_vm_close(struct vm_area_struct
*vma
);
1543 int drm_gem_mmap_obj(struct drm_gem_object
*obj
, unsigned long obj_size
,
1544 struct vm_area_struct
*vma
);
1545 int drm_gem_mmap(struct file
*filp
, struct vm_area_struct
*vma
);
1547 int i915_gem_pager_ctor(void *handle
, vm_ooffset_t size
, vm_prot_t prot
,
1548 vm_ooffset_t foff
, struct ucred
*cred
, u_short
*color
);
1549 void i915_gem_pager_dtor(void * handle
);
1551 #include <drm/drm_global.h>
1554 drm_gem_object_reference(struct drm_gem_object
*obj
)
1556 kref_get(&obj
->refcount
);
1560 drm_gem_object_unreference(struct drm_gem_object
*obj
)
1563 kref_put(&obj
->refcount
, drm_gem_object_free
);
1567 drm_gem_object_unreference_unlocked(struct drm_gem_object
*obj
)
1570 struct drm_device
*dev
= obj
->dev
;
1572 kref_put(&obj
->refcount
, drm_gem_object_free
);
1577 int drm_gem_handle_create_tail(struct drm_file
*file_priv
,
1578 struct drm_gem_object
*obj
,
1580 int drm_gem_handle_create(struct drm_file
*file_priv
,
1581 struct drm_gem_object
*obj
,
1583 int drm_gem_handle_delete(struct drm_file
*filp
, u32 handle
);
1585 struct drm_gem_object
*drm_gem_object_lookup(struct drm_device
*dev
,
1586 struct drm_file
*filp
,
1588 int drm_gem_close_ioctl(struct drm_device
*dev
, void *data
,
1589 struct drm_file
*file_priv
);
1590 int drm_gem_flink_ioctl(struct drm_device
*dev
, void *data
,
1591 struct drm_file
*file_priv
);
1592 int drm_gem_open_ioctl(struct drm_device
*dev
, void *data
,
1593 struct drm_file
*file_priv
);
1594 void drm_gem_open(struct drm_device
*dev
, struct drm_file
*file_priv
);
1595 void drm_gem_release(struct drm_device
*dev
, struct drm_file
*file_priv
);
1597 void drm_gem_free_mmap_offset(struct drm_gem_object
*obj
);
1598 int drm_gem_create_mmap_offset(struct drm_gem_object
*obj
);
1599 int drm_gem_create_mmap_offset_size(struct drm_gem_object
*obj
, size_t size
);
1601 int drm_gem_mmap_single(struct drm_device
*dev
, vm_ooffset_t
*offset
,
1602 vm_size_t size
, struct vm_object
**obj_res
, int nprot
);
1603 void drm_gem_pager_dtr(void *obj
);
1605 struct ttm_bo_device
;
1606 int ttm_bo_mmap_single(struct ttm_bo_device
*bdev
, vm_ooffset_t
*offset
,
1607 vm_size_t size
, struct vm_object
**obj_res
, int nprot
);
1608 struct ttm_buffer_object
;
1609 void ttm_bo_release_mmap(struct ttm_buffer_object
*bo
);
1611 void drm_device_lock_mtx(struct drm_device
*dev
);
1612 void drm_device_unlock_mtx(struct drm_device
*dev
);
1613 int drm_device_sleep_mtx(struct drm_device
*dev
, void *chan
, int flags
,
1614 const char *msg
, int timeout
);
1615 void drm_device_assert_mtx_locked(struct drm_device
*dev
);
1616 void drm_device_assert_mtx_unlocked(struct drm_device
*dev
);
1618 void drm_device_lock_struct(struct drm_device
*dev
);
1619 void drm_device_unlock_struct(struct drm_device
*dev
);
1620 int drm_device_sleep_struct(struct drm_device
*dev
, void *chan
, int flags
,
1621 const char *msg
, int timeout
);
1622 void drm_device_assert_struct_locked(struct drm_device
*dev
);
1623 void drm_device_assert_struct_unlocked(struct drm_device
*dev
);
1625 void drm_compat_locking_init(struct drm_device
*dev
);
1626 void drm_sleep_locking_init(struct drm_device
*dev
);
1628 /* XXX glue logic, should be done in drm_pci_init(), pending drm update */
1629 void drm_init_pdev(struct device
*dev
, struct pci_dev
**pdev
);
1630 void drm_fini_pdev(struct pci_dev
**pdev
);
1632 /* Inline replacements for drm_alloc and friends */
1633 static __inline__
void *
1634 drm_alloc(size_t size
, struct malloc_type
*area
)
1636 return kmalloc(size
, area
, M_WAITOK
| M_NULLOK
);
1639 static __inline__
void *
1640 drm_calloc(size_t nmemb
, size_t size
, struct malloc_type
*area
)
1642 return kmalloc(size
* nmemb
, area
, M_WAITOK
| M_NULLOK
| M_ZERO
);
1645 static __inline__
void
1646 drm_free(void *pt
, struct malloc_type
*area
)
1651 static __inline__
void
1652 drm_core_ioremap_wc(struct drm_local_map
*map
, struct drm_device
*dev
)
1654 map
->handle
= drm_ioremap_wc(dev
, map
);
1656 static __inline__
void
1657 drm_core_ioremap(struct drm_local_map
*map
, struct drm_device
*dev
)
1659 map
->handle
= drm_ioremap(dev
, map
);
1661 static __inline__
void
1662 drm_core_ioremapfree(struct drm_local_map
*map
, struct drm_device
*dev
)
1664 if ( map
->handle
&& map
->size
)
1665 drm_ioremapfree(map
);
1668 static __inline__
struct drm_local_map
*
1669 drm_core_findmap(struct drm_device
*dev
, unsigned long offset
)
1671 struct drm_map_list
*_entry
;
1673 list_for_each_entry(_entry
, &dev
->maplist
, head
) {
1674 if (offset
== (unsigned long)_entry
->map
->handle
)
1680 static __inline__
void drm_core_dropmap(struct drm_map
*map
)
1684 #include <drm/drm_mem_util.h>
1686 struct drm_device
*drm_dev_alloc(struct drm_driver
*driver
,
1687 struct device
*parent
);
1688 void drm_dev_ref(struct drm_device
*dev
);
1689 void drm_dev_unref(struct drm_device
*dev
);
1690 int drm_dev_register(struct drm_device
*dev
, unsigned long flags
);
1691 void drm_dev_unregister(struct drm_device
*dev
);
1692 int drm_dev_set_unique(struct drm_device
*dev
, const char *fmt
, ...);
1694 /* FreeBSD compatibility macros */
1695 #define VM_OBJECT_WLOCK(object) VM_OBJECT_LOCK(object)
1696 #define VM_OBJECT_WUNLOCK(object) VM_OBJECT_UNLOCK(object)
1698 #define DRM_PCIE_SPEED_25 1
1699 #define DRM_PCIE_SPEED_50 2
1700 #define DRM_PCIE_SPEED_80 4
1702 extern int drm_pcie_get_speed_cap_mask(struct drm_device
*dev
, u32
*speed_mask
);
1705 #define drm_can_sleep() (HZ & 1)
1707 #endif /* __KERNEL__ */
1708 #endif /* _DRM_P_H_ */