<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0078D7;margin:15pt;" align="Left">
[AMD Official Use Only - Internal Distribution Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(32, 31, 30); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important">Reviewed-by:
 Hersen Wu <hersenxs.wu@amd.com></span><br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(32, 31, 30); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important"><br>
</span></div>
<div>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Bhawanpreet Lakha <Bhawanpreet.Lakha@amd.com><br>
<b>Sent:</b> June 12, 2020 7:50 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; Deucher, Alexander <Alexander.Deucher@amd.com>; Kazlauskas, Nicholas <Nicholas.Kazlauskas@amd.com>; Wu, Hersen <hersenxs.wu@amd.com><br>
<b>Cc:</b> Lee, Alvin <Alvin.Lee2@amd.com>; Lakha, Bhawanpreet <Bhawanpreet.Lakha@amd.com><br>
<b>Subject:</b> [PATCH] drm/amd/display: Get num_chans from VBIOS table</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">From: Alvin Lee <alvin.lee2@amd.com><br>
<br>
Get the values from VBIOS table<br>
<br>
Signed-off-by: Alvin Lee <alvin.lee2@amd.com><br>
Signed-off-by: Bhawanpreet Lakha <Bhawanpreet.Lakha@amd.com><br>
---<br>
 .../drm/amd/display/dc/bios/bios_parser2.c    | 98 +++++++++++++++++++<br>
 .../gpu/drm/amd/display/dc/dc_bios_types.h    |  1 +<br>
 .../drm/amd/display/dc/dcn30/dcn30_resource.c |  7 +-<br>
 .../display/include/grph_object_ctrl_defs.h   |  5 +<br>
 4 files changed, 110 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c b/drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c<br>
index 9311fec1643c..b8684131151d 100644<br>
--- a/drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c<br>
+++ b/drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c<br>
@@ -1378,6 +1378,63 @@ static struct atom_encoder_caps_record *get_encoder_cap_record(<br>
         return NULL;<br>
 }<br>
 <br>
+static enum bp_result get_vram_info_v23(<br>
+       struct bios_parser *bp,<br>
+       struct dc_vram_info *info)<br>
+{<br>
+       struct atom_vram_info_header_v2_3 *info_v23;<br>
+       enum bp_result result = BP_RESULT_OK;<br>
+<br>
+       info_v23 = GET_IMAGE(struct atom_vram_info_header_v2_3,<br>
+                                               DATA_TABLES(vram_info));<br>
+<br>
+       if (info_v23 == NULL)<br>
+               return BP_RESULT_BADBIOSTABLE;<br>
+<br>
+       info->num_chans = info_v23->vram_module[0].channel_num;<br>
+       info->dram_channel_width_bytes = (1 << info_v23->vram_module[0].channel_width) / 8;<br>
+<br>
+       return result;<br>
+}<br>
+<br>
+static enum bp_result get_vram_info_v24(<br>
+       struct bios_parser *bp,<br>
+       struct dc_vram_info *info)<br>
+{<br>
+       struct atom_vram_info_header_v2_4 *info_v24;<br>
+       enum bp_result result = BP_RESULT_OK;<br>
+<br>
+       info_v24 = GET_IMAGE(struct atom_vram_info_header_v2_4,<br>
+                                               DATA_TABLES(vram_info));<br>
+<br>
+       if (info_v24 == NULL)<br>
+               return BP_RESULT_BADBIOSTABLE;<br>
+<br>
+       info->num_chans = info_v24->vram_module[0].channel_num;<br>
+       info->dram_channel_width_bytes = (1 << info_v24->vram_module[0].channel_width) / 8;<br>
+<br>
+       return result;<br>
+}<br>
+<br>
+static enum bp_result get_vram_info_v25(<br>
+       struct bios_parser *bp,<br>
+       struct dc_vram_info *info)<br>
+{<br>
+       struct atom_vram_info_header_v2_5 *info_v25;<br>
+       enum bp_result result = BP_RESULT_OK;<br>
+<br>
+       info_v25 = GET_IMAGE(struct atom_vram_info_header_v2_5,<br>
+                                               DATA_TABLES(vram_info));<br>
+<br>
+       if (info_v25 == NULL)<br>
+               return BP_RESULT_BADBIOSTABLE;<br>
+<br>
+       info->num_chans = info_v25->vram_module[0].channel_num;<br>
+       info->dram_channel_width_bytes = (1 << info_v25->vram_module[0].channel_width) / 8;<br>
+<br>
+       return result;<br>
+}<br>
+<br>
 /*<br>
  * get_integrated_info_v11<br>
  *<br>
@@ -1669,6 +1726,46 @@ static enum bp_result construct_integrated_info(<br>
         return result;<br>
 }<br>
 <br>
+static enum bp_result bios_parser_get_vram_info(<br>
+               struct dc_bios *dcb,<br>
+               struct dc_vram_info *info)<br>
+{<br>
+       struct bios_parser *bp = BP_FROM_DCB(dcb);<br>
+       enum bp_result result = BP_RESULT_BADBIOSTABLE;<br>
+       struct atom_common_table_header *header;<br>
+       struct atom_data_revision revision;<br>
+<br>
+       if (info && DATA_TABLES(vram_info)) {<br>
+               header = GET_IMAGE(struct atom_common_table_header,<br>
+                                       DATA_TABLES(vram_info));<br>
+<br>
+               get_atom_data_table_revision(header, &revision);<br>
+<br>
+               switch (revision.major) {<br>
+               case 2:<br>
+                       switch (revision.minor) {<br>
+                       case 3:<br>
+                               result = get_vram_info_v23(bp, info);<br>
+                               break;<br>
+                       case 4:<br>
+                               result = get_vram_info_v24(bp, info);<br>
+                               break;<br>
+                       case 5:<br>
+                               result = get_vram_info_v25(bp, info);<br>
+                               break;<br>
+                       default:<br>
+                               break;<br>
+                       }<br>
+                       break;<br>
+<br>
+               default:<br>
+                       return result;<br>
+               }<br>
+<br>
+       }<br>
+       return result;<br>
+}<br>
+<br>
 static struct integrated_info *bios_parser_create_integrated_info(<br>
         struct dc_bios *dcb)<br>
 {<br>
@@ -2112,6 +2209,7 @@ static bool bios_parser2_construct(<br>
 <br>
         bp->base.integrated_info = bios_parser_create_integrated_info(&bp->base);<br>
         bp->base.fw_info_valid = bios_parser_get_firmware_info(&bp->base, &bp->base.fw_info) == BP_RESULT_OK;<br>
+       bios_parser_get_vram_info(&bp->base, &bp->base.vram_info);<br>
 <br>
         return true;<br>
 }<br>
diff --git a/drivers/gpu/drm/amd/display/dc/dc_bios_types.h b/drivers/gpu/drm/amd/display/dc/dc_bios_types.h<br>
index 441768aa53ff..845a3054f21f 100644<br>
--- a/drivers/gpu/drm/amd/display/dc/dc_bios_types.h<br>
+++ b/drivers/gpu/drm/amd/display/dc/dc_bios_types.h<br>
@@ -153,6 +153,7 @@ struct dc_bios {<br>
         struct integrated_info *integrated_info;<br>
         struct dc_firmware_info fw_info;<br>
         bool fw_info_valid;<br>
+       struct dc_vram_info vram_info;<br>
 };<br>
 <br>
 #endif /* DC_BIOS_TYPES_H */<br>
diff --git a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c<br>
index 011f1454b8cb..654fdbbff86b 100644<br>
--- a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c<br>
+++ b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c<br>
@@ -195,7 +195,6 @@ struct _vcs_dpi_soc_bounding_box_st dcn3_0_soc = {<br>
         .max_avg_dram_bw_use_normal_percent = 40.0,<br>
         .writeback_latency_us = 12.0,<br>
         .max_request_size_bytes = 256,<br>
-       .dram_channel_width_bytes = 2,<br>
         .fabric_datapath_to_dcn_data_return_bytes = 64,<br>
         .dcn_downspread_percent = 0.5,<br>
         .downspread_percent = 0.38,<br>
@@ -2242,6 +2241,12 @@ static void dcn30_update_bw_bounding_box(struct dc *dc, struct clk_bw_params *bw<br>
 {<br>
         unsigned int i;<br>
 <br>
+       if (dc->ctx->dc_bios->vram_info.num_chans)<br>
+               dcn3_0_soc.num_chans = dc->ctx->dc_bios->vram_info.num_chans;<br>
+<br>
+       if (dc->ctx->dc_bios->vram_info.dram_channel_width_bytes)<br>
+               dcn3_0_soc.dram_channel_width_bytes = dc->ctx->dc_bios->vram_info.dram_channel_width_bytes;<br>
+<br>
         dcn3_0_soc.dispclk_dppclk_vco_speed_mhz = dc->clk_mgr->dentist_vco_freq_khz / 1000.0;<br>
         dc->dml.soc.dispclk_dppclk_vco_speed_mhz = dc->clk_mgr->dentist_vco_freq_khz / 1000.0;<br>
 <br>
diff --git a/drivers/gpu/drm/amd/display/include/grph_object_ctrl_defs.h b/drivers/gpu/drm/amd/display/include/grph_object_ctrl_defs.h<br>
index d51de94e4bc3..7a06e3914c00 100644<br>
--- a/drivers/gpu/drm/amd/display/include/grph_object_ctrl_defs.h<br>
+++ b/drivers/gpu/drm/amd/display/include/grph_object_ctrl_defs.h<br>
@@ -183,6 +183,11 @@ struct dc_firmware_info {<br>
 <br>
 };<br>
 <br>
+struct dc_vram_info {<br>
+       unsigned int num_chans;<br>
+       unsigned int dram_channel_width_bytes;<br>
+};<br>
+<br>
 struct step_and_delay_info {<br>
         uint32_t step;<br>
         uint32_t delay;<br>
-- <br>
2.17.1<br>
<br>
</div>
</span></font></div>
</div>
</div>
</body>
</html>