intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: "Huang, Sean Z" <sean.z.huang@intel.com>
To: Intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [RFC-v4 10/26] drm/i915/pxp: Implement ioctl action to set session in play
Date: Tue,  1 Dec 2020 20:03:25 -0800	[thread overview]
Message-ID: <20201202040341.31981-11-sean.z.huang@intel.com> (raw)
In-Reply-To: <20201202040341.31981-1-sean.z.huang@intel.com>

With this ioctl action, user space driver can set the session in
state "session in play", after dirver reserved the session slot/id
from driver, and sent the TEE commands to activate the
corresponding hardware session. Session state "session in play"
means this session is ready for secure playback.

Signed-off-by: Huang, Sean Z <sean.z.huang@intel.com>
---
 drivers/gpu/drm/i915/pxp/intel_pxp.c    |  4 ++
 drivers/gpu/drm/i915/pxp/intel_pxp_sm.c | 69 +++++++++++++++++++++++++
 drivers/gpu/drm/i915/pxp/intel_pxp_sm.h |  2 +
 3 files changed, 75 insertions(+)

diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp.c b/drivers/gpu/drm/i915/pxp/intel_pxp.c
index d0d126205b12..91ace0f49b5f 100644
--- a/drivers/gpu/drm/i915/pxp/intel_pxp.c
+++ b/drivers/gpu/drm/i915/pxp/intel_pxp.c
@@ -53,6 +53,10 @@ int i915_pxp_ops_ioctl(struct drm_device *dev, void *data, struct drm_file *drmf
 				pxp_info.sm_status = ret;
 				ret = 0;
 			}
+		} else if (params->req_session_state == PXP_SM_REQ_SESSION_IN_PLAY) {
+			ret = pxp_sm_mark_protected_session_in_play(i915, params->session_type,
+								    params->pxp_tag);
+
 		} else {
 			ret = -EINVAL;
 			goto end;
diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp_sm.c b/drivers/gpu/drm/i915/pxp/intel_pxp_sm.c
index e4218083f7ec..b69f5f8bf238 100644
--- a/drivers/gpu/drm/i915/pxp/intel_pxp_sm.c
+++ b/drivers/gpu/drm/i915/pxp/intel_pxp_sm.c
@@ -41,6 +41,18 @@ static int pxp_reg_write(struct drm_i915_private *i915, u32 offset, u32 regval)
 	return 0;
 }
 
+static int pxp_get_session_index(struct drm_i915_private *i915, u32 pxp_tag,
+				 int *session_index_out, int *session_type_out)
+{
+	if (!session_index_out || !session_type_out)
+		return -EINVAL;
+
+	*session_type_out = (pxp_tag & SESSION_TYPE_MASK) ? SESSION_TYPE_TYPE1 : SESSION_TYPE_TYPE0;
+	*session_index_out = pxp_tag & SESSION_ID_MASK;
+
+	return 0;
+}
+
 static u8 pxp_get_session_id(int session_index, int session_type)
 {
 	u8 session_id = session_index & SESSION_ID_MASK;
@@ -445,6 +457,63 @@ int intel_pxp_sm_reserve_session(struct drm_i915_private *i915, struct drm_file
 	return ret;
 }
 
+/**
+ * pxp_sm_mark_protected_session_in_play - To put an reserved protected session to "in_play" state
+ * @i915: i915 device handle.
+ * @session_type: Type of the session to be updated. One of enum pxp_session_types.
+ * @session_id: Session id identifier of the protected session.
+ *
+ * Return: status. 0 means update is successful.
+ */
+int pxp_sm_mark_protected_session_in_play(struct drm_i915_private *i915, int session_type,
+					  u32 session_id)
+{
+	int ret;
+	int session_index;
+	int session_type_in_id;
+	struct pxp_protected_session *current_session;
+
+	ret = pxp_get_session_index(i915, session_id, &session_index, &session_type_in_id);
+	if (ret) {
+		drm_err(&i915->drm, "Failed to pxp_get_session_index\n");
+		return ret;
+	}
+
+	if (session_type != session_type_in_id) {
+		drm_err(&i915->drm, "Failed to session_type and session_type_in_id don't match\n");
+		return -EINVAL;
+	}
+
+	lockdep_assert_held(&i915->pxp.ctx->ctx_mutex);
+
+	switch (session_type) {
+	case SESSION_TYPE_TYPE0:
+		list_for_each_entry(current_session, &i915->pxp.ctx->active_pxp_type0_sessions,
+				    session_list) {
+			if (current_session->session_index == session_index) {
+				current_session->session_is_in_play = true;
+				return 0;
+			}
+		}
+		break;
+	case SESSION_TYPE_TYPE1:
+		list_for_each_entry(current_session, &i915->pxp.ctx->active_pxp_type1_sessions,
+				    session_list) {
+			if (current_session->session_index == session_index) {
+				current_session->session_is_in_play = true;
+				return 0;
+			}
+		}
+		break;
+	default:
+		/* invalid session type */
+		return -EINVAL;
+	}
+
+	drm_err(&i915->drm, "Failed to %s couldn't find active session\n", __func__);
+	return -EINVAL;
+}
+
 int pxp_sm_set_kcr_init_reg(struct drm_i915_private *i915)
 {
 	int ret;
diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp_sm.h b/drivers/gpu/drm/i915/pxp/intel_pxp_sm.h
index 5fcf63f804f8..90f7d74cacdf 100644
--- a/drivers/gpu/drm/i915/pxp/intel_pxp_sm.h
+++ b/drivers/gpu/drm/i915/pxp/intel_pxp_sm.h
@@ -87,6 +87,8 @@ struct pxp_protected_session {
 int intel_pxp_sm_reserve_session(struct drm_i915_private *i915, struct drm_file *drmfile,
 				 int context_id, int session_type, int protection_mode,
 				 u32 *pxp_tag);
+int pxp_sm_mark_protected_session_in_play(struct drm_i915_private *i915, int session_type,
+					  u32 session_id);
 int pxp_sm_set_kcr_init_reg(struct drm_i915_private *i915);
 
 #endif /* __INTEL_PXP_SM_H__ */
-- 
2.17.1

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

  parent reply	other threads:[~2020-12-02  4:04 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-02  4:03 [Intel-gfx] [RFC-v4 00/26] Introduce Intel PXP component Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 01/26] drm/i915/pxp: " Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 02/26] drm/i915/pxp: Enable PXP irq worker and callback stub Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 03/26] drm/i915/pxp: Add PXP context for logical hardware states Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 04/26] drm/i915/pxp: set KCR reg init during the boot time Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 05/26] drm/i915/pxp: Implement ioctl action to set the user space context Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 06/26] drm/i915/pxp: Add PXP-related registers into allowlist Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 07/26] drm/i915/pxp: Read register to check hardware session state Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 08/26] drm/i915/pxp: Implement funcs to get/set PXP tag Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 09/26] drm/i915/pxp: Implement ioctl action to reserve session slot Huang, Sean Z
2020-12-02  4:03 ` Huang, Sean Z [this message]
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 11/26] drm/i915/pxp: Func to send hardware session termination Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 12/26] drm/i915/pxp: Implement ioctl action to terminate the session Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 13/26] drm/i915/pxp: Enable ioctl action to query PXP tag Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 14/26] drm/i915/pxp: Destroy all type0 sessions upon teardown Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 15/26] drm/i915/pxp: Termiante the session upon app crash Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 16/26] drm/i915/pxp: Enable PXP power management Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 17/26] drm/i915/pxp: Implement funcs to create the TEE channel Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 18/26] drm/i915/pxp: Implement ioctl action to send TEE commands Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 19/26] drm/i915/pxp: Create the arbitrary session after boot Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 20/26] drm/i915/pxp: Add i915 trace logs for PXP operations Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 21/26] drm/i915/pxp: Expose session state for display protection flip Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 22/26] mei: pxp: export pavp client to me client bus Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 23/26] drm/i915/uapi: introduce drm_i915_gem_create_ext Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 24/26] drm/i915/pxp: User interface for Protected buffer Huang, Sean Z
2020-12-04 14:24   ` Lionel Landwerlin
2020-12-04 18:56     ` Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 25/26] drm/i915/pxp: Add plane decryption support Huang, Sean Z
2020-12-02  4:03 ` [Intel-gfx] [RFC-v4 26/26] drm/i915/pxp: Enable the PXP ioctl for protected session Huang, Sean Z
2020-12-02  4:18 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for Introduce Intel PXP component (rev4) Patchwork
2020-12-02  4:48 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2020-12-02  7:08 ` [Intel-gfx] ✓ Fi.CI.IGT: " Patchwork

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=20201202040341.31981-11-sean.z.huang@intel.com \
    --to=sean.z.huang@intel.com \
    --cc=Intel-gfx@lists.freedesktop.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).