Skip to content

Commit ff48e05

Browse files
committed
drm/xe/pxp: Initialize PXP structure and KCR reg
As the first step towards adding PXP support, hook in the PXP init function, allocate the PXP structure and initialize the KCR register to allow PXP HWDRM sessions. v2: remove unneeded includes, free PXP memory on error (John) Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> Cc: John Harrison <John.C.Harrison@Intel.com> Reviewed-by: John Harrison <John.C.Harrison@Intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20250129174140.948829-2-daniele.ceraolospurio@intel.com
1 parent ae5d9cd commit ff48e05

File tree

9 files changed

+180
-4
lines changed

9 files changed

+180
-4
lines changed

drivers/gpu/drm/xe/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ xe-y += xe_bb.o \
8787
xe_preempt_fence.o \
8888
xe_pt.o \
8989
xe_pt_walk.o \
90+
xe_pxp.o \
9091
xe_query.o \
9192
xe_range_fence.o \
9293
xe_reg_sr.o \

drivers/gpu/drm/xe/compat-i915-headers/pxp/intel_pxp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include <linux/types.h>
1111

1212
struct drm_gem_object;
13-
struct intel_pxp;
13+
struct xe_pxp;
1414

15-
static inline int intel_pxp_key_check(struct intel_pxp *pxp,
15+
static inline int intel_pxp_key_check(struct xe_pxp *pxp,
1616
struct drm_gem_object *obj,
1717
bool assign)
1818
{
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* SPDX-License-Identifier: MIT */
2+
/*
3+
* Copyright(c) 2024, Intel Corporation. All rights reserved.
4+
*/
5+
6+
#ifndef __XE_PXP_REGS_H__
7+
#define __XE_PXP_REGS_H__
8+
9+
#include "regs/xe_regs.h"
10+
11+
/* The following registers are only valid on platforms with a media GT */
12+
13+
/* KCR enable/disable control */
14+
#define KCR_INIT XE_REG(0x3860f0)
15+
#define KCR_INIT_ALLOW_DISPLAY_ME_WRITES REG_BIT(14)
16+
17+
#endif /* __XE_PXP_REGS_H__ */

drivers/gpu/drm/xe/xe_device.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "xe_pcode.h"
5151
#include "xe_pm.h"
5252
#include "xe_pmu.h"
53+
#include "xe_pxp.h"
5354
#include "xe_query.h"
5455
#include "xe_sriov.h"
5556
#include "xe_survivability_mode.h"
@@ -861,6 +862,11 @@ int xe_device_probe(struct xe_device *xe)
861862
if (err)
862863
goto err_fini_oa;
863864

865+
/* A PXP init failure is not fatal */
866+
err = xe_pxp_init(xe);
867+
if (err && err != -EOPNOTSUPP)
868+
drm_err(&xe->drm, "PXP initialization failed: %pe\n", ERR_PTR(err));
869+
864870
err = drm_dev_register(&xe->drm, 0);
865871
if (err)
866872
goto err_fini_display;

drivers/gpu/drm/xe/xe_device_types.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
struct xe_ggtt;
3838
struct xe_pat_ops;
39+
struct xe_pxp;
3940

4041
#define XE_BO_INVALID_OFFSET LONG_MAX
4142

@@ -307,6 +308,8 @@ struct xe_device {
307308
u8 has_heci_gscfi:1;
308309
/** @info.has_llc: Device has a shared CPU+GPU last level cache */
309310
u8 has_llc:1;
311+
/** @info.has_pxp: Device has PXP support */
312+
u8 has_pxp:1;
310313
/** @info.has_range_tlb_invalidation: Has range based TLB invalidations */
311314
u8 has_range_tlb_invalidation:1;
312315
/** @info.has_sriov: Supports SR-IOV */
@@ -508,6 +511,9 @@ struct xe_device {
508511
/** @oa: oa observation subsystem */
509512
struct xe_oa oa;
510513

514+
/** @pxp: Encapsulate Protected Xe Path support */
515+
struct xe_pxp *pxp;
516+
511517
/** @needs_flr_on_fini: requests function-reset on fini */
512518
bool needs_flr_on_fini;
513519

@@ -583,8 +589,6 @@ struct xe_device {
583589
unsigned int czclk_freq;
584590
unsigned int fsb_freq, mem_freq, is_ddr3;
585591
};
586-
587-
void *pxp;
588592
#endif
589593
};
590594

drivers/gpu/drm/xe/xe_pci.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct xe_device_desc {
6262
u8 has_heci_gscfi:1;
6363
u8 has_heci_cscfi:1;
6464
u8 has_llc:1;
65+
u8 has_pxp:1;
6566
u8 has_sriov:1;
6667
u8 skip_guc_pc:1;
6768
u8 skip_mtcfg:1;
@@ -618,6 +619,7 @@ static int xe_info_init_early(struct xe_device *xe,
618619
xe->info.has_heci_gscfi = desc->has_heci_gscfi;
619620
xe->info.has_heci_cscfi = desc->has_heci_cscfi;
620621
xe->info.has_llc = desc->has_llc;
622+
xe->info.has_pxp = desc->has_pxp;
621623
xe->info.has_sriov = desc->has_sriov;
622624
xe->info.skip_guc_pc = desc->skip_guc_pc;
623625
xe->info.skip_mtcfg = desc->skip_mtcfg;

drivers/gpu/drm/xe/xe_pxp.c

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// SPDX-License-Identifier: MIT
2+
/*
3+
* Copyright(c) 2024 Intel Corporation.
4+
*/
5+
6+
#include "xe_pxp.h"
7+
8+
#include <drm/drm_managed.h>
9+
10+
#include "xe_device_types.h"
11+
#include "xe_force_wake.h"
12+
#include "xe_gt.h"
13+
#include "xe_gt_types.h"
14+
#include "xe_mmio.h"
15+
#include "xe_pxp_types.h"
16+
#include "xe_uc_fw.h"
17+
#include "regs/xe_pxp_regs.h"
18+
19+
/**
20+
* DOC: PXP
21+
*
22+
* PXP (Protected Xe Path) allows execution and flip to display of protected
23+
* (i.e. encrypted) objects. This feature is currently only supported in
24+
* integrated parts.
25+
*/
26+
27+
static bool pxp_is_supported(const struct xe_device *xe)
28+
{
29+
return xe->info.has_pxp && IS_ENABLED(CONFIG_INTEL_MEI_GSC_PROXY);
30+
}
31+
32+
static int kcr_pxp_set_status(const struct xe_pxp *pxp, bool enable)
33+
{
34+
u32 val = enable ? _MASKED_BIT_ENABLE(KCR_INIT_ALLOW_DISPLAY_ME_WRITES) :
35+
_MASKED_BIT_DISABLE(KCR_INIT_ALLOW_DISPLAY_ME_WRITES);
36+
unsigned int fw_ref;
37+
38+
fw_ref = xe_force_wake_get(gt_to_fw(pxp->gt), XE_FW_GT);
39+
if (!xe_force_wake_ref_has_domain(fw_ref, XE_FW_GT))
40+
return -EIO;
41+
42+
xe_mmio_write32(&pxp->gt->mmio, KCR_INIT, val);
43+
xe_force_wake_put(gt_to_fw(pxp->gt), fw_ref);
44+
45+
return 0;
46+
}
47+
48+
static int kcr_pxp_enable(const struct xe_pxp *pxp)
49+
{
50+
return kcr_pxp_set_status(pxp, true);
51+
}
52+
53+
/**
54+
* xe_pxp_init - initialize PXP support
55+
* @xe: the xe_device structure
56+
*
57+
* Initialize the HW state and allocate the objects required for PXP support.
58+
* Note that some of the requirement for PXP support (GSC proxy init, HuC auth)
59+
* are performed asynchronously as part of the GSC init. PXP can only be used
60+
* after both this function and the async worker have completed.
61+
*
62+
* Returns -EOPNOTSUPP if PXP is not supported, 0 if PXP initialization is
63+
* successful, other errno value if there is an error during the init.
64+
*/
65+
int xe_pxp_init(struct xe_device *xe)
66+
{
67+
struct xe_gt *gt = xe->tiles[0].media_gt;
68+
struct xe_pxp *pxp;
69+
int err;
70+
71+
if (!pxp_is_supported(xe))
72+
return -EOPNOTSUPP;
73+
74+
/* we only support PXP on single tile devices with a media GT */
75+
if (xe->info.tile_count > 1 || !gt)
76+
return -EOPNOTSUPP;
77+
78+
/* The GSCCS is required for submissions to the GSC FW */
79+
if (!(gt->info.engine_mask & BIT(XE_HW_ENGINE_GSCCS0)))
80+
return -EOPNOTSUPP;
81+
82+
/* PXP requires both GSC and HuC firmwares to be available */
83+
if (!xe_uc_fw_is_loadable(&gt->uc.gsc.fw) ||
84+
!xe_uc_fw_is_loadable(&gt->uc.huc.fw)) {
85+
drm_info(&xe->drm, "skipping PXP init due to missing FW dependencies");
86+
return -EOPNOTSUPP;
87+
}
88+
89+
pxp = drmm_kzalloc(&xe->drm, sizeof(struct xe_pxp), GFP_KERNEL);
90+
if (!pxp)
91+
return -ENOMEM;
92+
93+
pxp->xe = xe;
94+
pxp->gt = gt;
95+
96+
err = kcr_pxp_enable(pxp);
97+
if (err)
98+
goto out_free;
99+
100+
xe->pxp = pxp;
101+
102+
return 0;
103+
104+
out_free:
105+
drmm_kfree(&xe->drm, pxp);
106+
return err;
107+
}

drivers/gpu/drm/xe/xe_pxp.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* SPDX-License-Identifier: MIT */
2+
/*
3+
* Copyright(c) 2024, Intel Corporation. All rights reserved.
4+
*/
5+
6+
#ifndef __XE_PXP_H__
7+
#define __XE_PXP_H__
8+
9+
struct xe_device;
10+
11+
int xe_pxp_init(struct xe_device *xe);
12+
13+
#endif /* __XE_PXP_H__ */

drivers/gpu/drm/xe/xe_pxp_types.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* SPDX-License-Identifier: MIT */
2+
/*
3+
* Copyright(c) 2024, Intel Corporation. All rights reserved.
4+
*/
5+
6+
#ifndef __XE_PXP_TYPES_H__
7+
#define __XE_PXP_TYPES_H__
8+
9+
struct xe_device;
10+
struct xe_gt;
11+
12+
/**
13+
* struct xe_pxp - pxp state
14+
*/
15+
struct xe_pxp {
16+
/** @xe: Backpoiner to the xe_device struct */
17+
struct xe_device *xe;
18+
19+
/**
20+
* @gt: pointer to the gt that owns the submission-side of PXP
21+
* (VDBOX, KCR and GSC)
22+
*/
23+
struct xe_gt *gt;
24+
};
25+
26+
#endif /* __XE_PXP_TYPES_H__ */

0 commit comments

Comments
 (0)