1564 lines · c
1/*2 * Copyright © 2006 Keith Packard3 * Copyright © 2007-2008 Dave Airlie4 * Copyright © 2007-2008 Intel Corporation5 * Jesse Barnes <jesse.barnes@intel.com>6 * Copyright © 2011-2013 Intel Corporation7 * Copyright © 2015 Intel Corporation8 * Daniel Vetter <daniel.vetter@ffwll.ch>9 *10 * Permission is hereby granted, free of charge, to any person obtaining a11 * copy of this software and associated documentation files (the "Software"),12 * to deal in the Software without restriction, including without limitation13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,14 * and/or sell copies of the Software, and to permit persons to whom the15 * Software is furnished to do so, subject to the following conditions:16 *17 * The above copyright notice and this permission notice shall be included in18 * all copies or substantial portions of the Software.19 *20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL23 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR24 * 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 OR26 * OTHER DEALINGS IN THE SOFTWARE.27 */28 29#ifndef __DRM_MODESET_HELPER_VTABLES_H__30#define __DRM_MODESET_HELPER_VTABLES_H__31 32#include <drm/drm_crtc.h>33#include <drm/drm_encoder.h>34 35/**36 * DOC: overview37 *38 * The DRM mode setting helper functions are common code for drivers to use if39 * they wish. Drivers are not forced to use this code in their40 * implementations but it would be useful if the code they do use at least41 * provides a consistent interface and operation to userspace. Therefore it is42 * highly recommended to use the provided helpers as much as possible.43 *44 * Because there is only one pointer per modeset object to hold a vfunc table45 * for helper libraries they are by necessity shared among the different46 * helpers.47 *48 * To make this clear all the helper vtables are pulled together in this location here.49 */50 51struct drm_scanout_buffer;52struct drm_writeback_connector;53struct drm_writeback_job;54 55enum mode_set_atomic {56 LEAVE_ATOMIC_MODE_SET,57 ENTER_ATOMIC_MODE_SET,58};59 60/**61 * struct drm_crtc_helper_funcs - helper operations for CRTCs62 *63 * These hooks are used by the legacy CRTC helpers and the new atomic64 * modesetting helpers.65 */66struct drm_crtc_helper_funcs {67 /**68 * @dpms:69 *70 * Callback to control power levels on the CRTC. If the mode passed in71 * is unsupported, the provider must use the next lowest power level.72 * This is used by the legacy CRTC helpers to implement DPMS73 * functionality in drm_helper_connector_dpms().74 *75 * This callback is also used to disable a CRTC by calling it with76 * DRM_MODE_DPMS_OFF if the @disable hook isn't used.77 *78 * This callback is used by the legacy CRTC helpers. Atomic helpers79 * also support using this hook for enabling and disabling a CRTC to80 * facilitate transitions to atomic, but it is deprecated. Instead81 * @atomic_enable and @atomic_disable should be used.82 */83 void (*dpms)(struct drm_crtc *crtc, int mode);84 85 /**86 * @prepare:87 *88 * This callback should prepare the CRTC for a subsequent modeset, which89 * in practice means the driver should disable the CRTC if it is90 * running. Most drivers ended up implementing this by calling their91 * @dpms hook with DRM_MODE_DPMS_OFF.92 *93 * This callback is used by the legacy CRTC helpers. Atomic helpers94 * also support using this hook for disabling a CRTC to facilitate95 * transitions to atomic, but it is deprecated. Instead @atomic_disable96 * should be used.97 */98 void (*prepare)(struct drm_crtc *crtc);99 100 /**101 * @commit:102 *103 * This callback should commit the new mode on the CRTC after a modeset,104 * which in practice means the driver should enable the CRTC. Most105 * drivers ended up implementing this by calling their @dpms hook with106 * DRM_MODE_DPMS_ON.107 *108 * This callback is used by the legacy CRTC helpers. Atomic helpers109 * also support using this hook for enabling a CRTC to facilitate110 * transitions to atomic, but it is deprecated. Instead @atomic_enable111 * should be used.112 */113 void (*commit)(struct drm_crtc *crtc);114 115 /**116 * @mode_valid:117 *118 * This callback is used to check if a specific mode is valid in this119 * crtc. This should be implemented if the crtc has some sort of120 * restriction in the modes it can display. For example, a given crtc121 * may be responsible to set a clock value. If the clock can not122 * produce all the values for the available modes then this callback123 * can be used to restrict the number of modes to only the ones that124 * can be displayed.125 *126 * This hook is used by the probe helpers to filter the mode list in127 * drm_helper_probe_single_connector_modes(), and it is used by the128 * atomic helpers to validate modes supplied by userspace in129 * drm_atomic_helper_check_modeset().130 *131 * This function is optional.132 *133 * NOTE:134 *135 * Since this function is both called from the check phase of an atomic136 * commit, and the mode validation in the probe paths it is not allowed137 * to look at anything else but the passed-in mode, and validate it138 * against configuration-invariant hardware constraints. Any further139 * limits which depend upon the configuration can only be checked in140 * @mode_fixup or @atomic_check.141 *142 * RETURNS:143 *144 * drm_mode_status Enum145 */146 enum drm_mode_status (*mode_valid)(struct drm_crtc *crtc,147 const struct drm_display_mode *mode);148 149 /**150 * @mode_fixup:151 *152 * This callback is used to validate a mode. The parameter mode is the153 * display mode that userspace requested, adjusted_mode is the mode the154 * encoders need to be fed with. Note that this is the inverse semantics155 * of the meaning for the &drm_encoder and &drm_bridge_funcs.mode_fixup156 * vfunc. If the CRTC cannot support the requested conversion from mode157 * to adjusted_mode it should reject the modeset. See also158 * &drm_crtc_state.adjusted_mode for more details.159 *160 * This function is used by both legacy CRTC helpers and atomic helpers.161 * With atomic helpers it is optional.162 *163 * NOTE:164 *165 * This function is called in the check phase of atomic modesets, which166 * can be aborted for any reason (including on userspace's request to167 * just check whether a configuration would be possible). Atomic drivers168 * MUST NOT touch any persistent state (hardware or software) or data169 * structures except the passed in adjusted_mode parameter.170 *171 * This is in contrast to the legacy CRTC helpers where this was172 * allowed.173 *174 * Atomic drivers which need to inspect and adjust more state should175 * instead use the @atomic_check callback, but note that they're not176 * perfectly equivalent: @mode_valid is called from177 * drm_atomic_helper_check_modeset(), but @atomic_check is called from178 * drm_atomic_helper_check_planes(), because originally it was meant for179 * plane update checks only.180 *181 * Also beware that userspace can request its own custom modes, neither182 * core nor helpers filter modes to the list of probe modes reported by183 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure184 * that modes are filtered consistently put any CRTC constraints and185 * limits checks into @mode_valid.186 *187 * RETURNS:188 *189 * True if an acceptable configuration is possible, false if the modeset190 * operation should be rejected.191 */192 bool (*mode_fixup)(struct drm_crtc *crtc,193 const struct drm_display_mode *mode,194 struct drm_display_mode *adjusted_mode);195 196 /**197 * @mode_set:198 *199 * This callback is used by the legacy CRTC helpers to set a new mode,200 * position and framebuffer. Since it ties the primary plane to every201 * mode change it is incompatible with universal plane support. And202 * since it can't update other planes it's incompatible with atomic203 * modeset support.204 *205 * This callback is only used by CRTC helpers and deprecated.206 *207 * RETURNS:208 *209 * 0 on success or a negative error code on failure.210 */211 int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,212 struct drm_display_mode *adjusted_mode, int x, int y,213 struct drm_framebuffer *old_fb);214 215 /**216 * @mode_set_nofb:217 *218 * This callback is used to update the display mode of a CRTC without219 * changing anything of the primary plane configuration. This fits the220 * requirement of atomic and hence is used by the atomic helpers.221 *222 * Note that the display pipe is completely off when this function is223 * called. Atomic drivers which need hardware to be running before they224 * program the new display mode (e.g. because they implement runtime PM)225 * should not use this hook. This is because the helper library calls226 * this hook only once per mode change and not every time the display227 * pipeline is suspended using either DPMS or the new "ACTIVE" property.228 * Which means register values set in this callback might get reset when229 * the CRTC is suspended, but not restored. Such drivers should instead230 * move all their CRTC setup into the @atomic_enable callback.231 *232 * This callback is optional.233 */234 void (*mode_set_nofb)(struct drm_crtc *crtc);235 236 /**237 * @mode_set_base:238 *239 * This callback is used by the legacy CRTC helpers to set a new240 * framebuffer and scanout position. It is optional and used as an241 * optimized fast-path instead of a full mode set operation with all the242 * resulting flickering. If it is not present243 * drm_crtc_helper_set_config() will fall back to a full modeset, using244 * the @mode_set callback. Since it can't update other planes it's245 * incompatible with atomic modeset support.246 *247 * This callback is only used by the CRTC helpers and deprecated.248 *249 * RETURNS:250 *251 * 0 on success or a negative error code on failure.252 */253 int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,254 struct drm_framebuffer *old_fb);255 256 /**257 * @mode_set_base_atomic:258 *259 * This callback is used by the fbdev helpers to set a new framebuffer260 * and scanout without sleeping, i.e. from an atomic calling context. It261 * is only used to implement kgdb support.262 *263 * This callback is optional and only needed for kgdb support in the fbdev264 * helpers.265 *266 * RETURNS:267 *268 * 0 on success or a negative error code on failure.269 */270 int (*mode_set_base_atomic)(struct drm_crtc *crtc,271 struct drm_framebuffer *fb, int x, int y,272 enum mode_set_atomic);273 274 /**275 * @disable:276 *277 * This callback should be used to disable the CRTC. With the atomic278 * drivers it is called after all encoders connected to this CRTC have279 * been shut off already using their own280 * &drm_encoder_helper_funcs.disable hook. If that sequence is too281 * simple drivers can just add their own hooks and call it from this282 * CRTC callback here by looping over all encoders connected to it using283 * for_each_encoder_on_crtc().284 *285 * This hook is used both by legacy CRTC helpers and atomic helpers.286 * Atomic drivers don't need to implement it if there's no need to287 * disable anything at the CRTC level. To ensure that runtime PM288 * handling (using either DPMS or the new "ACTIVE" property) works289 * @disable must be the inverse of @atomic_enable for atomic drivers.290 * Atomic drivers should consider to use @atomic_disable instead of291 * this one.292 *293 * NOTE:294 *295 * With legacy CRTC helpers there's a big semantic difference between296 * @disable and other hooks (like @prepare or @dpms) used to shut down a297 * CRTC: @disable is only called when also logically disabling the298 * display pipeline and needs to release any resources acquired in299 * @mode_set (like shared PLLs, or again release pinned framebuffers).300 *301 * Therefore @disable must be the inverse of @mode_set plus @commit for302 * drivers still using legacy CRTC helpers, which is different from the303 * rules under atomic.304 */305 void (*disable)(struct drm_crtc *crtc);306 307 /**308 * @atomic_check:309 *310 * Drivers should check plane-update related CRTC constraints in this311 * hook. They can also check mode related limitations but need to be312 * aware of the calling order, since this hook is used by313 * drm_atomic_helper_check_planes() whereas the preparations needed to314 * check output routing and the display mode is done in315 * drm_atomic_helper_check_modeset(). Therefore drivers that want to316 * check output routing and display mode constraints in this callback317 * must ensure that drm_atomic_helper_check_modeset() has been called318 * beforehand. This is calling order used by the default helper319 * implementation in drm_atomic_helper_check().320 *321 * When using drm_atomic_helper_check_planes() this hook is called322 * after the &drm_plane_helper_funcs.atomic_check hook for planes, which323 * allows drivers to assign shared resources requested by planes in this324 * callback here. For more complicated dependencies the driver can call325 * the provided check helpers multiple times until the computed state326 * has a final configuration and everything has been checked.327 *328 * This function is also allowed to inspect any other object's state and329 * can add more state objects to the atomic commit if needed. Care must330 * be taken though to ensure that state check and compute functions for331 * these added states are all called, and derived state in other objects332 * all updated. Again the recommendation is to just call check helpers333 * until a maximal configuration is reached.334 *335 * This callback is used by the atomic modeset helpers, but it is336 * optional.337 *338 * NOTE:339 *340 * This function is called in the check phase of an atomic update. The341 * driver is not allowed to change anything outside of the free-standing342 * state object passed-in.343 *344 * Also beware that userspace can request its own custom modes, neither345 * core nor helpers filter modes to the list of probe modes reported by346 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure347 * that modes are filtered consistently put any CRTC constraints and348 * limits checks into @mode_valid.349 *350 * RETURNS:351 *352 * 0 on success, -EINVAL if the state or the transition can't be353 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an354 * attempt to obtain another state object ran into a &drm_modeset_lock355 * deadlock.356 */357 int (*atomic_check)(struct drm_crtc *crtc,358 struct drm_atomic_state *state);359 360 /**361 * @atomic_begin:362 *363 * Drivers should prepare for an atomic update of multiple planes on364 * a CRTC in this hook. Depending upon hardware this might be vblank365 * evasion, blocking updates by setting bits or doing preparatory work366 * for e.g. manual update display.367 *368 * This hook is called before any plane commit functions are called.369 *370 * Note that the power state of the display pipe when this function is371 * called depends upon the exact helpers and calling sequence the driver372 * has picked. See drm_atomic_helper_commit_planes() for a discussion of373 * the tradeoffs and variants of plane commit helpers.374 *375 * This callback is used by the atomic modeset helpers, but it is376 * optional.377 */378 void (*atomic_begin)(struct drm_crtc *crtc,379 struct drm_atomic_state *state);380 /**381 * @atomic_flush:382 *383 * Drivers should finalize an atomic update of multiple planes on384 * a CRTC in this hook. Depending upon hardware this might include385 * checking that vblank evasion was successful, unblocking updates by386 * setting bits or setting the GO bit to flush out all updates.387 *388 * Simple hardware or hardware with special requirements can commit and389 * flush out all updates for all planes from this hook and forgo all the390 * other commit hooks for plane updates.391 *392 * This hook is called after any plane commit functions are called.393 *394 * Note that the power state of the display pipe when this function is395 * called depends upon the exact helpers and calling sequence the driver396 * has picked. See drm_atomic_helper_commit_planes() for a discussion of397 * the tradeoffs and variants of plane commit helpers.398 *399 * This callback is used by the atomic modeset helpers, but it is400 * optional.401 */402 void (*atomic_flush)(struct drm_crtc *crtc,403 struct drm_atomic_state *state);404 405 /**406 * @atomic_enable:407 *408 * This callback should be used to enable the CRTC. With the atomic409 * drivers it is called before all encoders connected to this CRTC are410 * enabled through the encoder's own &drm_encoder_helper_funcs.enable411 * hook. If that sequence is too simple drivers can just add their own412 * hooks and call it from this CRTC callback here by looping over all413 * encoders connected to it using for_each_encoder_on_crtc().414 *415 * This hook is used only by atomic helpers, for symmetry with416 * @atomic_disable. Atomic drivers don't need to implement it if there's417 * no need to enable anything at the CRTC level. To ensure that runtime418 * PM handling (using either DPMS or the new "ACTIVE" property) works419 * @atomic_enable must be the inverse of @atomic_disable for atomic420 * drivers.421 *422 * This function is optional.423 */424 void (*atomic_enable)(struct drm_crtc *crtc,425 struct drm_atomic_state *state);426 427 /**428 * @atomic_disable:429 *430 * This callback should be used to disable the CRTC. With the atomic431 * drivers it is called after all encoders connected to this CRTC have432 * been shut off already using their own433 * &drm_encoder_helper_funcs.disable hook. If that sequence is too434 * simple drivers can just add their own hooks and call it from this435 * CRTC callback here by looping over all encoders connected to it using436 * for_each_encoder_on_crtc().437 *438 * This hook is used only by atomic helpers. Atomic drivers don't439 * need to implement it if there's no need to disable anything at the440 * CRTC level.441 *442 * This function is optional.443 */444 void (*atomic_disable)(struct drm_crtc *crtc,445 struct drm_atomic_state *state);446 447 /**448 * @get_scanout_position:449 *450 * Called by vblank timestamping code.451 *452 * Returns the current display scanout position from a CRTC and an453 * optional accurate ktime_get() timestamp of when the position was454 * measured. Note that this is a helper callback which is only used455 * if a driver uses drm_crtc_vblank_helper_get_vblank_timestamp()456 * for the @drm_crtc_funcs.get_vblank_timestamp callback.457 *458 * Parameters:459 *460 * crtc:461 * The CRTC.462 * in_vblank_irq:463 * True when called from drm_crtc_handle_vblank(). Some drivers464 * need to apply some workarounds for gpu-specific vblank irq465 * quirks if the flag is set.466 * vpos:467 * Target location for current vertical scanout position.468 * hpos:469 * Target location for current horizontal scanout position.470 * stime:471 * Target location for timestamp taken immediately before472 * scanout position query. Can be NULL to skip timestamp.473 * etime:474 * Target location for timestamp taken immediately after475 * scanout position query. Can be NULL to skip timestamp.476 * mode:477 * Current display timings.478 *479 * Returns vpos as a positive number while in active scanout area.480 * Returns vpos as a negative number inside vblank, counting the number481 * of scanlines to go until end of vblank, e.g., -1 means "one scanline482 * until start of active scanout / end of vblank."483 *484 * Returns:485 *486 * True on success, false if a reliable scanout position counter could487 * not be read out.488 */489 bool (*get_scanout_position)(struct drm_crtc *crtc,490 bool in_vblank_irq, int *vpos, int *hpos,491 ktime_t *stime, ktime_t *etime,492 const struct drm_display_mode *mode);493};494 495/**496 * drm_crtc_helper_add - sets the helper vtable for a crtc497 * @crtc: DRM CRTC498 * @funcs: helper vtable to set for @crtc499 */500static inline void drm_crtc_helper_add(struct drm_crtc *crtc,501 const struct drm_crtc_helper_funcs *funcs)502{503 crtc->helper_private = funcs;504}505 506/**507 * struct drm_encoder_helper_funcs - helper operations for encoders508 *509 * These hooks are used by the legacy CRTC helpers and the new atomic510 * modesetting helpers.511 */512struct drm_encoder_helper_funcs {513 /**514 * @dpms:515 *516 * Callback to control power levels on the encoder. If the mode passed in517 * is unsupported, the provider must use the next lowest power level.518 * This is used by the legacy encoder helpers to implement DPMS519 * functionality in drm_helper_connector_dpms().520 *521 * This callback is also used to disable an encoder by calling it with522 * DRM_MODE_DPMS_OFF if the @disable hook isn't used.523 *524 * This callback is used by the legacy CRTC helpers. Atomic helpers525 * also support using this hook for enabling and disabling an encoder to526 * facilitate transitions to atomic, but it is deprecated. Instead527 * @enable and @disable should be used.528 */529 void (*dpms)(struct drm_encoder *encoder, int mode);530 531 /**532 * @mode_valid:533 *534 * This callback is used to check if a specific mode is valid in this535 * encoder. This should be implemented if the encoder has some sort536 * of restriction in the modes it can display. For example, a given537 * encoder may be responsible to set a clock value. If the clock can538 * not produce all the values for the available modes then this callback539 * can be used to restrict the number of modes to only the ones that540 * can be displayed.541 *542 * This hook is used by the probe helpers to filter the mode list in543 * drm_helper_probe_single_connector_modes(), and it is used by the544 * atomic helpers to validate modes supplied by userspace in545 * drm_atomic_helper_check_modeset().546 *547 * This function is optional.548 *549 * NOTE:550 *551 * Since this function is both called from the check phase of an atomic552 * commit, and the mode validation in the probe paths it is not allowed553 * to look at anything else but the passed-in mode, and validate it554 * against configuration-invariant hardware constraints. Any further555 * limits which depend upon the configuration can only be checked in556 * @mode_fixup or @atomic_check.557 *558 * RETURNS:559 *560 * drm_mode_status Enum561 */562 enum drm_mode_status (*mode_valid)(struct drm_encoder *crtc,563 const struct drm_display_mode *mode);564 565 /**566 * @mode_fixup:567 *568 * This callback is used to validate and adjust a mode. The parameter569 * mode is the display mode that should be fed to the next element in570 * the display chain, either the final &drm_connector or a &drm_bridge.571 * The parameter adjusted_mode is the input mode the encoder requires. It572 * can be modified by this callback and does not need to match mode. See573 * also &drm_crtc_state.adjusted_mode for more details.574 *575 * This function is used by both legacy CRTC helpers and atomic helpers.576 * This hook is optional.577 *578 * NOTE:579 *580 * This function is called in the check phase of atomic modesets, which581 * can be aborted for any reason (including on userspace's request to582 * just check whether a configuration would be possible). Atomic drivers583 * MUST NOT touch any persistent state (hardware or software) or data584 * structures except the passed in adjusted_mode parameter.585 *586 * This is in contrast to the legacy CRTC helpers where this was587 * allowed.588 *589 * Atomic drivers which need to inspect and adjust more state should590 * instead use the @atomic_check callback. If @atomic_check is used,591 * this hook isn't called since @atomic_check allows a strict superset592 * of the functionality of @mode_fixup.593 *594 * Also beware that userspace can request its own custom modes, neither595 * core nor helpers filter modes to the list of probe modes reported by596 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure597 * that modes are filtered consistently put any encoder constraints and598 * limits checks into @mode_valid.599 *600 * RETURNS:601 *602 * True if an acceptable configuration is possible, false if the modeset603 * operation should be rejected.604 */605 bool (*mode_fixup)(struct drm_encoder *encoder,606 const struct drm_display_mode *mode,607 struct drm_display_mode *adjusted_mode);608 609 /**610 * @prepare:611 *612 * This callback should prepare the encoder for a subsequent modeset,613 * which in practice means the driver should disable the encoder if it614 * is running. Most drivers ended up implementing this by calling their615 * @dpms hook with DRM_MODE_DPMS_OFF.616 *617 * This callback is used by the legacy CRTC helpers. Atomic helpers618 * also support using this hook for disabling an encoder to facilitate619 * transitions to atomic, but it is deprecated. Instead @disable should620 * be used.621 */622 void (*prepare)(struct drm_encoder *encoder);623 624 /**625 * @commit:626 *627 * This callback should commit the new mode on the encoder after a modeset,628 * which in practice means the driver should enable the encoder. Most629 * drivers ended up implementing this by calling their @dpms hook with630 * DRM_MODE_DPMS_ON.631 *632 * This callback is used by the legacy CRTC helpers. Atomic helpers633 * also support using this hook for enabling an encoder to facilitate634 * transitions to atomic, but it is deprecated. Instead @enable should635 * be used.636 */637 void (*commit)(struct drm_encoder *encoder);638 639 /**640 * @mode_set:641 *642 * This callback is used to update the display mode of an encoder.643 *644 * Note that the display pipe is completely off when this function is645 * called. Drivers which need hardware to be running before they program646 * the new display mode (because they implement runtime PM) should not647 * use this hook, because the helper library calls it only once and not648 * every time the display pipeline is suspend using either DPMS or the649 * new "ACTIVE" property. Such drivers should instead move all their650 * encoder setup into the @enable callback.651 *652 * This callback is used both by the legacy CRTC helpers and the atomic653 * modeset helpers. It is optional in the atomic helpers.654 *655 * NOTE:656 *657 * If the driver uses the atomic modeset helpers and needs to inspect658 * the connector state or connector display info during mode setting,659 * @atomic_mode_set can be used instead.660 */661 void (*mode_set)(struct drm_encoder *encoder,662 struct drm_display_mode *mode,663 struct drm_display_mode *adjusted_mode);664 665 /**666 * @atomic_mode_set:667 *668 * This callback is used to update the display mode of an encoder.669 *670 * Note that the display pipe is completely off when this function is671 * called. Drivers which need hardware to be running before they program672 * the new display mode (because they implement runtime PM) should not673 * use this hook, because the helper library calls it only once and not674 * every time the display pipeline is suspended using either DPMS or the675 * new "ACTIVE" property. Such drivers should instead move all their676 * encoder setup into the @enable callback.677 *678 * This callback is used by the atomic modeset helpers in place of the679 * @mode_set callback, if set by the driver. It is optional and should680 * be used instead of @mode_set if the driver needs to inspect the681 * connector state or display info, since there is no direct way to682 * go from the encoder to the current connector.683 */684 void (*atomic_mode_set)(struct drm_encoder *encoder,685 struct drm_crtc_state *crtc_state,686 struct drm_connector_state *conn_state);687 688 /**689 * @detect:690 *691 * This callback can be used by drivers who want to do detection on the692 * encoder object instead of in connector functions.693 *694 * It is not used by any helper and therefore has purely driver-specific695 * semantics. New drivers shouldn't use this and instead just implement696 * their own private callbacks.697 *698 * FIXME:699 *700 * This should just be converted into a pile of driver vfuncs.701 * Currently radeon, amdgpu and nouveau are using it.702 */703 enum drm_connector_status (*detect)(struct drm_encoder *encoder,704 struct drm_connector *connector);705 706 /**707 * @atomic_disable:708 *709 * This callback should be used to disable the encoder. With the atomic710 * drivers it is called before this encoder's CRTC has been shut off711 * using their own &drm_crtc_helper_funcs.atomic_disable hook. If that712 * sequence is too simple drivers can just add their own driver private713 * encoder hooks and call them from CRTC's callback by looping over all714 * encoders connected to it using for_each_encoder_on_crtc().715 *716 * This callback is a variant of @disable that provides the atomic state717 * to the driver. If @atomic_disable is implemented, @disable is not718 * called by the helpers.719 *720 * This hook is only used by atomic helpers. Atomic drivers don't need721 * to implement it if there's no need to disable anything at the encoder722 * level. To ensure that runtime PM handling (using either DPMS or the723 * new "ACTIVE" property) works @atomic_disable must be the inverse of724 * @atomic_enable.725 */726 void (*atomic_disable)(struct drm_encoder *encoder,727 struct drm_atomic_state *state);728 729 /**730 * @atomic_enable:731 *732 * This callback should be used to enable the encoder. It is called733 * after this encoder's CRTC has been enabled using their own734 * &drm_crtc_helper_funcs.atomic_enable hook. If that sequence is735 * too simple drivers can just add their own driver private encoder736 * hooks and call them from CRTC's callback by looping over all encoders737 * connected to it using for_each_encoder_on_crtc().738 *739 * This callback is a variant of @enable that provides the atomic state740 * to the driver. If @atomic_enable is implemented, @enable is not741 * called by the helpers.742 *743 * This hook is only used by atomic helpers, it is the opposite of744 * @atomic_disable. Atomic drivers don't need to implement it if there's745 * no need to enable anything at the encoder level. To ensure that746 * runtime PM handling works @atomic_enable must be the inverse of747 * @atomic_disable.748 */749 void (*atomic_enable)(struct drm_encoder *encoder,750 struct drm_atomic_state *state);751 752 /**753 * @disable:754 *755 * This callback should be used to disable the encoder. With the atomic756 * drivers it is called before this encoder's CRTC has been shut off757 * using their own &drm_crtc_helper_funcs.disable hook. If that758 * sequence is too simple drivers can just add their own driver private759 * encoder hooks and call them from CRTC's callback by looping over all760 * encoders connected to it using for_each_encoder_on_crtc().761 *762 * This hook is used both by legacy CRTC helpers and atomic helpers.763 * Atomic drivers don't need to implement it if there's no need to764 * disable anything at the encoder level. To ensure that runtime PM765 * handling (using either DPMS or the new "ACTIVE" property) works766 * @disable must be the inverse of @enable for atomic drivers.767 *768 * For atomic drivers also consider @atomic_disable and save yourself769 * from having to read the NOTE below!770 *771 * NOTE:772 *773 * With legacy CRTC helpers there's a big semantic difference between774 * @disable and other hooks (like @prepare or @dpms) used to shut down a775 * encoder: @disable is only called when also logically disabling the776 * display pipeline and needs to release any resources acquired in777 * @mode_set (like shared PLLs, or again release pinned framebuffers).778 *779 * Therefore @disable must be the inverse of @mode_set plus @commit for780 * drivers still using legacy CRTC helpers, which is different from the781 * rules under atomic.782 */783 void (*disable)(struct drm_encoder *encoder);784 785 /**786 * @enable:787 *788 * This callback should be used to enable the encoder. With the atomic789 * drivers it is called after this encoder's CRTC has been enabled using790 * their own &drm_crtc_helper_funcs.enable hook. If that sequence is791 * too simple drivers can just add their own driver private encoder792 * hooks and call them from CRTC's callback by looping over all encoders793 * connected to it using for_each_encoder_on_crtc().794 *795 * This hook is only used by atomic helpers, it is the opposite of796 * @disable. Atomic drivers don't need to implement it if there's no797 * need to enable anything at the encoder level. To ensure that798 * runtime PM handling (using either DPMS or the new "ACTIVE" property)799 * works @enable must be the inverse of @disable for atomic drivers.800 */801 void (*enable)(struct drm_encoder *encoder);802 803 /**804 * @atomic_check:805 *806 * This callback is used to validate encoder state for atomic drivers.807 * Since the encoder is the object connecting the CRTC and connector it808 * gets passed both states, to be able to validate interactions and809 * update the CRTC to match what the encoder needs for the requested810 * connector.811 *812 * Since this provides a strict superset of the functionality of813 * @mode_fixup (the requested and adjusted modes are both available814 * through the passed in &struct drm_crtc_state) @mode_fixup is not815 * called when @atomic_check is implemented.816 *817 * This function is used by the atomic helpers, but it is optional.818 *819 * NOTE:820 *821 * This function is called in the check phase of an atomic update. The822 * driver is not allowed to change anything outside of the free-standing823 * state objects passed-in or assembled in the overall &drm_atomic_state824 * update tracking structure.825 *826 * Also beware that userspace can request its own custom modes, neither827 * core nor helpers filter modes to the list of probe modes reported by828 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure829 * that modes are filtered consistently put any encoder constraints and830 * limits checks into @mode_valid.831 *832 * RETURNS:833 *834 * 0 on success, -EINVAL if the state or the transition can't be835 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an836 * attempt to obtain another state object ran into a &drm_modeset_lock837 * deadlock.838 */839 int (*atomic_check)(struct drm_encoder *encoder,840 struct drm_crtc_state *crtc_state,841 struct drm_connector_state *conn_state);842};843 844/**845 * drm_encoder_helper_add - sets the helper vtable for an encoder846 * @encoder: DRM encoder847 * @funcs: helper vtable to set for @encoder848 */849static inline void drm_encoder_helper_add(struct drm_encoder *encoder,850 const struct drm_encoder_helper_funcs *funcs)851{852 encoder->helper_private = funcs;853}854 855/**856 * struct drm_connector_helper_funcs - helper operations for connectors857 *858 * These functions are used by the atomic and legacy modeset helpers and by the859 * probe helpers.860 */861struct drm_connector_helper_funcs {862 /**863 * @get_modes:864 *865 * This function should fill in all modes currently valid for the sink866 * into the &drm_connector.probed_modes list. It should also update the867 * EDID property by calling drm_connector_update_edid_property().868 *869 * The usual way to implement this is to cache the EDID retrieved in the870 * probe callback somewhere in the driver-private connector structure.871 * In this function drivers then parse the modes in the EDID and add872 * them by calling drm_add_edid_modes(). But connectors that drive a873 * fixed panel can also manually add specific modes using874 * drm_mode_probed_add(). Drivers which manually add modes should also875 * make sure that the &drm_connector.display_info,876 * &drm_connector.width_mm and &drm_connector.height_mm fields are877 * filled in.878 *879 * Note that the caller function will automatically add standard VESA880 * DMT modes up to 1024x768 if the .get_modes() helper operation returns881 * no mode and if the connector status is connector_status_connected or882 * connector_status_unknown. There is no need to call883 * drm_add_modes_noedid() manually in that case.884 *885 * Virtual drivers that just want some standard VESA mode with a given886 * resolution can call drm_add_modes_noedid(), and mark the preferred887 * one using drm_set_preferred_mode().888 *889 * This function is only called after the @detect hook has indicated890 * that a sink is connected and when the EDID isn't overridden through891 * sysfs or the kernel commandline.892 *893 * This callback is used by the probe helpers in e.g.894 * drm_helper_probe_single_connector_modes().895 *896 * To avoid races with concurrent connector state updates, the helper897 * libraries always call this with the &drm_mode_config.connection_mutex898 * held. Because of this it's safe to inspect &drm_connector->state.899 *900 * RETURNS:901 *902 * The number of modes added by calling drm_mode_probed_add(). Return 0903 * on failures (no modes) instead of negative error codes.904 */905 int (*get_modes)(struct drm_connector *connector);906 907 /**908 * @detect_ctx:909 *910 * Check to see if anything is attached to the connector. The parameter911 * force is set to false whilst polling, true when checking the912 * connector due to a user request. force can be used by the driver to913 * avoid expensive, destructive operations during automated probing.914 *915 * This callback is optional, if not implemented the connector will be916 * considered as always being attached.917 *918 * This is the atomic version of &drm_connector_funcs.detect.919 *920 * To avoid races against concurrent connector state updates, the921 * helper libraries always call this with ctx set to a valid context,922 * and &drm_mode_config.connection_mutex will always be locked with923 * the ctx parameter set to this ctx. This allows taking additional924 * locks as required.925 *926 * RETURNS:927 *928 * &drm_connector_status indicating the connector's status,929 * or the error code returned by drm_modeset_lock(), -EDEADLK.930 */931 int (*detect_ctx)(struct drm_connector *connector,932 struct drm_modeset_acquire_ctx *ctx,933 bool force);934 935 /**936 * @mode_valid:937 *938 * Callback to validate a mode for a connector, irrespective of the939 * specific display configuration.940 *941 * This callback is used by the probe helpers to filter the mode list942 * (which is usually derived from the EDID data block from the sink).943 * See e.g. drm_helper_probe_single_connector_modes().944 *945 * This function is optional.946 *947 * NOTE:948 *949 * This only filters the mode list supplied to userspace in the950 * GETCONNECTOR IOCTL. Compared to &drm_encoder_helper_funcs.mode_valid,951 * &drm_crtc_helper_funcs.mode_valid and &drm_bridge_funcs.mode_valid,952 * which are also called by the atomic helpers from953 * drm_atomic_helper_check_modeset(). This allows userspace to force and954 * ignore sink constraint (like the pixel clock limits in the screen's955 * EDID), which is useful for e.g. testing, or working around a broken956 * EDID. Any source hardware constraint (which always need to be957 * enforced) therefore should be checked in one of the above callbacks,958 * and not this one here.959 *960 * To avoid races with concurrent connector state updates, the helper961 * libraries always call this with the &drm_mode_config.connection_mutex962 * held. Because of this it's safe to inspect &drm_connector->state.963 *964 * RETURNS:965 *966 * Either &drm_mode_status.MODE_OK or one of the failure reasons in &enum967 * drm_mode_status.968 */969 enum drm_mode_status (*mode_valid)(struct drm_connector *connector,970 struct drm_display_mode *mode);971 972 /**973 * @mode_valid_ctx:974 *975 * Callback to validate a mode for a connector, irrespective of the976 * specific display configuration.977 *978 * This callback is used by the probe helpers to filter the mode list979 * (which is usually derived from the EDID data block from the sink).980 * See e.g. drm_helper_probe_single_connector_modes().981 *982 * This function is optional, and is the atomic version of983 * &drm_connector_helper_funcs.mode_valid.984 *985 * To allow for accessing the atomic state of modesetting objects, the986 * helper libraries always call this with ctx set to a valid context,987 * and &drm_mode_config.connection_mutex will always be locked with988 * the ctx parameter set to @ctx. This allows for taking additional989 * locks as required.990 *991 * Even though additional locks may be acquired, this callback is992 * still expected not to take any constraints into account which would993 * be influenced by the currently set display state - such constraints994 * should be handled in the driver's atomic check. For example, if a995 * connector shares display bandwidth with other connectors then it996 * would be ok to validate the minimum bandwidth requirement of a mode997 * against the maximum possible bandwidth of the connector. But it998 * wouldn't be ok to take the current bandwidth usage of other999 * connectors into account, as this would change depending on the1000 * display state.1001 *1002 * Returns:1003 * 0 if &drm_connector_helper_funcs.mode_valid_ctx succeeded and wrote1004 * the &enum drm_mode_status value to @status, or a negative error1005 * code otherwise.1006 *1007 */1008 int (*mode_valid_ctx)(struct drm_connector *connector,1009 struct drm_display_mode *mode,1010 struct drm_modeset_acquire_ctx *ctx,1011 enum drm_mode_status *status);1012 1013 /**1014 * @best_encoder:1015 *1016 * This function should select the best encoder for the given connector.1017 *1018 * This function is used by both the atomic helpers (in the1019 * drm_atomic_helper_check_modeset() function) and in the legacy CRTC1020 * helpers.1021 *1022 * NOTE:1023 *1024 * In atomic drivers this function is called in the check phase of an1025 * atomic update. The driver is not allowed to change or inspect1026 * anything outside of arguments passed-in. Atomic drivers which need to1027 * inspect dynamic configuration state should instead use1028 * @atomic_best_encoder.1029 *1030 * You can leave this function to NULL if the connector is only1031 * attached to a single encoder. In this case, the core will call1032 * drm_connector_get_single_encoder() for you.1033 *1034 * RETURNS:1035 *1036 * Encoder that should be used for the given connector and connector1037 * state, or NULL if no suitable encoder exists. Note that the helpers1038 * will ensure that encoders aren't used twice, drivers should not check1039 * for this.1040 */1041 struct drm_encoder *(*best_encoder)(struct drm_connector *connector);1042 1043 /**1044 * @atomic_best_encoder:1045 *1046 * This is the atomic version of @best_encoder for atomic drivers which1047 * need to select the best encoder depending upon the desired1048 * configuration and can't select it statically.1049 *1050 * This function is used by drm_atomic_helper_check_modeset().1051 * If it is not implemented, the core will fallback to @best_encoder1052 * (or drm_connector_get_single_encoder() if @best_encoder is NULL).1053 *1054 * NOTE:1055 *1056 * This function is called in the check phase of an atomic update. The1057 * driver is not allowed to change anything outside of the1058 * &drm_atomic_state update tracking structure passed in.1059 *1060 * RETURNS:1061 *1062 * Encoder that should be used for the given connector and connector1063 * state, or NULL if no suitable encoder exists. Note that the helpers1064 * will ensure that encoders aren't used twice, drivers should not check1065 * for this.1066 */1067 struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,1068 struct drm_atomic_state *state);1069 1070 /**1071 * @atomic_check:1072 *1073 * This hook is used to validate connector state. This function is1074 * called from &drm_atomic_helper_check_modeset, and is called when1075 * a connector property is set, or a modeset on the crtc is forced.1076 *1077 * Because &drm_atomic_helper_check_modeset may be called multiple times,1078 * this function should handle being called multiple times as well.1079 *1080 * This function is also allowed to inspect any other object's state and1081 * can add more state objects to the atomic commit if needed. Care must1082 * be taken though to ensure that state check and compute functions for1083 * these added states are all called, and derived state in other objects1084 * all updated. Again the recommendation is to just call check helpers1085 * until a maximal configuration is reached.1086 *1087 * NOTE:1088 *1089 * This function is called in the check phase of an atomic update. The1090 * driver is not allowed to change anything outside of the free-standing1091 * state objects passed-in or assembled in the overall &drm_atomic_state1092 * update tracking structure.1093 *1094 * RETURNS:1095 *1096 * 0 on success, -EINVAL if the state or the transition can't be1097 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an1098 * attempt to obtain another state object ran into a &drm_modeset_lock1099 * deadlock.1100 */1101 int (*atomic_check)(struct drm_connector *connector,1102 struct drm_atomic_state *state);1103 1104 /**1105 * @atomic_commit:1106 *1107 * This hook is to be used by drivers implementing writeback connectors1108 * that need a point when to commit the writeback job to the hardware.1109 * The writeback_job to commit is available in the new connector state,1110 * in &drm_connector_state.writeback_job.1111 *1112 * This hook is optional.1113 *1114 * This callback is used by the atomic modeset helpers.1115 */1116 void (*atomic_commit)(struct drm_connector *connector,1117 struct drm_atomic_state *state);1118 1119 /**1120 * @prepare_writeback_job:1121 *1122 * As writeback jobs contain a framebuffer, drivers may need to1123 * prepare and clean them up the same way they can prepare and1124 * clean up framebuffers for planes. This optional connector operation1125 * is used to support the preparation of writeback jobs. The job1126 * prepare operation is called from drm_atomic_helper_prepare_planes()1127 * for struct &drm_writeback_connector connectors only.1128 *1129 * This operation is optional.1130 *1131 * This callback is used by the atomic modeset helpers.1132 */1133 int (*prepare_writeback_job)(struct drm_writeback_connector *connector,1134 struct drm_writeback_job *job);1135 /**1136 * @cleanup_writeback_job:1137 *1138 * This optional connector operation is used to support the1139 * cleanup of writeback jobs. The job cleanup operation is called1140 * from the existing drm_writeback_cleanup_job() function, invoked1141 * both when destroying the job as part of an aborted commit, or when1142 * the job completes.1143 *1144 * This operation is optional.1145 *1146 * This callback is used by the atomic modeset helpers.1147 */1148 void (*cleanup_writeback_job)(struct drm_writeback_connector *connector,1149 struct drm_writeback_job *job);1150 1151 /**1152 * @enable_hpd:1153 *1154 * Enable hot-plug detection for the connector.1155 *1156 * This operation is optional.1157 *1158 * This callback is used by the drm_kms_helper_poll_enable() helpers.1159 *1160 * This operation does not need to perform any hpd state tracking as1161 * the DRM core handles that maintenance and ensures the calls to enable1162 * and disable hpd are balanced.1163 *1164 */1165 void (*enable_hpd)(struct drm_connector *connector);1166 1167 /**1168 * @disable_hpd:1169 *1170 * Disable hot-plug detection for the connector.1171 *1172 * This operation is optional.1173 *1174 * This callback is used by the drm_kms_helper_poll_disable() helpers.1175 *1176 * This operation does not need to perform any hpd state tracking as1177 * the DRM core handles that maintenance and ensures the calls to enable1178 * and disable hpd are balanced.1179 *1180 */1181 void (*disable_hpd)(struct drm_connector *connector);1182};1183 1184/**1185 * drm_connector_helper_add - sets the helper vtable for a connector1186 * @connector: DRM connector1187 * @funcs: helper vtable to set for @connector1188 */1189static inline void drm_connector_helper_add(struct drm_connector *connector,1190 const struct drm_connector_helper_funcs *funcs)1191{1192 connector->helper_private = funcs;1193}1194 1195/**1196 * struct drm_plane_helper_funcs - helper operations for planes1197 *1198 * These functions are used by the atomic helpers.1199 */1200struct drm_plane_helper_funcs {1201 /**1202 * @prepare_fb:1203 *1204 * This hook is to prepare a framebuffer for scanout by e.g. pinning1205 * its backing storage or relocating it into a contiguous block of1206 * VRAM. Other possible preparatory work includes flushing caches.1207 *1208 * This function must not block for outstanding rendering, since it is1209 * called in the context of the atomic IOCTL even for async commits to1210 * be able to return any errors to userspace. Instead the recommended1211 * way is to fill out the &drm_plane_state.fence of the passed-in1212 * &drm_plane_state. If the driver doesn't support native fences then1213 * equivalent functionality should be implemented through private1214 * members in the plane structure.1215 *1216 * For GEM drivers who neither have a @prepare_fb nor @cleanup_fb hook1217 * set drm_gem_plane_helper_prepare_fb() is called automatically to1218 * implement this. Other drivers which need additional plane processing1219 * can call drm_gem_plane_helper_prepare_fb() from their @prepare_fb1220 * hook.1221 *1222 * The resources acquired in @prepare_fb persist after the end of1223 * the atomic commit. Resources that can be release at the commit's end1224 * should be acquired in @begin_fb_access and released in @end_fb_access.1225 * For example, a GEM buffer's pin operation belongs into @prepare_fb to1226 * keep the buffer pinned after the commit. But a vmap operation for1227 * shadow-plane helpers belongs into @begin_fb_access, so that atomic1228 * helpers remove the mapping at the end of the commit.1229 *1230 * The helpers will call @cleanup_fb with matching arguments for every1231 * successful call to this hook.1232 *1233 * This callback is used by the atomic modeset helpers, but it is1234 * optional. See @begin_fb_access for preparing per-commit resources.1235 *1236 * RETURNS:1237 *1238 * 0 on success or one of the following negative error codes allowed by1239 * the &drm_mode_config_funcs.atomic_commit vfunc. When using helpers1240 * this callback is the only one which can fail an atomic commit,1241 * everything else must complete successfully.1242 */1243 int (*prepare_fb)(struct drm_plane *plane,1244 struct drm_plane_state *new_state);1245 /**1246 * @cleanup_fb:1247 *1248 * This hook is called to clean up any resources allocated for the given1249 * framebuffer and plane configuration in @prepare_fb.1250 *1251 * This callback is used by the atomic modeset helpers, but it is1252 * optional.1253 */1254 void (*cleanup_fb)(struct drm_plane *plane,1255 struct drm_plane_state *old_state);1256 1257 /**1258 * @begin_fb_access:1259 *1260 * This hook prepares the plane for access during an atomic commit.1261 * In contrast to @prepare_fb, resources acquired in @begin_fb_access,1262 * are released at the end of the atomic commit in @end_fb_access.1263 *1264 * For example, with shadow-plane helpers, the GEM buffer's vmap1265 * operation belongs into @begin_fb_access, so that the buffer's1266 * memory will be unmapped at the end of the commit in @end_fb_access.1267 * But a GEM buffer's pin operation belongs into @prepare_fb1268 * to keep the buffer pinned after the commit.1269 *1270 * The callback is used by the atomic modeset helpers, but it is optional.1271 * See @end_fb_cleanup for undoing the effects of @begin_fb_access and1272 * @prepare_fb for acquiring resources until the next pageflip.1273 *1274 * Returns:1275 * 0 on success, or a negative errno code otherwise.1276 */1277 int (*begin_fb_access)(struct drm_plane *plane, struct drm_plane_state *new_plane_state);1278 1279 /**1280 * @end_fb_access:1281 *1282 * This hook cleans up resources allocated by @begin_fb_access. It it called1283 * at the end of a commit for the new plane state.1284 */1285 void (*end_fb_access)(struct drm_plane *plane, struct drm_plane_state *new_plane_state);1286 1287 /**1288 * @atomic_check:1289 *1290 * Drivers should check plane specific constraints in this hook.1291 *1292 * When using drm_atomic_helper_check_planes() plane's @atomic_check1293 * hooks are called before the ones for CRTCs, which allows drivers to1294 * request shared resources that the CRTC controls here. For more1295 * complicated dependencies the driver can call the provided check helpers1296 * multiple times until the computed state has a final configuration and1297 * everything has been checked.1298 *1299 * This function is also allowed to inspect any other object's state and1300 * can add more state objects to the atomic commit if needed. Care must1301 * be taken though to ensure that state check and compute functions for1302 * these added states are all called, and derived state in other objects1303 * all updated. Again the recommendation is to just call check helpers1304 * until a maximal configuration is reached.1305 *1306 * This callback is used by the atomic modeset helpers, but it is1307 * optional.1308 *1309 * NOTE:1310 *1311 * This function is called in the check phase of an atomic update. The1312 * driver is not allowed to change anything outside of the1313 * &drm_atomic_state update tracking structure.1314 *1315 * RETURNS:1316 *1317 * 0 on success, -EINVAL if the state or the transition can't be1318 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an1319 * attempt to obtain another state object ran into a &drm_modeset_lock1320 * deadlock.1321 */1322 int (*atomic_check)(struct drm_plane *plane,1323 struct drm_atomic_state *state);1324 1325 /**1326 * @atomic_update:1327 *1328 * Drivers should use this function to update the plane state. This1329 * hook is called in-between the &drm_crtc_helper_funcs.atomic_begin and1330 * drm_crtc_helper_funcs.atomic_flush callbacks.1331 *1332 * Note that the power state of the display pipe when this function is1333 * called depends upon the exact helpers and calling sequence the driver1334 * has picked. See drm_atomic_helper_commit_planes() for a discussion of1335 * the tradeoffs and variants of plane commit helpers.1336 *1337 * This callback is used by the atomic modeset helpers, but it is optional.1338 */1339 void (*atomic_update)(struct drm_plane *plane,1340 struct drm_atomic_state *state);1341 1342 /**1343 * @atomic_enable:1344 *1345 * Drivers should use this function to unconditionally enable a plane.1346 * This hook is called in-between the &drm_crtc_helper_funcs.atomic_begin1347 * and drm_crtc_helper_funcs.atomic_flush callbacks. It is called after1348 * @atomic_update, which will be called for all enabled planes. Drivers1349 * that use @atomic_enable should set up a plane in @atomic_update and1350 * afterwards enable the plane in @atomic_enable. If a plane needs to be1351 * enabled before installing the scanout buffer, drivers can still do1352 * so in @atomic_update.1353 *1354 * Note that the power state of the display pipe when this function is1355 * called depends upon the exact helpers and calling sequence the driver1356 * has picked. See drm_atomic_helper_commit_planes() for a discussion of1357 * the tradeoffs and variants of plane commit helpers.1358 *1359 * This callback is used by the atomic modeset helpers, but it is1360 * optional. If implemented, @atomic_enable should be the inverse of1361 * @atomic_disable. Drivers that don't want to use either can still1362 * implement the complete plane update in @atomic_update.1363 */1364 void (*atomic_enable)(struct drm_plane *plane,1365 struct drm_atomic_state *state);1366 1367 /**1368 * @atomic_disable:1369 *1370 * Drivers should use this function to unconditionally disable a plane.1371 * This hook is called in-between the1372 * &drm_crtc_helper_funcs.atomic_begin and1373 * drm_crtc_helper_funcs.atomic_flush callbacks. It is an alternative to1374 * @atomic_update, which will be called for disabling planes, too, if1375 * the @atomic_disable hook isn't implemented.1376 *1377 * This hook is also useful to disable planes in preparation of a modeset,1378 * by calling drm_atomic_helper_disable_planes_on_crtc() from the1379 * &drm_crtc_helper_funcs.disable hook.1380 *1381 * Note that the power state of the display pipe when this function is1382 * called depends upon the exact helpers and calling sequence the driver1383 * has picked. See drm_atomic_helper_commit_planes() for a discussion of1384 * the tradeoffs and variants of plane commit helpers.1385 *1386 * This callback is used by the atomic modeset helpers, but it is1387 * optional. It's intended to reverse the effects of @atomic_enable.1388 */1389 void (*atomic_disable)(struct drm_plane *plane,1390 struct drm_atomic_state *state);1391 1392 /**1393 * @atomic_async_check:1394 *1395 * Drivers should set this function pointer to check if the plane's1396 * atomic state can be updated in a async fashion. Here async means1397 * "not vblank synchronized".1398 *1399 * This hook is called by drm_atomic_async_check() to establish if a1400 * given update can be committed asynchronously, that is, if it can1401 * jump ahead of the state currently queued for update.1402 *1403 * RETURNS:1404 *1405 * Return 0 on success and any error returned indicates that the update1406 * can not be applied in asynchronous manner.1407 */1408 int (*atomic_async_check)(struct drm_plane *plane,1409 struct drm_atomic_state *state);1410 1411 /**1412 * @atomic_async_update:1413 *1414 * Drivers should set this function pointer to perform asynchronous1415 * updates of planes, that is, jump ahead of the currently queued1416 * state and update the plane. Here async means "not vblank1417 * synchronized".1418 *1419 * This hook is called by drm_atomic_helper_async_commit().1420 *1421 * An async update will happen on legacy cursor updates. An async1422 * update won't happen if there is an outstanding commit modifying1423 * the same plane.1424 *1425 * When doing async_update drivers shouldn't replace the1426 * &drm_plane_state but update the current one with the new plane1427 * configurations in the new plane_state.1428 *1429 * Drivers should also swap the framebuffers between current plane1430 * state (&drm_plane.state) and new_state.1431 * This is required since cleanup for async commits is performed on1432 * the new state, rather than old state like for traditional commits.1433 * Since we want to give up the reference on the current (old) fb1434 * instead of our brand new one, swap them in the driver during the1435 * async commit.1436 *1437 * FIXME:1438 * - It only works for single plane updates1439 * - Async Pageflips are not supported yet1440 * - Some hw might still scan out the old buffer until the next1441 * vblank, however we let go of the fb references as soon as1442 * we run this hook. For now drivers must implement their own workers1443 * for deferring if needed, until a common solution is created.1444 */1445 void (*atomic_async_update)(struct drm_plane *plane,1446 struct drm_atomic_state *state);1447 1448 /**1449 * @get_scanout_buffer:1450 *1451 * Get the current scanout buffer, to display a message with drm_panic.1452 * The driver should do the minimum changes to provide a buffer,1453 * that can be used to display the panic screen. Currently only linear1454 * buffers are supported. Non-linear buffer support is on the TODO list.1455 * The device &dev.mode_config.panic_lock is taken before calling this1456 * function, so you can safely access the &plane.state1457 * It is called from a panic callback, and must follow its restrictions.1458 * Please look the documentation at drm_panic_trylock() for an in-depth1459 * discussions of what's safe and what is not allowed.1460 * It's a best effort mode, so it's expected that in some complex cases1461 * the panic screen won't be displayed.1462 * The returned &drm_scanout_buffer.map must be valid if no error code is1463 * returned.1464 *1465 * Return:1466 * %0 on success, negative errno on failure.1467 */1468 int (*get_scanout_buffer)(struct drm_plane *plane,1469 struct drm_scanout_buffer *sb);1470 1471 /**1472 * @panic_flush:1473 *1474 * It is used by drm_panic, and is called after the panic screen is1475 * drawn to the scanout buffer. In this function, the driver1476 * can send additional commands to the hardware, to make the scanout1477 * buffer visible.1478 * It is only called if get_scanout_buffer() returned successfully, and1479 * the &dev.mode_config.panic_lock is held during the entire sequence.1480 * It is called from a panic callback, and must follow its restrictions.1481 * Please look the documentation at drm_panic_trylock() for an in-depth1482 * discussions of what's safe and what is not allowed.1483 */1484 void (*panic_flush)(struct drm_plane *plane);1485};1486 1487/**1488 * drm_plane_helper_add - sets the helper vtable for a plane1489 * @plane: DRM plane1490 * @funcs: helper vtable to set for @plane1491 */1492static inline void drm_plane_helper_add(struct drm_plane *plane,1493 const struct drm_plane_helper_funcs *funcs)1494{1495 plane->helper_private = funcs;1496}1497 1498/**1499 * struct drm_mode_config_helper_funcs - global modeset helper operations1500 *1501 * These helper functions are used by the atomic helpers.1502 */1503struct drm_mode_config_helper_funcs {1504 /**1505 * @atomic_commit_tail:1506 *1507 * This hook is used by the default atomic_commit() hook implemented in1508 * drm_atomic_helper_commit() together with the nonblocking commit1509 * helpers (see drm_atomic_helper_setup_commit() for a starting point)1510 * to implement blocking and nonblocking commits easily. It is not used1511 * by the atomic helpers1512 *1513 * This function is called when the new atomic state has already been1514 * swapped into the various state pointers. The passed in state1515 * therefore contains copies of the old/previous state. This hook should1516 * commit the new state into hardware. Note that the helpers have1517 * already waited for preceding atomic commits and fences, but drivers1518 * can add more waiting calls at the start of their implementation, e.g.1519 * to wait for driver-internal request for implicit syncing, before1520 * starting to commit the update to the hardware.1521 *1522 * After the atomic update is committed to the hardware this hook needs1523 * to call drm_atomic_helper_commit_hw_done(). Then wait for the update1524 * to be executed by the hardware, for example using1525 * drm_atomic_helper_wait_for_vblanks() or1526 * drm_atomic_helper_wait_for_flip_done(), and then clean up the old1527 * framebuffers using drm_atomic_helper_cleanup_planes().1528 *1529 * When disabling a CRTC this hook _must_ stall for the commit to1530 * complete. Vblank waits don't work on disabled CRTC, hence the core1531 * can't take care of this. And it also can't rely on the vblank event,1532 * since that can be signalled already when the screen shows black,1533 * which can happen much earlier than the last hardware access needed to1534 * shut off the display pipeline completely.1535 *1536 * This hook is optional, the default implementation is1537 * drm_atomic_helper_commit_tail().1538 */1539 void (*atomic_commit_tail)(struct drm_atomic_state *state);1540 1541 /**1542 * @atomic_commit_setup:1543 *1544 * This hook is used by the default atomic_commit() hook implemented in1545 * drm_atomic_helper_commit() together with the nonblocking helpers (see1546 * drm_atomic_helper_setup_commit()) to extend the DRM commit setup. It1547 * is not used by the atomic helpers.1548 *1549 * This function is called at the end of1550 * drm_atomic_helper_setup_commit(), so once the commit has been1551 * properly setup across the generic DRM object states. It allows1552 * drivers to do some additional commit tracking that isn't related to a1553 * CRTC, plane or connector, tracked in a &drm_private_obj structure.1554 *1555 * Note that the documentation of &drm_private_obj has more details on1556 * how one should implement this.1557 *1558 * This hook is optional.1559 */1560 int (*atomic_commit_setup)(struct drm_atomic_state *state);1561};1562 1563#endif1564