]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/drm/drmP.h
drm/doc: move printf helpers out of drmP.h
[karo-tx-linux.git] / include / drm / drmP.h
1 /*
2  * Internal Header for the Direct Rendering Manager
3  *
4  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6  * Copyright (c) 2009-2010, Code Aurora Forum.
7  * All rights reserved.
8  *
9  * Author: Rickard E. (Rik) Faith <faith@valinux.com>
10  * Author: Gareth Hughes <gareth@valinux.com>
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice (including the next
20  * paragraph) shall be included in all copies or substantial portions of the
21  * Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
26  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
27  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29  * OTHER DEALINGS IN THE SOFTWARE.
30  */
31
32 #ifndef _DRM_P_H_
33 #define _DRM_P_H_
34
35 #include <linux/agp_backend.h>
36 #include <linux/cdev.h>
37 #include <linux/dma-mapping.h>
38 #include <linux/file.h>
39 #include <linux/fs.h>
40 #include <linux/highmem.h>
41 #include <linux/idr.h>
42 #include <linux/init.h>
43 #include <linux/io.h>
44 #include <linux/jiffies.h>
45 #include <linux/kernel.h>
46 #include <linux/kref.h>
47 #include <linux/miscdevice.h>
48 #include <linux/mm.h>
49 #include <linux/mutex.h>
50 #include <linux/platform_device.h>
51 #include <linux/poll.h>
52 #include <linux/ratelimit.h>
53 #include <linux/sched.h>
54 #include <linux/slab.h>
55 #include <linux/types.h>
56 #include <linux/vmalloc.h>
57 #include <linux/workqueue.h>
58 #include <linux/dma-fence.h>
59 #include <linux/module.h>
60
61 #include <asm/mman.h>
62 #include <asm/pgalloc.h>
63 #include <linux/uaccess.h>
64
65 #include <uapi/drm/drm.h>
66 #include <uapi/drm/drm_mode.h>
67
68 #include <drm/drm_agpsupport.h>
69 #include <drm/drm_crtc.h>
70 #include <drm/drm_fourcc.h>
71 #include <drm/drm_global.h>
72 #include <drm/drm_hashtab.h>
73 #include <drm/drm_mm.h>
74 #include <drm/drm_os_linux.h>
75 #include <drm/drm_sarea.h>
76 #include <drm/drm_drv.h>
77 #include <drm/drm_prime.h>
78 #include <drm/drm_pci.h>
79 #include <drm/drm_file.h>
80 #include <drm/drm_debugfs.h>
81 #include <drm/drm_ioctl.h>
82 #include <drm/drm_sysfs.h>
83
84 struct module;
85
86 struct drm_device;
87 struct drm_agp_head;
88 struct drm_local_map;
89 struct drm_device_dma;
90 struct drm_gem_object;
91 struct drm_master;
92 struct drm_vblank_crtc;
93 struct drm_vma_offset_manager;
94
95 struct device_node;
96 struct videomode;
97 struct reservation_object;
98 struct dma_buf_attachment;
99
100 struct pci_dev;
101 struct pci_controller;
102
103 /*
104  * The following categories are defined:
105  *
106  * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
107  *       This is the category used by the DRM_DEBUG() macro.
108  *
109  * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
110  *         This is the category used by the DRM_DEBUG_DRIVER() macro.
111  *
112  * KMS: used in the modesetting code.
113  *      This is the category used by the DRM_DEBUG_KMS() macro.
114  *
115  * PRIME: used in the prime code.
116  *        This is the category used by the DRM_DEBUG_PRIME() macro.
117  *
118  * ATOMIC: used in the atomic code.
119  *        This is the category used by the DRM_DEBUG_ATOMIC() macro.
120  *
121  * VBL: used for verbose debug message in the vblank code
122  *        This is the category used by the DRM_DEBUG_VBL() macro.
123  *
124  * Enabling verbose debug messages is done through the drm.debug parameter,
125  * each category being enabled by a bit.
126  *
127  * drm.debug=0x1 will enable CORE messages
128  * drm.debug=0x2 will enable DRIVER messages
129  * drm.debug=0x3 will enable CORE and DRIVER messages
130  * ...
131  * drm.debug=0x3f will enable all messages
132  *
133  * An interesting feature is that it's possible to enable verbose logging at
134  * run-time by echoing the debug value in its sysfs node:
135  *   # echo 0xf > /sys/module/drm/parameters/debug
136  */
137 #define DRM_UT_NONE             0x00
138 #define DRM_UT_CORE             0x01
139 #define DRM_UT_DRIVER           0x02
140 #define DRM_UT_KMS              0x04
141 #define DRM_UT_PRIME            0x08
142 #define DRM_UT_ATOMIC           0x10
143 #define DRM_UT_VBL              0x20
144 #define DRM_UT_STATE            0x40
145
146 /***********************************************************************/
147 /** \name DRM template customization defaults */
148 /*@{*/
149
150 /***********************************************************************/
151 /** \name Macros to make printk easier */
152 /*@{*/
153
154 #define _DRM_PRINTK(once, level, fmt, ...)                              \
155         do {                                                            \
156                 printk##once(KERN_##level "[" DRM_NAME "] " fmt,        \
157                              ##__VA_ARGS__);                            \
158         } while (0)
159
160 #define DRM_INFO(fmt, ...)                                              \
161         _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
162 #define DRM_NOTE(fmt, ...)                                              \
163         _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
164 #define DRM_WARN(fmt, ...)                                              \
165         _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
166
167 #define DRM_INFO_ONCE(fmt, ...)                                         \
168         _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
169 #define DRM_NOTE_ONCE(fmt, ...)                                         \
170         _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
171 #define DRM_WARN_ONCE(fmt, ...)                                         \
172         _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
173
174 /**
175  * Error output.
176  *
177  * \param fmt printf() like format string.
178  * \param arg arguments
179  */
180 #define DRM_DEV_ERROR(dev, fmt, ...)                                    \
181         drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\
182                        fmt, ##__VA_ARGS__)
183 #define DRM_ERROR(fmt, ...)                                             \
184         drm_printk(KERN_ERR, DRM_UT_NONE, fmt,  ##__VA_ARGS__)
185
186 /**
187  * Rate limited error output.  Like DRM_ERROR() but won't flood the log.
188  *
189  * \param fmt printf() like format string.
190  * \param arg arguments
191  */
192 #define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...)                        \
193 ({                                                                      \
194         static DEFINE_RATELIMIT_STATE(_rs,                              \
195                                       DEFAULT_RATELIMIT_INTERVAL,       \
196                                       DEFAULT_RATELIMIT_BURST);         \
197                                                                         \
198         if (__ratelimit(&_rs))                                          \
199                 DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__);                 \
200 })
201 #define DRM_ERROR_RATELIMITED(fmt, ...)                                 \
202         DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
203
204 #define DRM_DEV_INFO(dev, fmt, ...)                                     \
205         drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt,  \
206                        ##__VA_ARGS__)
207
208 #define DRM_DEV_INFO_ONCE(dev, fmt, ...)                                \
209 ({                                                                      \
210         static bool __print_once __read_mostly;                         \
211         if (!__print_once) {                                            \
212                 __print_once = true;                                    \
213                 DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__);                  \
214         }                                                               \
215 })
216
217 /**
218  * Debug output.
219  *
220  * \param fmt printf() like format string.
221  * \param arg arguments
222  */
223 #define DRM_DEV_DEBUG(dev, fmt, args...)                                \
224         drm_dev_printk(dev, KERN_DEBUG, DRM_UT_CORE, __func__, "", fmt, \
225                        ##args)
226 #define DRM_DEBUG(fmt, ...)                                             \
227         drm_printk(KERN_DEBUG, DRM_UT_CORE, fmt, ##__VA_ARGS__)
228
229 #define DRM_DEV_DEBUG_DRIVER(dev, fmt, args...)                         \
230         drm_dev_printk(dev, KERN_DEBUG, DRM_UT_DRIVER, __func__, "",    \
231                        fmt, ##args)
232 #define DRM_DEBUG_DRIVER(fmt, ...)                                      \
233         drm_printk(KERN_DEBUG, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
234
235 #define DRM_DEV_DEBUG_KMS(dev, fmt, args...)                            \
236         drm_dev_printk(dev, KERN_DEBUG, DRM_UT_KMS, __func__, "", fmt,  \
237                        ##args)
238 #define DRM_DEBUG_KMS(fmt, ...)                                 \
239         drm_printk(KERN_DEBUG, DRM_UT_KMS, fmt, ##__VA_ARGS__)
240
241 #define DRM_DEV_DEBUG_PRIME(dev, fmt, args...)                          \
242         drm_dev_printk(dev, KERN_DEBUG, DRM_UT_PRIME, __func__, "",     \
243                        fmt, ##args)
244 #define DRM_DEBUG_PRIME(fmt, ...)                                       \
245         drm_printk(KERN_DEBUG, DRM_UT_PRIME, fmt, ##__VA_ARGS__)
246
247 #define DRM_DEV_DEBUG_ATOMIC(dev, fmt, args...)                         \
248         drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ATOMIC, __func__, "",    \
249                        fmt, ##args)
250 #define DRM_DEBUG_ATOMIC(fmt, ...)                                      \
251         drm_printk(KERN_DEBUG, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
252
253 #define DRM_DEV_DEBUG_VBL(dev, fmt, args...)                            \
254         drm_dev_printk(dev, KERN_DEBUG, DRM_UT_VBL, __func__, "", fmt,  \
255                        ##args)
256 #define DRM_DEBUG_VBL(fmt, ...)                                 \
257         drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__)
258
259 #define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...)     \
260 ({                                                                      \
261         static DEFINE_RATELIMIT_STATE(_rs,                              \
262                                       DEFAULT_RATELIMIT_INTERVAL,       \
263                                       DEFAULT_RATELIMIT_BURST);         \
264         if (__ratelimit(&_rs))                                          \
265                 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ ## level,       \
266                                __func__, "", fmt, ##args);              \
267 })
268
269 /**
270  * Rate limited debug output. Like DRM_DEBUG() but won't flood the log.
271  *
272  * \param fmt printf() like format string.
273  * \param arg arguments
274  */
275 #define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...)                    \
276         DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args)
277 #define DRM_DEBUG_RATELIMITED(fmt, args...)                             \
278         DRM_DEV_DEBUG_RATELIMITED(NULL, fmt, ##args)
279 #define DRM_DEV_DEBUG_DRIVER_RATELIMITED(dev, fmt, args...)             \
280         _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, DRIVER, fmt, ##args)
281 #define DRM_DEBUG_DRIVER_RATELIMITED(fmt, args...)                      \
282         DRM_DEV_DEBUG_DRIVER_RATELIMITED(NULL, fmt, ##args)
283 #define DRM_DEV_DEBUG_KMS_RATELIMITED(dev, fmt, args...)                \
284         _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, KMS, fmt, ##args)
285 #define DRM_DEBUG_KMS_RATELIMITED(fmt, args...)                         \
286         DRM_DEV_DEBUG_KMS_RATELIMITED(NULL, fmt, ##args)
287 #define DRM_DEV_DEBUG_PRIME_RATELIMITED(dev, fmt, args...)              \
288         _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, PRIME, fmt, ##args)
289 #define DRM_DEBUG_PRIME_RATELIMITED(fmt, args...)                       \
290         DRM_DEV_DEBUG_PRIME_RATELIMITED(NULL, fmt, ##args)
291
292 /* Format strings and argument splitters to simplify printing
293  * various "complex" objects
294  */
295
296 /*@}*/
297
298 /***********************************************************************/
299 /** \name Internal types and structures */
300 /*@{*/
301
302 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
303
304
305 /**
306  * DRM device structure. This structure represent a complete card that
307  * may contain multiple heads.
308  */
309 struct drm_device {
310         struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
311         int if_version;                 /**< Highest interface version set */
312
313         /** \name Lifetime Management */
314         /*@{ */
315         struct kref ref;                /**< Object ref-count */
316         struct device *dev;             /**< Device structure of bus-device */
317         struct drm_driver *driver;      /**< DRM driver managing the device */
318         void *dev_private;              /**< DRM driver private data */
319         struct drm_minor *control;              /**< Control node */
320         struct drm_minor *primary;              /**< Primary node */
321         struct drm_minor *render;               /**< Render node */
322         bool registered;
323
324         /* currently active master for this device. Protected by master_mutex */
325         struct drm_master *master;
326
327         atomic_t unplugged;                     /**< Flag whether dev is dead */
328         struct inode *anon_inode;               /**< inode for private address-space */
329         char *unique;                           /**< unique name of the device */
330         /*@} */
331
332         /** \name Locks */
333         /*@{ */
334         struct mutex struct_mutex;      /**< For others */
335         struct mutex master_mutex;      /**< For drm_minor::master and drm_file::is_master */
336         /*@} */
337
338         /** \name Usage Counters */
339         /*@{ */
340         int open_count;                 /**< Outstanding files open, protected by drm_global_mutex. */
341         spinlock_t buf_lock;            /**< For drm_device::buf_use and a few other things. */
342         int buf_use;                    /**< Buffers in use -- cannot alloc */
343         atomic_t buf_alloc;             /**< Buffer allocation in progress */
344         /*@} */
345
346         struct mutex filelist_mutex;
347         struct list_head filelist;
348
349         /** \name Memory management */
350         /*@{ */
351         struct list_head maplist;       /**< Linked list of regions */
352         struct drm_open_hash map_hash;  /**< User token hash table for maps */
353
354         /** \name Context handle management */
355         /*@{ */
356         struct list_head ctxlist;       /**< Linked list of context handles */
357         struct mutex ctxlist_mutex;     /**< For ctxlist */
358
359         struct idr ctx_idr;
360
361         struct list_head vmalist;       /**< List of vmas (for debugging) */
362
363         /*@} */
364
365         /** \name DMA support */
366         /*@{ */
367         struct drm_device_dma *dma;             /**< Optional pointer for DMA support */
368         /*@} */
369
370         /** \name Context support */
371         /*@{ */
372
373         __volatile__ long context_flag; /**< Context swapping flag */
374         int last_context;               /**< Last current context */
375         /*@} */
376
377         /** \name VBLANK IRQ support */
378         /*@{ */
379         bool irq_enabled;
380         int irq;
381
382         /*
383          * If true, vblank interrupt will be disabled immediately when the
384          * refcount drops to zero, as opposed to via the vblank disable
385          * timer.
386          * This can be set to true it the hardware has a working vblank
387          * counter and the driver uses drm_vblank_on() and drm_vblank_off()
388          * appropriately.
389          */
390         bool vblank_disable_immediate;
391
392         /* array of size num_crtcs */
393         struct drm_vblank_crtc *vblank;
394
395         spinlock_t vblank_time_lock;    /**< Protects vblank count and time updates during vblank enable/disable */
396         spinlock_t vbl_lock;
397
398         u32 max_vblank_count;           /**< size of vblank counter register */
399
400         /**
401          * List of events
402          */
403         struct list_head vblank_event_list;
404         spinlock_t event_lock;
405
406         /*@} */
407
408         struct drm_agp_head *agp;       /**< AGP data */
409
410         struct pci_dev *pdev;           /**< PCI device structure */
411 #ifdef __alpha__
412         struct pci_controller *hose;
413 #endif
414
415         struct drm_sg_mem *sg;  /**< Scatter gather memory */
416         unsigned int num_crtcs;                  /**< Number of CRTCs on this device */
417
418         struct {
419                 int context;
420                 struct drm_hw_lock *lock;
421         } sigdata;
422
423         struct drm_local_map *agp_buffer_map;
424         unsigned int agp_buffer_token;
425
426         struct drm_mode_config mode_config;     /**< Current mode config */
427
428         /** \name GEM information */
429         /*@{ */
430         struct mutex object_name_lock;
431         struct idr object_name_idr;
432         struct drm_vma_offset_manager *vma_offset_manager;
433         /*@} */
434         int switch_power_state;
435 };
436
437 /**
438  * drm_drv_uses_atomic_modeset - check if the driver implements
439  * atomic_commit()
440  * @dev: DRM device
441  *
442  * This check is useful if drivers do not have DRIVER_ATOMIC set but
443  * have atomic modesetting internally implemented.
444  */
445 static inline bool drm_drv_uses_atomic_modeset(struct drm_device *dev)
446 {
447         return dev->mode_config.funcs->atomic_commit != NULL;
448 }
449
450 #include <drm/drm_irq.h>
451
452 #define DRM_SWITCH_POWER_ON 0
453 #define DRM_SWITCH_POWER_OFF 1
454 #define DRM_SWITCH_POWER_CHANGING 2
455 #define DRM_SWITCH_POWER_DYNAMIC_OFF 3
456
457 static __inline__ int drm_core_check_feature(struct drm_device *dev,
458                                              int feature)
459 {
460         return ((dev->driver->driver_features & feature) ? 1 : 0);
461 }
462
463 static inline void drm_device_set_unplugged(struct drm_device *dev)
464 {
465         smp_wmb();
466         atomic_set(&dev->unplugged, 1);
467 }
468
469 static inline int drm_device_is_unplugged(struct drm_device *dev)
470 {
471         int ret = atomic_read(&dev->unplugged);
472         smp_rmb();
473         return ret;
474 }
475
476 /******************************************************************/
477 /** \name Internal function definitions */
478 /*@{*/
479
480                                 /* Driver support (drm_drv.h) */
481
482 /*
483  * These are exported to drivers so that they can implement fencing using
484  * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
485  */
486
487 /*@}*/
488
489 /* returns true if currently okay to sleep */
490 static __inline__ bool drm_can_sleep(void)
491 {
492         if (in_atomic() || in_dbg_master() || irqs_disabled())
493                 return false;
494         return true;
495 }
496
497 /* helper for handling conditionals in various for_each macros */
498 #define for_each_if(condition) if (!(condition)) {} else
499
500 #endif