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>
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:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
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.
29 #ifndef __DRM_MODESET_HELPER_VTABLES_H__
30 #define __DRM_MODESET_HELPER_VTABLES_H__
32 #include <drm/drm_crtc.h>
33 #include <drm/drm_encoder.h>
38 * The DRM mode setting helper functions are common code for drivers to use if
39 * they wish. Drivers are not forced to use this code in their
40 * implementations but it would be useful if the code they do use at least
41 * provides a consistent interface and operation to userspace. Therefore it is
42 * highly recommended to use the provided helpers as much as possible.
44 * Because there is only one pointer per modeset object to hold a vfunc table
45 * for helper libraries they are by necessity shared among the different
48 * To make this clear all the helper vtables are pulled together in this location here.
54 * struct drm_crtc_helper_funcs - helper operations for CRTCs
56 * These hooks are used by the legacy CRTC helpers, the transitional plane
57 * helpers and the new atomic modesetting helpers.
59 struct drm_crtc_helper_funcs
{
63 * Callback to control power levels on the CRTC. If the mode passed in
64 * is unsupported, the provider must use the next lowest power level.
65 * This is used by the legacy CRTC helpers to implement DPMS
66 * functionality in drm_helper_connector_dpms().
68 * This callback is also used to disable a CRTC by calling it with
69 * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
71 * This callback is used by the legacy CRTC helpers. Atomic helpers
72 * also support using this hook for enabling and disabling a CRTC to
73 * facilitate transitions to atomic, but it is deprecated. Instead
74 * @enable and @disable should be used.
76 void (*dpms
)(struct drm_crtc
*crtc
, int mode
);
81 * This callback should prepare the CRTC for a subsequent modeset, which
82 * in practice means the driver should disable the CRTC if it is
83 * running. Most drivers ended up implementing this by calling their
84 * @dpms hook with DRM_MODE_DPMS_OFF.
86 * This callback is used by the legacy CRTC helpers. Atomic helpers
87 * also support using this hook for disabling a CRTC to facilitate
88 * transitions to atomic, but it is deprecated. Instead @disable should
91 void (*prepare
)(struct drm_crtc
*crtc
);
96 * This callback should commit the new mode on the CRTC after a modeset,
97 * which in practice means the driver should enable the CRTC. Most
98 * drivers ended up implementing this by calling their @dpms hook with
101 * This callback is used by the legacy CRTC helpers. Atomic helpers
102 * also support using this hook for enabling a CRTC to facilitate
103 * transitions to atomic, but it is deprecated. Instead @enable should
106 void (*commit
)(struct drm_crtc
*crtc
);
111 * This callback is used to check if a specific mode is valid in this
112 * crtc. This should be implemented if the crtc has some sort of
113 * restriction in the modes it can display. For example, a given crtc
114 * may be responsible to set a clock value. If the clock can not
115 * produce all the values for the available modes then this callback
116 * can be used to restrict the number of modes to only the ones that
119 * This hook is used by the probe helpers to filter the mode list in
120 * drm_helper_probe_single_connector_modes(), and it is used by the
121 * atomic helpers to validate modes supplied by userspace in
122 * drm_atomic_helper_check_modeset().
124 * This function is optional.
128 * Since this function is both called from the check phase of an atomic
129 * commit, and the mode validation in the probe paths it is not allowed
130 * to look at anything else but the passed-in mode, and validate it
131 * against configuration-invariant hardward constraints. Any further
132 * limits which depend upon the configuration can only be checked in
133 * @mode_fixup or @atomic_check.
137 * drm_mode_status Enum
139 enum drm_mode_status (*mode_valid
)(struct drm_crtc
*crtc
,
140 const struct drm_display_mode
*mode
);
145 * This callback is used to validate a mode. The parameter mode is the
146 * display mode that userspace requested, adjusted_mode is the mode the
147 * encoders need to be fed with. Note that this is the inverse semantics
148 * of the meaning for the &drm_encoder and &drm_bridge_funcs.mode_fixup
149 * vfunc. If the CRTC cannot support the requested conversion from mode
150 * to adjusted_mode it should reject the modeset.
152 * This function is used by both legacy CRTC helpers and atomic helpers.
153 * With atomic helpers it is optional.
157 * This function is called in the check phase of atomic modesets, which
158 * can be aborted for any reason (including on userspace's request to
159 * just check whether a configuration would be possible). Atomic drivers
160 * MUST NOT touch any persistent state (hardware or software) or data
161 * structures except the passed in adjusted_mode parameter.
163 * This is in contrast to the legacy CRTC helpers where this was
166 * Atomic drivers which need to inspect and adjust more state should
167 * instead use the @atomic_check callback.
169 * Also beware that userspace can request its own custom modes, neither
170 * core nor helpers filter modes to the list of probe modes reported by
171 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
172 * that modes are filtered consistently put any CRTC constraints and
173 * limits checks into @mode_valid.
177 * True if an acceptable configuration is possible, false if the modeset
178 * operation should be rejected.
180 bool (*mode_fixup
)(struct drm_crtc
*crtc
,
181 const struct drm_display_mode
*mode
,
182 struct drm_display_mode
*adjusted_mode
);
187 * This callback is used by the legacy CRTC helpers to set a new mode,
188 * position and framebuffer. Since it ties the primary plane to every
189 * mode change it is incompatible with universal plane support. And
190 * since it can't update other planes it's incompatible with atomic
193 * This callback is only used by CRTC helpers and deprecated.
197 * 0 on success or a negative error code on failure.
199 int (*mode_set
)(struct drm_crtc
*crtc
, struct drm_display_mode
*mode
,
200 struct drm_display_mode
*adjusted_mode
, int x
, int y
,
201 struct drm_framebuffer
*old_fb
);
206 * This callback is used to update the display mode of a CRTC without
207 * changing anything of the primary plane configuration. This fits the
208 * requirement of atomic and hence is used by the atomic helpers. It is
209 * also used by the transitional plane helpers to implement a
210 * @mode_set hook in drm_helper_crtc_mode_set().
212 * Note that the display pipe is completely off when this function is
213 * called. Atomic drivers which need hardware to be running before they
214 * program the new display mode (e.g. because they implement runtime PM)
215 * should not use this hook. This is because the helper library calls
216 * this hook only once per mode change and not every time the display
217 * pipeline is suspended using either DPMS or the new "ACTIVE" property.
218 * Which means register values set in this callback might get reset when
219 * the CRTC is suspended, but not restored. Such drivers should instead
220 * move all their CRTC setup into the @enable callback.
222 * This callback is optional.
224 void (*mode_set_nofb
)(struct drm_crtc
*crtc
);
229 * This callback is used by the legacy CRTC helpers to set a new
230 * framebuffer and scanout position. It is optional and used as an
231 * optimized fast-path instead of a full mode set operation with all the
232 * resulting flickering. If it is not present
233 * drm_crtc_helper_set_config() will fall back to a full modeset, using
234 * the @mode_set callback. Since it can't update other planes it's
235 * incompatible with atomic modeset support.
237 * This callback is only used by the CRTC helpers and deprecated.
241 * 0 on success or a negative error code on failure.
243 int (*mode_set_base
)(struct drm_crtc
*crtc
, int x
, int y
,
244 struct drm_framebuffer
*old_fb
);
247 * @mode_set_base_atomic:
249 * This callback is used by the fbdev helpers to set a new framebuffer
250 * and scanout without sleeping, i.e. from an atomic calling context. It
251 * is only used to implement kgdb support.
253 * This callback is optional and only needed for kgdb support in the fbdev
258 * 0 on success or a negative error code on failure.
260 int (*mode_set_base_atomic
)(struct drm_crtc
*crtc
,
261 struct drm_framebuffer
*fb
, int x
, int y
,
262 enum mode_set_atomic
);
267 * Load a LUT prepared with the &drm_fb_helper_funcs.gamma_set vfunc.
269 * This callback is optional and is only used by the fbdev emulation
274 * This callback is functionally redundant with the core gamma table
275 * support and simply exists because the fbdev hasn't yet been
276 * refactored to use the core gamma table interfaces.
278 void (*load_lut
)(struct drm_crtc
*crtc
);
283 * This callback should be used to disable the CRTC. With the atomic
284 * drivers it is called after all encoders connected to this CRTC have
285 * been shut off already using their own
286 * &drm_encoder_helper_funcs.disable hook. If that sequence is too
287 * simple drivers can just add their own hooks and call it from this
288 * CRTC callback here by looping over all encoders connected to it using
289 * for_each_encoder_on_crtc().
291 * This hook is used both by legacy CRTC helpers and atomic helpers.
292 * Atomic drivers don't need to implement it if there's no need to
293 * disable anything at the CRTC level. To ensure that runtime PM
294 * handling (using either DPMS or the new "ACTIVE" property) works
295 * @disable must be the inverse of @enable for atomic drivers.
296 * Atomic drivers should consider to use @atomic_disable instead of
301 * With legacy CRTC helpers there's a big semantic difference between
302 * @disable and other hooks (like @prepare or @dpms) used to shut down a
303 * CRTC: @disable is only called when also logically disabling the
304 * display pipeline and needs to release any resources acquired in
305 * @mode_set (like shared PLLs, or again release pinned framebuffers).
307 * Therefore @disable must be the inverse of @mode_set plus @commit for
308 * drivers still using legacy CRTC helpers, which is different from the
309 * rules under atomic.
311 void (*disable
)(struct drm_crtc
*crtc
);
316 * This callback should be used to enable the CRTC. With the atomic
317 * drivers it is called before all encoders connected to this CRTC are
318 * enabled through the encoder's own &drm_encoder_helper_funcs.enable
319 * hook. If that sequence is too simple drivers can just add their own
320 * hooks and call it from this CRTC callback here by looping over all
321 * encoders connected to it using for_each_encoder_on_crtc().
323 * This hook is used only by atomic helpers, for symmetry with @disable.
324 * Atomic drivers don't need to implement it if there's no need to
325 * enable anything at the CRTC level. To ensure that runtime PM handling
326 * (using either DPMS or the new "ACTIVE" property) works
327 * @enable must be the inverse of @disable for atomic drivers.
329 void (*enable
)(struct drm_crtc
*crtc
);
334 * Drivers should check plane-update related CRTC constraints in this
335 * hook. They can also check mode related limitations but need to be
336 * aware of the calling order, since this hook is used by
337 * drm_atomic_helper_check_planes() whereas the preparations needed to
338 * check output routing and the display mode is done in
339 * drm_atomic_helper_check_modeset(). Therefore drivers that want to
340 * check output routing and display mode constraints in this callback
341 * must ensure that drm_atomic_helper_check_modeset() has been called
342 * beforehand. This is calling order used by the default helper
343 * implementation in drm_atomic_helper_check().
345 * When using drm_atomic_helper_check_planes() this hook is called
346 * after the &drm_plane_helper_funcs.atomc_check hook for planes, which
347 * allows drivers to assign shared resources requested by planes in this
348 * callback here. For more complicated dependencies the driver can call
349 * the provided check helpers multiple times until the computed state
350 * has a final configuration and everything has been checked.
352 * This function is also allowed to inspect any other object's state and
353 * can add more state objects to the atomic commit if needed. Care must
354 * be taken though to ensure that state check and compute functions for
355 * these added states are all called, and derived state in other objects
356 * all updated. Again the recommendation is to just call check helpers
357 * until a maximal configuration is reached.
359 * This callback is used by the atomic modeset helpers and by the
360 * transitional plane helpers, but it is optional.
364 * This function is called in the check phase of an atomic update. The
365 * driver is not allowed to change anything outside of the free-standing
366 * state objects passed-in or assembled in the overall &drm_atomic_state
367 * update tracking structure.
369 * Also beware that userspace can request its own custom modes, neither
370 * core nor helpers filter modes to the list of probe modes reported by
371 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
372 * that modes are filtered consistently put any CRTC constraints and
373 * limits checks into @mode_valid.
377 * 0 on success, -EINVAL if the state or the transition can't be
378 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
379 * attempt to obtain another state object ran into a &drm_modeset_lock
382 int (*atomic_check
)(struct drm_crtc
*crtc
,
383 struct drm_crtc_state
*state
);
388 * Drivers should prepare for an atomic update of multiple planes on
389 * a CRTC in this hook. Depending upon hardware this might be vblank
390 * evasion, blocking updates by setting bits or doing preparatory work
391 * for e.g. manual update display.
393 * This hook is called before any plane commit functions are called.
395 * Note that the power state of the display pipe when this function is
396 * called depends upon the exact helpers and calling sequence the driver
397 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
398 * the tradeoffs and variants of plane commit helpers.
400 * This callback is used by the atomic modeset helpers and by the
401 * transitional plane helpers, but it is optional.
403 void (*atomic_begin
)(struct drm_crtc
*crtc
,
404 struct drm_crtc_state
*old_crtc_state
);
408 * Drivers should finalize an atomic update of multiple planes on
409 * a CRTC in this hook. Depending upon hardware this might include
410 * checking that vblank evasion was successful, unblocking updates by
411 * setting bits or setting the GO bit to flush out all updates.
413 * Simple hardware or hardware with special requirements can commit and
414 * flush out all updates for all planes from this hook and forgo all the
415 * other commit hooks for plane updates.
417 * This hook is called after any plane commit functions are called.
419 * Note that the power state of the display pipe when this function is
420 * called depends upon the exact helpers and calling sequence the driver
421 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
422 * the tradeoffs and variants of plane commit helpers.
424 * This callback is used by the atomic modeset helpers and by the
425 * transitional plane helpers, but it is optional.
427 void (*atomic_flush
)(struct drm_crtc
*crtc
,
428 struct drm_crtc_state
*old_crtc_state
);
433 * This callback should be used to disable the CRTC. With the atomic
434 * drivers it is called after all encoders connected to this CRTC have
435 * been shut off already using their own
436 * &drm_encoder_helper_funcs.disable hook. If that sequence is too
437 * simple drivers can just add their own hooks and call it from this
438 * CRTC callback here by looping over all encoders connected to it using
439 * for_each_encoder_on_crtc().
441 * This hook is used only by atomic helpers. Atomic drivers don't
442 * need to implement it if there's no need to disable anything at the
445 * Comparing to @disable, this one provides the additional input
446 * parameter @old_crtc_state which could be used to access the old
447 * state. Atomic drivers should consider to use this one instead
450 void (*atomic_disable
)(struct drm_crtc
*crtc
,
451 struct drm_crtc_state
*old_crtc_state
);
455 * drm_crtc_helper_add - sets the helper vtable for a crtc
457 * @funcs: helper vtable to set for @crtc
459 static inline void drm_crtc_helper_add(struct drm_crtc
*crtc
,
460 const struct drm_crtc_helper_funcs
*funcs
)
462 crtc
->helper_private
= funcs
;
466 * struct drm_encoder_helper_funcs - helper operations for encoders
468 * These hooks are used by the legacy CRTC helpers, the transitional plane
469 * helpers and the new atomic modesetting helpers.
471 struct drm_encoder_helper_funcs
{
475 * Callback to control power levels on the encoder. If the mode passed in
476 * is unsupported, the provider must use the next lowest power level.
477 * This is used by the legacy encoder helpers to implement DPMS
478 * functionality in drm_helper_connector_dpms().
480 * This callback is also used to disable an encoder by calling it with
481 * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
483 * This callback is used by the legacy CRTC helpers. Atomic helpers
484 * also support using this hook for enabling and disabling an encoder to
485 * facilitate transitions to atomic, but it is deprecated. Instead
486 * @enable and @disable should be used.
488 void (*dpms
)(struct drm_encoder
*encoder
, int mode
);
493 * This callback is used to check if a specific mode is valid in this
494 * encoder. This should be implemented if the encoder has some sort
495 * of restriction in the modes it can display. For example, a given
496 * encoder may be responsible to set a clock value. If the clock can
497 * not produce all the values for the available modes then this callback
498 * can be used to restrict the number of modes to only the ones that
501 * This hook is used by the probe helpers to filter the mode list in
502 * drm_helper_probe_single_connector_modes(), and it is used by the
503 * atomic helpers to validate modes supplied by userspace in
504 * drm_atomic_helper_check_modeset().
506 * This function is optional.
510 * Since this function is both called from the check phase of an atomic
511 * commit, and the mode validation in the probe paths it is not allowed
512 * to look at anything else but the passed-in mode, and validate it
513 * against configuration-invariant hardward constraints. Any further
514 * limits which depend upon the configuration can only be checked in
515 * @mode_fixup or @atomic_check.
519 * drm_mode_status Enum
521 enum drm_mode_status (*mode_valid
)(struct drm_encoder
*crtc
,
522 const struct drm_display_mode
*mode
);
527 * This callback is used to validate and adjust a mode. The parameter
528 * mode is the display mode that should be fed to the next element in
529 * the display chain, either the final &drm_connector or a &drm_bridge.
530 * The parameter adjusted_mode is the input mode the encoder requires. It
531 * can be modified by this callback and does not need to match mode.
533 * This function is used by both legacy CRTC helpers and atomic helpers.
534 * This hook is optional.
538 * This function is called in the check phase of atomic modesets, which
539 * can be aborted for any reason (including on userspace's request to
540 * just check whether a configuration would be possible). Atomic drivers
541 * MUST NOT touch any persistent state (hardware or software) or data
542 * structures except the passed in adjusted_mode parameter.
544 * This is in contrast to the legacy CRTC helpers where this was
547 * Atomic drivers which need to inspect and adjust more state should
548 * instead use the @atomic_check callback.
550 * Also beware that userspace can request its own custom modes, neither
551 * core nor helpers filter modes to the list of probe modes reported by
552 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
553 * that modes are filtered consistently put any encoder constraints and
554 * limits checks into @mode_valid.
558 * True if an acceptable configuration is possible, false if the modeset
559 * operation should be rejected.
561 bool (*mode_fixup
)(struct drm_encoder
*encoder
,
562 const struct drm_display_mode
*mode
,
563 struct drm_display_mode
*adjusted_mode
);
568 * This callback should prepare the encoder for a subsequent modeset,
569 * which in practice means the driver should disable the encoder if it
570 * is running. Most drivers ended up implementing this by calling their
571 * @dpms hook with DRM_MODE_DPMS_OFF.
573 * This callback is used by the legacy CRTC helpers. Atomic helpers
574 * also support using this hook for disabling an encoder to facilitate
575 * transitions to atomic, but it is deprecated. Instead @disable should
578 void (*prepare
)(struct drm_encoder
*encoder
);
583 * This callback should commit the new mode on the encoder after a modeset,
584 * which in practice means the driver should enable the encoder. Most
585 * drivers ended up implementing this by calling their @dpms hook with
588 * This callback is used by the legacy CRTC helpers. Atomic helpers
589 * also support using this hook for enabling an encoder to facilitate
590 * transitions to atomic, but it is deprecated. Instead @enable should
593 void (*commit
)(struct drm_encoder
*encoder
);
598 * This callback is used to update the display mode of an encoder.
600 * Note that the display pipe is completely off when this function is
601 * called. Drivers which need hardware to be running before they program
602 * the new display mode (because they implement runtime PM) should not
603 * use this hook, because the helper library calls it only once and not
604 * every time the display pipeline is suspend using either DPMS or the
605 * new "ACTIVE" property. Such drivers should instead move all their
606 * encoder setup into the @enable callback.
608 * This callback is used both by the legacy CRTC helpers and the atomic
609 * modeset helpers. It is optional in the atomic helpers.
613 * If the driver uses the atomic modeset helpers and needs to inspect
614 * the connector state or connector display info during mode setting,
615 * @atomic_mode_set can be used instead.
617 void (*mode_set
)(struct drm_encoder
*encoder
,
618 struct drm_display_mode
*mode
,
619 struct drm_display_mode
*adjusted_mode
);
624 * This callback is used to update the display mode of an encoder.
626 * Note that the display pipe is completely off when this function is
627 * called. Drivers which need hardware to be running before they program
628 * the new display mode (because they implement runtime PM) should not
629 * use this hook, because the helper library calls it only once and not
630 * every time the display pipeline is suspended using either DPMS or the
631 * new "ACTIVE" property. Such drivers should instead move all their
632 * encoder setup into the @enable callback.
634 * This callback is used by the atomic modeset helpers in place of the
635 * @mode_set callback, if set by the driver. It is optional and should
636 * be used instead of @mode_set if the driver needs to inspect the
637 * connector state or display info, since there is no direct way to
638 * go from the encoder to the current connector.
640 void (*atomic_mode_set
)(struct drm_encoder
*encoder
,
641 struct drm_crtc_state
*crtc_state
,
642 struct drm_connector_state
*conn_state
);
647 * This callback is used by the legacy CRTC helpers to work around
648 * deficiencies in its own book-keeping.
650 * Do not use, use atomic helpers instead, which get the book keeping
655 * Currently only nouveau is using this, and as soon as nouveau is
656 * atomic we can ditch this hook.
658 struct drm_crtc
*(*get_crtc
)(struct drm_encoder
*encoder
);
663 * This callback can be used by drivers who want to do detection on the
664 * encoder object instead of in connector functions.
666 * It is not used by any helper and therefore has purely driver-specific
667 * semantics. New drivers shouldn't use this and instead just implement
668 * their own private callbacks.
672 * This should just be converted into a pile of driver vfuncs.
673 * Currently radeon, amdgpu and nouveau are using it.
675 enum drm_connector_status (*detect
)(struct drm_encoder
*encoder
,
676 struct drm_connector
*connector
);
681 * This callback should be used to disable the encoder. With the atomic
682 * drivers it is called before this encoder's CRTC has been shut off
683 * using their own &drm_crtc_helper_funcs.disable hook. If that
684 * sequence is too simple drivers can just add their own driver private
685 * encoder hooks and call them from CRTC's callback by looping over all
686 * encoders connected to it using for_each_encoder_on_crtc().
688 * This hook is used both by legacy CRTC helpers and atomic helpers.
689 * Atomic drivers don't need to implement it if there's no need to
690 * disable anything at the encoder level. To ensure that runtime PM
691 * handling (using either DPMS or the new "ACTIVE" property) works
692 * @disable must be the inverse of @enable for atomic drivers.
696 * With legacy CRTC helpers there's a big semantic difference between
697 * @disable and other hooks (like @prepare or @dpms) used to shut down a
698 * encoder: @disable is only called when also logically disabling the
699 * display pipeline and needs to release any resources acquired in
700 * @mode_set (like shared PLLs, or again release pinned framebuffers).
702 * Therefore @disable must be the inverse of @mode_set plus @commit for
703 * drivers still using legacy CRTC helpers, which is different from the
704 * rules under atomic.
706 void (*disable
)(struct drm_encoder
*encoder
);
711 * This callback should be used to enable the encoder. With the atomic
712 * drivers it is called after this encoder's CRTC has been enabled using
713 * their own &drm_crtc_helper_funcs.enable hook. If that sequence is
714 * too simple drivers can just add their own driver private encoder
715 * hooks and call them from CRTC's callback by looping over all encoders
716 * connected to it using for_each_encoder_on_crtc().
718 * This hook is used only by atomic helpers, for symmetry with @disable.
719 * Atomic drivers don't need to implement it if there's no need to
720 * enable anything at the encoder level. To ensure that runtime PM handling
721 * (using either DPMS or the new "ACTIVE" property) works
722 * @enable must be the inverse of @disable for atomic drivers.
724 void (*enable
)(struct drm_encoder
*encoder
);
729 * This callback is used to validate encoder state for atomic drivers.
730 * Since the encoder is the object connecting the CRTC and connector it
731 * gets passed both states, to be able to validate interactions and
732 * update the CRTC to match what the encoder needs for the requested
735 * This function is used by the atomic helpers, but it is optional.
739 * This function is called in the check phase of an atomic update. The
740 * driver is not allowed to change anything outside of the free-standing
741 * state objects passed-in or assembled in the overall &drm_atomic_state
742 * update tracking structure.
744 * Also beware that userspace can request its own custom modes, neither
745 * core nor helpers filter modes to the list of probe modes reported by
746 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
747 * that modes are filtered consistently put any encoder constraints and
748 * limits checks into @mode_valid.
752 * 0 on success, -EINVAL if the state or the transition can't be
753 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
754 * attempt to obtain another state object ran into a &drm_modeset_lock
757 int (*atomic_check
)(struct drm_encoder
*encoder
,
758 struct drm_crtc_state
*crtc_state
,
759 struct drm_connector_state
*conn_state
);
763 * drm_encoder_helper_add - sets the helper vtable for an encoder
764 * @encoder: DRM encoder
765 * @funcs: helper vtable to set for @encoder
767 static inline void drm_encoder_helper_add(struct drm_encoder
*encoder
,
768 const struct drm_encoder_helper_funcs
*funcs
)
770 encoder
->helper_private
= funcs
;
774 * struct drm_connector_helper_funcs - helper operations for connectors
776 * These functions are used by the atomic and legacy modeset helpers and by the
779 struct drm_connector_helper_funcs
{
783 * This function should fill in all modes currently valid for the sink
784 * into the &drm_connector.probed_modes list. It should also update the
785 * EDID property by calling drm_mode_connector_update_edid_property().
787 * The usual way to implement this is to cache the EDID retrieved in the
788 * probe callback somewhere in the driver-private connector structure.
789 * In this function drivers then parse the modes in the EDID and add
790 * them by calling drm_add_edid_modes(). But connectors that driver a
791 * fixed panel can also manually add specific modes using
792 * drm_mode_probed_add(). Drivers which manually add modes should also
793 * make sure that the &drm_connector.display_info,
794 * &drm_connector.width_mm and &drm_connector.height_mm fields are
797 * Virtual drivers that just want some standard VESA mode with a given
798 * resolution can call drm_add_modes_noedid(), and mark the preferred
799 * one using drm_set_preferred_mode().
801 * Finally drivers that support audio probably want to update the ELD
802 * data, too, using drm_edid_to_eld().
804 * This function is only called after the @detect hook has indicated
805 * that a sink is connected and when the EDID isn't overridden through
806 * sysfs or the kernel commandline.
808 * This callback is used by the probe helpers in e.g.
809 * drm_helper_probe_single_connector_modes().
811 * To avoid races with concurrent connector state updates, the helper
812 * libraries always call this with the &drm_mode_config.connection_mutex
813 * held. Because of this it's safe to inspect &drm_connector->state.
817 * The number of modes added by calling drm_mode_probed_add().
819 int (*get_modes
)(struct drm_connector
*connector
);
824 * Check to see if anything is attached to the connector. The parameter
825 * force is set to false whilst polling, true when checking the
826 * connector due to a user request. force can be used by the driver to
827 * avoid expensive, destructive operations during automated probing.
829 * This callback is optional, if not implemented the connector will be
830 * considered as always being attached.
832 * This is the atomic version of &drm_connector_funcs.detect.
834 * To avoid races against concurrent connector state updates, the
835 * helper libraries always call this with ctx set to a valid context,
836 * and &drm_mode_config.connection_mutex will always be locked with
837 * the ctx parameter set to this ctx. This allows taking additional
842 * &drm_connector_status indicating the connector's status,
843 * or the error code returned by drm_modeset_lock(), -EDEADLK.
845 int (*detect_ctx
)(struct drm_connector
*connector
,
846 struct drm_modeset_acquire_ctx
*ctx
,
852 * Callback to validate a mode for a connector, irrespective of the
853 * specific display configuration.
855 * This callback is used by the probe helpers to filter the mode list
856 * (which is usually derived from the EDID data block from the sink).
857 * See e.g. drm_helper_probe_single_connector_modes().
859 * This function is optional.
863 * This only filters the mode list supplied to userspace in the
864 * GETCONNECTOR IOCTL. Compared to &drm_encoder_helper_funcs.mode_valid,
865 * &drm_crtc_helper_funcs.mode_valid and &drm_bridge_funcs.mode_valid,
866 * which are also called by the atomic helpers from
867 * drm_atomic_helper_check_modeset(). This allows userspace to force and
868 * ignore sink constraint (like the pixel clock limits in the screen's
869 * EDID), which is useful for e.g. testing, or working around a broken
870 * EDID. Any source hardware constraint (which always need to be
871 * enforced) therefore should be checked in one of the above callbacks,
872 * and not this one here.
874 * To avoid races with concurrent connector state updates, the helper
875 * libraries always call this with the &drm_mode_config.connection_mutex
876 * held. Because of this it's safe to inspect &drm_connector->state.
880 * Either &drm_mode_status.MODE_OK or one of the failure reasons in &enum
883 enum drm_mode_status (*mode_valid
)(struct drm_connector
*connector
,
884 struct drm_display_mode
*mode
);
888 * This function should select the best encoder for the given connector.
890 * This function is used by both the atomic helpers (in the
891 * drm_atomic_helper_check_modeset() function) and in the legacy CRTC
896 * In atomic drivers this function is called in the check phase of an
897 * atomic update. The driver is not allowed to change or inspect
898 * anything outside of arguments passed-in. Atomic drivers which need to
899 * inspect dynamic configuration state should instead use
900 * @atomic_best_encoder.
902 * You can leave this function to NULL if the connector is only
903 * attached to a single encoder and you are using the atomic helpers.
904 * In this case, the core will call drm_atomic_helper_best_encoder()
909 * Encoder that should be used for the given connector and connector
910 * state, or NULL if no suitable encoder exists. Note that the helpers
911 * will ensure that encoders aren't used twice, drivers should not check
914 struct drm_encoder
*(*best_encoder
)(struct drm_connector
*connector
);
917 * @atomic_best_encoder:
919 * This is the atomic version of @best_encoder for atomic drivers which
920 * need to select the best encoder depending upon the desired
921 * configuration and can't select it statically.
923 * This function is used by drm_atomic_helper_check_modeset().
924 * If it is not implemented, the core will fallback to @best_encoder
925 * (or drm_atomic_helper_best_encoder() if @best_encoder is NULL).
929 * This function is called in the check phase of an atomic update. The
930 * driver is not allowed to change anything outside of the free-standing
931 * state objects passed-in or assembled in the overall &drm_atomic_state
932 * update tracking structure.
936 * Encoder that should be used for the given connector and connector
937 * state, or NULL if no suitable encoder exists. Note that the helpers
938 * will ensure that encoders aren't used twice, drivers should not check
941 struct drm_encoder
*(*atomic_best_encoder
)(struct drm_connector
*connector
,
942 struct drm_connector_state
*connector_state
);
947 * This hook is used to validate connector state. This function is
948 * called from &drm_atomic_helper_check_modeset, and is called when
949 * a connector property is set, or a modeset on the crtc is forced.
951 * Because &drm_atomic_helper_check_modeset may be called multiple times,
952 * this function should handle being called multiple times as well.
954 * This function is also allowed to inspect any other object's state and
955 * can add more state objects to the atomic commit if needed. Care must
956 * be taken though to ensure that state check and compute functions for
957 * these added states are all called, and derived state in other objects
958 * all updated. Again the recommendation is to just call check helpers
959 * until a maximal configuration is reached.
963 * This function is called in the check phase of an atomic update. The
964 * driver is not allowed to change anything outside of the free-standing
965 * state objects passed-in or assembled in the overall &drm_atomic_state
966 * update tracking structure.
970 * 0 on success, -EINVAL if the state or the transition can't be
971 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
972 * attempt to obtain another state object ran into a &drm_modeset_lock
975 int (*atomic_check
)(struct drm_connector
*connector
,
976 struct drm_connector_state
*state
);
980 * drm_connector_helper_add - sets the helper vtable for a connector
981 * @connector: DRM connector
982 * @funcs: helper vtable to set for @connector
984 static inline void drm_connector_helper_add(struct drm_connector
*connector
,
985 const struct drm_connector_helper_funcs
*funcs
)
987 connector
->helper_private
= funcs
;
991 * struct drm_plane_helper_funcs - helper operations for planes
993 * These functions are used by the atomic helpers and by the transitional plane
996 struct drm_plane_helper_funcs
{
1000 * This hook is to prepare a framebuffer for scanout by e.g. pinning
1001 * it's backing storage or relocating it into a contiguous block of
1002 * VRAM. Other possible preparatory work includes flushing caches.
1004 * This function must not block for outstanding rendering, since it is
1005 * called in the context of the atomic IOCTL even for async commits to
1006 * be able to return any errors to userspace. Instead the recommended
1007 * way is to fill out the fence member of the passed-in
1008 * &drm_plane_state. If the driver doesn't support native fences then
1009 * equivalent functionality should be implemented through private
1010 * members in the plane structure.
1012 * The helpers will call @cleanup_fb with matching arguments for every
1013 * successful call to this hook.
1015 * This callback is used by the atomic modeset helpers and by the
1016 * transitional plane helpers, but it is optional.
1020 * 0 on success or one of the following negative error codes allowed by
1021 * the &drm_mode_config_funcs.atomic_commit vfunc. When using helpers
1022 * this callback is the only one which can fail an atomic commit,
1023 * everything else must complete successfully.
1025 int (*prepare_fb
)(struct drm_plane
*plane
,
1026 struct drm_plane_state
*new_state
);
1030 * This hook is called to clean up any resources allocated for the given
1031 * framebuffer and plane configuration in @prepare_fb.
1033 * This callback is used by the atomic modeset helpers and by the
1034 * transitional plane helpers, but it is optional.
1036 void (*cleanup_fb
)(struct drm_plane
*plane
,
1037 struct drm_plane_state
*old_state
);
1042 * Drivers should check plane specific constraints in this hook.
1044 * When using drm_atomic_helper_check_planes() plane's @atomic_check
1045 * hooks are called before the ones for CRTCs, which allows drivers to
1046 * request shared resources that the CRTC controls here. For more
1047 * complicated dependencies the driver can call the provided check helpers
1048 * multiple times until the computed state has a final configuration and
1049 * everything has been checked.
1051 * This function is also allowed to inspect any other object's state and
1052 * can add more state objects to the atomic commit if needed. Care must
1053 * be taken though to ensure that state check and compute functions for
1054 * these added states are all called, and derived state in other objects
1055 * all updated. Again the recommendation is to just call check helpers
1056 * until a maximal configuration is reached.
1058 * This callback is used by the atomic modeset helpers and by the
1059 * transitional plane helpers, but it is optional.
1063 * This function is called in the check phase of an atomic update. The
1064 * driver is not allowed to change anything outside of the free-standing
1065 * state objects passed-in or assembled in the overall &drm_atomic_state
1066 * update tracking structure.
1070 * 0 on success, -EINVAL if the state or the transition can't be
1071 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
1072 * attempt to obtain another state object ran into a &drm_modeset_lock
1075 int (*atomic_check
)(struct drm_plane
*plane
,
1076 struct drm_plane_state
*state
);
1081 * Drivers should use this function to update the plane state. This
1082 * hook is called in-between the &drm_crtc_helper_funcs.atomic_begin and
1083 * drm_crtc_helper_funcs.atomic_flush callbacks.
1085 * Note that the power state of the display pipe when this function is
1086 * called depends upon the exact helpers and calling sequence the driver
1087 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
1088 * the tradeoffs and variants of plane commit helpers.
1090 * This callback is used by the atomic modeset helpers and by the
1091 * transitional plane helpers, but it is optional.
1093 void (*atomic_update
)(struct drm_plane
*plane
,
1094 struct drm_plane_state
*old_state
);
1098 * Drivers should use this function to unconditionally disable a plane.
1099 * This hook is called in-between the
1100 * &drm_crtc_helper_funcs.atomic_begin and
1101 * drm_crtc_helper_funcs.atomic_flush callbacks. It is an alternative to
1102 * @atomic_update, which will be called for disabling planes, too, if
1103 * the @atomic_disable hook isn't implemented.
1105 * This hook is also useful to disable planes in preparation of a modeset,
1106 * by calling drm_atomic_helper_disable_planes_on_crtc() from the
1107 * &drm_crtc_helper_funcs.disable hook.
1109 * Note that the power state of the display pipe when this function is
1110 * called depends upon the exact helpers and calling sequence the driver
1111 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
1112 * the tradeoffs and variants of plane commit helpers.
1114 * This callback is used by the atomic modeset helpers and by the
1115 * transitional plane helpers, but it is optional.
1117 void (*atomic_disable
)(struct drm_plane
*plane
,
1118 struct drm_plane_state
*old_state
);
1122 * drm_plane_helper_add - sets the helper vtable for a plane
1124 * @funcs: helper vtable to set for @plane
1126 static inline void drm_plane_helper_add(struct drm_plane
*plane
,
1127 const struct drm_plane_helper_funcs
*funcs
)
1129 plane
->helper_private
= funcs
;
1133 * struct drm_mode_config_helper_funcs - global modeset helper operations
1135 * These helper functions are used by the atomic helpers.
1137 struct drm_mode_config_helper_funcs
{
1139 * @atomic_commit_tail:
1141 * This hook is used by the default atomic_commit() hook implemented in
1142 * drm_atomic_helper_commit() together with the nonblocking commit
1143 * helpers (see drm_atomic_helper_setup_commit() for a starting point)
1144 * to implement blocking and nonblocking commits easily. It is not used
1145 * by the atomic helpers
1147 * This function is called when the new atomic state has already been
1148 * swapped into the various state pointers. The passed in state
1149 * therefore contains copies of the old/previous state. This hook should
1150 * commit the new state into hardware. Note that the helpers have
1151 * already waited for preceeding atomic commits and fences, but drivers
1152 * can add more waiting calls at the start of their implementation, e.g.
1153 * to wait for driver-internal request for implicit syncing, before
1154 * starting to commit the update to the hardware.
1156 * After the atomic update is committed to the hardware this hook needs
1157 * to call drm_atomic_helper_commit_hw_done(). Then wait for the upate
1158 * to be executed by the hardware, for example using
1159 * drm_atomic_helper_wait_for_vblanks(), and then clean up the old
1160 * framebuffers using drm_atomic_helper_cleanup_planes().
1162 * When disabling a CRTC this hook _must_ stall for the commit to
1163 * complete. Vblank waits don't work on disabled CRTC, hence the core
1164 * can't take care of this. And it also can't rely on the vblank event,
1165 * since that can be signalled already when the screen shows black,
1166 * which can happen much earlier than the last hardware access needed to
1167 * shut off the display pipeline completely.
1169 * This hook is optional, the default implementation is
1170 * drm_atomic_helper_commit_tail().
1172 void (*atomic_commit_tail
)(struct drm_atomic_state
*state
);