Revert "drm/vc4: kms: Remove unassigned_channels from the HVS state"
authorDom Cobley <popcornmix@gmail.com>
Mon, 26 Jul 2021 17:02:25 +0000 (18:02 +0100)
committerPhil Elwell <8911409+pelwell@users.noreply.github.com>
Mon, 26 Jul 2021 19:59:02 +0000 (20:59 +0100)
This reverts commit 7ccf97eb2d8439b8fbc72b1a1ebd7f376422be32.

drivers/gpu/drm/vc4/vc4_kms.c

index 7b02bff7d9398b4c5138cb04f57258ebd84f2467..4103c9bb58ee07dd3e481a5c36c1ffbb1ef2d2d3 100644 (file)
@@ -39,6 +39,7 @@ static struct vc4_ctm_state *to_vc4_ctm_state(struct drm_private_state *priv)
 
 struct vc4_hvs_state {
        struct drm_private_state base;
+       unsigned int unassigned_channels;
 
        struct {
                unsigned in_use: 1;
@@ -795,6 +796,7 @@ vc4_hvs_channels_duplicate_state(struct drm_private_obj *obj)
 
        __drm_atomic_helper_private_obj_duplicate_state(obj, &state->base);
 
+       state->unassigned_channels = old_state->unassigned_channels;
 
        for (i = 0; i < HVS_NUM_CHANNELS; i++) {
                state->fifo_state[i].in_use = old_state->fifo_state[i].in_use;
@@ -845,6 +847,7 @@ static int vc4_hvs_channels_obj_init(struct vc4_dev *vc4)
        if (!state)
                return -ENOMEM;
 
+       state->unassigned_channels = GENMASK(HVS_NUM_CHANNELS - 1, 0);
        drm_atomic_private_obj_init(&vc4->base, &vc4->hvs_channels,
                                    &state->base,
                                    &vc4_hvs_state_funcs);
@@ -889,17 +892,12 @@ static int vc4_pv_muxing_atomic_check(struct drm_device *dev,
        struct vc4_hvs_state *hvs_new_state;
        struct drm_crtc_state *old_crtc_state, *new_crtc_state;
        struct drm_crtc *crtc;
-       unsigned int unassigned_channels = 0;
        unsigned int i;
 
        hvs_new_state = vc4_hvs_get_global_state(state);
        if (!hvs_new_state)
                return -EINVAL;
 
-       for (i = 0; i < ARRAY_SIZE(hvs_new_state->fifo_state); i++)
-               if (!hvs_new_state->fifo_state[i].in_use)
-                       unassigned_channels |= BIT(i);
-
        for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
                struct vc4_crtc_state *old_vc4_crtc_state =
                        to_vc4_crtc_state(old_crtc_state);
@@ -922,6 +920,8 @@ static int vc4_pv_muxing_atomic_check(struct drm_device *dev,
                /* If we're disabling our CRTC, we put back our channel */
                if (!new_crtc_state->enable) {
                        channel = old_vc4_crtc_state->assigned_channel;
+
+                       hvs_new_state->unassigned_channels |= BIT(channel);
                        hvs_new_state->fifo_state[channel].in_use = false;
                        new_vc4_crtc_state->assigned_channel = VC4_HVS_CHANNEL_DISABLED;
                        continue;
@@ -951,13 +951,13 @@ static int vc4_pv_muxing_atomic_check(struct drm_device *dev,
                 * the future, we will need to have something smarter,
                 * but it works so far.
                 */
-               matching_channels = unassigned_channels & vc4_crtc->data->hvs_available_channels;
+               matching_channels = hvs_new_state->unassigned_channels & vc4_crtc->data->hvs_available_channels;
                if (!matching_channels)
                        return -EINVAL;
 
                channel = ffs(matching_channels) - 1;
                new_vc4_crtc_state->assigned_channel = channel;
-               unassigned_channels &= ~BIT(channel);
+               hvs_new_state->unassigned_channels &= ~BIT(channel);
                hvs_new_state->fifo_state[channel].in_use = true;
        }