All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bhawanpreet Lakha <Bhawanpreet.Lakha-5C7GfCeVMHo@public.gmane.org>
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: Bhawanpreet Lakha <Bhawanpreet.Lakha-5C7GfCeVMHo@public.gmane.org>
Subject: [PATCH 09/20] drm/amdgpu: psp DTM init
Date: Tue, 10 Sep 2019 15:04:11 -0400	[thread overview]
Message-ID: <20190910190422.794-10-Bhawanpreet.Lakha@amd.com> (raw)
In-Reply-To: <20190910190422.794-1-Bhawanpreet.Lakha-5C7GfCeVMHo@public.gmane.org>

DTM is the display topology manager. This is needed to communicate with
psp about the display configurations.

This patch adds
    -Loading the firmware
    -The functions and definitions for communication with the firmware

v2: Fix formatting

Signed-off-by: Bhawanpreet Lakha <Bhawanpreet.Lakha@amd.com>
Reviewed-by: Harry Wentland <harry.wentland@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c   | 154 ++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h   |  15 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.h |   3 +
 drivers/gpu/drm/amd/amdgpu/psp_v10_0.c    |  11 +-
 4 files changed, 181 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index e75d164ea85b..ddb36a834e1c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -941,6 +941,149 @@ static int psp_hdcp_terminate(struct psp_context *psp)
 }
 // HDCP end
 
+// DTM start
+static void psp_prep_dtm_ta_load_cmd_buf(struct psp_gfx_cmd_resp *cmd,
+					 uint64_t dtm_ta_mc,
+					 uint64_t dtm_mc_shared,
+					 uint32_t dtm_ta_size,
+					 uint32_t shared_size)
+{
+	cmd->cmd_id = GFX_CMD_ID_LOAD_TA;
+	cmd->cmd.cmd_load_ta.app_phy_addr_lo = lower_32_bits(dtm_ta_mc);
+	cmd->cmd.cmd_load_ta.app_phy_addr_hi = upper_32_bits(dtm_ta_mc);
+	cmd->cmd.cmd_load_ta.app_len = dtm_ta_size;
+
+	cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_lo = lower_32_bits(dtm_mc_shared);
+	cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_hi = upper_32_bits(dtm_mc_shared);
+	cmd->cmd.cmd_load_ta.cmd_buf_len = shared_size;
+}
+
+static int psp_dtm_init_shared_buf(struct psp_context *psp)
+{
+	int ret;
+
+	/*
+	 * Allocate 16k memory aligned to 4k from Frame Buffer (local
+	 * physical) for dtm ta <-> Driver
+	 */
+	ret = amdgpu_bo_create_kernel(psp->adev, PSP_DTM_SHARED_MEM_SIZE,
+				      PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
+				      &psp->dtm_context.dtm_shared_bo,
+				      &psp->dtm_context.dtm_shared_mc_addr,
+				      &psp->dtm_context.dtm_shared_buf);
+
+	return ret;
+}
+
+static int psp_dtm_load(struct psp_context *psp)
+{
+	int ret;
+	struct psp_gfx_cmd_resp *cmd;
+
+	/*
+	 * TODO: bypass the loading in sriov for now
+	 */
+	if (amdgpu_sriov_vf(psp->adev))
+		return 0;
+
+	cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
+	if (!cmd)
+		return -ENOMEM;
+
+	memset(psp->fw_pri_buf, 0, PSP_1_MEG);
+	memcpy(psp->fw_pri_buf, psp->ta_dtm_start_addr, psp->ta_dtm_ucode_size);
+
+	psp_prep_dtm_ta_load_cmd_buf(cmd, psp->fw_pri_mc_addr,
+				     psp->dtm_context.dtm_shared_mc_addr,
+				     psp->ta_dtm_ucode_size,
+				     PSP_DTM_SHARED_MEM_SIZE);
+
+	ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
+
+	if (!ret) {
+		psp->dtm_context.dtm_initialized = 1;
+		psp->dtm_context.session_id = cmd->resp.session_id;
+	}
+
+	kfree(cmd);
+
+	return ret;
+}
+
+static int psp_dtm_initialize(struct psp_context *psp)
+{
+	int ret;
+
+	if (!psp->dtm_context.dtm_initialized) {
+		ret = psp_dtm_init_shared_buf(psp);
+		if (ret)
+			return ret;
+	}
+
+	ret = psp_dtm_load(psp);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static void psp_prep_dtm_ta_invoke_cmd_buf(struct psp_gfx_cmd_resp *cmd,
+					   uint32_t ta_cmd_id,
+					   uint32_t dtm_session_id)
+{
+	cmd->cmd_id = GFX_CMD_ID_INVOKE_CMD;
+	cmd->cmd.cmd_invoke_cmd.session_id = dtm_session_id;
+	cmd->cmd.cmd_invoke_cmd.ta_cmd_id = ta_cmd_id;
+	/* Note: cmd_invoke_cmd.buf is not used for now */
+}
+
+int psp_dtm_invoke(struct psp_context *psp, uint32_t ta_cmd_id)
+{
+	int ret;
+	struct psp_gfx_cmd_resp *cmd;
+
+	/*
+	 * TODO: bypass the loading in sriov for now
+	 */
+	if (amdgpu_sriov_vf(psp->adev))
+		return 0;
+
+	cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
+	if (!cmd)
+		return -ENOMEM;
+
+	psp_prep_dtm_ta_invoke_cmd_buf(cmd, ta_cmd_id,
+				       psp->dtm_context.session_id);
+
+	ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
+
+	kfree(cmd);
+
+	return ret;
+}
+
+static int psp_dtm_terminate(struct psp_context *psp)
+{
+	int ret;
+
+	if (!psp->dtm_context.dtm_initialized)
+		return 0;
+
+	ret = psp_hdcp_unload(psp);
+	if (ret)
+		return ret;
+
+	psp->dtm_context.dtm_initialized = 0;
+
+	/* free hdcp shared memory */
+	amdgpu_bo_free_kernel(&psp->dtm_context.dtm_shared_bo,
+			      &psp->dtm_context.dtm_shared_mc_addr,
+			      &psp->dtm_context.dtm_shared_buf);
+
+	return 0;
+}
+// DTM end
+
 static int psp_hw_start(struct psp_context *psp)
 {
 	struct amdgpu_device *adev = psp->adev;
@@ -1019,6 +1162,11 @@ static int psp_hw_start(struct psp_context *psp)
 		if (ret)
 			dev_err(psp->adev->dev,
 				"HDCP: Failed to initialize HDCP\n");
+
+		ret = psp_dtm_initialize(psp);
+		if (ret)
+			dev_err(psp->adev->dev,
+				"DTM: Failed to initialize DTM\n");
 	}
 
 	return 0;
@@ -1386,6 +1534,7 @@ static int psp_hw_fini(void *handle)
 
 	if (psp->adev->psp.ta_fw) {
 		psp_ras_terminate(psp);
+		psp_dtm_terminate(psp);
 		psp_hdcp_terminate(psp);
 	}
 
@@ -1434,6 +1583,11 @@ static int psp_suspend(void *handle)
 			DRM_ERROR("Failed to terminate hdcp ta\n");
 			return ret;
 		}
+		ret = psp_dtm_terminate(psp);
+		if (ret) {
+			DRM_ERROR("Failed to terminate dtm ta\n");
+			return ret;
+		}
 	}
 
 	ret = psp_ring_stop(psp, PSP_RING_TYPE__KM);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
index 6788e1601945..7dd9ae7dbbe4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
@@ -38,6 +38,7 @@
 #define PSP_1_MEG		0x100000
 #define PSP_TMR_SIZE	0x400000
 #define PSP_HDCP_SHARED_MEM_SIZE	0x4000
+#define PSP_DTM_SHARED_MEM_SIZE	0x4000
 #define PSP_SHARED_MEM_SIZE		0x4000
 
 struct psp_context;
@@ -152,6 +153,14 @@ struct psp_hdcp_context {
 	void			*hdcp_shared_buf;
 };
 
+struct psp_dtm_context {
+	bool			dtm_initialized;
+	uint32_t		session_id;
+	struct amdgpu_bo	*dtm_shared_bo;
+	uint64_t		dtm_shared_mc_addr;
+	void			*dtm_shared_buf;
+};
+
 struct psp_context
 {
 	struct amdgpu_device            *adev;
@@ -221,9 +230,14 @@ struct psp_context
 	uint32_t			ta_hdcp_ucode_size;
 	uint8_t				*ta_hdcp_start_addr;
 
+	uint32_t			ta_dtm_ucode_version;
+	uint32_t			ta_dtm_ucode_size;
+	uint8_t				*ta_dtm_start_addr;
+
 	struct psp_xgmi_context		xgmi_context;
 	struct psp_ras_context		ras;
 	struct psp_hdcp_context 	hdcp_context;
+	struct psp_dtm_context		dtm_context;
 	struct mutex			mutex;
 };
 
@@ -296,6 +310,7 @@ 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);
 int psp_hdcp_invoke(struct psp_context *psp, uint32_t ta_cmd_id);
+int psp_dtm_invoke(struct psp_context *psp, uint32_t ta_cmd_id);
 
 int psp_rlc_autoload_start(struct psp_context *psp);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.h
index c2b593ab7495..410587b950f3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.h
@@ -111,6 +111,9 @@ struct ta_firmware_header_v1_0 {
 	uint32_t ta_hdcp_ucode_version;
 	uint32_t ta_hdcp_offset_bytes;
 	uint32_t ta_hdcp_size_bytes;
+	uint32_t ta_dtm_ucode_version;
+	uint32_t ta_dtm_offset_bytes;
+	uint32_t ta_dtm_size_bytes;
 };
 
 /* version_major=1, version_minor=0 */
diff --git a/drivers/gpu/drm/amd/amdgpu/psp_v10_0.c b/drivers/gpu/drm/amd/amdgpu/psp_v10_0.c
index a43d7bafe954..6dec5fbc2678 100644
--- a/drivers/gpu/drm/amd/amdgpu/psp_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/psp_v10_0.c
@@ -99,8 +99,15 @@ static int psp_v10_0_init_microcode(struct psp_context *psp)
 			(uint8_t *)ta_hdr +
 			le32_to_cpu(ta_hdr->header.ucode_array_offset_bytes);
 
-		adev->psp.ta_fw_version =
-			le32_to_cpu(ta_hdr->header.ucode_version);
+		adev->psp.ta_fw_version = le32_to_cpu(ta_hdr->header.ucode_version);
+
+		adev->psp.ta_dtm_ucode_version =
+			le32_to_cpu(ta_hdr->ta_dtm_ucode_version);
+		adev->psp.ta_dtm_ucode_size =
+			le32_to_cpu(ta_hdr->ta_dtm_size_bytes);
+		adev->psp.ta_dtm_start_addr =
+			(uint8_t *)adev->psp.ta_hdcp_start_addr +
+			le32_to_cpu(ta_hdr->ta_dtm_offset_bytes);
 	}
 
 	return 0;
-- 
2.17.1

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

  parent reply	other threads:[~2019-09-10 19:04 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-29 16:22 [PATCH 00/20] HDCP 1.4 Content Protection Bhawanpreet Lakha
     [not found] ` <20190829162253.10195-1-Bhawanpreet.Lakha-5C7GfCeVMHo@public.gmane.org>
2019-08-29 16:22   ` [PATCH 01/20] drm: move content protection property to mode_config Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 02/20] drm: generic fn converting be24 to cpu and vice versa Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 03/20] drm: revocation check at drm subsystem Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 04/20] drm/hdcp: gathering hdcp related code into drm_hdcp.c Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 05/20] drm: Add Content protection type property Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 06/20] drm: uevent for connector status change Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 07/20] drm/hdcp: update content protection property with uevent Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 08/20] drm/amdgpu: psp HDCP init Bhawanpreet Lakha
     [not found]     ` <20190829162253.10195-9-Bhawanpreet.Lakha-5C7GfCeVMHo@public.gmane.org>
2019-09-10 19:02       ` Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 09/20] drm/amdgpu: psp DTM init Bhawanpreet Lakha
     [not found]     ` <20190829162253.10195-10-Bhawanpreet.Lakha-5C7GfCeVMHo@public.gmane.org>
2019-09-05 19:31       ` Harry Wentland
     [not found]         ` <63ec7ec3-8e1b-96b1-61eb-5c59432063e1-5C7GfCeVMHo@public.gmane.org>
2019-09-05 19:36           ` Lakha, Bhawanpreet
     [not found]             ` <228d8024-edca-035b-dc33-fa0787bb1c81-5C7GfCeVMHo@public.gmane.org>
2019-09-05 20:13               ` Harry Wentland
2019-09-10 19:05       ` [PATCH 00/20] HDCP 1.4 Content Protection Bhawanpreet Lakha
     [not found]         ` <20190910190554.1539-1-Bhawanpreet.Lakha-5C7GfCeVMHo@public.gmane.org>
2019-09-10 19:05           ` [PATCH 01/20] drm: move content protection property to mode_config Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 02/20] drm: generic fn converting be24 to cpu and vice versa Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 03/20] drm: revocation check at drm subsystem Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 04/20] drm/hdcp: gathering hdcp related code into drm_hdcp.c Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 05/20] drm: Add Content protection type property Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 06/20] drm: uevent for connector status change Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 07/20] drm/hdcp: update content protection property with uevent Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 08/20] drm/amdgpu: psp HDCP init Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 09/20] drm/amdgpu: psp DTM init Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 10/20] drm/amd/display: Add HDCP module Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 11/20] drm/amd/display: add PSP block to verify hdcp steps Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 12/20] drm/amd/display: Update hdcp display config Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 13/20] drm/amd/display: Create amdgpu_dm_hdcp Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 14/20] drm/amd/display: Create dpcd and i2c packing functions Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 15/20] drm/amd/display: Initialize HDCP work queue Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 16/20] drm/amd/display: Handle Content protection property changes Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 17/20] drm/amd/display: handle DP cpirq Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 18/20] drm/amd/display: Update CP property based on HW query Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 19/20] drm/amd/display: only enable HDCP for DCN+ Bhawanpreet Lakha
2019-09-10 19:05           ` [PATCH 20/20] drm/amd/display: Add hdcp to Kconfig Bhawanpreet Lakha
2019-09-11 13:56           ` [PATCH 00/20] HDCP 1.4 Content Protection Harry Wentland
2019-08-29 16:22   ` [PATCH 10/20] drm/amd/display: Add HDCP module Bhawanpreet Lakha
     [not found]     ` <20190829162253.10195-11-Bhawanpreet.Lakha-5C7GfCeVMHo@public.gmane.org>
2019-09-05 21:46       ` Liu, Wenjing
2019-08-29 16:22   ` [PATCH 11/20] drm/amd/display: add PSP block to verify hdcp steps Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 12/20] drm/amd/display: Update hdcp display config Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 13/20] drm/amd/display: Create amdgpu_dm_hdcp Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 14/20] drm/amd/display: Create dpcd and i2c packing functions Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 15/20] drm/amd/display: Initialize HDCP work queue Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 16/20] drm/amd/display: Handle Content protection property changes Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 17/20] drm/amd/display: handle DP cpirq Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 18/20] drm/amd/display: Update CP property based on HW query Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 19/20] drm/amd/display: only enable HDCP for DCN+ Bhawanpreet Lakha
2019-08-29 16:22   ` [PATCH 20/20] drm/amd/display: Add hdcp to Kconfig Bhawanpreet Lakha
2019-09-05 20:44   ` [PATCH 00/20] HDCP 1.4 Content Protection Harry Wentland
     [not found]     ` <eb83ae25-7635-45de-72dc-db24571066d2-5C7GfCeVMHo@public.gmane.org>
2019-09-10 19:04       ` Bhawanpreet Lakha
     [not found]         ` <20190910190422.794-1-Bhawanpreet.Lakha-5C7GfCeVMHo@public.gmane.org>
2019-09-10 19:04           ` [PATCH 01/20] drm: move content protection property to mode_config Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 02/20] drm: generic fn converting be24 to cpu and vice versa Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 03/20] drm: revocation check at drm subsystem Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 04/20] drm/hdcp: gathering hdcp related code into drm_hdcp.c Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 05/20] drm: Add Content protection type property Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 06/20] drm: uevent for connector status change Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 07/20] drm/hdcp: update content protection property with uevent Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 08/20] drm/amdgpu: psp HDCP init Bhawanpreet Lakha
2019-09-10 19:04           ` Bhawanpreet Lakha [this message]
2019-09-10 19:04           ` [PATCH 10/20] drm/amd/display: Add HDCP module Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 11/20] drm/amd/display: add PSP block to verify hdcp steps Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 12/20] drm/amd/display: Update hdcp display config Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 13/20] drm/amd/display: Create amdgpu_dm_hdcp Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 14/20] drm/amd/display: Create dpcd and i2c packing functions Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 15/20] drm/amd/display: Initialize HDCP work queue Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 16/20] drm/amd/display: Handle Content protection property changes Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 17/20] drm/amd/display: handle DP cpirq Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 18/20] drm/amd/display: Update CP property based on HW query Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 19/20] drm/amd/display: only enable HDCP for DCN+ Bhawanpreet Lakha
2019-09-10 19:04           ` [PATCH 20/20] drm/amd/display: Add hdcp to Kconfig Bhawanpreet Lakha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190910190422.794-10-Bhawanpreet.Lakha@amd.com \
    --to=bhawanpreet.lakha-5c7gfcevmho@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.