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 #include <linux/agp_backend.h>
39 #include <linux/cdev.h>
40 #include <linux/dma-mapping.h>
41 #include <linux/file.h>
43 #include <linux/highmem.h>
44 #include <linux/idr.h>
45 #include <linux/init.h>
47 #include <linux/jiffies.h>
48 #include <linux/kernel.h>
49 #include <linux/kref.h>
50 #include <linux/miscdevice.h>
52 #include <linux/mutex.h>
53 #include <linux/pci.h>
54 #include <linux/platform_device.h>
55 #include <linux/poll.h>
56 #include <linux/ratelimit.h>
57 #include <linux/sched.h>
58 #include <linux/slab.h>
59 #include <linux/types.h>
60 #include <linux/vmalloc.h>
61 #include <linux/workqueue.h>
64 #include <asm/pgalloc.h>
65 #include <asm/uaccess.h>
68 #include <drm/drm_hashtab.h>
69 #include <drm/drm_mm.h>
70 #include <drm/drm_os_linux.h>
71 #include <drm/drm_sarea.h>
72 #include <drm/drm_vma_manager.h>
82 struct reservation_object;
85 * 4 debug categories are defined:
87 * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
88 * This is the category used by the DRM_DEBUG() macro.
90 * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
91 * This is the category used by the DRM_DEBUG_DRIVER() macro.
93 * KMS: used in the modesetting code.
94 * This is the category used by the DRM_DEBUG_KMS() macro.
96 * PRIME: used in the prime code.
97 * This is the category used by the DRM_DEBUG_PRIME() macro.
99 * Enabling verbose debug messages is done through the drm.debug parameter,
100 * each category being enabled by a bit.
102 * drm.debug=0x1 will enable CORE messages
103 * drm.debug=0x2 will enable DRIVER messages
104 * drm.debug=0x3 will enable CORE and DRIVER messages
106 * drm.debug=0xf will enable all messages
108 * An interesting feature is that it's possible to enable verbose logging at
109 * run-time by echoing the debug value in its sysfs node:
110 * # echo 0xf > /sys/module/drm/parameters/debug
112 #define DRM_UT_CORE 0x01
113 #define DRM_UT_DRIVER 0x02
114 #define DRM_UT_KMS 0x04
115 #define DRM_UT_PRIME 0x08
117 extern __printf(2, 3)
118 void drm_ut_debug_printk(const char *function_name,
119 const char *format, ...);
120 extern __printf(2, 3)
121 int drm_err(const char *func, const char *format, ...);
123 /***********************************************************************/
124 /** \name DRM template customization defaults */
127 /* driver capabilities and requirements mask */
128 #define DRIVER_USE_AGP 0x1
129 #define DRIVER_PCI_DMA 0x8
130 #define DRIVER_SG 0x10
131 #define DRIVER_HAVE_DMA 0x20
132 #define DRIVER_HAVE_IRQ 0x40
133 #define DRIVER_IRQ_SHARED 0x80
134 #define DRIVER_GEM 0x1000
135 #define DRIVER_MODESET 0x2000
136 #define DRIVER_PRIME 0x4000
137 #define DRIVER_RENDER 0x8000
139 /***********************************************************************/
140 /** \name Begin the DRM... */
143 #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
147 /***********************************************************************/
148 /** \name Macros to make printk easier */
154 * \param fmt printf() like format string.
155 * \param arg arguments
157 #define DRM_ERROR(fmt, ...) \
158 drm_err(__func__, fmt, ##__VA_ARGS__)
161 * Rate limited error output. Like DRM_ERROR() but won't flood the log.
163 * \param fmt printf() like format string.
164 * \param arg arguments
166 #define DRM_ERROR_RATELIMITED(fmt, ...) \
168 static DEFINE_RATELIMIT_STATE(_rs, \
169 DEFAULT_RATELIMIT_INTERVAL, \
170 DEFAULT_RATELIMIT_BURST); \
172 if (__ratelimit(&_rs)) \
173 drm_err(__func__, fmt, ##__VA_ARGS__); \
176 #define DRM_INFO(fmt, ...) \
177 printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
179 #define DRM_INFO_ONCE(fmt, ...) \
180 printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
185 * \param fmt printf() like format string.
186 * \param arg arguments
188 #define DRM_DEBUG(fmt, args...) \
190 if (unlikely(drm_debug & DRM_UT_CORE)) \
191 drm_ut_debug_printk(__func__, fmt, ##args); \
194 #define DRM_DEBUG_DRIVER(fmt, args...) \
196 if (unlikely(drm_debug & DRM_UT_DRIVER)) \
197 drm_ut_debug_printk(__func__, fmt, ##args); \
199 #define DRM_DEBUG_KMS(fmt, args...) \
201 if (unlikely(drm_debug & DRM_UT_KMS)) \
202 drm_ut_debug_printk(__func__, fmt, ##args); \
204 #define DRM_DEBUG_PRIME(fmt, args...) \
206 if (unlikely(drm_debug & DRM_UT_PRIME)) \
207 drm_ut_debug_printk(__func__, fmt, ##args); \
212 /***********************************************************************/
213 /** \name Internal types and structures */
216 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
219 * Test that the hardware lock is held by the caller, returning otherwise.
221 * \param dev DRM device.
222 * \param filp file pointer of the caller.
224 #define LOCK_TEST_WITH_RETURN( dev, _file_priv ) \
226 if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) || \
227 _file_priv->master->lock.file_priv != _file_priv) { \
228 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
229 __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
230 _file_priv->master->lock.file_priv, _file_priv); \
236 * Ioctl function type.
238 * \param inode device inode.
239 * \param file_priv DRM file private pointer.
240 * \param cmd command.
241 * \param arg argument.
243 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
244 struct drm_file *file_priv);
246 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
249 #define DRM_IOCTL_NR(n) _IOC_NR(n)
250 #define DRM_MAJOR 226
253 #define DRM_MASTER 0x2
254 #define DRM_ROOT_ONLY 0x4
255 #define DRM_CONTROL_ALLOW 0x8
256 #define DRM_UNLOCKED 0x10
257 #define DRM_RENDER_ALLOW 0x20
259 struct drm_ioctl_desc {
263 unsigned int cmd_drv;
268 * Creates a driver or general drm_ioctl_desc array entry for the given
269 * ioctl, for use by drm_ioctl().
272 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
273 [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl, .name = #ioctl}
279 int idx; /**< Index into master buflist */
280 int total; /**< Buffer size */
281 int order; /**< log-base-2(total) */
282 int used; /**< Amount of buffer in use (for DMA) */
283 unsigned long offset; /**< Byte offset (used internally) */
284 void *address; /**< Address of buffer */
285 unsigned long bus_address; /**< Bus address of buffer */
286 struct drm_buf *next; /**< Kernel-only: used for free list */
287 __volatile__ int waiting; /**< On kernel DMA queue */
288 __volatile__ int pending; /**< On hardware DMA queue */
289 struct drm_file *file_priv; /**< Private of holding file descr */
290 int context; /**< Kernel queue for this buffer */
291 int while_locked; /**< Dispatch this buffer while locked */
299 } list; /**< Which list we're on */
301 int dev_priv_size; /**< Size of buffer private storage */
302 void *dev_private; /**< Per-buffer private storage */
305 typedef struct drm_dma_handle {
312 * Buffer entry. There is one of this for each buffer size order.
314 struct drm_buf_entry {
315 int buf_size; /**< size */
316 int buf_count; /**< number of buffers */
317 struct drm_buf *buflist; /**< buffer list */
320 struct drm_dma_handle **seglist;
322 int low_mark; /**< Low water mark */
323 int high_mark; /**< High water mark */
326 /* Event queued up for userspace to read */
327 struct drm_pending_event {
328 struct drm_event *event;
329 struct list_head link;
330 struct drm_file *file_priv;
331 pid_t pid; /* pid of requester, no guarantee it's valid by the time
332 we deliver the event, for tracing only */
333 void (*destroy)(struct drm_pending_event *event);
336 /* initial implementaton using a linked list - todo hashtab */
337 struct drm_prime_file_private {
338 struct list_head head;
342 /** File private data */
344 unsigned authenticated :1;
345 /* Whether we're master for a minor. Protected by master_mutex */
346 unsigned is_master :1;
347 /* true when the client has asked us to expose stereo 3D mode flags */
348 unsigned stereo_allowed :1;
350 * true if client understands CRTC primary planes and cursor planes
353 unsigned universal_planes:1;
358 struct list_head lhead;
359 struct drm_minor *minor;
360 unsigned long lock_count;
362 /** Mapping of mm object handles to object pointers. */
363 struct idr object_idr;
364 /** Lock for synchronization of access to object_idr. */
365 spinlock_t table_lock;
370 struct drm_master *master; /* master this node is currently associated with
371 N.B. not always minor->master */
373 * fbs - List of framebuffers associated with this file.
375 * Protected by fbs_lock. Note that the fbs list holds a reference on
376 * the fb object to prevent it from untimely disappearing.
378 struct list_head fbs;
379 struct mutex fbs_lock;
381 wait_queue_head_t event_wait;
382 struct list_head event_list;
385 struct drm_prime_file_private prime;
391 struct drm_lock_data {
392 struct drm_hw_lock *hw_lock; /**< Hardware lock */
393 /** Private of lock holder's file (NULL=kernel) */
394 struct drm_file *file_priv;
395 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
396 unsigned long lock_time; /**< Time of last lock in jiffies */
398 uint32_t kernel_waiters;
399 uint32_t user_waiters;
406 struct drm_device_dma {
408 struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
409 int buf_count; /**< total number of buffers */
410 struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
412 int page_count; /**< number of pages */
413 unsigned long *pagelist; /**< page list */
414 unsigned long byte_count;
416 _DRM_DMA_USE_AGP = 0x01,
417 _DRM_DMA_USE_SG = 0x02,
418 _DRM_DMA_USE_FB = 0x04,
419 _DRM_DMA_USE_PCI_RO = 0x08
425 * Scatter-gather memory.
428 unsigned long handle;
431 struct page **pagelist;
436 * Kernel side of a mapping
438 struct drm_local_map {
439 resource_size_t offset; /**< Requested physical address (0 for SAREA)*/
440 unsigned long size; /**< Requested physical size (bytes) */
441 enum drm_map_type type; /**< Type of memory to map */
442 enum drm_map_flags flags; /**< Flags */
443 void *handle; /**< User-space: "Handle" to pass to mmap() */
444 /**< Kernel-space: kernel-virtual address */
445 int mtrr; /**< MTRR slot used */
448 typedef struct drm_local_map drm_local_map_t;
453 struct drm_map_list {
454 struct list_head head; /**< list head */
455 struct drm_hash_item hash;
456 struct drm_local_map *map; /**< mapping */
458 struct drm_master *master;
461 /* location of GART table */
462 #define DRM_ATI_GART_MAIN 1
463 #define DRM_ATI_GART_FB 2
465 #define DRM_ATI_GART_PCI 1
466 #define DRM_ATI_GART_PCIE 2
467 #define DRM_ATI_GART_IGP 3
469 struct drm_ati_pcigart_info {
470 int gart_table_location;
474 dma_addr_t table_mask;
475 struct drm_dma_handle *table_handle;
476 struct drm_local_map mapping;
481 * This structure defines the drm_mm memory object, which will be used by the
482 * DRM for its buffer objects.
484 struct drm_gem_object {
485 /** Reference count of this object */
486 struct kref refcount;
489 * handle_count - gem file_priv handle count of this object
491 * Each handle also holds a reference. Note that when the handle_count
492 * drops to 0 any global names (e.g. the id in the flink namespace) will
495 * Protected by dev->object_name_lock.
497 unsigned handle_count;
499 /** Related drm device */
500 struct drm_device *dev;
502 /** File representing the shmem storage */
505 /* Mapping info for this object */
506 struct drm_vma_offset_node vma_node;
509 * Size of the object, in bytes. Immutable over the object's
515 * Global name for this object, starts at 1. 0 means unnamed.
516 * Access is covered by the object_name_lock in the related drm_device
521 * Memory domains. These monitor which caches contain read/write data
522 * related to the object. When transitioning from one set of domains
523 * to another, the driver is called to ensure that caches are suitably
524 * flushed and invalidated
526 uint32_t read_domains;
527 uint32_t write_domain;
530 * While validating an exec operation, the
531 * new read/write domain values are computed here.
532 * They will be transferred to the above values
533 * at the point that any cache flushing occurs
535 uint32_t pending_read_domains;
536 uint32_t pending_write_domain;
539 * dma_buf - dma buf associated with this GEM object
541 * Pointer to the dma-buf associated with this gem object (either
542 * through importing or exporting). We break the resulting reference
543 * loop when the last gem handle for this object is released.
545 * Protected by obj->object_name_lock
547 struct dma_buf *dma_buf;
550 * import_attach - dma buf attachment backing this object
552 * Any foreign dma_buf imported as a gem object has this set to the
553 * attachment point for the device. This is invariant over the lifetime
556 * The driver's ->gem_free_object callback is responsible for cleaning
557 * up the dma_buf attachment and references acquired at import time.
559 * Note that the drm gem/prime core does not depend upon drivers setting
560 * this field any more. So for drivers where this doesn't make sense
561 * (e.g. virtual devices or a displaylink behind an usb bus) they can
562 * simply leave it as NULL.
564 struct dma_buf_attachment *import_attach;
567 #include <drm/drm_crtc.h>
570 * struct drm_master - drm master structure
572 * @refcount: Refcount for this master object.
573 * @minor: Link back to minor char device we are master for. Immutable.
574 * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex.
575 * @unique_len: Length of unique field. Protected by drm_global_mutex.
576 * @unique_size: Amount allocated. Protected by drm_global_mutex.
577 * @magiclist: Hash of used authentication tokens. Protected by struct_mutex.
578 * @magicfree: List of used authentication tokens. Protected by struct_mutex.
579 * @lock: DRI lock information.
580 * @driver_priv: Pointer to driver-private information.
583 struct kref refcount;
584 struct drm_minor *minor;
588 struct drm_open_hash magiclist;
589 struct list_head magicfree;
590 struct drm_lock_data lock;
594 /* Size of ringbuffer for vblank timestamps. Just double-buffer
595 * in initial implementation.
597 #define DRM_VBLANKTIME_RBSIZE 2
599 /* Flags and return codes for get_vblank_timestamp() driver function. */
600 #define DRM_CALLED_FROM_VBLIRQ 1
601 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
602 #define DRM_VBLANKTIME_INVBL (1 << 1)
604 /* get_scanout_position() return flags */
605 #define DRM_SCANOUTPOS_VALID (1 << 0)
606 #define DRM_SCANOUTPOS_INVBL (1 << 1)
607 #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
610 int (*set_busid)(struct drm_device *dev, struct drm_master *master);
614 * DRM driver structure. This structure represent the common code for
615 * a family of cards. There will one drm_device for each card present
619 int (*load) (struct drm_device *, unsigned long flags);
620 int (*firstopen) (struct drm_device *);
621 int (*open) (struct drm_device *, struct drm_file *);
622 void (*preclose) (struct drm_device *, struct drm_file *file_priv);
623 void (*postclose) (struct drm_device *, struct drm_file *);
624 void (*lastclose) (struct drm_device *);
625 int (*unload) (struct drm_device *);
626 int (*suspend) (struct drm_device *, pm_message_t state);
627 int (*resume) (struct drm_device *);
628 int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
629 int (*dma_quiescent) (struct drm_device *);
630 int (*context_dtor) (struct drm_device *dev, int context);
633 * get_vblank_counter - get raw hardware vblank counter
635 * @crtc: counter to fetch
637 * Driver callback for fetching a raw hardware vblank counter for @crtc.
638 * If a device doesn't have a hardware counter, the driver can simply
639 * return the value of drm_vblank_count. The DRM core will account for
640 * missed vblank events while interrupts where disabled based on system
643 * Wraparound handling and loss of events due to modesetting is dealt
644 * with in the DRM core code.
647 * Raw vblank counter value.
649 u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
652 * enable_vblank - enable vblank interrupt events
654 * @crtc: which irq to enable
656 * Enable vblank interrupts for @crtc. If the device doesn't have
657 * a hardware vblank counter, this routine should be a no-op, since
658 * interrupts will have to stay on to keep the count accurate.
661 * Zero on success, appropriate errno if the given @crtc's vblank
662 * interrupt cannot be enabled.
664 int (*enable_vblank) (struct drm_device *dev, int crtc);
667 * disable_vblank - disable vblank interrupt events
669 * @crtc: which irq to enable
671 * Disable vblank interrupts for @crtc. If the device doesn't have
672 * a hardware vblank counter, this routine should be a no-op, since
673 * interrupts will have to stay on to keep the count accurate.
675 void (*disable_vblank) (struct drm_device *dev, int crtc);
678 * Called by \c drm_device_is_agp. Typically used to determine if a
679 * card is really attached to AGP or not.
681 * \param dev DRM device handle
684 * One of three values is returned depending on whether or not the
685 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
686 * (return of 1), or may or may not be AGP (return of 2).
688 int (*device_is_agp) (struct drm_device *dev);
691 * Called by vblank timestamping code.
693 * Return the current display scanout position from a crtc, and an
694 * optional accurate ktime_get timestamp of when position was measured.
696 * \param dev DRM device.
697 * \param crtc Id of the crtc to query.
698 * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
699 * \param *vpos Target location for current vertical scanout position.
700 * \param *hpos Target location for current horizontal scanout position.
701 * \param *stime Target location for timestamp taken immediately before
702 * scanout position query. Can be NULL to skip timestamp.
703 * \param *etime Target location for timestamp taken immediately after
704 * scanout position query. Can be NULL to skip timestamp.
706 * Returns vpos as a positive number while in active scanout area.
707 * Returns vpos as a negative number inside vblank, counting the number
708 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
709 * until start of active scanout / end of vblank."
711 * \return Flags, or'ed together as follows:
713 * DRM_SCANOUTPOS_VALID = Query successful.
714 * DRM_SCANOUTPOS_INVBL = Inside vblank.
715 * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
716 * this flag means that returned position may be offset by a constant
717 * but unknown small number of scanlines wrt. real scanout position.
720 int (*get_scanout_position) (struct drm_device *dev, int crtc,
722 int *vpos, int *hpos, ktime_t *stime,
726 * Called by \c drm_get_last_vbltimestamp. Should return a precise
727 * timestamp when the most recent VBLANK interval ended or will end.
729 * Specifically, the timestamp in @vblank_time should correspond as
730 * closely as possible to the time when the first video scanline of
731 * the video frame after the end of VBLANK will start scanning out,
732 * the time immediately after end of the VBLANK interval. If the
733 * @crtc is currently inside VBLANK, this will be a time in the future.
734 * If the @crtc is currently scanning out a frame, this will be the
735 * past start time of the current scanout. This is meant to adhere
736 * to the OpenML OML_sync_control extension specification.
738 * \param dev dev DRM device handle.
739 * \param crtc crtc for which timestamp should be returned.
740 * \param *max_error Maximum allowable timestamp error in nanoseconds.
741 * Implementation should strive to provide timestamp
742 * with an error of at most *max_error nanoseconds.
743 * Returns true upper bound on error for timestamp.
744 * \param *vblank_time Target location for returned vblank timestamp.
745 * \param flags 0 = Defaults, no special treatment needed.
746 * \param DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
747 * irq handler. Some drivers need to apply some workarounds
748 * for gpu-specific vblank irq quirks if flag is set.
751 * Zero if timestamping isn't supported in current display mode or a
752 * negative number on failure. A positive status code on success,
753 * which describes how the vblank_time timestamp was computed.
755 int (*get_vblank_timestamp) (struct drm_device *dev, int crtc,
757 struct timeval *vblank_time,
760 /* these have to be filled in */
762 irqreturn_t(*irq_handler) (int irq, void *arg);
763 void (*irq_preinstall) (struct drm_device *dev);
764 int (*irq_postinstall) (struct drm_device *dev);
765 void (*irq_uninstall) (struct drm_device *dev);
767 /* Master routines */
768 int (*master_create)(struct drm_device *dev, struct drm_master *master);
769 void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
771 * master_set is called whenever the minor master is set.
772 * master_drop is called whenever the minor master is dropped.
775 int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
777 void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv,
780 int (*debugfs_init)(struct drm_minor *minor);
781 void (*debugfs_cleanup)(struct drm_minor *minor);
784 * Driver-specific constructor for drm_gem_objects, to set up
785 * obj->driver_private.
787 * Returns 0 on success.
789 void (*gem_free_object) (struct drm_gem_object *obj);
790 int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
791 void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
794 /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
795 int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
796 uint32_t handle, uint32_t flags, int *prime_fd);
797 /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
798 int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
799 int prime_fd, uint32_t *handle);
800 /* export GEM -> dmabuf */
801 struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
802 struct drm_gem_object *obj, int flags);
803 /* import dmabuf -> GEM */
804 struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
805 struct dma_buf *dma_buf);
806 /* low-level interface used by drm_gem_prime_{import,export} */
807 int (*gem_prime_pin)(struct drm_gem_object *obj);
808 void (*gem_prime_unpin)(struct drm_gem_object *obj);
809 struct reservation_object * (*gem_prime_res_obj)(
810 struct drm_gem_object *obj);
811 struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
812 struct drm_gem_object *(*gem_prime_import_sg_table)(
813 struct drm_device *dev, size_t size,
814 struct sg_table *sgt);
815 void *(*gem_prime_vmap)(struct drm_gem_object *obj);
816 void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
817 int (*gem_prime_mmap)(struct drm_gem_object *obj,
818 struct vm_area_struct *vma);
820 /* vga arb irq handler */
821 void (*vgaarb_irq)(struct drm_device *dev, bool state);
823 /* dumb alloc support */
824 int (*dumb_create)(struct drm_file *file_priv,
825 struct drm_device *dev,
826 struct drm_mode_create_dumb *args);
827 int (*dumb_map_offset)(struct drm_file *file_priv,
828 struct drm_device *dev, uint32_t handle,
830 int (*dumb_destroy)(struct drm_file *file_priv,
831 struct drm_device *dev,
834 /* Driver private ops for this object */
835 const struct vm_operations_struct *gem_vm_ops;
846 const struct drm_ioctl_desc *ioctls;
848 const struct file_operations *fops;
851 /* List of devices hanging off this driver with stealth attach. */
852 struct list_head legacy_dev_list;
855 enum drm_minor_type {
863 * Info file list entry. This structure represents a debugfs or proc file to
864 * be created by the drm core
866 struct drm_info_list {
867 const char *name; /** file name */
868 int (*show)(struct seq_file*, void*); /** show callback */
869 u32 driver_features; /**< Required driver features for this entry */
874 * debugfs node structure. This structure represents a debugfs file.
876 struct drm_info_node {
877 struct list_head list;
878 struct drm_minor *minor;
879 const struct drm_info_list *info_ent;
884 * DRM minor structure. This structure represents a drm minor number.
887 int index; /**< Minor device number */
888 int type; /**< Control or render */
889 struct device *kdev; /**< Linux device */
890 struct drm_device *dev;
892 struct dentry *debugfs_root;
894 struct list_head debugfs_list;
895 struct mutex debugfs_lock; /* Protects debugfs_list. */
897 /* currently active master for this node. Protected by master_mutex */
898 struct drm_master *master;
899 struct drm_mode_group mode_group;
903 struct drm_pending_vblank_event {
904 struct drm_pending_event base;
906 struct drm_event_vblank event;
909 struct drm_vblank_crtc {
910 struct drm_device *dev; /* pointer to the drm_device */
911 wait_queue_head_t queue; /**< VBLANK wait queue */
912 struct timeval time[DRM_VBLANKTIME_RBSIZE]; /**< timestamp of current count */
913 struct timer_list disable_timer; /* delayed disable timer */
914 atomic_t count; /**< number of VBLANK interrupts */
915 atomic_t refcount; /* number of users of vblank interruptsper crtc */
916 u32 last; /* protected by dev->vbl_lock, used */
917 /* for wraparound handling */
918 u32 last_wait; /* Last vblank seqno waited per CRTC */
919 unsigned int inmodeset; /* Display driver is setting mode */
920 int crtc; /* crtc index */
921 bool enabled; /* so we don't call enable more than
926 * DRM device structure. This structure represent a complete card that
927 * may contain multiple heads.
930 struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
931 int if_version; /**< Highest interface version set */
933 /** \name Lifetime Management */
935 struct kref ref; /**< Object ref-count */
936 struct device *dev; /**< Device structure of bus-device */
937 struct drm_driver *driver; /**< DRM driver managing the device */
938 void *dev_private; /**< DRM driver private data */
939 struct drm_minor *control; /**< Control node */
940 struct drm_minor *primary; /**< Primary node */
941 struct drm_minor *render; /**< Render node */
942 atomic_t unplugged; /**< Flag whether dev is dead */
943 struct inode *anon_inode; /**< inode for private address-space */
944 char *unique; /**< unique name of the device */
949 struct mutex struct_mutex; /**< For others */
950 struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */
953 /** \name Usage Counters */
955 int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
956 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
957 int buf_use; /**< Buffers in use -- cannot alloc */
958 atomic_t buf_alloc; /**< Buffer allocation in progress */
961 struct list_head filelist;
963 /** \name Memory management */
965 struct list_head maplist; /**< Linked list of regions */
966 struct drm_open_hash map_hash; /**< User token hash table for maps */
968 /** \name Context handle management */
970 struct list_head ctxlist; /**< Linked list of context handles */
971 struct mutex ctxlist_mutex; /**< For ctxlist */
975 struct list_head vmalist; /**< List of vmas (for debugging) */
979 /** \name DMA support */
981 struct drm_device_dma *dma; /**< Optional pointer for DMA support */
984 /** \name Context support */
986 bool irq_enabled; /**< True if irq handler is enabled */
989 __volatile__ long context_flag; /**< Context swapping flag */
990 int last_context; /**< Last current context */
993 /** \name VBLANK IRQ support */
997 * At load time, disabling the vblank interrupt won't be allowed since
998 * old clients may not call the modeset ioctl and therefore misbehave.
999 * Once the modeset ioctl *has* been called though, we can safely
1000 * disable them when unused.
1002 bool vblank_disable_allowed;
1004 /* array of size num_crtcs */
1005 struct drm_vblank_crtc *vblank;
1007 spinlock_t vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
1008 spinlock_t vbl_lock;
1010 u32 max_vblank_count; /**< size of vblank counter register */
1015 struct list_head vblank_event_list;
1016 spinlock_t event_lock;
1020 struct drm_agp_head *agp; /**< AGP data */
1022 struct pci_dev *pdev; /**< PCI device structure */
1024 struct pci_controller *hose;
1027 struct platform_device *platformdev; /**< Platform device struture */
1028 struct usb_device *usbdev;
1030 struct drm_sg_mem *sg; /**< Scatter gather memory */
1031 unsigned int num_crtcs; /**< Number of CRTCs on this device */
1036 struct drm_hw_lock *lock;
1039 struct drm_local_map *agp_buffer_map;
1040 unsigned int agp_buffer_token;
1042 struct drm_mode_config mode_config; /**< Current mode config */
1044 /** \name GEM information */
1046 struct mutex object_name_lock;
1047 struct idr object_name_idr;
1048 struct drm_vma_offset_manager *vma_offset_manager;
1050 int switch_power_state;
1053 #define DRM_SWITCH_POWER_ON 0
1054 #define DRM_SWITCH_POWER_OFF 1
1055 #define DRM_SWITCH_POWER_CHANGING 2
1056 #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
1058 static __inline__ int drm_core_check_feature(struct drm_device *dev,
1061 return ((dev->driver->driver_features & feature) ? 1 : 0);
1064 static inline void drm_device_set_unplugged(struct drm_device *dev)
1067 atomic_set(&dev->unplugged, 1);
1070 static inline int drm_device_is_unplugged(struct drm_device *dev)
1072 int ret = atomic_read(&dev->unplugged);
1077 static inline bool drm_is_render_client(const struct drm_file *file_priv)
1079 return file_priv->minor->type == DRM_MINOR_RENDER;
1082 static inline bool drm_is_control_client(const struct drm_file *file_priv)
1084 return file_priv->minor->type == DRM_MINOR_CONTROL;
1087 static inline bool drm_is_primary_client(const struct drm_file *file_priv)
1089 return file_priv->minor->type == DRM_MINOR_LEGACY;
1092 /******************************************************************/
1093 /** \name Internal function definitions */
1096 /* Driver support (drm_drv.h) */
1097 extern long drm_ioctl(struct file *filp,
1098 unsigned int cmd, unsigned long arg);
1099 extern long drm_compat_ioctl(struct file *filp,
1100 unsigned int cmd, unsigned long arg);
1101 extern int drm_lastclose(struct drm_device *dev);
1102 extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
1104 /* Device support (drm_fops.h) */
1105 extern struct mutex drm_global_mutex;
1106 extern int drm_open(struct inode *inode, struct file *filp);
1107 extern ssize_t drm_read(struct file *filp, char __user *buffer,
1108 size_t count, loff_t *offset);
1109 extern int drm_release(struct inode *inode, struct file *filp);
1111 /* Mapping support (drm_vm.h) */
1112 extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
1113 extern int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma);
1114 extern void drm_vm_open_locked(struct drm_device *dev, struct vm_area_struct *vma);
1115 extern void drm_vm_close_locked(struct drm_device *dev, struct vm_area_struct *vma);
1116 extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
1118 /* Misc. IOCTL support (drm_ioctl.h) */
1119 extern int drm_irq_by_busid(struct drm_device *dev, void *data,
1120 struct drm_file *file_priv);
1121 extern int drm_getunique(struct drm_device *dev, void *data,
1122 struct drm_file *file_priv);
1123 extern int drm_setunique(struct drm_device *dev, void *data,
1124 struct drm_file *file_priv);
1125 extern int drm_getmap(struct drm_device *dev, void *data,
1126 struct drm_file *file_priv);
1127 extern int drm_getclient(struct drm_device *dev, void *data,
1128 struct drm_file *file_priv);
1129 extern int drm_getstats(struct drm_device *dev, void *data,
1130 struct drm_file *file_priv);
1131 extern int drm_getcap(struct drm_device *dev, void *data,
1132 struct drm_file *file_priv);
1133 extern int drm_setclientcap(struct drm_device *dev, void *data,
1134 struct drm_file *file_priv);
1135 extern int drm_setversion(struct drm_device *dev, void *data,
1136 struct drm_file *file_priv);
1137 extern int drm_noop(struct drm_device *dev, void *data,
1138 struct drm_file *file_priv);
1140 /* Authentication IOCTL support (drm_auth.h) */
1141 extern int drm_getmagic(struct drm_device *dev, void *data,
1142 struct drm_file *file_priv);
1143 extern int drm_authmagic(struct drm_device *dev, void *data,
1144 struct drm_file *file_priv);
1145 extern int drm_remove_magic(struct drm_master *master, drm_magic_t magic);
1147 /* Cache management (drm_cache.c) */
1148 void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
1149 void drm_clflush_sg(struct sg_table *st);
1150 void drm_clflush_virt_range(void *addr, unsigned long length);
1152 /* Locking IOCTL support (drm_lock.h) */
1153 extern int drm_lock(struct drm_device *dev, void *data,
1154 struct drm_file *file_priv);
1155 extern int drm_unlock(struct drm_device *dev, void *data,
1156 struct drm_file *file_priv);
1157 extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
1158 extern void drm_idlelock_take(struct drm_lock_data *lock_data);
1159 extern void drm_idlelock_release(struct drm_lock_data *lock_data);
1162 * These are exported to drivers so that they can implement fencing using
1163 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1166 extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
1168 /* DMA support (drm_dma.h) */
1169 extern int drm_legacy_dma_setup(struct drm_device *dev);
1170 extern void drm_legacy_dma_takedown(struct drm_device *dev);
1171 extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
1172 extern void drm_core_reclaim_buffers(struct drm_device *dev,
1173 struct drm_file *filp);
1175 /* IRQ support (drm_irq.h) */
1176 extern int drm_control(struct drm_device *dev, void *data,
1177 struct drm_file *file_priv);
1178 extern int drm_irq_install(struct drm_device *dev, int irq);
1179 extern int drm_irq_uninstall(struct drm_device *dev);
1181 extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1182 extern int drm_wait_vblank(struct drm_device *dev, void *data,
1183 struct drm_file *filp);
1184 extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1185 extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
1186 struct timeval *vblanktime);
1187 extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
1188 struct drm_pending_vblank_event *e);
1189 extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
1190 extern int drm_vblank_get(struct drm_device *dev, int crtc);
1191 extern void drm_vblank_put(struct drm_device *dev, int crtc);
1192 extern int drm_crtc_vblank_get(struct drm_crtc *crtc);
1193 extern void drm_crtc_vblank_put(struct drm_crtc *crtc);
1194 extern void drm_wait_one_vblank(struct drm_device *dev, int crtc);
1195 extern void drm_crtc_wait_one_vblank(struct drm_crtc *crtc);
1196 extern void drm_vblank_off(struct drm_device *dev, int crtc);
1197 extern void drm_vblank_on(struct drm_device *dev, int crtc);
1198 extern void drm_crtc_vblank_off(struct drm_crtc *crtc);
1199 extern void drm_crtc_vblank_on(struct drm_crtc *crtc);
1200 extern void drm_vblank_cleanup(struct drm_device *dev);
1202 extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
1203 struct timeval *tvblank, unsigned flags);
1204 extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
1205 int crtc, int *max_error,
1206 struct timeval *vblank_time,
1208 const struct drm_crtc *refcrtc,
1209 const struct drm_display_mode *mode);
1210 extern void drm_calc_timestamping_constants(struct drm_crtc *crtc,
1211 const struct drm_display_mode *mode);
1214 * drm_crtc_vblank_waitqueue - get vblank waitqueue for the CRTC
1215 * @crtc: which CRTC's vblank waitqueue to retrieve
1217 * This function returns a pointer to the vblank waitqueue for the CRTC.
1218 * Drivers can use this to implement vblank waits using wait_event() & co.
1220 static inline wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc)
1222 return &crtc->dev->vblank[drm_crtc_index(crtc)].queue;
1225 /* Modesetting support */
1226 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
1227 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
1228 extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1229 struct drm_file *file_priv);
1231 /* AGP/GART support (drm_agpsupport.h) */
1233 #include <drm/drm_agpsupport.h>
1235 /* Stub support (drm_stub.h) */
1236 extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1237 struct drm_file *file_priv);
1238 extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1239 struct drm_file *file_priv);
1240 struct drm_master *drm_master_create(struct drm_minor *minor);
1241 extern struct drm_master *drm_master_get(struct drm_master *master);
1242 extern void drm_master_put(struct drm_master **master);
1244 extern void drm_put_dev(struct drm_device *dev);
1245 extern void drm_unplug_dev(struct drm_device *dev);
1246 extern unsigned int drm_debug;
1248 extern unsigned int drm_vblank_offdelay;
1249 extern unsigned int drm_timestamp_precision;
1250 extern unsigned int drm_timestamp_monotonic;
1252 extern struct class *drm_class;
1254 /* Debugfs support */
1255 #if defined(CONFIG_DEBUG_FS)
1256 extern int drm_debugfs_init(struct drm_minor *minor, int minor_id,
1257 struct dentry *root);
1258 extern int drm_debugfs_create_files(const struct drm_info_list *files,
1259 int count, struct dentry *root,
1260 struct drm_minor *minor);
1261 extern int drm_debugfs_remove_files(const struct drm_info_list *files,
1262 int count, struct drm_minor *minor);
1263 extern int drm_debugfs_cleanup(struct drm_minor *minor);
1264 extern int drm_debugfs_connector_add(struct drm_connector *connector);
1265 extern void drm_debugfs_connector_remove(struct drm_connector *connector);
1267 static inline int drm_debugfs_init(struct drm_minor *minor, int minor_id,
1268 struct dentry *root)
1273 static inline int drm_debugfs_create_files(const struct drm_info_list *files,
1274 int count, struct dentry *root,
1275 struct drm_minor *minor)
1280 static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
1281 int count, struct drm_minor *minor)
1286 static inline int drm_debugfs_cleanup(struct drm_minor *minor)
1291 static inline int drm_debugfs_connector_add(struct drm_connector *connector)
1295 static inline void drm_debugfs_connector_remove(struct drm_connector *connector)
1301 /* Info file support */
1302 extern int drm_name_info(struct seq_file *m, void *data);
1303 extern int drm_vm_info(struct seq_file *m, void *data);
1304 extern int drm_bufs_info(struct seq_file *m, void *data);
1305 extern int drm_vblank_info(struct seq_file *m, void *data);
1306 extern int drm_clients_info(struct seq_file *m, void* data);
1307 extern int drm_gem_name_info(struct seq_file *m, void *data);
1310 extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
1311 struct drm_gem_object *obj, int flags);
1312 extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
1313 struct drm_file *file_priv, uint32_t handle, uint32_t flags,
1315 extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
1316 struct dma_buf *dma_buf);
1317 extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
1318 struct drm_file *file_priv, int prime_fd, uint32_t *handle);
1319 extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
1321 extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
1322 struct drm_file *file_priv);
1323 extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
1324 struct drm_file *file_priv);
1326 extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
1327 dma_addr_t *addrs, int max_pages);
1328 extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages);
1329 extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1331 int drm_gem_dumb_destroy(struct drm_file *file,
1332 struct drm_device *dev,
1335 void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
1336 void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
1337 void drm_prime_remove_buf_handle_locked(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf);
1339 extern int drm_vma_info(struct seq_file *m, void *data);
1341 /* Scatter Gather Support (drm_scatter.h) */
1342 extern void drm_legacy_sg_cleanup(struct drm_device *dev);
1343 extern int drm_sg_alloc(struct drm_device *dev, void *data,
1344 struct drm_file *file_priv);
1345 extern int drm_sg_free(struct drm_device *dev, void *data,
1346 struct drm_file *file_priv);
1348 /* ATI PCIGART support (ati_pcigart.h) */
1349 extern int drm_ati_pcigart_init(struct drm_device *dev,
1350 struct drm_ati_pcigart_info * gart_info);
1351 extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
1352 struct drm_ati_pcigart_info * gart_info);
1354 extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1356 extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1357 extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1358 extern int drm_pci_set_unique(struct drm_device *dev,
1359 struct drm_master *master,
1360 struct drm_unique *u);
1362 /* Legacy Support */
1364 int drm_legacy_addmap(struct drm_device *d, resource_size_t offset,
1365 unsigned int size, enum drm_map_type type,
1366 enum drm_map_flags flags, struct drm_local_map **map_p);
1367 int drm_legacy_rmmap(struct drm_device *d, struct drm_local_map *map);
1368 int drm_legacy_rmmap_locked(struct drm_device *d, struct drm_local_map *map);
1369 struct drm_local_map *drm_legacy_getsarea(struct drm_device *dev);
1371 int drm_legacy_addbufs_agp(struct drm_device *d, struct drm_buf_desc *req);
1372 int drm_legacy_addbufs_pci(struct drm_device *d, struct drm_buf_desc *req);
1374 void drm_legacy_vma_flush(struct drm_device *d);
1376 /* sysfs support (drm_sysfs.c) */
1377 struct drm_sysfs_class;
1378 extern struct class *drm_sysfs_create(struct module *owner, char *name);
1379 extern void drm_sysfs_destroy(void);
1380 extern struct device *drm_sysfs_minor_alloc(struct drm_minor *minor);
1381 extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1382 extern int drm_sysfs_connector_add(struct drm_connector *connector);
1383 extern void drm_sysfs_connector_remove(struct drm_connector *connector);
1385 /* Graphics Execution Manager library functions (drm_gem.c) */
1386 int drm_gem_init(struct drm_device *dev);
1387 void drm_gem_destroy(struct drm_device *dev);
1388 void drm_gem_object_release(struct drm_gem_object *obj);
1389 void drm_gem_object_free(struct kref *kref);
1390 int drm_gem_object_init(struct drm_device *dev,
1391 struct drm_gem_object *obj, size_t size);
1392 void drm_gem_private_object_init(struct drm_device *dev,
1393 struct drm_gem_object *obj, size_t size);
1394 void drm_gem_vm_open(struct vm_area_struct *vma);
1395 void drm_gem_vm_close(struct vm_area_struct *vma);
1396 int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
1397 struct vm_area_struct *vma);
1398 int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
1400 #include <drm/drm_global.h>
1403 drm_gem_object_reference(struct drm_gem_object *obj)
1405 kref_get(&obj->refcount);
1409 drm_gem_object_unreference(struct drm_gem_object *obj)
1412 kref_put(&obj->refcount, drm_gem_object_free);
1416 drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
1418 if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) {
1419 struct drm_device *dev = obj->dev;
1421 mutex_lock(&dev->struct_mutex);
1422 if (likely(atomic_dec_and_test(&obj->refcount.refcount)))
1423 drm_gem_object_free(&obj->refcount);
1424 mutex_unlock(&dev->struct_mutex);
1428 int drm_gem_handle_create_tail(struct drm_file *file_priv,
1429 struct drm_gem_object *obj,
1431 int drm_gem_handle_create(struct drm_file *file_priv,
1432 struct drm_gem_object *obj,
1434 int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
1437 void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
1438 int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
1439 int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size);
1441 struct page **drm_gem_get_pages(struct drm_gem_object *obj);
1442 void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages,
1443 bool dirty, bool accessed);
1445 struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1446 struct drm_file *filp,
1448 int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1449 struct drm_file *file_priv);
1450 int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1451 struct drm_file *file_priv);
1452 int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1453 struct drm_file *file_priv);
1454 void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
1455 void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
1457 extern void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
1458 extern void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
1459 extern void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
1461 static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev,
1464 struct drm_map_list *_entry;
1465 list_for_each_entry(_entry, &dev->maplist, head)
1466 if (_entry->user_token == token)
1471 static __inline__ void drm_core_dropmap(struct drm_local_map *map)
1475 #include <drm/drm_mem_util.h>
1477 struct drm_device *drm_dev_alloc(struct drm_driver *driver,
1478 struct device *parent);
1479 void drm_dev_ref(struct drm_device *dev);
1480 void drm_dev_unref(struct drm_device *dev);
1481 int drm_dev_register(struct drm_device *dev, unsigned long flags);
1482 void drm_dev_unregister(struct drm_device *dev);
1483 int drm_dev_set_unique(struct drm_device *dev, const char *fmt, ...);
1485 struct drm_minor *drm_minor_acquire(unsigned int minor_id);
1486 void drm_minor_release(struct drm_minor *minor);
1491 static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
1493 if (dev->driver->device_is_agp != NULL) {
1494 int err = (*dev->driver->device_is_agp) (dev);
1501 return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1503 void drm_pci_agp_destroy(struct drm_device *dev);
1505 extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
1506 extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
1507 extern int drm_get_pci_dev(struct pci_dev *pdev,
1508 const struct pci_device_id *ent,
1509 struct drm_driver *driver);
1511 #define DRM_PCIE_SPEED_25 1
1512 #define DRM_PCIE_SPEED_50 2
1513 #define DRM_PCIE_SPEED_80 4
1515 extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
1517 /* platform section */
1518 extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);
1520 /* returns true if currently okay to sleep */
1521 static __inline__ bool drm_can_sleep(void)
1523 if (in_atomic() || in_dbg_master() || irqs_disabled())