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