forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drm/i915/pxp: Create the arbitrary session after boot
Create the arbitrary session, with the fixed session id 0xf, after system boot, for the case that application allocates the protected buffer without establishing any protection session. Because the hardware requires at least one alive session for protected buffer creation. This arbitrary session needs to be re-created after teardown or power event because hardware encryption key won't be valid after such cases. Signed-off-by: Huang, Sean Z <sean.z.huang@intel.com>
- Loading branch information
1 parent
3376787
commit b7688bb
Showing
8 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
// SPDX-License-Identifier: MIT | ||
/* | ||
* Copyright(c) 2020, Intel Corporation. All rights reserved. | ||
*/ | ||
|
||
#include "gt/intel_context.h" | ||
#include "gt/intel_engine_pm.h" | ||
|
||
#include "intel_pxp_arb.h" | ||
#include "intel_pxp.h" | ||
#include "intel_pxp_context.h" | ||
#include "intel_pxp_tee.h" | ||
|
||
#define GEN12_KCR_SIP _MMIO(0x32260) /* KCR type0 session in play 0-31 */ | ||
|
||
/* Arbitrary session */ | ||
#define ARB_SESSION_INDEX 0xf | ||
#define ARB_SESSION_TYPE SESSION_TYPE_TYPE0 | ||
#define ARB_PROTECTION_MODE PROTECTION_MODE_HM | ||
|
||
static bool is_hw_arb_session_in_play(struct intel_pxp *pxp) | ||
{ | ||
u32 regval_sip = 0; | ||
intel_wakeref_t wakeref; | ||
struct intel_gt *gt = container_of(pxp, struct intel_gt, pxp); | ||
|
||
with_intel_runtime_pm(>->i915->runtime_pm, wakeref) { | ||
regval_sip = intel_uncore_read(gt->uncore, GEN12_KCR_SIP); | ||
} | ||
|
||
return regval_sip & BIT(ARB_SESSION_INDEX); | ||
} | ||
|
||
/* wait hw session_in_play reg to match the current sw state */ | ||
static int wait_arb_hw_sw_state(struct intel_pxp *pxp) | ||
{ | ||
const int max_retry = 10; | ||
const int ms_delay = 10; | ||
int retry = 0; | ||
int ret; | ||
struct pxp_protected_session *arb = pxp->ctx.arb_session; | ||
|
||
ret = -EINVAL; | ||
for (retry = 0; retry < max_retry; retry++) { | ||
if (is_hw_arb_session_in_play(pxp) == | ||
arb->is_in_play) { | ||
ret = 0; | ||
break; | ||
} | ||
|
||
msleep(ms_delay); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
/** | ||
* create_session_entry - Create a new session entry with provided info. | ||
* @pxp: pointer to pxp struct. | ||
* | ||
* Return: the pointer to the created session. | ||
*/ | ||
static struct pxp_protected_session *create_session_entry(struct intel_pxp *pxp) | ||
{ | ||
struct pxp_protected_session *session; | ||
|
||
session = kzalloc(sizeof(*session), GFP_KERNEL); | ||
if (!session) | ||
return NULL; | ||
|
||
session->context_id = pxp->ctx.id; | ||
session->type = ARB_SESSION_TYPE; | ||
session->protection_mode = ARB_PROTECTION_MODE; | ||
session->index = ARB_SESSION_INDEX; | ||
session->is_in_play = false; | ||
|
||
return session; | ||
} | ||
|
||
int intel_pxp_arb_reserve_session(struct intel_pxp *pxp) | ||
{ | ||
int ret; | ||
struct pxp_protected_session *session = NULL; | ||
|
||
lockdep_assert_held(&pxp->ctx.mutex); | ||
|
||
ret = wait_arb_hw_sw_state(pxp); | ||
if (ret) | ||
return ret; | ||
|
||
session = create_session_entry(pxp); | ||
if (!session) | ||
return -ENOMEM; | ||
|
||
return ret; | ||
} | ||
|
||
/** | ||
* intel_pxp_arb_mark_session_in_play - To put an reserved protected session to "in_play" state | ||
* @pxp: pointer to pxp struct. | ||
* | ||
* Return: status. 0 means update is successful. | ||
*/ | ||
static int intel_pxp_arb_mark_session_in_play(struct intel_pxp *pxp) | ||
{ | ||
struct pxp_protected_session *arb = pxp->ctx.arb_session; | ||
|
||
lockdep_assert_held(&pxp->ctx.mutex); | ||
|
||
if (arb->is_in_play) | ||
return -EINVAL; | ||
|
||
arb->is_in_play = true; | ||
return 0; | ||
} | ||
|
||
int intel_pxp_arb_create_session(struct intel_pxp *pxp) | ||
{ | ||
int ret; | ||
struct intel_gt *gt = container_of(pxp, typeof(*gt), pxp); | ||
|
||
lockdep_assert_held(&pxp->ctx.mutex); | ||
|
||
if (pxp->ctx.flag_display_hm_surface_keys) { | ||
drm_err(>->i915->drm, "%s: arb session is alive so skipping the creation\n", | ||
__func__); | ||
return 0; | ||
} | ||
|
||
ret = intel_pxp_arb_reserve_session(pxp); | ||
if (ret) { | ||
drm_err(>->i915->drm, "Failed to reserve arb session\n"); | ||
goto end; | ||
} | ||
|
||
ret = intel_pxp_tee_cmd_create_arb_session(pxp); | ||
if (ret) { | ||
drm_err(>->i915->drm, "Failed to send tee cmd for arb session creation\n"); | ||
goto end; | ||
} | ||
|
||
ret = intel_pxp_arb_mark_session_in_play(pxp); | ||
if (ret) { | ||
drm_err(>->i915->drm, "Failed to mark arb session status in play\n"); | ||
goto end; | ||
} | ||
|
||
pxp->ctx.flag_display_hm_surface_keys = true; | ||
|
||
end: | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* SPDX-License-Identifier: MIT */ | ||
/* | ||
* Copyright(c) 2020, Intel Corporation. All rights reserved. | ||
*/ | ||
|
||
#ifndef __INTEL_PXP_SM_H__ | ||
#define __INTEL_PXP_SM_H__ | ||
|
||
#include "intel_pxp.h" | ||
|
||
/** | ||
* struct pxp_protected_session - structure to track all active sessions. | ||
*/ | ||
struct pxp_protected_session { | ||
/** @index: Numeric identifier for this protected session */ | ||
int index; | ||
/** @type: Type of session */ | ||
int type; | ||
/** @protection_mode: mode of protection requested */ | ||
int protection_mode; | ||
/** @context_id: context identifier of the protected session requestor */ | ||
int context_id; | ||
|
||
/** | ||
* @is_in_play: indicates whether the session has been established | ||
* in the HW root of trust if this flag is false, it | ||
* indicates an application has reserved this session, | ||
* but has not * established the session in the | ||
* hardware yet. | ||
*/ | ||
bool is_in_play; | ||
}; | ||
|
||
int intel_pxp_arb_create_session(struct intel_pxp *pxp); | ||
|
||
#endif /* __INTEL_PXP_SM_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters