blob: 3031c256105ef1f92c78ad230ba9b816eaf69567 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
David Herrmannd7d2c482014-08-29 12:12:40 +02002 * Internal Header for the Direct Rendering Manager
3 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
Jordan Crousedcdb1672010-05-27 13:40:25 -06006 * Copyright (c) 2009-2010, Code Aurora Forum.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * All rights reserved.
8 *
David Herrmannd7d2c482014-08-29 12:12:40 +02009 * Author: Rickard E. (Rik) Faith <faith@valinux.com>
10 * Author: Gareth Hughes <gareth@valinux.com>
11 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * 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
David Herrmann96993902014-08-29 12:12:37 +020035#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/kernel.h>
David Herrmann099d1c22014-01-29 10:21:36 +010046#include <linux/kref.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/miscdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/mm.h>
Dave Airlie30e2fb12006-02-02 19:37:46 +110049#include <linux/mutex.h>
David Herrmann96993902014-08-29 12:12:37 +020050#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/poll.h>
David Herrmann96993902014-08-29 12:12:37 +020052#include <linux/ratelimit.h>
53#include <linux/sched.h>
54#include <linux/slab.h>
55#include <linux/types.h>
David Herrmannd6db6562014-08-29 12:12:35 +020056#include <linux/vmalloc.h>
David Herrmann96993902014-08-29 12:12:37 +020057#include <linux/workqueue.h>
Chris Wilsonf54d1862016-10-25 13:00:45 +010058#include <linux/dma-fence.h>
Daniel Vetterc6bb9ba2017-03-08 15:12:35 +010059#include <linux/module.h>
David Herrmann96993902014-08-29 12:12:37 +020060
61#include <asm/mman.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#include <asm/pgalloc.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080063#include <linux/uaccess.h>
David Herrmann96993902014-08-29 12:12:37 +020064
David Herrmannd7d2c482014-08-29 12:12:40 +020065#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>
Laurent Pinchartae4df112016-06-09 12:54:08 +030070#include <drm/drm_fourcc.h>
David Herrmannd7d2c482014-08-29 12:12:40 +020071#include <drm/drm_global.h>
David Herrmann96993902014-08-29 12:12:37 +020072#include <drm/drm_hashtab.h>
73#include <drm/drm_mm.h>
74#include <drm/drm_os_linux.h>
David Howells19218e42012-10-02 18:01:03 +010075#include <drm/drm_sarea.h>
Daniel Vetter85e634b2016-11-14 12:58:19 +010076#include <drm/drm_drv.h>
Daniel Vetterc6bb9ba2017-03-08 15:12:35 +010077#include <drm/drm_prime.h>
Daniel Vetter23ef59e2017-03-08 15:12:37 +010078#include <drm/drm_pci.h>
Daniel Vettera8f8b1d2017-03-08 15:12:42 +010079#include <drm/drm_file.h>
Daniel Vetter48344422017-03-22 21:53:36 +010080#include <drm/drm_debugfs.h>
Daniel Vetter7cfdf712017-03-22 21:54:47 +010081#include <drm/drm_ioctl.h>
Daniel Vettere2271702017-04-04 11:52:55 +020082#include <drm/drm_sysfs.h>
Daniel Vetter3ed43512017-05-31 11:21:46 +020083#include <drm/drm_vblank.h>
84#include <drm/drm_irq.h>
Daniel Vettere4672e52017-08-02 13:56:01 +020085#include <drm/drm_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Paul Gortmakerde477252011-05-26 13:46:22 -040087struct module;
88
Steffen Trumtraredb37a92012-10-28 18:28:06 +010089struct device_node;
Steffen Trumtrarebc64e42012-11-14 11:22:52 +010090struct videomode;
Maarten Lankhorst3aac4502014-07-01 12:57:26 +020091struct reservation_object;
Maarten Lankhorstb5e9c1a2014-01-09 11:03:14 +010092struct dma_buf_attachment;
Steffen Trumtrarebc64e42012-11-14 11:22:52 +010093
Daniel Vetter23ef59e2017-03-08 15:12:37 +010094struct pci_dev;
95struct pci_controller;
96
Lespiau, Damien1414b762014-03-24 15:53:08 +000097/*
Robert Foss346fea62016-04-14 10:34:16 -040098 * The following categories are defined:
Lespiau, Damien1414b762014-03-24 15:53:08 +000099 *
100 * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
101 * This is the category used by the DRM_DEBUG() macro.
102 *
103 * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
104 * This is the category used by the DRM_DEBUG_DRIVER() macro.
105 *
106 * KMS: used in the modesetting code.
107 * This is the category used by the DRM_DEBUG_KMS() macro.
108 *
109 * PRIME: used in the prime code.
110 * This is the category used by the DRM_DEBUG_PRIME() macro.
111 *
Daniel Vetter17a38d92015-02-22 12:24:16 +0100112 * ATOMIC: used in the atomic code.
113 * This is the category used by the DRM_DEBUG_ATOMIC() macro.
114 *
Ville Syrjälä235fabe2015-10-09 22:57:37 +0300115 * VBL: used for verbose debug message in the vblank code
116 * This is the category used by the DRM_DEBUG_VBL() macro.
117 *
Lespiau, Damien1414b762014-03-24 15:53:08 +0000118 * Enabling verbose debug messages is done through the drm.debug parameter,
119 * each category being enabled by a bit.
120 *
121 * drm.debug=0x1 will enable CORE messages
122 * drm.debug=0x2 will enable DRIVER messages
123 * drm.debug=0x3 will enable CORE and DRIVER messages
124 * ...
Ville Syrjälä235fabe2015-10-09 22:57:37 +0300125 * drm.debug=0x3f will enable all messages
Lespiau, Damien1414b762014-03-24 15:53:08 +0000126 *
127 * An interesting feature is that it's possible to enable verbose logging at
128 * run-time by echoing the debug value in its sysfs node:
129 * # echo 0xf > /sys/module/drm/parameters/debug
130 */
Sean Paulc4e68a52016-08-15 16:18:04 -0700131#define DRM_UT_NONE 0x00
yakui_zhao4fefcb22009-06-02 14:09:47 +0800132#define DRM_UT_CORE 0x01
133#define DRM_UT_DRIVER 0x02
134#define DRM_UT_KMS 0x04
Dave Airlie32488772011-11-25 15:21:02 +0000135#define DRM_UT_PRIME 0x08
Daniel Vetter17a38d92015-02-22 12:24:16 +0100136#define DRM_UT_ATOMIC 0x10
Ville Syrjälä235fabe2015-10-09 22:57:37 +0300137#define DRM_UT_VBL 0x20
Rob Clarkfceffb322016-11-05 11:08:09 -0400138#define DRM_UT_STATE 0x40
yakui_zhao4fefcb22009-06-02 14:09:47 +0800139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140/***********************************************************************/
141/** \name DRM template customization defaults */
142/*@{*/
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144/***********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/** \name Macros to make printk easier */
146/*@{*/
147
Dave Gordon30b0da82016-08-18 18:17:22 +0100148#define _DRM_PRINTK(once, level, fmt, ...) \
149 do { \
150 printk##once(KERN_##level "[" DRM_NAME "] " fmt, \
151 ##__VA_ARGS__); \
152 } while (0)
153
154#define DRM_INFO(fmt, ...) \
155 _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
156#define DRM_NOTE(fmt, ...) \
157 _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
158#define DRM_WARN(fmt, ...) \
159 _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
160
161#define DRM_INFO_ONCE(fmt, ...) \
162 _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
163#define DRM_NOTE_ONCE(fmt, ...) \
164 _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
165#define DRM_WARN_ONCE(fmt, ...) \
166 _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168/**
169 * Error output.
170 *
171 * \param fmt printf() like format string.
172 * \param arg arguments
173 */
Sean Paulc4e68a52016-08-15 16:18:04 -0700174#define DRM_DEV_ERROR(dev, fmt, ...) \
175 drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\
176 fmt, ##__VA_ARGS__)
177#define DRM_ERROR(fmt, ...) \
Joe Perches6bd488d2016-09-25 19:18:34 -0700178 drm_printk(KERN_ERR, DRM_UT_NONE, fmt, ##__VA_ARGS__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Rob Clark5d13d422013-11-21 14:29:51 -0500180/**
181 * Rate limited error output. Like DRM_ERROR() but won't flood the log.
182 *
183 * \param fmt printf() like format string.
184 * \param arg arguments
185 */
Sean Paulc4e68a52016-08-15 16:18:04 -0700186#define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \
Rob Clark5d13d422013-11-21 14:29:51 -0500187({ \
188 static DEFINE_RATELIMIT_STATE(_rs, \
189 DEFAULT_RATELIMIT_INTERVAL, \
190 DEFAULT_RATELIMIT_BURST); \
191 \
192 if (__ratelimit(&_rs)) \
Sean Paulc4e68a52016-08-15 16:18:04 -0700193 DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \
Rob Clark5d13d422013-11-21 14:29:51 -0500194})
Sean Paulc4e68a52016-08-15 16:18:04 -0700195#define DRM_ERROR_RATELIMITED(fmt, ...) \
196 DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
Rob Clark5d13d422013-11-21 14:29:51 -0500197
Sean Paulc4e68a52016-08-15 16:18:04 -0700198#define DRM_DEV_INFO(dev, fmt, ...) \
199 drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt, \
200 ##__VA_ARGS__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Sean Paulc4e68a52016-08-15 16:18:04 -0700202#define DRM_DEV_INFO_ONCE(dev, fmt, ...) \
203({ \
204 static bool __print_once __read_mostly; \
205 if (!__print_once) { \
206 __print_once = true; \
207 DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \
208 } \
209})
Jani Nikula48b8f632014-01-31 15:49:07 +0200210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211/**
212 * Debug output.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000213 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 * \param fmt printf() like format string.
215 * \param arg arguments
216 */
Sean Paulc4e68a52016-08-15 16:18:04 -0700217#define DRM_DEV_DEBUG(dev, fmt, args...) \
218 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_CORE, __func__, "", fmt, \
219 ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700220#define DRM_DEBUG(fmt, ...) \
221 drm_printk(KERN_DEBUG, DRM_UT_CORE, fmt, ##__VA_ARGS__)
yakui_zhao4fefcb22009-06-02 14:09:47 +0800222
Sean Paulc4e68a52016-08-15 16:18:04 -0700223#define DRM_DEV_DEBUG_DRIVER(dev, fmt, args...) \
224 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_DRIVER, __func__, "", \
225 fmt, ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700226#define DRM_DEBUG_DRIVER(fmt, ...) \
227 drm_printk(KERN_DEBUG, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
Sean Paulc4e68a52016-08-15 16:18:04 -0700229#define DRM_DEV_DEBUG_KMS(dev, fmt, args...) \
230 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_KMS, __func__, "", fmt, \
231 ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700232#define DRM_DEBUG_KMS(fmt, ...) \
233 drm_printk(KERN_DEBUG, DRM_UT_KMS, fmt, ##__VA_ARGS__)
Sean Paulc4e68a52016-08-15 16:18:04 -0700234
235#define DRM_DEV_DEBUG_PRIME(dev, fmt, args...) \
236 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_PRIME, __func__, "", \
237 fmt, ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700238#define DRM_DEBUG_PRIME(fmt, ...) \
239 drm_printk(KERN_DEBUG, DRM_UT_PRIME, fmt, ##__VA_ARGS__)
Sean Paulc4e68a52016-08-15 16:18:04 -0700240
241#define DRM_DEV_DEBUG_ATOMIC(dev, fmt, args...) \
242 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ATOMIC, __func__, "", \
243 fmt, ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700244#define DRM_DEBUG_ATOMIC(fmt, ...) \
245 drm_printk(KERN_DEBUG, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
Sean Paulc4e68a52016-08-15 16:18:04 -0700246
247#define DRM_DEV_DEBUG_VBL(dev, fmt, args...) \
248 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_VBL, __func__, "", fmt, \
249 ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700250#define DRM_DEBUG_VBL(fmt, ...) \
251 drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__)
Sean Paulc4e68a52016-08-15 16:18:04 -0700252
253#define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...) \
254({ \
255 static DEFINE_RATELIMIT_STATE(_rs, \
256 DEFAULT_RATELIMIT_INTERVAL, \
257 DEFAULT_RATELIMIT_BURST); \
258 if (__ratelimit(&_rs)) \
259 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ ## level, \
260 __func__, "", fmt, ##args); \
261})
Lyude27528c62016-08-05 20:30:38 -0400262
263/**
264 * Rate limited debug output. Like DRM_DEBUG() but won't flood the log.
265 *
266 * \param fmt printf() like format string.
267 * \param arg arguments
268 */
Sean Paulc4e68a52016-08-15 16:18:04 -0700269#define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...) \
270 DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args)
Lyude27528c62016-08-05 20:30:38 -0400271#define DRM_DEBUG_RATELIMITED(fmt, args...) \
Sean Paulc4e68a52016-08-15 16:18:04 -0700272 DRM_DEV_DEBUG_RATELIMITED(NULL, fmt, ##args)
273#define DRM_DEV_DEBUG_DRIVER_RATELIMITED(dev, fmt, args...) \
274 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, DRIVER, fmt, ##args)
Lyude27528c62016-08-05 20:30:38 -0400275#define DRM_DEBUG_DRIVER_RATELIMITED(fmt, args...) \
Sean Paulc4e68a52016-08-15 16:18:04 -0700276 DRM_DEV_DEBUG_DRIVER_RATELIMITED(NULL, fmt, ##args)
277#define DRM_DEV_DEBUG_KMS_RATELIMITED(dev, fmt, args...) \
278 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, KMS, fmt, ##args)
Lyude27528c62016-08-05 20:30:38 -0400279#define DRM_DEBUG_KMS_RATELIMITED(fmt, args...) \
Sean Paulc4e68a52016-08-15 16:18:04 -0700280 DRM_DEV_DEBUG_KMS_RATELIMITED(NULL, fmt, ##args)
281#define DRM_DEV_DEBUG_PRIME_RATELIMITED(dev, fmt, args...) \
282 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, PRIME, fmt, ##args)
Lyude27528c62016-08-05 20:30:38 -0400283#define DRM_DEBUG_PRIME_RATELIMITED(fmt, args...) \
Sean Paulc4e68a52016-08-15 16:18:04 -0700284 DRM_DEV_DEBUG_PRIME_RATELIMITED(NULL, fmt, ##args)
Lyude27528c62016-08-05 20:30:38 -0400285
Rob Clark65c7dc12016-11-05 11:08:06 -0400286/* Format strings and argument splitters to simplify printing
287 * various "complex" objects
288 */
Rob Clark65c7dc12016-11-05 11:08:06 -0400289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290/*@}*/
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292/***********************************************************************/
293/** \name Internal types and structures */
294/*@{*/
295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Ben Gamari955b12d2009-02-17 20:08:49 -0500299/**
Dhinakaran Pandiyana743d752016-12-22 00:50:42 -0800300 * drm_drv_uses_atomic_modeset - check if the driver implements
301 * atomic_commit()
302 * @dev: DRM device
303 *
304 * This check is useful if drivers do not have DRIVER_ATOMIC set but
305 * have atomic modesetting internally implemented.
306 */
307static inline bool drm_drv_uses_atomic_modeset(struct drm_device *dev)
308{
309 return dev->mode_config.funcs->atomic_commit != NULL;
310}
311
Dave Airlie5bcf7192010-12-07 09:20:40 +1000312#define DRM_SWITCH_POWER_ON 0
313#define DRM_SWITCH_POWER_OFF 1
314#define DRM_SWITCH_POWER_CHANGING 2
Dave Airlie13bb9cc2012-09-12 15:55:05 +1000315#define DRM_SWITCH_POWER_DYNAMIC_OFF 3
Dave Airlie5bcf7192010-12-07 09:20:40 +1000316
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000317static __inline__ int drm_core_check_feature(struct drm_device *dev,
318 int feature)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
320 return ((dev->driver->driver_features & feature) ? 1 : 0);
321}
322
Dave Airlie2c07a212012-02-20 14:18:07 +0000323static inline void drm_device_set_unplugged(struct drm_device *dev)
324{
325 smp_wmb();
326 atomic_set(&dev->unplugged, 1);
327}
328
329static inline int drm_device_is_unplugged(struct drm_device *dev)
330{
331 int ret = atomic_read(&dev->unplugged);
332 smp_rmb();
333 return ret;
334}
335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336/******************************************************************/
337/** \name Internal function definitions */
338/*@{*/
339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 /* Driver support (drm_drv.h) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Thomas Hellstrom040ac322007-03-23 13:28:33 +1100342/*
343 * These are exported to drivers so that they can implement fencing using
344 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
345 */
346
Dave Airlie8410ea32010-12-15 03:16:38 +1000347/*@}*/
348
Dave Airliecc1f7192012-01-05 09:55:22 +0000349/* returns true if currently okay to sleep */
350static __inline__ bool drm_can_sleep(void)
351{
352 if (in_atomic() || in_dbg_master() || irqs_disabled())
353 return false;
354 return true;
355}
356
Jani Nikula373701b2015-11-24 21:21:55 +0200357/* helper for handling conditionals in various for_each macros */
358#define for_each_if(condition) if (!(condition)) {} else
359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360#endif