2 * Internal Header for the Direct Rendering Manager
4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6 * Copyright (c) 2009-2010, Code Aurora Forum.
9 * Author: Rickard E. (Rik) Faith <faith@valinux.com>
10 * Author: Gareth Hughes <gareth@valinux.com>
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
19 * The above copyright notice and this permission notice (including the next
20 * paragraph) shall be included in all copies or substantial portions of the
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
27 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 * OTHER DEALINGS IN THE SOFTWARE.
35 #include <linux/agp_backend.h>
36 #include <linux/cdev.h>
37 #include <linux/dma-mapping.h>
38 #include <linux/file.h>
40 #include <linux/highmem.h>
41 #include <linux/idr.h>
42 #include <linux/init.h>
44 #include <linux/jiffies.h>
45 #include <linux/kernel.h>
46 #include <linux/kref.h>
47 #include <linux/miscdevice.h>
49 #include <linux/mutex.h>
50 #include <linux/pci.h>
51 #include <linux/platform_device.h>
52 #include <linux/poll.h>
53 #include <linux/ratelimit.h>
54 #include <linux/rbtree.h>
55 #include <linux/sched.h>
56 #include <linux/slab.h>
57 #include <linux/types.h>
58 #include <linux/vmalloc.h>
59 #include <linux/workqueue.h>
60 #include <linux/dma-fence.h>
63 #include <asm/pgalloc.h>
64 #include <linux/uaccess.h>
66 #include <uapi/drm/drm.h>
67 #include <uapi/drm/drm_mode.h>
69 #include <drm/drm_agpsupport.h>
70 #include <drm/drm_crtc.h>
71 #include <drm/drm_fourcc.h>
72 #include <drm/drm_global.h>
73 #include <drm/drm_hashtab.h>
74 #include <drm/drm_mem_util.h>
75 #include <drm/drm_mm.h>
76 #include <drm/drm_os_linux.h>
77 #include <drm/drm_sarea.h>
78 #include <drm/drm_vma_manager.h>
79 #include <drm/drm_drv.h>
87 struct drm_device_dma;
88 struct drm_dma_handle;
89 struct drm_gem_object;
91 struct drm_vblank_crtc;
95 struct reservation_object;
96 struct dma_buf_attachment;
99 * The following categories are defined:
101 * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
102 * This is the category used by the DRM_DEBUG() macro.
104 * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
105 * This is the category used by the DRM_DEBUG_DRIVER() macro.
107 * KMS: used in the modesetting code.
108 * This is the category used by the DRM_DEBUG_KMS() macro.
110 * PRIME: used in the prime code.
111 * This is the category used by the DRM_DEBUG_PRIME() macro.
113 * ATOMIC: used in the atomic code.
114 * This is the category used by the DRM_DEBUG_ATOMIC() macro.
116 * VBL: used for verbose debug message in the vblank code
117 * This is the category used by the DRM_DEBUG_VBL() macro.
119 * Enabling verbose debug messages is done through the drm.debug parameter,
120 * each category being enabled by a bit.
122 * drm.debug=0x1 will enable CORE messages
123 * drm.debug=0x2 will enable DRIVER messages
124 * drm.debug=0x3 will enable CORE and DRIVER messages
126 * drm.debug=0x3f will enable all messages
128 * An interesting feature is that it's possible to enable verbose logging at
129 * run-time by echoing the debug value in its sysfs node:
130 * # echo 0xf > /sys/module/drm/parameters/debug
132 #define DRM_UT_NONE 0x00
133 #define DRM_UT_CORE 0x01
134 #define DRM_UT_DRIVER 0x02
135 #define DRM_UT_KMS 0x04
136 #define DRM_UT_PRIME 0x08
137 #define DRM_UT_ATOMIC 0x10
138 #define DRM_UT_VBL 0x20
139 #define DRM_UT_STATE 0x40
141 /***********************************************************************/
142 /** \name DRM template customization defaults */
145 /***********************************************************************/
146 /** \name Macros to make printk easier */
149 #define _DRM_PRINTK(once, level, fmt, ...) \
151 printk##once(KERN_##level "[" DRM_NAME "] " fmt, \
155 #define DRM_INFO(fmt, ...) \
156 _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
157 #define DRM_NOTE(fmt, ...) \
158 _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
159 #define DRM_WARN(fmt, ...) \
160 _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
162 #define DRM_INFO_ONCE(fmt, ...) \
163 _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
164 #define DRM_NOTE_ONCE(fmt, ...) \
165 _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
166 #define DRM_WARN_ONCE(fmt, ...) \
167 _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
172 * \param fmt printf() like format string.
173 * \param arg arguments
175 #define DRM_DEV_ERROR(dev, fmt, ...) \
176 drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\
178 #define DRM_ERROR(fmt, ...) \
179 drm_printk(KERN_ERR, DRM_UT_NONE, fmt, ##__VA_ARGS__)
182 * Rate limited error output. Like DRM_ERROR() but won't flood the log.
184 * \param fmt printf() like format string.
185 * \param arg arguments
187 #define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \
189 static DEFINE_RATELIMIT_STATE(_rs, \
190 DEFAULT_RATELIMIT_INTERVAL, \
191 DEFAULT_RATELIMIT_BURST); \
193 if (__ratelimit(&_rs)) \
194 DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \
196 #define DRM_ERROR_RATELIMITED(fmt, ...) \
197 DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
199 #define DRM_DEV_INFO(dev, fmt, ...) \
200 drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt, \
203 #define DRM_DEV_INFO_ONCE(dev, fmt, ...) \
205 static bool __print_once __read_mostly; \
206 if (!__print_once) { \
207 __print_once = true; \
208 DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \
215 * \param fmt printf() like format string.
216 * \param arg arguments
218 #define DRM_DEV_DEBUG(dev, fmt, args...) \
219 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_CORE, __func__, "", fmt, \
221 #define DRM_DEBUG(fmt, ...) \
222 drm_printk(KERN_DEBUG, DRM_UT_CORE, fmt, ##__VA_ARGS__)
224 #define DRM_DEV_DEBUG_DRIVER(dev, fmt, args...) \
225 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_DRIVER, __func__, "", \
227 #define DRM_DEBUG_DRIVER(fmt, ...) \
228 drm_printk(KERN_DEBUG, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
230 #define DRM_DEV_DEBUG_KMS(dev, fmt, args...) \
231 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_KMS, __func__, "", fmt, \
233 #define DRM_DEBUG_KMS(fmt, ...) \
234 drm_printk(KERN_DEBUG, DRM_UT_KMS, fmt, ##__VA_ARGS__)
236 #define DRM_DEV_DEBUG_PRIME(dev, fmt, args...) \
237 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_PRIME, __func__, "", \
239 #define DRM_DEBUG_PRIME(fmt, ...) \
240 drm_printk(KERN_DEBUG, DRM_UT_PRIME, fmt, ##__VA_ARGS__)
242 #define DRM_DEV_DEBUG_ATOMIC(dev, fmt, args...) \
243 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ATOMIC, __func__, "", \
245 #define DRM_DEBUG_ATOMIC(fmt, ...) \
246 drm_printk(KERN_DEBUG, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
248 #define DRM_DEV_DEBUG_VBL(dev, fmt, args...) \
249 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_VBL, __func__, "", fmt, \
251 #define DRM_DEBUG_VBL(fmt, ...) \
252 drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__)
254 #define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...) \
256 static DEFINE_RATELIMIT_STATE(_rs, \
257 DEFAULT_RATELIMIT_INTERVAL, \
258 DEFAULT_RATELIMIT_BURST); \
259 if (__ratelimit(&_rs)) \
260 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ ## level, \
261 __func__, "", fmt, ##args); \
265 * Rate limited debug output. Like DRM_DEBUG() but won't flood the log.
267 * \param fmt printf() like format string.
268 * \param arg arguments
270 #define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...) \
271 DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args)
272 #define DRM_DEBUG_RATELIMITED(fmt, args...) \
273 DRM_DEV_DEBUG_RATELIMITED(NULL, fmt, ##args)
274 #define DRM_DEV_DEBUG_DRIVER_RATELIMITED(dev, fmt, args...) \
275 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, DRIVER, fmt, ##args)
276 #define DRM_DEBUG_DRIVER_RATELIMITED(fmt, args...) \
277 DRM_DEV_DEBUG_DRIVER_RATELIMITED(NULL, fmt, ##args)
278 #define DRM_DEV_DEBUG_KMS_RATELIMITED(dev, fmt, args...) \
279 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, KMS, fmt, ##args)
280 #define DRM_DEBUG_KMS_RATELIMITED(fmt, args...) \
281 DRM_DEV_DEBUG_KMS_RATELIMITED(NULL, fmt, ##args)
282 #define DRM_DEV_DEBUG_PRIME_RATELIMITED(dev, fmt, args...) \
283 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, PRIME, fmt, ##args)
284 #define DRM_DEBUG_PRIME_RATELIMITED(fmt, args...) \
285 DRM_DEV_DEBUG_PRIME_RATELIMITED(NULL, fmt, ##args)
287 /* Format strings and argument splitters to simplify printing
288 * various "complex" objects
290 #define DRM_MODE_FMT "%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x"
291 #define DRM_MODE_ARG(m) \
292 (m)->base.id, (m)->name, (m)->vrefresh, (m)->clock, \
293 (m)->hdisplay, (m)->hsync_start, (m)->hsync_end, (m)->htotal, \
294 (m)->vdisplay, (m)->vsync_start, (m)->vsync_end, (m)->vtotal, \
295 (m)->type, (m)->flags
297 #define DRM_RECT_FMT "%dx%d%+d%+d"
298 #define DRM_RECT_ARG(r) drm_rect_width(r), drm_rect_height(r), (r)->x1, (r)->y1
300 /* for rect's in fixed-point format: */
301 #define DRM_RECT_FP_FMT "%d.%06ux%d.%06u%+d.%06u%+d.%06u"
302 #define DRM_RECT_FP_ARG(r) \
303 drm_rect_width(r) >> 16, ((drm_rect_width(r) & 0xffff) * 15625) >> 10, \
304 drm_rect_height(r) >> 16, ((drm_rect_height(r) & 0xffff) * 15625) >> 10, \
305 (r)->x1 >> 16, (((r)->x1 & 0xffff) * 15625) >> 10, \
306 (r)->y1 >> 16, (((r)->y1 & 0xffff) * 15625) >> 10
310 /***********************************************************************/
311 /** \name Internal types and structures */
314 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
317 * Ioctl function type.
319 * \param inode device inode.
320 * \param file_priv DRM file private pointer.
321 * \param cmd command.
322 * \param arg argument.
324 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
325 struct drm_file *file_priv);
327 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
330 #define DRM_IOCTL_NR(n) _IOC_NR(n)
331 #define DRM_MAJOR 226
334 #define DRM_MASTER 0x2
335 #define DRM_ROOT_ONLY 0x4
336 #define DRM_CONTROL_ALLOW 0x8
337 #define DRM_UNLOCKED 0x10
338 #define DRM_RENDER_ALLOW 0x20
340 struct drm_ioctl_desc {
348 * Creates a driver or general drm_ioctl_desc array entry for the given
349 * ioctl, for use by drm_ioctl().
352 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
353 [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = { \
354 .cmd = DRM_IOCTL_##ioctl, \
360 /* Event queued up for userspace to read */
361 struct drm_pending_event {
362 struct completion *completion;
363 struct drm_event *event;
364 struct dma_fence *fence;
365 struct list_head link;
366 struct list_head pending_link;
367 struct drm_file *file_priv;
368 pid_t pid; /* pid of requester, no guarantee it's valid by the time
369 we deliver the event, for tracing only */
372 struct drm_prime_file_private {
374 struct rb_root dmabufs;
375 struct rb_root handles;
378 /** File private data */
380 unsigned authenticated :1;
381 /* true when the client has asked us to expose stereo 3D mode flags */
382 unsigned stereo_allowed :1;
384 * true if client understands CRTC primary planes and cursor planes
387 unsigned universal_planes:1;
388 /* true if client understands atomic properties */
391 * This client is the creator of @master.
392 * Protected by struct drm_device::master_mutex.
394 unsigned is_master:1;
398 struct list_head lhead;
399 struct drm_minor *minor;
400 unsigned long lock_count;
402 /** Mapping of mm object handles to object pointers. */
403 struct idr object_idr;
404 /** Lock for synchronization of access to object_idr. */
405 spinlock_t table_lock;
410 struct drm_master *master; /* master this node is currently associated with
411 N.B. not always dev->master */
413 * fbs - List of framebuffers associated with this file.
415 * Protected by fbs_lock. Note that the fbs list holds a reference on
416 * the fb object to prevent it from untimely disappearing.
418 struct list_head fbs;
419 struct mutex fbs_lock;
421 /** User-created blob properties; this retains a reference on the
423 struct list_head blobs;
425 wait_queue_head_t event_wait;
426 struct list_head pending_event_list;
427 struct list_head event_list;
430 struct mutex event_read_lock;
432 struct drm_prime_file_private prime;
438 struct drm_lock_data {
439 struct drm_hw_lock *hw_lock; /**< Hardware lock */
440 /** Private of lock holder's file (NULL=kernel) */
441 struct drm_file *file_priv;
442 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
443 unsigned long lock_time; /**< Time of last lock in jiffies */
445 uint32_t kernel_waiters;
446 uint32_t user_waiters;
450 /* Flags and return codes for get_vblank_timestamp() driver function. */
451 #define DRM_CALLED_FROM_VBLIRQ 1
452 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
453 #define DRM_VBLANKTIME_IN_VBLANK (1 << 1)
455 /* get_scanout_position() return flags */
456 #define DRM_SCANOUTPOS_VALID (1 << 0)
457 #define DRM_SCANOUTPOS_IN_VBLANK (1 << 1)
458 #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
460 enum drm_minor_type {
468 * Info file list entry. This structure represents a debugfs or proc file to
469 * be created by the drm core
471 struct drm_info_list {
472 const char *name; /** file name */
473 int (*show)(struct seq_file*, void*); /** show callback */
474 u32 driver_features; /**< Required driver features for this entry */
479 * debugfs node structure. This structure represents a debugfs file.
481 struct drm_info_node {
482 struct list_head list;
483 struct drm_minor *minor;
484 const struct drm_info_list *info_ent;
489 * DRM minor structure. This structure represents a drm minor number.
492 int index; /**< Minor device number */
493 int type; /**< Control or render */
494 struct device *kdev; /**< Linux device */
495 struct drm_device *dev;
497 struct dentry *debugfs_root;
499 struct list_head debugfs_list;
500 struct mutex debugfs_lock; /* Protects debugfs_list. */
504 * DRM device structure. This structure represent a complete card that
505 * may contain multiple heads.
508 struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
509 int if_version; /**< Highest interface version set */
511 /** \name Lifetime Management */
513 struct kref ref; /**< Object ref-count */
514 struct device *dev; /**< Device structure of bus-device */
515 struct drm_driver *driver; /**< DRM driver managing the device */
516 void *dev_private; /**< DRM driver private data */
517 struct drm_minor *control; /**< Control node */
518 struct drm_minor *primary; /**< Primary node */
519 struct drm_minor *render; /**< Render node */
522 /* currently active master for this device. Protected by master_mutex */
523 struct drm_master *master;
525 atomic_t unplugged; /**< Flag whether dev is dead */
526 struct inode *anon_inode; /**< inode for private address-space */
527 char *unique; /**< unique name of the device */
532 struct mutex struct_mutex; /**< For others */
533 struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */
536 /** \name Usage Counters */
538 int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
539 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
540 int buf_use; /**< Buffers in use -- cannot alloc */
541 atomic_t buf_alloc; /**< Buffer allocation in progress */
544 struct mutex filelist_mutex;
545 struct list_head filelist;
547 /** \name Memory management */
549 struct list_head maplist; /**< Linked list of regions */
550 struct drm_open_hash map_hash; /**< User token hash table for maps */
552 /** \name Context handle management */
554 struct list_head ctxlist; /**< Linked list of context handles */
555 struct mutex ctxlist_mutex; /**< For ctxlist */
559 struct list_head vmalist; /**< List of vmas (for debugging) */
563 /** \name DMA support */
565 struct drm_device_dma *dma; /**< Optional pointer for DMA support */
568 /** \name Context support */
571 __volatile__ long context_flag; /**< Context swapping flag */
572 int last_context; /**< Last current context */
575 /** \name VBLANK IRQ support */
581 * If true, vblank interrupt will be disabled immediately when the
582 * refcount drops to zero, as opposed to via the vblank disable
584 * This can be set to true it the hardware has a working vblank
585 * counter and the driver uses drm_vblank_on() and drm_vblank_off()
588 bool vblank_disable_immediate;
590 /* array of size num_crtcs */
591 struct drm_vblank_crtc *vblank;
593 spinlock_t vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
596 u32 max_vblank_count; /**< size of vblank counter register */
601 struct list_head vblank_event_list;
602 spinlock_t event_lock;
606 struct drm_agp_head *agp; /**< AGP data */
608 struct pci_dev *pdev; /**< PCI device structure */
610 struct pci_controller *hose;
613 struct platform_device *platformdev; /**< Platform device struture */
614 struct virtio_device *virtdev;
616 struct drm_sg_mem *sg; /**< Scatter gather memory */
617 unsigned int num_crtcs; /**< Number of CRTCs on this device */
621 struct drm_hw_lock *lock;
624 struct drm_local_map *agp_buffer_map;
625 unsigned int agp_buffer_token;
627 struct drm_mode_config mode_config; /**< Current mode config */
629 /** \name GEM information */
631 struct mutex object_name_lock;
632 struct idr object_name_idr;
633 struct drm_vma_offset_manager *vma_offset_manager;
635 int switch_power_state;
638 #include <drm/drm_irq.h>
640 #define DRM_SWITCH_POWER_ON 0
641 #define DRM_SWITCH_POWER_OFF 1
642 #define DRM_SWITCH_POWER_CHANGING 2
643 #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
645 static __inline__ int drm_core_check_feature(struct drm_device *dev,
648 return ((dev->driver->driver_features & feature) ? 1 : 0);
651 static inline void drm_device_set_unplugged(struct drm_device *dev)
654 atomic_set(&dev->unplugged, 1);
657 static inline int drm_device_is_unplugged(struct drm_device *dev)
659 int ret = atomic_read(&dev->unplugged);
664 static inline bool drm_is_render_client(const struct drm_file *file_priv)
666 return file_priv->minor->type == DRM_MINOR_RENDER;
669 static inline bool drm_is_control_client(const struct drm_file *file_priv)
671 return file_priv->minor->type == DRM_MINOR_CONTROL;
674 static inline bool drm_is_primary_client(const struct drm_file *file_priv)
676 return file_priv->minor->type == DRM_MINOR_PRIMARY;
679 /******************************************************************/
680 /** \name Internal function definitions */
683 /* Driver support (drm_drv.h) */
684 extern int drm_ioctl_permit(u32 flags, struct drm_file *file_priv);
685 extern long drm_ioctl(struct file *filp,
686 unsigned int cmd, unsigned long arg);
688 extern long drm_compat_ioctl(struct file *filp,
689 unsigned int cmd, unsigned long arg);
691 /* Let drm_compat_ioctl be assigned to .compat_ioctl unconditionally */
692 #define drm_compat_ioctl NULL
694 extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
696 /* File Operations (drm_fops.c) */
697 int drm_open(struct inode *inode, struct file *filp);
698 ssize_t drm_read(struct file *filp, char __user *buffer,
699 size_t count, loff_t *offset);
700 int drm_release(struct inode *inode, struct file *filp);
701 unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
702 int drm_event_reserve_init_locked(struct drm_device *dev,
703 struct drm_file *file_priv,
704 struct drm_pending_event *p,
705 struct drm_event *e);
706 int drm_event_reserve_init(struct drm_device *dev,
707 struct drm_file *file_priv,
708 struct drm_pending_event *p,
709 struct drm_event *e);
710 void drm_event_cancel_free(struct drm_device *dev,
711 struct drm_pending_event *p);
712 void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
713 void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
715 /* Misc. IOCTL support (drm_ioctl.c) */
716 int drm_noop(struct drm_device *dev, void *data,
717 struct drm_file *file_priv);
718 int drm_invalid_op(struct drm_device *dev, void *data,
719 struct drm_file *file_priv);
721 /* Cache management (drm_cache.c) */
722 void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
723 void drm_clflush_sg(struct sg_table *st);
724 void drm_clflush_virt_range(void *addr, unsigned long length);
727 * These are exported to drivers so that they can implement fencing using
728 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
731 /* Debugfs support */
732 #if defined(CONFIG_DEBUG_FS)
733 extern int drm_debugfs_create_files(const struct drm_info_list *files,
734 int count, struct dentry *root,
735 struct drm_minor *minor);
736 extern int drm_debugfs_remove_files(const struct drm_info_list *files,
737 int count, struct drm_minor *minor);
739 static inline int drm_debugfs_create_files(const struct drm_info_list *files,
740 int count, struct dentry *root,
741 struct drm_minor *minor)
746 static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
747 int count, struct drm_minor *minor)
753 struct dma_buf_export_info;
755 extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
756 struct drm_gem_object *obj,
758 extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
759 struct drm_file *file_priv, uint32_t handle, uint32_t flags,
761 extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
762 struct dma_buf *dma_buf);
763 extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
764 struct drm_file *file_priv, int prime_fd, uint32_t *handle);
765 struct dma_buf *drm_gem_dmabuf_export(struct drm_device *dev,
766 struct dma_buf_export_info *exp_info);
767 extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
769 extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
770 dma_addr_t *addrs, int max_pages);
771 extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, unsigned int nr_pages);
772 extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
775 extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size,
777 extern void drm_pci_free(struct drm_device *dev, struct drm_dma_handle * dmah);
779 /* sysfs support (drm_sysfs.c) */
780 extern void drm_sysfs_hotplug_event(struct drm_device *dev);
786 static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
788 if (dev->driver->device_is_agp != NULL) {
789 int err = (*dev->driver->device_is_agp) (dev);
796 return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
798 void drm_pci_agp_destroy(struct drm_device *dev);
800 extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
801 extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
803 extern int drm_get_pci_dev(struct pci_dev *pdev,
804 const struct pci_device_id *ent,
805 struct drm_driver *driver);
806 extern int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master);
808 static inline int drm_get_pci_dev(struct pci_dev *pdev,
809 const struct pci_device_id *ent,
810 struct drm_driver *driver)
815 static inline int drm_pci_set_busid(struct drm_device *dev,
816 struct drm_master *master)
822 #define DRM_PCIE_SPEED_25 1
823 #define DRM_PCIE_SPEED_50 2
824 #define DRM_PCIE_SPEED_80 4
826 extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
827 extern int drm_pcie_get_max_link_width(struct drm_device *dev, u32 *mlw);
829 /* platform section */
830 extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);
832 /* returns true if currently okay to sleep */
833 static __inline__ bool drm_can_sleep(void)
835 if (in_atomic() || in_dbg_master() || irqs_disabled())
840 /* helper for handling conditionals in various for_each macros */
841 #define for_each_if(condition) if (!(condition)) {} else