All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] drm/amd/amdgpu: Use IP discovery data to determine VCN enablement instead of MMSCH
@ 2021-06-03 10:42 Peng Ju Zhou
  2021-06-03 10:42 ` [PATCH 2/2] drm/amd/amdgpu: add instance_number check in amdgpu_discovery_get_ip_version Peng Ju Zhou
  2021-06-09 21:06 ` [PATCH 1/2] drm/amd/amdgpu: Use IP discovery data to determine VCN enablement instead of MMSCH Alex Deucher
  0 siblings, 2 replies; 6+ messages in thread
From: Peng Ju Zhou @ 2021-06-03 10:42 UTC (permalink / raw)
  To: amd-gfx; +Cc: Bokun Zhang

From: Bokun Zhang <Bokun.Zhang@amd.com>

In the past, we use MMSCH to determine whether a VCN is enabled or not.
This is not reliable since after a FLR, MMSCH may report junk data.

It is better to use IP discovery data.

Signed-off-by: Bokun Zhang <Bokun.Zhang@amd.com>
Signed-off-by: Peng Ju Zhou <PengJu.Zhou@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 73 +++++++++++++++++----------
 1 file changed, 45 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
index ce3c794c176f..92f88ea69035 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
@@ -27,6 +27,7 @@
 #include "amdgpu_pm.h"
 #include "soc15.h"
 #include "soc15d.h"
+#include "soc15_hw_ip.h"
 #include "vcn_v2_0.h"
 #include "mmsch_v3_0.h"
 
@@ -63,6 +64,17 @@ static int amdgpu_ucode_id_vcns[] = {
 	AMDGPU_UCODE_ID_VCN1
 };
 
+#define VCN_BLOCK_ENCODE_DISABLE_MASK 0x80
+#define VCN_BLOCK_DECODE_DISABLE_MASK 0x40
+#define VCN_BLOCK_QUEUE_DISABLE_MASK 0xC0
+
+enum vcn_ring_type {
+	VCN_ENCODE_RING,
+	VCN_DECODE_RING,
+	VCN_UNIFIED_RING,
+};
+
+static bool vcn_v3_0_is_disabled_vcn(struct amdgpu_device *adev, enum vcn_ring_type type, uint32_t vcn_instance);
 static int vcn_v3_0_start_sriov(struct amdgpu_device *adev);
 static void vcn_v3_0_set_dec_ring_funcs(struct amdgpu_device *adev);
 static void vcn_v3_0_set_enc_ring_funcs(struct amdgpu_device *adev);
@@ -324,18 +336,26 @@ static int vcn_v3_0_hw_init(void *handle)
 				continue;
 
 			ring = &adev->vcn.inst[i].ring_dec;
-			if (ring->sched.ready) {
+			if (vcn_v3_0_is_disabled_vcn(adev, VCN_DECODE_RING, i)) {
+				ring->sched.ready = false;
+				dev_info(adev->dev, "ring %s is disabled by hypervisor\n", ring->name);
+			} else {
 				ring->wptr = 0;
 				ring->wptr_old = 0;
 				vcn_v3_0_dec_ring_set_wptr(ring);
+				ring->sched.ready = true;
 			}
 
 			for (j = 0; j < adev->vcn.num_enc_rings; ++j) {
 				ring = &adev->vcn.inst[i].ring_enc[j];
-				if (ring->sched.ready) {
+				if (vcn_v3_0_is_disabled_vcn(adev, VCN_ENCODE_RING, i)) {
+					ring->sched.ready = false;
+					dev_info(adev->dev, "ring %s is disabled by hypervisor\n", ring->name);
+				} else {
 					ring->wptr = 0;
 					ring->wptr_old = 0;
 					vcn_v3_0_enc_ring_set_wptr(ring);
+					ring->sched.ready = true;
 				}
 			}
 		}
@@ -1286,6 +1306,29 @@ static int vcn_v3_0_start(struct amdgpu_device *adev)
 	return 0;
 }
 
+static bool vcn_v3_0_is_disabled_vcn(struct amdgpu_device *adev, enum vcn_ring_type type, uint32_t vcn_instance)
+{
+	bool ret = false;
+
+	int major;
+	int minor;
+	int revision;
+
+	/* if cannot find IP data, then this VCN does not exist */
+	if (amdgpu_discovery_get_ip_version(adev, VCN_HWID, vcn_instance, &major, &minor, &revision) != 0)
+		return true;
+
+	if ((type == VCN_ENCODE_RING) && (revision & VCN_BLOCK_ENCODE_DISABLE_MASK)) {
+		ret = true;
+	} else if ((type == VCN_DECODE_RING) && (revision & VCN_BLOCK_DECODE_DISABLE_MASK)) {
+		ret = true;
+	} else if ((type == VCN_UNIFIED_RING) && (revision & VCN_BLOCK_QUEUE_DISABLE_MASK)) {
+		ret = true;
+	}
+
+	return ret;
+}
+
 static int vcn_v3_0_start_sriov(struct amdgpu_device *adev)
 {
 	int i, j;
@@ -1303,8 +1346,6 @@ static int vcn_v3_0_start_sriov(struct amdgpu_device *adev)
 	uint32_t table_size;
 	uint32_t size, size_dw;
 
-	bool is_vcn_ready;
-
 	struct mmsch_v3_0_cmd_direct_write
 		direct_wt = { {0} };
 	struct mmsch_v3_0_cmd_direct_read_modify_write
@@ -1496,30 +1537,6 @@ static int vcn_v3_0_start_sriov(struct amdgpu_device *adev)
 		}
 	}
 
-	/* 6, check each VCN's init_status
-	 * if it remains as 0, then this VCN is not assigned to current VF
-	 * do not start ring for this VCN
-	 */
-	size = sizeof(struct mmsch_v3_0_init_header);
-	table_loc = (uint32_t *)table->cpu_addr;
-	memcpy(&header, (void *)table_loc, size);
-
-	for (i = 0; i < adev->vcn.num_vcn_inst; i++) {
-		if (adev->vcn.harvest_config & (1 << i))
-			continue;
-
-		is_vcn_ready = (header.inst[i].init_status == 1);
-		if (!is_vcn_ready)
-			DRM_INFO("VCN(%d) engine is disabled by hypervisor\n", i);
-
-		ring = &adev->vcn.inst[i].ring_dec;
-		ring->sched.ready = is_vcn_ready;
-		for (j = 0; j < adev->vcn.num_enc_rings; ++j) {
-			ring = &adev->vcn.inst[i].ring_enc[j];
-			ring->sched.ready = is_vcn_ready;
-		}
-	}
-
 	return 0;
 }
 
-- 
2.17.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] drm/amd/amdgpu: add instance_number check in amdgpu_discovery_get_ip_version
  2021-06-03 10:42 [PATCH 1/2] drm/amd/amdgpu: Use IP discovery data to determine VCN enablement instead of MMSCH Peng Ju Zhou
@ 2021-06-03 10:42 ` Peng Ju Zhou
  2021-06-07  8:13   ` Zhou, Peng Ju
  2021-06-09 21:08   ` Alex Deucher
  2021-06-09 21:06 ` [PATCH 1/2] drm/amd/amdgpu: Use IP discovery data to determine VCN enablement instead of MMSCH Alex Deucher
  1 sibling, 2 replies; 6+ messages in thread
From: Peng Ju Zhou @ 2021-06-03 10:42 UTC (permalink / raw)
  To: amd-gfx; +Cc: Bokun Zhang

The original code returns IP version of instantce_0 for every IP. This implementation may be correct for most of IPs.

However, for certain IP block (VCN for example), it may have 2 instances and
both of them have the same hw_id, BUT they have different revision number (0 and 1).

In this case, the original amdgpu_discovery_get_ip_version cannot correct reflects
the result and returns false information

Signed-off-by: Bokun Zhang <Bokun.Zhang@amd.com>
Signed-off-by: Peng Ju Zhou <PengJu.Zhou@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
index 99255c2f08f4..f949ed8bfd9e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
@@ -325,7 +325,7 @@ int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev)
 	return 0;
 }
 
-int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int hw_id,
+int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int hw_id, int number_instance,
 				    int *major, int *minor, int *revision)
 {
 	struct binary_header *bhdr;
@@ -357,7 +357,7 @@ int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int hw_id,
 		for (j = 0; j < num_ips; j++) {
 			ip = (struct ip *)(adev->mman.discovery_bin + ip_offset);
 
-			if (le16_to_cpu(ip->hw_id) == hw_id) {
+			if ((le16_to_cpu(ip->hw_id) == hw_id) && (ip->number_instance == number_instance)) {
 				if (major)
 					*major = ip->major;
 				if (minor)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
index 1b1ae21b1037..02e340cd3a38 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
@@ -30,7 +30,7 @@
 void amdgpu_discovery_fini(struct amdgpu_device *adev);
 int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev);
 void amdgpu_discovery_harvest_ip(struct amdgpu_device *adev);
-int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int hw_id,
+int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int hw_id, int number_instance,
                                     int *major, int *minor, int *revision);
 int amdgpu_discovery_get_gfx_info(struct amdgpu_device *adev);
 
-- 
2.17.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* RE: [PATCH 2/2] drm/amd/amdgpu: add instance_number check in amdgpu_discovery_get_ip_version
  2021-06-03 10:42 ` [PATCH 2/2] drm/amd/amdgpu: add instance_number check in amdgpu_discovery_get_ip_version Peng Ju Zhou
@ 2021-06-07  8:13   ` Zhou, Peng Ju
  2021-06-09 10:56     ` Zhou, Peng Ju
  2021-06-09 21:08   ` Alex Deucher
  1 sibling, 1 reply; 6+ messages in thread
From: Zhou, Peng Ju @ 2021-06-07  8:13 UTC (permalink / raw)
  To: Zhou, Peng Ju, amd-gfx, Deucher, Alexander; +Cc: Zhang, Bokun

[AMD Official Use Only]

Hi Alex
The following patch series were ported from amd-staging-dkms to fix VCN IB test fail.
Can you help to review it?

[PATCH 1/2] drm/amd/amdgpu: Use IP discovery data to determine VCN enablement instead of MMSCH
[PATCH 2/2] drm/amd/amdgpu: add instance_number check in amdgpu_discovery_get_ip_version


---------------------------------------------------------------------- 
BW
Pengju Zhou

 

> -----Original Message-----
> From: Peng Ju Zhou <PengJu.Zhou@amd.com>
> Sent: Thursday, June 3, 2021 6:42 PM
> To: amd-gfx@lists.freedesktop.org
> Cc: Zhou, Peng Ju <PengJu.Zhou@amd.com>; Zhang, Bokun
> <Bokun.Zhang@amd.com>
> Subject: [PATCH 2/2] drm/amd/amdgpu: add instance_number check in
> amdgpu_discovery_get_ip_version
> 
> The original code returns IP version of instantce_0 for every IP. This
> implementation may be correct for most of IPs.
> 
> However, for certain IP block (VCN for example), it may have 2 instances and
> both of them have the same hw_id, BUT they have different revision number
> (0 and 1).
> 
> In this case, the original amdgpu_discovery_get_ip_version cannot correct
> reflects the result and returns false information
> 
> Signed-off-by: Bokun Zhang <Bokun.Zhang@amd.com>
> Signed-off-by: Peng Ju Zhou <PengJu.Zhou@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 4 ++--
> drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> index 99255c2f08f4..f949ed8bfd9e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> @@ -325,7 +325,7 @@ int amdgpu_discovery_reg_base_init(struct
> amdgpu_device *adev)
>  	return 0;
>  }
> 
> -int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int hw_id,
> +int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int
> +hw_id, int number_instance,
>  				    int *major, int *minor, int *revision)  {
>  	struct binary_header *bhdr;
> @@ -357,7 +357,7 @@ int amdgpu_discovery_get_ip_version(struct
> amdgpu_device *adev, int hw_id,
>  		for (j = 0; j < num_ips; j++) {
>  			ip = (struct ip *)(adev->mman.discovery_bin +
> ip_offset);
> 
> -			if (le16_to_cpu(ip->hw_id) == hw_id) {
> +			if ((le16_to_cpu(ip->hw_id) == hw_id) && (ip-
> >number_instance ==
> +number_instance)) {
>  				if (major)
>  					*major = ip->major;
>  				if (minor)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
> index 1b1ae21b1037..02e340cd3a38 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
> @@ -30,7 +30,7 @@
>  void amdgpu_discovery_fini(struct amdgpu_device *adev);  int
> amdgpu_discovery_reg_base_init(struct amdgpu_device *adev);  void
> amdgpu_discovery_harvest_ip(struct amdgpu_device *adev); -int
> amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int hw_id,
> +int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int
> +hw_id, int number_instance,
>                                      int *major, int *minor, int *revision);  int
> amdgpu_discovery_get_gfx_info(struct amdgpu_device *adev);
> 
> --
> 2.17.1
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH 2/2] drm/amd/amdgpu: add instance_number check in amdgpu_discovery_get_ip_version
  2021-06-07  8:13   ` Zhou, Peng Ju
@ 2021-06-09 10:56     ` Zhou, Peng Ju
  0 siblings, 0 replies; 6+ messages in thread
From: Zhou, Peng Ju @ 2021-06-09 10:56 UTC (permalink / raw)
  To: amd-gfx, Deucher,  Alexander; +Cc: Zhang, Bokun

[AMD Official Use Only]

Ping on this series

--------------------------
Pengju Zhou

> -----Original Message-----
> From: Zhou, Peng Ju <PengJu.Zhou@amd.com>
> Sent: Monday, June 7, 2021 4:13 PM
> To: Zhou, Peng Ju <PengJu.Zhou@amd.com>; amd-gfx@lists.freedesktop.org;
> Deucher, Alexander <Alexander.Deucher@amd.com>
> Cc: Zhang, Bokun <Bokun.Zhang@amd.com>
> Subject: RE: [PATCH 2/2] drm/amd/amdgpu: add instance_number check in
> amdgpu_discovery_get_ip_version
> 
> [AMD Official Use Only]
> 
> Hi Alex
> The following patch series were ported from amd-staging-dkms to fix VCN IB
> test fail.
> Can you help to review it?
> 
> [PATCH 1/2] drm/amd/amdgpu: Use IP discovery data to determine VCN
> enablement instead of MMSCH [PATCH 2/2] drm/amd/amdgpu: add
> instance_number check in amdgpu_discovery_get_ip_version
> 
> 
> ----------------------------------------------------------------------
> BW
> Pengju Zhou
> 
> 
> 
> > -----Original Message-----
> > From: Peng Ju Zhou <PengJu.Zhou@amd.com>
> > Sent: Thursday, June 3, 2021 6:42 PM
> > To: amd-gfx@lists.freedesktop.org
> > Cc: Zhou, Peng Ju <PengJu.Zhou@amd.com>; Zhang, Bokun
> > <Bokun.Zhang@amd.com>
> > Subject: [PATCH 2/2] drm/amd/amdgpu: add instance_number check in
> > amdgpu_discovery_get_ip_version
> >
> > The original code returns IP version of instantce_0 for every IP. This
> > implementation may be correct for most of IPs.
> >
> > However, for certain IP block (VCN for example), it may have 2
> > instances and both of them have the same hw_id, BUT they have
> > different revision number
> > (0 and 1).
> >
> > In this case, the original amdgpu_discovery_get_ip_version cannot
> > correct reflects the result and returns false information
> >
> > Signed-off-by: Bokun Zhang <Bokun.Zhang@amd.com>
> > Signed-off-by: Peng Ju Zhou <PengJu.Zhou@amd.com>
> > ---
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 4 ++--
> > drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h | 2 +-
> >  2 files changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> > index 99255c2f08f4..f949ed8bfd9e 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> > @@ -325,7 +325,7 @@ int amdgpu_discovery_reg_base_init(struct
> > amdgpu_device *adev)
> >  	return 0;
> >  }
> >
> > -int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int
> > hw_id,
> > +int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int
> > +hw_id, int number_instance,
> >  				    int *major, int *minor, int *revision)  {
> >  	struct binary_header *bhdr;
> > @@ -357,7 +357,7 @@ int amdgpu_discovery_get_ip_version(struct
> > amdgpu_device *adev, int hw_id,
> >  		for (j = 0; j < num_ips; j++) {
> >  			ip = (struct ip *)(adev->mman.discovery_bin +
> ip_offset);
> >
> > -			if (le16_to_cpu(ip->hw_id) == hw_id) {
> > +			if ((le16_to_cpu(ip->hw_id) == hw_id) && (ip-
> > >number_instance ==
> > +number_instance)) {
> >  				if (major)
> >  					*major = ip->major;
> >  				if (minor)
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
> > index 1b1ae21b1037..02e340cd3a38 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
> > @@ -30,7 +30,7 @@
> >  void amdgpu_discovery_fini(struct amdgpu_device *adev);  int
> > amdgpu_discovery_reg_base_init(struct amdgpu_device *adev);  void
> > amdgpu_discovery_harvest_ip(struct amdgpu_device *adev); -int
> > amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int hw_id,
> > +int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int
> > +hw_id, int number_instance,
> >                                      int *major, int *minor, int
> > *revision);  int amdgpu_discovery_get_gfx_info(struct amdgpu_device
> > *adev);
> >
> > --
> > 2.17.1
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] drm/amd/amdgpu: Use IP discovery data to determine VCN enablement instead of MMSCH
  2021-06-03 10:42 [PATCH 1/2] drm/amd/amdgpu: Use IP discovery data to determine VCN enablement instead of MMSCH Peng Ju Zhou
  2021-06-03 10:42 ` [PATCH 2/2] drm/amd/amdgpu: add instance_number check in amdgpu_discovery_get_ip_version Peng Ju Zhou
@ 2021-06-09 21:06 ` Alex Deucher
  1 sibling, 0 replies; 6+ messages in thread
From: Alex Deucher @ 2021-06-09 21:06 UTC (permalink / raw)
  To: Peng Ju Zhou; +Cc: Bokun Zhang, amd-gfx list

On Thu, Jun 3, 2021 at 6:42 AM Peng Ju Zhou <PengJu.Zhou@amd.com> wrote:
>
> From: Bokun Zhang <Bokun.Zhang@amd.com>
>
> In the past, we use MMSCH to determine whether a VCN is enabled or not.
> This is not reliable since after a FLR, MMSCH may report junk data.
>
> It is better to use IP discovery data.
>
> Signed-off-by: Bokun Zhang <Bokun.Zhang@amd.com>
> Signed-off-by: Peng Ju Zhou <PengJu.Zhou@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 73 +++++++++++++++++----------
>  1 file changed, 45 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
> index ce3c794c176f..92f88ea69035 100644
> --- a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
> @@ -27,6 +27,7 @@
>  #include "amdgpu_pm.h"
>  #include "soc15.h"
>  #include "soc15d.h"
> +#include "soc15_hw_ip.h"
>  #include "vcn_v2_0.h"
>  #include "mmsch_v3_0.h"
>
> @@ -63,6 +64,17 @@ static int amdgpu_ucode_id_vcns[] = {
>         AMDGPU_UCODE_ID_VCN1
>  };
>
> +#define VCN_BLOCK_ENCODE_DISABLE_MASK 0x80
> +#define VCN_BLOCK_DECODE_DISABLE_MASK 0x40
> +#define VCN_BLOCK_QUEUE_DISABLE_MASK 0xC0
> +
> +enum vcn_ring_type {
> +       VCN_ENCODE_RING,
> +       VCN_DECODE_RING,
> +       VCN_UNIFIED_RING,
> +};
> +
> +static bool vcn_v3_0_is_disabled_vcn(struct amdgpu_device *adev, enum vcn_ring_type type, uint32_t vcn_instance);
>  static int vcn_v3_0_start_sriov(struct amdgpu_device *adev);
>  static void vcn_v3_0_set_dec_ring_funcs(struct amdgpu_device *adev);
>  static void vcn_v3_0_set_enc_ring_funcs(struct amdgpu_device *adev);
> @@ -324,18 +336,26 @@ static int vcn_v3_0_hw_init(void *handle)
>                                 continue;
>
>                         ring = &adev->vcn.inst[i].ring_dec;
> -                       if (ring->sched.ready) {
> +                       if (vcn_v3_0_is_disabled_vcn(adev, VCN_DECODE_RING, i)) {
> +                               ring->sched.ready = false;
> +                               dev_info(adev->dev, "ring %s is disabled by hypervisor\n", ring->name);
> +                       } else {
>                                 ring->wptr = 0;
>                                 ring->wptr_old = 0;
>                                 vcn_v3_0_dec_ring_set_wptr(ring);
> +                               ring->sched.ready = true;
>                         }
>
>                         for (j = 0; j < adev->vcn.num_enc_rings; ++j) {
>                                 ring = &adev->vcn.inst[i].ring_enc[j];
> -                               if (ring->sched.ready) {
> +                               if (vcn_v3_0_is_disabled_vcn(adev, VCN_ENCODE_RING, i)) {
> +                                       ring->sched.ready = false;
> +                                       dev_info(adev->dev, "ring %s is disabled by hypervisor\n", ring->name);
> +                               } else {
>                                         ring->wptr = 0;
>                                         ring->wptr_old = 0;
>                                         vcn_v3_0_enc_ring_set_wptr(ring);
> +                                       ring->sched.ready = true;


I think it would be cleaner to use the IP discovery data in
vcn_v3_0_early_init() to set the harvest config and just use that
here.


>                                 }
>                         }
>                 }
> @@ -1286,6 +1306,29 @@ static int vcn_v3_0_start(struct amdgpu_device *adev)
>         return 0;
>  }
>
> +static bool vcn_v3_0_is_disabled_vcn(struct amdgpu_device *adev, enum vcn_ring_type type, uint32_t vcn_instance)
> +{
> +       bool ret = false;
> +
> +       int major;
> +       int minor;
> +       int revision;
> +
> +       /* if cannot find IP data, then this VCN does not exist */
> +       if (amdgpu_discovery_get_ip_version(adev, VCN_HWID, vcn_instance, &major, &minor, &revision) != 0)
> +               return true;
> +
> +       if ((type == VCN_ENCODE_RING) && (revision & VCN_BLOCK_ENCODE_DISABLE_MASK)) {
> +               ret = true;
> +       } else if ((type == VCN_DECODE_RING) && (revision & VCN_BLOCK_DECODE_DISABLE_MASK)) {
> +               ret = true;
> +       } else if ((type == VCN_UNIFIED_RING) && (revision & VCN_BLOCK_QUEUE_DISABLE_MASK)) {
> +               ret = true;
> +       }
> +
> +       return ret;
> +}
> +

I don't think this is VCN 3.0 specific.  This could probably be moved
to amdgpu_vcn.c or amdgpu_discovery.c

Alex

>  static int vcn_v3_0_start_sriov(struct amdgpu_device *adev)
>  {
>         int i, j;
> @@ -1303,8 +1346,6 @@ static int vcn_v3_0_start_sriov(struct amdgpu_device *adev)
>         uint32_t table_size;
>         uint32_t size, size_dw;
>
> -       bool is_vcn_ready;
> -
>         struct mmsch_v3_0_cmd_direct_write
>                 direct_wt = { {0} };
>         struct mmsch_v3_0_cmd_direct_read_modify_write
> @@ -1496,30 +1537,6 @@ static int vcn_v3_0_start_sriov(struct amdgpu_device *adev)
>                 }
>         }
>
> -       /* 6, check each VCN's init_status
> -        * if it remains as 0, then this VCN is not assigned to current VF
> -        * do not start ring for this VCN
> -        */
> -       size = sizeof(struct mmsch_v3_0_init_header);
> -       table_loc = (uint32_t *)table->cpu_addr;
> -       memcpy(&header, (void *)table_loc, size);
> -
> -       for (i = 0; i < adev->vcn.num_vcn_inst; i++) {
> -               if (adev->vcn.harvest_config & (1 << i))
> -                       continue;
> -
> -               is_vcn_ready = (header.inst[i].init_status == 1);
> -               if (!is_vcn_ready)
> -                       DRM_INFO("VCN(%d) engine is disabled by hypervisor\n", i);
> -
> -               ring = &adev->vcn.inst[i].ring_dec;
> -               ring->sched.ready = is_vcn_ready;
> -               for (j = 0; j < adev->vcn.num_enc_rings; ++j) {
> -                       ring = &adev->vcn.inst[i].ring_enc[j];
> -                       ring->sched.ready = is_vcn_ready;
> -               }
> -       }
> -
>         return 0;
>  }
>
> --
> 2.17.1
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] drm/amd/amdgpu: add instance_number check in amdgpu_discovery_get_ip_version
  2021-06-03 10:42 ` [PATCH 2/2] drm/amd/amdgpu: add instance_number check in amdgpu_discovery_get_ip_version Peng Ju Zhou
  2021-06-07  8:13   ` Zhou, Peng Ju
@ 2021-06-09 21:08   ` Alex Deucher
  1 sibling, 0 replies; 6+ messages in thread
From: Alex Deucher @ 2021-06-09 21:08 UTC (permalink / raw)
  To: Peng Ju Zhou; +Cc: Bokun Zhang, amd-gfx list

On Thu, Jun 3, 2021 at 6:42 AM Peng Ju Zhou <PengJu.Zhou@amd.com> wrote:
>
> The original code returns IP version of instantce_0 for every IP. This implementation may be correct for most of IPs.
>
> However, for certain IP block (VCN for example), it may have 2 instances and
> both of them have the same hw_id, BUT they have different revision number (0 and 1).
>
> In this case, the original amdgpu_discovery_get_ip_version cannot correct reflects
> the result and returns false information
>
> Signed-off-by: Bokun Zhang <Bokun.Zhang@amd.com>
> Signed-off-by: Peng Ju Zhou <PengJu.Zhou@amd.com>

This patch is:
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 4 ++--
>  drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> index 99255c2f08f4..f949ed8bfd9e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> @@ -325,7 +325,7 @@ int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev)
>         return 0;
>  }
>
> -int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int hw_id,
> +int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int hw_id, int number_instance,
>                                     int *major, int *minor, int *revision)
>  {
>         struct binary_header *bhdr;
> @@ -357,7 +357,7 @@ int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int hw_id,
>                 for (j = 0; j < num_ips; j++) {
>                         ip = (struct ip *)(adev->mman.discovery_bin + ip_offset);
>
> -                       if (le16_to_cpu(ip->hw_id) == hw_id) {
> +                       if ((le16_to_cpu(ip->hw_id) == hw_id) && (ip->number_instance == number_instance)) {
>                                 if (major)
>                                         *major = ip->major;
>                                 if (minor)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
> index 1b1ae21b1037..02e340cd3a38 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
> @@ -30,7 +30,7 @@
>  void amdgpu_discovery_fini(struct amdgpu_device *adev);
>  int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev);
>  void amdgpu_discovery_harvest_ip(struct amdgpu_device *adev);
> -int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int hw_id,
> +int amdgpu_discovery_get_ip_version(struct amdgpu_device *adev, int hw_id, int number_instance,
>                                      int *major, int *minor, int *revision);
>  int amdgpu_discovery_get_gfx_info(struct amdgpu_device *adev);
>
> --
> 2.17.1
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-06-09 21:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-03 10:42 [PATCH 1/2] drm/amd/amdgpu: Use IP discovery data to determine VCN enablement instead of MMSCH Peng Ju Zhou
2021-06-03 10:42 ` [PATCH 2/2] drm/amd/amdgpu: add instance_number check in amdgpu_discovery_get_ip_version Peng Ju Zhou
2021-06-07  8:13   ` Zhou, Peng Ju
2021-06-09 10:56     ` Zhou, Peng Ju
2021-06-09 21:08   ` Alex Deucher
2021-06-09 21:06 ` [PATCH 1/2] drm/amd/amdgpu: Use IP discovery data to determine VCN enablement instead of MMSCH Alex Deucher

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.