Skip to contentSkip to conversation

Revert "drm/amdgpu: don't read registers if gfxoff is enabled (v2)"

PATCH In review Alex Deucher 4 participants 14 messages Nov 14, 2019 – Nov 19, 2019 9 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Revert "drm/amdgpu: don't read registers if gfxoff is enabled (v2)"

This reverts commit 5e49d6f654c569c2de920babbaf5cf7c4c4a353f.

Drop this workaround in favor of a better one.

---
 drivers/gpu/drm/amd/amdgpu/nv.c    | 27 ++++++++++----------------
 drivers/gpu/drm/amd/amdgpu/soc15.c | 31 ++++++++++++------------------
 2 files changed, 22 insertions(+), 36 deletions(-)
drivers/gpu/drm/amd/amdgpu/nv.c +10 -17
index 7283d6198b89..af68f9815f28 100644
@@ -201,25 +201,17 @@ static uint32_t nv_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
 	return val;
 }
 
-static int nv_get_register_value(struct amdgpu_device *adev,
+static uint32_t nv_get_register_value(struct amdgpu_device *adev,
 				      bool indexed, u32 se_num,
-				      u32 sh_num, u32 reg_offset,
-				      u32 *value)
+				      u32 sh_num, u32 reg_offset)
 {
 	if (indexed) {
-		if (adev->pm.pp_feature & PP_GFXOFF_MASK)
-			return -EINVAL;
-		*value = nv_read_indexed_register(adev, se_num, sh_num, reg_offset);
+		return nv_read_indexed_register(adev, se_num, sh_num, reg_offset);
 	} else {
-		if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG)) {
-			*value = adev->gfx.config.gb_addr_config;
-		} else {
-			if (adev->pm.pp_feature & PP_GFXOFF_MASK)
-				return -EINVAL;
-			*value = RREG32(reg_offset);
-		}
+		if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG))
+			return adev->gfx.config.gb_addr_config;
+		return RREG32(reg_offset);
 	}
-	return 0;
 }
 
 static int nv_read_register(struct amdgpu_device *adev, u32 se_num,
@@ -235,9 +227,10 @@ static int nv_read_register(struct amdgpu_device *adev, u32 se_num,
 		    (adev->reg_offset[en->hwip][en->inst][en->seg] + en->reg_offset))
 			continue;
 
-		return nv_get_register_value(adev,
-					     nv_allowed_read_registers[i].grbm_indexed,
-					     se_num, sh_num, reg_offset, value);
+		*value = nv_get_register_value(adev,
+					       nv_allowed_read_registers[i].grbm_indexed,
+					       se_num, sh_num, reg_offset);
+		return 0;
 	}
 	return -EINVAL;
 }
drivers/gpu/drm/amd/amdgpu/soc15.c +12 -19
index 3b55655f79c4..8e1640bc07af 100644
@@ -363,27 +363,19 @@ static uint32_t soc15_read_indexed_register(struct amdgpu_device *adev, u32 se_n
 	return val;
 }
 
-static int soc15_get_register_value(struct amdgpu_device *adev,
+static uint32_t soc15_get_register_value(struct amdgpu_device *adev,
 					 bool indexed, u32 se_num,
-					 u32 sh_num, u32 reg_offset,
-					 u32 *value)
+					 u32 sh_num, u32 reg_offset)
 {
 	if (indexed) {
-		if (adev->pm.pp_feature & PP_GFXOFF_MASK)
-			return -EINVAL;
-	        *value = soc15_read_indexed_register(adev, se_num, sh_num, reg_offset);
+		return soc15_read_indexed_register(adev, se_num, sh_num, reg_offset);
 	} else {
-		if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG)) {
-			*value = adev->gfx.config.gb_addr_config;
-		} else if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmDB_DEBUG2)) {
-			*value = adev->gfx.config.db_debug2;
-		} else {
-			if (adev->pm.pp_feature & PP_GFXOFF_MASK)
-				return -EINVAL;
-			*value = RREG32(reg_offset);
-		}
+		if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG))
+			return adev->gfx.config.gb_addr_config;
+		else if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmDB_DEBUG2))
+			return adev->gfx.config.db_debug2;
+		return RREG32(reg_offset);
 	}
-	return 0;
 }
 
 static int soc15_read_register(struct amdgpu_device *adev, u32 se_num,
@@ -399,9 +391,10 @@ static int soc15_read_register(struct amdgpu_device *adev, u32 se_num,
 					+ en->reg_offset))
 			continue;
 
-		return soc15_get_register_value(adev,
-						soc15_allowed_read_registers[i].grbm_indexed,
-						se_num, sh_num, reg_offset, value);
+		*value = soc15_get_register_value(adev,
+						  soc15_allowed_read_registers[i].grbm_indexed,
+						  se_num, sh_num, reg_offset);
+		return 0;
 	}
 	return -EINVAL;
 }
Signature · 6 lines
2.23.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20191114164148.2304223-1-alexander.deucher-5C7GfCeVMHo@public.gmane.org

#2 lore raw

PATCH 2/2 drm/amdgpu: disable gfxoff when using register read interface

When gfxoff is enabled, accessing gfx registers via MMIO can lead to a hang.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -1
index 6ddea7607ad0..5f3b3a705b29 100644
@@ -659,15 +659,19 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
 			return -ENOMEM;
 		alloc_size = info->read_mmr_reg.count * sizeof(*regs);
 
-		for (i = 0; i < info->read_mmr_reg.count; i++)
+		amdgpu_gfx_off_ctrl(adev, false);
+		for (i = 0; i < info->read_mmr_reg.count; i++) {
 			if (amdgpu_asic_read_register(adev, se_num, sh_num,
 						      info->read_mmr_reg.dword_offset + i,
 						      &regs[i])) {
 				DRM_DEBUG_KMS("unallowed offset %#x\n",
 					      info->read_mmr_reg.dword_offset + i);
 				kfree(regs);
+				amdgpu_gfx_off_ctrl(adev, true);
 				return -EFAULT;
 			}
+		}
+		amdgpu_gfx_off_ctrl(adev, true);
 		n = copy_to_user(out, regs, min(size, alloc_size));
 		kfree(regs);
 		return n ? -EFAULT : 0;
Signature · 6 lines
2.23.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20191114164148.2304223-2-alexander.deucher-5C7GfCeVMHo@public.gmane.org

#4 lore raw

Re: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

Ping?

Quoted 36 lines · Alex Deucher

When gfxoff is enabled, accessing gfx registers via MMIO can lead to a hang.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -2
index 6ddea7607ad0..5f3b3a705b29 100644
@@ -659,15 +659,19 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
                        return -ENOMEM;
                alloc_size = info->read_mmr_reg.count * sizeof(*regs);
 
-               for (i = 0; i < info->read_mmr_reg.count; i++)
+               amdgpu_gfx_off_ctrl(adev, false);
+               for (i = 0; i < info->read_mmr_reg.count; i++) {
                        if (amdgpu_asic_read_register(adev, se_num, sh_num,
                                                      info->read_mmr_reg.dword_offset + i,
                                                      &regs[i])) {
                                DRM_DEBUG_KMS("unallowed offset %#x\n",
                                              info->read_mmr_reg.dword_offset + i);
                                kfree(regs);
+                               amdgpu_gfx_off_ctrl(adev, true);
                                return -EFAULT;
                        }
+               }
+               amdgpu_gfx_off_ctrl(adev, true);
                n = copy_to_user(out, regs, min(size, alloc_size));
                kfree(regs);
                return n ? -EFAULT : 0;
--
Quoted 2 lines

2.23.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#5 lore raw

Re: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

In reply to a message not in the archive

Hi Alex,

IMHO, driver sending Disallow_Gfxoff message to SMU doesn't mean gfx block will be immediately powered up, so I'm not sure MMIO register access will be successful within this time window(maybe GRBM access will be pending until gfx block is powered up?)

If you are not in a hurry to commit this fix, I can verify on my Navi boards next Monday.

BR,
Xiaojie

Quoted 43 lines · Alex Deucher

When gfxoff is enabled, accessing gfx registers via MMIO can lead to a hang.

---
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -1
index 6ddea7607ad0..5f3b3a705b29 100644
@@ -659,15 +659,19 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
           return -ENOMEM;
       alloc_size = info->read_mmr_reg.count * sizeof(*regs);
 
-        for (i = 0; i < info->read_mmr_reg.count; i++)
+        amdgpu_gfx_off_ctrl(adev, false);
+        for (i = 0; i < info->read_mmr_reg.count; i++) {
           if (amdgpu_asic_read_register(adev, se_num, sh_num,
                             info->read_mmr_reg.dword_offset + i,
                             &regs[i])) {
               DRM_DEBUG_KMS("unallowed offset %#x\n",
                         info->read_mmr_reg.dword_offset + i);
               kfree(regs);
+                amdgpu_gfx_off_ctrl(adev, true);
               return -EFAULT;
           }
+        }
+        amdgpu_gfx_off_ctrl(adev, true);
       n = copy_to_user(out, regs, min(size, alloc_size));
       kfree(regs);
       return n ? -EFAULT : 0;
Signature · 6 lines
2.23.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 93CD6C6F-21F7-4BCA-AC65-FDC37AF896E3-5C7GfCeVMHo@public.gmane.org

#7 lore raw

Re: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

Quoted 6 lines · Xiaojie

Hi Alex,

IMHO, driver sending Disallow_Gfxoff message to SMU doesn't mean gfx block will be immediately powered up, so I'm not sure MMIO register access will be successful within this time window(maybe GRBM access will be pending until gfx block is powered up?)

If you are not in a hurry to commit this fix, I can verify on my Navi boards next Monday.

That would be great. Maybe we can add a delay in that function to take that into account?

Thanks!

Alex

Quoted 43 lines

BR,
Xiaojie

Quoted 39 lines · Alex Deucher

When gfxoff is enabled, accessing gfx registers via MMIO can lead to a hang.

---
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -2
index 6ddea7607ad0..5f3b3a705b29 100644
@@ -659,15 +659,19 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
           return -ENOMEM;
       alloc_size = info->read_mmr_reg.count * sizeof(*regs);
 
-        for (i = 0; i < info->read_mmr_reg.count; i++)
+        amdgpu_gfx_off_ctrl(adev, false);
+        for (i = 0; i < info->read_mmr_reg.count; i++) {
           if (amdgpu_asic_read_register(adev, se_num, sh_num,
                             info->read_mmr_reg.dword_offset + i,
                             &regs[i])) {
               DRM_DEBUG_KMS("unallowed offset %#x\n",
                         info->read_mmr_reg.dword_offset + i);
               kfree(regs);
+                amdgpu_gfx_off_ctrl(adev, true);
               return -EFAULT;
           }
+        }
+        amdgpu_gfx_off_ctrl(adev, true);
       n = copy_to_user(out, regs, min(size, alloc_size));
       kfree(regs);
       return n ? -EFAULT : 0;
--

2.23.0

Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CADnq5_McjfD_ZJHa_RFzfRuxFzjSkG7C1S1VhtYNPHH_f9MViA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#9 lore raw

Re: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

Yes. IIRC, some asics' amdgpu_gfx_ctrl() is implemented as synchronous (upon function returns, gfx block is guaranteed to be in power-up state). Anyway, let me confirm about that soon.

BR,
Xiaojie

Quoted 60 lines · Alex Deucher
Quoted 8 lines · Xiaojie

Hi Alex,

IMHO, driver sending Disallow_Gfxoff message to SMU doesn't mean gfx block will be immediately powered up, so I'm not sure MMIO register access will be successful within this time window(maybe GRBM access will be pending until gfx block is powered up?)

If you are not in a hurry to commit this fix, I can verify on my Navi boards next Monday.

That would be great. Maybe we can add a delay in that function to take that into account?

Thanks!

Alex

Quoted 43 lines

BR,
Xiaojie

Quoted 39 lines · Alex Deucher

When gfxoff is enabled, accessing gfx registers via MMIO can lead to a hang.

---
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -2
index 6ddea7607ad0..5f3b3a705b29 100644
@@ -659,15 +659,19 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
          return -ENOMEM;
      alloc_size = info->read_mmr_reg.count * sizeof(*regs);
 
-        for (i = 0; i < info->read_mmr_reg.count; i++)
+        amdgpu_gfx_off_ctrl(adev, false);
+        for (i = 0; i < info->read_mmr_reg.count; i++) {
          if (amdgpu_asic_read_register(adev, se_num, sh_num,
                            info->read_mmr_reg.dword_offset + i,
                            &regs[i])) {
              DRM_DEBUG_KMS("unallowed offset %#x\n",
                        info->read_mmr_reg.dword_offset + i);
              kfree(regs);
+                amdgpu_gfx_off_ctrl(adev, true);
              return -EFAULT;
          }
+        }
+        amdgpu_gfx_off_ctrl(adev, true);
      n = copy_to_user(out, regs, min(size, alloc_size));
      kfree(regs);
      return n ? -EFAULT : 0;
--

2.23.0

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 7F901A1C-E7F6-40A1-ACFE-630ECCA24104-5C7GfCeVMHo@public.gmane.org

#11 lore raw

Re: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

Hi Alex,

I tried on Navi14 with Gfxoff enabled (gfx in 'OFF' state when I run the test program) and used a test program to read GRBM_STATUS/CP_STAT/GB_ADDR_CONFIG via DRM_IOCTL_AMDGPU_INFO.

All read out values are valid as below (in this read cycle, I saw gfx block is first awakened and then powered off again automatically):

drm version: 3.36.0
grbm_status: 0x00003028
cp_stat: 0x00000000
gb_addr_config: 0x00000043

At least for Navi, reading register when gfxoff seems not a problem...

Test program:

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <libdrm/drm.h>
#include <libdrm/amdgpu_drm.h>

int get_reg_val(int fd, int reg_offset, int *val)

{
        struct drm_amdgpu_info request;
        int r;

        memset(&request, 0, sizeof(request));
        request.return_pointer = (uintptr_t)val;
        request.return_size = sizeof(uint32_t);
        request.query = AMDGPU_INFO_READ_MMR_REG;
        request.read_mmr_reg.dword_offset = reg_offset;
        request.read_mmr_reg.count = 1;
        request.read_mmr_reg.instance = 0xffffffff;
        request.read_mmr_reg.flags = 0;

        r = ioctl(fd, DRM_IOCTL_AMDGPU_INFO, &request);
        if (r < 0) {
                perror("failed to read register");
                return -errno;
        }

        return 0;
}

int main(int argc, const char *argv[])

{
        const char *device = "/dev/dri/card0";
        int fd;
        int r;
        struct drm_version version;
        struct drm_auth auth;
        int cp_stat;
        int grbm_status;
        int gb_addr_config;

        fd = open(device, O_RDWR | O_CLOEXEC);
        if (fd < 0) {
                perror("failed to open device\n");
                return -errno;
        }

        memset(&version, 0, sizeof(version));

        r = ioctl(fd, DRM_IOCTL_VERSION, &version);
        if (r < 0) {
                perror("failed to get drm version");
                r = -errno;
                goto close;
        }

        printf("drm version: %d.%d.%d\n", version.version_major,
                                          version.version_minor,
                                          version.version_patchlevel);

        r = get_reg_val(fd, 0x2004, &grbm_status);
        if (r < 0)
                goto close;
        printf("grbm_status: 0x%08x\n", grbm_status);

        r = get_reg_val(fd, 0x21a0, &cp_stat);
        if (r < 0)
                goto close;
        printf("cp_stat: 0x%08x\n", cp_stat);

        r = get_reg_val(fd, 0x263e, &gb_addr_config);
        if (r < 0)
                goto close;
        printf("gb_addr_config: 0x%08x\n", gb_addr_config);

close:

        close(fd);

        return r;
}

BR,
Xiaojie

________________________________________
From: amd-gfx <[email protected]> on behalf of Yuan, Xiaojie <[email protected]>
Sent: Saturday, November 16, 2019 1:02 AM
To: Alex Deucher
Cc: Deucher, Alexander; [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

Yes. IIRC, some asics' amdgpu_gfx_ctrl() is implemented as synchronous (upon function returns, gfx block is guaranteed to be in power-up state). Anyway, let me confirm about that soon.

BR,
Xiaojie

Quoted 60 lines · Alex Deucher
Quoted 8 lines · Xiaojie

Hi Alex,

IMHO, driver sending Disallow_Gfxoff message to SMU doesn't mean gfx block will be immediately powered up, so I'm not sure MMIO register access will be successful within this time window(maybe GRBM access will be pending until gfx block is powered up?)

If you are not in a hurry to commit this fix, I can verify on my Navi boards next Monday.

That would be great. Maybe we can add a delay in that function to take that into account?

Thanks!

Alex

Quoted 43 lines

BR,
Xiaojie

Quoted 39 lines · Alex Deucher

When gfxoff is enabled, accessing gfx registers via MMIO can lead to a hang.

---
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -2
index 6ddea7607ad0..5f3b3a705b29 100644
@@ -659,15 +659,19 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
          return -ENOMEM;
      alloc_size = info->read_mmr_reg.count * sizeof(*regs);
 
-        for (i = 0; i < info->read_mmr_reg.count; i++)
+        amdgpu_gfx_off_ctrl(adev, false);
+        for (i = 0; i < info->read_mmr_reg.count; i++) {
          if (amdgpu_asic_read_register(adev, se_num, sh_num,
                            info->read_mmr_reg.dword_offset + i,
                            &regs[i])) {
              DRM_DEBUG_KMS("unallowed offset %#x\n",
                        info->read_mmr_reg.dword_offset + i);
              kfree(regs);
+                amdgpu_gfx_off_ctrl(adev, true);
              return -EFAULT;
          }
+        }
+        amdgpu_gfx_off_ctrl(adev, true);
      n = copy_to_user(out, regs, min(size, alloc_size));
      kfree(regs);
      return n ? -EFAULT : 0;
--

2.23.0

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): MN2PR12MB308772C706D34387B2AECC52894D0-rweVpJHSKTpSqPH+ASrJYAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#13 lore raw

Re: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

Hi Xiaojie,

could you add that test to the unit tests we have in libdrm?

Would be rather nice to have,
Christian.

Am 18.11.19 um 15:09 schrieb Yuan, Xiaojie:

Quoted 175 lines

Hi Alex,

I tried on Navi14 with Gfxoff enabled (gfx in 'OFF' state when I run the test program) and used a test program to read GRBM_STATUS/CP_STAT/GB_ADDR_CONFIG via DRM_IOCTL_AMDGPU_INFO.

All read out values are valid as below (in this read cycle, I saw gfx block is first awakened and then powered off again automatically):

drm version: 3.36.0
grbm_status: 0x00003028
cp_stat: 0x00000000
gb_addr_config: 0x00000043

At least for Navi, reading register when gfxoff seems not a problem...

Test program:

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <libdrm/drm.h>
#include <libdrm/amdgpu_drm.h>

int get_reg_val(int fd, int reg_offset, int *val)

{
         struct drm_amdgpu_info request;
         int r;

         memset(&request, 0, sizeof(request));
         request.return_pointer = (uintptr_t)val;
         request.return_size = sizeof(uint32_t);
         request.query = AMDGPU_INFO_READ_MMR_REG;
         request.read_mmr_reg.dword_offset = reg_offset;
         request.read_mmr_reg.count = 1;
         request.read_mmr_reg.instance = 0xffffffff;
         request.read_mmr_reg.flags = 0;

         r = ioctl(fd, DRM_IOCTL_AMDGPU_INFO, &request);
         if (r < 0) {
                 perror("failed to read register");
                 return -errno;
         }

         return 0;
}

int main(int argc, const char *argv[])

{
         const char *device = "/dev/dri/card0";
         int fd;
         int r;
         struct drm_version version;
         struct drm_auth auth;
         int cp_stat;
         int grbm_status;
         int gb_addr_config;

         fd = open(device, O_RDWR | O_CLOEXEC);
         if (fd < 0) {
                 perror("failed to open device\n");
                 return -errno;
         }

         memset(&version, 0, sizeof(version));

         r = ioctl(fd, DRM_IOCTL_VERSION, &version);
         if (r < 0) {
                 perror("failed to get drm version");
                 r = -errno;
                 goto close;
         }

         printf("drm version: %d.%d.%d\n", version.version_major,
                                           version.version_minor,
                                           version.version_patchlevel);

         r = get_reg_val(fd, 0x2004, &grbm_status);
         if (r < 0)
                 goto close;
         printf("grbm_status: 0x%08x\n", grbm_status);

         r = get_reg_val(fd, 0x21a0, &cp_stat);
         if (r < 0)
                 goto close;
         printf("cp_stat: 0x%08x\n", cp_stat);

         r = get_reg_val(fd, 0x263e, &gb_addr_config);
         if (r < 0)
                 goto close;
         printf("gb_addr_config: 0x%08x\n", gb_addr_config);

close:

         close(fd);

         return r;
}

BR,
Xiaojie

________________________________________
From: amd-gfx <[email protected]> on behalf of Yuan, Xiaojie <[email protected]>
Sent: Saturday, November 16, 2019 1:02 AM
To: Alex Deucher
Cc: Deucher, Alexander; [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

Yes. IIRC, some asics' amdgpu_gfx_ctrl() is implemented as synchronous (upon function returns, gfx block is guaranteed to be in power-up state). Anyway, let me confirm about that soon.

BR,
Xiaojie

Quoted 58 lines · Alex Deucher
Quoted 8 lines · Xiaojie

Hi Alex,

IMHO, driver sending Disallow_Gfxoff message to SMU doesn't mean gfx block will be immediately powered up, so I'm not sure MMIO register access will be successful within this time window(maybe GRBM access will be pending until gfx block is powered up?)

If you are not in a hurry to commit this fix, I can verify on my Navi boards next Monday.

That would be great. Maybe we can add a delay in that function to take that into account?

Thanks!

Alex

Quoted 42 lines

BR,
Xiaojie

Quoted 39 lines · Alex Deucher

When gfxoff is enabled, accessing gfx registers via MMIO can lead to a hang.

---
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -2
index 6ddea7607ad0..5f3b3a705b29 100644
@@ -659,15 +659,19 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
           return -ENOMEM;
       alloc_size = info->read_mmr_reg.count * sizeof(*regs);
 
-        for (i = 0; i < info->read_mmr_reg.count; i++)
+        amdgpu_gfx_off_ctrl(adev, false);
+        for (i = 0; i < info->read_mmr_reg.count; i++) {
           if (amdgpu_asic_read_register(adev, se_num, sh_num,
                             info->read_mmr_reg.dword_offset + i,
                             &regs[i])) {
               DRM_DEBUG_KMS("unallowed offset %#x\n",
                         info->read_mmr_reg.dword_offset + i);
               kfree(regs);
+                amdgpu_gfx_off_ctrl(adev, true);
               return -EFAULT;
           }
+        }
+        amdgpu_gfx_off_ctrl(adev, true);
       n = copy_to_user(out, regs, min(size, alloc_size));
       kfree(regs);
       return n ? -EFAULT : 0;
--

2.23.0

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): b8f05608-6e00-712c-9208-dfb34a7a6a34-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#15 lore raw

Re: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

Hi Chris,

The info ioctl code path seems already covered at libdrm initialization time:

amdgpu_device_initialize()
-> amdgpu_queury_gpu_info_init()

    -> amdgpu_read_mm_registers()
        -> drmCommandWrite(fd, DRM_AMDGPU_INFO, ...)

BR,
Xiaojie

________________________________________
From: Christian König <[email protected]>
Sent: Tuesday, November 19, 2019 12:18 AM
To: Yuan, Xiaojie; Alex Deucher
Cc: Deucher, Alexander; [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

Hi Xiaojie,

could you add that test to the unit tests we have in libdrm?

Would be rather nice to have,
Christian.

Am 18.11.19 um 15:09 schrieb Yuan, Xiaojie:

Quoted 175 lines

Hi Alex,

I tried on Navi14 with Gfxoff enabled (gfx in 'OFF' state when I run the test program) and used a test program to read GRBM_STATUS/CP_STAT/GB_ADDR_CONFIG via DRM_IOCTL_AMDGPU_INFO.

All read out values are valid as below (in this read cycle, I saw gfx block is first awakened and then powered off again automatically):

drm version: 3.36.0
grbm_status: 0x00003028
cp_stat: 0x00000000
gb_addr_config: 0x00000043

At least for Navi, reading register when gfxoff seems not a problem...

Test program:

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <libdrm/drm.h>
#include <libdrm/amdgpu_drm.h>

int get_reg_val(int fd, int reg_offset, int *val)

{
         struct drm_amdgpu_info request;
         int r;

         memset(&request, 0, sizeof(request));
         request.return_pointer = (uintptr_t)val;
         request.return_size = sizeof(uint32_t);
         request.query = AMDGPU_INFO_READ_MMR_REG;
         request.read_mmr_reg.dword_offset = reg_offset;
         request.read_mmr_reg.count = 1;
         request.read_mmr_reg.instance = 0xffffffff;
         request.read_mmr_reg.flags = 0;

         r = ioctl(fd, DRM_IOCTL_AMDGPU_INFO, &request);
         if (r < 0) {
                 perror("failed to read register");
                 return -errno;
         }

         return 0;
}

int main(int argc, const char *argv[])

{
         const char *device = "/dev/dri/card0";
         int fd;
         int r;
         struct drm_version version;
         struct drm_auth auth;
         int cp_stat;
         int grbm_status;
         int gb_addr_config;

         fd = open(device, O_RDWR | O_CLOEXEC);
         if (fd < 0) {
                 perror("failed to open device\n");
                 return -errno;
         }

         memset(&version, 0, sizeof(version));

         r = ioctl(fd, DRM_IOCTL_VERSION, &version);
         if (r < 0) {
                 perror("failed to get drm version");
                 r = -errno;
                 goto close;
         }

         printf("drm version: %d.%d.%d\n", version.version_major,
                                           version.version_minor,
                                           version.version_patchlevel);

         r = get_reg_val(fd, 0x2004, &grbm_status);
         if (r < 0)
                 goto close;
         printf("grbm_status: 0x%08x\n", grbm_status);

         r = get_reg_val(fd, 0x21a0, &cp_stat);
         if (r < 0)
                 goto close;
         printf("cp_stat: 0x%08x\n", cp_stat);

         r = get_reg_val(fd, 0x263e, &gb_addr_config);
         if (r < 0)
                 goto close;
         printf("gb_addr_config: 0x%08x\n", gb_addr_config);

close:

         close(fd);

         return r;
}

BR,
Xiaojie

________________________________________
From: amd-gfx <[email protected]> on behalf of Yuan, Xiaojie <[email protected]>
Sent: Saturday, November 16, 2019 1:02 AM
To: Alex Deucher
Cc: Deucher, Alexander; [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

Yes. IIRC, some asics' amdgpu_gfx_ctrl() is implemented as synchronous (upon function returns, gfx block is guaranteed to be in power-up state). Anyway, let me confirm about that soon.

BR,
Xiaojie

Quoted 58 lines · Alex Deucher
Quoted 8 lines · Xiaojie

Hi Alex,

IMHO, driver sending Disallow_Gfxoff message to SMU doesn't mean gfx block will be immediately powered up, so I'm not sure MMIO register access will be successful within this time window(maybe GRBM access will be pending until gfx block is powered up?)

If you are not in a hurry to commit this fix, I can verify on my Navi boards next Monday.

That would be great. Maybe we can add a delay in that function to take that into account?

Thanks!

Alex

Quoted 42 lines

BR,
Xiaojie

Quoted 39 lines · Alex Deucher

When gfxoff is enabled, accessing gfx registers via MMIO can lead to a hang.

---
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -2
index 6ddea7607ad0..5f3b3a705b29 100644
@@ -659,15 +659,19 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
           return -ENOMEM;
       alloc_size = info->read_mmr_reg.count * sizeof(*regs);
 
-        for (i = 0; i < info->read_mmr_reg.count; i++)
+        amdgpu_gfx_off_ctrl(adev, false);
+        for (i = 0; i < info->read_mmr_reg.count; i++) {
           if (amdgpu_asic_read_register(adev, se_num, sh_num,
                             info->read_mmr_reg.dword_offset + i,
                             &regs[i])) {
               DRM_DEBUG_KMS("unallowed offset %#x\n",
                         info->read_mmr_reg.dword_offset + i);
               kfree(regs);
+                amdgpu_gfx_off_ctrl(adev, true);
               return -EFAULT;
           }
+        }
+        amdgpu_gfx_off_ctrl(adev, true);
       n = copy_to_user(out, regs, min(size, alloc_size));
       kfree(regs);
       return n ? -EFAULT : 0;
--

2.23.0

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#16 lore raw

Re: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

In reply to a message not in the archive

Can I get an RB or AB on the patch from anyone?

Thanks!

Alex

Quoted 178 lines · Xiaojie

Hi Alex,

I tried on Navi14 with Gfxoff enabled (gfx in 'OFF' state when I run the test program) and used a test program to read GRBM_STATUS/CP_STAT/GB_ADDR_CONFIG via DRM_IOCTL_AMDGPU_INFO.

All read out values are valid as below (in this read cycle, I saw gfx block is first awakened and then powered off again automatically):

drm version: 3.36.0
grbm_status: 0x00003028
cp_stat: 0x00000000
gb_addr_config: 0x00000043

At least for Navi, reading register when gfxoff seems not a problem...

Test program:

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <libdrm/drm.h>
#include <libdrm/amdgpu_drm.h>

int get_reg_val(int fd, int reg_offset, int *val)

{
        struct drm_amdgpu_info request;
        int r;

        memset(&request, 0, sizeof(request));
        request.return_pointer = (uintptr_t)val;
        request.return_size = sizeof(uint32_t);
        request.query = AMDGPU_INFO_READ_MMR_REG;
        request.read_mmr_reg.dword_offset = reg_offset;
        request.read_mmr_reg.count = 1;
        request.read_mmr_reg.instance = 0xffffffff;
        request.read_mmr_reg.flags = 0;

        r = ioctl(fd, DRM_IOCTL_AMDGPU_INFO, &request);
        if (r < 0) {
                perror("failed to read register");
                return -errno;
        }

        return 0;
}

int main(int argc, const char *argv[])

{
        const char *device = "/dev/dri/card0";
        int fd;
        int r;
        struct drm_version version;
        struct drm_auth auth;
        int cp_stat;
        int grbm_status;
        int gb_addr_config;

        fd = open(device, O_RDWR | O_CLOEXEC);
        if (fd < 0) {
                perror("failed to open device\n");
                return -errno;
        }

        memset(&version, 0, sizeof(version));

        r = ioctl(fd, DRM_IOCTL_VERSION, &version);
        if (r < 0) {
                perror("failed to get drm version");
                r = -errno;
                goto close;
        }

        printf("drm version: %d.%d.%d\n", version.version_major,
                                          version.version_minor,
                                          version.version_patchlevel);

        r = get_reg_val(fd, 0x2004, &grbm_status);
        if (r < 0)
                goto close;
        printf("grbm_status: 0x%08x\n", grbm_status);

        r = get_reg_val(fd, 0x21a0, &cp_stat);
        if (r < 0)
                goto close;
        printf("cp_stat: 0x%08x\n", cp_stat);

        r = get_reg_val(fd, 0x263e, &gb_addr_config);
        if (r < 0)
                goto close;
        printf("gb_addr_config: 0x%08x\n", gb_addr_config);

close:

        close(fd);

        return r;
}

BR,
Xiaojie

________________________________________
From: amd-gfx <[email protected]> on behalf of Yuan, Xiaojie <[email protected]>
Sent: Saturday, November 16, 2019 1:02 AM
To: Alex Deucher
Cc: Deucher, Alexander; [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

Yes. IIRC, some asics' amdgpu_gfx_ctrl() is implemented as synchronous (upon function returns, gfx block is guaranteed to be in power-up state). Anyway, let me confirm about that soon.

BR,
Xiaojie

Quoted 60 lines · Alex Deucher
Quoted 8 lines · Xiaojie

Hi Alex,

IMHO, driver sending Disallow_Gfxoff message to SMU doesn't mean gfx block will be immediately powered up, so I'm not sure MMIO register access will be successful within this time window(maybe GRBM access will be pending until gfx block is powered up?)

If you are not in a hurry to commit this fix, I can verify on my Navi boards next Monday.

That would be great. Maybe we can add a delay in that function to take that into account?

Thanks!

Alex

Quoted 43 lines

BR,
Xiaojie

Quoted 39 lines · Alex Deucher

When gfxoff is enabled, accessing gfx registers via MMIO can lead to a hang.

---
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -2
index 6ddea7607ad0..5f3b3a705b29 100644
@@ -659,15 +659,19 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
          return -ENOMEM;
      alloc_size = info->read_mmr_reg.count * sizeof(*regs);
 
-        for (i = 0; i < info->read_mmr_reg.count; i++)
+        amdgpu_gfx_off_ctrl(adev, false);
+        for (i = 0; i < info->read_mmr_reg.count; i++) {
          if (amdgpu_asic_read_register(adev, se_num, sh_num,
                            info->read_mmr_reg.dword_offset + i,
                            &regs[i])) {
              DRM_DEBUG_KMS("unallowed offset %#x\n",
                        info->read_mmr_reg.dword_offset + i);
              kfree(regs);
+                amdgpu_gfx_off_ctrl(adev, true);
              return -EFAULT;
          }
+        }
+        amdgpu_gfx_off_ctrl(adev, true);
      n = copy_to_user(out, regs, min(size, alloc_size));
      kfree(regs);
      return n ? -EFAULT : 0;
--

2.23.0

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CADnq5_PB86i_dYwJTcKW3mdDCGDu+35efjzFrJHv1hfHsmHCvA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

Acked-by Xiaojie Yuan
#18 lore raw

Re: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

BR,
Xiaojie

________________________________________
From: Alex Deucher <[email protected]>
Sent: Tuesday, November 19, 2019 1:24 AM
To: Yuan, Xiaojie
Cc: Deucher, Alexander; [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

Can I get an RB or AB on the patch from anyone?

Thanks!

Alex

Quoted 178 lines · Xiaojie

Hi Alex,

I tried on Navi14 with Gfxoff enabled (gfx in 'OFF' state when I run the test program) and used a test program to read GRBM_STATUS/CP_STAT/GB_ADDR_CONFIG via DRM_IOCTL_AMDGPU_INFO.

All read out values are valid as below (in this read cycle, I saw gfx block is first awakened and then powered off again automatically):

drm version: 3.36.0
grbm_status: 0x00003028
cp_stat: 0x00000000
gb_addr_config: 0x00000043

At least for Navi, reading register when gfxoff seems not a problem...

Test program:

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <libdrm/drm.h>
#include <libdrm/amdgpu_drm.h>

int get_reg_val(int fd, int reg_offset, int *val)

{
        struct drm_amdgpu_info request;
        int r;

        memset(&request, 0, sizeof(request));
        request.return_pointer = (uintptr_t)val;
        request.return_size = sizeof(uint32_t);
        request.query = AMDGPU_INFO_READ_MMR_REG;
        request.read_mmr_reg.dword_offset = reg_offset;
        request.read_mmr_reg.count = 1;
        request.read_mmr_reg.instance = 0xffffffff;
        request.read_mmr_reg.flags = 0;

        r = ioctl(fd, DRM_IOCTL_AMDGPU_INFO, &request);
        if (r < 0) {
                perror("failed to read register");
                return -errno;
        }

        return 0;
}

int main(int argc, const char *argv[])

{
        const char *device = "/dev/dri/card0";
        int fd;
        int r;
        struct drm_version version;
        struct drm_auth auth;
        int cp_stat;
        int grbm_status;
        int gb_addr_config;

        fd = open(device, O_RDWR | O_CLOEXEC);
        if (fd < 0) {
                perror("failed to open device\n");
                return -errno;
        }

        memset(&version, 0, sizeof(version));

        r = ioctl(fd, DRM_IOCTL_VERSION, &version);
        if (r < 0) {
                perror("failed to get drm version");
                r = -errno;
                goto close;
        }

        printf("drm version: %d.%d.%d\n", version.version_major,
                                          version.version_minor,
                                          version.version_patchlevel);

        r = get_reg_val(fd, 0x2004, &grbm_status);
        if (r < 0)
                goto close;
        printf("grbm_status: 0x%08x\n", grbm_status);

        r = get_reg_val(fd, 0x21a0, &cp_stat);
        if (r < 0)
                goto close;
        printf("cp_stat: 0x%08x\n", cp_stat);

        r = get_reg_val(fd, 0x263e, &gb_addr_config);
        if (r < 0)
                goto close;
        printf("gb_addr_config: 0x%08x\n", gb_addr_config);

close:

        close(fd);

        return r;
}

BR,
Xiaojie

________________________________________
From: amd-gfx <[email protected]> on behalf of Yuan, Xiaojie <[email protected]>
Sent: Saturday, November 16, 2019 1:02 AM
To: Alex Deucher
Cc: Deucher, Alexander; [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

Yes. IIRC, some asics' amdgpu_gfx_ctrl() is implemented as synchronous (upon function returns, gfx block is guaranteed to be in power-up state). Anyway, let me confirm about that soon.

BR,
Xiaojie

Quoted 60 lines · Alex Deucher
Quoted 8 lines · Xiaojie

Hi Alex,

IMHO, driver sending Disallow_Gfxoff message to SMU doesn't mean gfx block will be immediately powered up, so I'm not sure MMIO register access will be successful within this time window(maybe GRBM access will be pending until gfx block is powered up?)

If you are not in a hurry to commit this fix, I can verify on my Navi boards next Monday.

That would be great. Maybe we can add a delay in that function to take that into account?

Thanks!

Alex

Quoted 43 lines

BR,
Xiaojie

Quoted 39 lines · Alex Deucher

When gfxoff is enabled, accessing gfx registers via MMIO can lead to a hang.

---
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -2
index 6ddea7607ad0..5f3b3a705b29 100644
@@ -659,15 +659,19 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
          return -ENOMEM;
      alloc_size = info->read_mmr_reg.count * sizeof(*regs);
 
-        for (i = 0; i < info->read_mmr_reg.count; i++)
+        amdgpu_gfx_off_ctrl(adev, false);
+        for (i = 0; i < info->read_mmr_reg.count; i++) {
          if (amdgpu_asic_read_register(adev, se_num, sh_num,
                            info->read_mmr_reg.dword_offset + i,
                            &regs[i])) {
              DRM_DEBUG_KMS("unallowed offset %#x\n",
                        info->read_mmr_reg.dword_offset + i);
              kfree(regs);
+                amdgpu_gfx_off_ctrl(adev, true);
              return -EFAULT;
          }
+        }
+        amdgpu_gfx_off_ctrl(adev, true);
      n = copy_to_user(out, regs, min(size, alloc_size));
      kfree(regs);
      return n ? -EFAULT : 0;
--

2.23.0

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#19 lore raw

RE: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

In reply to a message not in the archive

Series is reviewed-by: Evan Quan <[email protected]>

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Friday, November 15, 2019 12:42 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 2/2] drm/amdgpu: disable gfxoff when using register read interface

When gfxoff is enabled, accessing gfx registers via MMIO can lead to a hang.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -1
index 6ddea7607ad0..5f3b3a705b29 100644
@@ -659,15 +659,19 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
 			return -ENOMEM;
 		alloc_size = info->read_mmr_reg.count * sizeof(*regs);
 
-		for (i = 0; i < info->read_mmr_reg.count; i++)
+		amdgpu_gfx_off_ctrl(adev, false);
+		for (i = 0; i < info->read_mmr_reg.count; i++) {
 			if (amdgpu_asic_read_register(adev, se_num, sh_num,
 						      info->read_mmr_reg.dword_offset + i,
 						      &regs[i])) {
 				DRM_DEBUG_KMS("unallowed offset %#x\n",
 					      info->read_mmr_reg.dword_offset + i);
 				kfree(regs);
+				amdgpu_gfx_off_ctrl(adev, true);
 				return -EFAULT;
 			}
+		}
+		amdgpu_gfx_off_ctrl(adev, true);
 		n = copy_to_user(out, regs, min(size, alloc_size));
 		kfree(regs);
 		return n ? -EFAULT : 0;

--
2.23.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#20 lore raw
In reply to a message not in the archive

Ping?

Quoted 116 lines · Alex Deucher

This reverts commit 5e49d6f654c569c2de920babbaf5cf7c4c4a353f.

Drop this workaround in favor of a better one.

---
 drivers/gpu/drm/amd/amdgpu/nv.c    | 27 ++++++++++----------------
 drivers/gpu/drm/amd/amdgpu/soc15.c | 31 ++++++++++++------------------
 2 files changed, 22 insertions(+), 36 deletions(-)
drivers/gpu/drm/amd/amdgpu/nv.c +10 -17
index 7283d6198b89..af68f9815f28 100644
@@ -201,25 +201,17 @@ static uint32_t nv_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
        return val;
 }
 
-static int nv_get_register_value(struct amdgpu_device *adev,
+static uint32_t nv_get_register_value(struct amdgpu_device *adev,
                                      bool indexed, u32 se_num,
-                                     u32 sh_num, u32 reg_offset,
-                                     u32 *value)
+                                     u32 sh_num, u32 reg_offset)
 {
        if (indexed) {
-               if (adev->pm.pp_feature & PP_GFXOFF_MASK)
-                       return -EINVAL;
-               *value = nv_read_indexed_register(adev, se_num, sh_num, reg_offset);
+               return nv_read_indexed_register(adev, se_num, sh_num, reg_offset);
        } else {
-               if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG)) {
-                       *value = adev->gfx.config.gb_addr_config;
-               } else {
-                       if (adev->pm.pp_feature & PP_GFXOFF_MASK)
-                               return -EINVAL;
-                       *value = RREG32(reg_offset);
-               }
+               if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG))
+                       return adev->gfx.config.gb_addr_config;
+               return RREG32(reg_offset);
        }
-       return 0;
 }
 
 static int nv_read_register(struct amdgpu_device *adev, u32 se_num,
@@ -235,9 +227,10 @@ static int nv_read_register(struct amdgpu_device *adev, u32 se_num,
                    (adev->reg_offset[en->hwip][en->inst][en->seg] + en->reg_offset))
                        continue;
 
-               return nv_get_register_value(adev,
-                                            nv_allowed_read_registers[i].grbm_indexed,
-                                            se_num, sh_num, reg_offset, value);
+               *value = nv_get_register_value(adev,
+                                              nv_allowed_read_registers[i].grbm_indexed,
+                                              se_num, sh_num, reg_offset);
+               return 0;
        }
        return -EINVAL;
 }
drivers/gpu/drm/amd/amdgpu/soc15.c +12 -20
index 3b55655f79c4..8e1640bc07af 100644
@@ -363,27 +363,19 @@ static uint32_t soc15_read_indexed_register(struct amdgpu_device *adev, u32 se_n
        return val;
 }
 
-static int soc15_get_register_value(struct amdgpu_device *adev,
+static uint32_t soc15_get_register_value(struct amdgpu_device *adev,
                                         bool indexed, u32 se_num,
-                                        u32 sh_num, u32 reg_offset,
-                                        u32 *value)
+                                        u32 sh_num, u32 reg_offset)
 {
        if (indexed) {
-               if (adev->pm.pp_feature & PP_GFXOFF_MASK)
-                       return -EINVAL;
-               *value = soc15_read_indexed_register(adev, se_num, sh_num, reg_offset);
+               return soc15_read_indexed_register(adev, se_num, sh_num, reg_offset);
        } else {
-               if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG)) {
-                       *value = adev->gfx.config.gb_addr_config;
-               } else if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmDB_DEBUG2)) {
-                       *value = adev->gfx.config.db_debug2;
-               } else {
-                       if (adev->pm.pp_feature & PP_GFXOFF_MASK)
-                               return -EINVAL;
-                       *value = RREG32(reg_offset);
-               }
+               if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG))
+                       return adev->gfx.config.gb_addr_config;
+               else if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmDB_DEBUG2))
+                       return adev->gfx.config.db_debug2;
+               return RREG32(reg_offset);
        }
-       return 0;
 }
 
 static int soc15_read_register(struct amdgpu_device *adev, u32 se_num,
@@ -399,9 +391,10 @@ static int soc15_read_register(struct amdgpu_device *adev, u32 se_num,
                                        + en->reg_offset))
                        continue;
 
-               return soc15_get_register_value(adev,
-                                               soc15_allowed_read_registers[i].grbm_indexed,
-                                               se_num, sh_num, reg_offset, value);
+               *value = soc15_get_register_value(adev,
+                                                 soc15_allowed_read_registers[i].grbm_indexed,
+                                                 se_num, sh_num, reg_offset);
+               return 0;
        }
        return -EINVAL;
 }
--
Quoted 2 lines

2.23.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CADnq5_P35L7Unqn-NwzeB0wdAiJcFhs8Ai0u2Uyx-J5eWjFkrQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

Reviewed-by Evan Quan
#22 lore raw
Quoted 148 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Saturday, November 16, 2019 12:15 AM
To: amd-gfx list <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH 1/2] Revert "drm/amdgpu: don't read registers if gfxoff is enabled (v2)"

Ping?

drivers/gpu/drm/amd/amdgpu/nv.c static uint32_t nv_read_indexed_register(struct

Quoted 18 lines · Alex Deucher

This reverts commit 5e49d6f654c569c2de920babbaf5cf7c4c4a353f.

Drop this workaround in favor of a better one.

---
 drivers/gpu/drm/amd/amdgpu/nv.c    | 27 ++++++++++----------------
 drivers/gpu/drm/amd/amdgpu/soc15.c | 31
++++++++++++------------------
 2 files changed, 22 insertions(+), 36 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/nv.c index 7283d6198b89..af68f9815f28 100644

drivers/gpu/drm/amd/amdgpu/nv.c +0 -0
@@ -201,25 +201,17 @@ static uint32_t nv_read_indexed_register(struct

amdgpu_device *adev, u32 se_num,

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/nv.c +0 -1
        return val;
 }
 
-static int nv_get_register_value(struct amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/nv.c static uint32_t nv_read_indexed_register(struct amdgpu_device *adev, u32 se_num,

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/nv.c +2 -5
+static uint32_t nv_get_register_value(struct amdgpu_device *adev,
                                      bool indexed, u32 se_num,
-                                     u32 sh_num, u32 reg_offset,
-                                     u32 *value)
+                                     u32 sh_num, u32 reg_offset)
 {
        if (indexed) {
-               if (adev->pm.pp_feature & PP_GFXOFF_MASK)
-                       return -EINVAL;
-               *value = nv_read_indexed_register(adev, se_num, sh_num,

reg_offset);

drivers/gpu/drm/amd/amdgpu/nv.c static uint32_t nv_read_indexed_register(struct · line 214

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/nv.c +2 -1
+               return nv_read_indexed_register(adev, se_num, sh_num,
+ reg_offset);
        } else {
-               if (reg_offset == SOC15_REG_OFFSET(GC, 0,

mmGB_ADDR_CONFIG)) {

drivers/gpu/drm/amd/amdgpu/nv.c static uint32_t nv_read_indexed_register(struct amdgpu_device *adev, u32 se_num,

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/nv.c +1 -6
-                       *value = adev->gfx.config.gb_addr_config;
-               } else {
-                       if (adev->pm.pp_feature & PP_GFXOFF_MASK)
-                               return -EINVAL;
-                       *value = RREG32(reg_offset);
-               }
+               if (reg_offset == SOC15_REG_OFFSET(GC, 0,

mmGB_ADDR_CONFIG))

drivers/gpu/drm/amd/amdgpu/nv.c static int nv_read_register(struct amdgpu_device

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/nv.c +2 -1
+                       return adev->gfx.config.gb_addr_config;
+               return RREG32(reg_offset);
        }
-       return 0;
 }
 
 static int nv_read_register(struct amdgpu_device *adev, u32 se_num,
@@ -235,9 +227,10 @@ static int nv_read_register(struct amdgpu_device

*adev, u32 se_num,

drivers/gpu/drm/amd/amdgpu/soc15.c static uint32_t soc15_read_indexed_register(struct

Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/nv.c +4 -3
                    (adev->reg_offset[en->hwip][en->inst][en->seg] + en->reg_offset))
                        continue;
 
-               return nv_get_register_value(adev,
-                                            nv_allowed_read_registers[i].grbm_indexed,
-                                            se_num, sh_num, reg_offset, value);
+               *value = nv_get_register_value(adev,
+                                              nv_allowed_read_registers[i].grbm_indexed,
+                                              se_num, sh_num, reg_offset);
+               return 0;
        }
        return -EINVAL;
 }
drivers/gpu/drm/amd/amdgpu/soc15.c +0 -0
index 3b55655f79c4..8e1640bc07af 100644
@@ -363,27 +363,19 @@ static uint32_t soc15_read_indexed_register(struct

amdgpu_device *adev, u32 se_n

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +0 -1
        return val;
 }
 
-static int soc15_get_register_value(struct amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/soc15.c static uint32_t soc15_read_indexed_register(struct amdgpu_device *adev, u32 se_n

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +2 -5
+static uint32_t soc15_get_register_value(struct amdgpu_device *adev,
                                         bool indexed, u32 se_num,
-                                        u32 sh_num, u32 reg_offset,
-                                        u32 *value)
+                                        u32 sh_num, u32 reg_offset)
 {
        if (indexed) {
-               if (adev->pm.pp_feature & PP_GFXOFF_MASK)
-                       return -EINVAL;
-               *value = soc15_read_indexed_register(adev, se_num, sh_num,

reg_offset);

drivers/gpu/drm/amd/amdgpu/soc15.c static uint32_t soc15_read_indexed_register(struct · line 376

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +2 -1
+               return soc15_read_indexed_register(adev, se_num,
+ sh_num, reg_offset);
        } else {
-               if (reg_offset == SOC15_REG_OFFSET(GC, 0,

mmGB_ADDR_CONFIG)) {

drivers/gpu/drm/amd/amdgpu/soc15.c static uint32_t soc15_read_indexed_register(struct · line 378

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +0 -2
-                       *value = adev->gfx.config.gb_addr_config;
-               } else if (reg_offset == SOC15_REG_OFFSET(GC, 0,

mmDB_DEBUG2)) {

drivers/gpu/drm/amd/amdgpu/soc15.c static uint32_t soc15_read_indexed_register(struct amdgpu_device *adev, u32 se_n

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +1 -6
-                       *value = adev->gfx.config.db_debug2;
-               } else {
-                       if (adev->pm.pp_feature & PP_GFXOFF_MASK)
-                               return -EINVAL;
-                       *value = RREG32(reg_offset);
-               }
+               if (reg_offset == SOC15_REG_OFFSET(GC, 0,

mmGB_ADDR_CONFIG))

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +4 -1
+                       return adev->gfx.config.gb_addr_config;
+               else if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmDB_DEBUG2))
+                       return adev->gfx.config.db_debug2;
+               return RREG32(reg_offset);
        }
-       return 0;
 }
 
 static int soc15_read_register(struct amdgpu_device *adev, u32

se_num, @@ -399,9 +391,10 @@ static int soc15_read_register(struct

amdgpu_device *adev, u32 se_num,

drivers/gpu/drm/amd/amdgpu/soc15.c static int soc15_read_register(struct amdgpu_device *adev, u32 se_num,

Quoted 8 lines

+ en->reg_offset))
continue;

drivers/gpu/drm/amd/amdgpu/soc15.c +2 -3
-               return soc15_get_register_value(adev,
-                                               soc15_allowed_read_registers[i].grbm_indexed,
-                                               se_num, sh_num, reg_offset, value);
+               *value = soc15_get_register_value(adev,
+

soc15_allowed_read_registers[i].grbm_indexed,

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +2 -1
+                                                 se_num, sh_num, reg_offset);
+               return 0;
        }
        return -EINVAL;
 }
--

2.23.0

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx