Skip to contentSkip to conversation

drm/amdgpu: move check from cpu address to bo

PATCH In review Huang Rui 3 participants 8 messages Jul 4, 2017 5 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Huang Rui

author
#0 lore raw

PATCH 1/3 drm/amdgpu: move check from cpu address to bo

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 4 ++--
 drivers/gpu/drm/amd/amdgpu/psp_v3_1.c   | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +2 -2
index 79db294..1469e6d 100644
@@ -435,10 +435,10 @@ static int psp_hw_fini(void *handle)
 
 	psp_ring_destroy(psp, PSP_RING_TYPE__KM);
 
-	if (psp->tmr_buf)
+	if (psp->tmr_bo)
 		amdgpu_bo_free_kernel(&psp->tmr_bo, &psp->tmr_mc_addr, &psp->tmr_buf);
 
-	if (psp->fw_pri_buf)
+	if (psp->fw_pri_bo)
 		amdgpu_bo_free_kernel(&psp->fw_pri_bo,
 				      &psp->fw_pri_mc_addr, &psp->fw_pri_buf);
 
drivers/gpu/drm/amd/amdgpu/psp_v3_1.c +1 -1
index 988ebd9..3d057d8 100644
@@ -341,7 +341,7 @@ int psp_v3_1_ring_destroy(struct psp_context *psp, enum psp_ring_type ring_type)
 	ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, mmMP0_SMN_C2PMSG_64),
 			   0x80000000, 0x80000000, false);
 
-	if (ring->ring_mem)
+	if (adev->firmware.rbuf)
 		amdgpu_bo_free_kernel(&adev->firmware.rbuf,
 				      &ring->ring_mem_mc_addr,
 				      (void **)&ring->ring_mem);
Signature · 6 lines
2.7.4

_______________________________________________
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): 1499148650-22409-1-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org

author
#2 lore raw

PATCH 2/3 drm/amdgpu: fix missed asd bo free when hw_fini

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +5 -0
index 1469e6d..7b43c60 100644
@@ -446,6 +446,11 @@ static int psp_hw_fini(void *handle)
 		amdgpu_bo_free_kernel(&psp->fence_buf_bo,
 				      &psp->fence_buf_mc_addr, &psp->fence_buf);
 
+	if (psp->asd_shared_bo)
+		amdgpu_bo_free_kernel(&psp->asd_shared_bo,
+				      &psp->asd_shared_mc_addr,
+				      &psp->asd_shared_buf);
+
 	kfree(psp->cmd);
 	psp->cmd = NULL;
 
Signature · 6 lines
2.7.4

_______________________________________________
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): 1499148650-22409-2-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org

#4 lore raw

Re: [PATCH 2/3] drm/amdgpu: fix missed asd bo free when hw_fini

Am 04.07.2017 um 08:10 schrieb Huang Rui:

Quoted 10 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0 -0
index 1469e6d..7b43c60 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_hw_fini(void *handle) · line 453

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +5 -0
@@ -446,6 +446,11 @@ static int psp_hw_fini(void *handle)
  		amdgpu_bo_free_kernel(&psp->fence_buf_bo,
  				      &psp->fence_buf_mc_addr, &psp->fence_buf);
 
+	if (psp->asd_shared_bo)
+		amdgpu_bo_free_kernel(&psp->asd_shared_bo,
+				      &psp->asd_shared_mc_addr,
+				      &psp->asd_shared_buf);
+

Good catch, but again please remove the "if".

With that fixed the patch is Reviewed-by: Christian König <[email protected]>.

Regards,
Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_hw_fini(void *handle) · line 456

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0 -0
  	kfree(psp->cmd);
  	psp->cmd = NULL;
 

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

author
#5 lore raw

PATCH 3/3 drm/amdgpu: make psp cmd buffer as a reserve memory

In reply to a message not in the archive

We would like to use a reserve vram to store all non-psp firmware data when it is submmited. And needn't alloc/free when each firmware submits again and again, we can reuse that just one page size buffer.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 39 +++++++++++++++++----------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h |  5 +++++
 2 files changed, 25 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +20 -19
index 7b43c60..59700a2 100644
@@ -118,33 +118,18 @@ psp_cmd_submit_buf(struct psp_context *psp,
 		   int index)
 {
 	int ret;
-	struct amdgpu_bo *cmd_buf_bo;
-	uint64_t cmd_buf_mc_addr;
-	struct psp_gfx_cmd_resp *cmd_buf_mem;
-	struct amdgpu_device *adev = psp->adev;
 
-	ret = amdgpu_bo_create_kernel(adev, PSP_CMD_BUFFER_SIZE, PAGE_SIZE,
-				      AMDGPU_GEM_DOMAIN_VRAM,
-				      &cmd_buf_bo, &cmd_buf_mc_addr,
-				      (void **)&cmd_buf_mem);
-	if (ret)
-		return ret;
-
-	memset(cmd_buf_mem, 0, PSP_CMD_BUFFER_SIZE);
+	memset(psp->cmd_buf_mem, 0, PSP_CMD_BUFFER_SIZE);
 
-	memcpy(cmd_buf_mem, cmd, sizeof(struct psp_gfx_cmd_resp));
+	memcpy(psp->cmd_buf_mem, cmd, sizeof(struct psp_gfx_cmd_resp));
 
-	ret = psp_cmd_submit(psp, ucode, cmd_buf_mc_addr,
+	ret = psp_cmd_submit(psp, ucode, psp->cmd_buf_mc_addr,
 			     fence_mc_addr, index);
 
 	while (*((unsigned int *)psp->fence_buf) != index) {
 		msleep(1);
 	}
 
-	amdgpu_bo_free_kernel(&cmd_buf_bo,
-			      &cmd_buf_mc_addr,
-			      (void **)&cmd_buf_mem);
-
 	return ret;
 }
 
@@ -352,6 +337,13 @@ static int psp_load_fw(struct amdgpu_device *adev)
 				      &psp->fence_buf_mc_addr,
 				      &psp->fence_buf);
 	if (ret)
+		goto failed_mem2;
+
+	ret = amdgpu_bo_create_kernel(adev, PSP_CMD_BUFFER_SIZE, PAGE_SIZE,
+				      AMDGPU_GEM_DOMAIN_VRAM,
+				      &psp->cmd_buf_bo, &psp->cmd_buf_mc_addr,
+				      (void **)&psp->cmd_buf_mem);
+	if (ret)
 		goto failed_mem1;
 
 	memset(psp->fence_buf, 0, PSP_FENCE_BUFFER_SIZE);
@@ -379,9 +371,13 @@ static int psp_load_fw(struct amdgpu_device *adev)
 	return 0;
 
 failed_mem:
+	amdgpu_bo_free_kernel(&psp->cmd_buf_bo,
+			      &psp->cmd_buf_mc_addr,
+			      (void **)&psp->cmd_buf_mem);
+failed_mem1:
 	amdgpu_bo_free_kernel(&psp->fence_buf_bo,
 			      &psp->fence_buf_mc_addr, &psp->fence_buf);
-failed_mem1:
+failed_mem2:
 	amdgpu_bo_free_kernel(&psp->fw_pri_bo,
 			      &psp->fw_pri_mc_addr, &psp->fw_pri_buf);
 failed:
@@ -451,6 +447,11 @@ static int psp_hw_fini(void *handle)
 				      &psp->asd_shared_mc_addr,
 				      &psp->asd_shared_buf);
 
+	if (psp->cmd_buf_bo)
+		amdgpu_bo_free_kernel(&psp->cmd_buf_bo,
+				      &psp->cmd_buf_mc_addr,
+				      (void **)&psp->cmd_buf_mem);
+
 	kfree(psp->cmd);
 	psp->cmd = NULL;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +5 -0
index 1a1c8b4..538fa9d 100644
@@ -108,6 +108,11 @@ struct psp_context
 	struct amdgpu_bo 		*fence_buf_bo;
 	uint64_t 			fence_buf_mc_addr;
 	void				*fence_buf;
+
+	/* cmd buffer */
+	struct amdgpu_bo		*cmd_buf_bo;
+	uint64_t			cmd_buf_mc_addr;
+	struct psp_gfx_cmd_resp		*cmd_buf_mem;
 };
 
 struct amdgpu_psp_funcs {
Signature · 6 lines
2.7.4

_______________________________________________
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): 1499148650-22409-3-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org

#7 lore raw

Re: [PATCH 3/3] drm/amdgpu: make psp cmd buffer as a reserve memory

Yeah, when I had a glance at this func, flashed a similar idea. A little comment inline, please confirm it.

Regards,
Jerry

Quoted 66 lines · Huang Rui

We would like to use a reserve vram to store all non-psp firmware data when it is submmited. And needn't alloc/free when each firmware submits again and again, we can reuse that just one page size buffer.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 39 +++++++++++++++++----------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h |  5 +++++
  2 files changed, 25 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +10 -18
index 7b43c60..59700a2 100644
@@ -118,33 +118,18 @@ psp_cmd_submit_buf(struct psp_context *psp,
  		   int index)
  {
  	int ret;
-	struct amdgpu_bo *cmd_buf_bo;
-	uint64_t cmd_buf_mc_addr;
-	struct psp_gfx_cmd_resp *cmd_buf_mem;
-	struct amdgpu_device *adev = psp->adev;
 
-	ret = amdgpu_bo_create_kernel(adev, PSP_CMD_BUFFER_SIZE, PAGE_SIZE,
-				      AMDGPU_GEM_DOMAIN_VRAM,
-				      &cmd_buf_bo, &cmd_buf_mc_addr,
-				      (void **)&cmd_buf_mem);
-	if (ret)
-		return ret;
-
-	memset(cmd_buf_mem, 0, PSP_CMD_BUFFER_SIZE);
+	memset(psp->cmd_buf_mem, 0, PSP_CMD_BUFFER_SIZE);
 
-	memcpy(cmd_buf_mem, cmd, sizeof(struct psp_gfx_cmd_resp));
+	memcpy(psp->cmd_buf_mem, cmd, sizeof(struct psp_gfx_cmd_resp));
 
-	ret = psp_cmd_submit(psp, ucode, cmd_buf_mc_addr,
+	ret = psp_cmd_submit(psp, ucode, psp->cmd_buf_mc_addr,
  			     fence_mc_addr, index);
 
  	while (*((unsigned int *)psp->fence_buf) != index) {
  		msleep(1);
  	}
 
-	amdgpu_bo_free_kernel(&cmd_buf_bo,
-			      &cmd_buf_mc_addr,
-			      (void **)&cmd_buf_mem);
-
  	return ret;
  }
 
@@ -352,6 +337,13 @@ static int psp_load_fw(struct amdgpu_device *adev)
  				      &psp->fence_buf_mc_addr,
  				      &psp->fence_buf);
  	if (ret)
+		goto failed_mem2;
+
+	ret = amdgpu_bo_create_kernel(adev, PSP_CMD_BUFFER_SIZE, PAGE_SIZE,
+				      AMDGPU_GEM_DOMAIN_VRAM,
+				      &psp->cmd_buf_bo, &psp->cmd_buf_mc_addr,
+				      (void **)&psp->cmd_buf_mem);
+	if (ret)
  		goto failed_mem1;
 
  	memset(psp->fence_buf, 0, PSP_FENCE_BUFFER_SIZE);

drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_load_fw(struct amdgpu_device *adev) · line 371

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0 -0
@@ -379,9 +371,13 @@ static int psp_load_fw(struct amdgpu_device *adev)
  	return 0;

We may also need to update the error handling for psp_ring_init() as "goto failed_mem;"

Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +10 -1
  failed_mem:
+	amdgpu_bo_free_kernel(&psp->cmd_buf_bo,
+			      &psp->cmd_buf_mc_addr,
+			      (void **)&psp->cmd_buf_mem);
+failed_mem1:
  	amdgpu_bo_free_kernel(&psp->fence_buf_bo,
  			      &psp->fence_buf_mc_addr, &psp->fence_buf);
-failed_mem1:
+failed_mem2:
  	amdgpu_bo_free_kernel(&psp->fw_pri_bo,
  			      &psp->fw_pri_mc_addr, &psp->fw_pri_buf);
  failed:
@@ -451,6 +447,11 @@ static int psp_hw_fini(void *handle)
  				      &psp->asd_shared_mc_addr,
  				      &psp->asd_shared_buf);
 
+	if (psp->cmd_buf_bo)
+		amdgpu_bo_free_kernel(&psp->cmd_buf_bo,
+				      &psp->cmd_buf_mc_addr,
+				      (void **)&psp->cmd_buf_mem);
+
  	kfree(psp->cmd);
  	psp->cmd = NULL;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +0 -0
index 1a1c8b4..538fa9d 100644
@@ -108,6 +108,11 @@ struct psp_context
  	struct amdgpu_bo 		*fence_buf_bo;

drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h struct psp_context · line 118

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +5 -0
  	uint64_t 			fence_buf_mc_addr;
  	void				*fence_buf;
+
+	/* cmd buffer */
+	struct amdgpu_bo		*cmd_buf_bo;
+	uint64_t			cmd_buf_mc_addr;
+	struct psp_gfx_cmd_resp		*cmd_buf_mem;
  };
 
  struct amdgpu_psp_funcs {

_______________________________________________
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): [email protected]

author
#9 lore raw

Re: [PATCH 3/3] drm/amdgpu: make psp cmd buffer as a reserve memory

Quoted 71 lines · Jerry (Junwei)

Yeah, when I had a glance at this func, flashed a similar idea. A little comment inline, please confirm it.

Regards,
Jerry

Quoted 64 lines · Huang Rui

We would like to use a reserve vram to store all non-psp firmware data when it is submmited. And needn't alloc/free when each firmware submits again and again, we can reuse that just one page size buffer.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 39 +++++++++++++++++----------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h |  5 +++++
 2 files changed, 25 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +10 -18
index 7b43c60..59700a2 100644
@@ -118,33 +118,18 @@ psp_cmd_submit_buf(struct psp_context *psp,
 		   int index)
 {
 	int ret;
-	struct amdgpu_bo *cmd_buf_bo;
-	uint64_t cmd_buf_mc_addr;
-	struct psp_gfx_cmd_resp *cmd_buf_mem;
-	struct amdgpu_device *adev = psp->adev;
 
-	ret = amdgpu_bo_create_kernel(adev, PSP_CMD_BUFFER_SIZE, PAGE_SIZE,
-				      AMDGPU_GEM_DOMAIN_VRAM,
-				      &cmd_buf_bo, &cmd_buf_mc_addr,
-				      (void **)&cmd_buf_mem);
-	if (ret)
-		return ret;
-
-	memset(cmd_buf_mem, 0, PSP_CMD_BUFFER_SIZE);
+	memset(psp->cmd_buf_mem, 0, PSP_CMD_BUFFER_SIZE);
 
-	memcpy(cmd_buf_mem, cmd, sizeof(struct psp_gfx_cmd_resp));
+	memcpy(psp->cmd_buf_mem, cmd, sizeof(struct psp_gfx_cmd_resp));
 
-	ret = psp_cmd_submit(psp, ucode, cmd_buf_mc_addr,
+	ret = psp_cmd_submit(psp, ucode, psp->cmd_buf_mc_addr,
 			     fence_mc_addr, index);
 
 	while (*((unsigned int *)psp->fence_buf) != index) {
 		msleep(1);
 	}
 
-	amdgpu_bo_free_kernel(&cmd_buf_bo,
-			      &cmd_buf_mc_addr,
-			      (void **)&cmd_buf_mem);
-
 	return ret;
 }
 
@@ -352,6 +337,13 @@ static int psp_load_fw(struct amdgpu_device *adev)
 				      &psp->fence_buf_mc_addr,
 				      &psp->fence_buf);
 	if (ret)
+		goto failed_mem2;
+
+	ret = amdgpu_bo_create_kernel(adev, PSP_CMD_BUFFER_SIZE, PAGE_SIZE,
+				      AMDGPU_GEM_DOMAIN_VRAM,
+				      &psp->cmd_buf_bo, &psp->cmd_buf_mc_addr,
+				      (void **)&psp->cmd_buf_mem);
+	if (ret)
 		goto failed_mem1;
 
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_load_fw(struct amdgpu_device *adev) · line 371

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0 -0
 	memset(psp->fence_buf, 0, PSP_FENCE_BUFFER_SIZE);
@@ -379,9 +371,13 @@ static int psp_load_fw(struct amdgpu_device *adev)
 	return 0;

We may also need to update the error handling for psp_ring_init() as "goto failed_mem;"

Right, nice catch. Will update it.

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

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

Actually amdgpu_bo_free_kernel is NULL save, so you should rather remove the "if"s here altogether.

Christian.

Am 04.07.2017 um 08:10 schrieb Huang Rui:

Quoted 28 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 4 ++--
  drivers/gpu/drm/amd/amdgpu/psp_v3_1.c   | 2 +-
  2 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +2 -2
index 79db294..1469e6d 100644
@@ -435,10 +435,10 @@ static int psp_hw_fini(void *handle)
 
  	psp_ring_destroy(psp, PSP_RING_TYPE__KM);
 
-	if (psp->tmr_buf)
+	if (psp->tmr_bo)
  		amdgpu_bo_free_kernel(&psp->tmr_bo, &psp->tmr_mc_addr, &psp->tmr_buf);
 
-	if (psp->fw_pri_buf)
+	if (psp->fw_pri_bo)
  		amdgpu_bo_free_kernel(&psp->fw_pri_bo,
  				      &psp->fw_pri_mc_addr, &psp->fw_pri_buf);
 
drivers/gpu/drm/amd/amdgpu/psp_v3_1.c +0 -0
index 988ebd9..3d057d8 100644

drivers/gpu/drm/amd/amdgpu/psp_v3_1.c int psp_v3_1_ring_destroy(struct psp_context *psp, enum psp_ring_type ring_type) · line 347

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/psp_v3_1.c +1 -1
@@ -341,7 +341,7 @@ int psp_v3_1_ring_destroy(struct psp_context *psp, enum psp_ring_type ring_type)
  	ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, mmMP0_SMN_C2PMSG_64),
  			   0x80000000, 0x80000000, false);
 
-	if (ring->ring_mem)
+	if (adev->firmware.rbuf)
  		amdgpu_bo_free_kernel(&adev->firmware.rbuf,
  				      &ring->ring_mem_mc_addr,
  				      (void **)&ring->ring_mem);

_______________________________________________
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): f4402921-1085-5e4a-c6aa-582534f842eb-5C7GfCeVMHo@public.gmane.org