drm_ioctl.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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_UNLOCKED:
  105. *
  106. * Whether &drm_ioctl_desc.func should be called with the DRM BKL held
  107. * or not. Enforced as the default for all modern drivers, hence there
  108. * should never be a need to set this flag.
  109. */
  110. DRM_UNLOCKED = BIT(4),
  111. /**
  112. * @DRM_RENDER_ALLOW:
  113. *
  114. * This is used for all ioctl needed for rendering only, for drivers
  115. * which support render nodes. This should be all new render drivers,
  116. * and hence it should be always set for any ioctl with DRM_AUTH set.
  117. * Note though that read-only query ioctl might have this set, but have
  118. * not set DRM_AUTH because they do not require authentication.
  119. */
  120. DRM_RENDER_ALLOW = BIT(5),
  121. };
  122. /**
  123. * struct drm_ioctl_desc - DRM driver ioctl entry
  124. * @cmd: ioctl command number, without flags
  125. * @flags: a bitmask of &enum drm_ioctl_flags
  126. * @func: handler for this ioctl
  127. * @name: user-readable name for debug output
  128. *
  129. * For convenience it's easier to create these using the DRM_IOCTL_DEF_DRV()
  130. * macro.
  131. */
  132. struct drm_ioctl_desc {
  133. unsigned int cmd;
  134. enum drm_ioctl_flags flags;
  135. drm_ioctl_t *func;
  136. const char *name;
  137. };
  138. /**
  139. * DRM_IOCTL_DEF_DRV() - helper macro to fill out a &struct drm_ioctl_desc
  140. * @ioctl: ioctl command suffix
  141. * @_func: handler for the ioctl
  142. * @_flags: a bitmask of &enum drm_ioctl_flags
  143. *
  144. * Small helper macro to create a &struct drm_ioctl_desc entry. The ioctl
  145. * command number is constructed by prepending ``DRM_IOCTL\_`` and passing that
  146. * to DRM_IOCTL_NR().
  147. */
  148. #define DRM_IOCTL_DEF_DRV(ioctl, _func, _flags) \
  149. [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = { \
  150. .cmd = DRM_IOCTL_##ioctl, \
  151. .func = _func, \
  152. .flags = _flags, \
  153. .name = #ioctl \
  154. }
  155. int drm_ioctl_permit(u32 flags, struct drm_file *file_priv);
  156. long drm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
  157. long drm_ioctl_kernel(struct file *, drm_ioctl_t, void *, u32);
  158. #ifdef CONFIG_COMPAT
  159. long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
  160. #else
  161. /* Let drm_compat_ioctl be assigned to .compat_ioctl unconditionally */
  162. #define drm_compat_ioctl NULL
  163. #endif
  164. bool drm_ioctl_flags(unsigned int nr, unsigned int *flags);
  165. int drm_noop(struct drm_device *dev, void *data,
  166. struct drm_file *file_priv);
  167. int drm_invalid_op(struct drm_device *dev, void *data,
  168. struct drm_file *file_priv);
  169. #endif /* _DRM_IOCTL_H_ */