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 51 enum mode_set_atomic; 52 struct drm_writeback_connector; 53 struct 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 */ 61 struct 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 objects passed-in or assembled in the overall &drm_atomic_state 340 * update tracking structure. 341 * 342 * Also beware that userspace can request its own custom modes, neither 343 * core nor helpers filter modes to the list of probe modes reported by 344 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure 345 * that modes are filtered consistently put any CRTC constraints and 346 * limits checks into @mode_valid. 347 * 348 * RETURNS: 349 * 350 * 0 on success, -EINVAL if the state or the transition can't be 351 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an 352 * attempt to obtain another state object ran into a &drm_modeset_lock 353 * deadlock. 354 */ 355 int (*atomic_check)(struct drm_crtc *crtc, 356 struct drm_crtc_state *state); 357 358 /** 359 * @atomic_begin: 360 * 361 * Drivers should prepare for an atomic update of multiple planes on 362 * a CRTC in this hook. Depending upon hardware this might be vblank 363 * evasion, blocking updates by setting bits or doing preparatory work 364 * for e.g. manual update display. 365 * 366 * This hook is called before any plane commit functions are called. 367 * 368 * Note that the power state of the display pipe when this function is 369 * called depends upon the exact helpers and calling sequence the driver 370 * has picked. See drm_atomic_helper_commit_planes() for a discussion of 371 * the tradeoffs and variants of plane commit helpers. 372 * 373 * This callback is used by the atomic modeset helpers and by the 374 * transitional plane helpers, but it is optional. 375 */ 376 void (*atomic_begin)(struct drm_crtc *crtc, 377 struct drm_crtc_state *old_crtc_state); 378 /** 379 * @atomic_flush: 380 * 381 * Drivers should finalize an atomic update of multiple planes on 382 * a CRTC in this hook. Depending upon hardware this might include 383 * checking that vblank evasion was successful, unblocking updates by 384 * setting bits or setting the GO bit to flush out all updates. 385 * 386 * Simple hardware or hardware with special requirements can commit and 387 * flush out all updates for all planes from this hook and forgo all the 388 * other commit hooks for plane updates. 389 * 390 * This hook is called after any plane commit functions are called. 391 * 392 * Note that the power state of the display pipe when this function is 393 * called depends upon the exact helpers and calling sequence the driver 394 * has picked. See drm_atomic_helper_commit_planes() for a discussion of 395 * the tradeoffs and variants of plane commit helpers. 396 * 397 * This callback is used by the atomic modeset helpers and by the 398 * transitional plane helpers, but it is optional. 399 */ 400 void (*atomic_flush)(struct drm_crtc *crtc, 401 struct drm_crtc_state *old_crtc_state); 402 403 /** 404 * @atomic_enable: 405 * 406 * This callback should be used to enable the CRTC. With the atomic 407 * drivers it is called before all encoders connected to this CRTC are 408 * enabled through the encoder's own &drm_encoder_helper_funcs.enable 409 * hook. If that sequence is too simple drivers can just add their own 410 * hooks and call it from this CRTC callback here by looping over all 411 * encoders connected to it using for_each_encoder_on_crtc(). 412 * 413 * This hook is used only by atomic helpers, for symmetry with 414 * @atomic_disable. Atomic drivers don't need to implement it if there's 415 * no need to enable anything at the CRTC level. To ensure that runtime 416 * PM handling (using either DPMS or the new "ACTIVE" property) works 417 * @atomic_enable must be the inverse of @atomic_disable for atomic 418 * drivers. 419 * 420 * This function is optional. 421 */ 422 void (*atomic_enable)(struct drm_crtc *crtc, 423 struct drm_atomic_state *state); 424 425 /** 426 * @atomic_disable: 427 * 428 * This callback should be used to disable the CRTC. With the atomic 429 * drivers it is called after all encoders connected to this CRTC have 430 * been shut off already using their own 431 * &drm_encoder_helper_funcs.disable hook. If that sequence is too 432 * simple drivers can just add their own hooks and call it from this 433 * CRTC callback here by looping over all encoders connected to it using 434 * for_each_encoder_on_crtc(). 435 * 436 * This hook is used only by atomic helpers. Atomic drivers don't 437 * need to implement it if there's no need to disable anything at the 438 * CRTC level. 439 * 440 * This function is optional. 441 */ 442 void (*atomic_disable)(struct drm_crtc *crtc, 443 struct drm_atomic_state *state); 444 445 /** 446 * @get_scanout_position: 447 * 448 * Called by vblank timestamping code. 449 * 450 * Returns the current display scanout position from a CRTC and an 451 * optional accurate ktime_get() timestamp of when the position was 452 * measured. Note that this is a helper callback which is only used 453 * if a driver uses drm_crtc_vblank_helper_get_vblank_timestamp() 454 * for the @drm_crtc_funcs.get_vblank_timestamp callback. 455 * 456 * Parameters: 457 * 458 * crtc: 459 * The CRTC. 460 * in_vblank_irq: 461 * True when called from drm_crtc_handle_vblank(). Some drivers 462 * need to apply some workarounds for gpu-specific vblank irq 463 * quirks if the flag is set. 464 * vpos: 465 * Target location for current vertical scanout position. 466 * hpos: 467 * Target location for current horizontal scanout position. 468 * stime: 469 * Target location for timestamp taken immediately before 470 * scanout position query. Can be NULL to skip timestamp. 471 * etime: 472 * Target location for timestamp taken immediately after 473 * scanout position query. Can be NULL to skip timestamp. 474 * mode: 475 * Current display timings. 476 * 477 * Returns vpos as a positive number while in active scanout area. 478 * Returns vpos as a negative number inside vblank, counting the number 479 * of scanlines to go until end of vblank, e.g., -1 means "one scanline 480 * until start of active scanout / end of vblank." 481 * 482 * Returns: 483 * 484 * True on success, false if a reliable scanout position counter could 485 * not be read out. 486 */ 487 bool (*get_scanout_position)(struct drm_crtc *crtc, 488 bool in_vblank_irq, int *vpos, int *hpos, 489 ktime_t *stime, ktime_t *etime, 490 const struct drm_display_mode *mode); 491 }; 492 493 /** 494 * drm_crtc_helper_add - sets the helper vtable for a crtc 495 * @crtc: DRM CRTC 496 * @funcs: helper vtable to set for @crtc 497 */ 498 static inline void drm_crtc_helper_add(struct drm_crtc *crtc, 499 const struct drm_crtc_helper_funcs *funcs) 500 { 501 crtc->helper_private = funcs; 502 } 503 504 /** 505 * struct drm_encoder_helper_funcs - helper operations for encoders 506 * 507 * These hooks are used by the legacy CRTC helpers, the transitional plane 508 * helpers and the new atomic modesetting helpers. 509 */ 510 struct drm_encoder_helper_funcs { 511 /** 512 * @dpms: 513 * 514 * Callback to control power levels on the encoder. If the mode passed in 515 * is unsupported, the provider must use the next lowest power level. 516 * This is used by the legacy encoder helpers to implement DPMS 517 * functionality in drm_helper_connector_dpms(). 518 * 519 * This callback is also used to disable an encoder by calling it with 520 * DRM_MODE_DPMS_OFF if the @disable hook isn't used. 521 * 522 * This callback is used by the legacy CRTC helpers. Atomic helpers 523 * also support using this hook for enabling and disabling an encoder to 524 * facilitate transitions to atomic, but it is deprecated. Instead 525 * @enable and @disable should be used. 526 */ 527 void (*dpms)(struct drm_encoder *encoder, int mode); 528 529 /** 530 * @mode_valid: 531 * 532 * This callback is used to check if a specific mode is valid in this 533 * encoder. This should be implemented if the encoder has some sort 534 * of restriction in the modes it can display. For example, a given 535 * encoder may be responsible to set a clock value. If the clock can 536 * not produce all the values for the available modes then this callback 537 * can be used to restrict the number of modes to only the ones that 538 * can be displayed. 539 * 540 * This hook is used by the probe helpers to filter the mode list in 541 * drm_helper_probe_single_connector_modes(), and it is used by the 542 * atomic helpers to validate modes supplied by userspace in 543 * drm_atomic_helper_check_modeset(). 544 * 545 * This function is optional. 546 * 547 * NOTE: 548 * 549 * Since this function is both called from the check phase of an atomic 550 * commit, and the mode validation in the probe paths it is not allowed 551 * to look at anything else but the passed-in mode, and validate it 552 * against configuration-invariant hardward constraints. Any further 553 * limits which depend upon the configuration can only be checked in 554 * @mode_fixup or @atomic_check. 555 * 556 * RETURNS: 557 * 558 * drm_mode_status Enum 559 */ 560 enum drm_mode_status (*mode_valid)(struct drm_encoder *crtc, 561 const struct drm_display_mode *mode); 562 563 /** 564 * @mode_fixup: 565 * 566 * This callback is used to validate and adjust a mode. The parameter 567 * mode is the display mode that should be fed to the next element in 568 * the display chain, either the final &drm_connector or a &drm_bridge. 569 * The parameter adjusted_mode is the input mode the encoder requires. It 570 * can be modified by this callback and does not need to match mode. See 571 * also &drm_crtc_state.adjusted_mode for more details. 572 * 573 * This function is used by both legacy CRTC helpers and atomic helpers. 574 * This hook is optional. 575 * 576 * NOTE: 577 * 578 * This function is called in the check phase of atomic modesets, which 579 * can be aborted for any reason (including on userspace's request to 580 * just check whether a configuration would be possible). Atomic drivers 581 * MUST NOT touch any persistent state (hardware or software) or data 582 * structures except the passed in adjusted_mode parameter. 583 * 584 * This is in contrast to the legacy CRTC helpers where this was 585 * allowed. 586 * 587 * Atomic drivers which need to inspect and adjust more state should 588 * instead use the @atomic_check callback. If @atomic_check is used, 589 * this hook isn't called since @atomic_check allows a strict superset 590 * of the functionality of @mode_fixup. 591 * 592 * Also beware that userspace can request its own custom modes, neither 593 * core nor helpers filter modes to the list of probe modes reported by 594 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure 595 * that modes are filtered consistently put any encoder constraints and 596 * limits checks into @mode_valid. 597 * 598 * RETURNS: 599 * 600 * True if an acceptable configuration is possible, false if the modeset 601 * operation should be rejected. 602 */ 603 bool (*mode_fixup)(struct drm_encoder *encoder, 604 const struct drm_display_mode *mode, 605 struct drm_display_mode *adjusted_mode); 606 607 /** 608 * @prepare: 609 * 610 * This callback should prepare the encoder for a subsequent modeset, 611 * which in practice means the driver should disable the encoder if it 612 * is running. Most drivers ended up implementing this by calling their 613 * @dpms hook with DRM_MODE_DPMS_OFF. 614 * 615 * This callback is used by the legacy CRTC helpers. Atomic helpers 616 * also support using this hook for disabling an encoder to facilitate 617 * transitions to atomic, but it is deprecated. Instead @disable should 618 * be used. 619 */ 620 void (*prepare)(struct drm_encoder *encoder); 621 622 /** 623 * @commit: 624 * 625 * This callback should commit the new mode on the encoder after a modeset, 626 * which in practice means the driver should enable the encoder. Most 627 * drivers ended up implementing this by calling their @dpms hook with 628 * DRM_MODE_DPMS_ON. 629 * 630 * This callback is used by the legacy CRTC helpers. Atomic helpers 631 * also support using this hook for enabling an encoder to facilitate 632 * transitions to atomic, but it is deprecated. Instead @enable should 633 * be used. 634 */ 635 void (*commit)(struct drm_encoder *encoder); 636 637 /** 638 * @mode_set: 639 * 640 * This callback is used to update the display mode of an encoder. 641 * 642 * Note that the display pipe is completely off when this function is 643 * called. Drivers which need hardware to be running before they program 644 * the new display mode (because they implement runtime PM) should not 645 * use this hook, because the helper library calls it only once and not 646 * every time the display pipeline is suspend using either DPMS or the 647 * new "ACTIVE" property. Such drivers should instead move all their 648 * encoder setup into the @enable callback. 649 * 650 * This callback is used both by the legacy CRTC helpers and the atomic 651 * modeset helpers. It is optional in the atomic helpers. 652 * 653 * NOTE: 654 * 655 * If the driver uses the atomic modeset helpers and needs to inspect 656 * the connector state or connector display info during mode setting, 657 * @atomic_mode_set can be used instead. 658 */ 659 void (*mode_set)(struct drm_encoder *encoder, 660 struct drm_display_mode *mode, 661 struct drm_display_mode *adjusted_mode); 662 663 /** 664 * @atomic_mode_set: 665 * 666 * This callback is used to update the display mode of an encoder. 667 * 668 * Note that the display pipe is completely off when this function is 669 * called. Drivers which need hardware to be running before they program 670 * the new display mode (because they implement runtime PM) should not 671 * use this hook, because the helper library calls it only once and not 672 * every time the display pipeline is suspended using either DPMS or the 673 * new "ACTIVE" property. Such drivers should instead move all their 674 * encoder setup into the @enable callback. 675 * 676 * This callback is used by the atomic modeset helpers in place of the 677 * @mode_set callback, if set by the driver. It is optional and should 678 * be used instead of @mode_set if the driver needs to inspect the 679 * connector state or display info, since there is no direct way to 680 * go from the encoder to the current connector. 681 */ 682 void (*atomic_mode_set)(struct drm_encoder *encoder, 683 struct drm_crtc_state *crtc_state, 684 struct drm_connector_state *conn_state); 685 686 /** 687 * @detect: 688 * 689 * This callback can be used by drivers who want to do detection on the 690 * encoder object instead of in connector functions. 691 * 692 * It is not used by any helper and therefore has purely driver-specific 693 * semantics. New drivers shouldn't use this and instead just implement 694 * their own private callbacks. 695 * 696 * FIXME: 697 * 698 * This should just be converted into a pile of driver vfuncs. 699 * Currently radeon, amdgpu and nouveau are using it. 700 */ 701 enum drm_connector_status (*detect)(struct drm_encoder *encoder, 702 struct drm_connector *connector); 703 704 /** 705 * @atomic_disable: 706 * 707 * This callback should be used to disable the encoder. With the atomic 708 * drivers it is called before this encoder's CRTC has been shut off 709 * using their own &drm_crtc_helper_funcs.atomic_disable hook. If that 710 * sequence is too simple drivers can just add their own driver private 711 * encoder hooks and call them from CRTC's callback by looping over all 712 * encoders connected to it using for_each_encoder_on_crtc(). 713 * 714 * This callback is a variant of @disable that provides the atomic state 715 * to the driver. If @atomic_disable is implemented, @disable is not 716 * called by the helpers. 717 * 718 * This hook is only used by atomic helpers. Atomic drivers don't need 719 * to implement it if there's no need to disable anything at the encoder 720 * level. To ensure that runtime PM handling (using either DPMS or the 721 * new "ACTIVE" property) works @atomic_disable must be the inverse of 722 * @atomic_enable. 723 */ 724 void (*atomic_disable)(struct drm_encoder *encoder, 725 struct drm_atomic_state *state); 726 727 /** 728 * @atomic_enable: 729 * 730 * This callback should be used to enable the encoder. It is called 731 * after this encoder's CRTC has been enabled using their own 732 * &drm_crtc_helper_funcs.atomic_enable hook. If that sequence is 733 * too simple drivers can just add their own driver private encoder 734 * hooks and call them from CRTC's callback by looping over all encoders 735 * connected to it using for_each_encoder_on_crtc(). 736 * 737 * This callback is a variant of @enable that provides the atomic state 738 * to the driver. If @atomic_enable is implemented, @enable is not 739 * called by the helpers. 740 * 741 * This hook is only used by atomic helpers, it is the opposite of 742 * @atomic_disable. Atomic drivers don't need to implement it if there's 743 * no need to enable anything at the encoder level. To ensure that 744 * runtime PM handling works @atomic_enable must be the inverse of 745 * @atomic_disable. 746 */ 747 void (*atomic_enable)(struct drm_encoder *encoder, 748 struct drm_atomic_state *state); 749 750 /** 751 * @disable: 752 * 753 * This callback should be used to disable the encoder. With the atomic 754 * drivers it is called before this encoder's CRTC has been shut off 755 * using their own &drm_crtc_helper_funcs.disable hook. If that 756 * sequence is too simple drivers can just add their own driver private 757 * encoder hooks and call them from CRTC's callback by looping over all 758 * encoders connected to it using for_each_encoder_on_crtc(). 759 * 760 * This hook is used both by legacy CRTC helpers and atomic helpers. 761 * Atomic drivers don't need to implement it if there's no need to 762 * disable anything at the encoder level. To ensure that runtime PM 763 * handling (using either DPMS or the new "ACTIVE" property) works 764 * @disable must be the inverse of @enable for atomic drivers. 765 * 766 * For atomic drivers also consider @atomic_disable and save yourself 767 * from having to read the NOTE below! 768 * 769 * NOTE: 770 * 771 * With legacy CRTC helpers there's a big semantic difference between 772 * @disable and other hooks (like @prepare or @dpms) used to shut down a 773 * encoder: @disable is only called when also logically disabling the 774 * display pipeline and needs to release any resources acquired in 775 * @mode_set (like shared PLLs, or again release pinned framebuffers). 776 * 777 * Therefore @disable must be the inverse of @mode_set plus @commit for 778 * drivers still using legacy CRTC helpers, which is different from the 779 * rules under atomic. 780 */ 781 void (*disable)(struct drm_encoder *encoder); 782 783 /** 784 * @enable: 785 * 786 * This callback should be used to enable the encoder. With the atomic 787 * drivers it is called after this encoder's CRTC has been enabled using 788 * their own &drm_crtc_helper_funcs.enable hook. If that sequence is 789 * too simple drivers can just add their own driver private encoder 790 * hooks and call them from CRTC's callback by looping over all encoders 791 * connected to it using for_each_encoder_on_crtc(). 792 * 793 * This hook is only used by atomic helpers, it is the opposite of 794 * @disable. Atomic drivers don't need to implement it if there's no 795 * need to enable anything at the encoder level. To ensure that 796 * runtime PM handling (using either DPMS or the new "ACTIVE" property) 797 * works @enable must be the inverse of @disable for atomic drivers. 798 */ 799 void (*enable)(struct drm_encoder *encoder); 800 801 /** 802 * @atomic_check: 803 * 804 * This callback is used to validate encoder state for atomic drivers. 805 * Since the encoder is the object connecting the CRTC and connector it 806 * gets passed both states, to be able to validate interactions and 807 * update the CRTC to match what the encoder needs for the requested 808 * connector. 809 * 810 * Since this provides a strict superset of the functionality of 811 * @mode_fixup (the requested and adjusted modes are both available 812 * through the passed in &struct drm_crtc_state) @mode_fixup is not 813 * called when @atomic_check is implemented. 814 * 815 * This function is used by the atomic helpers, but it is optional. 816 * 817 * NOTE: 818 * 819 * This function is called in the check phase of an atomic update. The 820 * driver is not allowed to change anything outside of the free-standing 821 * state objects passed-in or assembled in the overall &drm_atomic_state 822 * update tracking structure. 823 * 824 * Also beware that userspace can request its own custom modes, neither 825 * core nor helpers filter modes to the list of probe modes reported by 826 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure 827 * that modes are filtered consistently put any encoder constraints and 828 * limits checks into @mode_valid. 829 * 830 * RETURNS: 831 * 832 * 0 on success, -EINVAL if the state or the transition can't be 833 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an 834 * attempt to obtain another state object ran into a &drm_modeset_lock 835 * deadlock. 836 */ 837 int (*atomic_check)(struct drm_encoder *encoder, 838 struct drm_crtc_state *crtc_state, 839 struct drm_connector_state *conn_state); 840 }; 841 842 /** 843 * drm_encoder_helper_add - sets the helper vtable for an encoder 844 * @encoder: DRM encoder 845 * @funcs: helper vtable to set for @encoder 846 */ 847 static inline void drm_encoder_helper_add(struct drm_encoder *encoder, 848 const struct drm_encoder_helper_funcs *funcs) 849 { 850 encoder->helper_private = funcs; 851 } 852 853 /** 854 * struct drm_connector_helper_funcs - helper operations for connectors 855 * 856 * These functions are used by the atomic and legacy modeset helpers and by the 857 * probe helpers. 858 */ 859 struct drm_connector_helper_funcs { 860 /** 861 * @get_modes: 862 * 863 * This function should fill in all modes currently valid for the sink 864 * into the &drm_connector.probed_modes list. It should also update the 865 * EDID property by calling drm_connector_update_edid_property(). 866 * 867 * The usual way to implement this is to cache the EDID retrieved in the 868 * probe callback somewhere in the driver-private connector structure. 869 * In this function drivers then parse the modes in the EDID and add 870 * them by calling drm_add_edid_modes(). But connectors that driver a 871 * fixed panel can also manually add specific modes using 872 * drm_mode_probed_add(). Drivers which manually add modes should also 873 * make sure that the &drm_connector.display_info, 874 * &drm_connector.width_mm and &drm_connector.height_mm fields are 875 * filled in. 876 * 877 * Virtual drivers that just want some standard VESA mode with a given 878 * resolution can call drm_add_modes_noedid(), and mark the preferred 879 * one using drm_set_preferred_mode(). 880 * 881 * This function is only called after the @detect hook has indicated 882 * that a sink is connected and when the EDID isn't overridden through 883 * sysfs or the kernel commandline. 884 * 885 * This callback is used by the probe helpers in e.g. 886 * drm_helper_probe_single_connector_modes(). 887 * 888 * To avoid races with concurrent connector state updates, the helper 889 * libraries always call this with the &drm_mode_config.connection_mutex 890 * held. Because of this it's safe to inspect &drm_connector->state. 891 * 892 * RETURNS: 893 * 894 * The number of modes added by calling drm_mode_probed_add(). 895 */ 896 int (*get_modes)(struct drm_connector *connector); 897 898 /** 899 * @detect_ctx: 900 * 901 * Check to see if anything is attached to the connector. The parameter 902 * force is set to false whilst polling, true when checking the 903 * connector due to a user request. force can be used by the driver to 904 * avoid expensive, destructive operations during automated probing. 905 * 906 * This callback is optional, if not implemented the connector will be 907 * considered as always being attached. 908 * 909 * This is the atomic version of &drm_connector_funcs.detect. 910 * 911 * To avoid races against concurrent connector state updates, the 912 * helper libraries always call this with ctx set to a valid context, 913 * and &drm_mode_config.connection_mutex will always be locked with 914 * the ctx parameter set to this ctx. This allows taking additional 915 * locks as required. 916 * 917 * RETURNS: 918 * 919 * &drm_connector_status indicating the connector's status, 920 * or the error code returned by drm_modeset_lock(), -EDEADLK. 921 */ 922 int (*detect_ctx)(struct drm_connector *connector, 923 struct drm_modeset_acquire_ctx *ctx, 924 bool force); 925 926 /** 927 * @mode_valid: 928 * 929 * Callback to validate a mode for a connector, irrespective of the 930 * specific display configuration. 931 * 932 * This callback is used by the probe helpers to filter the mode list 933 * (which is usually derived from the EDID data block from the sink). 934 * See e.g. drm_helper_probe_single_connector_modes(). 935 * 936 * This function is optional. 937 * 938 * NOTE: 939 * 940 * This only filters the mode list supplied to userspace in the 941 * GETCONNECTOR IOCTL. Compared to &drm_encoder_helper_funcs.mode_valid, 942 * &drm_crtc_helper_funcs.mode_valid and &drm_bridge_funcs.mode_valid, 943 * which are also called by the atomic helpers from 944 * drm_atomic_helper_check_modeset(). This allows userspace to force and 945 * ignore sink constraint (like the pixel clock limits in the screen's 946 * EDID), which is useful for e.g. testing, or working around a broken 947 * EDID. Any source hardware constraint (which always need to be 948 * enforced) therefore should be checked in one of the above callbacks, 949 * and not this one here. 950 * 951 * To avoid races with concurrent connector state updates, the helper 952 * libraries always call this with the &drm_mode_config.connection_mutex 953 * held. Because of this it's safe to inspect &drm_connector->state. 954 * 955 * RETURNS: 956 * 957 * Either &drm_mode_status.MODE_OK or one of the failure reasons in &enum 958 * drm_mode_status. 959 */ 960 enum drm_mode_status (*mode_valid)(struct drm_connector *connector, 961 struct drm_display_mode *mode); 962 963 /** 964 * @mode_valid_ctx: 965 * 966 * Callback to validate a mode for a connector, irrespective of the 967 * specific display configuration. 968 * 969 * This callback is used by the probe helpers to filter the mode list 970 * (which is usually derived from the EDID data block from the sink). 971 * See e.g. drm_helper_probe_single_connector_modes(). 972 * 973 * This function is optional, and is the atomic version of 974 * &drm_connector_helper_funcs.mode_valid. 975 * 976 * To allow for accessing the atomic state of modesetting objects, the 977 * helper libraries always call this with ctx set to a valid context, 978 * and &drm_mode_config.connection_mutex will always be locked with 979 * the ctx parameter set to @ctx. This allows for taking additional 980 * locks as required. 981 * 982 * Even though additional locks may be acquired, this callback is 983 * still expected not to take any constraints into account which would 984 * be influenced by the currently set display state - such constraints 985 * should be handled in the driver's atomic check. For example, if a 986 * connector shares display bandwidth with other connectors then it 987 * would be ok to validate the minimum bandwidth requirement of a mode 988 * against the maximum possible bandwidth of the connector. But it 989 * wouldn't be ok to take the current bandwidth usage of other 990 * connectors into account, as this would change depending on the 991 * display state. 992 * 993 * Returns: 994 * 0 if &drm_connector_helper_funcs.mode_valid_ctx succeeded and wrote 995 * the &enum drm_mode_status value to @status, or a negative error 996 * code otherwise. 997 * 998 */ 999 int (*mode_valid_ctx)(struct drm_connector *connector, 1000 struct drm_display_mode *mode, 1001 struct drm_modeset_acquire_ctx *ctx, 1002 enum drm_mode_status *status); 1003 1004 /** 1005 * @best_encoder: 1006 * 1007 * This function should select the best encoder for the given connector. 1008 * 1009 * This function is used by both the atomic helpers (in the 1010 * drm_atomic_helper_check_modeset() function) and in the legacy CRTC 1011 * helpers. 1012 * 1013 * NOTE: 1014 * 1015 * In atomic drivers this function is called in the check phase of an 1016 * atomic update. The driver is not allowed to change or inspect 1017 * anything outside of arguments passed-in. Atomic drivers which need to 1018 * inspect dynamic configuration state should instead use 1019 * @atomic_best_encoder. 1020 * 1021 * You can leave this function to NULL if the connector is only 1022 * attached to a single encoder. In this case, the core will call 1023 * drm_connector_get_single_encoder() for you. 1024 * 1025 * RETURNS: 1026 * 1027 * Encoder that should be used for the given connector and connector 1028 * state, or NULL if no suitable encoder exists. Note that the helpers 1029 * will ensure that encoders aren't used twice, drivers should not check 1030 * for this. 1031 */ 1032 struct drm_encoder *(*best_encoder)(struct drm_connector *connector); 1033 1034 /** 1035 * @atomic_best_encoder: 1036 * 1037 * This is the atomic version of @best_encoder for atomic drivers which 1038 * need to select the best encoder depending upon the desired 1039 * configuration and can't select it statically. 1040 * 1041 * This function is used by drm_atomic_helper_check_modeset(). 1042 * If it is not implemented, the core will fallback to @best_encoder 1043 * (or drm_connector_get_single_encoder() if @best_encoder is NULL). 1044 * 1045 * NOTE: 1046 * 1047 * This function is called in the check phase of an atomic update. The 1048 * driver is not allowed to change anything outside of the free-standing 1049 * state objects passed-in or assembled in the overall &drm_atomic_state 1050 * update tracking structure. 1051 * 1052 * RETURNS: 1053 * 1054 * Encoder that should be used for the given connector and connector 1055 * state, or NULL if no suitable encoder exists. Note that the helpers 1056 * will ensure that encoders aren't used twice, drivers should not check 1057 * for this. 1058 */ 1059 struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector, 1060 struct drm_connector_state *connector_state); 1061 1062 /** 1063 * @atomic_check: 1064 * 1065 * This hook is used to validate connector state. This function is 1066 * called from &drm_atomic_helper_check_modeset, and is called when 1067 * a connector property is set, or a modeset on the crtc is forced. 1068 * 1069 * Because &drm_atomic_helper_check_modeset may be called multiple times, 1070 * this function should handle being called multiple times as well. 1071 * 1072 * This function is also allowed to inspect any other object's state and 1073 * can add more state objects to the atomic commit if needed. Care must 1074 * be taken though to ensure that state check and compute functions for 1075 * these added states are all called, and derived state in other objects 1076 * all updated. Again the recommendation is to just call check helpers 1077 * until a maximal configuration is reached. 1078 * 1079 * NOTE: 1080 * 1081 * This function is called in the check phase of an atomic update. The 1082 * driver is not allowed to change anything outside of the free-standing 1083 * state objects passed-in or assembled in the overall &drm_atomic_state 1084 * update tracking structure. 1085 * 1086 * RETURNS: 1087 * 1088 * 0 on success, -EINVAL if the state or the transition can't be 1089 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an 1090 * attempt to obtain another state object ran into a &drm_modeset_lock 1091 * deadlock. 1092 */ 1093 int (*atomic_check)(struct drm_connector *connector, 1094 struct drm_atomic_state *state); 1095 1096 /** 1097 * @atomic_commit: 1098 * 1099 * This hook is to be used by drivers implementing writeback connectors 1100 * that need a point when to commit the writeback job to the hardware. 1101 * The writeback_job to commit is available in 1102 * &drm_connector_state.writeback_job. 1103 * 1104 * This hook is optional. 1105 * 1106 * This callback is used by the atomic modeset helpers. 1107 */ 1108 void (*atomic_commit)(struct drm_connector *connector, 1109 struct drm_connector_state *state); 1110 1111 /** 1112 * @prepare_writeback_job: 1113 * 1114 * As writeback jobs contain a framebuffer, drivers may need to 1115 * prepare and clean them up the same way they can prepare and 1116 * clean up framebuffers for planes. This optional connector operation 1117 * is used to support the preparation of writeback jobs. The job 1118 * prepare operation is called from drm_atomic_helper_prepare_planes() 1119 * for struct &drm_writeback_connector connectors only. 1120 * 1121 * This operation is optional. 1122 * 1123 * This callback is used by the atomic modeset helpers. 1124 */ 1125 int (*prepare_writeback_job)(struct drm_writeback_connector *connector, 1126 struct drm_writeback_job *job); 1127 /** 1128 * @cleanup_writeback_job: 1129 * 1130 * This optional connector operation is used to support the 1131 * cleanup of writeback jobs. The job cleanup operation is called 1132 * from the existing drm_writeback_cleanup_job() function, invoked 1133 * both when destroying the job as part of an aborted commit, or when 1134 * the job completes. 1135 * 1136 * This operation is optional. 1137 * 1138 * This callback is used by the atomic modeset helpers. 1139 */ 1140 void (*cleanup_writeback_job)(struct drm_writeback_connector *connector, 1141 struct drm_writeback_job *job); 1142 }; 1143 1144 /** 1145 * drm_connector_helper_add - sets the helper vtable for a connector 1146 * @connector: DRM connector 1147 * @funcs: helper vtable to set for @connector 1148 */ 1149 static inline void drm_connector_helper_add(struct drm_connector *connector, 1150 const struct drm_connector_helper_funcs *funcs) 1151 { 1152 connector->helper_private = funcs; 1153 } 1154 1155 /** 1156 * struct drm_plane_helper_funcs - helper operations for planes 1157 * 1158 * These functions are used by the atomic helpers and by the transitional plane 1159 * helpers. 1160 */ 1161 struct drm_plane_helper_funcs { 1162 /** 1163 * @prepare_fb: 1164 * 1165 * This hook is to prepare a framebuffer for scanout by e.g. pinning 1166 * its backing storage or relocating it into a contiguous block of 1167 * VRAM. Other possible preparatory work includes flushing caches. 1168 * 1169 * This function must not block for outstanding rendering, since it is 1170 * called in the context of the atomic IOCTL even for async commits to 1171 * be able to return any errors to userspace. Instead the recommended 1172 * way is to fill out the &drm_plane_state.fence of the passed-in 1173 * &drm_plane_state. If the driver doesn't support native fences then 1174 * equivalent functionality should be implemented through private 1175 * members in the plane structure. 1176 * 1177 * Drivers which always have their buffers pinned should use 1178 * drm_gem_fb_prepare_fb() for this hook. 1179 * 1180 * The helpers will call @cleanup_fb with matching arguments for every 1181 * successful call to this hook. 1182 * 1183 * This callback is used by the atomic modeset helpers and by the 1184 * transitional plane helpers, but it is optional. 1185 * 1186 * RETURNS: 1187 * 1188 * 0 on success or one of the following negative error codes allowed by 1189 * the &drm_mode_config_funcs.atomic_commit vfunc. When using helpers 1190 * this callback is the only one which can fail an atomic commit, 1191 * everything else must complete successfully. 1192 */ 1193 int (*prepare_fb)(struct drm_plane *plane, 1194 struct drm_plane_state *new_state); 1195 /** 1196 * @cleanup_fb: 1197 * 1198 * This hook is called to clean up any resources allocated for the given 1199 * framebuffer and plane configuration in @prepare_fb. 1200 * 1201 * This callback is used by the atomic modeset helpers and by the 1202 * transitional plane helpers, but it is optional. 1203 */ 1204 void (*cleanup_fb)(struct drm_plane *plane, 1205 struct drm_plane_state *old_state); 1206 1207 /** 1208 * @atomic_check: 1209 * 1210 * Drivers should check plane specific constraints in this hook. 1211 * 1212 * When using drm_atomic_helper_check_planes() plane's @atomic_check 1213 * hooks are called before the ones for CRTCs, which allows drivers to 1214 * request shared resources that the CRTC controls here. For more 1215 * complicated dependencies the driver can call the provided check helpers 1216 * multiple times until the computed state has a final configuration and 1217 * everything has been checked. 1218 * 1219 * This function is also allowed to inspect any other object's state and 1220 * can add more state objects to the atomic commit if needed. Care must 1221 * be taken though to ensure that state check and compute functions for 1222 * these added states are all called, and derived state in other objects 1223 * all updated. Again the recommendation is to just call check helpers 1224 * until a maximal configuration is reached. 1225 * 1226 * This callback is used by the atomic modeset helpers and by the 1227 * transitional plane helpers, but it is optional. 1228 * 1229 * NOTE: 1230 * 1231 * This function is called in the check phase of an atomic update. The 1232 * driver is not allowed to change anything outside of the free-standing 1233 * state objects passed-in or assembled in the overall &drm_atomic_state 1234 * update tracking structure. 1235 * 1236 * RETURNS: 1237 * 1238 * 0 on success, -EINVAL if the state or the transition can't be 1239 * supported, -ENOMEM on memory allocation failure and -EDEADLK if an 1240 * attempt to obtain another state object ran into a &drm_modeset_lock 1241 * deadlock. 1242 */ 1243 int (*atomic_check)(struct drm_plane *plane, 1244 struct drm_plane_state *state); 1245 1246 /** 1247 * @atomic_update: 1248 * 1249 * Drivers should use this function to update the plane state. This 1250 * hook is called in-between the &drm_crtc_helper_funcs.atomic_begin and 1251 * drm_crtc_helper_funcs.atomic_flush callbacks. 1252 * 1253 * Note that the power state of the display pipe when this function is 1254 * called depends upon the exact helpers and calling sequence the driver 1255 * has picked. See drm_atomic_helper_commit_planes() for a discussion of 1256 * the tradeoffs and variants of plane commit helpers. 1257 * 1258 * This callback is used by the atomic modeset helpers and by the 1259 * transitional plane helpers, but it is optional. 1260 */ 1261 void (*atomic_update)(struct drm_plane *plane, 1262 struct drm_plane_state *old_state); 1263 /** 1264 * @atomic_disable: 1265 * 1266 * Drivers should use this function to unconditionally disable a plane. 1267 * This hook is called in-between the 1268 * &drm_crtc_helper_funcs.atomic_begin and 1269 * drm_crtc_helper_funcs.atomic_flush callbacks. It is an alternative to 1270 * @atomic_update, which will be called for disabling planes, too, if 1271 * the @atomic_disable hook isn't implemented. 1272 * 1273 * This hook is also useful to disable planes in preparation of a modeset, 1274 * by calling drm_atomic_helper_disable_planes_on_crtc() from the 1275 * &drm_crtc_helper_funcs.disable hook. 1276 * 1277 * Note that the power state of the display pipe when this function is 1278 * called depends upon the exact helpers and calling sequence the driver 1279 * has picked. See drm_atomic_helper_commit_planes() for a discussion of 1280 * the tradeoffs and variants of plane commit helpers. 1281 * 1282 * This callback is used by the atomic modeset helpers and by the 1283 * transitional plane helpers, but it is optional. 1284 */ 1285 void (*atomic_disable)(struct drm_plane *plane, 1286 struct drm_plane_state *old_state); 1287 1288 /** 1289 * @atomic_async_check: 1290 * 1291 * Drivers should set this function pointer to check if the plane state 1292 * can be updated in a async fashion. Here async means "not vblank 1293 * synchronized". 1294 * 1295 * This hook is called by drm_atomic_async_check() to establish if a 1296 * given update can be committed asynchronously, that is, if it can 1297 * jump ahead of the state currently queued for update. 1298 * 1299 * RETURNS: 1300 * 1301 * Return 0 on success and any error returned indicates that the update 1302 * can not be applied in asynchronous manner. 1303 */ 1304 int (*atomic_async_check)(struct drm_plane *plane, 1305 struct drm_plane_state *state); 1306 1307 /** 1308 * @atomic_async_update: 1309 * 1310 * Drivers should set this function pointer to perform asynchronous 1311 * updates of planes, that is, jump ahead of the currently queued 1312 * state and update the plane. Here async means "not vblank 1313 * synchronized". 1314 * 1315 * This hook is called by drm_atomic_helper_async_commit(). 1316 * 1317 * An async update will happen on legacy cursor updates. An async 1318 * update won't happen if there is an outstanding commit modifying 1319 * the same plane. 1320 * 1321 * Note that unlike &drm_plane_helper_funcs.atomic_update this hook 1322 * takes the new &drm_plane_state as parameter. When doing async_update 1323 * drivers shouldn't replace the &drm_plane_state but update the 1324 * current one with the new plane configurations in the new 1325 * plane_state. 1326 * 1327 * Drivers should also swap the framebuffers between current plane 1328 * state (&drm_plane.state) and new_state. 1329 * This is required since cleanup for async commits is performed on 1330 * the new state, rather than old state like for traditional commits. 1331 * Since we want to give up the reference on the current (old) fb 1332 * instead of our brand new one, swap them in the driver during the 1333 * async commit. 1334 * 1335 * FIXME: 1336 * - It only works for single plane updates 1337 * - Async Pageflips are not supported yet 1338 * - Some hw might still scan out the old buffer until the next 1339 * vblank, however we let go of the fb references as soon as 1340 * we run this hook. For now drivers must implement their own workers 1341 * for deferring if needed, until a common solution is created. 1342 */ 1343 void (*atomic_async_update)(struct drm_plane *plane, 1344 struct drm_plane_state *new_state); 1345 }; 1346 1347 /** 1348 * drm_plane_helper_add - sets the helper vtable for a plane 1349 * @plane: DRM plane 1350 * @funcs: helper vtable to set for @plane 1351 */ 1352 static inline void drm_plane_helper_add(struct drm_plane *plane, 1353 const struct drm_plane_helper_funcs *funcs) 1354 { 1355 plane->helper_private = funcs; 1356 } 1357 1358 /** 1359 * struct drm_mode_config_helper_funcs - global modeset helper operations 1360 * 1361 * These helper functions are used by the atomic helpers. 1362 */ 1363 struct drm_mode_config_helper_funcs { 1364 /** 1365 * @atomic_commit_tail: 1366 * 1367 * This hook is used by the default atomic_commit() hook implemented in 1368 * drm_atomic_helper_commit() together with the nonblocking commit 1369 * helpers (see drm_atomic_helper_setup_commit() for a starting point) 1370 * to implement blocking and nonblocking commits easily. It is not used 1371 * by the atomic helpers 1372 * 1373 * This function is called when the new atomic state has already been 1374 * swapped into the various state pointers. The passed in state 1375 * therefore contains copies of the old/previous state. This hook should 1376 * commit the new state into hardware. Note that the helpers have 1377 * already waited for preceeding atomic commits and fences, but drivers 1378 * can add more waiting calls at the start of their implementation, e.g. 1379 * to wait for driver-internal request for implicit syncing, before 1380 * starting to commit the update to the hardware. 1381 * 1382 * After the atomic update is committed to the hardware this hook needs 1383 * to call drm_atomic_helper_commit_hw_done(). Then wait for the upate 1384 * to be executed by the hardware, for example using 1385 * drm_atomic_helper_wait_for_vblanks() or 1386 * drm_atomic_helper_wait_for_flip_done(), and then clean up the old 1387 * framebuffers using drm_atomic_helper_cleanup_planes(). 1388 * 1389 * When disabling a CRTC this hook _must_ stall for the commit to 1390 * complete. Vblank waits don't work on disabled CRTC, hence the core 1391 * can't take care of this. And it also can't rely on the vblank event, 1392 * since that can be signalled already when the screen shows black, 1393 * which can happen much earlier than the last hardware access needed to 1394 * shut off the display pipeline completely. 1395 * 1396 * This hook is optional, the default implementation is 1397 * drm_atomic_helper_commit_tail(). 1398 */ 1399 void (*atomic_commit_tail)(struct drm_atomic_state *state); 1400 }; 1401 1402 #endif 1403