drm_ioctl.h 6.2 KB

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