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: 56117 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2250614wrn; Mon, 13 Feb 2023 01:29:50 -0800 (PST) X-Google-Smtp-Source: AK7set+lGfQq3sP371yc6VuI2qIvAHVvXPQr3jyFFOBgFOC7K3XMWBs5fIItzB/akbgnbj40nnCF X-Received: by 2002:a17:906:3994:b0:878:4dd1:5161 with SMTP id h20-20020a170906399400b008784dd15161mr21601120eje.11.1676280590100; Mon, 13 Feb 2023 01:29:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676280590; cv=none; d=google.com; s=arc-20160816; b=WChVUvNUlWLvd11yEbaBuWZBjIXWFAzhywSXAtzsPCeeq3EL3YhD6WhG/MLYTCXjbz 0CvOhNiaYbtlHzqectj7SbonNqi0NRalWgUgB5DHOhdURyd8nWbtvrVAFme8MOhILHIW aA/EWXt+YGxbgR3V/OYUIIoheHqqnoBDIpSS4C62yNqploAxXNqkwFQMs8mt685pr5up qL2B0WCHrAGkWbYB27I1V0zjUxe+mD2LzJqWSHX16kJelcEMtLv96FKKB6F6QQuCihDG 6ivhkPV/DY2q31jytBIgco+ASHQj9cDrn3vJMjD70EZzxWF5CtUZdBPJKiftr0izHEjq sFOA== 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=Li2UJyY0mGyrGpuxPLsk95rzcd9mDiZ9P/GYVetjqcw=; b=tI8jcwlLTb5Pg0Qw/wUeQ/Ridvix53KzQwnCe1DikllsLxYbKONj8rpfUXPmBO8Li5 SqpWvZNWVaw7LkG94UWGFFcfthMXxXFCiUezezjv40Nx2VyQKewbZ9RzJDmBBNZPkSGO 13jS5CM7KdorkKJfvmZaRPp3dxzInVaqvn8zYWR6QBIdjHBi9HpWZO9uo26NT8Zo3K7J QMD3ibtoy48MUFEfyGvco0aYsE4Yt4gtRuQ/6wCegnsaMRWB1+5Efl8d/7+AUystU8ck 293meQuuYTmg9iI9j/wnqBtzqp79K7GwFiwOzEi5c7EsiHCGngwzEJFY87p93a9cSIWp eBlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=MGKw1AOx; 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 fh23-20020a1709073a9700b008ad696c0494si13036367ejc.465.2023.02.13.01.29.27; Mon, 13 Feb 2023 01:29:50 -0800 (PST) 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=MGKw1AOx; 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 S229977AbjBMJZL (ORCPT + 99 others); Mon, 13 Feb 2023 04:25:11 -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 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?1757707596153331401?= X-GMAIL-MSGID: =?utf-8?q?1757707596153331401?= 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: 56123 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2250866wrn; Mon, 13 Feb 2023 01:30:32 -0800 (PST) X-Google-Smtp-Source: AK7set8rukHKvN42cdvg6u5oTvWgIQwXO1/J/TD3p6mWyEKIdkcRhje3KNYuS1eaUrtXokO3ILHR X-Received: by 2002:a17:906:3b94:b0:886:4ca1:39f1 with SMTP id u20-20020a1709063b9400b008864ca139f1mr23179924ejf.73.1676280631936; Mon, 13 Feb 2023 01:30:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676280631; cv=none; d=google.com; s=arc-20160816; b=zb8ZtpMENBJBfr43cFrh48YS34g7Lbya1Ee3S7nPwrjOsm+JQzaRNr+S4aQc0982ir IgLGP9slhAirAWMBgzOMCeYIWt9y9rZOeSBZqKsWeiCyzaNqOhXWUZTGmlk5M0e64KCW 6pVbSa8L01tzVB8afBpN2Ahm4/GIgesXw4tgb1RVtqlzoNRRdWmv+l1hiQCziOKHnWih c2pRs6KCRjt7NmhaNy30dYiYbCVuBqDPxbHzuLsGgumCmqT9Mkq6+XftOyv8B+bqPJCg Q1SqDrM3KKtp6oLVUcbD7Reer4yOCOP4Fg9mw6CkULVEJZkqTw7+Vyk9yWaLxJafcQGT CqMw== 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=9zBj7lGZiNLssSN0Bow0NnJuBiAOG3TjbvKNnsD+cgs=; b=WAJivH1uFV+BoVe5YFtFQe3JILo/WO5kK6uTqqiXH0SHecRSZ0ITUv5Mvx7x+Iuxts c6UmwmX7kimbAVVB/9igdrDpxmQPUKNdgT0b+jfNMDhPg88k7kC3wKQlLDU7dFaZcIwj EBzt2s6mroaQTrXj5uz3Bm1Imkib1E68P1P2HgRHzcSCM48/SCGksRp6/giKMmtQy56X vW+wp/KN1j17fscNDHDnFhNeu4FuZF3tBNPlihAzccAMlrz5N/xkQFZzE5s+PRfri1AU EnRcEsq2pN/zbymL4XWTCG0uGhGUYUZ51DnfSg7+AlK/Slg4WX4VYSMFtY+bW743npUj pZIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=U4oNPXXZ; 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 3-20020a170906224300b0088ad80b3730si19103065ejr.829.2023.02.13.01.30.09; Mon, 13 Feb 2023 01:30:31 -0800 (PST) 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=U4oNPXXZ; 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 S230080AbjBMJ0q (ORCPT + 99 others); Mon, 13 Feb 2023 04:26:46 -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 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?1757707639946844578?= X-GMAIL-MSGID: =?utf-8?q?1757707639946844578?= 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 */ From patchwork Mon Feb 13 09:24:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 56112 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2250147wrn; Mon, 13 Feb 2023 01:28:21 -0800 (PST) X-Google-Smtp-Source: AK7set+Ko4gwX1+sMM3qMhVB/lUWeFXOxercVTTqANTFCr4Wx98OwKN1FonkfXwvtHL99NAt0wqF X-Received: by 2002:a17:907:318c:b0:8aa:c0a4:2aa5 with SMTP id xe12-20020a170907318c00b008aac0a42aa5mr27987497ejb.16.1676280501239; Mon, 13 Feb 2023 01:28:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676280501; cv=none; d=google.com; s=arc-20160816; b=hkbQ+KP0J9RtCGLKYIi6A5/nUiyrJq4cugHPEQkLn/N4+8OSkm9z3Mqp4UATikdbDH ybgvpbXtxrZlYlbHjmN2V8lfa05YogQyYPEFpf8urYKxQ+qifwAdgnl4EQOCSkKAvdQV 9HgO2glBEOwFZkJSlVgepsodMuHL/+oI3nWSD1YNlPHq/J+fX9ajnYzh8olveO7EstNr llyqy3wlXC55WuQMGBmXBFgP/BJYQz+VAYG/RveGkjUEo57OemaWCEKtLRNkSQKgnVlW OKVYbvRcpEnD/W7fFm7JYcoKU2/IVZCbod7mWbgPqxzMVLRJpljORXRmtRCOjVal490s iELg== 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=f9Xx8zd3cC548f76QwXZyTN1kcFg1eYeHzMUDFo62GI=; b=aFbA9GFBAM7HvWg0faBfUdvsYvW4qt6CXWlMGqNYVjz4DNPazyqxSt6Nh57SGnJPDm 3iIodV844RGku8CHecZRhES768hd/BaYhGr5CAm2/Awvov3HK8gL3rYkzcb6MFjjhms3 TizLxyUxSUWO3Qn7udxgNJfzWHJboQcRUHaD6epm6vVbTXR9NpSRrSMZ9YyXi3scQiPO n8ZX7noS9Nwx/oLR+23kX00JWdulyfcNKaTQRguAItiuZsHviasEKqRxd52MNVUL7mSn CUG+/zeengtGJYHepbCyQMVDj8dm40UPzB2LzHubbUeMiTXITvhOxPz1sQu7f1mRS24b d9jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=QZQQ2O7N; 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 fx34-20020a1709069ea200b0088e6b7aff2csi14490527ejc.159.2023.02.13.01.27.58; Mon, 13 Feb 2023 01:28:21 -0800 (PST) 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=QZQQ2O7N; 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 S230102AbjBMJZT (ORCPT + 99 others); Mon, 13 Feb 2023 04:25:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230302AbjBMJZB (ORCPT ); Mon, 13 Feb 2023 04:25:01 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 17FBC7A87 for ; Mon, 13 Feb 2023 01:24:58 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id E555420C8B75; Mon, 13 Feb 2023 01:24:55 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E555420C8B75 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1676280297; bh=f9Xx8zd3cC548f76QwXZyTN1kcFg1eYeHzMUDFo62GI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QZQQ2O7Nd5vLeG2HLnBUkGl7LSBRS1xjMlq1HBa0j8hIdNM3YXthX9ARB/RcOcfAo ELD9XF+kPonyECix4PmTDi4PPQtbN47LtD7zDzBIZ41D+eo63MlmbB+mEc1RJivJJc MwQm0SFTybhMre1t/piwmmX+FOK2oSqEKXjx7eYE= 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 v2 3/8] x86/psp: Register PSP platform device when ASP table is present Date: Mon, 13 Feb 2023 09:24:24 +0000 Message-Id: <20230213092429.1167812-4-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 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?1757707502620801374?= X-GMAIL-MSGID: =?utf-8?q?1757707502620801374?= 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 | 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 f901658d9f7c..f7b71aa245e8 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 Feb 13 09:24:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 56113 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2250338wrn; Mon, 13 Feb 2023 01:28:56 -0800 (PST) X-Google-Smtp-Source: AK7set91vZNLu7WjMLNCpsQyyuYZoxSx0lkTxEFOgewdFOLGjf6wi3VJ7RpGdj26Sd6wwNFQse7Y X-Received: by 2002:a50:8a88:0:b0:4aa:f910:c21c with SMTP id j8-20020a508a88000000b004aaf910c21cmr19114398edj.3.1676280536139; Mon, 13 Feb 2023 01:28:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676280536; cv=none; d=google.com; s=arc-20160816; b=jX7AKwYcAJag5k7ZMtddxkn4QHUHsPhYdK8Kr70QGOaSrUAho0P65dHrf3/GFQbJ/A maDmOSX13WIO76rUvE6H/1UWcOlz8g8oHuH33Xr3CzX+F9CtiigpHBp1irH2hk2EATiQ Dlt5Z0XRNKCxqfavkdqiJHk4b+mcUonVnxwvWy10Bx2Z3rnL01WJQn/PdnVfbEnfjpVk P4i5icghWQDSpcyR6G1W15dfbk+LyMu1HLxl/tDA6ylSAxUuLOyxW65J3wkrHBdbmOCf bCdeLfHNCq03hzNu088GuUvLwYWq5Z+fSCSaJZQFOnCNE/XKRulQZKfBXbfaOCndF8ON JDSA== 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=Y6j4xfGwq3ZWpbpVdK5+8oMNaRGiUheAe5neUIwprVc=; b=mP61CG51jk0mEByZ5unAZuGRjO3a5xvD+i98BPgXFRI+i4uGTjClLrVMgbnRz+xUZ8 YjitP6n+HWzR8RfPc5UzklCZY1/Ujr4+06Nk5KxGzo3mi7xDu0wDfXJ3lw+w4P4XrfFA IyXaepN/fIwBiD9LH4NS7IJNhpiPxylMTdB0ISqkVQWGkHJ+SCrjBWe6JjWbOqGYyvZh k45jQaAz0A75GHIzcmzAR/bn8XvsGODVFCSCZL7fUrHJ0jKJB+aKlbdToeci+76HfHxj mVHOr1Tcd0nHfuJcJECH0efyRBrJt1kUJ6G5MFIQ8YJRJAalnBU7lGJsiD6m5hhEY+Qk 1mZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=CGDQmJJN; 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 bm2-20020a0564020b0200b004a2657551e4si13403039edb.287.2023.02.13.01.28.33; Mon, 13 Feb 2023 01:28:56 -0800 (PST) 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=CGDQmJJN; 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 S229552AbjBMJZ2 (ORCPT + 99 others); Mon, 13 Feb 2023 04:25:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230313AbjBMJZD (ORCPT ); Mon, 13 Feb 2023 04:25:03 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2D02DBDDA for ; Mon, 13 Feb 2023 01:25:00 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id 0608820C8B77; Mon, 13 Feb 2023 01:24:57 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0608820C8B77 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1676280299; bh=Y6j4xfGwq3ZWpbpVdK5+8oMNaRGiUheAe5neUIwprVc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CGDQmJJNY9LSBQbu78aVGyYkO09nStn5ZfgbcY/IKMzRLBEu3Avu7B+fLbFt2mTVX EU7nrU+D1+qOltsqM0UqN/IJX814bpkNyUbj0UxLMrV+7oTDuqawiExUWUjFgC9BAW iuaj6jHajHLGuOXHMz3brJ3doepQ73FfGkiDvgLw= 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 v2 4/8] x86/psp: Add IRQ support Date: Mon, 13 Feb 2023 09:24:25 +0000 Message-Id: <20230213092429.1167812-5-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 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?1757707539649873417?= X-GMAIL-MSGID: =?utf-8?q?1757707539649873417?= 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 | 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 Feb 13 09:24:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 56114 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2250355wrn; Mon, 13 Feb 2023 01:28:57 -0800 (PST) X-Google-Smtp-Source: AK7set/hZSwvtkFFPgvNwED8995YCLw+yVEN7gpeL7KGRsO71Oa1ev4x8/7kCGfLhGpKdQw74Ry2 X-Received: by 2002:a17:907:9619:b0:8ae:ea17:bae4 with SMTP id gb25-20020a170907961900b008aeea17bae4mr23244274ejc.30.1676280537435; Mon, 13 Feb 2023 01:28:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676280537; cv=none; d=google.com; s=arc-20160816; b=mpn/Kko+v3lfurlA+ZLhzTd2ZA1TMQv9/YFSYXIijkjM28NH3XWMKIrumBerok/xmI El40gOxJhzrkqw0EbDeMTEOZR/JJZmFsTITCX2UjDv6oaxDdvLh9PZmn7zn4tn5xXN9W 1ajWVQiaIKBGlUnO26Hvm8IqUnGT3kuISj1Ib1ga4uy7TLpCJZsPamNWLtEOgMUrUXGA JiOuExeQ5LJ/5KDRJiXXG5BphbTZWQiyZ4OLdg83e9d2TTnFYpd+Mtpk01XPEX0WgTzt ZKV2SxSmFEtt4UMDsz9E7368nw9a6GF+HDHY0fEE//j+fNOVgX56sYe//UKtHB0q11JR pR0Q== 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=u6bQzaO/aYZQza3w+Vx7rpLvq48R3EDcrSdcbhpKXaU=; b=eQFxAPEW406ml90xXf3ioZ16mWM6WF5BmPjNNoPGhYldpiYlh3GA27JIqO/PPX7xh7 gIl8WLGaa0Aqajw7bu6KH8d5aAnTc2GioOH7CATaXbvEyKIGwkm4bj5xRpcAfnlw22qx HQ0r3oFhfpbTHhGyaQkTUX++d2TMZQmXl4PejxpdvH9rutTxsJUqwsyZ4A5vk5Keusc7 zrAci6WhYCkR2RzQTPrjh671548XENe9YUVKVVQnp8ljuSr+ozilDDx9S5USjP1/TNN3 AGiG040Wlid//K2wuO+hKkU6R/WffGSFAJusYj1hgQJYxMYT6FBt08faZ37QeYB9xALu ikwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="Y/pSVvJB"; 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 15-20020a170906208f00b0086f0864592dsi15065048ejq.321.2023.02.13.01.28.34; Mon, 13 Feb 2023 01:28:57 -0800 (PST) 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="Y/pSVvJB"; 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 S229968AbjBMJZd (ORCPT + 99 others); Mon, 13 Feb 2023 04:25:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230314AbjBMJZD (ORCPT ); Mon, 13 Feb 2023 04:25:03 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9E54C7A87; Mon, 13 Feb 2023 01:25:01 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id 1A51120C8B78; Mon, 13 Feb 2023 01:24:59 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1A51120C8B78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1676280301; bh=u6bQzaO/aYZQza3w+Vx7rpLvq48R3EDcrSdcbhpKXaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y/pSVvJB+j4QH5pKCj4jDJjTzEpFFUlGKFJ+d5EOwghKmD0Zd9B/7e2ZXPwESAx3D KsFe4p6MvWBY+g8NQDFyKw1MuvoppY61ily10Ri3PUtSA0EFNZZ7uQGj3iQNIuF6LI 8lnL3yHMf2ibGfuN4cScAmo03phSD9GdEgV9kwtY= 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 v2 5/8] crypto: cpp - Bind to psp platform device on x86 Date: Mon, 13 Feb 2023 09:24:26 +0000 Message-Id: <20230213092429.1167812-6-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 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?1757707540649031357?= X-GMAIL-MSGID: =?utf-8?q?1757707540649031357?= 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 | 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 Feb 13 09:24:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 56115 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2250586wrn; Mon, 13 Feb 2023 01:29:45 -0800 (PST) X-Google-Smtp-Source: AK7set/8VSYDl+veS32xO7+Y9dq7np7Dro4IkZnvWXLXwZfFfAUGikEOd7h6HXQjF7t7+jSj0zSE X-Received: by 2002:a17:907:9c07:b0:8b1:fc:b1b0 with SMTP id ld7-20020a1709079c0700b008b100fcb1b0mr3876766ejc.44.1676280585102; Mon, 13 Feb 2023 01:29:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676280585; cv=none; d=google.com; s=arc-20160816; b=gPBA2/IdRjoQBkaE5dneuF6mVQKFZy6yr6vbalFk8Ns8WxB9gUJjhTNZZM0fnRBxaV iJL6gaRdAR/aiEEyyUP/JeKy5sjLOS6q0HwnebNH6EEib+z6RhlCWMi7Sg9biM8xpMHG nJteR3ZAyMs6QnqGWXw35PcNZCw9c1MA26rYeTzWgBw1xWx2VrUNBXBwaqXQfbIipX3S saycaDfAh3AwzDh8NrV7s/YcUatGgrZWShM+aJlJnsPuawhnGvvWlY3Zrwfhs3KJL3oU DUVIQmg9ocI75ITDzJlWcyeLMzUMgQKt3oaGEqnopthKZy+cXmdIkrrRoSXpBLuYqUb6 OcJA== 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=g0sUDZUZPSozLfPSFtOhNE8txHqjio4WGyZV6VO7onw=; b=UGHKRhd8OrnMaBp5dk1Ho7AlEZerEnNmtXCj7Tc1qa6bRPLenypgy+CHYyHS4F1yZo VlUJNosBJF4UqigwXHR4DJ9WWNpF3qDxfNDEdBmwJTW3UbS7hB0Ip6FGh8Ejo2mKMOfd JfejmEKZB5RF19nXOo1aVnHHIDlXZp9v7U2Uno5M0+sXZhjt6MqeFreOvovQx4XTJ6hZ oRvwvbwWMGn+Vd/u/QGaLcE/dRlKrmcjE/hR9m280b418V1b9H5dQpLMl1zy0MGr/Cwv 8qqO7rIF6oXsf5ZnrdzbvGby6jhjD5Whq/KlWPr7GgONIeYHagnmkHmTcU5E5kT1yUjE U2aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=OXxtBYyZ; 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 fb23-20020a1709073a1700b00890ac0d6147si12962175ejc.919.2023.02.13.01.29.22; Mon, 13 Feb 2023 01:29:45 -0800 (PST) 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=OXxtBYyZ; 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 S230120AbjBMJZj (ORCPT + 99 others); Mon, 13 Feb 2023 04:25:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229921AbjBMJZG (ORCPT ); Mon, 13 Feb 2023 04:25:06 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 302701555A; Mon, 13 Feb 2023 01:25:03 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id 957D520C8B72; Mon, 13 Feb 2023 01:25:01 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 957D520C8B72 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1676280302; bh=g0sUDZUZPSozLfPSFtOhNE8txHqjio4WGyZV6VO7onw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OXxtBYyZK7Lhe8lOkWYXpXS8uK2M8i64rNKEI7Qcb7M/8atqDkPrW7MN6GDqeJqt8 rdchrlIM4lZYS0j/RletwrfbjvSjh926xzoLo04yqJYD6EAnBbotAxKG5QgRV1oFwI VrmziZDwh9bPmE6h/dRNJavT6We3FdwaqAXsMm2g= 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 v2 6/8] crypto: ccp - Add vdata for platform device Date: Mon, 13 Feb 2023 09:24:27 +0000 Message-Id: <20230213092429.1167812-7-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 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?1757707590750025151?= X-GMAIL-MSGID: =?utf-8?q?1757707590750025151?= 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. 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 Feb 13 09:24:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 56116 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2250605wrn; Mon, 13 Feb 2023 01:29:49 -0800 (PST) X-Google-Smtp-Source: AK7set+K0U9ysB1o6ilrPVyhpUZL3W3y+nRY9uVrLK+hsB9LsbYcp6BmlUDEGHK17XrLXljVJ73N X-Received: by 2002:a17:907:1c18:b0:878:481c:c49b with SMTP id nc24-20020a1709071c1800b00878481cc49bmr32078313ejc.1.1676280588946; Mon, 13 Feb 2023 01:29:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676280588; cv=none; d=google.com; s=arc-20160816; b=0UEZstF11NKqwycAwF8zXHJSzBcBrNm8ya3jZQi+lPO9m2IutNFsideci3Hva3dxnb y31Hpt1cZ6ALh/rmK1dXlUbf9ER5KGBuRaPGY3eT7/uVE8bbDEvSRPHlHCr0bnXYivog 59rTxU5/M7rCEVwKLqxkVZrQJVWN0gyRGrggocgw9PyeZij0sWqnOb9S2PZUzQEdtwKg IcFd1uoNNBnwpnYq3luPqo3xyZdUJH2V+rVRQqquQUEG8j65Mdib6uFlunuRr3jc0WlT ZNR+AX0QR6nmlj19w0wa0S+rpS3V4LG/HmQRO7xQZP1UbUkXGeQ/Kr+YQlGPOzpb2kn0 +XEQ== 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=je/3mF6RDXR0n2F5L5ZDLOFD8qSmDdLzDu1s3CUF/yc=; b=yferql5WHD2pDL8QLvwac/pKxQxR8dJscOGnoB99K10OCbfqjURDmuU29kO3NLMgoj yPK7p3SELKPd31qJICv+wgCOCZUKuWMOehFAR3jAjbK3FhnAjoO2uLyFc7NDHkA/HLaX wFHIfOaEQM5mhs0VHfMSE3pzGbgfNq4rIbRFdDxpJ3AsBujdsfeYXAKbzjWMl6WA0HvB jnlypl/aXZz2+I1TaYXX2zn4EQ466t+nqm23oEYBioQiYFzHjbiBZhY6146hlMMm5y/z gaGkSUGof5SfFN7iqujKz3t74uXijwJqMDmSu8IWaaSeNfNWK6qVa+BtsDu7kdMlXWS9 kcVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="hJ7/epNy"; 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 cf8-20020a170907158800b008aaa653dd8dsi11586113ejc.951.2023.02.13.01.29.25; Mon, 13 Feb 2023 01:29:48 -0800 (PST) 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="hJ7/epNy"; 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 S230104AbjBMJZn (ORCPT + 99 others); Mon, 13 Feb 2023 04:25:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229941AbjBMJZG (ORCPT ); Mon, 13 Feb 2023 04:25:06 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A33B815569; Mon, 13 Feb 2023 01:25:04 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id 1CDF220C8B73; Mon, 13 Feb 2023 01:25:02 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1CDF220C8B73 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1676280304; bh=je/3mF6RDXR0n2F5L5ZDLOFD8qSmDdLzDu1s3CUF/yc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hJ7/epNy7b8mi67fZB7M1U54lgF3LVaLTJI4xfE+mwvMUqDY7peHg7DN7doTyVmEx IGodrFFAckw461TgAyJUJmovuuGsXAATgDo2c7Kyj3h/7aqtAB+Jvg8jlsad9JNXoS kc9oCI4UgDKL6vSWUjrh8vFC8KJO990w8mXkwxjc= 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 v2 7/8] crypto: ccp - Skip DMA coherency check for platform psp Date: Mon, 13 Feb 2023 09:24:28 +0000 Message-Id: <20230213092429.1167812-8-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 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?1757707594772122145?= X-GMAIL-MSGID: =?utf-8?q?1757707594772122145?= 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. 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 Feb 13 09:24:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremi Piotrowski X-Patchwork-Id: 56124 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2251331wrn; Mon, 13 Feb 2023 01:31:53 -0800 (PST) X-Google-Smtp-Source: AK7set8q6FONqxcphQWtHPGdteFkMZJdetoTBayCChXaThJ8wmsa8l4VCKO9s0sa3YnlgX4Jsu/I X-Received: by 2002:a17:906:3a8f:b0:88f:a236:69e6 with SMTP id y15-20020a1709063a8f00b0088fa23669e6mr22862693ejd.7.1676280713296; Mon, 13 Feb 2023 01:31:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676280713; cv=none; d=google.com; s=arc-20160816; b=RTjXA4mgmjdqJJmaGeZPMxf4IJJNY8AhfRY4Iu2fRWrIQ054xxh8yPZ8BLnvJc0jfW G5rs4TZ/O9cVRendPCyU5GSwa9WMPwsBY28cJum9j2E3no30LMYQ5i7Pneb10QGZWPBi 7zFEA6TLk+Uj1UtvfW7WVkdZoMyBeX3IqXhpiBVpL5jTzt5Gz4vlXOEIfFlqUpsEA/Hz WDMcUA+n6HjpvLjpeIaNeUPoNLdqTEBDuDT14alJUjD5Ql396z6VE+TMssliqyJufbpD dzNcaoDfzhN4xElVT6bKyLJcMIGu2p7SplwMldlFpYWkI0LoS+YhRu75YlHUd1ixOE/B UvIQ== 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=udNfQxhrzm6ZiBM4Ul0LOy1eV94C7n6f1u452pJAl34=; b=JdH9xquieuWGsRCbXEMTerzWd84GgOAPb95D0J9PQc5eDLNz561fRKVE7KDIuZmg/6 oR/T6zUE3uJPE7O/FDlytuO1vFtifk5m3oZX29Vuecz6FnBKV0vk/Er74wTN6Sd8zMpo XLVBfJz5BteAVRzyV3VS4pPnxsKeF4kfCE/dy6ZmjFZZ1lW47yAFti+8HqhDuHsmnxrG OMJmOBovdMMDq1tnJT6JQBbdB//ZYVuzMlPGWWa0mhUXBItpw7qTj0A0b3bdxMmziQd4 PcQA3r9Ib8KS+NuYSNMLPsQ/w9S0CynNwdVXlVlunnzLSXOS97PW9BUCCwwsVLlaMa8N TC4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=dhhhUcto; 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 fx36-20020a1709069ea400b008785a767443si6499740ejc.348.2023.02.13.01.31.30; Mon, 13 Feb 2023 01:31:53 -0800 (PST) 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=dhhhUcto; 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 S230333AbjBMJZp (ORCPT + 99 others); Mon, 13 Feb 2023 04:25:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230236AbjBMJZT (ORCPT ); Mon, 13 Feb 2023 04:25:19 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2F03A15C9C; Mon, 13 Feb 2023 01:25:06 -0800 (PST) Received: from vm02.corp.microsoft.com (unknown [167.220.196.155]) by linux.microsoft.com (Postfix) with ESMTPSA id 9733420C8B78; Mon, 13 Feb 2023 01:25:04 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 9733420C8B78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1676280305; bh=udNfQxhrzm6ZiBM4Ul0LOy1eV94C7n6f1u452pJAl34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dhhhUctoqB4JMn3JG6BfJBXEkobt/MxJ3r46mCeKrkjvDCKU9SDmYnrU5nTa+w1Uq fxfwaSKKB1+8ApAP7pB6Zd0Y5Hf2OdMvxJ45VQXouqyCq5JsNnEXhK9pYYzL8G9t/1 AGkn6giXzN3jSS9oV9AjbLIo7vXPBAfdxt17e6LY= 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 v2 8/8] crypto: ccp - Allow platform device to be psp master device Date: Mon, 13 Feb 2023 09:24:29 +0000 Message-Id: <20230213092429.1167812-9-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 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?1757707725547332836?= X-GMAIL-MSGID: =?utf-8?q?1757707725547332836?= 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 4c9f442b8a11..71461dfdfa4f 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 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; #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;