From patchwork Thu Dec 10 22:38:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Sean Z" X-Patchwork-Id: 11966797 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94D5BC0018C for ; Thu, 10 Dec 2020 22:39:55 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5FCC92332A for ; Thu, 10 Dec 2020 22:39:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5FCC92332A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E60516EB7B; Thu, 10 Dec 2020 22:39:54 +0000 (UTC) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7C5696EB7D for ; Thu, 10 Dec 2020 22:39:38 +0000 (UTC) IronPort-SDR: 68vCs5wsN67X2lMOAN9sBxBvTme6252ON1zag7hd10MijWl3+8Afb0wl1Syy1qbjr9AeZuq316 x44TSbkKUwBA== X-IronPort-AV: E=McAfee;i="6000,8403,9831"; a="192676675" X-IronPort-AV: E=Sophos;i="5.78,409,1599548400"; d="scan'208";a="192676675" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2020 14:39:33 -0800 IronPort-SDR: 4LaojTsE5LUM2IxaqflNo6dXb/K12lKohHn7V/lsw+264eyowHscgTPMCsaONWpF3fieJTZKXo IES80xOl7KnA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,409,1599548400"; d="scan'208";a="544017013" Received: from sean-virtualbox.fm.intel.com ([10.105.158.96]) by fmsmga005.fm.intel.com with ESMTP; 10 Dec 2020 14:39:33 -0800 From: "Huang, Sean Z" To: Intel-gfx@lists.freedesktop.org Date: Thu, 10 Dec 2020 14:38:53 -0800 Message-Id: <20201210223859.23882-16-sean.z.huang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201210223859.23882-1-sean.z.huang@intel.com> References: <20201210223859.23882-1-sean.z.huang@intel.com> Subject: [Intel-gfx] [RFC-v6 15/21] drm/i915/pxp: Implement ioctl action to set session in play X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" With this ioctl action, userspace driver can set the session in state "session in play", after dirver reserved the session slot/id from kernel PXP, 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 --- drivers/gpu/drm/i915/pxp/intel_pxp.c | 11 +++++- drivers/gpu/drm/i915/pxp/intel_pxp_sm.c | 51 +++++++++++++++++++++++++ drivers/gpu/drm/i915/pxp/intel_pxp_sm.h | 2 + 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp.c b/drivers/gpu/drm/i915/pxp/intel_pxp.c index e294134fef78..e000a78b782e 100644 --- a/drivers/gpu/drm/i915/pxp/intel_pxp.c +++ b/drivers/gpu/drm/i915/pxp/intel_pxp.c @@ -16,7 +16,13 @@ #define KCR_INIT_ALLOW_DISPLAY_ME_WRITES (BIT(14) | (BIT(14) << KCR_INIT_MASK_SHIFT)) #define PXP_ACTION_SET_SESSION_STATUS 1 -#define PXP_REQ_SESSION_ID_INIT 0 + +enum pxp_session_req { + /* Request KMD to allocate session id and move it to IN INIT */ + PXP_REQ_SESSION_ID_INIT = 0x0, + /* Inform KMD that UMD has completed the initialization */ + PXP_REQ_SESSION_IN_PLAY, +}; /* * struct pxp_set_session_status_params - Params to reserved, set or destroy @@ -228,6 +234,9 @@ 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_REQ_SESSION_IN_PLAY) { + ret = intel_pxp_sm_ioctl_mark_session_in_play(pxp, params->session_type, + params->pxp_tag); } else { ret = -EINVAL; } diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp_sm.c b/drivers/gpu/drm/i915/pxp/intel_pxp_sm.c index a68316be1bfd..e5858c17e62f 100644 --- a/drivers/gpu/drm/i915/pxp/intel_pxp_sm.c +++ b/drivers/gpu/drm/i915/pxp/intel_pxp_sm.c @@ -12,6 +12,9 @@ #define GEN12_KCR_TSIP _MMIO(0x32264) /* KCR type1 session in play 0-63 */ +#define SESSION_TYPE_MASK BIT(7) +#define SESSION_ID_MASK (BIT(7) - 1) + static inline int session_max(int session_type) { return (session_type == SESSION_TYPE_TYPE0) ? @@ -148,6 +151,17 @@ static int create_session_entry(struct intel_pxp *pxp, struct drm_file *drmfile, return 0; } +static int pxp_get_session_index(u32 session_id, int *index_out, int *type_out) +{ + if (!index_out || !type_out) + return -EINVAL; + + *type_out = (session_id & SESSION_TYPE_MASK) ? SESSION_TYPE_TYPE1 : SESSION_TYPE_TYPE0; + *index_out = session_id & SESSION_ID_MASK; + + return 0; +} + /** * intel_pxp_sm_ioctl_reserve_session - To reserve an available protected session. * @pxp: pointer to pxp struct @@ -192,3 +206,40 @@ int intel_pxp_sm_ioctl_reserve_session(struct intel_pxp *pxp, struct drm_file *d return PXP_SM_STATUS_SESSION_NOT_AVAILABLE; } + +/** + * intel_pxp_sm_ioctl_mark_session_in_play - Put an reserved session to "in_play" state + * @pxp: pointer to pxp struct + * @session_type: Type of the session to be updated. One of enum pxp_session_types. + * @session_id: Session identifier of the session, containing type and index info + * + * Return: status. 0 means update is successful. + */ +int intel_pxp_sm_ioctl_mark_session_in_play(struct intel_pxp *pxp, int session_type, + u32 session_id) +{ + int ret; + int session_index; + int session_type_in_id; + struct intel_pxp_sm_session *curr; + struct intel_gt *gt = container_of(pxp, struct intel_gt, pxp); + + ret = pxp_get_session_index(session_id, &session_index, &session_type_in_id); + if (ret) + return ret; + + if (session_type != session_type_in_id) + return -EINVAL; + + lockdep_assert_held(&pxp->ctx.mutex); + + list_for_each_entry(curr, session_list(pxp, session_type), list) { + if (curr->index == session_index) { + curr->is_in_play = true; + return 0; + } + } + + drm_err(>->i915->drm, "Failed to %s couldn't find active session\n", __func__); + return -EINVAL; +} diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp_sm.h b/drivers/gpu/drm/i915/pxp/intel_pxp_sm.h index 75fffb7d8b0e..aaa44d365f39 100644 --- a/drivers/gpu/drm/i915/pxp/intel_pxp_sm.h +++ b/drivers/gpu/drm/i915/pxp/intel_pxp_sm.h @@ -40,4 +40,6 @@ struct intel_pxp_sm_session { int intel_pxp_sm_ioctl_reserve_session(struct intel_pxp *pxp, struct drm_file *drmfile, int session_type, int protection_mode, u32 *pxp_tag); +int intel_pxp_sm_ioctl_mark_session_in_play(struct intel_pxp *pxp, int session_type, + u32 session_id); #endif /* __INTEL_PXP_SM_H__ */