]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/drm/drmP.h
dmaengine: imx-sdma: fix size check for sdma script_number
[mirror_ubuntu-bionic-kernel.git] / include / drm / drmP.h
CommitLineData
1da177e4 1/*
d7d2c48e
DH
2 * Internal Header for the Direct Rendering Manager
3 *
1da177e4
LT
4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
dcdb1674 6 * Copyright (c) 2009-2010, Code Aurora Forum.
1da177e4
LT
7 * All rights reserved.
8 *
d7d2c48e
DH
9 * Author: Rickard E. (Rik) Faith <faith@valinux.com>
10 * Author: Gareth Hughes <gareth@valinux.com>
11 *
1da177e4
LT
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
96993908
DH
35#include <linux/agp_backend.h>
36#include <linux/cdev.h>
37#include <linux/dma-mapping.h>
38#include <linux/file.h>
1da177e4 39#include <linux/fs.h>
96993908
DH
40#include <linux/highmem.h>
41#include <linux/idr.h>
1da177e4 42#include <linux/init.h>
96993908 43#include <linux/io.h>
1da177e4 44#include <linux/jiffies.h>
96993908
DH
45#include <linux/kernel.h>
46#include <linux/kref.h>
47#include <linux/miscdevice.h>
1da177e4 48#include <linux/mm.h>
30e2fb18 49#include <linux/mutex.h>
96993908
DH
50#include <linux/platform_device.h>
51#include <linux/poll.h>
5d13d425 52#include <linux/ratelimit.h>
96993908
DH
53#include <linux/sched.h>
54#include <linux/slab.h>
1da177e4 55#include <linux/types.h>
d6db6564 56#include <linux/vmalloc.h>
96993908 57#include <linux/workqueue.h>
f54d1867 58#include <linux/dma-fence.h>
c6bb9baa 59#include <linux/module.h>
96993908
DH
60
61#include <asm/mman.h>
1da177e4 62#include <asm/pgalloc.h>
7c0f6ba6 63#include <linux/uaccess.h>
96993908 64
d7d2c48e
DH
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>
ae4df11a 70#include <drm/drm_fourcc.h>
d7d2c48e 71#include <drm/drm_global.h>
96993908
DH
72#include <drm/drm_hashtab.h>
73#include <drm/drm_mm.h>
74#include <drm/drm_os_linux.h>
19218e48 75#include <drm/drm_sarea.h>
85e634bc 76#include <drm/drm_drv.h>
c6bb9baa 77#include <drm/drm_prime.h>
23ef59ef 78#include <drm/drm_pci.h>
a8f8b1d9 79#include <drm/drm_file.h>
4834442d 80#include <drm/drm_debugfs.h>
7cfdf711 81#include <drm/drm_ioctl.h>
e2271704 82#include <drm/drm_sysfs.h>
3ed4351a
DV
83#include <drm/drm_vblank.h>
84#include <drm/drm_irq.h>
e4672e55 85#include <drm/drm_device.h>
1da177e4 86
de477254
PG
87struct module;
88
edb37a95 89struct device_node;
ebc64e45 90struct videomode;
3aac4502 91struct reservation_object;
b5e9c1a2 92struct dma_buf_attachment;
ebc64e45 93
23ef59ef
DV
94struct pci_dev;
95struct pci_controller;
96
87fdff81 97/*
346fea63 98 * The following categories are defined:
1414b76c
LD
99 *
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.
87fdff81 105 *
1414b76c
LD
106 * KMS: used in the modesetting code.
107 * This is the category used by the DRM_DEBUG_KMS() macro.
87fdff81 108 *
1414b76c
LD
109 * PRIME: used in the prime code.
110 * This is the category used by the DRM_DEBUG_PRIME() macro.
87fdff81 111 *
17a38d9c
DV
112 * ATOMIC: used in the atomic code.
113 * This is the category used by the DRM_DEBUG_ATOMIC() macro.
114 *
235fabe0
VS
115 * VBL: used for verbose debug message in the vblank code
116 * This is the category used by the DRM_DEBUG_VBL() macro.
117 *
1414b76c
LD
118 * 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 * ...
235fabe0 125 * drm.debug=0x3f will enable all messages
1414b76c
LD
126 *
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
87fdff81 130 */
c4e68a58 131#define DRM_UT_NONE 0x00
1414b76c
LD
132#define DRM_UT_CORE 0x01
133#define DRM_UT_DRIVER 0x02
134#define DRM_UT_KMS 0x04
135#define DRM_UT_PRIME 0x08
17a38d9c 136#define DRM_UT_ATOMIC 0x10
235fabe0 137#define DRM_UT_VBL 0x20
fceffb32 138#define DRM_UT_STATE 0x40
e7646f84 139#define DRM_UT_LEASE 0x80
4fefcb27 140
1da177e4
LT
141/***********************************************************************/
142/** \name DRM template customization defaults */
143/*@{*/
144
1da177e4 145/***********************************************************************/
1da177e4
LT
146/** \name Macros to make printk easier */
147/*@{*/
148
30b0da8d
DG
149#define _DRM_PRINTK(once, level, fmt, ...) \
150 do { \
151 printk##once(KERN_##level "[" DRM_NAME "] " fmt, \
152 ##__VA_ARGS__); \
153 } while (0)
154
155#define DRM_INFO(fmt, ...) \
156 _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
157#define DRM_NOTE(fmt, ...) \
158 _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
159#define DRM_WARN(fmt, ...) \
160 _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
161
162#define DRM_INFO_ONCE(fmt, ...) \
163 _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
164#define DRM_NOTE_ONCE(fmt, ...) \
165 _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
166#define DRM_WARN_ONCE(fmt, ...) \
167 _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
168
1da177e4
LT
169/**
170 * Error output.
171 *
172 * \param fmt printf() like format string.
173 * \param arg arguments
174 */
c4e68a58
SP
175#define DRM_DEV_ERROR(dev, fmt, ...) \
176 drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\
177 fmt, ##__VA_ARGS__)
178#define DRM_ERROR(fmt, ...) \
6bd488db 179 drm_printk(KERN_ERR, DRM_UT_NONE, fmt, ##__VA_ARGS__)
1da177e4 180
5d13d425
RC
181/**
182 * Rate limited error output. Like DRM_ERROR() but won't flood the log.
183 *
184 * \param fmt printf() like format string.
185 * \param arg arguments
186 */
c4e68a58 187#define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \
5d13d425
RC
188({ \
189 static DEFINE_RATELIMIT_STATE(_rs, \
190 DEFAULT_RATELIMIT_INTERVAL, \
191 DEFAULT_RATELIMIT_BURST); \
192 \
193 if (__ratelimit(&_rs)) \
c4e68a58 194 DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \
5d13d425 195})
c4e68a58
SP
196#define DRM_ERROR_RATELIMITED(fmt, ...) \
197 DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
5d13d425 198
c4e68a58
SP
199#define DRM_DEV_INFO(dev, fmt, ...) \
200 drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt, \
201 ##__VA_ARGS__)
1da177e4 202
c4e68a58
SP
203#define DRM_DEV_INFO_ONCE(dev, fmt, ...) \
204({ \
205 static bool __print_once __read_mostly; \
206 if (!__print_once) { \
207 __print_once = true; \
208 DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \
209 } \
210})
48b8f631 211
1da177e4
LT
212/**
213 * Debug output.
b5e89ed5 214 *
1da177e4
LT
215 * \param fmt printf() like format string.
216 * \param arg arguments
217 */
c4e68a58
SP
218#define DRM_DEV_DEBUG(dev, fmt, args...) \
219 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_CORE, __func__, "", fmt, \
220 ##args)
6bd488db
JP
221#define DRM_DEBUG(fmt, ...) \
222 drm_printk(KERN_DEBUG, DRM_UT_CORE, fmt, ##__VA_ARGS__)
4fefcb27 223
c4e68a58
SP
224#define DRM_DEV_DEBUG_DRIVER(dev, fmt, args...) \
225 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_DRIVER, __func__, "", \
226 fmt, ##args)
6bd488db
JP
227#define DRM_DEBUG_DRIVER(fmt, ...) \
228 drm_printk(KERN_DEBUG, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
c4e68a58
SP
229
230#define DRM_DEV_DEBUG_KMS(dev, fmt, args...) \
231 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_KMS, __func__, "", fmt, \
232 ##args)
6bd488db
JP
233#define DRM_DEBUG_KMS(fmt, ...) \
234 drm_printk(KERN_DEBUG, DRM_UT_KMS, fmt, ##__VA_ARGS__)
c4e68a58
SP
235
236#define DRM_DEV_DEBUG_PRIME(dev, fmt, args...) \
237 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_PRIME, __func__, "", \
238 fmt, ##args)
6bd488db
JP
239#define DRM_DEBUG_PRIME(fmt, ...) \
240 drm_printk(KERN_DEBUG, DRM_UT_PRIME, fmt, ##__VA_ARGS__)
c4e68a58
SP
241
242#define DRM_DEV_DEBUG_ATOMIC(dev, fmt, args...) \
243 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ATOMIC, __func__, "", \
244 fmt, ##args)
6bd488db
JP
245#define DRM_DEBUG_ATOMIC(fmt, ...) \
246 drm_printk(KERN_DEBUG, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
c4e68a58
SP
247
248#define DRM_DEV_DEBUG_VBL(dev, fmt, args...) \
249 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_VBL, __func__, "", fmt, \
250 ##args)
6bd488db
JP
251#define DRM_DEBUG_VBL(fmt, ...) \
252 drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__)
1da177e4 253
e7646f84
KP
254#define DRM_DEBUG_LEASE(fmt, ...) \
255 drm_printk(KERN_DEBUG, DRM_UT_LEASE, fmt, ##__VA_ARGS__)
256
c4e68a58
SP
257#define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...) \
258({ \
259 static DEFINE_RATELIMIT_STATE(_rs, \
260 DEFAULT_RATELIMIT_INTERVAL, \
261 DEFAULT_RATELIMIT_BURST); \
262 if (__ratelimit(&_rs)) \
263 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ ## level, \
264 __func__, "", fmt, ##args); \
265})
27528c66
L
266
267/**
268 * Rate limited debug output. Like DRM_DEBUG() but won't flood the log.
269 *
270 * \param fmt printf() like format string.
271 * \param arg arguments
272 */
c4e68a58
SP
273#define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...) \
274 DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args)
27528c66 275#define DRM_DEBUG_RATELIMITED(fmt, args...) \
c4e68a58
SP
276 DRM_DEV_DEBUG_RATELIMITED(NULL, fmt, ##args)
277#define DRM_DEV_DEBUG_DRIVER_RATELIMITED(dev, fmt, args...) \
278 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, DRIVER, fmt, ##args)
27528c66 279#define DRM_DEBUG_DRIVER_RATELIMITED(fmt, args...) \
c4e68a58
SP
280 DRM_DEV_DEBUG_DRIVER_RATELIMITED(NULL, fmt, ##args)
281#define DRM_DEV_DEBUG_KMS_RATELIMITED(dev, fmt, args...) \
282 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, KMS, fmt, ##args)
27528c66 283#define DRM_DEBUG_KMS_RATELIMITED(fmt, args...) \
c4e68a58
SP
284 DRM_DEV_DEBUG_KMS_RATELIMITED(NULL, fmt, ##args)
285#define DRM_DEV_DEBUG_PRIME_RATELIMITED(dev, fmt, args...) \
286 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, PRIME, fmt, ##args)
27528c66 287#define DRM_DEBUG_PRIME_RATELIMITED(fmt, args...) \
c4e68a58 288 DRM_DEV_DEBUG_PRIME_RATELIMITED(NULL, fmt, ##args)
27528c66 289
65c7dc18
RC
290/* Format strings and argument splitters to simplify printing
291 * various "complex" objects
292 */
65c7dc18 293
1da177e4
LT
294/*@}*/
295
1da177e4
LT
296/***********************************************************************/
297/** \name Internal types and structures */
298/*@{*/
299
1da177e4 300#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
1da177e4 301
1da177e4 302
a743d758
DP
303/**
304 * drm_drv_uses_atomic_modeset - check if the driver implements
305 * atomic_commit()
306 * @dev: DRM device
307 *
308 * This check is useful if drivers do not have DRIVER_ATOMIC set but
309 * have atomic modesetting internally implemented.
310 */
311static inline bool drm_drv_uses_atomic_modeset(struct drm_device *dev)
312{
313 return dev->mode_config.funcs->atomic_commit != NULL;
314}
315
5bcf719b
DA
316#define DRM_SWITCH_POWER_ON 0
317#define DRM_SWITCH_POWER_OFF 1
318#define DRM_SWITCH_POWER_CHANGING 2
13bb9cc8 319#define DRM_SWITCH_POWER_DYNAMIC_OFF 3
5bcf719b 320
b5e89ed5
DA
321static __inline__ int drm_core_check_feature(struct drm_device *dev,
322 int feature)
1da177e4
LT
323{
324 return ((dev->driver->driver_features & feature) ? 1 : 0);
325}
326
1da177e4
LT
327/******************************************************************/
328/** \name Internal function definitions */
329/*@{*/
330
1da177e4 331 /* Driver support (drm_drv.h) */
1da177e4 332
040ac320
TH
333/*
334 * These are exported to drivers so that they can implement fencing using
335 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
336 */
337
8410ea3b
DA
338/*@}*/
339
cc1f7194
DA
340/* returns true if currently okay to sleep */
341static __inline__ bool drm_can_sleep(void)
342{
343 if (in_atomic() || in_dbg_master() || irqs_disabled())
344 return false;
345 return true;
346}
347
373701b1
JN
348/* helper for handling conditionals in various for_each macros */
349#define for_each_if(condition) if (!(condition)) {} else
350
1da177e4 351#endif