xref: /OK3568_Linux_fs/kernel/include/drm/drm_modeset_helper_vtables.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright © 2006 Keith Packard
3*4882a593Smuzhiyun  * Copyright © 2007-2008 Dave Airlie
4*4882a593Smuzhiyun  * Copyright © 2007-2008 Intel Corporation
5*4882a593Smuzhiyun  *   Jesse Barnes <jesse.barnes@intel.com>
6*4882a593Smuzhiyun  * Copyright © 2011-2013 Intel Corporation
7*4882a593Smuzhiyun  * Copyright © 2015 Intel Corporation
8*4882a593Smuzhiyun  *   Daniel Vetter <daniel.vetter@ffwll.ch>
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
11*4882a593Smuzhiyun  * copy of this software and associated documentation files (the "Software"),
12*4882a593Smuzhiyun  * to deal in the Software without restriction, including without limitation
13*4882a593Smuzhiyun  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14*4882a593Smuzhiyun  * and/or sell copies of the Software, and to permit persons to whom the
15*4882a593Smuzhiyun  * Software is furnished to do so, subject to the following conditions:
16*4882a593Smuzhiyun  *
17*4882a593Smuzhiyun  * The above copyright notice and this permission notice shall be included in
18*4882a593Smuzhiyun  * all copies or substantial portions of the Software.
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23*4882a593Smuzhiyun  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
24*4882a593Smuzhiyun  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25*4882a593Smuzhiyun  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26*4882a593Smuzhiyun  * OTHER DEALINGS IN THE SOFTWARE.
27*4882a593Smuzhiyun  */
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #ifndef __DRM_MODESET_HELPER_VTABLES_H__
30*4882a593Smuzhiyun #define __DRM_MODESET_HELPER_VTABLES_H__
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun #include <drm/drm_crtc.h>
33*4882a593Smuzhiyun #include <drm/drm_encoder.h>
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun /**
36*4882a593Smuzhiyun  * DOC: overview
37*4882a593Smuzhiyun  *
38*4882a593Smuzhiyun  * The DRM mode setting helper functions are common code for drivers to use if
39*4882a593Smuzhiyun  * they wish.  Drivers are not forced to use this code in their
40*4882a593Smuzhiyun  * implementations but it would be useful if the code they do use at least
41*4882a593Smuzhiyun  * provides a consistent interface and operation to userspace. Therefore it is
42*4882a593Smuzhiyun  * highly recommended to use the provided helpers as much as possible.
43*4882a593Smuzhiyun  *
44*4882a593Smuzhiyun  * Because there is only one pointer per modeset object to hold a vfunc table
45*4882a593Smuzhiyun  * for helper libraries they are by necessity shared among the different
46*4882a593Smuzhiyun  * helpers.
47*4882a593Smuzhiyun  *
48*4882a593Smuzhiyun  * To make this clear all the helper vtables are pulled together in this location here.
49*4882a593Smuzhiyun  */
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun enum mode_set_atomic;
52*4882a593Smuzhiyun struct drm_writeback_connector;
53*4882a593Smuzhiyun struct drm_writeback_job;
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun /**
56*4882a593Smuzhiyun  * struct drm_crtc_helper_funcs - helper operations for CRTCs
57*4882a593Smuzhiyun  *
58*4882a593Smuzhiyun  * These hooks are used by the legacy CRTC helpers, the transitional plane
59*4882a593Smuzhiyun  * helpers and the new atomic modesetting helpers.
60*4882a593Smuzhiyun  */
61*4882a593Smuzhiyun struct drm_crtc_helper_funcs {
62*4882a593Smuzhiyun 	/**
63*4882a593Smuzhiyun 	 * @dpms:
64*4882a593Smuzhiyun 	 *
65*4882a593Smuzhiyun 	 * Callback to control power levels on the CRTC.  If the mode passed in
66*4882a593Smuzhiyun 	 * is unsupported, the provider must use the next lowest power level.
67*4882a593Smuzhiyun 	 * This is used by the legacy CRTC helpers to implement DPMS
68*4882a593Smuzhiyun 	 * functionality in drm_helper_connector_dpms().
69*4882a593Smuzhiyun 	 *
70*4882a593Smuzhiyun 	 * This callback is also used to disable a CRTC by calling it with
71*4882a593Smuzhiyun 	 * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
72*4882a593Smuzhiyun 	 *
73*4882a593Smuzhiyun 	 * This callback is used by the legacy CRTC helpers.  Atomic helpers
74*4882a593Smuzhiyun 	 * also support using this hook for enabling and disabling a CRTC to
75*4882a593Smuzhiyun 	 * facilitate transitions to atomic, but it is deprecated. Instead
76*4882a593Smuzhiyun 	 * @atomic_enable and @atomic_disable should be used.
77*4882a593Smuzhiyun 	 */
78*4882a593Smuzhiyun 	void (*dpms)(struct drm_crtc *crtc, int mode);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 	/**
81*4882a593Smuzhiyun 	 * @prepare:
82*4882a593Smuzhiyun 	 *
83*4882a593Smuzhiyun 	 * This callback should prepare the CRTC for a subsequent modeset, which
84*4882a593Smuzhiyun 	 * in practice means the driver should disable the CRTC if it is
85*4882a593Smuzhiyun 	 * running. Most drivers ended up implementing this by calling their
86*4882a593Smuzhiyun 	 * @dpms hook with DRM_MODE_DPMS_OFF.
87*4882a593Smuzhiyun 	 *
88*4882a593Smuzhiyun 	 * This callback is used by the legacy CRTC helpers.  Atomic helpers
89*4882a593Smuzhiyun 	 * also support using this hook for disabling a CRTC to facilitate
90*4882a593Smuzhiyun 	 * transitions to atomic, but it is deprecated. Instead @atomic_disable
91*4882a593Smuzhiyun 	 * should be used.
92*4882a593Smuzhiyun 	 */
93*4882a593Smuzhiyun 	void (*prepare)(struct drm_crtc *crtc);
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun 	/**
96*4882a593Smuzhiyun 	 * @commit:
97*4882a593Smuzhiyun 	 *
98*4882a593Smuzhiyun 	 * This callback should commit the new mode on the CRTC after a modeset,
99*4882a593Smuzhiyun 	 * which in practice means the driver should enable the CRTC.  Most
100*4882a593Smuzhiyun 	 * drivers ended up implementing this by calling their @dpms hook with
101*4882a593Smuzhiyun 	 * DRM_MODE_DPMS_ON.
102*4882a593Smuzhiyun 	 *
103*4882a593Smuzhiyun 	 * This callback is used by the legacy CRTC helpers.  Atomic helpers
104*4882a593Smuzhiyun 	 * also support using this hook for enabling a CRTC to facilitate
105*4882a593Smuzhiyun 	 * transitions to atomic, but it is deprecated. Instead @atomic_enable
106*4882a593Smuzhiyun 	 * should be used.
107*4882a593Smuzhiyun 	 */
108*4882a593Smuzhiyun 	void (*commit)(struct drm_crtc *crtc);
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun 	/**
111*4882a593Smuzhiyun 	 * @mode_valid:
112*4882a593Smuzhiyun 	 *
113*4882a593Smuzhiyun 	 * This callback is used to check if a specific mode is valid in this
114*4882a593Smuzhiyun 	 * crtc. This should be implemented if the crtc has some sort of
115*4882a593Smuzhiyun 	 * restriction in the modes it can display. For example, a given crtc
116*4882a593Smuzhiyun 	 * may be responsible to set a clock value. If the clock can not
117*4882a593Smuzhiyun 	 * produce all the values for the available modes then this callback
118*4882a593Smuzhiyun 	 * can be used to restrict the number of modes to only the ones that
119*4882a593Smuzhiyun 	 * can be displayed.
120*4882a593Smuzhiyun 	 *
121*4882a593Smuzhiyun 	 * This hook is used by the probe helpers to filter the mode list in
122*4882a593Smuzhiyun 	 * drm_helper_probe_single_connector_modes(), and it is used by the
123*4882a593Smuzhiyun 	 * atomic helpers to validate modes supplied by userspace in
124*4882a593Smuzhiyun 	 * drm_atomic_helper_check_modeset().
125*4882a593Smuzhiyun 	 *
126*4882a593Smuzhiyun 	 * This function is optional.
127*4882a593Smuzhiyun 	 *
128*4882a593Smuzhiyun 	 * NOTE:
129*4882a593Smuzhiyun 	 *
130*4882a593Smuzhiyun 	 * Since this function is both called from the check phase of an atomic
131*4882a593Smuzhiyun 	 * commit, and the mode validation in the probe paths it is not allowed
132*4882a593Smuzhiyun 	 * to look at anything else but the passed-in mode, and validate it
133*4882a593Smuzhiyun 	 * against configuration-invariant hardward constraints. Any further
134*4882a593Smuzhiyun 	 * limits which depend upon the configuration can only be checked in
135*4882a593Smuzhiyun 	 * @mode_fixup or @atomic_check.
136*4882a593Smuzhiyun 	 *
137*4882a593Smuzhiyun 	 * RETURNS:
138*4882a593Smuzhiyun 	 *
139*4882a593Smuzhiyun 	 * drm_mode_status Enum
140*4882a593Smuzhiyun 	 */
141*4882a593Smuzhiyun 	enum drm_mode_status (*mode_valid)(struct drm_crtc *crtc,
142*4882a593Smuzhiyun 					   const struct drm_display_mode *mode);
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun 	/**
145*4882a593Smuzhiyun 	 * @mode_fixup:
146*4882a593Smuzhiyun 	 *
147*4882a593Smuzhiyun 	 * This callback is used to validate a mode. The parameter mode is the
148*4882a593Smuzhiyun 	 * display mode that userspace requested, adjusted_mode is the mode the
149*4882a593Smuzhiyun 	 * encoders need to be fed with. Note that this is the inverse semantics
150*4882a593Smuzhiyun 	 * of the meaning for the &drm_encoder and &drm_bridge_funcs.mode_fixup
151*4882a593Smuzhiyun 	 * vfunc. If the CRTC cannot support the requested conversion from mode
152*4882a593Smuzhiyun 	 * to adjusted_mode it should reject the modeset. See also
153*4882a593Smuzhiyun 	 * &drm_crtc_state.adjusted_mode for more details.
154*4882a593Smuzhiyun 	 *
155*4882a593Smuzhiyun 	 * This function is used by both legacy CRTC helpers and atomic helpers.
156*4882a593Smuzhiyun 	 * With atomic helpers it is optional.
157*4882a593Smuzhiyun 	 *
158*4882a593Smuzhiyun 	 * NOTE:
159*4882a593Smuzhiyun 	 *
160*4882a593Smuzhiyun 	 * This function is called in the check phase of atomic modesets, which
161*4882a593Smuzhiyun 	 * can be aborted for any reason (including on userspace's request to
162*4882a593Smuzhiyun 	 * just check whether a configuration would be possible). Atomic drivers
163*4882a593Smuzhiyun 	 * MUST NOT touch any persistent state (hardware or software) or data
164*4882a593Smuzhiyun 	 * structures except the passed in adjusted_mode parameter.
165*4882a593Smuzhiyun 	 *
166*4882a593Smuzhiyun 	 * This is in contrast to the legacy CRTC helpers where this was
167*4882a593Smuzhiyun 	 * allowed.
168*4882a593Smuzhiyun 	 *
169*4882a593Smuzhiyun 	 * Atomic drivers which need to inspect and adjust more state should
170*4882a593Smuzhiyun 	 * instead use the @atomic_check callback, but note that they're not
171*4882a593Smuzhiyun 	 * perfectly equivalent: @mode_valid is called from
172*4882a593Smuzhiyun 	 * drm_atomic_helper_check_modeset(), but @atomic_check is called from
173*4882a593Smuzhiyun 	 * drm_atomic_helper_check_planes(), because originally it was meant for
174*4882a593Smuzhiyun 	 * plane update checks only.
175*4882a593Smuzhiyun 	 *
176*4882a593Smuzhiyun 	 * Also beware that userspace can request its own custom modes, neither
177*4882a593Smuzhiyun 	 * core nor helpers filter modes to the list of probe modes reported by
178*4882a593Smuzhiyun 	 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
179*4882a593Smuzhiyun 	 * that modes are filtered consistently put any CRTC constraints and
180*4882a593Smuzhiyun 	 * limits checks into @mode_valid.
181*4882a593Smuzhiyun 	 *
182*4882a593Smuzhiyun 	 * RETURNS:
183*4882a593Smuzhiyun 	 *
184*4882a593Smuzhiyun 	 * True if an acceptable configuration is possible, false if the modeset
185*4882a593Smuzhiyun 	 * operation should be rejected.
186*4882a593Smuzhiyun 	 */
187*4882a593Smuzhiyun 	bool (*mode_fixup)(struct drm_crtc *crtc,
188*4882a593Smuzhiyun 			   const struct drm_display_mode *mode,
189*4882a593Smuzhiyun 			   struct drm_display_mode *adjusted_mode);
190*4882a593Smuzhiyun 
191*4882a593Smuzhiyun 	/**
192*4882a593Smuzhiyun 	 * @mode_set:
193*4882a593Smuzhiyun 	 *
194*4882a593Smuzhiyun 	 * This callback is used by the legacy CRTC helpers to set a new mode,
195*4882a593Smuzhiyun 	 * position and framebuffer. Since it ties the primary plane to every
196*4882a593Smuzhiyun 	 * mode change it is incompatible with universal plane support. And
197*4882a593Smuzhiyun 	 * since it can't update other planes it's incompatible with atomic
198*4882a593Smuzhiyun 	 * modeset support.
199*4882a593Smuzhiyun 	 *
200*4882a593Smuzhiyun 	 * This callback is only used by CRTC helpers and deprecated.
201*4882a593Smuzhiyun 	 *
202*4882a593Smuzhiyun 	 * RETURNS:
203*4882a593Smuzhiyun 	 *
204*4882a593Smuzhiyun 	 * 0 on success or a negative error code on failure.
205*4882a593Smuzhiyun 	 */
206*4882a593Smuzhiyun 	int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
207*4882a593Smuzhiyun 			struct drm_display_mode *adjusted_mode, int x, int y,
208*4882a593Smuzhiyun 			struct drm_framebuffer *old_fb);
209*4882a593Smuzhiyun 
210*4882a593Smuzhiyun 	/**
211*4882a593Smuzhiyun 	 * @mode_set_nofb:
212*4882a593Smuzhiyun 	 *
213*4882a593Smuzhiyun 	 * This callback is used to update the display mode of a CRTC without
214*4882a593Smuzhiyun 	 * changing anything of the primary plane configuration. This fits the
215*4882a593Smuzhiyun 	 * requirement of atomic and hence is used by the atomic helpers. It is
216*4882a593Smuzhiyun 	 * also used by the transitional plane helpers to implement a
217*4882a593Smuzhiyun 	 * @mode_set hook in drm_helper_crtc_mode_set().
218*4882a593Smuzhiyun 	 *
219*4882a593Smuzhiyun 	 * Note that the display pipe is completely off when this function is
220*4882a593Smuzhiyun 	 * called. Atomic drivers which need hardware to be running before they
221*4882a593Smuzhiyun 	 * program the new display mode (e.g. because they implement runtime PM)
222*4882a593Smuzhiyun 	 * should not use this hook. This is because the helper library calls
223*4882a593Smuzhiyun 	 * this hook only once per mode change and not every time the display
224*4882a593Smuzhiyun 	 * pipeline is suspended using either DPMS or the new "ACTIVE" property.
225*4882a593Smuzhiyun 	 * Which means register values set in this callback might get reset when
226*4882a593Smuzhiyun 	 * the CRTC is suspended, but not restored.  Such drivers should instead
227*4882a593Smuzhiyun 	 * move all their CRTC setup into the @atomic_enable callback.
228*4882a593Smuzhiyun 	 *
229*4882a593Smuzhiyun 	 * This callback is optional.
230*4882a593Smuzhiyun 	 */
231*4882a593Smuzhiyun 	void (*mode_set_nofb)(struct drm_crtc *crtc);
232*4882a593Smuzhiyun 
233*4882a593Smuzhiyun 	/**
234*4882a593Smuzhiyun 	 * @mode_set_base:
235*4882a593Smuzhiyun 	 *
236*4882a593Smuzhiyun 	 * This callback is used by the legacy CRTC helpers to set a new
237*4882a593Smuzhiyun 	 * framebuffer and scanout position. It is optional and used as an
238*4882a593Smuzhiyun 	 * optimized fast-path instead of a full mode set operation with all the
239*4882a593Smuzhiyun 	 * resulting flickering. If it is not present
240*4882a593Smuzhiyun 	 * drm_crtc_helper_set_config() will fall back to a full modeset, using
241*4882a593Smuzhiyun 	 * the @mode_set callback. Since it can't update other planes it's
242*4882a593Smuzhiyun 	 * incompatible with atomic modeset support.
243*4882a593Smuzhiyun 	 *
244*4882a593Smuzhiyun 	 * This callback is only used by the CRTC helpers and deprecated.
245*4882a593Smuzhiyun 	 *
246*4882a593Smuzhiyun 	 * RETURNS:
247*4882a593Smuzhiyun 	 *
248*4882a593Smuzhiyun 	 * 0 on success or a negative error code on failure.
249*4882a593Smuzhiyun 	 */
250*4882a593Smuzhiyun 	int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
251*4882a593Smuzhiyun 			     struct drm_framebuffer *old_fb);
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun 	/**
254*4882a593Smuzhiyun 	 * @mode_set_base_atomic:
255*4882a593Smuzhiyun 	 *
256*4882a593Smuzhiyun 	 * This callback is used by the fbdev helpers to set a new framebuffer
257*4882a593Smuzhiyun 	 * and scanout without sleeping, i.e. from an atomic calling context. It
258*4882a593Smuzhiyun 	 * is only used to implement kgdb support.
259*4882a593Smuzhiyun 	 *
260*4882a593Smuzhiyun 	 * This callback is optional and only needed for kgdb support in the fbdev
261*4882a593Smuzhiyun 	 * helpers.
262*4882a593Smuzhiyun 	 *
263*4882a593Smuzhiyun 	 * RETURNS:
264*4882a593Smuzhiyun 	 *
265*4882a593Smuzhiyun 	 * 0 on success or a negative error code on failure.
266*4882a593Smuzhiyun 	 */
267*4882a593Smuzhiyun 	int (*mode_set_base_atomic)(struct drm_crtc *crtc,
268*4882a593Smuzhiyun 				    struct drm_framebuffer *fb, int x, int y,
269*4882a593Smuzhiyun 				    enum mode_set_atomic);
270*4882a593Smuzhiyun 
271*4882a593Smuzhiyun 	/**
272*4882a593Smuzhiyun 	 * @disable:
273*4882a593Smuzhiyun 	 *
274*4882a593Smuzhiyun 	 * This callback should be used to disable the CRTC. With the atomic
275*4882a593Smuzhiyun 	 * drivers it is called after all encoders connected to this CRTC have
276*4882a593Smuzhiyun 	 * been shut off already using their own
277*4882a593Smuzhiyun 	 * &drm_encoder_helper_funcs.disable hook. If that sequence is too
278*4882a593Smuzhiyun 	 * simple drivers can just add their own hooks and call it from this
279*4882a593Smuzhiyun 	 * CRTC callback here by looping over all encoders connected to it using
280*4882a593Smuzhiyun 	 * for_each_encoder_on_crtc().
281*4882a593Smuzhiyun 	 *
282*4882a593Smuzhiyun 	 * This hook is used both by legacy CRTC helpers and atomic helpers.
283*4882a593Smuzhiyun 	 * Atomic drivers don't need to implement it if there's no need to
284*4882a593Smuzhiyun 	 * disable anything at the CRTC level. To ensure that runtime PM
285*4882a593Smuzhiyun 	 * handling (using either DPMS or the new "ACTIVE" property) works
286*4882a593Smuzhiyun 	 * @disable must be the inverse of @atomic_enable for atomic drivers.
287*4882a593Smuzhiyun 	 * Atomic drivers should consider to use @atomic_disable instead of
288*4882a593Smuzhiyun 	 * this one.
289*4882a593Smuzhiyun 	 *
290*4882a593Smuzhiyun 	 * NOTE:
291*4882a593Smuzhiyun 	 *
292*4882a593Smuzhiyun 	 * With legacy CRTC helpers there's a big semantic difference between
293*4882a593Smuzhiyun 	 * @disable and other hooks (like @prepare or @dpms) used to shut down a
294*4882a593Smuzhiyun 	 * CRTC: @disable is only called when also logically disabling the
295*4882a593Smuzhiyun 	 * display pipeline and needs to release any resources acquired in
296*4882a593Smuzhiyun 	 * @mode_set (like shared PLLs, or again release pinned framebuffers).
297*4882a593Smuzhiyun 	 *
298*4882a593Smuzhiyun 	 * Therefore @disable must be the inverse of @mode_set plus @commit for
299*4882a593Smuzhiyun 	 * drivers still using legacy CRTC helpers, which is different from the
300*4882a593Smuzhiyun 	 * rules under atomic.
301*4882a593Smuzhiyun 	 */
302*4882a593Smuzhiyun 	void (*disable)(struct drm_crtc *crtc);
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun 	/**
305*4882a593Smuzhiyun 	 * @atomic_check:
306*4882a593Smuzhiyun 	 *
307*4882a593Smuzhiyun 	 * Drivers should check plane-update related CRTC constraints in this
308*4882a593Smuzhiyun 	 * hook. They can also check mode related limitations but need to be
309*4882a593Smuzhiyun 	 * aware of the calling order, since this hook is used by
310*4882a593Smuzhiyun 	 * drm_atomic_helper_check_planes() whereas the preparations needed to
311*4882a593Smuzhiyun 	 * check output routing and the display mode is done in
312*4882a593Smuzhiyun 	 * drm_atomic_helper_check_modeset(). Therefore drivers that want to
313*4882a593Smuzhiyun 	 * check output routing and display mode constraints in this callback
314*4882a593Smuzhiyun 	 * must ensure that drm_atomic_helper_check_modeset() has been called
315*4882a593Smuzhiyun 	 * beforehand. This is calling order used by the default helper
316*4882a593Smuzhiyun 	 * implementation in drm_atomic_helper_check().
317*4882a593Smuzhiyun 	 *
318*4882a593Smuzhiyun 	 * When using drm_atomic_helper_check_planes() this hook is called
319*4882a593Smuzhiyun 	 * after the &drm_plane_helper_funcs.atomic_check hook for planes, which
320*4882a593Smuzhiyun 	 * allows drivers to assign shared resources requested by planes in this
321*4882a593Smuzhiyun 	 * callback here. For more complicated dependencies the driver can call
322*4882a593Smuzhiyun 	 * the provided check helpers multiple times until the computed state
323*4882a593Smuzhiyun 	 * has a final configuration and everything has been checked.
324*4882a593Smuzhiyun 	 *
325*4882a593Smuzhiyun 	 * This function is also allowed to inspect any other object's state and
326*4882a593Smuzhiyun 	 * can add more state objects to the atomic commit if needed. Care must
327*4882a593Smuzhiyun 	 * be taken though to ensure that state check and compute functions for
328*4882a593Smuzhiyun 	 * these added states are all called, and derived state in other objects
329*4882a593Smuzhiyun 	 * all updated. Again the recommendation is to just call check helpers
330*4882a593Smuzhiyun 	 * until a maximal configuration is reached.
331*4882a593Smuzhiyun 	 *
332*4882a593Smuzhiyun 	 * This callback is used by the atomic modeset helpers and by the
333*4882a593Smuzhiyun 	 * transitional plane helpers, but it is optional.
334*4882a593Smuzhiyun 	 *
335*4882a593Smuzhiyun 	 * NOTE:
336*4882a593Smuzhiyun 	 *
337*4882a593Smuzhiyun 	 * This function is called in the check phase of an atomic update. The
338*4882a593Smuzhiyun 	 * driver is not allowed to change anything outside of the free-standing
339*4882a593Smuzhiyun 	 * state objects passed-in or assembled in the overall &drm_atomic_state
340*4882a593Smuzhiyun 	 * update tracking structure.
341*4882a593Smuzhiyun 	 *
342*4882a593Smuzhiyun 	 * Also beware that userspace can request its own custom modes, neither
343*4882a593Smuzhiyun 	 * core nor helpers filter modes to the list of probe modes reported by
344*4882a593Smuzhiyun 	 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
345*4882a593Smuzhiyun 	 * that modes are filtered consistently put any CRTC constraints and
346*4882a593Smuzhiyun 	 * limits checks into @mode_valid.
347*4882a593Smuzhiyun 	 *
348*4882a593Smuzhiyun 	 * RETURNS:
349*4882a593Smuzhiyun 	 *
350*4882a593Smuzhiyun 	 * 0 on success, -EINVAL if the state or the transition can't be
351*4882a593Smuzhiyun 	 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
352*4882a593Smuzhiyun 	 * attempt to obtain another state object ran into a &drm_modeset_lock
353*4882a593Smuzhiyun 	 * deadlock.
354*4882a593Smuzhiyun 	 */
355*4882a593Smuzhiyun 	int (*atomic_check)(struct drm_crtc *crtc,
356*4882a593Smuzhiyun 			    struct drm_crtc_state *state);
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun 	/**
359*4882a593Smuzhiyun 	 * @atomic_begin:
360*4882a593Smuzhiyun 	 *
361*4882a593Smuzhiyun 	 * Drivers should prepare for an atomic update of multiple planes on
362*4882a593Smuzhiyun 	 * a CRTC in this hook. Depending upon hardware this might be vblank
363*4882a593Smuzhiyun 	 * evasion, blocking updates by setting bits or doing preparatory work
364*4882a593Smuzhiyun 	 * for e.g. manual update display.
365*4882a593Smuzhiyun 	 *
366*4882a593Smuzhiyun 	 * This hook is called before any plane commit functions are called.
367*4882a593Smuzhiyun 	 *
368*4882a593Smuzhiyun 	 * Note that the power state of the display pipe when this function is
369*4882a593Smuzhiyun 	 * called depends upon the exact helpers and calling sequence the driver
370*4882a593Smuzhiyun 	 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
371*4882a593Smuzhiyun 	 * the tradeoffs and variants of plane commit helpers.
372*4882a593Smuzhiyun 	 *
373*4882a593Smuzhiyun 	 * This callback is used by the atomic modeset helpers and by the
374*4882a593Smuzhiyun 	 * transitional plane helpers, but it is optional.
375*4882a593Smuzhiyun 	 */
376*4882a593Smuzhiyun 	void (*atomic_begin)(struct drm_crtc *crtc,
377*4882a593Smuzhiyun 			     struct drm_crtc_state *old_crtc_state);
378*4882a593Smuzhiyun 	/**
379*4882a593Smuzhiyun 	 * @atomic_flush:
380*4882a593Smuzhiyun 	 *
381*4882a593Smuzhiyun 	 * Drivers should finalize an atomic update of multiple planes on
382*4882a593Smuzhiyun 	 * a CRTC in this hook. Depending upon hardware this might include
383*4882a593Smuzhiyun 	 * checking that vblank evasion was successful, unblocking updates by
384*4882a593Smuzhiyun 	 * setting bits or setting the GO bit to flush out all updates.
385*4882a593Smuzhiyun 	 *
386*4882a593Smuzhiyun 	 * Simple hardware or hardware with special requirements can commit and
387*4882a593Smuzhiyun 	 * flush out all updates for all planes from this hook and forgo all the
388*4882a593Smuzhiyun 	 * other commit hooks for plane updates.
389*4882a593Smuzhiyun 	 *
390*4882a593Smuzhiyun 	 * This hook is called after any plane commit functions are called.
391*4882a593Smuzhiyun 	 *
392*4882a593Smuzhiyun 	 * Note that the power state of the display pipe when this function is
393*4882a593Smuzhiyun 	 * called depends upon the exact helpers and calling sequence the driver
394*4882a593Smuzhiyun 	 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
395*4882a593Smuzhiyun 	 * the tradeoffs and variants of plane commit helpers.
396*4882a593Smuzhiyun 	 *
397*4882a593Smuzhiyun 	 * This callback is used by the atomic modeset helpers and by the
398*4882a593Smuzhiyun 	 * transitional plane helpers, but it is optional.
399*4882a593Smuzhiyun 	 */
400*4882a593Smuzhiyun 	void (*atomic_flush)(struct drm_crtc *crtc,
401*4882a593Smuzhiyun 			     struct drm_crtc_state *old_crtc_state);
402*4882a593Smuzhiyun 
403*4882a593Smuzhiyun 	/**
404*4882a593Smuzhiyun 	 * @atomic_enable:
405*4882a593Smuzhiyun 	 *
406*4882a593Smuzhiyun 	 * This callback should be used to enable the CRTC. With the atomic
407*4882a593Smuzhiyun 	 * drivers it is called before all encoders connected to this CRTC are
408*4882a593Smuzhiyun 	 * enabled through the encoder's own &drm_encoder_helper_funcs.enable
409*4882a593Smuzhiyun 	 * hook.  If that sequence is too simple drivers can just add their own
410*4882a593Smuzhiyun 	 * hooks and call it from this CRTC callback here by looping over all
411*4882a593Smuzhiyun 	 * encoders connected to it using for_each_encoder_on_crtc().
412*4882a593Smuzhiyun 	 *
413*4882a593Smuzhiyun 	 * This hook is used only by atomic helpers, for symmetry with
414*4882a593Smuzhiyun 	 * @atomic_disable. Atomic drivers don't need to implement it if there's
415*4882a593Smuzhiyun 	 * no need to enable anything at the CRTC level. To ensure that runtime
416*4882a593Smuzhiyun 	 * PM handling (using either DPMS or the new "ACTIVE" property) works
417*4882a593Smuzhiyun 	 * @atomic_enable must be the inverse of @atomic_disable for atomic
418*4882a593Smuzhiyun 	 * drivers.
419*4882a593Smuzhiyun 	 *
420*4882a593Smuzhiyun 	 * Drivers can use the @old_crtc_state input parameter if the operations
421*4882a593Smuzhiyun 	 * needed to enable the CRTC don't depend solely on the new state but
422*4882a593Smuzhiyun 	 * also on the transition between the old state and the new state.
423*4882a593Smuzhiyun 	 *
424*4882a593Smuzhiyun 	 * This function is optional.
425*4882a593Smuzhiyun 	 */
426*4882a593Smuzhiyun 	void (*atomic_enable)(struct drm_crtc *crtc,
427*4882a593Smuzhiyun 			      struct drm_crtc_state *old_crtc_state);
428*4882a593Smuzhiyun 
429*4882a593Smuzhiyun 	/**
430*4882a593Smuzhiyun 	 * @atomic_disable:
431*4882a593Smuzhiyun 	 *
432*4882a593Smuzhiyun 	 * This callback should be used to disable the CRTC. With the atomic
433*4882a593Smuzhiyun 	 * drivers it is called after all encoders connected to this CRTC have
434*4882a593Smuzhiyun 	 * been shut off already using their own
435*4882a593Smuzhiyun 	 * &drm_encoder_helper_funcs.disable hook. If that sequence is too
436*4882a593Smuzhiyun 	 * simple drivers can just add their own hooks and call it from this
437*4882a593Smuzhiyun 	 * CRTC callback here by looping over all encoders connected to it using
438*4882a593Smuzhiyun 	 * for_each_encoder_on_crtc().
439*4882a593Smuzhiyun 	 *
440*4882a593Smuzhiyun 	 * This hook is used only by atomic helpers. Atomic drivers don't
441*4882a593Smuzhiyun 	 * need to implement it if there's no need to disable anything at the
442*4882a593Smuzhiyun 	 * CRTC level.
443*4882a593Smuzhiyun 	 *
444*4882a593Smuzhiyun 	 * Comparing to @disable, this one provides the additional input
445*4882a593Smuzhiyun 	 * parameter @old_crtc_state which could be used to access the old
446*4882a593Smuzhiyun 	 * state. Atomic drivers should consider to use this one instead
447*4882a593Smuzhiyun 	 * of @disable.
448*4882a593Smuzhiyun 	 *
449*4882a593Smuzhiyun 	 * This function is optional.
450*4882a593Smuzhiyun 	 */
451*4882a593Smuzhiyun 	void (*atomic_disable)(struct drm_crtc *crtc,
452*4882a593Smuzhiyun 			       struct drm_crtc_state *old_crtc_state);
453*4882a593Smuzhiyun 
454*4882a593Smuzhiyun 	/**
455*4882a593Smuzhiyun 	 * @get_scanout_position:
456*4882a593Smuzhiyun 	 *
457*4882a593Smuzhiyun 	 * Called by vblank timestamping code.
458*4882a593Smuzhiyun 	 *
459*4882a593Smuzhiyun 	 * Returns the current display scanout position from a CRTC and an
460*4882a593Smuzhiyun 	 * optional accurate ktime_get() timestamp of when the position was
461*4882a593Smuzhiyun 	 * measured. Note that this is a helper callback which is only used
462*4882a593Smuzhiyun 	 * if a driver uses drm_crtc_vblank_helper_get_vblank_timestamp()
463*4882a593Smuzhiyun 	 * for the @drm_crtc_funcs.get_vblank_timestamp callback.
464*4882a593Smuzhiyun 	 *
465*4882a593Smuzhiyun 	 * Parameters:
466*4882a593Smuzhiyun 	 *
467*4882a593Smuzhiyun 	 * crtc:
468*4882a593Smuzhiyun 	 *     The CRTC.
469*4882a593Smuzhiyun 	 * in_vblank_irq:
470*4882a593Smuzhiyun 	 *     True when called from drm_crtc_handle_vblank(). Some drivers
471*4882a593Smuzhiyun 	 *     need to apply some workarounds for gpu-specific vblank irq
472*4882a593Smuzhiyun 	 *     quirks if the flag is set.
473*4882a593Smuzhiyun 	 * vpos:
474*4882a593Smuzhiyun 	 *     Target location for current vertical scanout position.
475*4882a593Smuzhiyun 	 * hpos:
476*4882a593Smuzhiyun 	 *     Target location for current horizontal scanout position.
477*4882a593Smuzhiyun 	 * stime:
478*4882a593Smuzhiyun 	 *     Target location for timestamp taken immediately before
479*4882a593Smuzhiyun 	 *     scanout position query. Can be NULL to skip timestamp.
480*4882a593Smuzhiyun 	 * etime:
481*4882a593Smuzhiyun 	 *     Target location for timestamp taken immediately after
482*4882a593Smuzhiyun 	 *     scanout position query. Can be NULL to skip timestamp.
483*4882a593Smuzhiyun 	 * mode:
484*4882a593Smuzhiyun 	 *     Current display timings.
485*4882a593Smuzhiyun 	 *
486*4882a593Smuzhiyun 	 * Returns vpos as a positive number while in active scanout area.
487*4882a593Smuzhiyun 	 * Returns vpos as a negative number inside vblank, counting the number
488*4882a593Smuzhiyun 	 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
489*4882a593Smuzhiyun 	 * until start of active scanout / end of vblank."
490*4882a593Smuzhiyun 	 *
491*4882a593Smuzhiyun 	 * Returns:
492*4882a593Smuzhiyun 	 *
493*4882a593Smuzhiyun 	 * True on success, false if a reliable scanout position counter could
494*4882a593Smuzhiyun 	 * not be read out.
495*4882a593Smuzhiyun 	 */
496*4882a593Smuzhiyun 	bool (*get_scanout_position)(struct drm_crtc *crtc,
497*4882a593Smuzhiyun 				     bool in_vblank_irq, int *vpos, int *hpos,
498*4882a593Smuzhiyun 				     ktime_t *stime, ktime_t *etime,
499*4882a593Smuzhiyun 				     const struct drm_display_mode *mode);
500*4882a593Smuzhiyun };
501*4882a593Smuzhiyun 
502*4882a593Smuzhiyun /**
503*4882a593Smuzhiyun  * drm_crtc_helper_add - sets the helper vtable for a crtc
504*4882a593Smuzhiyun  * @crtc: DRM CRTC
505*4882a593Smuzhiyun  * @funcs: helper vtable to set for @crtc
506*4882a593Smuzhiyun  */
drm_crtc_helper_add(struct drm_crtc * crtc,const struct drm_crtc_helper_funcs * funcs)507*4882a593Smuzhiyun static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
508*4882a593Smuzhiyun 				       const struct drm_crtc_helper_funcs *funcs)
509*4882a593Smuzhiyun {
510*4882a593Smuzhiyun 	crtc->helper_private = funcs;
511*4882a593Smuzhiyun }
512*4882a593Smuzhiyun 
513*4882a593Smuzhiyun /**
514*4882a593Smuzhiyun  * struct drm_encoder_helper_funcs - helper operations for encoders
515*4882a593Smuzhiyun  *
516*4882a593Smuzhiyun  * These hooks are used by the legacy CRTC helpers, the transitional plane
517*4882a593Smuzhiyun  * helpers and the new atomic modesetting helpers.
518*4882a593Smuzhiyun  */
519*4882a593Smuzhiyun struct drm_encoder_helper_funcs {
520*4882a593Smuzhiyun 	/**
521*4882a593Smuzhiyun 	 * @dpms:
522*4882a593Smuzhiyun 	 *
523*4882a593Smuzhiyun 	 * Callback to control power levels on the encoder.  If the mode passed in
524*4882a593Smuzhiyun 	 * is unsupported, the provider must use the next lowest power level.
525*4882a593Smuzhiyun 	 * This is used by the legacy encoder helpers to implement DPMS
526*4882a593Smuzhiyun 	 * functionality in drm_helper_connector_dpms().
527*4882a593Smuzhiyun 	 *
528*4882a593Smuzhiyun 	 * This callback is also used to disable an encoder by calling it with
529*4882a593Smuzhiyun 	 * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
530*4882a593Smuzhiyun 	 *
531*4882a593Smuzhiyun 	 * This callback is used by the legacy CRTC helpers.  Atomic helpers
532*4882a593Smuzhiyun 	 * also support using this hook for enabling and disabling an encoder to
533*4882a593Smuzhiyun 	 * facilitate transitions to atomic, but it is deprecated. Instead
534*4882a593Smuzhiyun 	 * @enable and @disable should be used.
535*4882a593Smuzhiyun 	 */
536*4882a593Smuzhiyun 	void (*dpms)(struct drm_encoder *encoder, int mode);
537*4882a593Smuzhiyun 
538*4882a593Smuzhiyun 	/**
539*4882a593Smuzhiyun 	 * @mode_valid:
540*4882a593Smuzhiyun 	 *
541*4882a593Smuzhiyun 	 * This callback is used to check if a specific mode is valid in this
542*4882a593Smuzhiyun 	 * encoder. This should be implemented if the encoder has some sort
543*4882a593Smuzhiyun 	 * of restriction in the modes it can display. For example, a given
544*4882a593Smuzhiyun 	 * encoder may be responsible to set a clock value. If the clock can
545*4882a593Smuzhiyun 	 * not produce all the values for the available modes then this callback
546*4882a593Smuzhiyun 	 * can be used to restrict the number of modes to only the ones that
547*4882a593Smuzhiyun 	 * can be displayed.
548*4882a593Smuzhiyun 	 *
549*4882a593Smuzhiyun 	 * This hook is used by the probe helpers to filter the mode list in
550*4882a593Smuzhiyun 	 * drm_helper_probe_single_connector_modes(), and it is used by the
551*4882a593Smuzhiyun 	 * atomic helpers to validate modes supplied by userspace in
552*4882a593Smuzhiyun 	 * drm_atomic_helper_check_modeset().
553*4882a593Smuzhiyun 	 *
554*4882a593Smuzhiyun 	 * This function is optional.
555*4882a593Smuzhiyun 	 *
556*4882a593Smuzhiyun 	 * NOTE:
557*4882a593Smuzhiyun 	 *
558*4882a593Smuzhiyun 	 * Since this function is both called from the check phase of an atomic
559*4882a593Smuzhiyun 	 * commit, and the mode validation in the probe paths it is not allowed
560*4882a593Smuzhiyun 	 * to look at anything else but the passed-in mode, and validate it
561*4882a593Smuzhiyun 	 * against configuration-invariant hardward constraints. Any further
562*4882a593Smuzhiyun 	 * limits which depend upon the configuration can only be checked in
563*4882a593Smuzhiyun 	 * @mode_fixup or @atomic_check.
564*4882a593Smuzhiyun 	 *
565*4882a593Smuzhiyun 	 * RETURNS:
566*4882a593Smuzhiyun 	 *
567*4882a593Smuzhiyun 	 * drm_mode_status Enum
568*4882a593Smuzhiyun 	 */
569*4882a593Smuzhiyun 	enum drm_mode_status (*mode_valid)(struct drm_encoder *crtc,
570*4882a593Smuzhiyun 					   const struct drm_display_mode *mode);
571*4882a593Smuzhiyun 
572*4882a593Smuzhiyun 	/**
573*4882a593Smuzhiyun 	 * @mode_fixup:
574*4882a593Smuzhiyun 	 *
575*4882a593Smuzhiyun 	 * This callback is used to validate and adjust a mode. The parameter
576*4882a593Smuzhiyun 	 * mode is the display mode that should be fed to the next element in
577*4882a593Smuzhiyun 	 * the display chain, either the final &drm_connector or a &drm_bridge.
578*4882a593Smuzhiyun 	 * The parameter adjusted_mode is the input mode the encoder requires. It
579*4882a593Smuzhiyun 	 * can be modified by this callback and does not need to match mode. See
580*4882a593Smuzhiyun 	 * also &drm_crtc_state.adjusted_mode for more details.
581*4882a593Smuzhiyun 	 *
582*4882a593Smuzhiyun 	 * This function is used by both legacy CRTC helpers and atomic helpers.
583*4882a593Smuzhiyun 	 * This hook is optional.
584*4882a593Smuzhiyun 	 *
585*4882a593Smuzhiyun 	 * NOTE:
586*4882a593Smuzhiyun 	 *
587*4882a593Smuzhiyun 	 * This function is called in the check phase of atomic modesets, which
588*4882a593Smuzhiyun 	 * can be aborted for any reason (including on userspace's request to
589*4882a593Smuzhiyun 	 * just check whether a configuration would be possible). Atomic drivers
590*4882a593Smuzhiyun 	 * MUST NOT touch any persistent state (hardware or software) or data
591*4882a593Smuzhiyun 	 * structures except the passed in adjusted_mode parameter.
592*4882a593Smuzhiyun 	 *
593*4882a593Smuzhiyun 	 * This is in contrast to the legacy CRTC helpers where this was
594*4882a593Smuzhiyun 	 * allowed.
595*4882a593Smuzhiyun 	 *
596*4882a593Smuzhiyun 	 * Atomic drivers which need to inspect and adjust more state should
597*4882a593Smuzhiyun 	 * instead use the @atomic_check callback. If @atomic_check is used,
598*4882a593Smuzhiyun 	 * this hook isn't called since @atomic_check allows a strict superset
599*4882a593Smuzhiyun 	 * of the functionality of @mode_fixup.
600*4882a593Smuzhiyun 	 *
601*4882a593Smuzhiyun 	 * Also beware that userspace can request its own custom modes, neither
602*4882a593Smuzhiyun 	 * core nor helpers filter modes to the list of probe modes reported by
603*4882a593Smuzhiyun 	 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
604*4882a593Smuzhiyun 	 * that modes are filtered consistently put any encoder constraints and
605*4882a593Smuzhiyun 	 * limits checks into @mode_valid.
606*4882a593Smuzhiyun 	 *
607*4882a593Smuzhiyun 	 * RETURNS:
608*4882a593Smuzhiyun 	 *
609*4882a593Smuzhiyun 	 * True if an acceptable configuration is possible, false if the modeset
610*4882a593Smuzhiyun 	 * operation should be rejected.
611*4882a593Smuzhiyun 	 */
612*4882a593Smuzhiyun 	bool (*mode_fixup)(struct drm_encoder *encoder,
613*4882a593Smuzhiyun 			   const struct drm_display_mode *mode,
614*4882a593Smuzhiyun 			   struct drm_display_mode *adjusted_mode);
615*4882a593Smuzhiyun 
616*4882a593Smuzhiyun 	/**
617*4882a593Smuzhiyun 	 * @prepare:
618*4882a593Smuzhiyun 	 *
619*4882a593Smuzhiyun 	 * This callback should prepare the encoder for a subsequent modeset,
620*4882a593Smuzhiyun 	 * which in practice means the driver should disable the encoder if it
621*4882a593Smuzhiyun 	 * is running. Most drivers ended up implementing this by calling their
622*4882a593Smuzhiyun 	 * @dpms hook with DRM_MODE_DPMS_OFF.
623*4882a593Smuzhiyun 	 *
624*4882a593Smuzhiyun 	 * This callback is used by the legacy CRTC helpers.  Atomic helpers
625*4882a593Smuzhiyun 	 * also support using this hook for disabling an encoder to facilitate
626*4882a593Smuzhiyun 	 * transitions to atomic, but it is deprecated. Instead @disable should
627*4882a593Smuzhiyun 	 * be used.
628*4882a593Smuzhiyun 	 */
629*4882a593Smuzhiyun 	void (*prepare)(struct drm_encoder *encoder);
630*4882a593Smuzhiyun 
631*4882a593Smuzhiyun 	/**
632*4882a593Smuzhiyun 	 * @commit:
633*4882a593Smuzhiyun 	 *
634*4882a593Smuzhiyun 	 * This callback should commit the new mode on the encoder after a modeset,
635*4882a593Smuzhiyun 	 * which in practice means the driver should enable the encoder.  Most
636*4882a593Smuzhiyun 	 * drivers ended up implementing this by calling their @dpms hook with
637*4882a593Smuzhiyun 	 * DRM_MODE_DPMS_ON.
638*4882a593Smuzhiyun 	 *
639*4882a593Smuzhiyun 	 * This callback is used by the legacy CRTC helpers.  Atomic helpers
640*4882a593Smuzhiyun 	 * also support using this hook for enabling an encoder to facilitate
641*4882a593Smuzhiyun 	 * transitions to atomic, but it is deprecated. Instead @enable should
642*4882a593Smuzhiyun 	 * be used.
643*4882a593Smuzhiyun 	 */
644*4882a593Smuzhiyun 	void (*commit)(struct drm_encoder *encoder);
645*4882a593Smuzhiyun 
646*4882a593Smuzhiyun 	/**
647*4882a593Smuzhiyun 	 * @mode_set:
648*4882a593Smuzhiyun 	 *
649*4882a593Smuzhiyun 	 * This callback is used to update the display mode of an encoder.
650*4882a593Smuzhiyun 	 *
651*4882a593Smuzhiyun 	 * Note that the display pipe is completely off when this function is
652*4882a593Smuzhiyun 	 * called. Drivers which need hardware to be running before they program
653*4882a593Smuzhiyun 	 * the new display mode (because they implement runtime PM) should not
654*4882a593Smuzhiyun 	 * use this hook, because the helper library calls it only once and not
655*4882a593Smuzhiyun 	 * every time the display pipeline is suspend using either DPMS or the
656*4882a593Smuzhiyun 	 * new "ACTIVE" property. Such drivers should instead move all their
657*4882a593Smuzhiyun 	 * encoder setup into the @enable callback.
658*4882a593Smuzhiyun 	 *
659*4882a593Smuzhiyun 	 * This callback is used both by the legacy CRTC helpers and the atomic
660*4882a593Smuzhiyun 	 * modeset helpers. It is optional in the atomic helpers.
661*4882a593Smuzhiyun 	 *
662*4882a593Smuzhiyun 	 * NOTE:
663*4882a593Smuzhiyun 	 *
664*4882a593Smuzhiyun 	 * If the driver uses the atomic modeset helpers and needs to inspect
665*4882a593Smuzhiyun 	 * the connector state or connector display info during mode setting,
666*4882a593Smuzhiyun 	 * @atomic_mode_set can be used instead.
667*4882a593Smuzhiyun 	 */
668*4882a593Smuzhiyun 	void (*mode_set)(struct drm_encoder *encoder,
669*4882a593Smuzhiyun 			 struct drm_display_mode *mode,
670*4882a593Smuzhiyun 			 struct drm_display_mode *adjusted_mode);
671*4882a593Smuzhiyun 
672*4882a593Smuzhiyun 	/**
673*4882a593Smuzhiyun 	 * @atomic_mode_set:
674*4882a593Smuzhiyun 	 *
675*4882a593Smuzhiyun 	 * This callback is used to update the display mode of an encoder.
676*4882a593Smuzhiyun 	 *
677*4882a593Smuzhiyun 	 * Note that the display pipe is completely off when this function is
678*4882a593Smuzhiyun 	 * called. Drivers which need hardware to be running before they program
679*4882a593Smuzhiyun 	 * the new display mode (because they implement runtime PM) should not
680*4882a593Smuzhiyun 	 * use this hook, because the helper library calls it only once and not
681*4882a593Smuzhiyun 	 * every time the display pipeline is suspended using either DPMS or the
682*4882a593Smuzhiyun 	 * new "ACTIVE" property. Such drivers should instead move all their
683*4882a593Smuzhiyun 	 * encoder setup into the @enable callback.
684*4882a593Smuzhiyun 	 *
685*4882a593Smuzhiyun 	 * This callback is used by the atomic modeset helpers in place of the
686*4882a593Smuzhiyun 	 * @mode_set callback, if set by the driver. It is optional and should
687*4882a593Smuzhiyun 	 * be used instead of @mode_set if the driver needs to inspect the
688*4882a593Smuzhiyun 	 * connector state or display info, since there is no direct way to
689*4882a593Smuzhiyun 	 * go from the encoder to the current connector.
690*4882a593Smuzhiyun 	 */
691*4882a593Smuzhiyun 	void (*atomic_mode_set)(struct drm_encoder *encoder,
692*4882a593Smuzhiyun 				struct drm_crtc_state *crtc_state,
693*4882a593Smuzhiyun 				struct drm_connector_state *conn_state);
694*4882a593Smuzhiyun 
695*4882a593Smuzhiyun 	/**
696*4882a593Smuzhiyun 	 * @detect:
697*4882a593Smuzhiyun 	 *
698*4882a593Smuzhiyun 	 * This callback can be used by drivers who want to do detection on the
699*4882a593Smuzhiyun 	 * encoder object instead of in connector functions.
700*4882a593Smuzhiyun 	 *
701*4882a593Smuzhiyun 	 * It is not used by any helper and therefore has purely driver-specific
702*4882a593Smuzhiyun 	 * semantics. New drivers shouldn't use this and instead just implement
703*4882a593Smuzhiyun 	 * their own private callbacks.
704*4882a593Smuzhiyun 	 *
705*4882a593Smuzhiyun 	 * FIXME:
706*4882a593Smuzhiyun 	 *
707*4882a593Smuzhiyun 	 * This should just be converted into a pile of driver vfuncs.
708*4882a593Smuzhiyun 	 * Currently radeon, amdgpu and nouveau are using it.
709*4882a593Smuzhiyun 	 */
710*4882a593Smuzhiyun 	enum drm_connector_status (*detect)(struct drm_encoder *encoder,
711*4882a593Smuzhiyun 					    struct drm_connector *connector);
712*4882a593Smuzhiyun 
713*4882a593Smuzhiyun 	/**
714*4882a593Smuzhiyun 	 * @atomic_disable:
715*4882a593Smuzhiyun 	 *
716*4882a593Smuzhiyun 	 * This callback should be used to disable the encoder. With the atomic
717*4882a593Smuzhiyun 	 * drivers it is called before this encoder's CRTC has been shut off
718*4882a593Smuzhiyun 	 * using their own &drm_crtc_helper_funcs.atomic_disable hook. If that
719*4882a593Smuzhiyun 	 * sequence is too simple drivers can just add their own driver private
720*4882a593Smuzhiyun 	 * encoder hooks and call them from CRTC's callback by looping over all
721*4882a593Smuzhiyun 	 * encoders connected to it using for_each_encoder_on_crtc().
722*4882a593Smuzhiyun 	 *
723*4882a593Smuzhiyun 	 * This callback is a variant of @disable that provides the atomic state
724*4882a593Smuzhiyun 	 * to the driver. If @atomic_disable is implemented, @disable is not
725*4882a593Smuzhiyun 	 * called by the helpers.
726*4882a593Smuzhiyun 	 *
727*4882a593Smuzhiyun 	 * This hook is only used by atomic helpers. Atomic drivers don't need
728*4882a593Smuzhiyun 	 * to implement it if there's no need to disable anything at the encoder
729*4882a593Smuzhiyun 	 * level. To ensure that runtime PM handling (using either DPMS or the
730*4882a593Smuzhiyun 	 * new "ACTIVE" property) works @atomic_disable must be the inverse of
731*4882a593Smuzhiyun 	 * @atomic_enable.
732*4882a593Smuzhiyun 	 */
733*4882a593Smuzhiyun 	void (*atomic_disable)(struct drm_encoder *encoder,
734*4882a593Smuzhiyun 			       struct drm_atomic_state *state);
735*4882a593Smuzhiyun 
736*4882a593Smuzhiyun 	/**
737*4882a593Smuzhiyun 	 * @atomic_enable:
738*4882a593Smuzhiyun 	 *
739*4882a593Smuzhiyun 	 * This callback should be used to enable the encoder. It is called
740*4882a593Smuzhiyun 	 * after this encoder's CRTC has been enabled using their own
741*4882a593Smuzhiyun 	 * &drm_crtc_helper_funcs.atomic_enable hook. If that sequence is
742*4882a593Smuzhiyun 	 * too simple drivers can just add their own driver private encoder
743*4882a593Smuzhiyun 	 * hooks and call them from CRTC's callback by looping over all encoders
744*4882a593Smuzhiyun 	 * connected to it using for_each_encoder_on_crtc().
745*4882a593Smuzhiyun 	 *
746*4882a593Smuzhiyun 	 * This callback is a variant of @enable that provides the atomic state
747*4882a593Smuzhiyun 	 * to the driver. If @atomic_enable is implemented, @enable is not
748*4882a593Smuzhiyun 	 * called by the helpers.
749*4882a593Smuzhiyun 	 *
750*4882a593Smuzhiyun 	 * This hook is only used by atomic helpers, it is the opposite of
751*4882a593Smuzhiyun 	 * @atomic_disable. Atomic drivers don't need to implement it if there's
752*4882a593Smuzhiyun 	 * no need to enable anything at the encoder level. To ensure that
753*4882a593Smuzhiyun 	 * runtime PM handling works @atomic_enable must be the inverse of
754*4882a593Smuzhiyun 	 * @atomic_disable.
755*4882a593Smuzhiyun 	 */
756*4882a593Smuzhiyun 	void (*atomic_enable)(struct drm_encoder *encoder,
757*4882a593Smuzhiyun 			      struct drm_atomic_state *state);
758*4882a593Smuzhiyun 
759*4882a593Smuzhiyun 	/**
760*4882a593Smuzhiyun 	 * @disable:
761*4882a593Smuzhiyun 	 *
762*4882a593Smuzhiyun 	 * This callback should be used to disable the encoder. With the atomic
763*4882a593Smuzhiyun 	 * drivers it is called before this encoder's CRTC has been shut off
764*4882a593Smuzhiyun 	 * using their own &drm_crtc_helper_funcs.disable hook.  If that
765*4882a593Smuzhiyun 	 * sequence is too simple drivers can just add their own driver private
766*4882a593Smuzhiyun 	 * encoder hooks and call them from CRTC's callback by looping over all
767*4882a593Smuzhiyun 	 * encoders connected to it using for_each_encoder_on_crtc().
768*4882a593Smuzhiyun 	 *
769*4882a593Smuzhiyun 	 * This hook is used both by legacy CRTC helpers and atomic helpers.
770*4882a593Smuzhiyun 	 * Atomic drivers don't need to implement it if there's no need to
771*4882a593Smuzhiyun 	 * disable anything at the encoder level. To ensure that runtime PM
772*4882a593Smuzhiyun 	 * handling (using either DPMS or the new "ACTIVE" property) works
773*4882a593Smuzhiyun 	 * @disable must be the inverse of @enable for atomic drivers.
774*4882a593Smuzhiyun 	 *
775*4882a593Smuzhiyun 	 * For atomic drivers also consider @atomic_disable and save yourself
776*4882a593Smuzhiyun 	 * from having to read the NOTE below!
777*4882a593Smuzhiyun 	 *
778*4882a593Smuzhiyun 	 * NOTE:
779*4882a593Smuzhiyun 	 *
780*4882a593Smuzhiyun 	 * With legacy CRTC helpers there's a big semantic difference between
781*4882a593Smuzhiyun 	 * @disable and other hooks (like @prepare or @dpms) used to shut down a
782*4882a593Smuzhiyun 	 * encoder: @disable is only called when also logically disabling the
783*4882a593Smuzhiyun 	 * display pipeline and needs to release any resources acquired in
784*4882a593Smuzhiyun 	 * @mode_set (like shared PLLs, or again release pinned framebuffers).
785*4882a593Smuzhiyun 	 *
786*4882a593Smuzhiyun 	 * Therefore @disable must be the inverse of @mode_set plus @commit for
787*4882a593Smuzhiyun 	 * drivers still using legacy CRTC helpers, which is different from the
788*4882a593Smuzhiyun 	 * rules under atomic.
789*4882a593Smuzhiyun 	 */
790*4882a593Smuzhiyun 	void (*disable)(struct drm_encoder *encoder);
791*4882a593Smuzhiyun 
792*4882a593Smuzhiyun 	/**
793*4882a593Smuzhiyun 	 * @enable:
794*4882a593Smuzhiyun 	 *
795*4882a593Smuzhiyun 	 * This callback should be used to enable the encoder. With the atomic
796*4882a593Smuzhiyun 	 * drivers it is called after this encoder's CRTC has been enabled using
797*4882a593Smuzhiyun 	 * their own &drm_crtc_helper_funcs.enable hook.  If that sequence is
798*4882a593Smuzhiyun 	 * too simple drivers can just add their own driver private encoder
799*4882a593Smuzhiyun 	 * hooks and call them from CRTC's callback by looping over all encoders
800*4882a593Smuzhiyun 	 * connected to it using for_each_encoder_on_crtc().
801*4882a593Smuzhiyun 	 *
802*4882a593Smuzhiyun 	 * This hook is only used by atomic helpers, it is the opposite of
803*4882a593Smuzhiyun 	 * @disable. Atomic drivers don't need to implement it if there's no
804*4882a593Smuzhiyun 	 * need to enable anything at the encoder level. To ensure that
805*4882a593Smuzhiyun 	 * runtime PM handling (using either DPMS or the new "ACTIVE" property)
806*4882a593Smuzhiyun 	 * works @enable must be the inverse of @disable for atomic drivers.
807*4882a593Smuzhiyun 	 */
808*4882a593Smuzhiyun 	void (*enable)(struct drm_encoder *encoder);
809*4882a593Smuzhiyun 
810*4882a593Smuzhiyun 	/**
811*4882a593Smuzhiyun 	 * @atomic_check:
812*4882a593Smuzhiyun 	 *
813*4882a593Smuzhiyun 	 * This callback is used to validate encoder state for atomic drivers.
814*4882a593Smuzhiyun 	 * Since the encoder is the object connecting the CRTC and connector it
815*4882a593Smuzhiyun 	 * gets passed both states, to be able to validate interactions and
816*4882a593Smuzhiyun 	 * update the CRTC to match what the encoder needs for the requested
817*4882a593Smuzhiyun 	 * connector.
818*4882a593Smuzhiyun 	 *
819*4882a593Smuzhiyun 	 * Since this provides a strict superset of the functionality of
820*4882a593Smuzhiyun 	 * @mode_fixup (the requested and adjusted modes are both available
821*4882a593Smuzhiyun 	 * through the passed in &struct drm_crtc_state) @mode_fixup is not
822*4882a593Smuzhiyun 	 * called when @atomic_check is implemented.
823*4882a593Smuzhiyun 	 *
824*4882a593Smuzhiyun 	 * This function is used by the atomic helpers, but it is optional.
825*4882a593Smuzhiyun 	 *
826*4882a593Smuzhiyun 	 * NOTE:
827*4882a593Smuzhiyun 	 *
828*4882a593Smuzhiyun 	 * This function is called in the check phase of an atomic update. The
829*4882a593Smuzhiyun 	 * driver is not allowed to change anything outside of the free-standing
830*4882a593Smuzhiyun 	 * state objects passed-in or assembled in the overall &drm_atomic_state
831*4882a593Smuzhiyun 	 * update tracking structure.
832*4882a593Smuzhiyun 	 *
833*4882a593Smuzhiyun 	 * Also beware that userspace can request its own custom modes, neither
834*4882a593Smuzhiyun 	 * core nor helpers filter modes to the list of probe modes reported by
835*4882a593Smuzhiyun 	 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
836*4882a593Smuzhiyun 	 * that modes are filtered consistently put any encoder constraints and
837*4882a593Smuzhiyun 	 * limits checks into @mode_valid.
838*4882a593Smuzhiyun 	 *
839*4882a593Smuzhiyun 	 * RETURNS:
840*4882a593Smuzhiyun 	 *
841*4882a593Smuzhiyun 	 * 0 on success, -EINVAL if the state or the transition can't be
842*4882a593Smuzhiyun 	 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
843*4882a593Smuzhiyun 	 * attempt to obtain another state object ran into a &drm_modeset_lock
844*4882a593Smuzhiyun 	 * deadlock.
845*4882a593Smuzhiyun 	 */
846*4882a593Smuzhiyun 	int (*atomic_check)(struct drm_encoder *encoder,
847*4882a593Smuzhiyun 			    struct drm_crtc_state *crtc_state,
848*4882a593Smuzhiyun 			    struct drm_connector_state *conn_state);
849*4882a593Smuzhiyun };
850*4882a593Smuzhiyun 
851*4882a593Smuzhiyun /**
852*4882a593Smuzhiyun  * drm_encoder_helper_add - sets the helper vtable for an encoder
853*4882a593Smuzhiyun  * @encoder: DRM encoder
854*4882a593Smuzhiyun  * @funcs: helper vtable to set for @encoder
855*4882a593Smuzhiyun  */
drm_encoder_helper_add(struct drm_encoder * encoder,const struct drm_encoder_helper_funcs * funcs)856*4882a593Smuzhiyun static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
857*4882a593Smuzhiyun 					  const struct drm_encoder_helper_funcs *funcs)
858*4882a593Smuzhiyun {
859*4882a593Smuzhiyun 	encoder->helper_private = funcs;
860*4882a593Smuzhiyun }
861*4882a593Smuzhiyun 
862*4882a593Smuzhiyun /**
863*4882a593Smuzhiyun  * struct drm_connector_helper_funcs - helper operations for connectors
864*4882a593Smuzhiyun  *
865*4882a593Smuzhiyun  * These functions are used by the atomic and legacy modeset helpers and by the
866*4882a593Smuzhiyun  * probe helpers.
867*4882a593Smuzhiyun  */
868*4882a593Smuzhiyun struct drm_connector_helper_funcs {
869*4882a593Smuzhiyun 	/**
870*4882a593Smuzhiyun 	 * @get_modes:
871*4882a593Smuzhiyun 	 *
872*4882a593Smuzhiyun 	 * This function should fill in all modes currently valid for the sink
873*4882a593Smuzhiyun 	 * into the &drm_connector.probed_modes list. It should also update the
874*4882a593Smuzhiyun 	 * EDID property by calling drm_connector_update_edid_property().
875*4882a593Smuzhiyun 	 *
876*4882a593Smuzhiyun 	 * The usual way to implement this is to cache the EDID retrieved in the
877*4882a593Smuzhiyun 	 * probe callback somewhere in the driver-private connector structure.
878*4882a593Smuzhiyun 	 * In this function drivers then parse the modes in the EDID and add
879*4882a593Smuzhiyun 	 * them by calling drm_add_edid_modes(). But connectors that driver a
880*4882a593Smuzhiyun 	 * fixed panel can also manually add specific modes using
881*4882a593Smuzhiyun 	 * drm_mode_probed_add(). Drivers which manually add modes should also
882*4882a593Smuzhiyun 	 * make sure that the &drm_connector.display_info,
883*4882a593Smuzhiyun 	 * &drm_connector.width_mm and &drm_connector.height_mm fields are
884*4882a593Smuzhiyun 	 * filled in.
885*4882a593Smuzhiyun 	 *
886*4882a593Smuzhiyun 	 * Virtual drivers that just want some standard VESA mode with a given
887*4882a593Smuzhiyun 	 * resolution can call drm_add_modes_noedid(), and mark the preferred
888*4882a593Smuzhiyun 	 * one using drm_set_preferred_mode().
889*4882a593Smuzhiyun 	 *
890*4882a593Smuzhiyun 	 * This function is only called after the @detect hook has indicated
891*4882a593Smuzhiyun 	 * that a sink is connected and when the EDID isn't overridden through
892*4882a593Smuzhiyun 	 * sysfs or the kernel commandline.
893*4882a593Smuzhiyun 	 *
894*4882a593Smuzhiyun 	 * This callback is used by the probe helpers in e.g.
895*4882a593Smuzhiyun 	 * drm_helper_probe_single_connector_modes().
896*4882a593Smuzhiyun 	 *
897*4882a593Smuzhiyun 	 * To avoid races with concurrent connector state updates, the helper
898*4882a593Smuzhiyun 	 * libraries always call this with the &drm_mode_config.connection_mutex
899*4882a593Smuzhiyun 	 * held. Because of this it's safe to inspect &drm_connector->state.
900*4882a593Smuzhiyun 	 *
901*4882a593Smuzhiyun 	 * RETURNS:
902*4882a593Smuzhiyun 	 *
903*4882a593Smuzhiyun 	 * The number of modes added by calling drm_mode_probed_add().
904*4882a593Smuzhiyun 	 */
905*4882a593Smuzhiyun 	int (*get_modes)(struct drm_connector *connector);
906*4882a593Smuzhiyun 
907*4882a593Smuzhiyun 	/**
908*4882a593Smuzhiyun 	 * @detect_ctx:
909*4882a593Smuzhiyun 	 *
910*4882a593Smuzhiyun 	 * Check to see if anything is attached to the connector. The parameter
911*4882a593Smuzhiyun 	 * force is set to false whilst polling, true when checking the
912*4882a593Smuzhiyun 	 * connector due to a user request. force can be used by the driver to
913*4882a593Smuzhiyun 	 * avoid expensive, destructive operations during automated probing.
914*4882a593Smuzhiyun 	 *
915*4882a593Smuzhiyun 	 * This callback is optional, if not implemented the connector will be
916*4882a593Smuzhiyun 	 * considered as always being attached.
917*4882a593Smuzhiyun 	 *
918*4882a593Smuzhiyun 	 * This is the atomic version of &drm_connector_funcs.detect.
919*4882a593Smuzhiyun 	 *
920*4882a593Smuzhiyun 	 * To avoid races against concurrent connector state updates, the
921*4882a593Smuzhiyun 	 * helper libraries always call this with ctx set to a valid context,
922*4882a593Smuzhiyun 	 * and &drm_mode_config.connection_mutex will always be locked with
923*4882a593Smuzhiyun 	 * the ctx parameter set to this ctx. This allows taking additional
924*4882a593Smuzhiyun 	 * locks as required.
925*4882a593Smuzhiyun 	 *
926*4882a593Smuzhiyun 	 * RETURNS:
927*4882a593Smuzhiyun 	 *
928*4882a593Smuzhiyun 	 * &drm_connector_status indicating the connector's status,
929*4882a593Smuzhiyun 	 * or the error code returned by drm_modeset_lock(), -EDEADLK.
930*4882a593Smuzhiyun 	 */
931*4882a593Smuzhiyun 	int (*detect_ctx)(struct drm_connector *connector,
932*4882a593Smuzhiyun 			  struct drm_modeset_acquire_ctx *ctx,
933*4882a593Smuzhiyun 			  bool force);
934*4882a593Smuzhiyun 
935*4882a593Smuzhiyun 	/**
936*4882a593Smuzhiyun 	 * @mode_valid:
937*4882a593Smuzhiyun 	 *
938*4882a593Smuzhiyun 	 * Callback to validate a mode for a connector, irrespective of the
939*4882a593Smuzhiyun 	 * specific display configuration.
940*4882a593Smuzhiyun 	 *
941*4882a593Smuzhiyun 	 * This callback is used by the probe helpers to filter the mode list
942*4882a593Smuzhiyun 	 * (which is usually derived from the EDID data block from the sink).
943*4882a593Smuzhiyun 	 * See e.g. drm_helper_probe_single_connector_modes().
944*4882a593Smuzhiyun 	 *
945*4882a593Smuzhiyun 	 * This function is optional.
946*4882a593Smuzhiyun 	 *
947*4882a593Smuzhiyun 	 * NOTE:
948*4882a593Smuzhiyun 	 *
949*4882a593Smuzhiyun 	 * This only filters the mode list supplied to userspace in the
950*4882a593Smuzhiyun 	 * GETCONNECTOR IOCTL. Compared to &drm_encoder_helper_funcs.mode_valid,
951*4882a593Smuzhiyun 	 * &drm_crtc_helper_funcs.mode_valid and &drm_bridge_funcs.mode_valid,
952*4882a593Smuzhiyun 	 * which are also called by the atomic helpers from
953*4882a593Smuzhiyun 	 * drm_atomic_helper_check_modeset(). This allows userspace to force and
954*4882a593Smuzhiyun 	 * ignore sink constraint (like the pixel clock limits in the screen's
955*4882a593Smuzhiyun 	 * EDID), which is useful for e.g. testing, or working around a broken
956*4882a593Smuzhiyun 	 * EDID. Any source hardware constraint (which always need to be
957*4882a593Smuzhiyun 	 * enforced) therefore should be checked in one of the above callbacks,
958*4882a593Smuzhiyun 	 * and not this one here.
959*4882a593Smuzhiyun 	 *
960*4882a593Smuzhiyun 	 * To avoid races with concurrent connector state updates, the helper
961*4882a593Smuzhiyun 	 * libraries always call this with the &drm_mode_config.connection_mutex
962*4882a593Smuzhiyun 	 * held. Because of this it's safe to inspect &drm_connector->state.
963*4882a593Smuzhiyun          *
964*4882a593Smuzhiyun 	 * RETURNS:
965*4882a593Smuzhiyun 	 *
966*4882a593Smuzhiyun 	 * Either &drm_mode_status.MODE_OK or one of the failure reasons in &enum
967*4882a593Smuzhiyun 	 * drm_mode_status.
968*4882a593Smuzhiyun 	 */
969*4882a593Smuzhiyun 	enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
970*4882a593Smuzhiyun 					   struct drm_display_mode *mode);
971*4882a593Smuzhiyun 
972*4882a593Smuzhiyun 	/**
973*4882a593Smuzhiyun 	 * @mode_valid_ctx:
974*4882a593Smuzhiyun 	 *
975*4882a593Smuzhiyun 	 * Callback to validate a mode for a connector, irrespective of the
976*4882a593Smuzhiyun 	 * specific display configuration.
977*4882a593Smuzhiyun 	 *
978*4882a593Smuzhiyun 	 * This callback is used by the probe helpers to filter the mode list
979*4882a593Smuzhiyun 	 * (which is usually derived from the EDID data block from the sink).
980*4882a593Smuzhiyun 	 * See e.g. drm_helper_probe_single_connector_modes().
981*4882a593Smuzhiyun 	 *
982*4882a593Smuzhiyun 	 * This function is optional, and is the atomic version of
983*4882a593Smuzhiyun 	 * &drm_connector_helper_funcs.mode_valid.
984*4882a593Smuzhiyun 	 *
985*4882a593Smuzhiyun 	 * To allow for accessing the atomic state of modesetting objects, the
986*4882a593Smuzhiyun 	 * helper libraries always call this with ctx set to a valid context,
987*4882a593Smuzhiyun 	 * and &drm_mode_config.connection_mutex will always be locked with
988*4882a593Smuzhiyun 	 * the ctx parameter set to @ctx. This allows for taking additional
989*4882a593Smuzhiyun 	 * locks as required.
990*4882a593Smuzhiyun 	 *
991*4882a593Smuzhiyun 	 * Even though additional locks may be acquired, this callback is
992*4882a593Smuzhiyun 	 * still expected not to take any constraints into account which would
993*4882a593Smuzhiyun 	 * be influenced by the currently set display state - such constraints
994*4882a593Smuzhiyun 	 * should be handled in the driver's atomic check. For example, if a
995*4882a593Smuzhiyun 	 * connector shares display bandwidth with other connectors then it
996*4882a593Smuzhiyun 	 * would be ok to validate the minimum bandwidth requirement of a mode
997*4882a593Smuzhiyun 	 * against the maximum possible bandwidth of the connector. But it
998*4882a593Smuzhiyun 	 * wouldn't be ok to take the current bandwidth usage of other
999*4882a593Smuzhiyun 	 * connectors into account, as this would change depending on the
1000*4882a593Smuzhiyun 	 * display state.
1001*4882a593Smuzhiyun 	 *
1002*4882a593Smuzhiyun 	 * Returns:
1003*4882a593Smuzhiyun 	 * 0 if &drm_connector_helper_funcs.mode_valid_ctx succeeded and wrote
1004*4882a593Smuzhiyun 	 * the &enum drm_mode_status value to @status, or a negative error
1005*4882a593Smuzhiyun 	 * code otherwise.
1006*4882a593Smuzhiyun 	 *
1007*4882a593Smuzhiyun 	 */
1008*4882a593Smuzhiyun 	int (*mode_valid_ctx)(struct drm_connector *connector,
1009*4882a593Smuzhiyun 			      struct drm_display_mode *mode,
1010*4882a593Smuzhiyun 			      struct drm_modeset_acquire_ctx *ctx,
1011*4882a593Smuzhiyun 			      enum drm_mode_status *status);
1012*4882a593Smuzhiyun 
1013*4882a593Smuzhiyun 	/**
1014*4882a593Smuzhiyun 	 * @best_encoder:
1015*4882a593Smuzhiyun 	 *
1016*4882a593Smuzhiyun 	 * This function should select the best encoder for the given connector.
1017*4882a593Smuzhiyun 	 *
1018*4882a593Smuzhiyun 	 * This function is used by both the atomic helpers (in the
1019*4882a593Smuzhiyun 	 * drm_atomic_helper_check_modeset() function) and in the legacy CRTC
1020*4882a593Smuzhiyun 	 * helpers.
1021*4882a593Smuzhiyun 	 *
1022*4882a593Smuzhiyun 	 * NOTE:
1023*4882a593Smuzhiyun 	 *
1024*4882a593Smuzhiyun 	 * In atomic drivers this function is called in the check phase of an
1025*4882a593Smuzhiyun 	 * atomic update. The driver is not allowed to change or inspect
1026*4882a593Smuzhiyun 	 * anything outside of arguments passed-in. Atomic drivers which need to
1027*4882a593Smuzhiyun 	 * inspect dynamic configuration state should instead use
1028*4882a593Smuzhiyun 	 * @atomic_best_encoder.
1029*4882a593Smuzhiyun 	 *
1030*4882a593Smuzhiyun 	 * You can leave this function to NULL if the connector is only
1031*4882a593Smuzhiyun 	 * attached to a single encoder. In this case, the core will call
1032*4882a593Smuzhiyun 	 * drm_connector_get_single_encoder() for you.
1033*4882a593Smuzhiyun 	 *
1034*4882a593Smuzhiyun 	 * RETURNS:
1035*4882a593Smuzhiyun 	 *
1036*4882a593Smuzhiyun 	 * Encoder that should be used for the given connector and connector
1037*4882a593Smuzhiyun 	 * state, or NULL if no suitable encoder exists. Note that the helpers
1038*4882a593Smuzhiyun 	 * will ensure that encoders aren't used twice, drivers should not check
1039*4882a593Smuzhiyun 	 * for this.
1040*4882a593Smuzhiyun 	 */
1041*4882a593Smuzhiyun 	struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
1042*4882a593Smuzhiyun 
1043*4882a593Smuzhiyun 	/**
1044*4882a593Smuzhiyun 	 * @atomic_best_encoder:
1045*4882a593Smuzhiyun 	 *
1046*4882a593Smuzhiyun 	 * This is the atomic version of @best_encoder for atomic drivers which
1047*4882a593Smuzhiyun 	 * need to select the best encoder depending upon the desired
1048*4882a593Smuzhiyun 	 * configuration and can't select it statically.
1049*4882a593Smuzhiyun 	 *
1050*4882a593Smuzhiyun 	 * This function is used by drm_atomic_helper_check_modeset().
1051*4882a593Smuzhiyun 	 * If it is not implemented, the core will fallback to @best_encoder
1052*4882a593Smuzhiyun 	 * (or drm_connector_get_single_encoder() if @best_encoder is NULL).
1053*4882a593Smuzhiyun 	 *
1054*4882a593Smuzhiyun 	 * NOTE:
1055*4882a593Smuzhiyun 	 *
1056*4882a593Smuzhiyun 	 * This function is called in the check phase of an atomic update. The
1057*4882a593Smuzhiyun 	 * driver is not allowed to change anything outside of the free-standing
1058*4882a593Smuzhiyun 	 * state objects passed-in or assembled in the overall &drm_atomic_state
1059*4882a593Smuzhiyun 	 * update tracking structure.
1060*4882a593Smuzhiyun 	 *
1061*4882a593Smuzhiyun 	 * RETURNS:
1062*4882a593Smuzhiyun 	 *
1063*4882a593Smuzhiyun 	 * Encoder that should be used for the given connector and connector
1064*4882a593Smuzhiyun 	 * state, or NULL if no suitable encoder exists. Note that the helpers
1065*4882a593Smuzhiyun 	 * will ensure that encoders aren't used twice, drivers should not check
1066*4882a593Smuzhiyun 	 * for this.
1067*4882a593Smuzhiyun 	 */
1068*4882a593Smuzhiyun 	struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,
1069*4882a593Smuzhiyun 						   struct drm_connector_state *connector_state);
1070*4882a593Smuzhiyun 
1071*4882a593Smuzhiyun 	/**
1072*4882a593Smuzhiyun 	 * @atomic_check:
1073*4882a593Smuzhiyun 	 *
1074*4882a593Smuzhiyun 	 * This hook is used to validate connector state. This function is
1075*4882a593Smuzhiyun 	 * called from &drm_atomic_helper_check_modeset, and is called when
1076*4882a593Smuzhiyun 	 * a connector property is set, or a modeset on the crtc is forced.
1077*4882a593Smuzhiyun 	 *
1078*4882a593Smuzhiyun 	 * Because &drm_atomic_helper_check_modeset may be called multiple times,
1079*4882a593Smuzhiyun 	 * this function should handle being called multiple times as well.
1080*4882a593Smuzhiyun 	 *
1081*4882a593Smuzhiyun 	 * This function is also allowed to inspect any other object's state and
1082*4882a593Smuzhiyun 	 * can add more state objects to the atomic commit if needed. Care must
1083*4882a593Smuzhiyun 	 * be taken though to ensure that state check and compute functions for
1084*4882a593Smuzhiyun 	 * these added states are all called, and derived state in other objects
1085*4882a593Smuzhiyun 	 * all updated. Again the recommendation is to just call check helpers
1086*4882a593Smuzhiyun 	 * until a maximal configuration is reached.
1087*4882a593Smuzhiyun 	 *
1088*4882a593Smuzhiyun 	 * NOTE:
1089*4882a593Smuzhiyun 	 *
1090*4882a593Smuzhiyun 	 * This function is called in the check phase of an atomic update. The
1091*4882a593Smuzhiyun 	 * driver is not allowed to change anything outside of the free-standing
1092*4882a593Smuzhiyun 	 * state objects passed-in or assembled in the overall &drm_atomic_state
1093*4882a593Smuzhiyun 	 * update tracking structure.
1094*4882a593Smuzhiyun 	 *
1095*4882a593Smuzhiyun 	 * RETURNS:
1096*4882a593Smuzhiyun 	 *
1097*4882a593Smuzhiyun 	 * 0 on success, -EINVAL if the state or the transition can't be
1098*4882a593Smuzhiyun 	 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
1099*4882a593Smuzhiyun 	 * attempt to obtain another state object ran into a &drm_modeset_lock
1100*4882a593Smuzhiyun 	 * deadlock.
1101*4882a593Smuzhiyun 	 */
1102*4882a593Smuzhiyun 	int (*atomic_check)(struct drm_connector *connector,
1103*4882a593Smuzhiyun 			    struct drm_atomic_state *state);
1104*4882a593Smuzhiyun 
1105*4882a593Smuzhiyun 	/**
1106*4882a593Smuzhiyun 	 * @atomic_commit:
1107*4882a593Smuzhiyun 	 *
1108*4882a593Smuzhiyun 	 * This hook is to be used by drivers implementing writeback connectors
1109*4882a593Smuzhiyun 	 * that need a point when to commit the writeback job to the hardware.
1110*4882a593Smuzhiyun 	 * The writeback_job to commit is available in
1111*4882a593Smuzhiyun 	 * &drm_connector_state.writeback_job.
1112*4882a593Smuzhiyun 	 *
1113*4882a593Smuzhiyun 	 * This hook is optional.
1114*4882a593Smuzhiyun 	 *
1115*4882a593Smuzhiyun 	 * This callback is used by the atomic modeset helpers.
1116*4882a593Smuzhiyun 	 */
1117*4882a593Smuzhiyun 	void (*atomic_commit)(struct drm_connector *connector,
1118*4882a593Smuzhiyun 			      struct drm_connector_state *state);
1119*4882a593Smuzhiyun 
1120*4882a593Smuzhiyun 	/**
1121*4882a593Smuzhiyun 	 * @prepare_writeback_job:
1122*4882a593Smuzhiyun 	 *
1123*4882a593Smuzhiyun 	 * As writeback jobs contain a framebuffer, drivers may need to
1124*4882a593Smuzhiyun 	 * prepare and clean them up the same way they can prepare and
1125*4882a593Smuzhiyun 	 * clean up framebuffers for planes. This optional connector operation
1126*4882a593Smuzhiyun 	 * is used to support the preparation of writeback jobs. The job
1127*4882a593Smuzhiyun 	 * prepare operation is called from drm_atomic_helper_prepare_planes()
1128*4882a593Smuzhiyun 	 * for struct &drm_writeback_connector connectors only.
1129*4882a593Smuzhiyun 	 *
1130*4882a593Smuzhiyun 	 * This operation is optional.
1131*4882a593Smuzhiyun 	 *
1132*4882a593Smuzhiyun 	 * This callback is used by the atomic modeset helpers.
1133*4882a593Smuzhiyun 	 */
1134*4882a593Smuzhiyun 	int (*prepare_writeback_job)(struct drm_writeback_connector *connector,
1135*4882a593Smuzhiyun 				     struct drm_writeback_job *job);
1136*4882a593Smuzhiyun 	/**
1137*4882a593Smuzhiyun 	 * @cleanup_writeback_job:
1138*4882a593Smuzhiyun 	 *
1139*4882a593Smuzhiyun 	 * This optional connector operation is used to support the
1140*4882a593Smuzhiyun 	 * cleanup of writeback jobs. The job cleanup operation is called
1141*4882a593Smuzhiyun 	 * from the existing drm_writeback_cleanup_job() function, invoked
1142*4882a593Smuzhiyun 	 * both when destroying the job as part of an aborted commit, or when
1143*4882a593Smuzhiyun 	 * the job completes.
1144*4882a593Smuzhiyun 	 *
1145*4882a593Smuzhiyun 	 * This operation is optional.
1146*4882a593Smuzhiyun 	 *
1147*4882a593Smuzhiyun 	 * This callback is used by the atomic modeset helpers.
1148*4882a593Smuzhiyun 	 */
1149*4882a593Smuzhiyun 	void (*cleanup_writeback_job)(struct drm_writeback_connector *connector,
1150*4882a593Smuzhiyun 				      struct drm_writeback_job *job);
1151*4882a593Smuzhiyun };
1152*4882a593Smuzhiyun 
1153*4882a593Smuzhiyun /**
1154*4882a593Smuzhiyun  * drm_connector_helper_add - sets the helper vtable for a connector
1155*4882a593Smuzhiyun  * @connector: DRM connector
1156*4882a593Smuzhiyun  * @funcs: helper vtable to set for @connector
1157*4882a593Smuzhiyun  */
drm_connector_helper_add(struct drm_connector * connector,const struct drm_connector_helper_funcs * funcs)1158*4882a593Smuzhiyun static inline void drm_connector_helper_add(struct drm_connector *connector,
1159*4882a593Smuzhiyun 					    const struct drm_connector_helper_funcs *funcs)
1160*4882a593Smuzhiyun {
1161*4882a593Smuzhiyun 	connector->helper_private = funcs;
1162*4882a593Smuzhiyun }
1163*4882a593Smuzhiyun 
1164*4882a593Smuzhiyun /**
1165*4882a593Smuzhiyun  * struct drm_plane_helper_funcs - helper operations for planes
1166*4882a593Smuzhiyun  *
1167*4882a593Smuzhiyun  * These functions are used by the atomic helpers and by the transitional plane
1168*4882a593Smuzhiyun  * helpers.
1169*4882a593Smuzhiyun  */
1170*4882a593Smuzhiyun struct drm_plane_helper_funcs {
1171*4882a593Smuzhiyun 	/**
1172*4882a593Smuzhiyun 	 * @prepare_fb:
1173*4882a593Smuzhiyun 	 *
1174*4882a593Smuzhiyun 	 * This hook is to prepare a framebuffer for scanout by e.g. pinning
1175*4882a593Smuzhiyun 	 * its backing storage or relocating it into a contiguous block of
1176*4882a593Smuzhiyun 	 * VRAM. Other possible preparatory work includes flushing caches.
1177*4882a593Smuzhiyun 	 *
1178*4882a593Smuzhiyun 	 * This function must not block for outstanding rendering, since it is
1179*4882a593Smuzhiyun 	 * called in the context of the atomic IOCTL even for async commits to
1180*4882a593Smuzhiyun 	 * be able to return any errors to userspace. Instead the recommended
1181*4882a593Smuzhiyun 	 * way is to fill out the &drm_plane_state.fence of the passed-in
1182*4882a593Smuzhiyun 	 * &drm_plane_state. If the driver doesn't support native fences then
1183*4882a593Smuzhiyun 	 * equivalent functionality should be implemented through private
1184*4882a593Smuzhiyun 	 * members in the plane structure.
1185*4882a593Smuzhiyun 	 *
1186*4882a593Smuzhiyun 	 * Drivers which always have their buffers pinned should use
1187*4882a593Smuzhiyun 	 * drm_gem_fb_prepare_fb() for this hook.
1188*4882a593Smuzhiyun 	 *
1189*4882a593Smuzhiyun 	 * The helpers will call @cleanup_fb with matching arguments for every
1190*4882a593Smuzhiyun 	 * successful call to this hook.
1191*4882a593Smuzhiyun 	 *
1192*4882a593Smuzhiyun 	 * This callback is used by the atomic modeset helpers and by the
1193*4882a593Smuzhiyun 	 * transitional plane helpers, but it is optional.
1194*4882a593Smuzhiyun 	 *
1195*4882a593Smuzhiyun 	 * RETURNS:
1196*4882a593Smuzhiyun 	 *
1197*4882a593Smuzhiyun 	 * 0 on success or one of the following negative error codes allowed by
1198*4882a593Smuzhiyun 	 * the &drm_mode_config_funcs.atomic_commit vfunc. When using helpers
1199*4882a593Smuzhiyun 	 * this callback is the only one which can fail an atomic commit,
1200*4882a593Smuzhiyun 	 * everything else must complete successfully.
1201*4882a593Smuzhiyun 	 */
1202*4882a593Smuzhiyun 	int (*prepare_fb)(struct drm_plane *plane,
1203*4882a593Smuzhiyun 			  struct drm_plane_state *new_state);
1204*4882a593Smuzhiyun 	/**
1205*4882a593Smuzhiyun 	 * @cleanup_fb:
1206*4882a593Smuzhiyun 	 *
1207*4882a593Smuzhiyun 	 * This hook is called to clean up any resources allocated for the given
1208*4882a593Smuzhiyun 	 * framebuffer and plane configuration in @prepare_fb.
1209*4882a593Smuzhiyun 	 *
1210*4882a593Smuzhiyun 	 * This callback is used by the atomic modeset helpers and by the
1211*4882a593Smuzhiyun 	 * transitional plane helpers, but it is optional.
1212*4882a593Smuzhiyun 	 */
1213*4882a593Smuzhiyun 	void (*cleanup_fb)(struct drm_plane *plane,
1214*4882a593Smuzhiyun 			   struct drm_plane_state *old_state);
1215*4882a593Smuzhiyun 
1216*4882a593Smuzhiyun 	/**
1217*4882a593Smuzhiyun 	 * @atomic_check:
1218*4882a593Smuzhiyun 	 *
1219*4882a593Smuzhiyun 	 * Drivers should check plane specific constraints in this hook.
1220*4882a593Smuzhiyun 	 *
1221*4882a593Smuzhiyun 	 * When using drm_atomic_helper_check_planes() plane's @atomic_check
1222*4882a593Smuzhiyun 	 * hooks are called before the ones for CRTCs, which allows drivers to
1223*4882a593Smuzhiyun 	 * request shared resources that the CRTC controls here. For more
1224*4882a593Smuzhiyun 	 * complicated dependencies the driver can call the provided check helpers
1225*4882a593Smuzhiyun 	 * multiple times until the computed state has a final configuration and
1226*4882a593Smuzhiyun 	 * everything has been checked.
1227*4882a593Smuzhiyun 	 *
1228*4882a593Smuzhiyun 	 * This function is also allowed to inspect any other object's state and
1229*4882a593Smuzhiyun 	 * can add more state objects to the atomic commit if needed. Care must
1230*4882a593Smuzhiyun 	 * be taken though to ensure that state check and compute functions for
1231*4882a593Smuzhiyun 	 * these added states are all called, and derived state in other objects
1232*4882a593Smuzhiyun 	 * all updated. Again the recommendation is to just call check helpers
1233*4882a593Smuzhiyun 	 * until a maximal configuration is reached.
1234*4882a593Smuzhiyun 	 *
1235*4882a593Smuzhiyun 	 * This callback is used by the atomic modeset helpers and by the
1236*4882a593Smuzhiyun 	 * transitional plane helpers, but it is optional.
1237*4882a593Smuzhiyun 	 *
1238*4882a593Smuzhiyun 	 * NOTE:
1239*4882a593Smuzhiyun 	 *
1240*4882a593Smuzhiyun 	 * This function is called in the check phase of an atomic update. The
1241*4882a593Smuzhiyun 	 * driver is not allowed to change anything outside of the free-standing
1242*4882a593Smuzhiyun 	 * state objects passed-in or assembled in the overall &drm_atomic_state
1243*4882a593Smuzhiyun 	 * update tracking structure.
1244*4882a593Smuzhiyun 	 *
1245*4882a593Smuzhiyun 	 * RETURNS:
1246*4882a593Smuzhiyun 	 *
1247*4882a593Smuzhiyun 	 * 0 on success, -EINVAL if the state or the transition can't be
1248*4882a593Smuzhiyun 	 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
1249*4882a593Smuzhiyun 	 * attempt to obtain another state object ran into a &drm_modeset_lock
1250*4882a593Smuzhiyun 	 * deadlock.
1251*4882a593Smuzhiyun 	 */
1252*4882a593Smuzhiyun 	int (*atomic_check)(struct drm_plane *plane,
1253*4882a593Smuzhiyun 			    struct drm_plane_state *state);
1254*4882a593Smuzhiyun 
1255*4882a593Smuzhiyun 	/**
1256*4882a593Smuzhiyun 	 * @atomic_update:
1257*4882a593Smuzhiyun 	 *
1258*4882a593Smuzhiyun 	 * Drivers should use this function to update the plane state.  This
1259*4882a593Smuzhiyun 	 * hook is called in-between the &drm_crtc_helper_funcs.atomic_begin and
1260*4882a593Smuzhiyun 	 * drm_crtc_helper_funcs.atomic_flush callbacks.
1261*4882a593Smuzhiyun 	 *
1262*4882a593Smuzhiyun 	 * Note that the power state of the display pipe when this function is
1263*4882a593Smuzhiyun 	 * called depends upon the exact helpers and calling sequence the driver
1264*4882a593Smuzhiyun 	 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
1265*4882a593Smuzhiyun 	 * the tradeoffs and variants of plane commit helpers.
1266*4882a593Smuzhiyun 	 *
1267*4882a593Smuzhiyun 	 * This callback is used by the atomic modeset helpers and by the
1268*4882a593Smuzhiyun 	 * transitional plane helpers, but it is optional.
1269*4882a593Smuzhiyun 	 */
1270*4882a593Smuzhiyun 	void (*atomic_update)(struct drm_plane *plane,
1271*4882a593Smuzhiyun 			      struct drm_plane_state *old_state);
1272*4882a593Smuzhiyun 	/**
1273*4882a593Smuzhiyun 	 * @atomic_disable:
1274*4882a593Smuzhiyun 	 *
1275*4882a593Smuzhiyun 	 * Drivers should use this function to unconditionally disable a plane.
1276*4882a593Smuzhiyun 	 * This hook is called in-between the
1277*4882a593Smuzhiyun 	 * &drm_crtc_helper_funcs.atomic_begin and
1278*4882a593Smuzhiyun 	 * drm_crtc_helper_funcs.atomic_flush callbacks. It is an alternative to
1279*4882a593Smuzhiyun 	 * @atomic_update, which will be called for disabling planes, too, if
1280*4882a593Smuzhiyun 	 * the @atomic_disable hook isn't implemented.
1281*4882a593Smuzhiyun 	 *
1282*4882a593Smuzhiyun 	 * This hook is also useful to disable planes in preparation of a modeset,
1283*4882a593Smuzhiyun 	 * by calling drm_atomic_helper_disable_planes_on_crtc() from the
1284*4882a593Smuzhiyun 	 * &drm_crtc_helper_funcs.disable hook.
1285*4882a593Smuzhiyun 	 *
1286*4882a593Smuzhiyun 	 * Note that the power state of the display pipe when this function is
1287*4882a593Smuzhiyun 	 * called depends upon the exact helpers and calling sequence the driver
1288*4882a593Smuzhiyun 	 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
1289*4882a593Smuzhiyun 	 * the tradeoffs and variants of plane commit helpers.
1290*4882a593Smuzhiyun 	 *
1291*4882a593Smuzhiyun 	 * This callback is used by the atomic modeset helpers and by the
1292*4882a593Smuzhiyun 	 * transitional plane helpers, but it is optional.
1293*4882a593Smuzhiyun 	 */
1294*4882a593Smuzhiyun 	void (*atomic_disable)(struct drm_plane *plane,
1295*4882a593Smuzhiyun 			       struct drm_plane_state *old_state);
1296*4882a593Smuzhiyun 
1297*4882a593Smuzhiyun 	/**
1298*4882a593Smuzhiyun 	 * @atomic_async_check:
1299*4882a593Smuzhiyun 	 *
1300*4882a593Smuzhiyun 	 * Drivers should set this function pointer to check if the plane state
1301*4882a593Smuzhiyun 	 * can be updated in a async fashion. Here async means "not vblank
1302*4882a593Smuzhiyun 	 * synchronized".
1303*4882a593Smuzhiyun 	 *
1304*4882a593Smuzhiyun 	 * This hook is called by drm_atomic_async_check() to establish if a
1305*4882a593Smuzhiyun 	 * given update can be committed asynchronously, that is, if it can
1306*4882a593Smuzhiyun 	 * jump ahead of the state currently queued for update.
1307*4882a593Smuzhiyun 	 *
1308*4882a593Smuzhiyun 	 * RETURNS:
1309*4882a593Smuzhiyun 	 *
1310*4882a593Smuzhiyun 	 * Return 0 on success and any error returned indicates that the update
1311*4882a593Smuzhiyun 	 * can not be applied in asynchronous manner.
1312*4882a593Smuzhiyun 	 */
1313*4882a593Smuzhiyun 	int (*atomic_async_check)(struct drm_plane *plane,
1314*4882a593Smuzhiyun 				  struct drm_plane_state *state);
1315*4882a593Smuzhiyun 
1316*4882a593Smuzhiyun 	/**
1317*4882a593Smuzhiyun 	 * @atomic_async_update:
1318*4882a593Smuzhiyun 	 *
1319*4882a593Smuzhiyun 	 * Drivers should set this function pointer to perform asynchronous
1320*4882a593Smuzhiyun 	 * updates of planes, that is, jump ahead of the currently queued
1321*4882a593Smuzhiyun 	 * state and update the plane. Here async means "not vblank
1322*4882a593Smuzhiyun 	 * synchronized".
1323*4882a593Smuzhiyun 	 *
1324*4882a593Smuzhiyun 	 * This hook is called by drm_atomic_helper_async_commit().
1325*4882a593Smuzhiyun 	 *
1326*4882a593Smuzhiyun 	 * An async update will happen on legacy cursor updates. An async
1327*4882a593Smuzhiyun 	 * update won't happen if there is an outstanding commit modifying
1328*4882a593Smuzhiyun 	 * the same plane.
1329*4882a593Smuzhiyun 	 *
1330*4882a593Smuzhiyun 	 * Note that unlike &drm_plane_helper_funcs.atomic_update this hook
1331*4882a593Smuzhiyun 	 * takes the new &drm_plane_state as parameter. When doing async_update
1332*4882a593Smuzhiyun 	 * drivers shouldn't replace the &drm_plane_state but update the
1333*4882a593Smuzhiyun 	 * current one with the new plane configurations in the new
1334*4882a593Smuzhiyun 	 * plane_state.
1335*4882a593Smuzhiyun 	 *
1336*4882a593Smuzhiyun 	 * Drivers should also swap the framebuffers between current plane
1337*4882a593Smuzhiyun 	 * state (&drm_plane.state) and new_state.
1338*4882a593Smuzhiyun 	 * This is required since cleanup for async commits is performed on
1339*4882a593Smuzhiyun 	 * the new state, rather than old state like for traditional commits.
1340*4882a593Smuzhiyun 	 * Since we want to give up the reference on the current (old) fb
1341*4882a593Smuzhiyun 	 * instead of our brand new one, swap them in the driver during the
1342*4882a593Smuzhiyun 	 * async commit.
1343*4882a593Smuzhiyun 	 *
1344*4882a593Smuzhiyun 	 * FIXME:
1345*4882a593Smuzhiyun 	 *  - It only works for single plane updates
1346*4882a593Smuzhiyun 	 *  - Async Pageflips are not supported yet
1347*4882a593Smuzhiyun 	 *  - Some hw might still scan out the old buffer until the next
1348*4882a593Smuzhiyun 	 *    vblank, however we let go of the fb references as soon as
1349*4882a593Smuzhiyun 	 *    we run this hook. For now drivers must implement their own workers
1350*4882a593Smuzhiyun 	 *    for deferring if needed, until a common solution is created.
1351*4882a593Smuzhiyun 	 */
1352*4882a593Smuzhiyun 	void (*atomic_async_update)(struct drm_plane *plane,
1353*4882a593Smuzhiyun 				    struct drm_plane_state *new_state);
1354*4882a593Smuzhiyun };
1355*4882a593Smuzhiyun 
1356*4882a593Smuzhiyun /**
1357*4882a593Smuzhiyun  * drm_plane_helper_add - sets the helper vtable for a plane
1358*4882a593Smuzhiyun  * @plane: DRM plane
1359*4882a593Smuzhiyun  * @funcs: helper vtable to set for @plane
1360*4882a593Smuzhiyun  */
drm_plane_helper_add(struct drm_plane * plane,const struct drm_plane_helper_funcs * funcs)1361*4882a593Smuzhiyun static inline void drm_plane_helper_add(struct drm_plane *plane,
1362*4882a593Smuzhiyun 					const struct drm_plane_helper_funcs *funcs)
1363*4882a593Smuzhiyun {
1364*4882a593Smuzhiyun 	plane->helper_private = funcs;
1365*4882a593Smuzhiyun }
1366*4882a593Smuzhiyun 
1367*4882a593Smuzhiyun /**
1368*4882a593Smuzhiyun  * struct drm_mode_config_helper_funcs - global modeset helper operations
1369*4882a593Smuzhiyun  *
1370*4882a593Smuzhiyun  * These helper functions are used by the atomic helpers.
1371*4882a593Smuzhiyun  */
1372*4882a593Smuzhiyun struct drm_mode_config_helper_funcs {
1373*4882a593Smuzhiyun 	/**
1374*4882a593Smuzhiyun 	 * @atomic_commit_tail:
1375*4882a593Smuzhiyun 	 *
1376*4882a593Smuzhiyun 	 * This hook is used by the default atomic_commit() hook implemented in
1377*4882a593Smuzhiyun 	 * drm_atomic_helper_commit() together with the nonblocking commit
1378*4882a593Smuzhiyun 	 * helpers (see drm_atomic_helper_setup_commit() for a starting point)
1379*4882a593Smuzhiyun 	 * to implement blocking and nonblocking commits easily. It is not used
1380*4882a593Smuzhiyun 	 * by the atomic helpers
1381*4882a593Smuzhiyun 	 *
1382*4882a593Smuzhiyun 	 * This function is called when the new atomic state has already been
1383*4882a593Smuzhiyun 	 * swapped into the various state pointers. The passed in state
1384*4882a593Smuzhiyun 	 * therefore contains copies of the old/previous state. This hook should
1385*4882a593Smuzhiyun 	 * commit the new state into hardware. Note that the helpers have
1386*4882a593Smuzhiyun 	 * already waited for preceeding atomic commits and fences, but drivers
1387*4882a593Smuzhiyun 	 * can add more waiting calls at the start of their implementation, e.g.
1388*4882a593Smuzhiyun 	 * to wait for driver-internal request for implicit syncing, before
1389*4882a593Smuzhiyun 	 * starting to commit the update to the hardware.
1390*4882a593Smuzhiyun 	 *
1391*4882a593Smuzhiyun 	 * After the atomic update is committed to the hardware this hook needs
1392*4882a593Smuzhiyun 	 * to call drm_atomic_helper_commit_hw_done(). Then wait for the upate
1393*4882a593Smuzhiyun 	 * to be executed by the hardware, for example using
1394*4882a593Smuzhiyun 	 * drm_atomic_helper_wait_for_vblanks() or
1395*4882a593Smuzhiyun 	 * drm_atomic_helper_wait_for_flip_done(), and then clean up the old
1396*4882a593Smuzhiyun 	 * framebuffers using drm_atomic_helper_cleanup_planes().
1397*4882a593Smuzhiyun 	 *
1398*4882a593Smuzhiyun 	 * When disabling a CRTC this hook _must_ stall for the commit to
1399*4882a593Smuzhiyun 	 * complete. Vblank waits don't work on disabled CRTC, hence the core
1400*4882a593Smuzhiyun 	 * can't take care of this. And it also can't rely on the vblank event,
1401*4882a593Smuzhiyun 	 * since that can be signalled already when the screen shows black,
1402*4882a593Smuzhiyun 	 * which can happen much earlier than the last hardware access needed to
1403*4882a593Smuzhiyun 	 * shut off the display pipeline completely.
1404*4882a593Smuzhiyun 	 *
1405*4882a593Smuzhiyun 	 * This hook is optional, the default implementation is
1406*4882a593Smuzhiyun 	 * drm_atomic_helper_commit_tail().
1407*4882a593Smuzhiyun 	 */
1408*4882a593Smuzhiyun 	void (*atomic_commit_tail)(struct drm_atomic_state *state);
1409*4882a593Smuzhiyun };
1410*4882a593Smuzhiyun 
1411*4882a593Smuzhiyun #endif
1412