drm/amd/display: Fix GSL acquire
[linux-2.6-microblaze.git] / drivers / gpu / drm / amd / display / dc / dcn20 / dcn20_hwseq.c
index ac8c18f..9713f45 100644 (file)
 #include <linux/delay.h>
 
 #include "dm_services.h"
+#include "basics/dc_common.h"
 #include "dm_helpers.h"
 #include "core_types.h"
 #include "resource.h"
-#include "dcn20/dcn20_resource.h"
-#include "dce110/dce110_hw_sequencer.h"
-#include "dcn10/dcn10_hw_sequencer.h"
+#include "dcn20_resource.h"
 #include "dcn20_hwseq.h"
 #include "dce/dce_hwseq.h"
-#ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
-#include "dcn20/dcn20_dsc.h"
-#endif
+#include "dcn20_dsc.h"
+#include "dcn20_optc.h"
 #include "abm.h"
 #include "clk_mgr.h"
 #include "dmcu.h"
 #include "ipp.h"
 #include "mpc.h"
 #include "mcif_wb.h"
+#include "dchubbub.h"
 #include "reg_helper.h"
 #include "dcn10/dcn10_cm_common.h"
-#include "dcn10/dcn10_hubbub.h"
-#include "dcn10/dcn10_optc.h"
 #include "dc_link_dp.h"
 #include "vm_helper.h"
 #include "dccg.h"
 #define FN(reg_name, field_name) \
        hws->shifts->field_name, hws->masks->field_name
 
-static void dcn20_enable_power_gating_plane(
+static int find_free_gsl_group(const struct dc *dc)
+{
+       if (dc->res_pool->gsl_groups.gsl_0 == 0)
+               return 1;
+       if (dc->res_pool->gsl_groups.gsl_1 == 0)
+               return 2;
+       if (dc->res_pool->gsl_groups.gsl_2 == 0)
+               return 3;
+
+       return 0;
+}
+
+/* NOTE: This is not a generic setup_gsl function (hence the suffix as_lock)
+ * This is only used to lock pipes in pipe splitting case with immediate flip
+ * Ordinary MPC/OTG locks suppress VUPDATE which doesn't help with immediate,
+ * so we get tearing with freesync since we cannot flip multiple pipes
+ * atomically.
+ * We use GSL for this:
+ * - immediate flip: find first available GSL group if not already assigned
+ *                   program gsl with that group, set current OTG as master
+ *                   and always us 0x4 = AND of flip_ready from all pipes
+ * - vsync flip: disable GSL if used
+ *
+ * Groups in stream_res are stored as +1 from HW registers, i.e.
+ * gsl_0 <=> pipe_ctx->stream_res.gsl_group == 1
+ * Using a magic value like -1 would require tracking all inits/resets
+ */
+static void dcn20_setup_gsl_group_as_lock(
+               const struct dc *dc,
+               struct pipe_ctx *pipe_ctx,
+               bool enable)
+{
+       struct gsl_params gsl;
+       int group_idx;
+
+       memset(&gsl, 0, sizeof(struct gsl_params));
+
+       if (enable) {
+               /* return if group already assigned since GSL was set up
+                * for vsync flip, we would unassign so it can't be "left over"
+                */
+               if (pipe_ctx->stream_res.gsl_group > 0)
+                       return;
+
+               group_idx = find_free_gsl_group(dc);
+               ASSERT(group_idx != 0);
+               pipe_ctx->stream_res.gsl_group = group_idx;
+
+               /* set gsl group reg field and mark resource used */
+               switch (group_idx) {
+               case 1:
+                       gsl.gsl0_en = 1;
+                       dc->res_pool->gsl_groups.gsl_0 = 1;
+                       break;
+               case 2:
+                       gsl.gsl1_en = 1;
+                       dc->res_pool->gsl_groups.gsl_1 = 1;
+                       break;
+               case 3:
+                       gsl.gsl2_en = 1;
+                       dc->res_pool->gsl_groups.gsl_2 = 1;
+                       break;
+               default:
+                       BREAK_TO_DEBUGGER();
+                       return; // invalid case
+               }
+               gsl.gsl_master_en = 1;
+       } else {
+               group_idx = pipe_ctx->stream_res.gsl_group;
+               if (group_idx == 0)
+                       return; // if not in use, just return
+
+               pipe_ctx->stream_res.gsl_group = 0;
+
+               /* unset gsl group reg field and mark resource free */
+               switch (group_idx) {
+               case 1:
+                       gsl.gsl0_en = 0;
+                       dc->res_pool->gsl_groups.gsl_0 = 0;
+                       break;
+               case 2:
+                       gsl.gsl1_en = 0;
+                       dc->res_pool->gsl_groups.gsl_1 = 0;
+                       break;
+               case 3:
+                       gsl.gsl2_en = 0;
+                       dc->res_pool->gsl_groups.gsl_2 = 0;
+                       break;
+               default:
+                       BREAK_TO_DEBUGGER();
+                       return;
+               }
+               gsl.gsl_master_en = 0;
+       }
+
+       /* at this point we want to program whether it's to enable or disable */
+       if (pipe_ctx->stream_res.tg->funcs->set_gsl != NULL &&
+               pipe_ctx->stream_res.tg->funcs->set_gsl_source_select != NULL) {
+               pipe_ctx->stream_res.tg->funcs->set_gsl(
+                       pipe_ctx->stream_res.tg,
+                       &gsl);
+
+               pipe_ctx->stream_res.tg->funcs->set_gsl_source_select(
+                       pipe_ctx->stream_res.tg, group_idx,     enable ? 4 : 0);
+       } else
+               BREAK_TO_DEBUGGER();
+}
+
+void dcn20_set_flip_control_gsl(
+               struct pipe_ctx *pipe_ctx,
+               bool flip_immediate)
+{
+       if (pipe_ctx && pipe_ctx->plane_res.hubp->funcs->hubp_set_flip_control_surface_gsl)
+               pipe_ctx->plane_res.hubp->funcs->hubp_set_flip_control_surface_gsl(
+                               pipe_ctx->plane_res.hubp, flip_immediate);
+
+}
+
+void dcn20_enable_power_gating_plane(
        struct dce_hwseq *hws,
        bool enable)
 {
-       bool force_on = 1; /* disable power gating */
+       bool force_on = true; /* disable power gating */
 
        if (enable)
-               force_on = 0;
+               force_on = false;
 
        /* DCHUBP0/1/2/3/4/5 */
        REG_UPDATE(DOMAIN0_PG_CONFIG, DOMAIN0_POWER_FORCEON, force_on);
@@ -128,44 +243,6 @@ void dcn20_dccg_init(struct dce_hwseq *hws)
        /* This value is dependent on the hardware pipeline delay so set once per SOC */
        REG_WRITE(DISPCLK_FREQ_CHANGE_CNTL, 0x801003c);
 }
-void dcn20_display_init(struct dc *dc)
-{
-       struct dce_hwseq *hws = dc->hwseq;
-
-       /* RBBMIF
-        * disable RBBMIF timeout detection for all clients
-        * Ensure RBBMIF does not drop register accesses due to the per-client timeout
-        */
-       REG_WRITE(RBBMIF_TIMEOUT_DIS, 0xFFFFFFFF);
-       REG_WRITE(RBBMIF_TIMEOUT_DIS_2, 0xFFFFFFFF);
-
-       /* DCCG */
-       dcn20_dccg_init(hws);
-
-       REG_UPDATE(DC_MEM_GLOBAL_PWR_REQ_CNTL, DC_MEM_GLOBAL_PWR_REQ_DIS, 0);
-
-       /* DCHUB/MMHUBBUB
-        * set global timer refclk divider
-        * 100Mhz refclk -> 2
-        * 27Mhz refclk ->  1
-        * 48Mhz refclk ->  1
-        */
-       REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_REFDIV, 2);
-       REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_ENABLE, 1);
-       REG_WRITE(REFCLK_CNTL, 0);
-
-       /* OPTC
-        * OTG_CONTROL.OTG_DISABLE_POINT_CNTL = 0x3; will be set during optc2_enable_crtc
-        */
-
-       /* AZ
-        * default value is 0x64 for 100Mhz ref clock, if the ref clock is 100Mhz, no need to program this regiser,
-        * if not, it should be programmed according to the ref clock
-        */
-       REG_UPDATE(AZALIA_AUDIO_DTO, AZALIA_AUDIO_DTO_MODULE, 0x64);
-       /* Enable controller clock gating */
-       REG_WRITE(AZALIA_CONTROLLER_CLOCK_GATING, 0x1);
-}
 
 void dcn20_disable_vga(
        struct dce_hwseq *hws)
@@ -178,15 +255,15 @@ void dcn20_disable_vga(
        REG_WRITE(D6VGA_CONTROL, 0);
 }
 
-void dcn20_program_tripleBuffer(
+void dcn20_program_triple_buffer(
        const struct dc *dc,
        struct pipe_ctx *pipe_ctx,
-       bool enableTripleBuffer)
+       bool enable_triple_buffer)
 {
        if (pipe_ctx->plane_res.hubp && pipe_ctx->plane_res.hubp->funcs) {
                pipe_ctx->plane_res.hubp->funcs->hubp_enable_tripleBuffer(
                        pipe_ctx->plane_res.hubp,
-                       enableTripleBuffer);
+                       enable_triple_buffer);
        }
 }
 
@@ -195,6 +272,7 @@ void dcn20_init_blank(
                struct dc *dc,
                struct timing_generator *tg)
 {
+       struct dce_hwseq *hws = dc->hwseq;
        enum dc_color_space color_space;
        struct tg_color black_color = {0};
        struct output_pixel_processor *opp = NULL;
@@ -225,6 +303,7 @@ void dcn20_init_blank(
        opp->funcs->opp_set_disp_pattern_generator(
                        opp,
                        CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR,
+                       CONTROLLER_DP_COLOR_SPACE_UDEFINED,
                        COLOR_DEPTH_UNDEFINED,
                        &black_color,
                        otg_active_width,
@@ -234,17 +313,17 @@ void dcn20_init_blank(
                bottom_opp->funcs->opp_set_disp_pattern_generator(
                                bottom_opp,
                                CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR,
+                               CONTROLLER_DP_COLOR_SPACE_UDEFINED,
                                COLOR_DEPTH_UNDEFINED,
                                &black_color,
                                otg_active_width,
                                otg_active_height);
        }
 
-       dcn20_hwss_wait_for_blank_complete(opp);
+       hws->funcs.wait_for_blank_complete(opp);
 }
 
-#ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
-static void dcn20_dsc_pg_control(
+void dcn20_dsc_pg_control(
                struct dce_hwseq *hws,
                unsigned int dsc_inst,
                bool power_on)
@@ -320,9 +399,8 @@ static void dcn20_dsc_pg_control(
        if (org_ip_request_cntl == 0)
                REG_SET(DC_IP_REQUEST_CNTL, 0, IP_REQUEST_EN, 0);
 }
-#endif
 
-static void dcn20_dpp_pg_control(
+void dcn20_dpp_pg_control(
                struct dce_hwseq *hws,
                unsigned int dpp_inst,
                bool power_on)
@@ -396,7 +474,7 @@ static void dcn20_dpp_pg_control(
 }
 
 
-static void dcn20_hubp_pg_control(
+void dcn20_hubp_pg_control(
                struct dce_hwseq *hws,
                unsigned int hubp_inst,
                bool power_on)
@@ -473,8 +551,9 @@ static void dcn20_hubp_pg_control(
 /* disable HW used by plane.
  * note:  cannot disable until disconnect is complete
  */
-static void dcn20_plane_atomic_disable(struct dc *dc, struct pipe_ctx *pipe_ctx)
+void dcn20_plane_atomic_disable(struct dc *dc, struct pipe_ctx *pipe_ctx)
 {
+       struct dce_hwseq *hws = dc->hwseq;
        struct hubp *hubp = pipe_ctx->plane_res.hubp;
        struct dpp *dpp = pipe_ctx->plane_res.dpp;
 
@@ -493,9 +572,8 @@ static void dcn20_plane_atomic_disable(struct dc *dc, struct pipe_ctx *pipe_ctx)
        dpp->funcs->dpp_dppclk_control(dpp, false, false);
 
        hubp->power_gated = true;
-       dc->optimized_required = false; /* We're powering off, no need to optimize */
 
-       dc->hwss.plane_atomic_power_down(dc,
+       hws->funcs.plane_atomic_power_down(dc,
                        pipe_ctx->plane_res.dpp,
                        pipe_ctx->plane_res.hubp);
 
@@ -526,6 +604,7 @@ enum dc_status dcn20_enable_stream_timing(
                struct dc_state *context,
                struct dc *dc)
 {
+       struct dce_hwseq *hws = dc->hwseq;
        struct dc_stream_state *stream = pipe_ctx->stream;
        struct drr_params params = {0};
        unsigned int event_triggers = 0;
@@ -585,7 +664,7 @@ enum dc_status dcn20_enable_stream_timing(
                        pipe_ctx->stream_res.opp,
                        true);
 
-       dc->hwss.blank_pixel_data(dc, pipe_ctx, true);
+       hws->funcs.blank_pixel_data(dc, pipe_ctx, true);
 
        /* VTG is  within DCHUB command block. DCFCLK is always on */
        if (false == pipe_ctx->stream_res.tg->funcs->enable_crtc(pipe_ctx->stream_res.tg)) {
@@ -593,7 +672,7 @@ enum dc_status dcn20_enable_stream_timing(
                return DC_ERROR_UNEXPECTED;
        }
 
-       dcn20_hwss_wait_for_blank_complete(pipe_ctx->stream_res.opp);
+       hws->funcs.wait_for_blank_complete(pipe_ctx->stream_res.opp);
 
        params.vertical_total_min = stream->adjust.v_total_min;
        params.vertical_total_max = stream->adjust.v_total_max;
@@ -606,9 +685,13 @@ enum dc_status dcn20_enable_stream_timing(
        // DRR should set trigger event to monitor surface update event
        if (stream->adjust.v_total_min != 0 && stream->adjust.v_total_max != 0)
                event_triggers = 0x80;
+       /* Event triggers and num frames initialized for DRR, but can be
+        * later updated for PSR use. Note DRR trigger events are generated
+        * regardless of whether num frames met.
+        */
        if (pipe_ctx->stream_res.tg->funcs->set_static_screen_control)
                pipe_ctx->stream_res.tg->funcs->set_static_screen_control(
-                               pipe_ctx->stream_res.tg, event_triggers);
+                               pipe_ctx->stream_res.tg, event_triggers, 2);
 
        /* TODO program crtc source select for non-virtual signal*/
        /* TODO program FMT */
@@ -649,7 +732,7 @@ void dcn20_program_output_csc(struct dc *dc,
        }
 }
 
-bool dcn20_set_output_transfer_func(struct pipe_ctx *pipe_ctx,
+bool dcn20_set_output_transfer_func(struct dc *dc, struct pipe_ctx *pipe_ctx,
                                const struct dc_stream_state *stream)
 {
        int mpcc_id = pipe_ctx->plane_res.hubp->inst;
@@ -736,20 +819,14 @@ bool dcn20_set_shaper_3dlut(
        else
                result = dpp_base->funcs->dpp_program_3dlut(dpp_base, NULL);
 
-       if (plane_state->lut3d_func &&
-               plane_state->lut3d_func->state.bits.initialized == 1 &&
-               plane_state->lut3d_func->hdr_multiplier != 0)
-               dpp_base->funcs->dpp_set_hdr_multiplier(dpp_base,
-                               plane_state->lut3d_func->hdr_multiplier);
-       else
-               dpp_base->funcs->dpp_set_hdr_multiplier(dpp_base, 0x1f000);
-
        return result;
 }
 
-bool dcn20_set_input_transfer_func(struct pipe_ctx *pipe_ctx,
-                                         const struct dc_plane_state *plane_state)
+bool dcn20_set_input_transfer_func(struct dc *dc,
+                               struct pipe_ctx *pipe_ctx,
+                               const struct dc_plane_state *plane_state)
 {
+       struct dce_hwseq *hws = dc->hwseq;
        struct dpp *dpp_base = pipe_ctx->plane_res.dpp;
        const struct dc_transfer_func *tf = NULL;
        bool result = true;
@@ -758,8 +835,8 @@ bool dcn20_set_input_transfer_func(struct pipe_ctx *pipe_ctx,
        if (dpp_base == NULL || plane_state == NULL)
                return false;
 
-       dcn20_set_shaper_3dlut(pipe_ctx, plane_state);
-       dcn20_set_blend_lut(pipe_ctx, plane_state);
+       hws->funcs.set_shaper_3dlut(pipe_ctx, plane_state);
+       hws->funcs.set_blend_lut(pipe_ctx, plane_state);
 
        if (plane_state->in_transfer_func)
                tf = plane_state->in_transfer_func;
@@ -804,6 +881,11 @@ bool dcn20_set_input_transfer_func(struct pipe_ctx *pipe_ctx,
                                        IPP_DEGAMMA_MODE_BYPASS);
                        break;
                case TRANSFER_FUNCTION_PQ:
+                       dpp_base->funcs->dpp_set_degamma(dpp_base, IPP_DEGAMMA_MODE_USER_PWL);
+                       cm_helper_translate_curve_to_degamma_hw_format(tf, &dpp_base->degamma_params);
+                       dpp_base->funcs->dpp_program_degamma_pwl(dpp_base, &dpp_base->degamma_params);
+                       result = true;
+                       break;
                default:
                        result = false;
                        break;
@@ -824,7 +906,7 @@ bool dcn20_set_input_transfer_func(struct pipe_ctx *pipe_ctx,
        return result;
 }
 
-static void dcn20_update_odm(struct dc *dc, struct dc_state *context, struct pipe_ctx *pipe_ctx)
+void dcn20_update_odm(struct dc *dc, struct dc_state *context, struct pipe_ctx *pipe_ctx)
 {
        struct pipe_ctx *odm_pipe;
        int opp_cnt = 1;
@@ -855,12 +937,16 @@ void dcn20_blank_pixel_data(
        struct dc_stream_state *stream = pipe_ctx->stream;
        enum dc_color_space color_space = stream->output_color_space;
        enum controller_dp_test_pattern test_pattern = CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR;
+       enum controller_dp_color_space test_pattern_color_space = CONTROLLER_DP_COLOR_SPACE_UDEFINED;
        struct pipe_ctx *odm_pipe;
        int odm_cnt = 1;
 
        int width = stream->timing.h_addressable + stream->timing.h_border_left + stream->timing.h_border_right;
        int height = stream->timing.v_addressable + stream->timing.v_border_bottom + stream->timing.v_border_top;
 
+       if (stream->link->test_pattern_enabled)
+               return;
+
        /* get opp dpg blank color */
        color_space_to_black_color(dc, color_space, &black_color);
 
@@ -873,8 +959,10 @@ void dcn20_blank_pixel_data(
                if (stream_res->abm)
                        stream_res->abm->funcs->set_abm_immediate_disable(stream_res->abm);
 
-               if (dc->debug.visual_confirm != VISUAL_CONFIRM_DISABLE)
+               if (dc->debug.visual_confirm != VISUAL_CONFIRM_DISABLE) {
                        test_pattern = CONTROLLER_DP_TEST_PATTERN_COLORSQUARES;
+                       test_pattern_color_space = CONTROLLER_DP_COLOR_SPACE_RGB;
+               }
        } else {
                test_pattern = CONTROLLER_DP_TEST_PATTERN_VIDEOMODE;
        }
@@ -882,6 +970,7 @@ void dcn20_blank_pixel_data(
        stream_res->opp->funcs->opp_set_disp_pattern_generator(
                        stream_res->opp,
                        test_pattern,
+                       test_pattern_color_space,
                        stream->timing.display_color_depth,
                        &black_color,
                        width,
@@ -892,6 +981,7 @@ void dcn20_blank_pixel_data(
                                odm_pipe->stream_res.opp,
                                dc->debug.visual_confirm != VISUAL_CONFIRM_DISABLE && blank ?
                                                CONTROLLER_DP_TEST_PATTERN_COLORRAMP : test_pattern,
+                               test_pattern_color_space,
                                stream->timing.display_color_depth,
                                &black_color,
                                width,
@@ -998,40 +1088,18 @@ void dcn20_enable_plane(
 //     }
 }
 
-
-void dcn20_pipe_control_lock_global(
-               struct dc *dc,
-               struct pipe_ctx *pipe,
-               bool lock)
-{
-       if (lock) {
-               pipe->stream_res.tg->funcs->lock_doublebuffer_enable(
-                               pipe->stream_res.tg);
-               pipe->stream_res.tg->funcs->lock(pipe->stream_res.tg);
-       } else {
-               pipe->stream_res.tg->funcs->unlock(pipe->stream_res.tg);
-               pipe->stream_res.tg->funcs->wait_for_state(pipe->stream_res.tg,
-                               CRTC_STATE_VACTIVE);
-               pipe->stream_res.tg->funcs->wait_for_state(pipe->stream_res.tg,
-                               CRTC_STATE_VBLANK);
-               pipe->stream_res.tg->funcs->wait_for_state(pipe->stream_res.tg,
-                               CRTC_STATE_VACTIVE);
-               pipe->stream_res.tg->funcs->lock_doublebuffer_disable(
-                               pipe->stream_res.tg);
-       }
-}
-
 void dcn20_pipe_control_lock(
        struct dc *dc,
        struct pipe_ctx *pipe,
        bool lock)
 {
        bool flip_immediate = false;
+       bool dig_update_required = false;
 
        /* use TG master update lock to lock everything on the TG
         * therefore only top pipe need to lock
         */
-       if (pipe->top_pipe)
+       if (!pipe || pipe->top_pipe)
                return;
 
        if (pipe->plane_state != NULL)
@@ -1064,6 +1132,19 @@ void dcn20_pipe_control_lock(
                    (!flip_immediate && pipe->stream_res.gsl_group > 0))
                        dcn20_setup_gsl_group_as_lock(dc, pipe, flip_immediate);
 
+       if (pipe->stream && pipe->stream->update_flags.bits.dsc_changed)
+               dig_update_required = true;
+
+       /* Need double buffer lock mode in order to synchronize front end pipe
+        * updates with dig updates.
+        */
+       if (dig_update_required) {
+               if (lock) {
+                       pipe->stream_res.tg->funcs->lock_doublebuffer_enable(
+                                       pipe->stream_res.tg);
+               }
+       }
+
        if (pipe->plane_state != NULL && pipe->plane_state->triplebuffer_flips) {
                if (lock)
                        pipe->stream_res.tg->funcs->triplebuffer_lock(pipe->stream_res.tg);
@@ -1075,6 +1156,19 @@ void dcn20_pipe_control_lock(
                else
                        pipe->stream_res.tg->funcs->unlock(pipe->stream_res.tg);
        }
+
+       if (dig_update_required) {
+               if (!lock) {
+                       pipe->stream_res.tg->funcs->wait_for_state(pipe->stream_res.tg,
+                                       CRTC_STATE_VACTIVE);
+                       pipe->stream_res.tg->funcs->wait_for_state(pipe->stream_res.tg,
+                                       CRTC_STATE_VBLANK);
+                       pipe->stream_res.tg->funcs->wait_for_state(pipe->stream_res.tg,
+                                       CRTC_STATE_VACTIVE);
+                       pipe->stream_res.tg->funcs->lock_doublebuffer_disable(
+                                       pipe->stream_res.tg);
+               }
+       }
 }
 
 static void dcn20_detect_pipe_changes(struct pipe_ctx *old_pipe, struct pipe_ctx *new_pipe)
@@ -1217,9 +1311,11 @@ static void dcn20_update_dchubp_dpp(
        struct pipe_ctx *pipe_ctx,
        struct dc_state *context)
 {
+       struct dce_hwseq *hws = dc->hwseq;
        struct hubp *hubp = pipe_ctx->plane_res.hubp;
        struct dpp *dpp = pipe_ctx->plane_res.dpp;
        struct dc_plane_state *plane_state = pipe_ctx->plane_state;
+       bool viewport_changed = false;
 
        if (pipe_ctx->update_flags.bits.dppclk)
                dpp->funcs->dpp_dppclk_control(dpp, false, true);
@@ -1261,7 +1357,7 @@ static void dcn20_update_dchubp_dpp(
 
                if (dpp->funcs->dpp_program_bias_and_scale) {
                        //TODO :for CNVC set scale and bias registers if necessary
-                       dcn10_build_prescale_params(&bns_params, plane_state);
+                       build_prescale_params(&bns_params, plane_state);
                        dpp->funcs->dpp_program_bias_and_scale(dpp, &bns_params);
                }
        }
@@ -1269,19 +1365,19 @@ static void dcn20_update_dchubp_dpp(
        if (pipe_ctx->update_flags.bits.mpcc
                        || plane_state->update_flags.bits.global_alpha_change
                        || plane_state->update_flags.bits.per_pixel_alpha_change) {
-               /* Need mpcc to be idle if changing opp */
-               if (pipe_ctx->update_flags.bits.opp_changed) {
-                       struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[pipe_ctx->pipe_idx];
-                       int mpcc_inst;
-
-                       for (mpcc_inst = 0; mpcc_inst < MAX_PIPES; mpcc_inst++) {
-                               if (!old_pipe_ctx->stream_res.opp->mpcc_disconnect_pending[mpcc_inst])
-                                       continue;
+               // MPCC inst is equal to pipe index in practice
+               int mpcc_inst = hubp->inst;
+               int opp_inst;
+               int opp_count = dc->res_pool->pipe_count;
+
+               for (opp_inst = 0; opp_inst < opp_count; opp_inst++) {
+                       if (dc->res_pool->opps[opp_inst]->mpcc_disconnect_pending[mpcc_inst]) {
                                dc->res_pool->mpc->funcs->wait_for_idle(dc->res_pool->mpc, mpcc_inst);
-                               old_pipe_ctx->stream_res.opp->mpcc_disconnect_pending[mpcc_inst] = false;
+                               dc->res_pool->opps[opp_inst]->mpcc_disconnect_pending[mpcc_inst] = false;
+                               break;
                        }
                }
-               dc->hwss.update_mpcc(dc, pipe_ctx);
+               hws->funcs.update_mpcc(dc, pipe_ctx);
        }
 
        if (pipe_ctx->update_flags.bits.scaler ||
@@ -1298,14 +1394,18 @@ static void dcn20_update_dchubp_dpp(
 
        if (pipe_ctx->update_flags.bits.viewport ||
                        (context == dc->current_state && plane_state->update_flags.bits.scaling_change) ||
-                       (context == dc->current_state && pipe_ctx->stream->update_flags.bits.scaling))
+                       (context == dc->current_state && pipe_ctx->stream->update_flags.bits.scaling)) {
+
                hubp->funcs->mem_program_viewport(
                        hubp,
                        &pipe_ctx->plane_res.scl_data.viewport,
                        &pipe_ctx->plane_res.scl_data.viewport_c);
+               viewport_changed = true;
+       }
 
        /* Any updates are handled in dc interface, just need to apply existing for plane enable */
-       if ((pipe_ctx->update_flags.bits.enable || pipe_ctx->update_flags.bits.opp_changed)
+       if ((pipe_ctx->update_flags.bits.enable || pipe_ctx->update_flags.bits.opp_changed ||
+                       pipe_ctx->update_flags.bits.scaler || pipe_ctx->update_flags.bits.viewport)
                        && pipe_ctx->stream->cursor_attributes.address.quad_part != 0) {
                dc->hwss.set_cursor_position(pipe_ctx);
                dc->hwss.set_cursor_attribute(pipe_ctx);
@@ -1355,8 +1455,13 @@ static void dcn20_update_dchubp_dpp(
                hubp->power_gated = false;
        }
 
+       if (hubp->funcs->apply_PLAT_54186_wa && viewport_changed)
+               hubp->funcs->apply_PLAT_54186_wa(hubp, &plane_state->address);
+
        if (pipe_ctx->update_flags.bits.enable || plane_state->update_flags.bits.addr_update)
-               dc->hwss.update_plane_addr(dc, pipe_ctx);
+               hws->funcs.update_plane_addr(dc, pipe_ctx);
+
+
 
        if (pipe_ctx->update_flags.bits.enable)
                hubp->funcs->set_blank(hubp, false);
@@ -1368,10 +1473,11 @@ static void dcn20_program_pipe(
                struct pipe_ctx *pipe_ctx,
                struct dc_state *context)
 {
+       struct dce_hwseq *hws = dc->hwseq;
        /* Only need to unblank on top pipe */
        if ((pipe_ctx->update_flags.bits.enable || pipe_ctx->stream->update_flags.bits.abm_level)
                        && !pipe_ctx->top_pipe && !pipe_ctx->prev_odm_pipe)
-               dc->hwss.blank_pixel_data(dc, pipe_ctx, !pipe_ctx->plane_state->visible);
+               hws->funcs.blank_pixel_data(dc, pipe_ctx, !pipe_ctx->plane_state->visible);
 
        if (pipe_ctx->update_flags.bits.global_sync) {
                pipe_ctx->stream_res.tg->funcs->program_global_sync(
@@ -1384,12 +1490,12 @@ static void dcn20_program_pipe(
                pipe_ctx->stream_res.tg->funcs->set_vtg_params(
                                pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing);
 
-               if (dc->hwss.setup_vupdate_interrupt)
-                       dc->hwss.setup_vupdate_interrupt(pipe_ctx);
+               if (hws->funcs.setup_vupdate_interrupt)
+                       hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx);
        }
 
        if (pipe_ctx->update_flags.bits.odm)
-               dc->hwss.update_odm(dc, context, pipe_ctx);
+               hws->funcs.update_odm(dc, context, pipe_ctx);
 
        if (pipe_ctx->update_flags.bits.enable)
                dcn20_enable_plane(dc, pipe_ctx, context);
@@ -1398,20 +1504,20 @@ static void dcn20_program_pipe(
                dcn20_update_dchubp_dpp(dc, pipe_ctx, context);
 
        if (pipe_ctx->update_flags.bits.enable
-                       || pipe_ctx->plane_state->update_flags.bits.sdr_white_level)
-               set_hdr_multiplier(pipe_ctx);
+                       || pipe_ctx->plane_state->update_flags.bits.hdr_mult)
+               hws->funcs.set_hdr_multiplier(pipe_ctx);
 
        if (pipe_ctx->update_flags.bits.enable ||
                        pipe_ctx->plane_state->update_flags.bits.in_transfer_func_change ||
                        pipe_ctx->plane_state->update_flags.bits.gamma_change)
-               dc->hwss.set_input_transfer_func(pipe_ctx, pipe_ctx->plane_state);
+               hws->funcs.set_input_transfer_func(dc, pipe_ctx, pipe_ctx->plane_state);
 
        /* dcn10_translate_regamma_to_hw_format takes 750us to finish
         * only do gamma programming for powering on, internal memcmp to avoid
         * updating on slave planes
         */
        if (pipe_ctx->update_flags.bits.enable || pipe_ctx->stream->update_flags.bits.out_tf)
-               dc->hwss.set_output_transfer_func(pipe_ctx, pipe_ctx->stream);
+               hws->funcs.set_output_transfer_func(dc, pipe_ctx, pipe_ctx->stream);
 
        /* If the pipe has been enabled or has a different opp, we
         * should reprogram the fmt. This deals with cases where
@@ -1434,47 +1540,32 @@ static void dcn20_program_pipe(
        }
 }
 
-static bool does_pipe_need_lock(struct pipe_ctx *pipe)
-{
-       if ((pipe->plane_state && pipe->plane_state->update_flags.raw)
-                       || pipe->update_flags.raw)
-               return true;
-       if (pipe->bottom_pipe)
-               return does_pipe_need_lock(pipe->bottom_pipe);
-
-       return false;
-}
-
-static void dcn20_program_front_end_for_ctx(
+void dcn20_program_front_end_for_ctx(
                struct dc *dc,
                struct dc_state *context)
 {
-       const unsigned int TIMEOUT_FOR_PIPE_ENABLE_MS = 100;
        int i;
-       bool pipe_locked[MAX_PIPES] = {false};
+       struct dce_hwseq *hws = dc->hwseq;
        DC_LOGGER_INIT(dc->ctx->logger);
 
-       /* Carry over GSL groups in case the context is changing. */
-       for (i = 0; i < dc->res_pool->pipe_count; i++)
-               if (context->res_ctx.pipe_ctx[i].stream == dc->current_state->res_ctx.pipe_ctx[i].stream)
-                       context->res_ctx.pipe_ctx[i].stream_res.gsl_group =
-                               dc->current_state->res_ctx.pipe_ctx[i].stream_res.gsl_group;
+       for (i = 0; i < dc->res_pool->pipe_count; i++) {
+               struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
+
+               if (!pipe_ctx->top_pipe && !pipe_ctx->prev_odm_pipe && pipe_ctx->plane_state) {
+                       ASSERT(!pipe_ctx->plane_state->triplebuffer_flips);
+                       if (dc->hwss.program_triplebuffer != NULL &&
+                               !dc->debug.disable_tri_buf) {
+                               /*turn off triple buffer for full update*/
+                               dc->hwss.program_triplebuffer(
+                                       dc, pipe_ctx, pipe_ctx->plane_state->triplebuffer_flips);
+                       }
+               }
+       }
 
        /* Set pipe update flags and lock pipes */
        for (i = 0; i < dc->res_pool->pipe_count; i++)
                dcn20_detect_pipe_changes(&dc->current_state->res_ctx.pipe_ctx[i],
                                &context->res_ctx.pipe_ctx[i]);
-       for (i = 0; i < dc->res_pool->pipe_count; i++)
-               if (!context->res_ctx.pipe_ctx[i].top_pipe &&
-                               does_pipe_need_lock(&context->res_ctx.pipe_ctx[i])) {
-                       struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
-
-                       if (pipe_ctx->update_flags.bits.tg_changed || pipe_ctx->update_flags.bits.enable)
-                               dc->hwss.pipe_control_lock(dc, pipe_ctx, true);
-                       if (!pipe_ctx->update_flags.bits.enable)
-                               dc->hwss.pipe_control_lock(dc, &dc->current_state->res_ctx.pipe_ctx[i], true);
-                       pipe_locked[i] = true;
-               }
 
        /* OTG blank before disabling all front ends */
        for (i = 0; i < dc->res_pool->pipe_count; i++)
@@ -1482,13 +1573,13 @@ static void dcn20_program_front_end_for_ctx(
                                && !context->res_ctx.pipe_ctx[i].top_pipe
                                && !context->res_ctx.pipe_ctx[i].prev_odm_pipe
                                && context->res_ctx.pipe_ctx[i].stream)
-                       dc->hwss.blank_pixel_data(dc, &context->res_ctx.pipe_ctx[i], true);
+                       hws->funcs.blank_pixel_data(dc, &context->res_ctx.pipe_ctx[i], true);
 
        /* Disconnect mpcc */
        for (i = 0; i < dc->res_pool->pipe_count; i++)
                if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable
                                || context->res_ctx.pipe_ctx[i].update_flags.bits.opp_changed) {
-                       dc->hwss.plane_atomic_disconnect(dc, &dc->current_state->res_ctx.pipe_ctx[i]);
+                       hws->funcs.plane_atomic_disconnect(dc, &dc->current_state->res_ctx.pipe_ctx[i]);
                        DC_LOG_DC("Reset mpcc for pipe %d\n", dc->current_state->res_ctx.pipe_ctx[i].pipe_idx);
                }
 
@@ -1508,21 +1599,20 @@ static void dcn20_program_front_end_for_ctx(
                        pipe = &context->res_ctx.pipe_ctx[i];
                        if (!pipe->prev_odm_pipe && pipe->stream->num_wb_info > 0
                                        && (pipe->update_flags.raw || pipe->plane_state->update_flags.raw || pipe->stream->update_flags.raw)
-                                       && dc->hwss.program_all_writeback_pipes_in_tree)
-                               dc->hwss.program_all_writeback_pipes_in_tree(dc, pipe->stream, context);
+                                       && hws->funcs.program_all_writeback_pipes_in_tree)
+                               hws->funcs.program_all_writeback_pipes_in_tree(dc, pipe->stream, context);
                }
        }
+}
 
-       /* Unlock all locked pipes */
-       for (i = 0; i < dc->res_pool->pipe_count; i++)
-               if (pipe_locked[i]) {
-                       struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
+void dcn20_post_unlock_program_front_end(
+               struct dc *dc,
+               struct dc_state *context)
+{
+       int i;
+       const unsigned int TIMEOUT_FOR_PIPE_ENABLE_MS = 100;
 
-                       if (pipe_ctx->update_flags.bits.tg_changed || pipe_ctx->update_flags.bits.enable)
-                               dc->hwss.pipe_control_lock(dc, pipe_ctx, false);
-                       if (!pipe_ctx->update_flags.bits.enable)
-                               dc->hwss.pipe_control_lock(dc, &dc->current_state->res_ctx.pipe_ctx[i], false);
-               }
+       DC_LOGGER_INIT(dc->ctx->logger);
 
        for (i = 0; i < dc->res_pool->pipe_count; i++)
                if (context->res_ctx.pipe_ctx[i].update_flags.bits.disable)
@@ -1541,9 +1631,9 @@ static void dcn20_program_front_end_for_ctx(
                        struct hubp *hubp = pipe->plane_res.hubp;
                        int j = 0;
 
-                       for (j = 0; j < TIMEOUT_FOR_PIPE_ENABLE_MS
+                       for (j = 0; j < TIMEOUT_FOR_PIPE_ENABLE_MS*1000
                                        && hubp->funcs->hubp_is_flip_pending(hubp); j++)
-                               msleep(1);
+                               mdelay(1);
                }
        }
 
@@ -1552,7 +1642,6 @@ static void dcn20_program_front_end_for_ctx(
                dc->res_pool->hubbub->funcs->apply_DEDCN21_147_wa(dc->res_pool->hubbub);
 }
 
-
 void dcn20_prepare_bandwidth(
                struct dc *dc,
                struct dc_state *context)
@@ -1594,6 +1683,7 @@ bool dcn20_update_bandwidth(
                struct dc_state *context)
 {
        int i;
+       struct dce_hwseq *hws = dc->hwseq;
 
        /* recalculate DML parameters */
        if (!dc->res_pool->funcs->validate_bandwidth(dc, context, false))
@@ -1623,10 +1713,10 @@ bool dcn20_update_bandwidth(
                                        pipe_ctx->stream_res.tg, &pipe_ctx->stream->timing);
 
                        if (pipe_ctx->prev_odm_pipe == NULL)
-                               dc->hwss.blank_pixel_data(dc, pipe_ctx, blank);
+                               hws->funcs.blank_pixel_data(dc, pipe_ctx, blank);
 
-                       if (dc->hwss.setup_vupdate_interrupt)
-                               dc->hwss.setup_vupdate_interrupt(pipe_ctx);
+                       if (hws->funcs.setup_vupdate_interrupt)
+                               hws->funcs.setup_vupdate_interrupt(dc, pipe_ctx);
                }
 
                pipe_ctx->plane_res.hubp->funcs->hubp_setup(
@@ -1640,9 +1730,8 @@ bool dcn20_update_bandwidth(
        return true;
 }
 
-static void dcn20_enable_writeback(
+void dcn20_enable_writeback(
                struct dc *dc,
-               const struct dc_stream_status *stream_status,
                struct dc_writeback_info *wb_info,
                struct dc_state *context)
 {
@@ -1656,8 +1745,7 @@ static void dcn20_enable_writeback(
        mcif_wb = dc->res_pool->mcif_wb[wb_info->dwb_pipe_inst];
 
        /* set the OPTC source mux */
-       ASSERT(stream_status->primary_otg_inst < MAX_PIPES);
-       optc = dc->res_pool->timing_generators[stream_status->primary_otg_inst];
+       optc = dc->res_pool->timing_generators[dwb->otg_inst];
        optc->funcs->set_dwb_source(optc, wb_info->dwb_pipe_inst);
        /* set MCIF_WB buffer and arbitration configuration */
        mcif_wb->funcs->config_mcif_buf(mcif_wb, &wb_info->mcif_buf_params, wb_info->dwb_params.dest_height);
@@ -1684,7 +1772,7 @@ void dcn20_disable_writeback(
        mcif_wb->funcs->disable_mcif(mcif_wb);
 }
 
-bool dcn20_hwss_wait_for_blank_complete(
+bool dcn20_wait_for_blank_complete(
                struct output_pixel_processor *opp)
 {
        int counter;
@@ -1713,9 +1801,8 @@ bool dcn20_dmdata_status_done(struct pipe_ctx *pipe_ctx)
        return hubp->funcs->dmdata_status_done(hubp);
 }
 
-static void dcn20_disable_stream_gating(struct dc *dc, struct pipe_ctx *pipe_ctx)
+void dcn20_disable_stream_gating(struct dc *dc, struct pipe_ctx *pipe_ctx)
 {
-#ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
        struct dce_hwseq *hws = dc->hwseq;
 
        if (pipe_ctx->stream_res.dsc) {
@@ -1727,12 +1814,10 @@ static void dcn20_disable_stream_gating(struct dc *dc, struct pipe_ctx *pipe_ctx
                        odm_pipe = odm_pipe->next_odm_pipe;
                }
        }
-#endif
 }
 
-static void dcn20_enable_stream_gating(struct dc *dc, struct pipe_ctx *pipe_ctx)
+void dcn20_enable_stream_gating(struct dc *dc, struct pipe_ctx *pipe_ctx)
 {
-#ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
        struct dce_hwseq *hws = dc->hwseq;
 
        if (pipe_ctx->stream_res.dsc) {
@@ -1744,7 +1829,6 @@ static void dcn20_enable_stream_gating(struct dc *dc, struct pipe_ctx *pipe_ctx)
                        odm_pipe = odm_pipe->next_odm_pipe;
                }
        }
-#endif
 }
 
 void dcn20_set_dmdata_attributes(struct pipe_ctx *pipe_ctx)
@@ -1767,12 +1851,7 @@ void dcn20_set_dmdata_attributes(struct pipe_ctx *pipe_ctx)
        hubp->funcs->dmdata_set_attributes(hubp, &attr);
 }
 
-void dcn20_disable_stream(struct pipe_ctx *pipe_ctx)
-{
-       dce110_disable_stream(pipe_ctx);
-}
-
-static void dcn20_init_vm_ctx(
+void dcn20_init_vm_ctx(
                struct dce_hwseq *hws,
                struct dc *dc,
                struct dc_virtual_addr_space_config *va_config,
@@ -1794,7 +1873,7 @@ static void dcn20_init_vm_ctx(
        dc->res_pool->hubbub->funcs->init_vm_ctx(dc->res_pool->hubbub, &config, vmid);
 }
 
-static int dcn20_init_sys_ctx(struct dce_hwseq *hws, struct dc *dc, struct dc_phy_addr_space_config *pa_config)
+int dcn20_init_sys_ctx(struct dce_hwseq *hws, struct dc *dc, struct dc_phy_addr_space_config *pa_config)
 {
        struct dcn_hubbub_phys_addr_config config;
 
@@ -1838,8 +1917,7 @@ static bool patch_address_for_sbs_tb_stereo(
        return false;
 }
 
-
-static void dcn20_update_plane_addr(const struct dc *dc, struct pipe_ctx *pipe_ctx)
+void dcn20_update_plane_addr(const struct dc *dc, struct pipe_ctx *pipe_ctx)
 {
        bool addr_patched = false;
        PHYSICAL_ADDRESS_LOC addr;
@@ -1873,6 +1951,7 @@ void dcn20_unblank_stream(struct pipe_ctx *pipe_ctx,
        struct encoder_unblank_param params = { { 0 } };
        struct dc_stream_state *stream = pipe_ctx->stream;
        struct dc_link *link = stream->link;
+       struct dce_hwseq *hws = link->dc->hwseq;
        struct pipe_ctx *odm_pipe;
 
        params.opp_cnt = 1;
@@ -1885,7 +1964,7 @@ void dcn20_unblank_stream(struct pipe_ctx *pipe_ctx,
        params.link_settings.link_rate = link_settings->link_rate;
 
        if (dc_is_dp_signal(pipe_ctx->stream->signal)) {
-               if (optc1_is_two_pixels_per_containter(&stream->timing) || params.opp_cnt > 1)
+               if (optc2_is_two_pixels_per_containter(&stream->timing) || params.opp_cnt > 1)
                        params.timing.pix_clk_100hz /= 2;
                pipe_ctx->stream_res.stream_enc->funcs->dp_set_odm_combine(
                                pipe_ctx->stream_res.stream_enc, params.opp_cnt > 1);
@@ -1893,14 +1972,14 @@ void dcn20_unblank_stream(struct pipe_ctx *pipe_ctx,
        }
 
        if (link->local_sink && link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
-               link->dc->hwss.edp_backlight_control(link, true);
+               hws->funcs.edp_backlight_control(link, true);
        }
 }
 
-void dcn20_setup_vupdate_interrupt(struct pipe_ctx *pipe_ctx)
+void dcn20_setup_vupdate_interrupt(struct dc *dc, struct pipe_ctx *pipe_ctx)
 {
        struct timing_generator *tg = pipe_ctx->stream_res.tg;
-       int start_line = get_vupdate_offset_from_vsync(pipe_ctx);
+       int start_line = dc->hwss.get_vupdate_offset_from_vsync(pipe_ctx);
 
        if (start_line < 0)
                start_line = 0;
@@ -1915,6 +1994,7 @@ static void dcn20_reset_back_end_for_pipe(
                struct dc_state *context)
 {
        int i;
+       struct dc_link *link;
        DC_LOGGER_INIT(dc->ctx->logger);
        if (pipe_ctx->stream_res.stream_enc == NULL) {
                pipe_ctx->stream = NULL;
@@ -1922,8 +2002,14 @@ static void dcn20_reset_back_end_for_pipe(
        }
 
        if (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
-               /* DPMS may already disable */
-               if (!pipe_ctx->stream->dpms_off)
+               link = pipe_ctx->stream->link;
+               /* DPMS may already disable or */
+               /* dpms_off status is incorrect due to fastboot
+                * feature. When system resume from S4 with second
+                * screen only, the dpms_off would be true but
+                * VBIOS lit up eDP, so check link status too.
+                */
+               if (!pipe_ctx->stream->dpms_off || link->link_status.link_active)
                        core_link_disable_stream(pipe_ctx);
                else if (pipe_ctx->stream_res.audio)
                        dc->hwss.disable_audio_stream(pipe_ctx);
@@ -1943,11 +2029,9 @@ static void dcn20_reset_back_end_for_pipe(
                        }
                }
        }
-#ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
        else if (pipe_ctx->stream_res.dsc) {
                dp_set_dsc_enable(pipe_ctx, false);
        }
-#endif
 
        /* by upper caller loop, parent pipe: pipe0, will be reset last.
         * back end share by all pipes and will be disable only when disable
@@ -1978,11 +2062,12 @@ static void dcn20_reset_back_end_for_pipe(
                                        pipe_ctx->pipe_idx, pipe_ctx->stream_res.tg->inst);
 }
 
-static void dcn20_reset_hw_ctx_wrap(
+void dcn20_reset_hw_ctx_wrap(
                struct dc *dc,
                struct dc_state *context)
 {
        int i;
+       struct dce_hwseq *hws = dc->hwseq;
 
        /* Reset Back End*/
        for (i = dc->res_pool->pipe_count - 1; i >= 0 ; i--) {
@@ -2001,8 +2086,8 @@ static void dcn20_reset_hw_ctx_wrap(
                        struct clock_source *old_clk = pipe_ctx_old->clock_source;
 
                        dcn20_reset_back_end_for_pipe(dc, pipe_ctx_old, dc->current_state);
-                       if (dc->hwss.enable_stream_gating)
-                               dc->hwss.enable_stream_gating(dc, pipe_ctx);
+                       if (hws->funcs.enable_stream_gating)
+                               hws->funcs.enable_stream_gating(dc, pipe_ctx);
                        if (old_clk)
                                old_clk->funcs->cs_power_down(old_clk);
                }
@@ -2031,8 +2116,9 @@ void dcn20_get_mpctree_visual_confirm_color(
        *color = pipe_colors[top_pipe->pipe_idx];
 }
 
-static void dcn20_update_mpcc(struct dc *dc, struct pipe_ctx *pipe_ctx)
+void dcn20_update_mpcc(struct dc *dc, struct pipe_ctx *pipe_ctx)
 {
+       struct dce_hwseq *hws = dc->hwseq;
        struct hubp *hubp = pipe_ctx->plane_res.hubp;
        struct mpcc_blnd_cfg blnd_cfg = { {0} };
        bool per_pixel_alpha = pipe_ctx->plane_state->per_pixel_alpha;
@@ -2043,10 +2129,10 @@ static void dcn20_update_mpcc(struct dc *dc, struct pipe_ctx *pipe_ctx)
 
        // input to MPCC is always RGB, by default leave black_color at 0
        if (dc->debug.visual_confirm == VISUAL_CONFIRM_HDR) {
-               dcn10_get_hdr_visual_confirm_color(
+               hws->funcs.get_hdr_visual_confirm_color(
                                pipe_ctx, &blnd_cfg.black_color);
        } else if (dc->debug.visual_confirm == VISUAL_CONFIRM_SURFACE) {
-               dcn10_get_surface_visual_confirm_color(
+               hws->funcs.get_surface_visual_confirm_color(
                                pipe_ctx, &blnd_cfg.black_color);
        } else if (dc->debug.visual_confirm == VISUAL_CONFIRM_MPCTREE) {
                dcn20_get_mpctree_visual_confirm_color(
@@ -2083,12 +2169,6 @@ static void dcn20_update_mpcc(struct dc *dc, struct pipe_ctx *pipe_ctx)
         */
        mpcc_id = hubp->inst;
 
-       /* If there is no full update, don't need to touch MPC tree*/
-       if (!pipe_ctx->plane_state->update_flags.bits.full_update) {
-               mpc->funcs->update_blending(mpc, &blnd_cfg, mpcc_id);
-               return;
-       }
-
        /* check if this MPCC is already being used */
        new_mpcc = mpc->funcs->get_mpcc_for_dpp(mpc_tree_params, mpcc_id);
        /* remove MPCC if being used */
@@ -2113,125 +2193,7 @@ static void dcn20_update_mpcc(struct dc *dc, struct pipe_ctx *pipe_ctx)
        hubp->mpcc_id = mpcc_id;
 }
 
-static int find_free_gsl_group(const struct dc *dc)
-{
-       if (dc->res_pool->gsl_groups.gsl_0 == 0)
-               return 1;
-       if (dc->res_pool->gsl_groups.gsl_1 == 0)
-               return 2;
-       if (dc->res_pool->gsl_groups.gsl_2 == 0)
-               return 3;
-
-       return 0;
-}
-
-/* NOTE: This is not a generic setup_gsl function (hence the suffix as_lock)
- * This is only used to lock pipes in pipe splitting case with immediate flip
- * Ordinary MPC/OTG locks suppress VUPDATE which doesn't help with immediate,
- * so we get tearing with freesync since we cannot flip multiple pipes
- * atomically.
- * We use GSL for this:
- * - immediate flip: find first available GSL group if not already assigned
- *                   program gsl with that group, set current OTG as master
- *                   and always us 0x4 = AND of flip_ready from all pipes
- * - vsync flip: disable GSL if used
- *
- * Groups in stream_res are stored as +1 from HW registers, i.e.
- * gsl_0 <=> pipe_ctx->stream_res.gsl_group == 1
- * Using a magic value like -1 would require tracking all inits/resets
- */
-void dcn20_setup_gsl_group_as_lock(
-               const struct dc *dc,
-               struct pipe_ctx *pipe_ctx,
-               bool enable)
-{
-       struct gsl_params gsl;
-       int group_idx;
-
-       memset(&gsl, 0, sizeof(struct gsl_params));
-
-       if (enable) {
-               /* return if group already assigned since GSL was set up
-                * for vsync flip, we would unassign so it can't be "left over"
-                */
-               if (pipe_ctx->stream_res.gsl_group > 0)
-                       return;
-
-               group_idx = find_free_gsl_group(dc);
-               ASSERT(group_idx != 0);
-               pipe_ctx->stream_res.gsl_group = group_idx;
-
-               /* set gsl group reg field and mark resource used */
-               switch (group_idx) {
-               case 1:
-                       gsl.gsl0_en = 1;
-                       dc->res_pool->gsl_groups.gsl_0 = 1;
-                       break;
-               case 2:
-                       gsl.gsl1_en = 1;
-                       dc->res_pool->gsl_groups.gsl_1 = 1;
-                       break;
-               case 3:
-                       gsl.gsl2_en = 1;
-                       dc->res_pool->gsl_groups.gsl_2 = 1;
-                       break;
-               default:
-                       BREAK_TO_DEBUGGER();
-                       return; // invalid case
-               }
-               gsl.gsl_master_en = 1;
-       } else {
-               group_idx = pipe_ctx->stream_res.gsl_group;
-               if (group_idx == 0)
-                       return; // if not in use, just return
-
-               pipe_ctx->stream_res.gsl_group = 0;
-
-               /* unset gsl group reg field and mark resource free */
-               switch (group_idx) {
-               case 1:
-                       gsl.gsl0_en = 0;
-                       dc->res_pool->gsl_groups.gsl_0 = 0;
-                       break;
-               case 2:
-                       gsl.gsl1_en = 0;
-                       dc->res_pool->gsl_groups.gsl_1 = 0;
-                       break;
-               case 3:
-                       gsl.gsl2_en = 0;
-                       dc->res_pool->gsl_groups.gsl_2 = 0;
-                       break;
-               default:
-                       BREAK_TO_DEBUGGER();
-                       return;
-               }
-               gsl.gsl_master_en = 0;
-       }
-
-       /* at this point we want to program whether it's to enable or disable */
-       if (pipe_ctx->stream_res.tg->funcs->set_gsl != NULL &&
-               pipe_ctx->stream_res.tg->funcs->set_gsl_source_select != NULL) {
-               pipe_ctx->stream_res.tg->funcs->set_gsl(
-                       pipe_ctx->stream_res.tg,
-                       &gsl);
-
-               pipe_ctx->stream_res.tg->funcs->set_gsl_source_select(
-                       pipe_ctx->stream_res.tg, group_idx,     enable ? 4 : 0);
-       } else
-               BREAK_TO_DEBUGGER();
-}
-
-static void dcn20_set_flip_control_gsl(
-               struct pipe_ctx *pipe_ctx,
-               bool flip_immediate)
-{
-       if (pipe_ctx && pipe_ctx->plane_res.hubp->funcs->hubp_set_flip_control_surface_gsl)
-               pipe_ctx->plane_res.hubp->funcs->hubp_set_flip_control_surface_gsl(
-                               pipe_ctx->plane_res.hubp, flip_immediate);
-
-}
-
-static void dcn20_enable_stream(struct pipe_ctx *pipe_ctx)
+void dcn20_enable_stream(struct pipe_ctx *pipe_ctx)
 {
        enum dc_lane_count lane_count =
                pipe_ctx->stream->link->cur_link_settings.lane_count;
@@ -2279,7 +2241,7 @@ static void dcn20_enable_stream(struct pipe_ctx *pipe_ctx)
        }
 }
 
-static void dcn20_program_dmdata_engine(struct pipe_ctx *pipe_ctx)
+void dcn20_program_dmdata_engine(struct pipe_ctx *pipe_ctx)
 {
        struct dc_stream_state    *stream     = pipe_ctx->stream;
        struct hubp               *hubp       = pipe_ctx->plane_res.hubp;
@@ -2305,7 +2267,7 @@ static void dcn20_program_dmdata_engine(struct pipe_ctx *pipe_ctx)
                                                hubp->inst, mode);
 }
 
-static void dcn20_fpga_init_hw(struct dc *dc)
+void dcn20_fpga_init_hw(struct dc *dc)
 {
        int i, j;
        struct dce_hwseq *hws = dc->hwseq;
@@ -2320,13 +2282,13 @@ static void dcn20_fpga_init_hw(struct dc *dc)
                res_pool->dccg->funcs->dccg_init(res_pool->dccg);
 
        //Enable ability to power gate / don't force power on permanently
-       dc->hwss.enable_power_gating_plane(hws, true);
+       hws->funcs.enable_power_gating_plane(hws, true);
 
        // Specific to FPGA dccg and registers
        REG_WRITE(RBBMIF_TIMEOUT_DIS, 0xFFFFFFFF);
        REG_WRITE(RBBMIF_TIMEOUT_DIS_2, 0xFFFFFFFF);
 
-       dcn20_dccg_init(hws);
+       hws->funcs.dccg_init(hws);
 
        REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_REFDIV, 2);
        REG_UPDATE(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_ENABLE, 1);
@@ -2390,7 +2352,7 @@ static void dcn20_fpga_init_hw(struct dc *dc)
                dc->res_pool->opps[i]->mpcc_disconnect_pending[pipe_ctx->plane_res.mpcc_inst] = true;
                pipe_ctx->stream_res.opp = dc->res_pool->opps[i];
                /*to do*/
-               hwss1_plane_atomic_disconnect(dc, pipe_ctx);
+               hws->funcs.plane_atomic_disconnect(dc, pipe_ctx);
        }
 
        /* initialize DWB pointer to MCIF_WB */
@@ -2419,57 +2381,3 @@ static void dcn20_fpga_init_hw(struct dc *dc)
                tg->funcs->tg_init(tg);
        }
 }
-
-void dcn20_hw_sequencer_construct(struct dc *dc)
-{
-       dcn10_hw_sequencer_construct(dc);
-       dc->hwss.unblank_stream = dcn20_unblank_stream;
-       dc->hwss.update_plane_addr = dcn20_update_plane_addr;
-       dc->hwss.enable_stream_timing = dcn20_enable_stream_timing;
-       dc->hwss.program_triplebuffer = dcn20_program_tripleBuffer;
-       dc->hwss.set_input_transfer_func = dcn20_set_input_transfer_func;
-       dc->hwss.set_output_transfer_func = dcn20_set_output_transfer_func;
-       dc->hwss.apply_ctx_for_surface = NULL;
-       dc->hwss.program_front_end_for_ctx = dcn20_program_front_end_for_ctx;
-       dc->hwss.pipe_control_lock = dcn20_pipe_control_lock;
-       dc->hwss.pipe_control_lock_global = dcn20_pipe_control_lock_global;
-       dc->hwss.optimize_bandwidth = dcn20_optimize_bandwidth;
-       dc->hwss.prepare_bandwidth = dcn20_prepare_bandwidth;
-       dc->hwss.update_bandwidth = dcn20_update_bandwidth;
-       dc->hwss.enable_writeback = dcn20_enable_writeback;
-       dc->hwss.disable_writeback = dcn20_disable_writeback;
-       dc->hwss.program_output_csc = dcn20_program_output_csc;
-       dc->hwss.update_odm = dcn20_update_odm;
-       dc->hwss.blank_pixel_data = dcn20_blank_pixel_data;
-       dc->hwss.dmdata_status_done = dcn20_dmdata_status_done;
-       dc->hwss.program_dmdata_engine = dcn20_program_dmdata_engine;
-       dc->hwss.enable_stream = dcn20_enable_stream;
-       dc->hwss.disable_stream = dcn20_disable_stream;
-       dc->hwss.init_sys_ctx = dcn20_init_sys_ctx;
-       dc->hwss.init_vm_ctx = dcn20_init_vm_ctx;
-       dc->hwss.disable_stream_gating = dcn20_disable_stream_gating;
-       dc->hwss.enable_stream_gating = dcn20_enable_stream_gating;
-       dc->hwss.setup_vupdate_interrupt = dcn20_setup_vupdate_interrupt;
-       dc->hwss.reset_hw_ctx_wrap = dcn20_reset_hw_ctx_wrap;
-       dc->hwss.update_mpcc = dcn20_update_mpcc;
-       dc->hwss.set_flip_control_gsl = dcn20_set_flip_control_gsl;
-       dc->hwss.init_blank = dcn20_init_blank;
-       dc->hwss.disable_plane = dcn20_disable_plane;
-       dc->hwss.plane_atomic_disable = dcn20_plane_atomic_disable;
-       dc->hwss.enable_power_gating_plane = dcn20_enable_power_gating_plane;
-       dc->hwss.dpp_pg_control = dcn20_dpp_pg_control;
-       dc->hwss.hubp_pg_control = dcn20_hubp_pg_control;
-#ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
-       dc->hwss.dsc_pg_control = dcn20_dsc_pg_control;
-#else
-       dc->hwss.dsc_pg_control = NULL;
-#endif
-       dc->hwss.disable_vga = dcn20_disable_vga;
-
-       if (IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment)) {
-               dc->hwss.init_hw = dcn20_fpga_init_hw;
-               dc->hwss.init_pipes = NULL;
-       }
-
-
-}