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 33 /** 34 * struct drm_crtc_commit - track modeset commits on a CRTC 35 * 36 * This structure is used to track pending modeset changes and atomic commit on 37 * a per-CRTC basis. Since updating the list should never block this structure 38 * is reference counted to allow waiters to safely wait on an event to complete, 39 * without holding any locks. 40 * 41 * It has 3 different events in total to allow a fine-grained synchronization 42 * between outstanding updates:: 43 * 44 * atomic commit thread hardware 45 * 46 * write new state into hardware ----> ... 47 * signal hw_done 48 * switch to new state on next 49 * ... v/hblank 50 * 51 * wait for buffers to show up ... 52 * 53 * ... send completion irq 54 * irq handler signals flip_done 55 * cleanup old buffers 56 * 57 * signal cleanup_done 58 * 59 * wait for flip_done <---- 60 * clean up atomic state 61 * 62 * The important bit to know is that cleanup_done is the terminal event, but the 63 * ordering between flip_done and hw_done is entirely up to the specific driver 64 * and modeset state change. 65 * 66 * For an implementation of how to use this look at 67 * drm_atomic_helper_setup_commit() from the atomic helper library. 68 */ 69 struct drm_crtc_commit { 70 /** 71 * @crtc: 72 * 73 * DRM CRTC for this commit. 74 */ 75 struct drm_crtc *crtc; 76 77 /** 78 * @ref: 79 * 80 * Reference count for this structure. Needed to allow blocking on 81 * completions without the risk of the completion disappearing 82 * meanwhile. 83 */ 84 struct kref ref; 85 86 /** 87 * @flip_done: 88 * 89 * Will be signaled when the hardware has flipped to the new set of 90 * buffers. Signals at the same time as when the drm event for this 91 * commit is sent to userspace, or when an out-fence is singalled. Note 92 * that for most hardware, in most cases this happens after @hw_done is 93 * signalled. 94 */ 95 struct completion flip_done; 96 97 /** 98 * @hw_done: 99 * 100 * Will be signalled when all hw register changes for this commit have 101 * been written out. Especially when disabling a pipe this can be much 102 * later than than @flip_done, since that can signal already when the 103 * screen goes black, whereas to fully shut down a pipe more register 104 * I/O is required. 105 * 106 * Note that this does not need to include separately reference-counted 107 * resources like backing storage buffer pinning, or runtime pm 108 * management. 109 */ 110 struct completion hw_done; 111 112 /** 113 * @cleanup_done: 114 * 115 * Will be signalled after old buffers have been cleaned up by calling 116 * drm_atomic_helper_cleanup_planes(). Since this can only happen after 117 * a vblank wait completed it might be a bit later. This completion is 118 * useful to throttle updates and avoid hardware updates getting ahead 119 * of the buffer cleanup too much. 120 */ 121 struct completion cleanup_done; 122 123 /** 124 * @commit_entry: 125 * 126 * Entry on the per-CRTC &drm_crtc.commit_list. Protected by 127 * $drm_crtc.commit_lock. 128 */ 129 struct list_head commit_entry; 130 131 /** 132 * @event: 133 * 134 * &drm_pending_vblank_event pointer to clean up private events. 135 */ 136 struct drm_pending_vblank_event *event; 137 }; 138 139 struct __drm_planes_state { 140 struct drm_plane *ptr; 141 struct drm_plane_state *state, *old_state, *new_state; 142 }; 143 144 struct __drm_crtcs_state { 145 struct drm_crtc *ptr; 146 struct drm_crtc_state *state, *old_state, *new_state; 147 s32 __user *out_fence_ptr; 148 unsigned last_vblank_count; 149 }; 150 151 struct __drm_connnectors_state { 152 struct drm_connector *ptr; 153 struct drm_connector_state *state, *old_state, *new_state; 154 }; 155 156 struct drm_private_obj; 157 struct drm_private_state; 158 159 /** 160 * struct drm_private_state_funcs - atomic state functions for private objects 161 * 162 * These hooks are used by atomic helpers to create, swap and destroy states of 163 * private objects. The structure itself is used as a vtable to identify the 164 * associated private object type. Each private object type that needs to be 165 * added to the atomic states is expected to have an implementation of these 166 * hooks and pass a pointer to it's drm_private_state_funcs struct to 167 * drm_atomic_get_private_obj_state(). 168 */ 169 struct drm_private_state_funcs { 170 /** 171 * @atomic_duplicate_state: 172 * 173 * Duplicate the current state of the private object and return it. It 174 * is an error to call this before obj->state has been initialized. 175 * 176 * RETURNS: 177 * 178 * Duplicated atomic state or NULL when obj->state is not 179 * initialized or allocation failed. 180 */ 181 struct drm_private_state *(*atomic_duplicate_state)(struct drm_private_obj *obj); 182 183 /** 184 * @atomic_destroy_state: 185 * 186 * Frees the private object state created with @atomic_duplicate_state. 187 */ 188 void (*atomic_destroy_state)(struct drm_private_obj *obj, 189 struct drm_private_state *state); 190 }; 191 192 struct drm_private_obj { 193 struct drm_private_state *state; 194 195 const struct drm_private_state_funcs *funcs; 196 }; 197 198 struct drm_private_state { 199 struct drm_atomic_state *state; 200 }; 201 202 struct __drm_private_objs_state { 203 struct drm_private_obj *ptr; 204 struct drm_private_state *state, *old_state, *new_state; 205 }; 206 207 /** 208 * struct drm_atomic_state - the global state object for atomic updates 209 * @ref: count of all references to this state (will not be freed until zero) 210 * @dev: parent DRM device 211 * @allow_modeset: allow full modeset 212 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics 213 * @async_update: hint for asynchronous plane update 214 * @planes: pointer to array of structures with per-plane data 215 * @crtcs: pointer to array of CRTC pointers 216 * @num_connector: size of the @connectors and @connector_states arrays 217 * @connectors: pointer to array of structures with per-connector data 218 * @num_private_objs: size of the @private_objs array 219 * @private_objs: pointer to array of private object pointers 220 * @acquire_ctx: acquire context for this atomic modeset state update 221 */ 222 struct drm_atomic_state { 223 struct kref ref; 224 225 struct drm_device *dev; 226 bool allow_modeset : 1; 227 bool legacy_cursor_update : 1; 228 bool async_update : 1; 229 struct __drm_planes_state *planes; 230 struct __drm_crtcs_state *crtcs; 231 int num_connector; 232 struct __drm_connnectors_state *connectors; 233 int num_private_objs; 234 struct __drm_private_objs_state *private_objs; 235 236 struct drm_modeset_acquire_ctx *acquire_ctx; 237 238 /** 239 * @fake_commit: 240 * 241 * Used for signaling unbound planes/connectors. 242 * When a connector or plane is not bound to any CRTC, it's still important 243 * to preserve linearity to prevent the atomic states from being freed to early. 244 * 245 * This commit (if set) is not bound to any crtc, but will be completed when 246 * drm_atomic_helper_commit_hw_done() is called. 247 */ 248 struct drm_crtc_commit *fake_commit; 249 250 /** 251 * @commit_work: 252 * 253 * Work item which can be used by the driver or helpers to execute the 254 * commit without blocking. 255 */ 256 struct work_struct commit_work; 257 }; 258 259 void __drm_crtc_commit_free(struct kref *kref); 260 261 /** 262 * drm_crtc_commit_get - acquire a reference to the CRTC commit 263 * @commit: CRTC commit 264 * 265 * Increases the reference of @commit. 266 * 267 * Returns: 268 * The pointer to @commit, with reference increased. 269 */ 270 static inline struct drm_crtc_commit *drm_crtc_commit_get(struct drm_crtc_commit *commit) 271 { 272 kref_get(&commit->ref); 273 return commit; 274 } 275 276 /** 277 * drm_crtc_commit_put - release a reference to the CRTC commmit 278 * @commit: CRTC commit 279 * 280 * This releases a reference to @commit which is freed after removing the 281 * final reference. No locking required and callable from any context. 282 */ 283 static inline void drm_crtc_commit_put(struct drm_crtc_commit *commit) 284 { 285 kref_put(&commit->ref, __drm_crtc_commit_free); 286 } 287 288 struct drm_atomic_state * __must_check 289 drm_atomic_state_alloc(struct drm_device *dev); 290 void drm_atomic_state_clear(struct drm_atomic_state *state); 291 292 /** 293 * drm_atomic_state_get - acquire a reference to the atomic state 294 * @state: The atomic state 295 * 296 * Returns a new reference to the @state 297 */ 298 static inline struct drm_atomic_state * 299 drm_atomic_state_get(struct drm_atomic_state *state) 300 { 301 kref_get(&state->ref); 302 return state; 303 } 304 305 void __drm_atomic_state_free(struct kref *ref); 306 307 /** 308 * drm_atomic_state_put - release a reference to the atomic state 309 * @state: The atomic state 310 * 311 * This releases a reference to @state which is freed after removing the 312 * final reference. No locking required and callable from any context. 313 */ 314 static inline void drm_atomic_state_put(struct drm_atomic_state *state) 315 { 316 kref_put(&state->ref, __drm_atomic_state_free); 317 } 318 319 int __must_check 320 drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state); 321 void drm_atomic_state_default_clear(struct drm_atomic_state *state); 322 void drm_atomic_state_default_release(struct drm_atomic_state *state); 323 324 struct drm_crtc_state * __must_check 325 drm_atomic_get_crtc_state(struct drm_atomic_state *state, 326 struct drm_crtc *crtc); 327 int drm_atomic_crtc_set_property(struct drm_crtc *crtc, 328 struct drm_crtc_state *state, struct drm_property *property, 329 uint64_t val); 330 struct drm_plane_state * __must_check 331 drm_atomic_get_plane_state(struct drm_atomic_state *state, 332 struct drm_plane *plane); 333 struct drm_connector_state * __must_check 334 drm_atomic_get_connector_state(struct drm_atomic_state *state, 335 struct drm_connector *connector); 336 337 void drm_atomic_private_obj_init(struct drm_private_obj *obj, 338 struct drm_private_state *state, 339 const struct drm_private_state_funcs *funcs); 340 void drm_atomic_private_obj_fini(struct drm_private_obj *obj); 341 342 struct drm_private_state * __must_check 343 drm_atomic_get_private_obj_state(struct drm_atomic_state *state, 344 struct drm_private_obj *obj); 345 346 /** 347 * drm_atomic_get_existing_crtc_state - get crtc state, if it exists 348 * @state: global atomic state object 349 * @crtc: crtc to grab 350 * 351 * This function returns the crtc state for the given crtc, or NULL 352 * if the crtc is not part of the global atomic state. 353 * 354 * This function is deprecated, @drm_atomic_get_old_crtc_state or 355 * @drm_atomic_get_new_crtc_state should be used instead. 356 */ 357 static inline struct drm_crtc_state * 358 drm_atomic_get_existing_crtc_state(struct drm_atomic_state *state, 359 struct drm_crtc *crtc) 360 { 361 return state->crtcs[drm_crtc_index(crtc)].state; 362 } 363 364 /** 365 * drm_atomic_get_old_crtc_state - get old crtc state, if it exists 366 * @state: global atomic state object 367 * @crtc: crtc to grab 368 * 369 * This function returns the old crtc state for the given crtc, or 370 * NULL if the crtc is not part of the global atomic state. 371 */ 372 static inline struct drm_crtc_state * 373 drm_atomic_get_old_crtc_state(struct drm_atomic_state *state, 374 struct drm_crtc *crtc) 375 { 376 return state->crtcs[drm_crtc_index(crtc)].old_state; 377 } 378 /** 379 * drm_atomic_get_new_crtc_state - get new crtc state, if it exists 380 * @state: global atomic state object 381 * @crtc: crtc to grab 382 * 383 * This function returns the new crtc state for the given crtc, or 384 * NULL if the crtc is not part of the global atomic state. 385 */ 386 static inline struct drm_crtc_state * 387 drm_atomic_get_new_crtc_state(struct drm_atomic_state *state, 388 struct drm_crtc *crtc) 389 { 390 return state->crtcs[drm_crtc_index(crtc)].new_state; 391 } 392 393 /** 394 * drm_atomic_get_existing_plane_state - get plane state, if it exists 395 * @state: global atomic state object 396 * @plane: plane to grab 397 * 398 * This function returns the plane state for the given plane, or NULL 399 * if the plane is not part of the global atomic state. 400 * 401 * This function is deprecated, @drm_atomic_get_old_plane_state or 402 * @drm_atomic_get_new_plane_state should be used instead. 403 */ 404 static inline struct drm_plane_state * 405 drm_atomic_get_existing_plane_state(struct drm_atomic_state *state, 406 struct drm_plane *plane) 407 { 408 return state->planes[drm_plane_index(plane)].state; 409 } 410 411 /** 412 * drm_atomic_get_old_plane_state - get plane state, if it exists 413 * @state: global atomic state object 414 * @plane: plane to grab 415 * 416 * This function returns the old plane state for the given plane, or 417 * NULL if the plane is not part of the global atomic state. 418 */ 419 static inline struct drm_plane_state * 420 drm_atomic_get_old_plane_state(struct drm_atomic_state *state, 421 struct drm_plane *plane) 422 { 423 return state->planes[drm_plane_index(plane)].old_state; 424 } 425 426 /** 427 * drm_atomic_get_new_plane_state - get plane state, if it exists 428 * @state: global atomic state object 429 * @plane: plane to grab 430 * 431 * This function returns the new plane state for the given plane, or 432 * NULL if the plane is not part of the global atomic state. 433 */ 434 static inline struct drm_plane_state * 435 drm_atomic_get_new_plane_state(struct drm_atomic_state *state, 436 struct drm_plane *plane) 437 { 438 return state->planes[drm_plane_index(plane)].new_state; 439 } 440 441 /** 442 * drm_atomic_get_existing_connector_state - get connector state, if it exists 443 * @state: global atomic state object 444 * @connector: connector to grab 445 * 446 * This function returns the connector state for the given connector, 447 * or NULL if the connector is not part of the global atomic state. 448 * 449 * This function is deprecated, @drm_atomic_get_old_connector_state or 450 * @drm_atomic_get_new_connector_state should be used instead. 451 */ 452 static inline struct drm_connector_state * 453 drm_atomic_get_existing_connector_state(struct drm_atomic_state *state, 454 struct drm_connector *connector) 455 { 456 int index = drm_connector_index(connector); 457 458 if (index >= state->num_connector) 459 return NULL; 460 461 return state->connectors[index].state; 462 } 463 464 /** 465 * drm_atomic_get_old_connector_state - get connector state, if it exists 466 * @state: global atomic state object 467 * @connector: connector to grab 468 * 469 * This function returns the old connector state for the given connector, 470 * or NULL if the connector is not part of the global atomic state. 471 */ 472 static inline struct drm_connector_state * 473 drm_atomic_get_old_connector_state(struct drm_atomic_state *state, 474 struct drm_connector *connector) 475 { 476 int index = drm_connector_index(connector); 477 478 if (index >= state->num_connector) 479 return NULL; 480 481 return state->connectors[index].old_state; 482 } 483 484 /** 485 * drm_atomic_get_new_connector_state - get connector state, if it exists 486 * @state: global atomic state object 487 * @connector: connector to grab 488 * 489 * This function returns the new connector state for the given connector, 490 * or NULL if the connector is not part of the global atomic state. 491 */ 492 static inline struct drm_connector_state * 493 drm_atomic_get_new_connector_state(struct drm_atomic_state *state, 494 struct drm_connector *connector) 495 { 496 int index = drm_connector_index(connector); 497 498 if (index >= state->num_connector) 499 return NULL; 500 501 return state->connectors[index].new_state; 502 } 503 504 /** 505 * __drm_atomic_get_current_plane_state - get current plane state 506 * @state: global atomic state object 507 * @plane: plane to grab 508 * 509 * This function returns the plane state for the given plane, either from 510 * @state, or if the plane isn't part of the atomic state update, from @plane. 511 * This is useful in atomic check callbacks, when drivers need to peek at, but 512 * not change, state of other planes, since it avoids threading an error code 513 * back up the call chain. 514 * 515 * WARNING: 516 * 517 * Note that this function is in general unsafe since it doesn't check for the 518 * required locking for access state structures. Drivers must ensure that it is 519 * safe to access the returned state structure through other means. One common 520 * example is when planes are fixed to a single CRTC, and the driver knows that 521 * the CRTC lock is held already. In that case holding the CRTC lock gives a 522 * read-lock on all planes connected to that CRTC. But if planes can be 523 * reassigned things get more tricky. In that case it's better to use 524 * drm_atomic_get_plane_state and wire up full error handling. 525 * 526 * Returns: 527 * 528 * Read-only pointer to the current plane state. 529 */ 530 static inline const struct drm_plane_state * 531 __drm_atomic_get_current_plane_state(struct drm_atomic_state *state, 532 struct drm_plane *plane) 533 { 534 if (state->planes[drm_plane_index(plane)].state) 535 return state->planes[drm_plane_index(plane)].state; 536 537 return plane->state; 538 } 539 540 int __must_check 541 drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state, 542 const struct drm_display_mode *mode); 543 int __must_check 544 drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state, 545 struct drm_property_blob *blob); 546 int __must_check 547 drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state, 548 struct drm_crtc *crtc); 549 void drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state, 550 struct drm_framebuffer *fb); 551 void drm_atomic_set_fence_for_plane(struct drm_plane_state *plane_state, 552 struct dma_fence *fence); 553 int __must_check 554 drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state, 555 struct drm_crtc *crtc); 556 int __must_check 557 drm_atomic_add_affected_connectors(struct drm_atomic_state *state, 558 struct drm_crtc *crtc); 559 int __must_check 560 drm_atomic_add_affected_planes(struct drm_atomic_state *state, 561 struct drm_crtc *crtc); 562 563 void 564 drm_atomic_clean_old_fb(struct drm_device *dev, unsigned plane_mask, int ret); 565 566 int __must_check drm_atomic_check_only(struct drm_atomic_state *state); 567 int __must_check drm_atomic_commit(struct drm_atomic_state *state); 568 int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state); 569 570 void drm_state_dump(struct drm_device *dev, struct drm_printer *p); 571 572 /** 573 * for_each_oldnew_connector_in_state - iterate over all connectors in an atomic update 574 * @__state: &struct drm_atomic_state pointer 575 * @connector: &struct drm_connector iteration cursor 576 * @old_connector_state: &struct drm_connector_state iteration cursor for the 577 * old state 578 * @new_connector_state: &struct drm_connector_state iteration cursor for the 579 * new state 580 * @__i: int iteration cursor, for macro-internal use 581 * 582 * This iterates over all connectors in an atomic update, tracking both old and 583 * new state. This is useful in places where the state delta needs to be 584 * considered, for example in atomic check functions. 585 */ 586 #define for_each_oldnew_connector_in_state(__state, connector, old_connector_state, new_connector_state, __i) \ 587 for ((__i) = 0; \ 588 (__i) < (__state)->num_connector; \ 589 (__i)++) \ 590 for_each_if ((__state)->connectors[__i].ptr && \ 591 ((connector) = (__state)->connectors[__i].ptr, \ 592 (old_connector_state) = (__state)->connectors[__i].old_state, \ 593 (new_connector_state) = (__state)->connectors[__i].new_state, 1)) 594 595 /** 596 * for_each_old_connector_in_state - iterate over all connectors in an atomic update 597 * @__state: &struct drm_atomic_state pointer 598 * @connector: &struct drm_connector iteration cursor 599 * @old_connector_state: &struct drm_connector_state iteration cursor for the 600 * old state 601 * @__i: int iteration cursor, for macro-internal use 602 * 603 * This iterates over all connectors in an atomic update, tracking only the old 604 * state. This is useful in disable functions, where we need the old state the 605 * hardware is still in. 606 */ 607 #define for_each_old_connector_in_state(__state, connector, old_connector_state, __i) \ 608 for ((__i) = 0; \ 609 (__i) < (__state)->num_connector; \ 610 (__i)++) \ 611 for_each_if ((__state)->connectors[__i].ptr && \ 612 ((connector) = (__state)->connectors[__i].ptr, \ 613 (old_connector_state) = (__state)->connectors[__i].old_state, 1)) 614 615 /** 616 * for_each_new_connector_in_state - iterate over all connectors in an atomic update 617 * @__state: &struct drm_atomic_state pointer 618 * @connector: &struct drm_connector iteration cursor 619 * @new_connector_state: &struct drm_connector_state iteration cursor for the 620 * new state 621 * @__i: int iteration cursor, for macro-internal use 622 * 623 * This iterates over all connectors in an atomic update, tracking only the new 624 * state. This is useful in enable functions, where we need the new state the 625 * hardware should be in when the atomic commit operation has completed. 626 */ 627 #define for_each_new_connector_in_state(__state, connector, new_connector_state, __i) \ 628 for ((__i) = 0; \ 629 (__i) < (__state)->num_connector; \ 630 (__i)++) \ 631 for_each_if ((__state)->connectors[__i].ptr && \ 632 ((connector) = (__state)->connectors[__i].ptr, \ 633 (new_connector_state) = (__state)->connectors[__i].new_state, 1)) 634 635 /** 636 * for_each_oldnew_crtc_in_state - iterate over all CRTCs in an atomic update 637 * @__state: &struct drm_atomic_state pointer 638 * @crtc: &struct drm_crtc iteration cursor 639 * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state 640 * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state 641 * @__i: int iteration cursor, for macro-internal use 642 * 643 * This iterates over all CRTCs in an atomic update, tracking both old and 644 * new state. This is useful in places where the state delta needs to be 645 * considered, for example in atomic check functions. 646 */ 647 #define for_each_oldnew_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \ 648 for ((__i) = 0; \ 649 (__i) < (__state)->dev->mode_config.num_crtc; \ 650 (__i)++) \ 651 for_each_if ((__state)->crtcs[__i].ptr && \ 652 ((crtc) = (__state)->crtcs[__i].ptr, \ 653 (old_crtc_state) = (__state)->crtcs[__i].old_state, \ 654 (new_crtc_state) = (__state)->crtcs[__i].new_state, 1)) 655 656 /** 657 * for_each_old_crtc_in_state - iterate over all CRTCs in an atomic update 658 * @__state: &struct drm_atomic_state pointer 659 * @crtc: &struct drm_crtc iteration cursor 660 * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state 661 * @__i: int iteration cursor, for macro-internal use 662 * 663 * This iterates over all CRTCs in an atomic update, tracking only the old 664 * state. This is useful in disable functions, where we need the old state the 665 * hardware is still in. 666 */ 667 #define for_each_old_crtc_in_state(__state, crtc, old_crtc_state, __i) \ 668 for ((__i) = 0; \ 669 (__i) < (__state)->dev->mode_config.num_crtc; \ 670 (__i)++) \ 671 for_each_if ((__state)->crtcs[__i].ptr && \ 672 ((crtc) = (__state)->crtcs[__i].ptr, \ 673 (old_crtc_state) = (__state)->crtcs[__i].old_state, 1)) 674 675 /** 676 * for_each_new_crtc_in_state - iterate over all CRTCs in an atomic update 677 * @__state: &struct drm_atomic_state pointer 678 * @crtc: &struct drm_crtc iteration cursor 679 * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state 680 * @__i: int iteration cursor, for macro-internal use 681 * 682 * This iterates over all CRTCs in an atomic update, tracking only the new 683 * state. This is useful in enable functions, where we need the new state the 684 * hardware should be in when the atomic commit operation has completed. 685 */ 686 #define for_each_new_crtc_in_state(__state, crtc, new_crtc_state, __i) \ 687 for ((__i) = 0; \ 688 (__i) < (__state)->dev->mode_config.num_crtc; \ 689 (__i)++) \ 690 for_each_if ((__state)->crtcs[__i].ptr && \ 691 ((crtc) = (__state)->crtcs[__i].ptr, \ 692 (new_crtc_state) = (__state)->crtcs[__i].new_state, 1)) 693 694 /** 695 * for_each_oldnew_plane_in_state - iterate over all planes in an atomic update 696 * @__state: &struct drm_atomic_state pointer 697 * @plane: &struct drm_plane iteration cursor 698 * @old_plane_state: &struct drm_plane_state iteration cursor for the old state 699 * @new_plane_state: &struct drm_plane_state iteration cursor for the new state 700 * @__i: int iteration cursor, for macro-internal use 701 * 702 * This iterates over all planes in an atomic update, tracking both old and 703 * new state. This is useful in places where the state delta needs to be 704 * considered, for example in atomic check functions. 705 */ 706 #define for_each_oldnew_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \ 707 for ((__i) = 0; \ 708 (__i) < (__state)->dev->mode_config.num_total_plane; \ 709 (__i)++) \ 710 for_each_if ((__state)->planes[__i].ptr && \ 711 ((plane) = (__state)->planes[__i].ptr, \ 712 (old_plane_state) = (__state)->planes[__i].old_state,\ 713 (new_plane_state) = (__state)->planes[__i].new_state, 1)) 714 715 /** 716 * for_each_old_plane_in_state - iterate over all planes in an atomic update 717 * @__state: &struct drm_atomic_state pointer 718 * @plane: &struct drm_plane iteration cursor 719 * @old_plane_state: &struct drm_plane_state iteration cursor for the old state 720 * @__i: int iteration cursor, for macro-internal use 721 * 722 * This iterates over all planes in an atomic update, tracking only the old 723 * state. This is useful in disable functions, where we need the old state the 724 * hardware is still in. 725 */ 726 #define for_each_old_plane_in_state(__state, plane, old_plane_state, __i) \ 727 for ((__i) = 0; \ 728 (__i) < (__state)->dev->mode_config.num_total_plane; \ 729 (__i)++) \ 730 for_each_if ((__state)->planes[__i].ptr && \ 731 ((plane) = (__state)->planes[__i].ptr, \ 732 (old_plane_state) = (__state)->planes[__i].old_state, 1)) 733 /** 734 * for_each_new_plane_in_state - iterate over all planes in an atomic update 735 * @__state: &struct drm_atomic_state pointer 736 * @plane: &struct drm_plane iteration cursor 737 * @new_plane_state: &struct drm_plane_state iteration cursor for the new state 738 * @__i: int iteration cursor, for macro-internal use 739 * 740 * This iterates over all planes in an atomic update, tracking only the new 741 * state. This is useful in enable functions, where we need the new state the 742 * hardware should be in when the atomic commit operation has completed. 743 */ 744 #define for_each_new_plane_in_state(__state, plane, new_plane_state, __i) \ 745 for ((__i) = 0; \ 746 (__i) < (__state)->dev->mode_config.num_total_plane; \ 747 (__i)++) \ 748 for_each_if ((__state)->planes[__i].ptr && \ 749 ((plane) = (__state)->planes[__i].ptr, \ 750 (new_plane_state) = (__state)->planes[__i].new_state, 1)) 751 752 /** 753 * for_each_oldnew_private_obj_in_state - iterate over all private objects in an atomic update 754 * @__state: &struct drm_atomic_state pointer 755 * @obj: &struct drm_private_obj iteration cursor 756 * @old_obj_state: &struct drm_private_state iteration cursor for the old state 757 * @new_obj_state: &struct drm_private_state iteration cursor for the new state 758 * @__i: int iteration cursor, for macro-internal use 759 * 760 * This iterates over all private objects in an atomic update, tracking both 761 * old and new state. This is useful in places where the state delta needs 762 * to be considered, for example in atomic check functions. 763 */ 764 #define for_each_oldnew_private_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \ 765 for ((__i) = 0; \ 766 (__i) < (__state)->num_private_objs && \ 767 ((obj) = (__state)->private_objs[__i].ptr, \ 768 (old_obj_state) = (__state)->private_objs[__i].old_state, \ 769 (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \ 770 (__i)++) 771 772 /** 773 * for_each_old_private_obj_in_state - iterate over all private objects in an atomic update 774 * @__state: &struct drm_atomic_state pointer 775 * @obj: &struct drm_private_obj iteration cursor 776 * @old_obj_state: &struct drm_private_state iteration cursor for the old state 777 * @__i: int iteration cursor, for macro-internal use 778 * 779 * This iterates over all private objects in an atomic update, tracking only 780 * the old state. This is useful in disable functions, where we need the old 781 * state the hardware is still in. 782 */ 783 #define for_each_old_private_obj_in_state(__state, obj, old_obj_state, __i) \ 784 for ((__i) = 0; \ 785 (__i) < (__state)->num_private_objs && \ 786 ((obj) = (__state)->private_objs[__i].ptr, \ 787 (old_obj_state) = (__state)->private_objs[__i].old_state, 1); \ 788 (__i)++) 789 790 /** 791 * for_each_new_private_obj_in_state - iterate over all private objects in an atomic update 792 * @__state: &struct drm_atomic_state pointer 793 * @obj: &struct drm_private_obj iteration cursor 794 * @new_obj_state: &struct drm_private_state iteration cursor for the new state 795 * @__i: int iteration cursor, for macro-internal use 796 * 797 * This iterates over all private objects in an atomic update, tracking only 798 * the new state. This is useful in enable functions, where we need the new state the 799 * hardware should be in when the atomic commit operation has completed. 800 */ 801 #define for_each_new_private_obj_in_state(__state, obj, new_obj_state, __i) \ 802 for ((__i) = 0; \ 803 (__i) < (__state)->num_private_objs && \ 804 ((obj) = (__state)->private_objs[__i].ptr, \ 805 (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \ 806 (__i)++) 807 808 /** 809 * drm_atomic_crtc_needs_modeset - compute combined modeset need 810 * @state: &drm_crtc_state for the CRTC 811 * 812 * To give drivers flexibility &struct drm_crtc_state has 3 booleans to track 813 * whether the state CRTC changed enough to need a full modeset cycle: 814 * mode_changed, active_changed and connectors_changed. This helper simply 815 * combines these three to compute the overall need for a modeset for @state. 816 * 817 * The atomic helper code sets these booleans, but drivers can and should 818 * change them appropriately to accurately represent whether a modeset is 819 * really needed. In general, drivers should avoid full modesets whenever 820 * possible. 821 * 822 * For example if the CRTC mode has changed, and the hardware is able to enact 823 * the requested mode change without going through a full modeset, the driver 824 * should clear mode_changed in its &drm_mode_config_funcs.atomic_check 825 * implementation. 826 */ 827 static inline bool 828 drm_atomic_crtc_needs_modeset(const struct drm_crtc_state *state) 829 { 830 return state->mode_changed || state->active_changed || 831 state->connectors_changed; 832 } 833 834 #endif /* DRM_ATOMIC_H_ */ 835