drm-kms.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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 unnecessarily 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. Furthermore 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 embedding, 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. .. _kms_dumb_buffer_objects:
  278. Dumb Buffer Objects
  279. ===================
  280. .. kernel-doc:: drivers/gpu/drm/drm_dumb_buffers.c
  281. :doc: overview
  282. Plane Abstraction
  283. =================
  284. .. kernel-doc:: drivers/gpu/drm/drm_plane.c
  285. :doc: overview
  286. Plane Functions Reference
  287. -------------------------
  288. .. kernel-doc:: include/drm/drm_plane.h
  289. :internal:
  290. .. kernel-doc:: drivers/gpu/drm/drm_plane.c
  291. :export:
  292. Plane Composition Functions Reference
  293. -------------------------------------
  294. .. kernel-doc:: drivers/gpu/drm/drm_blend.c
  295. :export:
  296. Plane Damage Tracking Functions Reference
  297. -----------------------------------------
  298. .. kernel-doc:: drivers/gpu/drm/drm_damage_helper.c
  299. :export:
  300. .. kernel-doc:: include/drm/drm_damage_helper.h
  301. :internal:
  302. Plane Panic Feature
  303. -------------------
  304. .. kernel-doc:: drivers/gpu/drm/drm_panic.c
  305. :doc: overview
  306. Plane Panic Functions Reference
  307. -------------------------------
  308. .. kernel-doc:: include/drm/drm_panic.h
  309. :internal:
  310. .. kernel-doc:: drivers/gpu/drm/drm_panic.c
  311. :export:
  312. Display Modes Function Reference
  313. ================================
  314. .. kernel-doc:: include/drm/drm_modes.h
  315. :internal:
  316. .. kernel-doc:: drivers/gpu/drm/drm_modes.c
  317. :export:
  318. Connector Abstraction
  319. =====================
  320. .. kernel-doc:: drivers/gpu/drm/drm_connector.c
  321. :doc: overview
  322. Connector Functions Reference
  323. -----------------------------
  324. .. kernel-doc:: include/drm/drm_connector.h
  325. :internal:
  326. .. kernel-doc:: drivers/gpu/drm/drm_connector.c
  327. :export:
  328. Writeback Connectors
  329. --------------------
  330. .. kernel-doc:: drivers/gpu/drm/drm_writeback.c
  331. :doc: overview
  332. .. kernel-doc:: include/drm/drm_writeback.h
  333. :internal:
  334. .. kernel-doc:: drivers/gpu/drm/drm_writeback.c
  335. :export:
  336. Encoder Abstraction
  337. ===================
  338. .. kernel-doc:: drivers/gpu/drm/drm_encoder.c
  339. :doc: overview
  340. Encoder Functions Reference
  341. ---------------------------
  342. .. kernel-doc:: include/drm/drm_encoder.h
  343. :internal:
  344. .. kernel-doc:: drivers/gpu/drm/drm_encoder.c
  345. :export:
  346. KMS Locking
  347. ===========
  348. .. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
  349. :doc: kms locking
  350. .. kernel-doc:: include/drm/drm_modeset_lock.h
  351. :internal:
  352. .. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
  353. :export:
  354. KMS Properties
  355. ==============
  356. This section of the documentation is primarily aimed at user-space developers.
  357. For the driver APIs, see the other sections.
  358. Requirements
  359. ------------
  360. KMS drivers might need to add extra properties to support new features. Each
  361. new property introduced in a driver needs to meet a few requirements, in
  362. addition to the one mentioned above:
  363. * It must be standardized, documenting:
  364. * The full, exact, name string;
  365. * If the property is an enum, all the valid value name strings;
  366. * What values are accepted, and what these values mean;
  367. * What the property does and how it can be used;
  368. * How the property might interact with other, existing properties.
  369. * It must provide a generic helper in the core code to register that
  370. property on the object it attaches to.
  371. * Its content must be decoded by the core and provided in the object's
  372. associated state structure. That includes anything drivers might want
  373. to precompute, like struct drm_clip_rect for planes.
  374. * Its initial state must match the behavior prior to the property
  375. introduction. This might be a fixed value matching what the hardware
  376. does, or it may be inherited from the state the firmware left the
  377. system in during boot.
  378. * An IGT test must be submitted where reasonable.
  379. For historical reasons, non-standard, driver-specific properties exist. If a KMS
  380. driver wants to add support for one of those properties, the requirements for
  381. new properties apply where possible. Additionally, the documented behavior must
  382. match the de facto semantics of the existing property to ensure compatibility.
  383. Developers of the driver that first added the property should help with those
  384. tasks and must ACK the documented behavior if possible.
  385. Property Types and Blob Property Support
  386. ----------------------------------------
  387. .. kernel-doc:: drivers/gpu/drm/drm_property.c
  388. :doc: overview
  389. .. kernel-doc:: include/drm/drm_property.h
  390. :internal:
  391. .. kernel-doc:: drivers/gpu/drm/drm_property.c
  392. :export:
  393. .. _standard_connector_properties:
  394. Standard Connector Properties
  395. -----------------------------
  396. .. kernel-doc:: drivers/gpu/drm/drm_connector.c
  397. :doc: standard connector properties
  398. HDMI Specific Connector Properties
  399. ----------------------------------
  400. .. kernel-doc:: drivers/gpu/drm/drm_connector.c
  401. :doc: HDMI connector properties
  402. Analog TV Specific Connector Properties
  403. ---------------------------------------
  404. .. kernel-doc:: drivers/gpu/drm/drm_connector.c
  405. :doc: Analog TV Connector Properties
  406. Standard CRTC Properties
  407. ------------------------
  408. .. kernel-doc:: drivers/gpu/drm/drm_crtc.c
  409. :doc: standard CRTC properties
  410. Standard Plane Properties
  411. -------------------------
  412. .. kernel-doc:: drivers/gpu/drm/drm_plane.c
  413. :doc: standard plane properties
  414. .. _plane_composition_properties:
  415. Plane Composition Properties
  416. ----------------------------
  417. .. kernel-doc:: drivers/gpu/drm/drm_blend.c
  418. :doc: overview
  419. .. _damage_tracking_properties:
  420. Damage Tracking Properties
  421. --------------------------
  422. .. kernel-doc:: drivers/gpu/drm/drm_plane.c
  423. :doc: damage tracking
  424. Color Management Properties
  425. ---------------------------
  426. .. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c
  427. :doc: overview
  428. Tile Group Property
  429. -------------------
  430. .. kernel-doc:: drivers/gpu/drm/drm_connector.c
  431. :doc: Tile group
  432. Explicit Fencing Properties
  433. ---------------------------
  434. .. kernel-doc:: drivers/gpu/drm/drm_atomic_uapi.c
  435. :doc: explicit fencing properties
  436. Variable Refresh Properties
  437. ---------------------------
  438. .. kernel-doc:: drivers/gpu/drm/drm_connector.c
  439. :doc: Variable refresh properties
  440. Cursor Hotspot Properties
  441. ---------------------------
  442. .. kernel-doc:: drivers/gpu/drm/drm_plane.c
  443. :doc: hotspot properties
  444. Existing KMS Properties
  445. -----------------------
  446. The following table gives description of drm properties exposed by various
  447. modules/drivers. Because this table is very unwieldy, do not add any new
  448. properties here. Instead document them in a section above.
  449. .. csv-table::
  450. :header-rows: 1
  451. :file: kms-properties.csv
  452. Vertical Blanking
  453. =================
  454. .. kernel-doc:: drivers/gpu/drm/drm_vblank.c
  455. :doc: vblank handling
  456. Vertical Blanking and Interrupt Handling Functions Reference
  457. ------------------------------------------------------------
  458. .. kernel-doc:: include/drm/drm_vblank.h
  459. :internal:
  460. .. kernel-doc:: drivers/gpu/drm/drm_vblank.c
  461. :export:
  462. Vertical Blank Work
  463. ===================
  464. .. kernel-doc:: drivers/gpu/drm/drm_vblank_work.c
  465. :doc: vblank works
  466. Vertical Blank Work Functions Reference
  467. ---------------------------------------
  468. .. kernel-doc:: include/drm/drm_vblank_work.h
  469. :internal:
  470. .. kernel-doc:: drivers/gpu/drm/drm_vblank_work.c
  471. :export: