[PATCH 2/2] drm/amdgpu: add psp session ID get interface for sriov

Zhang, Hawking Hawking.Zhang at amd.com
Mon Dec 23 09:20:06 UTC 2019

[AMD Official Use Only - Internal Distribution Only]

Hi Frank,

The new function amdgpu_xgmi_get_session_id seems not necessary to me because you just need to delay the xgmi ta loading until IH get initialized. The xgmi session Id will be updated to xgmi_context so it should be okay anytime you want use it to issue any cmd to xgmi ta. I think it should work if you call psp_xgmi_init directly from xgmi_add_device. Is that correct?

Instead of having xgmi ta session initialization for sriov and bare-metal use scenario respectively, I'd like to have a unified sequence for both use scenario anyway. It seems to me, moving xgmi ta session initialization to xgmi_add_device should just work. We should also terminate the session in xgmi_remove_device, and accordingly, current xgmi ta session termination from psp_hw_fini will not be needed anymore. The current xgmi ta session init/fini sequence in suspend/resume should work and don't need any change. 

I quickly created the attached patch, can you try it in sriov to see whether it works or not?

-----Original Message-----
From: amd-gfx <amd-gfx-bounces at lists.freedesktop.org> On Behalf Of Frank.Min
Sent: Thursday, December 19, 2019 19:44
To: amd-gfx at lists.freedesktop.org
Cc: Min, Frank <Frank.Min at amd.com>
Subject: [PATCH 2/2] drm/amdgpu: add psp session ID get interface for sriov

on sriov, psp vf ring running depends on interrupt, so have to move the xgmi TA loading after IH hw init.

Change-Id: Ieffb3a94107c437f54abc0c41238c6f40274b35d
Signed-off-by: Frank.Min <Frank.Min at amd.com>
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c  |  4 ++--  drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h  |  2 +-  drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 16 ++++++++++++++++  drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h |  1 +
 4 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index a0bee12b095f..73c393392b0e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -573,7 +573,7 @@ static int psp_xgmi_terminate(struct psp_context *psp)
 	return 0;
-static int psp_xgmi_initialize(struct psp_context *psp)
+int psp_xgmi_initialize(struct psp_context *psp)
 	struct ta_xgmi_shared_memory *xgmi_cmd;
 	int ret;
@@ -1540,7 +1540,7 @@ static int psp_load_fw(struct amdgpu_device *adev)
 		return ret;
-	if (adev->gmc.xgmi.num_physical_nodes > 1) {
+	if (adev->gmc.xgmi.num_physical_nodes > 1 && !amdgpu_sriov_vf(adev)) {
 		ret = psp_xgmi_initialize(psp);
 		/* Warning the XGMI seesion initialize failure
 		 * Instead of stop driver initialization diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
index 5f8fd3e3535b..a29ffe2e5b45 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
@@ -362,7 +362,7 @@ int psp_update_vcn_sram(struct amdgpu_device *adev, int inst_idx,
 			uint64_t cmd_gpu_addr, int cmd_size);
 int psp_xgmi_invoke(struct psp_context *psp, uint32_t ta_cmd_id);
+int psp_xgmi_initialize(struct psp_context *psp);
 int psp_ras_invoke(struct psp_context *psp, uint32_t ta_cmd_id);  int psp_ras_enable_features(struct psp_context *psp,
 		union ta_ras_cmd_input *info, bool enable); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
index 61d13d8b7b20..f791ff3f1f64 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
@@ -357,6 +357,19 @@ int amdgpu_xgmi_get_hops_count(struct amdgpu_device *adev,
 	return	-EINVAL;
+int amdgpu_xgmi_get_session_id(struct amdgpu_device *adev) {
+	int ret;
+	if (amdgpu_sriov_vf(adev) && !adev->psp.xgmi_context.initialized)
+		ret = psp_xgmi_initialize(&adev->psp);
+	if (adev->psp.xgmi_context.initialized)
+		return adev->psp.xgmi_context.session_id;
+	else
+		return -EINVAL;
 int amdgpu_xgmi_add_device(struct amdgpu_device *adev)  {
 	struct psp_xgmi_topology_info *top_info; @@ -369,6 +382,9 @@ int amdgpu_xgmi_add_device(struct amdgpu_device *adev)
 	if (!adev->gmc.xgmi.supported)
 		return 0;
+	if(amdgpu_sriov_vf(adev))
+		amdgpu_xgmi_get_session_id(adev);
 	if (amdgpu_device_ip_get_ip_block(adev, AMD_IP_BLOCK_TYPE_PSP)) {
 		ret = psp_xgmi_get_hive_id(&adev->psp, &adev->gmc.xgmi.hive_id);
 		if (ret) {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h
index bbf504ff7051..9e917208e25f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h
@@ -36,6 +36,7 @@ struct amdgpu_hive_info {  };
 struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev, int lock);
+int amdgpu_xgmi_get_session_id(struct amdgpu_device *adev);
 int amdgpu_xgmi_update_topology(struct amdgpu_hive_info *hive, struct amdgpu_device *adev);  int amdgpu_xgmi_add_device(struct amdgpu_device *adev);  void amdgpu_xgmi_remove_device(struct amdgpu_device *adev);

amd-gfx mailing list
amd-gfx at lists.freedesktop.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-drm-amdgpu-move-xgmi-init-fini-to-xgmi_add-remove_de.patch
Type: application/octet-stream
Size: 5453 bytes
Desc: 0001-drm-amdgpu-move-xgmi-init-fini-to-xgmi_add-remove_de.patch
URL: <https://lists.freedesktop.org/archives/amd-gfx/attachments/20191223/84253693/attachment-0001.obj>

More information about the amd-gfx mailing list