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.
39 #include <linux/sched.h>
40 #include <linux/kernel.h>
41 #include <linux/kref.h>
42 #include <linux/miscdevice.h>
44 #include <linux/init.h>
45 #include <linux/file.h>
46 #include <linux/platform_device.h>
47 #include <linux/pci.h>
48 #include <linux/jiffies.h>
49 #include <linux/dma-mapping.h>
51 #include <linux/cdev.h>
52 #include <linux/mutex.h>
54 #include <linux/slab.h>
55 #include <linux/ratelimit.h>
57 #include <asm/uaccess.h>
58 #include <linux/types.h>
59 #include <linux/agp_backend.h>
60 #include <linux/workqueue.h>
61 #include <linux/poll.h>
62 #include <asm/pgalloc.h>
64 #include <drm/drm_sarea.h>
65 #include <drm/drm_vma_manager.h>
67 #include <linux/idr.h>
69 #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
79 struct reservation_object;
81 #include <drm/drm_os_linux.h>
82 #include <drm/drm_hashtab.h>
83 #include <drm/drm_mm.h>
86 * 4 debug categories are defined:
88 * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
89 * This is the category used by the DRM_DEBUG() macro.
91 * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
92 * This is the category used by the DRM_DEBUG_DRIVER() macro.
94 * KMS: used in the modesetting code.
95 * This is the category used by the DRM_DEBUG_KMS() macro.
97 * PRIME: used in the prime code.
98 * This is the category used by the DRM_DEBUG_PRIME() macro.
100 * Enabling verbose debug messages is done through the drm.debug parameter,
101 * each category being enabled by a bit.
103 * drm.debug=0x1 will enable CORE messages
104 * drm.debug=0x2 will enable DRIVER messages
105 * drm.debug=0x3 will enable CORE and DRIVER messages
107 * drm.debug=0xf will enable all messages
109 * An interesting feature is that it's possible to enable verbose logging at
110 * run-time by echoing the debug value in its sysfs node:
111 * # echo 0xf > /sys/module/drm/parameters/debug
113 #define DRM_UT_CORE 0x01
114 #define DRM_UT_DRIVER 0x02
115 #define DRM_UT_KMS 0x04
116 #define DRM_UT_PRIME 0x08
118 extern __printf(2, 3)
119 void drm_ut_debug_printk(const char *function_name,
120 const char *format, ...);
121 extern __printf(2, 3)
122 int drm_err(const char *func, const char *format, ...);
124 /***********************************************************************/
125 /** \name DRM template customization defaults */
128 /* driver capabilities and requirements mask */
129 #define DRIVER_USE_AGP 0x1
130 #define DRIVER_PCI_DMA 0x8
131 #define DRIVER_SG 0x10
132 #define DRIVER_HAVE_DMA 0x20
133 #define DRIVER_HAVE_IRQ 0x40
134 #define DRIVER_IRQ_SHARED 0x80
135 #define DRIVER_GEM 0x1000
136 #define DRIVER_MODESET 0x2000
137 #define DRIVER_PRIME 0x4000
138 #define DRIVER_RENDER 0x8000
140 /***********************************************************************/
141 /** \name Begin the DRM... */
144 #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
145 also include looping detection. */
147 #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
151 /***********************************************************************/
152 /** \name Macros to make printk easier */
158 * \param fmt printf() like format string.
159 * \param arg arguments
161 #define DRM_ERROR(fmt, ...) \
162 drm_err(__func__, fmt, ##__VA_ARGS__)
165 * Rate limited error output. Like DRM_ERROR() but won't flood the log.
167 * \param fmt printf() like format string.
168 * \param arg arguments
170 #define DRM_ERROR_RATELIMITED(fmt, ...) \
172 static DEFINE_RATELIMIT_STATE(_rs, \
173 DEFAULT_RATELIMIT_INTERVAL, \
174 DEFAULT_RATELIMIT_BURST); \
176 if (__ratelimit(&_rs)) \
177 drm_err(__func__, fmt, ##__VA_ARGS__); \
180 #define DRM_INFO(fmt, ...) \
181 printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
183 #define DRM_INFO_ONCE(fmt, ...) \
184 printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
189 * \param fmt printf() like format string.
190 * \param arg arguments
193 #define DRM_DEBUG(fmt, args...) \
195 if (unlikely(drm_debug & DRM_UT_CORE)) \
196 drm_ut_debug_printk(__func__, fmt, ##args); \
199 #define DRM_DEBUG_DRIVER(fmt, args...) \
201 if (unlikely(drm_debug & DRM_UT_DRIVER)) \
202 drm_ut_debug_printk(__func__, fmt, ##args); \
204 #define DRM_DEBUG_KMS(fmt, args...) \
206 if (unlikely(drm_debug & DRM_UT_KMS)) \
207 drm_ut_debug_printk(__func__, fmt, ##args); \
209 #define DRM_DEBUG_PRIME(fmt, args...) \
211 if (unlikely(drm_debug & DRM_UT_PRIME)) \
212 drm_ut_debug_printk(__func__, fmt, ##args); \
215 #define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0)
216 #define DRM_DEBUG_KMS(fmt, args...) do { } while (0)
217 #define DRM_DEBUG_PRIME(fmt, args...) do { } while (0)
218 #define DRM_DEBUG(fmt, arg...) do { } while (0)
223 /***********************************************************************/
224 /** \name Internal types and structures */
227 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
230 * Test that the hardware lock is held by the caller, returning otherwise.
232 * \param dev DRM device.
233 * \param filp file pointer of the caller.
235 #define LOCK_TEST_WITH_RETURN( dev, _file_priv ) \
237 if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) || \
238 _file_priv->master->lock.file_priv != _file_priv) { \
239 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
240 __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
241 _file_priv->master->lock.file_priv, _file_priv); \
247 * Ioctl function type.
249 * \param inode device inode.
250 * \param file_priv DRM file private pointer.
251 * \param cmd command.
252 * \param arg argument.
254 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
255 struct drm_file *file_priv);
257 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
260 #define DRM_IOCTL_NR(n) _IOC_NR(n)
261 #define DRM_MAJOR 226
264 #define DRM_MASTER 0x2
265 #define DRM_ROOT_ONLY 0x4
266 #define DRM_CONTROL_ALLOW 0x8
267 #define DRM_UNLOCKED 0x10
268 #define DRM_RENDER_ALLOW 0x20
270 struct drm_ioctl_desc {
274 unsigned int cmd_drv;
279 * Creates a driver or general drm_ioctl_desc array entry for the given
280 * ioctl, for use by drm_ioctl().
283 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
284 [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl, .name = #ioctl}
290 int idx; /**< Index into master buflist */
291 int total; /**< Buffer size */
292 int order; /**< log-base-2(total) */
293 int used; /**< Amount of buffer in use (for DMA) */
294 unsigned long offset; /**< Byte offset (used internally) */
295 void *address; /**< Address of buffer */
296 unsigned long bus_address; /**< Bus address of buffer */
297 struct drm_buf *next; /**< Kernel-only: used for free list */
298 __volatile__ int waiting; /**< On kernel DMA queue */
299 __volatile__ int pending; /**< On hardware DMA queue */
300 struct drm_file *file_priv; /**< Private of holding file descr */
301 int context; /**< Kernel queue for this buffer */
302 int while_locked; /**< Dispatch this buffer while locked */
310 } list; /**< Which list we're on */
312 int dev_priv_size; /**< Size of buffer private storage */
313 void *dev_private; /**< Per-buffer private storage */
316 typedef struct drm_dma_handle {
323 * Buffer entry. There is one of this for each buffer size order.
325 struct drm_buf_entry {
326 int buf_size; /**< size */
327 int buf_count; /**< number of buffers */
328 struct drm_buf *buflist; /**< buffer list */
331 struct drm_dma_handle **seglist;
333 int low_mark; /**< Low water mark */
334 int high_mark; /**< High water mark */
337 /* Event queued up for userspace to read */
338 struct drm_pending_event {
339 struct drm_event *event;
340 struct list_head link;
341 struct drm_file *file_priv;
342 pid_t pid; /* pid of requester, no guarantee it's valid by the time
343 we deliver the event, for tracing only */
344 void (*destroy)(struct drm_pending_event *event);
347 /* initial implementaton using a linked list - todo hashtab */
348 struct drm_prime_file_private {
349 struct list_head head;
353 /** File private data */
355 unsigned authenticated :1;
356 /* Whether we're master for a minor. Protected by master_mutex */
357 unsigned is_master :1;
358 /* true when the client has asked us to expose stereo 3D mode flags */
359 unsigned stereo_allowed :1;
361 * true if client understands CRTC primary planes and cursor planes
364 unsigned universal_planes:1;
369 struct list_head lhead;
370 struct drm_minor *minor;
371 unsigned long lock_count;
373 /** Mapping of mm object handles to object pointers. */
374 struct idr object_idr;
375 /** Lock for synchronization of access to object_idr. */
376 spinlock_t table_lock;
381 struct drm_master *master; /* master this node is currently associated with
382 N.B. not always minor->master */
384 * fbs - List of framebuffers associated with this file.
386 * Protected by fbs_lock. Note that the fbs list holds a reference on
387 * the fb object to prevent it from untimely disappearing.
389 struct list_head fbs;
390 struct mutex fbs_lock;
392 wait_queue_head_t event_wait;
393 struct list_head event_list;
396 struct drm_prime_file_private prime;
402 struct drm_lock_data {
403 struct drm_hw_lock *hw_lock; /**< Hardware lock */
404 /** Private of lock holder's file (NULL=kernel) */
405 struct drm_file *file_priv;
406 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
407 unsigned long lock_time; /**< Time of last lock in jiffies */
409 uint32_t kernel_waiters;
410 uint32_t user_waiters;
417 struct drm_device_dma {
419 struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
420 int buf_count; /**< total number of buffers */
421 struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
423 int page_count; /**< number of pages */
424 unsigned long *pagelist; /**< page list */
425 unsigned long byte_count;
427 _DRM_DMA_USE_AGP = 0x01,
428 _DRM_DMA_USE_SG = 0x02,
429 _DRM_DMA_USE_FB = 0x04,
430 _DRM_DMA_USE_PCI_RO = 0x08
436 * Scatter-gather memory.
439 unsigned long handle;
442 struct page **pagelist;
448 struct drm_hw_lock *lock;
453 * Kernel side of a mapping
455 struct drm_local_map {
456 resource_size_t offset; /**< Requested physical address (0 for SAREA)*/
457 unsigned long size; /**< Requested physical size (bytes) */
458 enum drm_map_type type; /**< Type of memory to map */
459 enum drm_map_flags flags; /**< Flags */
460 void *handle; /**< User-space: "Handle" to pass to mmap() */
461 /**< Kernel-space: kernel-virtual address */
462 int mtrr; /**< MTRR slot used */
465 typedef struct drm_local_map drm_local_map_t;
470 struct drm_map_list {
471 struct list_head head; /**< list head */
472 struct drm_hash_item hash;
473 struct drm_local_map *map; /**< mapping */
475 struct drm_master *master;
478 /* location of GART table */
479 #define DRM_ATI_GART_MAIN 1
480 #define DRM_ATI_GART_FB 2
482 #define DRM_ATI_GART_PCI 1
483 #define DRM_ATI_GART_PCIE 2
484 #define DRM_ATI_GART_IGP 3
486 struct drm_ati_pcigart_info {
487 int gart_table_location;
491 dma_addr_t table_mask;
492 struct drm_dma_handle *table_handle;
493 struct drm_local_map mapping;
498 * This structure defines the drm_mm memory object, which will be used by the
499 * DRM for its buffer objects.
501 struct drm_gem_object {
502 /** Reference count of this object */
503 struct kref refcount;
506 * handle_count - gem file_priv handle count of this object
508 * Each handle also holds a reference. Note that when the handle_count
509 * drops to 0 any global names (e.g. the id in the flink namespace) will
512 * Protected by dev->object_name_lock.
514 unsigned handle_count;
516 /** Related drm device */
517 struct drm_device *dev;
519 /** File representing the shmem storage */
522 /* Mapping info for this object */
523 struct drm_vma_offset_node vma_node;
526 * Size of the object, in bytes. Immutable over the object's
532 * Global name for this object, starts at 1. 0 means unnamed.
533 * Access is covered by the object_name_lock in the related drm_device
538 * Memory domains. These monitor which caches contain read/write data
539 * related to the object. When transitioning from one set of domains
540 * to another, the driver is called to ensure that caches are suitably
541 * flushed and invalidated
543 uint32_t read_domains;
544 uint32_t write_domain;
547 * While validating an exec operation, the
548 * new read/write domain values are computed here.
549 * They will be transferred to the above values
550 * at the point that any cache flushing occurs
552 uint32_t pending_read_domains;
553 uint32_t pending_write_domain;
556 * dma_buf - dma buf associated with this GEM object
558 * Pointer to the dma-buf associated with this gem object (either
559 * through importing or exporting). We break the resulting reference
560 * loop when the last gem handle for this object is released.
562 * Protected by obj->object_name_lock
564 struct dma_buf *dma_buf;
567 * import_attach - dma buf attachment backing this object
569 * Any foreign dma_buf imported as a gem object has this set to the
570 * attachment point for the device. This is invariant over the lifetime
573 * The driver's ->gem_free_object callback is responsible for cleaning
574 * up the dma_buf attachment and references acquired at import time.
576 * Note that the drm gem/prime core does not depend upon drivers setting
577 * this field any more. So for drivers where this doesn't make sense
578 * (e.g. virtual devices or a displaylink behind an usb bus) they can
579 * simply leave it as NULL.
581 struct dma_buf_attachment *import_attach;
584 #include <drm/drm_crtc.h>
587 * struct drm_master - drm master structure
589 * @refcount: Refcount for this master object.
590 * @minor: Link back to minor char device we are master for. Immutable.
591 * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex.
592 * @unique_len: Length of unique field. Protected by drm_global_mutex.
593 * @unique_size: Amount allocated. Protected by drm_global_mutex.
594 * @magiclist: Hash of used authentication tokens. Protected by struct_mutex.
595 * @magicfree: List of used authentication tokens. Protected by struct_mutex.
596 * @lock: DRI lock information.
597 * @driver_priv: Pointer to driver-private information.
600 struct kref refcount;
601 struct drm_minor *minor;
605 struct drm_open_hash magiclist;
606 struct list_head magicfree;
607 struct drm_lock_data lock;
611 /* Size of ringbuffer for vblank timestamps. Just double-buffer
612 * in initial implementation.
614 #define DRM_VBLANKTIME_RBSIZE 2
616 /* Flags and return codes for get_vblank_timestamp() driver function. */
617 #define DRM_CALLED_FROM_VBLIRQ 1
618 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
619 #define DRM_VBLANKTIME_INVBL (1 << 1)
621 /* get_scanout_position() return flags */
622 #define DRM_SCANOUTPOS_VALID (1 << 0)
623 #define DRM_SCANOUTPOS_INVBL (1 << 1)
624 #define DRM_SCANOUTPOS_ACCURATE (1 << 2)
627 int (*set_busid)(struct drm_device *dev, struct drm_master *master);
631 * DRM driver structure. This structure represent the common code for
632 * a family of cards. There will one drm_device for each card present
636 int (*load) (struct drm_device *, unsigned long flags);
637 int (*firstopen) (struct drm_device *);
638 int (*open) (struct drm_device *, struct drm_file *);
639 void (*preclose) (struct drm_device *, struct drm_file *file_priv);
640 void (*postclose) (struct drm_device *, struct drm_file *);
641 void (*lastclose) (struct drm_device *);
642 int (*unload) (struct drm_device *);
643 int (*suspend) (struct drm_device *, pm_message_t state);
644 int (*resume) (struct drm_device *);
645 int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
646 int (*dma_quiescent) (struct drm_device *);
647 int (*context_dtor) (struct drm_device *dev, int context);
650 * get_vblank_counter - get raw hardware vblank counter
652 * @crtc: counter to fetch
654 * Driver callback for fetching a raw hardware vblank counter for @crtc.
655 * If a device doesn't have a hardware counter, the driver can simply
656 * return the value of drm_vblank_count. The DRM core will account for
657 * missed vblank events while interrupts where disabled based on system
660 * Wraparound handling and loss of events due to modesetting is dealt
661 * with in the DRM core code.
664 * Raw vblank counter value.
666 u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
669 * enable_vblank - enable vblank interrupt events
671 * @crtc: which irq to enable
673 * Enable vblank interrupts for @crtc. If the device doesn't have
674 * a hardware vblank counter, this routine should be a no-op, since
675 * interrupts will have to stay on to keep the count accurate.
678 * Zero on success, appropriate errno if the given @crtc's vblank
679 * interrupt cannot be enabled.
681 int (*enable_vblank) (struct drm_device *dev, int crtc);
684 * disable_vblank - disable vblank interrupt events
686 * @crtc: which irq to enable
688 * Disable vblank interrupts for @crtc. If the device doesn't have
689 * a hardware vblank counter, this routine should be a no-op, since
690 * interrupts will have to stay on to keep the count accurate.
692 void (*disable_vblank) (struct drm_device *dev, int crtc);
695 * Called by \c drm_device_is_agp. Typically used to determine if a
696 * card is really attached to AGP or not.
698 * \param dev DRM device handle
701 * One of three values is returned depending on whether or not the
702 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
703 * (return of 1), or may or may not be AGP (return of 2).
705 int (*device_is_agp) (struct drm_device *dev);
708 * Called by vblank timestamping code.
710 * Return the current display scanout position from a crtc, and an
711 * optional accurate ktime_get timestamp of when position was measured.
713 * \param dev DRM device.
714 * \param crtc Id of the crtc to query.
715 * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
716 * \param *vpos Target location for current vertical scanout position.
717 * \param *hpos Target location for current horizontal scanout position.
718 * \param *stime Target location for timestamp taken immediately before
719 * scanout position query. Can be NULL to skip timestamp.
720 * \param *etime Target location for timestamp taken immediately after
721 * scanout position query. Can be NULL to skip timestamp.
723 * Returns vpos as a positive number while in active scanout area.
724 * Returns vpos as a negative number inside vblank, counting the number
725 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
726 * until start of active scanout / end of vblank."
728 * \return Flags, or'ed together as follows:
730 * DRM_SCANOUTPOS_VALID = Query successful.
731 * DRM_SCANOUTPOS_INVBL = Inside vblank.
732 * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
733 * this flag means that returned position may be offset by a constant
734 * but unknown small number of scanlines wrt. real scanout position.
737 int (*get_scanout_position) (struct drm_device *dev, int crtc,
739 int *vpos, int *hpos, ktime_t *stime,
743 * Called by \c drm_get_last_vbltimestamp. Should return a precise
744 * timestamp when the most recent VBLANK interval ended or will end.
746 * Specifically, the timestamp in @vblank_time should correspond as
747 * closely as possible to the time when the first video scanline of
748 * the video frame after the end of VBLANK will start scanning out,
749 * the time immediately after end of the VBLANK interval. If the
750 * @crtc is currently inside VBLANK, this will be a time in the future.
751 * If the @crtc is currently scanning out a frame, this will be the
752 * past start time of the current scanout. This is meant to adhere
753 * to the OpenML OML_sync_control extension specification.
755 * \param dev dev DRM device handle.
756 * \param crtc crtc for which timestamp should be returned.
757 * \param *max_error Maximum allowable timestamp error in nanoseconds.
758 * Implementation should strive to provide timestamp
759 * with an error of at most *max_error nanoseconds.
760 * Returns true upper bound on error for timestamp.
761 * \param *vblank_time Target location for returned vblank timestamp.
762 * \param flags 0 = Defaults, no special treatment needed.
763 * \param DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
764 * irq handler. Some drivers need to apply some workarounds
765 * for gpu-specific vblank irq quirks if flag is set.
768 * Zero if timestamping isn't supported in current display mode or a
769 * negative number on failure. A positive status code on success,
770 * which describes how the vblank_time timestamp was computed.
772 int (*get_vblank_timestamp) (struct drm_device *dev, int crtc,
774 struct timeval *vblank_time,
777 /* these have to be filled in */
779 irqreturn_t(*irq_handler) (int irq, void *arg);
780 void (*irq_preinstall) (struct drm_device *dev);
781 int (*irq_postinstall) (struct drm_device *dev);
782 void (*irq_uninstall) (struct drm_device *dev);
784 /* Master routines */
785 int (*master_create)(struct drm_device *dev, struct drm_master *master);
786 void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
788 * master_set is called whenever the minor master is set.
789 * master_drop is called whenever the minor master is dropped.
792 int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
794 void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv,
797 int (*debugfs_init)(struct drm_minor *minor);
798 void (*debugfs_cleanup)(struct drm_minor *minor);
801 * Driver-specific constructor for drm_gem_objects, to set up
802 * obj->driver_private.
804 * Returns 0 on success.
806 void (*gem_free_object) (struct drm_gem_object *obj);
807 int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
808 void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
811 /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
812 int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
813 uint32_t handle, uint32_t flags, int *prime_fd);
814 /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
815 int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
816 int prime_fd, uint32_t *handle);
817 /* export GEM -> dmabuf */
818 struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
819 struct drm_gem_object *obj, int flags);
820 /* import dmabuf -> GEM */
821 struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
822 struct dma_buf *dma_buf);
823 /* low-level interface used by drm_gem_prime_{import,export} */
824 int (*gem_prime_pin)(struct drm_gem_object *obj);
825 void (*gem_prime_unpin)(struct drm_gem_object *obj);
826 struct reservation_object * (*gem_prime_res_obj)(
827 struct drm_gem_object *obj);
828 struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
829 struct drm_gem_object *(*gem_prime_import_sg_table)(
830 struct drm_device *dev, size_t size,
831 struct sg_table *sgt);
832 void *(*gem_prime_vmap)(struct drm_gem_object *obj);
833 void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
834 int (*gem_prime_mmap)(struct drm_gem_object *obj,
835 struct vm_area_struct *vma);
837 /* vga arb irq handler */
838 void (*vgaarb_irq)(struct drm_device *dev, bool state);
840 /* dumb alloc support */
841 int (*dumb_create)(struct drm_file *file_priv,
842 struct drm_device *dev,
843 struct drm_mode_create_dumb *args);
844 int (*dumb_map_offset)(struct drm_file *file_priv,
845 struct drm_device *dev, uint32_t handle,
847 int (*dumb_destroy)(struct drm_file *file_priv,
848 struct drm_device *dev,
851 /* Driver private ops for this object */
852 const struct vm_operations_struct *gem_vm_ops;
863 const struct drm_ioctl_desc *ioctls;
865 const struct file_operations *fops;
868 /* List of devices hanging off this driver with stealth attach. */
869 struct list_head legacy_dev_list;
872 enum drm_minor_type {
880 * Info file list entry. This structure represents a debugfs or proc file to
881 * be created by the drm core
883 struct drm_info_list {
884 const char *name; /** file name */
885 int (*show)(struct seq_file*, void*); /** show callback */
886 u32 driver_features; /**< Required driver features for this entry */
891 * debugfs node structure. This structure represents a debugfs file.
893 struct drm_info_node {
894 struct list_head list;
895 struct drm_minor *minor;
896 const struct drm_info_list *info_ent;
901 * DRM minor structure. This structure represents a drm minor number.
904 int index; /**< Minor device number */
905 int type; /**< Control or render */
906 struct device *kdev; /**< Linux device */
907 struct drm_device *dev;
909 struct dentry *debugfs_root;
911 struct list_head debugfs_list;
912 struct mutex debugfs_lock; /* Protects debugfs_list. */
914 /* currently active master for this node. Protected by master_mutex */
915 struct drm_master *master;
916 struct drm_mode_group mode_group;
920 struct drm_pending_vblank_event {
921 struct drm_pending_event base;
923 struct drm_event_vblank event;
926 struct drm_vblank_crtc {
927 struct drm_device *dev; /* pointer to the drm_device */
928 wait_queue_head_t queue; /**< VBLANK wait queue */
929 struct timeval time[DRM_VBLANKTIME_RBSIZE]; /**< timestamp of current count */
930 struct timer_list disable_timer; /* delayed disable timer */
931 atomic_t count; /**< number of VBLANK interrupts */
932 atomic_t refcount; /* number of users of vblank interruptsper crtc */
933 u32 last; /* protected by dev->vbl_lock, used */
934 /* for wraparound handling */
935 u32 last_wait; /* Last vblank seqno waited per CRTC */
936 unsigned int inmodeset; /* Display driver is setting mode */
937 int crtc; /* crtc index */
938 bool enabled; /* so we don't call enable more than
943 * DRM device structure. This structure represent a complete card that
944 * may contain multiple heads.
947 struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
948 int if_version; /**< Highest interface version set */
950 /** \name Lifetime Management */
952 struct kref ref; /**< Object ref-count */
953 struct device *dev; /**< Device structure of bus-device */
954 struct drm_driver *driver; /**< DRM driver managing the device */
955 void *dev_private; /**< DRM driver private data */
956 struct drm_minor *control; /**< Control node */
957 struct drm_minor *primary; /**< Primary node */
958 struct drm_minor *render; /**< Render node */
959 atomic_t unplugged; /**< Flag whether dev is dead */
960 struct inode *anon_inode; /**< inode for private address-space */
961 char *unique; /**< unique name of the device */
966 struct mutex struct_mutex; /**< For others */
967 struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */
970 /** \name Usage Counters */
972 int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
973 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
974 int buf_use; /**< Buffers in use -- cannot alloc */
975 atomic_t buf_alloc; /**< Buffer allocation in progress */
978 struct list_head filelist;
980 /** \name Memory management */
982 struct list_head maplist; /**< Linked list of regions */
983 struct drm_open_hash map_hash; /**< User token hash table for maps */
985 /** \name Context handle management */
987 struct list_head ctxlist; /**< Linked list of context handles */
988 struct mutex ctxlist_mutex; /**< For ctxlist */
992 struct list_head vmalist; /**< List of vmas (for debugging) */
996 /** \name DMA support */
998 struct drm_device_dma *dma; /**< Optional pointer for DMA support */
1001 /** \name Context support */
1003 bool irq_enabled; /**< True if irq handler is enabled */
1006 __volatile__ long context_flag; /**< Context swapping flag */
1007 int last_context; /**< Last current context */
1010 /** \name VBLANK IRQ support */
1014 * At load time, disabling the vblank interrupt won't be allowed since
1015 * old clients may not call the modeset ioctl and therefore misbehave.
1016 * Once the modeset ioctl *has* been called though, we can safely
1017 * disable them when unused.
1019 bool vblank_disable_allowed;
1021 /* array of size num_crtcs */
1022 struct drm_vblank_crtc *vblank;
1024 spinlock_t vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
1025 spinlock_t vbl_lock;
1027 u32 max_vblank_count; /**< size of vblank counter register */
1032 struct list_head vblank_event_list;
1033 spinlock_t event_lock;
1037 struct drm_agp_head *agp; /**< AGP data */
1039 struct pci_dev *pdev; /**< PCI device structure */
1041 struct pci_controller *hose;
1044 struct platform_device *platformdev; /**< Platform device struture */
1045 struct usb_device *usbdev;
1047 struct drm_sg_mem *sg; /**< Scatter gather memory */
1048 unsigned int num_crtcs; /**< Number of CRTCs on this device */
1049 struct drm_sigdata sigdata; /**< For block_all_signals */
1052 struct drm_local_map *agp_buffer_map;
1053 unsigned int agp_buffer_token;
1055 struct drm_mode_config mode_config; /**< Current mode config */
1057 /** \name GEM information */
1059 struct mutex object_name_lock;
1060 struct idr object_name_idr;
1061 struct drm_vma_offset_manager *vma_offset_manager;
1063 int switch_power_state;
1066 #define DRM_SWITCH_POWER_ON 0
1067 #define DRM_SWITCH_POWER_OFF 1
1068 #define DRM_SWITCH_POWER_CHANGING 2
1069 #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
1071 static __inline__ int drm_core_check_feature(struct drm_device *dev,
1074 return ((dev->driver->driver_features & feature) ? 1 : 0);
1077 static inline void drm_device_set_unplugged(struct drm_device *dev)
1080 atomic_set(&dev->unplugged, 1);
1083 static inline int drm_device_is_unplugged(struct drm_device *dev)
1085 int ret = atomic_read(&dev->unplugged);
1090 static inline bool drm_is_render_client(const struct drm_file *file_priv)
1092 return file_priv->minor->type == DRM_MINOR_RENDER;
1095 static inline bool drm_is_control_client(const struct drm_file *file_priv)
1097 return file_priv->minor->type == DRM_MINOR_CONTROL;
1100 static inline bool drm_is_primary_client(const struct drm_file *file_priv)
1102 return file_priv->minor->type == DRM_MINOR_LEGACY;
1105 /******************************************************************/
1106 /** \name Internal function definitions */
1109 /* Driver support (drm_drv.h) */
1110 extern long drm_ioctl(struct file *filp,
1111 unsigned int cmd, unsigned long arg);
1112 extern long drm_compat_ioctl(struct file *filp,
1113 unsigned int cmd, unsigned long arg);
1114 extern int drm_lastclose(struct drm_device *dev);
1115 extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
1117 /* Device support (drm_fops.h) */
1118 extern struct mutex drm_global_mutex;
1119 extern int drm_open(struct inode *inode, struct file *filp);
1120 extern ssize_t drm_read(struct file *filp, char __user *buffer,
1121 size_t count, loff_t *offset);
1122 extern int drm_release(struct inode *inode, struct file *filp);
1124 /* Mapping support (drm_vm.h) */
1125 extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
1126 extern int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma);
1127 extern void drm_vm_open_locked(struct drm_device *dev, struct vm_area_struct *vma);
1128 extern void drm_vm_close_locked(struct drm_device *dev, struct vm_area_struct *vma);
1129 extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
1131 /* Memory management support (drm_memory.h) */
1132 #include <drm/drm_memory.h>
1135 /* Misc. IOCTL support (drm_ioctl.h) */
1136 extern int drm_irq_by_busid(struct drm_device *dev, void *data,
1137 struct drm_file *file_priv);
1138 extern int drm_getunique(struct drm_device *dev, void *data,
1139 struct drm_file *file_priv);
1140 extern int drm_setunique(struct drm_device *dev, void *data,
1141 struct drm_file *file_priv);
1142 extern int drm_getmap(struct drm_device *dev, void *data,
1143 struct drm_file *file_priv);
1144 extern int drm_getclient(struct drm_device *dev, void *data,
1145 struct drm_file *file_priv);
1146 extern int drm_getstats(struct drm_device *dev, void *data,
1147 struct drm_file *file_priv);
1148 extern int drm_getcap(struct drm_device *dev, void *data,
1149 struct drm_file *file_priv);
1150 extern int drm_setclientcap(struct drm_device *dev, void *data,
1151 struct drm_file *file_priv);
1152 extern int drm_setversion(struct drm_device *dev, void *data,
1153 struct drm_file *file_priv);
1154 extern int drm_noop(struct drm_device *dev, void *data,
1155 struct drm_file *file_priv);
1157 /* Authentication IOCTL support (drm_auth.h) */
1158 extern int drm_getmagic(struct drm_device *dev, void *data,
1159 struct drm_file *file_priv);
1160 extern int drm_authmagic(struct drm_device *dev, void *data,
1161 struct drm_file *file_priv);
1162 extern int drm_remove_magic(struct drm_master *master, drm_magic_t magic);
1164 /* Cache management (drm_cache.c) */
1165 void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
1166 void drm_clflush_sg(struct sg_table *st);
1167 void drm_clflush_virt_range(void *addr, unsigned long length);
1169 /* Locking IOCTL support (drm_lock.h) */
1170 extern int drm_lock(struct drm_device *dev, void *data,
1171 struct drm_file *file_priv);
1172 extern int drm_unlock(struct drm_device *dev, void *data,
1173 struct drm_file *file_priv);
1174 extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
1175 extern void drm_idlelock_take(struct drm_lock_data *lock_data);
1176 extern void drm_idlelock_release(struct drm_lock_data *lock_data);
1179 * These are exported to drivers so that they can implement fencing using
1180 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1183 extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
1185 /* DMA support (drm_dma.h) */
1186 extern int drm_legacy_dma_setup(struct drm_device *dev);
1187 extern void drm_legacy_dma_takedown(struct drm_device *dev);
1188 extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
1189 extern void drm_core_reclaim_buffers(struct drm_device *dev,
1190 struct drm_file *filp);
1192 /* IRQ support (drm_irq.h) */
1193 extern int drm_control(struct drm_device *dev, void *data,
1194 struct drm_file *file_priv);
1195 extern int drm_irq_install(struct drm_device *dev, int irq);
1196 extern int drm_irq_uninstall(struct drm_device *dev);
1198 extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1199 extern int drm_wait_vblank(struct drm_device *dev, void *data,
1200 struct drm_file *filp);
1201 extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1202 extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
1203 struct timeval *vblanktime);
1204 extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
1205 struct drm_pending_vblank_event *e);
1206 extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
1207 extern int drm_vblank_get(struct drm_device *dev, int crtc);
1208 extern void drm_vblank_put(struct drm_device *dev, int crtc);
1209 extern int drm_crtc_vblank_get(struct drm_crtc *crtc);
1210 extern void drm_crtc_vblank_put(struct drm_crtc *crtc);
1211 extern void drm_wait_one_vblank(struct drm_device *dev, int crtc);
1212 extern void drm_crtc_wait_one_vblank(struct drm_crtc *crtc);
1213 extern void drm_vblank_off(struct drm_device *dev, int crtc);
1214 extern void drm_vblank_on(struct drm_device *dev, int crtc);
1215 extern void drm_crtc_vblank_off(struct drm_crtc *crtc);
1216 extern void drm_crtc_vblank_on(struct drm_crtc *crtc);
1217 extern void drm_vblank_cleanup(struct drm_device *dev);
1219 extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
1220 struct timeval *tvblank, unsigned flags);
1221 extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
1222 int crtc, int *max_error,
1223 struct timeval *vblank_time,
1225 const struct drm_crtc *refcrtc,
1226 const struct drm_display_mode *mode);
1227 extern void drm_calc_timestamping_constants(struct drm_crtc *crtc,
1228 const struct drm_display_mode *mode);
1231 * drm_crtc_vblank_waitqueue - get vblank waitqueue for the CRTC
1232 * @crtc: which CRTC's vblank waitqueue to retrieve
1234 * This function returns a pointer to the vblank waitqueue for the CRTC.
1235 * Drivers can use this to implement vblank waits using wait_event() & co.
1237 static inline wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc)
1239 return &crtc->dev->vblank[drm_crtc_index(crtc)].queue;
1242 /* Modesetting support */
1243 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
1244 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
1245 extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1246 struct drm_file *file_priv);
1248 /* AGP/GART support (drm_agpsupport.h) */
1250 #include <drm/drm_agpsupport.h>
1252 /* Stub support (drm_stub.h) */
1253 extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1254 struct drm_file *file_priv);
1255 extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1256 struct drm_file *file_priv);
1257 struct drm_master *drm_master_create(struct drm_minor *minor);
1258 extern struct drm_master *drm_master_get(struct drm_master *master);
1259 extern void drm_master_put(struct drm_master **master);
1261 extern void drm_put_dev(struct drm_device *dev);
1262 extern void drm_unplug_dev(struct drm_device *dev);
1263 extern unsigned int drm_debug;
1265 extern unsigned int drm_vblank_offdelay;
1266 extern unsigned int drm_timestamp_precision;
1267 extern unsigned int drm_timestamp_monotonic;
1269 extern struct class *drm_class;
1271 /* Debugfs support */
1272 #if defined(CONFIG_DEBUG_FS)
1273 extern int drm_debugfs_init(struct drm_minor *minor, int minor_id,
1274 struct dentry *root);
1275 extern int drm_debugfs_create_files(const struct drm_info_list *files,
1276 int count, struct dentry *root,
1277 struct drm_minor *minor);
1278 extern int drm_debugfs_remove_files(const struct drm_info_list *files,
1279 int count, struct drm_minor *minor);
1280 extern int drm_debugfs_cleanup(struct drm_minor *minor);
1281 extern int drm_debugfs_connector_add(struct drm_connector *connector);
1282 extern void drm_debugfs_connector_remove(struct drm_connector *connector);
1284 static inline int drm_debugfs_init(struct drm_minor *minor, int minor_id,
1285 struct dentry *root)
1290 static inline int drm_debugfs_create_files(const struct drm_info_list *files,
1291 int count, struct dentry *root,
1292 struct drm_minor *minor)
1297 static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
1298 int count, struct drm_minor *minor)
1303 static inline int drm_debugfs_cleanup(struct drm_minor *minor)
1308 static inline int drm_debugfs_connector_add(struct drm_connector *connector)
1312 static inline void drm_debugfs_connector_remove(struct drm_connector *connector)
1318 /* Info file support */
1319 extern int drm_name_info(struct seq_file *m, void *data);
1320 extern int drm_vm_info(struct seq_file *m, void *data);
1321 extern int drm_bufs_info(struct seq_file *m, void *data);
1322 extern int drm_vblank_info(struct seq_file *m, void *data);
1323 extern int drm_clients_info(struct seq_file *m, void* data);
1324 extern int drm_gem_name_info(struct seq_file *m, void *data);
1327 extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
1328 struct drm_gem_object *obj, int flags);
1329 extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
1330 struct drm_file *file_priv, uint32_t handle, uint32_t flags,
1332 extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
1333 struct dma_buf *dma_buf);
1334 extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
1335 struct drm_file *file_priv, int prime_fd, uint32_t *handle);
1336 extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
1338 extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
1339 struct drm_file *file_priv);
1340 extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
1341 struct drm_file *file_priv);
1343 extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
1344 dma_addr_t *addrs, int max_pages);
1345 extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages);
1346 extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1348 int drm_gem_dumb_destroy(struct drm_file *file,
1349 struct drm_device *dev,
1352 void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
1353 void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
1354 void drm_prime_remove_buf_handle_locked(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf);
1357 extern int drm_vma_info(struct seq_file *m, void *data);
1360 /* Scatter Gather Support (drm_scatter.h) */
1361 extern void drm_legacy_sg_cleanup(struct drm_device *dev);
1362 extern int drm_sg_alloc(struct drm_device *dev, void *data,
1363 struct drm_file *file_priv);
1364 extern int drm_sg_free(struct drm_device *dev, void *data,
1365 struct drm_file *file_priv);
1367 /* ATI PCIGART support (ati_pcigart.h) */
1368 extern int drm_ati_pcigart_init(struct drm_device *dev,
1369 struct drm_ati_pcigart_info * gart_info);
1370 extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
1371 struct drm_ati_pcigart_info * gart_info);
1373 extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1375 extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1376 extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1377 extern int drm_pci_set_unique(struct drm_device *dev,
1378 struct drm_master *master,
1379 struct drm_unique *u);
1381 /* Legacy Support */
1383 int drm_legacy_addmap(struct drm_device *d, resource_size_t offset,
1384 unsigned int size, enum drm_map_type type,
1385 enum drm_map_flags flags, struct drm_local_map **map_p);
1386 int drm_legacy_rmmap(struct drm_device *d, struct drm_local_map *map);
1387 int drm_legacy_rmmap_locked(struct drm_device *d, struct drm_local_map *map);
1388 struct drm_local_map *drm_legacy_getsarea(struct drm_device *dev);
1390 int drm_legacy_addbufs_agp(struct drm_device *d, struct drm_buf_desc *req);
1391 int drm_legacy_addbufs_pci(struct drm_device *d, struct drm_buf_desc *req);
1393 void drm_legacy_vma_flush(struct drm_device *d);
1395 /* sysfs support (drm_sysfs.c) */
1396 struct drm_sysfs_class;
1397 extern struct class *drm_sysfs_create(struct module *owner, char *name);
1398 extern void drm_sysfs_destroy(void);
1399 extern struct device *drm_sysfs_minor_alloc(struct drm_minor *minor);
1400 extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1401 extern int drm_sysfs_connector_add(struct drm_connector *connector);
1402 extern void drm_sysfs_connector_remove(struct drm_connector *connector);
1404 /* Graphics Execution Manager library functions (drm_gem.c) */
1405 int drm_gem_init(struct drm_device *dev);
1406 void drm_gem_destroy(struct drm_device *dev);
1407 void drm_gem_object_release(struct drm_gem_object *obj);
1408 void drm_gem_object_free(struct kref *kref);
1409 int drm_gem_object_init(struct drm_device *dev,
1410 struct drm_gem_object *obj, size_t size);
1411 void drm_gem_private_object_init(struct drm_device *dev,
1412 struct drm_gem_object *obj, size_t size);
1413 void drm_gem_vm_open(struct vm_area_struct *vma);
1414 void drm_gem_vm_close(struct vm_area_struct *vma);
1415 int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
1416 struct vm_area_struct *vma);
1417 int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
1419 #include <drm/drm_global.h>
1422 drm_gem_object_reference(struct drm_gem_object *obj)
1424 kref_get(&obj->refcount);
1428 drm_gem_object_unreference(struct drm_gem_object *obj)
1431 kref_put(&obj->refcount, drm_gem_object_free);
1435 drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
1437 if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) {
1438 struct drm_device *dev = obj->dev;
1440 mutex_lock(&dev->struct_mutex);
1441 if (likely(atomic_dec_and_test(&obj->refcount.refcount)))
1442 drm_gem_object_free(&obj->refcount);
1443 mutex_unlock(&dev->struct_mutex);
1447 int drm_gem_handle_create_tail(struct drm_file *file_priv,
1448 struct drm_gem_object *obj,
1450 int drm_gem_handle_create(struct drm_file *file_priv,
1451 struct drm_gem_object *obj,
1453 int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
1456 void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
1457 int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
1458 int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size);
1460 struct page **drm_gem_get_pages(struct drm_gem_object *obj);
1461 void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages,
1462 bool dirty, bool accessed);
1464 struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1465 struct drm_file *filp,
1467 int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1468 struct drm_file *file_priv);
1469 int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1470 struct drm_file *file_priv);
1471 int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1472 struct drm_file *file_priv);
1473 void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
1474 void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
1476 extern void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
1477 extern void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
1478 extern void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
1480 static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev,
1483 struct drm_map_list *_entry;
1484 list_for_each_entry(_entry, &dev->maplist, head)
1485 if (_entry->user_token == token)
1490 static __inline__ void drm_core_dropmap(struct drm_local_map *map)
1494 #include <drm/drm_mem_util.h>
1496 struct drm_device *drm_dev_alloc(struct drm_driver *driver,
1497 struct device *parent);
1498 void drm_dev_ref(struct drm_device *dev);
1499 void drm_dev_unref(struct drm_device *dev);
1500 int drm_dev_register(struct drm_device *dev, unsigned long flags);
1501 void drm_dev_unregister(struct drm_device *dev);
1502 int drm_dev_set_unique(struct drm_device *dev, const char *fmt, ...);
1504 struct drm_minor *drm_minor_acquire(unsigned int minor_id);
1505 void drm_minor_release(struct drm_minor *minor);
1510 static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
1512 if (dev->driver->device_is_agp != NULL) {
1513 int err = (*dev->driver->device_is_agp) (dev);
1520 return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1522 void drm_pci_agp_destroy(struct drm_device *dev);
1524 extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
1525 extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
1526 extern int drm_get_pci_dev(struct pci_dev *pdev,
1527 const struct pci_device_id *ent,
1528 struct drm_driver *driver);
1530 #define DRM_PCIE_SPEED_25 1
1531 #define DRM_PCIE_SPEED_50 2
1532 #define DRM_PCIE_SPEED_80 4
1534 extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
1536 /* platform section */
1537 extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);
1539 /* returns true if currently okay to sleep */
1540 static __inline__ bool drm_can_sleep(void)
1542 if (in_atomic() || in_dbg_master() || irqs_disabled())
1547 #endif /* __KERNEL__ */