drm: inline "struct drm_sigdata"
[firefly-linux-kernel-4.4.55.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 #include <linux/agp_backend.h>
39 #include <linux/cdev.h>
40 #include <linux/dma-mapping.h>
41 #include <linux/file.h>
42 #include <linux/fs.h>
43 #include <linux/highmem.h>
44 #include <linux/idr.h>
45 #include <linux/init.h>
46 #include <linux/io.h>
47 #include <linux/jiffies.h>
48 #include <linux/kernel.h>
49 #include <linux/kref.h>
50 #include <linux/miscdevice.h>
51 #include <linux/mm.h>
52 #include <linux/mutex.h>
53 #include <linux/pci.h>
54 #include <linux/platform_device.h>
55 #include <linux/poll.h>
56 #include <linux/ratelimit.h>
57 #include <linux/sched.h>
58 #include <linux/slab.h>
59 #include <linux/types.h>
60 #include <linux/vmalloc.h>
61 #include <linux/workqueue.h>
62
63 #include <asm/mman.h>
64 #include <asm/pgalloc.h>
65 #include <asm/uaccess.h>
66
67 #include <drm/drm.h>
68 #include <drm/drm_hashtab.h>
69 #include <drm/drm_mm.h>
70 #include <drm/drm_os_linux.h>
71 #include <drm/drm_sarea.h>
72 #include <drm/drm_vma_manager.h>
73
74 struct module;
75
76 struct drm_file;
77 struct drm_device;
78 struct drm_agp_head;
79
80 struct device_node;
81 struct videomode;
82 struct reservation_object;
83
84 /*
85  * 4 debug categories are defined:
86  *
87  * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
88  *       This is the category used by the DRM_DEBUG() macro.
89  *
90  * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
91  *         This is the category used by the DRM_DEBUG_DRIVER() macro.
92  *
93  * KMS: used in the modesetting code.
94  *      This is the category used by the DRM_DEBUG_KMS() macro.
95  *
96  * PRIME: used in the prime code.
97  *        This is the category used by the DRM_DEBUG_PRIME() macro.
98  *
99  * Enabling verbose debug messages is done through the drm.debug parameter,
100  * each category being enabled by a bit.
101  *
102  * drm.debug=0x1 will enable CORE messages
103  * drm.debug=0x2 will enable DRIVER messages
104  * drm.debug=0x3 will enable CORE and DRIVER messages
105  * ...
106  * drm.debug=0xf will enable all messages
107  *
108  * An interesting feature is that it's possible to enable verbose logging at
109  * run-time by echoing the debug value in its sysfs node:
110  *   # echo 0xf > /sys/module/drm/parameters/debug
111  */
112 #define DRM_UT_CORE             0x01
113 #define DRM_UT_DRIVER           0x02
114 #define DRM_UT_KMS              0x04
115 #define DRM_UT_PRIME            0x08
116
117 extern __printf(2, 3)
118 void drm_ut_debug_printk(const char *function_name,
119                          const char *format, ...);
120 extern __printf(2, 3)
121 int drm_err(const char *func, const char *format, ...);
122
123 /***********************************************************************/
124 /** \name DRM template customization defaults */
125 /*@{*/
126
127 /* driver capabilities and requirements mask */
128 #define DRIVER_USE_AGP     0x1
129 #define DRIVER_PCI_DMA     0x8
130 #define DRIVER_SG          0x10
131 #define DRIVER_HAVE_DMA    0x20
132 #define DRIVER_HAVE_IRQ    0x40
133 #define DRIVER_IRQ_SHARED  0x80
134 #define DRIVER_GEM         0x1000
135 #define DRIVER_MODESET     0x2000
136 #define DRIVER_PRIME       0x4000
137 #define DRIVER_RENDER      0x8000
138
139 /***********************************************************************/
140 /** \name Begin the DRM... */
141 /*@{*/
142
143 #define DRM_MAGIC_HASH_ORDER  4  /**< Size of key hash table. Must be power of 2. */
144
145 /*@}*/
146
147 /***********************************************************************/
148 /** \name Macros to make printk easier */
149 /*@{*/
150
151 /**
152  * Error output.
153  *
154  * \param fmt printf() like format string.
155  * \param arg arguments
156  */
157 #define DRM_ERROR(fmt, ...)                             \
158         drm_err(__func__, fmt, ##__VA_ARGS__)
159
160 /**
161  * Rate limited error output.  Like DRM_ERROR() but won't flood the log.
162  *
163  * \param fmt printf() like format string.
164  * \param arg arguments
165  */
166 #define DRM_ERROR_RATELIMITED(fmt, ...)                         \
167 ({                                                                      \
168         static DEFINE_RATELIMIT_STATE(_rs,                              \
169                                       DEFAULT_RATELIMIT_INTERVAL,       \
170                                       DEFAULT_RATELIMIT_BURST);         \
171                                                                         \
172         if (__ratelimit(&_rs))                                          \
173                 drm_err(__func__, fmt, ##__VA_ARGS__);                  \
174 })
175
176 #define DRM_INFO(fmt, ...)                              \
177         printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
178
179 #define DRM_INFO_ONCE(fmt, ...)                         \
180         printk_once(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__)
181
182 /**
183  * Debug output.
184  *
185  * \param fmt printf() like format string.
186  * \param arg arguments
187  */
188 #define DRM_DEBUG(fmt, args...)                                         \
189         do {                                                            \
190                 if (unlikely(drm_debug & DRM_UT_CORE))                  \
191                         drm_ut_debug_printk(__func__, fmt, ##args);     \
192         } while (0)
193
194 #define DRM_DEBUG_DRIVER(fmt, args...)                                  \
195         do {                                                            \
196                 if (unlikely(drm_debug & DRM_UT_DRIVER))                \
197                         drm_ut_debug_printk(__func__, fmt, ##args);     \
198         } while (0)
199 #define DRM_DEBUG_KMS(fmt, args...)                                     \
200         do {                                                            \
201                 if (unlikely(drm_debug & DRM_UT_KMS))                   \
202                         drm_ut_debug_printk(__func__, fmt, ##args);     \
203         } while (0)
204 #define DRM_DEBUG_PRIME(fmt, args...)                                   \
205         do {                                                            \
206                 if (unlikely(drm_debug & DRM_UT_PRIME))                 \
207                         drm_ut_debug_printk(__func__, fmt, ##args);     \
208         } while (0)
209
210 /*@}*/
211
212 /***********************************************************************/
213 /** \name Internal types and structures */
214 /*@{*/
215
216 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
217
218 /**
219  * Test that the hardware lock is held by the caller, returning otherwise.
220  *
221  * \param dev DRM device.
222  * \param filp file pointer of the caller.
223  */
224 #define LOCK_TEST_WITH_RETURN( dev, _file_priv )                                \
225 do {                                                                            \
226         if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) ||       \
227             _file_priv->master->lock.file_priv != _file_priv)   {               \
228                 DRM_ERROR( "%s called without lock held, held  %d owner %p %p\n",\
229                            __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
230                            _file_priv->master->lock.file_priv, _file_priv);     \
231                 return -EINVAL;                                                 \
232         }                                                                       \
233 } while (0)
234
235 /**
236  * Ioctl function type.
237  *
238  * \param inode device inode.
239  * \param file_priv DRM file private pointer.
240  * \param cmd command.
241  * \param arg argument.
242  */
243 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
244                         struct drm_file *file_priv);
245
246 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
247                                unsigned long arg);
248
249 #define DRM_IOCTL_NR(n)                _IOC_NR(n)
250 #define DRM_MAJOR       226
251
252 #define DRM_AUTH        0x1
253 #define DRM_MASTER      0x2
254 #define DRM_ROOT_ONLY   0x4
255 #define DRM_CONTROL_ALLOW 0x8
256 #define DRM_UNLOCKED    0x10
257 #define DRM_RENDER_ALLOW 0x20
258
259 struct drm_ioctl_desc {
260         unsigned int cmd;
261         int flags;
262         drm_ioctl_t *func;
263         unsigned int cmd_drv;
264         const char *name;
265 };
266
267 /**
268  * Creates a driver or general drm_ioctl_desc array entry for the given
269  * ioctl, for use by drm_ioctl().
270  */
271
272 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)                 \
273         [DRM_IOCTL_NR(DRM_##ioctl)] = {.cmd = DRM_##ioctl, .func = _func, .flags = _flags, .cmd_drv = DRM_IOCTL_##ioctl, .name = #ioctl}
274
275 /**
276  * DMA buffer.
277  */
278 struct drm_buf {
279         int idx;                       /**< Index into master buflist */
280         int total;                     /**< Buffer size */
281         int order;                     /**< log-base-2(total) */
282         int used;                      /**< Amount of buffer in use (for DMA) */
283         unsigned long offset;          /**< Byte offset (used internally) */
284         void *address;                 /**< Address of buffer */
285         unsigned long bus_address;     /**< Bus address of buffer */
286         struct drm_buf *next;          /**< Kernel-only: used for free list */
287         __volatile__ int waiting;      /**< On kernel DMA queue */
288         __volatile__ int pending;      /**< On hardware DMA queue */
289         struct drm_file *file_priv;    /**< Private of holding file descr */
290         int context;                   /**< Kernel queue for this buffer */
291         int while_locked;              /**< Dispatch this buffer while locked */
292         enum {
293                 DRM_LIST_NONE = 0,
294                 DRM_LIST_FREE = 1,
295                 DRM_LIST_WAIT = 2,
296                 DRM_LIST_PEND = 3,
297                 DRM_LIST_PRIO = 4,
298                 DRM_LIST_RECLAIM = 5
299         } list;                        /**< Which list we're on */
300
301         int dev_priv_size;               /**< Size of buffer private storage */
302         void *dev_private;               /**< Per-buffer private storage */
303 };
304
305 typedef struct drm_dma_handle {
306         dma_addr_t busaddr;
307         void *vaddr;
308         size_t size;
309 } drm_dma_handle_t;
310
311 /**
312  * Buffer entry.  There is one of this for each buffer size order.
313  */
314 struct drm_buf_entry {
315         int buf_size;                   /**< size */
316         int buf_count;                  /**< number of buffers */
317         struct drm_buf *buflist;                /**< buffer list */
318         int seg_count;
319         int page_order;
320         struct drm_dma_handle **seglist;
321
322         int low_mark;                   /**< Low water mark */
323         int high_mark;                  /**< High water mark */
324 };
325
326 /* Event queued up for userspace to read */
327 struct drm_pending_event {
328         struct drm_event *event;
329         struct list_head link;
330         struct drm_file *file_priv;
331         pid_t pid; /* pid of requester, no guarantee it's valid by the time
332                       we deliver the event, for tracing only */
333         void (*destroy)(struct drm_pending_event *event);
334 };
335
336 /* initial implementaton using a linked list - todo hashtab */
337 struct drm_prime_file_private {
338         struct list_head head;
339         struct mutex lock;
340 };
341
342 /** File private data */
343 struct drm_file {
344         unsigned authenticated :1;
345         /* Whether we're master for a minor. Protected by master_mutex */
346         unsigned is_master :1;
347         /* true when the client has asked us to expose stereo 3D mode flags */
348         unsigned stereo_allowed :1;
349         /*
350          * true if client understands CRTC primary planes and cursor planes
351          * in the plane list
352          */
353         unsigned universal_planes:1;
354
355         struct pid *pid;
356         kuid_t uid;
357         drm_magic_t magic;
358         struct list_head lhead;
359         struct drm_minor *minor;
360         unsigned long lock_count;
361
362         /** Mapping of mm object handles to object pointers. */
363         struct idr object_idr;
364         /** Lock for synchronization of access to object_idr. */
365         spinlock_t table_lock;
366
367         struct file *filp;
368         void *driver_priv;
369
370         struct drm_master *master; /* master this node is currently associated with
371                                       N.B. not always minor->master */
372         /**
373          * fbs - List of framebuffers associated with this file.
374          *
375          * Protected by fbs_lock. Note that the fbs list holds a reference on
376          * the fb object to prevent it from untimely disappearing.
377          */
378         struct list_head fbs;
379         struct mutex fbs_lock;
380
381         wait_queue_head_t event_wait;
382         struct list_head event_list;
383         int event_space;
384
385         struct drm_prime_file_private prime;
386 };
387
388 /**
389  * Lock data.
390  */
391 struct drm_lock_data {
392         struct drm_hw_lock *hw_lock;    /**< Hardware lock */
393         /** Private of lock holder's file (NULL=kernel) */
394         struct drm_file *file_priv;
395         wait_queue_head_t lock_queue;   /**< Queue of blocked processes */
396         unsigned long lock_time;        /**< Time of last lock in jiffies */
397         spinlock_t spinlock;
398         uint32_t kernel_waiters;
399         uint32_t user_waiters;
400         int idle_has_lock;
401 };
402
403 /**
404  * DMA data.
405  */
406 struct drm_device_dma {
407
408         struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];   /**< buffers, grouped by their size order */
409         int buf_count;                  /**< total number of buffers */
410         struct drm_buf **buflist;               /**< Vector of pointers into drm_device_dma::bufs */
411         int seg_count;
412         int page_count;                 /**< number of pages */
413         unsigned long *pagelist;        /**< page list */
414         unsigned long byte_count;
415         enum {
416                 _DRM_DMA_USE_AGP = 0x01,
417                 _DRM_DMA_USE_SG = 0x02,
418                 _DRM_DMA_USE_FB = 0x04,
419                 _DRM_DMA_USE_PCI_RO = 0x08
420         } flags;
421
422 };
423
424 /**
425  * Scatter-gather memory.
426  */
427 struct drm_sg_mem {
428         unsigned long handle;
429         void *virtual;
430         int pages;
431         struct page **pagelist;
432         dma_addr_t *busaddr;
433 };
434
435 /**
436  * Kernel side of a mapping
437  */
438 struct drm_local_map {
439         resource_size_t offset;  /**< Requested physical address (0 for SAREA)*/
440         unsigned long size;      /**< Requested physical size (bytes) */
441         enum drm_map_type type;  /**< Type of memory to map */
442         enum drm_map_flags flags;        /**< Flags */
443         void *handle;            /**< User-space: "Handle" to pass to mmap() */
444                                  /**< Kernel-space: kernel-virtual address */
445         int mtrr;                /**< MTRR slot used */
446 };
447
448 typedef struct drm_local_map drm_local_map_t;
449
450 /**
451  * Mappings list
452  */
453 struct drm_map_list {
454         struct list_head head;          /**< list head */
455         struct drm_hash_item hash;
456         struct drm_local_map *map;      /**< mapping */
457         uint64_t user_token;
458         struct drm_master *master;
459 };
460
461 /* location of GART table */
462 #define DRM_ATI_GART_MAIN 1
463 #define DRM_ATI_GART_FB   2
464
465 #define DRM_ATI_GART_PCI 1
466 #define DRM_ATI_GART_PCIE 2
467 #define DRM_ATI_GART_IGP 3
468
469 struct drm_ati_pcigart_info {
470         int gart_table_location;
471         int gart_reg_if;
472         void *addr;
473         dma_addr_t bus_addr;
474         dma_addr_t table_mask;
475         struct drm_dma_handle *table_handle;
476         struct drm_local_map mapping;
477         int table_size;
478 };
479
480 /**
481  * This structure defines the drm_mm memory object, which will be used by the
482  * DRM for its buffer objects.
483  */
484 struct drm_gem_object {
485         /** Reference count of this object */
486         struct kref refcount;
487
488         /**
489          * handle_count - gem file_priv handle count of this object
490          *
491          * Each handle also holds a reference. Note that when the handle_count
492          * drops to 0 any global names (e.g. the id in the flink namespace) will
493          * be cleared.
494          *
495          * Protected by dev->object_name_lock.
496          * */
497         unsigned handle_count;
498
499         /** Related drm device */
500         struct drm_device *dev;
501
502         /** File representing the shmem storage */
503         struct file *filp;
504
505         /* Mapping info for this object */
506         struct drm_vma_offset_node vma_node;
507
508         /**
509          * Size of the object, in bytes.  Immutable over the object's
510          * lifetime.
511          */
512         size_t size;
513
514         /**
515          * Global name for this object, starts at 1. 0 means unnamed.
516          * Access is covered by the object_name_lock in the related drm_device
517          */
518         int name;
519
520         /**
521          * Memory domains. These monitor which caches contain read/write data
522          * related to the object. When transitioning from one set of domains
523          * to another, the driver is called to ensure that caches are suitably
524          * flushed and invalidated
525          */
526         uint32_t read_domains;
527         uint32_t write_domain;
528
529         /**
530          * While validating an exec operation, the
531          * new read/write domain values are computed here.
532          * They will be transferred to the above values
533          * at the point that any cache flushing occurs
534          */
535         uint32_t pending_read_domains;
536         uint32_t pending_write_domain;
537
538         /**
539          * dma_buf - dma buf associated with this GEM object
540          *
541          * Pointer to the dma-buf associated with this gem object (either
542          * through importing or exporting). We break the resulting reference
543          * loop when the last gem handle for this object is released.
544          *
545          * Protected by obj->object_name_lock
546          */
547         struct dma_buf *dma_buf;
548
549         /**
550          * import_attach - dma buf attachment backing this object
551          *
552          * Any foreign dma_buf imported as a gem object has this set to the
553          * attachment point for the device. This is invariant over the lifetime
554          * of a gem object.
555          *
556          * The driver's ->gem_free_object callback is responsible for cleaning
557          * up the dma_buf attachment and references acquired at import time.
558          *
559          * Note that the drm gem/prime core does not depend upon drivers setting
560          * this field any more. So for drivers where this doesn't make sense
561          * (e.g. virtual devices or a displaylink behind an usb bus) they can
562          * simply leave it as NULL.
563          */
564         struct dma_buf_attachment *import_attach;
565 };
566
567 #include <drm/drm_crtc.h>
568
569 /**
570  * struct drm_master - drm master structure
571  *
572  * @refcount: Refcount for this master object.
573  * @minor: Link back to minor char device we are master for. Immutable.
574  * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex.
575  * @unique_len: Length of unique field. Protected by drm_global_mutex.
576  * @unique_size: Amount allocated. Protected by drm_global_mutex.
577  * @magiclist: Hash of used authentication tokens. Protected by struct_mutex.
578  * @magicfree: List of used authentication tokens. Protected by struct_mutex.
579  * @lock: DRI lock information.
580  * @driver_priv: Pointer to driver-private information.
581  */
582 struct drm_master {
583         struct kref refcount;
584         struct drm_minor *minor;
585         char *unique;
586         int unique_len;
587         int unique_size;
588         struct drm_open_hash magiclist;
589         struct list_head magicfree;
590         struct drm_lock_data lock;
591         void *driver_priv;
592 };
593
594 /* Size of ringbuffer for vblank timestamps. Just double-buffer
595  * in initial implementation.
596  */
597 #define DRM_VBLANKTIME_RBSIZE 2
598
599 /* Flags and return codes for get_vblank_timestamp() driver function. */
600 #define DRM_CALLED_FROM_VBLIRQ 1
601 #define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
602 #define DRM_VBLANKTIME_INVBL             (1 << 1)
603
604 /* get_scanout_position() return flags */
605 #define DRM_SCANOUTPOS_VALID        (1 << 0)
606 #define DRM_SCANOUTPOS_INVBL        (1 << 1)
607 #define DRM_SCANOUTPOS_ACCURATE     (1 << 2)
608
609 struct drm_bus {
610         int (*set_busid)(struct drm_device *dev, struct drm_master *master);
611 };
612
613 /**
614  * DRM driver structure. This structure represent the common code for
615  * a family of cards. There will one drm_device for each card present
616  * in this family
617  */
618 struct drm_driver {
619         int (*load) (struct drm_device *, unsigned long flags);
620         int (*firstopen) (struct drm_device *);
621         int (*open) (struct drm_device *, struct drm_file *);
622         void (*preclose) (struct drm_device *, struct drm_file *file_priv);
623         void (*postclose) (struct drm_device *, struct drm_file *);
624         void (*lastclose) (struct drm_device *);
625         int (*unload) (struct drm_device *);
626         int (*suspend) (struct drm_device *, pm_message_t state);
627         int (*resume) (struct drm_device *);
628         int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
629         int (*dma_quiescent) (struct drm_device *);
630         int (*context_dtor) (struct drm_device *dev, int context);
631
632         /**
633          * get_vblank_counter - get raw hardware vblank counter
634          * @dev: DRM device
635          * @crtc: counter to fetch
636          *
637          * Driver callback for fetching a raw hardware vblank counter for @crtc.
638          * If a device doesn't have a hardware counter, the driver can simply
639          * return the value of drm_vblank_count. The DRM core will account for
640          * missed vblank events while interrupts where disabled based on system
641          * timestamps.
642          *
643          * Wraparound handling and loss of events due to modesetting is dealt
644          * with in the DRM core code.
645          *
646          * RETURNS
647          * Raw vblank counter value.
648          */
649         u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
650
651         /**
652          * enable_vblank - enable vblank interrupt events
653          * @dev: DRM device
654          * @crtc: which irq to enable
655          *
656          * Enable vblank interrupts for @crtc.  If the device doesn't have
657          * a hardware vblank counter, this routine should be a no-op, since
658          * interrupts will have to stay on to keep the count accurate.
659          *
660          * RETURNS
661          * Zero on success, appropriate errno if the given @crtc's vblank
662          * interrupt cannot be enabled.
663          */
664         int (*enable_vblank) (struct drm_device *dev, int crtc);
665
666         /**
667          * disable_vblank - disable vblank interrupt events
668          * @dev: DRM device
669          * @crtc: which irq to enable
670          *
671          * Disable vblank interrupts for @crtc.  If the device doesn't have
672          * a hardware vblank counter, this routine should be a no-op, since
673          * interrupts will have to stay on to keep the count accurate.
674          */
675         void (*disable_vblank) (struct drm_device *dev, int crtc);
676
677         /**
678          * Called by \c drm_device_is_agp.  Typically used to determine if a
679          * card is really attached to AGP or not.
680          *
681          * \param dev  DRM device handle
682          *
683          * \returns
684          * One of three values is returned depending on whether or not the
685          * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
686          * (return of 1), or may or may not be AGP (return of 2).
687          */
688         int (*device_is_agp) (struct drm_device *dev);
689
690         /**
691          * Called by vblank timestamping code.
692          *
693          * Return the current display scanout position from a crtc, and an
694          * optional accurate ktime_get timestamp of when position was measured.
695          *
696          * \param dev  DRM device.
697          * \param crtc Id of the crtc to query.
698          * \param flags Flags from the caller (DRM_CALLED_FROM_VBLIRQ or 0).
699          * \param *vpos Target location for current vertical scanout position.
700          * \param *hpos Target location for current horizontal scanout position.
701          * \param *stime Target location for timestamp taken immediately before
702          *               scanout position query. Can be NULL to skip timestamp.
703          * \param *etime Target location for timestamp taken immediately after
704          *               scanout position query. Can be NULL to skip timestamp.
705          *
706          * Returns vpos as a positive number while in active scanout area.
707          * Returns vpos as a negative number inside vblank, counting the number
708          * of scanlines to go until end of vblank, e.g., -1 means "one scanline
709          * until start of active scanout / end of vblank."
710          *
711          * \return Flags, or'ed together as follows:
712          *
713          * DRM_SCANOUTPOS_VALID = Query successful.
714          * DRM_SCANOUTPOS_INVBL = Inside vblank.
715          * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
716          * this flag means that returned position may be offset by a constant
717          * but unknown small number of scanlines wrt. real scanout position.
718          *
719          */
720         int (*get_scanout_position) (struct drm_device *dev, int crtc,
721                                      unsigned int flags,
722                                      int *vpos, int *hpos, ktime_t *stime,
723                                      ktime_t *etime);
724
725         /**
726          * Called by \c drm_get_last_vbltimestamp. Should return a precise
727          * timestamp when the most recent VBLANK interval ended or will end.
728          *
729          * Specifically, the timestamp in @vblank_time should correspond as
730          * closely as possible to the time when the first video scanline of
731          * the video frame after the end of VBLANK will start scanning out,
732          * the time immediately after end of the VBLANK interval. If the
733          * @crtc is currently inside VBLANK, this will be a time in the future.
734          * If the @crtc is currently scanning out a frame, this will be the
735          * past start time of the current scanout. This is meant to adhere
736          * to the OpenML OML_sync_control extension specification.
737          *
738          * \param dev dev DRM device handle.
739          * \param crtc crtc for which timestamp should be returned.
740          * \param *max_error Maximum allowable timestamp error in nanoseconds.
741          *                   Implementation should strive to provide timestamp
742          *                   with an error of at most *max_error nanoseconds.
743          *                   Returns true upper bound on error for timestamp.
744          * \param *vblank_time Target location for returned vblank timestamp.
745          * \param flags 0 = Defaults, no special treatment needed.
746          * \param       DRM_CALLED_FROM_VBLIRQ = Function is called from vblank
747          *              irq handler. Some drivers need to apply some workarounds
748          *              for gpu-specific vblank irq quirks if flag is set.
749          *
750          * \returns
751          * Zero if timestamping isn't supported in current display mode or a
752          * negative number on failure. A positive status code on success,
753          * which describes how the vblank_time timestamp was computed.
754          */
755         int (*get_vblank_timestamp) (struct drm_device *dev, int crtc,
756                                      int *max_error,
757                                      struct timeval *vblank_time,
758                                      unsigned flags);
759
760         /* these have to be filled in */
761
762         irqreturn_t(*irq_handler) (int irq, void *arg);
763         void (*irq_preinstall) (struct drm_device *dev);
764         int (*irq_postinstall) (struct drm_device *dev);
765         void (*irq_uninstall) (struct drm_device *dev);
766
767         /* Master routines */
768         int (*master_create)(struct drm_device *dev, struct drm_master *master);
769         void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
770         /**
771          * master_set is called whenever the minor master is set.
772          * master_drop is called whenever the minor master is dropped.
773          */
774
775         int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
776                           bool from_open);
777         void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv,
778                             bool from_release);
779
780         int (*debugfs_init)(struct drm_minor *minor);
781         void (*debugfs_cleanup)(struct drm_minor *minor);
782
783         /**
784          * Driver-specific constructor for drm_gem_objects, to set up
785          * obj->driver_private.
786          *
787          * Returns 0 on success.
788          */
789         void (*gem_free_object) (struct drm_gem_object *obj);
790         int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
791         void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
792
793         /* prime: */
794         /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
795         int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
796                                 uint32_t handle, uint32_t flags, int *prime_fd);
797         /* import fd -> handle (see drm_gem_prime_fd_to_handle() helper) */
798         int (*prime_fd_to_handle)(struct drm_device *dev, struct drm_file *file_priv,
799                                 int prime_fd, uint32_t *handle);
800         /* export GEM -> dmabuf */
801         struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
802                                 struct drm_gem_object *obj, int flags);
803         /* import dmabuf -> GEM */
804         struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
805                                 struct dma_buf *dma_buf);
806         /* low-level interface used by drm_gem_prime_{import,export} */
807         int (*gem_prime_pin)(struct drm_gem_object *obj);
808         void (*gem_prime_unpin)(struct drm_gem_object *obj);
809         struct reservation_object * (*gem_prime_res_obj)(
810                                 struct drm_gem_object *obj);
811         struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj);
812         struct drm_gem_object *(*gem_prime_import_sg_table)(
813                                 struct drm_device *dev, size_t size,
814                                 struct sg_table *sgt);
815         void *(*gem_prime_vmap)(struct drm_gem_object *obj);
816         void (*gem_prime_vunmap)(struct drm_gem_object *obj, void *vaddr);
817         int (*gem_prime_mmap)(struct drm_gem_object *obj,
818                                 struct vm_area_struct *vma);
819
820         /* vga arb irq handler */
821         void (*vgaarb_irq)(struct drm_device *dev, bool state);
822
823         /* dumb alloc support */
824         int (*dumb_create)(struct drm_file *file_priv,
825                            struct drm_device *dev,
826                            struct drm_mode_create_dumb *args);
827         int (*dumb_map_offset)(struct drm_file *file_priv,
828                                struct drm_device *dev, uint32_t handle,
829                                uint64_t *offset);
830         int (*dumb_destroy)(struct drm_file *file_priv,
831                             struct drm_device *dev,
832                             uint32_t handle);
833
834         /* Driver private ops for this object */
835         const struct vm_operations_struct *gem_vm_ops;
836
837         int major;
838         int minor;
839         int patchlevel;
840         char *name;
841         char *desc;
842         char *date;
843
844         u32 driver_features;
845         int dev_priv_size;
846         const struct drm_ioctl_desc *ioctls;
847         int num_ioctls;
848         const struct file_operations *fops;
849         struct drm_bus *bus;
850
851         /* List of devices hanging off this driver with stealth attach. */
852         struct list_head legacy_dev_list;
853 };
854
855 enum drm_minor_type {
856         DRM_MINOR_LEGACY,
857         DRM_MINOR_CONTROL,
858         DRM_MINOR_RENDER,
859         DRM_MINOR_CNT,
860 };
861
862 /**
863  * Info file list entry. This structure represents a debugfs or proc file to
864  * be created by the drm core
865  */
866 struct drm_info_list {
867         const char *name; /** file name */
868         int (*show)(struct seq_file*, void*); /** show callback */
869         u32 driver_features; /**< Required driver features for this entry */
870         void *data;
871 };
872
873 /**
874  * debugfs node structure. This structure represents a debugfs file.
875  */
876 struct drm_info_node {
877         struct list_head list;
878         struct drm_minor *minor;
879         const struct drm_info_list *info_ent;
880         struct dentry *dent;
881 };
882
883 /**
884  * DRM minor structure. This structure represents a drm minor number.
885  */
886 struct drm_minor {
887         int index;                      /**< Minor device number */
888         int type;                       /**< Control or render */
889         struct device *kdev;            /**< Linux device */
890         struct drm_device *dev;
891
892         struct dentry *debugfs_root;
893
894         struct list_head debugfs_list;
895         struct mutex debugfs_lock; /* Protects debugfs_list. */
896
897         /* currently active master for this node. Protected by master_mutex */
898         struct drm_master *master;
899         struct drm_mode_group mode_group;
900 };
901
902
903 struct drm_pending_vblank_event {
904         struct drm_pending_event base;
905         int pipe;
906         struct drm_event_vblank event;
907 };
908
909 struct drm_vblank_crtc {
910         struct drm_device *dev;         /* pointer to the drm_device */
911         wait_queue_head_t queue;        /**< VBLANK wait queue */
912         struct timeval time[DRM_VBLANKTIME_RBSIZE];     /**< timestamp of current count */
913         struct timer_list disable_timer;                /* delayed disable timer */
914         atomic_t count;                 /**< number of VBLANK interrupts */
915         atomic_t refcount;              /* number of users of vblank interruptsper crtc */
916         u32 last;                       /* protected by dev->vbl_lock, used */
917                                         /* for wraparound handling */
918         u32 last_wait;                  /* Last vblank seqno waited per CRTC */
919         unsigned int inmodeset;         /* Display driver is setting mode */
920         int crtc;                       /* crtc index */
921         bool enabled;                   /* so we don't call enable more than
922                                            once per disable */
923 };
924
925 /**
926  * DRM device structure. This structure represent a complete card that
927  * may contain multiple heads.
928  */
929 struct drm_device {
930         struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
931         int if_version;                 /**< Highest interface version set */
932
933         /** \name Lifetime Management */
934         /*@{ */
935         struct kref ref;                /**< Object ref-count */
936         struct device *dev;             /**< Device structure of bus-device */
937         struct drm_driver *driver;      /**< DRM driver managing the device */
938         void *dev_private;              /**< DRM driver private data */
939         struct drm_minor *control;              /**< Control node */
940         struct drm_minor *primary;              /**< Primary node */
941         struct drm_minor *render;               /**< Render node */
942         atomic_t unplugged;                     /**< Flag whether dev is dead */
943         struct inode *anon_inode;               /**< inode for private address-space */
944         char *unique;                           /**< unique name of the device */
945         /*@} */
946
947         /** \name Locks */
948         /*@{ */
949         struct mutex struct_mutex;      /**< For others */
950         struct mutex master_mutex;      /**< For drm_minor::master and drm_file::is_master */
951         /*@} */
952
953         /** \name Usage Counters */
954         /*@{ */
955         int open_count;                 /**< Outstanding files open, protected by drm_global_mutex. */
956         spinlock_t buf_lock;            /**< For drm_device::buf_use and a few other things. */
957         int buf_use;                    /**< Buffers in use -- cannot alloc */
958         atomic_t buf_alloc;             /**< Buffer allocation in progress */
959         /*@} */
960
961         struct list_head filelist;
962
963         /** \name Memory management */
964         /*@{ */
965         struct list_head maplist;       /**< Linked list of regions */
966         struct drm_open_hash map_hash;  /**< User token hash table for maps */
967
968         /** \name Context handle management */
969         /*@{ */
970         struct list_head ctxlist;       /**< Linked list of context handles */
971         struct mutex ctxlist_mutex;     /**< For ctxlist */
972
973         struct idr ctx_idr;
974
975         struct list_head vmalist;       /**< List of vmas (for debugging) */
976
977         /*@} */
978
979         /** \name DMA support */
980         /*@{ */
981         struct drm_device_dma *dma;             /**< Optional pointer for DMA support */
982         /*@} */
983
984         /** \name Context support */
985         /*@{ */
986         bool irq_enabled;               /**< True if irq handler is enabled */
987         int irq;
988
989         __volatile__ long context_flag; /**< Context swapping flag */
990         int last_context;               /**< Last current context */
991         /*@} */
992
993         /** \name VBLANK IRQ support */
994         /*@{ */
995
996         /*
997          * At load time, disabling the vblank interrupt won't be allowed since
998          * old clients may not call the modeset ioctl and therefore misbehave.
999          * Once the modeset ioctl *has* been called though, we can safely
1000          * disable them when unused.
1001          */
1002         bool vblank_disable_allowed;
1003
1004         /* array of size num_crtcs */
1005         struct drm_vblank_crtc *vblank;
1006
1007         spinlock_t vblank_time_lock;    /**< Protects vblank count and time updates during vblank enable/disable */
1008         spinlock_t vbl_lock;
1009
1010         u32 max_vblank_count;           /**< size of vblank counter register */
1011
1012         /**
1013          * List of events
1014          */
1015         struct list_head vblank_event_list;
1016         spinlock_t event_lock;
1017
1018         /*@} */
1019
1020         struct drm_agp_head *agp;       /**< AGP data */
1021
1022         struct pci_dev *pdev;           /**< PCI device structure */
1023 #ifdef __alpha__
1024         struct pci_controller *hose;
1025 #endif
1026
1027         struct platform_device *platformdev; /**< Platform device struture */
1028         struct usb_device *usbdev;
1029
1030         struct drm_sg_mem *sg;  /**< Scatter gather memory */
1031         unsigned int num_crtcs;                  /**< Number of CRTCs on this device */
1032         sigset_t sigmask;
1033
1034         struct {
1035                 int context;
1036                 struct drm_hw_lock *lock;
1037         } sigdata;
1038
1039         struct drm_local_map *agp_buffer_map;
1040         unsigned int agp_buffer_token;
1041
1042         struct drm_mode_config mode_config;     /**< Current mode config */
1043
1044         /** \name GEM information */
1045         /*@{ */
1046         struct mutex object_name_lock;
1047         struct idr object_name_idr;
1048         struct drm_vma_offset_manager *vma_offset_manager;
1049         /*@} */
1050         int switch_power_state;
1051 };
1052
1053 #define DRM_SWITCH_POWER_ON 0
1054 #define DRM_SWITCH_POWER_OFF 1
1055 #define DRM_SWITCH_POWER_CHANGING 2
1056 #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
1057
1058 static __inline__ int drm_core_check_feature(struct drm_device *dev,
1059                                              int feature)
1060 {
1061         return ((dev->driver->driver_features & feature) ? 1 : 0);
1062 }
1063
1064 static inline void drm_device_set_unplugged(struct drm_device *dev)
1065 {
1066         smp_wmb();
1067         atomic_set(&dev->unplugged, 1);
1068 }
1069
1070 static inline int drm_device_is_unplugged(struct drm_device *dev)
1071 {
1072         int ret = atomic_read(&dev->unplugged);
1073         smp_rmb();
1074         return ret;
1075 }
1076
1077 static inline bool drm_is_render_client(const struct drm_file *file_priv)
1078 {
1079         return file_priv->minor->type == DRM_MINOR_RENDER;
1080 }
1081
1082 static inline bool drm_is_control_client(const struct drm_file *file_priv)
1083 {
1084         return file_priv->minor->type == DRM_MINOR_CONTROL;
1085 }
1086
1087 static inline bool drm_is_primary_client(const struct drm_file *file_priv)
1088 {
1089         return file_priv->minor->type == DRM_MINOR_LEGACY;
1090 }
1091
1092 /******************************************************************/
1093 /** \name Internal function definitions */
1094 /*@{*/
1095
1096                                 /* Driver support (drm_drv.h) */
1097 extern long drm_ioctl(struct file *filp,
1098                       unsigned int cmd, unsigned long arg);
1099 extern long drm_compat_ioctl(struct file *filp,
1100                              unsigned int cmd, unsigned long arg);
1101 extern int drm_lastclose(struct drm_device *dev);
1102 extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
1103
1104                                 /* Device support (drm_fops.h) */
1105 extern struct mutex drm_global_mutex;
1106 extern int drm_open(struct inode *inode, struct file *filp);
1107 extern ssize_t drm_read(struct file *filp, char __user *buffer,
1108                         size_t count, loff_t *offset);
1109 extern int drm_release(struct inode *inode, struct file *filp);
1110
1111                                 /* Mapping support (drm_vm.h) */
1112 extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
1113 extern int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma);
1114 extern void drm_vm_open_locked(struct drm_device *dev, struct vm_area_struct *vma);
1115 extern void drm_vm_close_locked(struct drm_device *dev, struct vm_area_struct *vma);
1116 extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
1117
1118                                 /* Misc. IOCTL support (drm_ioctl.h) */
1119 extern int drm_irq_by_busid(struct drm_device *dev, void *data,
1120                             struct drm_file *file_priv);
1121 extern int drm_getunique(struct drm_device *dev, void *data,
1122                          struct drm_file *file_priv);
1123 extern int drm_setunique(struct drm_device *dev, void *data,
1124                          struct drm_file *file_priv);
1125 extern int drm_getmap(struct drm_device *dev, void *data,
1126                       struct drm_file *file_priv);
1127 extern int drm_getclient(struct drm_device *dev, void *data,
1128                          struct drm_file *file_priv);
1129 extern int drm_getstats(struct drm_device *dev, void *data,
1130                         struct drm_file *file_priv);
1131 extern int drm_getcap(struct drm_device *dev, void *data,
1132                       struct drm_file *file_priv);
1133 extern int drm_setclientcap(struct drm_device *dev, void *data,
1134                             struct drm_file *file_priv);
1135 extern int drm_setversion(struct drm_device *dev, void *data,
1136                           struct drm_file *file_priv);
1137 extern int drm_noop(struct drm_device *dev, void *data,
1138                     struct drm_file *file_priv);
1139
1140                                 /* Authentication IOCTL support (drm_auth.h) */
1141 extern int drm_getmagic(struct drm_device *dev, void *data,
1142                         struct drm_file *file_priv);
1143 extern int drm_authmagic(struct drm_device *dev, void *data,
1144                          struct drm_file *file_priv);
1145 extern int drm_remove_magic(struct drm_master *master, drm_magic_t magic);
1146
1147 /* Cache management (drm_cache.c) */
1148 void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
1149 void drm_clflush_sg(struct sg_table *st);
1150 void drm_clflush_virt_range(void *addr, unsigned long length);
1151
1152                                 /* Locking IOCTL support (drm_lock.h) */
1153 extern int drm_lock(struct drm_device *dev, void *data,
1154                     struct drm_file *file_priv);
1155 extern int drm_unlock(struct drm_device *dev, void *data,
1156                       struct drm_file *file_priv);
1157 extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
1158 extern void drm_idlelock_take(struct drm_lock_data *lock_data);
1159 extern void drm_idlelock_release(struct drm_lock_data *lock_data);
1160
1161 /*
1162  * These are exported to drivers so that they can implement fencing using
1163  * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1164  */
1165
1166 extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
1167
1168                                 /* DMA support (drm_dma.h) */
1169 extern int drm_legacy_dma_setup(struct drm_device *dev);
1170 extern void drm_legacy_dma_takedown(struct drm_device *dev);
1171 extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
1172 extern void drm_core_reclaim_buffers(struct drm_device *dev,
1173                                      struct drm_file *filp);
1174
1175                                 /* IRQ support (drm_irq.h) */
1176 extern int drm_control(struct drm_device *dev, void *data,
1177                        struct drm_file *file_priv);
1178 extern int drm_irq_install(struct drm_device *dev, int irq);
1179 extern int drm_irq_uninstall(struct drm_device *dev);
1180
1181 extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1182 extern int drm_wait_vblank(struct drm_device *dev, void *data,
1183                            struct drm_file *filp);
1184 extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1185 extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
1186                                      struct timeval *vblanktime);
1187 extern void drm_send_vblank_event(struct drm_device *dev, int crtc,
1188                                      struct drm_pending_vblank_event *e);
1189 extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
1190 extern int drm_vblank_get(struct drm_device *dev, int crtc);
1191 extern void drm_vblank_put(struct drm_device *dev, int crtc);
1192 extern int drm_crtc_vblank_get(struct drm_crtc *crtc);
1193 extern void drm_crtc_vblank_put(struct drm_crtc *crtc);
1194 extern void drm_wait_one_vblank(struct drm_device *dev, int crtc);
1195 extern void drm_crtc_wait_one_vblank(struct drm_crtc *crtc);
1196 extern void drm_vblank_off(struct drm_device *dev, int crtc);
1197 extern void drm_vblank_on(struct drm_device *dev, int crtc);
1198 extern void drm_crtc_vblank_off(struct drm_crtc *crtc);
1199 extern void drm_crtc_vblank_on(struct drm_crtc *crtc);
1200 extern void drm_vblank_cleanup(struct drm_device *dev);
1201
1202 extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
1203                                      struct timeval *tvblank, unsigned flags);
1204 extern int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
1205                                                  int crtc, int *max_error,
1206                                                  struct timeval *vblank_time,
1207                                                  unsigned flags,
1208                                                  const struct drm_crtc *refcrtc,
1209                                                  const struct drm_display_mode *mode);
1210 extern void drm_calc_timestamping_constants(struct drm_crtc *crtc,
1211                                             const struct drm_display_mode *mode);
1212
1213 /**
1214  * drm_crtc_vblank_waitqueue - get vblank waitqueue for the CRTC
1215  * @crtc: which CRTC's vblank waitqueue to retrieve
1216  *
1217  * This function returns a pointer to the vblank waitqueue for the CRTC.
1218  * Drivers can use this to implement vblank waits using wait_event() & co.
1219  */
1220 static inline wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc)
1221 {
1222         return &crtc->dev->vblank[drm_crtc_index(crtc)].queue;
1223 }
1224
1225 /* Modesetting support */
1226 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
1227 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
1228 extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1229                            struct drm_file *file_priv);
1230
1231                                 /* AGP/GART support (drm_agpsupport.h) */
1232
1233 #include <drm/drm_agpsupport.h>
1234
1235                                 /* Stub support (drm_stub.h) */
1236 extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1237                                struct drm_file *file_priv);
1238 extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1239                                 struct drm_file *file_priv);
1240 struct drm_master *drm_master_create(struct drm_minor *minor);
1241 extern struct drm_master *drm_master_get(struct drm_master *master);
1242 extern void drm_master_put(struct drm_master **master);
1243
1244 extern void drm_put_dev(struct drm_device *dev);
1245 extern void drm_unplug_dev(struct drm_device *dev);
1246 extern unsigned int drm_debug;
1247
1248 extern unsigned int drm_vblank_offdelay;
1249 extern unsigned int drm_timestamp_precision;
1250 extern unsigned int drm_timestamp_monotonic;
1251
1252 extern struct class *drm_class;
1253
1254                                 /* Debugfs support */
1255 #if defined(CONFIG_DEBUG_FS)
1256 extern int drm_debugfs_init(struct drm_minor *minor, int minor_id,
1257                             struct dentry *root);
1258 extern int drm_debugfs_create_files(const struct drm_info_list *files,
1259                                     int count, struct dentry *root,
1260                                     struct drm_minor *minor);
1261 extern int drm_debugfs_remove_files(const struct drm_info_list *files,
1262                                     int count, struct drm_minor *minor);
1263 extern int drm_debugfs_cleanup(struct drm_minor *minor);
1264 extern int drm_debugfs_connector_add(struct drm_connector *connector);
1265 extern void drm_debugfs_connector_remove(struct drm_connector *connector);
1266 #else
1267 static inline int drm_debugfs_init(struct drm_minor *minor, int minor_id,
1268                                    struct dentry *root)
1269 {
1270         return 0;
1271 }
1272
1273 static inline int drm_debugfs_create_files(const struct drm_info_list *files,
1274                                            int count, struct dentry *root,
1275                                            struct drm_minor *minor)
1276 {
1277         return 0;
1278 }
1279
1280 static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
1281                                            int count, struct drm_minor *minor)
1282 {
1283         return 0;
1284 }
1285
1286 static inline int drm_debugfs_cleanup(struct drm_minor *minor)
1287 {
1288         return 0;
1289 }
1290
1291 static inline int drm_debugfs_connector_add(struct drm_connector *connector)
1292 {
1293         return 0;
1294 }
1295 static inline void drm_debugfs_connector_remove(struct drm_connector *connector)
1296 {
1297 }
1298
1299 #endif
1300
1301                                 /* Info file support */
1302 extern int drm_name_info(struct seq_file *m, void *data);
1303 extern int drm_vm_info(struct seq_file *m, void *data);
1304 extern int drm_bufs_info(struct seq_file *m, void *data);
1305 extern int drm_vblank_info(struct seq_file *m, void *data);
1306 extern int drm_clients_info(struct seq_file *m, void* data);
1307 extern int drm_gem_name_info(struct seq_file *m, void *data);
1308
1309
1310 extern struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
1311                 struct drm_gem_object *obj, int flags);
1312 extern int drm_gem_prime_handle_to_fd(struct drm_device *dev,
1313                 struct drm_file *file_priv, uint32_t handle, uint32_t flags,
1314                 int *prime_fd);
1315 extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
1316                 struct dma_buf *dma_buf);
1317 extern int drm_gem_prime_fd_to_handle(struct drm_device *dev,
1318                 struct drm_file *file_priv, int prime_fd, uint32_t *handle);
1319 extern void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
1320
1321 extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
1322                                         struct drm_file *file_priv);
1323 extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
1324                                         struct drm_file *file_priv);
1325
1326 extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
1327                                             dma_addr_t *addrs, int max_pages);
1328 extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages);
1329 extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1330
1331 int drm_gem_dumb_destroy(struct drm_file *file,
1332                          struct drm_device *dev,
1333                          uint32_t handle);
1334
1335 void drm_prime_init_file_private(struct drm_prime_file_private *prime_fpriv);
1336 void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv);
1337 void drm_prime_remove_buf_handle_locked(struct drm_prime_file_private *prime_fpriv, struct dma_buf *dma_buf);
1338
1339 extern int drm_vma_info(struct seq_file *m, void *data);
1340
1341                                 /* Scatter Gather Support (drm_scatter.h) */
1342 extern void drm_legacy_sg_cleanup(struct drm_device *dev);
1343 extern int drm_sg_alloc(struct drm_device *dev, void *data,
1344                         struct drm_file *file_priv);
1345 extern int drm_sg_free(struct drm_device *dev, void *data,
1346                        struct drm_file *file_priv);
1347
1348                                /* ATI PCIGART support (ati_pcigart.h) */
1349 extern int drm_ati_pcigart_init(struct drm_device *dev,
1350                                 struct drm_ati_pcigart_info * gart_info);
1351 extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
1352                                    struct drm_ati_pcigart_info * gart_info);
1353
1354 extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1355                                        size_t align);
1356 extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1357 extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1358 extern int drm_pci_set_unique(struct drm_device *dev,
1359                               struct drm_master *master,
1360                               struct drm_unique *u);
1361
1362                                 /* Legacy Support */
1363
1364 int drm_legacy_addmap(struct drm_device *d, resource_size_t offset,
1365                       unsigned int size, enum drm_map_type type,
1366                       enum drm_map_flags flags, struct drm_local_map **map_p);
1367 int drm_legacy_rmmap(struct drm_device *d, struct drm_local_map *map);
1368 int drm_legacy_rmmap_locked(struct drm_device *d, struct drm_local_map *map);
1369 struct drm_local_map *drm_legacy_getsarea(struct drm_device *dev);
1370
1371 int drm_legacy_addbufs_agp(struct drm_device *d, struct drm_buf_desc *req);
1372 int drm_legacy_addbufs_pci(struct drm_device *d, struct drm_buf_desc *req);
1373
1374 void drm_legacy_vma_flush(struct drm_device *d);
1375
1376                                /* sysfs support (drm_sysfs.c) */
1377 struct drm_sysfs_class;
1378 extern struct class *drm_sysfs_create(struct module *owner, char *name);
1379 extern void drm_sysfs_destroy(void);
1380 extern struct device *drm_sysfs_minor_alloc(struct drm_minor *minor);
1381 extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1382 extern int drm_sysfs_connector_add(struct drm_connector *connector);
1383 extern void drm_sysfs_connector_remove(struct drm_connector *connector);
1384
1385 /* Graphics Execution Manager library functions (drm_gem.c) */
1386 int drm_gem_init(struct drm_device *dev);
1387 void drm_gem_destroy(struct drm_device *dev);
1388 void drm_gem_object_release(struct drm_gem_object *obj);
1389 void drm_gem_object_free(struct kref *kref);
1390 int drm_gem_object_init(struct drm_device *dev,
1391                         struct drm_gem_object *obj, size_t size);
1392 void drm_gem_private_object_init(struct drm_device *dev,
1393                                  struct drm_gem_object *obj, size_t size);
1394 void drm_gem_vm_open(struct vm_area_struct *vma);
1395 void drm_gem_vm_close(struct vm_area_struct *vma);
1396 int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
1397                      struct vm_area_struct *vma);
1398 int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
1399
1400 #include <drm/drm_global.h>
1401
1402 static inline void
1403 drm_gem_object_reference(struct drm_gem_object *obj)
1404 {
1405         kref_get(&obj->refcount);
1406 }
1407
1408 static inline void
1409 drm_gem_object_unreference(struct drm_gem_object *obj)
1410 {
1411         if (obj != NULL)
1412                 kref_put(&obj->refcount, drm_gem_object_free);
1413 }
1414
1415 static inline void
1416 drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
1417 {
1418         if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) {
1419                 struct drm_device *dev = obj->dev;
1420
1421                 mutex_lock(&dev->struct_mutex);
1422                 if (likely(atomic_dec_and_test(&obj->refcount.refcount)))
1423                         drm_gem_object_free(&obj->refcount);
1424                 mutex_unlock(&dev->struct_mutex);
1425         }
1426 }
1427
1428 int drm_gem_handle_create_tail(struct drm_file *file_priv,
1429                                struct drm_gem_object *obj,
1430                                u32 *handlep);
1431 int drm_gem_handle_create(struct drm_file *file_priv,
1432                           struct drm_gem_object *obj,
1433                           u32 *handlep);
1434 int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
1435
1436
1437 void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
1438 int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
1439 int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size);
1440
1441 struct page **drm_gem_get_pages(struct drm_gem_object *obj);
1442 void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages,
1443                 bool dirty, bool accessed);
1444
1445 struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1446                                              struct drm_file *filp,
1447                                              u32 handle);
1448 int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1449                         struct drm_file *file_priv);
1450 int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1451                         struct drm_file *file_priv);
1452 int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1453                        struct drm_file *file_priv);
1454 void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
1455 void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
1456
1457 extern void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev);
1458 extern void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
1459 extern void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
1460
1461 static __inline__ struct drm_local_map *drm_core_findmap(struct drm_device *dev,
1462                                                          unsigned int token)
1463 {
1464         struct drm_map_list *_entry;
1465         list_for_each_entry(_entry, &dev->maplist, head)
1466             if (_entry->user_token == token)
1467                 return _entry->map;
1468         return NULL;
1469 }
1470
1471 static __inline__ void drm_core_dropmap(struct drm_local_map *map)
1472 {
1473 }
1474
1475 #include <drm/drm_mem_util.h>
1476
1477 struct drm_device *drm_dev_alloc(struct drm_driver *driver,
1478                                  struct device *parent);
1479 void drm_dev_ref(struct drm_device *dev);
1480 void drm_dev_unref(struct drm_device *dev);
1481 int drm_dev_register(struct drm_device *dev, unsigned long flags);
1482 void drm_dev_unregister(struct drm_device *dev);
1483 int drm_dev_set_unique(struct drm_device *dev, const char *fmt, ...);
1484
1485 struct drm_minor *drm_minor_acquire(unsigned int minor_id);
1486 void drm_minor_release(struct drm_minor *minor);
1487
1488 /*@}*/
1489
1490 /* PCI section */
1491 static __inline__ int drm_pci_device_is_agp(struct drm_device *dev)
1492 {
1493         if (dev->driver->device_is_agp != NULL) {
1494                 int err = (*dev->driver->device_is_agp) (dev);
1495
1496                 if (err != 2) {
1497                         return err;
1498                 }
1499         }
1500
1501         return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1502 }
1503 void drm_pci_agp_destroy(struct drm_device *dev);
1504
1505 extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
1506 extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
1507 extern int drm_get_pci_dev(struct pci_dev *pdev,
1508                            const struct pci_device_id *ent,
1509                            struct drm_driver *driver);
1510
1511 #define DRM_PCIE_SPEED_25 1
1512 #define DRM_PCIE_SPEED_50 2
1513 #define DRM_PCIE_SPEED_80 4
1514
1515 extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
1516
1517 /* platform section */
1518 extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);
1519
1520 /* returns true if currently okay to sleep */
1521 static __inline__ bool drm_can_sleep(void)
1522 {
1523         if (in_atomic() || in_dbg_master() || irqs_disabled())
1524                 return false;
1525         return true;
1526 }
1527
1528 #endif