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: 653568 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6063BC636CC for ; Mon, 13 Feb 2023 09:25:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229865AbjBMJZH (ORCPT ); Mon, 13 Feb 2023 04:25:07 -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 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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: 653567 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D274C636D4 for ; Mon, 13 Feb 2023 09:25:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229931AbjBMJZV (ORCPT ); Mon, 13 Feb 2023 04:25:21 -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 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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: 653284 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED448C636D4 for ; Mon, 13 Feb 2023 09:25:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230207AbjBMJZZ (ORCPT ); Mon, 13 Feb 2023 04:25:25 -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 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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: 653566 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DCBAC636D7 for ; Mon, 13 Feb 2023 09:25:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230154AbjBMJZi (ORCPT ); Mon, 13 Feb 2023 04:25:38 -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 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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;