drm_modeset_helper_vtables.h 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  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. #include <drm/drm_encoder.h>
  32. /**
  33. * DOC: overview
  34. *
  35. * The DRM mode setting helper functions are common code for drivers to use if
  36. * they wish. Drivers are not forced to use this code in their
  37. * implementations but it would be useful if the code they do use at least
  38. * provides a consistent interface and operation to userspace. Therefore it is
  39. * highly recommended to use the provided helpers as much as possible.
  40. *
  41. * Because there is only one pointer per modeset object to hold a vfunc table
  42. * for helper libraries they are by necessity shared among the different
  43. * helpers.
  44. *
  45. * To make this clear all the helper vtables are pulled together in this location here.
  46. */
  47. enum mode_set_atomic;
  48. /**
  49. * struct drm_crtc_helper_funcs - helper operations for CRTCs
  50. *
  51. * These hooks are used by the legacy CRTC helpers, the transitional plane
  52. * helpers and the new atomic modesetting helpers.
  53. */
  54. struct drm_crtc_helper_funcs {
  55. /**
  56. * @dpms:
  57. *
  58. * Callback to control power levels on the CRTC. If the mode passed in
  59. * is unsupported, the provider must use the next lowest power level.
  60. * This is used by the legacy CRTC helpers to implement DPMS
  61. * functionality in drm_helper_connector_dpms().
  62. *
  63. * This callback is also used to disable a CRTC by calling it with
  64. * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
  65. *
  66. * This callback is used by the legacy CRTC helpers. Atomic helpers
  67. * also support using this hook for enabling and disabling a CRTC to
  68. * facilitate transitions to atomic, but it is deprecated. Instead
  69. * @atomic_enable and @atomic_disable should be used.
  70. */
  71. void (*dpms)(struct drm_crtc *crtc, int mode);
  72. /**
  73. * @prepare:
  74. *
  75. * This callback should prepare the CRTC for a subsequent modeset, which
  76. * in practice means the driver should disable the CRTC if it is
  77. * running. Most drivers ended up implementing this by calling their
  78. * @dpms hook with DRM_MODE_DPMS_OFF.
  79. *
  80. * This callback is used by the legacy CRTC helpers. Atomic helpers
  81. * also support using this hook for disabling a CRTC to facilitate
  82. * transitions to atomic, but it is deprecated. Instead @atomic_disable
  83. * should be used.
  84. */
  85. void (*prepare)(struct drm_crtc *crtc);
  86. /**
  87. * @commit:
  88. *
  89. * This callback should commit the new mode on the CRTC after a modeset,
  90. * which in practice means the driver should enable the CRTC. Most
  91. * drivers ended up implementing this by calling their @dpms hook with
  92. * DRM_MODE_DPMS_ON.
  93. *
  94. * This callback is used by the legacy CRTC helpers. Atomic helpers
  95. * also support using this hook for enabling a CRTC to facilitate
  96. * transitions to atomic, but it is deprecated. Instead @atomic_enable
  97. * should be used.
  98. */
  99. void (*commit)(struct drm_crtc *crtc);
  100. /**
  101. * @mode_valid:
  102. *
  103. * This callback is used to check if a specific mode is valid in this
  104. * crtc. This should be implemented if the crtc has some sort of
  105. * restriction in the modes it can display. For example, a given crtc
  106. * may be responsible to set a clock value. If the clock can not
  107. * produce all the values for the available modes then this callback
  108. * can be used to restrict the number of modes to only the ones that
  109. * can be displayed.
  110. *
  111. * This hook is used by the probe helpers to filter the mode list in
  112. * drm_helper_probe_single_connector_modes(), and it is used by the
  113. * atomic helpers to validate modes supplied by userspace in
  114. * drm_atomic_helper_check_modeset().
  115. *
  116. * This function is optional.
  117. *
  118. * NOTE:
  119. *
  120. * Since this function is both called from the check phase of an atomic
  121. * commit, and the mode validation in the probe paths it is not allowed
  122. * to look at anything else but the passed-in mode, and validate it
  123. * against configuration-invariant hardward constraints. Any further
  124. * limits which depend upon the configuration can only be checked in
  125. * @mode_fixup or @atomic_check.
  126. *
  127. * RETURNS:
  128. *
  129. * drm_mode_status Enum
  130. */
  131. enum drm_mode_status (*mode_valid)(struct drm_crtc *crtc,
  132. const struct drm_display_mode *mode);
  133. /**
  134. * @mode_fixup:
  135. *
  136. * This callback is used to validate a mode. The parameter mode is the
  137. * display mode that userspace requested, adjusted_mode is the mode the
  138. * encoders need to be fed with. Note that this is the inverse semantics
  139. * of the meaning for the &drm_encoder and &drm_bridge_funcs.mode_fixup
  140. * vfunc. If the CRTC cannot support the requested conversion from mode
  141. * to adjusted_mode it should reject the modeset. See also
  142. * &drm_crtc_state.adjusted_mode for more details.
  143. *
  144. * This function is used by both legacy CRTC helpers and atomic helpers.
  145. * With atomic helpers it is optional.
  146. *
  147. * NOTE:
  148. *
  149. * This function is called in the check phase of atomic modesets, which
  150. * can be aborted for any reason (including on userspace's request to
  151. * just check whether a configuration would be possible). Atomic drivers
  152. * MUST NOT touch any persistent state (hardware or software) or data
  153. * structures except the passed in adjusted_mode parameter.
  154. *
  155. * This is in contrast to the legacy CRTC helpers where this was
  156. * allowed.
  157. *
  158. * Atomic drivers which need to inspect and adjust more state should
  159. * instead use the @atomic_check callback, but note that they're not
  160. * perfectly equivalent: @mode_valid is called from
  161. * drm_atomic_helper_check_modeset(), but @atomic_check is called from
  162. * drm_atomic_helper_check_planes(), because originally it was meant for
  163. * plane update checks only.
  164. *
  165. * Also beware that userspace can request its own custom modes, neither
  166. * core nor helpers filter modes to the list of probe modes reported by
  167. * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
  168. * that modes are filtered consistently put any CRTC constraints and
  169. * limits checks into @mode_valid.
  170. *
  171. * RETURNS:
  172. *
  173. * True if an acceptable configuration is possible, false if the modeset
  174. * operation should be rejected.
  175. */
  176. bool (*mode_fixup)(struct drm_crtc *crtc,
  177. const struct drm_display_mode *mode,
  178. struct drm_display_mode *adjusted_mode);
  179. /**
  180. * @mode_set:
  181. *
  182. * This callback is used by the legacy CRTC helpers to set a new mode,
  183. * position and framebuffer. Since it ties the primary plane to every
  184. * mode change it is incompatible with universal plane support. And
  185. * since it can't update other planes it's incompatible with atomic
  186. * modeset support.
  187. *
  188. * This callback is only used by CRTC helpers and deprecated.
  189. *
  190. * RETURNS:
  191. *
  192. * 0 on success or a negative error code on failure.
  193. */
  194. int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
  195. struct drm_display_mode *adjusted_mode, int x, int y,
  196. struct drm_framebuffer *old_fb);
  197. /**
  198. * @mode_set_nofb:
  199. *
  200. * This callback is used to update the display mode of a CRTC without
  201. * changing anything of the primary plane configuration. This fits the
  202. * requirement of atomic and hence is used by the atomic helpers. It is
  203. * also used by the transitional plane helpers to implement a
  204. * @mode_set hook in drm_helper_crtc_mode_set().
  205. *
  206. * Note that the display pipe is completely off when this function is
  207. * called. Atomic drivers which need hardware to be running before they
  208. * program the new display mode (e.g. because they implement runtime PM)
  209. * should not use this hook. This is because the helper library calls
  210. * this hook only once per mode change and not every time the display
  211. * pipeline is suspended using either DPMS or the new "ACTIVE" property.
  212. * Which means register values set in this callback might get reset when
  213. * the CRTC is suspended, but not restored. Such drivers should instead
  214. * move all their CRTC setup into the @atomic_enable callback.
  215. *
  216. * This callback is optional.
  217. */
  218. void (*mode_set_nofb)(struct drm_crtc *crtc);
  219. /**
  220. * @mode_set_base:
  221. *
  222. * This callback is used by the legacy CRTC helpers to set a new
  223. * framebuffer and scanout position. It is optional and used as an
  224. * optimized fast-path instead of a full mode set operation with all the
  225. * resulting flickering. If it is not present
  226. * drm_crtc_helper_set_config() will fall back to a full modeset, using
  227. * the @mode_set callback. Since it can't update other planes it's
  228. * incompatible with atomic modeset support.
  229. *
  230. * This callback is only used by the CRTC helpers and deprecated.
  231. *
  232. * RETURNS:
  233. *
  234. * 0 on success or a negative error code on failure.
  235. */
  236. int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
  237. struct drm_framebuffer *old_fb);
  238. /**
  239. * @mode_set_base_atomic:
  240. *
  241. * This callback is used by the fbdev helpers to set a new framebuffer
  242. * and scanout without sleeping, i.e. from an atomic calling context. It
  243. * is only used to implement kgdb support.
  244. *
  245. * This callback is optional and only needed for kgdb support in the fbdev
  246. * helpers.
  247. *
  248. * RETURNS:
  249. *
  250. * 0 on success or a negative error code on failure.
  251. */
  252. int (*mode_set_base_atomic)(struct drm_crtc *crtc,
  253. struct drm_framebuffer *fb, int x, int y,
  254. enum mode_set_atomic);
  255. /**
  256. * @disable:
  257. *
  258. * This callback should be used to disable the CRTC. With the atomic
  259. * drivers it is called after all encoders connected to this CRTC have
  260. * been shut off already using their own
  261. * &drm_encoder_helper_funcs.disable hook. If that sequence is too
  262. * simple drivers can just add their own hooks and call it from this
  263. * CRTC callback here by looping over all encoders connected to it using
  264. * for_each_encoder_on_crtc().
  265. *
  266. * This hook is used both by legacy CRTC helpers and atomic helpers.
  267. * Atomic drivers don't need to implement it if there's no need to
  268. * disable anything at the CRTC level. To ensure that runtime PM
  269. * handling (using either DPMS or the new "ACTIVE" property) works
  270. * @disable must be the inverse of @atomic_enable for atomic drivers.
  271. * Atomic drivers should consider to use @atomic_disable instead of
  272. * this one.
  273. *
  274. * NOTE:
  275. *
  276. * With legacy CRTC helpers there's a big semantic difference between
  277. * @disable and other hooks (like @prepare or @dpms) used to shut down a
  278. * CRTC: @disable is only called when also logically disabling the
  279. * display pipeline and needs to release any resources acquired in
  280. * @mode_set (like shared PLLs, or again release pinned framebuffers).
  281. *
  282. * Therefore @disable must be the inverse of @mode_set plus @commit for
  283. * drivers still using legacy CRTC helpers, which is different from the
  284. * rules under atomic.
  285. */
  286. void (*disable)(struct drm_crtc *crtc);
  287. /**
  288. * @atomic_check:
  289. *
  290. * Drivers should check plane-update related CRTC constraints in this
  291. * hook. They can also check mode related limitations but need to be
  292. * aware of the calling order, since this hook is used by
  293. * drm_atomic_helper_check_planes() whereas the preparations needed to
  294. * check output routing and the display mode is done in
  295. * drm_atomic_helper_check_modeset(). Therefore drivers that want to
  296. * check output routing and display mode constraints in this callback
  297. * must ensure that drm_atomic_helper_check_modeset() has been called
  298. * beforehand. This is calling order used by the default helper
  299. * implementation in drm_atomic_helper_check().
  300. *
  301. * When using drm_atomic_helper_check_planes() this hook is called
  302. * after the &drm_plane_helper_funcs.atomc_check hook for planes, which
  303. * allows drivers to assign shared resources requested by planes in this
  304. * callback here. For more complicated dependencies the driver can call
  305. * the provided check helpers multiple times until the computed state
  306. * has a final configuration and everything has been checked.
  307. *
  308. * This function is also allowed to inspect any other object's state and
  309. * can add more state objects to the atomic commit if needed. Care must
  310. * be taken though to ensure that state check and compute functions for
  311. * these added states are all called, and derived state in other objects
  312. * all updated. Again the recommendation is to just call check helpers
  313. * until a maximal configuration is reached.
  314. *
  315. * This callback is used by the atomic modeset helpers and by the
  316. * transitional plane helpers, but it is optional.
  317. *
  318. * NOTE:
  319. *
  320. * This function is called in the check phase of an atomic update. The
  321. * driver is not allowed to change anything outside of the free-standing
  322. * state objects passed-in or assembled in the overall &drm_atomic_state
  323. * update tracking structure.
  324. *
  325. * Also beware that userspace can request its own custom modes, neither
  326. * core nor helpers filter modes to the list of probe modes reported by
  327. * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
  328. * that modes are filtered consistently put any CRTC constraints and
  329. * limits checks into @mode_valid.
  330. *
  331. * RETURNS:
  332. *
  333. * 0 on success, -EINVAL if the state or the transition can't be
  334. * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
  335. * attempt to obtain another state object ran into a &drm_modeset_lock
  336. * deadlock.
  337. */
  338. int (*atomic_check)(struct drm_crtc *crtc,
  339. struct drm_crtc_state *state);
  340. /**
  341. * @atomic_begin:
  342. *
  343. * Drivers should prepare for an atomic update of multiple planes on
  344. * a CRTC in this hook. Depending upon hardware this might be vblank
  345. * evasion, blocking updates by setting bits or doing preparatory work
  346. * for e.g. manual update display.
  347. *
  348. * This hook is called before any plane commit functions are called.
  349. *
  350. * Note that the power state of the display pipe when this function is
  351. * called depends upon the exact helpers and calling sequence the driver
  352. * has picked. See drm_atomic_helper_commit_planes() for a discussion of
  353. * the tradeoffs and variants of plane commit helpers.
  354. *
  355. * This callback is used by the atomic modeset helpers and by the
  356. * transitional plane helpers, but it is optional.
  357. */
  358. void (*atomic_begin)(struct drm_crtc *crtc,
  359. struct drm_crtc_state *old_crtc_state);
  360. /**
  361. * @atomic_flush:
  362. *
  363. * Drivers should finalize an atomic update of multiple planes on
  364. * a CRTC in this hook. Depending upon hardware this might include
  365. * checking that vblank evasion was successful, unblocking updates by
  366. * setting bits or setting the GO bit to flush out all updates.
  367. *
  368. * Simple hardware or hardware with special requirements can commit and
  369. * flush out all updates for all planes from this hook and forgo all the
  370. * other commit hooks for plane updates.
  371. *
  372. * This hook is called after any plane commit functions are called.
  373. *
  374. * Note that the power state of the display pipe when this function is
  375. * called depends upon the exact helpers and calling sequence the driver
  376. * has picked. See drm_atomic_helper_commit_planes() for a discussion of
  377. * the tradeoffs and variants of plane commit helpers.
  378. *
  379. * This callback is used by the atomic modeset helpers and by the
  380. * transitional plane helpers, but it is optional.
  381. */
  382. void (*atomic_flush)(struct drm_crtc *crtc,
  383. struct drm_crtc_state *old_crtc_state);
  384. /**
  385. * @atomic_enable:
  386. *
  387. * This callback should be used to enable the CRTC. With the atomic
  388. * drivers it is called before all encoders connected to this CRTC are
  389. * enabled through the encoder's own &drm_encoder_helper_funcs.enable
  390. * hook. If that sequence is too simple drivers can just add their own
  391. * hooks and call it from this CRTC callback here by looping over all
  392. * encoders connected to it using for_each_encoder_on_crtc().
  393. *
  394. * This hook is used only by atomic helpers, for symmetry with
  395. * @atomic_disable. Atomic drivers don't need to implement it if there's
  396. * no need to enable anything at the CRTC level. To ensure that runtime
  397. * PM handling (using either DPMS or the new "ACTIVE" property) works
  398. * @atomic_enable must be the inverse of @atomic_disable for atomic
  399. * drivers.
  400. *
  401. * Drivers can use the @old_crtc_state input parameter if the operations
  402. * needed to enable the CRTC don't depend solely on the new state but
  403. * also on the transition between the old state and the new state.
  404. */
  405. void (*atomic_enable)(struct drm_crtc *crtc,
  406. struct drm_crtc_state *old_crtc_state);
  407. /**
  408. * @atomic_disable:
  409. *
  410. * This callback should be used to disable the CRTC. With the atomic
  411. * drivers it is called after all encoders connected to this CRTC have
  412. * been shut off already using their own
  413. * &drm_encoder_helper_funcs.disable hook. If that sequence is too
  414. * simple drivers can just add their own hooks and call it from this
  415. * CRTC callback here by looping over all encoders connected to it using
  416. * for_each_encoder_on_crtc().
  417. *
  418. * This hook is used only by atomic helpers. Atomic drivers don't
  419. * need to implement it if there's no need to disable anything at the
  420. * CRTC level.
  421. *
  422. * Comparing to @disable, this one provides the additional input
  423. * parameter @old_crtc_state which could be used to access the old
  424. * state. Atomic drivers should consider to use this one instead
  425. * of @disable.
  426. */
  427. void (*atomic_disable)(struct drm_crtc *crtc,
  428. struct drm_crtc_state *old_crtc_state);
  429. };
  430. /**
  431. * drm_crtc_helper_add - sets the helper vtable for a crtc
  432. * @crtc: DRM CRTC
  433. * @funcs: helper vtable to set for @crtc
  434. */
  435. static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
  436. const struct drm_crtc_helper_funcs *funcs)
  437. {
  438. crtc->helper_private = funcs;
  439. }
  440. /**
  441. * struct drm_encoder_helper_funcs - helper operations for encoders
  442. *
  443. * These hooks are used by the legacy CRTC helpers, the transitional plane
  444. * helpers and the new atomic modesetting helpers.
  445. */
  446. struct drm_encoder_helper_funcs {
  447. /**
  448. * @dpms:
  449. *
  450. * Callback to control power levels on the encoder. If the mode passed in
  451. * is unsupported, the provider must use the next lowest power level.
  452. * This is used by the legacy encoder helpers to implement DPMS
  453. * functionality in drm_helper_connector_dpms().
  454. *
  455. * This callback is also used to disable an encoder by calling it with
  456. * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
  457. *
  458. * This callback is used by the legacy CRTC helpers. Atomic helpers
  459. * also support using this hook for enabling and disabling an encoder to
  460. * facilitate transitions to atomic, but it is deprecated. Instead
  461. * @enable and @disable should be used.
  462. */
  463. void (*dpms)(struct drm_encoder *encoder, int mode);
  464. /**
  465. * @mode_valid:
  466. *
  467. * This callback is used to check if a specific mode is valid in this
  468. * encoder. This should be implemented if the encoder has some sort
  469. * of restriction in the modes it can display. For example, a given
  470. * encoder may be responsible to set a clock value. If the clock can
  471. * not produce all the values for the available modes then this callback
  472. * can be used to restrict the number of modes to only the ones that
  473. * can be displayed.
  474. *
  475. * This hook is used by the probe helpers to filter the mode list in
  476. * drm_helper_probe_single_connector_modes(), and it is used by the
  477. * atomic helpers to validate modes supplied by userspace in
  478. * drm_atomic_helper_check_modeset().
  479. *
  480. * This function is optional.
  481. *
  482. * NOTE:
  483. *
  484. * Since this function is both called from the check phase of an atomic
  485. * commit, and the mode validation in the probe paths it is not allowed
  486. * to look at anything else but the passed-in mode, and validate it
  487. * against configuration-invariant hardward constraints. Any further
  488. * limits which depend upon the configuration can only be checked in
  489. * @mode_fixup or @atomic_check.
  490. *
  491. * RETURNS:
  492. *
  493. * drm_mode_status Enum
  494. */
  495. enum drm_mode_status (*mode_valid)(struct drm_encoder *crtc,
  496. const struct drm_display_mode *mode);
  497. /**
  498. * @mode_fixup:
  499. *
  500. * This callback is used to validate and adjust a mode. The parameter
  501. * mode is the display mode that should be fed to the next element in
  502. * the display chain, either the final &drm_connector or a &drm_bridge.
  503. * The parameter adjusted_mode is the input mode the encoder requires. It
  504. * can be modified by this callback and does not need to match mode. See
  505. * also &drm_crtc_state.adjusted_mode for more details.
  506. *
  507. * This function is used by both legacy CRTC helpers and atomic helpers.
  508. * This hook is optional.
  509. *
  510. * NOTE:
  511. *
  512. * This function is called in the check phase of atomic modesets, which
  513. * can be aborted for any reason (including on userspace's request to
  514. * just check whether a configuration would be possible). Atomic drivers
  515. * MUST NOT touch any persistent state (hardware or software) or data
  516. * structures except the passed in adjusted_mode parameter.
  517. *
  518. * This is in contrast to the legacy CRTC helpers where this was
  519. * allowed.
  520. *
  521. * Atomic drivers which need to inspect and adjust more state should
  522. * instead use the @atomic_check callback. If @atomic_check is used,
  523. * this hook isn't called since @atomic_check allows a strict superset
  524. * of the functionality of @mode_fixup.
  525. *
  526. * Also beware that userspace can request its own custom modes, neither
  527. * core nor helpers filter modes to the list of probe modes reported by
  528. * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
  529. * that modes are filtered consistently put any encoder constraints and
  530. * limits checks into @mode_valid.
  531. *
  532. * RETURNS:
  533. *
  534. * True if an acceptable configuration is possible, false if the modeset
  535. * operation should be rejected.
  536. */
  537. bool (*mode_fixup)(struct drm_encoder *encoder,
  538. const struct drm_display_mode *mode,
  539. struct drm_display_mode *adjusted_mode);
  540. /**
  541. * @prepare:
  542. *
  543. * This callback should prepare the encoder for a subsequent modeset,
  544. * which in practice means the driver should disable the encoder if it
  545. * is running. Most drivers ended up implementing this by calling their
  546. * @dpms hook with DRM_MODE_DPMS_OFF.
  547. *
  548. * This callback is used by the legacy CRTC helpers. Atomic helpers
  549. * also support using this hook for disabling an encoder to facilitate
  550. * transitions to atomic, but it is deprecated. Instead @disable should
  551. * be used.
  552. */
  553. void (*prepare)(struct drm_encoder *encoder);
  554. /**
  555. * @commit:
  556. *
  557. * This callback should commit the new mode on the encoder after a modeset,
  558. * which in practice means the driver should enable the encoder. Most
  559. * drivers ended up implementing this by calling their @dpms hook with
  560. * DRM_MODE_DPMS_ON.
  561. *
  562. * This callback is used by the legacy CRTC helpers. Atomic helpers
  563. * also support using this hook for enabling an encoder to facilitate
  564. * transitions to atomic, but it is deprecated. Instead @enable should
  565. * be used.
  566. */
  567. void (*commit)(struct drm_encoder *encoder);
  568. /**
  569. * @mode_set:
  570. *
  571. * This callback is used to update the display mode of an encoder.
  572. *
  573. * Note that the display pipe is completely off when this function is
  574. * called. Drivers which need hardware to be running before they program
  575. * the new display mode (because they implement runtime PM) should not
  576. * use this hook, because the helper library calls it only once and not
  577. * every time the display pipeline is suspend using either DPMS or the
  578. * new "ACTIVE" property. Such drivers should instead move all their
  579. * encoder setup into the @enable callback.
  580. *
  581. * This callback is used both by the legacy CRTC helpers and the atomic
  582. * modeset helpers. It is optional in the atomic helpers.
  583. *
  584. * NOTE:
  585. *
  586. * If the driver uses the atomic modeset helpers and needs to inspect
  587. * the connector state or connector display info during mode setting,
  588. * @atomic_mode_set can be used instead.
  589. */
  590. void (*mode_set)(struct drm_encoder *encoder,
  591. struct drm_display_mode *mode,
  592. struct drm_display_mode *adjusted_mode);
  593. /**
  594. * @atomic_mode_set:
  595. *
  596. * This callback is used to update the display mode of an encoder.
  597. *
  598. * Note that the display pipe is completely off when this function is
  599. * called. Drivers which need hardware to be running before they program
  600. * the new display mode (because they implement runtime PM) should not
  601. * use this hook, because the helper library calls it only once and not
  602. * every time the display pipeline is suspended using either DPMS or the
  603. * new "ACTIVE" property. Such drivers should instead move all their
  604. * encoder setup into the @enable callback.
  605. *
  606. * This callback is used by the atomic modeset helpers in place of the
  607. * @mode_set callback, if set by the driver. It is optional and should
  608. * be used instead of @mode_set if the driver needs to inspect the
  609. * connector state or display info, since there is no direct way to
  610. * go from the encoder to the current connector.
  611. */
  612. void (*atomic_mode_set)(struct drm_encoder *encoder,
  613. struct drm_crtc_state *crtc_state,
  614. struct drm_connector_state *conn_state);
  615. /**
  616. * @get_crtc:
  617. *
  618. * This callback is used by the legacy CRTC helpers to work around
  619. * deficiencies in its own book-keeping.
  620. *
  621. * Do not use, use atomic helpers instead, which get the book keeping
  622. * right.
  623. *
  624. * FIXME:
  625. *
  626. * Currently only nouveau is using this, and as soon as nouveau is
  627. * atomic we can ditch this hook.
  628. */
  629. struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder);
  630. /**
  631. * @detect:
  632. *
  633. * This callback can be used by drivers who want to do detection on the
  634. * encoder object instead of in connector functions.
  635. *
  636. * It is not used by any helper and therefore has purely driver-specific
  637. * semantics. New drivers shouldn't use this and instead just implement
  638. * their own private callbacks.
  639. *
  640. * FIXME:
  641. *
  642. * This should just be converted into a pile of driver vfuncs.
  643. * Currently radeon, amdgpu and nouveau are using it.
  644. */
  645. enum drm_connector_status (*detect)(struct drm_encoder *encoder,
  646. struct drm_connector *connector);
  647. /**
  648. * @disable:
  649. *
  650. * This callback should be used to disable the encoder. With the atomic
  651. * drivers it is called before this encoder's CRTC has been shut off
  652. * using their own &drm_crtc_helper_funcs.disable hook. If that
  653. * sequence is too simple drivers can just add their own driver private
  654. * encoder hooks and call them from CRTC's callback by looping over all
  655. * encoders connected to it using for_each_encoder_on_crtc().
  656. *
  657. * This hook is used both by legacy CRTC helpers and atomic helpers.
  658. * Atomic drivers don't need to implement it if there's no need to
  659. * disable anything at the encoder level. To ensure that runtime PM
  660. * handling (using either DPMS or the new "ACTIVE" property) works
  661. * @disable must be the inverse of @enable for atomic drivers.
  662. *
  663. * NOTE:
  664. *
  665. * With legacy CRTC helpers there's a big semantic difference between
  666. * @disable and other hooks (like @prepare or @dpms) used to shut down a
  667. * encoder: @disable is only called when also logically disabling the
  668. * display pipeline and needs to release any resources acquired in
  669. * @mode_set (like shared PLLs, or again release pinned framebuffers).
  670. *
  671. * Therefore @disable must be the inverse of @mode_set plus @commit for
  672. * drivers still using legacy CRTC helpers, which is different from the
  673. * rules under atomic.
  674. */
  675. void (*disable)(struct drm_encoder *encoder);
  676. /**
  677. * @enable:
  678. *
  679. * This callback should be used to enable the encoder. With the atomic
  680. * drivers it is called after this encoder's CRTC has been enabled using
  681. * their own &drm_crtc_helper_funcs.enable hook. If that sequence is
  682. * too simple drivers can just add their own driver private encoder
  683. * hooks and call them from CRTC's callback by looping over all encoders
  684. * connected to it using for_each_encoder_on_crtc().
  685. *
  686. * This hook is used only by atomic helpers, for symmetry with @disable.
  687. * Atomic drivers don't need to implement it if there's no need to
  688. * enable anything at the encoder level. To ensure that runtime PM handling
  689. * (using either DPMS or the new "ACTIVE" property) works
  690. * @enable must be the inverse of @disable for atomic drivers.
  691. */
  692. void (*enable)(struct drm_encoder *encoder);
  693. /**
  694. * @atomic_check:
  695. *
  696. * This callback is used to validate encoder state for atomic drivers.
  697. * Since the encoder is the object connecting the CRTC and connector it
  698. * gets passed both states, to be able to validate interactions and
  699. * update the CRTC to match what the encoder needs for the requested
  700. * connector.
  701. *
  702. * Since this provides a strict superset of the functionality of
  703. * @mode_fixup (the requested and adjusted modes are both available
  704. * through the passed in &struct drm_crtc_state) @mode_fixup is not
  705. * called when @atomic_check is implemented.
  706. *
  707. * This function is used by the atomic helpers, but it is optional.
  708. *
  709. * NOTE:
  710. *
  711. * This function is called in the check phase of an atomic update. The
  712. * driver is not allowed to change anything outside of the free-standing
  713. * state objects passed-in or assembled in the overall &drm_atomic_state
  714. * update tracking structure.
  715. *
  716. * Also beware that userspace can request its own custom modes, neither
  717. * core nor helpers filter modes to the list of probe modes reported by
  718. * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
  719. * that modes are filtered consistently put any encoder constraints and
  720. * limits checks into @mode_valid.
  721. *
  722. * RETURNS:
  723. *
  724. * 0 on success, -EINVAL if the state or the transition can't be
  725. * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
  726. * attempt to obtain another state object ran into a &drm_modeset_lock
  727. * deadlock.
  728. */
  729. int (*atomic_check)(struct drm_encoder *encoder,
  730. struct drm_crtc_state *crtc_state,
  731. struct drm_connector_state *conn_state);
  732. };
  733. /**
  734. * drm_encoder_helper_add - sets the helper vtable for an encoder
  735. * @encoder: DRM encoder
  736. * @funcs: helper vtable to set for @encoder
  737. */
  738. static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
  739. const struct drm_encoder_helper_funcs *funcs)
  740. {
  741. encoder->helper_private = funcs;
  742. }
  743. /**
  744. * struct drm_connector_helper_funcs - helper operations for connectors
  745. *
  746. * These functions are used by the atomic and legacy modeset helpers and by the
  747. * probe helpers.
  748. */
  749. struct drm_connector_helper_funcs {
  750. /**
  751. * @get_modes:
  752. *
  753. * This function should fill in all modes currently valid for the sink
  754. * into the &drm_connector.probed_modes list. It should also update the
  755. * EDID property by calling drm_mode_connector_update_edid_property().
  756. *
  757. * The usual way to implement this is to cache the EDID retrieved in the
  758. * probe callback somewhere in the driver-private connector structure.
  759. * In this function drivers then parse the modes in the EDID and add
  760. * them by calling drm_add_edid_modes(). But connectors that driver a
  761. * fixed panel can also manually add specific modes using
  762. * drm_mode_probed_add(). Drivers which manually add modes should also
  763. * make sure that the &drm_connector.display_info,
  764. * &drm_connector.width_mm and &drm_connector.height_mm fields are
  765. * filled in.
  766. *
  767. * Virtual drivers that just want some standard VESA mode with a given
  768. * resolution can call drm_add_modes_noedid(), and mark the preferred
  769. * one using drm_set_preferred_mode().
  770. *
  771. * Finally drivers that support audio probably want to update the ELD
  772. * data, too, using drm_edid_to_eld().
  773. *
  774. * This function is only called after the @detect hook has indicated
  775. * that a sink is connected and when the EDID isn't overridden through
  776. * sysfs or the kernel commandline.
  777. *
  778. * This callback is used by the probe helpers in e.g.
  779. * drm_helper_probe_single_connector_modes().
  780. *
  781. * To avoid races with concurrent connector state updates, the helper
  782. * libraries always call this with the &drm_mode_config.connection_mutex
  783. * held. Because of this it's safe to inspect &drm_connector->state.
  784. *
  785. * RETURNS:
  786. *
  787. * The number of modes added by calling drm_mode_probed_add().
  788. */
  789. int (*get_modes)(struct drm_connector *connector);
  790. /**
  791. * @detect_ctx:
  792. *
  793. * Check to see if anything is attached to the connector. The parameter
  794. * force is set to false whilst polling, true when checking the
  795. * connector due to a user request. force can be used by the driver to
  796. * avoid expensive, destructive operations during automated probing.
  797. *
  798. * This callback is optional, if not implemented the connector will be
  799. * considered as always being attached.
  800. *
  801. * This is the atomic version of &drm_connector_funcs.detect.
  802. *
  803. * To avoid races against concurrent connector state updates, the
  804. * helper libraries always call this with ctx set to a valid context,
  805. * and &drm_mode_config.connection_mutex will always be locked with
  806. * the ctx parameter set to this ctx. This allows taking additional
  807. * locks as required.
  808. *
  809. * RETURNS:
  810. *
  811. * &drm_connector_status indicating the connector's status,
  812. * or the error code returned by drm_modeset_lock(), -EDEADLK.
  813. */
  814. int (*detect_ctx)(struct drm_connector *connector,
  815. struct drm_modeset_acquire_ctx *ctx,
  816. bool force);
  817. /**
  818. * @mode_valid:
  819. *
  820. * Callback to validate a mode for a connector, irrespective of the
  821. * specific display configuration.
  822. *
  823. * This callback is used by the probe helpers to filter the mode list
  824. * (which is usually derived from the EDID data block from the sink).
  825. * See e.g. drm_helper_probe_single_connector_modes().
  826. *
  827. * This function is optional.
  828. *
  829. * NOTE:
  830. *
  831. * This only filters the mode list supplied to userspace in the
  832. * GETCONNECTOR IOCTL. Compared to &drm_encoder_helper_funcs.mode_valid,
  833. * &drm_crtc_helper_funcs.mode_valid and &drm_bridge_funcs.mode_valid,
  834. * which are also called by the atomic helpers from
  835. * drm_atomic_helper_check_modeset(). This allows userspace to force and
  836. * ignore sink constraint (like the pixel clock limits in the screen's
  837. * EDID), which is useful for e.g. testing, or working around a broken
  838. * EDID. Any source hardware constraint (which always need to be
  839. * enforced) therefore should be checked in one of the above callbacks,
  840. * and not this one here.
  841. *
  842. * To avoid races with concurrent connector state updates, the helper
  843. * libraries always call this with the &drm_mode_config.connection_mutex
  844. * held. Because of this it's safe to inspect &drm_connector->state.
  845. *
  846. * RETURNS:
  847. *
  848. * Either &drm_mode_status.MODE_OK or one of the failure reasons in &enum
  849. * drm_mode_status.
  850. */
  851. enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
  852. struct drm_display_mode *mode);
  853. /**
  854. * @best_encoder:
  855. *
  856. * This function should select the best encoder for the given connector.
  857. *
  858. * This function is used by both the atomic helpers (in the
  859. * drm_atomic_helper_check_modeset() function) and in the legacy CRTC
  860. * helpers.
  861. *
  862. * NOTE:
  863. *
  864. * In atomic drivers this function is called in the check phase of an
  865. * atomic update. The driver is not allowed to change or inspect
  866. * anything outside of arguments passed-in. Atomic drivers which need to
  867. * inspect dynamic configuration state should instead use
  868. * @atomic_best_encoder.
  869. *
  870. * You can leave this function to NULL if the connector is only
  871. * attached to a single encoder and you are using the atomic helpers.
  872. * In this case, the core will call drm_atomic_helper_best_encoder()
  873. * for you.
  874. *
  875. * RETURNS:
  876. *
  877. * Encoder that should be used for the given connector and connector
  878. * state, or NULL if no suitable encoder exists. Note that the helpers
  879. * will ensure that encoders aren't used twice, drivers should not check
  880. * for this.
  881. */
  882. struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
  883. /**
  884. * @atomic_best_encoder:
  885. *
  886. * This is the atomic version of @best_encoder for atomic drivers which
  887. * need to select the best encoder depending upon the desired
  888. * configuration and can't select it statically.
  889. *
  890. * This function is used by drm_atomic_helper_check_modeset().
  891. * If it is not implemented, the core will fallback to @best_encoder
  892. * (or drm_atomic_helper_best_encoder() if @best_encoder is NULL).
  893. *
  894. * NOTE:
  895. *
  896. * This function is called in the check phase of an atomic update. The
  897. * driver is not allowed to change anything outside of the free-standing
  898. * state objects passed-in or assembled in the overall &drm_atomic_state
  899. * update tracking structure.
  900. *
  901. * RETURNS:
  902. *
  903. * Encoder that should be used for the given connector and connector
  904. * state, or NULL if no suitable encoder exists. Note that the helpers
  905. * will ensure that encoders aren't used twice, drivers should not check
  906. * for this.
  907. */
  908. struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,
  909. struct drm_connector_state *connector_state);
  910. /**
  911. * @atomic_check:
  912. *
  913. * This hook is used to validate connector state. This function is
  914. * called from &drm_atomic_helper_check_modeset, and is called when
  915. * a connector property is set, or a modeset on the crtc is forced.
  916. *
  917. * Because &drm_atomic_helper_check_modeset may be called multiple times,
  918. * this function should handle being called multiple times as well.
  919. *
  920. * This function is also allowed to inspect any other object's state and
  921. * can add more state objects to the atomic commit if needed. Care must
  922. * be taken though to ensure that state check and compute functions for
  923. * these added states are all called, and derived state in other objects
  924. * all updated. Again the recommendation is to just call check helpers
  925. * until a maximal configuration is reached.
  926. *
  927. * NOTE:
  928. *
  929. * This function is called in the check phase of an atomic update. The
  930. * driver is not allowed to change anything outside of the free-standing
  931. * state objects passed-in or assembled in the overall &drm_atomic_state
  932. * update tracking structure.
  933. *
  934. * RETURNS:
  935. *
  936. * 0 on success, -EINVAL if the state or the transition can't be
  937. * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
  938. * attempt to obtain another state object ran into a &drm_modeset_lock
  939. * deadlock.
  940. */
  941. int (*atomic_check)(struct drm_connector *connector,
  942. struct drm_connector_state *state);
  943. /**
  944. * @atomic_commit:
  945. *
  946. * This hook is to be used by drivers implementing writeback connectors
  947. * that need a point when to commit the writeback job to the hardware.
  948. *
  949. * This callback is used by the atomic modeset helpers.
  950. */
  951. void (*atomic_commit)(struct drm_connector *connector,
  952. struct drm_writeback_job *writeback_job);
  953. };
  954. /**
  955. * drm_connector_helper_add - sets the helper vtable for a connector
  956. * @connector: DRM connector
  957. * @funcs: helper vtable to set for @connector
  958. */
  959. static inline void drm_connector_helper_add(struct drm_connector *connector,
  960. const struct drm_connector_helper_funcs *funcs)
  961. {
  962. connector->helper_private = funcs;
  963. }
  964. /**
  965. * struct drm_plane_helper_funcs - helper operations for planes
  966. *
  967. * These functions are used by the atomic helpers and by the transitional plane
  968. * helpers.
  969. */
  970. struct drm_plane_helper_funcs {
  971. /**
  972. * @prepare_fb:
  973. *
  974. * This hook is to prepare a framebuffer for scanout by e.g. pinning
  975. * it's backing storage or relocating it into a contiguous block of
  976. * VRAM. Other possible preparatory work includes flushing caches.
  977. *
  978. * This function must not block for outstanding rendering, since it is
  979. * called in the context of the atomic IOCTL even for async commits to
  980. * be able to return any errors to userspace. Instead the recommended
  981. * way is to fill out the fence member of the passed-in
  982. * &drm_plane_state. If the driver doesn't support native fences then
  983. * equivalent functionality should be implemented through private
  984. * members in the plane structure.
  985. *
  986. * The helpers will call @cleanup_fb with matching arguments for every
  987. * successful call to this hook.
  988. *
  989. * This callback is used by the atomic modeset helpers and by the
  990. * transitional plane helpers, but it is optional.
  991. *
  992. * RETURNS:
  993. *
  994. * 0 on success or one of the following negative error codes allowed by
  995. * the &drm_mode_config_funcs.atomic_commit vfunc. When using helpers
  996. * this callback is the only one which can fail an atomic commit,
  997. * everything else must complete successfully.
  998. */
  999. int (*prepare_fb)(struct drm_plane *plane,
  1000. struct drm_plane_state *new_state);
  1001. /**
  1002. * @cleanup_fb:
  1003. *
  1004. * This hook is called to clean up any resources allocated for the given
  1005. * framebuffer and plane configuration in @prepare_fb.
  1006. *
  1007. * This callback is used by the atomic modeset helpers and by the
  1008. * transitional plane helpers, but it is optional.
  1009. */
  1010. void (*cleanup_fb)(struct drm_plane *plane,
  1011. struct drm_plane_state *old_state);
  1012. /**
  1013. * @atomic_check:
  1014. *
  1015. * Drivers should check plane specific constraints in this hook.
  1016. *
  1017. * When using drm_atomic_helper_check_planes() plane's @atomic_check
  1018. * hooks are called before the ones for CRTCs, which allows drivers to
  1019. * request shared resources that the CRTC controls here. For more
  1020. * complicated dependencies the driver can call the provided check helpers
  1021. * multiple times until the computed state has a final configuration and
  1022. * everything has been checked.
  1023. *
  1024. * This function is also allowed to inspect any other object's state and
  1025. * can add more state objects to the atomic commit if needed. Care must
  1026. * be taken though to ensure that state check and compute functions for
  1027. * these added states are all called, and derived state in other objects
  1028. * all updated. Again the recommendation is to just call check helpers
  1029. * until a maximal configuration is reached.
  1030. *
  1031. * This callback is used by the atomic modeset helpers and by the
  1032. * transitional plane helpers, but it is optional.
  1033. *
  1034. * NOTE:
  1035. *
  1036. * This function is called in the check phase of an atomic update. The
  1037. * driver is not allowed to change anything outside of the free-standing
  1038. * state objects passed-in or assembled in the overall &drm_atomic_state
  1039. * update tracking structure.
  1040. *
  1041. * RETURNS:
  1042. *
  1043. * 0 on success, -EINVAL if the state or the transition can't be
  1044. * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
  1045. * attempt to obtain another state object ran into a &drm_modeset_lock
  1046. * deadlock.
  1047. */
  1048. int (*atomic_check)(struct drm_plane *plane,
  1049. struct drm_plane_state *state);
  1050. /**
  1051. * @atomic_update:
  1052. *
  1053. * Drivers should use this function to update the plane state. This
  1054. * hook is called in-between the &drm_crtc_helper_funcs.atomic_begin and
  1055. * drm_crtc_helper_funcs.atomic_flush callbacks.
  1056. *
  1057. * Note that the power state of the display pipe when this function is
  1058. * called depends upon the exact helpers and calling sequence the driver
  1059. * has picked. See drm_atomic_helper_commit_planes() for a discussion of
  1060. * the tradeoffs and variants of plane commit helpers.
  1061. *
  1062. * This callback is used by the atomic modeset helpers and by the
  1063. * transitional plane helpers, but it is optional.
  1064. */
  1065. void (*atomic_update)(struct drm_plane *plane,
  1066. struct drm_plane_state *old_state);
  1067. /**
  1068. * @atomic_disable:
  1069. *
  1070. * Drivers should use this function to unconditionally disable a plane.
  1071. * This hook is called in-between the
  1072. * &drm_crtc_helper_funcs.atomic_begin and
  1073. * drm_crtc_helper_funcs.atomic_flush callbacks. It is an alternative to
  1074. * @atomic_update, which will be called for disabling planes, too, if
  1075. * the @atomic_disable hook isn't implemented.
  1076. *
  1077. * This hook is also useful to disable planes in preparation of a modeset,
  1078. * by calling drm_atomic_helper_disable_planes_on_crtc() from the
  1079. * &drm_crtc_helper_funcs.disable hook.
  1080. *
  1081. * Note that the power state of the display pipe when this function is
  1082. * called depends upon the exact helpers and calling sequence the driver
  1083. * has picked. See drm_atomic_helper_commit_planes() for a discussion of
  1084. * the tradeoffs and variants of plane commit helpers.
  1085. *
  1086. * This callback is used by the atomic modeset helpers and by the
  1087. * transitional plane helpers, but it is optional.
  1088. */
  1089. void (*atomic_disable)(struct drm_plane *plane,
  1090. struct drm_plane_state *old_state);
  1091. /**
  1092. * @atomic_async_check:
  1093. *
  1094. * Drivers should set this function pointer to check if the plane state
  1095. * can be updated in a async fashion. Here async means "not vblank
  1096. * synchronized".
  1097. *
  1098. * This hook is called by drm_atomic_async_check() to establish if a
  1099. * given update can be committed asynchronously, that is, if it can
  1100. * jump ahead of the state currently queued for update.
  1101. *
  1102. * RETURNS:
  1103. *
  1104. * Return 0 on success and any error returned indicates that the update
  1105. * can not be applied in asynchronous manner.
  1106. */
  1107. int (*atomic_async_check)(struct drm_plane *plane,
  1108. struct drm_plane_state *state);
  1109. /**
  1110. * @atomic_async_update:
  1111. *
  1112. * Drivers should set this function pointer to perform asynchronous
  1113. * updates of planes, that is, jump ahead of the currently queued
  1114. * state and update the plane. Here async means "not vblank
  1115. * synchronized".
  1116. *
  1117. * This hook is called by drm_atomic_helper_async_commit().
  1118. *
  1119. * An async update will happen on legacy cursor updates. An async
  1120. * update won't happen if there is an outstanding commit modifying
  1121. * the same plane.
  1122. *
  1123. * Note that unlike &drm_plane_helper_funcs.atomic_update this hook
  1124. * takes the new &drm_plane_state as parameter. When doing async_update
  1125. * drivers shouldn't replace the &drm_plane_state but update the
  1126. * current one with the new plane configurations in the new
  1127. * plane_state.
  1128. *
  1129. * Drivers should also swap the framebuffers between current plane
  1130. * state (&drm_plane.state) and new_state.
  1131. * This is required since cleanup for async commits is performed on
  1132. * the new state, rather than old state like for traditional commits.
  1133. * Since we want to give up the reference on the current (old) fb
  1134. * instead of our brand new one, swap them in the driver during the
  1135. * async commit.
  1136. *
  1137. * FIXME:
  1138. * - It only works for single plane updates
  1139. * - Async Pageflips are not supported yet
  1140. * - Some hw might still scan out the old buffer until the next
  1141. * vblank, however we let go of the fb references as soon as
  1142. * we run this hook. For now drivers must implement their own workers
  1143. * for deferring if needed, until a common solution is created.
  1144. */
  1145. void (*atomic_async_update)(struct drm_plane *plane,
  1146. struct drm_plane_state *new_state);
  1147. };
  1148. /**
  1149. * drm_plane_helper_add - sets the helper vtable for a plane
  1150. * @plane: DRM plane
  1151. * @funcs: helper vtable to set for @plane
  1152. */
  1153. static inline void drm_plane_helper_add(struct drm_plane *plane,
  1154. const struct drm_plane_helper_funcs *funcs)
  1155. {
  1156. plane->helper_private = funcs;
  1157. }
  1158. /**
  1159. * struct drm_mode_config_helper_funcs - global modeset helper operations
  1160. *
  1161. * These helper functions are used by the atomic helpers.
  1162. */
  1163. struct drm_mode_config_helper_funcs {
  1164. /**
  1165. * @atomic_commit_tail:
  1166. *
  1167. * This hook is used by the default atomic_commit() hook implemented in
  1168. * drm_atomic_helper_commit() together with the nonblocking commit
  1169. * helpers (see drm_atomic_helper_setup_commit() for a starting point)
  1170. * to implement blocking and nonblocking commits easily. It is not used
  1171. * by the atomic helpers
  1172. *
  1173. * This function is called when the new atomic state has already been
  1174. * swapped into the various state pointers. The passed in state
  1175. * therefore contains copies of the old/previous state. This hook should
  1176. * commit the new state into hardware. Note that the helpers have
  1177. * already waited for preceeding atomic commits and fences, but drivers
  1178. * can add more waiting calls at the start of their implementation, e.g.
  1179. * to wait for driver-internal request for implicit syncing, before
  1180. * starting to commit the update to the hardware.
  1181. *
  1182. * After the atomic update is committed to the hardware this hook needs
  1183. * to call drm_atomic_helper_commit_hw_done(). Then wait for the upate
  1184. * to be executed by the hardware, for example using
  1185. * drm_atomic_helper_wait_for_vblanks() or
  1186. * drm_atomic_helper_wait_for_flip_done(), and then clean up the old
  1187. * framebuffers using drm_atomic_helper_cleanup_planes().
  1188. *
  1189. * When disabling a CRTC this hook _must_ stall for the commit to
  1190. * complete. Vblank waits don't work on disabled CRTC, hence the core
  1191. * can't take care of this. And it also can't rely on the vblank event,
  1192. * since that can be signalled already when the screen shows black,
  1193. * which can happen much earlier than the last hardware access needed to
  1194. * shut off the display pipeline completely.
  1195. *
  1196. * This hook is optional, the default implementation is
  1197. * drm_atomic_helper_commit_tail().
  1198. */
  1199. void (*atomic_commit_tail)(struct drm_atomic_state *state);
  1200. };
  1201. #endif