Commit cbbd3764 authored by Huang, Sean Z's avatar Huang, Sean Z Committed by Rodrigo Vivi
Browse files

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 will need to be re-created after
teardown or power event because hardware encryption key won't be
valid after such cases.

The session ID is exposed as part of the uapi so it can be used as part
of userspace commands.

v2: use gt->uncore->rpm (Chris)
v3: s/arb_is_in_play/arb_is_valid (Chris), move set-up to the new
    init_hw function
v4: move interface defs to separate header, set arb_is valid to false
    on fini (Rodrigo)
v5: handle async component binding

Signed-off-by: default avatarHuang, Sean Z <sean.z.huang@intel.com>
Signed-off-by: default avatarDaniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Reviewed-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210924191452.1539378-8-alan.previn.teres.alexis@intel.com
parent e0111ce0
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -281,6 +281,7 @@ i915-y += i915_perf.o
# Protected execution platform (PXP) support
# Protected execution platform (PXP) support
i915-$(CONFIG_DRM_I915_PXP) += \
i915-$(CONFIG_DRM_I915_PXP) += \
	pxp/intel_pxp.o \
	pxp/intel_pxp.o \
	pxp/intel_pxp_session.o \
	pxp/intel_pxp_tee.o
	pxp/intel_pxp_tee.o


# Post-mortem debug and GPU hang state capture
# Post-mortem debug and GPU hang state capture
+12 −0
Original line number Original line Diff line number Diff line
@@ -3,6 +3,7 @@
 * Copyright(c) 2020 Intel Corporation.
 * Copyright(c) 2020 Intel Corporation.
 */
 */
#include "intel_pxp.h"
#include "intel_pxp.h"
#include "intel_pxp_session.h"
#include "intel_pxp_tee.h"
#include "intel_pxp_tee.h"
#include "gt/intel_context.h"
#include "gt/intel_context.h"
#include "i915_drv.h"
#include "i915_drv.h"
@@ -12,6 +13,11 @@ struct intel_gt *pxp_to_gt(const struct intel_pxp *pxp)
	return container_of(pxp, struct intel_gt, pxp);
	return container_of(pxp, struct intel_gt, pxp);
}
}


bool intel_pxp_is_active(const struct intel_pxp *pxp)
{
	return pxp->arb_is_valid;
}

/* KCR register definitions */
/* KCR register definitions */
#define KCR_INIT _MMIO(0x320f0)
#define KCR_INIT _MMIO(0x320f0)
/* Setting KCR Init bit is required after system boot */
/* Setting KCR Init bit is required after system boot */
@@ -72,6 +78,8 @@ void intel_pxp_init(struct intel_pxp *pxp)
	if (!HAS_PXP(gt->i915))
	if (!HAS_PXP(gt->i915))
		return;
		return;


	mutex_init(&pxp->tee_mutex);

	ret = create_vcs_context(pxp);
	ret = create_vcs_context(pxp);
	if (ret)
	if (ret)
		return;
		return;
@@ -93,6 +101,8 @@ void intel_pxp_fini(struct intel_pxp *pxp)
	if (!intel_pxp_is_enabled(pxp))
	if (!intel_pxp_is_enabled(pxp))
		return;
		return;


	pxp->arb_is_valid = false;

	intel_pxp_tee_component_fini(pxp);
	intel_pxp_tee_component_fini(pxp);


	destroy_vcs_context(pxp);
	destroy_vcs_context(pxp);
@@ -101,6 +111,8 @@ void intel_pxp_fini(struct intel_pxp *pxp)
void intel_pxp_init_hw(struct intel_pxp *pxp)
void intel_pxp_init_hw(struct intel_pxp *pxp)
{
{
	kcr_pxp_enable(pxp_to_gt(pxp));
	kcr_pxp_enable(pxp_to_gt(pxp));

	intel_pxp_create_arb_session(pxp);
}
}


void intel_pxp_fini_hw(struct intel_pxp *pxp)
void intel_pxp_fini_hw(struct intel_pxp *pxp)
+2 −0
Original line number Original line Diff line number Diff line
@@ -15,6 +15,8 @@ static inline bool intel_pxp_is_enabled(const struct intel_pxp *pxp)


#ifdef CONFIG_DRM_I915_PXP
#ifdef CONFIG_DRM_I915_PXP
struct intel_gt *pxp_to_gt(const struct intel_pxp *pxp);
struct intel_gt *pxp_to_gt(const struct intel_pxp *pxp);
bool intel_pxp_is_active(const struct intel_pxp *pxp);

void intel_pxp_init(struct intel_pxp *pxp);
void intel_pxp_init(struct intel_pxp *pxp);
void intel_pxp_fini(struct intel_pxp *pxp);
void intel_pxp_fini(struct intel_pxp *pxp);


+74 −0
Original line number Original line Diff line number Diff line
// SPDX-License-Identifier: MIT
/*
 * Copyright(c) 2020, Intel Corporation. All rights reserved.
 */

#include "drm/i915_drm.h"
#include "i915_drv.h"

#include "intel_pxp.h"
#include "intel_pxp_session.h"
#include "intel_pxp_tee.h"
#include "intel_pxp_types.h"

#define ARB_SESSION I915_PROTECTED_CONTENT_DEFAULT_SESSION /* shorter define */

#define GEN12_KCR_SIP _MMIO(0x32260) /* KCR hwdrm session in play 0-31 */

static bool intel_pxp_session_is_in_play(struct intel_pxp *pxp, u32 id)
{
	struct intel_gt *gt = pxp_to_gt(pxp);
	intel_wakeref_t wakeref;
	u32 sip = 0;

	with_intel_runtime_pm(gt->uncore->rpm, wakeref)
		sip = intel_uncore_read(gt->uncore, GEN12_KCR_SIP);

	return sip & BIT(id);
}

static int pxp_wait_for_session_state(struct intel_pxp *pxp, u32 id, bool in_play)
{
	struct intel_gt *gt = pxp_to_gt(pxp);
	intel_wakeref_t wakeref;
	u32 mask = BIT(id);
	int ret;

	with_intel_runtime_pm(gt->uncore->rpm, wakeref)
		ret = intel_wait_for_register(gt->uncore,
					      GEN12_KCR_SIP,
					      mask,
					      in_play ? mask : 0,
					      100);

	return ret;
}

int intel_pxp_create_arb_session(struct intel_pxp *pxp)
{
	struct intel_gt *gt = pxp_to_gt(pxp);
	int ret;

	pxp->arb_is_valid = false;

	if (intel_pxp_session_is_in_play(pxp, ARB_SESSION)) {
		drm_err(&gt->i915->drm, "arb session already in play at creation time\n");
		return -EEXIST;
	}

	ret = intel_pxp_tee_cmd_create_arb_session(pxp, ARB_SESSION);
	if (ret) {
		drm_err(&gt->i915->drm, "tee cmd for arb session creation failed\n");
		return ret;
	}

	ret = pxp_wait_for_session_state(pxp, ARB_SESSION, true);
	if (ret) {
		drm_err(&gt->i915->drm, "arb session failed to go in play\n");
		return ret;
	}

	pxp->arb_is_valid = true;

	return 0;
}
+15 −0
Original line number Original line Diff line number Diff line
/* SPDX-License-Identifier: MIT */
/*
 * Copyright(c) 2020, Intel Corporation. All rights reserved.
 */

#ifndef __INTEL_PXP_SESSION_H__
#define __INTEL_PXP_SESSION_H__

#include <linux/types.h>

struct intel_pxp;

int intel_pxp_create_arb_session(struct intel_pxp *pxp);

#endif /* __INTEL_PXP_SESSION_H__ */
Loading