xref: /openbsd/sys/dev/pci/drm/include/drm/drm_ioctl.h (revision 1bb76ff1)
1 /*
2  * Internal Header for the Direct Rendering Manager
3  *
4  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6  * Copyright (c) 2009-2010, Code Aurora Forum.
7  * All rights reserved.
8  *
9  * Author: Rickard E. (Rik) Faith <faith@valinux.com>
10  * Author: Gareth Hughes <gareth@valinux.com>
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice (including the next
20  * paragraph) shall be included in all copies or substantial portions of the
21  * Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
26  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
27  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29  * OTHER DEALINGS IN THE SOFTWARE.
30  */
31 
32 #ifndef _DRM_IOCTL_H_
33 #define _DRM_IOCTL_H_
34 
35 #include <linux/types.h>
36 #include <linux/bitops.h>
37 
38 #include <asm/ioctl.h>
39 
40 struct drm_device;
41 struct drm_file;
42 struct file;
43 
44 /**
45  * drm_ioctl_t - DRM ioctl function type.
46  * @dev: DRM device inode
47  * @data: private pointer of the ioctl call
48  * @file_priv: DRM file this ioctl was made on
49  *
50  * This is the DRM ioctl typedef. Note that drm_ioctl() has alrady copied @data
51  * into kernel-space, and will also copy it back, depending upon the read/write
52  * settings in the ioctl command code.
53  */
54 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
55 			struct drm_file *file_priv);
56 
57 /**
58  * drm_ioctl_compat_t - compatibility DRM ioctl function type.
59  * @filp: file pointer
60  * @cmd: ioctl command code
61  * @arg: DRM file this ioctl was made on
62  *
63  * Just a typedef to make declaring an array of compatibility handlers easier.
64  * New drivers shouldn't screw up the structure layout for their ioctl
65  * structures and hence never need this.
66  */
67 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
68 			       unsigned long arg);
69 
70 #ifdef __linux__
71 #define DRM_IOCTL_NR(n)                _IOC_NR(n)
72 #define DRM_IOCTL_TYPE(n)              _IOC_TYPE(n)
73 #define DRM_MAJOR       226
74 #else
75 #define DRM_IOCTL_NR(n)			((n) & 0xff)
76 #define DRM_IOCTL_TYPE(n)              IOCGROUP(n)
77 #endif
78 
79 /**
80  * enum drm_ioctl_flags - DRM ioctl flags
81  *
82  * Various flags that can be set in &drm_ioctl_desc.flags to control how
83  * userspace can use a given ioctl.
84  */
85 enum drm_ioctl_flags {
86 	/**
87 	 * @DRM_AUTH:
88 	 *
89 	 * This is for ioctl which are used for rendering, and require that the
90 	 * file descriptor is either for a render node, or if it's a
91 	 * legacy/primary node, then it must be authenticated.
92 	 */
93 	DRM_AUTH		= BIT(0),
94 	/**
95 	 * @DRM_MASTER:
96 	 *
97 	 * This must be set for any ioctl which can change the modeset or
98 	 * display state. Userspace must call the ioctl through a primary node,
99 	 * while it is the active master.
100 	 *
101 	 * Note that read-only modeset ioctl can also be called by
102 	 * unauthenticated clients, or when a master is not the currently active
103 	 * one.
104 	 */
105 	DRM_MASTER		= BIT(1),
106 	/**
107 	 * @DRM_ROOT_ONLY:
108 	 *
109 	 * Anything that could potentially wreak a master file descriptor needs
110 	 * to have this flag set. Current that's only for the SETMASTER and
111 	 * DROPMASTER ioctl, which e.g. logind can call to force a non-behaving
112 	 * master (display compositor) into compliance.
113 	 *
114 	 * This is equivalent to callers with the SYSADMIN capability.
115 	 */
116 	DRM_ROOT_ONLY		= BIT(2),
117 	/**
118 	 * @DRM_UNLOCKED:
119 	 *
120 	 * Whether &drm_ioctl_desc.func should be called with the DRM BKL held
121 	 * or not. Enforced as the default for all modern drivers, hence there
122 	 * should never be a need to set this flag.
123 	 *
124 	 * Do not use anywhere else than for the VBLANK_WAIT IOCTL, which is the
125 	 * only legacy IOCTL which needs this.
126 	 */
127 	DRM_UNLOCKED		= BIT(4),
128 	/**
129 	 * @DRM_RENDER_ALLOW:
130 	 *
131 	 * This is used for all ioctl needed for rendering only, for drivers
132 	 * which support render nodes. This should be all new render drivers,
133 	 * and hence it should be always set for any ioctl with DRM_AUTH set.
134 	 * Note though that read-only query ioctl might have this set, but have
135 	 * not set DRM_AUTH because they do not require authentication.
136 	 */
137 	DRM_RENDER_ALLOW	= BIT(5),
138 };
139 
140 /**
141  * struct drm_ioctl_desc - DRM driver ioctl entry
142  * @cmd: ioctl command number, without flags
143  * @flags: a bitmask of &enum drm_ioctl_flags
144  * @func: handler for this ioctl
145  * @name: user-readable name for debug output
146  *
147  * For convenience it's easier to create these using the DRM_IOCTL_DEF_DRV()
148  * macro.
149  */
150 struct drm_ioctl_desc {
151 	unsigned int cmd;
152 	enum drm_ioctl_flags flags;
153 	drm_ioctl_t *func;
154 	const char *name;
155 };
156 
157 /**
158  * DRM_IOCTL_DEF_DRV() - helper macro to fill out a &struct drm_ioctl_desc
159  * @ioctl: ioctl command suffix
160  * @_func: handler for the ioctl
161  * @_flags: a bitmask of &enum drm_ioctl_flags
162  *
163  * Small helper macro to create a &struct drm_ioctl_desc entry. The ioctl
164  * command number is constructed by prepending ``DRM_IOCTL\_`` and passing that
165  * to DRM_IOCTL_NR().
166  */
167 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)				\
168 	[DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = {	\
169 		.cmd = DRM_IOCTL_##ioctl,				\
170 		.func = _func,						\
171 		.flags = _flags,					\
172 		.name = #ioctl						\
173 	}
174 
175 long drm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
176 long drm_ioctl_kernel(struct file *, drm_ioctl_t, void *, u32);
177 #ifdef CONFIG_COMPAT
178 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
179 #else
180 /* Let drm_compat_ioctl be assigned to .compat_ioctl unconditionally */
181 #define drm_compat_ioctl NULL
182 #endif
183 bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
184 
185 int drm_noop(struct drm_device *dev, void *data,
186 	     struct drm_file *file_priv);
187 int drm_invalid_op(struct drm_device *dev, void *data,
188 		   struct drm_file *file_priv);
189 
190 #endif /* _DRM_IOCTL_H_ */
191