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