blob: 625c7475c5df8015f383bc1b9689f380090ac1d5 [file] [log] [blame]
Daniel Vetter092d01d2015-12-04 09:45:44 +01001/*
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>
Laurent Pinchart93382032016-11-28 20:51:09 +020033#include <drm/drm_encoder.h>
Daniel Vetter092d01d2015-12-04 09:45:44 +010034
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
51enum mode_set_atomic;
52
53/**
54 * struct drm_crtc_helper_funcs - helper operations for CRTCs
Daniel Vetter092d01d2015-12-04 09:45:44 +010055 *
Daniel Vetter36b66082015-12-04 09:46:08 +010056 * These hooks are used by the legacy CRTC helpers, the transitional plane
57 * helpers and the new atomic modesetting helpers.
Daniel Vetter092d01d2015-12-04 09:45:44 +010058 */
59struct drm_crtc_helper_funcs {
Daniel Vetter36b66082015-12-04 09:46:08 +010060 /**
61 * @dpms:
62 *
63 * Callback to control power levels on the CRTC. If the mode passed in
64 * is unsupported, the provider must use the next lowest power level.
65 * This is used by the legacy CRTC helpers to implement DPMS
66 * functionality in drm_helper_connector_dpms().
67 *
68 * This callback is also used to disable a CRTC by calling it with
69 * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
70 *
71 * This callback is used by the legacy CRTC helpers. Atomic helpers
72 * also support using this hook for enabling and disabling a CRTC to
73 * facilitate transitions to atomic, but it is deprecated. Instead
74 * @enable and @disable should be used.
Daniel Vetter092d01d2015-12-04 09:45:44 +010075 */
76 void (*dpms)(struct drm_crtc *crtc, int mode);
Daniel Vetter36b66082015-12-04 09:46:08 +010077
78 /**
79 * @prepare:
80 *
81 * This callback should prepare the CRTC for a subsequent modeset, which
82 * in practice means the driver should disable the CRTC if it is
83 * running. Most drivers ended up implementing this by calling their
84 * @dpms hook with DRM_MODE_DPMS_OFF.
85 *
86 * This callback is used by the legacy CRTC helpers. Atomic helpers
87 * also support using this hook for disabling a CRTC to facilitate
88 * transitions to atomic, but it is deprecated. Instead @disable should
89 * be used.
90 */
Daniel Vetter092d01d2015-12-04 09:45:44 +010091 void (*prepare)(struct drm_crtc *crtc);
Daniel Vetter36b66082015-12-04 09:46:08 +010092
93 /**
94 * @commit:
95 *
96 * This callback should commit the new mode on the CRTC after a modeset,
97 * which in practice means the driver should enable the CRTC. Most
98 * drivers ended up implementing this by calling their @dpms hook with
99 * DRM_MODE_DPMS_ON.
100 *
101 * This callback is used by the legacy CRTC helpers. Atomic helpers
102 * also support using this hook for enabling a CRTC to facilitate
103 * transitions to atomic, but it is deprecated. Instead @enable should
104 * be used.
105 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100106 void (*commit)(struct drm_crtc *crtc);
107
Daniel Vetter36b66082015-12-04 09:46:08 +0100108 /**
109 * @mode_fixup:
110 *
111 * This callback is used to validate a mode. The parameter mode is the
112 * display mode that userspace requested, adjusted_mode is the mode the
113 * encoders need to be fed with. Note that this is the inverse semantics
114 * of the meaning for the &drm_encoder and &drm_bridge
115 * ->mode_fixup() functions. If the CRTC cannot support the requested
116 * conversion from mode to adjusted_mode it should reject the modeset.
117 *
118 * This function is used by both legacy CRTC helpers and atomic helpers.
119 * With atomic helpers it is optional.
120 *
121 * NOTE:
122 *
123 * This function is called in the check phase of atomic modesets, which
124 * can be aborted for any reason (including on userspace's request to
125 * just check whether a configuration would be possible). Atomic drivers
126 * MUST NOT touch any persistent state (hardware or software) or data
127 * structures except the passed in adjusted_mode parameter.
128 *
129 * This is in contrast to the legacy CRTC helpers where this was
130 * allowed.
131 *
132 * Atomic drivers which need to inspect and adjust more state should
133 * instead use the @atomic_check callback.
134 *
Daniel Vetterdf7d6782016-01-04 07:53:36 +0100135 * Also beware that neither core nor helpers filter modes before
136 * passing them to the driver: While the list of modes that is
137 * advertised to userspace is filtered using the connector's
138 * ->mode_valid() callback, neither the core nor the helpers do any
139 * filtering on modes passed in from userspace when setting a mode. It
140 * is therefore possible for userspace to pass in a mode that was
141 * previously filtered out using ->mode_valid() or add a custom mode
142 * that wasn't probed from EDID or similar to begin with. Even though
143 * this is an advanced feature and rarely used nowadays, some users rely
144 * on being able to specify modes manually so drivers must be prepared
145 * to deal with it. Specifically this means that all drivers need not
146 * only validate modes in ->mode_valid() but also in ->mode_fixup() to
147 * make sure invalid modes passed in from userspace are rejected.
148 *
Daniel Vetter36b66082015-12-04 09:46:08 +0100149 * RETURNS:
150 *
151 * True if an acceptable configuration is possible, false if the modeset
152 * operation should be rejected.
153 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100154 bool (*mode_fixup)(struct drm_crtc *crtc,
155 const struct drm_display_mode *mode,
156 struct drm_display_mode *adjusted_mode);
Daniel Vetter36b66082015-12-04 09:46:08 +0100157
158 /**
159 * @mode_set:
160 *
161 * This callback is used by the legacy CRTC helpers to set a new mode,
162 * position and framebuffer. Since it ties the primary plane to every
163 * mode change it is incompatible with universal plane support. And
164 * since it can't update other planes it's incompatible with atomic
165 * modeset support.
166 *
167 * This callback is only used by CRTC helpers and deprecated.
168 *
169 * RETURNS:
170 *
171 * 0 on success or a negative error code on failure.
172 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100173 int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
174 struct drm_display_mode *adjusted_mode, int x, int y,
175 struct drm_framebuffer *old_fb);
Daniel Vetter36b66082015-12-04 09:46:08 +0100176
177 /**
178 * @mode_set_nofb:
179 *
180 * This callback is used to update the display mode of a CRTC without
181 * changing anything of the primary plane configuration. This fits the
182 * requirement of atomic and hence is used by the atomic helpers. It is
183 * also used by the transitional plane helpers to implement a
184 * @mode_set hook in drm_helper_crtc_mode_set().
185 *
186 * Note that the display pipe is completely off when this function is
187 * called. Atomic drivers which need hardware to be running before they
188 * program the new display mode (e.g. because they implement runtime PM)
189 * should not use this hook. This is because the helper library calls
190 * this hook only once per mode change and not every time the display
191 * pipeline is suspended using either DPMS or the new "ACTIVE" property.
192 * Which means register values set in this callback might get reset when
193 * the CRTC is suspended, but not restored. Such drivers should instead
194 * move all their CRTC setup into the @enable callback.
195 *
196 * This callback is optional.
197 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100198 void (*mode_set_nofb)(struct drm_crtc *crtc);
199
Daniel Vetter36b66082015-12-04 09:46:08 +0100200 /**
201 * @mode_set_base:
202 *
203 * This callback is used by the legacy CRTC helpers to set a new
204 * framebuffer and scanout position. It is optional and used as an
205 * optimized fast-path instead of a full mode set operation with all the
Daniel Vetterdf7d6782016-01-04 07:53:36 +0100206 * resulting flickering. If it is not present
207 * drm_crtc_helper_set_config() will fall back to a full modeset, using
208 * the ->mode_set() callback. Since it can't update other planes it's
Daniel Vetter36b66082015-12-04 09:46:08 +0100209 * incompatible with atomic modeset support.
210 *
211 * This callback is only used by the CRTC helpers and deprecated.
212 *
213 * RETURNS:
214 *
215 * 0 on success or a negative error code on failure.
216 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100217 int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
218 struct drm_framebuffer *old_fb);
Daniel Vetter36b66082015-12-04 09:46:08 +0100219
220 /**
221 * @mode_set_base_atomic:
222 *
223 * This callback is used by the fbdev helpers to set a new framebuffer
224 * and scanout without sleeping, i.e. from an atomic calling context. It
225 * is only used to implement kgdb support.
226 *
227 * This callback is optional and only needed for kgdb support in the fbdev
228 * helpers.
229 *
230 * RETURNS:
231 *
232 * 0 on success or a negative error code on failure.
233 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100234 int (*mode_set_base_atomic)(struct drm_crtc *crtc,
235 struct drm_framebuffer *fb, int x, int y,
236 enum mode_set_atomic);
237
Daniel Vetter36b66082015-12-04 09:46:08 +0100238 /**
239 * @load_lut:
240 *
241 * Load a LUT prepared with the @gamma_set functions from
242 * &drm_fb_helper_funcs.
243 *
244 * This callback is optional and is only used by the fbdev emulation
245 * helpers.
246 *
247 * FIXME:
248 *
249 * This callback is functionally redundant with the core gamma table
250 * support and simply exists because the fbdev hasn't yet been
251 * refactored to use the core gamma table interfaces.
252 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100253 void (*load_lut)(struct drm_crtc *crtc);
254
Daniel Vetter36b66082015-12-04 09:46:08 +0100255 /**
256 * @disable:
257 *
258 * This callback should be used to disable the CRTC. With the atomic
259 * drivers it is called after all encoders connected to this CRTC have
260 * been shut off already using their own ->disable hook. If that
261 * sequence is too simple drivers can just add their own hooks and call
262 * it from this CRTC callback here by looping over all encoders
263 * connected to it using for_each_encoder_on_crtc().
264 *
265 * This hook is used both by legacy CRTC helpers and atomic helpers.
266 * Atomic drivers don't need to implement it if there's no need to
267 * disable anything at the CRTC level. To ensure that runtime PM
268 * handling (using either DPMS or the new "ACTIVE" property) works
269 * @disable must be the inverse of @enable for atomic drivers.
Liu Yingc9ac8b42016-08-26 15:30:38 +0800270 * Atomic drivers should consider to use @atomic_disable instead of
271 * this one.
Daniel Vetter36b66082015-12-04 09:46:08 +0100272 *
273 * NOTE:
274 *
275 * With legacy CRTC helpers there's a big semantic difference between
276 * @disable and other hooks (like @prepare or @dpms) used to shut down a
277 * CRTC: @disable is only called when also logically disabling the
278 * display pipeline and needs to release any resources acquired in
279 * @mode_set (like shared PLLs, or again release pinned framebuffers).
280 *
281 * Therefore @disable must be the inverse of @mode_set plus @commit for
282 * drivers still using legacy CRTC helpers, which is different from the
283 * rules under atomic.
284 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100285 void (*disable)(struct drm_crtc *crtc);
Daniel Vetter36b66082015-12-04 09:46:08 +0100286
287 /**
288 * @enable:
289 *
290 * This callback should be used to enable the CRTC. With the atomic
291 * drivers it is called before all encoders connected to this CRTC are
292 * enabled through the encoder's own ->enable hook. If that sequence is
293 * too simple drivers can just add their own hooks and call it from this
294 * CRTC callback here by looping over all encoders connected to it using
295 * for_each_encoder_on_crtc().
296 *
297 * This hook is used only by atomic helpers, for symmetry with @disable.
298 * Atomic drivers don't need to implement it if there's no need to
299 * enable anything at the CRTC level. To ensure that runtime PM handling
300 * (using either DPMS or the new "ACTIVE" property) works
301 * @enable must be the inverse of @disable for atomic drivers.
302 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100303 void (*enable)(struct drm_crtc *crtc);
304
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100305 /**
306 * @atomic_check:
307 *
308 * Drivers should check plane-update related CRTC constraints in this
309 * hook. They can also check mode related limitations but need to be
310 * aware of the calling order, since this hook is used by
311 * drm_atomic_helper_check_planes() whereas the preparations needed to
312 * check output routing and the display mode is done in
313 * drm_atomic_helper_check_modeset(). Therefore drivers that want to
314 * check output routing and display mode constraints in this callback
315 * must ensure that drm_atomic_helper_check_modeset() has been called
316 * beforehand. This is calling order used by the default helper
317 * implementation in drm_atomic_helper_check().
318 *
319 * When using drm_atomic_helper_check_planes() CRTCs' ->atomic_check()
320 * hooks are called after the ones for planes, which allows drivers to
321 * assign shared resources requested by planes in the CRTC callback
322 * here. For more complicated dependencies the driver can call the provided
323 * check helpers multiple times until the computed state has a final
324 * configuration and everything has been checked.
325 *
326 * This function is also allowed to inspect any other object's state and
327 * can add more state objects to the atomic commit if needed. Care must
328 * be taken though to ensure that state check&compute functions for
329 * these added states are all called, and derived state in other objects
330 * all updated. Again the recommendation is to just call check helpers
331 * until a maximal configuration is reached.
332 *
333 * This callback is used by the atomic modeset helpers and by the
334 * transitional plane helpers, but it is optional.
335 *
336 * NOTE:
337 *
338 * This function is called in the check phase of an atomic update. The
339 * driver is not allowed to change anything outside of the free-standing
340 * state objects passed-in or assembled in the overall &drm_atomic_state
341 * update tracking structure.
342 *
343 * RETURNS:
344 *
345 * 0 on success, -EINVAL if the state or the transition can't be
346 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
347 * attempt to obtain another state object ran into a &drm_modeset_lock
348 * deadlock.
349 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100350 int (*atomic_check)(struct drm_crtc *crtc,
351 struct drm_crtc_state *state);
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100352
353 /**
354 * @atomic_begin:
355 *
356 * Drivers should prepare for an atomic update of multiple planes on
357 * a CRTC in this hook. Depending upon hardware this might be vblank
358 * evasion, blocking updates by setting bits or doing preparatory work
359 * for e.g. manual update display.
360 *
361 * This hook is called before any plane commit functions are called.
362 *
363 * Note that the power state of the display pipe when this function is
364 * called depends upon the exact helpers and calling sequence the driver
Stefan Agner0dc99672016-10-31 10:36:46 -0700365 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
366 * the tradeoffs and variants of plane commit helpers.
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100367 *
368 * This callback is used by the atomic modeset helpers and by the
369 * transitional plane helpers, but it is optional.
370 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100371 void (*atomic_begin)(struct drm_crtc *crtc,
372 struct drm_crtc_state *old_crtc_state);
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100373 /**
374 * @atomic_flush:
375 *
376 * Drivers should finalize an atomic update of multiple planes on
377 * a CRTC in this hook. Depending upon hardware this might include
378 * checking that vblank evasion was successful, unblocking updates by
379 * setting bits or setting the GO bit to flush out all updates.
380 *
381 * Simple hardware or hardware with special requirements can commit and
382 * flush out all updates for all planes from this hook and forgo all the
383 * other commit hooks for plane updates.
384 *
385 * This hook is called after any plane commit functions are called.
386 *
387 * Note that the power state of the display pipe when this function is
388 * called depends upon the exact helpers and calling sequence the driver
Stefan Agner0dc99672016-10-31 10:36:46 -0700389 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
390 * the tradeoffs and variants of plane commit helpers.
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100391 *
392 * This callback is used by the atomic modeset helpers and by the
393 * transitional plane helpers, but it is optional.
394 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100395 void (*atomic_flush)(struct drm_crtc *crtc,
396 struct drm_crtc_state *old_crtc_state);
Liu Yingc9ac8b42016-08-26 15:30:38 +0800397
398 /**
399 * @atomic_disable:
400 *
401 * This callback should be used to disable the CRTC. With the atomic
402 * drivers it is called after all encoders connected to this CRTC have
403 * been shut off already using their own ->disable hook. If that
404 * sequence is too simple drivers can just add their own hooks and call
405 * it from this CRTC callback here by looping over all encoders
406 * connected to it using for_each_encoder_on_crtc().
407 *
408 * This hook is used only by atomic helpers. Atomic drivers don't
409 * need to implement it if there's no need to disable anything at the
410 * CRTC level.
411 *
412 * Comparing to @disable, this one provides the additional input
413 * parameter @old_crtc_state which could be used to access the old
414 * state. Atomic drivers should consider to use this one instead
415 * of @disable.
416 */
417 void (*atomic_disable)(struct drm_crtc *crtc,
418 struct drm_crtc_state *old_crtc_state);
Daniel Vetter092d01d2015-12-04 09:45:44 +0100419};
420
421/**
422 * drm_crtc_helper_add - sets the helper vtable for a crtc
423 * @crtc: DRM CRTC
424 * @funcs: helper vtable to set for @crtc
425 */
426static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
427 const struct drm_crtc_helper_funcs *funcs)
428{
429 crtc->helper_private = funcs;
430}
431
432/**
433 * struct drm_encoder_helper_funcs - helper operations for encoders
Daniel Vetter092d01d2015-12-04 09:45:44 +0100434 *
Daniel Vetter36b66082015-12-04 09:46:08 +0100435 * These hooks are used by the legacy CRTC helpers, the transitional plane
436 * helpers and the new atomic modesetting helpers.
Daniel Vetter092d01d2015-12-04 09:45:44 +0100437 */
438struct drm_encoder_helper_funcs {
Daniel Vetter36b66082015-12-04 09:46:08 +0100439 /**
440 * @dpms:
441 *
442 * Callback to control power levels on the encoder. If the mode passed in
443 * is unsupported, the provider must use the next lowest power level.
444 * This is used by the legacy encoder helpers to implement DPMS
445 * functionality in drm_helper_connector_dpms().
446 *
447 * This callback is also used to disable an encoder by calling it with
448 * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
449 *
450 * This callback is used by the legacy CRTC helpers. Atomic helpers
451 * also support using this hook for enabling and disabling an encoder to
452 * facilitate transitions to atomic, but it is deprecated. Instead
453 * @enable and @disable should be used.
454 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100455 void (*dpms)(struct drm_encoder *encoder, int mode);
Daniel Vetter092d01d2015-12-04 09:45:44 +0100456
Daniel Vetter36b66082015-12-04 09:46:08 +0100457 /**
458 * @mode_fixup:
459 *
460 * This callback is used to validate and adjust a mode. The parameter
461 * mode is the display mode that should be fed to the next element in
462 * the display chain, either the final &drm_connector or a &drm_bridge.
463 * The parameter adjusted_mode is the input mode the encoder requires. It
464 * can be modified by this callback and does not need to match mode.
465 *
466 * This function is used by both legacy CRTC helpers and atomic helpers.
Carlos Palminha3c5b2672016-02-10 12:15:22 +0000467 * This hook is optional.
Daniel Vetter36b66082015-12-04 09:46:08 +0100468 *
469 * NOTE:
470 *
471 * This function is called in the check phase of atomic modesets, which
472 * can be aborted for any reason (including on userspace's request to
473 * just check whether a configuration would be possible). Atomic drivers
474 * MUST NOT touch any persistent state (hardware or software) or data
475 * structures except the passed in adjusted_mode parameter.
476 *
477 * This is in contrast to the legacy CRTC helpers where this was
478 * allowed.
479 *
480 * Atomic drivers which need to inspect and adjust more state should
481 * instead use the @atomic_check callback.
482 *
Daniel Vetterdf7d6782016-01-04 07:53:36 +0100483 * Also beware that neither core nor helpers filter modes before
484 * passing them to the driver: While the list of modes that is
485 * advertised to userspace is filtered using the connector's
486 * ->mode_valid() callback, neither the core nor the helpers do any
487 * filtering on modes passed in from userspace when setting a mode. It
488 * is therefore possible for userspace to pass in a mode that was
489 * previously filtered out using ->mode_valid() or add a custom mode
490 * that wasn't probed from EDID or similar to begin with. Even though
491 * this is an advanced feature and rarely used nowadays, some users rely
492 * on being able to specify modes manually so drivers must be prepared
493 * to deal with it. Specifically this means that all drivers need not
494 * only validate modes in ->mode_valid() but also in ->mode_fixup() to
495 * make sure invalid modes passed in from userspace are rejected.
496 *
Daniel Vetter36b66082015-12-04 09:46:08 +0100497 * RETURNS:
498 *
499 * True if an acceptable configuration is possible, false if the modeset
500 * operation should be rejected.
501 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100502 bool (*mode_fixup)(struct drm_encoder *encoder,
503 const struct drm_display_mode *mode,
504 struct drm_display_mode *adjusted_mode);
Daniel Vetter36b66082015-12-04 09:46:08 +0100505
506 /**
507 * @prepare:
508 *
509 * This callback should prepare the encoder for a subsequent modeset,
510 * which in practice means the driver should disable the encoder if it
511 * is running. Most drivers ended up implementing this by calling their
512 * @dpms hook with DRM_MODE_DPMS_OFF.
513 *
514 * This callback is used by the legacy CRTC helpers. Atomic helpers
515 * also support using this hook for disabling an encoder to facilitate
516 * transitions to atomic, but it is deprecated. Instead @disable should
517 * be used.
518 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100519 void (*prepare)(struct drm_encoder *encoder);
Daniel Vetter36b66082015-12-04 09:46:08 +0100520
521 /**
522 * @commit:
523 *
524 * This callback should commit the new mode on the encoder after a modeset,
525 * which in practice means the driver should enable the encoder. Most
526 * drivers ended up implementing this by calling their @dpms hook with
527 * DRM_MODE_DPMS_ON.
528 *
529 * This callback is used by the legacy CRTC helpers. Atomic helpers
530 * also support using this hook for enabling an encoder to facilitate
531 * transitions to atomic, but it is deprecated. Instead @enable should
532 * be used.
533 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100534 void (*commit)(struct drm_encoder *encoder);
Daniel Vetter36b66082015-12-04 09:46:08 +0100535
536 /**
537 * @mode_set:
538 *
539 * This callback is used to update the display mode of an encoder.
540 *
541 * Note that the display pipe is completely off when this function is
542 * called. Drivers which need hardware to be running before they program
543 * the new display mode (because they implement runtime PM) should not
544 * use this hook, because the helper library calls it only once and not
545 * every time the display pipeline is suspend using either DPMS or the
546 * new "ACTIVE" property. Such drivers should instead move all their
547 * encoder setup into the ->enable() callback.
548 *
549 * This callback is used both by the legacy CRTC helpers and the atomic
550 * modeset helpers. It is optional in the atomic helpers.
Philipp Zabelfe4a11c2016-07-22 12:20:47 +0200551 *
552 * NOTE:
553 *
554 * If the driver uses the atomic modeset helpers and needs to inspect
555 * the connector state or connector display info during mode setting,
556 * @atomic_mode_set can be used instead.
Daniel Vetter36b66082015-12-04 09:46:08 +0100557 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100558 void (*mode_set)(struct drm_encoder *encoder,
559 struct drm_display_mode *mode,
560 struct drm_display_mode *adjusted_mode);
Daniel Vetter36b66082015-12-04 09:46:08 +0100561
562 /**
Philipp Zabelfe4a11c2016-07-22 12:20:47 +0200563 * @atomic_mode_set:
564 *
565 * This callback is used to update the display mode of an encoder.
566 *
567 * Note that the display pipe is completely off when this function is
568 * called. Drivers which need hardware to be running before they program
569 * the new display mode (because they implement runtime PM) should not
570 * use this hook, because the helper library calls it only once and not
571 * every time the display pipeline is suspended using either DPMS or the
572 * new "ACTIVE" property. Such drivers should instead move all their
573 * encoder setup into the ->enable() callback.
574 *
575 * This callback is used by the atomic modeset helpers in place of the
576 * @mode_set callback, if set by the driver. It is optional and should
577 * be used instead of @mode_set if the driver needs to inspect the
578 * connector state or display info, since there is no direct way to
579 * go from the encoder to the current connector.
580 */
581 void (*atomic_mode_set)(struct drm_encoder *encoder,
582 struct drm_crtc_state *crtc_state,
583 struct drm_connector_state *conn_state);
584
585 /**
Daniel Vetter36b66082015-12-04 09:46:08 +0100586 * @get_crtc:
587 *
588 * This callback is used by the legacy CRTC helpers to work around
589 * deficiencies in its own book-keeping.
590 *
591 * Do not use, use atomic helpers instead, which get the book keeping
592 * right.
593 *
594 * FIXME:
595 *
596 * Currently only nouveau is using this, and as soon as nouveau is
597 * atomic we can ditch this hook.
598 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100599 struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder);
Daniel Vetter36b66082015-12-04 09:46:08 +0100600
601 /**
602 * @detect:
603 *
604 * This callback can be used by drivers who want to do detection on the
605 * encoder object instead of in connector functions.
606 *
607 * It is not used by any helper and therefore has purely driver-specific
608 * semantics. New drivers shouldn't use this and instead just implement
609 * their own private callbacks.
610 *
611 * FIXME:
612 *
613 * This should just be converted into a pile of driver vfuncs.
614 * Currently radeon, amdgpu and nouveau are using it.
615 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100616 enum drm_connector_status (*detect)(struct drm_encoder *encoder,
617 struct drm_connector *connector);
Daniel Vetter36b66082015-12-04 09:46:08 +0100618
619 /**
620 * @disable:
621 *
622 * This callback should be used to disable the encoder. With the atomic
623 * drivers it is called before this encoder's CRTC has been shut off
624 * using the CRTC's own ->disable hook. If that sequence is too simple
625 * drivers can just add their own driver private encoder hooks and call
626 * them from CRTC's callback by looping over all encoders connected to
627 * it using for_each_encoder_on_crtc().
628 *
629 * This hook is used both by legacy CRTC helpers and atomic helpers.
630 * Atomic drivers don't need to implement it if there's no need to
631 * disable anything at the encoder level. To ensure that runtime PM
632 * handling (using either DPMS or the new "ACTIVE" property) works
633 * @disable must be the inverse of @enable for atomic drivers.
634 *
635 * NOTE:
636 *
637 * With legacy CRTC helpers there's a big semantic difference between
638 * @disable and other hooks (like @prepare or @dpms) used to shut down a
639 * encoder: @disable is only called when also logically disabling the
640 * display pipeline and needs to release any resources acquired in
641 * @mode_set (like shared PLLs, or again release pinned framebuffers).
642 *
643 * Therefore @disable must be the inverse of @mode_set plus @commit for
644 * drivers still using legacy CRTC helpers, which is different from the
645 * rules under atomic.
646 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100647 void (*disable)(struct drm_encoder *encoder);
648
Daniel Vetter36b66082015-12-04 09:46:08 +0100649 /**
650 * @enable:
651 *
652 * This callback should be used to enable the encoder. With the atomic
653 * drivers it is called after this encoder's CRTC has been enabled using
654 * the CRTC's own ->enable hook. If that sequence is too simple drivers
655 * can just add their own driver private encoder hooks and call them
656 * from CRTC's callback by looping over all encoders connected to it
657 * using for_each_encoder_on_crtc().
658 *
659 * This hook is used only by atomic helpers, for symmetry with @disable.
660 * Atomic drivers don't need to implement it if there's no need to
661 * enable anything at the encoder level. To ensure that runtime PM handling
662 * (using either DPMS or the new "ACTIVE" property) works
663 * @enable must be the inverse of @disable for atomic drivers.
664 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100665 void (*enable)(struct drm_encoder *encoder);
666
Daniel Vetter36b66082015-12-04 09:46:08 +0100667 /**
668 * @atomic_check:
669 *
670 * This callback is used to validate encoder state for atomic drivers.
671 * Since the encoder is the object connecting the CRTC and connector it
672 * gets passed both states, to be able to validate interactions and
673 * update the CRTC to match what the encoder needs for the requested
674 * connector.
675 *
676 * This function is used by the atomic helpers, but it is optional.
677 *
678 * NOTE:
679 *
680 * This function is called in the check phase of an atomic update. The
681 * driver is not allowed to change anything outside of the free-standing
682 * state objects passed-in or assembled in the overall &drm_atomic_state
683 * update tracking structure.
684 *
685 * RETURNS:
686 *
687 * 0 on success, -EINVAL if the state or the transition can't be
688 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
689 * attempt to obtain another state object ran into a &drm_modeset_lock
690 * deadlock.
691 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100692 int (*atomic_check)(struct drm_encoder *encoder,
693 struct drm_crtc_state *crtc_state,
694 struct drm_connector_state *conn_state);
695};
696
697/**
Daniel Vetter36b66082015-12-04 09:46:08 +0100698 * drm_encoder_helper_add - sets the helper vtable for an encoder
Daniel Vetter092d01d2015-12-04 09:45:44 +0100699 * @encoder: DRM encoder
700 * @funcs: helper vtable to set for @encoder
701 */
702static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
703 const struct drm_encoder_helper_funcs *funcs)
704{
705 encoder->helper_private = funcs;
706}
707
708/**
709 * struct drm_connector_helper_funcs - helper operations for connectors
Daniel Vetter092d01d2015-12-04 09:45:44 +0100710 *
Daniel Vetter4ee60342015-12-04 09:46:05 +0100711 * These functions are used by the atomic and legacy modeset helpers and by the
712 * probe helpers.
Daniel Vetter092d01d2015-12-04 09:45:44 +0100713 */
714struct drm_connector_helper_funcs {
Daniel Vetter4ee60342015-12-04 09:46:05 +0100715 /**
716 * @get_modes:
717 *
718 * This function should fill in all modes currently valid for the sink
719 * into the connector->probed_modes list. It should also update the
720 * EDID property by calling drm_mode_connector_update_edid_property().
721 *
722 * The usual way to implement this is to cache the EDID retrieved in the
723 * probe callback somewhere in the driver-private connector structure.
724 * In this function drivers then parse the modes in the EDID and add
725 * them by calling drm_add_edid_modes(). But connectors that driver a
726 * fixed panel can also manually add specific modes using
Daniel Vetterdf7d6782016-01-04 07:53:36 +0100727 * drm_mode_probed_add(). Drivers which manually add modes should also
728 * make sure that the @display_info, @width_mm and @height_mm fields of the
Daniel Vetter0e1a4852016-05-04 15:42:07 +0200729 * struct &drm_connector are filled in.
Daniel Vetterdf7d6782016-01-04 07:53:36 +0100730 *
731 * Virtual drivers that just want some standard VESA mode with a given
732 * resolution can call drm_add_modes_noedid(), and mark the preferred
733 * one using drm_set_preferred_mode().
734 *
735 * Finally drivers that support audio probably want to update the ELD
736 * data, too, using drm_edid_to_eld().
Daniel Vetter4ee60342015-12-04 09:46:05 +0100737 *
738 * This function is only called after the ->detect() hook has indicated
739 * that a sink is connected and when the EDID isn't overridden through
740 * sysfs or the kernel commandline.
741 *
742 * This callback is used by the probe helpers in e.g.
743 * drm_helper_probe_single_connector_modes().
744 *
745 * RETURNS:
746 *
747 * The number of modes added by calling drm_mode_probed_add().
748 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100749 int (*get_modes)(struct drm_connector *connector);
Daniel Vetter4ee60342015-12-04 09:46:05 +0100750
751 /**
752 * @mode_valid:
753 *
754 * Callback to validate a mode for a connector, irrespective of the
755 * specific display configuration.
756 *
757 * This callback is used by the probe helpers to filter the mode list
758 * (which is usually derived from the EDID data block from the sink).
759 * See e.g. drm_helper_probe_single_connector_modes().
760 *
761 * NOTE:
762 *
763 * This only filters the mode list supplied to userspace in the
764 * GETCONNECOTR IOCTL. Userspace is free to create modes of its own and
765 * ask the kernel to use them. It this case the atomic helpers or legacy
766 * CRTC helpers will not call this function. Drivers therefore must
767 * still fully validate any mode passed in in a modeset request.
768 *
769 * RETURNS:
770 *
771 * Either MODE_OK or one of the failure reasons in enum
772 * &drm_mode_status.
773 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100774 enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
775 struct drm_display_mode *mode);
Daniel Vetter4ee60342015-12-04 09:46:05 +0100776 /**
777 * @best_encoder:
778 *
779 * This function should select the best encoder for the given connector.
780 *
781 * This function is used by both the atomic helpers (in the
782 * drm_atomic_helper_check_modeset() function) and in the legacy CRTC
783 * helpers.
784 *
785 * NOTE:
786 *
787 * In atomic drivers this function is called in the check phase of an
788 * atomic update. The driver is not allowed to change or inspect
789 * anything outside of arguments passed-in. Atomic drivers which need to
790 * inspect dynamic configuration state should instead use
791 * @atomic_best_encoder.
792 *
Boris Brezillonc61b93f2016-06-07 13:47:56 +0200793 * You can leave this function to NULL if the connector is only
794 * attached to a single encoder and you are using the atomic helpers.
795 * In this case, the core will call drm_atomic_helper_best_encoder()
796 * for you.
797 *
Daniel Vetter4ee60342015-12-04 09:46:05 +0100798 * RETURNS:
799 *
800 * Encoder that should be used for the given connector and connector
801 * state, or NULL if no suitable encoder exists. Note that the helpers
802 * will ensure that encoders aren't used twice, drivers should not check
803 * for this.
804 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100805 struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
Daniel Vetter4ee60342015-12-04 09:46:05 +0100806
807 /**
808 * @atomic_best_encoder:
809 *
810 * This is the atomic version of @best_encoder for atomic drivers which
811 * need to select the best encoder depending upon the desired
812 * configuration and can't select it statically.
813 *
Boris Brezillonc61b93f2016-06-07 13:47:56 +0200814 * This function is used by drm_atomic_helper_check_modeset().
815 * If it is not implemented, the core will fallback to @best_encoder
816 * (or drm_atomic_helper_best_encoder() if @best_encoder is NULL).
Daniel Vetter4ee60342015-12-04 09:46:05 +0100817 *
818 * NOTE:
819 *
820 * This function is called in the check phase of an atomic update. The
821 * driver is not allowed to change anything outside of the free-standing
822 * state objects passed-in or assembled in the overall &drm_atomic_state
823 * update tracking structure.
824 *
825 * RETURNS:
826 *
827 * Encoder that should be used for the given connector and connector
828 * state, or NULL if no suitable encoder exists. Note that the helpers
829 * will ensure that encoders aren't used twice, drivers should not check
830 * for this.
831 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100832 struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,
833 struct drm_connector_state *connector_state);
834};
835
836/**
837 * drm_connector_helper_add - sets the helper vtable for a connector
838 * @connector: DRM connector
839 * @funcs: helper vtable to set for @connector
840 */
841static inline void drm_connector_helper_add(struct drm_connector *connector,
842 const struct drm_connector_helper_funcs *funcs)
843{
844 connector->helper_private = funcs;
845}
846
847/**
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100848 * struct drm_plane_helper_funcs - helper operations for planes
Daniel Vetter092d01d2015-12-04 09:45:44 +0100849 *
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100850 * These functions are used by the atomic helpers and by the transitional plane
851 * helpers.
Daniel Vetter092d01d2015-12-04 09:45:44 +0100852 */
853struct drm_plane_helper_funcs {
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100854 /**
855 * @prepare_fb:
856 *
857 * This hook is to prepare a framebuffer for scanout by e.g. pinning
858 * it's backing storage or relocating it into a contiguous block of
859 * VRAM. Other possible preparatory work includes flushing caches.
860 *
861 * This function must not block for outstanding rendering, since it is
862 * called in the context of the atomic IOCTL even for async commits to
863 * be able to return any errors to userspace. Instead the recommended
864 * way is to fill out the fence member of the passed-in
865 * &drm_plane_state. If the driver doesn't support native fences then
866 * equivalent functionality should be implemented through private
867 * members in the plane structure.
868 *
869 * The helpers will call @cleanup_fb with matching arguments for every
870 * successful call to this hook.
871 *
872 * This callback is used by the atomic modeset helpers and by the
873 * transitional plane helpers, but it is optional.
874 *
875 * RETURNS:
876 *
877 * 0 on success or one of the following negative error codes allowed by
878 * the atomic_commit hook in &drm_mode_config_funcs. When using helpers
879 * this callback is the only one which can fail an atomic commit,
880 * everything else must complete successfully.
881 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100882 int (*prepare_fb)(struct drm_plane *plane,
Chris Wilson18320402016-08-18 19:00:16 +0100883 struct drm_plane_state *new_state);
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100884 /**
885 * @cleanup_fb:
886 *
887 * This hook is called to clean up any resources allocated for the given
888 * framebuffer and plane configuration in @prepare_fb.
889 *
890 * This callback is used by the atomic modeset helpers and by the
891 * transitional plane helpers, but it is optional.
892 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100893 void (*cleanup_fb)(struct drm_plane *plane,
Chris Wilson18320402016-08-18 19:00:16 +0100894 struct drm_plane_state *old_state);
Daniel Vetter092d01d2015-12-04 09:45:44 +0100895
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100896 /**
897 * @atomic_check:
898 *
899 * Drivers should check plane specific constraints in this hook.
900 *
901 * When using drm_atomic_helper_check_planes() plane's ->atomic_check()
902 * hooks are called before the ones for CRTCs, which allows drivers to
903 * request shared resources that the CRTC controls here. For more
904 * complicated dependencies the driver can call the provided check helpers
905 * multiple times until the computed state has a final configuration and
906 * everything has been checked.
907 *
908 * This function is also allowed to inspect any other object's state and
909 * can add more state objects to the atomic commit if needed. Care must
910 * be taken though to ensure that state check&compute functions for
911 * these added states are all called, and derived state in other objects
912 * all updated. Again the recommendation is to just call check helpers
913 * until a maximal configuration is reached.
914 *
915 * This callback is used by the atomic modeset helpers and by the
916 * transitional plane helpers, but it is optional.
917 *
918 * NOTE:
919 *
920 * This function is called in the check phase of an atomic update. The
921 * driver is not allowed to change anything outside of the free-standing
922 * state objects passed-in or assembled in the overall &drm_atomic_state
923 * update tracking structure.
924 *
925 * RETURNS:
926 *
927 * 0 on success, -EINVAL if the state or the transition can't be
928 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
929 * attempt to obtain another state object ran into a &drm_modeset_lock
930 * deadlock.
931 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100932 int (*atomic_check)(struct drm_plane *plane,
933 struct drm_plane_state *state);
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100934
935 /**
936 * @atomic_update:
937 *
938 * Drivers should use this function to update the plane state. This
939 * hook is called in-between the ->atomic_begin() and
940 * ->atomic_flush() of &drm_crtc_helper_funcs.
941 *
942 * Note that the power state of the display pipe when this function is
943 * called depends upon the exact helpers and calling sequence the driver
Stefan Agner0dc99672016-10-31 10:36:46 -0700944 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
945 * the tradeoffs and variants of plane commit helpers.
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100946 *
947 * This callback is used by the atomic modeset helpers and by the
948 * transitional plane helpers, but it is optional.
949 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100950 void (*atomic_update)(struct drm_plane *plane,
951 struct drm_plane_state *old_state);
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100952 /**
953 * @atomic_disable:
954 *
955 * Drivers should use this function to unconditionally disable a plane.
956 * This hook is called in-between the ->atomic_begin() and
957 * ->atomic_flush() of &drm_crtc_helper_funcs. It is an alternative to
958 * @atomic_update, which will be called for disabling planes, too, if
959 * the @atomic_disable hook isn't implemented.
960 *
961 * This hook is also useful to disable planes in preparation of a modeset,
962 * by calling drm_atomic_helper_disable_planes_on_crtc() from the
963 * ->disable() hook in &drm_crtc_helper_funcs.
964 *
965 * Note that the power state of the display pipe when this function is
966 * called depends upon the exact helpers and calling sequence the driver
Stefan Agner0dc99672016-10-31 10:36:46 -0700967 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
968 * the tradeoffs and variants of plane commit helpers.
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100969 *
970 * This callback is used by the atomic modeset helpers and by the
971 * transitional plane helpers, but it is optional.
972 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100973 void (*atomic_disable)(struct drm_plane *plane,
974 struct drm_plane_state *old_state);
975};
976
977/**
978 * drm_plane_helper_add - sets the helper vtable for a plane
979 * @plane: DRM plane
980 * @funcs: helper vtable to set for @plane
981 */
982static inline void drm_plane_helper_add(struct drm_plane *plane,
983 const struct drm_plane_helper_funcs *funcs)
984{
985 plane->helper_private = funcs;
986}
987
Daniel Vetter9f2a7952016-06-08 14:19:02 +0200988/**
989 * struct drm_mode_config_helper_funcs - global modeset helper operations
990 *
991 * These helper functions are used by the atomic helpers.
992 */
993struct drm_mode_config_helper_funcs {
994 /**
995 * @atomic_commit_tail:
996 *
997 * This hook is used by the default atomic_commit() hook implemented in
998 * drm_atomic_helper_commit() together with the nonblocking commit
999 * helpers (see drm_atomic_helper_setup_commit() for a starting point)
1000 * to implement blocking and nonblocking commits easily. It is not used
1001 * by the atomic helpers
1002 *
Daniel Vetter1ea0c022016-11-21 18:18:02 +01001003 * This function is called when the new atomic state has already been
1004 * swapped into the various state pointers. The passed in state
1005 * therefore contains copies of the old/previous state. This hook should
1006 * commit the new state into hardware. Note that the helpers have
1007 * already waited for preceeding atomic commits and fences, but drivers
1008 * can add more waiting calls at the start of their implementation, e.g.
1009 * to wait for driver-internal request for implicit syncing, before
1010 * starting to commit the update to the hardware.
Daniel Vetter9f2a7952016-06-08 14:19:02 +02001011 *
1012 * After the atomic update is committed to the hardware this hook needs
1013 * to call drm_atomic_helper_commit_hw_done(). Then wait for the upate
1014 * to be executed by the hardware, for example using
1015 * drm_atomic_helper_wait_for_vblanks(), and then clean up the old
1016 * framebuffers using drm_atomic_helper_cleanup_planes().
1017 *
1018 * When disabling a CRTC this hook _must_ stall for the commit to
1019 * complete. Vblank waits don't work on disabled CRTC, hence the core
1020 * can't take care of this. And it also can't rely on the vblank event,
1021 * since that can be signalled already when the screen shows black,
1022 * which can happen much earlier than the last hardware access needed to
1023 * shut off the display pipeline completely.
1024 *
1025 * This hook is optional, the default implementation is
1026 * drm_atomic_helper_commit_tail().
1027 */
1028 void (*atomic_commit_tail)(struct drm_atomic_state *state);
1029};
1030
Daniel Vetter092d01d2015-12-04 09:45:44 +01001031#endif