drm_modeset_helper_vtables.h 40 KB

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