drm_modeset_helper_vtables.h 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557
  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. struct drm_scanout_buffer;
  48. struct drm_writeback_connector;
  49. struct drm_writeback_job;
  50. /**
  51. * struct drm_crtc_helper_funcs - helper operations for CRTCs
  52. *
  53. * These hooks are used by the legacy CRTC helpers and the new atomic
  54. * modesetting helpers.
  55. */
  56. struct drm_crtc_helper_funcs {
  57. /**
  58. * @dpms:
  59. *
  60. * Callback to control power levels on the CRTC. If the mode passed in
  61. * is unsupported, the provider must use the next lowest power level.
  62. * This is used by the legacy CRTC helpers to implement DPMS
  63. * functionality in drm_helper_connector_dpms().
  64. *
  65. * This callback is also used to disable a CRTC by calling it with
  66. * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
  67. *
  68. * This callback is used by the legacy CRTC helpers. Atomic helpers
  69. * also support using this hook for enabling and disabling a CRTC to
  70. * facilitate transitions to atomic, but it is deprecated. Instead
  71. * @atomic_enable and @atomic_disable should be used.
  72. */
  73. void (*dpms)(struct drm_crtc *crtc, int mode);
  74. /**
  75. * @prepare:
  76. *
  77. * This callback should prepare the CRTC for a subsequent modeset, which
  78. * in practice means the driver should disable the CRTC if it is
  79. * running. Most drivers ended up implementing this by calling their
  80. * @dpms hook with DRM_MODE_DPMS_OFF.
  81. *
  82. * This callback is used by the legacy CRTC helpers. Atomic helpers
  83. * also support using this hook for disabling a CRTC to facilitate
  84. * transitions to atomic, but it is deprecated. Instead @atomic_disable
  85. * should be used.
  86. */
  87. void (*prepare)(struct drm_crtc *crtc);
  88. /**
  89. * @commit:
  90. *
  91. * This callback should commit the new mode on the CRTC after a modeset,
  92. * which in practice means the driver should enable the CRTC. Most
  93. * drivers ended up implementing this by calling their @dpms hook with
  94. * DRM_MODE_DPMS_ON.
  95. *
  96. * This callback is used by the legacy CRTC helpers. Atomic helpers
  97. * also support using this hook for enabling a CRTC to facilitate
  98. * transitions to atomic, but it is deprecated. Instead @atomic_enable
  99. * should be used.
  100. */
  101. void (*commit)(struct drm_crtc *crtc);
  102. /**
  103. * @mode_valid:
  104. *
  105. * This callback is used to check if a specific mode is valid in this
  106. * crtc. This should be implemented if the crtc has some sort of
  107. * restriction in the modes it can display. For example, a given crtc
  108. * may be responsible to set a clock value. If the clock can not
  109. * produce all the values for the available modes then this callback
  110. * can be used to restrict the number of modes to only the ones that
  111. * can be displayed.
  112. *
  113. * This hook is used by the probe helpers to filter the mode list in
  114. * drm_helper_probe_single_connector_modes(), and it is used by the
  115. * atomic helpers to validate modes supplied by userspace in
  116. * drm_atomic_helper_check_modeset().
  117. *
  118. * This function is optional.
  119. *
  120. * NOTE:
  121. *
  122. * Since this function is both called from the check phase of an atomic
  123. * commit, and the mode validation in the probe paths it is not allowed
  124. * to look at anything else but the passed-in mode, and validate it
  125. * against configuration-invariant hardware constraints. Any further
  126. * limits which depend upon the configuration can only be checked in
  127. * @mode_fixup or @atomic_check.
  128. *
  129. * RETURNS:
  130. *
  131. * drm_mode_status Enum
  132. */
  133. enum drm_mode_status (*mode_valid)(struct drm_crtc *crtc,
  134. const struct drm_display_mode *mode);
  135. /**
  136. * @mode_fixup:
  137. *
  138. * This callback is used to validate a mode. The parameter mode is the
  139. * display mode that userspace requested, adjusted_mode is the mode the
  140. * encoders need to be fed with. Note that this is the inverse semantics
  141. * of the meaning for the &drm_encoder and &drm_bridge_funcs.mode_fixup
  142. * vfunc. If the CRTC cannot support the requested conversion from mode
  143. * to adjusted_mode it should reject the modeset. See also
  144. * &drm_crtc_state.adjusted_mode for more details.
  145. *
  146. * This function is used by both legacy CRTC helpers and atomic helpers.
  147. * With atomic helpers it is optional.
  148. *
  149. * NOTE:
  150. *
  151. * This function is called in the check phase of atomic modesets, which
  152. * can be aborted for any reason (including on userspace's request to
  153. * just check whether a configuration would be possible). Atomic drivers
  154. * MUST NOT touch any persistent state (hardware or software) or data
  155. * structures except the passed in adjusted_mode parameter.
  156. *
  157. * This is in contrast to the legacy CRTC helpers where this was
  158. * allowed.
  159. *
  160. * Atomic drivers which need to inspect and adjust more state should
  161. * instead use the @atomic_check callback, but note that they're not
  162. * perfectly equivalent: @mode_valid is called from
  163. * drm_atomic_helper_check_modeset(), but @atomic_check is called from
  164. * drm_atomic_helper_check_planes(), because originally it was meant for
  165. * plane update checks only.
  166. *
  167. * Also beware that userspace can request its own custom modes, neither
  168. * core nor helpers filter modes to the list of probe modes reported by
  169. * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
  170. * that modes are filtered consistently put any CRTC constraints and
  171. * limits checks into @mode_valid.
  172. *
  173. * RETURNS:
  174. *
  175. * True if an acceptable configuration is possible, false if the modeset
  176. * operation should be rejected.
  177. */
  178. bool (*mode_fixup)(struct drm_crtc *crtc,
  179. const struct drm_display_mode *mode,
  180. struct drm_display_mode *adjusted_mode);
  181. /**
  182. * @mode_set:
  183. *
  184. * This callback is used by the legacy CRTC helpers to set a new mode,
  185. * position and framebuffer. Since it ties the primary plane to every
  186. * mode change it is incompatible with universal plane support. And
  187. * since it can't update other planes it's incompatible with atomic
  188. * modeset support.
  189. *
  190. * This callback is only used by CRTC helpers and deprecated.
  191. *
  192. * RETURNS:
  193. *
  194. * 0 on success or a negative error code on failure.
  195. */
  196. int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
  197. struct drm_display_mode *adjusted_mode, int x, int y,
  198. struct drm_framebuffer *old_fb);
  199. /**
  200. * @mode_set_nofb:
  201. *
  202. * This callback is used to update the display mode of a CRTC without
  203. * changing anything of the primary plane configuration. This fits the
  204. * requirement of atomic and hence is used by the atomic helpers.
  205. *
  206. * Note that the display pipe is completely off when this function is
  207. * called. Atomic drivers which need hardware to be running before they
  208. * program the new display mode (e.g. because they implement runtime PM)
  209. * should not use this hook. This is because the helper library calls
  210. * this hook only once per mode change and not every time the display
  211. * pipeline is suspended using either DPMS or the new "ACTIVE" property.
  212. * Which means register values set in this callback might get reset when
  213. * the CRTC is suspended, but not restored. Such drivers should instead
  214. * move all their CRTC setup into the @atomic_enable callback.
  215. *
  216. * This callback is optional.
  217. */
  218. void (*mode_set_nofb)(struct drm_crtc *crtc);
  219. /**
  220. * @mode_set_base:
  221. *
  222. * This callback is used by the legacy CRTC helpers to set a new
  223. * framebuffer and scanout position. It is optional and used as an
  224. * optimized fast-path instead of a full mode set operation with all the
  225. * resulting flickering. If it is not present
  226. * drm_crtc_helper_set_config() will fall back to a full modeset, using
  227. * the @mode_set callback. Since it can't update other planes it's
  228. * incompatible with atomic modeset support.
  229. *
  230. * This callback is only used by the CRTC helpers and deprecated.
  231. *
  232. * RETURNS:
  233. *
  234. * 0 on success or a negative error code on failure.
  235. */
  236. int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
  237. struct drm_framebuffer *old_fb);
  238. /**
  239. * @disable:
  240. *
  241. * This callback should be used to disable the CRTC. With the atomic
  242. * drivers it is called after all encoders connected to this CRTC have
  243. * been shut off already using their own
  244. * &drm_encoder_helper_funcs.disable hook. If that sequence is too
  245. * simple drivers can just add their own hooks and call it from this
  246. * CRTC callback here by looping over all encoders connected to it using
  247. * for_each_encoder_on_crtc().
  248. *
  249. * This hook is used both by legacy CRTC helpers and atomic helpers.
  250. * Atomic drivers don't need to implement it if there's no need to
  251. * disable anything at the CRTC level. To ensure that runtime PM
  252. * handling (using either DPMS or the new "ACTIVE" property) works
  253. * @disable must be the inverse of @atomic_enable for atomic drivers.
  254. * Atomic drivers should consider to use @atomic_disable instead of
  255. * this one.
  256. *
  257. * NOTE:
  258. *
  259. * With legacy CRTC helpers there's a big semantic difference between
  260. * @disable and other hooks (like @prepare or @dpms) used to shut down a
  261. * CRTC: @disable is only called when also logically disabling the
  262. * display pipeline and needs to release any resources acquired in
  263. * @mode_set (like shared PLLs, or again release pinned framebuffers).
  264. *
  265. * Therefore @disable must be the inverse of @mode_set plus @commit for
  266. * drivers still using legacy CRTC helpers, which is different from the
  267. * rules under atomic.
  268. */
  269. void (*disable)(struct drm_crtc *crtc);
  270. /**
  271. * @atomic_check:
  272. *
  273. * Drivers should check plane-update related CRTC constraints in this
  274. * hook. They can also check mode related limitations but need to be
  275. * aware of the calling order, since this hook is used by
  276. * drm_atomic_helper_check_planes() whereas the preparations needed to
  277. * check output routing and the display mode is done in
  278. * drm_atomic_helper_check_modeset(). Therefore drivers that want to
  279. * check output routing and display mode constraints in this callback
  280. * must ensure that drm_atomic_helper_check_modeset() has been called
  281. * beforehand. This is calling order used by the default helper
  282. * implementation in drm_atomic_helper_check().
  283. *
  284. * When using drm_atomic_helper_check_planes() this hook is called
  285. * after the &drm_plane_helper_funcs.atomic_check hook for planes, which
  286. * allows drivers to assign shared resources requested by planes in this
  287. * callback here. For more complicated dependencies the driver can call
  288. * the provided check helpers multiple times until the computed state
  289. * has a final configuration and everything has been checked.
  290. *
  291. * This function is also allowed to inspect any other object's state and
  292. * can add more state objects to the atomic commit if needed. Care must
  293. * be taken though to ensure that state check and compute functions for
  294. * these added states are all called, and derived state in other objects
  295. * all updated. Again the recommendation is to just call check helpers
  296. * until a maximal configuration is reached.
  297. *
  298. * This callback is used by the atomic modeset helpers, but it is
  299. * optional.
  300. *
  301. * NOTE:
  302. *
  303. * This function is called in the check phase of an atomic update. The
  304. * driver is not allowed to change anything outside of the free-standing
  305. * state object passed-in.
  306. *
  307. * Also beware that userspace can request its own custom modes, neither
  308. * core nor helpers filter modes to the list of probe modes reported by
  309. * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
  310. * that modes are filtered consistently put any CRTC constraints and
  311. * limits checks into @mode_valid.
  312. *
  313. * RETURNS:
  314. *
  315. * 0 on success, -EINVAL if the state or the transition can't be
  316. * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
  317. * attempt to obtain another state object ran into a &drm_modeset_lock
  318. * deadlock.
  319. */
  320. int (*atomic_check)(struct drm_crtc *crtc,
  321. struct drm_atomic_state *state);
  322. /**
  323. * @atomic_begin:
  324. *
  325. * Drivers should prepare for an atomic update of multiple planes on
  326. * a CRTC in this hook. Depending upon hardware this might be vblank
  327. * evasion, blocking updates by setting bits or doing preparatory work
  328. * for e.g. manual update display.
  329. *
  330. * This hook is called before any plane commit functions are called.
  331. *
  332. * Note that the power state of the display pipe when this function is
  333. * called depends upon the exact helpers and calling sequence the driver
  334. * has picked. See drm_atomic_helper_commit_planes() for a discussion of
  335. * the tradeoffs and variants of plane commit helpers.
  336. *
  337. * This callback is used by the atomic modeset helpers, but it is
  338. * optional.
  339. */
  340. void (*atomic_begin)(struct drm_crtc *crtc,
  341. struct drm_atomic_state *state);
  342. /**
  343. * @atomic_flush:
  344. *
  345. * Drivers should finalize an atomic update of multiple planes on
  346. * a CRTC in this hook. Depending upon hardware this might include
  347. * checking that vblank evasion was successful, unblocking updates by
  348. * setting bits or setting the GO bit to flush out all updates.
  349. *
  350. * Simple hardware or hardware with special requirements can commit and
  351. * flush out all updates for all planes from this hook and forgo all the
  352. * other commit hooks for plane updates.
  353. *
  354. * This hook is called after any plane commit functions are called.
  355. *
  356. * Note that the power state of the display pipe when this function is
  357. * called depends upon the exact helpers and calling sequence the driver
  358. * has picked. See drm_atomic_helper_commit_planes() for a discussion of
  359. * the tradeoffs and variants of plane commit helpers.
  360. *
  361. * This callback is used by the atomic modeset helpers, but it is
  362. * optional.
  363. */
  364. void (*atomic_flush)(struct drm_crtc *crtc,
  365. struct drm_atomic_state *state);
  366. /**
  367. * @atomic_enable:
  368. *
  369. * This callback should be used to enable the CRTC. With the atomic
  370. * drivers it is called before all encoders connected to this CRTC are
  371. * enabled through the encoder's own &drm_encoder_helper_funcs.enable
  372. * hook. If that sequence is too simple drivers can just add their own
  373. * hooks and call it from this CRTC callback here by looping over all
  374. * encoders connected to it using for_each_encoder_on_crtc().
  375. *
  376. * This hook is used only by atomic helpers, for symmetry with
  377. * @atomic_disable. Atomic drivers don't need to implement it if there's
  378. * no need to enable anything at the CRTC level. To ensure that runtime
  379. * PM handling (using either DPMS or the new "ACTIVE" property) works
  380. * @atomic_enable must be the inverse of @atomic_disable for atomic
  381. * drivers.
  382. *
  383. * This function is optional.
  384. */
  385. void (*atomic_enable)(struct drm_crtc *crtc,
  386. struct drm_atomic_state *state);
  387. /**
  388. * @atomic_disable:
  389. *
  390. * This callback should be used to disable the CRTC. With the atomic
  391. * drivers it is called after all encoders connected to this CRTC have
  392. * been shut off already using their own
  393. * &drm_encoder_helper_funcs.disable hook. If that sequence is too
  394. * simple drivers can just add their own hooks and call it from this
  395. * CRTC callback here by looping over all encoders connected to it using
  396. * for_each_encoder_on_crtc().
  397. *
  398. * This hook is used only by atomic helpers. Atomic drivers don't
  399. * need to implement it if there's no need to disable anything at the
  400. * CRTC level.
  401. *
  402. * This function is optional.
  403. */
  404. void (*atomic_disable)(struct drm_crtc *crtc,
  405. struct drm_atomic_state *state);
  406. /**
  407. * @get_scanout_position:
  408. *
  409. * Called by vblank timestamping code.
  410. *
  411. * Returns the current display scanout position from a CRTC and an
  412. * optional accurate ktime_get() timestamp of when the position was
  413. * measured. Note that this is a helper callback which is only used
  414. * if a driver uses drm_crtc_vblank_helper_get_vblank_timestamp()
  415. * for the @drm_crtc_funcs.get_vblank_timestamp callback.
  416. *
  417. * Parameters:
  418. *
  419. * crtc:
  420. * The CRTC.
  421. * in_vblank_irq:
  422. * True when called from drm_crtc_handle_vblank(). Some drivers
  423. * need to apply some workarounds for gpu-specific vblank irq
  424. * quirks if the flag is set.
  425. * vpos:
  426. * Target location for current vertical scanout position.
  427. * hpos:
  428. * Target location for current horizontal scanout position.
  429. * stime:
  430. * Target location for timestamp taken immediately before
  431. * scanout position query. Can be NULL to skip timestamp.
  432. * etime:
  433. * Target location for timestamp taken immediately after
  434. * scanout position query. Can be NULL to skip timestamp.
  435. * mode:
  436. * Current display timings.
  437. *
  438. * Returns vpos as a positive number while in active scanout area.
  439. * Returns vpos as a negative number inside vblank, counting the number
  440. * of scanlines to go until end of vblank, e.g., -1 means "one scanline
  441. * until start of active scanout / end of vblank."
  442. *
  443. * Returns:
  444. *
  445. * True on success, false if a reliable scanout position counter could
  446. * not be read out.
  447. */
  448. bool (*get_scanout_position)(struct drm_crtc *crtc,
  449. bool in_vblank_irq, int *vpos, int *hpos,
  450. ktime_t *stime, ktime_t *etime,
  451. const struct drm_display_mode *mode);
  452. /**
  453. * @handle_vblank_timeout: Handles timeouts of the vblank timer.
  454. *
  455. * Called by CRTC's the vblank timer on each timeout. Semantics is
  456. * equivalient to drm_crtc_handle_vblank(). Implementations should
  457. * invoke drm_crtc_handle_vblank() as part of processing the timeout.
  458. *
  459. * This callback is optional. If unset, the vblank timer invokes
  460. * drm_crtc_handle_vblank() directly.
  461. */
  462. bool (*handle_vblank_timeout)(struct drm_crtc *crtc);
  463. };
  464. /**
  465. * drm_crtc_helper_add - sets the helper vtable for a crtc
  466. * @crtc: DRM CRTC
  467. * @funcs: helper vtable to set for @crtc
  468. */
  469. static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
  470. const struct drm_crtc_helper_funcs *funcs)
  471. {
  472. crtc->helper_private = funcs;
  473. }
  474. /**
  475. * struct drm_encoder_helper_funcs - helper operations for encoders
  476. *
  477. * These hooks are used by the legacy CRTC helpers and the new atomic
  478. * modesetting helpers.
  479. */
  480. struct drm_encoder_helper_funcs {
  481. /**
  482. * @dpms:
  483. *
  484. * Callback to control power levels on the encoder. If the mode passed in
  485. * is unsupported, the provider must use the next lowest power level.
  486. * This is used by the legacy encoder helpers to implement DPMS
  487. * functionality in drm_helper_connector_dpms().
  488. *
  489. * This callback is also used to disable an encoder by calling it with
  490. * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
  491. *
  492. * This callback is used by the legacy CRTC helpers. Atomic helpers
  493. * also support using this hook for enabling and disabling an encoder to
  494. * facilitate transitions to atomic, but it is deprecated. Instead
  495. * @enable and @disable should be used.
  496. */
  497. void (*dpms)(struct drm_encoder *encoder, int mode);
  498. /**
  499. * @mode_valid:
  500. *
  501. * This callback is used to check if a specific mode is valid in this
  502. * encoder. This should be implemented if the encoder has some sort
  503. * of restriction in the modes it can display. For example, a given
  504. * encoder may be responsible to set a clock value. If the clock can
  505. * not produce all the values for the available modes then this callback
  506. * can be used to restrict the number of modes to only the ones that
  507. * can be displayed.
  508. *
  509. * This hook is used by the probe helpers to filter the mode list in
  510. * drm_helper_probe_single_connector_modes(), and it is used by the
  511. * atomic helpers to validate modes supplied by userspace in
  512. * drm_atomic_helper_check_modeset().
  513. *
  514. * This function is optional.
  515. *
  516. * NOTE:
  517. *
  518. * Since this function is both called from the check phase of an atomic
  519. * commit, and the mode validation in the probe paths it is not allowed
  520. * to look at anything else but the passed-in mode, and validate it
  521. * against configuration-invariant hardware constraints. Any further
  522. * limits which depend upon the configuration can only be checked in
  523. * @mode_fixup or @atomic_check.
  524. *
  525. * RETURNS:
  526. *
  527. * drm_mode_status Enum
  528. */
  529. enum drm_mode_status (*mode_valid)(struct drm_encoder *crtc,
  530. const struct drm_display_mode *mode);
  531. /**
  532. * @mode_fixup:
  533. *
  534. * This callback is used to validate and adjust a mode. The parameter
  535. * mode is the display mode that should be fed to the next element in
  536. * the display chain, either the final &drm_connector or a &drm_bridge.
  537. * The parameter adjusted_mode is the input mode the encoder requires. It
  538. * can be modified by this callback and does not need to match mode. See
  539. * also &drm_crtc_state.adjusted_mode for more details.
  540. *
  541. * This function is used by both legacy CRTC helpers and atomic helpers.
  542. * This hook is optional.
  543. *
  544. * NOTE:
  545. *
  546. * This function is called in the check phase of atomic modesets, which
  547. * can be aborted for any reason (including on userspace's request to
  548. * just check whether a configuration would be possible). Atomic drivers
  549. * MUST NOT touch any persistent state (hardware or software) or data
  550. * structures except the passed in adjusted_mode parameter.
  551. *
  552. * This is in contrast to the legacy CRTC helpers where this was
  553. * allowed.
  554. *
  555. * Atomic drivers which need to inspect and adjust more state should
  556. * instead use the @atomic_check callback. If @atomic_check is used,
  557. * this hook isn't called since @atomic_check allows a strict superset
  558. * of the functionality of @mode_fixup.
  559. *
  560. * Also beware that userspace can request its own custom modes, neither
  561. * core nor helpers filter modes to the list of probe modes reported by
  562. * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
  563. * that modes are filtered consistently put any encoder constraints and
  564. * limits checks into @mode_valid.
  565. *
  566. * RETURNS:
  567. *
  568. * True if an acceptable configuration is possible, false if the modeset
  569. * operation should be rejected.
  570. */
  571. bool (*mode_fixup)(struct drm_encoder *encoder,
  572. const struct drm_display_mode *mode,
  573. struct drm_display_mode *adjusted_mode);
  574. /**
  575. * @prepare:
  576. *
  577. * This callback should prepare the encoder for a subsequent modeset,
  578. * which in practice means the driver should disable the encoder if it
  579. * is running. Most drivers ended up implementing this by calling their
  580. * @dpms hook with DRM_MODE_DPMS_OFF.
  581. *
  582. * This callback is used by the legacy CRTC helpers. Atomic helpers
  583. * also support using this hook for disabling an encoder to facilitate
  584. * transitions to atomic, but it is deprecated. Instead @disable should
  585. * be used.
  586. */
  587. void (*prepare)(struct drm_encoder *encoder);
  588. /**
  589. * @commit:
  590. *
  591. * This callback should commit the new mode on the encoder after a modeset,
  592. * which in practice means the driver should enable the encoder. Most
  593. * drivers ended up implementing this by calling their @dpms hook with
  594. * DRM_MODE_DPMS_ON.
  595. *
  596. * This callback is used by the legacy CRTC helpers. Atomic helpers
  597. * also support using this hook for enabling an encoder to facilitate
  598. * transitions to atomic, but it is deprecated. Instead @enable should
  599. * be used.
  600. */
  601. void (*commit)(struct drm_encoder *encoder);
  602. /**
  603. * @mode_set:
  604. *
  605. * This callback is used to update the display mode of an encoder.
  606. *
  607. * Note that the display pipe is completely off when this function is
  608. * called. Drivers which need hardware to be running before they program
  609. * the new display mode (because they implement runtime PM) should not
  610. * use this hook, because the helper library calls it only once and not
  611. * every time the display pipeline is suspend using either DPMS or the
  612. * new "ACTIVE" property. Such drivers should instead move all their
  613. * encoder setup into the @enable callback.
  614. *
  615. * This callback is used both by the legacy CRTC helpers and the atomic
  616. * modeset helpers. It is optional in the atomic helpers.
  617. *
  618. * NOTE:
  619. *
  620. * If the driver uses the atomic modeset helpers and needs to inspect
  621. * the connector state or connector display info during mode setting,
  622. * @atomic_mode_set can be used instead.
  623. */
  624. void (*mode_set)(struct drm_encoder *encoder,
  625. struct drm_display_mode *mode,
  626. struct drm_display_mode *adjusted_mode);
  627. /**
  628. * @atomic_mode_set:
  629. *
  630. * This callback is used to update the display mode of an encoder.
  631. *
  632. * Note that the display pipe is completely off when this function is
  633. * called. Drivers which need hardware to be running before they program
  634. * the new display mode (because they implement runtime PM) should not
  635. * use this hook, because the helper library calls it only once and not
  636. * every time the display pipeline is suspended using either DPMS or the
  637. * new "ACTIVE" property. Such drivers should instead move all their
  638. * encoder setup into the @enable callback.
  639. *
  640. * This callback is used by the atomic modeset helpers in place of the
  641. * @mode_set callback, if set by the driver. It is optional and should
  642. * be used instead of @mode_set if the driver needs to inspect the
  643. * connector state or display info, since there is no direct way to
  644. * go from the encoder to the current connector.
  645. */
  646. void (*atomic_mode_set)(struct drm_encoder *encoder,
  647. struct drm_crtc_state *crtc_state,
  648. struct drm_connector_state *conn_state);
  649. /**
  650. * @detect:
  651. *
  652. * This callback can be used by drivers who want to do detection on the
  653. * encoder object instead of in connector functions.
  654. *
  655. * It is not used by any helper and therefore has purely driver-specific
  656. * semantics. New drivers shouldn't use this and instead just implement
  657. * their own private callbacks.
  658. *
  659. * FIXME:
  660. *
  661. * This should just be converted into a pile of driver vfuncs.
  662. * Currently radeon, amdgpu and nouveau are using it.
  663. */
  664. enum drm_connector_status (*detect)(struct drm_encoder *encoder,
  665. struct drm_connector *connector);
  666. /**
  667. * @atomic_disable:
  668. *
  669. * This callback should be used to disable the encoder. With the atomic
  670. * drivers it is called before this encoder's CRTC has been shut off
  671. * using their own &drm_crtc_helper_funcs.atomic_disable hook. If that
  672. * sequence is too simple drivers can just add their own driver private
  673. * encoder hooks and call them from CRTC's callback by looping over all
  674. * encoders connected to it using for_each_encoder_on_crtc().
  675. *
  676. * This callback is a variant of @disable that provides the atomic state
  677. * to the driver. If @atomic_disable is implemented, @disable is not
  678. * called by the helpers.
  679. *
  680. * This hook is only used by atomic helpers. Atomic drivers don't need
  681. * to implement it if there's no need to disable anything at the encoder
  682. * level. To ensure that runtime PM handling (using either DPMS or the
  683. * new "ACTIVE" property) works @atomic_disable must be the inverse of
  684. * @atomic_enable.
  685. */
  686. void (*atomic_disable)(struct drm_encoder *encoder,
  687. struct drm_atomic_state *state);
  688. /**
  689. * @atomic_enable:
  690. *
  691. * This callback should be used to enable the encoder. It is called
  692. * after this encoder's CRTC has been enabled using their own
  693. * &drm_crtc_helper_funcs.atomic_enable hook. If that sequence is
  694. * too simple drivers can just add their own driver private encoder
  695. * hooks and call them from CRTC's callback by looping over all encoders
  696. * connected to it using for_each_encoder_on_crtc().
  697. *
  698. * This callback is a variant of @enable that provides the atomic state
  699. * to the driver. If @atomic_enable is implemented, @enable is not
  700. * called by the helpers.
  701. *
  702. * This hook is only used by atomic helpers, it is the opposite of
  703. * @atomic_disable. Atomic drivers don't need to implement it if there's
  704. * no need to enable anything at the encoder level. To ensure that
  705. * runtime PM handling works @atomic_enable must be the inverse of
  706. * @atomic_disable.
  707. */
  708. void (*atomic_enable)(struct drm_encoder *encoder,
  709. struct drm_atomic_state *state);
  710. /**
  711. * @disable:
  712. *
  713. * This callback should be used to disable the encoder. With the atomic
  714. * drivers it is called before this encoder's CRTC has been shut off
  715. * using their own &drm_crtc_helper_funcs.disable hook. If that
  716. * sequence is too simple drivers can just add their own driver private
  717. * encoder hooks and call them from CRTC's callback by looping over all
  718. * encoders connected to it using for_each_encoder_on_crtc().
  719. *
  720. * This hook is used both by legacy CRTC helpers and atomic helpers.
  721. * Atomic drivers don't need to implement it if there's no need to
  722. * disable anything at the encoder level. To ensure that runtime PM
  723. * handling (using either DPMS or the new "ACTIVE" property) works
  724. * @disable must be the inverse of @enable for atomic drivers.
  725. *
  726. * For atomic drivers also consider @atomic_disable and save yourself
  727. * from having to read the NOTE below!
  728. *
  729. * NOTE:
  730. *
  731. * With legacy CRTC helpers there's a big semantic difference between
  732. * @disable and other hooks (like @prepare or @dpms) used to shut down a
  733. * encoder: @disable is only called when also logically disabling the
  734. * display pipeline and needs to release any resources acquired in
  735. * @mode_set (like shared PLLs, or again release pinned framebuffers).
  736. *
  737. * Therefore @disable must be the inverse of @mode_set plus @commit for
  738. * drivers still using legacy CRTC helpers, which is different from the
  739. * rules under atomic.
  740. */
  741. void (*disable)(struct drm_encoder *encoder);
  742. /**
  743. * @enable:
  744. *
  745. * This callback should be used to enable the encoder. With the atomic
  746. * drivers it is called after this encoder's CRTC has been enabled using
  747. * their own &drm_crtc_helper_funcs.enable hook. If that sequence is
  748. * too simple drivers can just add their own driver private encoder
  749. * hooks and call them from CRTC's callback by looping over all encoders
  750. * connected to it using for_each_encoder_on_crtc().
  751. *
  752. * This hook is only used by atomic helpers, it is the opposite of
  753. * @disable. Atomic drivers don't need to implement it if there's no
  754. * need to enable anything at the encoder level. To ensure that
  755. * runtime PM handling (using either DPMS or the new "ACTIVE" property)
  756. * works @enable must be the inverse of @disable for atomic drivers.
  757. */
  758. void (*enable)(struct drm_encoder *encoder);
  759. /**
  760. * @atomic_check:
  761. *
  762. * This callback is used to validate encoder state for atomic drivers.
  763. * Since the encoder is the object connecting the CRTC and connector it
  764. * gets passed both states, to be able to validate interactions and
  765. * update the CRTC to match what the encoder needs for the requested
  766. * connector.
  767. *
  768. * Since this provides a strict superset of the functionality of
  769. * @mode_fixup (the requested and adjusted modes are both available
  770. * through the passed in &struct drm_crtc_state) @mode_fixup is not
  771. * called when @atomic_check is implemented.
  772. *
  773. * This function is used by the atomic helpers, but it is optional.
  774. *
  775. * NOTE:
  776. *
  777. * This function is called in the check phase of an atomic update. The
  778. * driver is not allowed to change anything outside of the free-standing
  779. * state objects passed-in or assembled in the overall &drm_atomic_state
  780. * update tracking structure.
  781. *
  782. * Also beware that userspace can request its own custom modes, neither
  783. * core nor helpers filter modes to the list of probe modes reported by
  784. * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
  785. * that modes are filtered consistently put any encoder constraints and
  786. * limits checks into @mode_valid.
  787. *
  788. * RETURNS:
  789. *
  790. * 0 on success, -EINVAL if the state or the transition can't be
  791. * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
  792. * attempt to obtain another state object ran into a &drm_modeset_lock
  793. * deadlock.
  794. */
  795. int (*atomic_check)(struct drm_encoder *encoder,
  796. struct drm_crtc_state *crtc_state,
  797. struct drm_connector_state *conn_state);
  798. };
  799. /**
  800. * drm_encoder_helper_add - sets the helper vtable for an encoder
  801. * @encoder: DRM encoder
  802. * @funcs: helper vtable to set for @encoder
  803. */
  804. static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
  805. const struct drm_encoder_helper_funcs *funcs)
  806. {
  807. encoder->helper_private = funcs;
  808. }
  809. /**
  810. * struct drm_connector_helper_funcs - helper operations for connectors
  811. *
  812. * These functions are used by the atomic and legacy modeset helpers and by the
  813. * probe helpers.
  814. */
  815. struct drm_connector_helper_funcs {
  816. /**
  817. * @get_modes:
  818. *
  819. * This function should fill in all modes currently valid for the sink
  820. * into the &drm_connector.probed_modes list. It should also update the
  821. * EDID property by calling drm_connector_update_edid_property().
  822. *
  823. * The usual way to implement this is to cache the EDID retrieved in the
  824. * probe callback somewhere in the driver-private connector structure.
  825. * In this function drivers then parse the modes in the EDID and add
  826. * them by calling drm_add_edid_modes(). But connectors that drive a
  827. * fixed panel can also manually add specific modes using
  828. * drm_mode_probed_add(). Drivers which manually add modes should also
  829. * make sure that the &drm_connector.display_info,
  830. * &drm_connector.width_mm and &drm_connector.height_mm fields are
  831. * filled in.
  832. *
  833. * Note that the caller function will automatically add standard VESA
  834. * DMT modes up to 1024x768 if the .get_modes() helper operation returns
  835. * no mode and if the connector status is connector_status_connected or
  836. * connector_status_unknown. There is no need to call
  837. * drm_add_modes_noedid() manually in that case.
  838. *
  839. * Virtual drivers that just want some standard VESA mode with a given
  840. * resolution can call drm_add_modes_noedid(), and mark the preferred
  841. * one using drm_set_preferred_mode().
  842. *
  843. * This function is only called after the @detect hook has indicated
  844. * that a sink is connected and when the EDID isn't overridden through
  845. * sysfs or the kernel commandline.
  846. *
  847. * This callback is used by the probe helpers in e.g.
  848. * drm_helper_probe_single_connector_modes().
  849. *
  850. * To avoid races with concurrent connector state updates, the helper
  851. * libraries always call this with the &drm_mode_config.connection_mutex
  852. * held. Because of this it's safe to inspect &drm_connector->state.
  853. *
  854. * RETURNS:
  855. *
  856. * The number of modes added by calling drm_mode_probed_add(). Return 0
  857. * on failures (no modes) instead of negative error codes.
  858. */
  859. int (*get_modes)(struct drm_connector *connector);
  860. /**
  861. * @detect_ctx:
  862. *
  863. * Check to see if anything is attached to the connector. The parameter
  864. * force is set to false whilst polling, true when checking the
  865. * connector due to a user request. force can be used by the driver to
  866. * avoid expensive, destructive operations during automated probing.
  867. *
  868. * This callback is optional, if not implemented the connector will be
  869. * considered as always being attached.
  870. *
  871. * This is the atomic version of &drm_connector_funcs.detect.
  872. *
  873. * To avoid races against concurrent connector state updates, the
  874. * helper libraries always call this with ctx set to a valid context,
  875. * and &drm_mode_config.connection_mutex will always be locked with
  876. * the ctx parameter set to this ctx. This allows taking additional
  877. * locks as required.
  878. *
  879. * RETURNS:
  880. *
  881. * &drm_connector_status indicating the connector's status,
  882. * or the error code returned by drm_modeset_lock(), -EDEADLK.
  883. */
  884. int (*detect_ctx)(struct drm_connector *connector,
  885. struct drm_modeset_acquire_ctx *ctx,
  886. bool force);
  887. /**
  888. * @mode_valid:
  889. *
  890. * Callback to validate a mode for a connector, irrespective of the
  891. * specific display configuration.
  892. *
  893. * This callback is used by the probe helpers to filter the mode list
  894. * (which is usually derived from the EDID data block from the sink).
  895. * See e.g. drm_helper_probe_single_connector_modes().
  896. *
  897. * This function is optional.
  898. *
  899. * NOTE:
  900. *
  901. * This only filters the mode list supplied to userspace in the
  902. * GETCONNECTOR IOCTL. Compared to &drm_encoder_helper_funcs.mode_valid,
  903. * &drm_crtc_helper_funcs.mode_valid and &drm_bridge_funcs.mode_valid,
  904. * which are also called by the atomic helpers from
  905. * drm_atomic_helper_check_modeset(). This allows userspace to force and
  906. * ignore sink constraint (like the pixel clock limits in the screen's
  907. * EDID), which is useful for e.g. testing, or working around a broken
  908. * EDID. Any source hardware constraint (which always need to be
  909. * enforced) therefore should be checked in one of the above callbacks,
  910. * and not this one here.
  911. *
  912. * To avoid races with concurrent connector state updates, the helper
  913. * libraries always call this with the &drm_mode_config.connection_mutex
  914. * held. Because of this it's safe to inspect &drm_connector->state.
  915. *
  916. * RETURNS:
  917. *
  918. * Either &drm_mode_status.MODE_OK or one of the failure reasons in &enum
  919. * drm_mode_status.
  920. */
  921. enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
  922. const struct drm_display_mode *mode);
  923. /**
  924. * @mode_valid_ctx:
  925. *
  926. * Callback to validate a mode for a connector, irrespective of the
  927. * specific display configuration.
  928. *
  929. * This callback is used by the probe helpers to filter the mode list
  930. * (which is usually derived from the EDID data block from the sink).
  931. * See e.g. drm_helper_probe_single_connector_modes().
  932. *
  933. * This function is optional, and is the atomic version of
  934. * &drm_connector_helper_funcs.mode_valid.
  935. *
  936. * To allow for accessing the atomic state of modesetting objects, the
  937. * helper libraries always call this with ctx set to a valid context,
  938. * and &drm_mode_config.connection_mutex will always be locked with
  939. * the ctx parameter set to @ctx. This allows for taking additional
  940. * locks as required.
  941. *
  942. * Even though additional locks may be acquired, this callback is
  943. * still expected not to take any constraints into account which would
  944. * be influenced by the currently set display state - such constraints
  945. * should be handled in the driver's atomic check. For example, if a
  946. * connector shares display bandwidth with other connectors then it
  947. * would be ok to validate the minimum bandwidth requirement of a mode
  948. * against the maximum possible bandwidth of the connector. But it
  949. * wouldn't be ok to take the current bandwidth usage of other
  950. * connectors into account, as this would change depending on the
  951. * display state.
  952. *
  953. * Returns:
  954. * 0 if &drm_connector_helper_funcs.mode_valid_ctx succeeded and wrote
  955. * the &enum drm_mode_status value to @status, or a negative error
  956. * code otherwise.
  957. *
  958. */
  959. int (*mode_valid_ctx)(struct drm_connector *connector,
  960. const struct drm_display_mode *mode,
  961. struct drm_modeset_acquire_ctx *ctx,
  962. enum drm_mode_status *status);
  963. /**
  964. * @best_encoder:
  965. *
  966. * This function should select the best encoder for the given connector.
  967. *
  968. * This function is used by both the atomic helpers (in the
  969. * drm_atomic_helper_check_modeset() function) and in the legacy CRTC
  970. * helpers.
  971. *
  972. * NOTE:
  973. *
  974. * In atomic drivers this function is called in the check phase of an
  975. * atomic update. The driver is not allowed to change or inspect
  976. * anything outside of arguments passed-in. Atomic drivers which need to
  977. * inspect dynamic configuration state should instead use
  978. * @atomic_best_encoder.
  979. *
  980. * You can leave this function to NULL if the connector is only
  981. * attached to a single encoder. In this case, the core will call
  982. * drm_connector_get_single_encoder() for you.
  983. *
  984. * RETURNS:
  985. *
  986. * Encoder that should be used for the given connector and connector
  987. * state, or NULL if no suitable encoder exists. Note that the helpers
  988. * will ensure that encoders aren't used twice, drivers should not check
  989. * for this.
  990. */
  991. struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
  992. /**
  993. * @atomic_best_encoder:
  994. *
  995. * This is the atomic version of @best_encoder for atomic drivers which
  996. * need to select the best encoder depending upon the desired
  997. * configuration and can't select it statically.
  998. *
  999. * This function is used by drm_atomic_helper_check_modeset().
  1000. * If it is not implemented, the core will fallback to @best_encoder
  1001. * (or drm_connector_get_single_encoder() if @best_encoder is NULL).
  1002. *
  1003. * NOTE:
  1004. *
  1005. * This function is called in the check phase of an atomic update. The
  1006. * driver is not allowed to change anything outside of the
  1007. * &drm_atomic_state update tracking structure passed in.
  1008. *
  1009. * RETURNS:
  1010. *
  1011. * Encoder that should be used for the given connector and connector
  1012. * state, or NULL if no suitable encoder exists. Note that the helpers
  1013. * will ensure that encoders aren't used twice, drivers should not check
  1014. * for this.
  1015. */
  1016. struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,
  1017. struct drm_atomic_state *state);
  1018. /**
  1019. * @atomic_check:
  1020. *
  1021. * This hook is used to validate connector state. This function is
  1022. * called from &drm_atomic_helper_check_modeset, and is called when
  1023. * a connector property is set, or a modeset on the crtc is forced.
  1024. *
  1025. * Because &drm_atomic_helper_check_modeset may be called multiple times,
  1026. * this function should handle being called multiple times as well.
  1027. *
  1028. * This function is also allowed to inspect any other object's state and
  1029. * can add more state objects to the atomic commit if needed. Care must
  1030. * be taken though to ensure that state check and compute functions for
  1031. * these added states are all called, and derived state in other objects
  1032. * all updated. Again the recommendation is to just call check helpers
  1033. * until a maximal configuration is reached.
  1034. *
  1035. * NOTE:
  1036. *
  1037. * This function is called in the check phase of an atomic update. The
  1038. * driver is not allowed to change anything outside of the free-standing
  1039. * state objects passed-in or assembled in the overall &drm_atomic_state
  1040. * update tracking structure.
  1041. *
  1042. * RETURNS:
  1043. *
  1044. * 0 on success, -EINVAL if the state or the transition can't be
  1045. * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
  1046. * attempt to obtain another state object ran into a &drm_modeset_lock
  1047. * deadlock.
  1048. */
  1049. int (*atomic_check)(struct drm_connector *connector,
  1050. struct drm_atomic_state *state);
  1051. /**
  1052. * @atomic_commit:
  1053. *
  1054. * This hook is to be used by drivers implementing writeback connectors
  1055. * that need a point when to commit the writeback job to the hardware.
  1056. * The writeback_job to commit is available in the new connector state,
  1057. * in &drm_connector_state.writeback_job.
  1058. *
  1059. * This hook is optional.
  1060. *
  1061. * This callback is used by the atomic modeset helpers.
  1062. */
  1063. void (*atomic_commit)(struct drm_connector *connector,
  1064. struct drm_atomic_state *state);
  1065. /**
  1066. * @prepare_writeback_job:
  1067. *
  1068. * As writeback jobs contain a framebuffer, drivers may need to
  1069. * prepare and clean them up the same way they can prepare and
  1070. * clean up framebuffers for planes. This optional connector operation
  1071. * is used to support the preparation of writeback jobs. The job
  1072. * prepare operation is called from drm_atomic_helper_prepare_planes()
  1073. * for struct &drm_writeback_connector connectors only.
  1074. *
  1075. * This operation is optional.
  1076. *
  1077. * This callback is used by the atomic modeset helpers.
  1078. */
  1079. int (*prepare_writeback_job)(struct drm_writeback_connector *connector,
  1080. struct drm_writeback_job *job);
  1081. /**
  1082. * @cleanup_writeback_job:
  1083. *
  1084. * This optional connector operation is used to support the
  1085. * cleanup of writeback jobs. The job cleanup operation is called
  1086. * from the existing drm_writeback_cleanup_job() function, invoked
  1087. * both when destroying the job as part of an aborted commit, or when
  1088. * the job completes.
  1089. *
  1090. * This operation is optional.
  1091. *
  1092. * This callback is used by the atomic modeset helpers.
  1093. */
  1094. void (*cleanup_writeback_job)(struct drm_writeback_connector *connector,
  1095. struct drm_writeback_job *job);
  1096. /**
  1097. * @enable_hpd:
  1098. *
  1099. * Enable hot-plug detection for the connector.
  1100. *
  1101. * This operation is optional.
  1102. *
  1103. * This callback is used by the drm_kms_helper_poll_enable() helpers.
  1104. *
  1105. * This operation does not need to perform any hpd state tracking as
  1106. * the DRM core handles that maintenance and ensures the calls to enable
  1107. * and disable hpd are balanced.
  1108. *
  1109. */
  1110. void (*enable_hpd)(struct drm_connector *connector);
  1111. /**
  1112. * @disable_hpd:
  1113. *
  1114. * Disable hot-plug detection for the connector.
  1115. *
  1116. * This operation is optional.
  1117. *
  1118. * This callback is used by the drm_kms_helper_poll_disable() helpers.
  1119. *
  1120. * This operation does not need to perform any hpd state tracking as
  1121. * the DRM core handles that maintenance and ensures the calls to enable
  1122. * and disable hpd are balanced.
  1123. *
  1124. */
  1125. void (*disable_hpd)(struct drm_connector *connector);
  1126. };
  1127. /**
  1128. * drm_connector_helper_add - sets the helper vtable for a connector
  1129. * @connector: DRM connector
  1130. * @funcs: helper vtable to set for @connector
  1131. */
  1132. static inline void drm_connector_helper_add(struct drm_connector *connector,
  1133. const struct drm_connector_helper_funcs *funcs)
  1134. {
  1135. connector->helper_private = funcs;
  1136. }
  1137. /**
  1138. * struct drm_plane_helper_funcs - helper operations for planes
  1139. *
  1140. * These functions are used by the atomic helpers.
  1141. */
  1142. struct drm_plane_helper_funcs {
  1143. /**
  1144. * @prepare_fb:
  1145. *
  1146. * This hook is to prepare a framebuffer for scanout by e.g. pinning
  1147. * its backing storage or relocating it into a contiguous block of
  1148. * VRAM. Other possible preparatory work includes flushing caches.
  1149. *
  1150. * This function must not block for outstanding rendering, since it is
  1151. * called in the context of the atomic IOCTL even for async commits to
  1152. * be able to return any errors to userspace. Instead the recommended
  1153. * way is to fill out the &drm_plane_state.fence of the passed-in
  1154. * &drm_plane_state. If the driver doesn't support native fences then
  1155. * equivalent functionality should be implemented through private
  1156. * members in the plane structure.
  1157. *
  1158. * For GEM drivers who neither have a @prepare_fb nor @cleanup_fb hook
  1159. * set drm_gem_plane_helper_prepare_fb() is called automatically to
  1160. * implement this. Other drivers which need additional plane processing
  1161. * can call drm_gem_plane_helper_prepare_fb() from their @prepare_fb
  1162. * hook.
  1163. *
  1164. * The resources acquired in @prepare_fb persist after the end of
  1165. * the atomic commit. Resources that can be release at the commit's end
  1166. * should be acquired in @begin_fb_access and released in @end_fb_access.
  1167. * For example, a GEM buffer's pin operation belongs into @prepare_fb to
  1168. * keep the buffer pinned after the commit. But a vmap operation for
  1169. * shadow-plane helpers belongs into @begin_fb_access, so that atomic
  1170. * helpers remove the mapping at the end of the commit.
  1171. *
  1172. * The helpers will call @cleanup_fb with matching arguments for every
  1173. * successful call to this hook.
  1174. *
  1175. * This callback is used by the atomic modeset helpers, but it is
  1176. * optional. See @begin_fb_access for preparing per-commit resources.
  1177. *
  1178. * RETURNS:
  1179. *
  1180. * 0 on success or one of the following negative error codes allowed by
  1181. * the &drm_mode_config_funcs.atomic_commit vfunc. When using helpers
  1182. * this callback is the only one which can fail an atomic commit,
  1183. * everything else must complete successfully.
  1184. */
  1185. int (*prepare_fb)(struct drm_plane *plane,
  1186. struct drm_plane_state *new_state);
  1187. /**
  1188. * @cleanup_fb:
  1189. *
  1190. * This hook is called to clean up any resources allocated for the given
  1191. * framebuffer and plane configuration in @prepare_fb.
  1192. *
  1193. * This callback is used by the atomic modeset helpers, but it is
  1194. * optional.
  1195. */
  1196. void (*cleanup_fb)(struct drm_plane *plane,
  1197. struct drm_plane_state *old_state);
  1198. /**
  1199. * @begin_fb_access:
  1200. *
  1201. * This hook prepares the plane for access during an atomic commit.
  1202. * In contrast to @prepare_fb, resources acquired in @begin_fb_access,
  1203. * are released at the end of the atomic commit in @end_fb_access.
  1204. *
  1205. * For example, with shadow-plane helpers, the GEM buffer's vmap
  1206. * operation belongs into @begin_fb_access, so that the buffer's
  1207. * memory will be unmapped at the end of the commit in @end_fb_access.
  1208. * But a GEM buffer's pin operation belongs into @prepare_fb
  1209. * to keep the buffer pinned after the commit.
  1210. *
  1211. * The callback is used by the atomic modeset helpers, but it is optional.
  1212. * See @end_fb_cleanup for undoing the effects of @begin_fb_access and
  1213. * @prepare_fb for acquiring resources until the next pageflip.
  1214. *
  1215. * Returns:
  1216. * 0 on success, or a negative errno code otherwise.
  1217. */
  1218. int (*begin_fb_access)(struct drm_plane *plane, struct drm_plane_state *new_plane_state);
  1219. /**
  1220. * @end_fb_access:
  1221. *
  1222. * This hook cleans up resources allocated by @begin_fb_access. It it called
  1223. * at the end of a commit for the new plane state.
  1224. */
  1225. void (*end_fb_access)(struct drm_plane *plane, struct drm_plane_state *new_plane_state);
  1226. /**
  1227. * @atomic_check:
  1228. *
  1229. * Drivers should check plane specific constraints in this hook.
  1230. *
  1231. * When using drm_atomic_helper_check_planes() plane's @atomic_check
  1232. * hooks are called before the ones for CRTCs, which allows drivers to
  1233. * request shared resources that the CRTC controls here. For more
  1234. * complicated dependencies the driver can call the provided check helpers
  1235. * multiple times until the computed state has a final configuration and
  1236. * everything has been checked.
  1237. *
  1238. * This function is also allowed to inspect any other object's state and
  1239. * can add more state objects to the atomic commit if needed. Care must
  1240. * be taken though to ensure that state check and compute functions for
  1241. * these added states are all called, and derived state in other objects
  1242. * all updated. Again the recommendation is to just call check helpers
  1243. * until a maximal configuration is reached.
  1244. *
  1245. * This callback is used by the atomic modeset helpers, but it is
  1246. * optional.
  1247. *
  1248. * NOTE:
  1249. *
  1250. * This function is called in the check phase of an atomic update. The
  1251. * driver is not allowed to change anything outside of the
  1252. * &drm_atomic_state update tracking structure.
  1253. *
  1254. * RETURNS:
  1255. *
  1256. * 0 on success, -EINVAL if the state or the transition can't be
  1257. * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
  1258. * attempt to obtain another state object ran into a &drm_modeset_lock
  1259. * deadlock.
  1260. */
  1261. int (*atomic_check)(struct drm_plane *plane,
  1262. struct drm_atomic_state *state);
  1263. /**
  1264. * @atomic_update:
  1265. *
  1266. * Drivers should use this function to update the plane state. This
  1267. * hook is called in-between the &drm_crtc_helper_funcs.atomic_begin and
  1268. * drm_crtc_helper_funcs.atomic_flush callbacks.
  1269. *
  1270. * Note that the power state of the display pipe when this function is
  1271. * called depends upon the exact helpers and calling sequence the driver
  1272. * has picked. See drm_atomic_helper_commit_planes() for a discussion of
  1273. * the tradeoffs and variants of plane commit helpers.
  1274. *
  1275. * This callback is used by the atomic modeset helpers, but it is optional.
  1276. */
  1277. void (*atomic_update)(struct drm_plane *plane,
  1278. struct drm_atomic_state *state);
  1279. /**
  1280. * @atomic_enable:
  1281. *
  1282. * Drivers should use this function to unconditionally enable a plane.
  1283. * This hook is called in-between the &drm_crtc_helper_funcs.atomic_begin
  1284. * and drm_crtc_helper_funcs.atomic_flush callbacks. It is called after
  1285. * @atomic_update, which will be called for all enabled planes. Drivers
  1286. * that use @atomic_enable should set up a plane in @atomic_update and
  1287. * afterwards enable the plane in @atomic_enable. If a plane needs to be
  1288. * enabled before installing the scanout buffer, drivers can still do
  1289. * so in @atomic_update.
  1290. *
  1291. * Note that the power state of the display pipe when this function is
  1292. * called depends upon the exact helpers and calling sequence the driver
  1293. * has picked. See drm_atomic_helper_commit_planes() for a discussion of
  1294. * the tradeoffs and variants of plane commit helpers.
  1295. *
  1296. * This callback is used by the atomic modeset helpers, but it is
  1297. * optional. If implemented, @atomic_enable should be the inverse of
  1298. * @atomic_disable. Drivers that don't want to use either can still
  1299. * implement the complete plane update in @atomic_update.
  1300. */
  1301. void (*atomic_enable)(struct drm_plane *plane,
  1302. struct drm_atomic_state *state);
  1303. /**
  1304. * @atomic_disable:
  1305. *
  1306. * Drivers should use this function to unconditionally disable a plane.
  1307. * This hook is called in-between the
  1308. * &drm_crtc_helper_funcs.atomic_begin and
  1309. * drm_crtc_helper_funcs.atomic_flush callbacks. It is an alternative to
  1310. * @atomic_update, which will be called for disabling planes, too, if
  1311. * the @atomic_disable hook isn't implemented.
  1312. *
  1313. * This hook is also useful to disable planes in preparation of a modeset,
  1314. * by calling drm_atomic_helper_disable_planes_on_crtc() from the
  1315. * &drm_crtc_helper_funcs.disable hook.
  1316. *
  1317. * Note that the power state of the display pipe when this function is
  1318. * called depends upon the exact helpers and calling sequence the driver
  1319. * has picked. See drm_atomic_helper_commit_planes() for a discussion of
  1320. * the tradeoffs and variants of plane commit helpers.
  1321. *
  1322. * This callback is used by the atomic modeset helpers, but it is
  1323. * optional. It's intended to reverse the effects of @atomic_enable.
  1324. */
  1325. void (*atomic_disable)(struct drm_plane *plane,
  1326. struct drm_atomic_state *state);
  1327. /**
  1328. * @atomic_async_check:
  1329. *
  1330. * Drivers should set this function pointer to check if the plane's
  1331. * atomic state can be updated in a async fashion. Here async means
  1332. * "not vblank synchronized".
  1333. *
  1334. * This hook is called by drm_atomic_async_check() to establish if a
  1335. * given update can be committed asynchronously, that is, if it can
  1336. * jump ahead of the state currently queued for update.
  1337. *
  1338. * This function is also used by drm_atomic_set_property() to determine
  1339. * if the plane can be flipped in async. The flip flag is used to
  1340. * distinguish if the function is used for just the plane state or for a
  1341. * flip.
  1342. *
  1343. * RETURNS:
  1344. *
  1345. * Return 0 on success and any error returned indicates that the update
  1346. * can not be applied in asynchronous manner.
  1347. */
  1348. int (*atomic_async_check)(struct drm_plane *plane,
  1349. struct drm_atomic_state *state, bool flip);
  1350. /**
  1351. * @atomic_async_update:
  1352. *
  1353. * Drivers should set this function pointer to perform asynchronous
  1354. * updates of planes, that is, jump ahead of the currently queued
  1355. * state and update the plane. Here async means "not vblank
  1356. * synchronized".
  1357. *
  1358. * This hook is called by drm_atomic_helper_async_commit().
  1359. *
  1360. * An async update will happen on legacy cursor updates. An async
  1361. * update won't happen if there is an outstanding commit modifying
  1362. * the same plane.
  1363. *
  1364. * When doing async_update drivers shouldn't replace the
  1365. * &drm_plane_state but update the current one with the new plane
  1366. * configurations in the new plane_state.
  1367. *
  1368. * Drivers should also swap the framebuffers between current plane
  1369. * state (&drm_plane.state) and new_state.
  1370. * This is required since cleanup for async commits is performed on
  1371. * the new state, rather than old state like for traditional commits.
  1372. * Since we want to give up the reference on the current (old) fb
  1373. * instead of our brand new one, swap them in the driver during the
  1374. * async commit.
  1375. *
  1376. * FIXME:
  1377. * - It only works for single plane updates
  1378. * - Async Pageflips are not supported yet
  1379. * - Some hw might still scan out the old buffer until the next
  1380. * vblank, however we let go of the fb references as soon as
  1381. * we run this hook. For now drivers must implement their own workers
  1382. * for deferring if needed, until a common solution is created.
  1383. */
  1384. void (*atomic_async_update)(struct drm_plane *plane,
  1385. struct drm_atomic_state *state);
  1386. /**
  1387. * @get_scanout_buffer:
  1388. *
  1389. * Get the current scanout buffer, to display a message with drm_panic.
  1390. * The driver should do the minimum changes to provide a buffer,
  1391. * that can be used to display the panic screen. Currently only linear
  1392. * buffers are supported. Non-linear buffer support is on the TODO list.
  1393. * The device &dev.mode_config.panic_lock is taken before calling this
  1394. * function, so you can safely access the &plane.state
  1395. * It is called from a panic callback, and must follow its restrictions.
  1396. * Please look the documentation at drm_panic_trylock() for an in-depth
  1397. * discussions of what's safe and what is not allowed.
  1398. * It's a best effort mode, so it's expected that in some complex cases
  1399. * the panic screen won't be displayed.
  1400. * The returned &drm_scanout_buffer.map must be valid if no error code is
  1401. * returned.
  1402. *
  1403. * Return:
  1404. * %0 on success, negative errno on failure.
  1405. */
  1406. int (*get_scanout_buffer)(struct drm_plane *plane,
  1407. struct drm_scanout_buffer *sb);
  1408. /**
  1409. * @panic_flush:
  1410. *
  1411. * It is used by drm_panic, and is called after the panic screen is
  1412. * drawn to the scanout buffer. In this function, the driver
  1413. * can send additional commands to the hardware, to make the scanout
  1414. * buffer visible.
  1415. * It is only called if get_scanout_buffer() returned successfully, and
  1416. * the &dev.mode_config.panic_lock is held during the entire sequence.
  1417. * It is called from a panic callback, and must follow its restrictions.
  1418. * Please look the documentation at drm_panic_trylock() for an in-depth
  1419. * discussions of what's safe and what is not allowed.
  1420. */
  1421. void (*panic_flush)(struct drm_plane *plane);
  1422. };
  1423. /**
  1424. * drm_plane_helper_add - sets the helper vtable for a plane
  1425. * @plane: DRM plane
  1426. * @funcs: helper vtable to set for @plane
  1427. */
  1428. static inline void drm_plane_helper_add(struct drm_plane *plane,
  1429. const struct drm_plane_helper_funcs *funcs)
  1430. {
  1431. plane->helper_private = funcs;
  1432. }
  1433. /**
  1434. * struct drm_mode_config_helper_funcs - global modeset helper operations
  1435. *
  1436. * These helper functions are used by the atomic helpers.
  1437. */
  1438. struct drm_mode_config_helper_funcs {
  1439. /**
  1440. * @atomic_commit_tail:
  1441. *
  1442. * This hook is used by the default atomic_commit() hook implemented in
  1443. * drm_atomic_helper_commit() together with the nonblocking commit
  1444. * helpers (see drm_atomic_helper_setup_commit() for a starting point)
  1445. * to implement blocking and nonblocking commits easily. It is not used
  1446. * by the atomic helpers
  1447. *
  1448. * This function is called when the new atomic state has already been
  1449. * swapped into the various state pointers. The passed in state
  1450. * therefore contains copies of the old/previous state. This hook should
  1451. * commit the new state into hardware. Note that the helpers have
  1452. * already waited for preceding atomic commits and fences, but drivers
  1453. * can add more waiting calls at the start of their implementation, e.g.
  1454. * to wait for driver-internal request for implicit syncing, before
  1455. * starting to commit the update to the hardware.
  1456. *
  1457. * After the atomic update is committed to the hardware this hook needs
  1458. * to call drm_atomic_helper_commit_hw_done(). Then wait for the update
  1459. * to be executed by the hardware, for example using
  1460. * drm_atomic_helper_wait_for_vblanks() or
  1461. * drm_atomic_helper_wait_for_flip_done(), and then clean up the old
  1462. * framebuffers using drm_atomic_helper_cleanup_planes().
  1463. *
  1464. * When disabling a CRTC this hook _must_ stall for the commit to
  1465. * complete. Vblank waits don't work on disabled CRTC, hence the core
  1466. * can't take care of this. And it also can't rely on the vblank event,
  1467. * since that can be signalled already when the screen shows black,
  1468. * which can happen much earlier than the last hardware access needed to
  1469. * shut off the display pipeline completely.
  1470. *
  1471. * This hook is optional, the default implementation is
  1472. * drm_atomic_helper_commit_tail().
  1473. */
  1474. void (*atomic_commit_tail)(struct drm_atomic_state *state);
  1475. /**
  1476. * @atomic_commit_setup:
  1477. *
  1478. * This hook is used by the default atomic_commit() hook implemented in
  1479. * drm_atomic_helper_commit() together with the nonblocking helpers (see
  1480. * drm_atomic_helper_setup_commit()) to extend the DRM commit setup. It
  1481. * is not used by the atomic helpers.
  1482. *
  1483. * This function is called at the end of
  1484. * drm_atomic_helper_setup_commit(), so once the commit has been
  1485. * properly setup across the generic DRM object states. It allows
  1486. * drivers to do some additional commit tracking that isn't related to a
  1487. * CRTC, plane or connector, tracked in a &drm_private_obj structure.
  1488. *
  1489. * Note that the documentation of &drm_private_obj has more details on
  1490. * how one should implement this.
  1491. *
  1492. * This hook is optional.
  1493. */
  1494. int (*atomic_commit_setup)(struct drm_atomic_state *state);
  1495. };
  1496. #endif