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