drm_modeset_helper_vtables.h 48 KB

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