drm/atomic: kerneldoc for drm_atomic_crtc_needs_modeset
[cascardo/linux.git] / include / drm / drm_atomic.h
index 92c84e9..a16861c 100644 (file)
@@ -71,7 +71,7 @@ static inline struct drm_crtc_state *
 drm_atomic_get_existing_crtc_state(struct drm_atomic_state *state,
                                   struct drm_crtc *crtc)
 {
-       return state->crtc_states[drm_crtc_index(crtc)];
+       return state->crtcs[drm_crtc_index(crtc)].state;
 }
 
 /**
@@ -86,7 +86,7 @@ static inline struct drm_plane_state *
 drm_atomic_get_existing_plane_state(struct drm_atomic_state *state,
                                    struct drm_plane *plane)
 {
-       return state->plane_states[drm_plane_index(plane)];
+       return state->planes[drm_plane_index(plane)].state;
 }
 
 /**
@@ -106,7 +106,43 @@ drm_atomic_get_existing_connector_state(struct drm_atomic_state *state,
        if (index >= state->num_connector)
                return NULL;
 
-       return state->connector_states[index];
+       return state->connectors[index].state;
+}
+
+/**
+ * __drm_atomic_get_current_plane_state - get current plane state
+ * @state: global atomic state object
+ * @plane: plane to grab
+ *
+ * This function returns the plane state for the given plane, either from
+ * @state, or if the plane isn't part of the atomic state update, from @plane.
+ * This is useful in atomic check callbacks, when drivers need to peek at, but
+ * not change, state of other planes, since it avoids threading an error code
+ * back up the call chain.
+ *
+ * WARNING:
+ *
+ * Note that this function is in general unsafe since it doesn't check for the
+ * required locking for access state structures. Drivers must ensure that it is
+ * safe to access the returned state structure through other means. One common
+ * example is when planes are fixed to a single CRTC, and the driver knows that
+ * the CRTC lock is held already. In that case holding the CRTC lock gives a
+ * read-lock on all planes connected to that CRTC. But if planes can be
+ * reassigned things get more tricky. In that case it's better to use
+ * drm_atomic_get_plane_state and wire up full error handling.
+ *
+ * Returns:
+ *
+ * Read-only pointer to the current plane state.
+ */
+static inline const struct drm_plane_state *
+__drm_atomic_get_current_plane_state(struct drm_atomic_state *state,
+                                    struct drm_plane *plane)
+{
+       if (state->planes[drm_plane_index(plane)].state)
+               return state->planes[drm_plane_index(plane)].state;
+
+       return plane->state;
 }
 
 int __must_check
@@ -139,29 +175,39 @@ int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
 int __must_check drm_atomic_commit(struct drm_atomic_state *state);
 int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);
 
-#define for_each_connector_in_state(state, connector, connector_state, __i) \
+#define for_each_connector_in_state(__state, connector, connector_state, __i) \
        for ((__i) = 0;                                                 \
-            (__i) < (state)->num_connector &&                          \
-            ((connector) = (state)->connectors[__i],                   \
-            (connector_state) = (state)->connector_states[__i], 1);    \
+            (__i) < (__state)->num_connector &&                                \
+            ((connector) = (__state)->connectors[__i].ptr,                     \
+            (connector_state) = (__state)->connectors[__i].state, 1);  \
             (__i)++)                                                   \
                for_each_if (connector)
 
-#define for_each_crtc_in_state(state, crtc, crtc_state, __i)   \
+#define for_each_crtc_in_state(__state, crtc, crtc_state, __i) \
        for ((__i) = 0;                                         \
-            (__i) < (state)->dev->mode_config.num_crtc &&      \
-            ((crtc) = (state)->crtcs[__i],                     \
-            (crtc_state) = (state)->crtc_states[__i], 1);      \
+            (__i) < (__state)->dev->mode_config.num_crtc &&    \
+            ((crtc) = (__state)->crtcs[__i].ptr,                       \
+            (crtc_state) = (__state)->crtcs[__i].state, 1);    \
             (__i)++)                                           \
                for_each_if (crtc_state)
 
-#define for_each_plane_in_state(state, plane, plane_state, __i)                \
+#define for_each_plane_in_state(__state, plane, plane_state, __i)              \
        for ((__i) = 0;                                                 \
-            (__i) < (state)->dev->mode_config.num_total_plane &&       \
-            ((plane) = (state)->planes[__i],                           \
-            (plane_state) = (state)->plane_states[__i], 1);            \
+            (__i) < (__state)->dev->mode_config.num_total_plane &&     \
+            ((plane) = (__state)->planes[__i].ptr,                             \
+            (plane_state) = (__state)->planes[__i].state, 1);          \
             (__i)++)                                                   \
                for_each_if (plane_state)
+
+/**
+ * drm_atomic_crtc_needs_modeset - compute combined modeset need
+ * @state: &drm_crtc_state for the CRTC
+ *
+ * To give drivers flexibility struct &drm_crtc_state has 3 booleans to track
+ * whether the state CRTC changed enough to need a full modeset cycle:
+ * connectors_changed, mode_changed and active_change. This helper simply
+ * combines these three to compute the overall need for a modeset for @state.
+ */
 static inline bool
 drm_atomic_crtc_needs_modeset(struct drm_crtc_state *state)
 {