<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:10pt;color:#008000;margin:15pt;" align="Left">
[Public]<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 Peng Ju Zhou <PengJu.Zhou@amd.com><br>
<b>Sent:</b> Thursday, June 17, 2021 3:46 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Zhang, Bokun <Bokun.Zhang@amd.com><br>
<b>Subject:</b> [PATCH v3] drm/amd/amdgpu: Use IP discovery data to determine VCN enablement instead of MMSCH</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">From: Bokun Zhang <Bokun.Zhang@amd.com><br>
<br>
In the past, we use MMSCH to determine whether a VCN is enabled or not.<br>
This is not reliable since after a FLR, MMSCH may report junk data.<br>
<br>
It is better to use IP discovery data.<br>
<br>
Signed-off-by: Bokun Zhang <Bokun.Zhang@amd.com><br>
Signed-off-by: Peng Ju Zhou <PengJu.Zhou@amd.com><br>
---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 8 +++<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h | 3 ++<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 23 ++++++++<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h | 13 +++++<br>
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 53 +++++--------------<br>
5 files changed, 61 insertions(+), 39 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c<br>
index f949ed8bfd9e..e02405a24fe3 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c<br>
@@ -373,6 +373,14 @@ int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int hw_id, int n<br>
return -EINVAL;<br>
}<br>
<br>
+<br>
+int amdgpu_discovery_get_vcn_version(struct amdgpu_device *adev, int vcn_instance,<br>
+ int *major, int *minor, int *revision)<br>
+{<br>
+ return amdgpu_discovery_get_ip_version(adev, VCN_HWID,<br>
+ vcn_instance, major, minor, revision);<br>
+}<br>
+<br>
void amdgpu_discovery_harvest_ip(struct amdgpu_device *adev)<br>
{<br>
struct binary_header *bhdr;<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h<br>
index 02e340cd3a38..48e6b88cfdfe 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h<br>
@@ -32,6 +32,9 @@ int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev);<br>
void amdgpu_discovery_harvest_ip(struct amdgpu_device *adev);<br>
int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int hw_id, int number_instance,<br>
int *major, int *minor, int *revision);<br>
+<br>
+int amdgpu_discovery_get_vcn_version(struct amdgpu_device *adev, int vcn_instance,<br>
+ int *major, int *minor, int *revision);<br>
int amdgpu_discovery_get_gfx_info(struct amdgpu_device *adev);<br>
<br>
#endif /* __AMDGPU_DISCOVERY__ */<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c<br>
index 9492b505e69b..84b025405578 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c<br>
@@ -287,6 +287,29 @@ int amdgpu_vcn_sw_fini(struct amdgpu_device *adev)<br>
return 0;<br>
}<br>
<br>
+bool amdgpu_vcn_is_disabled_vcn(struct amdgpu_device *adev, enum vcn_ring_type type, uint32_t vcn_instance)<br>
+{<br>
+ bool ret = false;<br>
+<br>
+ int major;<br>
+ int minor;<br>
+ int revision;<br>
+<br>
+ /* if cannot find IP data, then this VCN does not exist */<br>
+ if (amdgpu_discovery_get_vcn_version(adev, vcn_instance, &major, &minor, &revision) != 0)<br>
+ return true;<br>
+<br>
+ if ((type == VCN_ENCODE_RING) && (revision & VCN_BLOCK_ENCODE_DISABLE_MASK)) {<br>
+ ret = true;<br>
+ } else if ((type == VCN_DECODE_RING) && (revision & VCN_BLOCK_DECODE_DISABLE_MASK)) {<br>
+ ret = true;<br>
+ } else if ((type == VCN_UNIFIED_RING) && (revision & VCN_BLOCK_QUEUE_DISABLE_MASK)) {<br>
+ ret = true;<br>
+ }<br>
+<br>
+ return ret;<br>
+}<br>
+<br>
int amdgpu_vcn_suspend(struct amdgpu_device *adev)<br>
{<br>
unsigned size;<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h<br>
index bc76cab67697..d74c62b49795 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h<br>
@@ -280,6 +280,16 @@ struct amdgpu_vcn_decode_buffer {<br>
uint32_t pad[30];<br>
};<br>
<br>
+#define VCN_BLOCK_ENCODE_DISABLE_MASK 0x80<br>
+#define VCN_BLOCK_DECODE_DISABLE_MASK 0x40<br>
+#define VCN_BLOCK_QUEUE_DISABLE_MASK 0xC0<br>
+<br>
+enum vcn_ring_type {<br>
+ VCN_ENCODE_RING,<br>
+ VCN_DECODE_RING,<br>
+ VCN_UNIFIED_RING,<br>
+};<br>
+<br>
int amdgpu_vcn_sw_init(struct amdgpu_device *adev);<br>
int amdgpu_vcn_sw_fini(struct amdgpu_device *adev);<br>
int amdgpu_vcn_suspend(struct amdgpu_device *adev);<br>
@@ -287,6 +297,9 @@ int amdgpu_vcn_resume(struct amdgpu_device *adev);<br>
void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring);<br>
void amdgpu_vcn_ring_end_use(struct amdgpu_ring *ring);<br>
<br>
+bool amdgpu_vcn_is_disabled_vcn(struct amdgpu_device *adev,<br>
+ enum vcn_ring_type type, uint32_t vcn_instance);<br>
+<br>
int amdgpu_vcn_dec_ring_test_ring(struct amdgpu_ring *ring);<br>
int amdgpu_vcn_dec_ring_test_ib(struct amdgpu_ring *ring, long timeout);<br>
int amdgpu_vcn_dec_sw_ring_test_ring(struct amdgpu_ring *ring);<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c<br>
index 798b6b4d8f46..c3580de3ea9c 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c<br>
@@ -85,16 +85,18 @@ static void vcn_v3_0_enc_ring_set_wptr(struct amdgpu_ring *ring);<br>
static int vcn_v3_0_early_init(void *handle)<br>
{<br>
struct amdgpu_device *adev = (struct amdgpu_device *)handle;<br>
+ int i;<br>
<br>
if (amdgpu_sriov_vf(adev)) {<br>
- adev->vcn.num_vcn_inst = VCN_INSTANCES_SIENNA_CICHLID;<br>
+ for (i = 0; i < VCN_INSTANCES_SIENNA_CICHLID; i++)<br>
+ if (amdgpu_vcn_is_disabled_vcn(adev, VCN_DECODE_RING, i))<br>
+ adev->vcn.num_vcn_inst++;<br>
adev->vcn.harvest_config = 0;<br>
adev->vcn.num_enc_rings = 1;<br>
<br>
} else {<br>
if (adev->asic_type == CHIP_SIENNA_CICHLID) {<br>
u32 harvest;<br>
- int i;<br>
<br>
adev->vcn.num_vcn_inst = VCN_INSTANCES_SIENNA_CICHLID;<br>
for (i = 0; i < adev->vcn.num_vcn_inst; i++) {<br>
@@ -149,7 +151,8 @@ static int vcn_v3_0_sw_init(void *handle)<br>
adev->firmware.fw_size +=<br>
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE);<br>
<br>
- if (adev->vcn.num_vcn_inst == VCN_INSTANCES_SIENNA_CICHLID) {<br>
+ if ((adev->vcn.num_vcn_inst == VCN_INSTANCES_SIENNA_CICHLID) ||<br>
+ (amdgpu_sriov_vf(adev) && adev->asic_type == CHIP_SIENNA_CICHLID)) {<br>
adev->firmware.ucode[AMDGPU_UCODE_ID_VCN1].ucode_id = AMDGPU_UCODE_ID_VCN1;<br>
adev->firmware.ucode[AMDGPU_UCODE_ID_VCN1].fw = adev->vcn.fw;<br>
adev->firmware.fw_size +=<br>
@@ -319,19 +322,17 @@ static int vcn_v3_0_hw_init(void *handle)<br>
continue;<br>
<br>
ring = &adev->vcn.inst[i].ring_dec;<br>
- if (ring->sched.ready) {<br>
- ring->wptr = 0;<br>
- ring->wptr_old = 0;<br>
- vcn_v3_0_dec_ring_set_wptr(ring);<br>
- }<br>
+ ring->wptr = 0;<br>
+ ring->wptr_old = 0;<br>
+ vcn_v3_0_dec_ring_set_wptr(ring);<br>
+ ring->sched.ready = true;<br>
<br>
for (j = 0; j < adev->vcn.num_enc_rings; ++j) {<br>
ring = &adev->vcn.inst[i].ring_enc[j];<br>
- if (ring->sched.ready) {<br>
- ring->wptr = 0;<br>
- ring->wptr_old = 0;<br>
- vcn_v3_0_enc_ring_set_wptr(ring);<br>
- }<br>
+ ring->wptr = 0;<br>
+ ring->wptr_old = 0;<br>
+ vcn_v3_0_enc_ring_set_wptr(ring);<br>
+ ring->sched.ready = true;<br>
}<br>
}<br>
} else {<br>
@@ -1298,8 +1299,6 @@ static int vcn_v3_0_start_sriov(struct amdgpu_device *adev)<br>
uint32_t table_size;<br>
uint32_t size, size_dw;<br>
<br>
- bool is_vcn_ready;<br>
-<br>
struct mmsch_v3_0_cmd_direct_write<br>
direct_wt = { {0} };<br>
struct mmsch_v3_0_cmd_direct_read_modify_write<br>
@@ -1491,30 +1490,6 @@ static int vcn_v3_0_start_sriov(struct amdgpu_device *adev)<br>
}<br>
}<br>
<br>
- /* 6, check each VCN's init_status<br>
- * if it remains as 0, then this VCN is not assigned to current VF<br>
- * do not start ring for this VCN<br>
- */<br>
- size = sizeof(struct mmsch_v3_0_init_header);<br>
- table_loc = (uint32_t *)table->cpu_addr;<br>
- memcpy(&header, (void *)table_loc, size);<br>
-<br>
- for (i = 0; i < adev->vcn.num_vcn_inst; i++) {<br>
- if (adev->vcn.harvest_config & (1 << i))<br>
- continue;<br>
-<br>
- is_vcn_ready = (header.inst[i].init_status == 1);<br>
- if (!is_vcn_ready)<br>
- DRM_INFO("VCN(%d) engine is disabled by hypervisor\n", i);<br>
-<br>
- ring = &adev->vcn.inst[i].ring_dec;<br>
- ring->sched.ready = is_vcn_ready;<br>
- for (j = 0; j < adev->vcn.num_enc_rings; ++j) {<br>
- ring = &adev->vcn.inst[i].ring_enc[j];<br>
- ring->sched.ready = is_vcn_ready;<br>
- }<br>
- }<br>
-<br>
return 0;<br>
}<br>
<br>
-- <br>
2.17.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&data=04%7C01%7Calexander.deucher%40amd.com%7C10420624e72c44cc5edd08d93163fe4e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637595127876624163%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=5MzzuTLBnE5tFffBAMinenV5MVHWOG0lZH3jAnBbvzg%3D&reserved=0">https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=04%7C01%7Calexander.deucher%40amd.com%7C10420624e72c44cc5edd08d93163fe4e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637595127876624163%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=5MzzuTLBnE5tFffBAMinenV5MVHWOG0lZH3jAnBbvzg%3D&reserved=0</a><br>
</div>
</span></font></div>
</div>
</body>
</html>