drm_modeset_helper_vtables.h 56 KB

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