<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:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Reviewed-by: Yang Wang <kevinyang.wang@amd.com></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Best Regards,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Kevin</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> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Hawking Zhang <Hawking.Zhang@amd.com><br>
<b>Sent:</b> Thursday, January 20, 2022 7:26 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; Deucher, Alexander <Alexander.Deucher@amd.com><br>
<b>Cc:</b> Zhang, Hawking <Hawking.Zhang@amd.com><br>
<b>Subject:</b> [PATCH] drm/amdgpu: switch to common helper to read bios from rom</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">create a common helper function for soc15 and onwards<br>
to read bios image from rom<br>
<br>
Signed-off-by: Hawking Zhang <Hawking.Zhang@amd.com><br>
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu.h      |  3 +-<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c | 38 ++++++++++++++++++++++++<br>
 drivers/gpu/drm/amd/amdgpu/nv.c          | 34 +--------------------<br>
 drivers/gpu/drm/amd/amdgpu/soc15.c       | 37 ++---------------------<br>
 4 files changed, 43 insertions(+), 69 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
index 8a7759147fb2..b2da840f4718 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
@@ -378,7 +378,8 @@ int amdgpu_device_ip_block_add(struct amdgpu_device *adev,<br>
  */<br>
 bool amdgpu_get_bios(struct amdgpu_device *adev);<br>
 bool amdgpu_read_bios(struct amdgpu_device *adev);<br>
-<br>
+bool amdgpu_soc15_read_bios_from_rom(struct amdgpu_device *adev,<br>
+                                    u8 *bios, u32 length_bytes);<br>
 /*<br>
  * Clocks<br>
  */<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c<br>
index ca0503d56e5c..a819828408fd 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c<br>
@@ -476,3 +476,41 @@ bool amdgpu_get_bios(struct amdgpu_device *adev)<br>
         adev->is_atom_fw = (adev->asic_type >= CHIP_VEGA10) ? true : false;<br>
         return true;<br>
 }<br>
+<br>
+/* helper function for soc15 and onwards to read bios from rom */<br>
+bool amdgpu_soc15_read_bios_from_rom(struct amdgpu_device *adev,<br>
+                                    u8 *bios, u32 length_bytes)<br>
+{<br>
+       u32 *dw_ptr;<br>
+       u32 i, length_dw;<br>
+       u32 rom_index_offset;<br>
+       u32 rom_data_offset;<br>
+<br>
+       if (bios == NULL)<br>
+               return false;<br>
+       if (length_bytes == 0)<br>
+               return false;<br>
+       /* APU vbios image is part of sbios image */<br>
+       if (adev->flags & AMD_IS_APU)<br>
+               return false;<br>
+       if (!adev->smuio.funcs ||<br>
+           !adev->smuio.funcs->get_rom_index_offset ||<br>
+           !adev->smuio.funcs->get_rom_data_offset)<br>
+               return false;<br>
+<br>
+       dw_ptr = (u32 *)bios;<br>
+       length_dw = ALIGN(length_bytes, 4) / 4;<br>
+<br>
+       rom_index_offset =<br>
+               adev->smuio.funcs->get_rom_index_offset(adev);<br>
+       rom_data_offset =<br>
+               adev->smuio.funcs->get_rom_data_offset(adev);<br>
+<br>
+       /* set rom index to 0 */<br>
+       WREG32(rom_index_offset, 0);<br>
+       /* read out the rom data */<br>
+       for (i = 0; i < length_dw; i++)<br>
+               dw_ptr[i] = RREG32(rom_data_offset);<br>
+<br>
+       return true;<br>
+}<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/nv.c b/drivers/gpu/drm/amd/amdgpu/nv.c<br>
index 3ccd3b42196a..e52d1114501c 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/nv.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/nv.c<br>
@@ -358,38 +358,6 @@ static bool nv_read_disabled_bios(struct amdgpu_device *adev)<br>
         return false;<br>
 }<br>
 <br>
-static bool nv_read_bios_from_rom(struct amdgpu_device *adev,<br>
-                                 u8 *bios, u32 length_bytes)<br>
-{<br>
-       u32 *dw_ptr;<br>
-       u32 i, length_dw;<br>
-       u32 rom_index_offset, rom_data_offset;<br>
-<br>
-       if (bios == NULL)<br>
-               return false;<br>
-       if (length_bytes == 0)<br>
-               return false;<br>
-       /* APU vbios image is part of sbios image */<br>
-       if (adev->flags & AMD_IS_APU)<br>
-               return false;<br>
-<br>
-       dw_ptr = (u32 *)bios;<br>
-       length_dw = ALIGN(length_bytes, 4) / 4;<br>
-<br>
-       rom_index_offset =<br>
-               adev->smuio.funcs->get_rom_index_offset(adev);<br>
-       rom_data_offset =<br>
-               adev->smuio.funcs->get_rom_data_offset(adev);<br>
-<br>
-       /* set rom index to 0 */<br>
-       WREG32(rom_index_offset, 0);<br>
-       /* read out the rom data */<br>
-       for (i = 0; i < length_dw; i++)<br>
-               dw_ptr[i] = RREG32(rom_data_offset);<br>
-<br>
-       return true;<br>
-}<br>
-<br>
 static struct soc15_allowed_register_entry nv_allowed_read_registers[] = {<br>
         { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)},<br>
         { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS2)},<br>
@@ -707,7 +675,7 @@ static int nv_update_umd_stable_pstate(struct amdgpu_device *adev,<br>
 static const struct amdgpu_asic_funcs nv_asic_funcs =<br>
 {<br>
         .read_disabled_bios = &nv_read_disabled_bios,<br>
-       .read_bios_from_rom = &nv_read_bios_from_rom,<br>
+       .read_bios_from_rom = &amdgpu_soc15_read_bios_from_rom,<br>
         .read_register = &nv_read_register,<br>
         .reset = &nv_asic_reset,<br>
         .reset_method = &nv_asic_reset_method,<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c b/drivers/gpu/drm/amd/amdgpu/soc15.c<br>
index 0fc1747e4a70..e5a1950fb862 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/soc15.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.c<br>
@@ -375,39 +375,6 @@ static bool soc15_read_disabled_bios(struct amdgpu_device *adev)<br>
         return false;<br>
 }<br>
 <br>
-static bool soc15_read_bios_from_rom(struct amdgpu_device *adev,<br>
-                                    u8 *bios, u32 length_bytes)<br>
-{<br>
-       u32 *dw_ptr;<br>
-       u32 i, length_dw;<br>
-       uint32_t rom_index_offset;<br>
-       uint32_t rom_data_offset;<br>
-<br>
-       if (bios == NULL)<br>
-               return false;<br>
-       if (length_bytes == 0)<br>
-               return false;<br>
-       /* APU vbios image is part of sbios image */<br>
-       if (adev->flags & AMD_IS_APU)<br>
-               return false;<br>
-<br>
-       dw_ptr = (u32 *)bios;<br>
-       length_dw = ALIGN(length_bytes, 4) / 4;<br>
-<br>
-       rom_index_offset =<br>
-               adev->smuio.funcs->get_rom_index_offset(adev);<br>
-       rom_data_offset =<br>
-               adev->smuio.funcs->get_rom_data_offset(adev);<br>
-<br>
-       /* set rom index to 0 */<br>
-       WREG32(rom_index_offset, 0);<br>
-       /* read out the rom data */<br>
-       for (i = 0; i < length_dw; i++)<br>
-               dw_ptr[i] = RREG32(rom_data_offset);<br>
-<br>
-       return true;<br>
-}<br>
-<br>
 static struct soc15_allowed_register_entry soc15_allowed_read_registers[] = {<br>
         { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)},<br>
         { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS2)},<br>
@@ -925,7 +892,7 @@ static void soc15_pre_asic_init(struct amdgpu_device *adev)<br>
 static const struct amdgpu_asic_funcs soc15_asic_funcs =<br>
 {<br>
         .read_disabled_bios = &soc15_read_disabled_bios,<br>
-       .read_bios_from_rom = &soc15_read_bios_from_rom,<br>
+       .read_bios_from_rom = &amdgpu_soc15_read_bios_from_rom,<br>
         .read_register = &soc15_read_register,<br>
         .reset = &soc15_asic_reset,<br>
         .reset_method = &soc15_asic_reset_method,<br>
@@ -947,7 +914,7 @@ static const struct amdgpu_asic_funcs soc15_asic_funcs =<br>
 static const struct amdgpu_asic_funcs vega20_asic_funcs =<br>
 {<br>
         .read_disabled_bios = &soc15_read_disabled_bios,<br>
-       .read_bios_from_rom = &soc15_read_bios_from_rom,<br>
+       .read_bios_from_rom = &amdgpu_soc15_read_bios_from_rom,<br>
         .read_register = &soc15_read_register,<br>
         .reset = &soc15_asic_reset,<br>
         .reset_method = &soc15_asic_reset_method,<br>
-- <br>
2.17.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>