drm: Consolidate connector arrays in drm_atomic_state
[cascardo/linux.git] / drivers / gpu / drm / drm_atomic_helper.c
index 43a0b3d..b4e2e98 100644 (file)
@@ -110,8 +110,10 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state,
 
                if (funcs->atomic_best_encoder)
                        new_encoder = funcs->atomic_best_encoder(connector, conn_state);
-               else
+               else if (funcs->best_encoder)
                        new_encoder = funcs->best_encoder(connector);
+               else
+                       new_encoder = drm_atomic_helper_best_encoder(connector);
 
                if (new_encoder) {
                        if (encoder_mask & (1 << drm_encoder_index(new_encoder))) {
@@ -414,6 +416,9 @@ mode_fixup(struct drm_atomic_state *state)
        for_each_crtc_in_state(state, crtc, crtc_state, i) {
                const struct drm_crtc_helper_funcs *funcs;
 
+               if (!crtc_state->enable)
+                       continue;
+
                if (!crtc_state->mode_changed &&
                    !crtc_state->connectors_changed)
                        continue;
@@ -611,7 +616,7 @@ drm_atomic_helper_check_planes(struct drm_device *dev,
                if (!funcs || !funcs->atomic_check)
                        continue;
 
-               ret = funcs->atomic_check(crtc, state->crtc_states[i]);
+               ret = funcs->atomic_check(crtc, crtc_state);
                if (ret) {
                        DRM_DEBUG_ATOMIC("[CRTC:%d:%s] atomic driver check failed\n",
                                         crtc->base.id, crtc->name);
@@ -1249,16 +1254,12 @@ EXPORT_SYMBOL(drm_atomic_helper_commit);
 int drm_atomic_helper_prepare_planes(struct drm_device *dev,
                                     struct drm_atomic_state *state)
 {
-       int nplanes = dev->mode_config.num_total_plane;
-       int ret, i;
+       struct drm_plane *plane;
+       struct drm_plane_state *plane_state;
+       int ret, i, j;
 
-       for (i = 0; i < nplanes; i++) {
+       for_each_plane_in_state(state, plane, plane_state, i) {
                const struct drm_plane_helper_funcs *funcs;
-               struct drm_plane *plane = state->planes[i];
-               struct drm_plane_state *plane_state = state->plane_states[i];
-
-               if (!plane)
-                       continue;
 
                funcs = plane->helper_private;
 
@@ -1272,12 +1273,10 @@ int drm_atomic_helper_prepare_planes(struct drm_device *dev,
        return 0;
 
 fail:
-       for (i--; i >= 0; i--) {
+       for_each_plane_in_state(state, plane, plane_state, j) {
                const struct drm_plane_helper_funcs *funcs;
-               struct drm_plane *plane = state->planes[i];
-               struct drm_plane_state *plane_state = state->plane_states[i];
 
-               if (!plane)
+               if (j >= i)
                        continue;
 
                funcs = plane->helper_private;
@@ -1564,35 +1563,26 @@ void drm_atomic_helper_swap_state(struct drm_device *dev,
                                  struct drm_atomic_state *state)
 {
        int i;
+       struct drm_connector *connector;
+       struct drm_connector_state *conn_state;
+       struct drm_crtc *crtc;
+       struct drm_crtc_state *crtc_state;
+       struct drm_plane *plane;
+       struct drm_plane_state *plane_state;
 
-       for (i = 0; i < state->num_connector; i++) {
-               struct drm_connector *connector = state->connectors[i];
-
-               if (!connector)
-                       continue;
-
+       for_each_connector_in_state(state, connector, conn_state, i) {
                connector->state->state = state;
-               swap(state->connector_states[i], connector->state);
+               swap(state->connectors[i].state, connector->state);
                connector->state->state = NULL;
        }
 
-       for (i = 0; i < dev->mode_config.num_crtc; i++) {
-               struct drm_crtc *crtc = state->crtcs[i];
-
-               if (!crtc)
-                       continue;
-
+       for_each_crtc_in_state(state, crtc, crtc_state, i) {
                crtc->state->state = state;
                swap(state->crtc_states[i], crtc->state);
                crtc->state->state = NULL;
        }
 
-       for (i = 0; i < dev->mode_config.num_total_plane; i++) {
-               struct drm_plane *plane = state->planes[i];
-
-               if (!plane)
-                       continue;
-
+       for_each_plane_in_state(state, plane, plane_state, i) {
                plane->state->state = state;
                swap(state->plane_states[i], plane->state);
                plane->state->state = NULL;
@@ -2409,7 +2399,7 @@ EXPORT_SYMBOL(drm_atomic_helper_page_flip);
  * This is the main helper function provided by the atomic helper framework for
  * implementing the legacy DPMS connector interface. It computes the new desired
  * ->active state for the corresponding CRTC (if the connector is enabled) and
- *  updates it.
+ * updates it.
  *
  * Returns:
  * Returns 0 on success, negative errno numbers on failure.
@@ -2530,7 +2520,7 @@ EXPORT_SYMBOL(drm_atomic_helper_best_encoder);
 void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc)
 {
        if (crtc->state)
-               __drm_atomic_helper_crtc_destroy_state(crtc, crtc->state);
+               __drm_atomic_helper_crtc_destroy_state(crtc->state);
 
        kfree(crtc->state);
        crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL);
@@ -2595,15 +2585,13 @@ EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
 
 /**
  * __drm_atomic_helper_crtc_destroy_state - release CRTC state
- * @crtc: CRTC object
  * @state: CRTC state object to release
  *
  * Releases all resources stored in the CRTC state without actually freeing
  * the memory of the CRTC state. This is useful for drivers that subclass the
  * CRTC state.
  */
-void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
-                                           struct drm_crtc_state *state)
+void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state)
 {
        drm_property_unreference_blob(state->mode_blob);
        drm_property_unreference_blob(state->degamma_lut);
@@ -2623,7 +2611,7 @@ EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state);
 void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
                                          struct drm_crtc_state *state)
 {
-       __drm_atomic_helper_crtc_destroy_state(crtc, state);
+       __drm_atomic_helper_crtc_destroy_state(state);
        kfree(state);
 }
 EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state);
@@ -2638,7 +2626,7 @@ EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state);
 void drm_atomic_helper_plane_reset(struct drm_plane *plane)
 {
        if (plane->state)
-               __drm_atomic_helper_plane_destroy_state(plane, plane->state);
+               __drm_atomic_helper_plane_destroy_state(plane->state);
 
        kfree(plane->state);
        plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL);
@@ -2693,15 +2681,13 @@ EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state);
 
 /**
  * __drm_atomic_helper_plane_destroy_state - release plane state
- * @plane: plane object
  * @state: plane state object to release
  *
  * Releases all resources stored in the plane state without actually freeing
  * the memory of the plane state. This is useful for drivers that subclass the
  * plane state.
  */
-void __drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
-                                            struct drm_plane_state *state)
+void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state *state)
 {
        if (state->fb)
                drm_framebuffer_unreference(state->fb);
@@ -2719,7 +2705,7 @@ EXPORT_SYMBOL(__drm_atomic_helper_plane_destroy_state);
 void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
                                           struct drm_plane_state *state)
 {
-       __drm_atomic_helper_plane_destroy_state(plane, state);
+       __drm_atomic_helper_plane_destroy_state(state);
        kfree(state);
 }
 EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state);
@@ -2760,8 +2746,7 @@ void drm_atomic_helper_connector_reset(struct drm_connector *connector)
                kzalloc(sizeof(*conn_state), GFP_KERNEL);
 
        if (connector->state)
-               __drm_atomic_helper_connector_destroy_state(connector,
-                                                           connector->state);
+               __drm_atomic_helper_connector_destroy_state(connector->state);
 
        kfree(connector->state);
        __drm_atomic_helper_connector_reset(connector, conn_state);
@@ -2894,7 +2879,6 @@ EXPORT_SYMBOL(drm_atomic_helper_duplicate_state);
 
 /**
  * __drm_atomic_helper_connector_destroy_state - release connector state
- * @connector: connector object
  * @state: connector state object to release
  *
  * Releases all resources stored in the connector state without actually
@@ -2902,8 +2886,7 @@ EXPORT_SYMBOL(drm_atomic_helper_duplicate_state);
  * subclass the connector state.
  */
 void
-__drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
-                                           struct drm_connector_state *state)
+__drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state)
 {
        /*
         * This is currently a placeholder so that drivers that subclass the
@@ -2926,7 +2909,7 @@ EXPORT_SYMBOL(__drm_atomic_helper_connector_destroy_state);
 void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
                                          struct drm_connector_state *state)
 {
-       __drm_atomic_helper_connector_destroy_state(connector, state);
+       __drm_atomic_helper_connector_destroy_state(state);
        kfree(state);
 }
 EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state);