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