blob: 5f829d2372da2ec6f303f803bedfd210d4c0ea9a [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/pci.h>
51#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/poll.h>
David Herrmann96993902014-08-29 12:12:37 +020053#include <linux/ratelimit.h>
54#include <linux/sched.h>
55#include <linux/slab.h>
56#include <linux/types.h>
David Herrmannd6db6562014-08-29 12:12:35 +020057#include <linux/vmalloc.h>
David Herrmann96993902014-08-29 12:12:37 +020058#include <linux/workqueue.h>
Chris Wilsonf54d1862016-10-25 13:00:45 +010059#include <linux/dma-fence.h>
Daniel Vetterc6bb9ba2017-03-08 15:12:35 +010060#include <linux/module.h>
David Herrmann96993902014-08-29 12:12:37 +020061
62#include <asm/mman.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#include <asm/pgalloc.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080064#include <linux/uaccess.h>
David Herrmann96993902014-08-29 12:12:37 +020065
David Herrmannd7d2c482014-08-29 12:12:40 +020066#include <uapi/drm/drm.h>
67#include <uapi/drm/drm_mode.h>
68
69#include <drm/drm_agpsupport.h>
70#include <drm/drm_crtc.h>
Laurent Pinchartae4df112016-06-09 12:54:08 +030071#include <drm/drm_fourcc.h>
David Herrmannd7d2c482014-08-29 12:12:40 +020072#include <drm/drm_global.h>
David Herrmann96993902014-08-29 12:12:37 +020073#include <drm/drm_hashtab.h>
David Herrmannd7d2c482014-08-29 12:12:40 +020074#include <drm/drm_mem_util.h>
David Herrmann96993902014-08-29 12:12:37 +020075#include <drm/drm_mm.h>
76#include <drm/drm_os_linux.h>
David Howells19218e42012-10-02 18:01:03 +010077#include <drm/drm_sarea.h>
Daniel Vetter85e634b2016-11-14 12:58:19 +010078#include <drm/drm_drv.h>
Daniel Vetterc6bb9ba2017-03-08 15:12:35 +010079#include <drm/drm_prime.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Paul Gortmakerde477252011-05-26 13:46:22 -040081struct module;
82
Eric Anholtc153f452007-09-03 12:06:45 +100083struct drm_file;
84struct 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;
88struct drm_dma_handle;
Daniel Vetterd9fc9412014-09-23 15:46:53 +020089struct drm_gem_object;
Daniel Vetter3b96a0b2016-06-21 10:54:22 +020090struct drm_master;
Daniel Vetter34a67dd2016-07-15 21:48:01 +020091struct drm_vblank_crtc;
Daniel Vetterc6bb9ba2017-03-08 15:12:35 +010092struct drm_vma_offset_manager;
Eric Anholtc153f452007-09-03 12:06:45 +100093
Steffen Trumtraredb37a92012-10-28 18:28:06 +010094struct device_node;
Steffen Trumtrarebc64e42012-11-14 11:22:52 +010095struct videomode;
Maarten Lankhorst3aac4502014-07-01 12:57:26 +020096struct reservation_object;
Maarten Lankhorstb5e9c1a2014-01-09 11:03:14 +010097struct dma_buf_attachment;
Steffen Trumtrarebc64e42012-11-14 11:22:52 +010098
Lespiau, Damien1414b762014-03-24 15:53:08 +000099/*
Robert Foss346fea62016-04-14 10:34:16 -0400100 * The following categories are defined:
Lespiau, Damien1414b762014-03-24 15:53:08 +0000101 *
102 * CORE: Used in the generic drm code: drm_ioctl.c, drm_mm.c, drm_memory.c, ...
103 * This is the category used by the DRM_DEBUG() macro.
104 *
105 * DRIVER: Used in the vendor specific part of the driver: i915, radeon, ...
106 * This is the category used by the DRM_DEBUG_DRIVER() macro.
107 *
108 * KMS: used in the modesetting code.
109 * This is the category used by the DRM_DEBUG_KMS() macro.
110 *
111 * PRIME: used in the prime code.
112 * This is the category used by the DRM_DEBUG_PRIME() macro.
113 *
Daniel Vetter17a38d92015-02-22 12:24:16 +0100114 * ATOMIC: used in the atomic code.
115 * This is the category used by the DRM_DEBUG_ATOMIC() macro.
116 *
Ville Syrjälä235fabe2015-10-09 22:57:37 +0300117 * VBL: used for verbose debug message in the vblank code
118 * This is the category used by the DRM_DEBUG_VBL() macro.
119 *
Lespiau, Damien1414b762014-03-24 15:53:08 +0000120 * Enabling verbose debug messages is done through the drm.debug parameter,
121 * each category being enabled by a bit.
122 *
123 * drm.debug=0x1 will enable CORE messages
124 * drm.debug=0x2 will enable DRIVER messages
125 * drm.debug=0x3 will enable CORE and DRIVER messages
126 * ...
Ville Syrjälä235fabe2015-10-09 22:57:37 +0300127 * drm.debug=0x3f will enable all messages
Lespiau, Damien1414b762014-03-24 15:53:08 +0000128 *
129 * An interesting feature is that it's possible to enable verbose logging at
130 * run-time by echoing the debug value in its sysfs node:
131 * # echo 0xf > /sys/module/drm/parameters/debug
132 */
Sean Paulc4e68a52016-08-15 16:18:04 -0700133#define DRM_UT_NONE 0x00
yakui_zhao4fefcb22009-06-02 14:09:47 +0800134#define DRM_UT_CORE 0x01
135#define DRM_UT_DRIVER 0x02
136#define DRM_UT_KMS 0x04
Dave Airlie32488772011-11-25 15:21:02 +0000137#define DRM_UT_PRIME 0x08
Daniel Vetter17a38d92015-02-22 12:24:16 +0100138#define DRM_UT_ATOMIC 0x10
Ville Syrjälä235fabe2015-10-09 22:57:37 +0300139#define DRM_UT_VBL 0x20
Rob Clarkfceffb322016-11-05 11:08:09 -0400140#define DRM_UT_STATE 0x40
yakui_zhao4fefcb22009-06-02 14:09:47 +0800141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142/***********************************************************************/
143/** \name DRM template customization defaults */
144/*@{*/
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146/***********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147/** \name Macros to make printk easier */
148/*@{*/
149
Dave Gordon30b0da82016-08-18 18:17:22 +0100150#define _DRM_PRINTK(once, level, fmt, ...) \
151 do { \
152 printk##once(KERN_##level "[" DRM_NAME "] " fmt, \
153 ##__VA_ARGS__); \
154 } while (0)
155
156#define DRM_INFO(fmt, ...) \
157 _DRM_PRINTK(, INFO, fmt, ##__VA_ARGS__)
158#define DRM_NOTE(fmt, ...) \
159 _DRM_PRINTK(, NOTICE, fmt, ##__VA_ARGS__)
160#define DRM_WARN(fmt, ...) \
161 _DRM_PRINTK(, WARNING, fmt, ##__VA_ARGS__)
162
163#define DRM_INFO_ONCE(fmt, ...) \
164 _DRM_PRINTK(_once, INFO, fmt, ##__VA_ARGS__)
165#define DRM_NOTE_ONCE(fmt, ...) \
166 _DRM_PRINTK(_once, NOTICE, fmt, ##__VA_ARGS__)
167#define DRM_WARN_ONCE(fmt, ...) \
168 _DRM_PRINTK(_once, WARNING, fmt, ##__VA_ARGS__)
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170/**
171 * Error output.
172 *
173 * \param fmt printf() like format string.
174 * \param arg arguments
175 */
Sean Paulc4e68a52016-08-15 16:18:04 -0700176#define DRM_DEV_ERROR(dev, fmt, ...) \
177 drm_dev_printk(dev, KERN_ERR, DRM_UT_NONE, __func__, " *ERROR*",\
178 fmt, ##__VA_ARGS__)
179#define DRM_ERROR(fmt, ...) \
Joe Perches6bd488d2016-09-25 19:18:34 -0700180 drm_printk(KERN_ERR, DRM_UT_NONE, fmt, ##__VA_ARGS__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Rob Clark5d13d422013-11-21 14:29:51 -0500182/**
183 * Rate limited error output. Like DRM_ERROR() but won't flood the log.
184 *
185 * \param fmt printf() like format string.
186 * \param arg arguments
187 */
Sean Paulc4e68a52016-08-15 16:18:04 -0700188#define DRM_DEV_ERROR_RATELIMITED(dev, fmt, ...) \
Rob Clark5d13d422013-11-21 14:29:51 -0500189({ \
190 static DEFINE_RATELIMIT_STATE(_rs, \
191 DEFAULT_RATELIMIT_INTERVAL, \
192 DEFAULT_RATELIMIT_BURST); \
193 \
194 if (__ratelimit(&_rs)) \
Sean Paulc4e68a52016-08-15 16:18:04 -0700195 DRM_DEV_ERROR(dev, fmt, ##__VA_ARGS__); \
Rob Clark5d13d422013-11-21 14:29:51 -0500196})
Sean Paulc4e68a52016-08-15 16:18:04 -0700197#define DRM_ERROR_RATELIMITED(fmt, ...) \
198 DRM_DEV_ERROR_RATELIMITED(NULL, fmt, ##__VA_ARGS__)
Rob Clark5d13d422013-11-21 14:29:51 -0500199
Sean Paulc4e68a52016-08-15 16:18:04 -0700200#define DRM_DEV_INFO(dev, fmt, ...) \
201 drm_dev_printk(dev, KERN_INFO, DRM_UT_NONE, __func__, "", fmt, \
202 ##__VA_ARGS__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Sean Paulc4e68a52016-08-15 16:18:04 -0700204#define DRM_DEV_INFO_ONCE(dev, fmt, ...) \
205({ \
206 static bool __print_once __read_mostly; \
207 if (!__print_once) { \
208 __print_once = true; \
209 DRM_DEV_INFO(dev, fmt, ##__VA_ARGS__); \
210 } \
211})
Jani Nikula48b8f632014-01-31 15:49:07 +0200212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213/**
214 * Debug output.
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000215 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 * \param fmt printf() like format string.
217 * \param arg arguments
218 */
Sean Paulc4e68a52016-08-15 16:18:04 -0700219#define DRM_DEV_DEBUG(dev, fmt, args...) \
220 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_CORE, __func__, "", fmt, \
221 ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700222#define DRM_DEBUG(fmt, ...) \
223 drm_printk(KERN_DEBUG, DRM_UT_CORE, fmt, ##__VA_ARGS__)
yakui_zhao4fefcb22009-06-02 14:09:47 +0800224
Sean Paulc4e68a52016-08-15 16:18:04 -0700225#define DRM_DEV_DEBUG_DRIVER(dev, fmt, args...) \
226 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_DRIVER, __func__, "", \
227 fmt, ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700228#define DRM_DEBUG_DRIVER(fmt, ...) \
229 drm_printk(KERN_DEBUG, DRM_UT_DRIVER, fmt, ##__VA_ARGS__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Sean Paulc4e68a52016-08-15 16:18:04 -0700231#define DRM_DEV_DEBUG_KMS(dev, fmt, args...) \
232 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_KMS, __func__, "", fmt, \
233 ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700234#define DRM_DEBUG_KMS(fmt, ...) \
235 drm_printk(KERN_DEBUG, DRM_UT_KMS, fmt, ##__VA_ARGS__)
Sean Paulc4e68a52016-08-15 16:18:04 -0700236
237#define DRM_DEV_DEBUG_PRIME(dev, fmt, args...) \
238 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_PRIME, __func__, "", \
239 fmt, ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700240#define DRM_DEBUG_PRIME(fmt, ...) \
241 drm_printk(KERN_DEBUG, DRM_UT_PRIME, fmt, ##__VA_ARGS__)
Sean Paulc4e68a52016-08-15 16:18:04 -0700242
243#define DRM_DEV_DEBUG_ATOMIC(dev, fmt, args...) \
244 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ATOMIC, __func__, "", \
245 fmt, ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700246#define DRM_DEBUG_ATOMIC(fmt, ...) \
247 drm_printk(KERN_DEBUG, DRM_UT_ATOMIC, fmt, ##__VA_ARGS__)
Sean Paulc4e68a52016-08-15 16:18:04 -0700248
249#define DRM_DEV_DEBUG_VBL(dev, fmt, args...) \
250 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_VBL, __func__, "", fmt, \
251 ##args)
Joe Perches6bd488d2016-09-25 19:18:34 -0700252#define DRM_DEBUG_VBL(fmt, ...) \
253 drm_printk(KERN_DEBUG, DRM_UT_VBL, fmt, ##__VA_ARGS__)
Sean Paulc4e68a52016-08-15 16:18:04 -0700254
255#define _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, level, fmt, args...) \
256({ \
257 static DEFINE_RATELIMIT_STATE(_rs, \
258 DEFAULT_RATELIMIT_INTERVAL, \
259 DEFAULT_RATELIMIT_BURST); \
260 if (__ratelimit(&_rs)) \
261 drm_dev_printk(dev, KERN_DEBUG, DRM_UT_ ## level, \
262 __func__, "", fmt, ##args); \
263})
Lyude27528c62016-08-05 20:30:38 -0400264
265/**
266 * Rate limited debug output. Like DRM_DEBUG() but won't flood the log.
267 *
268 * \param fmt printf() like format string.
269 * \param arg arguments
270 */
Sean Paulc4e68a52016-08-15 16:18:04 -0700271#define DRM_DEV_DEBUG_RATELIMITED(dev, fmt, args...) \
272 DEV__DRM_DEFINE_DEBUG_RATELIMITED(dev, CORE, fmt, ##args)
Lyude27528c62016-08-05 20:30:38 -0400273#define DRM_DEBUG_RATELIMITED(fmt, args...) \
Sean Paulc4e68a52016-08-15 16:18:04 -0700274 DRM_DEV_DEBUG_RATELIMITED(NULL, fmt, ##args)
275#define DRM_DEV_DEBUG_DRIVER_RATELIMITED(dev, fmt, args...) \
276 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, DRIVER, fmt, ##args)
Lyude27528c62016-08-05 20:30:38 -0400277#define DRM_DEBUG_DRIVER_RATELIMITED(fmt, args...) \
Sean Paulc4e68a52016-08-15 16:18:04 -0700278 DRM_DEV_DEBUG_DRIVER_RATELIMITED(NULL, fmt, ##args)
279#define DRM_DEV_DEBUG_KMS_RATELIMITED(dev, fmt, args...) \
280 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, KMS, fmt, ##args)
Lyude27528c62016-08-05 20:30:38 -0400281#define DRM_DEBUG_KMS_RATELIMITED(fmt, args...) \
Sean Paulc4e68a52016-08-15 16:18:04 -0700282 DRM_DEV_DEBUG_KMS_RATELIMITED(NULL, fmt, ##args)
283#define DRM_DEV_DEBUG_PRIME_RATELIMITED(dev, fmt, args...) \
284 _DRM_DEV_DEFINE_DEBUG_RATELIMITED(dev, PRIME, fmt, ##args)
Lyude27528c62016-08-05 20:30:38 -0400285#define DRM_DEBUG_PRIME_RATELIMITED(fmt, args...) \
Sean Paulc4e68a52016-08-15 16:18:04 -0700286 DRM_DEV_DEBUG_PRIME_RATELIMITED(NULL, fmt, ##args)
Lyude27528c62016-08-05 20:30:38 -0400287
Rob Clark65c7dc12016-11-05 11:08:06 -0400288/* Format strings and argument splitters to simplify printing
289 * various "complex" objects
290 */
291#define DRM_MODE_FMT "%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x"
292#define DRM_MODE_ARG(m) \
293 (m)->base.id, (m)->name, (m)->vrefresh, (m)->clock, \
294 (m)->hdisplay, (m)->hsync_start, (m)->hsync_end, (m)->htotal, \
295 (m)->vdisplay, (m)->vsync_start, (m)->vsync_end, (m)->vtotal, \
296 (m)->type, (m)->flags
297
298#define DRM_RECT_FMT "%dx%d%+d%+d"
299#define DRM_RECT_ARG(r) drm_rect_width(r), drm_rect_height(r), (r)->x1, (r)->y1
300
301/* for rect's in fixed-point format: */
302#define DRM_RECT_FP_FMT "%d.%06ux%d.%06u%+d.%06u%+d.%06u"
303#define DRM_RECT_FP_ARG(r) \
304 drm_rect_width(r) >> 16, ((drm_rect_width(r) & 0xffff) * 15625) >> 10, \
305 drm_rect_height(r) >> 16, ((drm_rect_height(r) & 0xffff) * 15625) >> 10, \
306 (r)->x1 >> 16, (((r)->x1 & 0xffff) * 15625) >> 10, \
307 (r)->y1 >> 16, (((r)->y1 & 0xffff) * 15625) >> 10
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309/*@}*/
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311/***********************************************************************/
312/** \name Internal types and structures */
313/*@{*/
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 * Ioctl function type.
319 *
320 * \param inode device inode.
Eric Anholt6c340ea2007-08-25 20:23:09 +1000321 * \param file_priv DRM file private pointer.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 * \param cmd command.
323 * \param arg argument.
324 */
Eric Anholtc153f452007-09-03 12:06:45 +1000325typedef int drm_ioctl_t(struct drm_device *dev, void *data,
326 struct drm_file *file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Dave Airlie9a186642005-06-23 21:29:18 +1000328typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
329 unsigned long arg);
330
Kristian Høgsberg1a959162009-12-02 12:13:48 -0500331#define DRM_IOCTL_NR(n) _IOC_NR(n)
332#define DRM_MAJOR 226
333
Dave Airliea7a2cc32006-01-02 13:54:04 +1100334#define DRM_AUTH 0x1
335#define DRM_MASTER 0x2
336#define DRM_ROOT_ONLY 0x4
Dave Airlief453ba02008-11-07 14:05:41 -0800337#define DRM_CONTROL_ALLOW 0x8
Arnd Bergmanned8b6702009-12-16 22:17:09 +0000338#define DRM_UNLOCKED 0x10
David Herrmann17931262013-08-25 18:29:00 +0200339#define DRM_RENDER_ALLOW 0x20
Dave Airliea7a2cc32006-01-02 13:54:04 +1100340
Eric Anholtc153f452007-09-03 12:06:45 +1000341struct drm_ioctl_desc {
342 unsigned int cmd;
Dave Airliea7a2cc32006-01-02 13:54:04 +1100343 int flags;
Richard Kennedyc972d752009-03-18 17:26:44 +0000344 drm_ioctl_t *func;
Chris Cumminsb9434d02013-05-09 14:20:40 +0100345 const char *name;
Eric Anholtc153f452007-09-03 12:06:45 +1000346};
347
348/**
349 * Creates a driver or general drm_ioctl_desc array entry for the given
350 * ioctl, for use by drm_ioctl().
351 */
Dave Airlie1b2f1482010-08-14 20:20:34 +1000352
Emil Velikov066626d2015-03-30 17:10:36 +0000353#define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
354 [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = { \
355 .cmd = DRM_IOCTL_##ioctl, \
356 .func = _func, \
357 .flags = _flags, \
358 .name = #ioctl \
359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Kristian Høgsbergc9a9c5e2009-09-12 04:33:34 +1000361/* Event queued up for userspace to read */
362struct drm_pending_event {
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200363 struct completion *completion;
Daniel Vetter24835e42016-12-21 11:23:30 +0100364 void (*completion_release)(struct completion *completion);
Kristian Høgsbergc9a9c5e2009-09-12 04:33:34 +1000365 struct drm_event *event;
Chris Wilsonf54d1862016-10-25 13:00:45 +0100366 struct dma_fence *fence;
Kristian Høgsbergc9a9c5e2009-09-12 04:33:34 +1000367 struct list_head link;
Daniel Vetter681047b2016-01-25 22:16:43 +0100368 struct list_head pending_link;
Kristian Høgsbergc9a9c5e2009-09-12 04:33:34 +1000369 struct drm_file *file_priv;
Jesse Barnesb9c2c9a2010-07-01 16:48:09 -0700370 pid_t pid; /* pid of requester, no guarantee it's valid by the time
371 we deliver the event, for tracing only */
Kristian Høgsbergc9a9c5e2009-09-12 04:33:34 +1000372};
373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374/** File private data */
Dave Airlie84b1fd12007-07-11 15:53:27 +1000375struct drm_file {
Chris Wilson39868bd2013-10-29 08:55:58 +0000376 unsigned authenticated :1;
Chris Wilson39868bd2013-10-29 08:55:58 +0000377 /* true when the client has asked us to expose stereo 3D mode flags */
378 unsigned stereo_allowed :1;
Matt Roper681e7ec2014-04-01 15:22:42 -0700379 /*
380 * true if client understands CRTC primary planes and cursor planes
381 * in the plane list
382 */
383 unsigned universal_planes:1;
Rob Clark88a48e22014-12-18 16:01:50 -0500384 /* true if client understands atomic properties */
385 unsigned atomic:1;
Thomas Hellstroma0af2e52015-12-02 09:24:46 -0800386 /*
Daniel Vetter0aae5922016-06-21 10:54:21 +0200387 * This client is the creator of @master.
Thomas Hellstroma0af2e52015-12-02 09:24:46 -0800388 * Protected by struct drm_device::master_mutex.
389 */
Daniel Vetter0aae5922016-06-21 10:54:21 +0200390 unsigned is_master:1;
Chris Wilson39868bd2013-10-29 08:55:58 +0000391
Eric W. Biederman5fce5e02012-02-07 16:47:26 -0800392 struct pid *pid;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000393 drm_magic_t magic;
Dave Airliebd1b3312007-05-26 05:01:51 +1000394 struct list_head lhead;
Dave Airlie2c14f282008-04-21 16:47:32 +1000395 struct drm_minor *minor;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000396 unsigned long lock_count;
Dave Airlie7c1c2872008-11-28 14:22:24 +1000397
Eric Anholt673a3942008-07-30 12:06:12 -0700398 /** Mapping of mm object handles to object pointers. */
399 struct idr object_idr;
400 /** Lock for synchronization of access to object_idr. */
401 spinlock_t table_lock;
Dave Airlie7c1c2872008-11-28 14:22:24 +1000402
Eric Anholt6c340ea2007-08-25 20:23:09 +1000403 struct file *filp;
Dave Airlie8562b3f2007-11-05 12:37:41 +1000404 void *driver_priv;
Dave Airlie7c1c2872008-11-28 14:22:24 +1000405
Dave Airlie7c1c2872008-11-28 14:22:24 +1000406 struct drm_master *master; /* master this node is currently associated with
Daniel Vetter95c081c2016-06-21 10:54:12 +0200407 N.B. not always dev->master */
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100408 /**
409 * fbs - List of framebuffers associated with this file.
410 *
411 * Protected by fbs_lock. Note that the fbs list holds a reference on
412 * the fb object to prevent it from untimely disappearing.
413 */
Dave Airlief453ba02008-11-07 14:05:41 -0800414 struct list_head fbs;
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100415 struct mutex fbs_lock;
Kristian Høgsbergc9a9c5e2009-09-12 04:33:34 +1000416
Daniel Stonee2f5d2e2015-05-22 13:34:51 +0100417 /** User-created blob properties; this retains a reference on the
418 * property. */
419 struct list_head blobs;
420
Kristian Høgsbergc9a9c5e2009-09-12 04:33:34 +1000421 wait_queue_head_t event_wait;
Daniel Vetter681047b2016-01-25 22:16:43 +0100422 struct list_head pending_event_list;
Kristian Høgsbergc9a9c5e2009-09-12 04:33:34 +1000423 struct list_head event_list;
424 int event_space;
Dave Airlie32488772011-11-25 15:21:02 +0000425
Chris Wilson9b2c0b72015-11-25 14:39:03 +0000426 struct mutex event_read_lock;
427
Dave Airlie32488772011-11-25 15:21:02 +0000428 struct drm_prime_file_private prime;
Dave Airlie84b1fd12007-07-11 15:53:27 +1000429};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431/**
432 * Lock data.
433 */
Dave Airlie55910512007-07-11 16:53:40 +1000434struct drm_lock_data {
Dave Airliec60ce622007-07-11 15:27:12 +1000435 struct drm_hw_lock *hw_lock; /**< Hardware lock */
Dave Airlie8562b3f2007-11-05 12:37:41 +1000436 /** Private of lock holder's file (NULL=kernel) */
437 struct drm_file *file_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000439 unsigned long lock_time; /**< Time of last lock in jiffies */
Thomas Hellstrom040ac322007-03-23 13:28:33 +1100440 spinlock_t spinlock;
441 uint32_t kernel_waiters;
442 uint32_t user_waiters;
443 int idle_has_lock;
Dave Airlie55910512007-07-11 16:53:40 +1000444};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Mario Kleiner27641c32010-10-23 04:20:23 +0200446/* Flags and return codes for get_vblank_timestamp() driver function. */
447#define DRM_CALLED_FROM_VBLIRQ 1
448#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
Daniel Vetter3d3cbd82014-09-10 17:36:11 +0200449#define DRM_VBLANKTIME_IN_VBLANK (1 << 1)
Mario Kleiner27641c32010-10-23 04:20:23 +0200450
451/* get_scanout_position() return flags */
452#define DRM_SCANOUTPOS_VALID (1 << 0)
Daniel Vetter3d3cbd82014-09-10 17:36:11 +0200453#define DRM_SCANOUTPOS_IN_VBLANK (1 << 1)
Mario Kleiner27641c32010-10-23 04:20:23 +0200454#define DRM_SCANOUTPOS_ACCURATE (1 << 2)
455
David Herrmanncb8a2392014-01-29 12:31:40 +0100456enum drm_minor_type {
David Herrmanna3ccc462016-08-03 20:04:25 +0200457 DRM_MINOR_PRIMARY,
David Herrmanncb8a2392014-01-29 12:31:40 +0100458 DRM_MINOR_CONTROL,
459 DRM_MINOR_RENDER,
460 DRM_MINOR_CNT,
461};
Dave Airlie2c14f282008-04-21 16:47:32 +1000462
Ben Gamari955b12d2009-02-17 20:08:49 -0500463/**
464 * Info file list entry. This structure represents a debugfs or proc file to
465 * be created by the drm core
466 */
467struct drm_info_list {
468 const char *name; /** file name */
469 int (*show)(struct seq_file*, void*); /** show callback */
470 u32 driver_features; /**< Required driver features for this entry */
471 void *data;
472};
473
474/**
475 * debugfs node structure. This structure represents a debugfs file.
476 */
477struct drm_info_node {
478 struct list_head list;
479 struct drm_minor *minor;
David Howellsce089b52013-04-12 15:23:25 +0100480 const struct drm_info_list *info_ent;
Ben Gamari955b12d2009-02-17 20:08:49 -0500481 struct dentry *dent;
482};
483
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484/**
Dave Airlie2c14f282008-04-21 16:47:32 +1000485 * DRM minor structure. This structure represents a drm minor number.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 */
Dave Airlie2c14f282008-04-21 16:47:32 +1000487struct drm_minor {
488 int index; /**< Minor device number */
489 int type; /**< Control or render */
Dave Airlie5bdebb12013-10-11 14:07:25 +1000490 struct device *kdev; /**< Linux device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 struct drm_device *dev;
Ben Gamari955b12d2009-02-17 20:08:49 -0500492
Ben Gamari955b12d2009-02-17 20:08:49 -0500493 struct dentry *debugfs_root;
Marcin Slusarzb3e067c2011-11-09 22:20:35 +0100494
495 struct list_head debugfs_list;
496 struct mutex debugfs_lock; /* Protects debugfs_list. */
Dave Airlie84b1fd12007-07-11 15:53:27 +1000497};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
499/**
500 * DRM device structure. This structure represent a complete card that
501 * may contain multiple heads.
502 */
Dave Airlie84b1fd12007-07-11 15:53:27 +1000503struct drm_device {
Daniel Vetterb3f23332013-12-11 11:34:31 +0100504 struct list_head legacy_dev_list;/**< list of devices per driver for stealth attach cleanup */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000505 int if_version; /**< Highest interface version set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
David Herrmann45e212d2014-01-28 16:00:35 +0100507 /** \name Lifetime Management */
508 /*@{ */
David Herrmann099d1c22014-01-29 10:21:36 +0100509 struct kref ref; /**< Object ref-count */
David Herrmann45e212d2014-01-28 16:00:35 +0100510 struct device *dev; /**< Device structure of bus-device */
511 struct drm_driver *driver; /**< DRM driver managing the device */
512 void *dev_private; /**< DRM driver private data */
David Herrmann45e212d2014-01-28 16:00:35 +0100513 struct drm_minor *control; /**< Control node */
514 struct drm_minor *primary; /**< Primary node */
515 struct drm_minor *render; /**< Render node */
Daniel Vettere6e7b482017-01-12 17:15:56 +0100516 bool registered;
Daniel Vetter95c081c2016-06-21 10:54:12 +0200517
518 /* currently active master for this device. Protected by master_mutex */
519 struct drm_master *master;
520
David Herrmann45e212d2014-01-28 16:00:35 +0100521 atomic_t unplugged; /**< Flag whether dev is dead */
David Herrmann07b48c32014-03-16 13:13:51 +0100522 struct inode *anon_inode; /**< inode for private address-space */
Thierry Redingca8e2ad2014-04-11 15:23:00 +0200523 char *unique; /**< unique name of the device */
David Herrmann45e212d2014-01-28 16:00:35 +0100524 /*@} */
525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 /** \name Locks */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000527 /*@{ */
Dave Airlie30e2fb12006-02-02 19:37:46 +1100528 struct mutex struct_mutex; /**< For others */
Thomas Hellstromc996fd02014-02-25 19:57:44 +0100529 struct mutex master_mutex; /**< For drm_minor::master and drm_file::is_master */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000530 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532 /** \name Usage Counters */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000533 /*@{ */
Daniel Vetterfc8fd402013-11-03 20:46:34 +0100534 int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
Daniel Vetter2177a212013-12-16 11:21:06 +0100535 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000536 int buf_use; /**< Buffers in use -- cannot alloc */
537 atomic_t buf_alloc; /**< Buffer allocation in progress */
538 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200540 struct mutex filelist_mutex;
Dave Airliebd1b3312007-05-26 05:01:51 +1000541 struct list_head filelist;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543 /** \name Memory management */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000544 /*@{ */
Dave Airliebd1b3312007-05-26 05:01:51 +1000545 struct list_head maplist; /**< Linked list of regions */
Dave Airliee0be4282007-07-12 10:26:44 +1000546 struct drm_open_hash map_hash; /**< User token hash table for maps */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 /** \name Context handle management */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000549 /*@{ */
Dave Airliebd1b3312007-05-26 05:01:51 +1000550 struct list_head ctxlist; /**< Linked list of context handles */
Dave Airlie30e2fb12006-02-02 19:37:46 +1100551 struct mutex ctxlist_mutex; /**< For ctxlist */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
Dave Airlie62968142007-07-17 10:46:52 +1000553 struct idr ctx_idr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Dave Airliebd1b3312007-05-26 05:01:51 +1000555 struct list_head vmalist; /**< List of vmas (for debugging) */
Dave Airlief453ba02008-11-07 14:05:41 -0800556
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000557 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Daniel Vettera344a7e2011-10-26 00:54:41 +0200559 /** \name DMA support */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000560 /*@{ */
Dave Airliecdd55a22007-07-11 16:32:08 +1000561 struct drm_device_dma *dma; /**< Optional pointer for DMA support */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000562 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
564 /** \name Context support */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000565 /*@{ */
Daniel Vetter7c1a38e32013-12-16 11:21:15 +0100566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 __volatile__ long context_flag; /**< Context swapping flag */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000568 int last_context; /**< Last current context */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000569 /*@} */
570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 /** \name VBLANK IRQ support */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000572 /*@{ */
Thierry Redingb46004b2014-12-17 16:41:41 +0100573 bool irq_enabled;
574 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700576 /*
Ville Syrjälä00185e62014-08-06 14:49:54 +0300577 * If true, vblank interrupt will be disabled immediately when the
578 * refcount drops to zero, as opposed to via the vblank disable
579 * timer.
580 * This can be set to true it the hardware has a working vblank
581 * counter and the driver uses drm_vblank_on() and drm_vblank_off()
582 * appropriately.
583 */
584 bool vblank_disable_immediate;
585
Ville Syrjälä5380e922013-10-04 14:53:36 +0300586 /* array of size num_crtcs */
587 struct drm_vblank_crtc *vblank;
588
Mario Kleiner27641c32010-10-23 04:20:23 +0200589 spinlock_t vblank_time_lock; /**< Protects vblank count and time updates during vblank enable/disable */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000590 spinlock_t vbl_lock;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700591
592 u32 max_vblank_count; /**< size of vblank counter register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
Kristian Høgsbergc9a9c5e2009-09-12 04:33:34 +1000594 /**
595 * List of events
596 */
597 struct list_head vblank_event_list;
598 spinlock_t event_lock;
599
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000600 /*@} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Dave Airlie55910512007-07-11 16:53:40 +1000602 struct drm_agp_head *agp; /**< AGP data */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000604 struct pci_dev *pdev; /**< PCI device structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#ifdef __alpha__
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 struct pci_controller *hose;
607#endif
Jordan Crousedcdb1672010-05-27 13:40:25 -0600608
609 struct platform_device *platformdev; /**< Platform device struture */
Dave Airliedc5698e2013-09-09 10:02:56 +1000610 struct virtio_device *virtdev;
Jordan Crousedcdb1672010-05-27 13:40:25 -0600611
Dave Airlie55910512007-07-11 16:53:40 +1000612 struct drm_sg_mem *sg; /**< Scatter gather memory */
Dave Airlie19227562011-02-24 08:35:06 +1000613 unsigned int num_crtcs; /**< Number of CRTCs on this device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
David Herrmann69d516c2014-08-29 12:12:39 +0200615 struct {
616 int context;
617 struct drm_hw_lock *lock;
618 } sigdata;
619
Benjamin Herrenschmidtf77d3902009-02-02 16:55:46 +1100620 struct drm_local_map *agp_buffer_map;
Dave Airlied1f2b552005-08-05 22:11:22 +1000621 unsigned int agp_buffer_token;
=?utf-8?q?Michel_D=C3=A4nzer?=bea56792006-10-24 23:04:19 +1000622
Rob Clark417009fb2014-11-25 20:33:10 -0500623 struct drm_mode_config mode_config; /**< Current mode config */
Dave Airlief453ba02008-11-07 14:05:41 -0800624
Eric Anholt673a3942008-07-30 12:06:12 -0700625 /** \name GEM information */
626 /*@{ */
Daniel Vettercd4f0132013-08-15 00:02:44 +0200627 struct mutex object_name_lock;
Eric Anholt673a3942008-07-30 12:06:12 -0700628 struct idr object_name_idr;
Daniel Vetterb04a5902013-12-11 14:24:46 +0100629 struct drm_vma_offset_manager *vma_offset_manager;
Eric Anholt673a3942008-07-30 12:06:12 -0700630 /*@} */
Dave Airlie5bcf7192010-12-07 09:20:40 +1000631 int switch_power_state;
Dave Airlie84b1fd12007-07-11 15:53:27 +1000632};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Dhinakaran Pandiyana743d752016-12-22 00:50:42 -0800634/**
635 * drm_drv_uses_atomic_modeset - check if the driver implements
636 * atomic_commit()
637 * @dev: DRM device
638 *
639 * This check is useful if drivers do not have DRIVER_ATOMIC set but
640 * have atomic modesetting internally implemented.
641 */
642static inline bool drm_drv_uses_atomic_modeset(struct drm_device *dev)
643{
644 return dev->mode_config.funcs->atomic_commit != NULL;
645}
646
Daniel Vetter34a67dd2016-07-15 21:48:01 +0200647#include <drm/drm_irq.h>
648
Dave Airlie5bcf7192010-12-07 09:20:40 +1000649#define DRM_SWITCH_POWER_ON 0
650#define DRM_SWITCH_POWER_OFF 1
651#define DRM_SWITCH_POWER_CHANGING 2
Dave Airlie13bb9cc2012-09-12 15:55:05 +1000652#define DRM_SWITCH_POWER_DYNAMIC_OFF 3
Dave Airlie5bcf7192010-12-07 09:20:40 +1000653
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000654static __inline__ int drm_core_check_feature(struct drm_device *dev,
655 int feature)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656{
657 return ((dev->driver->driver_features & feature) ? 1 : 0);
658}
659
Dave Airlie2c07a212012-02-20 14:18:07 +0000660static inline void drm_device_set_unplugged(struct drm_device *dev)
661{
662 smp_wmb();
663 atomic_set(&dev->unplugged, 1);
664}
665
666static inline int drm_device_is_unplugged(struct drm_device *dev)
667{
668 int ret = atomic_read(&dev->unplugged);
669 smp_rmb();
670 return ret;
671}
672
Thomas Hellstrom43683052014-03-13 11:07:44 +0100673static inline bool drm_is_render_client(const struct drm_file *file_priv)
David Herrmann17931262013-08-25 18:29:00 +0200674{
675 return file_priv->minor->type == DRM_MINOR_RENDER;
676}
677
Thomas Hellstromac05dbc2014-02-19 14:21:48 +0100678static inline bool drm_is_control_client(const struct drm_file *file_priv)
679{
680 return file_priv->minor->type == DRM_MINOR_CONTROL;
681}
682
Thomas Hellstrom43683052014-03-13 11:07:44 +0100683static inline bool drm_is_primary_client(const struct drm_file *file_priv)
684{
David Herrmanna3ccc462016-08-03 20:04:25 +0200685 return file_priv->minor->type == DRM_MINOR_PRIMARY;
Thomas Hellstrom43683052014-03-13 11:07:44 +0100686}
687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688/******************************************************************/
689/** \name Internal function definitions */
690/*@{*/
691
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 /* Driver support (drm_drv.h) */
Thomas Hellstrom51010202015-07-10 22:31:08 -0700693extern int drm_ioctl_permit(u32 flags, struct drm_file *file_priv);
Arnd Bergmanned8b6702009-12-16 22:17:09 +0000694extern long drm_ioctl(struct file *filp,
695 unsigned int cmd, unsigned long arg);
Jani Nikula55edf412016-11-01 17:40:44 +0200696#ifdef CONFIG_COMPAT
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000697extern long drm_compat_ioctl(struct file *filp,
698 unsigned int cmd, unsigned long arg);
Jani Nikula55edf412016-11-01 17:40:44 +0200699#else
700/* Let drm_compat_ioctl be assigned to .compat_ioctl unconditionally */
701#define drm_compat_ioctl NULL
702#endif
Thomas Hellstrom4beb6d92014-02-26 15:51:57 +0100703extern bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Daniel Vetterbcb877e2016-01-11 22:40:55 +0100705/* File Operations (drm_fops.c) */
706int drm_open(struct inode *inode, struct file *filp);
707ssize_t drm_read(struct file *filp, char __user *buffer,
708 size_t count, loff_t *offset);
709int drm_release(struct inode *inode, struct file *filp);
Daniel Vetterbcb877e2016-01-11 22:40:55 +0100710unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
Daniel Vetter4020b222016-01-28 12:01:04 +0100711int drm_event_reserve_init_locked(struct drm_device *dev,
712 struct drm_file *file_priv,
713 struct drm_pending_event *p,
714 struct drm_event *e);
Daniel Vetter2dd500f2016-01-11 22:40:56 +0100715int drm_event_reserve_init(struct drm_device *dev,
716 struct drm_file *file_priv,
717 struct drm_pending_event *p,
718 struct drm_event *e);
719void drm_event_cancel_free(struct drm_device *dev,
720 struct drm_pending_event *p);
Daniel Vetterfb740cf2016-01-11 22:40:59 +0100721void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
722void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
Daniel Vetter78238752014-09-10 12:43:55 +0200724/* Misc. IOCTL support (drm_ioctl.c) */
725int drm_noop(struct drm_device *dev, void *data,
726 struct drm_file *file_priv);
Daniel Vetter4b635392015-09-08 13:56:26 +0200727int drm_invalid_op(struct drm_device *dev, void *data,
728 struct drm_file *file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
Thomas Hellstrom040ac322007-03-23 13:28:33 +1100730/*
731 * These are exported to drivers so that they can implement fencing using
732 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
733 */
734
Ben Gamari955b12d2009-02-17 20:08:49 -0500735 /* Debugfs support */
736#if defined(CONFIG_DEBUG_FS)
Lespiau, Damien7d747952013-10-17 19:09:53 +0100737extern int drm_debugfs_create_files(const struct drm_info_list *files,
738 int count, struct dentry *root,
739 struct drm_minor *minor);
740extern int drm_debugfs_remove_files(const struct drm_info_list *files,
741 int count, struct drm_minor *minor);
Thierry Reding66ee52e2013-12-12 15:44:04 +0100742#else
Thierry Reding66ee52e2013-12-12 15:44:04 +0100743static inline int drm_debugfs_create_files(const struct drm_info_list *files,
744 int count, struct dentry *root,
745 struct drm_minor *minor)
746{
747 return 0;
748}
749
750static inline int drm_debugfs_remove_files(const struct drm_info_list *files,
751 int count, struct drm_minor *minor)
752{
753 return 0;
754}
Ben Gamari955b12d2009-02-17 20:08:49 -0500755#endif
756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Daniel Vetterba8286f2014-09-11 07:43:25 +0200758extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size,
759 size_t align);
760extern void drm_pci_free(struct drm_device *dev, struct drm_dma_handle * dmah);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 /* sysfs support (drm_sysfs.c) */
Dave Airlief453ba02008-11-07 14:05:41 -0800763extern void drm_sysfs_hotplug_event(struct drm_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Eric Anholt673a3942008-07-30 12:06:12 -0700765
Dave Airlie8410ea32010-12-15 03:16:38 +1000766/*@}*/
767
Dave Airlie8410ea32010-12-15 03:16:38 +1000768extern int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
769extern void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
Thierry Redinga9e3c902014-08-05 13:37:47 +0200770#ifdef CONFIG_PCI
Dave Airlie8410ea32010-12-15 03:16:38 +1000771extern int drm_get_pci_dev(struct pci_dev *pdev,
Jordan Crousedcdb1672010-05-27 13:40:25 -0600772 const struct pci_device_id *ent,
773 struct drm_driver *driver);
David Herrmann915b4d12014-08-29 12:12:43 +0200774extern int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master);
Thierry Redinga9e3c902014-08-05 13:37:47 +0200775#else
776static inline int drm_get_pci_dev(struct pci_dev *pdev,
777 const struct pci_device_id *ent,
778 struct drm_driver *driver)
779{
780 return -ENOSYS;
781}
782
783static inline int drm_pci_set_busid(struct drm_device *dev,
784 struct drm_master *master)
785{
786 return -ENOSYS;
787}
788#endif
Dave Airlie8410ea32010-12-15 03:16:38 +1000789
Dave Airlief4297782012-06-27 08:35:53 +0100790#define DRM_PCIE_SPEED_25 1
791#define DRM_PCIE_SPEED_50 2
792#define DRM_PCIE_SPEED_80 4
793
794extern int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *speed_mask);
Alex Deucher60d8edd2015-11-11 23:14:39 -0500795extern int drm_pcie_get_max_link_width(struct drm_device *dev, u32 *mlw);
Dave Airlie8410ea32010-12-15 03:16:38 +1000796
797/* platform section */
798extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);
Dave Airlie8410ea32010-12-15 03:16:38 +1000799
Dave Airliecc1f7192012-01-05 09:55:22 +0000800/* returns true if currently okay to sleep */
801static __inline__ bool drm_can_sleep(void)
802{
803 if (in_atomic() || in_dbg_master() || irqs_disabled())
804 return false;
805 return true;
806}
807
Jani Nikula373701b2015-11-24 21:21:55 +0200808/* helper for handling conditionals in various for_each macros */
809#define for_each_if(condition) if (!(condition)) {} else
810
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811#endif