From patchwork Mon Mar 20 19:19:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 72423 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1398702wrt; Mon, 20 Mar 2023 12:34:48 -0700 (PDT) X-Google-Smtp-Source: AK7set868t9XGGzqAc0ZGY+nirOOcxTpw5bG2MQbTCjSrVK5HiE1/07lcWPjOOvxdqnuiGWcKQqb X-Received: by 2002:a05:6a20:e688:b0:c6:c85f:da5b with SMTP id mz8-20020a056a20e68800b000c6c85fda5bmr17616717pzb.55.1679340888391; Mon, 20 Mar 2023 12:34:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679340888; cv=none; d=google.com; s=arc-20160816; b=Ag08jRrhaYWKYs0pyAl80Fa/tl6oYTf7EcKj70Hzl5uNVDHR858fIXPfN0T8nnhg1/ z1j/qSNQIpJfVJwZs3Zu4zbmuaug8oDhH30reJqb4pevVKQHVvKmsZy/HL3bI0FPWE7k ChyDxUpyw2Jb4VZkYXF+pL4SmpHHX9rlvYCLcehjl8+wJEPScUxWXGqeDjDQfp+5uLxU GpLIVW7CuQV+MuqdrWJmr4lNZXCOV1+RH1p6V6SFosNoVmxWI1IvIkLOb5FvNNbjfZ3q PWd2jQW3QO6fHBRySdY3YWlqKpCg7JGzvTF5DupgqmHzve/GBZjUAGnbSd7CkXAr3WSK IpoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=PDHjd28pCHQeWoo/8MKDfBqPLwlQl6LSVCeyeDUCNL4=; b=LIqK8msrtcO9T2+4anNOkOrfGPJ8NWGVyUtlmB/q3ILTLr5dogo0sCA00eSrBwEtBI s+hc2BhOqbCwV475CD3OUZxdmEO1tUmZXX6/UKi99LTuAuchDYO55wD+FZvocxVkE8a3 KMSO2ee5OFZuN98JaDqgshph4KAaMnEcSAa3NhmBkV0Oppdgh39U8Plkpgj2s6HTS8e7 kLEqkMUDsWce60MegEJFXIriQVDREv5WXmQLwPRcdxnQm6myaNzz/abYcF5CSA6gnA6q 5v/BVOXe5GEZcEwyHngdctyRnjP3riDO4CY6V69xUQLqfHdQu6jrSmvGiNoPIlbV/esr eESQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=ks183xzt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 14-20020a056a00072e00b00624e7c7bb07si10354595pfm.265.2023.03.20.12.34.34; Mon, 20 Mar 2023 12:34:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=ks183xzt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229917AbjCTT2o (ORCPT + 99 others); Mon, 20 Mar 2023 15:28:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbjCTT2M (ORCPT ); Mon, 20 Mar 2023 15:28:12 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E811A4D615; Mon, 20 Mar 2023 12:20:36 -0700 (PDT) Received: from vm02.corp.microsoft.com (unknown [167.220.197.27]) by linux.microsoft.com (Postfix) with ESMTPSA id 4222E20FAEF9; Mon, 20 Mar 2023 12:20:21 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4222E20FAEF9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679340022; bh=PDHjd28pCHQeWoo/8MKDfBqPLwlQl6LSVCeyeDUCNL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ks183xztHwu+yKYWRpkmAtOT3nQMgL8zrC0wEtBJBioj52nPRS1jIC7bhmul7mGJL 9nAmKzzkIcFgQBIQk6wtdI7MW1aFPVwSBxkFgnaOOw+pbYAWDeqf9o9YsRQRXyX9sH K2zjqGqmsgkQ8nL1SQMlRochNdblkKXWRMYFAaak= 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 v3 1/8] include/acpi: add definition of ASPT table Date: Mon, 20 Mar 2023 19:19:49 +0000 Message-Id: <20230320191956.1354602-2-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> References: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760916551503571912?= X-GMAIL-MSGID: =?utf-8?q?1760916551503571912?= 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. Link: https://github.com/acpica/acpica/commit/15b939b034ab41a864b4e7647b8e2233780bb0c7 Link: https://www.amd.com/system/files/TechDocs/58028_1.00-PUB.pdf Acked-by: Tom Lendacky 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 4175dce3967c..0fa428d335b2 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 */ @@ -107,6 +108,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 Mar 20 19:19:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 72430 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1409430wrt; Mon, 20 Mar 2023 13:00:24 -0700 (PDT) X-Google-Smtp-Source: AK7set9SNA2ZvAHE9dVh0r1eFFyO9+LVwZ9FN6l8PLgHwf0T44Go3IkQW9lvKzWzq7gy+FKvjrZv X-Received: by 2002:a62:cf83:0:b0:627:ea2c:ad9c with SMTP id b125-20020a62cf83000000b00627ea2cad9cmr81745pfg.9.1679342423829; Mon, 20 Mar 2023 13:00:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679342423; cv=none; d=google.com; s=arc-20160816; b=RfcmaqvWkZs2/sYAka8kh9udAbyj8GwcRxi0GAtjIzqUQEVcfXlBuigMPJZG7rA64d SWY7bZ2zLYhtogwsskl0IF/ua6PiYv3ba2otsZFqfaxrH78mO+JlbNBtQgMXtJ4XEyic mPy/4SvJxLWZEMF7eslupahknAOupqXEiRJu2G+0ooUqC4fGHouUjx7CrjXjt26eHjqG E5jtLtItD4FRMXwo49nxtC/IJeSlJd4Hwnu9Y90iPQGaUnDHSPLxxPVoOgJfVUu2zFt2 dm/XxMWznNu/yBARTyYT70HmO5iDjezWTPgyaoBJE6b8korf7XV23O6SNebuOsHmiLBS 2sOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=5BR0f6PrkO2ZuCv3kzx8IsqaHLeKQ2EwX1QEDZefxrY=; b=UVxdC9VNvzFqmuunjsTmBOy85rNiKOhxfr0fixxbOVm+HQ8p9s+DHDs777+4o4mK+N 9SgV6dBOxqYmvX0u5+0+WB6CMhdGQOfIldWTUHz/S8EWbSYYGHCV/If/ymY09wv72y/j WnTEqAdwoS7P/7oYUMIZFE/JtM4YIOMfRuuUIoKGK2/DlC3Zo0VP5A3XY20J/kuS4xeD +o3p8X73iKJ0W2w5PEJeq5NHzrKsrBDK/I4J8g30PSj8cvVZ3cNvdiGvRUXmgy6/5Auy rv17IpfQvvCg2HdrO1bcoFCEq8LrDcYeqcgmzyRygSx+25+XOGTmMVac5fwAQzcblRFV 4+8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=UVBn9ynW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n186-20020a6327c3000000b004fbf520c66csi11231056pgn.254.2023.03.20.13.00.08; Mon, 20 Mar 2023 13:00:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=UVBn9ynW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230105AbjCTT2s (ORCPT + 99 others); Mon, 20 Mar 2023 15:28:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229939AbjCTT2P (ORCPT ); Mon, 20 Mar 2023 15:28:15 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4C2A44DBCA; Mon, 20 Mar 2023 12:20:39 -0700 (PDT) Received: from vm02.corp.microsoft.com (unknown [167.220.197.27]) by linux.microsoft.com (Postfix) with ESMTPSA id 13D3A20FAEFE; Mon, 20 Mar 2023 12:20:22 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 13D3A20FAEFE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679340024; bh=5BR0f6PrkO2ZuCv3kzx8IsqaHLeKQ2EwX1QEDZefxrY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UVBn9ynWsu5EEl41Ch9x59ghkmiYuQwTFGsIQTdRxgfKS6ybWbXZ10Wc4UTEgIdAw hqp1jpwGZ52hjOzpcsH9vswOMXbvqKyNemXqPOh2NpFLZsotXf5xF/46fmL6gPklwt bIqP+aDsurNEzApM1gjIab7W7hOz0OdU/xA9CM1E= 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 v3 2/8] ACPI: ASPT: Add helper to parse table Date: Mon, 20 Mar 2023 19:19:50 +0000 Message-Id: <20230320191956.1354602-3-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> References: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760918161274738540?= X-GMAIL-MSGID: =?utf-8?q?1760918161274738540?= 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. Link: https://github.com/acpica/acpica/commit/15b939b034ab41a864b4e7647b8e2233780bb0c7 Link: https://www.amd.com/system/files/TechDocs/58028_1.00-PUB.pdf Acked-by: Tom Lendacky 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 feb36c0b9446..831d7a12b522 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 */ From patchwork Mon Mar 20 19:19:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 72426 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1404168wrt; Mon, 20 Mar 2023 12:47:07 -0700 (PDT) X-Google-Smtp-Source: AK7set/o6RVGSV5W0P2Brt/VNAXwjp+AiZInVp5Vd0OJjh8h4KEvHZ/DDBC8F4unS3QHPaMCSS+C X-Received: by 2002:a17:903:11c5:b0:19c:ea4d:5995 with SMTP id q5-20020a17090311c500b0019cea4d5995mr22470575plh.68.1679341627152; Mon, 20 Mar 2023 12:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679341627; cv=none; d=google.com; s=arc-20160816; b=kTYnUhtlDTJu0WHtwLNTWuoYqyFXj3FjFk23Vpv+Y9Ux+ezGFuB/Q4+4/CzxHRRH+1 OI+Oowthf1tZtV1GiuJIJisQlPS2KrAChWp9j2y2OQjCwhZ4SkJQwXcmmBW+jDmY64Sf isual/2tJYOBkbzwceAqm7NR5ObssWFHwyrh+PF//TPOaWjW54F7YtH5HV/AS0D3zCEm zHiXBSJJ+KSAAlXgm4QpY23wmnvlyO8YIChvsXfg73YnUFHBiSISpmX8LHjmCdA/9dpV DMF/aEI8ZD+nt866aeylIKlKLcGNalkI1ds3OiZ7gs/CoQL9ysGwtB3FmMzP0V2QDyrn sUbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=T/Kzn8Yd7+WmZZ2G5JhyiJuSkC/HTVlKDk1fI7xOGw8=; b=tOrUsrhkHxuXehz9CKNarKzY+xPpU2PDGwUKPe4+ClLpGECw5tBTYEN2pEws3QAQPT xkl5IeDuHikfXTxfcbeJSik5kUTElSY0SE1xPJCv+1nvXHhBBlMkNHOl3lSR81YnQoN+ D/Xdv63kmWDjsFC3SX9pJA26eArMdbWgnGPr+ssEYgXYmChkC0jKxNzCnDsLimlGPZxI qrYNsaqHzv3tBpYxHWSWUVLVBItoure/nO1hbSOZOYqucFCw2Cxy9gFgDhRq8eHaMiQT 9ItJTPxf7pa4nX38knCemyFk2NjlixWBfjVWLl9JYCWtI+9L3pRBRT9fQNnFavFWKS/g YP4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=fHWiqLsr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bg11-20020a1709028e8b00b0019ad44844b3si10640109plb.118.2023.03.20.12.46.51; Mon, 20 Mar 2023 12:47:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=fHWiqLsr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231239AbjCTT3V (ORCPT + 99 others); Mon, 20 Mar 2023 15:29:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbjCTT2o (ORCPT ); Mon, 20 Mar 2023 15:28:44 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 38FCE4EE6 for ; Mon, 20 Mar 2023 12:21:11 -0700 (PDT) Received: from vm02.corp.microsoft.com (unknown [167.220.197.27]) by linux.microsoft.com (Postfix) with ESMTPSA id D8F7920FB19F; Mon, 20 Mar 2023 12:20:24 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D8F7920FB19F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679340026; bh=T/Kzn8Yd7+WmZZ2G5JhyiJuSkC/HTVlKDk1fI7xOGw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fHWiqLsrsK5liuESoXYcTTsH+AG4ywvK6DdfILXohxXaQ8w8PYxf8XsCWZC+quRxc 0LyPjJ7373jeo+PuF+N7d4tJbKXYpVTromx/Fae/X5OBaAPUd+rKgLEcl0Tui6E5jD +/1yfZ8hRogHXmYTmkRpu/XVtLL1+7fiNV8tRkro= 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 v3 3/8] x86/psp: Register PSP platform device when ASP table is present Date: Mon, 20 Mar 2023 19:19:51 +0000 Message-Id: <20230320191956.1354602-4-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> References: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760916763701839647?= X-GMAIL-MSGID: =?utf-8?q?1760917325945093466?= 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. Acked-by: Tom Lendacky Signed-off-by: Jeremi Piotrowski --- arch/x86/kernel/Makefile | 1 + arch/x86/kernel/psp.c | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 arch/x86/kernel/psp.c diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 96d51bbc2bd4..6fe52328bc28 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -139,6 +139,7 @@ obj-$(CONFIG_UNWINDER_ORC) += unwind_orc.o obj-$(CONFIG_UNWINDER_FRAME_POINTER) += unwind_frame.o obj-$(CONFIG_UNWINDER_GUESS) += unwind_guess.o +obj-$(CONFIG_KVM_AMD_SEV) += psp.o obj-$(CONFIG_AMD_MEM_ENCRYPT) += sev.o obj-$(CONFIG_CFI_CLANG) += cfi.o diff --git a/arch/x86/kernel/psp.c b/arch/x86/kernel/psp.c new file mode 100644 index 000000000000..64f3bfc5c9ff --- /dev/null +++ b/arch/x86/kernel/psp.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include + +static struct platform_device psp_device = { + .name = "psp", + .id = PLATFORM_DEVID_NONE, +}; + +static int __init psp_init_platform_device(void) +{ + struct psp_platform_data pdata = {}; + 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 = acpi_parse_aspt(res, &pdata); + if (err) + return err; + err = platform_device_add_resources(&psp_device, res, 1); + if (err) + return err; + err = platform_device_add_data(&psp_device, &pdata, sizeof(pdata)); + if (err) + return err; + + err = platform_device_register(&psp_device); + if (err) + return err; + return 0; +} +device_initcall(psp_init_platform_device); From patchwork Mon Mar 20 19:19:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 72425 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1404122wrt; Mon, 20 Mar 2023 12:46:59 -0700 (PDT) X-Google-Smtp-Source: AK7set/C9HIRviHjVSyN02bt0PvnFYPpkSGuq30BoEh83atL979D1jplxIpWuliA4+jhd8Vz8CWS X-Received: by 2002:a17:903:283:b0:1a0:4341:4cd9 with SMTP id j3-20020a170903028300b001a043414cd9mr23078518plr.31.1679341619245; Mon, 20 Mar 2023 12:46:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679341619; cv=none; d=google.com; s=arc-20160816; b=LMrdrx1uEwBMa3F0z80PjKzjtXn9s/qpfSVlBUWHM9RLJsXclh6QjwYPBs8kyyOU7U +SBPoiqZq+y4IGYpAKV9jdKJsmm5OuboG8IuG3WlbxvkQbOKwQq4E/zFDYR1kY/FyD78 9t/eQrkCkDm1BKkPd6jd2v1OvwyMlrt9L5IR/0Ef1yBNgiwi8jTAApCbZHbB9G79ONjU PX04ke/Qv5b3oMOPVmn8S7sQ2Hh+Y5ysPcekzKoDNTHH+hYmm8w/BMVckhVkLEV4vrAc Hni1QideLOZwU30zMPZQjOQFwXIeFblwo1w2tS6lFIhZ10sU1u7ftji8UwHAiDvzeRhJ wKgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=XPpcWj9XwPGuObfeTqrxZHmfuFJ0keGteN1DGS91Sf0=; b=pE0CsKOUclA5NXj8TnvdyyYeWr2AApy7UEleONivW8ScUim2lgld9yMODfs5kFCdbC BnqK3GZdkm27KTkDI30URNMPQEi3OQwYMTCy2+uf05Q00RuBkZdjuH0A2nf9X14rCiqM V2TIipJUXbi300+iywFiqNw0YZsj7+WDdlQ7IMe719BFrqcF+styusVO6Ewwv+/UOEO+ duAk/CyZkf76kjN9NPYoqUzU6mZlFQO7yIPIEzMi4sWX5SzQoaDCXFLtn0NmTcKp4o2f I9GTHj0o/UJswU/Vo1gATrA7YZnUsS4pD/0pn7twGox9GdVfnT9O7/2Cph+Q8QjlAxpn or7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=bABrdq8y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c13-20020a170902d48d00b0019cf4957404si12444899plg.24.2023.03.20.12.46.43; Mon, 20 Mar 2023 12:46:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=bABrdq8y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229833AbjCTT3F (ORCPT + 99 others); Mon, 20 Mar 2023 15:29:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbjCTT2X (ORCPT ); Mon, 20 Mar 2023 15:28:23 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B0FCB4D639 for ; Mon, 20 Mar 2023 12:20:52 -0700 (PDT) Received: from vm02.corp.microsoft.com (unknown [167.220.197.27]) by linux.microsoft.com (Postfix) with ESMTPSA id F1C8A20FB1AB; Mon, 20 Mar 2023 12:20:26 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com F1C8A20FB1AB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679340028; bh=XPpcWj9XwPGuObfeTqrxZHmfuFJ0keGteN1DGS91Sf0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bABrdq8yChhaL+TAl8T/zmeoHEpKXhc5iK2fots8wPlIDyZL2ahgwfCxdYvQGG1Ia BPUODW5DEF2aEBVL9SwuvqhnJKplIdH5ziG+0dOtAQqNjSDj5DJ5KD6TWJ3SlqRreB qRQ8P8hUXInN0/QVyL63rYhBPPUeXLEKQEnlbTRk= 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 v3 4/8] x86/psp: Add IRQ support Date: Mon, 20 Mar 2023 19:19:52 +0000 Message-Id: <20230320191956.1354602-5-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> References: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760917318159276134?= X-GMAIL-MSGID: =?utf-8?q?1760917318159276134?= 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. Acked-by: Tom Lendacky Signed-off-by: Jeremi Piotrowski --- arch/x86/kernel/psp.c | 185 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 181 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/psp.c b/arch/x86/kernel/psp.c index 64f3bfc5c9ff..fc059cf3b25c 100644 --- a/arch/x86/kernel/psp.c +++ b/arch/x86/kernel/psp.c @@ -1,8 +1,182 @@ // SPDX-License-Identifier: GPL-2.0-only - +#define pr_fmt(fmt) "psp: " fmt #include #include +#include +#include #include +#include + +#define PSP_ACPI_CMDID_SHIFT 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_MASK GENMASK(7, 0) +#define PSP_ACPI_MBOX_IRQID_SHIFT 10 +#define PSP_ACPI_IRQ_EN_BIT BIT(0) +#define PSP_ACPI_IRQ_EN_MBOX_IRQID_SHIFT 10 + +#define PSP_CMD_DELAY_US 2 +#define PSP_CMD_TIMEOUT_US 10000 + +enum ASP_CMDID { + ASP_CMDID_PART1 = 0x82, + ASP_CMDID_PART2 = 0x83, + ASP_CMDID_PART3 = 0x84, + ASP_CMDID_IRQ_EN = 0x85, +}; + +enum ASP_CMD_STATUS { + ASP_CMD_STATUS_SUCCESS = 0x0, + ASP_CMD_STATUS_INVALID_CMD = 0x1, + ASP_CMD_STATUS_INVALID_PARAM = 0x2, + ASP_CMD_STATUS_INVALID_FW_STATE = 0x3, + ASP_CMD_STATUS_FAILURE = 0x1F, +}; + +struct psp_irq_data { + void __iomem *base; + u8 mbox_irq_id; + int acpi_cmd_resp_reg; +}; + +static int psp_sync_cmd(void __iomem *reg, u8 cmd, u16 data) +{ + u32 val; + int err; + + val = data; + val |= cmd << PSP_ACPI_CMDID_SHIFT; + writel(val, reg); + err = readl_poll_timeout_atomic(reg, val, val & PSP_ACPI_RESPONSE_BIT, PSP_CMD_DELAY_US, + PSP_CMD_TIMEOUT_US); + if (err) + 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 = data->base + data->acpi_cmd_resp_reg; + u16 val = 0; + int err; + + if (data->mbox_irq_id > 63) + return -EINVAL; + + val = irq_en ? PSP_ACPI_IRQ_EN_BIT : 0; + val |= data->mbox_irq_id << PSP_ACPI_IRQ_EN_MBOX_IRQID_SHIFT; + err = psp_sync_cmd(reg, ASP_CMDID_IRQ_EN, val); + if (err != 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, unsigned int vector, unsigned int cpu) +{ + void __iomem *reg = data->base + data->acpi_cmd_resp_reg; + unsigned int dest_cpu = cpu_physical_id(cpu); + u16 part1, part2, part3; + int err; + + if (data->mbox_irq_id > 63) + return -EINVAL; + + part1 = dest_cpu; + part2 = dest_cpu >> 16; + part3 = vector & PSP_ACPI_VECTOR_MASK; + part3 |= data->mbox_irq_id << PSP_ACPI_MBOX_IRQID_SHIFT; + + err = psp_sync_cmd(reg, ASP_CMDID_PART1, part1); + if (err != ASP_CMD_STATUS_SUCCESS) { + pr_err("ASP_CMDID_PART1 failed: %d\n", err); + return -EIO; + } + err = psp_sync_cmd(reg, ASP_CMDID_PART2, part2); + if (err != ASP_CMD_STATUS_SUCCESS) { + pr_err("ASP_CMDID_PART2 failed: %d\n", err); + return -EIO; + } + err = psp_sync_cmd(reg, ASP_CMDID_PART3, part3); + if (err != 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; + struct irq_cfg *cfg; + void __iomem *base; + int virq; + int err; + + base = ioremap(reg->start, resource_size(reg)); + if (!base) + return -ENOMEM; + + pspirqd.mbox_irq_id = pdata->mbox_irq_id; + pspirqd.acpi_cmd_resp_reg = pdata->acpi_cmd_resp_reg; + pspirqd.base = base; + init_irq_alloc_info(&info, cpumask_of(0)); + virq = irq_domain_alloc_irqs(NULL, 1, NUMA_NO_NODE, &info); + if (virq <= 0) { + pr_err("failed to allocate vector: %d\n", virq); + err = -ENOMEM; + goto unmap; + } + irq_set_handler(virq, handle_edge_irq); + + data = irq_get_irq_data(virq); + if (!data) { + pr_err("no irq data\n"); + err = -ENODEV; + goto freeirq; + } + + cfg = irqd_cfg(data); + if (!cfg) { + pr_err("no irq cfg\n"); + err = -ENODEV; + goto freeirq; + } + + err = psp_configure_irq(&pspirqd, cfg->vector, 0); + if (err) { + pr_err("failed to configure irq: %d\n", err); + goto freeirq; + } + + err = psp_set_irq_enable(&pspirqd, true); + if (err) { + pr_err("failed to enable irq: %d\n", err); + goto freeirq; + } + + *irq = (struct resource)DEFINE_RES_IRQ(virq); + + iounmap(base); + + return 0; + +freeirq: + irq_domain_free_irqs(virq, 1); + +unmap: + iounmap(base); + + return err; +} static struct platform_device psp_device = { .name = "psp", @@ -12,7 +186,7 @@ static struct platform_device psp_device = { static int __init psp_init_platform_device(void) { struct psp_platform_data pdata = {}; - struct resource res[1]; + struct resource res[2]; int err; /* @@ -24,10 +198,13 @@ static int __init psp_init_platform_device(void) if (!hypervisor_is_type(X86_HYPER_MS_HYPERV)) return -ENODEV; - err = acpi_parse_aspt(res, &pdata); + err = acpi_parse_aspt(&res[0], &pdata); + if (err) + return err; + err = psp_init_irq(&pdata, &res[0], &res[1]); if (err) return err; - err = platform_device_add_resources(&psp_device, res, 1); + err = platform_device_add_resources(&psp_device, res, 2); if (err) return err; err = platform_device_add_data(&psp_device, &pdata, sizeof(pdata)); From patchwork Mon Mar 20 19:19:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 72429 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1406451wrt; Mon, 20 Mar 2023 12:53:05 -0700 (PDT) X-Google-Smtp-Source: AK7set84FCJH2LmHrQ3wYZTICHWKZASXvEZEwZkH4Vbl6XNPmIkdkau21Szyn2+ol6eXgOOU+jZc X-Received: by 2002:a17:903:234a:b0:19e:6e29:2a8c with SMTP id c10-20020a170903234a00b0019e6e292a8cmr22358556plh.5.1679341984925; Mon, 20 Mar 2023 12:53:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679341984; cv=none; d=google.com; s=arc-20160816; b=EZdSapAZK87KIZjOlD1WssPXz1uQPR8hK3ulzG+73pw8BH6yIfU7Wm0S3FO+MDqDB6 6sfVlvOTfLSYmxXvNsFjZ30H2awCgcvSPYIraMnQTL/smxbIaGg6l1xpPWhUvWS/qyPy +KPTF9SFA3OJVOWsFd3LL7aXkQmXL5aastcgDCOd68A0R0PyYsmeFefQQ3bxnl1TRjgx 8+Bb9x+r+aMtF32dtlg+7NU0t/USthmWIU5KlTLkLOqdCuJ6sSX5ptpyt3CvnuMugxop TfIIJTYjI3QBig75s1Sci5cZ0rosAx+wdfECiGCNEthQEFaJONPUNugxtvM+pFGpcwgL nhxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=JLW993L7KNZ43aI6v0ynXV6I6nnprRROSEVuJCp8QVo=; b=E5LWE//LGtEF3WBQiQzbOMr1hjD+unQ239vcIX156Fw5D+bJruyzQsYIYbxY8TJSMA ookJ71S0KchIkN6h1o0aspJbatP3V49k1saWIqqV+H2hZWyM3PzwFhP2iP1ILxYyZmwz kQhtg/x3fA33jTIbl9ZUbxLkdac1ruooZ7PsR2B7gXOUUr1cEthFDFA48IDSl+PwuCUW /bLxHCc+uSLpQDDLphEhPxwPmcgym7R5DDttOdtxtC/ERf+rCrrfO79ybN+QAgzwXw7X +ehjYSlyTRPdbIsYI3j2U5XQIIK+mQXFCsnd7nj1W6WehZ207PCfnZ+ZtV2Ba2cX5GAv Gxrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=jZdE92xk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 2-20020a170902e9c200b0019f186f11c8si10110722plk.453.2023.03.20.12.52.48; Mon, 20 Mar 2023 12:53:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=jZdE92xk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231149AbjCTTgO (ORCPT + 99 others); Mon, 20 Mar 2023 15:36:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229992AbjCTTfd (ORCPT ); Mon, 20 Mar 2023 15:35:33 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 03C40144A0; Mon, 20 Mar 2023 12:30:20 -0700 (PDT) Received: from vm02.corp.microsoft.com (unknown [167.220.197.27]) by linux.microsoft.com (Postfix) with ESMTPSA id 15EF420FB1B2; Mon, 20 Mar 2023 12:20:28 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 15EF420FB1B2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679340030; bh=JLW993L7KNZ43aI6v0ynXV6I6nnprRROSEVuJCp8QVo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jZdE92xkSlNsSdtRY8SG1L72AfSgg+/UasdFbiQcPghgRMaTIcGcQI7O/GdJjG+2g aWqacbBFkt1YwcRsXRt//5OyRFmExbllwk6D5Dauo/wgqJENztvMcvlC21wtD1AULa 6T9tnRofIADsnQym6v0uN3sS6lgk2IRXtyo1dh+M= From: Jeremi Piotrowski To: linux-kernel@vger.kernel.org Cc: Jeremi Piotrowski , "Tom Lendacky" , "Kalra, Ashish" , linux-crypto@vger.kernel.org Subject: [PATCH v3 5/8] crypto: cpp - Bind to psp platform device on x86 Date: Mon, 20 Mar 2023 19:19:53 +0000 Message-Id: <20230320191956.1354602-6-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> References: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760917701305062862?= X-GMAIL-MSGID: =?utf-8?q?1760917701305062862?= 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. Acked-by: Tom Lendacky Signed-off-by: Jeremi Piotrowski --- drivers/crypto/ccp/sp-dev.c | 7 +++++++ drivers/crypto/ccp/sp-platform.c | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/drivers/crypto/ccp/sp-dev.c b/drivers/crypto/ccp/sp-dev.c index 7eb3e4668286..4c9f442b8a11 100644 --- a/drivers/crypto/ccp/sp-dev.c +++ b/drivers/crypto/ccp/sp-dev.c @@ -259,6 +259,12 @@ static int __init sp_mod_init(void) if (ret) return ret; + ret = sp_platform_init(); + if (ret) { + sp_pci_exit(); + return ret; + } + #ifdef CONFIG_CRYPTO_DEV_SP_PSP psp_pci_init(); #endif @@ -286,6 +292,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 diff --git a/drivers/crypto/ccp/sp-platform.c b/drivers/crypto/ccp/sp-platform.c index 7d79a8744f9a..5dcc834deb72 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[] = { MODULE_DEVICE_TABLE(of, sp_of_match); #endif +static const struct platform_device_id sp_platform_match[] = { + { "psp" }, + { }, +}; +MODULE_DEVICE_TABLE(platform, sp_platform_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 *pdev) #endif static struct platform_driver sp_platform_driver = { + .id_table = sp_platform_match, .driver = { .name = "ccp", #ifdef CONFIG_ACPI From patchwork Mon Mar 20 19:19:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 72431 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1410734wrt; Mon, 20 Mar 2023 13:02:39 -0700 (PDT) X-Google-Smtp-Source: AK7set+AYrtQ45lGr6QofAIBA4403V+67pIfnaGRHCJIltHVBu+DnjOLOY9RoM3cj/Fk9AMtzI7A X-Received: by 2002:a17:903:5c7:b0:1a1:cc8b:7b0b with SMTP id kf7-20020a17090305c700b001a1cc8b7b0bmr4600826plb.66.1679342559030; Mon, 20 Mar 2023 13:02:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679342559; cv=none; d=google.com; s=arc-20160816; b=EuooeYf2ALNsKEUc/9SUDkvDo/oq0sHIVomTDKKZXzSMaPCcdYbAw9xCmFB6SmE5VJ oGiWPjOyNyvekeehwzBOzW3xI/8pNkufe/D2KqfJDKqZ/wB2rKH+oDflbkl2yA6KxiqV Z3cJchIvXHFwuD1BOfBZJo+7gwjdNcqAd3fVvqALmKt2u+hxOLWtl66YxdmR7xbzy4Rv xx7+90LpoogGzga+cn1nHxY79bQFtBw056QirrlCrKM5AsUyZhLNpospIVdttH4tANF4 IpR2gEbb599Hv5mIiShw7cdUfmvwEt5CH8PfamgwxrV0GX17lG5x+xLsgBRoxaHmY7zm nNFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=yubtDMU1v+j6puBmAVgHQ5Fbx/QE7P8/F/J6/XMCF5I=; b=ruEE4yKD0i9lu61F8AfUrpv7pM3AUtzJPJMpKIJMmPMLmqSQesYenA55QnrQT7bsTK gGEMmoQNnPbJX+7f2Yprr9J82H8DJPQe90c0uhiF3v8nuuNNd3RHCHkMwcBIP9YurW/A uRe2QKQcZQoXsNMX7a1Er5DdrzuGgQEUFA5j/EsxW2CNNvW2Pz++XVlLMB69n38Otsyl 1mc16o17UOJ0rUQ5ceHDKL1AWwz09padObQ2iIhIO6bL7gvuqC9UakRCuNjJ7Q18nT5i 5fYYN9wINTzLLxmFCTOCnmz2eANSh6muy3DekLZpkO3XuUquaQDDHX57GOadPKF89WbK udFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="qRsn/jD8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k17-20020a170902c41100b0019a96125cd7si13562802plk.332.2023.03.20.13.02.21; Mon, 20 Mar 2023 13:02:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="qRsn/jD8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231128AbjCTTgJ (ORCPT + 99 others); Mon, 20 Mar 2023 15:36:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229949AbjCTTfd (ORCPT ); Mon, 20 Mar 2023 15:35:33 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 01D2E136CA; Mon, 20 Mar 2023 12:30:20 -0700 (PDT) Received: from vm02.corp.microsoft.com (unknown [167.220.197.27]) by linux.microsoft.com (Postfix) with ESMTPSA id 6FB7E20FB1BC; Mon, 20 Mar 2023 12:20:30 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6FB7E20FB1BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679340031; bh=yubtDMU1v+j6puBmAVgHQ5Fbx/QE7P8/F/J6/XMCF5I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qRsn/jD8/Zhfxs1pKJpuzggNoPqR1eQ/83CCyFv542Int3WEAgis1VYGpxm8RnqUQ 4D05Nv7bUNSZ2kZfJQ4Q8bKcmJT9ZrvL9pFeAgj12h94reMER9x9GDNMjI0HnZ5Pnr j95Ck8CVgd9rc9C0WxRtfkN+CKDfHxKsX4nGUk64= 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 v3 6/8] crypto: ccp - Add vdata for platform device Date: Mon, 20 Mar 2023 19:19:54 +0000 Message-Id: <20230320191956.1354602-7-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> References: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760918303014786165?= X-GMAIL-MSGID: =?utf-8?q?1760918303014786165?= When matching the "psp" platform_device, the register offsets are determined at runtime from the ASP ACPI table. The structure containing the offset is passed through the platform data field provided before registering the platform device. To support this scenario, dynamically allocate vdata structs and fill those in with offsets provided by the platform. Due to the fields of the structs being const, it was necessary to use temporary structs and memcpy, as any assignment of the whole struct fails with an 'read-only location' compiler error. Acked-by: Tom Lendacky Signed-off-by: Jeremi Piotrowski --- drivers/crypto/ccp/sp-platform.c | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/drivers/crypto/ccp/sp-platform.c b/drivers/crypto/ccp/sp-platform.c index 5dcc834deb72..2e57ec15046b 100644 --- a/drivers/crypto/ccp/sp-platform.c +++ b/drivers/crypto/ccp/sp-platform.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "ccp-dev.h" @@ -86,6 +87,60 @@ static struct sp_dev_vdata *sp_get_acpi_version(struct platform_device *pdev) return NULL; } +static void sp_platform_fill_vdata(struct sp_dev_vdata *vdata, struct psp_vdata *psp, + struct sev_vdata *sev, const struct psp_platform_data *pdata) +{ + struct sev_vdata sevtmp = { + .cmdresp_reg = pdata->sev_cmd_resp_reg, + .cmdbuff_addr_lo_reg = pdata->sev_cmd_buf_lo_reg, + .cmdbuff_addr_hi_reg = pdata->sev_cmd_buf_hi_reg, + }; + struct psp_vdata psptmp = { + .sev = sev, + .feature_reg = pdata->feature_reg, + .inten_reg = pdata->irq_en_reg, + .intsts_reg = pdata->irq_st_reg, + }; + + memcpy(sev, &sevtmp, sizeof(*sev)); + memcpy(psp, &psptmp, sizeof(*psp)); + vdata->psp_vdata = psp; +} + +static struct sp_dev_vdata *sp_get_platform_version(struct sp_device *sp) +{ + struct psp_platform_data *pdata; + struct device *dev = sp->dev; + struct sp_dev_vdata *vdata; + struct psp_vdata *psp; + struct sev_vdata *sev; + + pdata = dev_get_platdata(dev); + if (!pdata) { + dev_err(dev, "missing platform data\n"); + return NULL; + } + + vdata = devm_kzalloc(dev, sizeof(*vdata) + sizeof(*psp) + sizeof(*sev), GFP_KERNEL); + if (!vdata) + return NULL; + + psp = (void *)vdata + sizeof(*vdata); + sev = (void *)psp + sizeof(*psp); + sp_platform_fill_vdata(vdata, psp, sev, pdata); + + dev_dbg(dev, "PSP feature register:\t%x\n", psp->feature_reg); + dev_dbg(dev, "PSP IRQ enable register:\t%x\n", psp->inten_reg); + dev_dbg(dev, "PSP IRQ status register:\t%x\n", psp->intsts_reg); + dev_dbg(dev, "SEV cmdresp register:\t%x\n", sev->cmdresp_reg); + dev_dbg(dev, "SEV cmdbuf lo register:\t%x\n", sev->cmdbuff_addr_lo_reg); + dev_dbg(dev, "SEV cmdbuf hi register:\t%x\n", sev->cmdbuff_addr_hi_reg); + dev_dbg(dev, "SEV cmdresp IRQ:\t%x\n", pdata->mbox_irq_id); + dev_dbg(dev, "ACPI cmdresp register:\t%x\n", pdata->acpi_cmd_resp_reg); + + return vdata; +} + static int sp_get_irqs(struct sp_device *sp) { struct sp_platform *sp_platform = sp->dev_specific; @@ -137,6 +192,8 @@ static int sp_platform_probe(struct platform_device *pdev) sp->dev_specific = sp_platform; sp->dev_vdata = pdev->dev.of_node ? sp_get_of_version(pdev) : sp_get_acpi_version(pdev); + if (!sp->dev_vdata) + sp->dev_vdata = sp_get_platform_version(sp); if (!sp->dev_vdata) { ret = -ENODEV; dev_err(dev, "missing driver data\n"); From patchwork Mon Mar 20 19:19:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 72432 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1411873wrt; Mon, 20 Mar 2023 13:04:50 -0700 (PDT) X-Google-Smtp-Source: AK7set+Dxf+r0jl+nbBuV5/V18+RPXSIeaztOAItAGUsIBb6soALlOpfQJkPm8ZkEa1CQTqfRfOa X-Received: by 2002:a17:902:ec8f:b0:1a1:d544:e5ef with SMTP id x15-20020a170902ec8f00b001a1d544e5efmr4295903plg.33.1679342690571; Mon, 20 Mar 2023 13:04:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679342690; cv=none; d=google.com; s=arc-20160816; b=wvFI8yaXROlJyI0eAI2JCW1zq8EW2wIHbvsjmRZoaHLvL3bcBQuasIbz1h0YF8df5L nabltAbw7dDQ7FpADGI+3uF5Gigs2Z3PPX5ItXZirQcSfi+qvfGX/WMIgyaPt53dR8H+ nG+r0jVfajgsMCXk4L1wUIasRjy4q8eRArge+LOhXioV50u+vYR2eZCVAFpExY29YgbI nk23/BiQrcmqy/SY46K3iHgMgUkV5CHqJTl+73OEXLQOlcbXRzIBSpQB1nPJAmsFSmTT IwQJqdWj5uxXDxAbRyx1eMH2fnXzmAy1FkNEHYW0qlR3ZlSCfDpx8MTGwy7CKguougdJ AVdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=bBdSO4BEUDEVvMxcTCZ7JtzxLQQi6ViWeqB1o0Yg5QQ=; b=jovBUzlSN6sCqXLl+n6d1H6QkRVXcoWUeEqA6Wl7FtIofmKi307ePOfMzczdYqpM7Q MPbdHNSXQ7HTIF3nkRzdoMiVoi/D3IBzf0wixv9Ec8rAAkVaTp5kho3+gwixBx5oW3iX tz6DWBzyRSC4HdWqe7WNiOSv87sKfbrrOIICyIg7NeqtLxO9fJdbORtH86sfm75r8R8K ZtDjfatFpyYKGX54XBsHHiuJVSs3Bog24AQpM1qxBGXBq3t2ygEdsYL3yGoMh0aOORhc 9xK6V8AJIv64LoxCz2gb55RRs70FHtEon0t0mkNAvTTPz2OK++vPVV9P2Fy7HWMEqWpb qLfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=aC4qY5fb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i12-20020a1709026acc00b0019f5311982csi10923142plt.215.2023.03.20.13.04.35; Mon, 20 Mar 2023 13:04:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=aC4qY5fb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230376AbjCTTlS (ORCPT + 99 others); Mon, 20 Mar 2023 15:41:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229997AbjCTTkn (ORCPT ); Mon, 20 Mar 2023 15:40:43 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2676C40FA; Mon, 20 Mar 2023 12:35:49 -0700 (PDT) Received: from vm02.corp.microsoft.com (unknown [167.220.197.27]) by linux.microsoft.com (Postfix) with ESMTPSA id ECE8B20FB401; Mon, 20 Mar 2023 12:20:31 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com ECE8B20FB401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679340033; bh=bBdSO4BEUDEVvMxcTCZ7JtzxLQQi6ViWeqB1o0Yg5QQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aC4qY5fbWDOd1/rAuigVUKUZ43nQyrIVW4WFOyvpm+pi97B1zWWKl+JPY0633s+7t 1HReNQZ1bUjA6tZVJWrlVhCfEdptTd7x/0CBnuo2AMavRVYrL4QbA0HOrVZuSJYOoA +N5MumsbrDr0W1dPgg08GkGb90B1bsKbjQjeL1t4= 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 v3 7/8] crypto: ccp - Skip DMA coherency check for platform psp Date: Mon, 20 Mar 2023 19:19:55 +0000 Message-Id: <20230320191956.1354602-8-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> References: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760918441211292127?= X-GMAIL-MSGID: =?utf-8?q?1760918441211292127?= 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. Skip the dma_attr check by keeping track of the fact that we are a pure platform device. Acked-by: Tom Lendacky Signed-off-by: Jeremi Piotrowski --- drivers/crypto/ccp/sp-platform.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/ccp/sp-platform.c b/drivers/crypto/ccp/sp-platform.c index 2e57ec15046b..be8306c47196 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_device; }; static const struct sp_dev_vdata dev_vdata[] = { @@ -109,6 +110,7 @@ static void sp_platform_fill_vdata(struct sp_dev_vdata *vdata, struct psp_vdata static struct sp_dev_vdata *sp_get_platform_version(struct sp_device *sp) { + struct sp_platform *sp_platform = sp->dev_specific; struct psp_platform_data *pdata; struct device *dev = sp->dev; struct sp_dev_vdata *vdata; @@ -129,6 +131,8 @@ static struct sp_dev_vdata *sp_get_platform_version(struct sp_device *sp) sev = (void *)psp + sizeof(*psp); sp_platform_fill_vdata(vdata, psp, sev, pdata); + sp_platform->is_platform_device = true; + dev_dbg(dev, "PSP feature register:\t%x\n", psp->feature_reg); dev_dbg(dev, "PSP IRQ enable register:\t%x\n", psp->inten_reg); dev_dbg(dev, "PSP IRQ status register:\t%x\n", psp->intsts_reg); @@ -207,7 +211,7 @@ static int sp_platform_probe(struct platform_device *pdev) } attr = device_get_dma_attr(dev); - if (attr == DEV_DMA_NOT_SUPPORTED) { + if (attr == DEV_DMA_NOT_SUPPORTED && !sp_platform->is_platform_device) { dev_err(dev, "DMA is not supported"); goto e_err; } From patchwork Mon Mar 20 19:19:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 72428 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1406390wrt; Mon, 20 Mar 2023 12:52:56 -0700 (PDT) X-Google-Smtp-Source: AK7set8QbP8HOrt1BmQ+UL6ooEN8phLd5LdvGl5zjBKNV3m6PQKH3HmUVsPkHTtx34VeZjtisqsJ X-Received: by 2002:a17:90b:2751:b0:23d:133a:62cc with SMTP id qi17-20020a17090b275100b0023d133a62ccmr337973pjb.17.1679341976392; Mon, 20 Mar 2023 12:52:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679341976; cv=none; d=google.com; s=arc-20160816; b=0u8zcx5C/dluQcyyetnfKzU1wFjrQp1v9igZfB8LX+aJgSHTjA7Y4ex26iAIl1xUgu Oi9L1Dww21XT7Q/Mp//m4pkJz3MgpkjTAMEASBnikAR4ClRHI1aSyTuEoUtQfAGxWNAH lwRRU/5aL4w0JeSci9Ddw6qeUjVlmL5Oq2PSfET1wxlnAPTR9A75rNVKaUFt016s5Twd Sblf8vo0OtHL1Bhn6rKt5cKP+PhcGNPQgXi7vZV1Z29wZELCsE+ihPQTpoFgr3UXlMTM QgaXl4vT88Y7vswrcrATj49B22KZEzp79h/nZr5gDm9gNzVkZ3opbEBghOAsEyklGtH7 IPYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=N7X8cpFIpuK4qMY5rWG6YjlSHa36cQnB2pwTMJA8wzA=; b=Rck6IzUra4dp9uBMLGMmXAJjVwZg7CH6xfmPEdLYe9h9LbN0adD+GPN5jXSo/tQFjz CC1llNVKdd0Mjjj2ohZUmhTBKV2acWvfXWI6GuPRPLtaDxDqzPVRvIHgF6uXs6wo08IZ c6GykqTR6SPlnSbrnaMu+ixvvR+XDKVTQLrlQj/Q/dE260R+h7Zro3YJY0WjMV4ZQxZ/ 7MQsYHVckPc85WJw3mqP92IDdhlAMCUp/s6Hn+4YZFheFahUp696DaCBUfkPZXLmjGnY w9PNpUv77+ykNCvVXR+b6RINa5dAlg1DhQ6Qz4VnMOHOxl8QM57ryrr+R+K19coMQis0 ADbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=VR8sJxLE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c1-20020a17090ad90100b002296a8ff568si10293799pjv.152.2023.03.20.12.52.41; Mon, 20 Mar 2023 12:52:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=VR8sJxLE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230172AbjCTTlX (ORCPT + 99 others); Mon, 20 Mar 2023 15:41:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230021AbjCTTkn (ORCPT ); Mon, 20 Mar 2023 15:40:43 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B17CE1E9D4; Mon, 20 Mar 2023 12:35:49 -0700 (PDT) Received: from vm02.corp.microsoft.com (unknown [167.220.197.27]) by linux.microsoft.com (Postfix) with ESMTPSA id 7629A20FB405; Mon, 20 Mar 2023 12:20:33 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7629A20FB405 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679340034; bh=N7X8cpFIpuK4qMY5rWG6YjlSHa36cQnB2pwTMJA8wzA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VR8sJxLE8sZRLhaxkiAtc0w04A3OXdj9dLjpLvsbpCig/9VRR4CxLnzKPalpQyOCR fmMzzsUj0GGyht2eoewFahA3XRJMkopHgFbwU5GyTmTK5LpfvyjD+4fin+KC5X7jnB pLjFJUZqu4AF8X9sCCr3RvoHf77y8p0Hf5yULuF4= 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 v3 8/8] crypto: ccp - Allow platform device to be psp master device Date: Mon, 20 Mar 2023 19:19:56 +0000 Message-Id: <20230320191956.1354602-9-jpiotrowski@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> References: <20230320191956.1354602-1-jpiotrowski@linux.microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760917692133909086?= X-GMAIL-MSGID: =?utf-8?q?1760917692133909086?= 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. Acked-by: Tom Lendacky Signed-off-by: Jeremi Piotrowski --- drivers/crypto/ccp/sp-dev.c | 58 ++++++++++++++++++++++++++++++++ drivers/crypto/ccp/sp-dev.h | 4 +++ drivers/crypto/ccp/sp-pci.c | 48 -------------------------- drivers/crypto/ccp/sp-platform.c | 6 ++++ 4 files changed, 68 insertions(+), 48 deletions(-) diff --git a/drivers/crypto/ccp/sp-dev.c b/drivers/crypto/ccp/sp-dev.c index 4c9f442b8a11..0ac1d0eba8bb 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; +static struct sp_device *sp_dev_master; + static void sp_add_device(struct sp_device *sp) { unsigned long flags; @@ -250,6 +254,60 @@ struct sp_device *sp_get_psp_master_device(void) return ret; } +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 = sp->dev; + dev_cur = sp_dev_master->dev; + + pdev_new = to_pci_dev(dev_new); + pdev_cur = 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 = sp; + return; + } + + dev_new = sp->dev; + dev_cur = sp_dev_master->dev; + + if (dev_is_pci(dev_new) && dev_is_pci(dev_cur) && sp_pci_is_master(sp)) + sp_dev_master = sp; + if (dev_is_pci(dev_new) && dev_is_platform(dev_cur)) + sp_dev_master = sp; +} + +struct sp_device *psp_get_master(void) +{ + return sp_dev_master; +} + +void psp_clear_master(struct sp_device *sp) +{ + if (sp == sp_dev_master) { + sp_dev_master = 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 20377e67f65d..c05f1fa82ff4 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_handler_t handler, void sp_free_psp_irq(struct sp_device *sp, void *data); struct sp_device *sp_get_psp_master_device(void); +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 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 084d052fddcc..af8f0f65c4b5 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; #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 = 0; } -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 = sp->dev; - dev_cur = sp_dev_master->dev; - - pdev_new = to_pci_dev(dev_new); - pdev_cur = 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 = sp; - return; - } - - if (sp_pci_is_master(sp)) - sp_dev_master = sp; -} - -static struct sp_device *psp_get_master(void) -{ - return sp_dev_master; -} - -static void psp_clear_master(struct sp_device *sp) -{ - if (sp == sp_dev_master) { - sp_dev_master = 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-platform.c index be8306c47196..e22d9fee0956 100644 --- a/drivers/crypto/ccp/sp-platform.c +++ b/drivers/crypto/ccp/sp-platform.c @@ -234,6 +234,12 @@ static int sp_platform_probe(struct platform_device *pdev) dev_set_drvdata(dev, sp); + if (sp_platform->is_platform_device) { + sp->set_psp_master_device = psp_set_master; + sp->get_psp_master_device = psp_get_master; + sp->clear_psp_master_device = psp_clear_master; + } + ret = sp_init(sp); if (ret) goto e_err;