drm_modeset_helper_vtables.h 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. /*
  2. * Copyright © 2006 Keith Packard
  3. * Copyright © 2007-2008 Dave Airlie
  4. * Copyright © 2007-2008 Intel Corporation
  5. * Jesse Barnes <jesse.barnes@intel.com>
  6. * Copyright © 2011-2013 Intel Corporation
  7. * Copyright © 2015 Intel Corporation
  8. * Daniel Vetter <daniel.vetter@ffwll.ch>
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a
  11. * copy of this software and associated documentation files (the "Software"),
  12. * to deal in the Software without restriction, including without limitation
  13. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  14. * and/or sell copies of the Software, and to permit persons to whom the
  15. * Software is furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included in
  18. * all copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  23. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  24. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  25. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  26. * OTHER DEALINGS IN THE SOFTWARE.
  27. */
  28. #ifndef __DRM_MODESET_HELPER_VTABLES_H__
  29. #define __DRM_MODESET_HELPER_VTABLES_H__
  30. #include <drm/drm_crtc.h>
  31. /**
  32. * DOC: overview
  33. *
  34. * The DRM mode setting helper functions are common code for drivers to use if
  35. * they wish. Drivers are not forced to use this code in their
  36. * implementations but it would be useful if the code they do use at least
  37. * provides a consistent interface and operation to userspace. Therefore it is
  38. * highly recommended to use the provided helpers as much as possible.
  39. *
  40. * Because there is only one pointer per modeset object to hold a vfunc table
  41. * for helper libraries they are by necessity shared among the different
  42. * helpers.
  43. *
  44. * To make this clear all the helper vtables are pulled together in this location here.
  45. */
  46. enum mode_set_atomic;
  47. /**
  48. * struct drm_crtc_helper_funcs - helper operations for CRTCs
  49. *
  50. * These hooks are used by the legacy CRTC helpers, the transitional plane
  51. * helpers and the new atomic modesetting helpers.
  52. */
  53. struct drm_crtc_helper_funcs {
  54. /**
  55. * @dpms:
  56. *
  57. * Callback to control power levels on the CRTC. If the mode passed in
  58. * is unsupported, the provider must use the next lowest power level.
  59. * This is used by the legacy CRTC helpers to implement DPMS
  60. * functionality in drm_helper_connector_dpms().
  61. *
  62. * This callback is also used to disable a CRTC by calling it with
  63. * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
  64. *
  65. * This callback is used by the legacy CRTC helpers. Atomic helpers
  66. * also support using this hook for enabling and disabling a CRTC to
  67. * facilitate transitions to atomic, but it is deprecated. Instead
  68. * @enable and @disable should be used.
  69. */
  70. void (*dpms)(struct drm_crtc *crtc, int mode);
  71. /**
  72. * @prepare:
  73. *
  74. * This callback should prepare the CRTC for a subsequent modeset, which
  75. * in practice means the driver should disable the CRTC if it is
  76. * running. Most drivers ended up implementing this by calling their
  77. * @dpms hook with DRM_MODE_DPMS_OFF.
  78. *
  79. * This callback is used by the legacy CRTC helpers. Atomic helpers
  80. * also support using this hook for disabling a CRTC to facilitate
  81. * transitions to atomic, but it is deprecated. Instead @disable should
  82. * be used.
  83. */
  84. void (*prepare)(struct drm_crtc *crtc);
  85. /**
  86. * @commit:
  87. *
  88. * This callback should commit the new mode on the CRTC after a modeset,
  89. * which in practice means the driver should enable the CRTC. Most
  90. * drivers ended up implementing this by calling their @dpms hook with
  91. * DRM_MODE_DPMS_ON.
  92. *
  93. * This callback is used by the legacy CRTC helpers. Atomic helpers
  94. * also support using this hook for enabling a CRTC to facilitate
  95. * transitions to atomic, but it is deprecated. Instead @enable should
  96. * be used.
  97. */
  98. void (*commit)(struct drm_crtc *crtc);
  99. /**
  100. * @mode_fixup:
  101. *
  102. * This callback is used to validate a mode. The parameter mode is the
  103. * display mode that userspace requested, adjusted_mode is the mode the
  104. * encoders need to be fed with. Note that this is the inverse semantics
  105. * of the meaning for the &drm_encoder and &drm_bridge
  106. * ->mode_fixup() functions. If the CRTC cannot support the requested
  107. * conversion from mode to adjusted_mode it should reject the modeset.
  108. *
  109. * This function is used by both legacy CRTC helpers and atomic helpers.
  110. * With atomic helpers it is optional.
  111. *
  112. * NOTE:
  113. *
  114. * This function is called in the check phase of atomic modesets, which
  115. * can be aborted for any reason (including on userspace's request to
  116. * just check whether a configuration would be possible). Atomic drivers
  117. * MUST NOT touch any persistent state (hardware or software) or data
  118. * structures except the passed in adjusted_mode parameter.
  119. *
  120. * This is in contrast to the legacy CRTC helpers where this was
  121. * allowed.
  122. *
  123. * Atomic drivers which need to inspect and adjust more state should
  124. * instead use the @atomic_check callback.
  125. *
  126. * Also beware that neither core nor helpers filter modes before
  127. * passing them to the driver: While the list of modes that is
  128. * advertised to userspace is filtered using the connector's
  129. * ->mode_valid() callback, neither the core nor the helpers do any
  130. * filtering on modes passed in from userspace when setting a mode. It
  131. * is therefore possible for userspace to pass in a mode that was
  132. * previously filtered out using ->mode_valid() or add a custom mode
  133. * that wasn't probed from EDID or similar to begin with. Even though
  134. * this is an advanced feature and rarely used nowadays, some users rely
  135. * on being able to specify modes manually so drivers must be prepared
  136. * to deal with it. Specifically this means that all drivers need not
  137. * only validate modes in ->mode_valid() but also in ->mode_fixup() to
  138. * make sure invalid modes passed in from userspace are rejected.
  139. *
  140. * RETURNS:
  141. *
  142. * True if an acceptable configuration is possible, false if the modeset
  143. * operation should be rejected.
  144. */
  145. bool (*mode_fixup)(struct drm_crtc *crtc,
  146. const struct drm_display_mode *mode,
  147. struct drm_display_mode *adjusted_mode);
  148. /**
  149. * @mode_set:
  150. *
  151. * This callback is used by the legacy CRTC helpers to set a new mode,
  152. * position and framebuffer. Since it ties the primary plane to every
  153. * mode change it is incompatible with universal plane support. And
  154. * since it can't update other planes it's incompatible with atomic
  155. * modeset support.
  156. *
  157. * This callback is only used by CRTC helpers and deprecated.
  158. *
  159. * RETURNS:
  160. *
  161. * 0 on success or a negative error code on failure.
  162. */
  163. int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
  164. struct drm_display_mode *adjusted_mode, int x, int y,
  165. struct drm_framebuffer *old_fb);
  166. /**
  167. * @mode_set_nofb:
  168. *
  169. * This callback is used to update the display mode of a CRTC without
  170. * changing anything of the primary plane configuration. This fits the
  171. * requirement of atomic and hence is used by the atomic helpers. It is
  172. * also used by the transitional plane helpers to implement a
  173. * @mode_set hook in drm_helper_crtc_mode_set().
  174. *
  175. * Note that the display pipe is completely off when this function is
  176. * called. Atomic drivers which need hardware to be running before they
  177. * program the new display mode (e.g. because they implement runtime PM)
  178. * should not use this hook. This is because the helper library calls
  179. * this hook only once per mode change and not every time the display
  180. * pipeline is suspended using either DPMS or the new "ACTIVE" property.
  181. * Which means register values set in this callback might get reset when
  182. * the CRTC is suspended, but not restored. Such drivers should instead
  183. * move all their CRTC setup into the @enable callback.
  184. *
  185. * This callback is optional.
  186. */
  187. void (*mode_set_nofb)(struct drm_crtc *crtc);
  188. /**
  189. * @mode_set_base:
  190. *
  191. * This callback is used by the legacy CRTC helpers to set a new
  192. * framebuffer and scanout position. It is optional and used as an
  193. * optimized fast-path instead of a full mode set operation with all the
  194. * resulting flickering. If it is not present
  195. * drm_crtc_helper_set_config() will fall back to a full modeset, using
  196. * the ->mode_set() callback. Since it can't update other planes it's
  197. * incompatible with atomic modeset support.
  198. *
  199. * This callback is only used by the CRTC helpers and deprecated.
  200. *
  201. * RETURNS:
  202. *
  203. * 0 on success or a negative error code on failure.
  204. */
  205. int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
  206. struct drm_framebuffer *old_fb);
  207. /**
  208. * @mode_set_base_atomic:
  209. *
  210. * This callback is used by the fbdev helpers to set a new framebuffer
  211. * and scanout without sleeping, i.e. from an atomic calling context. It
  212. * is only used to implement kgdb support.
  213. *
  214. * This callback is optional and only needed for kgdb support in the fbdev
  215. * helpers.
  216. *
  217. * RETURNS:
  218. *
  219. * 0 on success or a negative error code on failure.
  220. */
  221. int (*mode_set_base_atomic)(struct drm_crtc *crtc,
  222. struct drm_framebuffer *fb, int x, int y,
  223. enum mode_set_atomic);
  224. /**
  225. * @load_lut:
  226. *
  227. * Load a LUT prepared with the @gamma_set functions from
  228. * &drm_fb_helper_funcs.
  229. *
  230. * This callback is optional and is only used by the fbdev emulation
  231. * helpers.
  232. *
  233. * FIXME:
  234. *
  235. * This callback is functionally redundant with the core gamma table
  236. * support and simply exists because the fbdev hasn't yet been
  237. * refactored to use the core gamma table interfaces.
  238. */
  239. void (*load_lut)(struct drm_crtc *crtc);
  240. /**
  241. * @disable:
  242. *
  243. * This callback should be used to disable the CRTC. With the atomic
  244. * drivers it is called after all encoders connected to this CRTC have
  245. * been shut off already using their own ->disable hook. If that
  246. * sequence is too simple drivers can just add their own hooks and call
  247. * it from this CRTC callback here by looping over all encoders
  248. * connected to it using for_each_encoder_on_crtc().
  249. *
  250. * This hook is used both by legacy CRTC helpers and atomic helpers.
  251. * Atomic drivers don't need to implement it if there's no need to
  252. * disable anything at the CRTC level. To ensure that runtime PM
  253. * handling (using either DPMS or the new "ACTIVE" property) works
  254. * @disable must be the inverse of @enable for atomic drivers.
  255. * Atomic drivers should consider to use @atomic_disable instead of
  256. * this one.
  257. *
  258. * NOTE:
  259. *
  260. * With legacy CRTC helpers there's a big semantic difference between
  261. * @disable and other hooks (like @prepare or @dpms) used to shut down a
  262. * CRTC: @disable is only called when also logically disabling the
  263. * display pipeline and needs to release any resources acquired in
  264. * @mode_set (like shared PLLs, or again release pinned framebuffers).
  265. *
  266. * Therefore @disable must be the inverse of @mode_set plus @commit for
  267. * drivers still using legacy CRTC helpers, which is different from the
  268. * rules under atomic.
  269. */
  270. void (*disable)(struct drm_crtc *crtc);
  271. /**
  272. * @enable:
  273. *
  274. * This callback should be used to enable the CRTC. With the atomic
  275. * drivers it is called before all encoders connected to this CRTC are
  276. * enabled through the encoder's own ->enable hook. If that sequence is
  277. * too simple drivers can just add their own hooks and call it from this
  278. * CRTC callback here by looping over all encoders connected to it using
  279. * for_each_encoder_on_crtc().
  280. *
  281. * This hook is used only by atomic helpers, for symmetry with @disable.
  282. * Atomic drivers don't need to implement it if there's no need to
  283. * enable anything at the CRTC level. To ensure that runtime PM handling
  284. * (using either DPMS or the new "ACTIVE" property) works
  285. * @enable must be the inverse of @disable for atomic drivers.
  286. */
  287. void (*enable)(struct drm_crtc *crtc);
  288. /**
  289. * @atomic_check:
  290. *
  291. * Drivers should check plane-update related CRTC constraints in this
  292. * hook. They can also check mode related limitations but need to be
  293. * aware of the calling order, since this hook is used by
  294. * drm_atomic_helper_check_planes() whereas the preparations needed to
  295. * check output routing and the display mode is done in
  296. * drm_atomic_helper_check_modeset(). Therefore drivers that want to
  297. * check output routing and display mode constraints in this callback
  298. * must ensure that drm_atomic_helper_check_modeset() has been called
  299. * beforehand. This is calling order used by the default helper
  300. * implementation in drm_atomic_helper_check().
  301. *
  302. * When using drm_atomic_helper_check_planes() CRTCs' ->atomic_check()
  303. * hooks are called after the ones for planes, which allows drivers to
  304. * assign shared resources requested by planes in the CRTC callback
  305. * here. For more complicated dependencies the driver can call the provided
  306. * check helpers multiple times until the computed state has a final
  307. * configuration and everything has been checked.
  308. *
  309. * This function is also allowed to inspect any other object's state and
  310. * can add more state objects to the atomic commit if needed. Care must
  311. * be taken though to ensure that state check&compute functions for
  312. * these added states are all called, and derived state in other objects
  313. * all updated. Again the recommendation is to just call check helpers
  314. * until a maximal configuration is reached.
  315. *
  316. * This callback is used by the atomic modeset helpers and by the
  317. * transitional plane helpers, but it is optional.
  318. *
  319. * NOTE:
  320. *
  321. * This function is called in the check phase of an atomic update. The
  322. * driver is not allowed to change anything outside of the free-standing
  323. * state objects passed-in or assembled in the overall &drm_atomic_state
  324. * update tracking structure.
  325. *
  326. * RETURNS:
  327. *
  328. * 0 on success, -EINVAL if the state or the transition can't be
  329. * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
  330. * attempt to obtain another state object ran into a &drm_modeset_lock
  331. * deadlock.
  332. */
  333. int (*atomic_check)(struct drm_crtc *crtc,
  334. struct drm_crtc_state *state);
  335. /**
  336. * @atomic_begin:
  337. *
  338. * Drivers should prepare for an atomic update of multiple planes on
  339. * a CRTC in this hook. Depending upon hardware this might be vblank
  340. * evasion, blocking updates by setting bits or doing preparatory work
  341. * for e.g. manual update display.
  342. *
  343. * This hook is called before any plane commit functions are called.
  344. *
  345. * Note that the power state of the display pipe when this function is
  346. * called depends upon the exact helpers and calling sequence the driver
  347. * has picked. See drm_atomic_commit_planes() for a discussion of the
  348. * tradeoffs and variants of plane commit helpers.
  349. *
  350. * This callback is used by the atomic modeset helpers and by the
  351. * transitional plane helpers, but it is optional.
  352. */
  353. void (*atomic_begin)(struct drm_crtc *crtc,
  354. struct drm_crtc_state *old_crtc_state);
  355. /**
  356. * @atomic_flush:
  357. *
  358. * Drivers should finalize an atomic update of multiple planes on
  359. * a CRTC in this hook. Depending upon hardware this might include
  360. * checking that vblank evasion was successful, unblocking updates by
  361. * setting bits or setting the GO bit to flush out all updates.
  362. *
  363. * Simple hardware or hardware with special requirements can commit and
  364. * flush out all updates for all planes from this hook and forgo all the
  365. * other commit hooks for plane updates.
  366. *
  367. * This hook is called after any plane commit functions are called.
  368. *
  369. * Note that the power state of the display pipe when this function is
  370. * called depends upon the exact helpers and calling sequence the driver
  371. * has picked. See drm_atomic_commit_planes() for a discussion of the
  372. * tradeoffs and variants of plane commit helpers.
  373. *
  374. * This callback is used by the atomic modeset helpers and by the
  375. * transitional plane helpers, but it is optional.
  376. */
  377. void (*atomic_flush)(struct drm_crtc *crtc,
  378. struct drm_crtc_state *old_crtc_state);
  379. /**
  380. * @atomic_disable:
  381. *
  382. * This callback should be used to disable the CRTC. With the atomic
  383. * drivers it is called after all encoders connected to this CRTC have
  384. * been shut off already using their own ->disable hook. If that
  385. * sequence is too simple drivers can just add their own hooks and call
  386. * it from this CRTC callback here by looping over all encoders
  387. * connected to it using for_each_encoder_on_crtc().
  388. *
  389. * This hook is used only by atomic helpers. Atomic drivers don't
  390. * need to implement it if there's no need to disable anything at the
  391. * CRTC level.
  392. *
  393. * Comparing to @disable, this one provides the additional input
  394. * parameter @old_crtc_state which could be used to access the old
  395. * state. Atomic drivers should consider to use this one instead
  396. * of @disable.
  397. */
  398. void (*atomic_disable)(struct drm_crtc *crtc,
  399. struct drm_crtc_state *old_crtc_state);
  400. };
  401. /**
  402. * drm_crtc_helper_add - sets the helper vtable for a crtc
  403. * @crtc: DRM CRTC
  404. * @funcs: helper vtable to set for @crtc
  405. */
  406. static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
  407. const struct drm_crtc_helper_funcs *funcs)
  408. {
  409. crtc->helper_private = funcs;
  410. }
  411. /**
  412. * struct drm_encoder_helper_funcs - helper operations for encoders
  413. *
  414. * These hooks are used by the legacy CRTC helpers, the transitional plane
  415. * helpers and the new atomic modesetting helpers.
  416. */
  417. struct drm_encoder_helper_funcs {
  418. /**
  419. * @dpms:
  420. *
  421. * Callback to control power levels on the encoder. If the mode passed in
  422. * is unsupported, the provider must use the next lowest power level.
  423. * This is used by the legacy encoder helpers to implement DPMS
  424. * functionality in drm_helper_connector_dpms().
  425. *
  426. * This callback is also used to disable an encoder by calling it with
  427. * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
  428. *
  429. * This callback is used by the legacy CRTC helpers. Atomic helpers
  430. * also support using this hook for enabling and disabling an encoder to
  431. * facilitate transitions to atomic, but it is deprecated. Instead
  432. * @enable and @disable should be used.
  433. */
  434. void (*dpms)(struct drm_encoder *encoder, int mode);
  435. /**
  436. * @mode_fixup:
  437. *
  438. * This callback is used to validate and adjust a mode. The parameter
  439. * mode is the display mode that should be fed to the next element in
  440. * the display chain, either the final &drm_connector or a &drm_bridge.
  441. * The parameter adjusted_mode is the input mode the encoder requires. It
  442. * can be modified by this callback and does not need to match mode.
  443. *
  444. * This function is used by both legacy CRTC helpers and atomic helpers.
  445. * This hook is optional.
  446. *
  447. * NOTE:
  448. *
  449. * This function is called in the check phase of atomic modesets, which
  450. * can be aborted for any reason (including on userspace's request to
  451. * just check whether a configuration would be possible). Atomic drivers
  452. * MUST NOT touch any persistent state (hardware or software) or data
  453. * structures except the passed in adjusted_mode parameter.
  454. *
  455. * This is in contrast to the legacy CRTC helpers where this was
  456. * allowed.
  457. *
  458. * Atomic drivers which need to inspect and adjust more state should
  459. * instead use the @atomic_check callback.
  460. *
  461. * Also beware that neither core nor helpers filter modes before
  462. * passing them to the driver: While the list of modes that is
  463. * advertised to userspace is filtered using the connector's
  464. * ->mode_valid() callback, neither the core nor the helpers do any
  465. * filtering on modes passed in from userspace when setting a mode. It
  466. * is therefore possible for userspace to pass in a mode that was
  467. * previously filtered out using ->mode_valid() or add a custom mode
  468. * that wasn't probed from EDID or similar to begin with. Even though
  469. * this is an advanced feature and rarely used nowadays, some users rely
  470. * on being able to specify modes manually so drivers must be prepared
  471. * to deal with it. Specifically this means that all drivers need not
  472. * only validate modes in ->mode_valid() but also in ->mode_fixup() to
  473. * make sure invalid modes passed in from userspace are rejected.
  474. *
  475. * RETURNS:
  476. *
  477. * True if an acceptable configuration is possible, false if the modeset
  478. * operation should be rejected.
  479. */
  480. bool (*mode_fixup)(struct drm_encoder *encoder,
  481. const struct drm_display_mode *mode,
  482. struct drm_display_mode *adjusted_mode);
  483. /**
  484. * @prepare:
  485. *
  486. * This callback should prepare the encoder for a subsequent modeset,
  487. * which in practice means the driver should disable the encoder if it
  488. * is running. Most drivers ended up implementing this by calling their
  489. * @dpms hook with DRM_MODE_DPMS_OFF.
  490. *
  491. * This callback is used by the legacy CRTC helpers. Atomic helpers
  492. * also support using this hook for disabling an encoder to facilitate
  493. * transitions to atomic, but it is deprecated. Instead @disable should
  494. * be used.
  495. */
  496. void (*prepare)(struct drm_encoder *encoder);
  497. /**
  498. * @commit:
  499. *
  500. * This callback should commit the new mode on the encoder after a modeset,
  501. * which in practice means the driver should enable the encoder. Most
  502. * drivers ended up implementing this by calling their @dpms hook with
  503. * DRM_MODE_DPMS_ON.
  504. *
  505. * This callback is used by the legacy CRTC helpers. Atomic helpers
  506. * also support using this hook for enabling an encoder to facilitate
  507. * transitions to atomic, but it is deprecated. Instead @enable should
  508. * be used.
  509. */
  510. void (*commit)(struct drm_encoder *encoder);
  511. /**
  512. * @mode_set:
  513. *
  514. * This callback is used to update the display mode of an encoder.
  515. *
  516. * Note that the display pipe is completely off when this function is
  517. * called. Drivers which need hardware to be running before they program
  518. * the new display mode (because they implement runtime PM) should not
  519. * use this hook, because the helper library calls it only once and not
  520. * every time the display pipeline is suspend using either DPMS or the
  521. * new "ACTIVE" property. Such drivers should instead move all their
  522. * encoder setup into the ->enable() callback.
  523. *
  524. * This callback is used both by the legacy CRTC helpers and the atomic
  525. * modeset helpers. It is optional in the atomic helpers.
  526. *
  527. * NOTE:
  528. *
  529. * If the driver uses the atomic modeset helpers and needs to inspect
  530. * the connector state or connector display info during mode setting,
  531. * @atomic_mode_set can be used instead.
  532. */
  533. void (*mode_set)(struct drm_encoder *encoder,
  534. struct drm_display_mode *mode,
  535. struct drm_display_mode *adjusted_mode);
  536. /**
  537. * @atomic_mode_set:
  538. *
  539. * This callback is used to update the display mode of an encoder.
  540. *
  541. * Note that the display pipe is completely off when this function is
  542. * called. Drivers which need hardware to be running before they program
  543. * the new display mode (because they implement runtime PM) should not
  544. * use this hook, because the helper library calls it only once and not
  545. * every time the display pipeline is suspended using either DPMS or the
  546. * new "ACTIVE" property. Such drivers should instead move all their
  547. * encoder setup into the ->enable() callback.
  548. *
  549. * This callback is used by the atomic modeset helpers in place of the
  550. * @mode_set callback, if set by the driver. It is optional and should
  551. * be used instead of @mode_set if the driver needs to inspect the
  552. * connector state or display info, since there is no direct way to
  553. * go from the encoder to the current connector.
  554. */
  555. void (*atomic_mode_set)(struct drm_encoder *encoder,
  556. struct drm_crtc_state *crtc_state,
  557. struct drm_connector_state *conn_state);
  558. /**
  559. * @get_crtc:
  560. *
  561. * This callback is used by the legacy CRTC helpers to work around
  562. * deficiencies in its own book-keeping.
  563. *
  564. * Do not use, use atomic helpers instead, which get the book keeping
  565. * right.
  566. *
  567. * FIXME:
  568. *
  569. * Currently only nouveau is using this, and as soon as nouveau is
  570. * atomic we can ditch this hook.
  571. */
  572. struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder);
  573. /**
  574. * @detect:
  575. *
  576. * This callback can be used by drivers who want to do detection on the
  577. * encoder object instead of in connector functions.
  578. *
  579. * It is not used by any helper and therefore has purely driver-specific
  580. * semantics. New drivers shouldn't use this and instead just implement
  581. * their own private callbacks.
  582. *
  583. * FIXME:
  584. *
  585. * This should just be converted into a pile of driver vfuncs.
  586. * Currently radeon, amdgpu and nouveau are using it.
  587. */
  588. enum drm_connector_status (*detect)(struct drm_encoder *encoder,
  589. struct drm_connector *connector);
  590. /**
  591. * @disable:
  592. *
  593. * This callback should be used to disable the encoder. With the atomic
  594. * drivers it is called before this encoder's CRTC has been shut off
  595. * using the CRTC's own ->disable hook. If that sequence is too simple
  596. * drivers can just add their own driver private encoder hooks and call
  597. * them from CRTC's callback by looping over all encoders connected to
  598. * it using for_each_encoder_on_crtc().
  599. *
  600. * This hook is used both by legacy CRTC helpers and atomic helpers.
  601. * Atomic drivers don't need to implement it if there's no need to
  602. * disable anything at the encoder level. To ensure that runtime PM
  603. * handling (using either DPMS or the new "ACTIVE" property) works
  604. * @disable must be the inverse of @enable for atomic drivers.
  605. *
  606. * NOTE:
  607. *
  608. * With legacy CRTC helpers there's a big semantic difference between
  609. * @disable and other hooks (like @prepare or @dpms) used to shut down a
  610. * encoder: @disable is only called when also logically disabling the
  611. * display pipeline and needs to release any resources acquired in
  612. * @mode_set (like shared PLLs, or again release pinned framebuffers).
  613. *
  614. * Therefore @disable must be the inverse of @mode_set plus @commit for
  615. * drivers still using legacy CRTC helpers, which is different from the
  616. * rules under atomic.
  617. */
  618. void (*disable)(struct drm_encoder *encoder);
  619. /**
  620. * @enable:
  621. *
  622. * This callback should be used to enable the encoder. With the atomic
  623. * drivers it is called after this encoder's CRTC has been enabled using
  624. * the CRTC's own ->enable hook. If that sequence is too simple drivers
  625. * can just add their own driver private encoder hooks and call them
  626. * from CRTC's callback by looping over all encoders connected to it
  627. * using for_each_encoder_on_crtc().
  628. *
  629. * This hook is used only by atomic helpers, for symmetry with @disable.
  630. * Atomic drivers don't need to implement it if there's no need to
  631. * enable anything at the encoder level. To ensure that runtime PM handling
  632. * (using either DPMS or the new "ACTIVE" property) works
  633. * @enable must be the inverse of @disable for atomic drivers.
  634. */
  635. void (*enable)(struct drm_encoder *encoder);
  636. /**
  637. * @atomic_check:
  638. *
  639. * This callback is used to validate encoder state for atomic drivers.
  640. * Since the encoder is the object connecting the CRTC and connector it
  641. * gets passed both states, to be able to validate interactions and
  642. * update the CRTC to match what the encoder needs for the requested
  643. * connector.
  644. *
  645. * This function is used by the atomic helpers, but it is optional.
  646. *
  647. * NOTE:
  648. *
  649. * This function is called in the check phase of an atomic update. The
  650. * driver is not allowed to change anything outside of the free-standing
  651. * state objects passed-in or assembled in the overall &drm_atomic_state
  652. * update tracking structure.
  653. *
  654. * RETURNS:
  655. *
  656. * 0 on success, -EINVAL if the state or the transition can't be
  657. * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
  658. * attempt to obtain another state object ran into a &drm_modeset_lock
  659. * deadlock.
  660. */
  661. int (*atomic_check)(struct drm_encoder *encoder,
  662. struct drm_crtc_state *crtc_state,
  663. struct drm_connector_state *conn_state);
  664. };
  665. /**
  666. * drm_encoder_helper_add - sets the helper vtable for an encoder
  667. * @encoder: DRM encoder
  668. * @funcs: helper vtable to set for @encoder
  669. */
  670. static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
  671. const struct drm_encoder_helper_funcs *funcs)
  672. {
  673. encoder->helper_private = funcs;
  674. }
  675. /**
  676. * struct drm_connector_helper_funcs - helper operations for connectors
  677. *
  678. * These functions are used by the atomic and legacy modeset helpers and by the
  679. * probe helpers.
  680. */
  681. struct drm_connector_helper_funcs {
  682. /**
  683. * @get_modes:
  684. *
  685. * This function should fill in all modes currently valid for the sink
  686. * into the connector->probed_modes list. It should also update the
  687. * EDID property by calling drm_mode_connector_update_edid_property().
  688. *
  689. * The usual way to implement this is to cache the EDID retrieved in the
  690. * probe callback somewhere in the driver-private connector structure.
  691. * In this function drivers then parse the modes in the EDID and add
  692. * them by calling drm_add_edid_modes(). But connectors that driver a
  693. * fixed panel can also manually add specific modes using
  694. * drm_mode_probed_add(). Drivers which manually add modes should also
  695. * make sure that the @display_info, @width_mm and @height_mm fields of the
  696. * struct &drm_connector are filled in.
  697. *
  698. * Virtual drivers that just want some standard VESA mode with a given
  699. * resolution can call drm_add_modes_noedid(), and mark the preferred
  700. * one using drm_set_preferred_mode().
  701. *
  702. * Finally drivers that support audio probably want to update the ELD
  703. * data, too, using drm_edid_to_eld().
  704. *
  705. * This function is only called after the ->detect() hook has indicated
  706. * that a sink is connected and when the EDID isn't overridden through
  707. * sysfs or the kernel commandline.
  708. *
  709. * This callback is used by the probe helpers in e.g.
  710. * drm_helper_probe_single_connector_modes().
  711. *
  712. * RETURNS:
  713. *
  714. * The number of modes added by calling drm_mode_probed_add().
  715. */
  716. int (*get_modes)(struct drm_connector *connector);
  717. /**
  718. * @mode_valid:
  719. *
  720. * Callback to validate a mode for a connector, irrespective of the
  721. * specific display configuration.
  722. *
  723. * This callback is used by the probe helpers to filter the mode list
  724. * (which is usually derived from the EDID data block from the sink).
  725. * See e.g. drm_helper_probe_single_connector_modes().
  726. *
  727. * NOTE:
  728. *
  729. * This only filters the mode list supplied to userspace in the
  730. * GETCONNECOTR IOCTL. Userspace is free to create modes of its own and
  731. * ask the kernel to use them. It this case the atomic helpers or legacy
  732. * CRTC helpers will not call this function. Drivers therefore must
  733. * still fully validate any mode passed in in a modeset request.
  734. *
  735. * RETURNS:
  736. *
  737. * Either MODE_OK or one of the failure reasons in enum
  738. * &drm_mode_status.
  739. */
  740. enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
  741. struct drm_display_mode *mode);
  742. /**
  743. * @best_encoder:
  744. *
  745. * This function should select the best encoder for the given connector.
  746. *
  747. * This function is used by both the atomic helpers (in the
  748. * drm_atomic_helper_check_modeset() function) and in the legacy CRTC
  749. * helpers.
  750. *
  751. * NOTE:
  752. *
  753. * In atomic drivers this function is called in the check phase of an
  754. * atomic update. The driver is not allowed to change or inspect
  755. * anything outside of arguments passed-in. Atomic drivers which need to
  756. * inspect dynamic configuration state should instead use
  757. * @atomic_best_encoder.
  758. *
  759. * You can leave this function to NULL if the connector is only
  760. * attached to a single encoder and you are using the atomic helpers.
  761. * In this case, the core will call drm_atomic_helper_best_encoder()
  762. * for you.
  763. *
  764. * RETURNS:
  765. *
  766. * Encoder that should be used for the given connector and connector
  767. * state, or NULL if no suitable encoder exists. Note that the helpers
  768. * will ensure that encoders aren't used twice, drivers should not check
  769. * for this.
  770. */
  771. struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
  772. /**
  773. * @atomic_best_encoder:
  774. *
  775. * This is the atomic version of @best_encoder for atomic drivers which
  776. * need to select the best encoder depending upon the desired
  777. * configuration and can't select it statically.
  778. *
  779. * This function is used by drm_atomic_helper_check_modeset().
  780. * If it is not implemented, the core will fallback to @best_encoder
  781. * (or drm_atomic_helper_best_encoder() if @best_encoder is NULL).
  782. *
  783. * NOTE:
  784. *
  785. * This function is called in the check phase of an atomic update. The
  786. * driver is not allowed to change anything outside of the free-standing
  787. * state objects passed-in or assembled in the overall &drm_atomic_state
  788. * update tracking structure.
  789. *
  790. * RETURNS:
  791. *
  792. * Encoder that should be used for the given connector and connector
  793. * state, or NULL if no suitable encoder exists. Note that the helpers
  794. * will ensure that encoders aren't used twice, drivers should not check
  795. * for this.
  796. */
  797. struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,
  798. struct drm_connector_state *connector_state);
  799. };
  800. /**
  801. * drm_connector_helper_add - sets the helper vtable for a connector
  802. * @connector: DRM connector
  803. * @funcs: helper vtable to set for @connector
  804. */
  805. static inline void drm_connector_helper_add(struct drm_connector *connector,
  806. const struct drm_connector_helper_funcs *funcs)
  807. {
  808. connector->helper_private = funcs;
  809. }
  810. /**
  811. * struct drm_plane_helper_funcs - helper operations for planes
  812. *
  813. * These functions are used by the atomic helpers and by the transitional plane
  814. * helpers.
  815. */
  816. struct drm_plane_helper_funcs {
  817. /**
  818. * @prepare_fb:
  819. *
  820. * This hook is to prepare a framebuffer for scanout by e.g. pinning
  821. * it's backing storage or relocating it into a contiguous block of
  822. * VRAM. Other possible preparatory work includes flushing caches.
  823. *
  824. * This function must not block for outstanding rendering, since it is
  825. * called in the context of the atomic IOCTL even for async commits to
  826. * be able to return any errors to userspace. Instead the recommended
  827. * way is to fill out the fence member of the passed-in
  828. * &drm_plane_state. If the driver doesn't support native fences then
  829. * equivalent functionality should be implemented through private
  830. * members in the plane structure.
  831. *
  832. * The helpers will call @cleanup_fb with matching arguments for every
  833. * successful call to this hook.
  834. *
  835. * This callback is used by the atomic modeset helpers and by the
  836. * transitional plane helpers, but it is optional.
  837. *
  838. * RETURNS:
  839. *
  840. * 0 on success or one of the following negative error codes allowed by
  841. * the atomic_commit hook in &drm_mode_config_funcs. When using helpers
  842. * this callback is the only one which can fail an atomic commit,
  843. * everything else must complete successfully.
  844. */
  845. int (*prepare_fb)(struct drm_plane *plane,
  846. struct drm_plane_state *new_state);
  847. /**
  848. * @cleanup_fb:
  849. *
  850. * This hook is called to clean up any resources allocated for the given
  851. * framebuffer and plane configuration in @prepare_fb.
  852. *
  853. * This callback is used by the atomic modeset helpers and by the
  854. * transitional plane helpers, but it is optional.
  855. */
  856. void (*cleanup_fb)(struct drm_plane *plane,
  857. struct drm_plane_state *old_state);
  858. /**
  859. * @atomic_check:
  860. *
  861. * Drivers should check plane specific constraints in this hook.
  862. *
  863. * When using drm_atomic_helper_check_planes() plane's ->atomic_check()
  864. * hooks are called before the ones for CRTCs, which allows drivers to
  865. * request shared resources that the CRTC controls here. For more
  866. * complicated dependencies the driver can call the provided check helpers
  867. * multiple times until the computed state has a final configuration and
  868. * everything has been checked.
  869. *
  870. * This function is also allowed to inspect any other object's state and
  871. * can add more state objects to the atomic commit if needed. Care must
  872. * be taken though to ensure that state check&compute functions for
  873. * these added states are all called, and derived state in other objects
  874. * all updated. Again the recommendation is to just call check helpers
  875. * until a maximal configuration is reached.
  876. *
  877. * This callback is used by the atomic modeset helpers and by the
  878. * transitional plane helpers, but it is optional.
  879. *
  880. * NOTE:
  881. *
  882. * This function is called in the check phase of an atomic update. The
  883. * driver is not allowed to change anything outside of the free-standing
  884. * state objects passed-in or assembled in the overall &drm_atomic_state
  885. * update tracking structure.
  886. *
  887. * RETURNS:
  888. *
  889. * 0 on success, -EINVAL if the state or the transition can't be
  890. * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
  891. * attempt to obtain another state object ran into a &drm_modeset_lock
  892. * deadlock.
  893. */
  894. int (*atomic_check)(struct drm_plane *plane,
  895. struct drm_plane_state *state);
  896. /**
  897. * @atomic_update:
  898. *
  899. * Drivers should use this function to update the plane state. This
  900. * hook is called in-between the ->atomic_begin() and
  901. * ->atomic_flush() of &drm_crtc_helper_funcs.
  902. *
  903. * Note that the power state of the display pipe when this function is
  904. * called depends upon the exact helpers and calling sequence the driver
  905. * has picked. See drm_atomic_commit_planes() for a discussion of the
  906. * tradeoffs and variants of plane commit helpers.
  907. *
  908. * This callback is used by the atomic modeset helpers and by the
  909. * transitional plane helpers, but it is optional.
  910. */
  911. void (*atomic_update)(struct drm_plane *plane,
  912. struct drm_plane_state *old_state);
  913. /**
  914. * @atomic_disable:
  915. *
  916. * Drivers should use this function to unconditionally disable a plane.
  917. * This hook is called in-between the ->atomic_begin() and
  918. * ->atomic_flush() of &drm_crtc_helper_funcs. It is an alternative to
  919. * @atomic_update, which will be called for disabling planes, too, if
  920. * the @atomic_disable hook isn't implemented.
  921. *
  922. * This hook is also useful to disable planes in preparation of a modeset,
  923. * by calling drm_atomic_helper_disable_planes_on_crtc() from the
  924. * ->disable() hook in &drm_crtc_helper_funcs.
  925. *
  926. * Note that the power state of the display pipe when this function is
  927. * called depends upon the exact helpers and calling sequence the driver
  928. * has picked. See drm_atomic_commit_planes() for a discussion of the
  929. * tradeoffs and variants of plane commit helpers.
  930. *
  931. * This callback is used by the atomic modeset helpers and by the
  932. * transitional plane helpers, but it is optional.
  933. */
  934. void (*atomic_disable)(struct drm_plane *plane,
  935. struct drm_plane_state *old_state);
  936. };
  937. /**
  938. * drm_plane_helper_add - sets the helper vtable for a plane
  939. * @plane: DRM plane
  940. * @funcs: helper vtable to set for @plane
  941. */
  942. static inline void drm_plane_helper_add(struct drm_plane *plane,
  943. const struct drm_plane_helper_funcs *funcs)
  944. {
  945. plane->helper_private = funcs;
  946. }
  947. /**
  948. * struct drm_mode_config_helper_funcs - global modeset helper operations
  949. *
  950. * These helper functions are used by the atomic helpers.
  951. */
  952. struct drm_mode_config_helper_funcs {
  953. /**
  954. * @atomic_commit_tail:
  955. *
  956. * This hook is used by the default atomic_commit() hook implemented in
  957. * drm_atomic_helper_commit() together with the nonblocking commit
  958. * helpers (see drm_atomic_helper_setup_commit() for a starting point)
  959. * to implement blocking and nonblocking commits easily. It is not used
  960. * by the atomic helpers
  961. *
  962. * This hook should first commit the given atomic state to the hardware.
  963. * But drivers can add more waiting calls at the start of their
  964. * implementation, e.g. to wait for driver-internal request for implicit
  965. * syncing, before starting to commit the update to the hardware.
  966. *
  967. * After the atomic update is committed to the hardware this hook needs
  968. * to call drm_atomic_helper_commit_hw_done(). Then wait for the upate
  969. * to be executed by the hardware, for example using
  970. * drm_atomic_helper_wait_for_vblanks(), and then clean up the old
  971. * framebuffers using drm_atomic_helper_cleanup_planes().
  972. *
  973. * When disabling a CRTC this hook _must_ stall for the commit to
  974. * complete. Vblank waits don't work on disabled CRTC, hence the core
  975. * can't take care of this. And it also can't rely on the vblank event,
  976. * since that can be signalled already when the screen shows black,
  977. * which can happen much earlier than the last hardware access needed to
  978. * shut off the display pipeline completely.
  979. *
  980. * This hook is optional, the default implementation is
  981. * drm_atomic_helper_commit_tail().
  982. */
  983. void (*atomic_commit_tail)(struct drm_atomic_state *state);
  984. };
  985. #endif