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