drm: simple_kms_helper: add support for bridges
[linux-2.6-block.git] / include / drm / drm_modeset_helper_vtables.h
CommitLineData
092d01da
DV
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
34/**
35 * DOC: overview
36 *
37 * The DRM mode setting helper functions are common code for drivers to use if
38 * they wish. Drivers are not forced to use this code in their
39 * implementations but it would be useful if the code they do use at least
40 * provides a consistent interface and operation to userspace. Therefore it is
41 * highly recommended to use the provided helpers as much as possible.
42 *
43 * Because there is only one pointer per modeset object to hold a vfunc table
44 * for helper libraries they are by necessity shared among the different
45 * helpers.
46 *
47 * To make this clear all the helper vtables are pulled together in this location here.
48 */
49
50enum mode_set_atomic;
51
52/**
53 * struct drm_crtc_helper_funcs - helper operations for CRTCs
092d01da 54 *
36b66080
DV
55 * These hooks are used by the legacy CRTC helpers, the transitional plane
56 * helpers and the new atomic modesetting helpers.
092d01da
DV
57 */
58struct drm_crtc_helper_funcs {
36b66080
DV
59 /**
60 * @dpms:
61 *
62 * Callback to control power levels on the CRTC. If the mode passed in
63 * is unsupported, the provider must use the next lowest power level.
64 * This is used by the legacy CRTC helpers to implement DPMS
65 * functionality in drm_helper_connector_dpms().
66 *
67 * This callback is also used to disable a CRTC by calling it with
68 * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
69 *
70 * This callback is used by the legacy CRTC helpers. Atomic helpers
71 * also support using this hook for enabling and disabling a CRTC to
72 * facilitate transitions to atomic, but it is deprecated. Instead
73 * @enable and @disable should be used.
092d01da
DV
74 */
75 void (*dpms)(struct drm_crtc *crtc, int mode);
36b66080
DV
76
77 /**
78 * @prepare:
79 *
80 * This callback should prepare the CRTC for a subsequent modeset, which
81 * in practice means the driver should disable the CRTC if it is
82 * running. Most drivers ended up implementing this by calling their
83 * @dpms hook with DRM_MODE_DPMS_OFF.
84 *
85 * This callback is used by the legacy CRTC helpers. Atomic helpers
86 * also support using this hook for disabling a CRTC to facilitate
87 * transitions to atomic, but it is deprecated. Instead @disable should
88 * be used.
89 */
092d01da 90 void (*prepare)(struct drm_crtc *crtc);
36b66080
DV
91
92 /**
93 * @commit:
94 *
95 * This callback should commit the new mode on the CRTC after a modeset,
96 * which in practice means the driver should enable the CRTC. Most
97 * drivers ended up implementing this by calling their @dpms hook with
98 * DRM_MODE_DPMS_ON.
99 *
100 * This callback is used by the legacy CRTC helpers. Atomic helpers
101 * also support using this hook for enabling a CRTC to facilitate
102 * transitions to atomic, but it is deprecated. Instead @enable should
103 * be used.
104 */
092d01da
DV
105 void (*commit)(struct drm_crtc *crtc);
106
36b66080
DV
107 /**
108 * @mode_fixup:
109 *
110 * This callback is used to validate a mode. The parameter mode is the
111 * display mode that userspace requested, adjusted_mode is the mode the
112 * encoders need to be fed with. Note that this is the inverse semantics
113 * of the meaning for the &drm_encoder and &drm_bridge
114 * ->mode_fixup() functions. If the CRTC cannot support the requested
115 * conversion from mode to adjusted_mode it should reject the modeset.
116 *
117 * This function is used by both legacy CRTC helpers and atomic helpers.
118 * With atomic helpers it is optional.
119 *
120 * NOTE:
121 *
122 * This function is called in the check phase of atomic modesets, which
123 * can be aborted for any reason (including on userspace's request to
124 * just check whether a configuration would be possible). Atomic drivers
125 * MUST NOT touch any persistent state (hardware or software) or data
126 * structures except the passed in adjusted_mode parameter.
127 *
128 * This is in contrast to the legacy CRTC helpers where this was
129 * allowed.
130 *
131 * Atomic drivers which need to inspect and adjust more state should
132 * instead use the @atomic_check callback.
133 *
df7d678b
DV
134 * Also beware that neither core nor helpers filter modes before
135 * passing them to the driver: While the list of modes that is
136 * advertised to userspace is filtered using the connector's
137 * ->mode_valid() callback, neither the core nor the helpers do any
138 * filtering on modes passed in from userspace when setting a mode. It
139 * is therefore possible for userspace to pass in a mode that was
140 * previously filtered out using ->mode_valid() or add a custom mode
141 * that wasn't probed from EDID or similar to begin with. Even though
142 * this is an advanced feature and rarely used nowadays, some users rely
143 * on being able to specify modes manually so drivers must be prepared
144 * to deal with it. Specifically this means that all drivers need not
145 * only validate modes in ->mode_valid() but also in ->mode_fixup() to
146 * make sure invalid modes passed in from userspace are rejected.
147 *
36b66080
DV
148 * RETURNS:
149 *
150 * True if an acceptable configuration is possible, false if the modeset
151 * operation should be rejected.
152 */
092d01da
DV
153 bool (*mode_fixup)(struct drm_crtc *crtc,
154 const struct drm_display_mode *mode,
155 struct drm_display_mode *adjusted_mode);
36b66080
DV
156
157 /**
158 * @mode_set:
159 *
160 * This callback is used by the legacy CRTC helpers to set a new mode,
161 * position and framebuffer. Since it ties the primary plane to every
162 * mode change it is incompatible with universal plane support. And
163 * since it can't update other planes it's incompatible with atomic
164 * modeset support.
165 *
166 * This callback is only used by CRTC helpers and deprecated.
167 *
168 * RETURNS:
169 *
170 * 0 on success or a negative error code on failure.
171 */
092d01da
DV
172 int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
173 struct drm_display_mode *adjusted_mode, int x, int y,
174 struct drm_framebuffer *old_fb);
36b66080
DV
175
176 /**
177 * @mode_set_nofb:
178 *
179 * This callback is used to update the display mode of a CRTC without
180 * changing anything of the primary plane configuration. This fits the
181 * requirement of atomic and hence is used by the atomic helpers. It is
182 * also used by the transitional plane helpers to implement a
183 * @mode_set hook in drm_helper_crtc_mode_set().
184 *
185 * Note that the display pipe is completely off when this function is
186 * called. Atomic drivers which need hardware to be running before they
187 * program the new display mode (e.g. because they implement runtime PM)
188 * should not use this hook. This is because the helper library calls
189 * this hook only once per mode change and not every time the display
190 * pipeline is suspended using either DPMS or the new "ACTIVE" property.
191 * Which means register values set in this callback might get reset when
192 * the CRTC is suspended, but not restored. Such drivers should instead
193 * move all their CRTC setup into the @enable callback.
194 *
195 * This callback is optional.
196 */
092d01da
DV
197 void (*mode_set_nofb)(struct drm_crtc *crtc);
198
36b66080
DV
199 /**
200 * @mode_set_base:
201 *
202 * This callback is used by the legacy CRTC helpers to set a new
203 * framebuffer and scanout position. It is optional and used as an
204 * optimized fast-path instead of a full mode set operation with all the
df7d678b
DV
205 * resulting flickering. If it is not present
206 * drm_crtc_helper_set_config() will fall back to a full modeset, using
207 * the ->mode_set() callback. Since it can't update other planes it's
36b66080
DV
208 * incompatible with atomic modeset support.
209 *
210 * This callback is only used by the CRTC helpers and deprecated.
211 *
212 * RETURNS:
213 *
214 * 0 on success or a negative error code on failure.
215 */
092d01da
DV
216 int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
217 struct drm_framebuffer *old_fb);
36b66080
DV
218
219 /**
220 * @mode_set_base_atomic:
221 *
222 * This callback is used by the fbdev helpers to set a new framebuffer
223 * and scanout without sleeping, i.e. from an atomic calling context. It
224 * is only used to implement kgdb support.
225 *
226 * This callback is optional and only needed for kgdb support in the fbdev
227 * helpers.
228 *
229 * RETURNS:
230 *
231 * 0 on success or a negative error code on failure.
232 */
092d01da
DV
233 int (*mode_set_base_atomic)(struct drm_crtc *crtc,
234 struct drm_framebuffer *fb, int x, int y,
235 enum mode_set_atomic);
236
36b66080
DV
237 /**
238 * @load_lut:
239 *
240 * Load a LUT prepared with the @gamma_set functions from
241 * &drm_fb_helper_funcs.
242 *
243 * This callback is optional and is only used by the fbdev emulation
244 * helpers.
245 *
246 * FIXME:
247 *
248 * This callback is functionally redundant with the core gamma table
249 * support and simply exists because the fbdev hasn't yet been
250 * refactored to use the core gamma table interfaces.
251 */
092d01da
DV
252 void (*load_lut)(struct drm_crtc *crtc);
253
36b66080
DV
254 /**
255 * @disable:
256 *
257 * This callback should be used to disable the CRTC. With the atomic
258 * drivers it is called after all encoders connected to this CRTC have
259 * been shut off already using their own ->disable hook. If that
260 * sequence is too simple drivers can just add their own hooks and call
261 * it from this CRTC callback here by looping over all encoders
262 * connected to it using for_each_encoder_on_crtc().
263 *
264 * This hook is used both by legacy CRTC helpers and atomic helpers.
265 * Atomic drivers don't need to implement it if there's no need to
266 * disable anything at the CRTC level. To ensure that runtime PM
267 * handling (using either DPMS or the new "ACTIVE" property) works
268 * @disable must be the inverse of @enable for atomic drivers.
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 */
092d01da 282 void (*disable)(struct drm_crtc *crtc);
36b66080
DV
283
284 /**
285 * @enable:
286 *
287 * This callback should be used to enable the CRTC. With the atomic
288 * drivers it is called before all encoders connected to this CRTC are
289 * enabled through the encoder's own ->enable hook. If that sequence is
290 * too simple drivers can just add their own hooks and call it from this
291 * CRTC callback here by looping over all encoders connected to it using
292 * for_each_encoder_on_crtc().
293 *
294 * This hook is used only by atomic helpers, for symmetry with @disable.
295 * Atomic drivers don't need to implement it if there's no need to
296 * enable anything at the CRTC level. To ensure that runtime PM handling
297 * (using either DPMS or the new "ACTIVE" property) works
298 * @enable must be the inverse of @disable for atomic drivers.
299 */
092d01da
DV
300 void (*enable)(struct drm_crtc *crtc);
301
11a0ba97
DV
302 /**
303 * @atomic_check:
304 *
305 * Drivers should check plane-update related CRTC constraints in this
306 * hook. They can also check mode related limitations but need to be
307 * aware of the calling order, since this hook is used by
308 * drm_atomic_helper_check_planes() whereas the preparations needed to
309 * check output routing and the display mode is done in
310 * drm_atomic_helper_check_modeset(). Therefore drivers that want to
311 * check output routing and display mode constraints in this callback
312 * must ensure that drm_atomic_helper_check_modeset() has been called
313 * beforehand. This is calling order used by the default helper
314 * implementation in drm_atomic_helper_check().
315 *
316 * When using drm_atomic_helper_check_planes() CRTCs' ->atomic_check()
317 * hooks are called after the ones for planes, which allows drivers to
318 * assign shared resources requested by planes in the CRTC callback
319 * here. For more complicated dependencies the driver can call the provided
320 * check helpers multiple times until the computed state has a final
321 * configuration and everything has been checked.
322 *
323 * This function is also allowed to inspect any other object's state and
324 * can add more state objects to the atomic commit if needed. Care must
325 * be taken though to ensure that state check&compute functions for
326 * these added states are all called, and derived state in other objects
327 * all updated. Again the recommendation is to just call check helpers
328 * until a maximal configuration is reached.
329 *
330 * This callback is used by the atomic modeset helpers and by the
331 * transitional plane helpers, but it is optional.
332 *
333 * NOTE:
334 *
335 * This function is called in the check phase of an atomic update. The
336 * driver is not allowed to change anything outside of the free-standing
337 * state objects passed-in or assembled in the overall &drm_atomic_state
338 * update tracking structure.
339 *
340 * RETURNS:
341 *
342 * 0 on success, -EINVAL if the state or the transition can't be
343 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
344 * attempt to obtain another state object ran into a &drm_modeset_lock
345 * deadlock.
346 */
092d01da
DV
347 int (*atomic_check)(struct drm_crtc *crtc,
348 struct drm_crtc_state *state);
11a0ba97
DV
349
350 /**
351 * @atomic_begin:
352 *
353 * Drivers should prepare for an atomic update of multiple planes on
354 * a CRTC in this hook. Depending upon hardware this might be vblank
355 * evasion, blocking updates by setting bits or doing preparatory work
356 * for e.g. manual update display.
357 *
358 * This hook is called before any plane commit functions are called.
359 *
360 * Note that the power state of the display pipe when this function is
361 * called depends upon the exact helpers and calling sequence the driver
362 * has picked. See drm_atomic_commit_planes() for a discussion of the
363 * tradeoffs and variants of plane commit helpers.
364 *
365 * This callback is used by the atomic modeset helpers and by the
366 * transitional plane helpers, but it is optional.
367 */
092d01da
DV
368 void (*atomic_begin)(struct drm_crtc *crtc,
369 struct drm_crtc_state *old_crtc_state);
11a0ba97
DV
370 /**
371 * @atomic_flush:
372 *
373 * Drivers should finalize an atomic update of multiple planes on
374 * a CRTC in this hook. Depending upon hardware this might include
375 * checking that vblank evasion was successful, unblocking updates by
376 * setting bits or setting the GO bit to flush out all updates.
377 *
378 * Simple hardware or hardware with special requirements can commit and
379 * flush out all updates for all planes from this hook and forgo all the
380 * other commit hooks for plane updates.
381 *
382 * This hook is called after any plane commit functions are called.
383 *
384 * Note that the power state of the display pipe when this function is
385 * called depends upon the exact helpers and calling sequence the driver
386 * has picked. See drm_atomic_commit_planes() for a discussion of the
387 * tradeoffs and variants of plane commit helpers.
388 *
389 * This callback is used by the atomic modeset helpers and by the
390 * transitional plane helpers, but it is optional.
391 */
092d01da
DV
392 void (*atomic_flush)(struct drm_crtc *crtc,
393 struct drm_crtc_state *old_crtc_state);
394};
395
396/**
397 * drm_crtc_helper_add - sets the helper vtable for a crtc
398 * @crtc: DRM CRTC
399 * @funcs: helper vtable to set for @crtc
400 */
401static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
402 const struct drm_crtc_helper_funcs *funcs)
403{
404 crtc->helper_private = funcs;
405}
406
407/**
408 * struct drm_encoder_helper_funcs - helper operations for encoders
092d01da 409 *
36b66080
DV
410 * These hooks are used by the legacy CRTC helpers, the transitional plane
411 * helpers and the new atomic modesetting helpers.
092d01da
DV
412 */
413struct drm_encoder_helper_funcs {
36b66080
DV
414 /**
415 * @dpms:
416 *
417 * Callback to control power levels on the encoder. If the mode passed in
418 * is unsupported, the provider must use the next lowest power level.
419 * This is used by the legacy encoder helpers to implement DPMS
420 * functionality in drm_helper_connector_dpms().
421 *
422 * This callback is also used to disable an encoder by calling it with
423 * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
424 *
425 * This callback is used by the legacy CRTC helpers. Atomic helpers
426 * also support using this hook for enabling and disabling an encoder to
427 * facilitate transitions to atomic, but it is deprecated. Instead
428 * @enable and @disable should be used.
429 */
092d01da 430 void (*dpms)(struct drm_encoder *encoder, int mode);
092d01da 431
36b66080
DV
432 /**
433 * @mode_fixup:
434 *
435 * This callback is used to validate and adjust a mode. The parameter
436 * mode is the display mode that should be fed to the next element in
437 * the display chain, either the final &drm_connector or a &drm_bridge.
438 * The parameter adjusted_mode is the input mode the encoder requires. It
439 * can be modified by this callback and does not need to match mode.
440 *
441 * This function is used by both legacy CRTC helpers and atomic helpers.
3c5b2673 442 * This hook is optional.
36b66080
DV
443 *
444 * NOTE:
445 *
446 * This function is called in the check phase of atomic modesets, which
447 * can be aborted for any reason (including on userspace's request to
448 * just check whether a configuration would be possible). Atomic drivers
449 * MUST NOT touch any persistent state (hardware or software) or data
450 * structures except the passed in adjusted_mode parameter.
451 *
452 * This is in contrast to the legacy CRTC helpers where this was
453 * allowed.
454 *
455 * Atomic drivers which need to inspect and adjust more state should
456 * instead use the @atomic_check callback.
457 *
df7d678b
DV
458 * Also beware that neither core nor helpers filter modes before
459 * passing them to the driver: While the list of modes that is
460 * advertised to userspace is filtered using the connector's
461 * ->mode_valid() callback, neither the core nor the helpers do any
462 * filtering on modes passed in from userspace when setting a mode. It
463 * is therefore possible for userspace to pass in a mode that was
464 * previously filtered out using ->mode_valid() or add a custom mode
465 * that wasn't probed from EDID or similar to begin with. Even though
466 * this is an advanced feature and rarely used nowadays, some users rely
467 * on being able to specify modes manually so drivers must be prepared
468 * to deal with it. Specifically this means that all drivers need not
469 * only validate modes in ->mode_valid() but also in ->mode_fixup() to
470 * make sure invalid modes passed in from userspace are rejected.
471 *
36b66080
DV
472 * RETURNS:
473 *
474 * True if an acceptable configuration is possible, false if the modeset
475 * operation should be rejected.
476 */
092d01da
DV
477 bool (*mode_fixup)(struct drm_encoder *encoder,
478 const struct drm_display_mode *mode,
479 struct drm_display_mode *adjusted_mode);
36b66080
DV
480
481 /**
482 * @prepare:
483 *
484 * This callback should prepare the encoder for a subsequent modeset,
485 * which in practice means the driver should disable the encoder if it
486 * is running. Most drivers ended up implementing this by calling their
487 * @dpms hook with DRM_MODE_DPMS_OFF.
488 *
489 * This callback is used by the legacy CRTC helpers. Atomic helpers
490 * also support using this hook for disabling an encoder to facilitate
491 * transitions to atomic, but it is deprecated. Instead @disable should
492 * be used.
493 */
092d01da 494 void (*prepare)(struct drm_encoder *encoder);
36b66080
DV
495
496 /**
497 * @commit:
498 *
499 * This callback should commit the new mode on the encoder after a modeset,
500 * which in practice means the driver should enable the encoder. Most
501 * drivers ended up implementing this by calling their @dpms hook with
502 * DRM_MODE_DPMS_ON.
503 *
504 * This callback is used by the legacy CRTC helpers. Atomic helpers
505 * also support using this hook for enabling an encoder to facilitate
506 * transitions to atomic, but it is deprecated. Instead @enable should
507 * be used.
508 */
092d01da 509 void (*commit)(struct drm_encoder *encoder);
36b66080
DV
510
511 /**
512 * @mode_set:
513 *
514 * This callback is used to update the display mode of an encoder.
515 *
516 * Note that the display pipe is completely off when this function is
517 * called. Drivers which need hardware to be running before they program
518 * the new display mode (because they implement runtime PM) should not
519 * use this hook, because the helper library calls it only once and not
520 * every time the display pipeline is suspend using either DPMS or the
521 * new "ACTIVE" property. Such drivers should instead move all their
522 * encoder setup into the ->enable() callback.
523 *
524 * This callback is used both by the legacy CRTC helpers and the atomic
525 * modeset helpers. It is optional in the atomic helpers.
fe4a11c9
PZ
526 *
527 * NOTE:
528 *
529 * If the driver uses the atomic modeset helpers and needs to inspect
530 * the connector state or connector display info during mode setting,
531 * @atomic_mode_set can be used instead.
36b66080 532 */
092d01da
DV
533 void (*mode_set)(struct drm_encoder *encoder,
534 struct drm_display_mode *mode,
535 struct drm_display_mode *adjusted_mode);
36b66080 536
fe4a11c9
PZ
537 /**
538 * @atomic_mode_set:
539 *
540 * This callback is used to update the display mode of an encoder.
541 *
542 * Note that the display pipe is completely off when this function is
543 * called. Drivers which need hardware to be running before they program
544 * the new display mode (because they implement runtime PM) should not
545 * use this hook, because the helper library calls it only once and not
546 * every time the display pipeline is suspended using either DPMS or the
547 * new "ACTIVE" property. Such drivers should instead move all their
548 * encoder setup into the ->enable() callback.
549 *
550 * This callback is used by the atomic modeset helpers in place of the
551 * @mode_set callback, if set by the driver. It is optional and should
552 * be used instead of @mode_set if the driver needs to inspect the
553 * connector state or display info, since there is no direct way to
554 * go from the encoder to the current connector.
555 */
556 void (*atomic_mode_set)(struct drm_encoder *encoder,
557 struct drm_crtc_state *crtc_state,
558 struct drm_connector_state *conn_state);
559
36b66080
DV
560 /**
561 * @get_crtc:
562 *
563 * This callback is used by the legacy CRTC helpers to work around
564 * deficiencies in its own book-keeping.
565 *
566 * Do not use, use atomic helpers instead, which get the book keeping
567 * right.
568 *
569 * FIXME:
570 *
571 * Currently only nouveau is using this, and as soon as nouveau is
572 * atomic we can ditch this hook.
573 */
092d01da 574 struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder);
36b66080
DV
575
576 /**
577 * @detect:
578 *
579 * This callback can be used by drivers who want to do detection on the
580 * encoder object instead of in connector functions.
581 *
582 * It is not used by any helper and therefore has purely driver-specific
583 * semantics. New drivers shouldn't use this and instead just implement
584 * their own private callbacks.
585 *
586 * FIXME:
587 *
588 * This should just be converted into a pile of driver vfuncs.
589 * Currently radeon, amdgpu and nouveau are using it.
590 */
092d01da
DV
591 enum drm_connector_status (*detect)(struct drm_encoder *encoder,
592 struct drm_connector *connector);
36b66080
DV
593
594 /**
595 * @disable:
596 *
597 * This callback should be used to disable the encoder. With the atomic
598 * drivers it is called before this encoder's CRTC has been shut off
599 * using the CRTC's own ->disable hook. If that sequence is too simple
600 * drivers can just add their own driver private encoder hooks and call
601 * them from CRTC's callback by looping over all encoders connected to
602 * it using for_each_encoder_on_crtc().
603 *
604 * This hook is used both by legacy CRTC helpers and atomic helpers.
605 * Atomic drivers don't need to implement it if there's no need to
606 * disable anything at the encoder level. To ensure that runtime PM
607 * handling (using either DPMS or the new "ACTIVE" property) works
608 * @disable must be the inverse of @enable for atomic drivers.
609 *
610 * NOTE:
611 *
612 * With legacy CRTC helpers there's a big semantic difference between
613 * @disable and other hooks (like @prepare or @dpms) used to shut down a
614 * encoder: @disable is only called when also logically disabling the
615 * display pipeline and needs to release any resources acquired in
616 * @mode_set (like shared PLLs, or again release pinned framebuffers).
617 *
618 * Therefore @disable must be the inverse of @mode_set plus @commit for
619 * drivers still using legacy CRTC helpers, which is different from the
620 * rules under atomic.
621 */
092d01da
DV
622 void (*disable)(struct drm_encoder *encoder);
623
36b66080
DV
624 /**
625 * @enable:
626 *
627 * This callback should be used to enable the encoder. With the atomic
628 * drivers it is called after this encoder's CRTC has been enabled using
629 * the CRTC's own ->enable hook. If that sequence is too simple drivers
630 * can just add their own driver private encoder hooks and call them
631 * from CRTC's callback by looping over all encoders connected to it
632 * using for_each_encoder_on_crtc().
633 *
634 * This hook is used only by atomic helpers, for symmetry with @disable.
635 * Atomic drivers don't need to implement it if there's no need to
636 * enable anything at the encoder level. To ensure that runtime PM handling
637 * (using either DPMS or the new "ACTIVE" property) works
638 * @enable must be the inverse of @disable for atomic drivers.
639 */
092d01da
DV
640 void (*enable)(struct drm_encoder *encoder);
641
36b66080
DV
642 /**
643 * @atomic_check:
644 *
645 * This callback is used to validate encoder state for atomic drivers.
646 * Since the encoder is the object connecting the CRTC and connector it
647 * gets passed both states, to be able to validate interactions and
648 * update the CRTC to match what the encoder needs for the requested
649 * connector.
650 *
651 * This function is used by the atomic helpers, but it is optional.
652 *
653 * NOTE:
654 *
655 * This function is called in the check phase of an atomic update. The
656 * driver is not allowed to change anything outside of the free-standing
657 * state objects passed-in or assembled in the overall &drm_atomic_state
658 * update tracking structure.
659 *
660 * RETURNS:
661 *
662 * 0 on success, -EINVAL if the state or the transition can't be
663 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
664 * attempt to obtain another state object ran into a &drm_modeset_lock
665 * deadlock.
666 */
092d01da
DV
667 int (*atomic_check)(struct drm_encoder *encoder,
668 struct drm_crtc_state *crtc_state,
669 struct drm_connector_state *conn_state);
670};
671
672/**
36b66080 673 * drm_encoder_helper_add - sets the helper vtable for an encoder
092d01da
DV
674 * @encoder: DRM encoder
675 * @funcs: helper vtable to set for @encoder
676 */
677static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
678 const struct drm_encoder_helper_funcs *funcs)
679{
680 encoder->helper_private = funcs;
681}
682
683/**
684 * struct drm_connector_helper_funcs - helper operations for connectors
092d01da 685 *
4ee6034c
DV
686 * These functions are used by the atomic and legacy modeset helpers and by the
687 * probe helpers.
092d01da
DV
688 */
689struct drm_connector_helper_funcs {
4ee6034c
DV
690 /**
691 * @get_modes:
692 *
693 * This function should fill in all modes currently valid for the sink
694 * into the connector->probed_modes list. It should also update the
695 * EDID property by calling drm_mode_connector_update_edid_property().
696 *
697 * The usual way to implement this is to cache the EDID retrieved in the
698 * probe callback somewhere in the driver-private connector structure.
699 * In this function drivers then parse the modes in the EDID and add
700 * them by calling drm_add_edid_modes(). But connectors that driver a
701 * fixed panel can also manually add specific modes using
df7d678b
DV
702 * drm_mode_probed_add(). Drivers which manually add modes should also
703 * make sure that the @display_info, @width_mm and @height_mm fields of the
0e1a485b 704 * struct &drm_connector are filled in.
df7d678b
DV
705 *
706 * Virtual drivers that just want some standard VESA mode with a given
707 * resolution can call drm_add_modes_noedid(), and mark the preferred
708 * one using drm_set_preferred_mode().
709 *
710 * Finally drivers that support audio probably want to update the ELD
711 * data, too, using drm_edid_to_eld().
4ee6034c
DV
712 *
713 * This function is only called after the ->detect() hook has indicated
714 * that a sink is connected and when the EDID isn't overridden through
715 * sysfs or the kernel commandline.
716 *
717 * This callback is used by the probe helpers in e.g.
718 * drm_helper_probe_single_connector_modes().
719 *
720 * RETURNS:
721 *
722 * The number of modes added by calling drm_mode_probed_add().
723 */
092d01da 724 int (*get_modes)(struct drm_connector *connector);
4ee6034c
DV
725
726 /**
727 * @mode_valid:
728 *
729 * Callback to validate a mode for a connector, irrespective of the
730 * specific display configuration.
731 *
732 * This callback is used by the probe helpers to filter the mode list
733 * (which is usually derived from the EDID data block from the sink).
734 * See e.g. drm_helper_probe_single_connector_modes().
735 *
736 * NOTE:
737 *
738 * This only filters the mode list supplied to userspace in the
739 * GETCONNECOTR IOCTL. Userspace is free to create modes of its own and
740 * ask the kernel to use them. It this case the atomic helpers or legacy
741 * CRTC helpers will not call this function. Drivers therefore must
742 * still fully validate any mode passed in in a modeset request.
743 *
744 * RETURNS:
745 *
746 * Either MODE_OK or one of the failure reasons in enum
747 * &drm_mode_status.
748 */
092d01da
DV
749 enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
750 struct drm_display_mode *mode);
4ee6034c
DV
751 /**
752 * @best_encoder:
753 *
754 * This function should select the best encoder for the given connector.
755 *
756 * This function is used by both the atomic helpers (in the
757 * drm_atomic_helper_check_modeset() function) and in the legacy CRTC
758 * helpers.
759 *
760 * NOTE:
761 *
762 * In atomic drivers this function is called in the check phase of an
763 * atomic update. The driver is not allowed to change or inspect
764 * anything outside of arguments passed-in. Atomic drivers which need to
765 * inspect dynamic configuration state should instead use
766 * @atomic_best_encoder.
767 *
c61b93fe
BB
768 * You can leave this function to NULL if the connector is only
769 * attached to a single encoder and you are using the atomic helpers.
770 * In this case, the core will call drm_atomic_helper_best_encoder()
771 * for you.
772 *
4ee6034c
DV
773 * RETURNS:
774 *
775 * Encoder that should be used for the given connector and connector
776 * state, or NULL if no suitable encoder exists. Note that the helpers
777 * will ensure that encoders aren't used twice, drivers should not check
778 * for this.
779 */
092d01da 780 struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
4ee6034c
DV
781
782 /**
783 * @atomic_best_encoder:
784 *
785 * This is the atomic version of @best_encoder for atomic drivers which
786 * need to select the best encoder depending upon the desired
787 * configuration and can't select it statically.
788 *
c61b93fe
BB
789 * This function is used by drm_atomic_helper_check_modeset().
790 * If it is not implemented, the core will fallback to @best_encoder
791 * (or drm_atomic_helper_best_encoder() if @best_encoder is NULL).
4ee6034c
DV
792 *
793 * NOTE:
794 *
795 * This function is called in the check phase of an atomic update. The
796 * driver is not allowed to change anything outside of the free-standing
797 * state objects passed-in or assembled in the overall &drm_atomic_state
798 * update tracking structure.
799 *
800 * RETURNS:
801 *
802 * Encoder that should be used for the given connector and connector
803 * state, or NULL if no suitable encoder exists. Note that the helpers
804 * will ensure that encoders aren't used twice, drivers should not check
805 * for this.
806 */
092d01da
DV
807 struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,
808 struct drm_connector_state *connector_state);
809};
810
811/**
812 * drm_connector_helper_add - sets the helper vtable for a connector
813 * @connector: DRM connector
814 * @funcs: helper vtable to set for @connector
815 */
816static inline void drm_connector_helper_add(struct drm_connector *connector,
817 const struct drm_connector_helper_funcs *funcs)
818{
819 connector->helper_private = funcs;
820}
821
822/**
11a0ba97 823 * struct drm_plane_helper_funcs - helper operations for planes
092d01da 824 *
11a0ba97
DV
825 * These functions are used by the atomic helpers and by the transitional plane
826 * helpers.
092d01da
DV
827 */
828struct drm_plane_helper_funcs {
11a0ba97
DV
829 /**
830 * @prepare_fb:
831 *
832 * This hook is to prepare a framebuffer for scanout by e.g. pinning
833 * it's backing storage or relocating it into a contiguous block of
834 * VRAM. Other possible preparatory work includes flushing caches.
835 *
836 * This function must not block for outstanding rendering, since it is
837 * called in the context of the atomic IOCTL even for async commits to
838 * be able to return any errors to userspace. Instead the recommended
839 * way is to fill out the fence member of the passed-in
840 * &drm_plane_state. If the driver doesn't support native fences then
841 * equivalent functionality should be implemented through private
842 * members in the plane structure.
843 *
844 * The helpers will call @cleanup_fb with matching arguments for every
845 * successful call to this hook.
846 *
847 * This callback is used by the atomic modeset helpers and by the
848 * transitional plane helpers, but it is optional.
849 *
850 * RETURNS:
851 *
852 * 0 on success or one of the following negative error codes allowed by
853 * the atomic_commit hook in &drm_mode_config_funcs. When using helpers
854 * this callback is the only one which can fail an atomic commit,
855 * everything else must complete successfully.
856 */
092d01da 857 int (*prepare_fb)(struct drm_plane *plane,
1832040d 858 struct drm_plane_state *new_state);
11a0ba97
DV
859 /**
860 * @cleanup_fb:
861 *
862 * This hook is called to clean up any resources allocated for the given
863 * framebuffer and plane configuration in @prepare_fb.
864 *
865 * This callback is used by the atomic modeset helpers and by the
866 * transitional plane helpers, but it is optional.
867 */
092d01da 868 void (*cleanup_fb)(struct drm_plane *plane,
1832040d 869 struct drm_plane_state *old_state);
092d01da 870
11a0ba97
DV
871 /**
872 * @atomic_check:
873 *
874 * Drivers should check plane specific constraints in this hook.
875 *
876 * When using drm_atomic_helper_check_planes() plane's ->atomic_check()
877 * hooks are called before the ones for CRTCs, which allows drivers to
878 * request shared resources that the CRTC controls here. For more
879 * complicated dependencies the driver can call the provided check helpers
880 * multiple times until the computed state has a final configuration and
881 * everything has been checked.
882 *
883 * This function is also allowed to inspect any other object's state and
884 * can add more state objects to the atomic commit if needed. Care must
885 * be taken though to ensure that state check&compute functions for
886 * these added states are all called, and derived state in other objects
887 * all updated. Again the recommendation is to just call check helpers
888 * until a maximal configuration is reached.
889 *
890 * This callback is used by the atomic modeset helpers and by the
891 * transitional plane helpers, but it is optional.
892 *
893 * NOTE:
894 *
895 * This function is called in the check phase of an atomic update. The
896 * driver is not allowed to change anything outside of the free-standing
897 * state objects passed-in or assembled in the overall &drm_atomic_state
898 * update tracking structure.
899 *
900 * RETURNS:
901 *
902 * 0 on success, -EINVAL if the state or the transition can't be
903 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
904 * attempt to obtain another state object ran into a &drm_modeset_lock
905 * deadlock.
906 */
092d01da
DV
907 int (*atomic_check)(struct drm_plane *plane,
908 struct drm_plane_state *state);
11a0ba97
DV
909
910 /**
911 * @atomic_update:
912 *
913 * Drivers should use this function to update the plane state. This
914 * hook is called in-between the ->atomic_begin() and
915 * ->atomic_flush() of &drm_crtc_helper_funcs.
916 *
917 * Note that the power state of the display pipe when this function is
918 * called depends upon the exact helpers and calling sequence the driver
919 * has picked. See drm_atomic_commit_planes() for a discussion of the
920 * tradeoffs and variants of plane commit helpers.
921 *
922 * This callback is used by the atomic modeset helpers and by the
923 * transitional plane helpers, but it is optional.
924 */
092d01da
DV
925 void (*atomic_update)(struct drm_plane *plane,
926 struct drm_plane_state *old_state);
11a0ba97
DV
927 /**
928 * @atomic_disable:
929 *
930 * Drivers should use this function to unconditionally disable a plane.
931 * This hook is called in-between the ->atomic_begin() and
932 * ->atomic_flush() of &drm_crtc_helper_funcs. It is an alternative to
933 * @atomic_update, which will be called for disabling planes, too, if
934 * the @atomic_disable hook isn't implemented.
935 *
936 * This hook is also useful to disable planes in preparation of a modeset,
937 * by calling drm_atomic_helper_disable_planes_on_crtc() from the
938 * ->disable() hook in &drm_crtc_helper_funcs.
939 *
940 * Note that the power state of the display pipe when this function is
941 * called depends upon the exact helpers and calling sequence the driver
942 * has picked. See drm_atomic_commit_planes() for a discussion of the
943 * tradeoffs and variants of plane commit helpers.
944 *
945 * This callback is used by the atomic modeset helpers and by the
946 * transitional plane helpers, but it is optional.
947 */
092d01da
DV
948 void (*atomic_disable)(struct drm_plane *plane,
949 struct drm_plane_state *old_state);
950};
951
952/**
953 * drm_plane_helper_add - sets the helper vtable for a plane
954 * @plane: DRM plane
955 * @funcs: helper vtable to set for @plane
956 */
957static inline void drm_plane_helper_add(struct drm_plane *plane,
958 const struct drm_plane_helper_funcs *funcs)
959{
960 plane->helper_private = funcs;
961}
962
9f2a7950
DV
963/**
964 * struct drm_mode_config_helper_funcs - global modeset helper operations
965 *
966 * These helper functions are used by the atomic helpers.
967 */
968struct drm_mode_config_helper_funcs {
969 /**
970 * @atomic_commit_tail:
971 *
972 * This hook is used by the default atomic_commit() hook implemented in
973 * drm_atomic_helper_commit() together with the nonblocking commit
974 * helpers (see drm_atomic_helper_setup_commit() for a starting point)
975 * to implement blocking and nonblocking commits easily. It is not used
976 * by the atomic helpers
977 *
978 * This hook should first commit the given atomic state to the hardware.
979 * But drivers can add more waiting calls at the start of their
980 * implementation, e.g. to wait for driver-internal request for implicit
981 * syncing, before starting to commit the update to the hardware.
982 *
983 * After the atomic update is committed to the hardware this hook needs
984 * to call drm_atomic_helper_commit_hw_done(). Then wait for the upate
985 * to be executed by the hardware, for example using
986 * drm_atomic_helper_wait_for_vblanks(), and then clean up the old
987 * framebuffers using drm_atomic_helper_cleanup_planes().
988 *
989 * When disabling a CRTC this hook _must_ stall for the commit to
990 * complete. Vblank waits don't work on disabled CRTC, hence the core
991 * can't take care of this. And it also can't rely on the vblank event,
992 * since that can be signalled already when the screen shows black,
993 * which can happen much earlier than the last hardware access needed to
994 * shut off the display pipeline completely.
995 *
996 * This hook is optional, the default implementation is
997 * drm_atomic_helper_commit_tail().
998 */
999 void (*atomic_commit_tail)(struct drm_atomic_state *state);
1000};
1001
092d01da 1002#endif