|
| 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(>->uc.gsc.fw) || |
| 84 | + !xe_uc_fw_is_loadable(>->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 | +} |
0 commit comments