1*5579de5fSriastradh /* $NetBSD: drm_ioctl.h,v 1.5 2022/10/15 15:19:28 riastradh Exp $ */ 24e390cabSriastradh 34e390cabSriastradh /* 44e390cabSriastradh * Internal Header for the Direct Rendering Manager 54e390cabSriastradh * 64e390cabSriastradh * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 74e390cabSriastradh * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 84e390cabSriastradh * Copyright (c) 2009-2010, Code Aurora Forum. 94e390cabSriastradh * All rights reserved. 104e390cabSriastradh * 114e390cabSriastradh * Author: Rickard E. (Rik) Faith <faith@valinux.com> 124e390cabSriastradh * Author: Gareth Hughes <gareth@valinux.com> 134e390cabSriastradh * 144e390cabSriastradh * Permission is hereby granted, free of charge, to any person obtaining a 154e390cabSriastradh * copy of this software and associated documentation files (the "Software"), 164e390cabSriastradh * to deal in the Software without restriction, including without limitation 174e390cabSriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense, 184e390cabSriastradh * and/or sell copies of the Software, and to permit persons to whom the 194e390cabSriastradh * Software is furnished to do so, subject to the following conditions: 204e390cabSriastradh * 214e390cabSriastradh * The above copyright notice and this permission notice (including the next 224e390cabSriastradh * paragraph) shall be included in all copies or substantial portions of the 234e390cabSriastradh * Software. 244e390cabSriastradh * 254e390cabSriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 264e390cabSriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 274e390cabSriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 284e390cabSriastradh * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 294e390cabSriastradh * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 304e390cabSriastradh * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 314e390cabSriastradh * OTHER DEALINGS IN THE SOFTWARE. 324e390cabSriastradh */ 334e390cabSriastradh 344e390cabSriastradh #ifndef _DRM_IOCTL_H_ 354e390cabSriastradh #define _DRM_IOCTL_H_ 364e390cabSriastradh 374e390cabSriastradh #include <linux/types.h> 384e390cabSriastradh #include <linux/bitops.h> 394e390cabSriastradh 404e390cabSriastradh #include <asm/ioctl.h> 414e390cabSriastradh 424e390cabSriastradh struct drm_device; 434e390cabSriastradh struct drm_file; 444e390cabSriastradh struct file; 454e390cabSriastradh 464e390cabSriastradh /** 474e390cabSriastradh * drm_ioctl_t - DRM ioctl function type. 484e390cabSriastradh * @dev: DRM device inode 494e390cabSriastradh * @data: private pointer of the ioctl call 504e390cabSriastradh * @file_priv: DRM file this ioctl was made on 514e390cabSriastradh * 524e390cabSriastradh * This is the DRM ioctl typedef. Note that drm_ioctl() has alrady copied @data 534e390cabSriastradh * into kernel-space, and will also copy it back, depending upon the read/write 544e390cabSriastradh * settings in the ioctl command code. 554e390cabSriastradh */ 564e390cabSriastradh typedef int drm_ioctl_t(struct drm_device *dev, void *data, 574e390cabSriastradh struct drm_file *file_priv); 584e390cabSriastradh 594e390cabSriastradh /** 604e390cabSriastradh * drm_ioctl_compat_t - compatibility DRM ioctl function type. 614e390cabSriastradh * @filp: file pointer 624e390cabSriastradh * @cmd: ioctl command code 634e390cabSriastradh * @arg: DRM file this ioctl was made on 644e390cabSriastradh * 654e390cabSriastradh * Just a typedef to make declaring an array of compatibility handlers easier. 664e390cabSriastradh * New drivers shouldn't screw up the structure layout for their ioctl 674e390cabSriastradh * structures and hence never need this. 684e390cabSriastradh */ 694e390cabSriastradh typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd, 704e390cabSriastradh unsigned long arg); 714e390cabSriastradh 721db231d3Sriastradh #ifdef __NetBSD__ 731db231d3Sriastradh /* XXX Kludge...is there a better way to do this? */ 741db231d3Sriastradh #define DRM_IOCTL_NR(n) \ 751db231d3Sriastradh (IOCBASECMD(n) &~ (IOC_DIRMASK | (IOCGROUP(n) << IOCGROUP_SHIFT))) 761db231d3Sriastradh #define DRM_MAJOR cdevsw_lookup_major(&drm_cdevsw) 771db231d3Sriastradh #else 784e390cabSriastradh #define DRM_IOCTL_NR(n) _IOC_NR(n) 794e390cabSriastradh #define DRM_MAJOR 226 801db231d3Sriastradh #endif 814e390cabSriastradh 824e390cabSriastradh /** 834e390cabSriastradh * enum drm_ioctl_flags - DRM ioctl flags 844e390cabSriastradh * 854e390cabSriastradh * Various flags that can be set in &drm_ioctl_desc.flags to control how 864e390cabSriastradh * userspace can use a given ioctl. 874e390cabSriastradh */ 884e390cabSriastradh enum drm_ioctl_flags { 894e390cabSriastradh /** 904e390cabSriastradh * @DRM_AUTH: 914e390cabSriastradh * 924e390cabSriastradh * This is for ioctl which are used for rendering, and require that the 934e390cabSriastradh * file descriptor is either for a render node, or if it's a 944e390cabSriastradh * legacy/primary node, then it must be authenticated. 954e390cabSriastradh */ 964e390cabSriastradh DRM_AUTH = BIT(0), 974e390cabSriastradh /** 984e390cabSriastradh * @DRM_MASTER: 994e390cabSriastradh * 1004e390cabSriastradh * This must be set for any ioctl which can change the modeset or 1014e390cabSriastradh * display state. Userspace must call the ioctl through a primary node, 1024e390cabSriastradh * while it is the active master. 1034e390cabSriastradh * 1044e390cabSriastradh * Note that read-only modeset ioctl can also be called by 1054e390cabSriastradh * unauthenticated clients, or when a master is not the currently active 1064e390cabSriastradh * one. 1074e390cabSriastradh */ 1084e390cabSriastradh DRM_MASTER = BIT(1), 1094e390cabSriastradh /** 1104e390cabSriastradh * @DRM_ROOT_ONLY: 1114e390cabSriastradh * 1124e390cabSriastradh * Anything that could potentially wreak a master file descriptor needs 1134e390cabSriastradh * to have this flag set. Current that's only for the SETMASTER and 1144e390cabSriastradh * DROPMASTER ioctl, which e.g. logind can call to force a non-behaving 1154e390cabSriastradh * master (display compositor) into compliance. 1164e390cabSriastradh * 1174e390cabSriastradh * This is equivalent to callers with the SYSADMIN capability. 1184e390cabSriastradh */ 1194e390cabSriastradh DRM_ROOT_ONLY = BIT(2), 1204e390cabSriastradh /** 1214e390cabSriastradh * @DRM_UNLOCKED: 1224e390cabSriastradh * 1234e390cabSriastradh * Whether &drm_ioctl_desc.func should be called with the DRM BKL held 1244e390cabSriastradh * or not. Enforced as the default for all modern drivers, hence there 1254e390cabSriastradh * should never be a need to set this flag. 1264e390cabSriastradh * 1274e390cabSriastradh * Do not use anywhere else than for the VBLANK_WAIT IOCTL, which is the 1284e390cabSriastradh * only legacy IOCTL which needs this. 1294e390cabSriastradh */ 1304e390cabSriastradh DRM_UNLOCKED = BIT(4), 1314e390cabSriastradh /** 1324e390cabSriastradh * @DRM_RENDER_ALLOW: 1334e390cabSriastradh * 1344e390cabSriastradh * This is used for all ioctl needed for rendering only, for drivers 1354e390cabSriastradh * which support render nodes. This should be all new render drivers, 1364e390cabSriastradh * and hence it should be always set for any ioctl with DRM_AUTH set. 1374e390cabSriastradh * Note though that read-only query ioctl might have this set, but have 1384e390cabSriastradh * not set DRM_AUTH because they do not require authentication. 1394e390cabSriastradh */ 1404e390cabSriastradh DRM_RENDER_ALLOW = BIT(5), 1414e390cabSriastradh }; 1424e390cabSriastradh 1434e390cabSriastradh /** 1444e390cabSriastradh * struct drm_ioctl_desc - DRM driver ioctl entry 1454e390cabSriastradh * @cmd: ioctl command number, without flags 1464e390cabSriastradh * @flags: a bitmask of &enum drm_ioctl_flags 1474e390cabSriastradh * @func: handler for this ioctl 1484e390cabSriastradh * @name: user-readable name for debug output 1494e390cabSriastradh * 1504e390cabSriastradh * For convenience it's easier to create these using the DRM_IOCTL_DEF_DRV() 1514e390cabSriastradh * macro. 1524e390cabSriastradh */ 1534e390cabSriastradh struct drm_ioctl_desc { 1544e390cabSriastradh unsigned int cmd; 1554e390cabSriastradh enum drm_ioctl_flags flags; 1564e390cabSriastradh drm_ioctl_t *func; 1574e390cabSriastradh const char *name; 1584e390cabSriastradh }; 1594e390cabSriastradh 1604e390cabSriastradh /** 1614e390cabSriastradh * DRM_IOCTL_DEF_DRV() - helper macro to fill out a &struct drm_ioctl_desc 1624e390cabSriastradh * @ioctl: ioctl command suffix 1634e390cabSriastradh * @_func: handler for the ioctl 1644e390cabSriastradh * @_flags: a bitmask of &enum drm_ioctl_flags 1654e390cabSriastradh * 1664e390cabSriastradh * Small helper macro to create a &struct drm_ioctl_desc entry. The ioctl 1674e390cabSriastradh * command number is constructed by prepending ``DRM_IOCTL\_`` and passing that 1684e390cabSriastradh * to DRM_IOCTL_NR(). 1694e390cabSriastradh */ 1704e390cabSriastradh #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \ 1714e390cabSriastradh [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = { \ 1724e390cabSriastradh .cmd = DRM_IOCTL_##ioctl, \ 1734e390cabSriastradh .func = _func, \ 1744e390cabSriastradh .flags = _flags, \ 1754e390cabSriastradh .name = #ioctl \ 1764e390cabSriastradh } 1774e390cabSriastradh 1784e390cabSriastradh int drm_ioctl_permit(u32 flags, struct drm_file *file_priv); 179c43809e2Sriastradh #ifdef __NetBSD__ 180c43809e2Sriastradh int drm_ioctl(struct file *, unsigned long, void *); 181*5579de5fSriastradh void drm_suspend_ioctl(struct drm_device *); 182*5579de5fSriastradh void drm_resume_ioctl(struct drm_device *); 183c43809e2Sriastradh #else 1844e390cabSriastradh long drm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 185c43809e2Sriastradh #endif 1864e390cabSriastradh long drm_ioctl_kernel(struct file *, drm_ioctl_t, void *, u32); 1874e390cabSriastradh #ifdef CONFIG_COMPAT 1884e390cabSriastradh long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 1894e390cabSriastradh #else 1904e390cabSriastradh /* Let drm_compat_ioctl be assigned to .compat_ioctl unconditionally */ 1914e390cabSriastradh #define drm_compat_ioctl NULL 1924e390cabSriastradh #endif 1934e390cabSriastradh bool drm_ioctl_flags(unsigned int nr, unsigned int *flags); 1944e390cabSriastradh 1954e390cabSriastradh int drm_noop(struct drm_device *dev, void *data, 1964e390cabSriastradh struct drm_file *file_priv); 1974e390cabSriastradh int drm_invalid_op(struct drm_device *dev, void *data, 1984e390cabSriastradh struct drm_file *file_priv); 1994e390cabSriastradh 2004e390cabSriastradh #endif /* _DRM_IOCTL_H_ */ 201