drm_modeset_helper_vtables.h 41 KB

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