blob: 0e383438f79326095edbc5b2d5eaf80642dedd47 [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>
David Herrmannd7d2c482014-08-29 12:12:40 +020073#include <drm/drm_mem_util.h>
David Herrmann96993902014-08-29 12:12:37 +020074#include <drm/drm_mm.h>
75#include <drm/drm_os_linux.h>
David Howells19218e42012-10-02 18:01:03 +010076#include <drm/drm_sarea.h>
Daniel Vetter85e634b2016-11-14 12:58:19 +010077#include <drm/drm_drv.h>
Daniel Vetterc6bb9ba2017-03-08 15:12:35 +010078#include <drm/drm_prime.h>
Daniel Vetter23ef59e2017-03-08 15:12:37 +010079#include <drm/drm_pci.h>
Daniel Vettera8f8b1d2017-03-08 15:12:42 +010080#include <drm/drm_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Paul Gortmakerde477252011-05-26 13:46:22 -040082struct module;
83
Eric Anholtc153f452007-09-03 12:06:45 +100084struct drm_device;
David Herrmanncc5ea592014-08-29 12:12:32 +020085struct drm_agp_head;
Daniel Vetterba8286f2014-09-11 07:43:25 +020086struct drm_local_map;
87struct drm_device_dma;
Daniel Vetterd9fc9412014-09-23 15:46:53 +020088struct drm_gem_object;
Daniel Vetter3b96a0b2016-06-21 10:54:22 +020089struct drm_master;
Daniel Vetter34a67dd2016-07-15 21:48:01 +020090struct drm_vblank_crtc;
Daniel Vetterc6bb9ba2017-03-08 15:12:35 +010091struct drm_vma_offset_manager;
Eric Anholtc153f452007-09-03 12:06:45 +100092
Steffen Trumtraredb37a92012-10-28 18:28:06 +010093struct device_node;
Steffen Trumtrarebc64e42012-11-14 11:22:52 +010094struct videomode;
Maarten Lankhorst3aac4502014-07-01 12:57:26 +020095struct reservation_object;
Maarten Lankhorstb5e9c1a2014-01-09 11:03:14 +010096struct dma_buf_attachment;
Steffen Trumtrarebc64e42012-11-14 11:22:52 +010097
Daniel Vetter23ef59e2017-03-08 15:12:37 +010098struct pci_dev;
99struct pci_controller;
100
Lespiau, Damien1414b762014-03-24 15:53:08 +0000101/*
Robert Foss346fea62016-04-14 10:34:16 -0400102 * The following categories are defined:
Lespiau, Damien1414b762014-03-24 15:53:08 +0000103 *
104 * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
105 * This is the category used by the DRM_DEBUG() macro.
106 *
107 * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
108 * This is the category used by the DRM_DEBUG_DRIVER() macro.
109 *
110 * KMS: used in the modesetting code.
111 * This is the category used by the DRM_DEBUG_KMS() macro.
112 *
113 * PRIME: used in the prime code.
114 * This is the category used by the DRM_DEBUG_PRIME() macro.
115 *
Daniel Vetter17a38d92015-02-22 12:24:16 +0100116 * ATOMIC: used in the atomic code.
117 * This is the category used by the DRM_DEBUG_ATOMIC() macro.
118 *
Ville Syrjälä235fabe2015-10-09 22:57:37 +0300119 * VBL: used for verbose debug message in the vblank code
120 * This is the category used by the DRM_DEBUG_VBL() macro.
121 *
Lespiau, Damien1414b762014-03-24 15:53:08 +0000122 * Enabling verbose debug messages is done through the drm.debug parameter,
123 * each category being enabled by a bit.
124 *
125 * drm.debug=0x1 will enable CORE messages
126 * drm.debug=0x2 will enable DRIVER messages
127 * drm.debug=0x3 will enable CORE and DRIVER messages
128 * ...
Ville Syrjälä235fabe2015-10-09 22:57:37 +0300129 * drm.debug=0x3f will enable all messages
Lespiau, Damien1414b762014-03-24 15:53:08 +0000130 *
131 * An interesting feature is that it's possible to enable verbose logging at
132 * run-time by echoing the debug value in its sysfs node:
133 * # echo 0xf > /sys/module/drm/parameters/debug
134 */
Sean Paulc4e68a52016-08-15 16:18:04 -0700135#define DRM_UT_NONE 0x00
yakui_zhao4fefcb22009-06-02 14:09:47 +0800136#define DRM_UT_CORE 0x01
137#define DRM_UT_DRIVER 0x02
138#define DRM_UT_KMS 0x04
Dave Airlie32488772011-11-25 15:21:02 +0000139#define DRM_UT_PRIME 0x08
Daniel Vetter17a38d92015-02-22 12:24:16 +0100140#define DRM_UT_ATOMIC 0x10
Ville Syrjälä235fabe2015-10-09 22:57:37 +0300141#define DRM_UT_VBL 0x20
Rob Clarkfceffb322016-11-05 11:08:09 -0400142#define DRM_UT_STATE 0x40
yakui_zhao4fefcb22009-06-02 14:09:47 +0800143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144/***********************************************************************/
145/** \name DRM template customization defaults */
146/*@{*/
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148/***********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149/** \name Macros to make printk easier */
150/*@{*/
151
Dave Gordon30b0da82016-08-18 18:17:22 +0100152#define _DRM_PRINTK(once, level, fmt, ...) \
153 do { \
154 printk##once(KERN_##level "[" DRM_NAME "] " fmt, \
155 ##__VA_ARGS__); \
156 } while (0)
157
158#define DRM_INFO(fmt, ...) \
159 _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
160#define DRM_NOTE(fmt, ...) \
161 _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
162#define DRM_WARN(fmt, ...) \
163 _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
164
165#define DRM_INFO_ONCE(fmt, ...) \
166 _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
167#define DRM_NOTE_ONCE(fmt, ...) \
168 _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
169#define DRM_WARN_ONCE(fmt, ...) \
170 _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172/**
173 * Error output.
174 *
175 * \param fmt printf() like format string.
176 * \param arg arguments
177 */
Sean Paulc4e68a52016-08-15 16:18:04 -0700178#define DRM_DEV_ERROR(dev, fmt, ...) \
179 drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\
180 fmt, ##__VA_ARGS__)
181#define DRM_ERROR(fmt, ...) \
Joe Perches6bd488d2016-09-25 19:18:34 -0700182 drm_printk(KERN_ERR, DRM_UT_NONE, fmt, ##__VA_ARGS__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Rob Clark5d13d422013-11-21 14:29:51 -0500184/**
185 * Rate limited error output. Like DRM_ERROR() but won't flood the log.
186 *
187 * \param fmt printf() like format string.
188 * \param arg arguments
189 */
Sean Paulc4e68a52016-08-15 16:18:04 -0700190#define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \
Rob Clark5d13d422013-11-21 14:29:51 -0500191({ \
192 static DEFINE_RATELIMIT_STATE(_rs, \
193 DEFAULT_RATELIMIT_INTERVAL, \
194 DEFAULT_RATELIMIT_BURST); \
195 \
196 if (__ratelimit(&_rs)) \
Sean Paulc4e68a52016-08-15 16:18:04 -0700197 DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \
Rob Clark5d13d422013-11-21 14:29:51 -0500198})
Sean Paulc4e68a52016-08-15 16:18:04 -0700199#define DRM_ERROR_RATELIMITED(fmt, ...) \
200 DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
Rob Clark5d13d422013-11-21 14:29:51 -0500201
Sean Paulc4e68a52016-08-15 16:18:04 -0700202#define DRM_DEV_INFO(dev, fmt, ...) \
203 drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt, \
204 ##__VA_ARGS__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Sean Paulc4e68a52016-08-15 16:18:04 -0700206#define DRM_DEV_INFO_ONCE(dev, fmt, ...) \
207({ \
208 static bool __print_once __read_mostly; \
209 if (!__print_once) { \
210 __print_once = true; \
211 DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \
212 } \
213})
Jani Nikula48b8f632014-01-31 15:49:07 +0200214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215/**
216 * Debug output.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000217 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 * \param fmt printf() like format string.
219 * \param arg arguments
220 */
Sean Paulc4e68a52016-08-15 16:18:04 -0700221#define DRM_DEV_DEBUG(dev, fmt, args...) \
222 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_CORE, __func__, "", fmt, \
223 ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700224#define DRM_DEBUG(fmt, ...) \
225 drm_printk(KERN_DEBUG, DRM_UT_CORE, fmt, ##__VA_ARGS__)
yakui_zhao4fefcb22009-06-02 14:09:47 +0800226
Sean Paulc4e68a52016-08-15 16:18:04 -0700227#define DRM_DEV_DEBUG_DRIVER(dev, fmt, args...) \
228 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_DRIVER, __func__, "", \
229 fmt, ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700230#define DRM_DEBUG_DRIVER(fmt, ...) \
231 drm_printk(KERN_DEBUG, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Sean Paulc4e68a52016-08-15 16:18:04 -0700233#define DRM_DEV_DEBUG_KMS(dev, fmt, args...) \
234 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_KMS, __func__, "", fmt, \
235 ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700236#define DRM_DEBUG_KMS(fmt, ...) \
237 drm_printk(KERN_DEBUG, DRM_UT_KMS, fmt, ##__VA_ARGS__)
Sean Paulc4e68a52016-08-15 16:18:04 -0700238
239#define DRM_DEV_DEBUG_PRIME(dev, fmt, args...) \
240 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_PRIME, __func__, "", \
241 fmt, ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700242#define DRM_DEBUG_PRIME(fmt, ...) \
243 drm_printk(KERN_DEBUG, DRM_UT_PRIME, fmt, ##__VA_ARGS__)
Sean Paulc4e68a52016-08-15 16:18:04 -0700244
245#define DRM_DEV_DEBUG_ATOMIC(dev, fmt, args...) \
246 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ATOMIC, __func__, "", \
247 fmt, ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700248#define DRM_DEBUG_ATOMIC(fmt, ...) \
249 drm_printk(KERN_DEBUG, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
Sean Paulc4e68a52016-08-15 16:18:04 -0700250
251#define DRM_DEV_DEBUG_VBL(dev, fmt, args...) \
252 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_VBL, __func__, "", fmt, \
253 ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700254#define DRM_DEBUG_VBL(fmt, ...) \
255 drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__)
Sean Paulc4e68a52016-08-15 16:18:04 -0700256
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})
Lyude27528c62016-08-05 20:30:38 -0400266
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 */
Sean Paulc4e68a52016-08-15 16:18:04 -0700273#define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...) \
274 DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args)
Lyude27528c62016-08-05 20:30:38 -0400275#define DRM_DEBUG_RATELIMITED(fmt, args...) \
Sean Paulc4e68a52016-08-15 16:18:04 -0700276 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)
Lyude27528c62016-08-05 20:30:38 -0400279#define DRM_DEBUG_DRIVER_RATELIMITED(fmt, args...) \
Sean Paulc4e68a52016-08-15 16:18:04 -0700280 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)
Lyude27528c62016-08-05 20:30:38 -0400283#define DRM_DEBUG_KMS_RATELIMITED(fmt, args...) \
Sean Paulc4e68a52016-08-15 16:18:04 -0700284 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)
Lyude27528c62016-08-05 20:30:38 -0400287#define DRM_DEBUG_PRIME_RATELIMITED(fmt, args...) \
Sean Paulc4e68a52016-08-15 16:18:04 -0700288 DRM_DEV_DEBUG_PRIME_RATELIMITED(NULL, fmt, ##args)
Lyude27528c62016-08-05 20:30:38 -0400289
Rob Clark65c7dc12016-11-05 11:08:06 -0400290/* Format strings and argument splitters to simplify printing
291 * various "complex" objects
292 */
293#define DRM_MODE_FMT "%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x"
294#define DRM_MODE_ARG(m) \
295 (m)->base.id, (m)->name, (m)->vrefresh, (m)->clock, \
296 (m)->hdisplay, (m)->hsync_start, (m)->hsync_end, (m)->htotal, \
297 (m)->vdisplay, (m)->vsync_start, (m)->vsync_end, (m)->vtotal, \
298 (m)->type, (m)->flags
299
300#define DRM_RECT_FMT "%dx%d%+d%+d"
301#define DRM_RECT_ARG(r) drm_rect_width(r), drm_rect_height(r), (r)->x1, (r)->y1
302
303/* for rect's in fixed-point format: */
304#define DRM_RECT_FP_FMT "%d.%06ux%d.%06u%+d.%06u%+d.%06u"
305#define DRM_RECT_FP_ARG(r) \
306 drm_rect_width(r) >> 16, ((drm_rect_width(r) & 0xffff) * 15625) >> 10, \
307 drm_rect_height(r) >> 16, ((drm_rect_height(r) & 0xffff) * 15625) >> 10, \
308 (r)->x1 >> 16, (((r)->x1 & 0xffff) * 15625) >> 10, \
309 (r)->y1 >> 16, (((r)->y1 & 0xffff) * 15625) >> 10
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311/*@}*/
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313/***********************************************************************/
314/** \name Internal types and structures */
315/*@{*/
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 * Ioctl function type.
321 *
322 * \param inode device inode.
Eric Anholt6c340ea2007-08-25 20:23:09 +1000323 * \param file_priv DRM file private pointer.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 * \param cmd command.
325 * \param arg argument.
326 */
Eric Anholtc153f452007-09-03 12:06:45 +1000327typedef int drm_ioctl_t(struct drm_device *dev, void *data,
328 struct drm_file *file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Dave Airlie9a186642005-06-23 21:29:18 +1000330typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
331 unsigned long arg);
332
Kristian Høgsberg1a959162009-12-02 12:13:48 -0500333#define DRM_IOCTL_NR(n) _IOC_NR(n)
334#define DRM_MAJOR 226
335
Dave Airliea7a2cc32006-01-02 13:54:04 +1100336#define DRM_AUTH 0x1
337#define DRM_MASTER 0x2
338#define DRM_ROOT_ONLY 0x4
Dave Airlief453ba02008-11-07 14:05:41 -0800339#define DRM_CONTROL_ALLOW 0x8
Arnd Bergmanned8b6702009-12-16 22:17:09 +0000340#define DRM_UNLOCKED 0x10
David Herrmann17931262013-08-25 18:29:00 +0200341#define DRM_RENDER_ALLOW 0x20
Dave Airliea7a2cc32006-01-02 13:54:04 +1100342
Eric Anholtc153f452007-09-03 12:06:45 +1000343struct drm_ioctl_desc {
344 unsigned int cmd;
Dave Airliea7a2cc32006-01-02 13:54:04 +1100345 int flags;
Richard Kennedyc972d752009-03-18 17:26:44 +0000346 drm_ioctl_t *func;
Chris Cumminsb9434d02013-05-09 14:20:40 +0100347 const char *name;
Eric Anholtc153f452007-09-03 12:06:45 +1000348};
349
350/**
351 * Creates a driver or general drm_ioctl_desc array entry for the given
352 * ioctl, for use by drm_ioctl().
353 */
Dave Airlie1b2f1482010-08-14 20:20:34 +1000354
Emil Velikov066626d2015-03-30 17:10:36 +0000355#define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
356 [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = { \
357 .cmd = DRM_IOCTL_##ioctl, \
358 .func = _func, \
359 .flags = _flags, \
360 .name = #ioctl \
361 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Mario Kleiner27641c32010-10-23 04:20:23 +0200363/* Flags and return codes for get_vblank_timestamp() driver function. */
364#define DRM_CALLED_FROM_VBLIRQ 1
365#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
Daniel Vetter3d3cbd82014-09-10 17:36:11 +0200366#define DRM_VBLANKTIME_IN_VBLANK (1 << 1)
Mario Kleiner27641c32010-10-23 04:20:23 +0200367
368/* get_scanout_position() return flags */
369#define DRM_SCANOUTPOS_VALID (1 << 0)
Daniel Vetter3d3cbd82014-09-10 17:36:11 +0200370#define DRM_SCANOUTPOS_IN_VBLANK (1 << 1)
Mario Kleiner27641c32010-10-23 04:20:23 +0200371#define DRM_SCANOUTPOS_ACCURATE (1 << 2)
372
Ben Gamari955b12d2009-02-17 20:08:49 -0500373/**
374 * Info file list entry. This structure represents a debugfs or proc file to
375 * be created by the drm core
376 */
377struct drm_info_list {
378 const char *name; /** file name */
379 int (*show)(struct seq_file*, void*); /** show callback */
380 u32 driver_features; /**< Required driver features for this entry */
381 void *data;
382};
383
384/**
385 * debugfs node structure. This structure represents a debugfs file.
386 */
387struct drm_info_node {
388 struct list_head list;
389 struct drm_minor *minor;
David Howellsce089b52013-04-12 15:23:25 +0100390 const struct drm_info_list *info_ent;
Ben Gamari955b12d2009-02-17 20:08:49 -0500391 struct dentry *dent;
392};
393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 * DRM device structure. This structure represent a complete card that
396 * may contain multiple heads.
397 */
Dave Airlie84b1fd12007-07-11 15:53:27 +1000398struct drm_device {
Daniel Vetterb3f23332013-12-11 11:34:31 +0100399 struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000400 int if_version; /**< Highest interface version set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
David Herrmann45e212d2014-01-28 16:00:35 +0100402 /** \name Lifetime Management */
403 /*@{ */
David Herrmann099d1c22014-01-29 10:21:36 +0100404 struct kref ref; /**< Object ref-count */
David Herrmann45e212d2014-01-28 16:00:35 +0100405 struct device *dev; /**< Device structure of bus-device */
406 struct drm_driver *driver; /**< DRM driver managing the device */
407 void *dev_private; /**< DRM driver private data */
David Herrmann45e212d2014-01-28 16:00:35 +0100408 struct drm_minor *control; /**< Control node */
409 struct drm_minor *primary; /**< Primary node */
410 struct drm_minor *render; /**< Render node */
Daniel Vettere6e7b482017-01-12 17:15:56 +0100411 bool registered;
Daniel Vetter95c081c2016-06-21 10:54:12 +0200412
413 /* currently active master for this device. Protected by master_mutex */
414 struct drm_master *master;
415
David Herrmann45e212d2014-01-28 16:00:35 +0100416 atomic_t unplugged; /**< Flag whether dev is dead */
David Herrmann07b48c32014-03-16 13:13:51 +0100417 struct inode *anon_inode; /**< inode for private address-space */
Thierry Redingca8e2ad2014-04-11 15:23:00 +0200418 char *unique; /**< unique name of the device */
David Herrmann45e212d2014-01-28 16:00:35 +0100419 /*@} */
420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 /** \name Locks */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000422 /*@{ */
Dave Airlie30e2fb12006-02-02 19:37:46 +1100423 struct mutex struct_mutex; /**< For others */
Thomas Hellstromc996fd02014-02-25 19:57:44 +0100424 struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000425 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 /** \name Usage Counters */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000428 /*@{ */
Daniel Vetterfc8fd402013-11-03 20:46:34 +0100429 int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
Daniel Vetter2177a212013-12-16 11:21:06 +0100430 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000431 int buf_use; /**< Buffers in use -- cannot alloc */
432 atomic_t buf_alloc; /**< Buffer allocation in progress */
433 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200435 struct mutex filelist_mutex;
Dave Airliebd1b3312007-05-26 05:01:51 +1000436 struct list_head filelist;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
438 /** \name Memory management */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000439 /*@{ */
Dave Airliebd1b3312007-05-26 05:01:51 +1000440 struct list_head maplist; /**< Linked list of regions */
Dave Airliee0be4282007-07-12 10:26:44 +1000441 struct drm_open_hash map_hash; /**< User token hash table for maps */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
443 /** \name Context handle management */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000444 /*@{ */
Dave Airliebd1b3312007-05-26 05:01:51 +1000445 struct list_head ctxlist; /**< Linked list of context handles */
Dave Airlie30e2fb12006-02-02 19:37:46 +1100446 struct mutex ctxlist_mutex; /**< For ctxlist */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Dave Airlie62968142007-07-17 10:46:52 +1000448 struct idr ctx_idr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Dave Airliebd1b3312007-05-26 05:01:51 +1000450 struct list_head vmalist; /**< List of vmas (for debugging) */
Dave Airlief453ba02008-11-07 14:05:41 -0800451
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000452 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Daniel Vettera344a7e2011-10-26 00:54:41 +0200454 /** \name DMA support */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000455 /*@{ */
Dave Airliecdd55a22007-07-11 16:32:08 +1000456 struct drm_device_dma *dma; /**< Optional pointer for DMA support */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000457 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
459 /** \name Context support */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000460 /*@{ */
Daniel Vetter7c1a38e32013-12-16 11:21:15 +0100461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 __volatile__ long context_flag; /**< Context swapping flag */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000463 int last_context; /**< Last current context */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000464 /*@} */
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 /** \name VBLANK IRQ support */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000467 /*@{ */
Thierry Redingb46004b2014-12-17 16:41:41 +0100468 bool irq_enabled;
469 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700471 /*
Ville Syrjälä00185e62014-08-06 14:49:54 +0300472 * If true, vblank interrupt will be disabled immediately when the
473 * refcount drops to zero, as opposed to via the vblank disable
474 * timer.
475 * This can be set to true it the hardware has a working vblank
476 * counter and the driver uses drm_vblank_on() and drm_vblank_off()
477 * appropriately.
478 */
479 bool vblank_disable_immediate;
480
Ville Syrjälä5380e922013-10-04 14:53:36 +0300481 /* array of size num_crtcs */
482 struct drm_vblank_crtc *vblank;
483
Mario Kleiner27641c32010-10-23 04:20:23 +0200484 spinlock_t vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000485 spinlock_t vbl_lock;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700486
487 u32 max_vblank_count; /**< size of vblank counter register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Kristian Høgsbergc9a9c5e2009-09-12 04:33:34 +1000489 /**
490 * List of events
491 */
492 struct list_head vblank_event_list;
493 spinlock_t event_lock;
494
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000495 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
Dave Airlie55910512007-07-11 16:53:40 +1000497 struct drm_agp_head *agp; /**< AGP data */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000499 struct pci_dev *pdev; /**< PCI device structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500#ifdef __alpha__
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 struct pci_controller *hose;
502#endif
Jordan Crousedcdb1672010-05-27 13:40:25 -0600503
Dave Airliedc5698e2013-09-09 10:02:56 +1000504 struct virtio_device *virtdev;
Jordan Crousedcdb1672010-05-27 13:40:25 -0600505
Dave Airlie55910512007-07-11 16:53:40 +1000506 struct drm_sg_mem *sg; /**< Scatter gather memory */
Dave Airlie19227562011-02-24 08:35:06 +1000507 unsigned int num_crtcs; /**< Number of CRTCs on this device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
David Herrmann69d516c2014-08-29 12:12:39 +0200509 struct {
510 int context;
511 struct drm_hw_lock *lock;
512 } sigdata;
513
Benjamin Herrenschmidtf77d3902009-02-02 16:55:46 +1100514 struct drm_local_map *agp_buffer_map;
Dave Airlied1f2b552005-08-05 22:11:22 +1000515 unsigned int agp_buffer_token;
=?utf-8?q?Michel_D=C3=A4nzer?=bea56792006-10-24 23:04:19 +1000516
Rob Clark417009fb2014-11-25 20:33:10 -0500517 struct drm_mode_config mode_config; /**< Current mode config */
Dave Airlief453ba02008-11-07 14:05:41 -0800518
Eric Anholt673a3942008-07-30 12:06:12 -0700519 /** \name GEM information */
520 /*@{ */
Daniel Vettercd4f0132013-08-15 00:02:44 +0200521 struct mutex object_name_lock;
Eric Anholt673a3942008-07-30 12:06:12 -0700522 struct idr object_name_idr;
Daniel Vetterb04a5902013-12-11 14:24:46 +0100523 struct drm_vma_offset_manager *vma_offset_manager;
Eric Anholt673a3942008-07-30 12:06:12 -0700524 /*@} */
Dave Airlie5bcf7192010-12-07 09:20:40 +1000525 int switch_power_state;
Dave Airlie84b1fd12007-07-11 15:53:27 +1000526};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Dhinakaran Pandiyana743d752016-12-22 00:50:42 -0800528/**
529 * drm_drv_uses_atomic_modeset - check if the driver implements
530 * atomic_commit()
531 * @dev: DRM device
532 *
533 * This check is useful if drivers do not have DRIVER_ATOMIC set but
534 * have atomic modesetting internally implemented.
535 */
536static inline bool drm_drv_uses_atomic_modeset(struct drm_device *dev)
537{
538 return dev->mode_config.funcs->atomic_commit != NULL;
539}
540
Daniel Vetter34a67dd2016-07-15 21:48:01 +0200541#include <drm/drm_irq.h>
542
Dave Airlie5bcf7192010-12-07 09:20:40 +1000543#define DRM_SWITCH_POWER_ON 0
544#define DRM_SWITCH_POWER_OFF 1
545#define DRM_SWITCH_POWER_CHANGING 2
Dave Airlie13bb9cc2012-09-12 15:55:05 +1000546#define DRM_SWITCH_POWER_DYNAMIC_OFF 3
Dave Airlie5bcf7192010-12-07 09:20:40 +1000547
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000548static __inline__ int drm_core_check_feature(struct drm_device *dev,
549 int feature)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550{
551 return ((dev->driver->driver_features & feature) ? 1 : 0);
552}
553
Dave Airlie2c07a212012-02-20 14:18:07 +0000554static inline void drm_device_set_unplugged(struct drm_device *dev)
555{
556 smp_wmb();
557 atomic_set(&dev->unplugged, 1);
558}
559
560static inline int drm_device_is_unplugged(struct drm_device *dev)
561{
562 int ret = atomic_read(&dev->unplugged);
563 smp_rmb();
564 return ret;
565}
566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567/******************************************************************/
568/** \name Internal function definitions */
569/*@{*/
570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 /* Driver support (drm_drv.h) */
Thomas Hellstrom51010202015-07-10 22:31:08 -0700572extern int drm_ioctl_permit(u32 flags, struct drm_file *file_priv);
Arnd Bergmanned8b6702009-12-16 22:17:09 +0000573extern long drm_ioctl(struct file *filp,
574 unsigned int cmd, unsigned long arg);
Jani Nikula55edf412016-11-01 17:40:44 +0200575#ifdef CONFIG_COMPAT
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000576extern long drm_compat_ioctl(struct file *filp,
577 unsigned int cmd, unsigned long arg);
Jani Nikula55edf412016-11-01 17:40:44 +0200578#else
579/* Let drm_compat_ioctl be assigned to .compat_ioctl unconditionally */
580#define drm_compat_ioctl NULL
581#endif
Thomas Hellstrom4beb6d92014-02-26 15:51:57 +0100582extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Daniel Vetter78238752014-09-10 12:43:55 +0200584/* Misc. IOCTL support (drm_ioctl.c) */
585int drm_noop(struct drm_device *dev, void *data,
586 struct drm_file *file_priv);
Daniel Vetter4b635392015-09-08 13:56:26 +0200587int drm_invalid_op(struct drm_device *dev, void *data,
588 struct drm_file *file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Thomas Hellstrom040ac322007-03-23 13:28:33 +1100590/*
591 * These are exported to drivers so that they can implement fencing using
592 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
593 */
594
Ben Gamari955b12d2009-02-17 20:08:49 -0500595 /* Debugfs support */
596#if defined(CONFIG_DEBUG_FS)
Lespiau, Damien7d747952013-10-17 19:09:53 +0100597extern int drm_debugfs_create_files(const struct drm_info_list *files,
598 int count, struct dentry *root,
599 struct drm_minor *minor);
600extern int drm_debugfs_remove_files(const struct drm_info_list *files,
601 int count, struct drm_minor *minor);
Thierry Reding66ee52e2013-12-12 15:44:04 +0100602#else
Thierry Reding66ee52e2013-12-12 15:44:04 +0100603static inline int drm_debugfs_create_files(const struct drm_info_list *files,
604 int count, struct dentry *root,
605 struct drm_minor *minor)
606{
607 return 0;
608}
609
610static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
611 int count, struct drm_minor *minor)
612{
613 return 0;
614}
Ben Gamari955b12d2009-02-17 20:08:49 -0500615#endif
616
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 /* sysfs support (drm_sysfs.c) */
Dave Airlief453ba02008-11-07 14:05:41 -0800618extern void drm_sysfs_hotplug_event(struct drm_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Eric Anholt673a3942008-07-30 12:06:12 -0700620
Dave Airlie8410ea32010-12-15 03:16:38 +1000621/*@}*/
622
Dave Airliecc1f7192012-01-05 09:55:22 +0000623/* returns true if currently okay to sleep */
624static __inline__ bool drm_can_sleep(void)
625{
626 if (in_atomic() || in_dbg_master() || irqs_disabled())
627 return false;
628 return true;
629}
630
Jani Nikula373701b2015-11-24 21:21:55 +0200631/* helper for handling conditionals in various for_each macros */
632#define for_each_if(condition) if (!(condition)) {} else
633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634#endif