drm-kms.rst 12 KB

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