From: Dave Airlie <[email protected]>

dc_dsc_compute_bandwidth_range() and dc_dsc_compute_config() took a
display_stream_compressor pointer that every caller fetched with
dc->res_pool->dscs[0]. The implementations immediately derive the dc
from dsc->ctx->dc anyway, so take struct dc directly and let DC pick
the DSC engine internally.

This removes all res_pool->dscs[0] dereferences from amdgpu_dm and is
a step towards not exposing struct dc outside DC.

Signed-off-by: Dave Airlie <[email protected]>
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c | 12 ++++++------
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c | 14 +++++++-------
 drivers/gpu/drm/amd/display/dc/dc_dsc.h                 |  4 ++--
 drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c             | 17 +++++++++++++++--
 4 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
index dee06fefdd1d..d334391bcbae 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
@@ -1229,7 +1229,7 @@ static void apply_dsc_policy_for_edp(struct 
amdgpu_dm_connector *aconnector,
        if (edp_max_bpp_x16 < edp_min_bpp_x16)
                edp_min_bpp_x16 = edp_max_bpp_x16;
 
-       if (dc_dsc_compute_bandwidth_range(dc->res_pool->dscs[0],
+       if (dc_dsc_compute_bandwidth_range(dc,
                                dc->debug.dsc_min_slice_height_override,
                                edp_min_bpp_x16, edp_max_bpp_x16,
                                dsc_caps,
@@ -1238,7 +1238,7 @@ static void apply_dsc_policy_for_edp(struct 
amdgpu_dm_connector *aconnector,
                                &bw_range)) {
 
                if (bw_range.max_kbps < link_bw_in_kbps) {
-                       if (dc_dsc_compute_config(dc->res_pool->dscs[0],
+                       if (dc_dsc_compute_config(dc,
                                        dsc_caps,
                                        &dsc_options,
                                        0,
@@ -1253,7 +1253,7 @@ static void apply_dsc_policy_for_edp(struct 
amdgpu_dm_connector *aconnector,
                }
        }
 
-       if (dc_dsc_compute_config(dc->res_pool->dscs[0],
+       if (dc_dsc_compute_config(dc,
                                dsc_caps,
                                &dsc_options,
                                link_bw_in_kbps,
@@ -1309,7 +1309,7 @@ static void apply_dsc_policy_for_stream(struct 
amdgpu_dm_connector *aconnector,
 
        } else if (sink->sink_signal == SIGNAL_TYPE_DISPLAY_PORT) {
                if (sink->link->dpcd_caps.dongle_type == DISPLAY_DONGLE_NONE) {
-                       if 
(dc_dsc_compute_config(aconnector->dc_link->ctx->dc->res_pool->dscs[0],
+                       if (dc_dsc_compute_config(dc,
                                                dsc_caps,
                                                &dsc_options,
                                                link_bandwidth_kbps,
@@ -1339,7 +1339,7 @@ static void apply_dsc_policy_for_stream(struct 
amdgpu_dm_connector *aconnector,
                        if (timing_bw_in_kbps > max_supported_bw_in_kbps &&
                                        max_supported_bw_in_kbps > 0 &&
                                        dsc_max_supported_bw_in_kbps > 0)
-                               if 
(dc_dsc_compute_config(aconnector->dc_link->ctx->dc->res_pool->dscs[0],
+                               if (dc_dsc_compute_config(dc,
                                                dsc_caps,
                                                &dsc_options,
                                                dsc_max_supported_bw_in_kbps,
@@ -1368,7 +1368,7 @@ static void apply_dsc_policy_for_stream(struct 
amdgpu_dm_connector *aconnector,
 
                if ((timing_bw_in_kbps > link_bandwidth_kbps && 
dsc_sink_bw_in_kbps > 0) ||
                    (dsc_policy.enable_dsc_when_not_needed || 
dsc_options.force_dsc_when_not_needed)) {
-                       if 
(dc_dsc_compute_config(aconnector->dc_link->ctx->dc->res_pool->dscs[0],
+                       if (dc_dsc_compute_config(dc,
                                        dsc_caps,
                                        &dsc_options,
                                        dsc_sink_bw_in_kbps,
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
index 5697645ef7cc..a3877ef767ec 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
@@ -980,7 +980,7 @@ static void set_dsc_configs_from_fairness_vars(struct 
dsc_mst_fairness_params *p
 
                memset(&params[i].timing->dsc_cfg, 0, 
sizeof(params[i].timing->dsc_cfg));
                if (vars[i + k].dsc_enabled && dc_dsc_compute_config(
-                                       
params[i].sink->ctx->dc->res_pool->dscs[0],
+                                       params[i].sink->ctx->dc,
                                        &params[i].sink->dsc_caps.dsc_dec_caps,
                                        &dsc_options,
                                        0,
@@ -1033,7 +1033,7 @@ static int bpp_x16_from_pbn(struct 
dsc_mst_fairness_params param, int pbn)
 
        kbps = div_u64((u64)pbn * 994 * 8 * 54, 64);
        dc_dsc_compute_config(
-                       param.sink->ctx->dc->res_pool->dscs[0],
+                       param.sink->ctx->dc,
                        &param.sink->dsc_caps.dsc_dec_caps,
                        &dsc_options,
                        (int) kbps, param.timing,
@@ -1278,7 +1278,7 @@ static void build_frl_mst_dsc_params(struct 
amdgpu_dm_connector *aconnector,
                        
stream->sink->edid_caps.panel_patch.max_dsc_target_bpp_limit * 16;
 
        if (dc_dsc_compute_config(
-                       stream->sink->ctx->dc->res_pool->dscs[0],
+                       stream->sink->ctx->dc,
                        &stream->sink->dsc_caps.dsc_dec_caps,
                        &dsc_options,
                        frl_conv_dsc_bw_in_kbps,
@@ -1398,7 +1398,7 @@ static int compute_mst_dsc_configs_for_link(struct 
drm_atomic_commit *state,
                                stream->sink->dsc_caps.dsc_dec_caps.is_frl)
                        build_frl_mst_dsc_params(aconnector, stream, 
&dsc_policy, &params[count], frl_conv_dsc_bw_in_kbps);
                if (!dc_dsc_compute_bandwidth_range(
-                               stream->sink->ctx->dc->res_pool->dscs[0],
+                               stream->sink->ctx->dc,
                                
stream->sink->ctx->dc->debug.dsc_min_slice_height_override,
                                min_target_bpp_x16,
                                max_target_bpp_x16,
@@ -1651,7 +1651,7 @@ int compute_mst_dsc_configs_for_state(struct 
drm_atomic_commit *state,
 
        for (i = 0; i < dc_state->stream_count; i++) {
                stream = dc_state->streams[i];
-               res_pool = stream->ctx->dc->res_pool;
+               res_pool = dc_get_res_pool(stream->ctx->dc);
 
                if (stream->signal != SIGNAL_TYPE_DISPLAY_PORT_MST)
                        continue;
@@ -1943,7 +1943,7 @@ static bool is_dsc_common_config_possible(struct 
dc_stream_state *stream,
        bool is_dsc_possible;
 
        dc_dsc_get_policy_for_timing(&stream->timing, 0, &dsc_policy, 
dc_link_get_highest_encoding_format(stream->link));
-       is_dsc_possible = 
dc_dsc_compute_bandwidth_range(stream->sink->ctx->dc->res_pool->dscs[0],
+       is_dsc_possible = dc_dsc_compute_bandwidth_range(stream->sink->ctx->dc,
                                                         
stream->sink->ctx->dc->debug.dsc_min_slice_height_override,
                                                         
dsc_policy.min_target_bpp * 16,
                                                         
dsc_policy.max_target_bpp * 16,
@@ -2108,7 +2108,7 @@ enum dc_status dm_dp_mst_is_port_support_mode(
                /*Confirm if we can obtain dsc config*/
                dc_dsc_get_default_config_option(stream->link->dc, 
&dsc_options);
                dsc_options.max_target_bpp_limit_override_x16 = 
aconnector->base.display_info.max_dsc_bpp * 16;
-               if 
(dc_dsc_compute_config(stream->sink->ctx->dc->res_pool->dscs[0],
+               if (dc_dsc_compute_config(stream->sink->ctx->dc,
                                &stream->sink->dsc_caps.dsc_dec_caps,
                                &dsc_options,
                                end_to_end_bw_in_kbps,
diff --git a/drivers/gpu/drm/amd/display/dc/dc_dsc.h 
b/drivers/gpu/drm/amd/display/dc/dc_dsc.h
index de169ed3b3b7..7e1a5cd6d2aa 100644
--- a/drivers/gpu/drm/amd/display/dc/dc_dsc.h
+++ b/drivers/gpu/drm/amd/display/dc/dc_dsc.h
@@ -77,7 +77,7 @@ bool dc_dsc_parse_dsc_edid(const struct dc *dc,
                struct dsc_dec_dpcd_caps *dsc_sink_caps);
 
 bool dc_dsc_compute_bandwidth_range(
-               const struct display_stream_compressor *dsc,
+               const struct dc *dc,
                uint32_t dsc_min_slice_height_override,
                uint32_t min_bpp_x16,
                uint32_t max_bpp_x16,
@@ -87,7 +87,7 @@ bool dc_dsc_compute_bandwidth_range(
                struct dc_dsc_bw_range *range);
 
 bool dc_dsc_compute_config(
-               const struct display_stream_compressor *dsc,
+               const struct dc *dc,
                const struct dsc_dec_dpcd_caps *dsc_sink_caps,
                const struct dc_dsc_config_options *options,
                uint32_t target_bandwidth_kbps,
diff --git a/drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c 
b/drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c
index 45ef1f745c7d..56db43d1b072 100644
--- a/drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c
+++ b/drivers/gpu/drm/amd/display/dc/dsc/dc_dsc.c
@@ -924,7 +924,7 @@ bool dc_dsc_parse_dsc_edid(const struct dc *dc, const 
struct dc_edid_caps *edid_
  * If DSC is not possible, leave '*range' untouched.
  */
 bool dc_dsc_compute_bandwidth_range(
-               const struct display_stream_compressor *dsc,
+               const struct dc *dc,
                uint32_t dsc_min_slice_height_override,
                uint32_t min_bpp_x16,
                uint32_t max_bpp_x16,
@@ -939,6 +939,12 @@ bool dc_dsc_compute_bandwidth_range(
        struct dsc_enc_caps dsc_common_caps;
        struct dc_dsc_config config = {0};
        struct dc_dsc_config_options options = {0};
+       const struct display_stream_compressor *dsc;
+
+       if (!dc || !dc->res_pool)
+               return false;
+
+       dsc = dc->res_pool->dscs[0];
 
        options.dsc_min_slice_height_override = dsc_min_slice_height_override;
        options.max_target_bpp_limit_override_x16 = max_bpp_x16;
@@ -2020,7 +2026,7 @@ static bool setup_dsc_config(
 }
 
 bool dc_dsc_compute_config(
-               const struct display_stream_compressor *dsc,
+               const struct dc *dc,
                const struct dsc_dec_dpcd_caps *dsc_sink_caps,
                const struct dc_dsc_config_options *options,
                uint32_t target_bandwidth_kbps,
@@ -2031,6 +2037,13 @@ bool dc_dsc_compute_config(
        bool is_dsc_possible = false;
        struct dsc_enc_caps dsc_enc_caps;
        unsigned int min_dsc_slice_count;
+       const struct display_stream_compressor *dsc;
+
+       if (!dc || !dc->res_pool)
+               return false;
+
+       dsc = dc->res_pool->dscs[0];
+
        get_dsc_enc_caps(dsc, &dsc_enc_caps, timing->pix_clk_100hz);
 
        min_dsc_slice_count = get_min_dsc_slice_count_for_odm(dsc, 
&dsc_enc_caps, timing);

-- 
2.56.0


Reply via email to