Skip to contentSkip to conversation

drm/amdgpu/vcn: add shared menory restore after wake up from sleep.

PATCH Superseded James Zhu 5 participants 8 messages Apr 3, 2020 – Apr 6, 2020

Subsystems (2)
lore
Share & tools
lore

James Zhu

author
#0 lore raw

PATCH 1/1 drm/amdgpu/vcn: add shared menory restore after wake up from sleep.

VCN shared memory needs restore after wake up during S3 test.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 26 ++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h |  1 +
 2 files changed, 27 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +26 -0
index d653a18..5891390 100644
@@ -205,6 +205,7 @@ int amdgpu_vcn_sw_fini(struct amdgpu_device *adev)
 		if (adev->vcn.harvest_config & (1 << j))
 			continue;
 
+		kvfree(adev->vcn.inst[j].saved_shm_bo);
 		amdgpu_bo_free_kernel(&adev->vcn.inst[j].fw_shared_bo,
 					  &adev->vcn.inst[j].fw_shared_gpu_addr,
 					  (void **)&adev->vcn.inst[j].fw_shared_cpu_addr);
@@ -254,6 +255,18 @@ int amdgpu_vcn_suspend(struct amdgpu_device *adev)
 			return -ENOMEM;
 
 		memcpy_fromio(adev->vcn.inst[i].saved_bo, ptr, size);
+
+		if (adev->vcn.inst[i].fw_shared_bo == NULL)
+			return 0;
+
+		size = amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+		ptr = adev->vcn.inst[i].fw_shared_cpu_addr;
+
+		adev->vcn.inst[i].saved_shm_bo = kvmalloc(size, GFP_KERNEL);
+		if (!adev->vcn.inst[i].saved_shm_bo)
+			return -ENOMEM;
+
+		memcpy_fromio(adev->vcn.inst[i].saved_shm_bo, ptr, size);
 	}
 	return 0;
 }
@@ -291,6 +304,19 @@ int amdgpu_vcn_resume(struct amdgpu_device *adev)
 			}
 			memset_io(ptr, 0, size);
 		}
+
+		if (adev->vcn.inst[i].fw_shared_bo == NULL)
+			return -EINVAL;
+
+		size = amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+		ptr = adev->vcn.inst[i].fw_shared_cpu_addr;
+
+		if (adev->vcn.inst[i].saved_shm_bo != NULL) {
+			memcpy_toio(ptr, adev->vcn.inst[i].saved_shm_bo, size);
+			kvfree(adev->vcn.inst[i].saved_shm_bo);
+			adev->vcn.inst[i].saved_shm_bo = NULL;
+		} else
+			memset_io(ptr, 0, size);
 	}
 	return 0;
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +1 -0
index f739e1a..bd77dae 100644
@@ -194,6 +194,7 @@ struct amdgpu_vcn_inst {
 	atomic_t		dpg_enc_submission_cnt;
 	void			*fw_shared_cpu_addr;
 	uint64_t		fw_shared_gpu_addr;
+	void			*saved_shm_bo;
 };
 
 struct amdgpu_vcn {
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by on v1 1/1
#1 lore raw

[AMD Official Use Only - Internal Distribution Only]

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of James Zhu
Sent: 2020年4月3日 20:52
To: [email protected]
Cc: Li, Pauline <[email protected]>; Zhu, James <[email protected]>
Subject: [PATCH] drm/amdgpu/vcn: add shared menory restore after wake up from sleep.

VCN shared memory needs restore after wake up during S3 test.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 26 ++++++++++++++++++++++++++  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h |  1 +
 2 files changed, 27 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +26 -0
index d653a18..5891390 100644
@@ -205,6 +205,7 @@ int amdgpu_vcn_sw_fini(struct amdgpu_device *adev)
 		if (adev->vcn.harvest_config & (1 << j))
 			continue;
 
+		kvfree(adev->vcn.inst[j].saved_shm_bo);
 		amdgpu_bo_free_kernel(&adev->vcn.inst[j].fw_shared_bo,
 					  &adev->vcn.inst[j].fw_shared_gpu_addr,
 					  (void **)&adev->vcn.inst[j].fw_shared_cpu_addr);
@@ -254,6 +255,18 @@ int amdgpu_vcn_suspend(struct amdgpu_device *adev)
 			return -ENOMEM;
 
 		memcpy_fromio(adev->vcn.inst[i].saved_bo, ptr, size);
+
+		if (adev->vcn.inst[i].fw_shared_bo == NULL)
+			return 0;
+
+		size = amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+		ptr = adev->vcn.inst[i].fw_shared_cpu_addr;
+
+		adev->vcn.inst[i].saved_shm_bo = kvmalloc(size, GFP_KERNEL);
+		if (!adev->vcn.inst[i].saved_shm_bo)
+			return -ENOMEM;
+
+		memcpy_fromio(adev->vcn.inst[i].saved_shm_bo, ptr, size);
 	}
 	return 0;
 }
@@ -291,6 +304,19 @@ int amdgpu_vcn_resume(struct amdgpu_device *adev)
 			}
 			memset_io(ptr, 0, size);
 		}
+
+		if (adev->vcn.inst[i].fw_shared_bo == NULL)
+			return -EINVAL;
+
+		size = amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+		ptr = adev->vcn.inst[i].fw_shared_cpu_addr;
+
+		if (adev->vcn.inst[i].saved_shm_bo != NULL) {
+			memcpy_toio(ptr, adev->vcn.inst[i].saved_shm_bo, size);
+			kvfree(adev->vcn.inst[i].saved_shm_bo);
+			adev->vcn.inst[i].saved_shm_bo = NULL;
+		} else
+			memset_io(ptr, 0, size);
 	}
 	return 0;
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +1 -0
index f739e1a..bd77dae 100644
@@ -194,6 +194,7 @@ struct amdgpu_vcn_inst {
 	atomic_t		dpg_enc_submission_cnt;
 	void			*fw_shared_cpu_addr;
 	uint64_t		fw_shared_gpu_addr;
+	void			*saved_shm_bo;
 };
 
 struct amdgpu_vcn {

--
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7CFeifei.Xu%40amd.com%7C6de5512ca8574257613108d7d7cdd780%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637215152681686620&amp;sdata=X07gFq7Cf1swi%2FVtOl0ldpaOsbtC3gO5BPUlYwxrano%3D&amp;reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#2 lore raw
In reply to James Zhu
Quoted 2 lines · James Zhu

VCN shared memory needs restore after wake up during S3 test.

How big is the shared memory? It might be better to allocate the memory once at sw_init and then free it in sw_fini rather than allocating and freeing in every suspend/resume.

Alex

Quoted 73 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 26 ++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h |  1 +
 2 files changed, 27 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +26 -0
index d653a18..5891390 100644
@@ -205,6 +205,7 @@ int amdgpu_vcn_sw_fini(struct amdgpu_device *adev)
                if (adev->vcn.harvest_config & (1 << j))
                        continue;
 
+               kvfree(adev->vcn.inst[j].saved_shm_bo);
                amdgpu_bo_free_kernel(&adev->vcn.inst[j].fw_shared_bo,
                                          &adev->vcn.inst[j].fw_shared_gpu_addr,
                                          (void **)&adev->vcn.inst[j].fw_shared_cpu_addr);
@@ -254,6 +255,18 @@ int amdgpu_vcn_suspend(struct amdgpu_device *adev)
                        return -ENOMEM;
 
                memcpy_fromio(adev->vcn.inst[i].saved_bo, ptr, size);
+
+               if (adev->vcn.inst[i].fw_shared_bo == NULL)
+                       return 0;
+
+               size = amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+               ptr = adev->vcn.inst[i].fw_shared_cpu_addr;
+
+               adev->vcn.inst[i].saved_shm_bo = kvmalloc(size, GFP_KERNEL);
+               if (!adev->vcn.inst[i].saved_shm_bo)
+                       return -ENOMEM;
+
+               memcpy_fromio(adev->vcn.inst[i].saved_shm_bo, ptr, size);
        }
        return 0;
 }
@@ -291,6 +304,19 @@ int amdgpu_vcn_resume(struct amdgpu_device *adev)
                        }
                        memset_io(ptr, 0, size);
                }
+
+               if (adev->vcn.inst[i].fw_shared_bo == NULL)
+                       return -EINVAL;
+
+               size = amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+               ptr = adev->vcn.inst[i].fw_shared_cpu_addr;
+
+               if (adev->vcn.inst[i].saved_shm_bo != NULL) {
+                       memcpy_toio(ptr, adev->vcn.inst[i].saved_shm_bo, size);
+                       kvfree(adev->vcn.inst[i].saved_shm_bo);
+                       adev->vcn.inst[i].saved_shm_bo = NULL;
+               } else
+                       memset_io(ptr, 0, size);
        }
        return 0;
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +1 -1
index f739e1a..bd77dae 100644
@@ -194,6 +194,7 @@ struct amdgpu_vcn_inst {
        atomic_t                dpg_enc_submission_cnt;
        void                    *fw_shared_cpu_addr;
        uint64_t                fw_shared_gpu_addr;
+       void                    *saved_shm_bo;
 };
 
 struct amdgpu_vcn {
--

2.7.4

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

#3 lore raw
Quoted 5 lines · Alex Deucher
Quoted 1 line · James Zhu

VCN shared memory needs restore after wake up during S3 test.

How big is the shared memory? It might be better to allocate the memory once at sw_init and then free it in sw_fini rather than allocating and freeing in every suspend/resume.

Hi Alex,

After alignment, it is only 4k. I can change it as you suggest.

Best Regards!

James

Quoted 71 lines

Alex

Quoted 68 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 26 ++++++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h |  1 +
  2 files changed, 27 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +26 -0
index d653a18..5891390 100644
@@ -205,6 +205,7 @@ int amdgpu_vcn_sw_fini(struct amdgpu_device *adev)
                 if (adev->vcn.harvest_config & (1 << j))
                         continue;
 
+               kvfree(adev->vcn.inst[j].saved_shm_bo);
                 amdgpu_bo_free_kernel(&adev->vcn.inst[j].fw_shared_bo,
                                           &adev->vcn.inst[j].fw_shared_gpu_addr,
                                           (void **)&adev->vcn.inst[j].fw_shared_cpu_addr);
@@ -254,6 +255,18 @@ int amdgpu_vcn_suspend(struct amdgpu_device *adev)
                         return -ENOMEM;
 
                 memcpy_fromio(adev->vcn.inst[i].saved_bo, ptr, size);
+
+               if (adev->vcn.inst[i].fw_shared_bo == NULL)
+                       return 0;
+
+               size = amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+               ptr = adev->vcn.inst[i].fw_shared_cpu_addr;
+
+               adev->vcn.inst[i].saved_shm_bo = kvmalloc(size, GFP_KERNEL);
+               if (!adev->vcn.inst[i].saved_shm_bo)
+                       return -ENOMEM;
+
+               memcpy_fromio(adev->vcn.inst[i].saved_shm_bo, ptr, size);
         }
         return 0;
  }
@@ -291,6 +304,19 @@ int amdgpu_vcn_resume(struct amdgpu_device *adev)
                         }
                         memset_io(ptr, 0, size);
                 }
+
+               if (adev->vcn.inst[i].fw_shared_bo == NULL)
+                       return -EINVAL;
+
+               size = amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+               ptr = adev->vcn.inst[i].fw_shared_cpu_addr;
+
+               if (adev->vcn.inst[i].saved_shm_bo != NULL) {
+                       memcpy_toio(ptr, adev->vcn.inst[i].saved_shm_bo, size);
+                       kvfree(adev->vcn.inst[i].saved_shm_bo);
+                       adev->vcn.inst[i].saved_shm_bo = NULL;
+               } else
+                       memset_io(ptr, 0, size);
         }
         return 0;
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +1 -0
index f739e1a..bd77dae 100644
@@ -194,6 +194,7 @@ struct amdgpu_vcn_inst {
         atomic_t                dpg_enc_submission_cnt;
         void                    *fw_shared_cpu_addr;
         uint64_t                fw_shared_gpu_addr;
+       void                    *saved_shm_bo;
  };
 
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +0 -1
  struct amdgpu_vcn {
--

2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7CJames.Zhu%40amd.com%7C46c4773164334ec712b708d7d7e4ebd6%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637215250518903143&amp;sdata=Mj%2FgeXKkiNVFUUsyKAesC5eaanDg%2FvQQpQe1rhT9uek%3D&amp;reserved=0

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

#4 lore raw

Am 03.04.20 um 17:54 schrieb James Zhu:

Quoted 11 lines · Alex Deucher
Quoted 5 lines · James Zhu
Quoted 1 line

VCN shared memory needs restore after wake up during S3 test.

How big is the shared memory?  It might be better to allocate the memory once at sw_init and then free it in sw_fini rather than allocating and freeing in every suspend/resume.

Hi Alex,

After alignment, it is only 4k. I can change it as you suggest.

Does this needs to stay at the same place after a suspend/resume?

See we only backup the firmware manually because we otherwise can't guarantee that it will be moved back to the same place after resume.

If that isn't an issue for the shared bo we could just unpin it on suspend and pin it again on resume.

BTW: What is that used for and why can't it be part of the VCN firmware BO?

Thanks,
Christian.

Quoted 83 lines

Best Regards!

James

Quoted 78 lines

Alex

Quoted 75 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 26
++++++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h |  1 +

  2 files changed, 27 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +13 -0
index d653a18..5891390 100644
@@ -205,6 +205,7 @@ int amdgpu_vcn_sw_fini(struct amdgpu_device *adev)
                  if (adev->vcn.harvest_config & (1 << j))
                          continue;
 
+               kvfree(adev->vcn.inst[j].saved_shm_bo);
 amdgpu_bo_free_kernel(&adev->vcn.inst[j].fw_shared_bo,
 &adev->vcn.inst[j].fw_shared_gpu_addr,
                                            (void **)&adev->vcn.inst[j].fw_shared_cpu_addr);
@@ -254,6 +255,18 @@ int amdgpu_vcn_suspend(struct amdgpu_device *adev)
                          return -ENOMEM;
 
                  memcpy_fromio(adev->vcn.inst[i].saved_bo, ptr, size);
+
+               if (adev->vcn.inst[i].fw_shared_bo == NULL)
+                       return 0;
+
+               size = amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+               ptr = adev->vcn.inst[i].fw_shared_cpu_addr;
+
+               adev->vcn.inst[i].saved_shm_bo = kvmalloc(size, 
 GFP_KERNEL);
+               if (!adev->vcn.inst[i].saved_shm_bo)
+                       return -ENOMEM;
+
+ memcpy_fromio(adev->vcn.inst[i].saved_shm_bo, ptr, size);
          }
          return 0;

  }

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +13 -0
@@ -291,6 +304,19 @@ int amdgpu_vcn_resume(struct amdgpu_device *adev)
                          }
                          memset_io(ptr, 0, size);
                  }
+
+               if (adev->vcn.inst[i].fw_shared_bo == NULL)
+                       return -EINVAL;
+
+               size = amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+               ptr = adev->vcn.inst[i].fw_shared_cpu_addr;
+
+               if (adev->vcn.inst[i].saved_shm_bo != NULL) {
+                       memcpy_toio(ptr, 
 adev->vcn.inst[i].saved_shm_bo, size);
+ kvfree(adev->vcn.inst[i].saved_shm_bo);
+                       adev->vcn.inst[i].saved_shm_bo = NULL;
+               } else
+                       memset_io(ptr, 0, size);
          }
          return 0;

  }

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +1 -0
index f739e1a..bd77dae 100644
@@ -194,6 +194,7 @@ struct amdgpu_vcn_inst {
          atomic_t                dpg_enc_submission_cnt;
          void                    *fw_shared_cpu_addr;
          uint64_t                fw_shared_gpu_addr;
+       void                    *saved_shm_bo;
   };
 
   struct amdgpu_vcn {
Signature · 1 line
2.7.4
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7CJames.Zhu%40amd.com%7C46c4773164334ec712b708d7d7e4ebd6%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637215250518903143&amp;sdata=Mj%2FgeXKkiNVFUUsyKAesC5eaanDg%2FvQQpQe1rhT9uek%3D&amp;reserved=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

#5 lore raw
Quoted 9 lines · Christian König

Am 03.04.20 um 17:54 schrieb James Zhu:

Quoted 8 lines · Alex Deucher
Quoted 5 lines · James Zhu
Quoted 1 line

VCN shared memory needs restore after wake up during S3 test.

How big is the shared memory?  It might be better to allocate the memory once at sw_init and then free it in sw_fini rather than allocating and freeing in every suspend/resume.

Quoted 7 lines
Quoted 3 lines

Hi Alex,

After alignment, it is only 4k. I can change it as you suggest.

Does this needs to stay at the same place after a suspend/resume?

See we only backup the firmware manually because we otherwise can't guarantee that it will be moved back to the same place after resume.

Yes, this is the case.. FW request the same for their resume processing.

Quoted 3 lines

If that isn't an issue for the shared bo we could just unpin it on suspend and pin it again on resume.

BTW: What is that used for and why can't it be part of the VCN firmware BO?

Logically it is used for FW and driver sharing some settings conveniently. If you suggest it can be added into VCN BO, then it will simply the implementation.

Thanks and Best Regards!

James Zhu

Quoted 99 lines

Thanks,
Christian.

Quoted 94 lines

Best Regards!

James

Quoted 79 lines

Alex

Quoted 76 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 26
++++++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h |  1 +

  2 files changed, 27 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +13 -0
index d653a18..5891390 100644
@@ -205,6 +205,7 @@ int amdgpu_vcn_sw_fini(struct amdgpu_device *adev)
                  if (adev->vcn.harvest_config & (1 << j))
                          continue;
 
+               kvfree(adev->vcn.inst[j].saved_shm_bo);
 amdgpu_bo_free_kernel(&adev->vcn.inst[j].fw_shared_bo,
 &adev->vcn.inst[j].fw_shared_gpu_addr,
                                            (void **)&adev->vcn.inst[j].fw_shared_cpu_addr);
@@ -254,6 +255,18 @@ int amdgpu_vcn_suspend(struct amdgpu_device 
 *adev)
                          return -ENOMEM;
 
 memcpy_fromio(adev->vcn.inst[i].saved_bo, ptr, size);
+
+               if (adev->vcn.inst[i].fw_shared_bo == NULL)
+                       return 0;
+
+               size = amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+               ptr = adev->vcn.inst[i].fw_shared_cpu_addr;
+
+               adev->vcn.inst[i].saved_shm_bo = kvmalloc(size, 
 GFP_KERNEL);
+               if (!adev->vcn.inst[i].saved_shm_bo)
+                       return -ENOMEM;
+
+ memcpy_fromio(adev->vcn.inst[i].saved_shm_bo, ptr, size);
          }

         return 0;
  }

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +13 -0
@@ -291,6 +304,19 @@ int amdgpu_vcn_resume(struct amdgpu_device *adev)
                          }
                          memset_io(ptr, 0, size);
                  }
+
+               if (adev->vcn.inst[i].fw_shared_bo == NULL)
+                       return -EINVAL;
+
+               size = amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+               ptr = adev->vcn.inst[i].fw_shared_cpu_addr;
+
+               if (adev->vcn.inst[i].saved_shm_bo != NULL) {
+                       memcpy_toio(ptr, 
 adev->vcn.inst[i].saved_shm_bo, size);
+ kvfree(adev->vcn.inst[i].saved_shm_bo);
+                       adev->vcn.inst[i].saved_shm_bo = NULL;
+               } else
+                       memset_io(ptr, 0, size);
          }
          return 0;

  }

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +1 -0
index f739e1a..bd77dae 100644
@@ -194,6 +194,7 @@ struct amdgpu_vcn_inst {
          atomic_t                dpg_enc_submission_cnt;
          void                    *fw_shared_cpu_addr;
          uint64_t                fw_shared_gpu_addr;
+       void                    *saved_shm_bo;
   };
 
   struct amdgpu_vcn {
Signature · 1 line
2.7.4
Quoted 5 lines
Quoted 5 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7CJames.Zhu%40amd.com%7Ccf00d8be2e994e71381808d7d9f8a0d7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637217534184643911&amp;sdata=pjIqtWZKO5768HmBOjH1fhjZMPScuyBUg%2FprxH2QWc4%3D&amp;reserved=0

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7CJames.Zhu%40amd.com%7Ccf00d8be2e994e71381808d7d9f8a0d7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637217534184643911&amp;sdata=pjIqtWZKO5768HmBOjH1fhjZMPScuyBUg%2FprxH2QWc4%3D&amp;reserved=0

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

#6 lore raw

Am 06.04.20 um 14:31 schrieb James Zhu:

Quoted 17 lines · Christian König
Quoted 15 lines

Am 03.04.20 um 17:54 schrieb James Zhu:

Quoted 11 lines · Alex Deucher
Quoted 5 lines · James Zhu
Quoted 1 line

VCN shared memory needs restore after wake up during S3 test.

How big is the shared memory?  It might be better to allocate the memory once at sw_init and then free it in sw_fini rather than allocating and freeing in every suspend/resume.

Hi Alex,

After alignment, it is only 4k. I can change it as you suggest.

Does this needs to stay at the same place after a suspend/resume?

Quoted 7 lines
Quoted 1 line

See we only backup the firmware manually because we otherwise can't guarantee that it will be moved back to the same place after resume.

Yes, this is the case.. FW request the same for their resume processing.

Quoted 3 lines

If that isn't an issue for the shared bo we could just unpin it on suspend and pin it again on resume.

BTW: What is that used for and why can't it be part of the VCN firmware BO?

Logically it is used for FW and driver sharing some settings conveniently. If you suggest it can be added into VCN BO, then it will simply the implementation.

As long as this is only used by the kernel driver it sounds like it is best put into the VCN BO as well, yes.

Regards,
Christian.

Quoted 108 lines

Thanks and Best Regards!

James Zhu

Quoted 103 lines

Thanks,
Christian.

Quoted 98 lines

Best Regards!

James

Quoted 83 lines

Alex

Quoted 80 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 26
++++++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h |  1 +

  2 files changed, 27 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +1 -0
index d653a18..5891390 100644
@@ -205,6 +205,7 @@ int amdgpu_vcn_sw_fini(struct amdgpu_device 
 *adev)
                  if (adev->vcn.harvest_config & (1 << j))
                          continue;
 
+               kvfree(adev->vcn.inst[j].saved_shm_bo);
 amdgpu_bo_free_kernel(&adev->vcn.inst[j].fw_shared_bo,
 &adev->vcn.inst[j].fw_shared_gpu_addr,

                                           (void **)&adev->vcn.inst[j].fw_shared_cpu_addr);

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +12 -0
@@ -254,6 +255,18 @@ int amdgpu_vcn_suspend(struct amdgpu_device 
 *adev)
                          return -ENOMEM;
 
 memcpy_fromio(adev->vcn.inst[i].saved_bo, ptr, size);
+
+               if (adev->vcn.inst[i].fw_shared_bo == NULL)
+                       return 0;
+
+               size = 
 amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+               ptr = adev->vcn.inst[i].fw_shared_cpu_addr;
+
+               adev->vcn.inst[i].saved_shm_bo = kvmalloc(size, 
 GFP_KERNEL);
+               if (!adev->vcn.inst[i].saved_shm_bo)
+                       return -ENOMEM;
+
+ memcpy_fromio(adev->vcn.inst[i].saved_shm_bo, ptr, size);

         }
         return 0;
  }

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +13 -0
@@ -291,6 +304,19 @@ int amdgpu_vcn_resume(struct amdgpu_device 
 *adev)
                          }
                          memset_io(ptr, 0, size);
                  }
+
+               if (adev->vcn.inst[i].fw_shared_bo == NULL)
+                       return -EINVAL;
+
+               size = 
 amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+               ptr = adev->vcn.inst[i].fw_shared_cpu_addr;
+
+               if (adev->vcn.inst[i].saved_shm_bo != NULL) {
+                       memcpy_toio(ptr, 
 adev->vcn.inst[i].saved_shm_bo, size);
+ kvfree(adev->vcn.inst[i].saved_shm_bo);
+                       adev->vcn.inst[i].saved_shm_bo = NULL;
+               } else
+                       memset_io(ptr, 0, size);

         }
         return 0;
  }

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +1 -0
index f739e1a..bd77dae 100644
@@ -194,6 +194,7 @@ struct amdgpu_vcn_inst {
          atomic_t                dpg_enc_submission_cnt;
          void                    *fw_shared_cpu_addr;
          uint64_t                fw_shared_gpu_addr;
+       void                    *saved_shm_bo;
   };
 
   struct amdgpu_vcn {
Signature · 1 line
2.7.4
Quoted 5 lines
Quoted 5 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7CJames.Zhu%40amd.com%7Ccf00d8be2e994e71381808d7d9f8a0d7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637217534184643911&amp;sdata=pjIqtWZKO5768HmBOjH1fhjZMPScuyBUg%2FprxH2QWc4%3D&amp;reserved=0

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7CJames.Zhu%40amd.com%7Ccf00d8be2e994e71381808d7d9f8a0d7%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637217534184643911&amp;sdata=pjIqtWZKO5768HmBOjH1fhjZMPScuyBUg%2FprxH2QWc4%3D&amp;reserved=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

author
#7 lore raw

PATCH v2 1/1 drm/amdgpu/vcn: add shared menory restore after wake up from sleep.

In reply to James Zhu

VCN shared memory needs restore after wake up during S3 test.

v2: Allocate shared memory saved_bo at sw_init and free it in sw_fini.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 28 +++++++++++++++++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h |  1 +
 2 files changed, 28 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +27 -1
index d653a18..dab34f6 100644
@@ -56,7 +56,7 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work);
 
 int amdgpu_vcn_sw_init(struct amdgpu_device *adev)
 {
-	unsigned long bo_size;
+	unsigned long bo_size, fw_shared_bo_size;
 	const char *fw_name;
 	const struct common_firmware_header *hdr;
 	unsigned char fw_check;
@@ -190,6 +190,9 @@ int amdgpu_vcn_sw_init(struct amdgpu_device *adev)
 			dev_err(adev->dev, "VCN %d (%d) failed to allocate firmware shared bo\n", i, r);
 			return r;
 		}
+
+		fw_shared_bo_size = amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+		adev->vcn.inst[i].saved_shm_bo = kvmalloc(fw_shared_bo_size, GFP_KERNEL);
 	}
 
 	return 0;
@@ -205,6 +208,7 @@ int amdgpu_vcn_sw_fini(struct amdgpu_device *adev)
 		if (adev->vcn.harvest_config & (1 << j))
 			continue;
 
+		kvfree(adev->vcn.inst[j].saved_shm_bo);
 		amdgpu_bo_free_kernel(&adev->vcn.inst[j].fw_shared_bo,
 					  &adev->vcn.inst[j].fw_shared_gpu_addr,
 					  (void **)&adev->vcn.inst[j].fw_shared_cpu_addr);
@@ -254,6 +258,17 @@ int amdgpu_vcn_suspend(struct amdgpu_device *adev)
 			return -ENOMEM;
 
 		memcpy_fromio(adev->vcn.inst[i].saved_bo, ptr, size);
+
+		if (adev->vcn.inst[i].fw_shared_bo == NULL)
+			return 0;
+
+		if (!adev->vcn.inst[i].saved_shm_bo)
+			return -ENOMEM;
+
+		size = amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+		ptr = adev->vcn.inst[i].fw_shared_cpu_addr;
+
+		memcpy_fromio(adev->vcn.inst[i].saved_shm_bo, ptr, size);
 	}
 	return 0;
 }
@@ -291,6 +306,17 @@ int amdgpu_vcn_resume(struct amdgpu_device *adev)
 			}
 			memset_io(ptr, 0, size);
 		}
+
+		if (adev->vcn.inst[i].fw_shared_bo == NULL)
+			return -EINVAL;
+
+		size = amdgpu_bo_size(adev->vcn.inst[i].fw_shared_bo);
+		ptr = adev->vcn.inst[i].fw_shared_cpu_addr;
+
+		if (adev->vcn.inst[i].saved_shm_bo != NULL)
+			memcpy_toio(ptr, adev->vcn.inst[i].saved_shm_bo, size);
+		else
+			memset_io(ptr, 0, size);
 	}
 	return 0;
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +1 -0
index f739e1a..bd77dae 100644
@@ -194,6 +194,7 @@ struct amdgpu_vcn_inst {
 	atomic_t		dpg_enc_submission_cnt;
 	void			*fw_shared_cpu_addr;
 	uint64_t		fw_shared_gpu_addr;
+	void			*saved_shm_bo;
 };
 
 struct amdgpu_vcn {
Signature · 6 lines
2.7.4

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