<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<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:11pt;color:#0078D7;margin:5pt;" 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);">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com><br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Liu, Monk <Monk.Liu@amd.com><br>
<b>Sent:</b> Thursday, May 13, 2021 7:50 AM<br>
<b>To:</b> Zhang, Bokun <Bokun.Zhang@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Zhang, Bokun <Bokun.Zhang@amd.com><br>
<b>Subject:</b> RE: [PATCH] drm/amdgpu: Complete multimedia bandwidth interface</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">[AMD Official Use Only - Internal Distribution Only]<br>
<br>
Reviewed-by: Monk liu <monk.liu@amd.com><br>
<br>
Better get  open source team's RB as well <br>
<br>
Thanks <br>
<br>
------------------------------------------<br>
Monk Liu | Cloud-GPU Core team<br>
------------------------------------------<br>
<br>
-----Original Message-----<br>
From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of Bokun Zhang<br>
Sent: Thursday, May 13, 2021 1:20 PM<br>
To: amd-gfx@lists.freedesktop.org<br>
Cc: Zhang, Bokun <Bokun.Zhang@amd.com><br>
Subject: [PATCH] drm/amdgpu: Complete multimedia bandwidth interface<br>
<br>
- Update SRIOV PF2VF header with latest revision<br>
<br>
- Extend existing function in amdgpu_virt.c to read MM bandwidth config<br>
  from PF2VF message<br>
<br>
- Add SRIOV Sienna Cichlid codec array and update the bandwidth with<br>
  PF2VF message<br>
<br>
Change-Id: Id0cfa2e1adb7a097997d53b34d41a6d36a390c00<br>
Signed-off-by: Bokun Zhang <bokun.zhang@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c    |  56 ++++++++++<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h    |  13 +++<br>
 drivers/gpu/drm/amd/amdgpu/amdgv_sriovmsg.h |  54 ++++++++--<br>
 drivers/gpu/drm/amd/amdgpu/nv.c             | 110 +++++++++++++++++++-<br>
 4 files changed, 226 insertions(+), 7 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c<br>
index a57842689d42..c64e583347c6 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c<br>
@@ -432,6 +432,9 @@ static int amdgpu_virt_read_pf2vf_data(struct amdgpu_device *adev)<br>
         uint32_t checksum;<br>
         uint32_t checkval;<br>
 <br>
+       uint32_t i;<br>
+       uint32_t tmp;<br>
+<br>
         if (adev->virt.fw_reserve.p_pf2vf == NULL)<br>
                 return -EINVAL;<br>
 <br>
@@ -472,6 +475,27 @@ static int amdgpu_virt_read_pf2vf_data(struct amdgpu_device *adev)<br>
                 adev->virt.reg_access =<br>
                         ((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->reg_access_flags.all;<br>
 <br>
+               adev->virt.decode_max_dimension_pixels = 0;<br>
+               adev->virt.decode_max_frame_pixels = 0;<br>
+               adev->virt.encode_max_dimension_pixels = 0;<br>
+               adev->virt.encode_max_frame_pixels = 0;<br>
+               adev->virt.is_mm_bw_enabled = false;<br>
+               for (i = 0; i < AMD_SRIOV_MSG_RESERVE_VCN_INST; i++) {<br>
+                       tmp = ((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->mm_bw_management[i].decode_max_dimension_pixels;<br>
+                       adev->virt.decode_max_dimension_pixels = max(tmp, <br>
+adev->virt.decode_max_dimension_pixels);<br>
+<br>
+                       tmp = ((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->mm_bw_management[i].decode_max_frame_pixels;<br>
+                       adev->virt.decode_max_frame_pixels = max(tmp, <br>
+adev->virt.decode_max_frame_pixels);<br>
+<br>
+                       tmp = ((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->mm_bw_management[i].encode_max_dimension_pixels;<br>
+                       adev->virt.encode_max_dimension_pixels = max(tmp, <br>
+adev->virt.encode_max_dimension_pixels);<br>
+<br>
+                       tmp = ((struct amd_sriov_msg_pf2vf_info *)pf2vf_info)->mm_bw_management[i].encode_max_frame_pixels;<br>
+                       adev->virt.encode_max_frame_pixels = max(tmp, adev->virt.encode_max_frame_pixels);<br>
+               }<br>
+               if((adev->virt.decode_max_dimension_pixels > 0) || (adev->virt.encode_max_dimension_pixels > 0))<br>
+                       adev->virt.is_mm_bw_enabled = true;<br>
+<br>
                 break;<br>
         default:<br>
                 DRM_ERROR("invalid pf2vf version\n"); @@ -744,3 +768,35 @@ enum amdgpu_sriov_vf_mode amdgpu_virt_get_sriov_vf_mode(struct amdgpu_device *ad<br>
 <br>
         return mode;<br>
 }<br>
+<br>
+void amdgpu_virt_update_sriov_video_codec(struct amdgpu_device *adev,<br>
+                       struct amdgpu_video_codec_info *encode, uint32_t encode_array_size,<br>
+                       struct amdgpu_video_codec_info *decode, uint32_t decode_array_size)
<br>
+{<br>
+       uint32_t i;<br>
+<br>
+       if (!adev->virt.is_mm_bw_enabled)<br>
+               return;<br>
+<br>
+       if (encode) {<br>
+               for (i = 0; i < encode_array_size; i++) {<br>
+                       encode[i].max_width = adev->virt.encode_max_dimension_pixels;<br>
+                       encode[i].max_pixels_per_frame = adev->virt.encode_max_frame_pixels;<br>
+                       if (encode[i].max_width > 0)<br>
+                               encode[i].max_height = encode[i].max_pixels_per_frame / encode[i].max_width;<br>
+                       else<br>
+                               encode[i].max_height = 0;<br>
+               }<br>
+       }<br>
+<br>
+       if (decode) {<br>
+               for (i = 0; i < decode_array_size; i++) {<br>
+                       decode[i].max_width = adev->virt.decode_max_dimension_pixels;<br>
+                       decode[i].max_pixels_per_frame = adev->virt.decode_max_frame_pixels;<br>
+                       if (decode[i].max_width > 0)<br>
+                               decode[i].max_height = decode[i].max_pixels_per_frame / decode[i].max_width;<br>
+                       else<br>
+                               decode[i].max_height = 0;<br>
+               }<br>
+       }<br>
+}<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h<br>
index 383d4bdc3fb5..8d4c20bb71c5 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h<br>
@@ -233,8 +233,17 @@ struct amdgpu_virt {<br>
         /* vf2pf message */<br>
         struct delayed_work vf2pf_work;<br>
         uint32_t vf2pf_update_interval_ms;<br>
+<br>
+       /* multimedia bandwidth config */<br>
+       bool     is_mm_bw_enabled;<br>
+       uint32_t decode_max_dimension_pixels;<br>
+       uint32_t decode_max_frame_pixels;<br>
+       uint32_t encode_max_dimension_pixels;<br>
+       uint32_t encode_max_frame_pixels;<br>
 };<br>
 <br>
+struct amdgpu_video_codec_info;<br>
+<br>
 #define amdgpu_sriov_enabled(adev) \<br>
 ((adev)->virt.caps & AMDGPU_SRIOV_CAPS_ENABLE_IOV)<br>
 <br>
@@ -307,4 +316,8 @@ int amdgpu_virt_enable_access_debugfs(struct amdgpu_device *adev);  void amdgpu_virt_disable_access_debugfs(struct amdgpu_device *adev);<br>
 <br>
 enum amdgpu_sriov_vf_mode amdgpu_virt_get_sriov_vf_mode(struct amdgpu_device *adev);<br>
+<br>
+void amdgpu_virt_update_sriov_video_codec(struct amdgpu_device *adev,<br>
+                       struct amdgpu_video_codec_info *encode, uint32_t encode_array_size,<br>
+                       struct amdgpu_video_codec_info *decode, uint32_t decode_array_size);<br>
 #endif<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgv_sriovmsg.h b/drivers/gpu/drm/amd/amdgpu/amdgv_sriovmsg.h<br>
index befd0b4b7bea..a434c71fde8e 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgv_sriovmsg.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgv_sriovmsg.h<br>
@@ -56,6 +56,8 @@<br>
 <br>
 #define AMD_SRIOV_MSG_RESERVE_UCODE             24<br>
 <br>
+#define AMD_SRIOV_MSG_RESERVE_VCN_INST 4<br>
+<br>
 enum amd_sriov_ucode_engine_id {<br>
         AMD_SRIOV_UCODE_ID_VCE = 0,<br>
         AMD_SRIOV_UCODE_ID_UVD,<br>
@@ -98,10 +100,10 @@ union amd_sriov_msg_feature_flags {<br>
 <br>
 union amd_sriov_reg_access_flags {<br>
         struct {<br>
-               uint32_t vf_reg_psp_access_ih    : 1;<br>
-               uint32_t vf_reg_rlc_access_mmhub : 1;<br>
-               uint32_t vf_reg_rlc_access_gc    : 1;<br>
-               uint32_t reserved            : 29;<br>
+               uint32_t vf_reg_access_ih         : 1;<br>
+               uint32_t vf_reg_access_mmhub : 1;<br>
+               uint32_t vf_reg_access_gc         : 1;<br>
+               uint32_t reserved                : 29;<br>
         } flags;<br>
         uint32_t all;<br>
 };<br>
@@ -114,6 +116,37 @@ union amd_sriov_msg_os_info {<br>
         uint32_t      all;<br>
 };<br>
 <br>
+struct amd_sriov_msg_uuid_info {<br>
+       union {<br>
+               struct {<br>
+                       uint32_t did    : 16;<br>
+                       uint32_t fcn    : 8;<br>
+                       uint32_t asic_7 : 8;<br>
+               };<br>
+               uint32_t time_low;<br>
+       };<br>
+<br>
+       struct {<br>
+               uint32_t time_mid  : 16;<br>
+               uint32_t time_high : 12;<br>
+               uint32_t version   : 4;<br>
+       };<br>
+<br>
+       struct {<br>
+               struct {<br>
+                       uint8_t clk_seq_hi : 6;<br>
+                       uint8_t variant    : 2;<br>
+               };<br>
+               union {<br>
+                       uint8_t clk_seq_low;<br>
+                       uint8_t asic_6;<br>
+               };<br>
+               uint16_t asic_4;<br>
+       };<br>
+<br>
+       uint32_t asic_0;<br>
+};<br>
+<br>
 struct amd_sriov_msg_pf2vf_info_header {<br>
         /* the total structure size in byte */<br>
         uint32_t size;<br>
@@ -160,10 +193,19 @@ struct amd_sriov_msg_pf2vf_info {<br>
         /* identification in ROCm SMI */<br>
         uint64_t uuid;<br>
         uint32_t fcn_idx;<br>
-       /* flags which indicate the register access method VF should use */<br>
+       /* flags to indicate which register access method VF should use */<br>
         union amd_sriov_reg_access_flags reg_access_flags;<br>
+       /* MM BW management */<br>
+       struct {<br>
+               uint32_t decode_max_dimension_pixels;<br>
+               uint32_t decode_max_frame_pixels;<br>
+               uint32_t encode_max_dimension_pixels;<br>
+               uint32_t encode_max_frame_pixels;<br>
+       } mm_bw_management[AMD_SRIOV_MSG_RESERVE_VCN_INST];<br>
+       /* UUID info */<br>
+       struct amd_sriov_msg_uuid_info uuid_info;<br>
         /* reserved */<br>
-       uint32_t reserved[256-27];<br>
+       uint32_t reserved[256 - 47];<br>
 };<br>
 <br>
 struct amd_sriov_msg_vf2pf_info_header { diff --git a/drivers/gpu/drm/amd/amdgpu/nv.c b/drivers/gpu/drm/amd/amdgpu/nv.c index 75d1f9b939b2..9f74060207a4 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/nv.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/nv.c<br>
@@ -218,11 +218,114 @@ static const struct amdgpu_video_codecs sc_video_codecs_decode =<br>
         .codec_array = sc_video_codecs_decode_array,  };<br>
 <br>
+/* SRIOV Sienna Cichlid, not const since data is controlled by host */ <br>
+static struct amdgpu_video_codec_info <br>
+sriov_sc_video_codecs_encode_array[] = {<br>
+       {<br>
+               .codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC,<br>
+               .max_width = 4096,<br>
+               .max_height = 2304,<br>
+               .max_pixels_per_frame = 4096 * 2304,<br>
+               .max_level = 0,<br>
+       },<br>
+       {<br>
+               .codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC,<br>
+               .max_width = 4096,<br>
+               .max_height = 2304,<br>
+               .max_pixels_per_frame = 4096 * 2304,<br>
+               .max_level = 0,<br>
+       },<br>
+};<br>
+<br>
+static struct amdgpu_video_codec_info <br>
+sriov_sc_video_codecs_decode_array[] = {<br>
+       {<br>
+               .codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2,<br>
+               .max_width = 4096,<br>
+               .max_height = 4096,<br>
+               .max_pixels_per_frame = 4096 * 4096,<br>
+               .max_level = 3,<br>
+       },<br>
+       {<br>
+               .codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4,<br>
+               .max_width = 4096,<br>
+               .max_height = 4096,<br>
+               .max_pixels_per_frame = 4096 * 4096,<br>
+               .max_level = 5,<br>
+       },<br>
+       {<br>
+               .codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC,<br>
+               .max_width = 4096,<br>
+               .max_height = 4096,<br>
+               .max_pixels_per_frame = 4096 * 4096,<br>
+               .max_level = 52,<br>
+       },<br>
+       {<br>
+               .codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1,<br>
+               .max_width = 4096,<br>
+               .max_height = 4096,<br>
+               .max_pixels_per_frame = 4096 * 4096,<br>
+               .max_level = 4,<br>
+       },<br>
+       {<br>
+               .codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC,<br>
+               .max_width = 8192,<br>
+               .max_height = 4352,<br>
+               .max_pixels_per_frame = 8192 * 4352,<br>
+               .max_level = 186,<br>
+       },<br>
+       {<br>
+               .codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG,<br>
+               .max_width = 4096,<br>
+               .max_height = 4096,<br>
+               .max_pixels_per_frame = 4096 * 4096,<br>
+               .max_level = 0,<br>
+       },<br>
+       {<br>
+               .codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9,<br>
+               .max_width = 8192,<br>
+               .max_height = 4352,<br>
+               .max_pixels_per_frame = 8192 * 4352,<br>
+               .max_level = 0,<br>
+       },<br>
+       {<br>
+               .codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1,<br>
+               .max_width = 8192,<br>
+               .max_height = 4352,<br>
+               .max_pixels_per_frame = 8192 * 4352,<br>
+               .max_level = 0,<br>
+       },<br>
+};<br>
+<br>
+static struct amdgpu_video_codecs sriov_sc_video_codecs_encode = {<br>
+       .codec_count = ARRAY_SIZE(sriov_sc_video_codecs_encode_array),<br>
+       .codec_array = sriov_sc_video_codecs_encode_array,<br>
+};<br>
+<br>
+static struct amdgpu_video_codecs sriov_sc_video_codecs_decode = {<br>
+       .codec_count = ARRAY_SIZE(sriov_sc_video_codecs_decode_array),<br>
+       .codec_array = sriov_sc_video_codecs_decode_array,<br>
+};<br>
+<br>
 static int nv_query_video_codecs(struct amdgpu_device *adev, bool encode,<br>
                                  const struct amdgpu_video_codecs **codecs)  {<br>
         switch (adev->asic_type) {<br>
         case CHIP_SIENNA_CICHLID:<br>
+               if (amdgpu_sriov_vf(adev)) {<br>
+                       if (encode)<br>
+                               *codecs = &sriov_sc_video_codecs_encode;<br>
+                       else<br>
+                               *codecs = &sriov_sc_video_codecs_decode;<br>
+               } else {<br>
+                       if (encode)<br>
+                               *codecs = &nv_video_codecs_encode;<br>
+                       else<br>
+                               *codecs = &sc_video_codecs_decode;<br>
+               }<br>
+               return 0;<br>
         case CHIP_NAVY_FLOUNDER:<br>
         case CHIP_DIMGREY_CAVEFISH:<br>
         case CHIP_VANGOGH:<br>
@@ -1173,9 +1276,14 @@ static int nv_common_early_init(void *handle)  static int nv_common_late_init(void *handle)  {<br>
         struct amdgpu_device *adev = (struct amdgpu_device *)handle;<br>
+       uint32_t i;<br>
 <br>
-       if (amdgpu_sriov_vf(adev))<br>
+       if (amdgpu_sriov_vf(adev)) {<br>
                 xgpu_nv_mailbox_get_irq(adev);<br>
+               amdgpu_virt_update_sriov_video_codec(adev,<br>
+                               sriov_sc_video_codecs_encode_array, ARRAY_SIZE(sriov_sc_video_codecs_encode_array),<br>
+                               sriov_sc_video_codecs_decode_array, ARRAY_SIZE(sriov_sc_video_codecs_decode_array));<br>
+       }<br>
 <br>
         return 0;<br>
 }<br>
--<br>
2.20.1<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7Calexander.deucher%40amd.com%7C9be40f22588749e14c8608d916055a9d%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637565034521071448%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=6raS%2BZy0ngarsgVcG4NBkmH5Ym0%2BuyD7GCXo4su4V30%3D&amp;reserved=0">https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7Calexander.deucher%40amd.com%7C9be40f22588749e14c8608d916055a9d%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637565034521071448%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=6raS%2BZy0ngarsgVcG4NBkmH5Ym0%2BuyD7GCXo4su4V30%3D&amp;reserved=0</a><br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7Calexander.deucher%40amd.com%7C9be40f22588749e14c8608d916055a9d%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637565034521071448%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=6raS%2BZy0ngarsgVcG4NBkmH5Ym0%2BuyD7GCXo4su4V30%3D&amp;reserved=0">https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7Calexander.deucher%40amd.com%7C9be40f22588749e14c8608d916055a9d%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637565034521071448%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=6raS%2BZy0ngarsgVcG4NBkmH5Ym0%2BuyD7GCXo4su4V30%3D&amp;reserved=0</a><br>
</div>
</span></font></div>
</div>
</body>
</html>