drm-kms.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. =========================
  2. Kernel Mode Setting (KMS)
  3. =========================
  4. Drivers must initialize the mode setting core by calling
  5. :c:func:`drm_mode_config_init()` on the DRM device. The function
  6. initializes the :c:type:`struct drm_device <drm_device>`
  7. mode_config field and never fails. Once done, mode configuration must
  8. be setup by initializing the following fields.
  9. - int min_width, min_height; int max_width, max_height;
  10. Minimum and maximum width and height of the frame buffers in pixel
  11. units.
  12. - struct drm_mode_config_funcs \*funcs;
  13. Mode setting functions.
  14. Modeset Base Object Abstraction
  15. ===============================
  16. .. kernel-doc:: include/drm/drm_mode_object.h
  17. :internal:
  18. .. kernel-doc:: drivers/gpu/drm/drm_mode_object.c
  19. :export:
  20. KMS Data Structures
  21. ===================
  22. .. kernel-doc:: include/drm/drm_crtc.h
  23. :internal:
  24. KMS API Functions
  25. =================
  26. .. kernel-doc:: drivers/gpu/drm/drm_crtc.c
  27. :export:
  28. Atomic Mode Setting Function Reference
  29. ======================================
  30. .. kernel-doc:: drivers/gpu/drm/drm_atomic.c
  31. :export:
  32. .. kernel-doc:: include/drm/drm_atomic.h
  33. :internal:
  34. Frame Buffer Abstraction
  35. ========================
  36. .. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c
  37. :doc: overview
  38. Frame Buffer Functions Reference
  39. --------------------------------
  40. .. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c
  41. :export:
  42. .. kernel-doc:: include/drm/drm_framebuffer.h
  43. :internal:
  44. DRM Format Handling
  45. ===================
  46. .. kernel-doc:: drivers/gpu/drm/drm_fourcc.c
  47. :export:
  48. Dumb Buffer Objects
  49. ===================
  50. The KMS API doesn't standardize backing storage object creation and
  51. leaves it to driver-specific ioctls. Furthermore actually creating a
  52. buffer object even for GEM-based drivers is done through a
  53. driver-specific ioctl - GEM only has a common userspace interface for
  54. sharing and destroying objects. While not an issue for full-fledged
  55. graphics stacks that include device-specific userspace components (in
  56. libdrm for instance), this limit makes DRM-based early boot graphics
  57. unnecessarily complex.
  58. Dumb objects partly alleviate the problem by providing a standard API to
  59. create dumb buffers suitable for scanout, which can then be used to
  60. create KMS frame buffers.
  61. To support dumb objects drivers must implement the dumb_create,
  62. dumb_destroy and dumb_map_offset operations.
  63. - int (\*dumb_create)(struct drm_file \*file_priv, struct
  64. drm_device \*dev, struct drm_mode_create_dumb \*args);
  65. The dumb_create operation creates a driver object (GEM or TTM
  66. handle) suitable for scanout based on the width, height and depth
  67. from the struct :c:type:`struct drm_mode_create_dumb
  68. <drm_mode_create_dumb>` argument. It fills the argument's
  69. handle, pitch and size fields with a handle for the newly created
  70. object and its line pitch and size in bytes.
  71. - int (\*dumb_destroy)(struct drm_file \*file_priv, struct
  72. drm_device \*dev, uint32_t handle);
  73. The dumb_destroy operation destroys a dumb object created by
  74. dumb_create.
  75. - int (\*dumb_map_offset)(struct drm_file \*file_priv, struct
  76. drm_device \*dev, uint32_t handle, uint64_t \*offset);
  77. The dumb_map_offset operation associates an mmap fake offset with
  78. the object given by the handle and returns it. Drivers must use the
  79. :c:func:`drm_gem_create_mmap_offset()` function to associate
  80. the fake offset as described in ?.
  81. Note that dumb objects may not be used for gpu acceleration, as has been
  82. attempted on some ARM embedded platforms. Such drivers really must have
  83. a hardware-specific ioctl to allocate suitable buffer objects.
  84. Plane Abstraction
  85. =================
  86. .. kernel-doc:: drivers/gpu/drm/drm_plane.c
  87. :doc: overview
  88. Plane Functions Reference
  89. -------------------------
  90. .. kernel-doc:: include/drm/drm_plane.h
  91. :internal:
  92. .. kernel-doc:: drivers/gpu/drm/drm_plane.c
  93. :export:
  94. Display Modes Function Reference
  95. ================================
  96. .. kernel-doc:: include/drm/drm_modes.h
  97. :internal:
  98. .. kernel-doc:: drivers/gpu/drm/drm_modes.c
  99. :export:
  100. Connector Abstraction
  101. =====================
  102. .. kernel-doc:: drivers/gpu/drm/drm_connector.c
  103. :doc: overview
  104. Connector Functions Reference
  105. -----------------------------
  106. .. kernel-doc:: include/drm/drm_connector.h
  107. :internal:
  108. .. kernel-doc:: drivers/gpu/drm/drm_connector.c
  109. :export:
  110. Encoder Abstraction
  111. ===================
  112. .. kernel-doc:: drivers/gpu/drm/drm_encoder.c
  113. :doc: overview
  114. Encoder Functions Reference
  115. ---------------------------
  116. .. kernel-doc:: include/drm/drm_encoder.h
  117. :internal:
  118. .. kernel-doc:: drivers/gpu/drm/drm_encoder.c
  119. :export:
  120. KMS Initialization and Cleanup
  121. ==============================
  122. A KMS device is abstracted and exposed as a set of planes, CRTCs,
  123. encoders and connectors. KMS drivers must thus create and initialize all
  124. those objects at load time after initializing mode setting.
  125. CRTCs (:c:type:`struct drm_crtc <drm_crtc>`)
  126. --------------------------------------------
  127. A CRTC is an abstraction representing a part of the chip that contains a
  128. pointer to a scanout buffer. Therefore, the number of CRTCs available
  129. determines how many independent scanout buffers can be active at any
  130. given time. The CRTC structure contains several fields to support this:
  131. a pointer to some video memory (abstracted as a frame buffer object), a
  132. display mode, and an (x, y) offset into the video memory to support
  133. panning or configurations where one piece of video memory spans multiple
  134. CRTCs.
  135. CRTC Initialization
  136. ~~~~~~~~~~~~~~~~~~~
  137. A KMS device must create and register at least one struct
  138. :c:type:`struct drm_crtc <drm_crtc>` instance. The instance is
  139. allocated and zeroed by the driver, possibly as part of a larger
  140. structure, and registered with a call to :c:func:`drm_crtc_init()`
  141. with a pointer to CRTC functions.
  142. Cleanup
  143. -------
  144. The DRM core manages its objects' lifetime. When an object is not needed
  145. anymore the core calls its destroy function, which must clean up and
  146. free every resource allocated for the object. Every
  147. :c:func:`drm_\*_init()` call must be matched with a corresponding
  148. :c:func:`drm_\*_cleanup()` call to cleanup CRTCs
  149. (:c:func:`drm_crtc_cleanup()`), planes
  150. (:c:func:`drm_plane_cleanup()`), encoders
  151. (:c:func:`drm_encoder_cleanup()`) and connectors
  152. (:c:func:`drm_connector_cleanup()`). Furthermore, connectors that
  153. have been added to sysfs must be removed by a call to
  154. :c:func:`drm_connector_unregister()` before calling
  155. :c:func:`drm_connector_cleanup()`.
  156. Connectors state change detection must be cleanup up with a call to
  157. :c:func:`drm_kms_helper_poll_fini()`.
  158. Output discovery and initialization example
  159. -------------------------------------------
  160. ::
  161. void intel_crt_init(struct drm_device *dev)
  162. {
  163. struct drm_connector *connector;
  164. struct intel_output *intel_output;
  165. intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL);
  166. if (!intel_output)
  167. return;
  168. connector = &intel_output->base;
  169. drm_connector_init(dev, &intel_output->base,
  170. &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA);
  171. drm_encoder_init(dev, &intel_output->enc, &intel_crt_enc_funcs,
  172. DRM_MODE_ENCODER_DAC);
  173. drm_mode_connector_attach_encoder(&intel_output->base,
  174. &intel_output->enc);
  175. /* Set up the DDC bus. */
  176. intel_output->ddc_bus = intel_i2c_create(dev, GPIOA, "CRTDDC_A");
  177. if (!intel_output->ddc_bus) {
  178. dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration "
  179. "failed.\n");
  180. return;
  181. }
  182. intel_output->type = INTEL_OUTPUT_ANALOG;
  183. connector->interlace_allowed = 0;
  184. connector->doublescan_allowed = 0;
  185. drm_encoder_helper_add(&intel_output->enc, &intel_crt_helper_funcs);
  186. drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
  187. drm_connector_register(connector);
  188. }
  189. In the example above (taken from the i915 driver), a CRTC, connector and
  190. encoder combination is created. A device-specific i2c bus is also
  191. created for fetching EDID data and performing monitor detection. Once
  192. the process is complete, the new connector is registered with sysfs to
  193. make its properties available to applications.
  194. KMS Locking
  195. ===========
  196. .. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
  197. :doc: kms locking
  198. .. kernel-doc:: include/drm/drm_modeset_lock.h
  199. :internal:
  200. .. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
  201. :export:
  202. KMS Properties
  203. ==============
  204. Property Types and Blob Property Support
  205. ----------------------------------------
  206. .. kernel-doc:: drivers/gpu/drm/drm_property.c
  207. :doc: overview
  208. .. kernel-doc:: include/drm/drm_property.h
  209. :internal:
  210. .. kernel-doc:: drivers/gpu/drm/drm_property.c
  211. :export:
  212. Plane Composition Properties
  213. ----------------------------
  214. .. kernel-doc:: drivers/gpu/drm/drm_blend.c
  215. :doc: overview
  216. .. kernel-doc:: drivers/gpu/drm/drm_blend.c
  217. :export:
  218. Color Management Properties
  219. ---------------------------
  220. .. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c
  221. :doc: overview
  222. .. kernel-doc:: include/drm/drm_color_mgmt.h
  223. :internal:
  224. .. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c
  225. :export:
  226. Existing KMS Properties
  227. -----------------------
  228. The following table gives description of drm properties exposed by
  229. various modules/drivers.
  230. .. csv-table::
  231. :header-rows: 1
  232. :file: kms-properties.csv
  233. Vertical Blanking
  234. =================
  235. Vertical blanking plays a major role in graphics rendering. To achieve
  236. tear-free display, users must synchronize page flips and/or rendering to
  237. vertical blanking. The DRM API offers ioctls to perform page flips
  238. synchronized to vertical blanking and wait for vertical blanking.
  239. The DRM core handles most of the vertical blanking management logic,
  240. which involves filtering out spurious interrupts, keeping race-free
  241. blanking counters, coping with counter wrap-around and resets and
  242. keeping use counts. It relies on the driver to generate vertical
  243. blanking interrupts and optionally provide a hardware vertical blanking
  244. counter. Drivers must implement the following operations.
  245. - int (\*enable_vblank) (struct drm_device \*dev, int crtc); void
  246. (\*disable_vblank) (struct drm_device \*dev, int crtc);
  247. Enable or disable vertical blanking interrupts for the given CRTC.
  248. - u32 (\*get_vblank_counter) (struct drm_device \*dev, int crtc);
  249. Retrieve the value of the vertical blanking counter for the given
  250. CRTC. If the hardware maintains a vertical blanking counter its value
  251. should be returned. Otherwise drivers can use the
  252. :c:func:`drm_vblank_count()` helper function to handle this
  253. operation.
  254. Drivers must initialize the vertical blanking handling core with a call
  255. to :c:func:`drm_vblank_init()` in their load operation.
  256. Vertical blanking interrupts can be enabled by the DRM core or by
  257. drivers themselves (for instance to handle page flipping operations).
  258. The DRM core maintains a vertical blanking use count to ensure that the
  259. interrupts are not disabled while a user still needs them. To increment
  260. the use count, drivers call :c:func:`drm_vblank_get()`. Upon
  261. return vertical blanking interrupts are guaranteed to be enabled.
  262. To decrement the use count drivers call
  263. :c:func:`drm_vblank_put()`. Only when the use count drops to zero
  264. will the DRM core disable the vertical blanking interrupts after a delay
  265. by scheduling a timer. The delay is accessible through the
  266. vblankoffdelay module parameter or the ``drm_vblank_offdelay`` global
  267. variable and expressed in milliseconds. Its default value is 5000 ms.
  268. Zero means never disable, and a negative value means disable
  269. immediately. Drivers may override the behaviour by setting the
  270. :c:type:`struct drm_device <drm_device>`
  271. vblank_disable_immediate flag, which when set causes vblank interrupts
  272. to be disabled immediately regardless of the drm_vblank_offdelay
  273. value. The flag should only be set if there's a properly working
  274. hardware vblank counter present.
  275. When a vertical blanking interrupt occurs drivers only need to call the
  276. :c:func:`drm_handle_vblank()` function to account for the
  277. interrupt.
  278. Resources allocated by :c:func:`drm_vblank_init()` must be freed
  279. with a call to :c:func:`drm_vblank_cleanup()` in the driver unload
  280. operation handler.
  281. Vertical Blanking and Interrupt Handling Functions Reference
  282. ------------------------------------------------------------
  283. .. kernel-doc:: drivers/gpu/drm/drm_irq.c
  284. :export:
  285. .. kernel-doc:: include/drm/drm_irq.h
  286. :internal: