drm_modeset_helper_vtables.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  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. *
  256. * NOTE:
  257. *
  258. * With legacy CRTC helpers there's a big semantic difference between
  259. * @disable and other hooks (like @prepare or @dpms) used to shut down a
  260. * CRTC: @disable is only called when also logically disabling the
  261. * display pipeline and needs to release any resources acquired in
  262. * @mode_set (like shared PLLs, or again release pinned framebuffers).
  263. *
  264. * Therefore @disable must be the inverse of @mode_set plus @commit for
  265. * drivers still using legacy CRTC helpers, which is different from the
  266. * rules under atomic.
  267. */
  268. void (*disable)(struct drm_crtc *crtc);
  269. /**
  270. * @enable:
  271. *
  272. * This callback should be used to enable the CRTC. With the atomic
  273. * drivers it is called before all encoders connected to this CRTC are
  274. * enabled through the encoder's own ->enable hook. If that sequence is
  275. * too simple drivers can just add their own hooks and call it from this
  276. * CRTC callback here by looping over all encoders connected to it using
  277. * for_each_encoder_on_crtc().
  278. *
  279. * This hook is used only by atomic helpers, for symmetry with @disable.
  280. * Atomic drivers don't need to implement it if there's no need to
  281. * enable anything at the CRTC level. To ensure that runtime PM handling
  282. * (using either DPMS or the new "ACTIVE" property) works
  283. * @enable must be the inverse of @disable for atomic drivers.
  284. */
  285. void (*enable)(struct drm_crtc *crtc);
  286. /**
  287. * @atomic_check:
  288. *
  289. * Drivers should check plane-update related CRTC constraints in this
  290. * hook. They can also check mode related limitations but need to be
  291. * aware of the calling order, since this hook is used by
  292. * drm_atomic_helper_check_planes() whereas the preparations needed to
  293. * check output routing and the display mode is done in
  294. * drm_atomic_helper_check_modeset(). Therefore drivers that want to
  295. * check output routing and display mode constraints in this callback
  296. * must ensure that drm_atomic_helper_check_modeset() has been called
  297. * beforehand. This is calling order used by the default helper
  298. * implementation in drm_atomic_helper_check().
  299. *
  300. * When using drm_atomic_helper_check_planes() CRTCs' ->atomic_check()
  301. * hooks are called after the ones for planes, which allows drivers to
  302. * assign shared resources requested by planes in the CRTC callback
  303. * here. For more complicated dependencies the driver can call the provided
  304. * check helpers multiple times until the computed state has a final
  305. * configuration and everything has been checked.
  306. *
  307. * This function is also allowed to inspect any other object's state and
  308. * can add more state objects to the atomic commit if needed. Care must
  309. * be taken though to ensure that state check&compute functions for
  310. * these added states are all called, and derived state in other objects
  311. * all updated. Again the recommendation is to just call check helpers
  312. * until a maximal configuration is reached.
  313. *
  314. * This callback is used by the atomic modeset helpers and by the
  315. * transitional plane helpers, but it is optional.
  316. *
  317. * NOTE:
  318. *
  319. * This function is called in the check phase of an atomic update. The
  320. * driver is not allowed to change anything outside of the free-standing
  321. * state objects passed-in or assembled in the overall &drm_atomic_state
  322. * update tracking structure.
  323. *
  324. * RETURNS:
  325. *
  326. * 0 on success, -EINVAL if the state or the transition can't be
  327. * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
  328. * attempt to obtain another state object ran into a &drm_modeset_lock
  329. * deadlock.
  330. */
  331. int (*atomic_check)(struct drm_crtc *crtc,
  332. struct drm_crtc_state *state);
  333. /**
  334. * @atomic_begin:
  335. *
  336. * Drivers should prepare for an atomic update of multiple planes on
  337. * a CRTC in this hook. Depending upon hardware this might be vblank
  338. * evasion, blocking updates by setting bits or doing preparatory work
  339. * for e.g. manual update display.
  340. *
  341. * This hook is called before any plane commit functions are called.
  342. *
  343. * Note that the power state of the display pipe when this function is
  344. * called depends upon the exact helpers and calling sequence the driver
  345. * has picked. See drm_atomic_commit_planes() for a discussion of the
  346. * tradeoffs and variants of plane commit helpers.
  347. *
  348. * This callback is used by the atomic modeset helpers and by the
  349. * transitional plane helpers, but it is optional.
  350. */
  351. void (*atomic_begin)(struct drm_crtc *crtc,
  352. struct drm_crtc_state *old_crtc_state);
  353. /**
  354. * @atomic_flush:
  355. *
  356. * Drivers should finalize an atomic update of multiple planes on
  357. * a CRTC in this hook. Depending upon hardware this might include
  358. * checking that vblank evasion was successful, unblocking updates by
  359. * setting bits or setting the GO bit to flush out all updates.
  360. *
  361. * Simple hardware or hardware with special requirements can commit and
  362. * flush out all updates for all planes from this hook and forgo all the
  363. * other commit hooks for plane updates.
  364. *
  365. * This hook is called after any plane commit functions are called.
  366. *
  367. * Note that the power state of the display pipe when this function is
  368. * called depends upon the exact helpers and calling sequence the driver
  369. * has picked. See drm_atomic_commit_planes() for a discussion of the
  370. * tradeoffs and variants of plane commit helpers.
  371. *
  372. * This callback is used by the atomic modeset helpers and by the
  373. * transitional plane helpers, but it is optional.
  374. */
  375. void (*atomic_flush)(struct drm_crtc *crtc,
  376. struct drm_crtc_state *old_crtc_state);
  377. };
  378. /**
  379. * drm_crtc_helper_add - sets the helper vtable for a crtc
  380. * @crtc: DRM CRTC
  381. * @funcs: helper vtable to set for @crtc
  382. */
  383. static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
  384. const struct drm_crtc_helper_funcs *funcs)
  385. {
  386. crtc->helper_private = funcs;
  387. }
  388. /**
  389. * struct drm_encoder_helper_funcs - helper operations for encoders
  390. *
  391. * These hooks are used by the legacy CRTC helpers, the transitional plane
  392. * helpers and the new atomic modesetting helpers.
  393. */
  394. struct drm_encoder_helper_funcs {
  395. /**
  396. * @dpms:
  397. *
  398. * Callback to control power levels on the encoder. If the mode passed in
  399. * is unsupported, the provider must use the next lowest power level.
  400. * This is used by the legacy encoder helpers to implement DPMS
  401. * functionality in drm_helper_connector_dpms().
  402. *
  403. * This callback is also used to disable an encoder by calling it with
  404. * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
  405. *
  406. * This callback is used by the legacy CRTC helpers. Atomic helpers
  407. * also support using this hook for enabling and disabling an encoder to
  408. * facilitate transitions to atomic, but it is deprecated. Instead
  409. * @enable and @disable should be used.
  410. */
  411. void (*dpms)(struct drm_encoder *encoder, int mode);
  412. /**
  413. * @mode_fixup:
  414. *
  415. * This callback is used to validate and adjust a mode. The parameter
  416. * mode is the display mode that should be fed to the next element in
  417. * the display chain, either the final &drm_connector or a &drm_bridge.
  418. * The parameter adjusted_mode is the input mode the encoder requires. It
  419. * can be modified by this callback and does not need to match mode.
  420. *
  421. * This function is used by both legacy CRTC helpers and atomic helpers.
  422. * With atomic helpers it is optional.
  423. *
  424. * NOTE:
  425. *
  426. * This function is called in the check phase of atomic modesets, which
  427. * can be aborted for any reason (including on userspace's request to
  428. * just check whether a configuration would be possible). Atomic drivers
  429. * MUST NOT touch any persistent state (hardware or software) or data
  430. * structures except the passed in adjusted_mode parameter.
  431. *
  432. * This is in contrast to the legacy CRTC helpers where this was
  433. * allowed.
  434. *
  435. * Atomic drivers which need to inspect and adjust more state should
  436. * instead use the @atomic_check callback.
  437. *
  438. * Also beware that neither core nor helpers filter modes before
  439. * passing them to the driver: While the list of modes that is
  440. * advertised to userspace is filtered using the connector's
  441. * ->mode_valid() callback, neither the core nor the helpers do any
  442. * filtering on modes passed in from userspace when setting a mode. It
  443. * is therefore possible for userspace to pass in a mode that was
  444. * previously filtered out using ->mode_valid() or add a custom mode
  445. * that wasn't probed from EDID or similar to begin with. Even though
  446. * this is an advanced feature and rarely used nowadays, some users rely
  447. * on being able to specify modes manually so drivers must be prepared
  448. * to deal with it. Specifically this means that all drivers need not
  449. * only validate modes in ->mode_valid() but also in ->mode_fixup() to
  450. * make sure invalid modes passed in from userspace are rejected.
  451. *
  452. * RETURNS:
  453. *
  454. * True if an acceptable configuration is possible, false if the modeset
  455. * operation should be rejected.
  456. */
  457. bool (*mode_fixup)(struct drm_encoder *encoder,
  458. const struct drm_display_mode *mode,
  459. struct drm_display_mode *adjusted_mode);
  460. /**
  461. * @prepare:
  462. *
  463. * This callback should prepare the encoder for a subsequent modeset,
  464. * which in practice means the driver should disable the encoder if it
  465. * is running. Most drivers ended up implementing this by calling their
  466. * @dpms hook with DRM_MODE_DPMS_OFF.
  467. *
  468. * This callback is used by the legacy CRTC helpers. Atomic helpers
  469. * also support using this hook for disabling an encoder to facilitate
  470. * transitions to atomic, but it is deprecated. Instead @disable should
  471. * be used.
  472. */
  473. void (*prepare)(struct drm_encoder *encoder);
  474. /**
  475. * @commit:
  476. *
  477. * This callback should commit the new mode on the encoder after a modeset,
  478. * which in practice means the driver should enable the encoder. Most
  479. * drivers ended up implementing this by calling their @dpms hook with
  480. * DRM_MODE_DPMS_ON.
  481. *
  482. * This callback is used by the legacy CRTC helpers. Atomic helpers
  483. * also support using this hook for enabling an encoder to facilitate
  484. * transitions to atomic, but it is deprecated. Instead @enable should
  485. * be used.
  486. */
  487. void (*commit)(struct drm_encoder *encoder);
  488. /**
  489. * @mode_set:
  490. *
  491. * This callback is used to update the display mode of an encoder.
  492. *
  493. * Note that the display pipe is completely off when this function is
  494. * called. Drivers which need hardware to be running before they program
  495. * the new display mode (because they implement runtime PM) should not
  496. * use this hook, because the helper library calls it only once and not
  497. * every time the display pipeline is suspend using either DPMS or the
  498. * new "ACTIVE" property. Such drivers should instead move all their
  499. * encoder setup into the ->enable() callback.
  500. *
  501. * This callback is used both by the legacy CRTC helpers and the atomic
  502. * modeset helpers. It is optional in the atomic helpers.
  503. */
  504. void (*mode_set)(struct drm_encoder *encoder,
  505. struct drm_display_mode *mode,
  506. struct drm_display_mode *adjusted_mode);
  507. /**
  508. * @get_crtc:
  509. *
  510. * This callback is used by the legacy CRTC helpers to work around
  511. * deficiencies in its own book-keeping.
  512. *
  513. * Do not use, use atomic helpers instead, which get the book keeping
  514. * right.
  515. *
  516. * FIXME:
  517. *
  518. * Currently only nouveau is using this, and as soon as nouveau is
  519. * atomic we can ditch this hook.
  520. */
  521. struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder);
  522. /**
  523. * @detect:
  524. *
  525. * This callback can be used by drivers who want to do detection on the
  526. * encoder object instead of in connector functions.
  527. *
  528. * It is not used by any helper and therefore has purely driver-specific
  529. * semantics. New drivers shouldn't use this and instead just implement
  530. * their own private callbacks.
  531. *
  532. * FIXME:
  533. *
  534. * This should just be converted into a pile of driver vfuncs.
  535. * Currently radeon, amdgpu and nouveau are using it.
  536. */
  537. enum drm_connector_status (*detect)(struct drm_encoder *encoder,
  538. struct drm_connector *connector);
  539. /**
  540. * @disable:
  541. *
  542. * This callback should be used to disable the encoder. With the atomic
  543. * drivers it is called before this encoder's CRTC has been shut off
  544. * using the CRTC's own ->disable hook. If that sequence is too simple
  545. * drivers can just add their own driver private encoder hooks and call
  546. * them from CRTC's callback by looping over all encoders connected to
  547. * it using for_each_encoder_on_crtc().
  548. *
  549. * This hook is used both by legacy CRTC helpers and atomic helpers.
  550. * Atomic drivers don't need to implement it if there's no need to
  551. * disable anything at the encoder level. To ensure that runtime PM
  552. * handling (using either DPMS or the new "ACTIVE" property) works
  553. * @disable must be the inverse of @enable for atomic drivers.
  554. *
  555. * NOTE:
  556. *
  557. * With legacy CRTC helpers there's a big semantic difference between
  558. * @disable and other hooks (like @prepare or @dpms) used to shut down a
  559. * encoder: @disable is only called when also logically disabling the
  560. * display pipeline and needs to release any resources acquired in
  561. * @mode_set (like shared PLLs, or again release pinned framebuffers).
  562. *
  563. * Therefore @disable must be the inverse of @mode_set plus @commit for
  564. * drivers still using legacy CRTC helpers, which is different from the
  565. * rules under atomic.
  566. */
  567. void (*disable)(struct drm_encoder *encoder);
  568. /**
  569. * @enable:
  570. *
  571. * This callback should be used to enable the encoder. With the atomic
  572. * drivers it is called after this encoder's CRTC has been enabled using
  573. * the CRTC's own ->enable hook. If that sequence is too simple drivers
  574. * can just add their own driver private encoder hooks and call them
  575. * from CRTC's callback by looping over all encoders connected to it
  576. * using for_each_encoder_on_crtc().
  577. *
  578. * This hook is used only by atomic helpers, for symmetry with @disable.
  579. * Atomic drivers don't need to implement it if there's no need to
  580. * enable anything at the encoder level. To ensure that runtime PM handling
  581. * (using either DPMS or the new "ACTIVE" property) works
  582. * @enable must be the inverse of @disable for atomic drivers.
  583. */
  584. void (*enable)(struct drm_encoder *encoder);
  585. /**
  586. * @atomic_check:
  587. *
  588. * This callback is used to validate encoder state for atomic drivers.
  589. * Since the encoder is the object connecting the CRTC and connector it
  590. * gets passed both states, to be able to validate interactions and
  591. * update the CRTC to match what the encoder needs for the requested
  592. * connector.
  593. *
  594. * This function is used by the atomic helpers, but it is optional.
  595. *
  596. * NOTE:
  597. *
  598. * This function is called in the check phase of an atomic update. The
  599. * driver is not allowed to change anything outside of the free-standing
  600. * state objects passed-in or assembled in the overall &drm_atomic_state
  601. * update tracking structure.
  602. *
  603. * RETURNS:
  604. *
  605. * 0 on success, -EINVAL if the state or the transition can't be
  606. * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
  607. * attempt to obtain another state object ran into a &drm_modeset_lock
  608. * deadlock.
  609. */
  610. int (*atomic_check)(struct drm_encoder *encoder,
  611. struct drm_crtc_state *crtc_state,
  612. struct drm_connector_state *conn_state);
  613. };
  614. /**
  615. * drm_encoder_helper_add - sets the helper vtable for an encoder
  616. * @encoder: DRM encoder
  617. * @funcs: helper vtable to set for @encoder
  618. */
  619. static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
  620. const struct drm_encoder_helper_funcs *funcs)
  621. {
  622. encoder->helper_private = funcs;
  623. }
  624. /**
  625. * struct drm_connector_helper_funcs - helper operations for connectors
  626. *
  627. * These functions are used by the atomic and legacy modeset helpers and by the
  628. * probe helpers.
  629. */
  630. struct drm_connector_helper_funcs {
  631. /**
  632. * @get_modes:
  633. *
  634. * This function should fill in all modes currently valid for the sink
  635. * into the connector->probed_modes list. It should also update the
  636. * EDID property by calling drm_mode_connector_update_edid_property().
  637. *
  638. * The usual way to implement this is to cache the EDID retrieved in the
  639. * probe callback somewhere in the driver-private connector structure.
  640. * In this function drivers then parse the modes in the EDID and add
  641. * them by calling drm_add_edid_modes(). But connectors that driver a
  642. * fixed panel can also manually add specific modes using
  643. * drm_mode_probed_add(). Drivers which manually add modes should also
  644. * make sure that the @display_info, @width_mm and @height_mm fields of the
  645. * struct #drm_connector are filled in.
  646. *
  647. * Virtual drivers that just want some standard VESA mode with a given
  648. * resolution can call drm_add_modes_noedid(), and mark the preferred
  649. * one using drm_set_preferred_mode().
  650. *
  651. * Finally drivers that support audio probably want to update the ELD
  652. * data, too, using drm_edid_to_eld().
  653. *
  654. * This function is only called after the ->detect() hook has indicated
  655. * that a sink is connected and when the EDID isn't overridden through
  656. * sysfs or the kernel commandline.
  657. *
  658. * This callback is used by the probe helpers in e.g.
  659. * drm_helper_probe_single_connector_modes().
  660. *
  661. * RETURNS:
  662. *
  663. * The number of modes added by calling drm_mode_probed_add().
  664. */
  665. int (*get_modes)(struct drm_connector *connector);
  666. /**
  667. * @mode_valid:
  668. *
  669. * Callback to validate a mode for a connector, irrespective of the
  670. * specific display configuration.
  671. *
  672. * This callback is used by the probe helpers to filter the mode list
  673. * (which is usually derived from the EDID data block from the sink).
  674. * See e.g. drm_helper_probe_single_connector_modes().
  675. *
  676. * NOTE:
  677. *
  678. * This only filters the mode list supplied to userspace in the
  679. * GETCONNECOTR IOCTL. Userspace is free to create modes of its own and
  680. * ask the kernel to use them. It this case the atomic helpers or legacy
  681. * CRTC helpers will not call this function. Drivers therefore must
  682. * still fully validate any mode passed in in a modeset request.
  683. *
  684. * RETURNS:
  685. *
  686. * Either MODE_OK or one of the failure reasons in enum
  687. * &drm_mode_status.
  688. */
  689. enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
  690. struct drm_display_mode *mode);
  691. /**
  692. * @best_encoder:
  693. *
  694. * This function should select the best encoder for the given connector.
  695. *
  696. * This function is used by both the atomic helpers (in the
  697. * drm_atomic_helper_check_modeset() function) and in the legacy CRTC
  698. * helpers.
  699. *
  700. * NOTE:
  701. *
  702. * In atomic drivers this function is called in the check phase of an
  703. * atomic update. The driver is not allowed to change or inspect
  704. * anything outside of arguments passed-in. Atomic drivers which need to
  705. * inspect dynamic configuration state should instead use
  706. * @atomic_best_encoder.
  707. *
  708. * RETURNS:
  709. *
  710. * Encoder that should be used for the given connector and connector
  711. * state, or NULL if no suitable encoder exists. Note that the helpers
  712. * will ensure that encoders aren't used twice, drivers should not check
  713. * for this.
  714. */
  715. struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
  716. /**
  717. * @atomic_best_encoder:
  718. *
  719. * This is the atomic version of @best_encoder for atomic drivers which
  720. * need to select the best encoder depending upon the desired
  721. * configuration and can't select it statically.
  722. *
  723. * This function is used by drm_atomic_helper_check_modeset() and either
  724. * this or @best_encoder is required.
  725. *
  726. * NOTE:
  727. *
  728. * This function is called in the check phase of an atomic update. The
  729. * driver is not allowed to change anything outside of the free-standing
  730. * state objects passed-in or assembled in the overall &drm_atomic_state
  731. * update tracking structure.
  732. *
  733. * RETURNS:
  734. *
  735. * Encoder that should be used for the given connector and connector
  736. * state, or NULL if no suitable encoder exists. Note that the helpers
  737. * will ensure that encoders aren't used twice, drivers should not check
  738. * for this.
  739. */
  740. struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,
  741. struct drm_connector_state *connector_state);
  742. };
  743. /**
  744. * drm_connector_helper_add - sets the helper vtable for a connector
  745. * @connector: DRM connector
  746. * @funcs: helper vtable to set for @connector
  747. */
  748. static inline void drm_connector_helper_add(struct drm_connector *connector,
  749. const struct drm_connector_helper_funcs *funcs)
  750. {
  751. connector->helper_private = funcs;
  752. }
  753. /**
  754. * struct drm_plane_helper_funcs - helper operations for planes
  755. *
  756. * These functions are used by the atomic helpers and by the transitional plane
  757. * helpers.
  758. */
  759. struct drm_plane_helper_funcs {
  760. /**
  761. * @prepare_fb:
  762. *
  763. * This hook is to prepare a framebuffer for scanout by e.g. pinning
  764. * it's backing storage or relocating it into a contiguous block of
  765. * VRAM. Other possible preparatory work includes flushing caches.
  766. *
  767. * This function must not block for outstanding rendering, since it is
  768. * called in the context of the atomic IOCTL even for async commits to
  769. * be able to return any errors to userspace. Instead the recommended
  770. * way is to fill out the fence member of the passed-in
  771. * &drm_plane_state. If the driver doesn't support native fences then
  772. * equivalent functionality should be implemented through private
  773. * members in the plane structure.
  774. *
  775. * The helpers will call @cleanup_fb with matching arguments for every
  776. * successful call to this hook.
  777. *
  778. * This callback is used by the atomic modeset helpers and by the
  779. * transitional plane helpers, but it is optional.
  780. *
  781. * RETURNS:
  782. *
  783. * 0 on success or one of the following negative error codes allowed by
  784. * the atomic_commit hook in &drm_mode_config_funcs. When using helpers
  785. * this callback is the only one which can fail an atomic commit,
  786. * everything else must complete successfully.
  787. */
  788. int (*prepare_fb)(struct drm_plane *plane,
  789. const struct drm_plane_state *new_state);
  790. /**
  791. * @cleanup_fb:
  792. *
  793. * This hook is called to clean up any resources allocated for the given
  794. * framebuffer and plane configuration in @prepare_fb.
  795. *
  796. * This callback is used by the atomic modeset helpers and by the
  797. * transitional plane helpers, but it is optional.
  798. */
  799. void (*cleanup_fb)(struct drm_plane *plane,
  800. const struct drm_plane_state *old_state);
  801. /**
  802. * @atomic_check:
  803. *
  804. * Drivers should check plane specific constraints in this hook.
  805. *
  806. * When using drm_atomic_helper_check_planes() plane's ->atomic_check()
  807. * hooks are called before the ones for CRTCs, which allows drivers to
  808. * request shared resources that the CRTC controls here. For more
  809. * complicated dependencies the driver can call the provided check helpers
  810. * multiple times until the computed state has a final configuration and
  811. * everything has been checked.
  812. *
  813. * This function is also allowed to inspect any other object's state and
  814. * can add more state objects to the atomic commit if needed. Care must
  815. * be taken though to ensure that state check&compute functions for
  816. * these added states are all called, and derived state in other objects
  817. * all updated. Again the recommendation is to just call check helpers
  818. * until a maximal configuration is reached.
  819. *
  820. * This callback is used by the atomic modeset helpers and by the
  821. * transitional plane helpers, but it is optional.
  822. *
  823. * NOTE:
  824. *
  825. * This function is called in the check phase of an atomic update. The
  826. * driver is not allowed to change anything outside of the free-standing
  827. * state objects passed-in or assembled in the overall &drm_atomic_state
  828. * update tracking structure.
  829. *
  830. * RETURNS:
  831. *
  832. * 0 on success, -EINVAL if the state or the transition can't be
  833. * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
  834. * attempt to obtain another state object ran into a &drm_modeset_lock
  835. * deadlock.
  836. */
  837. int (*atomic_check)(struct drm_plane *plane,
  838. struct drm_plane_state *state);
  839. /**
  840. * @atomic_update:
  841. *
  842. * Drivers should use this function to update the plane state. This
  843. * hook is called in-between the ->atomic_begin() and
  844. * ->atomic_flush() of &drm_crtc_helper_funcs.
  845. *
  846. * Note that the power state of the display pipe when this function is
  847. * called depends upon the exact helpers and calling sequence the driver
  848. * has picked. See drm_atomic_commit_planes() for a discussion of the
  849. * tradeoffs and variants of plane commit helpers.
  850. *
  851. * This callback is used by the atomic modeset helpers and by the
  852. * transitional plane helpers, but it is optional.
  853. */
  854. void (*atomic_update)(struct drm_plane *plane,
  855. struct drm_plane_state *old_state);
  856. /**
  857. * @atomic_disable:
  858. *
  859. * Drivers should use this function to unconditionally disable a plane.
  860. * This hook is called in-between the ->atomic_begin() and
  861. * ->atomic_flush() of &drm_crtc_helper_funcs. It is an alternative to
  862. * @atomic_update, which will be called for disabling planes, too, if
  863. * the @atomic_disable hook isn't implemented.
  864. *
  865. * This hook is also useful to disable planes in preparation of a modeset,
  866. * by calling drm_atomic_helper_disable_planes_on_crtc() from the
  867. * ->disable() hook in &drm_crtc_helper_funcs.
  868. *
  869. * Note that the power state of the display pipe when this function is
  870. * called depends upon the exact helpers and calling sequence the driver
  871. * has picked. See drm_atomic_commit_planes() for a discussion of the
  872. * tradeoffs and variants of plane commit helpers.
  873. *
  874. * This callback is used by the atomic modeset helpers and by the
  875. * transitional plane helpers, but it is optional.
  876. */
  877. void (*atomic_disable)(struct drm_plane *plane,
  878. struct drm_plane_state *old_state);
  879. };
  880. /**
  881. * drm_plane_helper_add - sets the helper vtable for a plane
  882. * @plane: DRM plane
  883. * @funcs: helper vtable to set for @plane
  884. */
  885. static inline void drm_plane_helper_add(struct drm_plane *plane,
  886. const struct drm_plane_helper_funcs *funcs)
  887. {
  888. plane->helper_private = funcs;
  889. }
  890. #endif