drm-uapi.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. ===================
  2. Userland interfaces
  3. ===================
  4. The DRM core exports several interfaces to applications, generally
  5. intended to be used through corresponding libdrm wrapper functions. In
  6. addition, drivers export device-specific interfaces for use by userspace
  7. drivers & device-aware applications through ioctls and sysfs files.
  8. External interfaces include: memory mapping, context management, DMA
  9. operations, AGP management, vblank control, fence management, memory
  10. management, and output management.
  11. Cover generic ioctls and sysfs layout here. We only need high-level
  12. info, since man pages should cover the rest.
  13. libdrm Device Lookup
  14. ====================
  15. .. kernel-doc:: drivers/gpu/drm/drm_ioctl.c
  16. :doc: getunique and setversion story
  17. .. _drm_primary_node:
  18. Primary Nodes, DRM Master and Authentication
  19. ============================================
  20. .. kernel-doc:: drivers/gpu/drm/drm_auth.c
  21. :doc: master and authentication
  22. .. kernel-doc:: drivers/gpu/drm/drm_auth.c
  23. :export:
  24. .. kernel-doc:: include/drm/drm_auth.h
  25. :internal:
  26. Open-Source Userspace Requirements
  27. ==================================
  28. The DRM subsystem has stricter requirements than most other kernel subsystems on
  29. what the userspace side for new uAPI needs to look like. This section here
  30. explains what exactly those requirements are, and why they exist.
  31. The short summary is that any addition of DRM uAPI requires corresponding
  32. open-sourced userspace patches, and those patches must be reviewed and ready for
  33. merging into a suitable and canonical upstream project.
  34. GFX devices (both display and render/GPU side) are really complex bits of
  35. hardware, with userspace and kernel by necessity having to work together really
  36. closely. The interfaces, for rendering and modesetting, must be extremely wide
  37. and flexible, and therefore it is almost always impossible to precisely define
  38. them for every possible corner case. This in turn makes it really practically
  39. infeasible to differentiate between behaviour that's required by userspace, and
  40. which must not be changed to avoid regressions, and behaviour which is only an
  41. accidental artifact of the current implementation.
  42. Without access to the full source code of all userspace users that means it
  43. becomes impossible to change the implementation details, since userspace could
  44. depend upon the accidental behaviour of the current implementation in minute
  45. details. And debugging such regressions without access to source code is pretty
  46. much impossible. As a consequence this means:
  47. - The Linux kernel's "no regression" policy holds in practice only for
  48. open-source userspace of the DRM subsystem. DRM developers are perfectly fine
  49. if closed-source blob drivers in userspace use the same uAPI as the open
  50. drivers, but they must do so in the exact same way as the open drivers.
  51. Creative (ab)use of the interfaces will, and in the past routinely has, lead
  52. to breakage.
  53. - Any new userspace interface must have an open-source implementation as
  54. demonstration vehicle.
  55. The other reason for requiring open-source userspace is uAPI review. Since the
  56. kernel and userspace parts of a GFX stack must work together so closely, code
  57. review can only assess whether a new interface achieves its goals by looking at
  58. both sides. Making sure that the interface indeed covers the use-case fully
  59. leads to a few additional requirements:
  60. - The open-source userspace must not be a toy/test application, but the real
  61. thing. Specifically it needs to handle all the usual error and corner cases.
  62. These are often the places where new uAPI falls apart and hence essential to
  63. assess the fitness of a proposed interface.
  64. - The userspace side must be fully reviewed and tested to the standards of that
  65. userspace project. For e.g. mesa this means piglit testcases and review on the
  66. mailing list. This is again to ensure that the new interface actually gets the
  67. job done.
  68. - The userspace patches must be against the canonical upstream, not some vendor
  69. fork. This is to make sure that no one cheats on the review and testing
  70. requirements by doing a quick fork.
  71. - The kernel patch can only be merged after all the above requirements are met,
  72. but it **must** be merged **before** the userspace patches land. uAPI always flows
  73. from the kernel, doing things the other way round risks divergence of the uAPI
  74. definitions and header files.
  75. These are fairly steep requirements, but have grown out from years of shared
  76. pain and experience with uAPI added hastily, and almost always regretted about
  77. just as fast. GFX devices change really fast, requiring a paradigm shift and
  78. entire new set of uAPI interfaces every few years at least. Together with the
  79. Linux kernel's guarantee to keep existing userspace running for 10+ years this
  80. is already rather painful for the DRM subsystem, with multiple different uAPIs
  81. for the same thing co-existing. If we add a few more complete mistakes into the
  82. mix every year it would be entirely unmanageable.
  83. .. _drm_render_node:
  84. Render nodes
  85. ============
  86. DRM core provides multiple character-devices for user-space to use.
  87. Depending on which device is opened, user-space can perform a different
  88. set of operations (mainly ioctls). The primary node is always created
  89. and called card<num>. Additionally, a currently unused control node,
  90. called controlD<num> is also created. The primary node provides all
  91. legacy operations and historically was the only interface used by
  92. userspace. With KMS, the control node was introduced. However, the
  93. planned KMS control interface has never been written and so the control
  94. node stays unused to date.
  95. With the increased use of offscreen renderers and GPGPU applications,
  96. clients no longer require running compositors or graphics servers to
  97. make use of a GPU. But the DRM API required unprivileged clients to
  98. authenticate to a DRM-Master prior to getting GPU access. To avoid this
  99. step and to grant clients GPU access without authenticating, render
  100. nodes were introduced. Render nodes solely serve render clients, that
  101. is, no modesetting or privileged ioctls can be issued on render nodes.
  102. Only non-global rendering commands are allowed. If a driver supports
  103. render nodes, it must advertise it via the DRIVER_RENDER DRM driver
  104. capability. If not supported, the primary node must be used for render
  105. clients together with the legacy drmAuth authentication procedure.
  106. If a driver advertises render node support, DRM core will create a
  107. separate render node called renderD<num>. There will be one render node
  108. per device. No ioctls except PRIME-related ioctls will be allowed on
  109. this node. Especially GEM_OPEN will be explicitly prohibited. Render
  110. nodes are designed to avoid the buffer-leaks, which occur if clients
  111. guess the flink names or mmap offsets on the legacy interface.
  112. Additionally to this basic interface, drivers must mark their
  113. driver-dependent render-only ioctls as DRM_RENDER_ALLOW so render
  114. clients can use them. Driver authors must be careful not to allow any
  115. privileged ioctls on render nodes.
  116. With render nodes, user-space can now control access to the render node
  117. via basic file-system access-modes. A running graphics server which
  118. authenticates clients on the privileged primary/legacy node is no longer
  119. required. Instead, a client can open the render node and is immediately
  120. granted GPU access. Communication between clients (or servers) is done
  121. via PRIME. FLINK from render node to legacy node is not supported. New
  122. clients must not use the insecure FLINK interface.
  123. Besides dropping all modeset/global ioctls, render nodes also drop the
  124. DRM-Master concept. There is no reason to associate render clients with
  125. a DRM-Master as they are independent of any graphics server. Besides,
  126. they must work without any running master, anyway. Drivers must be able
  127. to run without a master object if they support render nodes. If, on the
  128. other hand, a driver requires shared state between clients which is
  129. visible to user-space and accessible beyond open-file boundaries, they
  130. cannot support render nodes.
  131. .. _drm_driver_ioctl:
  132. IOCTL Support on Device Nodes
  133. =============================
  134. .. kernel-doc:: drivers/gpu/drm/drm_ioctl.c
  135. :doc: driver specific ioctls
  136. .. kernel-doc:: include/drm/drm_ioctl.h
  137. :internal:
  138. .. kernel-doc:: drivers/gpu/drm/drm_ioctl.c
  139. :export:
  140. .. kernel-doc:: drivers/gpu/drm/drm_ioc32.c
  141. :export:
  142. Testing and validation
  143. ======================
  144. Validating changes with IGT
  145. ---------------------------
  146. There's a collection of tests that aims to cover the whole functionality of
  147. DRM drivers and that can be used to check that changes to DRM drivers or the
  148. core don't regress existing functionality. This test suite is called IGT and
  149. its code can be found in https://cgit.freedesktop.org/drm/igt-gpu-tools/.
  150. To build IGT, start by installing its build dependencies. In Debian-based
  151. systems::
  152. # apt-get build-dep intel-gpu-tools
  153. And in Fedora-based systems::
  154. # dnf builddep intel-gpu-tools
  155. Then clone the repository::
  156. $ git clone git://anongit.freedesktop.org/drm/igt-gpu-tools
  157. Configure the build system and start the build::
  158. $ cd igt-gpu-tools && ./autogen.sh && make -j6
  159. Download the piglit dependency::
  160. $ ./scripts/run-tests.sh -d
  161. And run the tests::
  162. $ ./scripts/run-tests.sh -t kms -t core -s
  163. run-tests.sh is a wrapper around piglit that will execute the tests matching
  164. the -t options. A report in HTML format will be available in
  165. ./results/html/index.html. Results can be compared with piglit.
  166. Display CRC Support
  167. -------------------
  168. .. kernel-doc:: drivers/gpu/drm/drm_debugfs_crc.c
  169. :doc: CRC ABI
  170. .. kernel-doc:: drivers/gpu/drm/drm_debugfs_crc.c
  171. :export:
  172. Debugfs Support
  173. ---------------
  174. .. kernel-doc:: include/drm/drm_debugfs.h
  175. :internal:
  176. .. kernel-doc:: drivers/gpu/drm/drm_debugfs.c
  177. :export:
  178. Sysfs Support
  179. =============
  180. .. kernel-doc:: drivers/gpu/drm/drm_sysfs.c
  181. :doc: overview
  182. .. kernel-doc:: drivers/gpu/drm/drm_sysfs.c
  183. :export:
  184. VBlank event handling
  185. =====================
  186. The DRM core exposes two vertical blank related ioctls:
  187. DRM_IOCTL_WAIT_VBLANK
  188. This takes a struct drm_wait_vblank structure as its argument, and
  189. it is used to block or request a signal when a specified vblank
  190. event occurs.
  191. DRM_IOCTL_MODESET_CTL
  192. This was only used for user-mode-settind drivers around modesetting
  193. changes to allow the kernel to update the vblank interrupt after
  194. mode setting, since on many devices the vertical blank counter is
  195. reset to 0 at some point during modeset. Modern drivers should not
  196. call this any more since with kernel mode setting it is a no-op.