From: Rafal Ostrowski <[email protected]>

[Why]
- Both steps carried dc and pipe_ctx, which breaks the block sequence
  rules on flat params and instance specification.
- ABM_SET_IMMEDIATE_DISABLE also stored the panel backlight level, which
  belongs to a different HW block (panel_cntl).

[How]
- Both steps share set_abm_pipe_params: the ABM handle, otg, panel and
  pwrseq instances and the ABM type of the panel. The builder resolves
  them with hwss_prepare_abm_set_pipe(), which the legacy dcn21 path
  uses too.
- Add a sixth parameter, feature_support, to abm_funcs.set_pipe_ex so
  the executor needs no dc lookup. The type is the new enum
  abm_feature_support in abm.h.
- Rename abm_feature_support() in dmub_abm.c to
  dmub_abm_feature_support(), declare it in dmub_abm.h and make it
  return the new enum. It looks the panel up by panel_inst, so the ABM
  type is unchanged.
  hwss_prepare_abm_set_pipe() uses it, like the other dmub_abm hooks.
- Adders return bool and hold all null and hook checks. Both adders
  require set_pipe_ex: no ASIC that runs the block sequence creates a
  DMCU, so the DMCU branch is gone from the BLS path. The level 0/255
  skip for non-CACP panels applies as in dcn21_set_abm_immediate_disable.
- Add PANEL_CNTL_STORE_BACKLIGHT_LEVEL. The callers add it with
  hwss_add_abm_immediate_disable_and_store_backlight(), which checks
  both free slots and the store hook first, so the ABM is never
  disabled without storing the backlight level.
Cc: Alvin Lee <[email protected]>
Signed-off-by: Rafal Ostrowski <[email protected]>
Signed-off-by: Chenyu Chen <[email protected]>
---
 drivers/gpu/drm/amd/display/dc/core/dc.c      |   2 +-
 .../drm/amd/display/dc/core/dc_hw_sequencer.c | 164 ++++++++++++++----
 drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c |  66 ++++---
 drivers/gpu/drm/amd/display/dc/dce/dmub_abm.h |   2 +
 .../amd/display/dc/hwss/dcn21/dcn21_hwseq.c   | 108 ++++++------
 .../amd/display/dc/hwss/dcn401/dcn401_hwseq.c |   6 +-
 .../drm/amd/display/dc/hwss/hw_sequencer.h    |  49 ++++--
 drivers/gpu/drm/amd/display/dc/inc/hw/abm.h   |  10 +-
 8 files changed, 267 insertions(+), 140 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c 
b/drivers/gpu/drm/amd/display/dc/core/dc.c
index 584eb3e0f4c6..032ce62c810e 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
@@ -4471,7 +4471,7 @@ static void 
commit_planes_do_stream_update_sequence(struct dc *dc,
 
                                if (should_program_abm) {
                                        if (*stream_update->abm_level == 
ABM_LEVEL_IMMEDIATE_DISABLE) {
-                                               
hwss_add_abm_set_immediate_disable(&seq_state, dc, pipe_ctx);
+                                               
hwss_add_abm_immediate_disable_and_store_backlight(&seq_state, pipe_ctx);
                                        } else {
                                                
hwss_add_abm_set_level(&seq_state, pipe_ctx->stream_res.abm, stream->abm_level);
                                        }
diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c 
b/drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c
index 079a9ee8c5f5..0cd17e0a4b9f 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c
@@ -40,6 +40,7 @@
 #include "clk_mgr.h"
 #include "dcn10/dcn10_hubbub.h"
 #include "dce/dmub_hw_lock_mgr.h"
+#include "dce/dmub_abm.h"
 #include "link_service.h"
 #include "custom_float.h"
 
@@ -1926,13 +1927,16 @@ void hwss_execute_sequence(struct dc *dc,
                        hwss_opp_set_disp_pattern_generator(params);
                        break;
                case ABM_SET_PIPE:
-                       hwss_set_abm_pipe(params);
+                       hwss_abm_set_pipe(params);
                        break;
                case ABM_SET_LEVEL:
-                       hwss_set_abm_level(params);
+                       hwss_abm_set_level(params);
                        break;
                case ABM_SET_IMMEDIATE_DISABLE:
-                       hwss_set_abm_immediate_disable(params);
+                       hwss_abm_set_immediate_disable(params);
+                       break;
+               case PANEL_CNTL_STORE_BACKLIGHT_LEVEL:
+                       hwss_panel_cntl_store_backlight_level(params);
                        break;
                case MPC_REMOVE_MPCC:
                        hwss_mpc_remove_mpcc(params);
@@ -2948,19 +2952,64 @@ void hwss_add_opp_program_left_edge_extra_pixel(struct 
block_sequence_state *seq
        }
 }
 
+bool hwss_should_skip_abm_immediate_disable(const struct pipe_ctx *pipe_ctx)
+{
+       const struct dc_stream_state *stream = pipe_ctx->stream;
+       const struct dc_link *link = stream->link;
+
+       // make a short term w/a for an issue that backlight ramping 
unexpectedly paused in the middle,
+       // will decouple backlight from ABM and redefine DMUB interface, then 
this w/a could be removed
+       return (stream->abm_level == 0 || stream->abm_level == 
ABM_LEVEL_IMMEDIATE_DISABLE) &&
+                       (link && !link->panel_config.cacp.cacp_supported);
+}
+
+bool hwss_prepare_abm_set_pipe(const struct pipe_ctx *pipe_ctx,
+               struct set_abm_pipe_params *params)
+{
+       struct abm *abm = pipe_ctx->stream_res.abm;
+       struct timing_generator *tg = pipe_ctx->stream_res.tg;
+       struct panel_cntl *panel_cntl = NULL;
+
+       memset(params, 0, sizeof(*params));
+
+       if (!pipe_ctx->stream || !pipe_ctx->stream->link)
+               return false;
+
+       panel_cntl = pipe_ctx->stream->link->panel_cntl;
+
+       if (!abm || !tg || !panel_cntl)
+               return false;
+
+       params->abm = abm;
+       params->otg_inst = tg->inst;
+       params->panel_inst = panel_cntl->inst;
+       params->pwrseq_inst = panel_cntl->pwrseq_inst;
+       params->abm_feature_support = dmub_abm_feature_support(abm, 
params->panel_inst);
+
+       return true;
+}
+
 /*
  * Helper function to add ABM set pipe to block sequence
  */
-void hwss_add_abm_set_pipe(struct block_sequence_state *seq_state,
-               struct dc *dc,
+bool hwss_add_abm_set_pipe(struct block_sequence_state *seq_state,
                struct pipe_ctx *pipe_ctx)
 {
-       if (*seq_state->num_steps < MAX_HWSS_BLOCK_SEQUENCE_SIZE) {
-               
seq_state->steps[*seq_state->num_steps].params.set_abm_pipe_params.dc = dc;
-               
seq_state->steps[*seq_state->num_steps].params.set_abm_pipe_params.pipe_ctx = 
pipe_ctx;
-               seq_state->steps[*seq_state->num_steps].func = ABM_SET_PIPE;
-               (*seq_state->num_steps)++;
-       }
+       struct set_abm_pipe_params prepared = {};
+
+       if (!seq_state || !seq_state->steps || !seq_state->num_steps ||
+                       *seq_state->num_steps >= MAX_HWSS_BLOCK_SEQUENCE_SIZE 
|| !pipe_ctx)
+               return false;
+
+       if (!hwss_prepare_abm_set_pipe(pipe_ctx, &prepared) ||
+                       !prepared.abm->funcs || 
!prepared.abm->funcs->set_pipe_ex)
+               return false;
+
+       seq_state->steps[*seq_state->num_steps].func = ABM_SET_PIPE;
+       seq_state->steps[*seq_state->num_steps].params.set_abm_pipe_params = 
prepared;
+       (*seq_state->num_steps)++;
+
+       return true;
 }
 
 /*
@@ -3803,15 +3852,15 @@ void hwss_opp_set_disp_pattern_generator(union 
block_sequence_params *params)
        }
 }
 
-void hwss_set_abm_pipe(union block_sequence_params *params)
+void hwss_abm_set_pipe(union block_sequence_params *params)
 {
-       struct dc *dc = params->set_abm_pipe_params.dc;
-       struct pipe_ctx *pipe_ctx = params->set_abm_pipe_params.pipe_ctx;
+       struct set_abm_pipe_params *p = &params->set_abm_pipe_params;
 
-       dc->hwss.set_pipe(pipe_ctx);
+       p->abm->funcs->set_pipe_ex(p->abm, p->otg_inst, SET_ABM_PIPE_NORMAL, 
p->panel_inst,
+                       p->pwrseq_inst, p->abm_feature_support);
 }
 
-void hwss_set_abm_level(union block_sequence_params *params)
+void hwss_abm_set_level(union block_sequence_params *params)
 {
        struct abm *abm = params->set_abm_level_params.abm;
        unsigned int abm_level = params->set_abm_level_params.abm_level;
@@ -3820,13 +3869,19 @@ void hwss_set_abm_level(union block_sequence_params 
*params)
                abm->funcs->set_abm_level(abm, abm_level);
 }
 
-void hwss_set_abm_immediate_disable(union block_sequence_params *params)
+void hwss_abm_set_immediate_disable(union block_sequence_params *params)
 {
-       struct dc *dc = params->set_abm_immediate_disable_params.dc;
-       struct pipe_ctx *pipe_ctx = 
params->set_abm_immediate_disable_params.pipe_ctx;
+       struct set_abm_pipe_params *p = 
&params->set_abm_immediate_disable_params;
 
-       if (dc && dc->hwss.set_abm_immediate_disable)
-               dc->hwss.set_abm_immediate_disable(pipe_ctx);
+       p->abm->funcs->set_pipe_ex(p->abm, p->otg_inst, 
SET_ABM_PIPE_IMMEDIATELY_DISABLE,
+                       p->panel_inst, p->pwrseq_inst, p->abm_feature_support);
+}
+
+void hwss_panel_cntl_store_backlight_level(union block_sequence_params *params)
+{
+       struct panel_cntl *panel_cntl = 
params->panel_cntl_store_backlight_level_params.panel_cntl;
+
+       panel_cntl->funcs->store_backlight_level(panel_cntl);
 }
 
 void hwss_mpc_remove_mpcc(union block_sequence_params *params)
@@ -5112,15 +5167,66 @@ void hwss_add_dc_set_optimized_required(struct 
block_sequence_state *seq_state,
        }
 }
 
-void hwss_add_abm_set_immediate_disable(struct block_sequence_state *seq_state,
-               struct dc *dc, struct pipe_ctx *pipe_ctx)
+bool hwss_add_abm_set_immediate_disable(struct block_sequence_state *seq_state,
+               struct pipe_ctx *pipe_ctx)
 {
-       if (*seq_state->num_steps < MAX_HWSS_BLOCK_SEQUENCE_SIZE) {
-               seq_state->steps[*seq_state->num_steps].func = 
ABM_SET_IMMEDIATE_DISABLE;
-               
seq_state->steps[*seq_state->num_steps].params.set_abm_immediate_disable_params.dc
 = dc;
-               
seq_state->steps[*seq_state->num_steps].params.set_abm_immediate_disable_params.pipe_ctx
 = pipe_ctx;
-               (*seq_state->num_steps)++;
-       }
+       struct set_abm_pipe_params prepared = {};
+
+       if (!seq_state || !seq_state->steps || !seq_state->num_steps ||
+                       *seq_state->num_steps >= MAX_HWSS_BLOCK_SEQUENCE_SIZE 
|| !pipe_ctx)
+               return false;
+
+       if (!hwss_prepare_abm_set_pipe(pipe_ctx, &prepared) ||
+                       !prepared.abm->funcs || 
!prepared.abm->funcs->set_pipe_ex)
+               return false;
+
+       if (hwss_should_skip_abm_immediate_disable(pipe_ctx))
+               return false;
+
+       seq_state->steps[*seq_state->num_steps].func = 
ABM_SET_IMMEDIATE_DISABLE;
+       
seq_state->steps[*seq_state->num_steps].params.set_abm_immediate_disable_params 
= prepared;
+       (*seq_state->num_steps)++;
+
+       return true;
+}
+
+bool hwss_add_panel_cntl_store_backlight_level(struct block_sequence_state 
*seq_state,
+               struct panel_cntl *panel_cntl)
+{
+       if (!seq_state || !seq_state->steps || !seq_state->num_steps ||
+                       *seq_state->num_steps >= MAX_HWSS_BLOCK_SEQUENCE_SIZE 
|| !panel_cntl)
+               return false;
+
+       if (!panel_cntl->funcs || !panel_cntl->funcs->store_backlight_level)
+               return false;
+
+       seq_state->steps[*seq_state->num_steps].func = 
PANEL_CNTL_STORE_BACKLIGHT_LEVEL;
+       seq_state->steps[*seq_state->num_steps]
+                       
.params.panel_cntl_store_backlight_level_params.panel_cntl = panel_cntl;
+       (*seq_state->num_steps)++;
+
+       return true;
+}
+
+bool hwss_add_abm_immediate_disable_and_store_backlight(
+               struct block_sequence_state *seq_state, struct pipe_ctx 
*pipe_ctx)
+{
+       struct panel_cntl *panel_cntl;
+
+       if (!seq_state || !seq_state->num_steps || !pipe_ctx || 
!pipe_ctx->stream ||
+                       !pipe_ctx->stream->link)
+               return false;
+
+       panel_cntl = pipe_ctx->stream->link->panel_cntl;
+
+       if (*seq_state->num_steps + 2 > MAX_HWSS_BLOCK_SEQUENCE_SIZE || 
!panel_cntl ||
+                       !panel_cntl->funcs || 
!panel_cntl->funcs->store_backlight_level)
+               return false;
+
+       if (!hwss_add_abm_set_immediate_disable(seq_state, pipe_ctx))
+               return false;
+
+       return hwss_add_panel_cntl_store_backlight_level(seq_state, panel_cntl);
 }
 
 void hwss_add_opp_set_disp_pattern_generator(struct block_sequence_state 
*seq_state,
diff --git a/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c 
b/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c
index 8cca8599b917..b50260d2bd45 100644
--- a/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c
+++ b/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c
@@ -35,33 +35,26 @@
 #define TO_DMUB_ABM(abm)\
        container_of(abm, struct dce_abm, base)
 
-#define ABM_FEATURE_NO_SUPPORT 0
-#define ABM_LCD_SUPPORT                        1
-#define ABM_CACP_SUPPORT               2
-
-static unsigned int abm_feature_support(struct abm *abm, unsigned int 
panel_inst)
+enum abm_feature_support dmub_abm_feature_support(struct abm *abm, unsigned 
int panel_inst)
 {
-       struct dc_context *dc = abm->ctx;
        struct dc_link *edp_links[MAX_NUM_EDP];
-       unsigned int i, edp_num;
-       unsigned int ret = ABM_FEATURE_NO_SUPPORT;
+       unsigned int edp_num;
+       const struct dc_link *link;
 
-       dc_get_edp_links(dc->dc, edp_links, &edp_num);
+       dc_get_edp_links(abm->ctx->dc, edp_links, &edp_num);
 
-       for (i = 0; i < edp_num; i++) {
-               if (panel_inst == i)
-                       break;
-       }
+       if (panel_inst >= edp_num)
+               return ABM_FEATURE_NO_SUPPORT;
 
-       if (i < edp_num) {
-               if (edp_links[panel_inst]->panel_config.cacp.cacp_supported)
-                       ret = ABM_CACP_SUPPORT;
-               else if ((edp_links[panel_inst]->panel_type == PANEL_TYPE_LCD) 
||
-                               (edp_links[panel_inst]->panel_type == 
PANEL_TYPE_MINILED))
-                       ret = ABM_LCD_SUPPORT;
-       }
+       link = edp_links[panel_inst];
 
-       return ret;
+       if (link->panel_config.cacp.cacp_supported)
+               return ABM_CACP_SUPPORT;
+
+       if (link->panel_type == PANEL_TYPE_LCD || link->panel_type == 
PANEL_TYPE_MINILED)
+               return ABM_LCD_SUPPORT;
+
+       return ABM_FEATURE_NO_SUPPORT;
 }
 
 static enum dc_panel_type abm_get_paneltype(struct abm *abm, unsigned int 
panel_inst)
@@ -115,12 +108,13 @@ static unsigned int 
dmub_abm_get_target_backlight_ex(struct abm *abm)
 static bool dmub_abm_set_level_ex(struct abm *abm, uint32_t level)
 {
        bool ret = false;
-       unsigned int feature_support, i;
+       enum abm_feature_support feature_support;
+       unsigned int i;
        uint8_t panel_mask0 = 0;
        uint8_t panel_mask1 = 0;
 
        for (i = 0; i < MAX_NUM_EDP; i++) {
-               feature_support = abm_feature_support(abm, i);
+               feature_support = dmub_abm_feature_support(abm, i);
 
                if (feature_support == ABM_LCD_SUPPORT)
                        panel_mask0 |= (0x01 << i);
@@ -142,9 +136,9 @@ static bool dmub_abm_init_config_ex(struct abm *abm,
        unsigned int bytes,
        unsigned int inst)
 {
-       unsigned int feature_support;
+       enum abm_feature_support feature_support;
 
-       feature_support = abm_feature_support(abm, inst);
+       feature_support = dmub_abm_feature_support(abm, inst);
 
        if (feature_support == ABM_LCD_SUPPORT)
                dmub_abm_init_config(abm, src, bytes, inst);
@@ -157,9 +151,9 @@ static bool dmub_abm_init_config_ex(struct abm *abm,
 static bool dmub_abm_set_pause_ex(struct abm *abm, bool pause, unsigned int 
panel_inst, unsigned int stream_inst)
 {
        bool ret = false;
-       unsigned int feature_support;
+       enum abm_feature_support feature_support;
 
-       feature_support = abm_feature_support(abm, panel_inst);
+       feature_support = dmub_abm_feature_support(abm, panel_inst);
 
        if (feature_support == ABM_LCD_SUPPORT)
                ret = dmub_abm_set_pause(abm, pause, panel_inst, stream_inst);
@@ -184,10 +178,10 @@ static bool dmub_abm_save_restore_ex(
                struct abm_save_restore *pData)
 {
        bool ret = false;
-       unsigned int feature_support;
+       enum abm_feature_support feature_support;
        struct dc_context *dc = abm->ctx;
 
-       feature_support = abm_feature_support(abm, panel_inst);
+       feature_support = dmub_abm_feature_support(abm, panel_inst);
 
        if (feature_support == ABM_LCD_SUPPORT)
                ret = dmub_abm_save_restore(dc, panel_inst, pData);
@@ -199,12 +193,10 @@ static bool dmub_abm_set_pipe_ex(struct abm *abm,
                uint32_t otg_inst,
                uint32_t option,
                uint32_t panel_inst,
-               uint32_t pwrseq_inst)
+               uint32_t pwrseq_inst,
+               enum abm_feature_support feature_support)
 {
        bool ret = false;
-       unsigned int feature_support;
-
-       feature_support = abm_feature_support(abm, panel_inst);
 
        if (feature_support == ABM_LCD_SUPPORT)
                ret = dmub_abm_set_pipe(abm, otg_inst, option, panel_inst, 
pwrseq_inst);
@@ -219,9 +211,9 @@ static bool dmub_abm_set_event_ex(struct abm *abm, unsigned 
int full_screen, uns
                unsigned int panel_inst)
 {
        bool ret = false;
-       unsigned int feature_support;
+       enum abm_feature_support feature_support;
 
-       feature_support = abm_feature_support(abm, panel_inst);
+       feature_support = dmub_abm_feature_support(abm, panel_inst);
 
        if (feature_support == ABM_LCD_SUPPORT)
                ret = dmub_abm_set_event(abm, scaling_enable, 
scaling_strength_map, panel_inst);
@@ -239,10 +231,10 @@ static bool dmub_abm_set_backlight_level_pwm_ex(struct 
abm *abm,
 {
        (void)controller_id;
        bool ret = false;
-       unsigned int feature_support;
+       enum abm_feature_support feature_support;
        enum dc_panel_type panel_type = PANEL_TYPE_NONE;
 
-       feature_support = abm_feature_support(abm, panel_inst);
+       feature_support = dmub_abm_feature_support(abm, panel_inst);
 
        if (feature_support == ABM_LCD_SUPPORT)
                ret = dmub_abm_set_backlight_level(abm, backlight_pwm_u16_16, 
frame_ramp, panel_inst);
diff --git a/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.h 
b/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.h
index 3a5d5ac7a86e..eef2fa803aed 100644
--- a/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.h
+++ b/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.h
@@ -37,4 +37,6 @@ struct abm *dmub_abm_create(
 
 void dmub_abm_destroy(struct abm **abm);
 
+enum abm_feature_support dmub_abm_feature_support(struct abm *abm, unsigned 
int panel_inst);
+
 #endif
diff --git a/drivers/gpu/drm/amd/display/dc/hwss/dcn21/dcn21_hwseq.c 
b/drivers/gpu/drm/amd/display/dc/hwss/dcn21/dcn21_hwseq.c
index 2be68f8dd0fc..673fc188fca9 100644
--- a/drivers/gpu/drm/amd/display/dc/hwss/dcn21/dcn21_hwseq.c
+++ b/drivers/gpu/drm/amd/display/dc/hwss/dcn21/dcn21_hwseq.c
@@ -197,55 +197,51 @@ static void dmub_abm_set_backlight(struct dc_context *dc, 
uint32_t backlight_pwm
 
 void dcn21_set_abm_immediate_disable(struct pipe_ctx *pipe_ctx)
 {
-       struct abm *abm = pipe_ctx->stream_res.abm;
-       uint32_t otg_inst = pipe_ctx->stream_res.tg->inst;
-       struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
+       struct set_abm_pipe_params params = {};
        struct dmcu *dmcu = pipe_ctx->stream->ctx->dc->res_pool->dmcu;
        struct dc_link *link = pipe_ctx->stream->link;
+       struct abm *abm = NULL;
 
-       // make a short term w/a for an issue that backlight ramping 
unexpectedly paused in the middle,
-       // will decouple backlight from ABM and redefine DMUB interface, then 
this w/a could be removed
-       if ((pipe_ctx->stream->abm_level == 0 || pipe_ctx->stream->abm_level == 
ABM_LEVEL_IMMEDIATE_DISABLE)
-               && (link && !link->panel_config.cacp.cacp_supported)) {
+       if (hwss_should_skip_abm_immediate_disable(pipe_ctx))
                return;
-       }
 
        if (dmcu) {
                dce110_set_abm_immediate_disable(pipe_ctx);
                return;
        }
 
-       if (abm && panel_cntl) {
-               if (abm->funcs && abm->funcs->set_pipe_ex) {
-                       abm->funcs->set_pipe_ex(abm, otg_inst, 
SET_ABM_PIPE_IMMEDIATELY_DISABLE,
-                                       panel_cntl->inst, 
panel_cntl->pwrseq_inst);
-               } else if (link && link->panel_config.cacp.cacp_supported) {
-                       dcn21_dmub_cacp_set_pipe(abm, otg_inst, 
SET_CACP_PIPE_IMMEDIATELY_DISABLE,
-                                               panel_cntl->inst, 
panel_cntl->pwrseq_inst);
-               } else {
-                       dcn21_dmub_abm_set_pipe(abm,
-                                               otg_inst,
-                                               
SET_ABM_PIPE_IMMEDIATELY_DISABLE,
-                                               panel_cntl->inst,
-                                               panel_cntl->pwrseq_inst);
-               }
-               panel_cntl->funcs->store_backlight_level(panel_cntl);
+       if (!hwss_prepare_abm_set_pipe(pipe_ctx, &params))
+               return;
+
+       abm = params.abm;
+
+       if (abm->funcs && abm->funcs->set_pipe_ex) {
+               abm->funcs->set_pipe_ex(abm, params.otg_inst, 
SET_ABM_PIPE_IMMEDIATELY_DISABLE,
+                               params.panel_inst, params.pwrseq_inst, 
params.abm_feature_support);
+       } else if (link->panel_config.cacp.cacp_supported) {
+               dcn21_dmub_cacp_set_pipe(abm, params.otg_inst, 
SET_CACP_PIPE_IMMEDIATELY_DISABLE,
+                                       params.panel_inst, params.pwrseq_inst);
+       } else {
+               dcn21_dmub_abm_set_pipe(abm,
+                                       params.otg_inst,
+                                       SET_ABM_PIPE_IMMEDIATELY_DISABLE,
+                                       params.panel_inst,
+                                       params.pwrseq_inst);
        }
+       link->panel_cntl->funcs->store_backlight_level(link->panel_cntl);
 }
 
 void dcn21_set_pipe(struct pipe_ctx *pipe_ctx)
 {
-       struct abm *abm = pipe_ctx->stream_res.abm;
-       struct timing_generator *tg = pipe_ctx->stream_res.tg;
-       struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
+       struct set_abm_pipe_params params = {};
        struct dmcu *dmcu = pipe_ctx->stream->ctx->dc->res_pool->dmcu;
        struct dc_link *link = pipe_ctx->stream->link;
-       uint32_t otg_inst;
+       struct abm *abm = NULL;
 
-       if (!abm || !tg || !panel_cntl)
+       if (!hwss_prepare_abm_set_pipe(pipe_ctx, &params))
                return;
 
-       otg_inst = tg->inst;
+       abm = params.abm;
 
        if (dmcu) {
                dce110_set_pipe(pipe_ctx);
@@ -254,20 +250,21 @@ void dcn21_set_pipe(struct pipe_ctx *pipe_ctx)
 
        if (abm->funcs && abm->funcs->set_pipe_ex) {
                abm->funcs->set_pipe_ex(abm,
-                                       otg_inst,
+                                       params.otg_inst,
                                        SET_ABM_PIPE_NORMAL,
-                                       panel_cntl->inst,
-                                       panel_cntl->pwrseq_inst);
+                                       params.panel_inst,
+                                       params.pwrseq_inst,
+                                       params.abm_feature_support);
        } else {
 
-               if (link && link->panel_config.cacp.cacp_supported)
-                       dcn21_dmub_cacp_set_pipe(abm, otg_inst, 
SET_CACP_PIPE_NORMAL,
-                                       panel_cntl->inst, 
panel_cntl->pwrseq_inst);
+               if (link->panel_config.cacp.cacp_supported)
+                       dcn21_dmub_cacp_set_pipe(abm, params.otg_inst, 
SET_CACP_PIPE_NORMAL,
+                                       params.panel_inst, params.pwrseq_inst);
                else
-                       dcn21_dmub_abm_set_pipe(abm, otg_inst,
+                       dcn21_dmub_abm_set_pipe(abm, params.otg_inst,
                                  SET_ABM_PIPE_NORMAL,
-                                 panel_cntl->inst,
-                                 panel_cntl->pwrseq_inst);
+                                 params.panel_inst,
+                                 params.pwrseq_inst);
        }
 }
 
@@ -275,18 +272,16 @@ bool dcn21_set_backlight_level(struct pipe_ctx *pipe_ctx,
        struct set_backlight_level_params *backlight_level_params)
 {
        struct dc_context *dc = pipe_ctx->stream->ctx;
-       struct abm *abm = pipe_ctx->stream_res.abm;
-       struct timing_generator *tg = pipe_ctx->stream_res.tg;
-       struct panel_cntl *panel_cntl = pipe_ctx->stream->link->panel_cntl;
-       uint32_t otg_inst;
+       struct set_abm_pipe_params params = {};
        uint32_t backlight_pwm_u16_16 = 
backlight_level_params->backlight_pwm_u16_16;
        uint32_t frame_ramp = backlight_level_params->frame_ramp;
        struct dc_link *link = pipe_ctx->stream->link;
+       struct abm *abm = NULL;
 
-       if (!abm || !tg || !panel_cntl)
+       if (!hwss_prepare_abm_set_pipe(pipe_ctx, &params))
                return false;
 
-       otg_inst = tg->inst;
+       abm = params.abm;
 
        if (dc->dc->res_pool->dmcu) {
                dce110_set_backlight_level(pipe_ctx, backlight_level_params);
@@ -295,29 +290,30 @@ bool dcn21_set_backlight_level(struct pipe_ctx *pipe_ctx,
 
        if (abm->funcs && abm->funcs->set_pipe_ex) {
                abm->funcs->set_pipe_ex(abm,
-                                       otg_inst,
+                                       params.otg_inst,
                                        SET_ABM_PIPE_NORMAL,
-                                       panel_cntl->inst,
-                                       panel_cntl->pwrseq_inst);
+                                       params.panel_inst,
+                                       params.pwrseq_inst,
+                                       params.abm_feature_support);
        } else {
-               if (link && link->panel_config.cacp.cacp_supported)
-                       dcn21_dmub_cacp_set_pipe(abm, otg_inst,
+               if (link->panel_config.cacp.cacp_supported)
+                       dcn21_dmub_cacp_set_pipe(abm, params.otg_inst,
                                        SET_CACP_PIPE_NORMAL,
-                                       panel_cntl->inst,
-                                       panel_cntl->pwrseq_inst);
+                                       params.panel_inst,
+                                       params.pwrseq_inst);
                else
                        dcn21_dmub_abm_set_pipe(abm,
-                                 otg_inst,
+                                 params.otg_inst,
                                  SET_ABM_PIPE_NORMAL,
-                                 panel_cntl->inst,
-                                 panel_cntl->pwrseq_inst);
+                                 params.panel_inst,
+                                 params.pwrseq_inst);
        }
 
        if (abm->funcs && abm->funcs->set_backlight_level_pwm)
                abm->funcs->set_backlight_level_pwm(abm, backlight_pwm_u16_16,
-                       frame_ramp, 0, panel_cntl->inst);
+                       frame_ramp, 0, params.panel_inst);
        else
-               dmub_abm_set_backlight(dc, backlight_pwm_u16_16, frame_ramp, 
panel_cntl->inst);
+               dmub_abm_set_backlight(dc, backlight_pwm_u16_16, frame_ramp, 
params.panel_inst);
 
        return true;
 }
diff --git a/drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.c 
b/drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.c
index 7b1eca0e2b57..26b9137dc017 100644
--- a/drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.c
+++ b/drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.c
@@ -2553,7 +2553,7 @@ void dcn401_program_pipe_sequence(
        /* Set ABM pipe after other pipe configurations done */
        if ((pipe_ctx->plane_state && pipe_ctx->plane_state->visible)) {
                if (pipe_ctx->stream_res.abm) {
-                       hwss_add_abm_set_pipe(seq_state, dc, pipe_ctx);
+                       hwss_add_abm_set_pipe(seq_state, pipe_ctx);
 
                        hwss_add_abm_set_level(seq_state, 
pipe_ctx->stream_res.abm, pipe_ctx->stream->abm_level);
                }
@@ -3382,7 +3382,7 @@ void dcn401_blank_pixel_data_sequence(
 
        if (blank) {
                /* Set ABM immediate disable */
-               hwss_add_abm_set_immediate_disable(seq_state, dc, pipe_ctx);
+               hwss_add_abm_immediate_disable_and_store_backlight(seq_state, 
pipe_ctx);
 
                if (dc->debug.visual_confirm != VISUAL_CONFIRM_DISABLE) {
                        test_pattern = CONTROLLER_DP_TEST_PATTERN_COLORSQUARES;
@@ -3432,7 +3432,7 @@ void dcn401_blank_pixel_data_sequence(
        if (!blank) {
                if (stream_res->abm) {
                        /* Set pipe for ABM */
-                       hwss_add_abm_set_pipe(seq_state, dc, pipe_ctx);
+                       hwss_add_abm_set_pipe(seq_state, pipe_ctx);
 
                        /* Set ABM level */
                        hwss_add_abm_set_level(seq_state, stream_res->abm, 
stream->abm_level);
diff --git a/drivers/gpu/drm/amd/display/dc/hwss/hw_sequencer.h 
b/drivers/gpu/drm/amd/display/dc/hwss/hw_sequencer.h
index 4769c71f05fb..da795c6501f5 100644
--- a/drivers/gpu/drm/amd/display/dc/hwss/hw_sequencer.h
+++ b/drivers/gpu/drm/amd/display/dc/hwss/hw_sequencer.h
@@ -34,6 +34,7 @@
 #include "inc/core_status.h"
 #include "inc/hw/hw_shared.h"
 #include "inc/hw/dchubbub.h"
+#include "inc/hw/abm.h"
 #include "dsc/dsc.h"
 #include "link_service_types.h"
 #include "dmub/inc/dmub_cmd.h"
@@ -772,9 +773,13 @@ struct opp_set_disp_pattern_generator_params {
        bool disable_dyn_exp_for_test_pattern;
 };
 
+/* Params of both ABM_SET_PIPE and ABM_SET_IMMEDIATE_DISABLE. */
 struct set_abm_pipe_params {
-       struct dc *dc;
-       struct pipe_ctx *pipe_ctx;
+       struct abm *abm;
+       unsigned int otg_inst;
+       unsigned int panel_inst;
+       unsigned int pwrseq_inst;
+       enum abm_feature_support abm_feature_support; /* resolved at build time 
*/
 };
 
 struct set_abm_level_params {
@@ -782,9 +787,8 @@ struct set_abm_level_params {
        unsigned int abm_level;
 };
 
-struct set_abm_immediate_disable_params {
-       struct dc *dc;
-       struct pipe_ctx *pipe_ctx;
+struct panel_cntl_store_backlight_level_params {
+       struct panel_cntl *panel_cntl;
 };
 
 struct mpc_update_blending_params {
@@ -1459,7 +1463,9 @@ union block_sequence_params {
        struct opp_set_disp_pattern_generator_params 
opp_set_disp_pattern_generator_params;
        struct set_abm_pipe_params set_abm_pipe_params;
        struct set_abm_level_params set_abm_level_params;
-       struct set_abm_immediate_disable_params 
set_abm_immediate_disable_params;
+       struct set_abm_pipe_params set_abm_immediate_disable_params;
+       struct panel_cntl_store_backlight_level_params
+                       panel_cntl_store_backlight_level_params;
        struct mpc_remove_mpcc_params mpc_remove_mpcc_params;
        struct dc_set_optimized_required_params 
dc_set_optimized_required_params;
        struct hubp_disconnect_params hubp_disconnect_params;
@@ -1896,6 +1902,7 @@ enum block_sequence_func {
        HUBP_SET_3DLUT_FL,
        PMFW_SEND_MESSAGE_AND_WAIT,
        DMUB_SEND_DMCUB_CMD2,
+       PANEL_CNTL_STORE_BACKLIGHT_LEVEL,
        /* This must be the last value in this enum, add new ones above */
        HWSS_BLOCK_SEQUENCE_FUNC_COUNT
 };
@@ -2500,11 +2507,13 @@ void hwss_opp_program_bit_depth_reduction(union 
block_sequence_params *params);
 
 void hwss_opp_set_disp_pattern_generator(union block_sequence_params *params);
 
-void hwss_set_abm_pipe(union block_sequence_params *params);
+void hwss_abm_set_pipe(union block_sequence_params *params);
 
-void hwss_set_abm_level(union block_sequence_params *params);
+void hwss_abm_set_level(union block_sequence_params *params);
 
-void hwss_set_abm_immediate_disable(union block_sequence_params *params);
+void hwss_abm_set_immediate_disable(union block_sequence_params *params);
+
+void hwss_panel_cntl_store_backlight_level(union block_sequence_params 
*params);
 
 void hwss_mpc_remove_mpcc(union block_sequence_params *params);
 
@@ -2805,8 +2814,13 @@ void hwss_add_opp_program_fmt(struct 
block_sequence_state *seq_state,
                struct output_pixel_processor *opp, struct 
bit_depth_reduction_params *fmt_bit_depth,
                struct clamping_and_pixel_encoding_params *clamping);
 
-void hwss_add_abm_set_pipe(struct block_sequence_state *seq_state,
-               struct dc *dc, struct pipe_ctx *pipe_ctx);
+bool hwss_add_abm_set_pipe(struct block_sequence_state *seq_state,
+               struct pipe_ctx *pipe_ctx);
+
+bool hwss_prepare_abm_set_pipe(const struct pipe_ctx *pipe_ctx,
+               struct set_abm_pipe_params *params);
+
+bool hwss_should_skip_abm_immediate_disable(const struct pipe_ctx *pipe_ctx);
 
 void hwss_add_abm_set_level(struct block_sequence_state *seq_state,
                struct abm *abm, uint32_t abm_level);
@@ -2842,8 +2856,17 @@ void hwss_add_dsc_disconnect(struct block_sequence_state 
*seq_state,
 void hwss_add_dc_set_optimized_required(struct block_sequence_state *seq_state,
                bool optimized_required);
 
-void hwss_add_abm_set_immediate_disable(struct block_sequence_state *seq_state,
-               struct dc *dc, struct pipe_ctx *pipe_ctx);
+/* Callers must use hwss_add_abm_immediate_disable_and_store_backlight(): this 
step alone
+ * does not store the backlight level.
+ */
+bool hwss_add_abm_set_immediate_disable(struct block_sequence_state *seq_state,
+               struct pipe_ctx *pipe_ctx);
+
+bool hwss_add_panel_cntl_store_backlight_level(struct block_sequence_state 
*seq_state,
+               struct panel_cntl *panel_cntl);
+
+bool hwss_add_abm_immediate_disable_and_store_backlight(
+               struct block_sequence_state *seq_state, struct pipe_ctx 
*pipe_ctx);
 
 void hwss_add_opp_set_disp_pattern_generator(struct block_sequence_state 
*seq_state,
                struct output_pixel_processor *opp,
diff --git a/drivers/gpu/drm/amd/display/dc/inc/hw/abm.h 
b/drivers/gpu/drm/amd/display/dc/inc/hw/abm.h
index e3fa987304da..925d80d956d8 100644
--- a/drivers/gpu/drm/amd/display/dc/inc/hw/abm.h
+++ b/drivers/gpu/drm/amd/display/dc/inc/hw/abm.h
@@ -27,6 +27,13 @@
 
 #include "dm_services_types.h"
 
+/* ABM engine type a panel is driven by. */
+enum abm_feature_support {
+       ABM_FEATURE_NO_SUPPORT = 0,
+       ABM_LCD_SUPPORT = 1,
+       ABM_CACP_SUPPORT = 2,
+};
+
 struct abm_save_restore;
 
 struct abm {
@@ -66,7 +73,8 @@ struct abm_funcs {
                        unsigned int otg_inst,
                        unsigned int option,
                        unsigned int panel_inst,
-                       unsigned int pwrseq_inst);
+                       unsigned int pwrseq_inst,
+                       enum abm_feature_support feature_support);
        bool (*set_abm_event)(struct abm *abm, unsigned int full_screen, 
unsigned int trans_info,
                        unsigned int hdr_mode, unsigned int scaling_enable, 
unsigned int scaling_strength_map,
                        unsigned int panel_inst);
-- 
2.43.0

Reply via email to