Linux Audio

Check our new training course

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