Home | History | Annotate | Line # | Download | only in drm
drm_ioctl.h revision 1.1
      1 /*	$NetBSD: drm_ioctl.h,v 1.1 2021/12/18 20:15:57 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 #define DRM_IOCTL_NR(n)                _IOC_NR(n)
     73 #define DRM_MAJOR       226
     74 
     75 /**
     76  * enum drm_ioctl_flags - DRM ioctl flags
     77  *
     78  * Various flags that can be set in &drm_ioctl_desc.flags to control how
     79  * userspace can use a given ioctl.
     80  */
     81 enum drm_ioctl_flags {
     82 	/**
     83 	 * @DRM_AUTH:
     84 	 *
     85 	 * This is for ioctl which are used for rendering, and require that the
     86 	 * file descriptor is either for a render node, or if it's a
     87 	 * legacy/primary node, then it must be authenticated.
     88 	 */
     89 	DRM_AUTH		= BIT(0),
     90 	/**
     91 	 * @DRM_MASTER:
     92 	 *
     93 	 * This must be set for any ioctl which can change the modeset or
     94 	 * display state. Userspace must call the ioctl through a primary node,
     95 	 * while it is the active master.
     96 	 *
     97 	 * Note that read-only modeset ioctl can also be called by
     98 	 * unauthenticated clients, or when a master is not the currently active
     99 	 * one.
    100 	 */
    101 	DRM_MASTER		= BIT(1),
    102 	/**
    103 	 * @DRM_ROOT_ONLY:
    104 	 *
    105 	 * Anything that could potentially wreak a master file descriptor needs
    106 	 * to have this flag set. Current that's only for the SETMASTER and
    107 	 * DROPMASTER ioctl, which e.g. logind can call to force a non-behaving
    108 	 * master (display compositor) into compliance.
    109 	 *
    110 	 * This is equivalent to callers with the SYSADMIN capability.
    111 	 */
    112 	DRM_ROOT_ONLY		= BIT(2),
    113 	/**
    114 	 * @DRM_UNLOCKED:
    115 	 *
    116 	 * Whether &drm_ioctl_desc.func should be called with the DRM BKL held
    117 	 * or not. Enforced as the default for all modern drivers, hence there
    118 	 * should never be a need to set this flag.
    119 	 *
    120 	 * Do not use anywhere else than for the VBLANK_WAIT IOCTL, which is the
    121 	 * only legacy IOCTL which needs this.
    122 	 */
    123 	DRM_UNLOCKED		= BIT(4),
    124 	/**
    125 	 * @DRM_RENDER_ALLOW:
    126 	 *
    127 	 * This is used for all ioctl needed for rendering only, for drivers
    128 	 * which support render nodes. This should be all new render drivers,
    129 	 * and hence it should be always set for any ioctl with DRM_AUTH set.
    130 	 * Note though that read-only query ioctl might have this set, but have
    131 	 * not set DRM_AUTH because they do not require authentication.
    132 	 */
    133 	DRM_RENDER_ALLOW	= BIT(5),
    134 };
    135 
    136 /**
    137  * struct drm_ioctl_desc - DRM driver ioctl entry
    138  * @cmd: ioctl command number, without flags
    139  * @flags: a bitmask of &enum drm_ioctl_flags
    140  * @func: handler for this ioctl
    141  * @name: user-readable name for debug output
    142  *
    143  * For convenience it's easier to create these using the DRM_IOCTL_DEF_DRV()
    144  * macro.
    145  */
    146 struct drm_ioctl_desc {
    147 	unsigned int cmd;
    148 	enum drm_ioctl_flags flags;
    149 	drm_ioctl_t *func;
    150 	const char *name;
    151 };
    152 
    153 /**
    154  * DRM_IOCTL_DEF_DRV() - helper macro to fill out a &struct drm_ioctl_desc
    155  * @ioctl: ioctl command suffix
    156  * @_func: handler for the ioctl
    157  * @_flags: a bitmask of &enum drm_ioctl_flags
    158  *
    159  * Small helper macro to create a &struct drm_ioctl_desc entry. The ioctl
    160  * command number is constructed by prepending ``DRM_IOCTL\_`` and passing that
    161  * to DRM_IOCTL_NR().
    162  */
    163 #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags)				\
    164 	[DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = {	\
    165 		.cmd = DRM_IOCTL_##ioctl,				\
    166 		.func = _func,						\
    167 		.flags = _flags,					\
    168 		.name = #ioctl						\
    169 	}
    170 
    171 int drm_ioctl_permit(u32 flags, struct drm_file *file_priv);
    172 long drm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
    173 long drm_ioctl_kernel(struct file *, drm_ioctl_t, void *, u32);
    174 #ifdef CONFIG_COMPAT
    175 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
    176 #else
    177 /* Let drm_compat_ioctl be assigned to .compat_ioctl unconditionally */
    178 #define drm_compat_ioctl NULL
    179 #endif
    180 bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
    181 
    182 int drm_noop(struct drm_device *dev, void *data,
    183 	     struct drm_file *file_priv);
    184 int drm_invalid_op(struct drm_device *dev, void *data,
    185 		   struct drm_file *file_priv);
    186 
    187 #endif /* _DRM_IOCTL_H_ */
    188