Skip to content

Commit

Permalink
drm/amd/display: Introduce DML2
Browse files Browse the repository at this point in the history
DC is transitioning from DML to DML2, and this commit introduces all the
required changes for some of the already available ASICs and adds the
required code infra to support new ASICs under DML2. DML2 is also a
generated code that provides better mode verification and programming
models for software/hardware, and it enables a better way to create
validation tools. This version is more like a middle step to the
complete transition to the DML2 version.

Changes since V1:
- Alex: Fix typos

Changes since V2:
- Update DC includes

Changes since V3:
- Fix 32 bit compilation issues on x86

Changes since V4:
- Avoid compilation of DML2 on some not supported 32-bit architecture
- Update commit message

Co-developed-by: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
Signed-off-by: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
Co-developed-by: Roman Li <roman.li@amd.com>
Signed-off-by: Roman Li <roman.li@amd.com>
Signed-off-by: Qingqing Zhuo <Qingqing.Zhuo@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
  • Loading branch information
Qingqing Zhuo authored and Alex Deucher committed Oct 9, 2023
1 parent 6e2c494 commit 7966f31
Show file tree
Hide file tree
Showing 36 changed files with 19,572 additions and 4 deletions.
3 changes: 2 additions & 1 deletion drivers/gpu/drm/amd/display/dc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ ifdef CONFIG_DRM_AMD_DC_FP

KCOV_INSTRUMENT := n

DC_LIBS += dcn20
DC_LIBS += dcn10
DC_LIBS += dcn20
DC_LIBS += dcn21
DC_LIBS += dcn201
DC_LIBS += dcn30
Expand All @@ -44,6 +44,7 @@ DC_LIBS += dcn32
DC_LIBS += dcn321
DC_LIBS += dcn35
DC_LIBS += dml
DC_LIBS += dml2
endif

DC_LIBS += dce120
Expand Down
39 changes: 39 additions & 0 deletions drivers/gpu/drm/amd/display/dc/core/dc.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@

#include "hw_sequencer_private.h"

#include "dml2/dml2_internal_types.h"

#include "dce/dmub_outbox.h"

#define CTX \
Expand Down Expand Up @@ -2176,6 +2178,11 @@ struct dc_state *dc_create_state(struct dc *dc)

init_state(dc, context);

#ifdef CONFIG_DRM_AMD_DC_FP
if (dc->debug.using_dml2) {
dml2_create(dc, &dc->dml2_options, &context->bw_ctx.dml2);
}
#endif
kref_init(&context->refcount);

return context;
Expand All @@ -2185,11 +2192,25 @@ struct dc_state *dc_copy_state(struct dc_state *src_ctx)
{
int i, j;
struct dc_state *new_ctx = kvmalloc(sizeof(struct dc_state), GFP_KERNEL);
#ifdef CONFIG_DRM_AMD_DC_FP
struct dml2_context *dml2 = NULL;
#endif

if (!new_ctx)
return NULL;
memcpy(new_ctx, src_ctx, sizeof(struct dc_state));

#ifdef CONFIG_DRM_AMD_DC_FP
if (new_ctx->bw_ctx.dml2) {
dml2 = kzalloc(sizeof(struct dml2_context), GFP_KERNEL);
if (!dml2)
return NULL;

memcpy(dml2, src_ctx->bw_ctx.dml2, sizeof(struct dml2_context));
new_ctx->bw_ctx.dml2 = dml2;
}
#endif

for (i = 0; i < MAX_PIPES; i++) {
struct pipe_ctx *cur_pipe = &new_ctx->res_ctx.pipe_ctx[i];

Expand Down Expand Up @@ -2228,6 +2249,12 @@ static void dc_state_free(struct kref *kref)
{
struct dc_state *context = container_of(kref, struct dc_state, refcount);
dc_resource_state_destruct(context);

#ifdef CONFIG_DRM_AMD_DC_FP
dml2_destroy(context->bw_ctx.dml2);
context->bw_ctx.dml2 = 0;
#endif

kvfree(context);
}

Expand Down Expand Up @@ -4679,6 +4706,9 @@ bool dc_set_power_state(
{
struct kref refcount;
struct display_mode_lib *dml;
#ifdef CONFIG_DRM_AMD_DC_FP
struct dml2_context *dml2 = NULL;
#endif

if (!dc->current_state)
return true;
Expand All @@ -4698,6 +4728,10 @@ bool dc_set_power_state(

break;
default:
#ifdef CONFIG_DRM_AMD_DC_FP
if (dc->debug.using_dml2)
dml2 = dc->current_state->bw_ctx.dml2;
#endif
ASSERT(dc->current_state->stream_count == 0);
/* Zero out the current context so that on resume we start with
* clean state, and dc hw programming optimizations will not
Expand All @@ -4724,6 +4758,11 @@ bool dc_set_power_state(

kfree(dml);

#ifdef CONFIG_DRM_AMD_DC_FP
if (dc->debug.using_dml2)
dc->current_state->bw_ctx.dml2 = dml2;
#endif

break;
}

Expand Down
20 changes: 20 additions & 0 deletions drivers/gpu/drm/amd/display/dc/core/dc_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "dpcd_defs.h"
#include "link_enc_cfg.h"
#include "link.h"
#include "clk_mgr.h"
#include "virtual/virtual_link_hwss.h"
#include "link/hwss/link_hwss_dio.h"
#include "link/hwss/link_hwss_dpia.h"
Expand Down Expand Up @@ -86,6 +87,8 @@
dc->ctx->logger
#define DC_LOGGER_INIT(logger)

#include "dml2/dml2_wrapper.h"

#define UNABLE_TO_SPLIT -1

enum dce_version resource_parse_asic_id(struct hw_asic_id asic_id)
Expand Down Expand Up @@ -318,6 +321,10 @@ struct resource_pool *dc_create_resource_pool(struct dc *dc,
res_pool->ref_clocks.xtalin_clock_inKhz;
res_pool->ref_clocks.dchub_ref_clock_inKhz =
res_pool->ref_clocks.xtalin_clock_inKhz;
if ((res_pool->hubbub->funcs->get_dchub_ref_freq))
res_pool->hubbub->funcs->get_dchub_ref_freq(res_pool->hubbub,
res_pool->ref_clocks.dccg_ref_clock_inKhz,
&res_pool->ref_clocks.dchub_ref_clock_inKhz);
} else
ASSERT_CRITICAL(false);
}
Expand Down Expand Up @@ -4358,9 +4365,22 @@ void dc_resource_state_copy_construct(
{
int i, j;
struct kref refcount = dst_ctx->refcount;
#ifdef CONFIG_DRM_AMD_DC_FP
struct dml2_context *dml2 = NULL;

// Need to preserve allocated dml2 context
if (src_ctx->clk_mgr->ctx->dc->debug.using_dml2)
dml2 = dst_ctx->bw_ctx.dml2;
#endif

*dst_ctx = *src_ctx;

#ifdef CONFIG_DRM_AMD_DC_FP
// Preserve allocated dml2 context
if (src_ctx->clk_mgr->ctx->dc->debug.using_dml2)
dst_ctx->bw_ctx.dml2 = dml2;
#endif

for (i = 0; i < MAX_PIPES; i++) {
struct pipe_ctx *cur_pipe = &dst_ctx->res_ctx.pipe_ctx[i];

Expand Down
5 changes: 5 additions & 0 deletions drivers/gpu/drm/amd/display/dc/dc.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include "inc/hw/dmcu.h"
#include "dml/display_mode_lib.h"

#include "dml2/dml2_wrapper.h"

struct abm_save_restore;

/* forward declaration */
Expand Down Expand Up @@ -942,6 +944,7 @@ struct dc_debug_options {
bool dml_disallow_alternate_prefetch_modes;
bool use_legacy_soc_bb_mechanism;
bool exit_idle_opt_for_cursor_updates;
bool using_dml2;
bool enable_single_display_2to1_odm_policy;
bool enable_double_buffered_dsc_pg_support;
bool enable_dp_dig_pixel_rate_div_policy;
Expand Down Expand Up @@ -1049,6 +1052,8 @@ struct dc {
struct _vcs_dpi_voltage_scaling_st clock_limits[DC__VOLTAGE_STATES];
} update_bw_bounding_box;
} scratch;

struct dml2_configuration_options dml2_options;
};

enum frame_buffer_mode {
Expand Down
61 changes: 58 additions & 3 deletions drivers/gpu/drm/amd/display/dc/dcn32/dcn32_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
#include "dcn20/dcn20_vmid.h"
#include "dml/dcn32/dcn32_fpu.h"

#include "dml2/dml2_wrapper.h"

#define DC_LOGGER_INIT(logger)

enum dcn32_clk_src_array_id {
Expand Down Expand Up @@ -714,6 +716,7 @@ static const struct dc_debug_options debug_defaults_drv = {
.use_max_lb = true,
.force_disable_subvp = false,
.exit_idle_opt_for_cursor_updates = true,
.using_dml2 = false,
.enable_single_display_2to1_odm_policy = true,

/* Must match enable_single_display_2to1_odm_policy to support dynamic ODM transitions*/
Expand Down Expand Up @@ -1805,9 +1808,7 @@ void dcn32_add_phantom_pipes(struct dc *dc, struct dc_state *context,
}
}

bool dcn32_validate_bandwidth(struct dc *dc,
struct dc_state *context,
bool fast_validate)
static bool dml1_validate(struct dc *dc, struct dc_state *context, bool fast_validate)
{
bool out = false;

Expand Down Expand Up @@ -1885,6 +1886,19 @@ bool dcn32_validate_bandwidth(struct dc *dc,
return out;
}

bool dcn32_validate_bandwidth(struct dc *dc,
struct dc_state *context,
bool fast_validate)
{
bool out = false;

if (dc->debug.using_dml2)
out = dml2_validate(dc, context, fast_validate);
else
out = dml1_validate(dc, context, fast_validate);
return out;
}

int dcn32_populate_dml_pipes_from_context(
struct dc *dc, struct dc_state *context,
display_e2e_pipe_params_st *pipes,
Expand Down Expand Up @@ -2422,6 +2436,47 @@ static bool dcn32_resource_construct(
pool->base.oem_device = NULL;
}

dc->dml2_options.dcn_pipe_count = pool->base.pipe_count;
dc->dml2_options.use_native_pstate_optimization = false;
dc->dml2_options.use_native_soc_bb_construction = true;
dc->dml2_options.minimize_dispclk_using_odm = true;

dc->dml2_options.callbacks.dc = dc;
dc->dml2_options.callbacks.build_scaling_params = &resource_build_scaling_params;
dc->dml2_options.callbacks.can_support_mclk_switch_using_fw_based_vblank_stretch = &dcn30_can_support_mclk_switch_using_fw_based_vblank_stretch;
dc->dml2_options.callbacks.acquire_secondary_pipe_for_mpc_odm = &dc_resource_acquire_secondary_pipe_for_mpc_odm_legacy;

dc->dml2_options.svp_pstate.callbacks.dc = dc;
dc->dml2_options.svp_pstate.callbacks.add_plane_to_context = &dc_add_plane_to_context;
dc->dml2_options.svp_pstate.callbacks.add_stream_to_ctx = &dc_add_stream_to_ctx;
dc->dml2_options.svp_pstate.callbacks.build_scaling_params = &resource_build_scaling_params;
dc->dml2_options.svp_pstate.callbacks.create_plane = &dc_create_plane_state;
dc->dml2_options.svp_pstate.callbacks.remove_plane_from_context = &dc_remove_plane_from_context;
dc->dml2_options.svp_pstate.callbacks.remove_stream_from_ctx = &dc_remove_stream_from_ctx;
dc->dml2_options.svp_pstate.callbacks.create_stream_for_sink = &dc_create_stream_for_sink;
dc->dml2_options.svp_pstate.callbacks.plane_state_release = &dc_plane_state_release;
dc->dml2_options.svp_pstate.callbacks.stream_release = &dc_stream_release;
dc->dml2_options.svp_pstate.callbacks.release_dsc = &dcn20_release_dsc;

dc->dml2_options.svp_pstate.subvp_fw_processing_delay_us = dc->caps.subvp_fw_processing_delay_us;
dc->dml2_options.svp_pstate.subvp_prefetch_end_to_mall_start_us = dc->caps.subvp_prefetch_end_to_mall_start_us;
dc->dml2_options.svp_pstate.subvp_pstate_allow_width_us = dc->caps.subvp_pstate_allow_width_us;
dc->dml2_options.svp_pstate.subvp_swath_height_margin_lines = dc->caps.subvp_swath_height_margin_lines;

dc->dml2_options.svp_pstate.force_disable_subvp = dc->debug.force_disable_subvp;
dc->dml2_options.svp_pstate.force_enable_subvp = dc->debug.force_subvp_mclk_switch;

dc->dml2_options.mall_cfg.cache_line_size_bytes = dc->caps.cache_line_size;
dc->dml2_options.mall_cfg.cache_num_ways = dc->caps.cache_num_ways;
dc->dml2_options.mall_cfg.max_cab_allocation_bytes = dc->caps.max_cab_allocation_bytes;
dc->dml2_options.mall_cfg.mblk_height_4bpe_pixels = DCN3_2_MBLK_HEIGHT_4BPE;
dc->dml2_options.mall_cfg.mblk_height_8bpe_pixels = DCN3_2_MBLK_HEIGHT_8BPE;
dc->dml2_options.mall_cfg.mblk_size_bytes = DCN3_2_MALL_MBLK_SIZE_BYTES;
dc->dml2_options.mall_cfg.mblk_width_pixels = DCN3_2_MBLK_WIDTH;

dc->dml2_options.max_segments_per_hubp = 18;
dc->dml2_options.det_segment_size = DCN3_2_DET_SEG_SIZE;

if (ASICREV_IS_GC_11_0_3(dc->ctx->asic_id.hw_internal_rev) && (dc->config.sdpif_request_limit_words_per_umc == 0))
dc->config.sdpif_request_limit_words_per_umc = 16;

Expand Down
41 changes: 41 additions & 0 deletions drivers/gpu/drm/amd/display/dc/dcn321/dcn321_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,47 @@ static bool dcn321_resource_construct(
pool->base.oem_device = NULL;
}

dc->dml2_options.dcn_pipe_count = pool->base.pipe_count;
dc->dml2_options.use_native_pstate_optimization = false;
dc->dml2_options.use_native_soc_bb_construction = true;
dc->dml2_options.minimize_dispclk_using_odm = true;

dc->dml2_options.callbacks.dc = dc;
dc->dml2_options.callbacks.build_scaling_params = &resource_build_scaling_params;
dc->dml2_options.callbacks.can_support_mclk_switch_using_fw_based_vblank_stretch = &dcn30_can_support_mclk_switch_using_fw_based_vblank_stretch;
dc->dml2_options.callbacks.acquire_secondary_pipe_for_mpc_odm = &dc_resource_acquire_secondary_pipe_for_mpc_odm_legacy;

dc->dml2_options.svp_pstate.callbacks.dc = dc;
dc->dml2_options.svp_pstate.callbacks.add_plane_to_context = &dc_add_plane_to_context;
dc->dml2_options.svp_pstate.callbacks.add_stream_to_ctx = &dc_add_stream_to_ctx;
dc->dml2_options.svp_pstate.callbacks.build_scaling_params = &resource_build_scaling_params;
dc->dml2_options.svp_pstate.callbacks.create_plane = &dc_create_plane_state;
dc->dml2_options.svp_pstate.callbacks.remove_plane_from_context = &dc_remove_plane_from_context;
dc->dml2_options.svp_pstate.callbacks.remove_stream_from_ctx = &dc_remove_stream_from_ctx;
dc->dml2_options.svp_pstate.callbacks.create_stream_for_sink = &dc_create_stream_for_sink;
dc->dml2_options.svp_pstate.callbacks.plane_state_release = &dc_plane_state_release;
dc->dml2_options.svp_pstate.callbacks.stream_release = &dc_stream_release;
dc->dml2_options.svp_pstate.callbacks.release_dsc = &dcn20_release_dsc;

dc->dml2_options.svp_pstate.subvp_fw_processing_delay_us = dc->caps.subvp_fw_processing_delay_us;
dc->dml2_options.svp_pstate.subvp_prefetch_end_to_mall_start_us = dc->caps.subvp_prefetch_end_to_mall_start_us;
dc->dml2_options.svp_pstate.subvp_pstate_allow_width_us = dc->caps.subvp_pstate_allow_width_us;
dc->dml2_options.svp_pstate.subvp_swath_height_margin_lines = dc->caps.subvp_swath_height_margin_lines;

dc->dml2_options.svp_pstate.force_disable_subvp = dc->debug.force_disable_subvp;
dc->dml2_options.svp_pstate.force_enable_subvp = dc->debug.force_subvp_mclk_switch;

dc->dml2_options.mall_cfg.cache_line_size_bytes = dc->caps.cache_line_size;
dc->dml2_options.mall_cfg.cache_num_ways = dc->caps.cache_num_ways;
dc->dml2_options.mall_cfg.max_cab_allocation_bytes = dc->caps.max_cab_allocation_bytes;
dc->dml2_options.mall_cfg.mblk_height_4bpe_pixels = DCN3_2_MBLK_HEIGHT_4BPE;
dc->dml2_options.mall_cfg.mblk_height_8bpe_pixels = DCN3_2_MBLK_HEIGHT_8BPE;
dc->dml2_options.mall_cfg.mblk_size_bytes = DCN3_2_MALL_MBLK_SIZE_BYTES;
dc->dml2_options.mall_cfg.mblk_width_pixels = DCN3_2_MBLK_WIDTH;

dc->dml2_options.max_segments_per_hubp = 18;
dc->dml2_options.det_segment_size = DCN3_2_DET_SEG_SIZE;

return true;

create_fail:
Expand Down
Loading

0 comments on commit 7966f31

Please sign in to comment.