drm-kms.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. =========================
  2. Kernel Mode Setting (KMS)
  3. =========================
  4. Drivers must initialize the mode setting core by calling
  5. drmm_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. Overview
  15. ========
  16. .. kernel-render:: DOT
  17. :alt: KMS Display Pipeline
  18. :caption: KMS Display Pipeline Overview
  19. digraph "KMS" {
  20. node [shape=box]
  21. subgraph cluster_static {
  22. style=dashed
  23. label="Static Objects"
  24. node [bgcolor=grey style=filled]
  25. "drm_plane A" -> "drm_crtc"
  26. "drm_plane B" -> "drm_crtc"
  27. "drm_crtc" -> "drm_encoder A"
  28. "drm_crtc" -> "drm_encoder B"
  29. }
  30. subgraph cluster_user_created {
  31. style=dashed
  32. label="Userspace-Created"
  33. node [shape=oval]
  34. "drm_framebuffer 1" -> "drm_plane A"
  35. "drm_framebuffer 2" -> "drm_plane B"
  36. }
  37. subgraph cluster_connector {
  38. style=dashed
  39. label="Hotpluggable"
  40. "drm_encoder A" -> "drm_connector A"
  41. "drm_encoder B" -> "drm_connector B"
  42. }
  43. }
  44. The basic object structure KMS presents to userspace is fairly simple.
  45. Framebuffers (represented by :c:type:`struct drm_framebuffer <drm_framebuffer>`,
  46. see `Frame Buffer Abstraction`_) feed into planes. Planes are represented by
  47. :c:type:`struct drm_plane <drm_plane>`, see `Plane Abstraction`_ for more
  48. details. One or more (or even no) planes feed their pixel data into a CRTC
  49. (represented by :c:type:`struct drm_crtc <drm_crtc>`, see `CRTC Abstraction`_)
  50. for blending. The precise blending step is explained in more detail in `Plane
  51. Composition Properties`_ and related chapters.
  52. For the output routing the first step is encoders (represented by
  53. :c:type:`struct drm_encoder <drm_encoder>`, see `Encoder Abstraction`_). Those
  54. are really just internal artifacts of the helper libraries used to implement KMS
  55. drivers. Besides that they make it unecessarily more complicated for userspace
  56. to figure out which connections between a CRTC and a connector are possible, and
  57. what kind of cloning is supported, they serve no purpose in the userspace API.
  58. Unfortunately encoders have been exposed to userspace, hence can't remove them
  59. at this point. Futhermore the exposed restrictions are often wrongly set by
  60. drivers, and in many cases not powerful enough to express the real restrictions.
  61. A CRTC can be connected to multiple encoders, and for an active CRTC there must
  62. be at least one encoder.
  63. The final, and real, endpoint in the display chain is the connector (represented
  64. by :c:type:`struct drm_connector <drm_connector>`, see `Connector
  65. Abstraction`_). Connectors can have different possible encoders, but the kernel
  66. driver selects which encoder to use for each connector. The use case is DVI,
  67. which could switch between an analog and a digital encoder. Encoders can also
  68. drive multiple different connectors. There is exactly one active connector for
  69. every active encoder.
  70. Internally the output pipeline is a bit more complex and matches today's
  71. hardware more closely:
  72. .. kernel-render:: DOT
  73. :alt: KMS Output Pipeline
  74. :caption: KMS Output Pipeline
  75. digraph "Output Pipeline" {
  76. node [shape=box]
  77. subgraph {
  78. "drm_crtc" [bgcolor=grey style=filled]
  79. }
  80. subgraph cluster_internal {
  81. style=dashed
  82. label="Internal Pipeline"
  83. {
  84. node [bgcolor=grey style=filled]
  85. "drm_encoder A";
  86. "drm_encoder B";
  87. "drm_encoder C";
  88. }
  89. {
  90. node [bgcolor=grey style=filled]
  91. "drm_encoder B" -> "drm_bridge B"
  92. "drm_encoder C" -> "drm_bridge C1"
  93. "drm_bridge C1" -> "drm_bridge C2";
  94. }
  95. }
  96. "drm_crtc" -> "drm_encoder A"
  97. "drm_crtc" -> "drm_encoder B"
  98. "drm_crtc" -> "drm_encoder C"
  99. subgraph cluster_output {
  100. style=dashed
  101. label="Outputs"
  102. "drm_encoder A" -> "drm_connector A";
  103. "drm_bridge B" -> "drm_connector B";
  104. "drm_bridge C2" -> "drm_connector C";
  105. "drm_panel"
  106. }
  107. }
  108. Internally two additional helper objects come into play. First, to be able to
  109. share code for encoders (sometimes on the same SoC, sometimes off-chip) one or
  110. more :ref:`drm_bridges` (represented by :c:type:`struct drm_bridge
  111. <drm_bridge>`) can be linked to an encoder. This link is static and cannot be
  112. changed, which means the cross-bar (if there is any) needs to be mapped between
  113. the CRTC and any encoders. Often for drivers with bridges there's no code left
  114. at the encoder level. Atomic drivers can leave out all the encoder callbacks to
  115. essentially only leave a dummy routing object behind, which is needed for
  116. backwards compatibility since encoders are exposed to userspace.
  117. The second object is for panels, represented by :c:type:`struct drm_panel
  118. <drm_panel>`, see :ref:`drm_panel_helper`. Panels do not have a fixed binding
  119. point, but are generally linked to the driver private structure that embeds
  120. :c:type:`struct drm_connector <drm_connector>`.
  121. Note that currently the bridge chaining and interactions with connectors and
  122. panels are still in-flux and not really fully sorted out yet.
  123. KMS Core Structures and Functions
  124. =================================
  125. .. kernel-doc:: include/drm/drm_mode_config.h
  126. :internal:
  127. .. kernel-doc:: drivers/gpu/drm/drm_mode_config.c
  128. :export:
  129. .. _kms_base_object_abstraction:
  130. Modeset Base Object Abstraction
  131. ===============================
  132. .. kernel-render:: DOT
  133. :alt: Mode Objects and Properties
  134. :caption: Mode Objects and Properties
  135. digraph {
  136. node [shape=box]
  137. "drm_property A" -> "drm_mode_object A"
  138. "drm_property A" -> "drm_mode_object B"
  139. "drm_property B" -> "drm_mode_object A"
  140. }
  141. The base structure for all KMS objects is :c:type:`struct drm_mode_object
  142. <drm_mode_object>`. One of the base services it provides is tracking properties,
  143. which are especially important for the atomic IOCTL (see `Atomic Mode
  144. Setting`_). The somewhat surprising part here is that properties are not
  145. directly instantiated on each object, but free-standing mode objects themselves,
  146. represented by :c:type:`struct drm_property <drm_property>`, which only specify
  147. the type and value range of a property. Any given property can be attached
  148. multiple times to different objects using drm_object_attach_property().
  149. .. kernel-doc:: include/drm/drm_mode_object.h
  150. :internal:
  151. .. kernel-doc:: drivers/gpu/drm/drm_mode_object.c
  152. :export:
  153. Atomic Mode Setting
  154. ===================
  155. .. kernel-render:: DOT
  156. :alt: Mode Objects and Properties
  157. :caption: Mode Objects and Properties
  158. digraph {
  159. node [shape=box]
  160. subgraph cluster_state {
  161. style=dashed
  162. label="Free-standing state"
  163. "drm_atomic_state" -> "duplicated drm_plane_state A"
  164. "drm_atomic_state" -> "duplicated drm_plane_state B"
  165. "drm_atomic_state" -> "duplicated drm_crtc_state"
  166. "drm_atomic_state" -> "duplicated drm_connector_state"
  167. "drm_atomic_state" -> "duplicated driver private state"
  168. }
  169. subgraph cluster_current {
  170. style=dashed
  171. label="Current state"
  172. "drm_device" -> "drm_plane A"
  173. "drm_device" -> "drm_plane B"
  174. "drm_device" -> "drm_crtc"
  175. "drm_device" -> "drm_connector"
  176. "drm_device" -> "driver private object"
  177. "drm_plane A" -> "drm_plane_state A"
  178. "drm_plane B" -> "drm_plane_state B"
  179. "drm_crtc" -> "drm_crtc_state"
  180. "drm_connector" -> "drm_connector_state"
  181. "driver private object" -> "driver private state"
  182. }
  183. "drm_atomic_state" -> "drm_device" [label="atomic_commit"]
  184. "duplicated drm_plane_state A" -> "drm_device"[style=invis]
  185. }
  186. Atomic provides transactional modeset (including planes) updates, but a
  187. bit differently from the usual transactional approach of try-commit and
  188. rollback:
  189. - Firstly, no hardware changes are allowed when the commit would fail. This
  190. allows us to implement the DRM_MODE_ATOMIC_TEST_ONLY mode, which allows
  191. userspace to explore whether certain configurations would work or not.
  192. - This would still allow setting and rollback of just the software state,
  193. simplifying conversion of existing drivers. But auditing drivers for
  194. correctness of the atomic_check code becomes really hard with that: Rolling
  195. back changes in data structures all over the place is hard to get right.
  196. - Lastly, for backwards compatibility and to support all use-cases, atomic
  197. updates need to be incremental and be able to execute in parallel. Hardware
  198. doesn't always allow it, but where possible plane updates on different CRTCs
  199. should not interfere, and not get stalled due to output routing changing on
  200. different CRTCs.
  201. Taken all together there's two consequences for the atomic design:
  202. - The overall state is split up into per-object state structures:
  203. :c:type:`struct drm_plane_state <drm_plane_state>` for planes, :c:type:`struct
  204. drm_crtc_state <drm_crtc_state>` for CRTCs and :c:type:`struct
  205. drm_connector_state <drm_connector_state>` for connectors. These are the only
  206. objects with userspace-visible and settable state. For internal state drivers
  207. can subclass these structures through embeddeding, or add entirely new state
  208. structures for their globally shared hardware functions, see :c:type:`struct
  209. drm_private_state<drm_private_state>`.
  210. - An atomic update is assembled and validated as an entirely free-standing pile
  211. of structures within the :c:type:`drm_atomic_state <drm_atomic_state>`
  212. container. Driver private state structures are also tracked in the same
  213. structure; see the next chapter. Only when a state is committed is it applied
  214. to the driver and modeset objects. This way rolling back an update boils down
  215. to releasing memory and unreferencing objects like framebuffers.
  216. Locking of atomic state structures is internally using :c:type:`struct
  217. drm_modeset_lock <drm_modeset_lock>`. As a general rule the locking shouldn't be
  218. exposed to drivers, instead the right locks should be automatically acquired by
  219. any function that duplicates or peeks into a state, like e.g.
  220. drm_atomic_get_crtc_state(). Locking only protects the software data
  221. structure, ordering of committing state changes to hardware is sequenced using
  222. :c:type:`struct drm_crtc_commit <drm_crtc_commit>`.
  223. Read on in this chapter, and also in :ref:`drm_atomic_helper` for more detailed
  224. coverage of specific topics.
  225. Handling Driver Private State
  226. -----------------------------
  227. .. kernel-doc:: drivers/gpu/drm/drm_atomic.c
  228. :doc: handling driver private state
  229. Atomic Mode Setting Function Reference
  230. --------------------------------------
  231. .. kernel-doc:: include/drm/drm_atomic.h
  232. :internal:
  233. .. kernel-doc:: drivers/gpu/drm/drm_atomic.c
  234. :export:
  235. Atomic Mode Setting IOCTL and UAPI Functions
  236. --------------------------------------------
  237. .. kernel-doc:: drivers/gpu/drm/drm_atomic_uapi.c
  238. :doc: overview
  239. .. kernel-doc:: drivers/gpu/drm/drm_atomic_uapi.c
  240. :export:
  241. CRTC Abstraction
  242. ================
  243. .. kernel-doc:: drivers/gpu/drm/drm_crtc.c
  244. :doc: overview
  245. CRTC Functions Reference
  246. --------------------------------
  247. .. kernel-doc:: include/drm/drm_crtc.h
  248. :internal:
  249. .. kernel-doc:: drivers/gpu/drm/drm_crtc.c
  250. :export:
  251. Color Management Functions Reference
  252. ------------------------------------
  253. .. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c
  254. :export:
  255. .. kernel-doc:: include/drm/drm_color_mgmt.h
  256. :internal:
  257. Frame Buffer Abstraction
  258. ========================
  259. .. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c
  260. :doc: overview
  261. Frame Buffer Functions Reference
  262. --------------------------------
  263. .. kernel-doc:: include/drm/drm_framebuffer.h
  264. :internal:
  265. .. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c
  266. :export:
  267. DRM Format Handling
  268. ===================
  269. .. kernel-doc:: include/uapi/drm/drm_fourcc.h
  270. :doc: overview
  271. Format Functions Reference
  272. --------------------------
  273. .. kernel-doc:: include/drm/drm_fourcc.h
  274. :internal:
  275. .. kernel-doc:: drivers/gpu/drm/drm_fourcc.c
  276. :export:
  277. Dumb Buffer Objects
  278. ===================
  279. .. kernel-doc:: drivers/gpu/drm/drm_dumb_buffers.c
  280. :doc: overview
  281. Plane Abstraction
  282. =================
  283. .. kernel-doc:: drivers/gpu/drm/drm_plane.c
  284. :doc: overview
  285. Plane Functions Reference
  286. -------------------------
  287. .. kernel-doc:: include/drm/drm_plane.h
  288. :internal:
  289. .. kernel-doc:: drivers/gpu/drm/drm_plane.c
  290. :export:
  291. Plane Composition Functions Reference
  292. -------------------------------------
  293. .. kernel-doc:: drivers/gpu/drm/drm_blend.c
  294. :export:
  295. Plane Damage Tracking Functions Reference
  296. -----------------------------------------
  297. .. kernel-doc:: drivers/gpu/drm/drm_damage_helper.c
  298. :export:
  299. .. kernel-doc:: include/drm/drm_damage_helper.h
  300. :internal:
  301. Display Modes Function Reference
  302. ================================
  303. .. kernel-doc:: include/drm/drm_modes.h
  304. :internal:
  305. .. kernel-doc:: drivers/gpu/drm/drm_modes.c
  306. :export:
  307. Connector Abstraction
  308. =====================
  309. .. kernel-doc:: drivers/gpu/drm/drm_connector.c
  310. :doc: overview
  311. Connector Functions Reference
  312. -----------------------------
  313. .. kernel-doc:: include/drm/drm_connector.h
  314. :internal:
  315. .. kernel-doc:: drivers/gpu/drm/drm_connector.c
  316. :export:
  317. Writeback Connectors
  318. --------------------
  319. .. kernel-doc:: drivers/gpu/drm/drm_writeback.c
  320. :doc: overview
  321. .. kernel-doc:: include/drm/drm_writeback.h
  322. :internal:
  323. .. kernel-doc:: drivers/gpu/drm/drm_writeback.c
  324. :export:
  325. Encoder Abstraction
  326. ===================
  327. .. kernel-doc:: drivers/gpu/drm/drm_encoder.c
  328. :doc: overview
  329. Encoder Functions Reference
  330. ---------------------------
  331. .. kernel-doc:: include/drm/drm_encoder.h
  332. :internal:
  333. .. kernel-doc:: drivers/gpu/drm/drm_encoder.c
  334. :export:
  335. KMS Locking
  336. ===========
  337. .. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
  338. :doc: kms locking
  339. .. kernel-doc:: include/drm/drm_modeset_lock.h
  340. :internal:
  341. .. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
  342. :export:
  343. KMS Properties
  344. ==============
  345. This section of the documentation is primarily aimed at user-space developers.
  346. For the driver APIs, see the other sections.
  347. Requirements
  348. ------------
  349. KMS drivers might need to add extra properties to support new features. Each
  350. new property introduced in a driver needs to meet a few requirements, in
  351. addition to the one mentioned above:
  352. * It must be standardized, documenting:
  353. * The full, exact, name string;
  354. * If the property is an enum, all the valid value name strings;
  355. * What values are accepted, and what these values mean;
  356. * What the property does and how it can be used;
  357. * How the property might interact with other, existing properties.
  358. * It must provide a generic helper in the core code to register that
  359. property on the object it attaches to.
  360. * Its content must be decoded by the core and provided in the object's
  361. associated state structure. That includes anything drivers might want
  362. to precompute, like struct drm_clip_rect for planes.
  363. * Its initial state must match the behavior prior to the property
  364. introduction. This might be a fixed value matching what the hardware
  365. does, or it may be inherited from the state the firmware left the
  366. system in during boot.
  367. * An IGT test must be submitted where reasonable.
  368. Property Types and Blob Property Support
  369. ----------------------------------------
  370. .. kernel-doc:: drivers/gpu/drm/drm_property.c
  371. :doc: overview
  372. .. kernel-doc:: include/drm/drm_property.h
  373. :internal:
  374. .. kernel-doc:: drivers/gpu/drm/drm_property.c
  375. :export:
  376. .. _standard_connector_properties:
  377. Standard Connector Properties
  378. -----------------------------
  379. .. kernel-doc:: drivers/gpu/drm/drm_connector.c
  380. :doc: standard connector properties
  381. HDMI Specific Connector Properties
  382. ----------------------------------
  383. .. kernel-doc:: drivers/gpu/drm/drm_connector.c
  384. :doc: HDMI connector properties
  385. Standard CRTC Properties
  386. ------------------------
  387. .. kernel-doc:: drivers/gpu/drm/drm_crtc.c
  388. :doc: standard CRTC properties
  389. Standard Plane Properties
  390. -------------------------
  391. .. kernel-doc:: drivers/gpu/drm/drm_plane.c
  392. :doc: standard plane properties
  393. .. _plane_composition_properties:
  394. Plane Composition Properties
  395. ----------------------------
  396. .. kernel-doc:: drivers/gpu/drm/drm_blend.c
  397. :doc: overview
  398. Damage Tracking Properties
  399. --------------------------
  400. .. kernel-doc:: drivers/gpu/drm/drm_plane.c
  401. :doc: damage tracking
  402. Color Management Properties
  403. ---------------------------
  404. .. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c
  405. :doc: overview
  406. Tile Group Property
  407. -------------------
  408. .. kernel-doc:: drivers/gpu/drm/drm_connector.c
  409. :doc: Tile group
  410. Explicit Fencing Properties
  411. ---------------------------
  412. .. kernel-doc:: drivers/gpu/drm/drm_atomic_uapi.c
  413. :doc: explicit fencing properties
  414. Variable Refresh Properties
  415. ---------------------------
  416. .. kernel-doc:: drivers/gpu/drm/drm_connector.c
  417. :doc: Variable refresh properties
  418. Existing KMS Properties
  419. -----------------------
  420. The following table gives description of drm properties exposed by various
  421. modules/drivers. Because this table is very unwieldy, do not add any new
  422. properties here. Instead document them in a section above.
  423. .. csv-table::
  424. :header-rows: 1
  425. :file: kms-properties.csv
  426. Vertical Blanking
  427. =================
  428. .. kernel-doc:: drivers/gpu/drm/drm_vblank.c
  429. :doc: vblank handling
  430. Vertical Blanking and Interrupt Handling Functions Reference
  431. ------------------------------------------------------------
  432. .. kernel-doc:: include/drm/drm_vblank.h
  433. :internal:
  434. .. kernel-doc:: drivers/gpu/drm/drm_vblank.c
  435. :export:
  436. Vertical Blank Work
  437. ===================
  438. .. kernel-doc:: drivers/gpu/drm/drm_vblank_work.c
  439. :doc: vblank works
  440. Vertical Blank Work Functions Reference
  441. ---------------------------------------
  442. .. kernel-doc:: include/drm/drm_vblank_work.h
  443. :internal:
  444. .. kernel-doc:: drivers/gpu/drm/drm_vblank_work.c
  445. :export: