Home | History | Annotate | Line # | Download | only in drm
      1  1.4  riastrad /*	$NetBSD: drm_atomic.h,v 1.4 2021/12/19 01:57:35 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright (C) 2014 Red Hat
      5  1.1  riastrad  * Copyright (C) 2014 Intel Corp.
      6  1.1  riastrad  *
      7  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      8  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      9  1.1  riastrad  * to deal in the Software without restriction, including without limitation
     10  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     11  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     12  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     13  1.1  riastrad  *
     14  1.1  riastrad  * The above copyright notice and this permission notice shall be included in
     15  1.1  riastrad  * all copies or substantial portions of the Software.
     16  1.1  riastrad  *
     17  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     18  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     19  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     20  1.1  riastrad  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     21  1.1  riastrad  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     22  1.1  riastrad  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     23  1.1  riastrad  * OTHER DEALINGS IN THE SOFTWARE.
     24  1.1  riastrad  *
     25  1.1  riastrad  * Authors:
     26  1.1  riastrad  * Rob Clark <robdclark (at) gmail.com>
     27  1.1  riastrad  * Daniel Vetter <daniel.vetter (at) ffwll.ch>
     28  1.1  riastrad  */
     29  1.1  riastrad 
     30  1.1  riastrad #ifndef DRM_ATOMIC_H_
     31  1.1  riastrad #define DRM_ATOMIC_H_
     32  1.1  riastrad 
     33  1.4  riastrad #include <linux/completion.h>
     34  1.1  riastrad #include <drm/drm_crtc.h>
     35  1.3  riastrad #include <drm/drm_util.h>
     36  1.3  riastrad 
     37  1.3  riastrad /**
     38  1.3  riastrad  * struct drm_crtc_commit - track modeset commits on a CRTC
     39  1.3  riastrad  *
     40  1.3  riastrad  * This structure is used to track pending modeset changes and atomic commit on
     41  1.3  riastrad  * a per-CRTC basis. Since updating the list should never block, this structure
     42  1.3  riastrad  * is reference counted to allow waiters to safely wait on an event to complete,
     43  1.3  riastrad  * without holding any locks.
     44  1.3  riastrad  *
     45  1.3  riastrad  * It has 3 different events in total to allow a fine-grained synchronization
     46  1.3  riastrad  * between outstanding updates::
     47  1.3  riastrad  *
     48  1.3  riastrad  *	atomic commit thread			hardware
     49  1.3  riastrad  *
     50  1.3  riastrad  * 	write new state into hardware	---->	...
     51  1.3  riastrad  * 	signal hw_done
     52  1.3  riastrad  * 						switch to new state on next
     53  1.3  riastrad  * 	...					v/hblank
     54  1.3  riastrad  *
     55  1.3  riastrad  *	wait for buffers to show up		...
     56  1.3  riastrad  *
     57  1.3  riastrad  *	...					send completion irq
     58  1.3  riastrad  *						irq handler signals flip_done
     59  1.3  riastrad  *	cleanup old buffers
     60  1.3  riastrad  *
     61  1.3  riastrad  * 	signal cleanup_done
     62  1.3  riastrad  *
     63  1.3  riastrad  * 	wait for flip_done		<----
     64  1.3  riastrad  * 	clean up atomic state
     65  1.3  riastrad  *
     66  1.3  riastrad  * The important bit to know is that &cleanup_done is the terminal event, but the
     67  1.3  riastrad  * ordering between &flip_done and &hw_done is entirely up to the specific driver
     68  1.3  riastrad  * and modeset state change.
     69  1.3  riastrad  *
     70  1.3  riastrad  * For an implementation of how to use this look at
     71  1.3  riastrad  * drm_atomic_helper_setup_commit() from the atomic helper library.
     72  1.3  riastrad  */
     73  1.3  riastrad struct drm_crtc_commit {
     74  1.3  riastrad 	/**
     75  1.3  riastrad 	 * @crtc:
     76  1.3  riastrad 	 *
     77  1.3  riastrad 	 * DRM CRTC for this commit.
     78  1.3  riastrad 	 */
     79  1.3  riastrad 	struct drm_crtc *crtc;
     80  1.3  riastrad 
     81  1.3  riastrad 	/**
     82  1.3  riastrad 	 * @ref:
     83  1.3  riastrad 	 *
     84  1.3  riastrad 	 * Reference count for this structure. Needed to allow blocking on
     85  1.3  riastrad 	 * completions without the risk of the completion disappearing
     86  1.3  riastrad 	 * meanwhile.
     87  1.3  riastrad 	 */
     88  1.3  riastrad 	struct kref ref;
     89  1.3  riastrad 
     90  1.3  riastrad 	/**
     91  1.3  riastrad 	 * @flip_done:
     92  1.3  riastrad 	 *
     93  1.3  riastrad 	 * Will be signaled when the hardware has flipped to the new set of
     94  1.3  riastrad 	 * buffers. Signals at the same time as when the drm event for this
     95  1.3  riastrad 	 * commit is sent to userspace, or when an out-fence is singalled. Note
     96  1.3  riastrad 	 * that for most hardware, in most cases this happens after @hw_done is
     97  1.3  riastrad 	 * signalled.
     98  1.3  riastrad 	 *
     99  1.3  riastrad 	 * Completion of this stage is signalled implicitly by calling
    100  1.3  riastrad 	 * drm_crtc_send_vblank_event() on &drm_crtc_state.event.
    101  1.3  riastrad 	 */
    102  1.3  riastrad 	struct completion flip_done;
    103  1.3  riastrad 
    104  1.3  riastrad 	/**
    105  1.3  riastrad 	 * @hw_done:
    106  1.3  riastrad 	 *
    107  1.3  riastrad 	 * Will be signalled when all hw register changes for this commit have
    108  1.3  riastrad 	 * been written out. Especially when disabling a pipe this can be much
    109  1.3  riastrad 	 * later than than @flip_done, since that can signal already when the
    110  1.3  riastrad 	 * screen goes black, whereas to fully shut down a pipe more register
    111  1.3  riastrad 	 * I/O is required.
    112  1.3  riastrad 	 *
    113  1.3  riastrad 	 * Note that this does not need to include separately reference-counted
    114  1.3  riastrad 	 * resources like backing storage buffer pinning, or runtime pm
    115  1.3  riastrad 	 * management.
    116  1.3  riastrad 	 *
    117  1.3  riastrad 	 * Drivers should call drm_atomic_helper_commit_hw_done() to signal
    118  1.3  riastrad 	 * completion of this stage.
    119  1.3  riastrad 	 */
    120  1.3  riastrad 	struct completion hw_done;
    121  1.3  riastrad 
    122  1.3  riastrad 	/**
    123  1.3  riastrad 	 * @cleanup_done:
    124  1.3  riastrad 	 *
    125  1.3  riastrad 	 * Will be signalled after old buffers have been cleaned up by calling
    126  1.3  riastrad 	 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
    127  1.3  riastrad 	 * a vblank wait completed it might be a bit later. This completion is
    128  1.3  riastrad 	 * useful to throttle updates and avoid hardware updates getting ahead
    129  1.3  riastrad 	 * of the buffer cleanup too much.
    130  1.3  riastrad 	 *
    131  1.3  riastrad 	 * Drivers should call drm_atomic_helper_commit_cleanup_done() to signal
    132  1.3  riastrad 	 * completion of this stage.
    133  1.3  riastrad 	 */
    134  1.3  riastrad 	struct completion cleanup_done;
    135  1.3  riastrad 
    136  1.3  riastrad 	/**
    137  1.3  riastrad 	 * @commit_entry:
    138  1.3  riastrad 	 *
    139  1.3  riastrad 	 * Entry on the per-CRTC &drm_crtc.commit_list. Protected by
    140  1.3  riastrad 	 * $drm_crtc.commit_lock.
    141  1.3  riastrad 	 */
    142  1.3  riastrad 	struct list_head commit_entry;
    143  1.3  riastrad 
    144  1.3  riastrad 	/**
    145  1.3  riastrad 	 * @event:
    146  1.3  riastrad 	 *
    147  1.3  riastrad 	 * &drm_pending_vblank_event pointer to clean up private events.
    148  1.3  riastrad 	 */
    149  1.3  riastrad 	struct drm_pending_vblank_event *event;
    150  1.3  riastrad 
    151  1.3  riastrad 	/**
    152  1.3  riastrad 	 * @abort_completion:
    153  1.3  riastrad 	 *
    154  1.3  riastrad 	 * A flag that's set after drm_atomic_helper_setup_commit() takes a
    155  1.3  riastrad 	 * second reference for the completion of $drm_crtc_state.event. It's
    156  1.3  riastrad 	 * used by the free code to remove the second reference if commit fails.
    157  1.3  riastrad 	 */
    158  1.3  riastrad 	bool abort_completion;
    159  1.3  riastrad };
    160  1.3  riastrad 
    161  1.3  riastrad struct __drm_planes_state {
    162  1.3  riastrad 	struct drm_plane *ptr;
    163  1.3  riastrad 	struct drm_plane_state *state, *old_state, *new_state;
    164  1.3  riastrad };
    165  1.3  riastrad 
    166  1.3  riastrad struct __drm_crtcs_state {
    167  1.3  riastrad 	struct drm_crtc *ptr;
    168  1.3  riastrad 	struct drm_crtc_state *state, *old_state, *new_state;
    169  1.3  riastrad 
    170  1.3  riastrad 	/**
    171  1.3  riastrad 	 * @commit:
    172  1.3  riastrad 	 *
    173  1.3  riastrad 	 * A reference to the CRTC commit object that is kept for use by
    174  1.3  riastrad 	 * drm_atomic_helper_wait_for_flip_done() after
    175  1.3  riastrad 	 * drm_atomic_helper_commit_hw_done() is called. This ensures that a
    176  1.3  riastrad 	 * concurrent commit won't free a commit object that is still in use.
    177  1.3  riastrad 	 */
    178  1.3  riastrad 	struct drm_crtc_commit *commit;
    179  1.3  riastrad 
    180  1.3  riastrad 	s32 __user *out_fence_ptr;
    181  1.3  riastrad 	u64 last_vblank_count;
    182  1.3  riastrad };
    183  1.3  riastrad 
    184  1.3  riastrad struct __drm_connnectors_state {
    185  1.3  riastrad 	struct drm_connector *ptr;
    186  1.3  riastrad 	struct drm_connector_state *state, *old_state, *new_state;
    187  1.3  riastrad 	/**
    188  1.3  riastrad 	 * @out_fence_ptr:
    189  1.3  riastrad 	 *
    190  1.3  riastrad 	 * User-provided pointer which the kernel uses to return a sync_file
    191  1.3  riastrad 	 * file descriptor. Used by writeback connectors to signal completion of
    192  1.3  riastrad 	 * the writeback.
    193  1.3  riastrad 	 */
    194  1.3  riastrad 	s32 __user *out_fence_ptr;
    195  1.3  riastrad };
    196  1.3  riastrad 
    197  1.3  riastrad struct drm_private_obj;
    198  1.3  riastrad struct drm_private_state;
    199  1.3  riastrad 
    200  1.3  riastrad /**
    201  1.3  riastrad  * struct drm_private_state_funcs - atomic state functions for private objects
    202  1.3  riastrad  *
    203  1.3  riastrad  * These hooks are used by atomic helpers to create, swap and destroy states of
    204  1.3  riastrad  * private objects. The structure itself is used as a vtable to identify the
    205  1.3  riastrad  * associated private object type. Each private object type that needs to be
    206  1.3  riastrad  * added to the atomic states is expected to have an implementation of these
    207  1.3  riastrad  * hooks and pass a pointer to its drm_private_state_funcs struct to
    208  1.3  riastrad  * drm_atomic_get_private_obj_state().
    209  1.3  riastrad  */
    210  1.3  riastrad struct drm_private_state_funcs {
    211  1.3  riastrad 	/**
    212  1.3  riastrad 	 * @atomic_duplicate_state:
    213  1.3  riastrad 	 *
    214  1.3  riastrad 	 * Duplicate the current state of the private object and return it. It
    215  1.3  riastrad 	 * is an error to call this before obj->state has been initialized.
    216  1.3  riastrad 	 *
    217  1.3  riastrad 	 * RETURNS:
    218  1.3  riastrad 	 *
    219  1.3  riastrad 	 * Duplicated atomic state or NULL when obj->state is not
    220  1.3  riastrad 	 * initialized or allocation failed.
    221  1.3  riastrad 	 */
    222  1.3  riastrad 	struct drm_private_state *(*atomic_duplicate_state)(struct drm_private_obj *obj);
    223  1.3  riastrad 
    224  1.3  riastrad 	/**
    225  1.3  riastrad 	 * @atomic_destroy_state:
    226  1.3  riastrad 	 *
    227  1.3  riastrad 	 * Frees the private object state created with @atomic_duplicate_state.
    228  1.3  riastrad 	 */
    229  1.3  riastrad 	void (*atomic_destroy_state)(struct drm_private_obj *obj,
    230  1.3  riastrad 				     struct drm_private_state *state);
    231  1.3  riastrad };
    232  1.3  riastrad 
    233  1.3  riastrad /**
    234  1.3  riastrad  * struct drm_private_obj - base struct for driver private atomic object
    235  1.3  riastrad  *
    236  1.3  riastrad  * A driver private object is initialized by calling
    237  1.3  riastrad  * drm_atomic_private_obj_init() and cleaned up by calling
    238  1.3  riastrad  * drm_atomic_private_obj_fini().
    239  1.3  riastrad  *
    240  1.3  riastrad  * Currently only tracks the state update functions and the opaque driver
    241  1.3  riastrad  * private state itself, but in the future might also track which
    242  1.3  riastrad  * &drm_modeset_lock is required to duplicate and update this object's state.
    243  1.3  riastrad  *
    244  1.3  riastrad  * All private objects must be initialized before the DRM device they are
    245  1.3  riastrad  * attached to is registered to the DRM subsystem (call to drm_dev_register())
    246  1.3  riastrad  * and should stay around until this DRM device is unregistered (call to
    247  1.3  riastrad  * drm_dev_unregister()). In other words, private objects lifetime is tied
    248  1.3  riastrad  * to the DRM device lifetime. This implies that:
    249  1.3  riastrad  *
    250  1.3  riastrad  * 1/ all calls to drm_atomic_private_obj_init() must be done before calling
    251  1.3  riastrad  *    drm_dev_register()
    252  1.3  riastrad  * 2/ all calls to drm_atomic_private_obj_fini() must be done after calling
    253  1.3  riastrad  *    drm_dev_unregister()
    254  1.3  riastrad  */
    255  1.3  riastrad struct drm_private_obj {
    256  1.3  riastrad 	/**
    257  1.3  riastrad 	 * @head: List entry used to attach a private object to a &drm_device
    258  1.3  riastrad 	 * (queued to &drm_mode_config.privobj_list).
    259  1.3  riastrad 	 */
    260  1.3  riastrad 	struct list_head head;
    261  1.3  riastrad 
    262  1.3  riastrad 	/**
    263  1.3  riastrad 	 * @lock: Modeset lock to protect the state object.
    264  1.3  riastrad 	 */
    265  1.3  riastrad 	struct drm_modeset_lock lock;
    266  1.3  riastrad 
    267  1.3  riastrad 	/**
    268  1.3  riastrad 	 * @state: Current atomic state for this driver private object.
    269  1.3  riastrad 	 */
    270  1.3  riastrad 	struct drm_private_state *state;
    271  1.3  riastrad 
    272  1.3  riastrad 	/**
    273  1.3  riastrad 	 * @funcs:
    274  1.3  riastrad 	 *
    275  1.3  riastrad 	 * Functions to manipulate the state of this driver private object, see
    276  1.3  riastrad 	 * &drm_private_state_funcs.
    277  1.3  riastrad 	 */
    278  1.3  riastrad 	const struct drm_private_state_funcs *funcs;
    279  1.3  riastrad };
    280  1.3  riastrad 
    281  1.3  riastrad /**
    282  1.3  riastrad  * drm_for_each_privobj() - private object iterator
    283  1.3  riastrad  *
    284  1.3  riastrad  * @privobj: pointer to the current private object. Updated after each
    285  1.3  riastrad  *	     iteration
    286  1.3  riastrad  * @dev: the DRM device we want get private objects from
    287  1.3  riastrad  *
    288  1.3  riastrad  * Allows one to iterate over all private objects attached to @dev
    289  1.3  riastrad  */
    290  1.3  riastrad #define drm_for_each_privobj(privobj, dev) \
    291  1.3  riastrad 	list_for_each_entry(privobj, &(dev)->mode_config.privobj_list, head)
    292  1.3  riastrad 
    293  1.3  riastrad /**
    294  1.3  riastrad  * struct drm_private_state - base struct for driver private object state
    295  1.3  riastrad  * @state: backpointer to global drm_atomic_state
    296  1.3  riastrad  *
    297  1.3  riastrad  * Currently only contains a backpointer to the overall atomic update, but in
    298  1.3  riastrad  * the future also might hold synchronization information similar to e.g.
    299  1.3  riastrad  * &drm_crtc.commit.
    300  1.3  riastrad  */
    301  1.3  riastrad struct drm_private_state {
    302  1.3  riastrad 	struct drm_atomic_state *state;
    303  1.3  riastrad };
    304  1.3  riastrad 
    305  1.3  riastrad struct __drm_private_objs_state {
    306  1.3  riastrad 	struct drm_private_obj *ptr;
    307  1.3  riastrad 	struct drm_private_state *state, *old_state, *new_state;
    308  1.3  riastrad };
    309  1.3  riastrad 
    310  1.3  riastrad /**
    311  1.3  riastrad  * struct drm_atomic_state - the global state object for atomic updates
    312  1.3  riastrad  * @ref: count of all references to this state (will not be freed until zero)
    313  1.3  riastrad  * @dev: parent DRM device
    314  1.3  riastrad  * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
    315  1.3  riastrad  * @async_update: hint for asynchronous plane update
    316  1.3  riastrad  * @planes: pointer to array of structures with per-plane data
    317  1.3  riastrad  * @crtcs: pointer to array of CRTC pointers
    318  1.3  riastrad  * @num_connector: size of the @connectors and @connector_states arrays
    319  1.3  riastrad  * @connectors: pointer to array of structures with per-connector data
    320  1.3  riastrad  * @num_private_objs: size of the @private_objs array
    321  1.3  riastrad  * @private_objs: pointer to array of private object pointers
    322  1.3  riastrad  * @acquire_ctx: acquire context for this atomic modeset state update
    323  1.3  riastrad  *
    324  1.3  riastrad  * States are added to an atomic update by calling drm_atomic_get_crtc_state(),
    325  1.3  riastrad  * drm_atomic_get_plane_state(), drm_atomic_get_connector_state(), or for
    326  1.3  riastrad  * private state structures, drm_atomic_get_private_obj_state().
    327  1.3  riastrad  */
    328  1.3  riastrad struct drm_atomic_state {
    329  1.3  riastrad 	struct kref ref;
    330  1.3  riastrad 
    331  1.3  riastrad 	struct drm_device *dev;
    332  1.3  riastrad 
    333  1.3  riastrad 	/**
    334  1.3  riastrad 	 * @allow_modeset:
    335  1.3  riastrad 	 *
    336  1.3  riastrad 	 * Allow full modeset. This is used by the ATOMIC IOCTL handler to
    337  1.3  riastrad 	 * implement the DRM_MODE_ATOMIC_ALLOW_MODESET flag. Drivers should
    338  1.3  riastrad 	 * never consult this flag, instead looking at the output of
    339  1.3  riastrad 	 * drm_atomic_crtc_needs_modeset().
    340  1.3  riastrad 	 */
    341  1.3  riastrad 	bool allow_modeset : 1;
    342  1.3  riastrad 	bool legacy_cursor_update : 1;
    343  1.3  riastrad 	bool async_update : 1;
    344  1.3  riastrad 	/**
    345  1.3  riastrad 	 * @duplicated:
    346  1.3  riastrad 	 *
    347  1.3  riastrad 	 * Indicates whether or not this atomic state was duplicated using
    348  1.3  riastrad 	 * drm_atomic_helper_duplicate_state(). Drivers and atomic helpers
    349  1.3  riastrad 	 * should use this to fixup normal  inconsistencies in duplicated
    350  1.3  riastrad 	 * states.
    351  1.3  riastrad 	 */
    352  1.3  riastrad 	bool duplicated : 1;
    353  1.3  riastrad 	struct __drm_planes_state *planes;
    354  1.3  riastrad 	struct __drm_crtcs_state *crtcs;
    355  1.3  riastrad 	int num_connector;
    356  1.3  riastrad 	struct __drm_connnectors_state *connectors;
    357  1.3  riastrad 	int num_private_objs;
    358  1.3  riastrad 	struct __drm_private_objs_state *private_objs;
    359  1.3  riastrad 
    360  1.3  riastrad 	struct drm_modeset_acquire_ctx *acquire_ctx;
    361  1.3  riastrad 
    362  1.3  riastrad 	/**
    363  1.3  riastrad 	 * @fake_commit:
    364  1.3  riastrad 	 *
    365  1.3  riastrad 	 * Used for signaling unbound planes/connectors.
    366  1.3  riastrad 	 * When a connector or plane is not bound to any CRTC, it's still important
    367  1.3  riastrad 	 * to preserve linearity to prevent the atomic states from being freed to early.
    368  1.3  riastrad 	 *
    369  1.3  riastrad 	 * This commit (if set) is not bound to any CRTC, but will be completed when
    370  1.3  riastrad 	 * drm_atomic_helper_commit_hw_done() is called.
    371  1.3  riastrad 	 */
    372  1.3  riastrad 	struct drm_crtc_commit *fake_commit;
    373  1.3  riastrad 
    374  1.3  riastrad 	/**
    375  1.3  riastrad 	 * @commit_work:
    376  1.3  riastrad 	 *
    377  1.3  riastrad 	 * Work item which can be used by the driver or helpers to execute the
    378  1.3  riastrad 	 * commit without blocking.
    379  1.3  riastrad 	 */
    380  1.3  riastrad 	struct work_struct commit_work;
    381  1.3  riastrad };
    382  1.3  riastrad 
    383  1.3  riastrad void __drm_crtc_commit_free(struct kref *kref);
    384  1.3  riastrad 
    385  1.3  riastrad /**
    386  1.3  riastrad  * drm_crtc_commit_get - acquire a reference to the CRTC commit
    387  1.3  riastrad  * @commit: CRTC commit
    388  1.3  riastrad  *
    389  1.3  riastrad  * Increases the reference of @commit.
    390  1.3  riastrad  *
    391  1.3  riastrad  * Returns:
    392  1.3  riastrad  * The pointer to @commit, with reference increased.
    393  1.3  riastrad  */
    394  1.3  riastrad static inline struct drm_crtc_commit *drm_crtc_commit_get(struct drm_crtc_commit *commit)
    395  1.3  riastrad {
    396  1.3  riastrad 	kref_get(&commit->ref);
    397  1.3  riastrad 	return commit;
    398  1.3  riastrad }
    399  1.3  riastrad 
    400  1.3  riastrad /**
    401  1.3  riastrad  * drm_crtc_commit_put - release a reference to the CRTC commmit
    402  1.3  riastrad  * @commit: CRTC commit
    403  1.3  riastrad  *
    404  1.3  riastrad  * This releases a reference to @commit which is freed after removing the
    405  1.3  riastrad  * final reference. No locking required and callable from any context.
    406  1.3  riastrad  */
    407  1.3  riastrad static inline void drm_crtc_commit_put(struct drm_crtc_commit *commit)
    408  1.3  riastrad {
    409  1.3  riastrad 	kref_put(&commit->ref, __drm_crtc_commit_free);
    410  1.3  riastrad }
    411  1.1  riastrad 
    412  1.1  riastrad struct drm_atomic_state * __must_check
    413  1.1  riastrad drm_atomic_state_alloc(struct drm_device *dev);
    414  1.1  riastrad void drm_atomic_state_clear(struct drm_atomic_state *state);
    415  1.3  riastrad 
    416  1.3  riastrad /**
    417  1.3  riastrad  * drm_atomic_state_get - acquire a reference to the atomic state
    418  1.3  riastrad  * @state: The atomic state
    419  1.3  riastrad  *
    420  1.3  riastrad  * Returns a new reference to the @state
    421  1.3  riastrad  */
    422  1.3  riastrad static inline struct drm_atomic_state *
    423  1.3  riastrad drm_atomic_state_get(struct drm_atomic_state *state)
    424  1.3  riastrad {
    425  1.3  riastrad 	kref_get(&state->ref);
    426  1.3  riastrad 	return state;
    427  1.3  riastrad }
    428  1.3  riastrad 
    429  1.3  riastrad void __drm_atomic_state_free(struct kref *ref);
    430  1.3  riastrad 
    431  1.3  riastrad /**
    432  1.3  riastrad  * drm_atomic_state_put - release a reference to the atomic state
    433  1.3  riastrad  * @state: The atomic state
    434  1.3  riastrad  *
    435  1.3  riastrad  * This releases a reference to @state which is freed after removing the
    436  1.3  riastrad  * final reference. No locking required and callable from any context.
    437  1.3  riastrad  */
    438  1.3  riastrad static inline void drm_atomic_state_put(struct drm_atomic_state *state)
    439  1.3  riastrad {
    440  1.3  riastrad 	kref_put(&state->ref, __drm_atomic_state_free);
    441  1.3  riastrad }
    442  1.1  riastrad 
    443  1.1  riastrad int  __must_check
    444  1.1  riastrad drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state);
    445  1.1  riastrad void drm_atomic_state_default_clear(struct drm_atomic_state *state);
    446  1.1  riastrad void drm_atomic_state_default_release(struct drm_atomic_state *state);
    447  1.1  riastrad 
    448  1.1  riastrad struct drm_crtc_state * __must_check
    449  1.1  riastrad drm_atomic_get_crtc_state(struct drm_atomic_state *state,
    450  1.1  riastrad 			  struct drm_crtc *crtc);
    451  1.1  riastrad struct drm_plane_state * __must_check
    452  1.1  riastrad drm_atomic_get_plane_state(struct drm_atomic_state *state,
    453  1.1  riastrad 			   struct drm_plane *plane);
    454  1.1  riastrad struct drm_connector_state * __must_check
    455  1.1  riastrad drm_atomic_get_connector_state(struct drm_atomic_state *state,
    456  1.1  riastrad 			       struct drm_connector *connector);
    457  1.3  riastrad 
    458  1.3  riastrad void drm_atomic_private_obj_init(struct drm_device *dev,
    459  1.3  riastrad 				 struct drm_private_obj *obj,
    460  1.3  riastrad 				 struct drm_private_state *state,
    461  1.3  riastrad 				 const struct drm_private_state_funcs *funcs);
    462  1.3  riastrad void drm_atomic_private_obj_fini(struct drm_private_obj *obj);
    463  1.3  riastrad 
    464  1.3  riastrad struct drm_private_state * __must_check
    465  1.3  riastrad drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
    466  1.3  riastrad 				 struct drm_private_obj *obj);
    467  1.3  riastrad struct drm_private_state *
    468  1.3  riastrad drm_atomic_get_old_private_obj_state(struct drm_atomic_state *state,
    469  1.3  riastrad 				     struct drm_private_obj *obj);
    470  1.3  riastrad struct drm_private_state *
    471  1.3  riastrad drm_atomic_get_new_private_obj_state(struct drm_atomic_state *state,
    472  1.3  riastrad 				     struct drm_private_obj *obj);
    473  1.3  riastrad 
    474  1.3  riastrad struct drm_connector *
    475  1.3  riastrad drm_atomic_get_old_connector_for_encoder(struct drm_atomic_state *state,
    476  1.3  riastrad 					 struct drm_encoder *encoder);
    477  1.3  riastrad struct drm_connector *
    478  1.3  riastrad drm_atomic_get_new_connector_for_encoder(struct drm_atomic_state *state,
    479  1.3  riastrad 					 struct drm_encoder *encoder);
    480  1.1  riastrad 
    481  1.1  riastrad /**
    482  1.3  riastrad  * drm_atomic_get_existing_crtc_state - get CRTC state, if it exists
    483  1.1  riastrad  * @state: global atomic state object
    484  1.3  riastrad  * @crtc: CRTC to grab
    485  1.3  riastrad  *
    486  1.3  riastrad  * This function returns the CRTC state for the given CRTC, or NULL
    487  1.3  riastrad  * if the CRTC is not part of the global atomic state.
    488  1.1  riastrad  *
    489  1.3  riastrad  * This function is deprecated, @drm_atomic_get_old_crtc_state or
    490  1.3  riastrad  * @drm_atomic_get_new_crtc_state should be used instead.
    491  1.1  riastrad  */
    492  1.1  riastrad static inline struct drm_crtc_state *
    493  1.1  riastrad drm_atomic_get_existing_crtc_state(struct drm_atomic_state *state,
    494  1.1  riastrad 				   struct drm_crtc *crtc)
    495  1.1  riastrad {
    496  1.3  riastrad 	return state->crtcs[drm_crtc_index(crtc)].state;
    497  1.3  riastrad }
    498  1.3  riastrad 
    499  1.3  riastrad /**
    500  1.3  riastrad  * drm_atomic_get_old_crtc_state - get old CRTC state, if it exists
    501  1.3  riastrad  * @state: global atomic state object
    502  1.3  riastrad  * @crtc: CRTC to grab
    503  1.3  riastrad  *
    504  1.3  riastrad  * This function returns the old CRTC state for the given CRTC, or
    505  1.3  riastrad  * NULL if the CRTC is not part of the global atomic state.
    506  1.3  riastrad  */
    507  1.3  riastrad static inline struct drm_crtc_state *
    508  1.3  riastrad drm_atomic_get_old_crtc_state(struct drm_atomic_state *state,
    509  1.3  riastrad 			      struct drm_crtc *crtc)
    510  1.3  riastrad {
    511  1.3  riastrad 	return state->crtcs[drm_crtc_index(crtc)].old_state;
    512  1.3  riastrad }
    513  1.3  riastrad /**
    514  1.3  riastrad  * drm_atomic_get_new_crtc_state - get new CRTC state, if it exists
    515  1.3  riastrad  * @state: global atomic state object
    516  1.3  riastrad  * @crtc: CRTC to grab
    517  1.3  riastrad  *
    518  1.3  riastrad  * This function returns the new CRTC state for the given CRTC, or
    519  1.3  riastrad  * NULL if the CRTC is not part of the global atomic state.
    520  1.3  riastrad  */
    521  1.3  riastrad static inline struct drm_crtc_state *
    522  1.3  riastrad drm_atomic_get_new_crtc_state(struct drm_atomic_state *state,
    523  1.3  riastrad 			      struct drm_crtc *crtc)
    524  1.3  riastrad {
    525  1.3  riastrad 	return state->crtcs[drm_crtc_index(crtc)].new_state;
    526  1.1  riastrad }
    527  1.1  riastrad 
    528  1.1  riastrad /**
    529  1.1  riastrad  * drm_atomic_get_existing_plane_state - get plane state, if it exists
    530  1.1  riastrad  * @state: global atomic state object
    531  1.1  riastrad  * @plane: plane to grab
    532  1.1  riastrad  *
    533  1.1  riastrad  * This function returns the plane state for the given plane, or NULL
    534  1.1  riastrad  * if the plane is not part of the global atomic state.
    535  1.3  riastrad  *
    536  1.3  riastrad  * This function is deprecated, @drm_atomic_get_old_plane_state or
    537  1.3  riastrad  * @drm_atomic_get_new_plane_state should be used instead.
    538  1.1  riastrad  */
    539  1.1  riastrad static inline struct drm_plane_state *
    540  1.1  riastrad drm_atomic_get_existing_plane_state(struct drm_atomic_state *state,
    541  1.1  riastrad 				    struct drm_plane *plane)
    542  1.1  riastrad {
    543  1.3  riastrad 	return state->planes[drm_plane_index(plane)].state;
    544  1.3  riastrad }
    545  1.3  riastrad 
    546  1.3  riastrad /**
    547  1.3  riastrad  * drm_atomic_get_old_plane_state - get plane state, if it exists
    548  1.3  riastrad  * @state: global atomic state object
    549  1.3  riastrad  * @plane: plane to grab
    550  1.3  riastrad  *
    551  1.3  riastrad  * This function returns the old plane state for the given plane, or
    552  1.3  riastrad  * NULL if the plane is not part of the global atomic state.
    553  1.3  riastrad  */
    554  1.3  riastrad static inline struct drm_plane_state *
    555  1.3  riastrad drm_atomic_get_old_plane_state(struct drm_atomic_state *state,
    556  1.3  riastrad 			       struct drm_plane *plane)
    557  1.3  riastrad {
    558  1.3  riastrad 	return state->planes[drm_plane_index(plane)].old_state;
    559  1.3  riastrad }
    560  1.3  riastrad 
    561  1.3  riastrad /**
    562  1.3  riastrad  * drm_atomic_get_new_plane_state - get plane state, if it exists
    563  1.3  riastrad  * @state: global atomic state object
    564  1.3  riastrad  * @plane: plane to grab
    565  1.3  riastrad  *
    566  1.3  riastrad  * This function returns the new plane state for the given plane, or
    567  1.3  riastrad  * NULL if the plane is not part of the global atomic state.
    568  1.3  riastrad  */
    569  1.3  riastrad static inline struct drm_plane_state *
    570  1.3  riastrad drm_atomic_get_new_plane_state(struct drm_atomic_state *state,
    571  1.3  riastrad 			       struct drm_plane *plane)
    572  1.3  riastrad {
    573  1.3  riastrad 	return state->planes[drm_plane_index(plane)].new_state;
    574  1.1  riastrad }
    575  1.1  riastrad 
    576  1.1  riastrad /**
    577  1.1  riastrad  * drm_atomic_get_existing_connector_state - get connector state, if it exists
    578  1.1  riastrad  * @state: global atomic state object
    579  1.1  riastrad  * @connector: connector to grab
    580  1.1  riastrad  *
    581  1.1  riastrad  * This function returns the connector state for the given connector,
    582  1.1  riastrad  * or NULL if the connector is not part of the global atomic state.
    583  1.3  riastrad  *
    584  1.3  riastrad  * This function is deprecated, @drm_atomic_get_old_connector_state or
    585  1.3  riastrad  * @drm_atomic_get_new_connector_state should be used instead.
    586  1.1  riastrad  */
    587  1.1  riastrad static inline struct drm_connector_state *
    588  1.1  riastrad drm_atomic_get_existing_connector_state(struct drm_atomic_state *state,
    589  1.1  riastrad 					struct drm_connector *connector)
    590  1.1  riastrad {
    591  1.1  riastrad 	int index = drm_connector_index(connector);
    592  1.1  riastrad 
    593  1.1  riastrad 	if (index >= state->num_connector)
    594  1.1  riastrad 		return NULL;
    595  1.1  riastrad 
    596  1.3  riastrad 	return state->connectors[index].state;
    597  1.3  riastrad }
    598  1.3  riastrad 
    599  1.3  riastrad /**
    600  1.3  riastrad  * drm_atomic_get_old_connector_state - get connector state, if it exists
    601  1.3  riastrad  * @state: global atomic state object
    602  1.3  riastrad  * @connector: connector to grab
    603  1.3  riastrad  *
    604  1.3  riastrad  * This function returns the old connector state for the given connector,
    605  1.3  riastrad  * or NULL if the connector is not part of the global atomic state.
    606  1.3  riastrad  */
    607  1.3  riastrad static inline struct drm_connector_state *
    608  1.3  riastrad drm_atomic_get_old_connector_state(struct drm_atomic_state *state,
    609  1.3  riastrad 				   struct drm_connector *connector)
    610  1.3  riastrad {
    611  1.3  riastrad 	int index = drm_connector_index(connector);
    612  1.3  riastrad 
    613  1.3  riastrad 	if (index >= state->num_connector)
    614  1.3  riastrad 		return NULL;
    615  1.3  riastrad 
    616  1.3  riastrad 	return state->connectors[index].old_state;
    617  1.3  riastrad }
    618  1.3  riastrad 
    619  1.3  riastrad /**
    620  1.3  riastrad  * drm_atomic_get_new_connector_state - get connector state, if it exists
    621  1.3  riastrad  * @state: global atomic state object
    622  1.3  riastrad  * @connector: connector to grab
    623  1.3  riastrad  *
    624  1.3  riastrad  * This function returns the new connector state for the given connector,
    625  1.3  riastrad  * or NULL if the connector is not part of the global atomic state.
    626  1.3  riastrad  */
    627  1.3  riastrad static inline struct drm_connector_state *
    628  1.3  riastrad drm_atomic_get_new_connector_state(struct drm_atomic_state *state,
    629  1.3  riastrad 				   struct drm_connector *connector)
    630  1.3  riastrad {
    631  1.3  riastrad 	int index = drm_connector_index(connector);
    632  1.3  riastrad 
    633  1.3  riastrad 	if (index >= state->num_connector)
    634  1.3  riastrad 		return NULL;
    635  1.3  riastrad 
    636  1.3  riastrad 	return state->connectors[index].new_state;
    637  1.3  riastrad }
    638  1.3  riastrad 
    639  1.3  riastrad /**
    640  1.3  riastrad  * __drm_atomic_get_current_plane_state - get current plane state
    641  1.3  riastrad  * @state: global atomic state object
    642  1.3  riastrad  * @plane: plane to grab
    643  1.3  riastrad  *
    644  1.3  riastrad  * This function returns the plane state for the given plane, either from
    645  1.3  riastrad  * @state, or if the plane isn't part of the atomic state update, from @plane.
    646  1.3  riastrad  * This is useful in atomic check callbacks, when drivers need to peek at, but
    647  1.3  riastrad  * not change, state of other planes, since it avoids threading an error code
    648  1.3  riastrad  * back up the call chain.
    649  1.3  riastrad  *
    650  1.3  riastrad  * WARNING:
    651  1.3  riastrad  *
    652  1.3  riastrad  * Note that this function is in general unsafe since it doesn't check for the
    653  1.3  riastrad  * required locking for access state structures. Drivers must ensure that it is
    654  1.3  riastrad  * safe to access the returned state structure through other means. One common
    655  1.3  riastrad  * example is when planes are fixed to a single CRTC, and the driver knows that
    656  1.3  riastrad  * the CRTC lock is held already. In that case holding the CRTC lock gives a
    657  1.3  riastrad  * read-lock on all planes connected to that CRTC. But if planes can be
    658  1.3  riastrad  * reassigned things get more tricky. In that case it's better to use
    659  1.3  riastrad  * drm_atomic_get_plane_state and wire up full error handling.
    660  1.3  riastrad  *
    661  1.3  riastrad  * Returns:
    662  1.3  riastrad  *
    663  1.3  riastrad  * Read-only pointer to the current plane state.
    664  1.3  riastrad  */
    665  1.3  riastrad static inline const struct drm_plane_state *
    666  1.3  riastrad __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,
    667  1.3  riastrad 				     struct drm_plane *plane)
    668  1.3  riastrad {
    669  1.3  riastrad 	if (state->planes[drm_plane_index(plane)].state)
    670  1.3  riastrad 		return state->planes[drm_plane_index(plane)].state;
    671  1.3  riastrad 
    672  1.3  riastrad 	return plane->state;
    673  1.1  riastrad }
    674  1.1  riastrad 
    675  1.1  riastrad int __must_check
    676  1.1  riastrad drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
    677  1.1  riastrad 				   struct drm_crtc *crtc);
    678  1.1  riastrad int __must_check
    679  1.1  riastrad drm_atomic_add_affected_planes(struct drm_atomic_state *state,
    680  1.1  riastrad 			       struct drm_crtc *crtc);
    681  1.1  riastrad 
    682  1.3  riastrad int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
    683  1.3  riastrad int __must_check drm_atomic_commit(struct drm_atomic_state *state);
    684  1.3  riastrad int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);
    685  1.3  riastrad 
    686  1.3  riastrad void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
    687  1.3  riastrad 
    688  1.3  riastrad /**
    689  1.3  riastrad  * for_each_oldnew_connector_in_state - iterate over all connectors in an atomic update
    690  1.3  riastrad  * @__state: &struct drm_atomic_state pointer
    691  1.3  riastrad  * @connector: &struct drm_connector iteration cursor
    692  1.3  riastrad  * @old_connector_state: &struct drm_connector_state iteration cursor for the
    693  1.3  riastrad  * 	old state
    694  1.3  riastrad  * @new_connector_state: &struct drm_connector_state iteration cursor for the
    695  1.3  riastrad  * 	new state
    696  1.3  riastrad  * @__i: int iteration cursor, for macro-internal use
    697  1.3  riastrad  *
    698  1.3  riastrad  * This iterates over all connectors in an atomic update, tracking both old and
    699  1.3  riastrad  * new state. This is useful in places where the state delta needs to be
    700  1.3  riastrad  * considered, for example in atomic check functions.
    701  1.3  riastrad  */
    702  1.3  riastrad #define for_each_oldnew_connector_in_state(__state, connector, old_connector_state, new_connector_state, __i) \
    703  1.3  riastrad 	for ((__i) = 0;								\
    704  1.3  riastrad 	     (__i) < (__state)->num_connector;					\
    705  1.3  riastrad 	     (__i)++)								\
    706  1.3  riastrad 		for_each_if ((__state)->connectors[__i].ptr &&			\
    707  1.3  riastrad 			     ((connector) = (__state)->connectors[__i].ptr,	\
    708  1.3  riastrad 			     (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
    709  1.3  riastrad 			     (old_connector_state) = (__state)->connectors[__i].old_state,	\
    710  1.3  riastrad 			     (new_connector_state) = (__state)->connectors[__i].new_state, 1))
    711  1.1  riastrad 
    712  1.3  riastrad /**
    713  1.3  riastrad  * for_each_old_connector_in_state - iterate over all connectors in an atomic update
    714  1.3  riastrad  * @__state: &struct drm_atomic_state pointer
    715  1.3  riastrad  * @connector: &struct drm_connector iteration cursor
    716  1.3  riastrad  * @old_connector_state: &struct drm_connector_state iteration cursor for the
    717  1.3  riastrad  * 	old state
    718  1.3  riastrad  * @__i: int iteration cursor, for macro-internal use
    719  1.3  riastrad  *
    720  1.3  riastrad  * This iterates over all connectors in an atomic update, tracking only the old
    721  1.3  riastrad  * state. This is useful in disable functions, where we need the old state the
    722  1.3  riastrad  * hardware is still in.
    723  1.3  riastrad  */
    724  1.3  riastrad #define for_each_old_connector_in_state(__state, connector, old_connector_state, __i) \
    725  1.3  riastrad 	for ((__i) = 0;								\
    726  1.3  riastrad 	     (__i) < (__state)->num_connector;					\
    727  1.3  riastrad 	     (__i)++)								\
    728  1.3  riastrad 		for_each_if ((__state)->connectors[__i].ptr &&			\
    729  1.3  riastrad 			     ((connector) = (__state)->connectors[__i].ptr,	\
    730  1.3  riastrad 			     (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
    731  1.3  riastrad 			     (old_connector_state) = (__state)->connectors[__i].old_state, 1))
    732  1.1  riastrad 
    733  1.3  riastrad /**
    734  1.3  riastrad  * for_each_new_connector_in_state - iterate over all connectors in an atomic update
    735  1.3  riastrad  * @__state: &struct drm_atomic_state pointer
    736  1.3  riastrad  * @connector: &struct drm_connector iteration cursor
    737  1.3  riastrad  * @new_connector_state: &struct drm_connector_state iteration cursor for the
    738  1.3  riastrad  * 	new state
    739  1.3  riastrad  * @__i: int iteration cursor, for macro-internal use
    740  1.3  riastrad  *
    741  1.3  riastrad  * This iterates over all connectors in an atomic update, tracking only the new
    742  1.3  riastrad  * state. This is useful in enable functions, where we need the new state the
    743  1.3  riastrad  * hardware should be in when the atomic commit operation has completed.
    744  1.3  riastrad  */
    745  1.3  riastrad #define for_each_new_connector_in_state(__state, connector, new_connector_state, __i) \
    746  1.3  riastrad 	for ((__i) = 0;								\
    747  1.3  riastrad 	     (__i) < (__state)->num_connector;					\
    748  1.3  riastrad 	     (__i)++)								\
    749  1.3  riastrad 		for_each_if ((__state)->connectors[__i].ptr &&			\
    750  1.3  riastrad 			     ((connector) = (__state)->connectors[__i].ptr,	\
    751  1.3  riastrad 			     (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
    752  1.3  riastrad 			     (new_connector_state) = (__state)->connectors[__i].new_state, \
    753  1.3  riastrad 			     (void)(new_connector_state) /* Only to avoid unused-but-set-variable warning */, 1))
    754  1.1  riastrad 
    755  1.3  riastrad /**
    756  1.3  riastrad  * for_each_oldnew_crtc_in_state - iterate over all CRTCs in an atomic update
    757  1.3  riastrad  * @__state: &struct drm_atomic_state pointer
    758  1.3  riastrad  * @crtc: &struct drm_crtc iteration cursor
    759  1.3  riastrad  * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
    760  1.3  riastrad  * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
    761  1.3  riastrad  * @__i: int iteration cursor, for macro-internal use
    762  1.3  riastrad  *
    763  1.3  riastrad  * This iterates over all CRTCs in an atomic update, tracking both old and
    764  1.3  riastrad  * new state. This is useful in places where the state delta needs to be
    765  1.3  riastrad  * considered, for example in atomic check functions.
    766  1.3  riastrad  */
    767  1.3  riastrad #define for_each_oldnew_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \
    768  1.3  riastrad 	for ((__i) = 0;							\
    769  1.3  riastrad 	     (__i) < (__state)->dev->mode_config.num_crtc;		\
    770  1.3  riastrad 	     (__i)++)							\
    771  1.3  riastrad 		for_each_if ((__state)->crtcs[__i].ptr &&		\
    772  1.3  riastrad 			     ((crtc) = (__state)->crtcs[__i].ptr,	\
    773  1.3  riastrad 			      (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \
    774  1.3  riastrad 			     (old_crtc_state) = (__state)->crtcs[__i].old_state, \
    775  1.3  riastrad 			     (void)(old_crtc_state) /* Only to avoid unused-but-set-variable warning */, \
    776  1.3  riastrad 			     (new_crtc_state) = (__state)->crtcs[__i].new_state, 1))
    777  1.3  riastrad 
    778  1.3  riastrad /**
    779  1.3  riastrad  * for_each_old_crtc_in_state - iterate over all CRTCs in an atomic update
    780  1.3  riastrad  * @__state: &struct drm_atomic_state pointer
    781  1.3  riastrad  * @crtc: &struct drm_crtc iteration cursor
    782  1.3  riastrad  * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
    783  1.3  riastrad  * @__i: int iteration cursor, for macro-internal use
    784  1.3  riastrad  *
    785  1.3  riastrad  * This iterates over all CRTCs in an atomic update, tracking only the old
    786  1.3  riastrad  * state. This is useful in disable functions, where we need the old state the
    787  1.3  riastrad  * hardware is still in.
    788  1.3  riastrad  */
    789  1.3  riastrad #define for_each_old_crtc_in_state(__state, crtc, old_crtc_state, __i)	\
    790  1.3  riastrad 	for ((__i) = 0;							\
    791  1.3  riastrad 	     (__i) < (__state)->dev->mode_config.num_crtc;		\
    792  1.3  riastrad 	     (__i)++)							\
    793  1.3  riastrad 		for_each_if ((__state)->crtcs[__i].ptr &&		\
    794  1.3  riastrad 			     ((crtc) = (__state)->crtcs[__i].ptr,	\
    795  1.3  riastrad 			     (old_crtc_state) = (__state)->crtcs[__i].old_state, 1))
    796  1.3  riastrad 
    797  1.3  riastrad /**
    798  1.3  riastrad  * for_each_new_crtc_in_state - iterate over all CRTCs in an atomic update
    799  1.3  riastrad  * @__state: &struct drm_atomic_state pointer
    800  1.3  riastrad  * @crtc: &struct drm_crtc iteration cursor
    801  1.3  riastrad  * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
    802  1.3  riastrad  * @__i: int iteration cursor, for macro-internal use
    803  1.3  riastrad  *
    804  1.3  riastrad  * This iterates over all CRTCs in an atomic update, tracking only the new
    805  1.3  riastrad  * state. This is useful in enable functions, where we need the new state the
    806  1.3  riastrad  * hardware should be in when the atomic commit operation has completed.
    807  1.3  riastrad  */
    808  1.3  riastrad #define for_each_new_crtc_in_state(__state, crtc, new_crtc_state, __i)	\
    809  1.3  riastrad 	for ((__i) = 0;							\
    810  1.3  riastrad 	     (__i) < (__state)->dev->mode_config.num_crtc;		\
    811  1.3  riastrad 	     (__i)++)							\
    812  1.3  riastrad 		for_each_if ((__state)->crtcs[__i].ptr &&		\
    813  1.3  riastrad 			     ((crtc) = (__state)->crtcs[__i].ptr,	\
    814  1.3  riastrad 			     (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \
    815  1.3  riastrad 			     (new_crtc_state) = (__state)->crtcs[__i].new_state, \
    816  1.3  riastrad 			     (void)(new_crtc_state) /* Only to avoid unused-but-set-variable warning */, 1))
    817  1.1  riastrad 
    818  1.3  riastrad /**
    819  1.3  riastrad  * for_each_oldnew_plane_in_state - iterate over all planes in an atomic update
    820  1.3  riastrad  * @__state: &struct drm_atomic_state pointer
    821  1.3  riastrad  * @plane: &struct drm_plane iteration cursor
    822  1.3  riastrad  * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
    823  1.3  riastrad  * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
    824  1.3  riastrad  * @__i: int iteration cursor, for macro-internal use
    825  1.3  riastrad  *
    826  1.3  riastrad  * This iterates over all planes in an atomic update, tracking both old and
    827  1.3  riastrad  * new state. This is useful in places where the state delta needs to be
    828  1.3  riastrad  * considered, for example in atomic check functions.
    829  1.3  riastrad  */
    830  1.3  riastrad #define for_each_oldnew_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \
    831  1.1  riastrad 	for ((__i) = 0;							\
    832  1.3  riastrad 	     (__i) < (__state)->dev->mode_config.num_total_plane;	\
    833  1.1  riastrad 	     (__i)++)							\
    834  1.3  riastrad 		for_each_if ((__state)->planes[__i].ptr &&		\
    835  1.3  riastrad 			     ((plane) = (__state)->planes[__i].ptr,	\
    836  1.3  riastrad 			      (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
    837  1.3  riastrad 			      (old_plane_state) = (__state)->planes[__i].old_state,\
    838  1.3  riastrad 			      (new_plane_state) = (__state)->planes[__i].new_state, 1))
    839  1.1  riastrad 
    840  1.3  riastrad /**
    841  1.3  riastrad  * for_each_oldnew_plane_in_state_reverse - iterate over all planes in an atomic
    842  1.3  riastrad  * update in reverse order
    843  1.3  riastrad  * @__state: &struct drm_atomic_state pointer
    844  1.3  riastrad  * @plane: &struct drm_plane iteration cursor
    845  1.3  riastrad  * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
    846  1.3  riastrad  * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
    847  1.3  riastrad  * @__i: int iteration cursor, for macro-internal use
    848  1.3  riastrad  *
    849  1.3  riastrad  * This iterates over all planes in an atomic update in reverse order,
    850  1.3  riastrad  * tracking both old and  new state. This is useful in places where the
    851  1.3  riastrad  * state delta needs to be considered, for example in atomic check functions.
    852  1.3  riastrad  */
    853  1.3  riastrad #define for_each_oldnew_plane_in_state_reverse(__state, plane, old_plane_state, new_plane_state, __i) \
    854  1.3  riastrad 	for ((__i) = ((__state)->dev->mode_config.num_total_plane - 1);	\
    855  1.3  riastrad 	     (__i) >= 0;						\
    856  1.3  riastrad 	     (__i)--)							\
    857  1.3  riastrad 		for_each_if ((__state)->planes[__i].ptr &&		\
    858  1.3  riastrad 			     ((plane) = (__state)->planes[__i].ptr,	\
    859  1.3  riastrad 			      (old_plane_state) = (__state)->planes[__i].old_state,\
    860  1.3  riastrad 			      (new_plane_state) = (__state)->planes[__i].new_state, 1))
    861  1.1  riastrad 
    862  1.3  riastrad /**
    863  1.3  riastrad  * for_each_old_plane_in_state - iterate over all planes in an atomic update
    864  1.3  riastrad  * @__state: &struct drm_atomic_state pointer
    865  1.3  riastrad  * @plane: &struct drm_plane iteration cursor
    866  1.3  riastrad  * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
    867  1.3  riastrad  * @__i: int iteration cursor, for macro-internal use
    868  1.3  riastrad  *
    869  1.3  riastrad  * This iterates over all planes in an atomic update, tracking only the old
    870  1.3  riastrad  * state. This is useful in disable functions, where we need the old state the
    871  1.3  riastrad  * hardware is still in.
    872  1.3  riastrad  */
    873  1.3  riastrad #define for_each_old_plane_in_state(__state, plane, old_plane_state, __i) \
    874  1.1  riastrad 	for ((__i) = 0;							\
    875  1.3  riastrad 	     (__i) < (__state)->dev->mode_config.num_total_plane;	\
    876  1.1  riastrad 	     (__i)++)							\
    877  1.3  riastrad 		for_each_if ((__state)->planes[__i].ptr &&		\
    878  1.3  riastrad 			     ((plane) = (__state)->planes[__i].ptr,	\
    879  1.3  riastrad 			      (old_plane_state) = (__state)->planes[__i].old_state, 1))
    880  1.3  riastrad /**
    881  1.3  riastrad  * for_each_new_plane_in_state - iterate over all planes in an atomic update
    882  1.3  riastrad  * @__state: &struct drm_atomic_state pointer
    883  1.3  riastrad  * @plane: &struct drm_plane iteration cursor
    884  1.3  riastrad  * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
    885  1.3  riastrad  * @__i: int iteration cursor, for macro-internal use
    886  1.3  riastrad  *
    887  1.3  riastrad  * This iterates over all planes in an atomic update, tracking only the new
    888  1.3  riastrad  * state. This is useful in enable functions, where we need the new state the
    889  1.3  riastrad  * hardware should be in when the atomic commit operation has completed.
    890  1.3  riastrad  */
    891  1.3  riastrad #define for_each_new_plane_in_state(__state, plane, new_plane_state, __i) \
    892  1.3  riastrad 	for ((__i) = 0;							\
    893  1.3  riastrad 	     (__i) < (__state)->dev->mode_config.num_total_plane;	\
    894  1.3  riastrad 	     (__i)++)							\
    895  1.3  riastrad 		for_each_if ((__state)->planes[__i].ptr &&		\
    896  1.3  riastrad 			     ((plane) = (__state)->planes[__i].ptr,	\
    897  1.3  riastrad 			      (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
    898  1.3  riastrad 			      (new_plane_state) = (__state)->planes[__i].new_state, \
    899  1.3  riastrad 			      (void)(new_plane_state) /* Only to avoid unused-but-set-variable warning */, 1))
    900  1.3  riastrad 
    901  1.3  riastrad /**
    902  1.3  riastrad  * for_each_oldnew_private_obj_in_state - iterate over all private objects in an atomic update
    903  1.3  riastrad  * @__state: &struct drm_atomic_state pointer
    904  1.3  riastrad  * @obj: &struct drm_private_obj iteration cursor
    905  1.3  riastrad  * @old_obj_state: &struct drm_private_state iteration cursor for the old state
    906  1.3  riastrad  * @new_obj_state: &struct drm_private_state iteration cursor for the new state
    907  1.3  riastrad  * @__i: int iteration cursor, for macro-internal use
    908  1.3  riastrad  *
    909  1.3  riastrad  * This iterates over all private objects in an atomic update, tracking both
    910  1.3  riastrad  * old and new state. This is useful in places where the state delta needs
    911  1.3  riastrad  * to be considered, for example in atomic check functions.
    912  1.3  riastrad  */
    913  1.3  riastrad #define for_each_oldnew_private_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \
    914  1.3  riastrad 	for ((__i) = 0; \
    915  1.3  riastrad 	     (__i) < (__state)->num_private_objs && \
    916  1.3  riastrad 		     ((obj) = (__state)->private_objs[__i].ptr, \
    917  1.3  riastrad 		      (old_obj_state) = (__state)->private_objs[__i].old_state,	\
    918  1.3  riastrad 		      (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
    919  1.3  riastrad 	     (__i)++)
    920  1.3  riastrad 
    921  1.3  riastrad /**
    922  1.3  riastrad  * for_each_old_private_obj_in_state - iterate over all private objects in an atomic update
    923  1.3  riastrad  * @__state: &struct drm_atomic_state pointer
    924  1.3  riastrad  * @obj: &struct drm_private_obj iteration cursor
    925  1.3  riastrad  * @old_obj_state: &struct drm_private_state iteration cursor for the old state
    926  1.3  riastrad  * @__i: int iteration cursor, for macro-internal use
    927  1.3  riastrad  *
    928  1.3  riastrad  * This iterates over all private objects in an atomic update, tracking only
    929  1.3  riastrad  * the old state. This is useful in disable functions, where we need the old
    930  1.3  riastrad  * state the hardware is still in.
    931  1.3  riastrad  */
    932  1.3  riastrad #define for_each_old_private_obj_in_state(__state, obj, old_obj_state, __i) \
    933  1.3  riastrad 	for ((__i) = 0; \
    934  1.3  riastrad 	     (__i) < (__state)->num_private_objs && \
    935  1.3  riastrad 		     ((obj) = (__state)->private_objs[__i].ptr, \
    936  1.3  riastrad 		      (old_obj_state) = (__state)->private_objs[__i].old_state, 1); \
    937  1.3  riastrad 	     (__i)++)
    938  1.3  riastrad 
    939  1.3  riastrad /**
    940  1.3  riastrad  * for_each_new_private_obj_in_state - iterate over all private objects in an atomic update
    941  1.3  riastrad  * @__state: &struct drm_atomic_state pointer
    942  1.3  riastrad  * @obj: &struct drm_private_obj iteration cursor
    943  1.3  riastrad  * @new_obj_state: &struct drm_private_state iteration cursor for the new state
    944  1.3  riastrad  * @__i: int iteration cursor, for macro-internal use
    945  1.3  riastrad  *
    946  1.3  riastrad  * This iterates over all private objects in an atomic update, tracking only
    947  1.3  riastrad  * the new state. This is useful in enable functions, where we need the new state the
    948  1.3  riastrad  * hardware should be in when the atomic commit operation has completed.
    949  1.3  riastrad  */
    950  1.3  riastrad #define for_each_new_private_obj_in_state(__state, obj, new_obj_state, __i) \
    951  1.3  riastrad 	for ((__i) = 0; \
    952  1.3  riastrad 	     (__i) < (__state)->num_private_objs && \
    953  1.3  riastrad 		     ((obj) = (__state)->private_objs[__i].ptr, \
    954  1.3  riastrad 		      (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
    955  1.3  riastrad 	     (__i)++)
    956  1.3  riastrad 
    957  1.3  riastrad /**
    958  1.3  riastrad  * drm_atomic_crtc_needs_modeset - compute combined modeset need
    959  1.3  riastrad  * @state: &drm_crtc_state for the CRTC
    960  1.3  riastrad  *
    961  1.3  riastrad  * To give drivers flexibility &struct drm_crtc_state has 3 booleans to track
    962  1.3  riastrad  * whether the state CRTC changed enough to need a full modeset cycle:
    963  1.3  riastrad  * mode_changed, active_changed and connectors_changed. This helper simply
    964  1.3  riastrad  * combines these three to compute the overall need for a modeset for @state.
    965  1.3  riastrad  *
    966  1.3  riastrad  * The atomic helper code sets these booleans, but drivers can and should
    967  1.3  riastrad  * change them appropriately to accurately represent whether a modeset is
    968  1.3  riastrad  * really needed. In general, drivers should avoid full modesets whenever
    969  1.3  riastrad  * possible.
    970  1.3  riastrad  *
    971  1.3  riastrad  * For example if the CRTC mode has changed, and the hardware is able to enact
    972  1.3  riastrad  * the requested mode change without going through a full modeset, the driver
    973  1.3  riastrad  * should clear mode_changed in its &drm_mode_config_funcs.atomic_check
    974  1.3  riastrad  * implementation.
    975  1.3  riastrad  */
    976  1.1  riastrad static inline bool
    977  1.3  riastrad drm_atomic_crtc_needs_modeset(const struct drm_crtc_state *state)
    978  1.1  riastrad {
    979  1.1  riastrad 	return state->mode_changed || state->active_changed ||
    980  1.1  riastrad 	       state->connectors_changed;
    981  1.1  riastrad }
    982  1.1  riastrad 
    983  1.3  riastrad /**
    984  1.3  riastrad  * drm_atomic_crtc_effectively_active - compute whether CRTC is actually active
    985  1.3  riastrad  * @state: &drm_crtc_state for the CRTC
    986  1.3  riastrad  *
    987  1.3  riastrad  * When in self refresh mode, the crtc_state->active value will be false, since
    988  1.3  riastrad  * the CRTC is off. However in some cases we're interested in whether the CRTC
    989  1.3  riastrad  * is active, or effectively active (ie: it's connected to an active display).
    990  1.3  riastrad  * In these cases, use this function instead of just checking active.
    991  1.3  riastrad  */
    992  1.3  riastrad static inline bool
    993  1.3  riastrad drm_atomic_crtc_effectively_active(const struct drm_crtc_state *state)
    994  1.3  riastrad {
    995  1.3  riastrad 	return state->active || state->self_refresh_active;
    996  1.3  riastrad }
    997  1.1  riastrad 
    998  1.1  riastrad #endif /* DRM_ATOMIC_H_ */
    999