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: 13181782 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 B060BC7619A for ; Mon, 20 Mar 2023 19:36:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229910AbjCTTgJ (ORCPT ); Mon, 20 Mar 2023 15:36:09 -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 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. 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: 13181781 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 CC346C6FD1C for ; Mon, 20 Mar 2023 19:36:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229888AbjCTTgF (ORCPT ); Mon, 20 Mar 2023 15:36:05 -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 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. 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: 13181783 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 52871C6FD1D for ; Mon, 20 Mar 2023 19:41:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229933AbjCTTlP (ORCPT ); Mon, 20 Mar 2023 15:41:15 -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 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. 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: 13181784 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 BFE4EC6FD1C for ; Mon, 20 Mar 2023 19:41:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230050AbjCTTlR (ORCPT ); Mon, 20 Mar 2023 15:41:17 -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 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. 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;