drm_modeset_helper_vtables.h 61 KB

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