File Index
Files and directories
Sign in
FILE

drm_modeset_helper_vtables.h

File preview with syntax highlighting.

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