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