drm_modeset_helper_vtables.h 43 KB

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