From nobody Wed Apr 8 12:49:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1926DC05027 for ; Mon, 23 Jan 2023 15:29:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232329AbjAWP3U (ORCPT ); Mon, 23 Jan 2023 10:29:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231825AbjAWP3S (ORCPT ); Mon, 23 Jan 2023 10:29:18 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CCE2A1A483; Mon, 23 Jan 2023 07:28:56 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id DCD6220E2D11; Mon, 23 Jan 2023 07:23:07 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com DCD6220E2D11 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1674487389; bh=Li2UJyY0mGyrGpuxPLsk95rzcd9mDiZ9P/GYVetjqcw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I67w1+gjVjdOUzjLbHb5UkXxSblfXRehrmpBsxd/8+khhfHljgMF+bQMLFSczSexy 2gMObMMD5xu1Z4Lg15FsCs1KxVXQs9+7ySNPIhXhsAonwUOxlV5mWQkr37Abd8qcB9 lDhQQ4oG8UX6X1wbOYMV0w/lJFeX/DV9M8tfqL6E= From: Jeremi Piotrowski To: linux-kernel@vger.kernel.org Cc: Jeremi Piotrowski , "Brijesh Singh" , "Tom Lendacky" , "Kalra, Ashish" , "Rafael J. Wysocki" , "Len Brown" , linux-acpi@vger.kernel.org Subject: [PATCH v1 1/8] include/acpi: add definition of ASPT table Date: Mon, 23 Jan 2023 15:22:43 +0000 Message-Id: <20230123152250.26413-2-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230123152250.26413-1-jpiotrowski@linux.microsoft.com> References: <20230123152250.26413-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The AMD Secure Processor ACPI Table provides the memory location of the register window and register offsets necessary to communicate with AMD's PSP (Platform Security Processor). This table is exposed on Hyper-V VMs configured with support for AMD's SNP isolation technology. Signed-off-by: Jeremi Piotrowski --- include/acpi/actbl1.h | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/include/acpi/actbl1.h b/include/acpi/actbl1.h index 15c78678c5d3..00d40373df37 100644 --- a/include/acpi/actbl1.h +++ b/include/acpi/actbl1.h @@ -26,6 +26,7 @@ */ #define ACPI_SIG_AEST "AEST" /* Arm Error Source Table */ #define ACPI_SIG_ASF "ASF!" /* Alert Standard Format table */ +#define ACPI_SIG_ASPT "ASPT" /* AMD Secure Processor Table */ #define ACPI_SIG_BERT "BERT" /* Boot Error Record Table */ #define ACPI_SIG_BGRT "BGRT" /* Boot Graphics Resource Table */ #define ACPI_SIG_BOOT "BOOT" /* Simple Boot Flag Table */ @@ -106,6 +107,51 @@ struct acpi_whea_header { u64 mask; /* Bitmask required for this register instruction */ }; =20 +/* https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/acpitabl/= ns-acpitabl-aspt_table */ +#define ASPT_REVISION_ID 0x01 +struct acpi_table_aspt { + struct acpi_table_header header; + u32 num_entries; +}; + +struct acpi_aspt_header { + u16 type; + u16 length; +}; + +enum acpi_aspt_type { + ACPI_ASPT_TYPE_GLOBAL_REGS =3D 0, + ACPI_ASPT_TYPE_SEV_MBOX_REGS =3D 1, + ACPI_ASPT_TYPE_ACPI_MBOX_REGS =3D 2, +}; + +/* 0: ASPT Global Registers */ +struct acpi_aspt_global_regs { + struct acpi_aspt_header header; + u32 reserved; + u64 feature_reg_addr; + u64 irq_en_reg_addr; + u64 irq_st_reg_addr; +}; + +/* 1: ASPT SEV Mailbox Registers */ +struct acpi_aspt_sev_mbox_regs { + struct acpi_aspt_header header; + u8 mbox_irq_id; + u8 reserved[3]; + u64 cmd_resp_reg_addr; + u64 cmd_buf_lo_reg_addr; + u64 cmd_buf_hi_reg_addr; +}; + +/* 2: ASPT ACPI Mailbox Registers */ +struct acpi_aspt_acpi_mbox_regs { + struct acpi_aspt_header header; + u32 reserved1; + u64 cmd_resp_reg_addr; + u64 reserved2[2]; +}; + /*************************************************************************= ****** * * ASF - Alert Standard Format table (Signature "ASF!") --=20 2.25.1 From nobody Wed Apr 8 12:49:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A8CAC54E94 for ; Mon, 23 Jan 2023 15:24:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232726AbjAWPYc (ORCPT ); Mon, 23 Jan 2023 10:24:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232694AbjAWPYM (ORCPT ); Mon, 23 Jan 2023 10:24:12 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AF51E1449F; Mon, 23 Jan 2023 07:23:40 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id ADE7720E2D0F; Mon, 23 Jan 2023 07:23:19 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com ADE7720E2D0F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1674487401; bh=9zBj7lGZiNLssSN0Bow0NnJuBiAOG3TjbvKNnsD+cgs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=piUgfKTMtNgh91hbplX9eKpXd+cuU/rha676DInDJuLERkQLHA2nONmmv2OsnQVjp hSQBjrl0UAZPYIEpKncMTGUCcN6sqxXLu/n3hokF9Qt4rQ0XGuB0EibnNmjjuxQZjn zR6e6P54nIBapIr6mh5IysSrEzuQrfi7iY3Yr+48= From: Jeremi Piotrowski To: linux-kernel@vger.kernel.org Cc: Jeremi Piotrowski , "Brijesh Singh" , "Tom Lendacky" , "Kalra, Ashish" , linux-crypto@vger.kernel.org, "Rafael J. Wysocki" , "Len Brown" , linux-acpi@vger.kernel.org Subject: [PATCH v1 2/8] ACPI: ASPT: Add helper to parse table Date: Mon, 23 Jan 2023 15:22:44 +0000 Message-Id: <20230123152250.26413-3-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230123152250.26413-1-jpiotrowski@linux.microsoft.com> References: <20230123152250.26413-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The ASP table indicates the presence of a Platform Security Processor with a register window and registers to configure interrupt delivery. The helper checks for the presence of the table and returns a resource and struct with register offsets. Signed-off-by: Jeremi Piotrowski --- drivers/acpi/Makefile | 1 + drivers/acpi/aspt.c | 104 ++++++++++++++++++++++++++++++ include/linux/platform_data/psp.h | 32 +++++++++ 3 files changed, 137 insertions(+) create mode 100644 drivers/acpi/aspt.c create mode 100644 include/linux/platform_data/psp.h diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 0002eecbf870..9621c90e0221 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -57,6 +57,7 @@ acpi-y +=3D evged.o acpi-y +=3D sysfs.o acpi-y +=3D property.o acpi-$(CONFIG_X86) +=3D acpi_cmos_rtc.o +acpi-$(CONFIG_X86) +=3D aspt.o acpi-$(CONFIG_X86) +=3D x86/apple.o acpi-$(CONFIG_X86) +=3D x86/utils.o acpi-$(CONFIG_X86) +=3D x86/s2idle.o diff --git a/drivers/acpi/aspt.c b/drivers/acpi/aspt.c new file mode 100644 index 000000000000..cf629db35036 --- /dev/null +++ b/drivers/acpi/aspt.c @@ -0,0 +1,104 @@ +// SPDX-License-Identifier: GPL-2.0-only +#define pr_fmt(fmt) "ACPI: ASPT: " fmt +#include +#include +#include + +static int __init psp_validate_regs(const struct acpi_aspt_global_regs *gr= egs, + const struct acpi_aspt_sev_mbox_regs *sevregs, + const struct acpi_aspt_acpi_mbox_regs *acpiregs) +{ + u64 pfn; + int idx; + u64 regs[] =3D { + gregs->feature_reg_addr, + gregs->irq_en_reg_addr, + gregs->irq_st_reg_addr, + sevregs->cmd_resp_reg_addr, + sevregs->cmd_buf_lo_reg_addr, + sevregs->cmd_buf_hi_reg_addr, + acpiregs->cmd_resp_reg_addr + }; + pfn =3D regs[0] >> PAGE_SHIFT; + for (idx =3D 1; idx < ARRAY_SIZE(regs); idx++) { + if (regs[idx] >> PAGE_SHIFT !=3D pfn) + return -EINVAL; + } + return 0; +} + +/** + * acpi_parse_aspt - Parse ASPT table and return contained information + * @res: will be filled with the address and size of the ASP register wind= ow + * @pdata: will be filled with the register offsets parsed from the ASPT t= able + */ +int __init acpi_parse_aspt(struct resource *res, struct psp_platform_data = *pdata) +{ + struct acpi_aspt_acpi_mbox_regs acpiregs =3D {}; + struct acpi_aspt_sev_mbox_regs sevregs =3D {}; + struct acpi_aspt_global_regs gregs =3D {}; + struct acpi_aspt_header *entry, *end; + struct acpi_table_aspt *aspt; + unsigned long base; + acpi_status status; + int err =3D 0; + + status =3D acpi_get_table(ACPI_SIG_ASPT, 0, (struct acpi_table_header **)= &aspt); + if (ACPI_FAILURE(status)) + return -ENODEV; + if (aspt->header.revision !=3D ASPT_REVISION_ID) { + pr_err("unsupported table revision: %d\n", (int)aspt->header.revision); + err =3D -ENODEV; + goto exit; + } + entry =3D (struct acpi_aspt_header *)(aspt + 1); + end =3D (struct acpi_aspt_header *)((void *)aspt + aspt->header.length); + while (entry < end) { + if (((void *)entry + entry->length) > (void *)end) { + pr_err("error during parsing\n"); + err =3D -EINVAL; + goto exit; + } + switch (entry->type) { + case ACPI_ASPT_TYPE_GLOBAL_REGS: + memcpy(&gregs, entry, entry->length); + break; + case ACPI_ASPT_TYPE_SEV_MBOX_REGS: + memcpy(&sevregs, entry, entry->length); + break; + case ACPI_ASPT_TYPE_ACPI_MBOX_REGS: + memcpy(&acpiregs, entry, entry->length); + break; + } + entry =3D (struct acpi_aspt_header *)((void *)entry + entry->length); + } + if (!gregs.header.length || !sevregs.header.length || !acpiregs.header.le= ngth) { + pr_err("missing ASPT table entry: %u %u %u\n", gregs.header.length, + sevregs.header.length, + acpiregs.header.length); + err =3D -EINVAL; + goto exit; + } + /* All registers are expected to be within the same page */ + err =3D psp_validate_regs(&gregs, &sevregs, &acpiregs); + if (err) { + pr_err("ASPT registers span multiple pages\n"); + goto exit; + } + + base =3D ALIGN_DOWN(gregs.feature_reg_addr, PAGE_SIZE); + *res =3D (struct resource)DEFINE_RES_MEM(base, PAGE_SIZE); + + pdata->sev_cmd_resp_reg =3D sevregs.cmd_resp_reg_addr & ~PAGE_MASK; + pdata->sev_cmd_buf_lo_reg =3D sevregs.cmd_buf_lo_reg_addr & ~PAGE_MASK; + pdata->sev_cmd_buf_hi_reg =3D sevregs.cmd_buf_hi_reg_addr & ~PAGE_MASK; + pdata->feature_reg =3D gregs.feature_reg_addr & ~PAGE_MASK; + pdata->irq_en_reg =3D gregs.irq_en_reg_addr & ~PAGE_MASK; + pdata->irq_st_reg =3D gregs.irq_st_reg_addr & ~PAGE_MASK; + pdata->mbox_irq_id =3D sevregs.mbox_irq_id; + pdata->acpi_cmd_resp_reg =3D acpiregs.cmd_resp_reg_addr & ~PAGE_MASK; + +exit: + acpi_put_table((struct acpi_table_header *)aspt); + return err; +} diff --git a/include/linux/platform_data/psp.h b/include/linux/platform_dat= a/psp.h new file mode 100644 index 000000000000..b761f72168d6 --- /dev/null +++ b/include/linux/platform_data/psp.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * psp.h - PSP register offsets parsed from ASPT ACPI table + */ + +#ifndef __LINUX_PSP_H +#define __LINUX_PSP_H + +#include +#include + +struct psp_platform_data { + int sev_cmd_resp_reg; + int sev_cmd_buf_lo_reg; + int sev_cmd_buf_hi_reg; + int feature_reg; + int irq_en_reg; + int irq_st_reg; + int mbox_irq_id; + int acpi_cmd_resp_reg; +}; + +#if IS_ENABLED(CONFIG_ACPI) +int acpi_parse_aspt(struct resource *res, struct psp_platform_data *pdata); +#else +static inline acpi_parse_aspt(struct resource *res, struct psp_platform_da= ta *pdata) +{ + return -ENODEV; +} +#endif + +#endif /* __LINUX_PSP_H */ --=20 2.25.1 From nobody Wed Apr 8 12:49:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A018C38142 for ; Mon, 23 Jan 2023 15:24:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232739AbjAWPYf (ORCPT ); Mon, 23 Jan 2023 10:24:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232734AbjAWPYP (ORCPT ); Mon, 23 Jan 2023 10:24:15 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A863129E26 for ; Mon, 23 Jan 2023 07:23:47 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id 13B8D20E2D13; Mon, 23 Jan 2023 07:23:29 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 13B8D20E2D13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1674487411; bh=V5U0dGe/I5fPLsT2QyvbqmymDfcu/QZWw4Mvy3gGWjw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SQvKbGo8cIrDOydCG3spL4AUaVeGlrBPo7p9QgofABRCjv0RC9c5sN1asuZyvuICf JvPB3ps3aUdLfqo27z9zFSakWyOSH4WZqvXnX/u6DmRn8XKpbsEmA9q3j1GRpA//fl OpKH5zmVG8UdJxXeUxnXr/PIkJlPLyoqWbgTToqU= From: Jeremi Piotrowski To: linux-kernel@vger.kernel.org Cc: Jeremi Piotrowski , "Brijesh Singh" , "Tom Lendacky" , "Kalra, Ashish" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , x86@kernel.org Subject: [PATCH v1 3/8] x86/psp: Register PSP platform device when ASP table is present Date: Mon, 23 Jan 2023 15:22:45 +0000 Message-Id: <20230123152250.26413-4-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230123152250.26413-1-jpiotrowski@linux.microsoft.com> References: <20230123152250.26413-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The ASP table contains the memory location of the register window for communication with the Platform Security Processor. The device is not exposed as an acpi node, so it is necessary to probe for the table and register a platform_device to represent it in the kernel. At least conceptually, the same PSP may be exposed on the PCIe bus as well, in which case it would be necessary to choose whether to use a PCI BAR or the register window defined in ASPT for communication. There is no advantage to using the ACPI and there are no known bare-metal systems that expose the ASP table, so device registration is restricted to the only systems known to provide an ASPT: Hyper-V VMs. Hyper-V VMs also do not expose the PSP over PCIe. This is a skeleton device at this point, as the ccp driver is not yet prepared to correctly probe it. Interrupt configuration will come later on as well. Signed-off-by: Jeremi Piotrowski --- arch/x86/kernel/Makefile | 2 +- arch/x86/kernel/psp.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 arch/x86/kernel/psp.c diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index f901658d9f7c..e2e19f2d08a7 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -139,7 +139,7 @@ obj-$(CONFIG_UNWINDER_ORC) +=3D unwind_orc.o obj-$(CONFIG_UNWINDER_FRAME_POINTER) +=3D unwind_frame.o obj-$(CONFIG_UNWINDER_GUESS) +=3D unwind_guess.o =20 -obj-$(CONFIG_AMD_MEM_ENCRYPT) +=3D sev.o +obj-$(CONFIG_AMD_MEM_ENCRYPT) +=3D psp.o sev.o =20 obj-$(CONFIG_CFI_CLANG) +=3D cfi.o =20 diff --git a/arch/x86/kernel/psp.c b/arch/x86/kernel/psp.c new file mode 100644 index 000000000000..d404df47cc04 --- /dev/null +++ b/arch/x86/kernel/psp.c @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include + +static struct platform_device psp_device =3D { + .name =3D "psp", + .id =3D PLATFORM_DEVID_NONE, +}; + +static int __init psp_init_platform_device(void) +{ + struct psp_platform_data pdata =3D {}; + struct resource res[1]; + int err; + + /* + * The ACPI PSP interface is mutually exclusive with the PCIe interface, + * but there is no reason to use the ACPI interface over the PCIe one. + * Restrict probing ACPI PSP to platforms known to only expose the ACPI + * interface, which at this time is SNP-host capable Hyper-V VMs. + */ + if (!hypervisor_is_type(X86_HYPER_MS_HYPERV)) + return -ENODEV; + + err =3D acpi_parse_aspt(res, &pdata); + if (err) + return err; + err =3D platform_device_add_resources(&psp_device, res, 1); + if (err) + return err; + + err =3D platform_device_register(&psp_device); + if (err) + return err; + return 0; +} +device_initcall(psp_init_platform_device); --=20 2.25.1 From nobody Wed Apr 8 12:49:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4824AC54E94 for ; Mon, 23 Jan 2023 15:25:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232759AbjAWPYt (ORCPT ); Mon, 23 Jan 2023 10:24:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232716AbjAWPYX (ORCPT ); Mon, 23 Jan 2023 10:24:23 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 36F319773 for ; Mon, 23 Jan 2023 07:23:52 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id 009E320E2D18; Mon, 23 Jan 2023 07:23:32 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 009E320E2D18 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1674487414; bh=6yVfbftlAEMVDoy2/KKdGqDFHRZaTDzPvLDX+11tzNY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kArLyiRwH+OznKs79i5G67uEcgHmCnUZbMnLN0JL1ZXdhJhmVOmfef7eambtIiwpu /NTl2+i5amoldWk4AHR3xPs/NtPrijLuGLfZg91lpbkRmo+jw2E2NwDi3XfcDyhIlO ZI8pb/3yStKSmRegYbSVGDNMdLVoQwg3u7XxQ0ik= From: Jeremi Piotrowski To: linux-kernel@vger.kernel.org Cc: Jeremi Piotrowski , "Brijesh Singh" , "Tom Lendacky" , "Kalra, Ashish" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , x86@kernel.org Subject: [PATCH v1 4/8] x86/psp: Add IRQ support Date: Mon, 23 Jan 2023 15:22:46 +0000 Message-Id: <20230123152250.26413-5-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230123152250.26413-1-jpiotrowski@linux.microsoft.com> References: <20230123152250.26413-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The ACPI PSP device provides a mailbox irq that needs to be configured through the ACPI mailbox register first. This requires passing a CPU vector and physical CPU id and then enabling interrupt delivery. Allocate the irq directly from the default irq domain (x86_vector_domain) to get access to the required information. By passing a cpumask through irq_alloc_info the vector is immediately allocated (and not later during activation) and can be retrieved. Signed-off-by: Jeremi Piotrowski --- arch/x86/kernel/psp.c | 179 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 175 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/psp.c b/arch/x86/kernel/psp.c index d404df47cc04..24181d132bae 100644 --- a/arch/x86/kernel/psp.c +++ b/arch/x86/kernel/psp.c @@ -1,8 +1,176 @@ // SPDX-License-Identifier: GPL-2.0-only - +#define pr_fmt(fmt) "psp: " fmt #include #include +#include +#include #include +#include + +#define PSP_ACPI_DATA_SHIFT 0 +#define PSP_ACPI_DATA_MASK GENMASK(15, 0) +#define PSP_ACPI_CMDID_SHIFT 16 +#define PSP_ACPI_CMDID_MASK GENMASK(25, 16) +#define PSP_ACPI_STATUS_SHIFT 26 +#define PSP_ACPI_STATUS_MASK GENMASK(30, 26) +#define PSP_ACPI_RESPONSE_BIT BIT(31) + +#define PSP_ACPI_VECTOR_SHIFT 0 +#define PSP_ACPI_VECTOR_MASK GENMASK(7, 0) +#define PSP_ACPI_MBOX_IRQID_SHIFT 10 +#define PSP_ACPI_MBOX_IRQID_MASK GENMASK(15, 10) + +#define PSP_ACPI_IRQ_EN_BIT BIT(0) +#define PSP_ACPI_IRQ_EN_MBOX_IRQID_SHIFT 10 +#define PSP_ACPI_IRQ_EN_MBOX_IRQID_MASK GENMASK(15, 10) + +// AMD Secure Processor +enum ASP_CMDID { + ASP_CMDID_PART1 =3D 0x82, + ASP_CMDID_PART2 =3D 0x83, + ASP_CMDID_PART3 =3D 0x84, + ASP_CMDID_IRQ_EN =3D 0x85, +}; + +enum ASP_CMD_STATUS { + ASP_CMD_STATUS_SUCCESS =3D 0x0, + ASP_CMD_STATUS_INVALID_CMD =3D 0x1, + ASP_CMD_STATUS_INVALID_PARAM =3D 0x2, + ASP_CMD_STATUS_INVALID_FW_STATE =3D 0x3, + ASP_CMD_STATUS_FAILURE =3D 0x1F, +}; + +struct psp_irq_data { + void __iomem *base; + int mbox_irq_id; + int acpi_cmd_resp_reg; +}; + +static int psp_sync_cmd(void __iomem *reg, u8 cmd, u16 data) +{ + u32 val =3D 0; + int err; + + val |=3D data & PSP_ACPI_DATA_MASK; + val |=3D (cmd << PSP_ACPI_CMDID_SHIFT) & PSP_ACPI_CMDID_MASK; + writel(val, reg); + err =3D readl_poll_timeout_atomic(reg, val, val & PSP_ACPI_RESPONSE_BIT, = 2, 10000); + if (err < 0) + return err; + return (val & PSP_ACPI_STATUS_MASK) >> PSP_ACPI_STATUS_SHIFT; +} + +static int psp_set_irq_enable(struct psp_irq_data *data, bool irq_en) +{ + void __iomem *reg =3D data->base + data->acpi_cmd_resp_reg; + u8 mbox_irq_id =3D data->mbox_irq_id; + u16 val =3D 0; + int err; + + val |=3D irq_en ? PSP_ACPI_IRQ_EN_BIT : 0; + val |=3D (mbox_irq_id << PSP_ACPI_IRQ_EN_MBOX_IRQID_SHIFT) & PSP_ACPI_IRQ= _EN_MBOX_IRQID_MASK; + err =3D psp_sync_cmd(reg, ASP_CMDID_IRQ_EN, val); + if (err !=3D ASP_CMD_STATUS_SUCCESS) { + pr_err("ASP_CMDID_IRQ_EN failed: %d\n", err); + return -EIO; + } + return 0; +} + +static int psp_configure_irq(struct psp_irq_data *data, int vector, unsign= ed int cpu) +{ + void __iomem *reg =3D data->base + data->acpi_cmd_resp_reg; + unsigned int dest_cpu =3D cpu_physical_id(cpu); + u8 mbox_irq_id =3D data->mbox_irq_id; + u16 part1, part2, part3; + int err; + + part1 =3D dest_cpu; + part2 =3D dest_cpu >> 16; + part3 =3D vector & PSP_ACPI_VECTOR_MASK; + part3 |=3D (mbox_irq_id << PSP_ACPI_MBOX_IRQID_SHIFT) & PSP_ACPI_MBOX_IRQ= ID_MASK; + + err =3D psp_sync_cmd(reg, ASP_CMDID_PART1, part1); + if (err !=3D ASP_CMD_STATUS_SUCCESS) { + pr_err("ASP_CMDID_PART1 failed: %d\n", err); + return -EIO; + } + err =3D psp_sync_cmd(reg, ASP_CMDID_PART2, part2); + if (err !=3D ASP_CMD_STATUS_SUCCESS) { + pr_err("ASP_CMDID_PART2 failed: %d\n", err); + return -EIO; + } + err =3D psp_sync_cmd(reg, ASP_CMDID_PART3, part3); + if (err !=3D ASP_CMD_STATUS_SUCCESS) { + pr_err("ASP_CMDID_PART3 failed: %d\n", err); + return -EIO; + } + + return 0; +} + + +static int psp_init_irq(const struct psp_platform_data *pdata, + const struct resource *reg, struct resource *irq) +{ + struct psp_irq_data pspirqd; + struct irq_alloc_info info; + struct irq_data *data =3D NULL; + struct irq_cfg *cfg =3D NULL; + void __iomem *base =3D NULL; + int virq; + int err; + + base =3D ioremap(reg->start, resource_size(reg)); + if (IS_ERR(base)) + return PTR_ERR(base); + if (!base) + return -ENOMEM; + pspirqd.mbox_irq_id =3D pdata->mbox_irq_id; + pspirqd.acpi_cmd_resp_reg =3D pdata->acpi_cmd_resp_reg; + pspirqd.base =3D base; + init_irq_alloc_info(&info, cpumask_of(0)); + virq =3D irq_domain_alloc_irqs(NULL, 1, NUMA_NO_NODE, &info); + if (virq <=3D 0) { + pr_err("failed to allocate vector: %d\n", virq); + err =3D -ENOMEM; + goto unmap; + } + irq_set_handler(virq, handle_edge_irq); + data =3D irq_get_irq_data(virq); + if (!data) { + pr_err("no irq data\n"); + err =3D -ENODEV; + goto freeirq; + + } + cfg =3D irqd_cfg(data); + if (!data) { + pr_err("no irq cfg\n"); + err =3D -ENODEV; + goto freeirq; + } + err =3D psp_configure_irq(&pspirqd, cfg->vector, 0); + if (err) { + pr_err("failed to configure irq: %d\n", err); + goto freeirq; + } + err =3D psp_set_irq_enable(&pspirqd, true); + if (err) { + pr_err("failed to enable irq: %d\n", err); + goto freeirq; + } + + *irq =3D (struct resource)DEFINE_RES_IRQ(virq); + iounmap(base); + return 0; + +freeirq: + irq_domain_free_irqs(virq, 1); +unmap: + iounmap(base); + return err; +} =20 static struct platform_device psp_device =3D { .name =3D "psp", @@ -12,7 +180,7 @@ static struct platform_device psp_device =3D { static int __init psp_init_platform_device(void) { struct psp_platform_data pdata =3D {}; - struct resource res[1]; + struct resource res[2]; int err; =20 /* @@ -24,10 +192,13 @@ static int __init psp_init_platform_device(void) if (!hypervisor_is_type(X86_HYPER_MS_HYPERV)) return -ENODEV; =20 - err =3D acpi_parse_aspt(res, &pdata); + err =3D acpi_parse_aspt(&res[0], &pdata); + if (err) + return err; + err =3D psp_init_irq(&pdata, &res[0], &res[1]); if (err) return err; - err =3D platform_device_add_resources(&psp_device, res, 1); + err =3D platform_device_add_resources(&psp_device, res, 2); if (err) return err; =20 --=20 2.25.1 From nobody Wed Apr 8 12:49:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A8A0C61D97 for ; Mon, 23 Jan 2023 15:25:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232240AbjAWPZR (ORCPT ); Mon, 23 Jan 2023 10:25:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232747AbjAWPYq (ORCPT ); Mon, 23 Jan 2023 10:24:46 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CD9D429E14; Mon, 23 Jan 2023 07:24:25 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id CFB7320E2D17; Mon, 23 Jan 2023 07:23:35 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com CFB7320E2D17 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1674487416; bh=ZRr5emoAjwsKHLORaeHN0pRgcw3vJaLO85YWOsHBP7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BWIKbfSO9UWd7qMXcBTSiPeJnP/HB4O6zvUwhR8md4LIvss8UxStEY6iOg4rq3GJy XMLY9NJLgoKvARIO6sHAJmgJC19D4EZwbyVdqYiqVw6jxNo98NaKaz9mt6sMxOxd2O pQJwIIuO2wbw3SjO9y9yLwaTE00Xg4Sta9cCOP4M= From: Jeremi Piotrowski To: linux-kernel@vger.kernel.org Cc: "Brijesh Singh" , "Tom Lendacky" , "Kalra, Ashish" , linux-crypto@vger.kernel.org, Jeremi Piotrowski Subject: [PATCH v1 5/8] crypto: cpp - Bind to psp platform device on x86 Date: Mon, 23 Jan 2023 15:22:47 +0000 Message-Id: <20230123152250.26413-6-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230123152250.26413-1-jpiotrowski@linux.microsoft.com> References: <20230123152250.26413-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The PSP in Hyper-V VMs is exposed through the ASP ACPI table and is represented as a platform_device. Allow the ccp driver to bind to it by adding an id_table and initing the platform_driver also on x86. At this point probe is called for the psp device but init fails due to missing driver data. Signed-off-by: Jeremi Piotrowski --- drivers/crypto/ccp/sp-dev.c | 8 ++++++-- drivers/crypto/ccp/sp-platform.c | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/ccp/sp-dev.c b/drivers/crypto/ccp/sp-dev.c index 7eb3e4668286..52b8d957d0f6 100644 --- a/drivers/crypto/ccp/sp-dev.c +++ b/drivers/crypto/ccp/sp-dev.c @@ -258,7 +258,11 @@ static int __init sp_mod_init(void) ret =3D sp_pci_init(); if (ret) return ret; - + ret =3D sp_platform_init(); + if (ret) { + sp_pci_exit(); + return ret; + } #ifdef CONFIG_CRYPTO_DEV_SP_PSP psp_pci_init(); #endif @@ -286,7 +290,7 @@ static void __exit sp_mod_exit(void) #ifdef CONFIG_CRYPTO_DEV_SP_PSP psp_pci_exit(); #endif - + sp_platform_exit(); sp_pci_exit(); #endif =20 diff --git a/drivers/crypto/ccp/sp-platform.c b/drivers/crypto/ccp/sp-platf= orm.c index 7d79a8744f9a..ea8926e87981 100644 --- a/drivers/crypto/ccp/sp-platform.c +++ b/drivers/crypto/ccp/sp-platform.c @@ -56,6 +56,12 @@ static const struct of_device_id sp_of_match[] =3D { MODULE_DEVICE_TABLE(of, sp_of_match); #endif =20 +static const struct platform_device_id sp_plat_match[] =3D { + { "psp" }, + { }, +}; +MODULE_DEVICE_TABLE(platform, sp_plat_match); + static struct sp_dev_vdata *sp_get_of_version(struct platform_device *pdev) { #ifdef CONFIG_OF @@ -212,6 +218,7 @@ static int sp_platform_resume(struct platform_device *p= dev) #endif =20 static struct platform_driver sp_platform_driver =3D { + .id_table =3D sp_plat_match, .driver =3D { .name =3D "ccp", #ifdef CONFIG_ACPI --=20 2.25.1 From nobody Wed Apr 8 12:49:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18F3EC38142 for ; Mon, 23 Jan 2023 15:25:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232570AbjAWPZW (ORCPT ); Mon, 23 Jan 2023 10:25:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232773AbjAWPYu (ORCPT ); Mon, 23 Jan 2023 10:24:50 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9177C12F2C; Mon, 23 Jan 2023 07:24:27 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id 2739220E2D15; Mon, 23 Jan 2023 07:23:38 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2739220E2D15 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1674487419; bh=kkDxZ7tUwT0Uo+e694DaWN5gRE9F7nibTWpCkLw2i3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E5MxCEGujjEaZH+QtZxR+jxvdFxLcGfrMqPwfNsCobz8BQLAugzHtMDurcuLL0T4L AwTNX0kp0UJEpXPPxjrlfm5Xh7VKrP5STJvtF1jMqT5XiELQIL+RuxVK2H3R6zgidY u9xFs/q76p3A8ugKzc0vTINDye5I2/MVi4h9yZLs= From: Jeremi Piotrowski To: linux-kernel@vger.kernel.org Cc: Jeremi Piotrowski , "Brijesh Singh" , "Tom Lendacky" , "Kalra, Ashish" , linux-crypto@vger.kernel.org Subject: [PATCH v1 6/8] crypto: ccp - Add vdata for platform device Date: Mon, 23 Jan 2023 15:22:48 +0000 Message-Id: <20230123152250.26413-7-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230123152250.26413-1-jpiotrowski@linux.microsoft.com> References: <20230123152250.26413-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When matching the "psp" platform_device, determine the register offsets at runtime from the ASP ACPI table. Pass the parsed register offsets from the ASPT through platdata. To support this scenario, mark the members of 'struct sev_vdata' and 'struct psp_vdata' non-const so that the probe function can write the values. This does not affect the other users of sev_vdata/psp_vdata as they define the whole struct const and the pointer in struct sp_dev_vdata stays const too. Signed-off-by: Jeremi Piotrowski --- arch/x86/kernel/psp.c | 3 ++ drivers/crypto/ccp/sp-dev.h | 12 +++---- drivers/crypto/ccp/sp-platform.c | 57 +++++++++++++++++++++++++++++++- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/psp.c b/arch/x86/kernel/psp.c index 24181d132bae..68511a14df63 100644 --- a/arch/x86/kernel/psp.c +++ b/arch/x86/kernel/psp.c @@ -199,6 +199,9 @@ static int __init psp_init_platform_device(void) if (err) return err; err =3D platform_device_add_resources(&psp_device, res, 2); + if (err) + return err; + err =3D platform_device_add_data(&psp_device, &pdata, sizeof(pdata)); if (err) return err; =20 diff --git a/drivers/crypto/ccp/sp-dev.h b/drivers/crypto/ccp/sp-dev.h index 20377e67f65d..aaa651364425 100644 --- a/drivers/crypto/ccp/sp-dev.h +++ b/drivers/crypto/ccp/sp-dev.h @@ -40,9 +40,9 @@ struct ccp_vdata { }; =20 struct sev_vdata { - const unsigned int cmdresp_reg; - const unsigned int cmdbuff_addr_lo_reg; - const unsigned int cmdbuff_addr_hi_reg; + unsigned int cmdresp_reg; + unsigned int cmdbuff_addr_lo_reg; + unsigned int cmdbuff_addr_hi_reg; }; =20 struct tee_vdata { @@ -56,9 +56,9 @@ struct tee_vdata { struct psp_vdata { const struct sev_vdata *sev; const struct tee_vdata *tee; - const unsigned int feature_reg; - const unsigned int inten_reg; - const unsigned int intsts_reg; + unsigned int feature_reg; + unsigned int inten_reg; + unsigned int intsts_reg; }; =20 /* Structure to hold SP device data */ diff --git a/drivers/crypto/ccp/sp-platform.c b/drivers/crypto/ccp/sp-platf= orm.c index ea8926e87981..281dbf6b150c 100644 --- a/drivers/crypto/ccp/sp-platform.c +++ b/drivers/crypto/ccp/sp-platform.c @@ -22,6 +22,7 @@ #include #include #include +#include =20 #include "ccp-dev.h" =20 @@ -30,11 +31,31 @@ struct sp_platform { unsigned int irq_count; }; =20 +#ifdef CONFIG_CRYPTO_DEV_SP_PSP +static struct sev_vdata sev_platform =3D { + .cmdresp_reg =3D -1, + .cmdbuff_addr_lo_reg =3D -1, + .cmdbuff_addr_hi_reg =3D -1, +}; +static struct psp_vdata psp_platform =3D { + .sev =3D &sev_platform, + .feature_reg =3D -1, + .inten_reg =3D -1, + .intsts_reg =3D -1, +}; +#endif + static const struct sp_dev_vdata dev_vdata[] =3D { { .bar =3D 0, #ifdef CONFIG_CRYPTO_DEV_SP_CCP .ccp_vdata =3D &ccpv3_platform, +#endif + }, + { + .bar =3D 0, +#ifdef CONFIG_CRYPTO_DEV_SP_PSP + .psp_vdata =3D &psp_platform, #endif }, }; @@ -57,7 +78,7 @@ MODULE_DEVICE_TABLE(of, sp_of_match); #endif =20 static const struct platform_device_id sp_plat_match[] =3D { - { "psp" }, + { "psp", (kernel_ulong_t)&dev_vdata[1] }, { }, }; MODULE_DEVICE_TABLE(platform, sp_plat_match); @@ -86,6 +107,38 @@ static struct sp_dev_vdata *sp_get_acpi_version(struct = platform_device *pdev) return NULL; } =20 +static struct sp_dev_vdata *sp_get_plat_version(struct platform_device *pd= ev) +{ + struct sp_dev_vdata *drvdata =3D (struct sp_dev_vdata *)pdev->id_entry->d= river_data; + struct device *dev =3D &pdev->dev; + + if (drvdata =3D=3D &dev_vdata[1]) { + struct psp_platform_data *pdata =3D dev_get_platdata(dev); + + if (!pdata) { + dev_err(dev, "missing platform data\n"); + return NULL; + } +#ifdef CONFIG_CRYPTO_DEV_SP_PSP + psp_platform.feature_reg =3D pdata->feature_reg; + psp_platform.inten_reg =3D pdata->irq_en_reg; + psp_platform.intsts_reg =3D pdata->irq_st_reg; + sev_platform.cmdresp_reg =3D pdata->sev_cmd_resp_reg; + sev_platform.cmdbuff_addr_lo_reg =3D pdata->sev_cmd_buf_lo_reg; + sev_platform.cmdbuff_addr_hi_reg =3D pdata->sev_cmd_buf_hi_reg; + dev_dbg(dev, "GLBL feature:\t%x\n", pdata->feature_reg); + dev_dbg(dev, "GLBL irq en:\t%x\n", pdata->irq_en_reg); + dev_dbg(dev, "GLBL irq st:\t%x\n", pdata->irq_st_reg); + dev_dbg(dev, "SEV cmdresp:\t%x\n", pdata->sev_cmd_resp_reg); + dev_dbg(dev, "SEV cmdbuf lo:\t%x\n", pdata->sev_cmd_buf_lo_reg); + dev_dbg(dev, "SEV cmdbuf hi:\t%x\n", pdata->sev_cmd_buf_hi_reg); + dev_dbg(dev, "SEV mbox:\t%x\n", pdata->mbox_irq_id); + dev_dbg(dev, "ACPI cmdresp:\t%x\n", pdata->acpi_cmd_resp_reg); +#endif + } + return drvdata; +} + static int sp_get_irqs(struct sp_device *sp) { struct sp_platform *sp_platform =3D sp->dev_specific; @@ -137,6 +190,8 @@ static int sp_platform_probe(struct platform_device *pd= ev) sp->dev_specific =3D sp_platform; sp->dev_vdata =3D pdev->dev.of_node ? sp_get_of_version(pdev) : sp_get_acpi_version(pdev); + if (!sp->dev_vdata && pdev->id_entry) + sp->dev_vdata =3D sp_get_plat_version(pdev); if (!sp->dev_vdata) { ret =3D -ENODEV; dev_err(dev, "missing driver data\n"); --=20 2.25.1 From nobody Wed Apr 8 12:49:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F3C5C38142 for ; Mon, 23 Jan 2023 15:25:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231666AbjAWPZU (ORCPT ); Mon, 23 Jan 2023 10:25:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232755AbjAWPYs (ORCPT ); Mon, 23 Jan 2023 10:24:48 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 71EEA2A990; Mon, 23 Jan 2023 07:24:26 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id 45FBE20E2D1C; Mon, 23 Jan 2023 07:23:40 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 45FBE20E2D1C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1674487421; bh=f6pZHu6WA/l0Wr6r6xjwOggDdU/mGOH5y0VgIu48aRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CTpL+hP1jfHwJgIWyL5E02ar+Ivbg7F3vb3yLQyVIcOQ1EDXh1m4ST7PyAUL2S7Eo Ke9aI0JmACwIMQToFpulqUUS+D2RpYR/H7yKH4hwSNaPWlXbaDcYA+YFz8omtw+XMd 3mPd6S6VqHES18GPFY8B/pjM2NqtWQoY77jGuvlw= From: Jeremi Piotrowski To: linux-kernel@vger.kernel.org Cc: "Brijesh Singh" , "Tom Lendacky" , "Kalra, Ashish" , linux-crypto@vger.kernel.org, Jeremi Piotrowski Subject: [PATCH v1 7/8] crypto: ccp - Skip DMA coherency check for platform psp Date: Mon, 23 Jan 2023 15:22:49 +0000 Message-Id: <20230123152250.26413-8-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230123152250.26413-1-jpiotrowski@linux.microsoft.com> References: <20230123152250.26413-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The value of device_get_dma_attr() is only relevenat for ARM64 and CCP devices to configure the value of the axcache attribute used to access memory by the coprocessor. None of this applies to the platform psp so skip it. Signed-off-by: Jeremi Piotrowski --- drivers/crypto/ccp/sp-platform.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/ccp/sp-platform.c b/drivers/crypto/ccp/sp-platf= orm.c index 281dbf6b150c..b74f16e0e963 100644 --- a/drivers/crypto/ccp/sp-platform.c +++ b/drivers/crypto/ccp/sp-platform.c @@ -29,6 +29,7 @@ struct sp_platform { int coherent; unsigned int irq_count; + bool is_platform; }; =20 #ifdef CONFIG_CRYPTO_DEV_SP_PSP @@ -190,8 +191,10 @@ static int sp_platform_probe(struct platform_device *p= dev) sp->dev_specific =3D sp_platform; sp->dev_vdata =3D pdev->dev.of_node ? sp_get_of_version(pdev) : sp_get_acpi_version(pdev); - if (!sp->dev_vdata && pdev->id_entry) + if (!sp->dev_vdata && pdev->id_entry) { + sp_platform->is_platform =3D true; sp->dev_vdata =3D sp_get_plat_version(pdev); + } if (!sp->dev_vdata) { ret =3D -ENODEV; dev_err(dev, "missing driver data\n"); @@ -205,7 +208,7 @@ static int sp_platform_probe(struct platform_device *pd= ev) } =20 attr =3D device_get_dma_attr(dev); - if (attr =3D=3D DEV_DMA_NOT_SUPPORTED) { + if (!sp_platform->is_platform && attr =3D=3D DEV_DMA_NOT_SUPPORTED) { dev_err(dev, "DMA is not supported"); goto e_err; } --=20 2.25.1 From nobody Wed Apr 8 12:49:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A0C9C05027 for ; Mon, 23 Jan 2023 15:25:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232617AbjAWPZY (ORCPT ); Mon, 23 Jan 2023 10:25:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232799AbjAWPYx (ORCPT ); Mon, 23 Jan 2023 10:24:53 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 622AC29421; Mon, 23 Jan 2023 07:24:29 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id C4AF320E2D1F; Mon, 23 Jan 2023 07:23:42 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C4AF320E2D1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1674487423; bh=TrLo/S0rk6Ec9OVAJQe83mx0kjEtr7wV5wMozg+JQxQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nmeWfYa2vEbWklGBzPiHYHhjEEEmLaf5LUEnJ+k9NO+TxBuyZm/XzOA4TojJiLNcE RdZIMa1zNeUGkZjjBoNtO5wGBlRxvCAjgMEP0Vxp4nL4hmoEBXMx1XLWo1mOL7iXCY L4n6y/X0HCXNKWXoqkEYustu1F4tn8mOS/tWvFGs= From: Jeremi Piotrowski To: linux-kernel@vger.kernel.org Cc: Jeremi Piotrowski , "Brijesh Singh" , "Tom Lendacky" , "Kalra, Ashish" , linux-crypto@vger.kernel.org Subject: [PATCH v1 8/8] crypto: ccp - Allow platform device to be psp master device Date: Mon, 23 Jan 2023 15:22:50 +0000 Message-Id: <20230123152250.26413-9-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230123152250.26413-1-jpiotrowski@linux.microsoft.com> References: <20230123152250.26413-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move the getters/setters to sp-dev.c, so that they can be accessed from sp-pci.c and sp-platform.c. This makes it possible for the psp platform_device to set the function pointers and be assigned the role of master device by psp_dev_init(). While the case of a system having both a PCI and ACPI PSP is not supported (and not known to occur in the wild), it makes sense to have a single static global to assign to. Should such a system occur, the logic in psp_set_master() is that the pci device is preferred. Signed-off-by: Jeremi Piotrowski --- drivers/crypto/ccp/sp-dev.c | 59 ++++++++++++++++++++++++++++++++ drivers/crypto/ccp/sp-dev.h | 4 +++ drivers/crypto/ccp/sp-pci.c | 48 -------------------------- drivers/crypto/ccp/sp-platform.c | 6 ++++ 4 files changed, 69 insertions(+), 48 deletions(-) diff --git a/drivers/crypto/ccp/sp-dev.c b/drivers/crypto/ccp/sp-dev.c index 52b8d957d0f6..04b77d640f62 100644 --- a/drivers/crypto/ccp/sp-dev.c +++ b/drivers/crypto/ccp/sp-dev.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include #include @@ -39,6 +41,8 @@ static LIST_HEAD(sp_units); /* Ever-increasing value to produce unique unit numbers */ static atomic_t sp_ordinal; =20 +static struct sp_device *sp_dev_master; + static void sp_add_device(struct sp_device *sp) { unsigned long flags; @@ -250,6 +254,61 @@ struct sp_device *sp_get_psp_master_device(void) return ret; } =20 +static bool sp_pci_is_master(struct sp_device *sp) +{ + struct device *dev_cur, *dev_new; + struct pci_dev *pdev_cur, *pdev_new; + + dev_new =3D sp->dev; + dev_cur =3D sp_dev_master->dev; + + pdev_new =3D to_pci_dev(dev_new); + pdev_cur =3D to_pci_dev(dev_cur); + + if (pdev_new->bus->number < pdev_cur->bus->number) + return true; + + if (PCI_SLOT(pdev_new->devfn) < PCI_SLOT(pdev_cur->devfn)) + return true; + + if (PCI_FUNC(pdev_new->devfn) < PCI_FUNC(pdev_cur->devfn)) + return true; + + return false; +} + +void psp_set_master(struct sp_device *sp) +{ + struct device *dev_cur, *dev_new; + + if (!sp_dev_master) { + sp_dev_master =3D sp; + return; + } + + dev_new =3D sp->dev; + dev_cur =3D sp_dev_master->dev; + + if (dev_is_pci(dev_new) && dev_is_pci(dev_cur) && sp_pci_is_master(sp)) + sp_dev_master =3D sp; + if (dev_is_pci(dev_new) && dev_is_platform(dev_cur)) + sp_dev_master =3D sp; +} + +struct sp_device *psp_get_master(void) +{ + return sp_dev_master; +} + +void psp_clear_master(struct sp_device *sp) +{ + if (sp =3D=3D sp_dev_master) { + sp_dev_master =3D NULL; + dev_dbg(sp->dev, "Cleared sp_dev_master\n"); + } +} + + static int __init sp_mod_init(void) { #ifdef CONFIG_X86 diff --git a/drivers/crypto/ccp/sp-dev.h b/drivers/crypto/ccp/sp-dev.h index aaa651364425..083e57652c7b 100644 --- a/drivers/crypto/ccp/sp-dev.h +++ b/drivers/crypto/ccp/sp-dev.h @@ -129,6 +129,10 @@ int sp_request_psp_irq(struct sp_device *sp, irq_handl= er_t handler, void sp_free_psp_irq(struct sp_device *sp, void *data); struct sp_device *sp_get_psp_master_device(void); =20 +void psp_set_master(struct sp_device *sp); +struct sp_device *psp_get_master(void); +void psp_clear_master(struct sp_device *sp); + #ifdef CONFIG_CRYPTO_DEV_SP_CCP =20 int ccp_dev_init(struct sp_device *sp); diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c index 792d6da7f0c0..f9be8aba0acf 100644 --- a/drivers/crypto/ccp/sp-pci.c +++ b/drivers/crypto/ccp/sp-pci.c @@ -30,7 +30,6 @@ struct sp_pci { int msix_count; struct msix_entry msix_entry[MSIX_VECTORS]; }; -static struct sp_device *sp_dev_master; =20 #define attribute_show(name, def) \ static ssize_t name##_show(struct device *d, struct device_attribute *attr= , \ @@ -168,53 +167,6 @@ static void sp_free_irqs(struct sp_device *sp) sp->psp_irq =3D 0; } =20 -static bool sp_pci_is_master(struct sp_device *sp) -{ - struct device *dev_cur, *dev_new; - struct pci_dev *pdev_cur, *pdev_new; - - dev_new =3D sp->dev; - dev_cur =3D sp_dev_master->dev; - - pdev_new =3D to_pci_dev(dev_new); - pdev_cur =3D to_pci_dev(dev_cur); - - if (pdev_new->bus->number < pdev_cur->bus->number) - return true; - - if (PCI_SLOT(pdev_new->devfn) < PCI_SLOT(pdev_cur->devfn)) - return true; - - if (PCI_FUNC(pdev_new->devfn) < PCI_FUNC(pdev_cur->devfn)) - return true; - - return false; -} - -static void psp_set_master(struct sp_device *sp) -{ - if (!sp_dev_master) { - sp_dev_master =3D sp; - return; - } - - if (sp_pci_is_master(sp)) - sp_dev_master =3D sp; -} - -static struct sp_device *psp_get_master(void) -{ - return sp_dev_master; -} - -static void psp_clear_master(struct sp_device *sp) -{ - if (sp =3D=3D sp_dev_master) { - sp_dev_master =3D NULL; - dev_dbg(sp->dev, "Cleared sp_dev_master\n"); - } -} - static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *= id) { struct sp_device *sp; diff --git a/drivers/crypto/ccp/sp-platform.c b/drivers/crypto/ccp/sp-platf= orm.c index b74f16e0e963..d56b34255b97 100644 --- a/drivers/crypto/ccp/sp-platform.c +++ b/drivers/crypto/ccp/sp-platform.c @@ -231,6 +231,12 @@ static int sp_platform_probe(struct platform_device *p= dev) =20 dev_set_drvdata(dev, sp); =20 + if (sp_platform->is_platform) { + sp->set_psp_master_device =3D psp_set_master; + sp->get_psp_master_device =3D psp_get_master; + sp->clear_psp_master_device =3D psp_clear_master; + } + ret =3D sp_init(sp); if (ret) goto e_err; --=20 2.25.1