drm_ioctl.h 6.2 KB

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