blob: f9c94c2a1364699a2c89dd535b52a2d204e4ef40 [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;
Laurent Pinchart9d2230d2019-02-21 03:01:38 +020052struct drm_writeback_connector;
53struct drm_writeback_job;
Daniel Vetter092d01d2015-12-04 09:45:44 +010054
55/**
56 * struct drm_crtc_helper_funcs - helper operations for CRTCs
Daniel Vetter092d01d2015-12-04 09:45:44 +010057 *
Daniel Vetter36b66082015-12-04 09:46:08 +010058 * These hooks are used by the legacy CRTC helpers, the transitional plane
59 * helpers and the new atomic modesetting helpers.
Daniel Vetter092d01d2015-12-04 09:45:44 +010060 */
61struct drm_crtc_helper_funcs {
Daniel Vetter36b66082015-12-04 09:46:08 +010062 /**
63 * @dpms:
64 *
65 * Callback to control power levels on the CRTC. If the mode passed in
66 * is unsupported, the provider must use the next lowest power level.
67 * This is used by the legacy CRTC helpers to implement DPMS
68 * functionality in drm_helper_connector_dpms().
69 *
70 * This callback is also used to disable a CRTC by calling it with
71 * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
72 *
73 * This callback is used by the legacy CRTC helpers. Atomic helpers
74 * also support using this hook for enabling and disabling a CRTC to
75 * facilitate transitions to atomic, but it is deprecated. Instead
Laurent Pinchart0b20a0f2017-06-30 12:36:44 +030076 * @atomic_enable and @atomic_disable should be used.
Daniel Vetter092d01d2015-12-04 09:45:44 +010077 */
78 void (*dpms)(struct drm_crtc *crtc, int mode);
Daniel Vetter36b66082015-12-04 09:46:08 +010079
80 /**
81 * @prepare:
82 *
83 * This callback should prepare the CRTC for a subsequent modeset, which
84 * in practice means the driver should disable the CRTC if it is
85 * running. Most drivers ended up implementing this by calling their
86 * @dpms hook with DRM_MODE_DPMS_OFF.
87 *
88 * This callback is used by the legacy CRTC helpers. Atomic helpers
89 * also support using this hook for disabling a CRTC to facilitate
Laurent Pinchart0b20a0f2017-06-30 12:36:44 +030090 * transitions to atomic, but it is deprecated. Instead @atomic_disable
91 * should be used.
Daniel Vetter36b66082015-12-04 09:46:08 +010092 */
Daniel Vetter092d01d2015-12-04 09:45:44 +010093 void (*prepare)(struct drm_crtc *crtc);
Daniel Vetter36b66082015-12-04 09:46:08 +010094
95 /**
96 * @commit:
97 *
98 * This callback should commit the new mode on the CRTC after a modeset,
99 * which in practice means the driver should enable the CRTC. Most
100 * drivers ended up implementing this by calling their @dpms hook with
101 * DRM_MODE_DPMS_ON.
102 *
103 * This callback is used by the legacy CRTC helpers. Atomic helpers
104 * also support using this hook for enabling a CRTC to facilitate
Laurent Pinchart0b20a0f2017-06-30 12:36:44 +0300105 * transitions to atomic, but it is deprecated. Instead @atomic_enable
106 * should be used.
Daniel Vetter36b66082015-12-04 09:46:08 +0100107 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100108 void (*commit)(struct drm_crtc *crtc);
109
Daniel Vetter36b66082015-12-04 09:46:08 +0100110 /**
Jose Abreu3eb220a2017-05-15 11:33:47 +0200111 * @mode_valid:
112 *
113 * This callback is used to check if a specific mode is valid in this
114 * crtc. This should be implemented if the crtc has some sort of
115 * restriction in the modes it can display. For example, a given crtc
116 * may be responsible to set a clock value. If the clock can not
117 * produce all the values for the available modes then this callback
118 * can be used to restrict the number of modes to only the ones that
119 * can be displayed.
120 *
121 * This hook is used by the probe helpers to filter the mode list in
122 * drm_helper_probe_single_connector_modes(), and it is used by the
123 * atomic helpers to validate modes supplied by userspace in
124 * drm_atomic_helper_check_modeset().
125 *
126 * This function is optional.
127 *
128 * NOTE:
129 *
130 * Since this function is both called from the check phase of an atomic
131 * commit, and the mode validation in the probe paths it is not allowed
132 * to look at anything else but the passed-in mode, and validate it
133 * against configuration-invariant hardward constraints. Any further
134 * limits which depend upon the configuration can only be checked in
135 * @mode_fixup or @atomic_check.
136 *
137 * RETURNS:
138 *
139 * drm_mode_status Enum
140 */
141 enum drm_mode_status (*mode_valid)(struct drm_crtc *crtc,
142 const struct drm_display_mode *mode);
143
144 /**
Daniel Vetter36b66082015-12-04 09:46:08 +0100145 * @mode_fixup:
146 *
147 * This callback is used to validate a mode. The parameter mode is the
148 * display mode that userspace requested, adjusted_mode is the mode the
149 * encoders need to be fed with. Note that this is the inverse semantics
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100150 * of the meaning for the &drm_encoder and &drm_bridge_funcs.mode_fixup
151 * vfunc. If the CRTC cannot support the requested conversion from mode
Daniel Vetter9de5d4a2017-05-15 11:11:35 +0200152 * to adjusted_mode it should reject the modeset. See also
153 * &drm_crtc_state.adjusted_mode for more details.
Daniel Vetter36b66082015-12-04 09:46:08 +0100154 *
155 * This function is used by both legacy CRTC helpers and atomic helpers.
156 * With atomic helpers it is optional.
157 *
158 * NOTE:
159 *
160 * This function is called in the check phase of atomic modesets, which
161 * can be aborted for any reason (including on userspace's request to
162 * just check whether a configuration would be possible). Atomic drivers
163 * MUST NOT touch any persistent state (hardware or software) or data
164 * structures except the passed in adjusted_mode parameter.
165 *
166 * This is in contrast to the legacy CRTC helpers where this was
167 * allowed.
168 *
169 * Atomic drivers which need to inspect and adjust more state should
Daniel Vetter9f800212017-05-15 11:11:36 +0200170 * instead use the @atomic_check callback, but note that they're not
171 * perfectly equivalent: @mode_valid is called from
172 * drm_atomic_helper_check_modeset(), but @atomic_check is called from
173 * drm_atomic_helper_check_planes(), because originally it was meant for
174 * plane update checks only.
Daniel Vetter36b66082015-12-04 09:46:08 +0100175 *
Jose Abreu3eb220a2017-05-15 11:33:47 +0200176 * Also beware that userspace can request its own custom modes, neither
177 * core nor helpers filter modes to the list of probe modes reported by
178 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
179 * that modes are filtered consistently put any CRTC constraints and
180 * limits checks into @mode_valid.
Daniel Vetterdf7d6782016-01-04 07:53:36 +0100181 *
Daniel Vetter36b66082015-12-04 09:46:08 +0100182 * RETURNS:
183 *
184 * True if an acceptable configuration is possible, false if the modeset
185 * operation should be rejected.
186 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100187 bool (*mode_fixup)(struct drm_crtc *crtc,
188 const struct drm_display_mode *mode,
189 struct drm_display_mode *adjusted_mode);
Daniel Vetter36b66082015-12-04 09:46:08 +0100190
191 /**
192 * @mode_set:
193 *
194 * This callback is used by the legacy CRTC helpers to set a new mode,
195 * position and framebuffer. Since it ties the primary plane to every
196 * mode change it is incompatible with universal plane support. And
197 * since it can't update other planes it's incompatible with atomic
198 * modeset support.
199 *
200 * This callback is only used by CRTC helpers and deprecated.
201 *
202 * RETURNS:
203 *
204 * 0 on success or a negative error code on failure.
205 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100206 int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
207 struct drm_display_mode *adjusted_mode, int x, int y,
208 struct drm_framebuffer *old_fb);
Daniel Vetter36b66082015-12-04 09:46:08 +0100209
210 /**
211 * @mode_set_nofb:
212 *
213 * This callback is used to update the display mode of a CRTC without
214 * changing anything of the primary plane configuration. This fits the
215 * requirement of atomic and hence is used by the atomic helpers. It is
216 * also used by the transitional plane helpers to implement a
217 * @mode_set hook in drm_helper_crtc_mode_set().
218 *
219 * Note that the display pipe is completely off when this function is
220 * called. Atomic drivers which need hardware to be running before they
221 * program the new display mode (e.g. because they implement runtime PM)
222 * should not use this hook. This is because the helper library calls
223 * this hook only once per mode change and not every time the display
224 * pipeline is suspended using either DPMS or the new "ACTIVE" property.
225 * Which means register values set in this callback might get reset when
226 * the CRTC is suspended, but not restored. Such drivers should instead
Laurent Pinchart0b20a0f2017-06-30 12:36:44 +0300227 * move all their CRTC setup into the @atomic_enable callback.
Daniel Vetter36b66082015-12-04 09:46:08 +0100228 *
229 * This callback is optional.
230 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100231 void (*mode_set_nofb)(struct drm_crtc *crtc);
232
Daniel Vetter36b66082015-12-04 09:46:08 +0100233 /**
234 * @mode_set_base:
235 *
236 * This callback is used by the legacy CRTC helpers to set a new
237 * framebuffer and scanout position. It is optional and used as an
238 * optimized fast-path instead of a full mode set operation with all the
Daniel Vetterdf7d6782016-01-04 07:53:36 +0100239 * resulting flickering. If it is not present
240 * drm_crtc_helper_set_config() will fall back to a full modeset, using
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100241 * the @mode_set callback. Since it can't update other planes it's
Daniel Vetter36b66082015-12-04 09:46:08 +0100242 * incompatible with atomic modeset support.
243 *
244 * This callback is only used by the CRTC helpers and deprecated.
245 *
246 * RETURNS:
247 *
248 * 0 on success or a negative error code on failure.
249 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100250 int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
251 struct drm_framebuffer *old_fb);
Daniel Vetter36b66082015-12-04 09:46:08 +0100252
253 /**
254 * @mode_set_base_atomic:
255 *
256 * This callback is used by the fbdev helpers to set a new framebuffer
257 * and scanout without sleeping, i.e. from an atomic calling context. It
258 * is only used to implement kgdb support.
259 *
260 * This callback is optional and only needed for kgdb support in the fbdev
261 * helpers.
262 *
263 * RETURNS:
264 *
265 * 0 on success or a negative error code on failure.
266 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100267 int (*mode_set_base_atomic)(struct drm_crtc *crtc,
268 struct drm_framebuffer *fb, int x, int y,
269 enum mode_set_atomic);
270
Daniel Vetter36b66082015-12-04 09:46:08 +0100271 /**
Daniel Vetter36b66082015-12-04 09:46:08 +0100272 * @disable:
273 *
274 * This callback should be used to disable the CRTC. With the atomic
275 * drivers it is called after all encoders connected to this CRTC have
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100276 * been shut off already using their own
277 * &drm_encoder_helper_funcs.disable hook. If that sequence is too
278 * simple drivers can just add their own hooks and call it from this
279 * CRTC callback here by looping over all encoders connected to it using
280 * for_each_encoder_on_crtc().
Daniel Vetter36b66082015-12-04 09:46:08 +0100281 *
282 * This hook is used both by legacy CRTC helpers and atomic helpers.
283 * Atomic drivers don't need to implement it if there's no need to
284 * disable anything at the CRTC level. To ensure that runtime PM
285 * handling (using either DPMS or the new "ACTIVE" property) works
Laurent Pinchart0b20a0f2017-06-30 12:36:44 +0300286 * @disable must be the inverse of @atomic_enable for atomic drivers.
Liu Yingc9ac8b42016-08-26 15:30:38 +0800287 * Atomic drivers should consider to use @atomic_disable instead of
288 * this one.
Daniel Vetter36b66082015-12-04 09:46:08 +0100289 *
290 * NOTE:
291 *
292 * With legacy CRTC helpers there's a big semantic difference between
293 * @disable and other hooks (like @prepare or @dpms) used to shut down a
294 * CRTC: @disable is only called when also logically disabling the
295 * display pipeline and needs to release any resources acquired in
296 * @mode_set (like shared PLLs, or again release pinned framebuffers).
297 *
298 * Therefore @disable must be the inverse of @mode_set plus @commit for
299 * drivers still using legacy CRTC helpers, which is different from the
300 * rules under atomic.
301 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100302 void (*disable)(struct drm_crtc *crtc);
Daniel Vetter36b66082015-12-04 09:46:08 +0100303
304 /**
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100305 * @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 *
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100318 * When using drm_atomic_helper_check_planes() this hook is called
Thierry Reding2093ea22017-09-01 16:40:41 +0200319 * after the &drm_plane_helper_funcs.atomic_check hook for planes, which
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100320 * allows drivers to assign shared resources requested by planes in this
321 * callback here. For more complicated dependencies the driver can call
322 * the provided check helpers multiple times until the computed state
323 * has a final configuration and everything has been checked.
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100324 *
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
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100327 * be taken though to ensure that state check and compute functions for
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100328 * 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 *
Jose Abreu3eb220a2017-05-15 11:33:47 +0200342 * Also beware that userspace can request its own custom modes, neither
343 * core nor helpers filter modes to the list of probe modes reported by
344 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
345 * that modes are filtered consistently put any CRTC constraints and
346 * limits checks into @mode_valid.
347 *
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100348 * RETURNS:
349 *
350 * 0 on success, -EINVAL if the state or the transition can't be
351 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
352 * attempt to obtain another state object ran into a &drm_modeset_lock
353 * deadlock.
354 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100355 int (*atomic_check)(struct drm_crtc *crtc,
356 struct drm_crtc_state *state);
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100357
358 /**
359 * @atomic_begin:
360 *
361 * Drivers should prepare for an atomic update of multiple planes on
362 * a CRTC in this hook. Depending upon hardware this might be vblank
363 * evasion, blocking updates by setting bits or doing preparatory work
364 * for e.g. manual update display.
365 *
366 * This hook is called before any plane commit functions are called.
367 *
368 * Note that the power state of the display pipe when this function is
369 * called depends upon the exact helpers and calling sequence the driver
Stefan Agner0dc99672016-10-31 10:36:46 -0700370 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
371 * the tradeoffs and variants of plane commit helpers.
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100372 *
373 * This callback is used by the atomic modeset helpers and by the
374 * transitional plane helpers, but it is optional.
375 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100376 void (*atomic_begin)(struct drm_crtc *crtc,
377 struct drm_crtc_state *old_crtc_state);
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100378 /**
379 * @atomic_flush:
380 *
381 * Drivers should finalize an atomic update of multiple planes on
382 * a CRTC in this hook. Depending upon hardware this might include
383 * checking that vblank evasion was successful, unblocking updates by
384 * setting bits or setting the GO bit to flush out all updates.
385 *
386 * Simple hardware or hardware with special requirements can commit and
387 * flush out all updates for all planes from this hook and forgo all the
388 * other commit hooks for plane updates.
389 *
390 * This hook is called after any plane commit functions are called.
391 *
392 * Note that the power state of the display pipe when this function is
393 * called depends upon the exact helpers and calling sequence the driver
Stefan Agner0dc99672016-10-31 10:36:46 -0700394 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
395 * the tradeoffs and variants of plane commit helpers.
Daniel Vetter11a0ba92015-12-04 09:46:04 +0100396 *
397 * This callback is used by the atomic modeset helpers and by the
398 * transitional plane helpers, but it is optional.
399 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100400 void (*atomic_flush)(struct drm_crtc *crtc,
401 struct drm_crtc_state *old_crtc_state);
Liu Yingc9ac8b42016-08-26 15:30:38 +0800402
403 /**
Laurent Pinchart0b20a0f2017-06-30 12:36:44 +0300404 * @atomic_enable:
405 *
406 * This callback should be used to enable the CRTC. With the atomic
407 * drivers it is called before all encoders connected to this CRTC are
408 * enabled through the encoder's own &drm_encoder_helper_funcs.enable
409 * hook. If that sequence is too simple drivers can just add their own
410 * hooks and call it from this CRTC callback here by looping over all
411 * encoders connected to it using for_each_encoder_on_crtc().
412 *
413 * This hook is used only by atomic helpers, for symmetry with
414 * @atomic_disable. Atomic drivers don't need to implement it if there's
415 * no need to enable anything at the CRTC level. To ensure that runtime
416 * PM handling (using either DPMS or the new "ACTIVE" property) works
417 * @atomic_enable must be the inverse of @atomic_disable for atomic
418 * drivers.
419 *
420 * Drivers can use the @old_crtc_state input parameter if the operations
421 * needed to enable the CRTC don't depend solely on the new state but
422 * also on the transition between the old state and the new state.
Rodrigo Siqueirafe616922019-03-14 15:48:45 -0300423 *
424 * This function is optional.
Laurent Pinchart0b20a0f2017-06-30 12:36:44 +0300425 */
426 void (*atomic_enable)(struct drm_crtc *crtc,
427 struct drm_crtc_state *old_crtc_state);
428
429 /**
Liu Yingc9ac8b42016-08-26 15:30:38 +0800430 * @atomic_disable:
431 *
432 * This callback should be used to disable the CRTC. With the atomic
433 * drivers it is called after all encoders connected to this CRTC have
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100434 * been shut off already using their own
435 * &drm_encoder_helper_funcs.disable hook. If that sequence is too
436 * simple drivers can just add their own hooks and call it from this
437 * CRTC callback here by looping over all encoders connected to it using
438 * for_each_encoder_on_crtc().
Liu Yingc9ac8b42016-08-26 15:30:38 +0800439 *
440 * This hook is used only by atomic helpers. Atomic drivers don't
441 * need to implement it if there's no need to disable anything at the
442 * CRTC level.
443 *
444 * Comparing to @disable, this one provides the additional input
445 * parameter @old_crtc_state which could be used to access the old
446 * state. Atomic drivers should consider to use this one instead
447 * of @disable.
Rodrigo Siqueirafe616922019-03-14 15:48:45 -0300448 *
449 * This function is optional.
Liu Yingc9ac8b42016-08-26 15:30:38 +0800450 */
451 void (*atomic_disable)(struct drm_crtc *crtc,
452 struct drm_crtc_state *old_crtc_state);
Daniel Vetter092d01d2015-12-04 09:45:44 +0100453};
454
455/**
456 * drm_crtc_helper_add - sets the helper vtable for a crtc
457 * @crtc: DRM CRTC
458 * @funcs: helper vtable to set for @crtc
459 */
460static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
461 const struct drm_crtc_helper_funcs *funcs)
462{
463 crtc->helper_private = funcs;
464}
465
466/**
467 * struct drm_encoder_helper_funcs - helper operations for encoders
Daniel Vetter092d01d2015-12-04 09:45:44 +0100468 *
Daniel Vetter36b66082015-12-04 09:46:08 +0100469 * These hooks are used by the legacy CRTC helpers, the transitional plane
470 * helpers and the new atomic modesetting helpers.
Daniel Vetter092d01d2015-12-04 09:45:44 +0100471 */
472struct drm_encoder_helper_funcs {
Daniel Vetter36b66082015-12-04 09:46:08 +0100473 /**
474 * @dpms:
475 *
476 * Callback to control power levels on the encoder. If the mode passed in
477 * is unsupported, the provider must use the next lowest power level.
478 * This is used by the legacy encoder helpers to implement DPMS
479 * functionality in drm_helper_connector_dpms().
480 *
481 * This callback is also used to disable an encoder by calling it with
482 * DRM_MODE_DPMS_OFF if the @disable hook isn't used.
483 *
484 * This callback is used by the legacy CRTC helpers. Atomic helpers
485 * also support using this hook for enabling and disabling an encoder to
486 * facilitate transitions to atomic, but it is deprecated. Instead
487 * @enable and @disable should be used.
488 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100489 void (*dpms)(struct drm_encoder *encoder, int mode);
Daniel Vetter092d01d2015-12-04 09:45:44 +0100490
Daniel Vetter36b66082015-12-04 09:46:08 +0100491 /**
Jose Abreu3eb220a2017-05-15 11:33:47 +0200492 * @mode_valid:
493 *
494 * This callback is used to check if a specific mode is valid in this
495 * encoder. This should be implemented if the encoder has some sort
496 * of restriction in the modes it can display. For example, a given
497 * encoder may be responsible to set a clock value. If the clock can
498 * not produce all the values for the available modes then this callback
499 * can be used to restrict the number of modes to only the ones that
500 * can be displayed.
501 *
502 * This hook is used by the probe helpers to filter the mode list in
503 * drm_helper_probe_single_connector_modes(), and it is used by the
504 * atomic helpers to validate modes supplied by userspace in
505 * drm_atomic_helper_check_modeset().
506 *
507 * This function is optional.
508 *
509 * NOTE:
510 *
511 * Since this function is both called from the check phase of an atomic
512 * commit, and the mode validation in the probe paths it is not allowed
513 * to look at anything else but the passed-in mode, and validate it
514 * against configuration-invariant hardward constraints. Any further
515 * limits which depend upon the configuration can only be checked in
516 * @mode_fixup or @atomic_check.
517 *
518 * RETURNS:
519 *
520 * drm_mode_status Enum
521 */
522 enum drm_mode_status (*mode_valid)(struct drm_encoder *crtc,
523 const struct drm_display_mode *mode);
524
525 /**
Daniel Vetter36b66082015-12-04 09:46:08 +0100526 * @mode_fixup:
527 *
528 * This callback is used to validate and adjust a mode. The parameter
529 * mode is the display mode that should be fed to the next element in
530 * the display chain, either the final &drm_connector or a &drm_bridge.
531 * The parameter adjusted_mode is the input mode the encoder requires. It
Daniel Vetter9de5d4a2017-05-15 11:11:35 +0200532 * can be modified by this callback and does not need to match mode. See
533 * also &drm_crtc_state.adjusted_mode for more details.
Daniel Vetter36b66082015-12-04 09:46:08 +0100534 *
535 * This function is used by both legacy CRTC helpers and atomic helpers.
Carlos Palminha3c5b2672016-02-10 12:15:22 +0000536 * This hook is optional.
Daniel Vetter36b66082015-12-04 09:46:08 +0100537 *
538 * NOTE:
539 *
540 * This function is called in the check phase of atomic modesets, which
541 * can be aborted for any reason (including on userspace's request to
542 * just check whether a configuration would be possible). Atomic drivers
543 * MUST NOT touch any persistent state (hardware or software) or data
544 * structures except the passed in adjusted_mode parameter.
545 *
546 * This is in contrast to the legacy CRTC helpers where this was
547 * allowed.
548 *
549 * Atomic drivers which need to inspect and adjust more state should
Daniel Vetter9f800212017-05-15 11:11:36 +0200550 * instead use the @atomic_check callback. If @atomic_check is used,
551 * this hook isn't called since @atomic_check allows a strict superset
552 * of the functionality of @mode_fixup.
Daniel Vetter36b66082015-12-04 09:46:08 +0100553 *
Jose Abreu3eb220a2017-05-15 11:33:47 +0200554 * Also beware that userspace can request its own custom modes, neither
555 * core nor helpers filter modes to the list of probe modes reported by
556 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
557 * that modes are filtered consistently put any encoder constraints and
558 * limits checks into @mode_valid.
Daniel Vetterdf7d6782016-01-04 07:53:36 +0100559 *
Daniel Vetter36b66082015-12-04 09:46:08 +0100560 * RETURNS:
561 *
562 * True if an acceptable configuration is possible, false if the modeset
563 * operation should be rejected.
564 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100565 bool (*mode_fixup)(struct drm_encoder *encoder,
566 const struct drm_display_mode *mode,
567 struct drm_display_mode *adjusted_mode);
Daniel Vetter36b66082015-12-04 09:46:08 +0100568
569 /**
570 * @prepare:
571 *
572 * This callback should prepare the encoder for a subsequent modeset,
573 * which in practice means the driver should disable the encoder if it
574 * is running. Most drivers ended up implementing this by calling their
575 * @dpms hook with DRM_MODE_DPMS_OFF.
576 *
577 * This callback is used by the legacy CRTC helpers. Atomic helpers
578 * also support using this hook for disabling an encoder to facilitate
579 * transitions to atomic, but it is deprecated. Instead @disable should
580 * be used.
581 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100582 void (*prepare)(struct drm_encoder *encoder);
Daniel Vetter36b66082015-12-04 09:46:08 +0100583
584 /**
585 * @commit:
586 *
587 * This callback should commit the new mode on the encoder after a modeset,
588 * which in practice means the driver should enable the encoder. Most
589 * drivers ended up implementing this by calling their @dpms hook with
590 * DRM_MODE_DPMS_ON.
591 *
592 * This callback is used by the legacy CRTC helpers. Atomic helpers
593 * also support using this hook for enabling an encoder to facilitate
594 * transitions to atomic, but it is deprecated. Instead @enable should
595 * be used.
596 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100597 void (*commit)(struct drm_encoder *encoder);
Daniel Vetter36b66082015-12-04 09:46:08 +0100598
599 /**
600 * @mode_set:
601 *
602 * This callback is used to update the display mode of an encoder.
603 *
604 * Note that the display pipe is completely off when this function is
605 * called. Drivers which need hardware to be running before they program
606 * the new display mode (because they implement runtime PM) should not
607 * use this hook, because the helper library calls it only once and not
608 * every time the display pipeline is suspend using either DPMS or the
609 * new "ACTIVE" property. Such drivers should instead move all their
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100610 * encoder setup into the @enable callback.
Daniel Vetter36b66082015-12-04 09:46:08 +0100611 *
612 * This callback is used both by the legacy CRTC helpers and the atomic
613 * modeset helpers. It is optional in the atomic helpers.
Philipp Zabelfe4a11c2016-07-22 12:20:47 +0200614 *
615 * NOTE:
616 *
617 * If the driver uses the atomic modeset helpers and needs to inspect
618 * the connector state or connector display info during mode setting,
619 * @atomic_mode_set can be used instead.
Daniel Vetter36b66082015-12-04 09:46:08 +0100620 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100621 void (*mode_set)(struct drm_encoder *encoder,
622 struct drm_display_mode *mode,
623 struct drm_display_mode *adjusted_mode);
Daniel Vetter36b66082015-12-04 09:46:08 +0100624
625 /**
Philipp Zabelfe4a11c2016-07-22 12:20:47 +0200626 * @atomic_mode_set:
627 *
628 * This callback is used to update the display mode of an encoder.
629 *
630 * Note that the display pipe is completely off when this function is
631 * called. Drivers which need hardware to be running before they program
632 * the new display mode (because they implement runtime PM) should not
633 * use this hook, because the helper library calls it only once and not
634 * every time the display pipeline is suspended using either DPMS or the
635 * new "ACTIVE" property. Such drivers should instead move all their
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100636 * encoder setup into the @enable callback.
Philipp Zabelfe4a11c2016-07-22 12:20:47 +0200637 *
638 * This callback is used by the atomic modeset helpers in place of the
639 * @mode_set callback, if set by the driver. It is optional and should
640 * be used instead of @mode_set if the driver needs to inspect the
641 * connector state or display info, since there is no direct way to
642 * go from the encoder to the current connector.
643 */
644 void (*atomic_mode_set)(struct drm_encoder *encoder,
645 struct drm_crtc_state *crtc_state,
646 struct drm_connector_state *conn_state);
647
648 /**
Daniel Vetter36b66082015-12-04 09:46:08 +0100649 * @get_crtc:
650 *
651 * This callback is used by the legacy CRTC helpers to work around
652 * deficiencies in its own book-keeping.
653 *
654 * Do not use, use atomic helpers instead, which get the book keeping
655 * right.
656 *
657 * FIXME:
658 *
659 * Currently only nouveau is using this, and as soon as nouveau is
660 * atomic we can ditch this hook.
661 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100662 struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder);
Daniel Vetter36b66082015-12-04 09:46:08 +0100663
664 /**
665 * @detect:
666 *
667 * This callback can be used by drivers who want to do detection on the
668 * encoder object instead of in connector functions.
669 *
670 * It is not used by any helper and therefore has purely driver-specific
671 * semantics. New drivers shouldn't use this and instead just implement
672 * their own private callbacks.
673 *
674 * FIXME:
675 *
676 * This should just be converted into a pile of driver vfuncs.
677 * Currently radeon, amdgpu and nouveau are using it.
678 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100679 enum drm_connector_status (*detect)(struct drm_encoder *encoder,
680 struct drm_connector *connector);
Daniel Vetter36b66082015-12-04 09:46:08 +0100681
682 /**
683 * @disable:
684 *
685 * This callback should be used to disable the encoder. With the atomic
686 * drivers it is called before this encoder's CRTC has been shut off
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100687 * using their own &drm_crtc_helper_funcs.disable hook. If that
688 * sequence is too simple drivers can just add their own driver private
689 * encoder hooks and call them from CRTC's callback by looping over all
690 * encoders connected to it using for_each_encoder_on_crtc().
Daniel Vetter36b66082015-12-04 09:46:08 +0100691 *
692 * This hook is used both by legacy CRTC helpers and atomic helpers.
693 * Atomic drivers don't need to implement it if there's no need to
694 * disable anything at the encoder level. To ensure that runtime PM
695 * handling (using either DPMS or the new "ACTIVE" property) works
696 * @disable must be the inverse of @enable for atomic drivers.
697 *
698 * NOTE:
699 *
700 * With legacy CRTC helpers there's a big semantic difference between
701 * @disable and other hooks (like @prepare or @dpms) used to shut down a
702 * encoder: @disable is only called when also logically disabling the
703 * display pipeline and needs to release any resources acquired in
704 * @mode_set (like shared PLLs, or again release pinned framebuffers).
705 *
706 * Therefore @disable must be the inverse of @mode_set plus @commit for
707 * drivers still using legacy CRTC helpers, which is different from the
708 * rules under atomic.
709 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100710 void (*disable)(struct drm_encoder *encoder);
711
Daniel Vetter36b66082015-12-04 09:46:08 +0100712 /**
713 * @enable:
714 *
715 * This callback should be used to enable the encoder. With the atomic
716 * drivers it is called after this encoder's CRTC has been enabled using
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100717 * their own &drm_crtc_helper_funcs.enable hook. If that sequence is
718 * too simple drivers can just add their own driver private encoder
719 * hooks and call them from CRTC's callback by looping over all encoders
720 * connected to it using for_each_encoder_on_crtc().
Daniel Vetter36b66082015-12-04 09:46:08 +0100721 *
722 * This hook is used only by atomic helpers, for symmetry with @disable.
723 * Atomic drivers don't need to implement it if there's no need to
724 * enable anything at the encoder level. To ensure that runtime PM handling
725 * (using either DPMS or the new "ACTIVE" property) works
726 * @enable must be the inverse of @disable for atomic drivers.
727 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100728 void (*enable)(struct drm_encoder *encoder);
729
Daniel Vetter36b66082015-12-04 09:46:08 +0100730 /**
731 * @atomic_check:
732 *
733 * This callback is used to validate encoder state for atomic drivers.
734 * Since the encoder is the object connecting the CRTC and connector it
735 * gets passed both states, to be able to validate interactions and
736 * update the CRTC to match what the encoder needs for the requested
737 * connector.
738 *
Daniel Vetter9f800212017-05-15 11:11:36 +0200739 * Since this provides a strict superset of the functionality of
740 * @mode_fixup (the requested and adjusted modes are both available
741 * through the passed in &struct drm_crtc_state) @mode_fixup is not
742 * called when @atomic_check is implemented.
743 *
Daniel Vetter36b66082015-12-04 09:46:08 +0100744 * This function is used by the atomic helpers, but it is optional.
745 *
746 * NOTE:
747 *
748 * This function is called in the check phase of an atomic update. The
749 * driver is not allowed to change anything outside of the free-standing
750 * state objects passed-in or assembled in the overall &drm_atomic_state
751 * update tracking structure.
752 *
Jose Abreu3eb220a2017-05-15 11:33:47 +0200753 * Also beware that userspace can request its own custom modes, neither
754 * core nor helpers filter modes to the list of probe modes reported by
755 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
756 * that modes are filtered consistently put any encoder constraints and
757 * limits checks into @mode_valid.
758 *
Daniel Vetter36b66082015-12-04 09:46:08 +0100759 * RETURNS:
760 *
761 * 0 on success, -EINVAL if the state or the transition can't be
762 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
763 * attempt to obtain another state object ran into a &drm_modeset_lock
764 * deadlock.
765 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100766 int (*atomic_check)(struct drm_encoder *encoder,
767 struct drm_crtc_state *crtc_state,
768 struct drm_connector_state *conn_state);
769};
770
771/**
Daniel Vetter36b66082015-12-04 09:46:08 +0100772 * drm_encoder_helper_add - sets the helper vtable for an encoder
Daniel Vetter092d01d2015-12-04 09:45:44 +0100773 * @encoder: DRM encoder
774 * @funcs: helper vtable to set for @encoder
775 */
776static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
777 const struct drm_encoder_helper_funcs *funcs)
778{
779 encoder->helper_private = funcs;
780}
781
782/**
783 * struct drm_connector_helper_funcs - helper operations for connectors
Daniel Vetter092d01d2015-12-04 09:45:44 +0100784 *
Daniel Vetter4ee60342015-12-04 09:46:05 +0100785 * These functions are used by the atomic and legacy modeset helpers and by the
786 * probe helpers.
Daniel Vetter092d01d2015-12-04 09:45:44 +0100787 */
788struct drm_connector_helper_funcs {
Daniel Vetter4ee60342015-12-04 09:46:05 +0100789 /**
790 * @get_modes:
791 *
792 * This function should fill in all modes currently valid for the sink
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100793 * into the &drm_connector.probed_modes list. It should also update the
Daniel Vetterc555f022018-07-09 10:40:06 +0200794 * EDID property by calling drm_connector_update_edid_property().
Daniel Vetter4ee60342015-12-04 09:46:05 +0100795 *
796 * The usual way to implement this is to cache the EDID retrieved in the
797 * probe callback somewhere in the driver-private connector structure.
798 * In this function drivers then parse the modes in the EDID and add
799 * them by calling drm_add_edid_modes(). But connectors that driver a
800 * fixed panel can also manually add specific modes using
Daniel Vetterdf7d6782016-01-04 07:53:36 +0100801 * drm_mode_probed_add(). Drivers which manually add modes should also
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100802 * make sure that the &drm_connector.display_info,
803 * &drm_connector.width_mm and &drm_connector.height_mm fields are
804 * filled in.
Daniel Vetterdf7d6782016-01-04 07:53:36 +0100805 *
806 * Virtual drivers that just want some standard VESA mode with a given
807 * resolution can call drm_add_modes_noedid(), and mark the preferred
808 * one using drm_set_preferred_mode().
809 *
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100810 * This function is only called after the @detect hook has indicated
Daniel Vetter4ee60342015-12-04 09:46:05 +0100811 * that a sink is connected and when the EDID isn't overridden through
812 * sysfs or the kernel commandline.
813 *
814 * This callback is used by the probe helpers in e.g.
815 * drm_helper_probe_single_connector_modes().
816 *
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +0200817 * To avoid races with concurrent connector state updates, the helper
818 * libraries always call this with the &drm_mode_config.connection_mutex
819 * held. Because of this it's safe to inspect &drm_connector->state.
820 *
Daniel Vetter4ee60342015-12-04 09:46:05 +0100821 * RETURNS:
822 *
823 * The number of modes added by calling drm_mode_probed_add().
824 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100825 int (*get_modes)(struct drm_connector *connector);
Daniel Vetter4ee60342015-12-04 09:46:05 +0100826
827 /**
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +0200828 * @detect_ctx:
829 *
830 * Check to see if anything is attached to the connector. The parameter
831 * force is set to false whilst polling, true when checking the
832 * connector due to a user request. force can be used by the driver to
833 * avoid expensive, destructive operations during automated probing.
834 *
835 * This callback is optional, if not implemented the connector will be
836 * considered as always being attached.
837 *
838 * This is the atomic version of &drm_connector_funcs.detect.
839 *
840 * To avoid races against concurrent connector state updates, the
841 * helper libraries always call this with ctx set to a valid context,
842 * and &drm_mode_config.connection_mutex will always be locked with
843 * the ctx parameter set to this ctx. This allows taking additional
844 * locks as required.
845 *
846 * RETURNS:
847 *
848 * &drm_connector_status indicating the connector's status,
849 * or the error code returned by drm_modeset_lock(), -EDEADLK.
850 */
851 int (*detect_ctx)(struct drm_connector *connector,
852 struct drm_modeset_acquire_ctx *ctx,
853 bool force);
854
855 /**
Daniel Vetter4ee60342015-12-04 09:46:05 +0100856 * @mode_valid:
857 *
858 * Callback to validate a mode for a connector, irrespective of the
859 * specific display configuration.
860 *
861 * This callback is used by the probe helpers to filter the mode list
862 * (which is usually derived from the EDID data block from the sink).
863 * See e.g. drm_helper_probe_single_connector_modes().
864 *
Jose Abreu3eb220a2017-05-15 11:33:47 +0200865 * This function is optional.
866 *
Daniel Vetter4ee60342015-12-04 09:46:05 +0100867 * NOTE:
868 *
869 * This only filters the mode list supplied to userspace in the
Jose Abreu3eb220a2017-05-15 11:33:47 +0200870 * GETCONNECTOR IOCTL. Compared to &drm_encoder_helper_funcs.mode_valid,
871 * &drm_crtc_helper_funcs.mode_valid and &drm_bridge_funcs.mode_valid,
872 * which are also called by the atomic helpers from
873 * drm_atomic_helper_check_modeset(). This allows userspace to force and
874 * ignore sink constraint (like the pixel clock limits in the screen's
875 * EDID), which is useful for e.g. testing, or working around a broken
876 * EDID. Any source hardware constraint (which always need to be
877 * enforced) therefore should be checked in one of the above callbacks,
878 * and not this one here.
Daniel Vetter4ee60342015-12-04 09:46:05 +0100879 *
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +0200880 * To avoid races with concurrent connector state updates, the helper
881 * libraries always call this with the &drm_mode_config.connection_mutex
882 * held. Because of this it's safe to inspect &drm_connector->state.
883 *
Daniel Vetter4ee60342015-12-04 09:46:05 +0100884 * RETURNS:
885 *
Daniel Vetter6806cdf2017-01-25 07:26:43 +0100886 * Either &drm_mode_status.MODE_OK or one of the failure reasons in &enum
887 * drm_mode_status.
Daniel Vetter4ee60342015-12-04 09:46:05 +0100888 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100889 enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
890 struct drm_display_mode *mode);
Daniel Vetter4ee60342015-12-04 09:46:05 +0100891 /**
892 * @best_encoder:
893 *
894 * This function should select the best encoder for the given connector.
895 *
896 * This function is used by both the atomic helpers (in the
897 * drm_atomic_helper_check_modeset() function) and in the legacy CRTC
898 * helpers.
899 *
900 * NOTE:
901 *
902 * In atomic drivers this function is called in the check phase of an
903 * atomic update. The driver is not allowed to change or inspect
904 * anything outside of arguments passed-in. Atomic drivers which need to
905 * inspect dynamic configuration state should instead use
906 * @atomic_best_encoder.
907 *
Boris Brezillonc61b93f2016-06-07 13:47:56 +0200908 * You can leave this function to NULL if the connector is only
909 * attached to a single encoder and you are using the atomic helpers.
910 * In this case, the core will call drm_atomic_helper_best_encoder()
911 * for you.
912 *
Daniel Vetter4ee60342015-12-04 09:46:05 +0100913 * RETURNS:
914 *
915 * Encoder that should be used for the given connector and connector
916 * state, or NULL if no suitable encoder exists. Note that the helpers
917 * will ensure that encoders aren't used twice, drivers should not check
918 * for this.
919 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100920 struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
Daniel Vetter4ee60342015-12-04 09:46:05 +0100921
922 /**
923 * @atomic_best_encoder:
924 *
925 * This is the atomic version of @best_encoder for atomic drivers which
926 * need to select the best encoder depending upon the desired
927 * configuration and can't select it statically.
928 *
Boris Brezillonc61b93f2016-06-07 13:47:56 +0200929 * This function is used by drm_atomic_helper_check_modeset().
930 * If it is not implemented, the core will fallback to @best_encoder
931 * (or drm_atomic_helper_best_encoder() if @best_encoder is NULL).
Daniel Vetter4ee60342015-12-04 09:46:05 +0100932 *
933 * NOTE:
934 *
935 * This function is called in the check phase of an atomic update. The
936 * driver is not allowed to change anything outside of the free-standing
937 * state objects passed-in or assembled in the overall &drm_atomic_state
938 * update tracking structure.
939 *
940 * RETURNS:
941 *
942 * Encoder that should be used for the given connector and connector
943 * state, or NULL if no suitable encoder exists. Note that the helpers
944 * will ensure that encoders aren't used twice, drivers should not check
945 * for this.
946 */
Daniel Vetter092d01d2015-12-04 09:45:44 +0100947 struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,
948 struct drm_connector_state *connector_state);
Maarten Lankhorstce09d762017-04-06 13:19:03 +0200949
950 /**
951 * @atomic_check:
952 *
953 * This hook is used to validate connector state. This function is
954 * called from &drm_atomic_helper_check_modeset, and is called when
955 * a connector property is set, or a modeset on the crtc is forced.
956 *
957 * Because &drm_atomic_helper_check_modeset may be called multiple times,
958 * this function should handle being called multiple times as well.
959 *
960 * This function is also allowed to inspect any other object's state and
961 * can add more state objects to the atomic commit if needed. Care must
962 * be taken though to ensure that state check and compute functions for
963 * these added states are all called, and derived state in other objects
964 * all updated. Again the recommendation is to just call check helpers
965 * until a maximal configuration is reached.
966 *
967 * NOTE:
968 *
969 * This function is called in the check phase of an atomic update. The
970 * driver is not allowed to change anything outside of the free-standing
971 * state objects passed-in or assembled in the overall &drm_atomic_state
972 * update tracking structure.
973 *
974 * RETURNS:
975 *
976 * 0 on success, -EINVAL if the state or the transition can't be
977 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
978 * attempt to obtain another state object ran into a &drm_modeset_lock
979 * deadlock.
980 */
981 int (*atomic_check)(struct drm_connector *connector,
982 struct drm_connector_state *state);
Brian Starkey935774c2017-03-29 17:42:32 +0100983
984 /**
985 * @atomic_commit:
986 *
987 * This hook is to be used by drivers implementing writeback connectors
988 * that need a point when to commit the writeback job to the hardware.
Boris Brezillon425132f2018-07-03 09:50:16 +0200989 * The writeback_job to commit is available in
990 * &drm_connector_state.writeback_job.
Brian Starkey935774c2017-03-29 17:42:32 +0100991 *
Boris Brezillon814bde92018-07-03 09:50:17 +0200992 * This hook is optional.
993 *
Brian Starkey935774c2017-03-29 17:42:32 +0100994 * This callback is used by the atomic modeset helpers.
995 */
996 void (*atomic_commit)(struct drm_connector *connector,
Boris Brezillon425132f2018-07-03 09:50:16 +0200997 struct drm_connector_state *state);
Laurent Pinchart9d2230d2019-02-21 03:01:38 +0200998
999 int (*prepare_writeback_job)(struct drm_writeback_connector *connector,
1000 struct drm_writeback_job *job);
1001 void (*cleanup_writeback_job)(struct drm_writeback_connector *connector,
1002 struct drm_writeback_job *job);
Daniel Vetter092d01d2015-12-04 09:45:44 +01001003};
1004
1005/**
1006 * drm_connector_helper_add - sets the helper vtable for a connector
1007 * @connector: DRM connector
1008 * @funcs: helper vtable to set for @connector
1009 */
1010static inline void drm_connector_helper_add(struct drm_connector *connector,
1011 const struct drm_connector_helper_funcs *funcs)
1012{
1013 connector->helper_private = funcs;
1014}
1015
1016/**
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001017 * struct drm_plane_helper_funcs - helper operations for planes
Daniel Vetter092d01d2015-12-04 09:45:44 +01001018 *
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001019 * These functions are used by the atomic helpers and by the transitional plane
1020 * helpers.
Daniel Vetter092d01d2015-12-04 09:45:44 +01001021 */
1022struct drm_plane_helper_funcs {
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001023 /**
1024 * @prepare_fb:
1025 *
1026 * This hook is to prepare a framebuffer for scanout by e.g. pinning
Matt Roper1e55a532019-02-01 17:23:26 -08001027 * its backing storage or relocating it into a contiguous block of
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001028 * VRAM. Other possible preparatory work includes flushing caches.
1029 *
1030 * This function must not block for outstanding rendering, since it is
1031 * called in the context of the atomic IOCTL even for async commits to
1032 * be able to return any errors to userspace. Instead the recommended
Daniel Vetter30d23f22018-04-05 17:44:46 +02001033 * way is to fill out the &drm_plane_state.fence of the passed-in
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001034 * &drm_plane_state. If the driver doesn't support native fences then
1035 * equivalent functionality should be implemented through private
1036 * members in the plane structure.
1037 *
Daniel Vetter30d23f22018-04-05 17:44:46 +02001038 * Drivers which always have their buffers pinned should use
1039 * drm_gem_fb_prepare_fb() for this hook.
1040 *
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001041 * The helpers will call @cleanup_fb with matching arguments for every
1042 * successful call to this hook.
1043 *
1044 * This callback is used by the atomic modeset helpers and by the
1045 * transitional plane helpers, but it is optional.
1046 *
1047 * RETURNS:
1048 *
1049 * 0 on success or one of the following negative error codes allowed by
Daniel Vetter6806cdf2017-01-25 07:26:43 +01001050 * the &drm_mode_config_funcs.atomic_commit vfunc. When using helpers
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001051 * this callback is the only one which can fail an atomic commit,
1052 * everything else must complete successfully.
1053 */
Daniel Vetter092d01d2015-12-04 09:45:44 +01001054 int (*prepare_fb)(struct drm_plane *plane,
Chris Wilson18320402016-08-18 19:00:16 +01001055 struct drm_plane_state *new_state);
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001056 /**
1057 * @cleanup_fb:
1058 *
1059 * This hook is called to clean up any resources allocated for the given
1060 * framebuffer and plane configuration in @prepare_fb.
1061 *
1062 * This callback is used by the atomic modeset helpers and by the
1063 * transitional plane helpers, but it is optional.
1064 */
Daniel Vetter092d01d2015-12-04 09:45:44 +01001065 void (*cleanup_fb)(struct drm_plane *plane,
Chris Wilson18320402016-08-18 19:00:16 +01001066 struct drm_plane_state *old_state);
Daniel Vetter092d01d2015-12-04 09:45:44 +01001067
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001068 /**
1069 * @atomic_check:
1070 *
1071 * Drivers should check plane specific constraints in this hook.
1072 *
Daniel Vetter6806cdf2017-01-25 07:26:43 +01001073 * When using drm_atomic_helper_check_planes() plane's @atomic_check
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001074 * hooks are called before the ones for CRTCs, which allows drivers to
1075 * request shared resources that the CRTC controls here. For more
1076 * complicated dependencies the driver can call the provided check helpers
1077 * multiple times until the computed state has a final configuration and
1078 * everything has been checked.
1079 *
1080 * This function is also allowed to inspect any other object's state and
1081 * can add more state objects to the atomic commit if needed. Care must
Daniel Vetter6806cdf2017-01-25 07:26:43 +01001082 * be taken though to ensure that state check and compute functions for
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001083 * these added states are all called, and derived state in other objects
1084 * all updated. Again the recommendation is to just call check helpers
1085 * until a maximal configuration is reached.
1086 *
1087 * This callback is used by the atomic modeset helpers and by the
1088 * transitional plane helpers, but it is optional.
1089 *
1090 * NOTE:
1091 *
1092 * This function is called in the check phase of an atomic update. The
1093 * driver is not allowed to change anything outside of the free-standing
1094 * state objects passed-in or assembled in the overall &drm_atomic_state
1095 * update tracking structure.
1096 *
1097 * RETURNS:
1098 *
1099 * 0 on success, -EINVAL if the state or the transition can't be
1100 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
1101 * attempt to obtain another state object ran into a &drm_modeset_lock
1102 * deadlock.
1103 */
Daniel Vetter092d01d2015-12-04 09:45:44 +01001104 int (*atomic_check)(struct drm_plane *plane,
1105 struct drm_plane_state *state);
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001106
1107 /**
1108 * @atomic_update:
1109 *
1110 * Drivers should use this function to update the plane state. This
Daniel Vetter6806cdf2017-01-25 07:26:43 +01001111 * hook is called in-between the &drm_crtc_helper_funcs.atomic_begin and
1112 * drm_crtc_helper_funcs.atomic_flush callbacks.
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001113 *
1114 * Note that the power state of the display pipe when this function is
1115 * called depends upon the exact helpers and calling sequence the driver
Stefan Agner0dc99672016-10-31 10:36:46 -07001116 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
1117 * the tradeoffs and variants of plane commit helpers.
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001118 *
1119 * This callback is used by the atomic modeset helpers and by the
1120 * transitional plane helpers, but it is optional.
1121 */
Daniel Vetter092d01d2015-12-04 09:45:44 +01001122 void (*atomic_update)(struct drm_plane *plane,
1123 struct drm_plane_state *old_state);
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001124 /**
1125 * @atomic_disable:
1126 *
1127 * Drivers should use this function to unconditionally disable a plane.
Daniel Vetter6806cdf2017-01-25 07:26:43 +01001128 * This hook is called in-between the
1129 * &drm_crtc_helper_funcs.atomic_begin and
1130 * drm_crtc_helper_funcs.atomic_flush callbacks. It is an alternative to
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001131 * @atomic_update, which will be called for disabling planes, too, if
1132 * the @atomic_disable hook isn't implemented.
1133 *
1134 * This hook is also useful to disable planes in preparation of a modeset,
1135 * by calling drm_atomic_helper_disable_planes_on_crtc() from the
Daniel Vetter6806cdf2017-01-25 07:26:43 +01001136 * &drm_crtc_helper_funcs.disable hook.
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001137 *
1138 * Note that the power state of the display pipe when this function is
1139 * called depends upon the exact helpers and calling sequence the driver
Stefan Agner0dc99672016-10-31 10:36:46 -07001140 * has picked. See drm_atomic_helper_commit_planes() for a discussion of
1141 * the tradeoffs and variants of plane commit helpers.
Daniel Vetter11a0ba92015-12-04 09:46:04 +01001142 *
1143 * This callback is used by the atomic modeset helpers and by the
1144 * transitional plane helpers, but it is optional.
1145 */
Daniel Vetter092d01d2015-12-04 09:45:44 +01001146 void (*atomic_disable)(struct drm_plane *plane,
1147 struct drm_plane_state *old_state);
Gustavo Padovanfef9df82017-06-30 15:03:17 -03001148
1149 /**
1150 * @atomic_async_check:
1151 *
1152 * Drivers should set this function pointer to check if the plane state
1153 * can be updated in a async fashion. Here async means "not vblank
1154 * synchronized".
1155 *
1156 * This hook is called by drm_atomic_async_check() to establish if a
1157 * given update can be committed asynchronously, that is, if it can
1158 * jump ahead of the state currently queued for update.
1159 *
1160 * RETURNS:
1161 *
1162 * Return 0 on success and any error returned indicates that the update
1163 * can not be applied in asynchronous manner.
1164 */
1165 int (*atomic_async_check)(struct drm_plane *plane,
1166 struct drm_plane_state *state);
1167
1168 /**
1169 * @atomic_async_update:
1170 *
1171 * Drivers should set this function pointer to perform asynchronous
1172 * updates of planes, that is, jump ahead of the currently queued
1173 * state and update the plane. Here async means "not vblank
1174 * synchronized".
1175 *
1176 * This hook is called by drm_atomic_helper_async_commit().
1177 *
1178 * An async update will happen on legacy cursor updates. An async
1179 * update won't happen if there is an outstanding commit modifying
1180 * the same plane.
1181 *
1182 * Note that unlike &drm_plane_helper_funcs.atomic_update this hook
1183 * takes the new &drm_plane_state as parameter. When doing async_update
1184 * drivers shouldn't replace the &drm_plane_state but update the
1185 * current one with the new plane configurations in the new
1186 * plane_state.
1187 *
1188 * FIXME:
1189 * - It only works for single plane updates
1190 * - Async Pageflips are not supported yet
1191 * - Some hw might still scan out the old buffer until the next
Daniel Vetterc92883a2017-07-31 13:17:33 +02001192 * vblank, however we let go of the fb references as soon as
1193 * we run this hook. For now drivers must implement their own workers
1194 * for deferring if needed, until a common solution is created.
Gustavo Padovanfef9df82017-06-30 15:03:17 -03001195 */
1196 void (*atomic_async_update)(struct drm_plane *plane,
1197 struct drm_plane_state *new_state);
Daniel Vetter092d01d2015-12-04 09:45:44 +01001198};
1199
1200/**
1201 * drm_plane_helper_add - sets the helper vtable for a plane
1202 * @plane: DRM plane
1203 * @funcs: helper vtable to set for @plane
1204 */
1205static inline void drm_plane_helper_add(struct drm_plane *plane,
1206 const struct drm_plane_helper_funcs *funcs)
1207{
1208 plane->helper_private = funcs;
1209}
1210
Daniel Vetter9f2a7952016-06-08 14:19:02 +02001211/**
1212 * struct drm_mode_config_helper_funcs - global modeset helper operations
1213 *
1214 * These helper functions are used by the atomic helpers.
1215 */
1216struct drm_mode_config_helper_funcs {
1217 /**
1218 * @atomic_commit_tail:
1219 *
1220 * This hook is used by the default atomic_commit() hook implemented in
1221 * drm_atomic_helper_commit() together with the nonblocking commit
1222 * helpers (see drm_atomic_helper_setup_commit() for a starting point)
1223 * to implement blocking and nonblocking commits easily. It is not used
1224 * by the atomic helpers
1225 *
Daniel Vetter1ea0c022016-11-21 18:18:02 +01001226 * This function is called when the new atomic state has already been
1227 * swapped into the various state pointers. The passed in state
1228 * therefore contains copies of the old/previous state. This hook should
1229 * commit the new state into hardware. Note that the helpers have
1230 * already waited for preceeding atomic commits and fences, but drivers
1231 * can add more waiting calls at the start of their implementation, e.g.
1232 * to wait for driver-internal request for implicit syncing, before
1233 * starting to commit the update to the hardware.
Daniel Vetter9f2a7952016-06-08 14:19:02 +02001234 *
1235 * After the atomic update is committed to the hardware this hook needs
1236 * to call drm_atomic_helper_commit_hw_done(). Then wait for the upate
1237 * to be executed by the hardware, for example using
Boris Brezillon01086482017-06-02 10:32:06 +02001238 * drm_atomic_helper_wait_for_vblanks() or
1239 * drm_atomic_helper_wait_for_flip_done(), and then clean up the old
Daniel Vetter9f2a7952016-06-08 14:19:02 +02001240 * framebuffers using drm_atomic_helper_cleanup_planes().
1241 *
1242 * When disabling a CRTC this hook _must_ stall for the commit to
1243 * complete. Vblank waits don't work on disabled CRTC, hence the core
1244 * can't take care of this. And it also can't rely on the vblank event,
1245 * since that can be signalled already when the screen shows black,
1246 * which can happen much earlier than the last hardware access needed to
1247 * shut off the display pipeline completely.
1248 *
1249 * This hook is optional, the default implementation is
1250 * drm_atomic_helper_commit_tail().
1251 */
1252 void (*atomic_commit_tail)(struct drm_atomic_state *state);
1253};
1254
Daniel Vetter092d01d2015-12-04 09:45:44 +01001255#endif