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