1 /* 2 * Copyright (C) 2014 Red Hat 3 * Copyright (C) 2014 Intel Corp. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 * OTHER DEALINGS IN THE SOFTWARE. 22 * 23 * Authors: 24 * Rob Clark <robdclark@gmail.com> 25 * Daniel Vetter <daniel.vetter@ffwll.ch> 26 */ 27 28 #ifndef DRM_ATOMIC_H_ 29 #define DRM_ATOMIC_H_ 30 31 #include <drm/drm_crtc.h> 32 #include <drm/drm_util.h> 33 34 /** 35 * struct drm_crtc_commit - track modeset commits on a CRTC 36 * 37 * This structure is used to track pending modeset changes and atomic commit on 38 * a per-CRTC basis. Since updating the list should never block, this structure 39 * is reference counted to allow waiters to safely wait on an event to complete, 40 * without holding any locks. 41 * 42 * It has 3 different events in total to allow a fine-grained synchronization 43 * between outstanding updates:: 44 * 45 * atomic commit thread hardware 46 * 47 * write new state into hardware ----> ... 48 * signal hw_done 49 * switch to new state on next 50 * ... v/hblank 51 * 52 * wait for buffers to show up ... 53 * 54 * ... send completion irq 55 * irq handler signals flip_done 56 * cleanup old buffers 57 * 58 * signal cleanup_done 59 * 60 * wait for flip_done <---- 61 * clean up atomic state 62 * 63 * The important bit to know is that &cleanup_done is the terminal event, but the 64 * ordering between &flip_done and &hw_done is entirely up to the specific driver 65 * and modeset state change. 66 * 67 * For an implementation of how to use this look at 68 * drm_atomic_helper_setup_commit() from the atomic helper library. 69 * 70 * See also drm_crtc_commit_wait(). 71 */ 72 struct drm_crtc_commit { 73 /** 74 * @crtc: 75 * 76 * DRM CRTC for this commit. 77 */ 78 struct drm_crtc *crtc; 79 80 /** 81 * @ref: 82 * 83 * Reference count for this structure. Needed to allow blocking on 84 * completions without the risk of the completion disappearing 85 * meanwhile. 86 */ 87 struct kref ref; 88 89 /** 90 * @flip_done: 91 * 92 * Will be signaled when the hardware has flipped to the new set of 93 * buffers. Signals at the same time as when the drm event for this 94 * commit is sent to userspace, or when an out-fence is singalled. Note 95 * that for most hardware, in most cases this happens after @hw_done is 96 * signalled. 97 * 98 * Completion of this stage is signalled implicitly by calling 99 * drm_crtc_send_vblank_event() on &drm_crtc_state.event. 100 */ 101 struct completion flip_done; 102 103 /** 104 * @hw_done: 105 * 106 * Will be signalled when all hw register changes for this commit have 107 * been written out. Especially when disabling a pipe this can be much 108 * later than @flip_done, since that can signal already when the 109 * screen goes black, whereas to fully shut down a pipe more register 110 * I/O is required. 111 * 112 * Note that this does not need to include separately reference-counted 113 * resources like backing storage buffer pinning, or runtime pm 114 * management. 115 * 116 * Drivers should call drm_atomic_helper_commit_hw_done() to signal 117 * completion of this stage. 118 */ 119 struct completion hw_done; 120 121 /** 122 * @cleanup_done: 123 * 124 * Will be signalled after old buffers have been cleaned up by calling 125 * drm_atomic_helper_cleanup_planes(). Since this can only happen after 126 * a vblank wait completed it might be a bit later. This completion is 127 * useful to throttle updates and avoid hardware updates getting ahead 128 * of the buffer cleanup too much. 129 * 130 * Drivers should call drm_atomic_helper_commit_cleanup_done() to signal 131 * completion of this stage. 132 */ 133 struct completion cleanup_done; 134 135 /** 136 * @commit_entry: 137 * 138 * Entry on the per-CRTC &drm_crtc.commit_list. Protected by 139 * $drm_crtc.commit_lock. 140 */ 141 struct list_head commit_entry; 142 143 /** 144 * @event: 145 * 146 * &drm_pending_vblank_event pointer to clean up private events. 147 */ 148 struct drm_pending_vblank_event *event; 149 150 /** 151 * @abort_completion: 152 * 153 * A flag that's set after drm_atomic_helper_setup_commit() takes a 154 * second reference for the completion of $drm_crtc_state.event. It's 155 * used by the free code to remove the second reference if commit fails. 156 */ 157 bool abort_completion; 158 }; 159 160 struct __drm_colorops_state { 161 struct drm_colorop *ptr; 162 163 /** 164 * @state_to_destroy: 165 * 166 * Used to track the @drm_colorop_state we will need to free 167 * when tearing down the associated &drm_atomic_commit in 168 * $drm_mode_config_funcs.atomic_state_clear or 169 * drm_atomic_commit_default_clear(). 170 * 171 * Before a commit, and the call to 172 * drm_atomic_helper_swap_state() in particular, it points to 173 * the same state than @new_state. After a commit, it points to 174 * the same state than @old_state. 175 */ 176 struct drm_colorop_state *state_to_destroy; 177 178 struct drm_colorop_state *old_state, *new_state; 179 }; 180 181 struct __drm_planes_state { 182 struct drm_plane *ptr; 183 184 /** 185 * @state_to_destroy: 186 * 187 * Used to track the @drm_plane_state we will need to free when 188 * tearing down the associated &drm_atomic_commit in 189 * $drm_mode_config_funcs.atomic_state_clear or 190 * drm_atomic_commit_default_clear(). 191 * 192 * Before a commit, and the call to 193 * drm_atomic_helper_swap_state() in particular, it points to 194 * the same state than @new_state. After a commit, it points to 195 * the same state than @old_state. 196 */ 197 struct drm_plane_state *state_to_destroy; 198 199 struct drm_plane_state *old_state, *new_state; 200 }; 201 202 struct __drm_crtcs_state { 203 struct drm_crtc *ptr; 204 205 /** 206 * @state_to_destroy: 207 * 208 * Used to track the @drm_crtc_state we will need to free when 209 * tearing down the associated &drm_atomic_commit in 210 * $drm_mode_config_funcs.atomic_state_clear or 211 * drm_atomic_commit_default_clear(). 212 * 213 * Before a commit, and the call to 214 * drm_atomic_helper_swap_state() in particular, it points to 215 * the same state than @new_state. After a commit, it points to 216 * the same state than @old_state. 217 */ 218 struct drm_crtc_state *state_to_destroy; 219 220 struct drm_crtc_state *old_state, *new_state; 221 222 /** 223 * @commit: 224 * 225 * A reference to the CRTC commit object that is kept for use by 226 * drm_atomic_helper_wait_for_flip_done() after 227 * drm_atomic_helper_commit_hw_done() is called. This ensures that a 228 * concurrent commit won't free a commit object that is still in use. 229 */ 230 struct drm_crtc_commit *commit; 231 232 s32 __user *out_fence_ptr; 233 u64 last_vblank_count; 234 }; 235 236 struct __drm_connnectors_state { 237 struct drm_connector *ptr; 238 239 /** 240 * @state_to_destroy: 241 * 242 * Used to track the @drm_connector_state we will need to free 243 * when tearing down the associated &drm_atomic_commit in 244 * $drm_mode_config_funcs.atomic_state_clear or 245 * drm_atomic_commit_default_clear(). 246 * 247 * Before a commit, and the call to 248 * drm_atomic_helper_swap_state() in particular, it points to 249 * the same state than @new_state. After a commit, it points to 250 * the same state than @old_state. 251 */ 252 struct drm_connector_state *state_to_destroy; 253 254 struct drm_connector_state *old_state, *new_state; 255 256 /** 257 * @out_fence_ptr: 258 * 259 * User-provided pointer which the kernel uses to return a sync_file 260 * file descriptor. Used by writeback connectors to signal completion of 261 * the writeback. 262 */ 263 s32 __user *out_fence_ptr; 264 }; 265 266 struct drm_private_obj; 267 struct drm_private_state; 268 269 /** 270 * struct drm_private_state_funcs - atomic state functions for private objects 271 * 272 * These hooks are used by atomic helpers to create, swap and destroy states of 273 * private objects. The structure itself is used as a vtable to identify the 274 * associated private object type. Each private object type that needs to be 275 * added to the atomic states is expected to have an implementation of these 276 * hooks and pass a pointer to its drm_private_state_funcs struct to 277 * drm_atomic_get_private_obj_state(). 278 */ 279 struct drm_private_state_funcs { 280 /** 281 * @atomic_create_state: 282 * 283 * Allocates a pristine, initialized, state for the private 284 * object and returns it. This callback must have no side 285 * effects: in particular, the returned state must not be 286 * assigned to the object's state pointer and it must not affect 287 * the hardware state. 288 * 289 * RETURNS: 290 * 291 * A new, pristine, private state instance or an error pointer 292 * on failure. 293 */ 294 struct drm_private_state *(*atomic_create_state)(struct drm_private_obj *obj); 295 296 /** 297 * @atomic_duplicate_state: 298 * 299 * Duplicate the current state of the private object and return it. It 300 * is an error to call this before obj->state has been initialized. 301 * 302 * RETURNS: 303 * 304 * Duplicated atomic state or NULL when obj->state is not 305 * initialized or allocation failed. 306 */ 307 struct drm_private_state *(*atomic_duplicate_state)(struct drm_private_obj *obj); 308 309 /** 310 * @atomic_destroy_state: 311 * 312 * Frees the private object state created with @atomic_duplicate_state. 313 */ 314 void (*atomic_destroy_state)(struct drm_private_obj *obj, 315 struct drm_private_state *state); 316 317 /** 318 * @atomic_print_state: 319 * 320 * If driver subclasses &struct drm_private_state, it should implement 321 * this optional hook for printing additional driver specific state. 322 * 323 * Do not call this directly, use drm_atomic_private_obj_print_state() 324 * instead. 325 */ 326 void (*atomic_print_state)(struct drm_printer *p, 327 const struct drm_private_state *state); 328 }; 329 330 /** 331 * struct drm_private_obj - base struct for driver private atomic object 332 * 333 * A driver private object is initialized by calling 334 * drm_atomic_private_obj_init() and cleaned up by calling 335 * drm_atomic_private_obj_fini(). 336 * 337 * Currently only tracks the state update functions and the opaque driver 338 * private state itself, but in the future might also track which 339 * &drm_modeset_lock is required to duplicate and update this object's state. 340 * 341 * All private objects must be initialized before the DRM device they are 342 * attached to is registered to the DRM subsystem (call to drm_dev_register()) 343 * and should stay around until this DRM device is unregistered (call to 344 * drm_dev_unregister()). In other words, private objects lifetime is tied 345 * to the DRM device lifetime. This implies that: 346 * 347 * 1/ all calls to drm_atomic_private_obj_init() must be done before calling 348 * drm_dev_register() 349 * 2/ all calls to drm_atomic_private_obj_fini() must be done after calling 350 * drm_dev_unregister() 351 * 352 * If that private object is used to store a state shared by multiple 353 * CRTCs, proper care must be taken to ensure that non-blocking commits are 354 * properly ordered to avoid a use-after-free issue. 355 * 356 * Indeed, assuming a sequence of two non-blocking &drm_atomic_commit on two 357 * different &drm_crtc using different &drm_plane and &drm_connector, so with no 358 * resources shared, there's no guarantee on which commit is going to happen 359 * first. However, the second &drm_atomic_commit will consider the first 360 * &drm_private_obj its old state, and will be in charge of freeing it whenever 361 * the second &drm_atomic_commit is done. 362 * 363 * If the first &drm_atomic_commit happens after it, it will consider its 364 * &drm_private_obj the new state and will be likely to access it, resulting in 365 * an access to a freed memory region. Drivers should store (and get a reference 366 * to) the &drm_crtc_commit structure in our private state in 367 * &drm_mode_config_helper_funcs.atomic_commit_setup, and then wait for that 368 * commit to complete as the first step of 369 * &drm_mode_config_helper_funcs.atomic_commit_tail, similar to 370 * drm_atomic_helper_wait_for_dependencies(). 371 */ 372 struct drm_private_obj { 373 /** 374 * @dev: parent DRM device 375 */ 376 struct drm_device *dev; 377 378 /** 379 * @head: List entry used to attach a private object to a &drm_device 380 * (queued to &drm_mode_config.privobj_list). 381 */ 382 struct list_head head; 383 384 /** 385 * @lock: Modeset lock to protect the state object. 386 */ 387 struct drm_modeset_lock lock; 388 389 /** 390 * @state: Current atomic state for this driver private object. 391 */ 392 struct drm_private_state *state; 393 394 /** 395 * @funcs: 396 * 397 * Functions to manipulate the state of this driver private object, see 398 * &drm_private_state_funcs. 399 */ 400 const struct drm_private_state_funcs *funcs; 401 }; 402 403 /** 404 * drm_for_each_privobj() - private object iterator 405 * 406 * @privobj: pointer to the current private object. Updated after each 407 * iteration 408 * @dev: the DRM device we want get private objects from 409 * 410 * Allows one to iterate over all private objects attached to @dev 411 */ 412 #define drm_for_each_privobj(privobj, dev) \ 413 list_for_each_entry(privobj, &(dev)->mode_config.privobj_list, head) 414 415 /** 416 * struct drm_private_state - base struct for driver private object state 417 * 418 * Currently only contains a backpointer to the overall atomic update, 419 * and the relevant private object but in the future also might hold 420 * synchronization information similar to e.g. &drm_crtc.commit. 421 */ 422 struct drm_private_state { 423 /** 424 * @state: backpointer to global drm_atomic_commit 425 */ 426 struct drm_atomic_commit *state; 427 428 /** 429 * @obj: backpointer to the private object 430 */ 431 struct drm_private_obj *obj; 432 }; 433 434 struct __drm_private_objs_state { 435 struct drm_private_obj *ptr; 436 437 /** 438 * @state_to_destroy: 439 * 440 * Used to track the @drm_private_state we will need to free 441 * when tearing down the associated &drm_atomic_commit in 442 * $drm_mode_config_funcs.atomic_state_clear or 443 * drm_atomic_commit_default_clear(). 444 * 445 * Before a commit, and the call to 446 * drm_atomic_helper_swap_state() in particular, it points to 447 * the same state than @new_state. After a commit, it points to 448 * the same state than @old_state. 449 */ 450 struct drm_private_state *state_to_destroy; 451 452 struct drm_private_state *old_state, *new_state; 453 }; 454 455 /** 456 * struct drm_atomic_commit - Atomic commit structure 457 * 458 * This structure is the kernel counterpart of @drm_mode_atomic and represents 459 * an atomic commit that transitions from an old to a new display state. It 460 * contains all the objects affected by the atomic commit and both the new 461 * state structures and pointers to the old state structures for 462 * these. 463 * 464 * States are added to an atomic update by calling drm_atomic_get_crtc_state(), 465 * drm_atomic_get_plane_state(), drm_atomic_get_connector_state(), or for 466 * private state structures, drm_atomic_get_private_obj_state(). 467 * 468 * NOTE: struct drm_atomic_commit first started as a single collection of 469 * entities state pointers (drm_plane_state, drm_crtc_state, etc.). 470 * 471 * At atomic_check time, you could get the state about to be committed 472 * from drm_atomic_commit, and the one currently running from the 473 * entities state pointer (drm_crtc.state, for example). After the call 474 * to drm_atomic_helper_swap_state(), the entities state pointer would 475 * contain the state previously checked, and the drm_atomic_commit 476 * structure the old state. 477 * 478 * Over time, and in order to avoid confusion, drm_atomic_commit has 479 * grown to have both the old state (ie, the state we replace) and the 480 * new state (ie, the state we want to apply). Those names are stable 481 * during the commit process, which makes it easier to reason about. 482 * 483 * You can still find some traces of that evolution through some hooks 484 * or callbacks taking a drm_atomic_commit parameter called names like 485 * "old_state". This doesn't necessarily mean that the previous 486 * drm_atomic_commit is passed, but rather that this used to be the state 487 * collection we were replacing after drm_atomic_helper_swap_state(), 488 * but the variable name was never updated. 489 * 490 * Some atomic operations implementations followed a similar process. We 491 * first started to pass the entity state only. However, it was pretty 492 * cumbersome for drivers, and especially CRTCs, to retrieve the states 493 * of other components. Thus, we switched to passing the whole 494 * drm_atomic_commit as a parameter to those operations. Similarly, the 495 * transition isn't complete yet, and one might still find atomic 496 * operations taking a drm_atomic_commit pointer, or a component state 497 * pointer. The former is the preferred form. 498 */ 499 struct drm_atomic_commit { 500 /** 501 * @ref: 502 * 503 * Count of all references to this update (will not be freed until zero). 504 */ 505 struct kref ref; 506 507 /** 508 * @dev: Parent DRM Device. 509 */ 510 struct drm_device *dev; 511 512 /** 513 * @allow_modeset: 514 * 515 * Allow full modeset. This is used by the ATOMIC IOCTL handler to 516 * implement the DRM_MODE_ATOMIC_ALLOW_MODESET flag. Drivers should 517 * generally not consult this flag, but instead look at the output of 518 * drm_atomic_crtc_needs_modeset(). The detailed rules are: 519 * 520 * - Drivers must not consult @allow_modeset in the atomic commit path. 521 * Use drm_atomic_crtc_needs_modeset() instead. 522 * 523 * - Drivers must consult @allow_modeset before adding unrelated struct 524 * drm_crtc_state to this commit by calling 525 * drm_atomic_get_crtc_state(). See also the warning in the 526 * documentation for that function. 527 * 528 * - Drivers must never change this flag, it is under the exclusive 529 * control of userspace. 530 * 531 * - Drivers may consult @allow_modeset in the atomic check path, if 532 * they have the choice between an optimal hardware configuration 533 * which requires a modeset, and a less optimal configuration which 534 * can be committed without a modeset. An example would be suboptimal 535 * scanout FIFO allocation resulting in increased idle power 536 * consumption. This allows userspace to avoid flickering and delays 537 * for the normal composition loop at reasonable cost. 538 */ 539 bool allow_modeset : 1; 540 /** 541 * @legacy_cursor_update: 542 * 543 * Hint to enforce legacy cursor IOCTL semantics. 544 * 545 * WARNING: This is thoroughly broken and pretty much impossible to 546 * implement correctly. Drivers must ignore this and should instead 547 * implement &drm_plane_helper_funcs.atomic_async_check and 548 * &drm_plane_helper_funcs.atomic_async_commit hooks. New users of this 549 * flag are not allowed. 550 */ 551 bool legacy_cursor_update : 1; 552 553 /** 554 * @async_update: hint for asynchronous plane update 555 */ 556 bool async_update : 1; 557 558 /** 559 * @duplicated: 560 * 561 * Indicates whether or not this atomic state was duplicated using 562 * drm_atomic_helper_duplicate_state(). Drivers and atomic helpers 563 * should use this to fixup normal inconsistencies in duplicated 564 * states. 565 */ 566 bool duplicated : 1; 567 568 /** 569 * @checked: 570 * 571 * Indicates the state has been checked and thus must no longer 572 * be mutated. For internal use only, do not consult from drivers. 573 */ 574 bool checked : 1; 575 576 /** 577 * @plane_color_pipeline: 578 * 579 * Indicates whether this atomic state originated with a client that 580 * set the DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE. 581 * 582 * Drivers and helper functions should use this to ignore legacy 583 * properties that are incompatible with the drm_plane COLOR_PIPELINE 584 * behavior, such as: 585 * 586 * - COLOR_RANGE 587 * - COLOR_ENCODING 588 * 589 * or any other driver-specific properties that might affect pixel 590 * values. 591 */ 592 bool plane_color_pipeline : 1; 593 594 /** 595 * @colorops: 596 * 597 * Pointer to array of @drm_colorop and @drm_colorop_state part of this 598 * update. 599 */ 600 struct __drm_colorops_state *colorops; 601 602 /** 603 * @planes: 604 * 605 * Pointer to array of @drm_plane and @drm_plane_state part of this 606 * update. 607 */ 608 struct __drm_planes_state *planes; 609 610 /** 611 * @crtcs: 612 * 613 * Pointer to array of @drm_crtc and @drm_crtc_state part of this 614 * update. 615 */ 616 struct __drm_crtcs_state *crtcs; 617 618 /** 619 * @num_connector: size of the @connectors array 620 */ 621 int num_connector; 622 623 /** 624 * @connectors: 625 * 626 * Pointer to array of @drm_connector and @drm_connector_state part of 627 * this update. 628 */ 629 struct __drm_connnectors_state *connectors; 630 631 /** 632 * @num_private_objs: size of the @private_objs array 633 */ 634 int num_private_objs; 635 636 /** 637 * @private_objs: 638 * 639 * Pointer to array of @drm_private_obj and @drm_private_obj_state part 640 * of this update. 641 */ 642 struct __drm_private_objs_state *private_objs; 643 644 /** 645 * @acquire_ctx: acquire context for this atomic modeset state update 646 */ 647 struct drm_modeset_acquire_ctx *acquire_ctx; 648 649 /** 650 * @fake_commit: 651 * 652 * Used for signaling unbound planes/connectors. 653 * When a connector or plane is not bound to any CRTC, it's still important 654 * to preserve linearity to prevent the atomic states from being freed too early. 655 * 656 * This commit (if set) is not bound to any CRTC, but will be completed when 657 * drm_atomic_helper_commit_hw_done() is called. 658 */ 659 struct drm_crtc_commit *fake_commit; 660 661 /** 662 * @commit_work: 663 * 664 * Work item which can be used by the driver or helpers to execute the 665 * commit without blocking. 666 */ 667 struct work_struct commit_work; 668 }; 669 670 void __drm_crtc_commit_free(struct kref *kref); 671 672 /** 673 * drm_crtc_commit_get - acquire a reference to the CRTC commit 674 * @commit: CRTC commit 675 * 676 * Increases the reference of @commit. 677 * 678 * Returns: 679 * The pointer to @commit, with reference increased. 680 */ 681 static inline struct drm_crtc_commit *drm_crtc_commit_get(struct drm_crtc_commit *commit) 682 { 683 kref_get(&commit->ref); 684 return commit; 685 } 686 687 /** 688 * drm_crtc_commit_put - release a reference to the CRTC commmit 689 * @commit: CRTC commit 690 * 691 * This releases a reference to @commit which is freed after removing the 692 * final reference. No locking required and callable from any context. 693 */ 694 static inline void drm_crtc_commit_put(struct drm_crtc_commit *commit) 695 { 696 kref_put(&commit->ref, __drm_crtc_commit_free); 697 } 698 699 int drm_crtc_commit_wait(struct drm_crtc_commit *commit); 700 701 struct drm_atomic_commit * __must_check 702 drm_atomic_commit_alloc(struct drm_device *dev); 703 void drm_atomic_commit_clear(struct drm_atomic_commit *state); 704 705 /** 706 * drm_atomic_commit_get - acquire a reference to the atomic state 707 * @state: The atomic state 708 * 709 * Returns a new reference to the @state 710 */ 711 static inline struct drm_atomic_commit * 712 drm_atomic_commit_get(struct drm_atomic_commit *state) 713 { 714 kref_get(&state->ref); 715 return state; 716 } 717 718 void __drm_atomic_commit_free(struct kref *ref); 719 720 /** 721 * drm_atomic_commit_put - release a reference to the atomic state 722 * @state: The atomic state 723 * 724 * This releases a reference to @state which is freed after removing the 725 * final reference. No locking required and callable from any context. 726 */ 727 static inline void drm_atomic_commit_put(struct drm_atomic_commit *state) 728 { 729 kref_put(&state->ref, __drm_atomic_commit_free); 730 } 731 732 int __must_check 733 drm_atomic_commit_init(struct drm_device *dev, struct drm_atomic_commit *state); 734 void drm_atomic_commit_default_clear(struct drm_atomic_commit *state); 735 void drm_atomic_commit_default_release(struct drm_atomic_commit *state); 736 737 struct drm_crtc_state * __must_check 738 drm_atomic_get_crtc_state(struct drm_atomic_commit *state, 739 struct drm_crtc *crtc); 740 struct drm_plane_state * __must_check 741 drm_atomic_get_plane_state(struct drm_atomic_commit *state, 742 struct drm_plane *plane); 743 struct drm_colorop_state * 744 drm_atomic_get_colorop_state(struct drm_atomic_commit *state, 745 struct drm_colorop *colorop); 746 747 struct drm_colorop_state * 748 drm_atomic_get_old_colorop_state(struct drm_atomic_commit *state, 749 struct drm_colorop *colorop); 750 struct drm_colorop_state * 751 drm_atomic_get_new_colorop_state(struct drm_atomic_commit *state, 752 struct drm_colorop *colorop); 753 754 struct drm_connector_state * __must_check 755 drm_atomic_get_connector_state(struct drm_atomic_commit *state, 756 struct drm_connector *connector); 757 758 int drm_atomic_private_obj_init(struct drm_device *dev, 759 struct drm_private_obj *obj, 760 const struct drm_private_state_funcs *funcs); 761 void drm_atomic_private_obj_fini(struct drm_private_obj *obj); 762 763 struct drm_private_state * __must_check 764 drm_atomic_get_private_obj_state(struct drm_atomic_commit *state, 765 struct drm_private_obj *obj); 766 struct drm_private_state * 767 drm_atomic_get_old_private_obj_state(const struct drm_atomic_commit *state, 768 struct drm_private_obj *obj); 769 struct drm_private_state * 770 drm_atomic_get_new_private_obj_state(const struct drm_atomic_commit *state, 771 struct drm_private_obj *obj); 772 773 struct drm_connector * 774 drm_atomic_get_old_connector_for_encoder(const struct drm_atomic_commit *state, 775 struct drm_encoder *encoder); 776 struct drm_connector * 777 drm_atomic_get_new_connector_for_encoder(const struct drm_atomic_commit *state, 778 struct drm_encoder *encoder); 779 struct drm_connector * 780 drm_atomic_get_connector_for_encoder(const struct drm_encoder *encoder, 781 struct drm_modeset_acquire_ctx *ctx); 782 783 struct drm_crtc * 784 drm_atomic_get_old_crtc_for_encoder(struct drm_atomic_commit *state, 785 struct drm_encoder *encoder); 786 struct drm_crtc * 787 drm_atomic_get_new_crtc_for_encoder(struct drm_atomic_commit *state, 788 struct drm_encoder *encoder); 789 790 /** 791 * drm_atomic_get_old_crtc_state - get old CRTC state, if it exists 792 * @state: global atomic state object 793 * @crtc: CRTC to grab 794 * 795 * This function returns the old CRTC state for the given CRTC, or 796 * NULL if the CRTC is not part of the global atomic state. 797 */ 798 static inline struct drm_crtc_state * 799 drm_atomic_get_old_crtc_state(const struct drm_atomic_commit *state, 800 struct drm_crtc *crtc) 801 { 802 return state->crtcs[drm_crtc_index(crtc)].old_state; 803 } 804 /** 805 * drm_atomic_get_new_crtc_state - get new CRTC state, if it exists 806 * @state: global atomic state object 807 * @crtc: CRTC to grab 808 * 809 * This function returns the new CRTC state for the given CRTC, or 810 * NULL if the CRTC is not part of the global atomic state. 811 */ 812 static inline struct drm_crtc_state * 813 drm_atomic_get_new_crtc_state(const struct drm_atomic_commit *state, 814 struct drm_crtc *crtc) 815 { 816 return state->crtcs[drm_crtc_index(crtc)].new_state; 817 } 818 819 /** 820 * drm_atomic_get_old_plane_state - get plane state, if it exists 821 * @state: global atomic state object 822 * @plane: plane to grab 823 * 824 * This function returns the old plane state for the given plane, or 825 * NULL if the plane is not part of the global atomic state. 826 */ 827 static inline struct drm_plane_state * 828 drm_atomic_get_old_plane_state(const struct drm_atomic_commit *state, 829 struct drm_plane *plane) 830 { 831 return state->planes[drm_plane_index(plane)].old_state; 832 } 833 834 /** 835 * drm_atomic_get_new_plane_state - get plane state, if it exists 836 * @state: global atomic state object 837 * @plane: plane to grab 838 * 839 * This function returns the new plane state for the given plane, or 840 * NULL if the plane is not part of the global atomic state. 841 */ 842 static inline struct drm_plane_state * 843 drm_atomic_get_new_plane_state(const struct drm_atomic_commit *state, 844 struct drm_plane *plane) 845 { 846 return state->planes[drm_plane_index(plane)].new_state; 847 } 848 849 /** 850 * drm_atomic_get_old_connector_state - get connector state, if it exists 851 * @state: global atomic state object 852 * @connector: connector to grab 853 * 854 * This function returns the old connector state for the given connector, 855 * or NULL if the connector is not part of the global atomic state. 856 */ 857 static inline struct drm_connector_state * 858 drm_atomic_get_old_connector_state(const struct drm_atomic_commit *state, 859 struct drm_connector *connector) 860 { 861 int index = drm_connector_index(connector); 862 863 if (index >= state->num_connector) 864 return NULL; 865 866 return state->connectors[index].old_state; 867 } 868 869 /** 870 * drm_atomic_get_new_connector_state - get connector state, if it exists 871 * @state: global atomic state object 872 * @connector: connector to grab 873 * 874 * This function returns the new connector state for the given connector, 875 * or NULL if the connector is not part of the global atomic state. 876 */ 877 static inline struct drm_connector_state * 878 drm_atomic_get_new_connector_state(const struct drm_atomic_commit *state, 879 struct drm_connector *connector) 880 { 881 int index = drm_connector_index(connector); 882 883 if (index >= state->num_connector) 884 return NULL; 885 886 return state->connectors[index].new_state; 887 } 888 889 /** 890 * __drm_atomic_get_current_plane_state - get current plane state 891 * @state: global atomic state object 892 * @plane: plane to grab 893 * 894 * This function returns the plane state for the given plane, either the 895 * new plane state from @state, or if the plane isn't part of the atomic 896 * state update, from @plane. This is useful in atomic check callbacks, 897 * when drivers need to peek at, but not change, state of other planes, 898 * since it avoids threading an error code back up the call chain. 899 * 900 * WARNING: 901 * 902 * Note that this function is in general unsafe since it doesn't check for the 903 * required locking for access state structures. Drivers must ensure that it is 904 * safe to access the returned state structure through other means. One common 905 * example is when planes are fixed to a single CRTC, and the driver knows that 906 * the CRTC lock is held already. In that case holding the CRTC lock gives a 907 * read-lock on all planes connected to that CRTC. But if planes can be 908 * reassigned things get more tricky. In that case it's better to use 909 * drm_atomic_get_plane_state and wire up full error handling. 910 * 911 * Returns: 912 * 913 * Read-only pointer to the current plane state. 914 */ 915 static inline const struct drm_plane_state * 916 __drm_atomic_get_current_plane_state(const struct drm_atomic_commit *state, 917 struct drm_plane *plane) 918 { 919 struct drm_plane_state *plane_state; 920 921 plane_state = drm_atomic_get_new_plane_state(state, plane); 922 if (plane_state) 923 return plane_state; 924 925 /* 926 * If the plane isn't part of the state, fallback to the currently active one. 927 */ 928 return plane->state; 929 } 930 931 int __must_check 932 drm_atomic_add_encoder_bridges(struct drm_atomic_commit *state, 933 struct drm_encoder *encoder); 934 int __must_check 935 drm_atomic_add_affected_connectors(struct drm_atomic_commit *state, 936 struct drm_crtc *crtc); 937 int __must_check 938 drm_atomic_add_affected_planes(struct drm_atomic_commit *state, 939 struct drm_crtc *crtc); 940 int __must_check 941 drm_atomic_add_affected_colorops(struct drm_atomic_commit *state, 942 struct drm_plane *plane); 943 944 int __must_check drm_atomic_check_only(struct drm_atomic_commit *state); 945 int __must_check drm_atomic_commit(struct drm_atomic_commit *state); 946 int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_commit *state); 947 948 void drm_state_dump(struct drm_device *dev, struct drm_printer *p); 949 950 /** 951 * for_each_oldnew_connector_in_state - iterate over all connectors in an atomic update 952 * @__state: &struct drm_atomic_commit pointer 953 * @connector: &struct drm_connector iteration cursor 954 * @old_connector_state: &struct drm_connector_state iteration cursor for the 955 * old state 956 * @new_connector_state: &struct drm_connector_state iteration cursor for the 957 * new state 958 * @__i: int iteration cursor, for macro-internal use 959 * 960 * This iterates over all connectors in an atomic update, tracking both old and 961 * new state. This is useful in places where the state delta needs to be 962 * considered, for example in atomic check functions. 963 */ 964 #define for_each_oldnew_connector_in_state(__state, connector, old_connector_state, new_connector_state, __i) \ 965 for ((__i) = 0; \ 966 (__i) < (__state)->num_connector; \ 967 (__i)++) \ 968 for_each_if ((__state)->connectors[__i].ptr && \ 969 ((connector) = (__state)->connectors[__i].ptr, \ 970 (void)(connector) /* Only to avoid unused-but-set-variable warning */, \ 971 (old_connector_state) = (__state)->connectors[__i].old_state, \ 972 (void)(old_connector_state) /* Only to avoid unused-but-set-variable warning */, \ 973 (new_connector_state) = (__state)->connectors[__i].new_state, \ 974 (void)(new_connector_state) /* Only to avoid unused-but-set-variable warning */, 1)) 975 976 /** 977 * for_each_old_connector_in_state - iterate over all connectors in an atomic update 978 * @__state: &struct drm_atomic_commit pointer 979 * @connector: &struct drm_connector iteration cursor 980 * @old_connector_state: &struct drm_connector_state iteration cursor for the 981 * old state 982 * @__i: int iteration cursor, for macro-internal use 983 * 984 * This iterates over all connectors in an atomic update, tracking only the old 985 * state. This is useful in disable functions, where we need the old state the 986 * hardware is still in. 987 */ 988 #define for_each_old_connector_in_state(__state, connector, old_connector_state, __i) \ 989 for ((__i) = 0; \ 990 (__i) < (__state)->num_connector; \ 991 (__i)++) \ 992 for_each_if ((__state)->connectors[__i].ptr && \ 993 ((connector) = (__state)->connectors[__i].ptr, \ 994 (void)(connector) /* Only to avoid unused-but-set-variable warning */, \ 995 (old_connector_state) = (__state)->connectors[__i].old_state, \ 996 (void)(old_connector_state) /* Only to avoid unused-but-set-variable warning */, 1)) 997 998 /** 999 * for_each_new_connector_in_state - iterate over all connectors in an atomic update 1000 * @__state: &struct drm_atomic_commit pointer 1001 * @connector: &struct drm_connector iteration cursor 1002 * @new_connector_state: &struct drm_connector_state iteration cursor for the 1003 * new state 1004 * @__i: int iteration cursor, for macro-internal use 1005 * 1006 * This iterates over all connectors in an atomic update, tracking only the new 1007 * state. This is useful in enable functions, where we need the new state the 1008 * hardware should be in when the atomic commit operation has completed. 1009 */ 1010 #define for_each_new_connector_in_state(__state, connector, new_connector_state, __i) \ 1011 for ((__i) = 0; \ 1012 (__i) < (__state)->num_connector; \ 1013 (__i)++) \ 1014 for_each_if ((__state)->connectors[__i].ptr && \ 1015 ((connector) = (__state)->connectors[__i].ptr, \ 1016 (void)(connector) /* Only to avoid unused-but-set-variable warning */, \ 1017 (new_connector_state) = (__state)->connectors[__i].new_state, \ 1018 (void)(new_connector_state) /* Only to avoid unused-but-set-variable warning */, 1)) 1019 1020 /** 1021 * for_each_oldnew_crtc_in_state - iterate over all CRTCs in an atomic update 1022 * @__state: &struct drm_atomic_commit pointer 1023 * @crtc: &struct drm_crtc iteration cursor 1024 * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state 1025 * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state 1026 * @__i: int iteration cursor, for macro-internal use 1027 * 1028 * This iterates over all CRTCs in an atomic update, tracking both old and 1029 * new state. This is useful in places where the state delta needs to be 1030 * considered, for example in atomic check functions. 1031 */ 1032 #define for_each_oldnew_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \ 1033 for ((__i) = 0; \ 1034 (__i) < (__state)->dev->mode_config.num_crtc; \ 1035 (__i)++) \ 1036 for_each_if ((__state)->crtcs[__i].ptr && \ 1037 ((crtc) = (__state)->crtcs[__i].ptr, \ 1038 (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \ 1039 (old_crtc_state) = (__state)->crtcs[__i].old_state, \ 1040 (void)(old_crtc_state) /* Only to avoid unused-but-set-variable warning */, \ 1041 (new_crtc_state) = (__state)->crtcs[__i].new_state, \ 1042 (void)(new_crtc_state) /* Only to avoid unused-but-set-variable warning */, 1)) 1043 1044 /** 1045 * for_each_old_crtc_in_state - iterate over all CRTCs in an atomic update 1046 * @__state: &struct drm_atomic_commit pointer 1047 * @crtc: &struct drm_crtc iteration cursor 1048 * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state 1049 * @__i: int iteration cursor, for macro-internal use 1050 * 1051 * This iterates over all CRTCs in an atomic update, tracking only the old 1052 * state. This is useful in disable functions, where we need the old state the 1053 * hardware is still in. 1054 */ 1055 #define for_each_old_crtc_in_state(__state, crtc, old_crtc_state, __i) \ 1056 for ((__i) = 0; \ 1057 (__i) < (__state)->dev->mode_config.num_crtc; \ 1058 (__i)++) \ 1059 for_each_if ((__state)->crtcs[__i].ptr && \ 1060 ((crtc) = (__state)->crtcs[__i].ptr, \ 1061 (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \ 1062 (old_crtc_state) = (__state)->crtcs[__i].old_state, \ 1063 (void)(old_crtc_state) /* Only to avoid unused-but-set-variable warning */, 1)) 1064 1065 /** 1066 * for_each_new_crtc_in_state - iterate over all CRTCs in an atomic update 1067 * @__state: &struct drm_atomic_commit pointer 1068 * @crtc: &struct drm_crtc iteration cursor 1069 * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state 1070 * @__i: int iteration cursor, for macro-internal use 1071 * 1072 * This iterates over all CRTCs in an atomic update, tracking only the new 1073 * state. This is useful in enable functions, where we need the new state the 1074 * hardware should be in when the atomic commit operation has completed. 1075 */ 1076 #define for_each_new_crtc_in_state(__state, crtc, new_crtc_state, __i) \ 1077 for ((__i) = 0; \ 1078 (__i) < (__state)->dev->mode_config.num_crtc; \ 1079 (__i)++) \ 1080 for_each_if ((__state)->crtcs[__i].ptr && \ 1081 ((crtc) = (__state)->crtcs[__i].ptr, \ 1082 (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \ 1083 (new_crtc_state) = (__state)->crtcs[__i].new_state, \ 1084 (void)(new_crtc_state) /* Only to avoid unused-but-set-variable warning */, 1)) 1085 1086 /** 1087 * for_each_oldnew_colorop_in_state - iterate over all colorops in an atomic update 1088 * @__state: &struct drm_atomic_commit pointer 1089 * @colorop: &struct drm_colorop iteration cursor 1090 * @old_colorop_state: &struct drm_colorop_state iteration cursor for the old state 1091 * @new_colorop_state: &struct drm_colorop_state iteration cursor for the new state 1092 * @__i: int iteration cursor, for macro-internal use 1093 * 1094 * This iterates over all colorops in an atomic update, tracking both old and 1095 * new state. This is useful in places where the state delta needs to be 1096 * considered, for example in atomic check functions. 1097 */ 1098 #define for_each_oldnew_colorop_in_state(__state, colorop, old_colorop_state, \ 1099 new_colorop_state, __i) \ 1100 for ((__i) = 0; \ 1101 (__i) < (__state)->dev->mode_config.num_colorop; \ 1102 (__i)++) \ 1103 for_each_if ((__state)->colorops[__i].ptr && \ 1104 ((colorop) = (__state)->colorops[__i].ptr, \ 1105 (void)(colorop) /* Only to avoid unused-but-set-variable warning */, \ 1106 (old_colorop_state) = (__state)->colorops[__i].old_state,\ 1107 (new_colorop_state) = (__state)->colorops[__i].new_state, 1)) 1108 1109 /** 1110 * for_each_new_colorop_in_state - iterate over all colorops in an atomic update 1111 * @__state: &struct drm_atomic_commit pointer 1112 * @colorop: &struct drm_colorop iteration cursor 1113 * @new_colorop_state: &struct drm_colorop_state iteration cursor for the new state 1114 * @__i: int iteration cursor, for macro-internal use 1115 * 1116 * This iterates over all colorops in an atomic update, tracking new state. This is 1117 * useful in places where the state delta needs to be considered, for example in 1118 * atomic check functions. 1119 */ 1120 #define for_each_new_colorop_in_state(__state, colorop, new_colorop_state, __i) \ 1121 for ((__i) = 0; \ 1122 (__i) < (__state)->dev->mode_config.num_colorop; \ 1123 (__i)++) \ 1124 for_each_if ((__state)->colorops[__i].ptr && \ 1125 ((colorop) = (__state)->colorops[__i].ptr, \ 1126 (void)(colorop) /* Only to avoid unused-but-set-variable warning */, \ 1127 (new_colorop_state) = (__state)->colorops[__i].new_state,\ 1128 (void)(new_colorop_state) /* Only to avoid unused-but-set-variable warning */, 1)) 1129 1130 /** 1131 * for_each_oldnew_plane_in_state - iterate over all planes in an atomic update 1132 * @__state: &struct drm_atomic_commit pointer 1133 * @plane: &struct drm_plane iteration cursor 1134 * @old_plane_state: &struct drm_plane_state iteration cursor for the old state 1135 * @new_plane_state: &struct drm_plane_state iteration cursor for the new state 1136 * @__i: int iteration cursor, for macro-internal use 1137 * 1138 * This iterates over all planes in an atomic update, tracking both old and 1139 * new state. This is useful in places where the state delta needs to be 1140 * considered, for example in atomic check functions. 1141 */ 1142 #define for_each_oldnew_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \ 1143 for ((__i) = 0; \ 1144 (__i) < (__state)->dev->mode_config.num_total_plane; \ 1145 (__i)++) \ 1146 for_each_if ((__state)->planes[__i].ptr && \ 1147 ((plane) = (__state)->planes[__i].ptr, \ 1148 (void)(plane) /* Only to avoid unused-but-set-variable warning */, \ 1149 (old_plane_state) = (__state)->planes[__i].old_state, \ 1150 (void)(old_plane_state) /* Only to avoid unused-but-set-variable warning */, \ 1151 (new_plane_state) = (__state)->planes[__i].new_state, \ 1152 (void)(new_plane_state) /* Only to avoid unused-but-set-variable warning */, 1)) 1153 1154 /** 1155 * for_each_oldnew_plane_in_state_reverse - iterate over all planes in an atomic 1156 * update in reverse order 1157 * @__state: &struct drm_atomic_commit pointer 1158 * @plane: &struct drm_plane iteration cursor 1159 * @old_plane_state: &struct drm_plane_state iteration cursor for the old state 1160 * @new_plane_state: &struct drm_plane_state iteration cursor for the new state 1161 * @__i: int iteration cursor, for macro-internal use 1162 * 1163 * This iterates over all planes in an atomic update in reverse order, 1164 * tracking both old and new state. This is useful in places where the 1165 * state delta needs to be considered, for example in atomic check functions. 1166 */ 1167 #define for_each_oldnew_plane_in_state_reverse(__state, plane, old_plane_state, new_plane_state, __i) \ 1168 for ((__i) = ((__state)->dev->mode_config.num_total_plane - 1); \ 1169 (__i) >= 0; \ 1170 (__i)--) \ 1171 for_each_if ((__state)->planes[__i].ptr && \ 1172 ((plane) = (__state)->planes[__i].ptr, \ 1173 (void)(plane) /* Only to avoid unused-but-set-variable warning */, \ 1174 (old_plane_state) = (__state)->planes[__i].old_state, \ 1175 (void)(old_plane_state) /* Only to avoid unused-but-set-variable warning */, \ 1176 (new_plane_state) = (__state)->planes[__i].new_state, \ 1177 (void)(new_plane_state) /* Only to avoid unused-but-set-variable warning */, 1)) 1178 1179 /** 1180 * for_each_new_plane_in_state_reverse - other than only tracking new state, 1181 * it's the same as for_each_oldnew_plane_in_state_reverse 1182 * @__state: &struct drm_atomic_commit pointer 1183 * @plane: &struct drm_plane iteration cursor 1184 * @new_plane_state: &struct drm_plane_state iteration cursor for the new state 1185 * @__i: int iteration cursor, for macro-internal use 1186 */ 1187 #define for_each_new_plane_in_state_reverse(__state, plane, new_plane_state, __i) \ 1188 for ((__i) = ((__state)->dev->mode_config.num_total_plane - 1); \ 1189 (__i) >= 0; \ 1190 (__i)--) \ 1191 for_each_if ((__state)->planes[__i].ptr && \ 1192 ((plane) = (__state)->planes[__i].ptr, \ 1193 (void)(plane) /* Only to avoid unused-but-set-variable warning */, \ 1194 (new_plane_state) = (__state)->planes[__i].new_state, \ 1195 (void)(new_plane_state) /* Only to avoid unused-but-set-variable warning */, 1)) 1196 1197 /** 1198 * for_each_old_plane_in_state - iterate over all planes in an atomic update 1199 * @__state: &struct drm_atomic_commit pointer 1200 * @plane: &struct drm_plane iteration cursor 1201 * @old_plane_state: &struct drm_plane_state iteration cursor for the old state 1202 * @__i: int iteration cursor, for macro-internal use 1203 * 1204 * This iterates over all planes in an atomic update, tracking only the old 1205 * state. This is useful in disable functions, where we need the old state the 1206 * hardware is still in. 1207 */ 1208 #define for_each_old_plane_in_state(__state, plane, old_plane_state, __i) \ 1209 for ((__i) = 0; \ 1210 (__i) < (__state)->dev->mode_config.num_total_plane; \ 1211 (__i)++) \ 1212 for_each_if ((__state)->planes[__i].ptr && \ 1213 ((plane) = (__state)->planes[__i].ptr, \ 1214 (void)(plane) /* Only to avoid unused-but-set-variable warning */, \ 1215 (old_plane_state) = (__state)->planes[__i].old_state, \ 1216 (void)(old_plane_state) /* Only to avoid unused-but-set-variable warning */, 1)) 1217 1218 /** 1219 * for_each_new_plane_in_state - iterate over all planes in an atomic update 1220 * @__state: &struct drm_atomic_commit pointer 1221 * @plane: &struct drm_plane iteration cursor 1222 * @new_plane_state: &struct drm_plane_state iteration cursor for the new state 1223 * @__i: int iteration cursor, for macro-internal use 1224 * 1225 * This iterates over all planes in an atomic update, tracking only the new 1226 * state. This is useful in enable functions, where we need the new state the 1227 * hardware should be in when the atomic commit operation has completed. 1228 */ 1229 #define for_each_new_plane_in_state(__state, plane, new_plane_state, __i) \ 1230 for ((__i) = 0; \ 1231 (__i) < (__state)->dev->mode_config.num_total_plane; \ 1232 (__i)++) \ 1233 for_each_if ((__state)->planes[__i].ptr && \ 1234 ((plane) = (__state)->planes[__i].ptr, \ 1235 (void)(plane) /* Only to avoid unused-but-set-variable warning */, \ 1236 (new_plane_state) = (__state)->planes[__i].new_state, \ 1237 (void)(new_plane_state) /* Only to avoid unused-but-set-variable warning */, 1)) 1238 1239 /** 1240 * for_each_oldnew_private_obj_in_state - iterate over all private objects in an atomic update 1241 * @__state: &struct drm_atomic_commit pointer 1242 * @obj: &struct drm_private_obj iteration cursor 1243 * @old_obj_state: &struct drm_private_state iteration cursor for the old state 1244 * @new_obj_state: &struct drm_private_state iteration cursor for the new state 1245 * @__i: int iteration cursor, for macro-internal use 1246 * 1247 * This iterates over all private objects in an atomic update, tracking both 1248 * old and new state. This is useful in places where the state delta needs 1249 * to be considered, for example in atomic check functions. 1250 */ 1251 #define for_each_oldnew_private_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \ 1252 for ((__i) = 0; \ 1253 (__i) < (__state)->num_private_objs && \ 1254 ((obj) = (__state)->private_objs[__i].ptr, \ 1255 (void)(obj) /* Only to avoid unused-but-set-variable warning */, \ 1256 (old_obj_state) = (__state)->private_objs[__i].old_state, \ 1257 (void)(old_obj_state) /* Only to avoid unused-but-set-variable warning */, \ 1258 (new_obj_state) = (__state)->private_objs[__i].new_state, \ 1259 (void)(new_obj_state) /* Only to avoid unused-but-set-variable warning */, 1); \ 1260 (__i)++) 1261 1262 /** 1263 * for_each_old_private_obj_in_state - iterate over all private objects in an atomic update 1264 * @__state: &struct drm_atomic_commit pointer 1265 * @obj: &struct drm_private_obj iteration cursor 1266 * @old_obj_state: &struct drm_private_state iteration cursor for the old state 1267 * @__i: int iteration cursor, for macro-internal use 1268 * 1269 * This iterates over all private objects in an atomic update, tracking only 1270 * the old state. This is useful in disable functions, where we need the old 1271 * state the hardware is still in. 1272 */ 1273 #define for_each_old_private_obj_in_state(__state, obj, old_obj_state, __i) \ 1274 for ((__i) = 0; \ 1275 (__i) < (__state)->num_private_objs && \ 1276 ((obj) = (__state)->private_objs[__i].ptr, \ 1277 (void)(obj) /* Only to avoid unused-but-set-variable warning */, \ 1278 (old_obj_state) = (__state)->private_objs[__i].old_state, \ 1279 (void)(old_obj_state) /* Only to avoid unused-but-set-variable warning */, 1); \ 1280 (__i)++) 1281 1282 /** 1283 * for_each_new_private_obj_in_state - iterate over all private objects in an atomic update 1284 * @__state: &struct drm_atomic_commit pointer 1285 * @obj: &struct drm_private_obj iteration cursor 1286 * @new_obj_state: &struct drm_private_state iteration cursor for the new state 1287 * @__i: int iteration cursor, for macro-internal use 1288 * 1289 * This iterates over all private objects in an atomic update, tracking only 1290 * the new state. This is useful in enable functions, where we need the new state the 1291 * hardware should be in when the atomic commit operation has completed. 1292 */ 1293 #define for_each_new_private_obj_in_state(__state, obj, new_obj_state, __i) \ 1294 for ((__i) = 0; \ 1295 (__i) < (__state)->num_private_objs && \ 1296 ((obj) = (__state)->private_objs[__i].ptr, \ 1297 (void)(obj) /* Only to avoid unused-but-set-variable warning */, \ 1298 (new_obj_state) = (__state)->private_objs[__i].new_state, \ 1299 (void)(new_obj_state) /* Only to avoid unused-but-set-variable warning */, 1); \ 1300 (__i)++) 1301 1302 /** 1303 * drm_atomic_crtc_needs_modeset - compute combined modeset need 1304 * @state: &drm_crtc_state for the CRTC 1305 * 1306 * To give drivers flexibility &struct drm_crtc_state has 3 booleans to track 1307 * whether the state CRTC changed enough to need a full modeset cycle: 1308 * mode_changed, active_changed and connectors_changed. This helper simply 1309 * combines these three to compute the overall need for a modeset for @state. 1310 * 1311 * The atomic helper code sets these booleans, but drivers can and should 1312 * change them appropriately to accurately represent whether a modeset is 1313 * really needed. In general, drivers should avoid full modesets whenever 1314 * possible. 1315 * 1316 * For example if the CRTC mode has changed, and the hardware is able to enact 1317 * the requested mode change without going through a full modeset, the driver 1318 * should clear mode_changed in its &drm_mode_config_funcs.atomic_check 1319 * implementation. 1320 */ 1321 static inline bool 1322 drm_atomic_crtc_needs_modeset(const struct drm_crtc_state *state) 1323 { 1324 return state->mode_changed || state->active_changed || 1325 state->connectors_changed; 1326 } 1327 1328 /** 1329 * drm_atomic_crtc_effectively_active - compute whether CRTC is actually active 1330 * @state: &drm_crtc_state for the CRTC 1331 * 1332 * When in self refresh mode, the crtc_state->active value will be false, since 1333 * the CRTC is off. However in some cases we're interested in whether the CRTC 1334 * is active, or effectively active (ie: it's connected to an active display). 1335 * In these cases, use this function instead of just checking active. 1336 */ 1337 static inline bool 1338 drm_atomic_crtc_effectively_active(const struct drm_crtc_state *state) 1339 { 1340 return state->active || state->self_refresh_active; 1341 } 1342 1343 /** 1344 * struct drm_bus_cfg - bus configuration 1345 * 1346 * This structure stores the configuration of a physical bus between two 1347 * components in an output pipeline, usually between two bridges, an encoder 1348 * and a bridge, or a bridge and a connector. 1349 * 1350 * The bus configuration is stored in &drm_bridge_state separately for the 1351 * input and output buses, as seen from the point of view of each bridge. The 1352 * bus configuration of a bridge output is usually identical to the 1353 * configuration of the next bridge's input, but may differ if the signals are 1354 * modified between the two bridges, for instance by an inverter on the board. 1355 * The input and output configurations of a bridge may differ if the bridge 1356 * modifies the signals internally, for instance by performing format 1357 * conversion, or modifying signals polarities. 1358 */ 1359 struct drm_bus_cfg { 1360 /** 1361 * @format: format used on this bus (one of the MEDIA_BUS_FMT_* format) 1362 * 1363 * This field should not be directly modified by drivers 1364 * (drm_atomic_bridge_chain_select_bus_fmts() takes care of the bus 1365 * format negotiation). 1366 */ 1367 u32 format; 1368 1369 /** 1370 * @flags: DRM_BUS_* flags used on this bus 1371 */ 1372 u32 flags; 1373 }; 1374 1375 /** 1376 * struct drm_bridge_state - Atomic bridge state object 1377 */ 1378 struct drm_bridge_state { 1379 /** 1380 * @base: inherit from &drm_private_state 1381 */ 1382 struct drm_private_state base; 1383 1384 /** 1385 * @bridge: the bridge this state refers to 1386 */ 1387 struct drm_bridge *bridge; 1388 1389 /** 1390 * @input_bus_cfg: input bus configuration 1391 */ 1392 struct drm_bus_cfg input_bus_cfg; 1393 1394 /** 1395 * @output_bus_cfg: output bus configuration 1396 */ 1397 struct drm_bus_cfg output_bus_cfg; 1398 }; 1399 1400 #define drm_priv_to_bridge_state(priv) \ 1401 container_of_const(priv, struct drm_bridge_state, base) 1402 1403 struct drm_bridge_state * 1404 drm_atomic_get_bridge_state(struct drm_atomic_commit *state, 1405 struct drm_bridge *bridge); 1406 struct drm_bridge_state * 1407 drm_atomic_get_old_bridge_state(const struct drm_atomic_commit *state, 1408 struct drm_bridge *bridge); 1409 struct drm_bridge_state * 1410 drm_atomic_get_new_bridge_state(const struct drm_atomic_commit *state, 1411 struct drm_bridge *bridge); 1412 1413 #endif /* DRM_ATOMIC_H_ */ 1414