drm/amd/display: revert dc_get_validate_context re-entrancy fix
authorDmytro Laktyushkin <Dmytro.Laktyushkin@amd.com>
Wed, 17 May 2017 20:56:56 +0000 (16:56 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 26 Sep 2017 22:07:18 +0000 (18:07 -0400)
Apply dc_get_validate_context re-entrancy fix to dc_validate_resources instead

Signed-off-by: Dmytro Laktyushkin <Dmytro.Laktyushkin@amd.com>
Reviewed-by: Dmytro Laktyushkin <Dmytro.Laktyushkin@amd.com>
Acked-by: Harry Wentland <Harry.Wentland@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/dc/core/dc.c

index 0aafcc0..773f0ef 100644 (file)
@@ -653,6 +653,40 @@ void dc_destroy(struct dc **dc)
        *dc = NULL;
 }
 
+static bool is_validation_required(
+               const struct core_dc *dc,
+               const struct dc_validation_set set[],
+               int set_count)
+{
+       const struct validate_context *context = dc->current_context;
+       int i, j;
+
+       if (context->stream_count != set_count)
+               return true;
+
+       for (i = 0; i < set_count; i++) {
+
+               if (set[i].surface_count != context->stream_status[i].surface_count)
+                       return true;
+               if (!is_stream_unchanged(DC_STREAM_TO_CORE(set[i].stream), context->streams[i]))
+                       return true;
+
+               for (j = 0; j < set[i].surface_count; j++) {
+                       struct dc_surface temp_surf = { 0 };
+
+                       temp_surf = *context->stream_status[i].surfaces[j];
+                       temp_surf.clip_rect = set[i].surfaces[j]->clip_rect;
+                       temp_surf.dst_rect.x = set[i].surfaces[j]->dst_rect.x;
+                       temp_surf.dst_rect.y = set[i].surfaces[j]->dst_rect.y;
+
+                       if (memcmp(&temp_surf, set[i].surfaces[j], sizeof(temp_surf)) != 0)
+                               return true;
+               }
+       }
+
+       return false;
+}
+
 struct validate_context *dc_get_validate_context(
                const struct dc *dc,
                const struct dc_validation_set set[],
@@ -663,11 +697,16 @@ struct validate_context *dc_get_validate_context(
        struct validate_context *context;
 
        context = dm_alloc(sizeof(struct validate_context));
-       if(context == NULL)
+       if (context == NULL)
                goto context_alloc_fail;
 
+       if (!is_validation_required(core_dc, set, set_count)) {
+               dc_resource_validate_ctx_copy_construct(core_dc->current_context, context);
+               return context;
+       }
+
        result = core_dc->res_pool->funcs->validate_with_context(
-                               core_dc, set, set_count, context, NULL);
+                       core_dc, set, set_count, context, core_dc->current_context);
 
 context_alloc_fail:
        if (result != DC_OK) {
@@ -690,16 +729,30 @@ bool dc_validate_resources(
                const struct dc_validation_set set[],
                uint8_t set_count)
 {
-       struct validate_context *ctx;
+       struct core_dc *core_dc = DC_TO_CORE(dc);
+       enum dc_status result = DC_ERROR_UNEXPECTED;
+       struct validate_context *context;
 
-       ctx = dc_get_validate_context(dc, set, set_count);
-       if (ctx) {
-               dc_resource_validate_ctx_destruct(ctx);
-               dm_free(ctx);
-               return true;
+       context = dm_alloc(sizeof(struct validate_context));
+       if (context == NULL)
+               goto context_alloc_fail;
+
+       result = core_dc->res_pool->funcs->validate_with_context(
+                               core_dc, set, set_count, context, NULL);
+
+context_alloc_fail:
+       if (result != DC_OK) {
+               dm_logger_write(core_dc->ctx->logger, LOG_WARNING,
+                               "%s:resource validation failed, dc_status:%d\n",
+                               __func__,
+                               result);
        }
 
-       return false;
+       dc_resource_validate_ctx_destruct(context);
+       dm_free(context);
+       context = NULL;
+
+       return result == DC_OK;
 }
 
 bool dc_validate_guaranteed(