[media] coda: add Freescale firmware compatibility location
[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.
c9ac8b4c
LY
269 * Atomic drivers should consider to use @atomic_disable instead of
270 * this one.
36b66080
DV
271 *
272 * NOTE:
273 *
274 * With legacy CRTC helpers there's a big semantic difference between
275 * @disable and other hooks (like @prepare or @dpms) used to shut down a
276 * CRTC: @disable is only called when also logically disabling the
277 * display pipeline and needs to release any resources acquired in
278 * @mode_set (like shared PLLs, or again release pinned framebuffers).
279 *
280 * Therefore @disable must be the inverse of @mode_set plus @commit for
281 * drivers still using legacy CRTC helpers, which is different from the
282 * rules under atomic.
283 */
092d01da 284 void (*disable)(struct drm_crtc *crtc);
36b66080
DV
285
286 /**
287 * @enable:
288 *
289 * This callback should be used to enable the CRTC. With the atomic
290 * drivers it is called before all encoders connected to this CRTC are
291 * enabled through the encoder's own ->enable hook. If that sequence is
292 * too simple drivers can just add their own hooks and call it from this
293 * CRTC callback here by looping over all encoders connected to it using
294 * for_each_encoder_on_crtc().
295 *
296 * This hook is used only by atomic helpers, for symmetry with @disable.
297 * Atomic drivers don't need to implement it if there's no need to
298 * enable anything at the CRTC level. To ensure that runtime PM handling
299 * (using either DPMS or the new "ACTIVE" property) works
300 * @enable must be the inverse of @disable for atomic drivers.
301 */
092d01da
DV
302 void (*enable)(struct drm_crtc *crtc);
303
11a0ba97
DV
304 /**
305 * @atomic_check:
306 *
307 * Drivers should check plane-update related CRTC constraints in this
308 * hook. They can also check mode related limitations but need to be
309 * aware of the calling order, since this hook is used by
310 * drm_atomic_helper_check_planes() whereas the preparations needed to
311 * check output routing and the display mode is done in
312 * drm_atomic_helper_check_modeset(). Therefore drivers that want to
313 * check output routing and display mode constraints in this callback
314 * must ensure that drm_atomic_helper_check_modeset() has been called
315 * beforehand. This is calling order used by the default helper
316 * implementation in drm_atomic_helper_check().
317 *
318 * When using drm_atomic_helper_check_planes() CRTCs' ->atomic_check()
319 * hooks are called after the ones for planes, which allows drivers to
320 * assign shared resources requested by planes in the CRTC callback
321 * here. For more complicated dependencies the driver can call the provided
322 * check helpers multiple times until the computed state has a final
323 * configuration and everything has been checked.
324 *
325 * This function is also allowed to inspect any other object's state and
326 * can add more state objects to the atomic commit if needed. Care must
327 * be taken though to ensure that state check&compute functions for
328 * these added states are all called, and derived state in other objects
329 * all updated. Again the recommendation is to just call check helpers
330 * until a maximal configuration is reached.
331 *
332 * This callback is used by the atomic modeset helpers and by the
333 * transitional plane helpers, but it is optional.
334 *
335 * NOTE:
336 *
337 * This function is called in the check phase of an atomic update. The
338 * driver is not allowed to change anything outside of the free-standing
339 * state objects passed-in or assembled in the overall &drm_atomic_state
340 * update tracking structure.
341 *
342 * RETURNS:
343 *
344 * 0 on success, -EINVAL if the state or the transition can't be
345 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
346 * attempt to obtain another state object ran into a &drm_modeset_lock
347 * deadlock.
348 */
092d01da
DV
349 int (*atomic_check)(struct drm_crtc *crtc,
350 struct drm_crtc_state *state);
11a0ba97
DV
351
352 /**
353 * @atomic_begin:
354 *
355 * Drivers should prepare for an atomic update of multiple planes on
356 * a CRTC in this hook. Depending upon hardware this might be vblank
357 * evasion, blocking updates by setting bits or doing preparatory work
358 * for e.g. manual update display.
359 *
360 * This hook is called before any plane commit functions are called.
361 *
362 * Note that the power state of the display pipe when this function is
363 * called depends upon the exact helpers and calling sequence the driver
0dc9967d
SA
364 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
365 * the tradeoffs and variants of plane commit helpers.
11a0ba97
DV
366 *
367 * This callback is used by the atomic modeset helpers and by the
368 * transitional plane helpers, but it is optional.
369 */
092d01da
DV
370 void (*atomic_begin)(struct drm_crtc *crtc,
371 struct drm_crtc_state *old_crtc_state);
11a0ba97
DV
372 /**
373 * @atomic_flush:
374 *
375 * Drivers should finalize an atomic update of multiple planes on
376 * a CRTC in this hook. Depending upon hardware this might include
377 * checking that vblank evasion was successful, unblocking updates by
378 * setting bits or setting the GO bit to flush out all updates.
379 *
380 * Simple hardware or hardware with special requirements can commit and
381 * flush out all updates for all planes from this hook and forgo all the
382 * other commit hooks for plane updates.
383 *
384 * This hook is called after any plane commit functions are called.
385 *
386 * Note that the power state of the display pipe when this function is
387 * called depends upon the exact helpers and calling sequence the driver
0dc9967d
SA
388 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
389 * the tradeoffs and variants of plane commit helpers.
11a0ba97
DV
390 *
391 * This callback is used by the atomic modeset helpers and by the
392 * transitional plane helpers, but it is optional.
393 */
092d01da
DV
394 void (*atomic_flush)(struct drm_crtc *crtc,
395 struct drm_crtc_state *old_crtc_state);
c9ac8b4c
LY
396
397 /**
398 * @atomic_disable:
399 *
400 * This callback should be used to disable the CRTC. With the atomic
401 * drivers it is called after all encoders connected to this CRTC have
402 * been shut off already using their own ->disable hook. If that
403 * sequence is too simple drivers can just add their own hooks and call
404 * it from this CRTC callback here by looping over all encoders
405 * connected to it using for_each_encoder_on_crtc().
406 *
407 * This hook is used only by atomic helpers. Atomic drivers don't
408 * need to implement it if there's no need to disable anything at the
409 * CRTC level.
410 *
411 * Comparing to @disable, this one provides the additional input
412 * parameter @old_crtc_state which could be used to access the old
413 * state. Atomic drivers should consider to use this one instead
414 * of @disable.
415 */
416 void (*atomic_disable)(struct drm_crtc *crtc,
417 struct drm_crtc_state *old_crtc_state);
092d01da
DV
418};
419
420/**
421 * drm_crtc_helper_add - sets the helper vtable for a crtc
422 * @crtc: DRM CRTC
423 * @funcs: helper vtable to set for @crtc
424 */
425static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
426 const struct drm_crtc_helper_funcs *funcs)
427{
428 crtc->helper_private = funcs;
429}
430
431/**
432 * struct drm_encoder_helper_funcs - helper operations for encoders
092d01da 433 *
36b66080
DV
434 * These hooks are used by the legacy CRTC helpers, the transitional plane
435 * helpers and the new atomic modesetting helpers.
092d01da
DV
436 */
437struct drm_encoder_helper_funcs {
36b66080
DV
438 /**
439 * @dpms:
440 *
441 * Callback to control power levels on the encoder. If the mode passed in
442 * is unsupported, the provider must use the next lowest power level.
443 * This is used by the legacy encoder helpers to implement DPMS
444 * functionality in drm_helper_connector_dpms().
445 *
446 * This callback is also used to disable an encoder by calling it with
447 * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
448 *
449 * This callback is used by the legacy CRTC helpers. Atomic helpers
450 * also support using this hook for enabling and disabling an encoder to
451 * facilitate transitions to atomic, but it is deprecated. Instead
452 * @enable and @disable should be used.
453 */
092d01da 454 void (*dpms)(struct drm_encoder *encoder, int mode);
092d01da 455
36b66080
DV
456 /**
457 * @mode_fixup:
458 *
459 * This callback is used to validate and adjust a mode. The parameter
460 * mode is the display mode that should be fed to the next element in
461 * the display chain, either the final &drm_connector or a &drm_bridge.
462 * The parameter adjusted_mode is the input mode the encoder requires. It
463 * can be modified by this callback and does not need to match mode.
464 *
465 * This function is used by both legacy CRTC helpers and atomic helpers.
3c5b2673 466 * This hook is optional.
36b66080
DV
467 *
468 * NOTE:
469 *
470 * This function is called in the check phase of atomic modesets, which
471 * can be aborted for any reason (including on userspace's request to
472 * just check whether a configuration would be possible). Atomic drivers
473 * MUST NOT touch any persistent state (hardware or software) or data
474 * structures except the passed in adjusted_mode parameter.
475 *
476 * This is in contrast to the legacy CRTC helpers where this was
477 * allowed.
478 *
479 * Atomic drivers which need to inspect and adjust more state should
480 * instead use the @atomic_check callback.
481 *
df7d678b
DV
482 * Also beware that neither core nor helpers filter modes before
483 * passing them to the driver: While the list of modes that is
484 * advertised to userspace is filtered using the connector's
485 * ->mode_valid() callback, neither the core nor the helpers do any
486 * filtering on modes passed in from userspace when setting a mode. It
487 * is therefore possible for userspace to pass in a mode that was
488 * previously filtered out using ->mode_valid() or add a custom mode
489 * that wasn't probed from EDID or similar to begin with. Even though
490 * this is an advanced feature and rarely used nowadays, some users rely
491 * on being able to specify modes manually so drivers must be prepared
492 * to deal with it. Specifically this means that all drivers need not
493 * only validate modes in ->mode_valid() but also in ->mode_fixup() to
494 * make sure invalid modes passed in from userspace are rejected.
495 *
36b66080
DV
496 * RETURNS:
497 *
498 * True if an acceptable configuration is possible, false if the modeset
499 * operation should be rejected.
500 */
092d01da
DV
501 bool (*mode_fixup)(struct drm_encoder *encoder,
502 const struct drm_display_mode *mode,
503 struct drm_display_mode *adjusted_mode);
36b66080
DV
504
505 /**
506 * @prepare:
507 *
508 * This callback should prepare the encoder for a subsequent modeset,
509 * which in practice means the driver should disable the encoder if it
510 * is running. Most drivers ended up implementing this by calling their
511 * @dpms hook with DRM_MODE_DPMS_OFF.
512 *
513 * This callback is used by the legacy CRTC helpers. Atomic helpers
514 * also support using this hook for disabling an encoder to facilitate
515 * transitions to atomic, but it is deprecated. Instead @disable should
516 * be used.
517 */
092d01da 518 void (*prepare)(struct drm_encoder *encoder);
36b66080
DV
519
520 /**
521 * @commit:
522 *
523 * This callback should commit the new mode on the encoder after a modeset,
524 * which in practice means the driver should enable the encoder. Most
525 * drivers ended up implementing this by calling their @dpms hook with
526 * DRM_MODE_DPMS_ON.
527 *
528 * This callback is used by the legacy CRTC helpers. Atomic helpers
529 * also support using this hook for enabling an encoder to facilitate
530 * transitions to atomic, but it is deprecated. Instead @enable should
531 * be used.
532 */
092d01da 533 void (*commit)(struct drm_encoder *encoder);
36b66080
DV
534
535 /**
536 * @mode_set:
537 *
538 * This callback is used to update the display mode of an encoder.
539 *
540 * Note that the display pipe is completely off when this function is
541 * called. Drivers which need hardware to be running before they program
542 * the new display mode (because they implement runtime PM) should not
543 * use this hook, because the helper library calls it only once and not
544 * every time the display pipeline is suspend using either DPMS or the
545 * new "ACTIVE" property. Such drivers should instead move all their
546 * encoder setup into the ->enable() callback.
547 *
548 * This callback is used both by the legacy CRTC helpers and the atomic
549 * modeset helpers. It is optional in the atomic helpers.
fe4a11c9
PZ
550 *
551 * NOTE:
552 *
553 * If the driver uses the atomic modeset helpers and needs to inspect
554 * the connector state or connector display info during mode setting,
555 * @atomic_mode_set can be used instead.
36b66080 556 */
092d01da
DV
557 void (*mode_set)(struct drm_encoder *encoder,
558 struct drm_display_mode *mode,
559 struct drm_display_mode *adjusted_mode);
36b66080 560
fe4a11c9
PZ
561 /**
562 * @atomic_mode_set:
563 *
564 * This callback is used to update the display mode of an encoder.
565 *
566 * Note that the display pipe is completely off when this function is
567 * called. Drivers which need hardware to be running before they program
568 * the new display mode (because they implement runtime PM) should not
569 * use this hook, because the helper library calls it only once and not
570 * every time the display pipeline is suspended using either DPMS or the
571 * new "ACTIVE" property. Such drivers should instead move all their
572 * encoder setup into the ->enable() callback.
573 *
574 * This callback is used by the atomic modeset helpers in place of the
575 * @mode_set callback, if set by the driver. It is optional and should
576 * be used instead of @mode_set if the driver needs to inspect the
577 * connector state or display info, since there is no direct way to
578 * go from the encoder to the current connector.
579 */
580 void (*atomic_mode_set)(struct drm_encoder *encoder,
581 struct drm_crtc_state *crtc_state,
582 struct drm_connector_state *conn_state);
583
36b66080
DV
584 /**
585 * @get_crtc:
586 *
587 * This callback is used by the legacy CRTC helpers to work around
588 * deficiencies in its own book-keeping.
589 *
590 * Do not use, use atomic helpers instead, which get the book keeping
591 * right.
592 *
593 * FIXME:
594 *
595 * Currently only nouveau is using this, and as soon as nouveau is
596 * atomic we can ditch this hook.
597 */
092d01da 598 struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder);
36b66080
DV
599
600 /**
601 * @detect:
602 *
603 * This callback can be used by drivers who want to do detection on the
604 * encoder object instead of in connector functions.
605 *
606 * It is not used by any helper and therefore has purely driver-specific
607 * semantics. New drivers shouldn't use this and instead just implement
608 * their own private callbacks.
609 *
610 * FIXME:
611 *
612 * This should just be converted into a pile of driver vfuncs.
613 * Currently radeon, amdgpu and nouveau are using it.
614 */
092d01da
DV
615 enum drm_connector_status (*detect)(struct drm_encoder *encoder,
616 struct drm_connector *connector);
36b66080
DV
617
618 /**
619 * @disable:
620 *
621 * This callback should be used to disable the encoder. With the atomic
622 * drivers it is called before this encoder's CRTC has been shut off
623 * using the CRTC's own ->disable hook. If that sequence is too simple
624 * drivers can just add their own driver private encoder hooks and call
625 * them from CRTC's callback by looping over all encoders connected to
626 * it using for_each_encoder_on_crtc().
627 *
628 * This hook is used both by legacy CRTC helpers and atomic helpers.
629 * Atomic drivers don't need to implement it if there's no need to
630 * disable anything at the encoder level. To ensure that runtime PM
631 * handling (using either DPMS or the new "ACTIVE" property) works
632 * @disable must be the inverse of @enable for atomic drivers.
633 *
634 * NOTE:
635 *
636 * With legacy CRTC helpers there's a big semantic difference between
637 * @disable and other hooks (like @prepare or @dpms) used to shut down a
638 * encoder: @disable is only called when also logically disabling the
639 * display pipeline and needs to release any resources acquired in
640 * @mode_set (like shared PLLs, or again release pinned framebuffers).
641 *
642 * Therefore @disable must be the inverse of @mode_set plus @commit for
643 * drivers still using legacy CRTC helpers, which is different from the
644 * rules under atomic.
645 */
092d01da
DV
646 void (*disable)(struct drm_encoder *encoder);
647
36b66080
DV
648 /**
649 * @enable:
650 *
651 * This callback should be used to enable the encoder. With the atomic
652 * drivers it is called after this encoder's CRTC has been enabled using
653 * the CRTC's own ->enable hook. If that sequence is too simple drivers
654 * can just add their own driver private encoder hooks and call them
655 * from CRTC's callback by looping over all encoders connected to it
656 * using for_each_encoder_on_crtc().
657 *
658 * This hook is used only by atomic helpers, for symmetry with @disable.
659 * Atomic drivers don't need to implement it if there's no need to
660 * enable anything at the encoder level. To ensure that runtime PM handling
661 * (using either DPMS or the new "ACTIVE" property) works
662 * @enable must be the inverse of @disable for atomic drivers.
663 */
092d01da
DV
664 void (*enable)(struct drm_encoder *encoder);
665
36b66080
DV
666 /**
667 * @atomic_check:
668 *
669 * This callback is used to validate encoder state for atomic drivers.
670 * Since the encoder is the object connecting the CRTC and connector it
671 * gets passed both states, to be able to validate interactions and
672 * update the CRTC to match what the encoder needs for the requested
673 * connector.
674 *
675 * This function is used by the atomic helpers, but it is optional.
676 *
677 * NOTE:
678 *
679 * This function is called in the check phase of an atomic update. The
680 * driver is not allowed to change anything outside of the free-standing
681 * state objects passed-in or assembled in the overall &drm_atomic_state
682 * update tracking structure.
683 *
684 * RETURNS:
685 *
686 * 0 on success, -EINVAL if the state or the transition can't be
687 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
688 * attempt to obtain another state object ran into a &drm_modeset_lock
689 * deadlock.
690 */
092d01da
DV
691 int (*atomic_check)(struct drm_encoder *encoder,
692 struct drm_crtc_state *crtc_state,
693 struct drm_connector_state *conn_state);
694};
695
696/**
36b66080 697 * drm_encoder_helper_add - sets the helper vtable for an encoder
092d01da
DV
698 * @encoder: DRM encoder
699 * @funcs: helper vtable to set for @encoder
700 */
701static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
702 const struct drm_encoder_helper_funcs *funcs)
703{
704 encoder->helper_private = funcs;
705}
706
707/**
708 * struct drm_connector_helper_funcs - helper operations for connectors
092d01da 709 *
4ee6034c
DV
710 * These functions are used by the atomic and legacy modeset helpers and by the
711 * probe helpers.
092d01da
DV
712 */
713struct drm_connector_helper_funcs {
4ee6034c
DV
714 /**
715 * @get_modes:
716 *
717 * This function should fill in all modes currently valid for the sink
718 * into the connector->probed_modes list. It should also update the
719 * EDID property by calling drm_mode_connector_update_edid_property().
720 *
721 * The usual way to implement this is to cache the EDID retrieved in the
722 * probe callback somewhere in the driver-private connector structure.
723 * In this function drivers then parse the modes in the EDID and add
724 * them by calling drm_add_edid_modes(). But connectors that driver a
725 * fixed panel can also manually add specific modes using
df7d678b
DV
726 * drm_mode_probed_add(). Drivers which manually add modes should also
727 * make sure that the @display_info, @width_mm and @height_mm fields of the
0e1a485b 728 * struct &drm_connector are filled in.
df7d678b
DV
729 *
730 * Virtual drivers that just want some standard VESA mode with a given
731 * resolution can call drm_add_modes_noedid(), and mark the preferred
732 * one using drm_set_preferred_mode().
733 *
734 * Finally drivers that support audio probably want to update the ELD
735 * data, too, using drm_edid_to_eld().
4ee6034c
DV
736 *
737 * This function is only called after the ->detect() hook has indicated
738 * that a sink is connected and when the EDID isn't overridden through
739 * sysfs or the kernel commandline.
740 *
741 * This callback is used by the probe helpers in e.g.
742 * drm_helper_probe_single_connector_modes().
743 *
744 * RETURNS:
745 *
746 * The number of modes added by calling drm_mode_probed_add().
747 */
092d01da 748 int (*get_modes)(struct drm_connector *connector);
4ee6034c
DV
749
750 /**
751 * @mode_valid:
752 *
753 * Callback to validate a mode for a connector, irrespective of the
754 * specific display configuration.
755 *
756 * This callback is used by the probe helpers to filter the mode list
757 * (which is usually derived from the EDID data block from the sink).
758 * See e.g. drm_helper_probe_single_connector_modes().
759 *
760 * NOTE:
761 *
762 * This only filters the mode list supplied to userspace in the
763 * GETCONNECOTR IOCTL. Userspace is free to create modes of its own and
764 * ask the kernel to use them. It this case the atomic helpers or legacy
765 * CRTC helpers will not call this function. Drivers therefore must
766 * still fully validate any mode passed in in a modeset request.
767 *
768 * RETURNS:
769 *
770 * Either MODE_OK or one of the failure reasons in enum
771 * &drm_mode_status.
772 */
092d01da
DV
773 enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
774 struct drm_display_mode *mode);
4ee6034c
DV
775 /**
776 * @best_encoder:
777 *
778 * This function should select the best encoder for the given connector.
779 *
780 * This function is used by both the atomic helpers (in the
781 * drm_atomic_helper_check_modeset() function) and in the legacy CRTC
782 * helpers.
783 *
784 * NOTE:
785 *
786 * In atomic drivers this function is called in the check phase of an
787 * atomic update. The driver is not allowed to change or inspect
788 * anything outside of arguments passed-in. Atomic drivers which need to
789 * inspect dynamic configuration state should instead use
790 * @atomic_best_encoder.
791 *
c61b93fe
BB
792 * You can leave this function to NULL if the connector is only
793 * attached to a single encoder and you are using the atomic helpers.
794 * In this case, the core will call drm_atomic_helper_best_encoder()
795 * for you.
796 *
4ee6034c
DV
797 * RETURNS:
798 *
799 * Encoder that should be used for the given connector and connector
800 * state, or NULL if no suitable encoder exists. Note that the helpers
801 * will ensure that encoders aren't used twice, drivers should not check
802 * for this.
803 */
092d01da 804 struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
4ee6034c
DV
805
806 /**
807 * @atomic_best_encoder:
808 *
809 * This is the atomic version of @best_encoder for atomic drivers which
810 * need to select the best encoder depending upon the desired
811 * configuration and can't select it statically.
812 *
c61b93fe
BB
813 * This function is used by drm_atomic_helper_check_modeset().
814 * If it is not implemented, the core will fallback to @best_encoder
815 * (or drm_atomic_helper_best_encoder() if @best_encoder is NULL).
4ee6034c
DV
816 *
817 * NOTE:
818 *
819 * This function is called in the check phase of an atomic update. The
820 * driver is not allowed to change anything outside of the free-standing
821 * state objects passed-in or assembled in the overall &drm_atomic_state
822 * update tracking structure.
823 *
824 * RETURNS:
825 *
826 * Encoder that should be used for the given connector and connector
827 * state, or NULL if no suitable encoder exists. Note that the helpers
828 * will ensure that encoders aren't used twice, drivers should not check
829 * for this.
830 */
092d01da
DV
831 struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,
832 struct drm_connector_state *connector_state);
833};
834
835/**
836 * drm_connector_helper_add - sets the helper vtable for a connector
837 * @connector: DRM connector
838 * @funcs: helper vtable to set for @connector
839 */
840static inline void drm_connector_helper_add(struct drm_connector *connector,
841 const struct drm_connector_helper_funcs *funcs)
842{
843 connector->helper_private = funcs;
844}
845
846/**
11a0ba97 847 * struct drm_plane_helper_funcs - helper operations for planes
092d01da 848 *
11a0ba97
DV
849 * These functions are used by the atomic helpers and by the transitional plane
850 * helpers.
092d01da
DV
851 */
852struct drm_plane_helper_funcs {
11a0ba97
DV
853 /**
854 * @prepare_fb:
855 *
856 * This hook is to prepare a framebuffer for scanout by e.g. pinning
857 * it's backing storage or relocating it into a contiguous block of
858 * VRAM. Other possible preparatory work includes flushing caches.
859 *
860 * This function must not block for outstanding rendering, since it is
861 * called in the context of the atomic IOCTL even for async commits to
862 * be able to return any errors to userspace. Instead the recommended
863 * way is to fill out the fence member of the passed-in
864 * &drm_plane_state. If the driver doesn't support native fences then
865 * equivalent functionality should be implemented through private
866 * members in the plane structure.
867 *
868 * The helpers will call @cleanup_fb with matching arguments for every
869 * successful call to this hook.
870 *
871 * This callback is used by the atomic modeset helpers and by the
872 * transitional plane helpers, but it is optional.
873 *
874 * RETURNS:
875 *
876 * 0 on success or one of the following negative error codes allowed by
877 * the atomic_commit hook in &drm_mode_config_funcs. When using helpers
878 * this callback is the only one which can fail an atomic commit,
879 * everything else must complete successfully.
880 */
092d01da 881 int (*prepare_fb)(struct drm_plane *plane,
1832040d 882 struct drm_plane_state *new_state);
11a0ba97
DV
883 /**
884 * @cleanup_fb:
885 *
886 * This hook is called to clean up any resources allocated for the given
887 * framebuffer and plane configuration in @prepare_fb.
888 *
889 * This callback is used by the atomic modeset helpers and by the
890 * transitional plane helpers, but it is optional.
891 */
092d01da 892 void (*cleanup_fb)(struct drm_plane *plane,
1832040d 893 struct drm_plane_state *old_state);
092d01da 894
11a0ba97
DV
895 /**
896 * @atomic_check:
897 *
898 * Drivers should check plane specific constraints in this hook.
899 *
900 * When using drm_atomic_helper_check_planes() plane's ->atomic_check()
901 * hooks are called before the ones for CRTCs, which allows drivers to
902 * request shared resources that the CRTC controls here. For more
903 * complicated dependencies the driver can call the provided check helpers
904 * multiple times until the computed state has a final configuration and
905 * everything has been checked.
906 *
907 * This function is also allowed to inspect any other object's state and
908 * can add more state objects to the atomic commit if needed. Care must
909 * be taken though to ensure that state check&compute functions for
910 * these added states are all called, and derived state in other objects
911 * all updated. Again the recommendation is to just call check helpers
912 * until a maximal configuration is reached.
913 *
914 * This callback is used by the atomic modeset helpers and by the
915 * transitional plane helpers, but it is optional.
916 *
917 * NOTE:
918 *
919 * This function is called in the check phase of an atomic update. The
920 * driver is not allowed to change anything outside of the free-standing
921 * state objects passed-in or assembled in the overall &drm_atomic_state
922 * update tracking structure.
923 *
924 * RETURNS:
925 *
926 * 0 on success, -EINVAL if the state or the transition can't be
927 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
928 * attempt to obtain another state object ran into a &drm_modeset_lock
929 * deadlock.
930 */
092d01da
DV
931 int (*atomic_check)(struct drm_plane *plane,
932 struct drm_plane_state *state);
11a0ba97
DV
933
934 /**
935 * @atomic_update:
936 *
937 * Drivers should use this function to update the plane state. This
938 * hook is called in-between the ->atomic_begin() and
939 * ->atomic_flush() of &drm_crtc_helper_funcs.
940 *
941 * Note that the power state of the display pipe when this function is
942 * called depends upon the exact helpers and calling sequence the driver
0dc9967d
SA
943 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
944 * the tradeoffs and variants of plane commit helpers.
11a0ba97
DV
945 *
946 * This callback is used by the atomic modeset helpers and by the
947 * transitional plane helpers, but it is optional.
948 */
092d01da
DV
949 void (*atomic_update)(struct drm_plane *plane,
950 struct drm_plane_state *old_state);
11a0ba97
DV
951 /**
952 * @atomic_disable:
953 *
954 * Drivers should use this function to unconditionally disable a plane.
955 * This hook is called in-between the ->atomic_begin() and
956 * ->atomic_flush() of &drm_crtc_helper_funcs. It is an alternative to
957 * @atomic_update, which will be called for disabling planes, too, if
958 * the @atomic_disable hook isn't implemented.
959 *
960 * This hook is also useful to disable planes in preparation of a modeset,
961 * by calling drm_atomic_helper_disable_planes_on_crtc() from the
962 * ->disable() hook in &drm_crtc_helper_funcs.
963 *
964 * Note that the power state of the display pipe when this function is
965 * called depends upon the exact helpers and calling sequence the driver
0dc9967d
SA
966 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
967 * the tradeoffs and variants of plane commit helpers.
11a0ba97
DV
968 *
969 * This callback is used by the atomic modeset helpers and by the
970 * transitional plane helpers, but it is optional.
971 */
092d01da
DV
972 void (*atomic_disable)(struct drm_plane *plane,
973 struct drm_plane_state *old_state);
974};
975
976/**
977 * drm_plane_helper_add - sets the helper vtable for a plane
978 * @plane: DRM plane
979 * @funcs: helper vtable to set for @plane
980 */
981static inline void drm_plane_helper_add(struct drm_plane *plane,
982 const struct drm_plane_helper_funcs *funcs)
983{
984 plane->helper_private = funcs;
985}
986
9f2a7950
DV
987/**
988 * struct drm_mode_config_helper_funcs - global modeset helper operations
989 *
990 * These helper functions are used by the atomic helpers.
991 */
992struct drm_mode_config_helper_funcs {
993 /**
994 * @atomic_commit_tail:
995 *
996 * This hook is used by the default atomic_commit() hook implemented in
997 * drm_atomic_helper_commit() together with the nonblocking commit
998 * helpers (see drm_atomic_helper_setup_commit() for a starting point)
999 * to implement blocking and nonblocking commits easily. It is not used
1000 * by the atomic helpers
1001 *
1ea0c02e
DV
1002 * This function is called when the new atomic state has already been
1003 * swapped into the various state pointers. The passed in state
1004 * therefore contains copies of the old/previous state. This hook should
1005 * commit the new state into hardware. Note that the helpers have
1006 * already waited for preceeding atomic commits and fences, but drivers
1007 * can add more waiting calls at the start of their implementation, e.g.
1008 * to wait for driver-internal request for implicit syncing, before
1009 * starting to commit the update to the hardware.
9f2a7950
DV
1010 *
1011 * After the atomic update is committed to the hardware this hook needs
1012 * to call drm_atomic_helper_commit_hw_done(). Then wait for the upate
1013 * to be executed by the hardware, for example using
1014 * drm_atomic_helper_wait_for_vblanks(), and then clean up the old
1015 * framebuffers using drm_atomic_helper_cleanup_planes().
1016 *
1017 * When disabling a CRTC this hook _must_ stall for the commit to
1018 * complete. Vblank waits don't work on disabled CRTC, hence the core
1019 * can't take care of this. And it also can't rely on the vblank event,
1020 * since that can be signalled already when the screen shows black,
1021 * which can happen much earlier than the last hardware access needed to
1022 * shut off the display pipeline completely.
1023 *
1024 * This hook is optional, the default implementation is
1025 * drm_atomic_helper_commit_tail().
1026 */
1027 void (*atomic_commit_tail)(struct drm_atomic_state *state);
1028};
1029
092d01da 1030#endif