Revert "drm/prime: resolve race for drm_gem_prime_handle_to_fd()"
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / include / drm / drmP.h
1 /**
2  * \file drmP.h
3  * Private header for Direct Rendering Manager
4  *
5  * \author Rickard E. (Rik) Faith <faith@valinux.com>
6  * \author Gareth Hughes <gareth@valinux.com>
7  */
8
9 /*
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.
14  *
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:
21  *
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
24  * Software.
25  *
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.
33  */
34
35 #ifndef _DRM_P_H_
36 #define _DRM_P_H_
37
38 #ifdef __KERNEL__
39 #ifdef __alpha__
40 /* add include of current.h so that "current" is defined
41  * before static inline funcs in wait.h. Doing this so we
42  * can build the DRM (part of PI DRI). 4/21/2000 S + B */
43 #include <asm/current.h>
44 #endif                          /* __alpha__ */
45 #include <linux/kernel.h>
46 #include <linux/miscdevice.h>
47 #include <linux/fs.h>
48 #include <linux/proc_fs.h>
49 #include <linux/init.h>
50 #include <linux/file.h>
51 #include <linux/platform_device.h>
52 #include <linux/pci.h>
53 #include <linux/jiffies.h>
54 #include <linux/dma-mapping.h>
55 #include <linux/mm.h>
56 #include <linux/cdev.h>
57 #include <linux/mutex.h>
58 #include <linux/slab.h>
59 #if defined(__alpha__) || defined(__powerpc__)
60 #include <asm/pgtable.h>        /* For pte_wrprotect */
61 #endif
62 #include <asm/io.h>
63 #include <asm/mman.h>
64 #include <asm/uaccess.h>
65 #ifdef CONFIG_MTRR
66 #include <asm/mtrr.h>
67 #endif
68 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
69 #include <linux/types.h>
70 #include <linux/agp_backend.h>
71 #endif
72 #include <linux/workqueue.h>
73 #include <linux/poll.h>
74 #include <asm/pgalloc.h>
75 #include <drm/drm.h>
76 #include <drm/drm_sarea.h>
77
78 #include <linux/idr.h>
79 #include <linux/ion.h>
80
81 #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
82 #define __OS_HAS_MTRR (defined(CONFIG_MTRR))
83
84 struct module;
85
86 struct drm_file;
87 struct drm_device;
88
89 struct device_node;
90 struct videomode;
91
92 #include <drm/drm_os_linux.h>
93 #include <drm/drm_hashtab.h>
94 #include <drm/drm_mm.h>
95
96 #define DRM_UT_CORE             0x01
97 #define DRM_UT_DRIVER           0x02
98 #define DRM_UT_KMS              0x04
99 #define DRM_UT_PRIME            0x08
100 /*
101  * Three debug levels are defined.
102  * drm_core, drm_driver, drm_kms
103  * drm_core level can be used in the generic drm code. For example:
104  *      drm_ioctl, drm_mm, drm_memory
105  * The macro definition of DRM_DEBUG is used.
106  *      DRM_DEBUG(fmt, args...)
107  *      The debug info by using the DRM_DEBUG can be obtained by adding
108  *      the boot option of "drm.debug=1".
109  *
110  * drm_driver level can be used in the specific drm driver. It is used
111  * to add the debug info related with the drm driver. For example:
112  * i915_drv, i915_dma, i915_gem, radeon_drv,
113  *      The macro definition of DRM_DEBUG_DRIVER can be used.
114  *      DRM_DEBUG_DRIVER(fmt, args...)
115  *      The debug info by using the DRM_DEBUG_DRIVER can be obtained by
116  *      adding the boot option of "drm.debug=0x02"
117  *
118  * drm_kms level can be used in the KMS code related with specific drm driver.
119  * It is used to add the debug info related with KMS mode. For example:
120  * the connector/crtc ,
121  *      The macro definition of DRM_DEBUG_KMS can be used.
122  *      DRM_DEBUG_KMS(fmt, args...)
123  *      The debug info by using the DRM_DEBUG_KMS can be obtained by
124  *      adding the boot option of "drm.debug=0x04"
125  *
126  * If we add the boot option of "drm.debug=0x06", we can get the debug info by
127  * using the DRM_DEBUG_KMS and DRM_DEBUG_DRIVER.
128  * If we add the boot option of "drm.debug=0x05", we can get the debug info by
129  * using the DRM_DEBUG_KMS and DRM_DEBUG.
130  */
131
132 extern __printf(4, 5)
133 void drm_ut_debug_printk(unsigned int request_level,
134                          const char *prefix,
135                          const char *function_name,
136                          const char *format, ...);
137 extern __printf(2, 3)
138 int drm_err(const char *func, const char *format, ...);
139
140 /***********************************************************************/
141 /** \name DRM template customization defaults */
142 /*@{*/
143
144 /* driver capabilities and requirements mask */
145 #define DRIVER_USE_AGP     0x1
146 #define DRIVER_REQUIRE_AGP 0x2
147 #define DRIVER_USE_MTRR    0x4
148 #define DRIVER_PCI_DMA     0x8
149 #define DRIVER_SG          0x10
150 #define DRIVER_HAVE_DMA    0x20
151 #define DRIVER_HAVE_IRQ    0x40
152 #define DRIVER_IRQ_SHARED  0x80
153 #define DRIVER_IRQ_VBL     0x100
154 #define DRIVER_DMA_QUEUE   0x200
155 #define DRIVER_FB_DMA      0x400
156 #define DRIVER_IRQ_VBL2    0x800
157 #define DRIVER_GEM         0x1000
158 #define DRIVER_MODESET     0x2000
159 #define DRIVER_PRIME       0x4000
160
161 #define DRIVER_BUS_PCI 0x1
162 #define DRIVER_BUS_PLATFORM 0x2
163 #define DRIVER_BUS_USB 0x3
164
165 /***********************************************************************/
166 /** \name Begin the DRM... */
167 /*@{*/
168
169 #define DRM_DEBUG_CODE 2          /**< Include debugging code if > 1, then
170                                      also include looping detection. */
171
172 #define DRM_MAGIC_HASH_ORDER  4  /**< Size of key hash table. Must be power of 2. */
173 #define DRM_KERNEL_CONTEXT    0  /**< Change drm_resctx if changed */
174 #define DRM_RESERVED_CONTEXTS 1  /**< Change drm_resctx if changed */
175 #define DRM_LOOPING_LIMIT     5000000
176 #define DRM_TIME_SLICE        (HZ/20)  /**< Time slice for GLXContexts */
177 #define DRM_LOCK_SLICE        1 /**< Time slice for lock, in jiffies */
178
179 #define DRM_FLAG_DEBUG    0x01
180
181 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
182 #define DRM_MAP_HASH_OFFSET 0x10000000
183
184 /*@}*/
185
186 /***********************************************************************/
187 /** \name Macros to make printk easier */
188 /*@{*/
189
190 /**
191  * Error output.
192  *
193  * \param fmt printf() like format string.
194  * \param arg arguments
195  */
196 #define DRM_ERROR(fmt, ...)                             \
197         drm_err(__func__, fmt, ##__VA_ARGS__)
198
199 #define DRM_INFO(fmt, ...)                              \
200         printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
201
202 /**
203  * Debug output.
204  *
205  * \param fmt printf() like format string.
206  * \param arg arguments
207  */
208 #if DRM_DEBUG_CODE
209 #define DRM_DEBUG(fmt, args...)                                         \
210         do {                                                            \
211                 drm_ut_debug_printk(DRM_UT_CORE, DRM_NAME,              \
212                                         __func__, fmt, ##args);         \
213         } while (0)
214
215 #define DRM_DEBUG_DRIVER(fmt, args...)                                  \
216         do {                                                            \
217                 drm_ut_debug_printk(DRM_UT_DRIVER, DRM_NAME,            \
218                                         __func__, fmt, ##args);         \
219         } while (0)
220 #define DRM_DEBUG_KMS(fmt, args...)                             \
221         do {                                                            \
222                 drm_ut_debug_printk(DRM_UT_KMS, DRM_NAME,               \
223                                          __func__, fmt, ##args);        \
224         } while (0)
225 #define DRM_DEBUG_PRIME(fmt, args...)                                   \
226         do {                                                            \
227                 drm_ut_debug_printk(DRM_UT_PRIME, DRM_NAME,             \
228                                         __func__, fmt, ##args);         \
229         } while (0)
230 #define DRM_LOG(fmt, args...)                                           \
231         do {                                                            \
232                 drm_ut_debug_printk(DRM_UT_CORE, NULL,                  \
233                                         NULL, fmt, ##args);             \
234         } while (0)
235 #define DRM_LOG_KMS(fmt, args...)                                       \
236         do {                                                            \
237                 drm_ut_debug_printk(DRM_UT_KMS, NULL,                   \
238                                         NULL, fmt, ##args);             \
239         } while (0)
240 #define DRM_LOG_MODE(fmt, args...)                                      \
241         do {                                                            \
242                 drm_ut_debug_printk(DRM_UT_MODE, NULL,                  \
243                                         NULL, fmt, ##args);             \
244         } while (0)
245 #define DRM_LOG_DRIVER(fmt, args...)                                    \
246         do {                                                            \
247                 drm_ut_debug_printk(DRM_UT_DRIVER, NULL,                \
248                                         NULL, fmt, ##args);             \
249         } while (0)
250 #else
251 #define DRM_DEBUG_DRIVER(fmt, args...) do { } while (0)
252 #define DRM_DEBUG_KMS(fmt, args...)     do { } while (0)
253 #define DRM_DEBUG_PRIME(fmt, args...)   do { } while (0)
254 #define DRM_DEBUG(fmt, arg...)           do { } while (0)
255 #define DRM_LOG(fmt, arg...)            do { } while (0)
256 #define DRM_LOG_KMS(fmt, args...) do { } while (0)
257 #define DRM_LOG_MODE(fmt, arg...) do { } while (0)
258 #define DRM_LOG_DRIVER(fmt, arg...) do { } while (0)
259
260 #endif
261
262 /*@}*/
263
264 /***********************************************************************/
265 /** \name Internal types and structures */
266 /*@{*/
267
268 #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
269
270 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
271 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
272
273 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
274
275 /**
276  * Test that the hardware lock is held by the caller, returning otherwise.
277  *
278  * \param dev DRM device.
279  * \param filp file pointer of the caller.
280  */
281 #define LOCK_TEST_WITH_RETURN( dev, _file_priv )                                \
282 do {                                                                            \
283         if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) ||       \
284             _file_priv->master->lock.file_priv != _file_priv)   {               \
285                 DRM_ERROR( "%s called without lock held, held  %d owner %p %p\n",\
286                            __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
287                            _file_priv->master->lock.file_priv, _file_priv);     \
288                 return -EINVAL;                                                 \
289         }                                                                       \
290 } while (0)
291
292 /**
293  * Ioctl function type.
294  *
295  * \param inode device inode.
296  * \param file_priv DRM file private pointer.
297  * \param cmd command.
298  * \param arg argument.
299  */
300 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
301                         struct drm_file *file_priv);
302
303 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
304                                unsigned long arg);
305
306 #define DRM_IOCTL_NR(n)                _IOC_NR(n)
307 #define DRM_MAJOR       226
308
309 #define DRM_AUTH        0x1
310 #define DRM_MASTER      0x2
311 #define DRM_ROOT_ONLY   0x4
312 #define DRM_CONTROL_ALLOW 0x8
313 #define DRM_UNLOCKED    0x10
314
315 struct drm_ioctl_desc {
316         unsigned int cmd;
317         int flags;
318         drm_ioctl_t *func;
319         unsigned int cmd_drv;
320         const char *name;
321 };
322
323 /**
324  * Creates a driver or general drm_ioctl_desc array entry for the given
325  * ioctl, for use by drm_ioctl().
326  */
327
328 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)                 \
329         [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl, .name = #ioctl}
330
331 struct drm_magic_entry {
332         struct list_head head;
333         struct drm_hash_item hash_item;
334         struct drm_file *priv;
335 };
336
337 struct drm_vma_entry {
338         struct list_head head;
339         struct vm_area_struct *vma;
340         pid_t pid;
341 };
342
343 /**
344  * DMA buffer.
345  */
346 struct drm_buf {
347         int idx;                       /**< Index into master buflist */
348         int total;                     /**< Buffer size */
349         int order;                     /**< log-base-2(total) */
350         int used;                      /**< Amount of buffer in use (for DMA) */
351         unsigned long offset;          /**< Byte offset (used internally) */
352         void *address;                 /**< Address of buffer */
353         unsigned long bus_address;     /**< Bus address of buffer */
354         struct drm_buf *next;          /**< Kernel-only: used for free list */
355         __volatile__ int waiting;      /**< On kernel DMA queue */
356         __volatile__ int pending;      /**< On hardware DMA queue */
357         struct drm_file *file_priv;    /**< Private of holding file descr */
358         int context;                   /**< Kernel queue for this buffer */
359         int while_locked;              /**< Dispatch this buffer while locked */
360         enum {
361                 DRM_LIST_NONE = 0,
362                 DRM_LIST_FREE = 1,
363                 DRM_LIST_WAIT = 2,
364                 DRM_LIST_PEND = 3,
365                 DRM_LIST_PRIO = 4,
366                 DRM_LIST_RECLAIM = 5
367         } list;                        /**< Which list we're on */
368
369         int dev_priv_size;               /**< Size of buffer private storage */
370         void *dev_private;               /**< Per-buffer private storage */
371 };
372
373 /** bufs is one longer than it has to be */
374 struct drm_waitlist {
375         int count;                      /**< Number of possible buffers */
376         struct drm_buf **bufs;          /**< List of pointers to buffers */
377         struct drm_buf **rp;                    /**< Read pointer */
378         struct drm_buf **wp;                    /**< Write pointer */
379         struct drm_buf **end;           /**< End pointer */
380         spinlock_t read_lock;
381         spinlock_t write_lock;
382 };
383
384 struct drm_freelist {
385         int initialized;               /**< Freelist in use */
386         atomic_t count;                /**< Number of free buffers */
387         struct drm_buf *next;          /**< End pointer */
388
389         wait_queue_head_t waiting;     /**< Processes waiting on free bufs */
390         int low_mark;                  /**< Low water mark */
391         int high_mark;                 /**< High water mark */
392         atomic_t wfh;                  /**< If waiting for high mark */
393         spinlock_t lock;
394 };
395
396 typedef struct drm_dma_handle {
397         dma_addr_t busaddr;
398         void *vaddr;
399         size_t size;
400 } drm_dma_handle_t;
401
402 /**
403  * Buffer entry.  There is one of this for each buffer size order.
404  */
405 struct drm_buf_entry {
406         int buf_size;                   /**< size */
407         int buf_count;                  /**< number of buffers */
408         struct drm_buf *buflist;                /**< buffer list */
409         int seg_count;
410         int page_order;
411         struct drm_dma_handle **seglist;
412
413         struct drm_freelist freelist;
414 };
415
416 /* Event queued up for userspace to read */
417 struct drm_pending_event {
418         struct drm_event *event;
419         struct list_head link;
420         struct drm_file *file_priv;
421         pid_t pid; /* pid of requester, no guarantee it's valid by the time
422                       we deliver the event, for tracing only */
423         void (*destroy)(struct drm_pending_event *event);
424 };
425
426 /* initial implementaton using a linked list - todo hashtab */
427 struct drm_prime_file_private {
428         struct list_head head;
429         struct mutex lock;
430 };
431
432 /** File private data */
433 struct drm_file {
434         int authenticated;
435         struct pid *pid;
436         kuid_t uid;
437         drm_magic_t magic;
438         unsigned long ioctl_count;
439         struct list_head lhead;
440         struct drm_minor *minor;
441         unsigned long lock_count;
442
443         /** Mapping of mm object handles to object pointers. */
444         struct idr object_idr;
445         /** Lock for synchronization of access to object_idr. */
446         spinlock_t table_lock;
447
448         struct file *filp;
449         void *driver_priv;
450
451         int is_master; /* this file private is a master for a minor */
452         struct drm_master *master; /* master this node is currently associated with
453                                       N.B. not always minor->master */
454
455         /**
456          * fbs - List of framebuffers associated with this file.
457          *
458          * Protected by fbs_lock. Note that the fbs list holds a reference on
459          * the fb object to prevent it from untimely disappearing.
460          */
461         struct list_head fbs;
462         struct mutex fbs_lock;
463
464         wait_queue_head_t event_wait;
465         struct list_head event_list;
466         int event_space;
467
468         struct drm_prime_file_private prime;
469 };
470
471 /** Wait queue */
472 struct drm_queue {
473         atomic_t use_count;             /**< Outstanding uses (+1) */
474         atomic_t finalization;          /**< Finalization in progress */
475         atomic_t block_count;           /**< Count of processes waiting */
476         atomic_t block_read;            /**< Queue blocked for reads */
477         wait_queue_head_t read_queue;   /**< Processes waiting on block_read */
478         atomic_t block_write;           /**< Queue blocked for writes */
479         wait_queue_head_t write_queue;  /**< Processes waiting on block_write */
480         atomic_t total_queued;          /**< Total queued statistic */
481         atomic_t total_flushed;         /**< Total flushes statistic */
482         atomic_t total_locks;           /**< Total locks statistics */
483         enum drm_ctx_flags flags;       /**< Context preserving and 2D-only */
484         struct drm_waitlist waitlist;   /**< Pending buffers */
485         wait_queue_head_t flush_queue;  /**< Processes waiting until flush */
486 };
487
488 /**
489  * Lock data.
490  */
491 struct drm_lock_data {
492         struct drm_hw_lock *hw_lock;    /**< Hardware lock */
493         /** Private of lock holder's file (NULL=kernel) */
494         struct drm_file *file_priv;
495         wait_queue_head_t lock_queue;   /**< Queue of blocked processes */
496         unsigned long lock_time;        /**< Time of last lock in jiffies */
497         spinlock_t spinlock;
498         uint32_t kernel_waiters;
499         uint32_t user_waiters;
500         int idle_has_lock;
501 };
502
503 /**
504  * DMA data.
505  */
506 struct drm_device_dma {
507
508         struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];   /**< buffers, grouped by their size order */
509         int buf_count;                  /**< total number of buffers */
510         struct drm_buf **buflist;               /**< Vector of pointers into drm_device_dma::bufs */
511         int seg_count;
512         int page_count;                 /**< number of pages */
513         unsigned long *pagelist;        /**< page list */
514         unsigned long byte_count;
515         enum {
516                 _DRM_DMA_USE_AGP = 0x01,
517                 _DRM_DMA_USE_SG = 0x02,
518                 _DRM_DMA_USE_FB = 0x04,
519                 _DRM_DMA_USE_PCI_RO = 0x08
520         } flags;
521
522 };
523
524 /**
525  * AGP memory entry.  Stored as a doubly linked list.
526  */
527 struct drm_agp_mem {
528         unsigned long handle;           /**< handle */
529         DRM_AGP_MEM *memory;
530         unsigned long bound;            /**< address */
531         int pages;
532         struct list_head head;
533 };
534
535 /**
536  * AGP data.
537  *
538  * \sa drm_agp_init() and drm_device::agp.
539  */
540 struct drm_agp_head {
541         DRM_AGP_KERN agp_info;          /**< AGP device information */
542         struct list_head memory;
543         unsigned long mode;             /**< AGP mode */
544         struct agp_bridge_data *bridge;
545         int enabled;                    /**< whether the AGP bus as been enabled */
546         int acquired;                   /**< whether the AGP device has been acquired */
547         unsigned long base;
548         int agp_mtrr;
549         int cant_use_aperture;
550         unsigned long page_mask;
551 };
552
553 /**
554  * Scatter-gather memory.
555  */
556 struct drm_sg_mem {
557         unsigned long handle;
558         void *virtual;
559         int pages;
560         struct page **pagelist;
561         dma_addr_t *busaddr;
562 };
563
564 struct drm_sigdata {
565         int context;
566         struct drm_hw_lock *lock;
567 };
568
569
570 /**
571  * Kernel side of a mapping
572  */
573 struct drm_local_map {
574         resource_size_t offset;  /**< Requested physical address (0 for SAREA)*/
575         unsigned long size;      /**< Requested physical size (bytes) */
576         enum drm_map_type type;  /**< Type of memory to map */
577         enum drm_map_flags flags;        /**< Flags */
578         void *handle;            /**< User-space: "Handle" to pass to mmap() */
579                                  /**< Kernel-space: kernel-virtual address */
580         int mtrr;                /**< MTRR slot used */
581 };
582
583 typedef struct drm_local_map drm_local_map_t;
584
585 /**
586  * Mappings list
587  */
588 struct drm_map_list {
589         struct list_head head;          /**< list head */
590         struct drm_hash_item hash;
591         struct drm_local_map *map;      /**< mapping */
592         uint64_t user_token;
593         struct drm_master *master;
594         struct drm_mm_node *file_offset_node;   /**< fake offset */
595 };
596
597 /**
598  * Context handle list
599  */
600 struct drm_ctx_list {
601         struct list_head head;          /**< list head */
602         drm_context_t handle;           /**< context handle */
603         struct drm_file *tag;           /**< associated fd private data */
604 };
605
606 /* location of GART table */
607 #define DRM_ATI_GART_MAIN 1
608 #define DRM_ATI_GART_FB   2
609
610 #define DRM_ATI_GART_PCI 1
611 #define DRM_ATI_GART_PCIE 2
612 #define DRM_ATI_GART_IGP 3
613
614 struct drm_ati_pcigart_info {
615         int gart_table_location;
616         int gart_reg_if;
617         void *addr;
618         dma_addr_t bus_addr;
619         dma_addr_t table_mask;
620         struct drm_dma_handle *table_handle;
621         struct drm_local_map mapping;
622         int table_size;
623 };
624
625 /**
626  * GEM specific mm private for tracking GEM objects
627  */
628 struct drm_gem_mm {
629         struct drm_mm offset_manager;   /**< Offset mgmt for buffer objects */
630         struct drm_open_hash offset_hash; /**< User token hash table for maps */
631 };
632
633 /**
634  * This structure defines the drm_mm memory object, which will be used by the
635  * DRM for its buffer objects.
636  */
637 struct drm_gem_object {
638         /** Reference count of this object */
639         struct kref refcount;
640
641         /** Handle count of this object. Each handle also holds a reference */
642         atomic_t handle_count; /* number of handles on this object */
643
644         /** Related drm device */
645         struct drm_device *dev;
646
647         /** File representing the shmem storage */
648         struct file *filp;
649
650         /* Mapping info for this object */
651         struct drm_map_list map_list;
652
653         /**
654          * Size of the object, in bytes.  Immutable over the object's
655          * lifetime.
656          */
657         size_t size;
658
659         /**
660          * Global name for this object, starts at 1. 0 means unnamed.
661          * Access is covered by the object_name_lock in the related drm_device
662          */
663         int name;
664
665         /**
666          * Memory domains. These monitor which caches contain read/write data
667          * related to the object. When transitioning from one set of domains
668          * to another, the driver is called to ensure that caches are suitably
669          * flushed and invalidated
670          */
671         uint32_t read_domains;
672         uint32_t write_domain;
673
674         /**
675          * While validating an exec operation, the
676          * new read/write domain values are computed here.
677          * They will be transferred to the above values
678          * at the point that any cache flushing occurs
679          */
680         uint32_t pending_read_domains;
681         uint32_t pending_write_domain;
682
683         void *driver_private;
684
685         /* dma buf exported from this GEM object */
686         struct dma_buf *export_dma_buf;
687
688         /* dma buf attachment backing this object */
689         struct dma_buf_attachment *import_attach;
690 };
691
692 #include <drm/drm_crtc.h>
693
694 /* per-master structure */
695 struct drm_master {
696
697         struct kref refcount; /* refcount for this master */
698
699         struct list_head head; /**< each minor contains a list of masters */
700         struct drm_minor *minor; /**< link back to minor we are a master for */
701
702         char *unique;                   /**< Unique identifier: e.g., busid */
703         int unique_len;                 /**< Length of unique field */
704         int unique_size;                /**< amount allocated */
705
706         int blocked;                    /**< Blocked due to VC switch? */
707
708         /** \name Authentication */
709         /*@{ */
710         struct drm_open_hash magiclist;
711         struct list_head magicfree;
712         /*@} */
713
714         struct drm_lock_data lock;      /**< Information on hardware lock */
715
716         void *driver_priv; /**< Private structure for driver to use */
717 };
718
719 /* Size of ringbuffer for vblank timestamps. Just double-buffer
720  * in initial implementation.
721  */
722 #define DRM_VBLANKTIME_RBSIZE 2
723
724 /* Flags and return codes for get_vblank_timestamp() driver function. */
725 #define DRM_CALLED_FROM_VBLIRQ 1
726 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
727 #define DRM_VBLANKTIME_INVBL             (1 << 1)
728
729 /* get_scanout_position() return flags */
730 #define DRM_SCANOUTPOS_VALID        (1 << 0)
731 #define DRM_SCANOUTPOS_INVBL        (1 << 1)
732 #define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
733
734 struct drm_bus {
735         int bus_type;
736         int (*get_irq)(struct drm_device *dev);
737         const char *(*get_name)(struct drm_device *dev);
738         int (*set_busid)(struct drm_device *dev, struct drm_master *master);
739         int (*set_unique)(struct drm_device *dev, struct drm_master *master,
740                           struct drm_unique *unique);
741         int (*irq_by_busid)(struct drm_device *dev, struct drm_irq_busid *p);
742         /* hooks that are for PCI */
743         int (*agp_init)(struct drm_device *dev);
744
745 };
746
747 /**
748  * DRM driver structure. This structure represent the common code for
749  * a family of cards. There will one drm_device for each card present
750  * in this family
751  */
752 struct drm_driver {
753         int (*load) (struct drm_device *, unsigned long flags);
754         int (*firstopen) (struct drm_device *);
755         int (*open) (struct drm_device *, struct drm_file *);
756         void (*preclose) (struct drm_device *, struct drm_file *file_priv);
757         void (*postclose) (struct drm_device *, struct drm_file *);
758         void (*lastclose) (struct drm_device *);
759         int (*unload) (struct drm_device *);
760         int (*suspend) (struct drm_device *, pm_message_t state);
761         int (*resume) (struct drm_device *);
762         int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
763         int (*dma_quiescent) (struct drm_device *);
764         int (*context_dtor) (struct drm_device *dev, int context);
765
766         /**
767          * get_vblank_counter - get raw hardware vblank counter
768          * @dev: DRM device
769          * @crtc: counter to fetch
770          *
771          * Driver callback for fetching a raw hardware vblank counter for @crtc.
772          * If a device doesn't have a hardware counter, the driver can simply
773          * return the value of drm_vblank_count. The DRM core will account for
774          * missed vblank events while interrupts where disabled based on system
775          * timestamps.
776          *
777          * Wraparound handling and loss of events due to modesetting is dealt
778          * with in the DRM core code.
779          *
780          * RETURNS
781          * Raw vblank counter value.
782          */
783         u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
784
785         /**
786          * prepare_vblank - prepare wating vblank
787          * @dev: DRM device
788          * @crtc: which irq to enable
789          *
790          * Prepare vblank waiting @crtc.
791          */
792         int (*prepare_vblank) (struct drm_device *dev, int crtc, struct drm_file *file_priv);
793
794         /**
795          * enable_vblank - enable vblank interrupt events
796          * @dev: DRM device
797          * @crtc: which irq to enable
798          *
799          * Enable vblank interrupts for @crtc.  If the device doesn't have
800          * a hardware vblank counter, this routine should be a no-op, since
801          * interrupts will have to stay on to keep the count accurate.
802          *
803          * RETURNS
804          * Zero on success, appropriate errno if the given @crtc's vblank
805          * interrupt cannot be enabled.
806          */
807         int (*enable_vblank) (struct drm_device *dev, int crtc);
808
809         /**
810          * disable_vblank - disable vblank interrupt events
811          * @dev: DRM device
812          * @crtc: which irq to enable
813          *
814          * Disable vblank interrupts for @crtc.  If the device doesn't have
815          * a hardware vblank counter, this routine should be a no-op, since
816          * interrupts will have to stay on to keep the count accurate.
817          */
818         void (*disable_vblank) (struct drm_device *dev, int crtc);
819
820         /**
821          * Called by \c drm_device_is_agp.  Typically used to determine if a
822          * card is really attached to AGP or not.
823          *
824          * \param dev  DRM device handle
825          *
826          * \returns
827          * One of three values is returned depending on whether or not the
828          * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
829          * (return of 1), or may or may not be AGP (return of 2).
830          */
831         int (*device_is_agp) (struct drm_device *dev);
832
833         /**
834          * Called by vblank timestamping code.
835          *
836          * Return the current display scanout position from a crtc.
837          *
838          * \param dev  DRM device.
839          * \param crtc Id of the crtc to query.
840          * \param *vpos Target location for current vertical scanout position.
841          * \param *hpos Target location for current horizontal scanout position.
842          *
843          * Returns vpos as a positive number while in active scanout area.
844          * Returns vpos as a negative number inside vblank, counting the number
845          * of scanlines to go until end of vblank, e.g., -1 means "one scanline
846          * until start of active scanout / end of vblank."
847          *
848          * \return Flags, or'ed together as follows:
849          *
850          * DRM_SCANOUTPOS_VALID = Query successful.
851          * DRM_SCANOUTPOS_INVBL = Inside vblank.
852          * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
853          * this flag means that returned position may be offset by a constant
854          * but unknown small number of scanlines wrt. real scanout position.
855          *
856          */
857         int (*get_scanout_position) (struct drm_device *dev, int crtc,
858                                      int *vpos, int *hpos);
859
860         /**
861          * Called by \c drm_get_last_vbltimestamp. Should return a precise
862          * timestamp when the most recent VBLANK interval ended or will end.
863          *
864          * Specifically, the timestamp in @vblank_time should correspond as
865          * closely as possible to the time when the first video scanline of
866          * the video frame after the end of VBLANK will start scanning out,
867          * the time immediately after end of the VBLANK interval. If the
868          * @crtc is currently inside VBLANK, this will be a time in the future.
869          * If the @crtc is currently scanning out a frame, this will be the
870          * past start time of the current scanout. This is meant to adhere
871          * to the OpenML OML_sync_control extension specification.
872          *
873          * \param dev dev DRM device handle.
874          * \param crtc crtc for which timestamp should be returned.
875          * \param *max_error Maximum allowable timestamp error in nanoseconds.
876          *                   Implementation should strive to provide timestamp
877          *                   with an error of at most *max_error nanoseconds.
878          *                   Returns true upper bound on error for timestamp.
879          * \param *vblank_time Target location for returned vblank timestamp.
880          * \param flags 0 = Defaults, no special treatment needed.
881          * \param       DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
882          *              irq handler. Some drivers need to apply some workarounds
883          *              for gpu-specific vblank irq quirks if flag is set.
884          *
885          * \returns
886          * Zero if timestamping isn't supported in current display mode or a
887          * negative number on failure. A positive status code on success,
888          * which describes how the vblank_time timestamp was computed.
889          */
890         int (*get_vblank_timestamp) (struct drm_device *dev, int crtc,
891                                      int *max_error,
892                                      struct timeval *vblank_time,
893                                      unsigned flags);
894
895         /* these have to be filled in */
896
897         irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
898         void (*irq_preinstall) (struct drm_device *dev);
899         int (*irq_postinstall) (struct drm_device *dev);
900         void (*irq_uninstall) (struct drm_device *dev);
901         void (*set_version) (struct drm_device *dev,
902                              struct drm_set_version *sv);
903
904         /* Master routines */
905         int (*master_create)(struct drm_device *dev, struct drm_master *master);
906         void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
907         /**
908          * master_set is called whenever the minor master is set.
909          * master_drop is called whenever the minor master is dropped.
910          */
911
912         int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
913                           bool from_open);
914         void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv,
915                             bool from_release);
916
917         int (*debugfs_init)(struct drm_minor *minor);
918         void (*debugfs_cleanup)(struct drm_minor *minor);
919
920         /**
921          * Driver-specific constructor for drm_gem_objects, to set up
922          * obj->driver_private.
923          *
924          * Returns 0 on success.
925          */
926         int (*gem_init_object) (struct drm_gem_object *obj);
927         void (*gem_free_object) (struct drm_gem_object *obj);
928         int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
929         void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
930
931         /* prime: */
932         /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
933         int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
934                                 uint32_t handle, uint32_t flags, int *prime_fd);
935         /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
936         int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
937                                 int prime_fd, uint32_t *handle);
938         /* export GEM -> dmabuf */
939         struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
940                                 struct drm_gem_object *obj, int flags);
941         /* import dmabuf -> GEM */
942         struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
943                                 struct dma_buf *dma_buf);
944         /* low-level interface used by drm_gem_prime_{import,export} */
945         int (*gem_prime_pin)(struct drm_gem_object *obj);
946         struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
947         struct drm_gem_object *(*gem_prime_import_sg_table)(
948                                 struct drm_device *dev, size_t size,
949                                 struct sg_table *sgt);
950         void *(*gem_prime_vmap)(struct drm_gem_object *obj);
951         void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
952
953         /* vga arb irq handler */
954         void (*vgaarb_irq)(struct drm_device *dev, bool state);
955
956         /* dumb alloc support */
957         int (*dumb_create)(struct drm_file *file_priv,
958                            struct drm_device *dev,
959                            struct drm_mode_create_dumb *args);
960         int (*dumb_map_offset)(struct drm_file *file_priv,
961                                struct drm_device *dev, uint32_t handle,
962                                uint64_t *offset);
963         int (*dumb_destroy)(struct drm_file *file_priv,
964                             struct drm_device *dev,
965                             uint32_t handle);
966
967         /* Driver private ops for this object */
968         const struct vm_operations_struct *gem_vm_ops;
969
970         int major;
971         int minor;
972         int patchlevel;
973         char *name;
974         char *desc;
975         char *date;
976
977         u32 driver_features;
978         int dev_priv_size;
979         struct drm_ioctl_desc *ioctls;
980         int num_ioctls;
981         const struct file_operations *fops;
982         union {
983                 struct pci_driver *pci;
984                 struct platform_device *platform_device;
985                 struct usb_driver *usb;
986         } kdriver;
987         struct drm_bus *bus;
988
989         /* List of devices hanging off this driver */
990         struct list_head device_list;
991 };
992
993 #define DRM_MINOR_UNASSIGNED 0
994 #define DRM_MINOR_LEGACY 1
995 #define DRM_MINOR_CONTROL 2
996 #define DRM_MINOR_RENDER 3
997
998
999 /**
1000  * debugfs node list. This structure represents a debugfs file to
1001  * be created by the drm core
1002  */
1003 struct drm_debugfs_list {
1004         const char *name; /** file name */
1005         int (*show)(struct seq_file*, void*); /** show callback */
1006         u32 driver_features; /**< Required driver features for this entry */
1007 };
1008
1009 /**
1010  * debugfs node structure. This structure represents a debugfs file.
1011  */
1012 struct drm_debugfs_node {
1013         struct list_head list;
1014         struct drm_minor *minor;
1015         struct drm_debugfs_list *debugfs_ent;
1016         struct dentry *dent;
1017 };
1018
1019 /**
1020  * Info file list entry. This structure represents a debugfs or proc file to
1021  * be created by the drm core
1022  */
1023 struct drm_info_list {
1024         const char *name; /** file name */
1025         int (*show)(struct seq_file*, void*); /** show callback */
1026         u32 driver_features; /**< Required driver features for this entry */
1027         void *data;
1028 };
1029
1030 /**
1031  * debugfs node structure. This structure represents a debugfs file.
1032  */
1033 struct drm_info_node {
1034         struct list_head list;
1035         struct drm_minor *minor;
1036         const struct drm_info_list *info_ent;
1037         struct dentry *dent;
1038 };
1039
1040 /**
1041  * DRM minor structure. This structure represents a drm minor number.
1042  */
1043 struct drm_minor {
1044         int index;                      /**< Minor device number */
1045         int type;                       /**< Control or render */
1046         dev_t device;                   /**< Device number for mknod */
1047         struct device kdev;             /**< Linux device */
1048         struct drm_device *dev;
1049
1050         struct proc_dir_entry *proc_root;  /**< proc directory entry */
1051         struct drm_info_node proc_nodes;
1052         struct dentry *debugfs_root;
1053
1054         struct list_head debugfs_list;
1055         struct mutex debugfs_lock; /* Protects debugfs_list. */
1056
1057         struct drm_master *master; /* currently active master for this node */
1058         struct list_head master_list;
1059         struct drm_mode_group mode_group;
1060 };
1061
1062 /* mode specified on the command line */
1063 struct drm_cmdline_mode {
1064         bool specified;
1065         bool refresh_specified;
1066         bool bpp_specified;
1067         int xres, yres;
1068         int bpp;
1069         int refresh;
1070         bool rb;
1071         bool interlace;
1072         bool cvt;
1073         bool margins;
1074         enum drm_connector_force force;
1075 };
1076
1077
1078 struct drm_pending_vblank_event {
1079         struct drm_pending_event base;
1080         int pipe;
1081         struct drm_event_vblank event;
1082 };
1083
1084 /**
1085  * DRM device structure. This structure represent a complete card that
1086  * may contain multiple heads.
1087  */
1088 struct drm_device {
1089         struct list_head driver_item;   /**< list of devices per driver */
1090         char *devname;                  /**< For /proc/interrupts */
1091         int if_version;                 /**< Highest interface version set */
1092
1093         /** \name Locks */
1094         /*@{ */
1095         spinlock_t count_lock;          /**< For inuse, drm_device::open_count, drm_device::buf_use */
1096         struct mutex struct_mutex;      /**< For others */
1097         /*@} */
1098
1099         /** \name Usage Counters */
1100         /*@{ */
1101         int open_count;                 /**< Outstanding files open */
1102         atomic_t ioctl_count;           /**< Outstanding IOCTLs pending */
1103         atomic_t vma_count;             /**< Outstanding vma areas open */
1104         int buf_use;                    /**< Buffers in use -- cannot alloc */
1105         atomic_t buf_alloc;             /**< Buffer allocation in progress */
1106         /*@} */
1107
1108         /** \name Performance counters */
1109         /*@{ */
1110         unsigned long counters;
1111         enum drm_stat_type types[15];
1112         atomic_t counts[15];
1113         /*@} */
1114
1115         struct list_head filelist;
1116
1117         /** \name Memory management */
1118         /*@{ */
1119         struct list_head maplist;       /**< Linked list of regions */
1120         int map_count;                  /**< Number of mappable regions */
1121         struct drm_open_hash map_hash;  /**< User token hash table for maps */
1122
1123         /** \name Context handle management */
1124         /*@{ */
1125         struct list_head ctxlist;       /**< Linked list of context handles */
1126         int ctx_count;                  /**< Number of context handles */
1127         struct mutex ctxlist_mutex;     /**< For ctxlist */
1128
1129         struct idr ctx_idr;
1130
1131         struct list_head vmalist;       /**< List of vmas (for debugging) */
1132
1133         /*@} */
1134
1135         /** \name DMA support */
1136         /*@{ */
1137         struct drm_device_dma *dma;             /**< Optional pointer for DMA support */
1138         /*@} */
1139
1140         /** \name Context support */
1141         /*@{ */
1142         int irq_enabled;                /**< True if irq handler is enabled */
1143         __volatile__ long context_flag; /**< Context swapping flag */
1144         __volatile__ long interrupt_flag; /**< Interruption handler flag */
1145         __volatile__ long dma_flag;     /**< DMA dispatch flag */
1146         wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
1147         int last_checked;               /**< Last context checked for DMA */
1148         int last_context;               /**< Last current context */
1149         unsigned long last_switch;      /**< jiffies at last context switch */
1150         /*@} */
1151
1152         struct work_struct work;
1153         /** \name VBLANK IRQ support */
1154         /*@{ */
1155
1156         /*
1157          * At load time, disabling the vblank interrupt won't be allowed since
1158          * old clients may not call the modeset ioctl and therefore misbehave.
1159          * Once the modeset ioctl *has* been called though, we can safely
1160          * disable them when unused.
1161          */
1162         int vblank_disable_allowed;
1163
1164         wait_queue_head_t *vbl_queue;   /**< VBLANK wait queue */
1165         atomic_t *_vblank_count;        /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
1166         struct timeval *_vblank_time;   /**< timestamp of current vblank_count (drivers must alloc right number of fields) */
1167         spinlock_t vblank_time_lock;    /**< Protects vblank count and time updates during vblank enable/disable */
1168         spinlock_t vbl_lock;
1169         atomic_t *vblank_refcount;      /* number of users of vblank interruptsper crtc */
1170         u32 *last_vblank;               /* protected by dev->vbl_lock, used */
1171                                         /* for wraparound handling */
1172         int *vblank_enabled;            /* so we don't call enable more than
1173                                            once per disable */
1174         int *vblank_inmodeset;          /* Display driver is setting mode */
1175         u32 *last_vblank_wait;          /* Last vblank seqno waited per CRTC */
1176         struct timer_list vblank_disable_timer;
1177
1178         u32 max_vblank_count;           /**< size of vblank counter register */
1179
1180         /**
1181          * List of events
1182          */
1183         struct list_head vblank_event_list;
1184         spinlock_t event_lock;
1185
1186         /*@} */
1187         cycles_t ctx_start;
1188         cycles_t lck_start;
1189
1190         struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
1191         wait_queue_head_t buf_readers;  /**< Processes waiting to read */
1192         wait_queue_head_t buf_writers;  /**< Processes waiting to ctx switch */
1193
1194         struct drm_agp_head *agp;       /**< AGP data */
1195
1196         struct device *dev;             /**< Device structure */
1197         struct pci_dev *pdev;           /**< PCI device structure */
1198         int pci_vendor;                 /**< PCI vendor id */
1199         int pci_device;                 /**< PCI device id */
1200 #ifdef __alpha__
1201         struct pci_controller *hose;
1202 #endif
1203
1204         struct platform_device *platformdev; /**< Platform device struture */
1205         struct usb_device *usbdev;
1206
1207         struct drm_sg_mem *sg;  /**< Scatter gather memory */
1208         unsigned int num_crtcs;                  /**< Number of CRTCs on this device */
1209         void *dev_private;              /**< device private data */
1210         void *mm_private;
1211         struct address_space *dev_mapping;
1212         struct drm_sigdata sigdata;        /**< For block_all_signals */
1213         sigset_t sigmask;
1214
1215         struct drm_driver *driver;
1216         struct drm_local_map *agp_buffer_map;
1217         unsigned int agp_buffer_token;
1218         struct drm_minor *control;              /**< Control node for card */
1219         struct drm_minor *primary;              /**< render type primary screen head */
1220
1221         struct drm_mode_config mode_config;     /**< Current mode config */
1222
1223         /** \name GEM information */
1224         /*@{ */
1225         spinlock_t object_name_lock;
1226         struct idr object_name_idr;
1227         /*@} */
1228         int switch_power_state;
1229
1230         atomic_t unplugged; /* device has been unplugged or gone away */
1231 };
1232
1233 #define DRM_SWITCH_POWER_ON 0
1234 #define DRM_SWITCH_POWER_OFF 1
1235 #define DRM_SWITCH_POWER_CHANGING 2
1236
1237 static __inline__ int drm_core_check_feature(struct drm_device *dev,
1238                                              int feature)
1239 {
1240         return ((dev->driver->driver_features & feature) ? 1 : 0);
1241 }
1242
1243 static inline int drm_dev_to_irq(struct drm_device *dev)
1244 {
1245         return dev->driver->bus->get_irq(dev);
1246 }
1247
1248
1249 #if __OS_HAS_AGP
1250 static inline int drm_core_has_AGP(struct drm_device *dev)
1251 {
1252         return drm_core_check_feature(dev, DRIVER_USE_AGP);
1253 }
1254 #else
1255 #define drm_core_has_AGP(dev) (0)
1256 #endif
1257
1258 #if __OS_HAS_MTRR
1259 static inline int drm_core_has_MTRR(struct drm_device *dev)
1260 {
1261         return drm_core_check_feature(dev, DRIVER_USE_MTRR);
1262 }
1263
1264 #define DRM_MTRR_WC             MTRR_TYPE_WRCOMB
1265
1266 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
1267                                unsigned int flags)
1268 {
1269         return mtrr_add(offset, size, flags, 1);
1270 }
1271
1272 static inline int drm_mtrr_del(int handle, unsigned long offset,
1273                                unsigned long size, unsigned int flags)
1274 {
1275         return mtrr_del(handle, offset, size);
1276 }
1277
1278 #else
1279 #define drm_core_has_MTRR(dev) (0)
1280
1281 #define DRM_MTRR_WC             0
1282
1283 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
1284                                unsigned int flags)
1285 {
1286         return 0;
1287 }
1288
1289 static inline int drm_mtrr_del(int handle, unsigned long offset,
1290                                unsigned long size, unsigned int flags)
1291 {
1292         return 0;
1293 }
1294 #endif
1295
1296 static inline void drm_device_set_unplugged(struct drm_device *dev)
1297 {
1298         smp_wmb();
1299         atomic_set(&dev->unplugged, 1);
1300 }
1301
1302 static inline int drm_device_is_unplugged(struct drm_device *dev)
1303 {
1304         int ret = atomic_read(&dev->unplugged);
1305         smp_rmb();
1306         return ret;
1307 }
1308
1309 static inline bool drm_modeset_is_locked(struct drm_device *dev)
1310 {
1311         return mutex_is_locked(&dev->mode_config.mutex);
1312 }
1313
1314 /******************************************************************/
1315 /** \name Internal function definitions */
1316 /*@{*/
1317
1318                                 /* Driver support (drm_drv.h) */
1319 extern long drm_ioctl(struct file *filp,
1320                       unsigned int cmd, unsigned long arg);
1321 extern long drm_compat_ioctl(struct file *filp,
1322                              unsigned int cmd, unsigned long arg);
1323 extern int drm_lastclose(struct drm_device *dev);
1324
1325                                 /* Device support (drm_fops.h) */
1326 extern struct mutex drm_global_mutex;
1327 extern int drm_open(struct inode *inode, struct file *filp);
1328 extern int drm_stub_open(struct inode *inode, struct file *filp);
1329 extern int drm_fasync(int fd, struct file *filp, int on);
1330 extern ssize_t drm_read(struct file *filp, char __user *buffer,
1331                         size_t count, loff_t *offset);
1332 extern int drm_release(struct inode *inode, struct file *filp);
1333
1334                                 /* Mapping support (drm_vm.h) */
1335 extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
1336 extern int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma);
1337 extern void drm_vm_open_locked(struct drm_device *dev, struct vm_area_struct *vma);
1338 extern void drm_vm_close_locked(struct drm_device *dev, struct vm_area_struct *vma);
1339 extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
1340
1341                                 /* Memory management support (drm_memory.h) */
1342 #include <drm/drm_memory.h>
1343 extern void drm_free_agp(DRM_AGP_MEM * handle, int pages);
1344 extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
1345 extern DRM_AGP_MEM *drm_agp_bind_pages(struct drm_device *dev,
1346                                        struct page **pages,
1347                                        unsigned long num_pages,
1348                                        uint32_t gtt_offset,
1349                                        uint32_t type);
1350 extern int drm_unbind_agp(DRM_AGP_MEM * handle);
1351
1352                                 /* Misc. IOCTL support (drm_ioctl.h) */
1353 extern int drm_irq_by_busid(struct drm_device *dev, void *data,
1354                             struct drm_file *file_priv);
1355 extern int drm_getunique(struct drm_device *dev, void *data,
1356                          struct drm_file *file_priv);
1357 extern int drm_setunique(struct drm_device *dev, void *data,
1358                          struct drm_file *file_priv);
1359 extern int drm_getmap(struct drm_device *dev, void *data,
1360                       struct drm_file *file_priv);
1361 extern int drm_getclient(struct drm_device *dev, void *data,
1362                          struct drm_file *file_priv);
1363 extern int drm_getstats(struct drm_device *dev, void *data,
1364                         struct drm_file *file_priv);
1365 extern int drm_getcap(struct drm_device *dev, void *data,
1366                       struct drm_file *file_priv);
1367 extern int drm_setversion(struct drm_device *dev, void *data,
1368                           struct drm_file *file_priv);
1369 extern int drm_noop(struct drm_device *dev, void *data,
1370                     struct drm_file *file_priv);
1371
1372                                 /* Context IOCTL support (drm_context.h) */
1373 extern int drm_resctx(struct drm_device *dev, void *data,
1374                       struct drm_file *file_priv);
1375 extern int drm_addctx(struct drm_device *dev, void *data,
1376                       struct drm_file *file_priv);
1377 extern int drm_modctx(struct drm_device *dev, void *data,
1378                       struct drm_file *file_priv);
1379 extern int drm_getctx(struct drm_device *dev, void *data,
1380                       struct drm_file *file_priv);
1381 extern int drm_switchctx(struct drm_device *dev, void *data,
1382                          struct drm_file *file_priv);
1383 extern int drm_newctx(struct drm_device *dev, void *data,
1384                       struct drm_file *file_priv);
1385 extern int drm_rmctx(struct drm_device *dev, void *data,
1386                      struct drm_file *file_priv);
1387
1388 extern int drm_ctxbitmap_init(struct drm_device *dev);
1389 extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
1390 extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
1391
1392 extern int drm_setsareactx(struct drm_device *dev, void *data,
1393                            struct drm_file *file_priv);
1394 extern int drm_getsareactx(struct drm_device *dev, void *data,
1395                            struct drm_file *file_priv);
1396
1397                                 /* Authentication IOCTL support (drm_auth.h) */
1398 extern int drm_getmagic(struct drm_device *dev, void *data,
1399                         struct drm_file *file_priv);
1400 extern int drm_authmagic(struct drm_device *dev, void *data,
1401                          struct drm_file *file_priv);
1402 extern int drm_remove_magic(struct drm_master *master, drm_magic_t magic);
1403
1404 /* Cache management (drm_cache.c) */
1405 void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
1406 void drm_clflush_sg(struct sg_table *st);
1407 void drm_clflush_virt_range(char *addr, unsigned long length);
1408
1409                                 /* Locking IOCTL support (drm_lock.h) */
1410 extern int drm_lock(struct drm_device *dev, void *data,
1411                     struct drm_file *file_priv);
1412 extern int drm_unlock(struct drm_device *dev, void *data,
1413                       struct drm_file *file_priv);
1414 extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
1415 extern void drm_idlelock_take(struct drm_lock_data *lock_data);
1416 extern void drm_idlelock_release(struct drm_lock_data *lock_data);
1417
1418 /*
1419  * These are exported to drivers so that they can implement fencing using
1420  * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1421  */
1422
1423 extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
1424
1425                                 /* Buffer management support (drm_bufs.h) */
1426 extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
1427 extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
1428 extern int drm_addmap(struct drm_device *dev, resource_size_t offset,
1429                       unsigned int size, enum drm_map_type type,
1430                       enum drm_map_flags flags, struct drm_local_map **map_ptr);
1431 extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
1432                             struct drm_file *file_priv);
1433 extern int drm_rmmap(struct drm_device *dev, struct drm_local_map *map);
1434 extern int drm_rmmap_locked(struct drm_device *dev, struct drm_local_map *map);
1435 extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1436                            struct drm_file *file_priv);
1437 extern int drm_addbufs(struct drm_device *dev, void *data,
1438                        struct drm_file *file_priv);
1439 extern int drm_infobufs(struct drm_device *dev, void *data,
1440                         struct drm_file *file_priv);
1441 extern int drm_markbufs(struct drm_device *dev, void *data,
1442                         struct drm_file *file_priv);
1443 extern int drm_freebufs(struct drm_device *dev, void *data,
1444                         struct drm_file *file_priv);
1445 extern int drm_mapbufs(struct drm_device *dev, void *data,
1446                        struct drm_file *file_priv);
1447 extern int drm_order(unsigned long size);
1448
1449                                 /* DMA support (drm_dma.h) */
1450 extern int drm_dma_setup(struct drm_device *dev);
1451 extern void drm_dma_takedown(struct drm_device *dev);
1452 extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
1453 extern void drm_core_reclaim_buffers(struct drm_device *dev,
1454                                      struct drm_file *filp);
1455
1456                                 /* IRQ support (drm_irq.h) */
1457 extern int drm_control(struct drm_device *dev, void *data,
1458                        struct drm_file *file_priv);
1459 extern int drm_irq_install(struct drm_device *dev);
1460 extern int drm_irq_uninstall(struct drm_device *dev);
1461
1462 extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1463 extern int drm_wait_vblank(struct drm_device *dev, void *data,
1464                            struct drm_file *filp);
1465 extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
1466 extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1467 extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
1468                                      struct timeval *vblanktime);
1469 extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
1470                                      struct drm_pending_vblank_event *e);
1471 extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
1472 extern int drm_vblank_get(struct drm_device *dev, int crtc);
1473 extern void drm_vblank_put(struct drm_device *dev, int crtc);
1474 extern void drm_vblank_off(struct drm_device *dev, int crtc);
1475 extern void drm_vblank_cleanup(struct drm_device *dev);
1476 extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
1477                                      struct timeval *tvblank, unsigned flags);
1478 extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
1479                                                  int crtc, int *max_error,
1480                                                  struct timeval *vblank_time,
1481                                                  unsigned flags,
1482                                                  struct drm_crtc *refcrtc);
1483 extern void drm_calc_timestamping_constants(struct drm_crtc *crtc);
1484
1485 extern bool
1486 drm_mode_parse_command_line_for_connector(const char *mode_option,
1487                                           struct drm_connector *connector,
1488                                           struct drm_cmdline_mode *mode);
1489
1490 extern struct drm_display_mode *
1491 drm_mode_create_from_cmdline_mode(struct drm_device *dev,
1492                                   struct drm_cmdline_mode *cmd);
1493
1494 extern int drm_display_mode_from_videomode(const struct videomode *vm,
1495                                            struct drm_display_mode *dmode);
1496 extern int of_get_drm_display_mode(struct device_node *np,
1497                                    struct drm_display_mode *dmode,
1498                                    int index);
1499
1500 /* Modesetting support */
1501 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
1502 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
1503 extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1504                            struct drm_file *file_priv);
1505
1506                                 /* AGP/GART support (drm_agpsupport.h) */
1507 extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
1508 extern int drm_agp_acquire(struct drm_device *dev);
1509 extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1510                                  struct drm_file *file_priv);
1511 extern int drm_agp_release(struct drm_device *dev);
1512 extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1513                                  struct drm_file *file_priv);
1514 extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1515 extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1516                                 struct drm_file *file_priv);
1517 extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
1518 extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1519                         struct drm_file *file_priv);
1520 extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1521 extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1522                          struct drm_file *file_priv);
1523 extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1524 extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1525                         struct drm_file *file_priv);
1526 extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1527 extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1528                           struct drm_file *file_priv);
1529 extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1530 extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1531                         struct drm_file *file_priv);
1532
1533                                 /* Stub support (drm_stub.h) */
1534 extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1535                                struct drm_file *file_priv);
1536 extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1537                                 struct drm_file *file_priv);
1538 struct drm_master *drm_master_create(struct drm_minor *minor);
1539 extern struct drm_master *drm_master_get(struct drm_master *master);
1540 extern void drm_master_put(struct drm_master **master);
1541
1542 extern void drm_put_dev(struct drm_device *dev);
1543 extern int drm_put_minor(struct drm_minor **minor);
1544 extern void drm_unplug_dev(struct drm_device *dev);
1545 extern unsigned int drm_debug;
1546
1547 extern unsigned int drm_vblank_offdelay;
1548 extern unsigned int drm_timestamp_precision;
1549 extern unsigned int drm_timestamp_monotonic;
1550
1551 extern struct class *drm_class;
1552 extern struct proc_dir_entry *drm_proc_root;
1553 extern struct dentry *drm_debugfs_root;
1554
1555 extern struct idr drm_minors_idr;
1556
1557 extern struct drm_local_map *drm_getsarea(struct drm_device *dev);
1558
1559                                 /* Proc support (drm_proc.h) */
1560 extern int drm_proc_init(struct drm_minor *minor, struct proc_dir_entry *root);
1561 extern int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root);
1562
1563                                 /* Debugfs support */
1564 #if defined(CONFIG_DEBUG_FS)
1565 extern int drm_debugfs_init(struct drm_minor *minor, int minor_id,
1566                             struct dentry *root);
1567 extern int drm_debugfs_create_files(struct drm_info_list *files, int count,
1568                                     struct dentry *root, struct drm_minor *minor);
1569 extern int drm_debugfs_remove_files(struct drm_info_list *files, int count,
1570                                     struct drm_minor *minor);
1571 extern int drm_debugfs_cleanup(struct drm_minor *minor);
1572 #endif
1573
1574                                 /* Info file support */
1575 extern int drm_name_info(struct seq_file *m, void *data);
1576 extern int drm_vm_info(struct seq_file *m, void *data);
1577 extern int drm_bufs_info(struct seq_file *m, void *data);
1578 extern int drm_vblank_info(struct seq_file *m, void *data);
1579 extern int drm_clients_info(struct seq_file *m, void* data);
1580 extern int drm_gem_name_info(struct seq_file *m, void *data);
1581
1582
1583 extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
1584                 struct drm_gem_object *obj, int flags);
1585 extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
1586                 struct drm_file *file_priv, uint32_t handle, uint32_t flags,
1587                 int *prime_fd);
1588 extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
1589                 struct dma_buf *dma_buf);
1590 extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
1591                 struct drm_file *file_priv, int prime_fd, uint32_t *handle);
1592
1593 extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
1594                                         struct drm_file *file_priv);
1595 extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
1596                                         struct drm_file *file_priv);
1597
1598 extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
1599                                             dma_addr_t *addrs, int max_pages);
1600 extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages);
1601 extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1602
1603
1604 void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
1605 void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
1606 int drm_prime_add_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t handle);
1607 int drm_prime_lookup_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf, uint32_t *handle);
1608 void drm_prime_remove_buf_handle(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf);
1609
1610 int drm_prime_add_dma_buf(struct drm_device *dev, struct drm_gem_object *obj);
1611 int drm_prime_lookup_obj(struct drm_device *dev, struct dma_buf *buf,
1612                          struct drm_gem_object **obj);
1613
1614 #if DRM_DEBUG_CODE
1615 extern int drm_vma_info(struct seq_file *m, void *data);
1616 #endif
1617
1618                                 /* Scatter Gather Support (drm_scatter.h) */
1619 extern void drm_sg_cleanup(struct drm_sg_mem * entry);
1620 extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1621                         struct drm_file *file_priv);
1622 extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
1623 extern int drm_sg_free(struct drm_device *dev, void *data,
1624                        struct drm_file *file_priv);
1625
1626                                /* ATI PCIGART support (ati_pcigart.h) */
1627 extern int drm_ati_pcigart_init(struct drm_device *dev,
1628                                 struct drm_ati_pcigart_info * gart_info);
1629 extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
1630                                    struct drm_ati_pcigart_info * gart_info);
1631
1632 extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1633                                        size_t align);
1634 extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1635 extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1636
1637                                /* sysfs support (drm_sysfs.c) */
1638 struct drm_sysfs_class;
1639 extern struct class *drm_sysfs_create(struct module *owner, char *name);
1640 extern void drm_sysfs_destroy(void);
1641 extern int drm_sysfs_device_add(struct drm_minor *minor);
1642 extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1643 extern void drm_sysfs_device_remove(struct drm_minor *minor);
1644 extern char *drm_get_connector_status_name(enum drm_connector_status status);
1645 extern int drm_sysfs_connector_add(struct drm_connector *connector);
1646 extern void drm_sysfs_connector_remove(struct drm_connector *connector);
1647
1648 /* Graphics Execution Manager library functions (drm_gem.c) */
1649 int drm_gem_init(struct drm_device *dev);
1650 void drm_gem_destroy(struct drm_device *dev);
1651 void drm_gem_object_release(struct drm_gem_object *obj);
1652 void drm_gem_object_free(struct kref *kref);
1653 struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,
1654                                             size_t size);
1655 int drm_gem_object_init(struct drm_device *dev,
1656                         struct drm_gem_object *obj, size_t size);
1657 int drm_gem_private_object_init(struct drm_device *dev,
1658                         struct drm_gem_object *obj, size_t size);
1659 void drm_gem_object_handle_free(struct drm_gem_object *obj);
1660 void drm_gem_vm_open(struct vm_area_struct *vma);
1661 void drm_gem_vm_close(struct vm_area_struct *vma);
1662 int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
1663
1664 #include <drm/drm_global.h>
1665
1666 static inline void
1667 drm_gem_object_reference(struct drm_gem_object *obj)
1668 {
1669         kref_get(&obj->refcount);
1670 }
1671
1672 static inline void
1673 drm_gem_object_unreference(struct drm_gem_object *obj)
1674 {
1675         if (obj != NULL)
1676                 kref_put(&obj->refcount, drm_gem_object_free);
1677 }
1678
1679 static inline void
1680 drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
1681 {
1682         if (obj != NULL) {
1683                 struct drm_device *dev = obj->dev;
1684                 mutex_lock(&dev->struct_mutex);
1685                 kref_put(&obj->refcount, drm_gem_object_free);
1686                 mutex_unlock(&dev->struct_mutex);
1687         }
1688 }
1689
1690 int drm_gem_handle_create(struct drm_file *file_priv,
1691                           struct drm_gem_object *obj,
1692                           u32 *handlep);
1693 int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
1694
1695 static inline void
1696 drm_gem_object_handle_reference(struct drm_gem_object *obj)
1697 {
1698         drm_gem_object_reference(obj);
1699         atomic_inc(&obj->handle_count);
1700 }
1701
1702 static inline void
1703 drm_gem_object_handle_unreference(struct drm_gem_object *obj)
1704 {
1705         if (obj == NULL)
1706                 return;
1707
1708         if (atomic_read(&obj->handle_count) == 0)
1709                 return;
1710         /*
1711          * Must bump handle count first as this may be the last
1712          * ref, in which case the object would disappear before we
1713          * checked for a name
1714          */
1715         if (atomic_dec_and_test(&obj->handle_count))
1716                 drm_gem_object_handle_free(obj);
1717         drm_gem_object_unreference(obj);
1718 }
1719
1720 static inline void
1721 drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj)
1722 {
1723         if (obj == NULL)
1724                 return;
1725
1726         if (atomic_read(&obj->handle_count) == 0)
1727                 return;
1728
1729         /*
1730         * Must bump handle count first as this may be the last
1731         * ref, in which case the object would disappear before we
1732         * checked for a name
1733         */
1734
1735         if (atomic_dec_and_test(&obj->handle_count))
1736                 drm_gem_object_handle_free(obj);
1737         drm_gem_object_unreference_unlocked(obj);
1738 }
1739
1740 void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
1741 int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
1742
1743 struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1744                                              struct drm_file *filp,
1745                                              u32 handle);
1746 int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1747                         struct drm_file *file_priv);
1748 int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1749                         struct drm_file *file_priv);
1750 int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1751                        struct drm_file *file_priv);
1752 void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
1753 void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
1754
1755 extern void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
1756 extern void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
1757 extern void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
1758
1759 static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev,
1760                                                          unsigned int token)
1761 {
1762         struct drm_map_list *_entry;
1763         list_for_each_entry(_entry, &dev->maplist, head)
1764             if (_entry->user_token == token)
1765                 return _entry->map;
1766         return NULL;
1767 }
1768
1769 static __inline__ void drm_core_dropmap(struct drm_local_map *map)
1770 {
1771 }
1772
1773 #include <drm/drm_mem_util.h>
1774
1775 extern int drm_fill_in_dev(struct drm_device *dev,
1776                            const struct pci_device_id *ent,
1777                            struct drm_driver *driver);
1778 int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type);
1779 /*@}*/
1780
1781 /* PCI section */
1782 static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
1783 {
1784         if (dev->driver->device_is_agp != NULL) {
1785                 int err = (*dev->driver->device_is_agp) (dev);
1786
1787                 if (err != 2) {
1788                         return err;
1789                 }
1790         }
1791
1792         return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1793 }
1794
1795 extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
1796 extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
1797 extern int drm_get_pci_dev(struct pci_dev *pdev,
1798                            const struct pci_device_id *ent,
1799                            struct drm_driver *driver);
1800
1801 #define DRM_PCIE_SPEED_25 1
1802 #define DRM_PCIE_SPEED_50 2
1803 #define DRM_PCIE_SPEED_80 4
1804
1805 extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
1806
1807 /* platform section */
1808 extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);
1809 extern void drm_platform_exit(struct drm_driver *driver, struct platform_device *platform_device);
1810
1811 extern int drm_get_platform_dev(struct platform_device *pdev,
1812                                 struct drm_driver *driver);
1813
1814 /* returns true if currently okay to sleep */
1815 static __inline__ bool drm_can_sleep(void)
1816 {
1817         if (in_atomic() || in_dbg_master() || irqs_disabled())
1818                 return false;
1819         return true;
1820 }
1821
1822 #endif                          /* __KERNEL__ */
1823 #endif