From: Dominik Kowalski <[email protected]>

[Why & How]
Add allocation, deallocation and initialization of DPMS-v2 context.

Cc: Wenjing Liu <[email protected]>
Signed-off-by: Dominik Kowalski <[email protected]>
Signed-off-by: Chenyu Chen <[email protected]>
---
 .../drm/amd/display/dc/link/link_dpms_v2.c    | 25 ++++++++-
 .../drm/amd/display/dc/link/link_factory.c    | 55 ++++++++++++++++++-
 2 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/link/link_dpms_v2.c 
b/drivers/gpu/drm/amd/display/dc/link/link_dpms_v2.c
index 43c3f7dfa343..14f5bf4f53b1 100644
--- a/drivers/gpu/drm/amd/display/dc/link/link_dpms_v2.c
+++ b/drivers/gpu/drm/amd/display/dc/link/link_dpms_v2.c
@@ -25,10 +25,28 @@
 
 #include "dc/link/link_dpms_v2.h"
 
+#include "dc/inc/core_types.h"
+#include "dc/inc/link_tx.h"
+
+// TODO: This should be moved to dc_update_state_prepare
+static void link_dpms_ctx_init(struct link_dpms_ctx *dpms_ctx,
+                         struct pipe_ctx *pipe_ctx)
+{
+       dpms_ctx->link_config = pipe_ctx->link_config;
+
+       // TODO: Implement
+       dpms_ctx->stream_descriptor = (struct link_dpms_stream_descriptor){
+               .dummy = 0,
+       };
+}
+
 enum dc_status link_set_dpms_off_v2(struct pipe_ctx *pipe_ctx)
 {
+       struct dc_link *link = pipe_ctx->stream->link;
+
+       link_dpms_ctx_init(link->dpms_ctx, pipe_ctx);
+
        // TODO: Implement
-       (void)pipe_ctx;
        ASSERT(false);
        return DC_ERROR_UNEXPECTED;
 }
@@ -36,9 +54,12 @@ enum dc_status link_set_dpms_off_v2(struct pipe_ctx 
*pipe_ctx)
 enum dc_status link_set_dpms_on_v2(struct dc_state *state,
                                   struct pipe_ctx *pipe_ctx)
 {
+       struct dc_link *link = pipe_ctx->stream->link;
+
+       link_dpms_ctx_init(link->dpms_ctx, pipe_ctx);
+
        // TODO: Implement
        (void)state;
-       (void)pipe_ctx;
        ASSERT(false);
        return DC_ERROR_UNEXPECTED;
 }
diff --git a/drivers/gpu/drm/amd/display/dc/link/link_factory.c 
b/drivers/gpu/drm/amd/display/dc/link/link_factory.c
index 919f67b76f91..1e32f96348b7 100644
--- a/drivers/gpu/drm/amd/display/dc/link/link_factory.c
+++ b/drivers/gpu/drm/amd/display/dc/link/link_factory.c
@@ -416,6 +416,29 @@ static bool encoder_is_external_dp(
        }
 }
 
+static void link_destroy_dpms_ctx(struct link_dpms_ctx *ctx)
+{
+       if (!ctx)
+               return;
+
+       kfree(ctx);
+}
+
+// Do not dereference the pointer, as it is mid-construction
+static struct link_dpms_ctx *link_create_dpms_ctx(struct dc_link *link)
+{
+       struct link_dpms_ctx *ctx = kzalloc_obj(*ctx);
+
+       if (!ctx)
+               return NULL;
+
+       *ctx = (struct link_dpms_ctx){
+               .link = link,
+       };
+
+       return ctx;
+}
+
 static void link_destruct(struct dc_link *link)
 {
        unsigned int i;
@@ -445,6 +468,9 @@ static void link_destruct(struct dc_link *link)
 
        for (i = 0; i < link->sink_count; ++i)
                dc_sink_release(link->remote_sinks[i]);
+
+       if (link->dpms_ctx)
+               link_destroy_dpms_ctx(link->dpms_ctx);
 }
 
 static enum channel_id get_ddc_line(struct dc_link *link)
@@ -896,12 +922,22 @@ static bool construct_phy(struct dc_link *link,
                }
        }
 
+       if (init_params->dc->config.enable_dpms_v2) {
+               link->dpms_ctx = link_create_dpms_ctx(link);
+               if (!link->dpms_ctx) {
+                       DC_ERROR("Failed to create dpms_ctx!\n");
+                       goto fail;
+               }
+       }
+
        link->psr_settings.psr_vtotal_control_support = false;
        link->psr_settings.psr_version = DC_PSR_VERSION_UNSUPPORTED;
        link->replay_settings.config.replay_version = 
DC_REPLAY_VERSION_UNSUPPORTED;
 
        DC_LOG_DC("BIOS object table - %s finished successfully.\n", __func__);
        return true;
+
+fail:
 hpo_enc_create_fail:
 device_tag_fail:
 link_enc_create_fail:
@@ -914,6 +950,8 @@ static bool construct_phy(struct dc_link *link,
                link->panel_cntl->funcs->destroy(&link->panel_cntl);
        if (link->link_enc)
                link->link_enc->funcs->destroy(&link->link_enc);
+       if (link->dpms_ctx)
+               link_destroy_dpms_ctx(link->dpms_ctx);
 
        DC_LOG_DC("BIOS object table - %s failed.\n", __func__);
        return false;
@@ -965,7 +1003,15 @@ static bool construct_dpia(struct dc_link *link,
        link->ddc = link_create_ddc_service(&ddc_service_init_data);
        if (!link->ddc) {
                DC_ERROR("Failed to create ddc_service!\n");
-               goto ddc_create_fail;
+               goto fail;
+       }
+
+       if (init_params->dc->config.enable_dpms_v2) {
+               link->dpms_ctx = link_create_dpms_ctx(link);
+               if (!link->dpms_ctx) {
+                       DC_ERROR("Failed to create dpms_ctx!\n");
+                       goto fail;
+               }
        }
 
        /* Set dpia port index : 0 to number of dpia ports */
@@ -982,7 +1028,12 @@ static bool construct_dpia(struct dc_link *link,
 
        return true;
 
-ddc_create_fail:
+fail:
+       if (link->ddc)
+               link_destroy_ddc_service(&link->ddc);
+       if (link->dpms_ctx)
+               link_destroy_dpms_ctx(link->dpms_ctx);
+
        return false;
 }
 
-- 
2.43.0

Reply via email to