drm/amd/display: Add dml2 copy functions
authorDillon Varone <dillon.varone@amd.com>
Fri, 1 Dec 2023 13:25:18 +0000 (06:25 -0700)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 6 Dec 2023 20:22:34 +0000 (15:22 -0500)
Add function to handle deep copying dml2 context.

Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
Reviewed-by: Chaitanya Dhere <chaitanya.dhere@amd.com>
Acked-by: Rodrigo Siqueira <rodrigo.siqueira@amd.com>
Signed-off-by: Dillon Varone <dillon.varone@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/dc/core/dc.c
drivers/gpu/drm/amd/display/dc/dml2/dml2_wrapper.c
drivers/gpu/drm/amd/display/dc/dml2/dml2_wrapper.h

index eab713c0da0d787ca3ebb210a2405c3d28bb6ab0..102d00a9a24f195b8bb30b08c2ff7fd5d4808798 100644 (file)
@@ -2258,23 +2258,16 @@ struct dc_state *dc_copy_state(struct dc_state *src_ctx)
 {
        int i, j;
        struct dc_state *new_ctx = kvmalloc(sizeof(struct dc_state), GFP_KERNEL);
-#ifdef CONFIG_DRM_AMD_DC_FP
-       struct dml2_context *dml2 =  NULL;
-#endif
 
        if (!new_ctx)
                return NULL;
        memcpy(new_ctx, src_ctx, sizeof(struct dc_state));
 
 #ifdef CONFIG_DRM_AMD_DC_FP
-       if (new_ctx->bw_ctx.dml2) {
-               dml2 = kzalloc(sizeof(struct dml2_context), GFP_KERNEL);
-               if (!dml2)
-                       return NULL;
-
-               memcpy(dml2, src_ctx->bw_ctx.dml2, sizeof(struct dml2_context));
-               new_ctx->bw_ctx.dml2 = dml2;
-       }
+       if (new_ctx->bw_ctx.dml2 && !dml2_create_copy(&new_ctx->bw_ctx.dml2, src_ctx->bw_ctx.dml2)) {
+               dc_release_state(new_ctx);
+               return NULL;
+       }
 #endif
 
        for (i = 0; i < MAX_PIPES; i++) {
index 8f231418870f2afbad672878d005088771335271..9d354fde6908a9f97c7a5574db14353d4dc25b16 100644 (file)
@@ -691,10 +691,15 @@ bool dml2_validate(const struct dc *in_dc, struct dc_state *context, bool fast_v
        return out;
 }
 
+static inline struct dml2_context *dml2_allocate_memory(void)
+{
+       return (struct dml2_context *) kzalloc(sizeof(struct dml2_context), GFP_KERNEL);
+}
+
 bool dml2_create(const struct dc *in_dc, const struct dml2_configuration_options *config, struct dml2_context **dml2)
 {
        // Allocate Mode Lib Ctx
-       *dml2 = (struct dml2_context *) kzalloc(sizeof(struct dml2_context), GFP_KERNEL);
+       *dml2 = dml2_allocate_memory();
 
        if (!(*dml2))
                return false;
@@ -745,3 +750,25 @@ void dml2_extract_dram_and_fclk_change_support(struct dml2_context *dml2,
        *fclk_change_support = (unsigned int) dml2->v20.dml_core_ctx.ms.support.FCLKChangeSupport[0];
        *dram_clk_change_support = (unsigned int) dml2->v20.dml_core_ctx.ms.support.DRAMClockChangeSupport[0];
 }
+
+void dml2_copy(struct dml2_context *dst_dml2,
+       struct dml2_context *src_dml2)
+{
+       /* copy Mode Lib Ctx */
+       memcpy(dst_dml2, src_dml2, sizeof(struct dml2_context));
+}
+
+bool dml2_create_copy(struct dml2_context **dst_dml2,
+       struct dml2_context *src_dml2)
+{
+       /* Allocate Mode Lib Ctx */
+       *dst_dml2 = dml2_allocate_memory();
+
+       if (!(*dst_dml2))
+               return false;
+
+       /* copy Mode Lib Ctx */
+       dml2_copy(*dst_dml2, src_dml2);
+
+       return true;
+}
index fe15baa4bf094828ee9f74d8e104889e67500b7d..0de6886969c69b3860dda4a60269a9eb922f6cb0 100644 (file)
@@ -191,6 +191,10 @@ bool dml2_create(const struct dc *in_dc,
                                 struct dml2_context **dml2);
 
 void dml2_destroy(struct dml2_context *dml2);
+void dml2_copy(struct dml2_context *dst_dml2,
+       struct dml2_context *src_dml2);
+bool dml2_create_copy(struct dml2_context **dst_dml2,
+       struct dml2_context *src_dml2);
 
 /*
  * dml2_validate - Determines if a display configuration is supported or not.