xref: /openbmc/linux/include/drm/drm_modeset_helper_vtables.h (revision 46eeaa11bdd1bc9e077bdf741d32ca7235d263c6)
1092d01daSDaniel Vetter /*
2092d01daSDaniel Vetter  * Copyright © 2006 Keith Packard
3092d01daSDaniel Vetter  * Copyright © 2007-2008 Dave Airlie
4092d01daSDaniel Vetter  * Copyright © 2007-2008 Intel Corporation
5092d01daSDaniel Vetter  *   Jesse Barnes <jesse.barnes@intel.com>
6092d01daSDaniel Vetter  * Copyright © 2011-2013 Intel Corporation
7092d01daSDaniel Vetter  * Copyright © 2015 Intel Corporation
8092d01daSDaniel Vetter  *   Daniel Vetter <daniel.vetter@ffwll.ch>
9092d01daSDaniel Vetter  *
10092d01daSDaniel Vetter  * Permission is hereby granted, free of charge, to any person obtaining a
11092d01daSDaniel Vetter  * copy of this software and associated documentation files (the "Software"),
12092d01daSDaniel Vetter  * to deal in the Software without restriction, including without limitation
13092d01daSDaniel Vetter  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14092d01daSDaniel Vetter  * and/or sell copies of the Software, and to permit persons to whom the
15092d01daSDaniel Vetter  * Software is furnished to do so, subject to the following conditions:
16092d01daSDaniel Vetter  *
17092d01daSDaniel Vetter  * The above copyright notice and this permission notice shall be included in
18092d01daSDaniel Vetter  * all copies or substantial portions of the Software.
19092d01daSDaniel Vetter  *
20092d01daSDaniel Vetter  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21092d01daSDaniel Vetter  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22092d01daSDaniel Vetter  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23092d01daSDaniel Vetter  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
24092d01daSDaniel Vetter  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25092d01daSDaniel Vetter  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26092d01daSDaniel Vetter  * OTHER DEALINGS IN THE SOFTWARE.
27092d01daSDaniel Vetter  */
28092d01daSDaniel Vetter 
29092d01daSDaniel Vetter #ifndef __DRM_MODESET_HELPER_VTABLES_H__
30092d01daSDaniel Vetter #define __DRM_MODESET_HELPER_VTABLES_H__
31092d01daSDaniel Vetter 
32092d01daSDaniel Vetter #include <drm/drm_crtc.h>
339338203cSLaurent Pinchart #include <drm/drm_encoder.h>
34092d01daSDaniel Vetter 
35092d01daSDaniel Vetter /**
36092d01daSDaniel Vetter  * DOC: overview
37092d01daSDaniel Vetter  *
38092d01daSDaniel Vetter  * The DRM mode setting helper functions are common code for drivers to use if
39092d01daSDaniel Vetter  * they wish.  Drivers are not forced to use this code in their
40092d01daSDaniel Vetter  * implementations but it would be useful if the code they do use at least
41092d01daSDaniel Vetter  * provides a consistent interface and operation to userspace. Therefore it is
42092d01daSDaniel Vetter  * highly recommended to use the provided helpers as much as possible.
43092d01daSDaniel Vetter  *
44092d01daSDaniel Vetter  * Because there is only one pointer per modeset object to hold a vfunc table
45092d01daSDaniel Vetter  * for helper libraries they are by necessity shared among the different
46092d01daSDaniel Vetter  * helpers.
47092d01daSDaniel Vetter  *
48092d01daSDaniel Vetter  * To make this clear all the helper vtables are pulled together in this location here.
49092d01daSDaniel Vetter  */
50092d01daSDaniel Vetter 
519d2230dcSLaurent Pinchart struct drm_writeback_connector;
529d2230dcSLaurent Pinchart struct drm_writeback_job;
53092d01daSDaniel Vetter 
547e9a14adSThomas Zimmermann enum mode_set_atomic {
557e9a14adSThomas Zimmermann 	LEAVE_ATOMIC_MODE_SET,
567e9a14adSThomas Zimmermann 	ENTER_ATOMIC_MODE_SET,
577e9a14adSThomas Zimmermann };
587e9a14adSThomas Zimmermann 
59092d01daSDaniel Vetter /**
60092d01daSDaniel Vetter  * struct drm_crtc_helper_funcs - helper operations for CRTCs
61092d01daSDaniel Vetter  *
6281ed7d73SGeert Uytterhoeven  * These hooks are used by the legacy CRTC helpers and the new atomic
6381ed7d73SGeert Uytterhoeven  * modesetting helpers.
64092d01daSDaniel Vetter  */
65092d01daSDaniel Vetter struct drm_crtc_helper_funcs {
6636b66080SDaniel Vetter 	/**
6736b66080SDaniel Vetter 	 * @dpms:
6836b66080SDaniel Vetter 	 *
6936b66080SDaniel Vetter 	 * Callback to control power levels on the CRTC.  If the mode passed in
7036b66080SDaniel Vetter 	 * is unsupported, the provider must use the next lowest power level.
7136b66080SDaniel Vetter 	 * This is used by the legacy CRTC helpers to implement DPMS
7236b66080SDaniel Vetter 	 * functionality in drm_helper_connector_dpms().
7336b66080SDaniel Vetter 	 *
7436b66080SDaniel Vetter 	 * This callback is also used to disable a CRTC by calling it with
7536b66080SDaniel Vetter 	 * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
7636b66080SDaniel Vetter 	 *
7736b66080SDaniel Vetter 	 * This callback is used by the legacy CRTC helpers.  Atomic helpers
7836b66080SDaniel Vetter 	 * also support using this hook for enabling and disabling a CRTC to
7936b66080SDaniel Vetter 	 * facilitate transitions to atomic, but it is deprecated. Instead
800b20a0f8SLaurent Pinchart 	 * @atomic_enable and @atomic_disable should be used.
81092d01daSDaniel Vetter 	 */
82092d01daSDaniel Vetter 	void (*dpms)(struct drm_crtc *crtc, int mode);
8336b66080SDaniel Vetter 
8436b66080SDaniel Vetter 	/**
8536b66080SDaniel Vetter 	 * @prepare:
8636b66080SDaniel Vetter 	 *
8736b66080SDaniel Vetter 	 * This callback should prepare the CRTC for a subsequent modeset, which
8836b66080SDaniel Vetter 	 * in practice means the driver should disable the CRTC if it is
8936b66080SDaniel Vetter 	 * running. Most drivers ended up implementing this by calling their
9036b66080SDaniel Vetter 	 * @dpms hook with DRM_MODE_DPMS_OFF.
9136b66080SDaniel Vetter 	 *
9236b66080SDaniel Vetter 	 * This callback is used by the legacy CRTC helpers.  Atomic helpers
9336b66080SDaniel Vetter 	 * also support using this hook for disabling a CRTC to facilitate
940b20a0f8SLaurent Pinchart 	 * transitions to atomic, but it is deprecated. Instead @atomic_disable
950b20a0f8SLaurent Pinchart 	 * should be used.
9636b66080SDaniel Vetter 	 */
97092d01daSDaniel Vetter 	void (*prepare)(struct drm_crtc *crtc);
9836b66080SDaniel Vetter 
9936b66080SDaniel Vetter 	/**
10036b66080SDaniel Vetter 	 * @commit:
10136b66080SDaniel Vetter 	 *
10236b66080SDaniel Vetter 	 * This callback should commit the new mode on the CRTC after a modeset,
10336b66080SDaniel Vetter 	 * which in practice means the driver should enable the CRTC.  Most
10436b66080SDaniel Vetter 	 * drivers ended up implementing this by calling their @dpms hook with
10536b66080SDaniel Vetter 	 * DRM_MODE_DPMS_ON.
10636b66080SDaniel Vetter 	 *
10736b66080SDaniel Vetter 	 * This callback is used by the legacy CRTC helpers.  Atomic helpers
10836b66080SDaniel Vetter 	 * also support using this hook for enabling a CRTC to facilitate
1090b20a0f8SLaurent Pinchart 	 * transitions to atomic, but it is deprecated. Instead @atomic_enable
1100b20a0f8SLaurent Pinchart 	 * should be used.
11136b66080SDaniel Vetter 	 */
112092d01daSDaniel Vetter 	void (*commit)(struct drm_crtc *crtc);
113092d01daSDaniel Vetter 
11436b66080SDaniel Vetter 	/**
1153eb220a5SJose Abreu 	 * @mode_valid:
1163eb220a5SJose Abreu 	 *
1173eb220a5SJose Abreu 	 * This callback is used to check if a specific mode is valid in this
1183eb220a5SJose Abreu 	 * crtc. This should be implemented if the crtc has some sort of
1193eb220a5SJose Abreu 	 * restriction in the modes it can display. For example, a given crtc
1203eb220a5SJose Abreu 	 * may be responsible to set a clock value. If the clock can not
1213eb220a5SJose Abreu 	 * produce all the values for the available modes then this callback
1223eb220a5SJose Abreu 	 * can be used to restrict the number of modes to only the ones that
1233eb220a5SJose Abreu 	 * can be displayed.
1243eb220a5SJose Abreu 	 *
1253eb220a5SJose Abreu 	 * This hook is used by the probe helpers to filter the mode list in
1263eb220a5SJose Abreu 	 * drm_helper_probe_single_connector_modes(), and it is used by the
1273eb220a5SJose Abreu 	 * atomic helpers to validate modes supplied by userspace in
1283eb220a5SJose Abreu 	 * drm_atomic_helper_check_modeset().
1293eb220a5SJose Abreu 	 *
1303eb220a5SJose Abreu 	 * This function is optional.
1313eb220a5SJose Abreu 	 *
1323eb220a5SJose Abreu 	 * NOTE:
1333eb220a5SJose Abreu 	 *
1343eb220a5SJose Abreu 	 * Since this function is both called from the check phase of an atomic
1353eb220a5SJose Abreu 	 * commit, and the mode validation in the probe paths it is not allowed
1363eb220a5SJose Abreu 	 * to look at anything else but the passed-in mode, and validate it
1373eb220a5SJose Abreu 	 * against configuration-invariant hardward constraints. Any further
1383eb220a5SJose Abreu 	 * limits which depend upon the configuration can only be checked in
1393eb220a5SJose Abreu 	 * @mode_fixup or @atomic_check.
1403eb220a5SJose Abreu 	 *
1413eb220a5SJose Abreu 	 * RETURNS:
1423eb220a5SJose Abreu 	 *
1433eb220a5SJose Abreu 	 * drm_mode_status Enum
1443eb220a5SJose Abreu 	 */
1453eb220a5SJose Abreu 	enum drm_mode_status (*mode_valid)(struct drm_crtc *crtc,
1463eb220a5SJose Abreu 					   const struct drm_display_mode *mode);
1473eb220a5SJose Abreu 
1483eb220a5SJose Abreu 	/**
14936b66080SDaniel Vetter 	 * @mode_fixup:
15036b66080SDaniel Vetter 	 *
15136b66080SDaniel Vetter 	 * This callback is used to validate a mode. The parameter mode is the
15236b66080SDaniel Vetter 	 * display mode that userspace requested, adjusted_mode is the mode the
15336b66080SDaniel Vetter 	 * encoders need to be fed with. Note that this is the inverse semantics
1546806cdf9SDaniel Vetter 	 * of the meaning for the &drm_encoder and &drm_bridge_funcs.mode_fixup
1556806cdf9SDaniel Vetter 	 * vfunc. If the CRTC cannot support the requested conversion from mode
1569de5d4a6SDaniel Vetter 	 * to adjusted_mode it should reject the modeset. See also
1579de5d4a6SDaniel Vetter 	 * &drm_crtc_state.adjusted_mode for more details.
15836b66080SDaniel Vetter 	 *
15936b66080SDaniel Vetter 	 * This function is used by both legacy CRTC helpers and atomic helpers.
16036b66080SDaniel Vetter 	 * With atomic helpers it is optional.
16136b66080SDaniel Vetter 	 *
16236b66080SDaniel Vetter 	 * NOTE:
16336b66080SDaniel Vetter 	 *
16436b66080SDaniel Vetter 	 * This function is called in the check phase of atomic modesets, which
16536b66080SDaniel Vetter 	 * can be aborted for any reason (including on userspace's request to
16636b66080SDaniel Vetter 	 * just check whether a configuration would be possible). Atomic drivers
16736b66080SDaniel Vetter 	 * MUST NOT touch any persistent state (hardware or software) or data
16836b66080SDaniel Vetter 	 * structures except the passed in adjusted_mode parameter.
16936b66080SDaniel Vetter 	 *
17036b66080SDaniel Vetter 	 * This is in contrast to the legacy CRTC helpers where this was
17136b66080SDaniel Vetter 	 * allowed.
17236b66080SDaniel Vetter 	 *
17336b66080SDaniel Vetter 	 * Atomic drivers which need to inspect and adjust more state should
1749f800214SDaniel Vetter 	 * instead use the @atomic_check callback, but note that they're not
1759f800214SDaniel Vetter 	 * perfectly equivalent: @mode_valid is called from
1769f800214SDaniel Vetter 	 * drm_atomic_helper_check_modeset(), but @atomic_check is called from
1779f800214SDaniel Vetter 	 * drm_atomic_helper_check_planes(), because originally it was meant for
1789f800214SDaniel Vetter 	 * plane update checks only.
17936b66080SDaniel Vetter 	 *
1803eb220a5SJose Abreu 	 * Also beware that userspace can request its own custom modes, neither
1813eb220a5SJose Abreu 	 * core nor helpers filter modes to the list of probe modes reported by
1823eb220a5SJose Abreu 	 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
1833eb220a5SJose Abreu 	 * that modes are filtered consistently put any CRTC constraints and
1843eb220a5SJose Abreu 	 * limits checks into @mode_valid.
185df7d678bSDaniel Vetter 	 *
18636b66080SDaniel Vetter 	 * RETURNS:
18736b66080SDaniel Vetter 	 *
18836b66080SDaniel Vetter 	 * True if an acceptable configuration is possible, false if the modeset
18936b66080SDaniel Vetter 	 * operation should be rejected.
19036b66080SDaniel Vetter 	 */
191092d01daSDaniel Vetter 	bool (*mode_fixup)(struct drm_crtc *crtc,
192092d01daSDaniel Vetter 			   const struct drm_display_mode *mode,
193092d01daSDaniel Vetter 			   struct drm_display_mode *adjusted_mode);
19436b66080SDaniel Vetter 
19536b66080SDaniel Vetter 	/**
19636b66080SDaniel Vetter 	 * @mode_set:
19736b66080SDaniel Vetter 	 *
19836b66080SDaniel Vetter 	 * This callback is used by the legacy CRTC helpers to set a new mode,
19936b66080SDaniel Vetter 	 * position and framebuffer. Since it ties the primary plane to every
20036b66080SDaniel Vetter 	 * mode change it is incompatible with universal plane support. And
20136b66080SDaniel Vetter 	 * since it can't update other planes it's incompatible with atomic
20236b66080SDaniel Vetter 	 * modeset support.
20336b66080SDaniel Vetter 	 *
20436b66080SDaniel Vetter 	 * This callback is only used by CRTC helpers and deprecated.
20536b66080SDaniel Vetter 	 *
20636b66080SDaniel Vetter 	 * RETURNS:
20736b66080SDaniel Vetter 	 *
20836b66080SDaniel Vetter 	 * 0 on success or a negative error code on failure.
20936b66080SDaniel Vetter 	 */
210092d01daSDaniel Vetter 	int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
211092d01daSDaniel Vetter 			struct drm_display_mode *adjusted_mode, int x, int y,
212092d01daSDaniel Vetter 			struct drm_framebuffer *old_fb);
21336b66080SDaniel Vetter 
21436b66080SDaniel Vetter 	/**
21536b66080SDaniel Vetter 	 * @mode_set_nofb:
21636b66080SDaniel Vetter 	 *
21736b66080SDaniel Vetter 	 * This callback is used to update the display mode of a CRTC without
21836b66080SDaniel Vetter 	 * changing anything of the primary plane configuration. This fits the
21981ed7d73SGeert Uytterhoeven 	 * requirement of atomic and hence is used by the atomic helpers.
22036b66080SDaniel Vetter 	 *
22136b66080SDaniel Vetter 	 * Note that the display pipe is completely off when this function is
22236b66080SDaniel Vetter 	 * called. Atomic drivers which need hardware to be running before they
22336b66080SDaniel Vetter 	 * program the new display mode (e.g. because they implement runtime PM)
22436b66080SDaniel Vetter 	 * should not use this hook. This is because the helper library calls
22536b66080SDaniel Vetter 	 * this hook only once per mode change and not every time the display
22636b66080SDaniel Vetter 	 * pipeline is suspended using either DPMS or the new "ACTIVE" property.
22736b66080SDaniel Vetter 	 * Which means register values set in this callback might get reset when
22836b66080SDaniel Vetter 	 * the CRTC is suspended, but not restored.  Such drivers should instead
2290b20a0f8SLaurent Pinchart 	 * move all their CRTC setup into the @atomic_enable callback.
23036b66080SDaniel Vetter 	 *
23136b66080SDaniel Vetter 	 * This callback is optional.
23236b66080SDaniel Vetter 	 */
233092d01daSDaniel Vetter 	void (*mode_set_nofb)(struct drm_crtc *crtc);
234092d01daSDaniel Vetter 
23536b66080SDaniel Vetter 	/**
23636b66080SDaniel Vetter 	 * @mode_set_base:
23736b66080SDaniel Vetter 	 *
23836b66080SDaniel Vetter 	 * This callback is used by the legacy CRTC helpers to set a new
23936b66080SDaniel Vetter 	 * framebuffer and scanout position. It is optional and used as an
24036b66080SDaniel Vetter 	 * optimized fast-path instead of a full mode set operation with all the
241df7d678bSDaniel Vetter 	 * resulting flickering. If it is not present
242df7d678bSDaniel Vetter 	 * drm_crtc_helper_set_config() will fall back to a full modeset, using
2436806cdf9SDaniel Vetter 	 * the @mode_set callback. Since it can't update other planes it's
24436b66080SDaniel Vetter 	 * incompatible with atomic modeset support.
24536b66080SDaniel Vetter 	 *
24636b66080SDaniel Vetter 	 * This callback is only used by the CRTC helpers and deprecated.
24736b66080SDaniel Vetter 	 *
24836b66080SDaniel Vetter 	 * RETURNS:
24936b66080SDaniel Vetter 	 *
25036b66080SDaniel Vetter 	 * 0 on success or a negative error code on failure.
25136b66080SDaniel Vetter 	 */
252092d01daSDaniel Vetter 	int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
253092d01daSDaniel Vetter 			     struct drm_framebuffer *old_fb);
25436b66080SDaniel Vetter 
25536b66080SDaniel Vetter 	/**
25636b66080SDaniel Vetter 	 * @mode_set_base_atomic:
25736b66080SDaniel Vetter 	 *
25836b66080SDaniel Vetter 	 * This callback is used by the fbdev helpers to set a new framebuffer
25936b66080SDaniel Vetter 	 * and scanout without sleeping, i.e. from an atomic calling context. It
26036b66080SDaniel Vetter 	 * is only used to implement kgdb support.
26136b66080SDaniel Vetter 	 *
26236b66080SDaniel Vetter 	 * This callback is optional and only needed for kgdb support in the fbdev
26336b66080SDaniel Vetter 	 * helpers.
26436b66080SDaniel Vetter 	 *
26536b66080SDaniel Vetter 	 * RETURNS:
26636b66080SDaniel Vetter 	 *
26736b66080SDaniel Vetter 	 * 0 on success or a negative error code on failure.
26836b66080SDaniel Vetter 	 */
269092d01daSDaniel Vetter 	int (*mode_set_base_atomic)(struct drm_crtc *crtc,
270092d01daSDaniel Vetter 				    struct drm_framebuffer *fb, int x, int y,
271092d01daSDaniel Vetter 				    enum mode_set_atomic);
272092d01daSDaniel Vetter 
27336b66080SDaniel Vetter 	/**
27436b66080SDaniel Vetter 	 * @disable:
27536b66080SDaniel Vetter 	 *
27636b66080SDaniel Vetter 	 * This callback should be used to disable the CRTC. With the atomic
27736b66080SDaniel Vetter 	 * drivers it is called after all encoders connected to this CRTC have
2786806cdf9SDaniel Vetter 	 * been shut off already using their own
2796806cdf9SDaniel Vetter 	 * &drm_encoder_helper_funcs.disable hook. If that sequence is too
2806806cdf9SDaniel Vetter 	 * simple drivers can just add their own hooks and call it from this
2816806cdf9SDaniel Vetter 	 * CRTC callback here by looping over all encoders connected to it using
2826806cdf9SDaniel Vetter 	 * for_each_encoder_on_crtc().
28336b66080SDaniel Vetter 	 *
28436b66080SDaniel Vetter 	 * This hook is used both by legacy CRTC helpers and atomic helpers.
28536b66080SDaniel Vetter 	 * Atomic drivers don't need to implement it if there's no need to
28636b66080SDaniel Vetter 	 * disable anything at the CRTC level. To ensure that runtime PM
28736b66080SDaniel Vetter 	 * handling (using either DPMS or the new "ACTIVE" property) works
2880b20a0f8SLaurent Pinchart 	 * @disable must be the inverse of @atomic_enable for atomic drivers.
289c9ac8b4cSLiu Ying 	 * Atomic drivers should consider to use @atomic_disable instead of
290c9ac8b4cSLiu Ying 	 * this one.
29136b66080SDaniel Vetter 	 *
29236b66080SDaniel Vetter 	 * NOTE:
29336b66080SDaniel Vetter 	 *
29436b66080SDaniel Vetter 	 * With legacy CRTC helpers there's a big semantic difference between
29536b66080SDaniel Vetter 	 * @disable and other hooks (like @prepare or @dpms) used to shut down a
29636b66080SDaniel Vetter 	 * CRTC: @disable is only called when also logically disabling the
29736b66080SDaniel Vetter 	 * display pipeline and needs to release any resources acquired in
29836b66080SDaniel Vetter 	 * @mode_set (like shared PLLs, or again release pinned framebuffers).
29936b66080SDaniel Vetter 	 *
30036b66080SDaniel Vetter 	 * Therefore @disable must be the inverse of @mode_set plus @commit for
30136b66080SDaniel Vetter 	 * drivers still using legacy CRTC helpers, which is different from the
30236b66080SDaniel Vetter 	 * rules under atomic.
30336b66080SDaniel Vetter 	 */
304092d01daSDaniel Vetter 	void (*disable)(struct drm_crtc *crtc);
30536b66080SDaniel Vetter 
30636b66080SDaniel Vetter 	/**
30711a0ba97SDaniel Vetter 	 * @atomic_check:
30811a0ba97SDaniel Vetter 	 *
30911a0ba97SDaniel Vetter 	 * Drivers should check plane-update related CRTC constraints in this
31011a0ba97SDaniel Vetter 	 * hook. They can also check mode related limitations but need to be
31111a0ba97SDaniel Vetter 	 * aware of the calling order, since this hook is used by
31211a0ba97SDaniel Vetter 	 * drm_atomic_helper_check_planes() whereas the preparations needed to
31311a0ba97SDaniel Vetter 	 * check output routing and the display mode is done in
31411a0ba97SDaniel Vetter 	 * drm_atomic_helper_check_modeset(). Therefore drivers that want to
31511a0ba97SDaniel Vetter 	 * check output routing and display mode constraints in this callback
31611a0ba97SDaniel Vetter 	 * must ensure that drm_atomic_helper_check_modeset() has been called
31711a0ba97SDaniel Vetter 	 * beforehand. This is calling order used by the default helper
31811a0ba97SDaniel Vetter 	 * implementation in drm_atomic_helper_check().
31911a0ba97SDaniel Vetter 	 *
3206806cdf9SDaniel Vetter 	 * When using drm_atomic_helper_check_planes() this hook is called
3212093ea2eSThierry Reding 	 * after the &drm_plane_helper_funcs.atomic_check hook for planes, which
3226806cdf9SDaniel Vetter 	 * allows drivers to assign shared resources requested by planes in this
3236806cdf9SDaniel Vetter 	 * callback here. For more complicated dependencies the driver can call
3246806cdf9SDaniel Vetter 	 * the provided check helpers multiple times until the computed state
3256806cdf9SDaniel Vetter 	 * has a final configuration and everything has been checked.
32611a0ba97SDaniel Vetter 	 *
32711a0ba97SDaniel Vetter 	 * This function is also allowed to inspect any other object's state and
32811a0ba97SDaniel Vetter 	 * can add more state objects to the atomic commit if needed. Care must
3296806cdf9SDaniel Vetter 	 * be taken though to ensure that state check and compute functions for
33011a0ba97SDaniel Vetter 	 * these added states are all called, and derived state in other objects
33111a0ba97SDaniel Vetter 	 * all updated. Again the recommendation is to just call check helpers
33211a0ba97SDaniel Vetter 	 * until a maximal configuration is reached.
33311a0ba97SDaniel Vetter 	 *
33481ed7d73SGeert Uytterhoeven 	 * This callback is used by the atomic modeset helpers, but it is
33581ed7d73SGeert Uytterhoeven 	 * optional.
33611a0ba97SDaniel Vetter 	 *
33711a0ba97SDaniel Vetter 	 * NOTE:
33811a0ba97SDaniel Vetter 	 *
33911a0ba97SDaniel Vetter 	 * This function is called in the check phase of an atomic update. The
34011a0ba97SDaniel Vetter 	 * driver is not allowed to change anything outside of the free-standing
34129b77ad7SMaxime Ripard 	 * state object passed-in.
34211a0ba97SDaniel Vetter 	 *
3433eb220a5SJose Abreu 	 * Also beware that userspace can request its own custom modes, neither
3443eb220a5SJose Abreu 	 * core nor helpers filter modes to the list of probe modes reported by
3453eb220a5SJose Abreu 	 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
3463eb220a5SJose Abreu 	 * that modes are filtered consistently put any CRTC constraints and
3473eb220a5SJose Abreu 	 * limits checks into @mode_valid.
3483eb220a5SJose Abreu 	 *
34911a0ba97SDaniel Vetter 	 * RETURNS:
35011a0ba97SDaniel Vetter 	 *
35111a0ba97SDaniel Vetter 	 * 0 on success, -EINVAL if the state or the transition can't be
35211a0ba97SDaniel Vetter 	 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
35311a0ba97SDaniel Vetter 	 * attempt to obtain another state object ran into a &drm_modeset_lock
35411a0ba97SDaniel Vetter 	 * deadlock.
35511a0ba97SDaniel Vetter 	 */
356092d01daSDaniel Vetter 	int (*atomic_check)(struct drm_crtc *crtc,
35729b77ad7SMaxime Ripard 			    struct drm_atomic_state *state);
35811a0ba97SDaniel Vetter 
35911a0ba97SDaniel Vetter 	/**
36011a0ba97SDaniel Vetter 	 * @atomic_begin:
36111a0ba97SDaniel Vetter 	 *
36211a0ba97SDaniel Vetter 	 * Drivers should prepare for an atomic update of multiple planes on
36311a0ba97SDaniel Vetter 	 * a CRTC in this hook. Depending upon hardware this might be vblank
36411a0ba97SDaniel Vetter 	 * evasion, blocking updates by setting bits or doing preparatory work
36511a0ba97SDaniel Vetter 	 * for e.g. manual update display.
36611a0ba97SDaniel Vetter 	 *
36711a0ba97SDaniel Vetter 	 * This hook is called before any plane commit functions are called.
36811a0ba97SDaniel Vetter 	 *
36911a0ba97SDaniel Vetter 	 * Note that the power state of the display pipe when this function is
37011a0ba97SDaniel Vetter 	 * called depends upon the exact helpers and calling sequence the driver
3710dc9967dSStefan Agner 	 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
3720dc9967dSStefan Agner 	 * the tradeoffs and variants of plane commit helpers.
37311a0ba97SDaniel Vetter 	 *
37481ed7d73SGeert Uytterhoeven 	 * This callback is used by the atomic modeset helpers, but it is
37581ed7d73SGeert Uytterhoeven 	 * optional.
37611a0ba97SDaniel Vetter 	 */
377092d01daSDaniel Vetter 	void (*atomic_begin)(struct drm_crtc *crtc,
378f6ebe9f9SMaxime Ripard 			     struct drm_atomic_state *state);
37911a0ba97SDaniel Vetter 	/**
38011a0ba97SDaniel Vetter 	 * @atomic_flush:
38111a0ba97SDaniel Vetter 	 *
38211a0ba97SDaniel Vetter 	 * Drivers should finalize an atomic update of multiple planes on
38311a0ba97SDaniel Vetter 	 * a CRTC in this hook. Depending upon hardware this might include
38411a0ba97SDaniel Vetter 	 * checking that vblank evasion was successful, unblocking updates by
38511a0ba97SDaniel Vetter 	 * setting bits or setting the GO bit to flush out all updates.
38611a0ba97SDaniel Vetter 	 *
38711a0ba97SDaniel Vetter 	 * Simple hardware or hardware with special requirements can commit and
38811a0ba97SDaniel Vetter 	 * flush out all updates for all planes from this hook and forgo all the
38911a0ba97SDaniel Vetter 	 * other commit hooks for plane updates.
39011a0ba97SDaniel Vetter 	 *
39111a0ba97SDaniel Vetter 	 * This hook is called after any plane commit functions are called.
39211a0ba97SDaniel Vetter 	 *
39311a0ba97SDaniel Vetter 	 * Note that the power state of the display pipe when this function is
39411a0ba97SDaniel Vetter 	 * called depends upon the exact helpers and calling sequence the driver
3950dc9967dSStefan Agner 	 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
3960dc9967dSStefan Agner 	 * the tradeoffs and variants of plane commit helpers.
39711a0ba97SDaniel Vetter 	 *
39881ed7d73SGeert Uytterhoeven 	 * This callback is used by the atomic modeset helpers, but it is
39981ed7d73SGeert Uytterhoeven 	 * optional.
40011a0ba97SDaniel Vetter 	 */
401092d01daSDaniel Vetter 	void (*atomic_flush)(struct drm_crtc *crtc,
402f6ebe9f9SMaxime Ripard 			     struct drm_atomic_state *state);
403c9ac8b4cSLiu Ying 
404c9ac8b4cSLiu Ying 	/**
4050b20a0f8SLaurent Pinchart 	 * @atomic_enable:
4060b20a0f8SLaurent Pinchart 	 *
4070b20a0f8SLaurent Pinchart 	 * This callback should be used to enable the CRTC. With the atomic
4080b20a0f8SLaurent Pinchart 	 * drivers it is called before all encoders connected to this CRTC are
4090b20a0f8SLaurent Pinchart 	 * enabled through the encoder's own &drm_encoder_helper_funcs.enable
4100b20a0f8SLaurent Pinchart 	 * hook.  If that sequence is too simple drivers can just add their own
4110b20a0f8SLaurent Pinchart 	 * hooks and call it from this CRTC callback here by looping over all
4120b20a0f8SLaurent Pinchart 	 * encoders connected to it using for_each_encoder_on_crtc().
4130b20a0f8SLaurent Pinchart 	 *
4140b20a0f8SLaurent Pinchart 	 * This hook is used only by atomic helpers, for symmetry with
4150b20a0f8SLaurent Pinchart 	 * @atomic_disable. Atomic drivers don't need to implement it if there's
4160b20a0f8SLaurent Pinchart 	 * no need to enable anything at the CRTC level. To ensure that runtime
4170b20a0f8SLaurent Pinchart 	 * PM handling (using either DPMS or the new "ACTIVE" property) works
4180b20a0f8SLaurent Pinchart 	 * @atomic_enable must be the inverse of @atomic_disable for atomic
4190b20a0f8SLaurent Pinchart 	 * drivers.
4200b20a0f8SLaurent Pinchart 	 *
421fe616928SRodrigo Siqueira 	 * This function is optional.
4220b20a0f8SLaurent Pinchart 	 */
4230b20a0f8SLaurent Pinchart 	void (*atomic_enable)(struct drm_crtc *crtc,
424351f950dSMaxime Ripard 			      struct drm_atomic_state *state);
4250b20a0f8SLaurent Pinchart 
4260b20a0f8SLaurent Pinchart 	/**
427c9ac8b4cSLiu Ying 	 * @atomic_disable:
428c9ac8b4cSLiu Ying 	 *
429c9ac8b4cSLiu Ying 	 * This callback should be used to disable the CRTC. With the atomic
430c9ac8b4cSLiu Ying 	 * drivers it is called after all encoders connected to this CRTC have
4316806cdf9SDaniel Vetter 	 * been shut off already using their own
4326806cdf9SDaniel Vetter 	 * &drm_encoder_helper_funcs.disable hook. If that sequence is too
4336806cdf9SDaniel Vetter 	 * simple drivers can just add their own hooks and call it from this
4346806cdf9SDaniel Vetter 	 * CRTC callback here by looping over all encoders connected to it using
4356806cdf9SDaniel Vetter 	 * for_each_encoder_on_crtc().
436c9ac8b4cSLiu Ying 	 *
437c9ac8b4cSLiu Ying 	 * This hook is used only by atomic helpers. Atomic drivers don't
438c9ac8b4cSLiu Ying 	 * need to implement it if there's no need to disable anything at the
439c9ac8b4cSLiu Ying 	 * CRTC level.
440c9ac8b4cSLiu Ying 	 *
441fe616928SRodrigo Siqueira 	 * This function is optional.
442c9ac8b4cSLiu Ying 	 */
443c9ac8b4cSLiu Ying 	void (*atomic_disable)(struct drm_crtc *crtc,
444351f950dSMaxime Ripard 			       struct drm_atomic_state *state);
445f1e2b637SThomas Zimmermann 
446f1e2b637SThomas Zimmermann 	/**
447f1e2b637SThomas Zimmermann 	 * @get_scanout_position:
448f1e2b637SThomas Zimmermann 	 *
449f1e2b637SThomas Zimmermann 	 * Called by vblank timestamping code.
450f1e2b637SThomas Zimmermann 	 *
451f1e2b637SThomas Zimmermann 	 * Returns the current display scanout position from a CRTC and an
452f1e2b637SThomas Zimmermann 	 * optional accurate ktime_get() timestamp of when the position was
453f1e2b637SThomas Zimmermann 	 * measured. Note that this is a helper callback which is only used
4547fe3f0d1SThomas Zimmermann 	 * if a driver uses drm_crtc_vblank_helper_get_vblank_timestamp()
4557fe3f0d1SThomas Zimmermann 	 * for the @drm_crtc_funcs.get_vblank_timestamp callback.
456f1e2b637SThomas Zimmermann 	 *
457f1e2b637SThomas Zimmermann 	 * Parameters:
458f1e2b637SThomas Zimmermann 	 *
459f1e2b637SThomas Zimmermann 	 * crtc:
460f1e2b637SThomas Zimmermann 	 *     The CRTC.
461f1e2b637SThomas Zimmermann 	 * in_vblank_irq:
462f1e2b637SThomas Zimmermann 	 *     True when called from drm_crtc_handle_vblank(). Some drivers
463f1e2b637SThomas Zimmermann 	 *     need to apply some workarounds for gpu-specific vblank irq
464f1e2b637SThomas Zimmermann 	 *     quirks if the flag is set.
465f1e2b637SThomas Zimmermann 	 * vpos:
466f1e2b637SThomas Zimmermann 	 *     Target location for current vertical scanout position.
467f1e2b637SThomas Zimmermann 	 * hpos:
468f1e2b637SThomas Zimmermann 	 *     Target location for current horizontal scanout position.
469f1e2b637SThomas Zimmermann 	 * stime:
470f1e2b637SThomas Zimmermann 	 *     Target location for timestamp taken immediately before
471f1e2b637SThomas Zimmermann 	 *     scanout position query. Can be NULL to skip timestamp.
472f1e2b637SThomas Zimmermann 	 * etime:
473f1e2b637SThomas Zimmermann 	 *     Target location for timestamp taken immediately after
474f1e2b637SThomas Zimmermann 	 *     scanout position query. Can be NULL to skip timestamp.
475f1e2b637SThomas Zimmermann 	 * mode:
476f1e2b637SThomas Zimmermann 	 *     Current display timings.
477f1e2b637SThomas Zimmermann 	 *
478f1e2b637SThomas Zimmermann 	 * Returns vpos as a positive number while in active scanout area.
479f1e2b637SThomas Zimmermann 	 * Returns vpos as a negative number inside vblank, counting the number
480f1e2b637SThomas Zimmermann 	 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
481f1e2b637SThomas Zimmermann 	 * until start of active scanout / end of vblank."
482f1e2b637SThomas Zimmermann 	 *
483f1e2b637SThomas Zimmermann 	 * Returns:
484f1e2b637SThomas Zimmermann 	 *
485f1e2b637SThomas Zimmermann 	 * True on success, false if a reliable scanout position counter could
486f1e2b637SThomas Zimmermann 	 * not be read out.
487f1e2b637SThomas Zimmermann 	 */
488f1e2b637SThomas Zimmermann 	bool (*get_scanout_position)(struct drm_crtc *crtc,
489f1e2b637SThomas Zimmermann 				     bool in_vblank_irq, int *vpos, int *hpos,
490f1e2b637SThomas Zimmermann 				     ktime_t *stime, ktime_t *etime,
491f1e2b637SThomas Zimmermann 				     const struct drm_display_mode *mode);
492092d01daSDaniel Vetter };
493092d01daSDaniel Vetter 
494092d01daSDaniel Vetter /**
495092d01daSDaniel Vetter  * drm_crtc_helper_add - sets the helper vtable for a crtc
496092d01daSDaniel Vetter  * @crtc: DRM CRTC
497092d01daSDaniel Vetter  * @funcs: helper vtable to set for @crtc
498092d01daSDaniel Vetter  */
drm_crtc_helper_add(struct drm_crtc * crtc,const struct drm_crtc_helper_funcs * funcs)499092d01daSDaniel Vetter static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
500092d01daSDaniel Vetter 				       const struct drm_crtc_helper_funcs *funcs)
501092d01daSDaniel Vetter {
502092d01daSDaniel Vetter 	crtc->helper_private = funcs;
503092d01daSDaniel Vetter }
504092d01daSDaniel Vetter 
505092d01daSDaniel Vetter /**
506092d01daSDaniel Vetter  * struct drm_encoder_helper_funcs - helper operations for encoders
507092d01daSDaniel Vetter  *
50881ed7d73SGeert Uytterhoeven  * These hooks are used by the legacy CRTC helpers and the new atomic
50981ed7d73SGeert Uytterhoeven  * modesetting helpers.
510092d01daSDaniel Vetter  */
511092d01daSDaniel Vetter struct drm_encoder_helper_funcs {
51236b66080SDaniel Vetter 	/**
51336b66080SDaniel Vetter 	 * @dpms:
51436b66080SDaniel Vetter 	 *
51536b66080SDaniel Vetter 	 * Callback to control power levels on the encoder.  If the mode passed in
51636b66080SDaniel Vetter 	 * is unsupported, the provider must use the next lowest power level.
51736b66080SDaniel Vetter 	 * This is used by the legacy encoder helpers to implement DPMS
51836b66080SDaniel Vetter 	 * functionality in drm_helper_connector_dpms().
51936b66080SDaniel Vetter 	 *
52036b66080SDaniel Vetter 	 * This callback is also used to disable an encoder by calling it with
52136b66080SDaniel Vetter 	 * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
52236b66080SDaniel Vetter 	 *
52336b66080SDaniel Vetter 	 * This callback is used by the legacy CRTC helpers.  Atomic helpers
52436b66080SDaniel Vetter 	 * also support using this hook for enabling and disabling an encoder to
52536b66080SDaniel Vetter 	 * facilitate transitions to atomic, but it is deprecated. Instead
52636b66080SDaniel Vetter 	 * @enable and @disable should be used.
52736b66080SDaniel Vetter 	 */
528092d01daSDaniel Vetter 	void (*dpms)(struct drm_encoder *encoder, int mode);
529092d01daSDaniel Vetter 
53036b66080SDaniel Vetter 	/**
5313eb220a5SJose Abreu 	 * @mode_valid:
5323eb220a5SJose Abreu 	 *
5333eb220a5SJose Abreu 	 * This callback is used to check if a specific mode is valid in this
5343eb220a5SJose Abreu 	 * encoder. This should be implemented if the encoder has some sort
5353eb220a5SJose Abreu 	 * of restriction in the modes it can display. For example, a given
5363eb220a5SJose Abreu 	 * encoder may be responsible to set a clock value. If the clock can
5373eb220a5SJose Abreu 	 * not produce all the values for the available modes then this callback
5383eb220a5SJose Abreu 	 * can be used to restrict the number of modes to only the ones that
5393eb220a5SJose Abreu 	 * can be displayed.
5403eb220a5SJose Abreu 	 *
5413eb220a5SJose Abreu 	 * This hook is used by the probe helpers to filter the mode list in
5423eb220a5SJose Abreu 	 * drm_helper_probe_single_connector_modes(), and it is used by the
5433eb220a5SJose Abreu 	 * atomic helpers to validate modes supplied by userspace in
5443eb220a5SJose Abreu 	 * drm_atomic_helper_check_modeset().
5453eb220a5SJose Abreu 	 *
5463eb220a5SJose Abreu 	 * This function is optional.
5473eb220a5SJose Abreu 	 *
5483eb220a5SJose Abreu 	 * NOTE:
5493eb220a5SJose Abreu 	 *
5503eb220a5SJose Abreu 	 * Since this function is both called from the check phase of an atomic
5513eb220a5SJose Abreu 	 * commit, and the mode validation in the probe paths it is not allowed
5523eb220a5SJose Abreu 	 * to look at anything else but the passed-in mode, and validate it
5533eb220a5SJose Abreu 	 * against configuration-invariant hardward constraints. Any further
5543eb220a5SJose Abreu 	 * limits which depend upon the configuration can only be checked in
5553eb220a5SJose Abreu 	 * @mode_fixup or @atomic_check.
5563eb220a5SJose Abreu 	 *
5573eb220a5SJose Abreu 	 * RETURNS:
5583eb220a5SJose Abreu 	 *
5593eb220a5SJose Abreu 	 * drm_mode_status Enum
5603eb220a5SJose Abreu 	 */
5613eb220a5SJose Abreu 	enum drm_mode_status (*mode_valid)(struct drm_encoder *crtc,
5623eb220a5SJose Abreu 					   const struct drm_display_mode *mode);
5633eb220a5SJose Abreu 
5643eb220a5SJose Abreu 	/**
56536b66080SDaniel Vetter 	 * @mode_fixup:
56636b66080SDaniel Vetter 	 *
56736b66080SDaniel Vetter 	 * This callback is used to validate and adjust a mode. The parameter
56836b66080SDaniel Vetter 	 * mode is the display mode that should be fed to the next element in
56936b66080SDaniel Vetter 	 * the display chain, either the final &drm_connector or a &drm_bridge.
57036b66080SDaniel Vetter 	 * The parameter adjusted_mode is the input mode the encoder requires. It
5719de5d4a6SDaniel Vetter 	 * can be modified by this callback and does not need to match mode. See
5729de5d4a6SDaniel Vetter 	 * also &drm_crtc_state.adjusted_mode for more details.
57336b66080SDaniel Vetter 	 *
57436b66080SDaniel Vetter 	 * This function is used by both legacy CRTC helpers and atomic helpers.
5753c5b2673SCarlos Palminha 	 * This hook is optional.
57636b66080SDaniel Vetter 	 *
57736b66080SDaniel Vetter 	 * NOTE:
57836b66080SDaniel Vetter 	 *
57936b66080SDaniel Vetter 	 * This function is called in the check phase of atomic modesets, which
58036b66080SDaniel Vetter 	 * can be aborted for any reason (including on userspace's request to
58136b66080SDaniel Vetter 	 * just check whether a configuration would be possible). Atomic drivers
58236b66080SDaniel Vetter 	 * MUST NOT touch any persistent state (hardware or software) or data
58336b66080SDaniel Vetter 	 * structures except the passed in adjusted_mode parameter.
58436b66080SDaniel Vetter 	 *
58536b66080SDaniel Vetter 	 * This is in contrast to the legacy CRTC helpers where this was
58636b66080SDaniel Vetter 	 * allowed.
58736b66080SDaniel Vetter 	 *
58836b66080SDaniel Vetter 	 * Atomic drivers which need to inspect and adjust more state should
5899f800214SDaniel Vetter 	 * instead use the @atomic_check callback. If @atomic_check is used,
5909f800214SDaniel Vetter 	 * this hook isn't called since @atomic_check allows a strict superset
5919f800214SDaniel Vetter 	 * of the functionality of @mode_fixup.
59236b66080SDaniel Vetter 	 *
5933eb220a5SJose Abreu 	 * Also beware that userspace can request its own custom modes, neither
5943eb220a5SJose Abreu 	 * core nor helpers filter modes to the list of probe modes reported by
5953eb220a5SJose Abreu 	 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
5963eb220a5SJose Abreu 	 * that modes are filtered consistently put any encoder constraints and
5973eb220a5SJose Abreu 	 * limits checks into @mode_valid.
598df7d678bSDaniel Vetter 	 *
59936b66080SDaniel Vetter 	 * RETURNS:
60036b66080SDaniel Vetter 	 *
60136b66080SDaniel Vetter 	 * True if an acceptable configuration is possible, false if the modeset
60236b66080SDaniel Vetter 	 * operation should be rejected.
60336b66080SDaniel Vetter 	 */
604092d01daSDaniel Vetter 	bool (*mode_fixup)(struct drm_encoder *encoder,
605092d01daSDaniel Vetter 			   const struct drm_display_mode *mode,
606092d01daSDaniel Vetter 			   struct drm_display_mode *adjusted_mode);
60736b66080SDaniel Vetter 
60836b66080SDaniel Vetter 	/**
60936b66080SDaniel Vetter 	 * @prepare:
61036b66080SDaniel Vetter 	 *
61136b66080SDaniel Vetter 	 * This callback should prepare the encoder for a subsequent modeset,
61236b66080SDaniel Vetter 	 * which in practice means the driver should disable the encoder if it
61336b66080SDaniel Vetter 	 * is running. Most drivers ended up implementing this by calling their
61436b66080SDaniel Vetter 	 * @dpms hook with DRM_MODE_DPMS_OFF.
61536b66080SDaniel Vetter 	 *
61636b66080SDaniel Vetter 	 * This callback is used by the legacy CRTC helpers.  Atomic helpers
61736b66080SDaniel Vetter 	 * also support using this hook for disabling an encoder to facilitate
61836b66080SDaniel Vetter 	 * transitions to atomic, but it is deprecated. Instead @disable should
61936b66080SDaniel Vetter 	 * be used.
62036b66080SDaniel Vetter 	 */
621092d01daSDaniel Vetter 	void (*prepare)(struct drm_encoder *encoder);
62236b66080SDaniel Vetter 
62336b66080SDaniel Vetter 	/**
62436b66080SDaniel Vetter 	 * @commit:
62536b66080SDaniel Vetter 	 *
62636b66080SDaniel Vetter 	 * This callback should commit the new mode on the encoder after a modeset,
62736b66080SDaniel Vetter 	 * which in practice means the driver should enable the encoder.  Most
62836b66080SDaniel Vetter 	 * drivers ended up implementing this by calling their @dpms hook with
62936b66080SDaniel Vetter 	 * DRM_MODE_DPMS_ON.
63036b66080SDaniel Vetter 	 *
63136b66080SDaniel Vetter 	 * This callback is used by the legacy CRTC helpers.  Atomic helpers
63236b66080SDaniel Vetter 	 * also support using this hook for enabling an encoder to facilitate
63336b66080SDaniel Vetter 	 * transitions to atomic, but it is deprecated. Instead @enable should
63436b66080SDaniel Vetter 	 * be used.
63536b66080SDaniel Vetter 	 */
636092d01daSDaniel Vetter 	void (*commit)(struct drm_encoder *encoder);
63736b66080SDaniel Vetter 
63836b66080SDaniel Vetter 	/**
63936b66080SDaniel Vetter 	 * @mode_set:
64036b66080SDaniel Vetter 	 *
64136b66080SDaniel Vetter 	 * This callback is used to update the display mode of an encoder.
64236b66080SDaniel Vetter 	 *
64336b66080SDaniel Vetter 	 * Note that the display pipe is completely off when this function is
64436b66080SDaniel Vetter 	 * called. Drivers which need hardware to be running before they program
64536b66080SDaniel Vetter 	 * the new display mode (because they implement runtime PM) should not
64636b66080SDaniel Vetter 	 * use this hook, because the helper library calls it only once and not
64736b66080SDaniel Vetter 	 * every time the display pipeline is suspend using either DPMS or the
64836b66080SDaniel Vetter 	 * new "ACTIVE" property. Such drivers should instead move all their
6496806cdf9SDaniel Vetter 	 * encoder setup into the @enable callback.
65036b66080SDaniel Vetter 	 *
65136b66080SDaniel Vetter 	 * This callback is used both by the legacy CRTC helpers and the atomic
65236b66080SDaniel Vetter 	 * modeset helpers. It is optional in the atomic helpers.
653fe4a11c9SPhilipp Zabel 	 *
654fe4a11c9SPhilipp Zabel 	 * NOTE:
655fe4a11c9SPhilipp Zabel 	 *
656fe4a11c9SPhilipp Zabel 	 * If the driver uses the atomic modeset helpers and needs to inspect
657fe4a11c9SPhilipp Zabel 	 * the connector state or connector display info during mode setting,
658fe4a11c9SPhilipp Zabel 	 * @atomic_mode_set can be used instead.
65936b66080SDaniel Vetter 	 */
660092d01daSDaniel Vetter 	void (*mode_set)(struct drm_encoder *encoder,
661092d01daSDaniel Vetter 			 struct drm_display_mode *mode,
662092d01daSDaniel Vetter 			 struct drm_display_mode *adjusted_mode);
66336b66080SDaniel Vetter 
66436b66080SDaniel Vetter 	/**
665fe4a11c9SPhilipp Zabel 	 * @atomic_mode_set:
666fe4a11c9SPhilipp Zabel 	 *
667fe4a11c9SPhilipp Zabel 	 * This callback is used to update the display mode of an encoder.
668fe4a11c9SPhilipp Zabel 	 *
669fe4a11c9SPhilipp Zabel 	 * Note that the display pipe is completely off when this function is
670fe4a11c9SPhilipp Zabel 	 * called. Drivers which need hardware to be running before they program
671fe4a11c9SPhilipp Zabel 	 * the new display mode (because they implement runtime PM) should not
672fe4a11c9SPhilipp Zabel 	 * use this hook, because the helper library calls it only once and not
673fe4a11c9SPhilipp Zabel 	 * every time the display pipeline is suspended using either DPMS or the
674fe4a11c9SPhilipp Zabel 	 * new "ACTIVE" property. Such drivers should instead move all their
6756806cdf9SDaniel Vetter 	 * encoder setup into the @enable callback.
676fe4a11c9SPhilipp Zabel 	 *
677fe4a11c9SPhilipp Zabel 	 * This callback is used by the atomic modeset helpers in place of the
678fe4a11c9SPhilipp Zabel 	 * @mode_set callback, if set by the driver. It is optional and should
679fe4a11c9SPhilipp Zabel 	 * be used instead of @mode_set if the driver needs to inspect the
680fe4a11c9SPhilipp Zabel 	 * connector state or display info, since there is no direct way to
681fe4a11c9SPhilipp Zabel 	 * go from the encoder to the current connector.
682fe4a11c9SPhilipp Zabel 	 */
683fe4a11c9SPhilipp Zabel 	void (*atomic_mode_set)(struct drm_encoder *encoder,
684fe4a11c9SPhilipp Zabel 				struct drm_crtc_state *crtc_state,
685fe4a11c9SPhilipp Zabel 				struct drm_connector_state *conn_state);
686fe4a11c9SPhilipp Zabel 
687fe4a11c9SPhilipp Zabel 	/**
68836b66080SDaniel Vetter 	 * @detect:
68936b66080SDaniel Vetter 	 *
69036b66080SDaniel Vetter 	 * This callback can be used by drivers who want to do detection on the
69136b66080SDaniel Vetter 	 * encoder object instead of in connector functions.
69236b66080SDaniel Vetter 	 *
69336b66080SDaniel Vetter 	 * It is not used by any helper and therefore has purely driver-specific
69436b66080SDaniel Vetter 	 * semantics. New drivers shouldn't use this and instead just implement
69536b66080SDaniel Vetter 	 * their own private callbacks.
69636b66080SDaniel Vetter 	 *
69736b66080SDaniel Vetter 	 * FIXME:
69836b66080SDaniel Vetter 	 *
69936b66080SDaniel Vetter 	 * This should just be converted into a pile of driver vfuncs.
70036b66080SDaniel Vetter 	 * Currently radeon, amdgpu and nouveau are using it.
70136b66080SDaniel Vetter 	 */
702092d01daSDaniel Vetter 	enum drm_connector_status (*detect)(struct drm_encoder *encoder,
703092d01daSDaniel Vetter 					    struct drm_connector *connector);
70436b66080SDaniel Vetter 
70536b66080SDaniel Vetter 	/**
70643c76d72SSean Paul 	 * @atomic_disable:
70743c76d72SSean Paul 	 *
70843c76d72SSean Paul 	 * This callback should be used to disable the encoder. With the atomic
70943c76d72SSean Paul 	 * drivers it is called before this encoder's CRTC has been shut off
71043c76d72SSean Paul 	 * using their own &drm_crtc_helper_funcs.atomic_disable hook. If that
71143c76d72SSean Paul 	 * sequence is too simple drivers can just add their own driver private
71243c76d72SSean Paul 	 * encoder hooks and call them from CRTC's callback by looping over all
71343c76d72SSean Paul 	 * encoders connected to it using for_each_encoder_on_crtc().
71443c76d72SSean Paul 	 *
71543c76d72SSean Paul 	 * This callback is a variant of @disable that provides the atomic state
71643c76d72SSean Paul 	 * to the driver. If @atomic_disable is implemented, @disable is not
71743c76d72SSean Paul 	 * called by the helpers.
71843c76d72SSean Paul 	 *
71943c76d72SSean Paul 	 * This hook is only used by atomic helpers. Atomic drivers don't need
72043c76d72SSean Paul 	 * to implement it if there's no need to disable anything at the encoder
72143c76d72SSean Paul 	 * level. To ensure that runtime PM handling (using either DPMS or the
72243c76d72SSean Paul 	 * new "ACTIVE" property) works @atomic_disable must be the inverse of
72343c76d72SSean Paul 	 * @atomic_enable.
72443c76d72SSean Paul 	 */
72543c76d72SSean Paul 	void (*atomic_disable)(struct drm_encoder *encoder,
72643c76d72SSean Paul 			       struct drm_atomic_state *state);
72743c76d72SSean Paul 
72843c76d72SSean Paul 	/**
72943c76d72SSean Paul 	 * @atomic_enable:
73043c76d72SSean Paul 	 *
73143c76d72SSean Paul 	 * This callback should be used to enable the encoder. It is called
73243c76d72SSean Paul 	 * after this encoder's CRTC has been enabled using their own
73343c76d72SSean Paul 	 * &drm_crtc_helper_funcs.atomic_enable hook. If that sequence is
73443c76d72SSean Paul 	 * too simple drivers can just add their own driver private encoder
73543c76d72SSean Paul 	 * hooks and call them from CRTC's callback by looping over all encoders
73643c76d72SSean Paul 	 * connected to it using for_each_encoder_on_crtc().
73743c76d72SSean Paul 	 *
73843c76d72SSean Paul 	 * This callback is a variant of @enable that provides the atomic state
73943c76d72SSean Paul 	 * to the driver. If @atomic_enable is implemented, @enable is not
74043c76d72SSean Paul 	 * called by the helpers.
74143c76d72SSean Paul 	 *
74243c76d72SSean Paul 	 * This hook is only used by atomic helpers, it is the opposite of
74343c76d72SSean Paul 	 * @atomic_disable. Atomic drivers don't need to implement it if there's
74443c76d72SSean Paul 	 * no need to enable anything at the encoder level. To ensure that
74543c76d72SSean Paul 	 * runtime PM handling works @atomic_enable must be the inverse of
74643c76d72SSean Paul 	 * @atomic_disable.
74743c76d72SSean Paul 	 */
74843c76d72SSean Paul 	void (*atomic_enable)(struct drm_encoder *encoder,
74943c76d72SSean Paul 			      struct drm_atomic_state *state);
75043c76d72SSean Paul 
75143c76d72SSean Paul 	/**
75236b66080SDaniel Vetter 	 * @disable:
75336b66080SDaniel Vetter 	 *
75436b66080SDaniel Vetter 	 * This callback should be used to disable the encoder. With the atomic
75536b66080SDaniel Vetter 	 * drivers it is called before this encoder's CRTC has been shut off
7566806cdf9SDaniel Vetter 	 * using their own &drm_crtc_helper_funcs.disable hook.  If that
7576806cdf9SDaniel Vetter 	 * sequence is too simple drivers can just add their own driver private
7586806cdf9SDaniel Vetter 	 * encoder hooks and call them from CRTC's callback by looping over all
7596806cdf9SDaniel Vetter 	 * encoders connected to it using for_each_encoder_on_crtc().
76036b66080SDaniel Vetter 	 *
76136b66080SDaniel Vetter 	 * This hook is used both by legacy CRTC helpers and atomic helpers.
76236b66080SDaniel Vetter 	 * Atomic drivers don't need to implement it if there's no need to
76336b66080SDaniel Vetter 	 * disable anything at the encoder level. To ensure that runtime PM
76436b66080SDaniel Vetter 	 * handling (using either DPMS or the new "ACTIVE" property) works
76536b66080SDaniel Vetter 	 * @disable must be the inverse of @enable for atomic drivers.
76636b66080SDaniel Vetter 	 *
76743c76d72SSean Paul 	 * For atomic drivers also consider @atomic_disable and save yourself
76843c76d72SSean Paul 	 * from having to read the NOTE below!
76943c76d72SSean Paul 	 *
77036b66080SDaniel Vetter 	 * NOTE:
77136b66080SDaniel Vetter 	 *
77236b66080SDaniel Vetter 	 * With legacy CRTC helpers there's a big semantic difference between
77336b66080SDaniel Vetter 	 * @disable and other hooks (like @prepare or @dpms) used to shut down a
77436b66080SDaniel Vetter 	 * encoder: @disable is only called when also logically disabling the
77536b66080SDaniel Vetter 	 * display pipeline and needs to release any resources acquired in
77636b66080SDaniel Vetter 	 * @mode_set (like shared PLLs, or again release pinned framebuffers).
77736b66080SDaniel Vetter 	 *
77836b66080SDaniel Vetter 	 * Therefore @disable must be the inverse of @mode_set plus @commit for
77936b66080SDaniel Vetter 	 * drivers still using legacy CRTC helpers, which is different from the
78036b66080SDaniel Vetter 	 * rules under atomic.
78136b66080SDaniel Vetter 	 */
782092d01daSDaniel Vetter 	void (*disable)(struct drm_encoder *encoder);
783092d01daSDaniel Vetter 
78436b66080SDaniel Vetter 	/**
78536b66080SDaniel Vetter 	 * @enable:
78636b66080SDaniel Vetter 	 *
78736b66080SDaniel Vetter 	 * This callback should be used to enable the encoder. With the atomic
78836b66080SDaniel Vetter 	 * drivers it is called after this encoder's CRTC has been enabled using
7896806cdf9SDaniel Vetter 	 * their own &drm_crtc_helper_funcs.enable hook.  If that sequence is
7906806cdf9SDaniel Vetter 	 * too simple drivers can just add their own driver private encoder
7916806cdf9SDaniel Vetter 	 * hooks and call them from CRTC's callback by looping over all encoders
7926806cdf9SDaniel Vetter 	 * connected to it using for_each_encoder_on_crtc().
79336b66080SDaniel Vetter 	 *
79409cc5609SSean Paul 	 * This hook is only used by atomic helpers, it is the opposite of
79509cc5609SSean Paul 	 * @disable. Atomic drivers don't need to implement it if there's no
79609cc5609SSean Paul 	 * need to enable anything at the encoder level. To ensure that
79709cc5609SSean Paul 	 * runtime PM handling (using either DPMS or the new "ACTIVE" property)
79809cc5609SSean Paul 	 * works @enable must be the inverse of @disable for atomic drivers.
79936b66080SDaniel Vetter 	 */
800092d01daSDaniel Vetter 	void (*enable)(struct drm_encoder *encoder);
801092d01daSDaniel Vetter 
80236b66080SDaniel Vetter 	/**
80336b66080SDaniel Vetter 	 * @atomic_check:
80436b66080SDaniel Vetter 	 *
80536b66080SDaniel Vetter 	 * This callback is used to validate encoder state for atomic drivers.
80636b66080SDaniel Vetter 	 * Since the encoder is the object connecting the CRTC and connector it
80736b66080SDaniel Vetter 	 * gets passed both states, to be able to validate interactions and
80836b66080SDaniel Vetter 	 * update the CRTC to match what the encoder needs for the requested
80936b66080SDaniel Vetter 	 * connector.
81036b66080SDaniel Vetter 	 *
8119f800214SDaniel Vetter 	 * Since this provides a strict superset of the functionality of
8129f800214SDaniel Vetter 	 * @mode_fixup (the requested and adjusted modes are both available
8139f800214SDaniel Vetter 	 * through the passed in &struct drm_crtc_state) @mode_fixup is not
8149f800214SDaniel Vetter 	 * called when @atomic_check is implemented.
8159f800214SDaniel Vetter 	 *
81636b66080SDaniel Vetter 	 * This function is used by the atomic helpers, but it is optional.
81736b66080SDaniel Vetter 	 *
81836b66080SDaniel Vetter 	 * NOTE:
81936b66080SDaniel Vetter 	 *
82036b66080SDaniel Vetter 	 * This function is called in the check phase of an atomic update. The
82136b66080SDaniel Vetter 	 * driver is not allowed to change anything outside of the free-standing
82236b66080SDaniel Vetter 	 * state objects passed-in or assembled in the overall &drm_atomic_state
82336b66080SDaniel Vetter 	 * update tracking structure.
82436b66080SDaniel Vetter 	 *
8253eb220a5SJose Abreu 	 * Also beware that userspace can request its own custom modes, neither
8263eb220a5SJose Abreu 	 * core nor helpers filter modes to the list of probe modes reported by
8273eb220a5SJose Abreu 	 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
8283eb220a5SJose Abreu 	 * that modes are filtered consistently put any encoder constraints and
8293eb220a5SJose Abreu 	 * limits checks into @mode_valid.
8303eb220a5SJose Abreu 	 *
83136b66080SDaniel Vetter 	 * RETURNS:
83236b66080SDaniel Vetter 	 *
83336b66080SDaniel Vetter 	 * 0 on success, -EINVAL if the state or the transition can't be
83436b66080SDaniel Vetter 	 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
83536b66080SDaniel Vetter 	 * attempt to obtain another state object ran into a &drm_modeset_lock
83636b66080SDaniel Vetter 	 * deadlock.
83736b66080SDaniel Vetter 	 */
838092d01daSDaniel Vetter 	int (*atomic_check)(struct drm_encoder *encoder,
839092d01daSDaniel Vetter 			    struct drm_crtc_state *crtc_state,
840092d01daSDaniel Vetter 			    struct drm_connector_state *conn_state);
841092d01daSDaniel Vetter };
842092d01daSDaniel Vetter 
843092d01daSDaniel Vetter /**
84436b66080SDaniel Vetter  * drm_encoder_helper_add - sets the helper vtable for an encoder
845092d01daSDaniel Vetter  * @encoder: DRM encoder
846092d01daSDaniel Vetter  * @funcs: helper vtable to set for @encoder
847092d01daSDaniel Vetter  */
drm_encoder_helper_add(struct drm_encoder * encoder,const struct drm_encoder_helper_funcs * funcs)848092d01daSDaniel Vetter static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
849092d01daSDaniel Vetter 					  const struct drm_encoder_helper_funcs *funcs)
850092d01daSDaniel Vetter {
851092d01daSDaniel Vetter 	encoder->helper_private = funcs;
852092d01daSDaniel Vetter }
853092d01daSDaniel Vetter 
854092d01daSDaniel Vetter /**
855092d01daSDaniel Vetter  * struct drm_connector_helper_funcs - helper operations for connectors
856092d01daSDaniel Vetter  *
8574ee6034cSDaniel Vetter  * These functions are used by the atomic and legacy modeset helpers and by the
8584ee6034cSDaniel Vetter  * probe helpers.
859092d01daSDaniel Vetter  */
860092d01daSDaniel Vetter struct drm_connector_helper_funcs {
8614ee6034cSDaniel Vetter 	/**
8624ee6034cSDaniel Vetter 	 * @get_modes:
8634ee6034cSDaniel Vetter 	 *
8644ee6034cSDaniel Vetter 	 * This function should fill in all modes currently valid for the sink
8656806cdf9SDaniel Vetter 	 * into the &drm_connector.probed_modes list. It should also update the
866c555f023SDaniel Vetter 	 * EDID property by calling drm_connector_update_edid_property().
8674ee6034cSDaniel Vetter 	 *
8684ee6034cSDaniel Vetter 	 * The usual way to implement this is to cache the EDID retrieved in the
8694ee6034cSDaniel Vetter 	 * probe callback somewhere in the driver-private connector structure.
8704ee6034cSDaniel Vetter 	 * In this function drivers then parse the modes in the EDID and add
8712551952eSLaurent Pinchart 	 * them by calling drm_add_edid_modes(). But connectors that drive a
8724ee6034cSDaniel Vetter 	 * fixed panel can also manually add specific modes using
873df7d678bSDaniel Vetter 	 * drm_mode_probed_add(). Drivers which manually add modes should also
8746806cdf9SDaniel Vetter 	 * make sure that the &drm_connector.display_info,
8756806cdf9SDaniel Vetter 	 * &drm_connector.width_mm and &drm_connector.height_mm fields are
8766806cdf9SDaniel Vetter 	 * filled in.
877df7d678bSDaniel Vetter 	 *
8782551952eSLaurent Pinchart 	 * Note that the caller function will automatically add standard VESA
8792551952eSLaurent Pinchart 	 * DMT modes up to 1024x768 if the .get_modes() helper operation returns
8802551952eSLaurent Pinchart 	 * no mode and if the connector status is connector_status_connected or
8812551952eSLaurent Pinchart 	 * connector_status_unknown. There is no need to call
8822551952eSLaurent Pinchart 	 * drm_add_modes_noedid() manually in that case.
8832551952eSLaurent Pinchart 	 *
884df7d678bSDaniel Vetter 	 * Virtual drivers that just want some standard VESA mode with a given
885df7d678bSDaniel Vetter 	 * resolution can call drm_add_modes_noedid(), and mark the preferred
886df7d678bSDaniel Vetter 	 * one using drm_set_preferred_mode().
887df7d678bSDaniel Vetter 	 *
8886806cdf9SDaniel Vetter 	 * This function is only called after the @detect hook has indicated
8894ee6034cSDaniel Vetter 	 * that a sink is connected and when the EDID isn't overridden through
8904ee6034cSDaniel Vetter 	 * sysfs or the kernel commandline.
8914ee6034cSDaniel Vetter 	 *
8924ee6034cSDaniel Vetter 	 * This callback is used by the probe helpers in e.g.
8934ee6034cSDaniel Vetter 	 * drm_helper_probe_single_connector_modes().
8944ee6034cSDaniel Vetter 	 *
8956c5ed5aeSMaarten Lankhorst 	 * To avoid races with concurrent connector state updates, the helper
8966c5ed5aeSMaarten Lankhorst 	 * libraries always call this with the &drm_mode_config.connection_mutex
8976c5ed5aeSMaarten Lankhorst 	 * held. Because of this it's safe to inspect &drm_connector->state.
8986c5ed5aeSMaarten Lankhorst 	 *
8994ee6034cSDaniel Vetter 	 * RETURNS:
9004ee6034cSDaniel Vetter 	 *
901*12bbe2c2SJani Nikula 	 * The number of modes added by calling drm_mode_probed_add(). Return 0
902*12bbe2c2SJani Nikula 	 * on failures (no modes) instead of negative error codes.
9034ee6034cSDaniel Vetter 	 */
904092d01daSDaniel Vetter 	int (*get_modes)(struct drm_connector *connector);
9054ee6034cSDaniel Vetter 
9064ee6034cSDaniel Vetter 	/**
9076c5ed5aeSMaarten Lankhorst 	 * @detect_ctx:
9086c5ed5aeSMaarten Lankhorst 	 *
9096c5ed5aeSMaarten Lankhorst 	 * Check to see if anything is attached to the connector. The parameter
9106c5ed5aeSMaarten Lankhorst 	 * force is set to false whilst polling, true when checking the
9116c5ed5aeSMaarten Lankhorst 	 * connector due to a user request. force can be used by the driver to
9126c5ed5aeSMaarten Lankhorst 	 * avoid expensive, destructive operations during automated probing.
9136c5ed5aeSMaarten Lankhorst 	 *
9146c5ed5aeSMaarten Lankhorst 	 * This callback is optional, if not implemented the connector will be
9156c5ed5aeSMaarten Lankhorst 	 * considered as always being attached.
9166c5ed5aeSMaarten Lankhorst 	 *
9176c5ed5aeSMaarten Lankhorst 	 * This is the atomic version of &drm_connector_funcs.detect.
9186c5ed5aeSMaarten Lankhorst 	 *
9196c5ed5aeSMaarten Lankhorst 	 * To avoid races against concurrent connector state updates, the
9206c5ed5aeSMaarten Lankhorst 	 * helper libraries always call this with ctx set to a valid context,
9216c5ed5aeSMaarten Lankhorst 	 * and &drm_mode_config.connection_mutex will always be locked with
9226c5ed5aeSMaarten Lankhorst 	 * the ctx parameter set to this ctx. This allows taking additional
9236c5ed5aeSMaarten Lankhorst 	 * locks as required.
9246c5ed5aeSMaarten Lankhorst 	 *
9256c5ed5aeSMaarten Lankhorst 	 * RETURNS:
9266c5ed5aeSMaarten Lankhorst 	 *
9276c5ed5aeSMaarten Lankhorst 	 * &drm_connector_status indicating the connector's status,
9286c5ed5aeSMaarten Lankhorst 	 * or the error code returned by drm_modeset_lock(), -EDEADLK.
9296c5ed5aeSMaarten Lankhorst 	 */
9306c5ed5aeSMaarten Lankhorst 	int (*detect_ctx)(struct drm_connector *connector,
9316c5ed5aeSMaarten Lankhorst 			  struct drm_modeset_acquire_ctx *ctx,
9326c5ed5aeSMaarten Lankhorst 			  bool force);
9336c5ed5aeSMaarten Lankhorst 
9346c5ed5aeSMaarten Lankhorst 	/**
9354ee6034cSDaniel Vetter 	 * @mode_valid:
9364ee6034cSDaniel Vetter 	 *
9374ee6034cSDaniel Vetter 	 * Callback to validate a mode for a connector, irrespective of the
9384ee6034cSDaniel Vetter 	 * specific display configuration.
9394ee6034cSDaniel Vetter 	 *
9404ee6034cSDaniel Vetter 	 * This callback is used by the probe helpers to filter the mode list
9414ee6034cSDaniel Vetter 	 * (which is usually derived from the EDID data block from the sink).
9424ee6034cSDaniel Vetter 	 * See e.g. drm_helper_probe_single_connector_modes().
9434ee6034cSDaniel Vetter 	 *
9443eb220a5SJose Abreu 	 * This function is optional.
9453eb220a5SJose Abreu 	 *
9464ee6034cSDaniel Vetter 	 * NOTE:
9474ee6034cSDaniel Vetter 	 *
9484ee6034cSDaniel Vetter 	 * This only filters the mode list supplied to userspace in the
9493eb220a5SJose Abreu 	 * GETCONNECTOR IOCTL. Compared to &drm_encoder_helper_funcs.mode_valid,
9503eb220a5SJose Abreu 	 * &drm_crtc_helper_funcs.mode_valid and &drm_bridge_funcs.mode_valid,
9513eb220a5SJose Abreu 	 * which are also called by the atomic helpers from
9523eb220a5SJose Abreu 	 * drm_atomic_helper_check_modeset(). This allows userspace to force and
9533eb220a5SJose Abreu 	 * ignore sink constraint (like the pixel clock limits in the screen's
9543eb220a5SJose Abreu 	 * EDID), which is useful for e.g. testing, or working around a broken
9553eb220a5SJose Abreu 	 * EDID. Any source hardware constraint (which always need to be
9563eb220a5SJose Abreu 	 * enforced) therefore should be checked in one of the above callbacks,
9573eb220a5SJose Abreu 	 * and not this one here.
9584ee6034cSDaniel Vetter 	 *
9596c5ed5aeSMaarten Lankhorst 	 * To avoid races with concurrent connector state updates, the helper
9606c5ed5aeSMaarten Lankhorst 	 * libraries always call this with the &drm_mode_config.connection_mutex
9616c5ed5aeSMaarten Lankhorst 	 * held. Because of this it's safe to inspect &drm_connector->state.
9626c5ed5aeSMaarten Lankhorst          *
9634ee6034cSDaniel Vetter 	 * RETURNS:
9644ee6034cSDaniel Vetter 	 *
9656806cdf9SDaniel Vetter 	 * Either &drm_mode_status.MODE_OK or one of the failure reasons in &enum
9666806cdf9SDaniel Vetter 	 * drm_mode_status.
9674ee6034cSDaniel Vetter 	 */
968092d01daSDaniel Vetter 	enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
969092d01daSDaniel Vetter 					   struct drm_display_mode *mode);
9701c26b8e0SLyude Paul 
9711c26b8e0SLyude Paul 	/**
9721c26b8e0SLyude Paul 	 * @mode_valid_ctx:
9731c26b8e0SLyude Paul 	 *
9741c26b8e0SLyude Paul 	 * Callback to validate a mode for a connector, irrespective of the
9751c26b8e0SLyude Paul 	 * specific display configuration.
9761c26b8e0SLyude Paul 	 *
9771c26b8e0SLyude Paul 	 * This callback is used by the probe helpers to filter the mode list
9781c26b8e0SLyude Paul 	 * (which is usually derived from the EDID data block from the sink).
9791c26b8e0SLyude Paul 	 * See e.g. drm_helper_probe_single_connector_modes().
9801c26b8e0SLyude Paul 	 *
9811c26b8e0SLyude Paul 	 * This function is optional, and is the atomic version of
9821c26b8e0SLyude Paul 	 * &drm_connector_helper_funcs.mode_valid.
9831c26b8e0SLyude Paul 	 *
9841c26b8e0SLyude Paul 	 * To allow for accessing the atomic state of modesetting objects, the
9851c26b8e0SLyude Paul 	 * helper libraries always call this with ctx set to a valid context,
9861c26b8e0SLyude Paul 	 * and &drm_mode_config.connection_mutex will always be locked with
9871c26b8e0SLyude Paul 	 * the ctx parameter set to @ctx. This allows for taking additional
9881c26b8e0SLyude Paul 	 * locks as required.
9891c26b8e0SLyude Paul 	 *
9901c26b8e0SLyude Paul 	 * Even though additional locks may be acquired, this callback is
9911c26b8e0SLyude Paul 	 * still expected not to take any constraints into account which would
9921c26b8e0SLyude Paul 	 * be influenced by the currently set display state - such constraints
9931c26b8e0SLyude Paul 	 * should be handled in the driver's atomic check. For example, if a
9941c26b8e0SLyude Paul 	 * connector shares display bandwidth with other connectors then it
9951c26b8e0SLyude Paul 	 * would be ok to validate the minimum bandwidth requirement of a mode
9961c26b8e0SLyude Paul 	 * against the maximum possible bandwidth of the connector. But it
9971c26b8e0SLyude Paul 	 * wouldn't be ok to take the current bandwidth usage of other
9981c26b8e0SLyude Paul 	 * connectors into account, as this would change depending on the
9991c26b8e0SLyude Paul 	 * display state.
10001c26b8e0SLyude Paul 	 *
10011c26b8e0SLyude Paul 	 * Returns:
10021c26b8e0SLyude Paul 	 * 0 if &drm_connector_helper_funcs.mode_valid_ctx succeeded and wrote
10031c26b8e0SLyude Paul 	 * the &enum drm_mode_status value to @status, or a negative error
10041c26b8e0SLyude Paul 	 * code otherwise.
10051c26b8e0SLyude Paul 	 *
10061c26b8e0SLyude Paul 	 */
10071c26b8e0SLyude Paul 	int (*mode_valid_ctx)(struct drm_connector *connector,
10081c26b8e0SLyude Paul 			      struct drm_display_mode *mode,
10091c26b8e0SLyude Paul 			      struct drm_modeset_acquire_ctx *ctx,
10101c26b8e0SLyude Paul 			      enum drm_mode_status *status);
10111c26b8e0SLyude Paul 
10124ee6034cSDaniel Vetter 	/**
10134ee6034cSDaniel Vetter 	 * @best_encoder:
10144ee6034cSDaniel Vetter 	 *
10154ee6034cSDaniel Vetter 	 * This function should select the best encoder for the given connector.
10164ee6034cSDaniel Vetter 	 *
10174ee6034cSDaniel Vetter 	 * This function is used by both the atomic helpers (in the
10184ee6034cSDaniel Vetter 	 * drm_atomic_helper_check_modeset() function) and in the legacy CRTC
10194ee6034cSDaniel Vetter 	 * helpers.
10204ee6034cSDaniel Vetter 	 *
10214ee6034cSDaniel Vetter 	 * NOTE:
10224ee6034cSDaniel Vetter 	 *
10234ee6034cSDaniel Vetter 	 * In atomic drivers this function is called in the check phase of an
10244ee6034cSDaniel Vetter 	 * atomic update. The driver is not allowed to change or inspect
10254ee6034cSDaniel Vetter 	 * anything outside of arguments passed-in. Atomic drivers which need to
10264ee6034cSDaniel Vetter 	 * inspect dynamic configuration state should instead use
10274ee6034cSDaniel Vetter 	 * @atomic_best_encoder.
10284ee6034cSDaniel Vetter 	 *
1029c61b93feSBoris Brezillon 	 * You can leave this function to NULL if the connector is only
1030a92462d6SJosé Roberto de Souza 	 * attached to a single encoder. In this case, the core will call
1031a92462d6SJosé Roberto de Souza 	 * drm_connector_get_single_encoder() for you.
1032c61b93feSBoris Brezillon 	 *
10334ee6034cSDaniel Vetter 	 * RETURNS:
10344ee6034cSDaniel Vetter 	 *
10354ee6034cSDaniel Vetter 	 * Encoder that should be used for the given connector and connector
10364ee6034cSDaniel Vetter 	 * state, or NULL if no suitable encoder exists. Note that the helpers
10374ee6034cSDaniel Vetter 	 * will ensure that encoders aren't used twice, drivers should not check
10384ee6034cSDaniel Vetter 	 * for this.
10394ee6034cSDaniel Vetter 	 */
1040092d01daSDaniel Vetter 	struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
10414ee6034cSDaniel Vetter 
10424ee6034cSDaniel Vetter 	/**
10434ee6034cSDaniel Vetter 	 * @atomic_best_encoder:
10444ee6034cSDaniel Vetter 	 *
10454ee6034cSDaniel Vetter 	 * This is the atomic version of @best_encoder for atomic drivers which
10464ee6034cSDaniel Vetter 	 * need to select the best encoder depending upon the desired
10474ee6034cSDaniel Vetter 	 * configuration and can't select it statically.
10484ee6034cSDaniel Vetter 	 *
1049c61b93feSBoris Brezillon 	 * This function is used by drm_atomic_helper_check_modeset().
1050c61b93feSBoris Brezillon 	 * If it is not implemented, the core will fallback to @best_encoder
1051a92462d6SJosé Roberto de Souza 	 * (or drm_connector_get_single_encoder() if @best_encoder is NULL).
10524ee6034cSDaniel Vetter 	 *
10534ee6034cSDaniel Vetter 	 * NOTE:
10544ee6034cSDaniel Vetter 	 *
10554ee6034cSDaniel Vetter 	 * This function is called in the check phase of an atomic update. The
1056eca22edbSMaxime Ripard 	 * driver is not allowed to change anything outside of the
1057eca22edbSMaxime Ripard 	 * &drm_atomic_state update tracking structure passed in.
10584ee6034cSDaniel Vetter 	 *
10594ee6034cSDaniel Vetter 	 * RETURNS:
10604ee6034cSDaniel Vetter 	 *
10614ee6034cSDaniel Vetter 	 * Encoder that should be used for the given connector and connector
10624ee6034cSDaniel Vetter 	 * state, or NULL if no suitable encoder exists. Note that the helpers
10634ee6034cSDaniel Vetter 	 * will ensure that encoders aren't used twice, drivers should not check
10644ee6034cSDaniel Vetter 	 * for this.
10654ee6034cSDaniel Vetter 	 */
1066092d01daSDaniel Vetter 	struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,
1067eca22edbSMaxime Ripard 						   struct drm_atomic_state *state);
1068ce09d766SMaarten Lankhorst 
1069ce09d766SMaarten Lankhorst 	/**
1070ce09d766SMaarten Lankhorst 	 * @atomic_check:
1071ce09d766SMaarten Lankhorst 	 *
1072ce09d766SMaarten Lankhorst 	 * This hook is used to validate connector state. This function is
1073ce09d766SMaarten Lankhorst 	 * called from &drm_atomic_helper_check_modeset, and is called when
1074ce09d766SMaarten Lankhorst 	 * a connector property is set, or a modeset on the crtc is forced.
1075ce09d766SMaarten Lankhorst 	 *
1076ce09d766SMaarten Lankhorst 	 * Because &drm_atomic_helper_check_modeset may be called multiple times,
1077ce09d766SMaarten Lankhorst 	 * this function should handle being called multiple times as well.
1078ce09d766SMaarten Lankhorst 	 *
1079ce09d766SMaarten Lankhorst 	 * This function is also allowed to inspect any other object's state and
1080ce09d766SMaarten Lankhorst 	 * can add more state objects to the atomic commit if needed. Care must
1081ce09d766SMaarten Lankhorst 	 * be taken though to ensure that state check and compute functions for
1082ce09d766SMaarten Lankhorst 	 * these added states are all called, and derived state in other objects
1083ce09d766SMaarten Lankhorst 	 * all updated. Again the recommendation is to just call check helpers
1084ce09d766SMaarten Lankhorst 	 * until a maximal configuration is reached.
1085ce09d766SMaarten Lankhorst 	 *
1086ce09d766SMaarten Lankhorst 	 * NOTE:
1087ce09d766SMaarten Lankhorst 	 *
1088ce09d766SMaarten Lankhorst 	 * This function is called in the check phase of an atomic update. The
1089ce09d766SMaarten Lankhorst 	 * driver is not allowed to change anything outside of the free-standing
1090ce09d766SMaarten Lankhorst 	 * state objects passed-in or assembled in the overall &drm_atomic_state
1091ce09d766SMaarten Lankhorst 	 * update tracking structure.
1092ce09d766SMaarten Lankhorst 	 *
1093ce09d766SMaarten Lankhorst 	 * RETURNS:
1094ce09d766SMaarten Lankhorst 	 *
1095ce09d766SMaarten Lankhorst 	 * 0 on success, -EINVAL if the state or the transition can't be
1096ce09d766SMaarten Lankhorst 	 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
1097ce09d766SMaarten Lankhorst 	 * attempt to obtain another state object ran into a &drm_modeset_lock
1098ce09d766SMaarten Lankhorst 	 * deadlock.
1099ce09d766SMaarten Lankhorst 	 */
1100ce09d766SMaarten Lankhorst 	int (*atomic_check)(struct drm_connector *connector,
11016f3b6278SSean Paul 			    struct drm_atomic_state *state);
1102935774cdSBrian Starkey 
1103935774cdSBrian Starkey 	/**
1104935774cdSBrian Starkey 	 * @atomic_commit:
1105935774cdSBrian Starkey 	 *
1106935774cdSBrian Starkey 	 * This hook is to be used by drivers implementing writeback connectors
1107935774cdSBrian Starkey 	 * that need a point when to commit the writeback job to the hardware.
1108eca22edbSMaxime Ripard 	 * The writeback_job to commit is available in the new connector state,
1109eca22edbSMaxime Ripard 	 * in &drm_connector_state.writeback_job.
1110935774cdSBrian Starkey 	 *
1111814bde99SBoris Brezillon 	 * This hook is optional.
1112814bde99SBoris Brezillon 	 *
1113935774cdSBrian Starkey 	 * This callback is used by the atomic modeset helpers.
1114935774cdSBrian Starkey 	 */
1115935774cdSBrian Starkey 	void (*atomic_commit)(struct drm_connector *connector,
1116eca22edbSMaxime Ripard 			      struct drm_atomic_state *state);
11179d2230dcSLaurent Pinchart 
111821de71f6SSam Ravnborg 	/**
111921de71f6SSam Ravnborg 	 * @prepare_writeback_job:
112021de71f6SSam Ravnborg 	 *
112121de71f6SSam Ravnborg 	 * As writeback jobs contain a framebuffer, drivers may need to
112221de71f6SSam Ravnborg 	 * prepare and clean them up the same way they can prepare and
112321de71f6SSam Ravnborg 	 * clean up framebuffers for planes. This optional connector operation
112421de71f6SSam Ravnborg 	 * is used to support the preparation of writeback jobs. The job
112521de71f6SSam Ravnborg 	 * prepare operation is called from drm_atomic_helper_prepare_planes()
112621de71f6SSam Ravnborg 	 * for struct &drm_writeback_connector connectors only.
112721de71f6SSam Ravnborg 	 *
112821de71f6SSam Ravnborg 	 * This operation is optional.
112921de71f6SSam Ravnborg 	 *
113021de71f6SSam Ravnborg 	 * This callback is used by the atomic modeset helpers.
113121de71f6SSam Ravnborg 	 */
11329d2230dcSLaurent Pinchart 	int (*prepare_writeback_job)(struct drm_writeback_connector *connector,
11339d2230dcSLaurent Pinchart 				     struct drm_writeback_job *job);
113421de71f6SSam Ravnborg 	/**
113521de71f6SSam Ravnborg 	 * @cleanup_writeback_job:
113621de71f6SSam Ravnborg 	 *
113721de71f6SSam Ravnborg 	 * This optional connector operation is used to support the
113821de71f6SSam Ravnborg 	 * cleanup of writeback jobs. The job cleanup operation is called
113921de71f6SSam Ravnborg 	 * from the existing drm_writeback_cleanup_job() function, invoked
114021de71f6SSam Ravnborg 	 * both when destroying the job as part of an aborted commit, or when
114121de71f6SSam Ravnborg 	 * the job completes.
114221de71f6SSam Ravnborg 	 *
114321de71f6SSam Ravnborg 	 * This operation is optional.
114421de71f6SSam Ravnborg 	 *
114521de71f6SSam Ravnborg 	 * This callback is used by the atomic modeset helpers.
114621de71f6SSam Ravnborg 	 */
11479d2230dcSLaurent Pinchart 	void (*cleanup_writeback_job)(struct drm_writeback_connector *connector,
11489d2230dcSLaurent Pinchart 				      struct drm_writeback_job *job);
1149c8268795SDmitry Baryshkov 
1150c8268795SDmitry Baryshkov 	/**
1151c8268795SDmitry Baryshkov 	 * @enable_hpd:
1152c8268795SDmitry Baryshkov 	 *
1153c8268795SDmitry Baryshkov 	 * Enable hot-plug detection for the connector.
1154c8268795SDmitry Baryshkov 	 *
1155c8268795SDmitry Baryshkov 	 * This operation is optional.
1156c8268795SDmitry Baryshkov 	 *
1157c8268795SDmitry Baryshkov 	 * This callback is used by the drm_kms_helper_poll_enable() helpers.
1158c8268795SDmitry Baryshkov 	 */
1159c8268795SDmitry Baryshkov 	void (*enable_hpd)(struct drm_connector *connector);
1160c8268795SDmitry Baryshkov 
1161c8268795SDmitry Baryshkov 	/**
1162c8268795SDmitry Baryshkov 	 * @disable_hpd:
1163c8268795SDmitry Baryshkov 	 *
1164c8268795SDmitry Baryshkov 	 * Disable hot-plug detection for the connector.
1165c8268795SDmitry Baryshkov 	 *
1166c8268795SDmitry Baryshkov 	 * This operation is optional.
1167c8268795SDmitry Baryshkov 	 *
1168c8268795SDmitry Baryshkov 	 * This callback is used by the drm_kms_helper_poll_disable() helpers.
1169c8268795SDmitry Baryshkov 	 */
1170c8268795SDmitry Baryshkov 	void (*disable_hpd)(struct drm_connector *connector);
1171092d01daSDaniel Vetter };
1172092d01daSDaniel Vetter 
1173092d01daSDaniel Vetter /**
1174092d01daSDaniel Vetter  * drm_connector_helper_add - sets the helper vtable for a connector
1175092d01daSDaniel Vetter  * @connector: DRM connector
1176092d01daSDaniel Vetter  * @funcs: helper vtable to set for @connector
1177092d01daSDaniel Vetter  */
drm_connector_helper_add(struct drm_connector * connector,const struct drm_connector_helper_funcs * funcs)1178092d01daSDaniel Vetter static inline void drm_connector_helper_add(struct drm_connector *connector,
1179092d01daSDaniel Vetter 					    const struct drm_connector_helper_funcs *funcs)
1180092d01daSDaniel Vetter {
1181092d01daSDaniel Vetter 	connector->helper_private = funcs;
1182092d01daSDaniel Vetter }
1183092d01daSDaniel Vetter 
1184092d01daSDaniel Vetter /**
118511a0ba97SDaniel Vetter  * struct drm_plane_helper_funcs - helper operations for planes
1186092d01daSDaniel Vetter  *
118781ed7d73SGeert Uytterhoeven  * These functions are used by the atomic helpers.
1188092d01daSDaniel Vetter  */
1189092d01daSDaniel Vetter struct drm_plane_helper_funcs {
119011a0ba97SDaniel Vetter 	/**
119111a0ba97SDaniel Vetter 	 * @prepare_fb:
119211a0ba97SDaniel Vetter 	 *
119311a0ba97SDaniel Vetter 	 * This hook is to prepare a framebuffer for scanout by e.g. pinning
11941e55a53aSMatt Roper 	 * its backing storage or relocating it into a contiguous block of
119511a0ba97SDaniel Vetter 	 * VRAM. Other possible preparatory work includes flushing caches.
119611a0ba97SDaniel Vetter 	 *
119711a0ba97SDaniel Vetter 	 * This function must not block for outstanding rendering, since it is
119811a0ba97SDaniel Vetter 	 * called in the context of the atomic IOCTL even for async commits to
119911a0ba97SDaniel Vetter 	 * be able to return any errors to userspace. Instead the recommended
120030d23f22SDaniel Vetter 	 * way is to fill out the &drm_plane_state.fence of the passed-in
120111a0ba97SDaniel Vetter 	 * &drm_plane_state. If the driver doesn't support native fences then
120211a0ba97SDaniel Vetter 	 * equivalent functionality should be implemented through private
120311a0ba97SDaniel Vetter 	 * members in the plane structure.
120411a0ba97SDaniel Vetter 	 *
12057d30963fSDaniel Vetter 	 * For GEM drivers who neither have a @prepare_fb nor @cleanup_fb hook
12067d30963fSDaniel Vetter 	 * set drm_gem_plane_helper_prepare_fb() is called automatically to
12077d30963fSDaniel Vetter 	 * implement this. Other drivers which need additional plane processing
12087d30963fSDaniel Vetter 	 * can call drm_gem_plane_helper_prepare_fb() from their @prepare_fb
12097d30963fSDaniel Vetter 	 * hook.
121030d23f22SDaniel Vetter 	 *
121194d879eaSThomas Zimmermann 	 * The resources acquired in @prepare_fb persist after the end of
121294d879eaSThomas Zimmermann 	 * the atomic commit. Resources that can be release at the commit's end
121394d879eaSThomas Zimmermann 	 * should be acquired in @begin_fb_access and released in @end_fb_access.
121494d879eaSThomas Zimmermann 	 * For example, a GEM buffer's pin operation belongs into @prepare_fb to
121594d879eaSThomas Zimmermann 	 * keep the buffer pinned after the commit. But a vmap operation for
121694d879eaSThomas Zimmermann 	 * shadow-plane helpers belongs into @begin_fb_access, so that atomic
121794d879eaSThomas Zimmermann 	 * helpers remove the mapping at the end of the commit.
121894d879eaSThomas Zimmermann 	 *
121911a0ba97SDaniel Vetter 	 * The helpers will call @cleanup_fb with matching arguments for every
122011a0ba97SDaniel Vetter 	 * successful call to this hook.
122111a0ba97SDaniel Vetter 	 *
122281ed7d73SGeert Uytterhoeven 	 * This callback is used by the atomic modeset helpers, but it is
122381ed7d73SGeert Uytterhoeven 	 * optional. See @begin_fb_access for preparing per-commit resources.
122411a0ba97SDaniel Vetter 	 *
122511a0ba97SDaniel Vetter 	 * RETURNS:
122611a0ba97SDaniel Vetter 	 *
122711a0ba97SDaniel Vetter 	 * 0 on success or one of the following negative error codes allowed by
12286806cdf9SDaniel Vetter 	 * the &drm_mode_config_funcs.atomic_commit vfunc. When using helpers
122911a0ba97SDaniel Vetter 	 * this callback is the only one which can fail an atomic commit,
123011a0ba97SDaniel Vetter 	 * everything else must complete successfully.
123111a0ba97SDaniel Vetter 	 */
1232092d01daSDaniel Vetter 	int (*prepare_fb)(struct drm_plane *plane,
12331832040dSChris Wilson 			  struct drm_plane_state *new_state);
123411a0ba97SDaniel Vetter 	/**
123511a0ba97SDaniel Vetter 	 * @cleanup_fb:
123611a0ba97SDaniel Vetter 	 *
123711a0ba97SDaniel Vetter 	 * This hook is called to clean up any resources allocated for the given
123811a0ba97SDaniel Vetter 	 * framebuffer and plane configuration in @prepare_fb.
123911a0ba97SDaniel Vetter 	 *
124081ed7d73SGeert Uytterhoeven 	 * This callback is used by the atomic modeset helpers, but it is
124181ed7d73SGeert Uytterhoeven 	 * optional.
124211a0ba97SDaniel Vetter 	 */
1243092d01daSDaniel Vetter 	void (*cleanup_fb)(struct drm_plane *plane,
12441832040dSChris Wilson 			   struct drm_plane_state *old_state);
1245092d01daSDaniel Vetter 
124611a0ba97SDaniel Vetter 	/**
124794d879eaSThomas Zimmermann 	 * @begin_fb_access:
124894d879eaSThomas Zimmermann 	 *
124994d879eaSThomas Zimmermann 	 * This hook prepares the plane for access during an atomic commit.
125094d879eaSThomas Zimmermann 	 * In contrast to @prepare_fb, resources acquired in @begin_fb_access,
125194d879eaSThomas Zimmermann 	 * are released at the end of the atomic commit in @end_fb_access.
125294d879eaSThomas Zimmermann 	 *
125394d879eaSThomas Zimmermann 	 * For example, with shadow-plane helpers, the GEM buffer's vmap
125494d879eaSThomas Zimmermann 	 * operation belongs into @begin_fb_access, so that the buffer's
125594d879eaSThomas Zimmermann 	 * memory will be unmapped at the end of the commit in @end_fb_access.
125694d879eaSThomas Zimmermann 	 * But a GEM buffer's pin operation belongs into @prepare_fb
125794d879eaSThomas Zimmermann 	 * to keep the buffer pinned after the commit.
125894d879eaSThomas Zimmermann 	 *
125994d879eaSThomas Zimmermann 	 * The callback is used by the atomic modeset helpers, but it is optional.
126094d879eaSThomas Zimmermann 	 * See @end_fb_cleanup for undoing the effects of @begin_fb_access and
126194d879eaSThomas Zimmermann 	 * @prepare_fb for acquiring resources until the next pageflip.
126294d879eaSThomas Zimmermann 	 *
126394d879eaSThomas Zimmermann 	 * Returns:
126494d879eaSThomas Zimmermann 	 * 0 on success, or a negative errno code otherwise.
126594d879eaSThomas Zimmermann 	 */
126694d879eaSThomas Zimmermann 	int (*begin_fb_access)(struct drm_plane *plane, struct drm_plane_state *new_plane_state);
126794d879eaSThomas Zimmermann 
126894d879eaSThomas Zimmermann 	/**
126994d879eaSThomas Zimmermann 	 * @end_fb_access:
127094d879eaSThomas Zimmermann 	 *
127194d879eaSThomas Zimmermann 	 * This hook cleans up resources allocated by @begin_fb_access. It it called
127294d879eaSThomas Zimmermann 	 * at the end of a commit for the new plane state.
127394d879eaSThomas Zimmermann 	 */
127494d879eaSThomas Zimmermann 	void (*end_fb_access)(struct drm_plane *plane, struct drm_plane_state *new_plane_state);
127594d879eaSThomas Zimmermann 
127694d879eaSThomas Zimmermann 	/**
127711a0ba97SDaniel Vetter 	 * @atomic_check:
127811a0ba97SDaniel Vetter 	 *
127911a0ba97SDaniel Vetter 	 * Drivers should check plane specific constraints in this hook.
128011a0ba97SDaniel Vetter 	 *
12816806cdf9SDaniel Vetter 	 * When using drm_atomic_helper_check_planes() plane's @atomic_check
128211a0ba97SDaniel Vetter 	 * hooks are called before the ones for CRTCs, which allows drivers to
128311a0ba97SDaniel Vetter 	 * request shared resources that the CRTC controls here. For more
128411a0ba97SDaniel Vetter 	 * complicated dependencies the driver can call the provided check helpers
128511a0ba97SDaniel Vetter 	 * multiple times until the computed state has a final configuration and
128611a0ba97SDaniel Vetter 	 * everything has been checked.
128711a0ba97SDaniel Vetter 	 *
128811a0ba97SDaniel Vetter 	 * This function is also allowed to inspect any other object's state and
128911a0ba97SDaniel Vetter 	 * can add more state objects to the atomic commit if needed. Care must
12906806cdf9SDaniel Vetter 	 * be taken though to ensure that state check and compute functions for
129111a0ba97SDaniel Vetter 	 * these added states are all called, and derived state in other objects
129211a0ba97SDaniel Vetter 	 * all updated. Again the recommendation is to just call check helpers
129311a0ba97SDaniel Vetter 	 * until a maximal configuration is reached.
129411a0ba97SDaniel Vetter 	 *
129581ed7d73SGeert Uytterhoeven 	 * This callback is used by the atomic modeset helpers, but it is
129681ed7d73SGeert Uytterhoeven 	 * optional.
129711a0ba97SDaniel Vetter 	 *
129811a0ba97SDaniel Vetter 	 * NOTE:
129911a0ba97SDaniel Vetter 	 *
130011a0ba97SDaniel Vetter 	 * This function is called in the check phase of an atomic update. The
13017c11b99aSMaxime Ripard 	 * driver is not allowed to change anything outside of the
13027c11b99aSMaxime Ripard 	 * &drm_atomic_state update tracking structure.
130311a0ba97SDaniel Vetter 	 *
130411a0ba97SDaniel Vetter 	 * RETURNS:
130511a0ba97SDaniel Vetter 	 *
130611a0ba97SDaniel Vetter 	 * 0 on success, -EINVAL if the state or the transition can't be
130711a0ba97SDaniel Vetter 	 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
130811a0ba97SDaniel Vetter 	 * attempt to obtain another state object ran into a &drm_modeset_lock
130911a0ba97SDaniel Vetter 	 * deadlock.
131011a0ba97SDaniel Vetter 	 */
1311092d01daSDaniel Vetter 	int (*atomic_check)(struct drm_plane *plane,
13127c11b99aSMaxime Ripard 			    struct drm_atomic_state *state);
131311a0ba97SDaniel Vetter 
131411a0ba97SDaniel Vetter 	/**
131511a0ba97SDaniel Vetter 	 * @atomic_update:
131611a0ba97SDaniel Vetter 	 *
131711a0ba97SDaniel Vetter 	 * Drivers should use this function to update the plane state.  This
13186806cdf9SDaniel Vetter 	 * hook is called in-between the &drm_crtc_helper_funcs.atomic_begin and
13196806cdf9SDaniel Vetter 	 * drm_crtc_helper_funcs.atomic_flush callbacks.
132011a0ba97SDaniel Vetter 	 *
132111a0ba97SDaniel Vetter 	 * Note that the power state of the display pipe when this function is
132211a0ba97SDaniel Vetter 	 * called depends upon the exact helpers and calling sequence the driver
13230dc9967dSStefan Agner 	 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
13240dc9967dSStefan Agner 	 * the tradeoffs and variants of plane commit helpers.
132511a0ba97SDaniel Vetter 	 *
132681ed7d73SGeert Uytterhoeven 	 * This callback is used by the atomic modeset helpers, but it is optional.
132711a0ba97SDaniel Vetter 	 */
1328092d01daSDaniel Vetter 	void (*atomic_update)(struct drm_plane *plane,
1329977697e2SMaxime Ripard 			      struct drm_atomic_state *state);
1330169b9182SThomas Zimmermann 
1331169b9182SThomas Zimmermann 	/**
1332169b9182SThomas Zimmermann 	 * @atomic_enable:
1333169b9182SThomas Zimmermann 	 *
1334169b9182SThomas Zimmermann 	 * Drivers should use this function to unconditionally enable a plane.
1335169b9182SThomas Zimmermann 	 * This hook is called in-between the &drm_crtc_helper_funcs.atomic_begin
1336169b9182SThomas Zimmermann 	 * and drm_crtc_helper_funcs.atomic_flush callbacks. It is called after
1337169b9182SThomas Zimmermann 	 * @atomic_update, which will be called for all enabled planes. Drivers
1338169b9182SThomas Zimmermann 	 * that use @atomic_enable should set up a plane in @atomic_update and
1339169b9182SThomas Zimmermann 	 * afterwards enable the plane in @atomic_enable. If a plane needs to be
1340169b9182SThomas Zimmermann 	 * enabled before installing the scanout buffer, drivers can still do
1341169b9182SThomas Zimmermann 	 * so in @atomic_update.
1342169b9182SThomas Zimmermann 	 *
1343169b9182SThomas Zimmermann 	 * Note that the power state of the display pipe when this function is
1344169b9182SThomas Zimmermann 	 * called depends upon the exact helpers and calling sequence the driver
1345169b9182SThomas Zimmermann 	 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
1346169b9182SThomas Zimmermann 	 * the tradeoffs and variants of plane commit helpers.
1347169b9182SThomas Zimmermann 	 *
1348169b9182SThomas Zimmermann 	 * This callback is used by the atomic modeset helpers, but it is
1349169b9182SThomas Zimmermann 	 * optional. If implemented, @atomic_enable should be the inverse of
1350169b9182SThomas Zimmermann 	 * @atomic_disable. Drivers that don't want to use either can still
1351169b9182SThomas Zimmermann 	 * implement the complete plane update in @atomic_update.
1352169b9182SThomas Zimmermann 	 */
1353169b9182SThomas Zimmermann 	void (*atomic_enable)(struct drm_plane *plane,
1354169b9182SThomas Zimmermann 			      struct drm_atomic_state *state);
1355169b9182SThomas Zimmermann 
135611a0ba97SDaniel Vetter 	/**
135711a0ba97SDaniel Vetter 	 * @atomic_disable:
135811a0ba97SDaniel Vetter 	 *
135911a0ba97SDaniel Vetter 	 * Drivers should use this function to unconditionally disable a plane.
13606806cdf9SDaniel Vetter 	 * This hook is called in-between the
13616806cdf9SDaniel Vetter 	 * &drm_crtc_helper_funcs.atomic_begin and
13626806cdf9SDaniel Vetter 	 * drm_crtc_helper_funcs.atomic_flush callbacks. It is an alternative to
136311a0ba97SDaniel Vetter 	 * @atomic_update, which will be called for disabling planes, too, if
136411a0ba97SDaniel Vetter 	 * the @atomic_disable hook isn't implemented.
136511a0ba97SDaniel Vetter 	 *
136611a0ba97SDaniel Vetter 	 * This hook is also useful to disable planes in preparation of a modeset,
136711a0ba97SDaniel Vetter 	 * by calling drm_atomic_helper_disable_planes_on_crtc() from the
13686806cdf9SDaniel Vetter 	 * &drm_crtc_helper_funcs.disable hook.
136911a0ba97SDaniel Vetter 	 *
137011a0ba97SDaniel Vetter 	 * Note that the power state of the display pipe when this function is
137111a0ba97SDaniel Vetter 	 * called depends upon the exact helpers and calling sequence the driver
13720dc9967dSStefan Agner 	 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
13730dc9967dSStefan Agner 	 * the tradeoffs and variants of plane commit helpers.
137411a0ba97SDaniel Vetter 	 *
137581ed7d73SGeert Uytterhoeven 	 * This callback is used by the atomic modeset helpers, but it is
137681ed7d73SGeert Uytterhoeven 	 * optional. It's intended to reverse the effects of @atomic_enable.
137711a0ba97SDaniel Vetter 	 */
1378092d01daSDaniel Vetter 	void (*atomic_disable)(struct drm_plane *plane,
1379977697e2SMaxime Ripard 			       struct drm_atomic_state *state);
1380fef9df8bSGustavo Padovan 
1381fef9df8bSGustavo Padovan 	/**
1382fef9df8bSGustavo Padovan 	 * @atomic_async_check:
1383fef9df8bSGustavo Padovan 	 *
13845ddb0bd4SMaxime Ripard 	 * Drivers should set this function pointer to check if the plane's
13855ddb0bd4SMaxime Ripard 	 * atomic state can be updated in a async fashion. Here async means
13865ddb0bd4SMaxime Ripard 	 * "not vblank synchronized".
1387fef9df8bSGustavo Padovan 	 *
1388fef9df8bSGustavo Padovan 	 * This hook is called by drm_atomic_async_check() to establish if a
1389fef9df8bSGustavo Padovan 	 * given update can be committed asynchronously, that is, if it can
1390fef9df8bSGustavo Padovan 	 * jump ahead of the state currently queued for update.
1391fef9df8bSGustavo Padovan 	 *
1392fef9df8bSGustavo Padovan 	 * RETURNS:
1393fef9df8bSGustavo Padovan 	 *
1394fef9df8bSGustavo Padovan 	 * Return 0 on success and any error returned indicates that the update
1395fef9df8bSGustavo Padovan 	 * can not be applied in asynchronous manner.
1396fef9df8bSGustavo Padovan 	 */
1397fef9df8bSGustavo Padovan 	int (*atomic_async_check)(struct drm_plane *plane,
13985ddb0bd4SMaxime Ripard 				  struct drm_atomic_state *state);
1399fef9df8bSGustavo Padovan 
1400fef9df8bSGustavo Padovan 	/**
1401fef9df8bSGustavo Padovan 	 * @atomic_async_update:
1402fef9df8bSGustavo Padovan 	 *
1403fef9df8bSGustavo Padovan 	 * Drivers should set this function pointer to perform asynchronous
1404fef9df8bSGustavo Padovan 	 * updates of planes, that is, jump ahead of the currently queued
1405fef9df8bSGustavo Padovan 	 * state and update the plane. Here async means "not vblank
1406fef9df8bSGustavo Padovan 	 * synchronized".
1407fef9df8bSGustavo Padovan 	 *
1408fef9df8bSGustavo Padovan 	 * This hook is called by drm_atomic_helper_async_commit().
1409fef9df8bSGustavo Padovan 	 *
1410fef9df8bSGustavo Padovan 	 * An async update will happen on legacy cursor updates. An async
1411fef9df8bSGustavo Padovan 	 * update won't happen if there is an outstanding commit modifying
1412fef9df8bSGustavo Padovan 	 * the same plane.
1413fef9df8bSGustavo Padovan 	 *
14145ddb0bd4SMaxime Ripard 	 * When doing async_update drivers shouldn't replace the
14155ddb0bd4SMaxime Ripard 	 * &drm_plane_state but update the current one with the new plane
14165ddb0bd4SMaxime Ripard 	 * configurations in the new plane_state.
1417fef9df8bSGustavo Padovan 	 *
141889a4aac0SHelen Koike 	 * Drivers should also swap the framebuffers between current plane
141989a4aac0SHelen Koike 	 * state (&drm_plane.state) and new_state.
142089a4aac0SHelen Koike 	 * This is required since cleanup for async commits is performed on
142189a4aac0SHelen Koike 	 * the new state, rather than old state like for traditional commits.
142289a4aac0SHelen Koike 	 * Since we want to give up the reference on the current (old) fb
142389a4aac0SHelen Koike 	 * instead of our brand new one, swap them in the driver during the
142489a4aac0SHelen Koike 	 * async commit.
142589a4aac0SHelen Koike 	 *
1426fef9df8bSGustavo Padovan 	 * FIXME:
1427fef9df8bSGustavo Padovan 	 *  - It only works for single plane updates
1428fef9df8bSGustavo Padovan 	 *  - Async Pageflips are not supported yet
1429fef9df8bSGustavo Padovan 	 *  - Some hw might still scan out the old buffer until the next
1430fef9df8bSGustavo Padovan 	 *    vblank, however we let go of the fb references as soon as
1431fef9df8bSGustavo Padovan 	 *    we run this hook. For now drivers must implement their own workers
1432fef9df8bSGustavo Padovan 	 *    for deferring if needed, until a common solution is created.
1433fef9df8bSGustavo Padovan 	 */
1434fef9df8bSGustavo Padovan 	void (*atomic_async_update)(struct drm_plane *plane,
14355ddb0bd4SMaxime Ripard 				    struct drm_atomic_state *state);
1436092d01daSDaniel Vetter };
1437092d01daSDaniel Vetter 
1438092d01daSDaniel Vetter /**
1439092d01daSDaniel Vetter  * drm_plane_helper_add - sets the helper vtable for a plane
1440092d01daSDaniel Vetter  * @plane: DRM plane
1441092d01daSDaniel Vetter  * @funcs: helper vtable to set for @plane
1442092d01daSDaniel Vetter  */
drm_plane_helper_add(struct drm_plane * plane,const struct drm_plane_helper_funcs * funcs)1443092d01daSDaniel Vetter static inline void drm_plane_helper_add(struct drm_plane *plane,
1444092d01daSDaniel Vetter 					const struct drm_plane_helper_funcs *funcs)
1445092d01daSDaniel Vetter {
1446092d01daSDaniel Vetter 	plane->helper_private = funcs;
1447092d01daSDaniel Vetter }
1448092d01daSDaniel Vetter 
14499f2a7950SDaniel Vetter /**
14509f2a7950SDaniel Vetter  * struct drm_mode_config_helper_funcs - global modeset helper operations
14519f2a7950SDaniel Vetter  *
14529f2a7950SDaniel Vetter  * These helper functions are used by the atomic helpers.
14539f2a7950SDaniel Vetter  */
14549f2a7950SDaniel Vetter struct drm_mode_config_helper_funcs {
14559f2a7950SDaniel Vetter 	/**
14569f2a7950SDaniel Vetter 	 * @atomic_commit_tail:
14579f2a7950SDaniel Vetter 	 *
14589f2a7950SDaniel Vetter 	 * This hook is used by the default atomic_commit() hook implemented in
14599f2a7950SDaniel Vetter 	 * drm_atomic_helper_commit() together with the nonblocking commit
14609f2a7950SDaniel Vetter 	 * helpers (see drm_atomic_helper_setup_commit() for a starting point)
14619f2a7950SDaniel Vetter 	 * to implement blocking and nonblocking commits easily. It is not used
14629f2a7950SDaniel Vetter 	 * by the atomic helpers
14639f2a7950SDaniel Vetter 	 *
14641ea0c02eSDaniel Vetter 	 * This function is called when the new atomic state has already been
14651ea0c02eSDaniel Vetter 	 * swapped into the various state pointers. The passed in state
14661ea0c02eSDaniel Vetter 	 * therefore contains copies of the old/previous state. This hook should
14671ea0c02eSDaniel Vetter 	 * commit the new state into hardware. Note that the helpers have
14681ea0c02eSDaniel Vetter 	 * already waited for preceeding atomic commits and fences, but drivers
14691ea0c02eSDaniel Vetter 	 * can add more waiting calls at the start of their implementation, e.g.
14701ea0c02eSDaniel Vetter 	 * to wait for driver-internal request for implicit syncing, before
14711ea0c02eSDaniel Vetter 	 * starting to commit the update to the hardware.
14729f2a7950SDaniel Vetter 	 *
14739f2a7950SDaniel Vetter 	 * After the atomic update is committed to the hardware this hook needs
147420b734c1SSui Jingfeng 	 * to call drm_atomic_helper_commit_hw_done(). Then wait for the update
14759f2a7950SDaniel Vetter 	 * to be executed by the hardware, for example using
147601086487SBoris Brezillon 	 * drm_atomic_helper_wait_for_vblanks() or
147701086487SBoris Brezillon 	 * drm_atomic_helper_wait_for_flip_done(), and then clean up the old
14789f2a7950SDaniel Vetter 	 * framebuffers using drm_atomic_helper_cleanup_planes().
14799f2a7950SDaniel Vetter 	 *
14809f2a7950SDaniel Vetter 	 * When disabling a CRTC this hook _must_ stall for the commit to
14819f2a7950SDaniel Vetter 	 * complete. Vblank waits don't work on disabled CRTC, hence the core
14829f2a7950SDaniel Vetter 	 * can't take care of this. And it also can't rely on the vblank event,
14839f2a7950SDaniel Vetter 	 * since that can be signalled already when the screen shows black,
14849f2a7950SDaniel Vetter 	 * which can happen much earlier than the last hardware access needed to
14859f2a7950SDaniel Vetter 	 * shut off the display pipeline completely.
14869f2a7950SDaniel Vetter 	 *
14879f2a7950SDaniel Vetter 	 * This hook is optional, the default implementation is
14889f2a7950SDaniel Vetter 	 * drm_atomic_helper_commit_tail().
14899f2a7950SDaniel Vetter 	 */
14909f2a7950SDaniel Vetter 	void (*atomic_commit_tail)(struct drm_atomic_state *state);
1491ddadd408SMaxime Ripard 
1492ddadd408SMaxime Ripard 	/**
1493ddadd408SMaxime Ripard 	 * @atomic_commit_setup:
1494ddadd408SMaxime Ripard 	 *
1495ddadd408SMaxime Ripard 	 * This hook is used by the default atomic_commit() hook implemented in
1496ddadd408SMaxime Ripard 	 * drm_atomic_helper_commit() together with the nonblocking helpers (see
1497ddadd408SMaxime Ripard 	 * drm_atomic_helper_setup_commit()) to extend the DRM commit setup. It
1498ddadd408SMaxime Ripard 	 * is not used by the atomic helpers.
1499ddadd408SMaxime Ripard 	 *
1500ddadd408SMaxime Ripard 	 * This function is called at the end of
1501ddadd408SMaxime Ripard 	 * drm_atomic_helper_setup_commit(), so once the commit has been
1502ddadd408SMaxime Ripard 	 * properly setup across the generic DRM object states. It allows
1503ddadd408SMaxime Ripard 	 * drivers to do some additional commit tracking that isn't related to a
1504ddadd408SMaxime Ripard 	 * CRTC, plane or connector, tracked in a &drm_private_obj structure.
1505ddadd408SMaxime Ripard 	 *
1506ddadd408SMaxime Ripard 	 * Note that the documentation of &drm_private_obj has more details on
1507ddadd408SMaxime Ripard 	 * how one should implement this.
1508ddadd408SMaxime Ripard 	 *
1509ddadd408SMaxime Ripard 	 * This hook is optional.
1510ddadd408SMaxime Ripard 	 */
1511ddadd408SMaxime Ripard 	int (*atomic_commit_setup)(struct drm_atomic_state *state);
15129f2a7950SDaniel Vetter };
15139f2a7950SDaniel Vetter 
1514092d01daSDaniel Vetter #endif
1515