From patchwork Mon Feb 13 09:24:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 653513 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 05896C636D7 for ; Mon, 13 Feb 2023 09:25:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229477AbjBMJZH (ORCPT ); Mon, 13 Feb 2023 04:25:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229980AbjBMJYz (ORCPT ); Mon, 13 Feb 2023 04:24:55 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 30C8614EBD; Mon, 13 Feb 2023 01:24:54 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id 55D5A20C8B72; Mon, 13 Feb 2023 01:24:52 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 55D5A20C8B72 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1676280293; bh=Li2UJyY0mGyrGpuxPLsk95rzcd9mDiZ9P/GYVetjqcw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MGKw1AOx5lnYWSVA69TTcybXKigN4Rnmbvhut0bR67pQqd4pyo67z+dGftc126bVT ZzE2bzgbsAgsxvtCTY3Qp/1Q52qwUTu4J2x8+GJzyvpA+CYFd5qm2cqzWf/evyutf3 O4kh0MtCCWVRtT25uSVzl8GsMWkPmP0n2+Krrj8c= 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 v2 1/8] include/acpi: add definition of ASPT table Date: Mon, 13 Feb 2023 09:24:22 +0000 Message-Id: <20230213092429.1167812-2-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230213092429.1167812-1-jpiotrowski@linux.microsoft.com> References: <20230213092429.1167812-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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 */ }; +/* 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 = 0, + ACPI_ASPT_TYPE_SEV_MBOX_REGS = 1, + ACPI_ASPT_TYPE_ACPI_MBOX_REGS = 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!") From patchwork Mon Feb 13 09:24:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 653512 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 8DF7CC636D4 for ; Mon, 13 Feb 2023 09:26:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230005AbjBMJ0o (ORCPT ); Mon, 13 Feb 2023 04:26:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230098AbjBMJY5 (ORCPT ); Mon, 13 Feb 2023 04:24:57 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 016887A87; Mon, 13 Feb 2023 01:24:55 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id 2349120C8B73; Mon, 13 Feb 2023 01:24:53 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2349120C8B73 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1676280295; bh=9zBj7lGZiNLssSN0Bow0NnJuBiAOG3TjbvKNnsD+cgs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U4oNPXXZ6M0cTM+NIlIoEC9XUveqKDoAD1don5hXHprDigZpvyyWWt8ppS4K8mCGp BcWfvCFcPTd5lcSbfP5J7mtnGqahXYzQ/iRqaAwP8zg5ii+Seu6RH/DspqdDwDR1RJ 6aktLLzZ3Z0fLSFd4jbeQ5jvc8jpVoNwB6o+kz+Q= 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 v2 2/8] ACPI: ASPT: Add helper to parse table Date: Mon, 13 Feb 2023 09:24:23 +0000 Message-Id: <20230213092429.1167812-3-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230213092429.1167812-1-jpiotrowski@linux.microsoft.com> References: <20230213092429.1167812-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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 += evged.o acpi-y += sysfs.o acpi-y += property.o acpi-$(CONFIG_X86) += acpi_cmos_rtc.o +acpi-$(CONFIG_X86) += aspt.o acpi-$(CONFIG_X86) += x86/apple.o acpi-$(CONFIG_X86) += x86/utils.o acpi-$(CONFIG_X86) += 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 *gregs, + const struct acpi_aspt_sev_mbox_regs *sevregs, + const struct acpi_aspt_acpi_mbox_regs *acpiregs) +{ + u64 pfn; + int idx; + u64 regs[] = { + 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 = regs[0] >> PAGE_SHIFT; + for (idx = 1; idx < ARRAY_SIZE(regs); idx++) { + if (regs[idx] >> PAGE_SHIFT != 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 window + * @pdata: will be filled with the register offsets parsed from the ASPT table + */ +int __init acpi_parse_aspt(struct resource *res, struct psp_platform_data *pdata) +{ + struct acpi_aspt_acpi_mbox_regs acpiregs = {}; + struct acpi_aspt_sev_mbox_regs sevregs = {}; + struct acpi_aspt_global_regs gregs = {}; + struct acpi_aspt_header *entry, *end; + struct acpi_table_aspt *aspt; + unsigned long base; + acpi_status status; + int err = 0; + + status = acpi_get_table(ACPI_SIG_ASPT, 0, (struct acpi_table_header **)&aspt); + if (ACPI_FAILURE(status)) + return -ENODEV; + if (aspt->header.revision != ASPT_REVISION_ID) { + pr_err("unsupported table revision: %d\n", (int)aspt->header.revision); + err = -ENODEV; + goto exit; + } + entry = (struct acpi_aspt_header *)(aspt + 1); + end = (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 = -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 = (struct acpi_aspt_header *)((void *)entry + entry->length); + } + if (!gregs.header.length || !sevregs.header.length || !acpiregs.header.length) { + pr_err("missing ASPT table entry: %u %u %u\n", gregs.header.length, + sevregs.header.length, + acpiregs.header.length); + err = -EINVAL; + goto exit; + } + /* All registers are expected to be within the same page */ + err = psp_validate_regs(&gregs, &sevregs, &acpiregs); + if (err) { + pr_err("ASPT registers span multiple pages\n"); + goto exit; + } + + base = ALIGN_DOWN(gregs.feature_reg_addr, PAGE_SIZE); + *res = (struct resource)DEFINE_RES_MEM(base, PAGE_SIZE); + + pdata->sev_cmd_resp_reg = sevregs.cmd_resp_reg_addr & ~PAGE_MASK; + pdata->sev_cmd_buf_lo_reg = sevregs.cmd_buf_lo_reg_addr & ~PAGE_MASK; + pdata->sev_cmd_buf_hi_reg = sevregs.cmd_buf_hi_reg_addr & ~PAGE_MASK; + pdata->feature_reg = gregs.feature_reg_addr & ~PAGE_MASK; + pdata->irq_en_reg = gregs.irq_en_reg_addr & ~PAGE_MASK; + pdata->irq_st_reg = gregs.irq_st_reg_addr & ~PAGE_MASK; + pdata->mbox_irq_id = sevregs.mbox_irq_id; + pdata->acpi_cmd_resp_reg = 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_data/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_data *pdata) +{ + return -ENODEV; +} +#endif + +#endif /* __LINUX_PSP_H */