From patchwork Thu Mar 2 15:16:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 9600789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A6A6260453 for ; Thu, 2 Mar 2017 16:04:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9170927D9B for ; Thu, 2 Mar 2017 16:04:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85360285B9; Thu, 2 Mar 2017 16:04:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C00D828562 for ; Thu, 2 Mar 2017 16:04:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754059AbdCBPgE (ORCPT ); Thu, 2 Mar 2017 10:36:04 -0500 Received: from mail-bl2nam02on0088.outbound.protection.outlook.com ([104.47.38.88]:58608 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752631AbdCBPfA (ORCPT ); Thu, 2 Mar 2017 10:35:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=QihZWXXwONT1e9sdV6kwnSi3citRVPvmFgEFigHghd4=; b=VxQG/pS5dvyjBxdDXv13QkYNEveB1BGqvl8NsyLKrPG0AeEnmgv9nVa3xfoUlFN7QNnJc2IUbm3s833vyLa/b486G+61hO6NyxBgooz/Z+2sgj+lFvJgvX/CTYKvCn+i++tYRitRqoFwpnXAdEg8mwOAfhuH2og4UcnkdQgcfCY= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from [127.0.1.1] (165.204.77.1) by DM5PR12MB1611.namprd12.prod.outlook.com (10.172.40.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.947.12; Thu, 2 Mar 2017 15:16:34 +0000 Subject: [RFC PATCH v2 20/32] crypto: ccp: Add Platform Security Processor (PSP) interface support From: Brijesh Singh To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Date: Thu, 2 Mar 2017 10:16:32 -0500 Message-ID: <148846779224.2349.7159735938287530197.stgit@brijesh-build-machine> In-Reply-To: <148846752022.2349.13667498174822419498.stgit@brijesh-build-machine> References: <148846752022.2349.13667498174822419498.stgit@brijesh-build-machine> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR14CA0011.namprd14.prod.outlook.com (10.173.227.21) To DM5PR12MB1611.namprd12.prod.outlook.com (10.172.40.17) X-MS-Office365-Filtering-Correlation-Id: 046b3cf6-0b3d-4d98-db62-08d4617f2073 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:DM5PR12MB1611; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1611; 3:LQy2JoqZNa0eRdt53E6KPza0OsUkaawlWPdJRb3tggtSmX8mYmX+KXoK7+r0Eb1gZETy9Qn+Wl0zIfLdkIJsiZgrjsWHrK6M9s0xbyLDrhNkC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3ls2UJ01ZKUnj8McUfrlKNqNWNDWEQ8go2/Lwyhi1FS9P4s2TFhZKovlMmausimRZctD1hofrHi1p2khAFkpo7DX8dNgGlVPcJD37+eiFM6PqvrYjmP+M3/OPge0DwWF+FJFyKZny9rsV/TpSW9bkbBY3yaZtUy53/s7EI2ZLQXIPS+L+9OPc+gmpKFD2eh+dpDul5CFCW0EXODFiEuISrneMoFciW35/dGjr7jlIbWwaiBRF95pkkwupVZsjY/9OPNyMoYUeVXG3hDvom/TWRfk7hRkJ8ESmw9KxcqD5Vhs5K4e+xEcgJ+Xj7vCIgTpbTegZuvnQ9dYCwFSv+50+BfB9s2zDEK X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192374486261705)(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6041248)(20161123555025)(20161123560025)(20161123558025)(20161123564025)(20161123562025)(6072148); SRVR:DM5PR12MB1611; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB1611; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1611; 4:hkyE195QLs9QQPp4zHhwel+pnYts9+04/KrcgraHr94Rt9Z+a+lrUQi0bYK1AO+4ZuYs97ix/E6G7ssyCYQnFzPrijBUuQg0eXrbaBjAm6pzR3VBvaHZhmThGiWpHyici5ZG+3FbeK7dK5SWd8Vh9jcOTMTWyIQFdg7n/VoOWwoEiPW45+rGehvdzUnuxVUi7MBC/HvvdwyKRJ9VJ07YNqGq9FZKaa/kZPHvGpHdftTHVMWGN/B990o5mj2iKZVZIZhqMfNYJVGNzKY2d2Ejwsqs8EKQRWXHzIHic+EKFu5BV0Z4ZDHNSWphAj9TuJ0PVm+Itfe3odBCQMTRsJIfkqid9PaIsDaS+VMdGeLPFDrtTXV3i4nQ237f44TIp/QPT41I7xQ56HiHj/liOzIjEAP67VRs07ROMwHb0nKjytITp6hMN0UBwA4G//qa6sp31NvpQoEd7PJAIcBhT0KjkdWmNzUOyIQ9oUuRUa/l+TgAWX1M0yZgnG7x8KeW4PgPEHuCZpEFqWrm0HvikfTmCdJ/5BevJmH2lEufYlBZJFeO3Cw+rz/O2mDBcRnT7vHN6Ei0NlVgBuSs8GGBQJzTdmhaZEvXIuCLtGipLxc68wmPNjsdSMlDxHg6qklhoSjxqYhwapHp75j5tFqdh+gQpIj+BbbTDyoeKY5BjJOtCDipAImLS9iwHQsKSsXz93mE X-Forefront-PRVS: 023495660C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6049001)(6009001)(7916002)(39850400002)(39840400002)(39450400003)(39860400002)(39410400002)(23676002)(50986999)(86362001)(42186005)(83506001)(54356999)(7736002)(7406005)(76176999)(2201001)(1191002)(33716001)(7366002)(7416002)(92566002)(305945005)(66066001)(189998001)(47776003)(15650500001)(53936002)(33646002)(2950100002)(50466002)(103116003)(25786008)(9686003)(3846002)(6116002)(90366009)(5660300001)(77096006)(230700001)(2906002)(6486002)(38730400002)(81166006)(8676002)(921003)(2101003)(217873001)(84006005)(83996005)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1611; H:[127.0.1.1]; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTVQUjEyTUIxNjExOzIzOjd5WjNEaFNaVDViOTV2UlBjY0pKTmFubzRF?= =?utf-8?B?cXFRU2pCeVZrYmdERzRINmVWZExWZ09aQWsyL3hRY1FZQlJTTHRhZkVjWXVQ?= =?utf-8?B?SlQwVEdLVCtYT3p2QUtpS05ySWNRZEhuZlJIQk9WbUs1WUcxTi9XcHdIdytN?= =?utf-8?B?d1ZwMjl0WVVicWhBelY5dzNPSTVKOFNPMmpMQ2JJM0xVRkVYR1d2bk44MEFo?= =?utf-8?B?cmlIcXlHOG9DT1FXYXMwVk9KRWxwTjFZTHF2Z3ZLVmhtTnMreXZoM05CYjZW?= =?utf-8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4rnvD79JGqD7HHUVHPSp0+uZca7j3A+3YwzcQ+YIUaVJulxRRQg=; 5:JWcwhtZhcBGtMIld1SOPFTgPIs8sg+hwjXVbDRdIyygDl7dzDPSXLLV7HgnQwaoCN9s1TX7VOAW5tU3R2MB3HDSNi6g5fmdlYI6nOy4chy61iZUU4DCZe7KRkxPvfmNchw+p74y/z8SlA6iQ9MF9mQ==; 24:j4BCq6o1IEMAhqfaHhWSj/ZrcQ5sa0w7wPxpeUlJkkZ4JcEmsCSGkrsar3v4/TeiDIB9baFCIW5TSElldTLIq1hQb2HlvNUYc+8ik5lsboA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB1611; 7:dNbqU1TliCcn43QOVRGpo2SKf4mYsAJVbILRytzUHbGeq+6PbcGjJ8LFdAuERzbakToGld57ESAgMv9Z8b5zOlgQobODQzq+ZaRIlVTHP7FsIDsp6DAtaxqT7shQ2wAlZZA9PXeUSJb9a2svgeXWVj/YXotXFaK65kCezVTUGze5PGLQzwUmJ8ZXZsOcT1ItRclX+vZwOYQyW7cUp1o8j7PXcZlQGWj3yu69FTRgKd/Xexy6gqOl7QbkU+iPr00Eb2RzWzlPHyBQN+DDl48Kd0/on2Us+3fmCjhyUIjtDUhnepPwTB7t36hA44I11wJrx2Uc4VsglvQPabjKEZMHmg==; 20:64mpBG1WeJLOMunPSC4YwHg/IhkGqAAAmCvIoDSzXKdNrtmzGq/ljxUC3V9PRlP52Wk+b2B+FewkuNPvL098Q/Cm4c9vv3/ZBTfnqBkwl3J9GYKMHyGenHxNk5KbszdcGIFB6D7bU6gJWpP+ZEVwFlq5PXr4m2pmb1iiyW8vxUpIbg1N9f00RwATI2dOg3prlWUd50s0p/HuSJZqLasvA+3rmTonkeEKL1Sx/nboiouSFd6MAtePsYkXi2pj4vHS X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2017 15:16:34.9909 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1611 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP AMD Platform Security Processor (PSP) is a dedicated processor that provides the support for encrypting the guest memory in a Secure Encrypted Virtualiztion (SEV) mode, along with software-based Tursted Executation Environment (TEE) to enable the third-party tursted applications. Signed-off-by: Brijesh Singh --- drivers/crypto/ccp/Kconfig | 7 + drivers/crypto/ccp/Makefile | 1 drivers/crypto/ccp/psp-dev.c | 211 ++++++++++++++++++++++++++++++++++++++++++ drivers/crypto/ccp/psp-dev.h | 102 ++++++++++++++++++++ drivers/crypto/ccp/sp-dev.c | 16 +++ drivers/crypto/ccp/sp-dev.h | 34 +++++++ drivers/crypto/ccp/sp-pci.c | 4 + 7 files changed, 374 insertions(+), 1 deletion(-) create mode 100644 drivers/crypto/ccp/psp-dev.c create mode 100644 drivers/crypto/ccp/psp-dev.h diff --git a/drivers/crypto/ccp/Kconfig b/drivers/crypto/ccp/Kconfig index bc08f03..59c207e 100644 --- a/drivers/crypto/ccp/Kconfig +++ b/drivers/crypto/ccp/Kconfig @@ -34,4 +34,11 @@ config CRYPTO_DEV_CCP Provides the interface to use the AMD Cryptographic Coprocessor which can be used to offload encryption operations such as SHA, AES and more. + +config CRYPTO_DEV_PSP + bool "Platform Security Processor interface" + default y + help + Provide the interface for AMD Platform Security Processor (PSP) device. + endif diff --git a/drivers/crypto/ccp/Makefile b/drivers/crypto/ccp/Makefile index 8127e18..12e569d 100644 --- a/drivers/crypto/ccp/Makefile +++ b/drivers/crypto/ccp/Makefile @@ -6,6 +6,7 @@ ccp-$(CONFIG_CRYPTO_DEV_CCP) += ccp-dev.o \ ccp-dev-v3.o \ ccp-dev-v5.o \ ccp-dmaengine.o +ccp-$(CONFIG_CRYPTO_DEV_PSP) += psp-dev.o obj-$(CONFIG_CRYPTO_DEV_CCP_CRYPTO) += ccp-crypto.o ccp-crypto-objs := ccp-crypto-main.o \ diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c new file mode 100644 index 0000000..6f64aa7 --- /dev/null +++ b/drivers/crypto/ccp/psp-dev.c @@ -0,0 +1,211 @@ +/* + * AMD Platform Security Processor (PSP) interface + * + * Copyright (C) 2016 Advanced Micro Devices, Inc. + * + * Author: Brijesh Singh + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "sp-dev.h" +#include "psp-dev.h" + +static LIST_HEAD(psp_devs); +static DEFINE_SPINLOCK(psp_devs_lock); + +const struct psp_vdata psp_entry = { + .offset = 0x10500, +}; + +void psp_add_device(struct psp_device *psp) +{ + unsigned long flags; + + spin_lock_irqsave(&psp_devs_lock, flags); + + list_add_tail(&psp->entry, &psp_devs); + + spin_unlock_irqrestore(&psp_devs_lock, flags); +} + +void psp_del_device(struct psp_device *psp) +{ + unsigned long flags; + + spin_lock_irqsave(&psp_devs_lock, flags); + + list_del(&psp->entry); + spin_unlock_irqrestore(&psp_devs_lock, flags); +} + +static struct psp_device *psp_alloc_struct(struct sp_device *sp) +{ + struct device *dev = sp->dev; + struct psp_device *psp; + + psp = devm_kzalloc(dev, sizeof(*psp), GFP_KERNEL); + if (!psp) + return NULL; + + psp->dev = dev; + psp->sp = sp; + + snprintf(psp->name, sizeof(psp->name), "psp-%u", sp->ord); + + return psp; +} + +irqreturn_t psp_irq_handler(int irq, void *data) +{ + unsigned int status; + irqreturn_t ret = IRQ_HANDLED; + struct psp_device *psp = data; + + /* read the interrupt status */ + status = ioread32(psp->io_regs + PSP_P2CMSG_INTSTS); + + /* invoke subdevice interrupt handlers */ + if (status) { + if (psp->sev_irq_handler) + ret = psp->sev_irq_handler(irq, psp->sev_irq_data); + } + + /* clear the interrupt status */ + iowrite32(status, psp->io_regs + PSP_P2CMSG_INTSTS); + + return ret; +} + +static int psp_init(struct psp_device *psp) +{ + psp_add_device(psp); + + sev_dev_init(psp); + + return 0; +} + +int psp_dev_init(struct sp_device *sp) +{ + struct device *dev = sp->dev; + struct psp_device *psp; + int ret; + + ret = -ENOMEM; + psp = psp_alloc_struct(sp); + if (!psp) + goto e_err; + sp->psp_data = psp; + + psp->vdata = (struct psp_vdata *)sp->dev_data->psp_vdata; + if (!psp->vdata) { + ret = -ENODEV; + dev_err(dev, "missing driver data\n"); + goto e_err; + } + + psp->io_regs = sp->io_map + psp->vdata->offset; + + /* Disable and clear interrupts until ready */ + iowrite32(0, psp->io_regs + PSP_P2CMSG_INTEN); + iowrite32(0xffffffff, psp->io_regs + PSP_P2CMSG_INTSTS); + + dev_dbg(dev, "requesting an IRQ ...\n"); + /* Request an irq */ + ret = sp_request_psp_irq(psp->sp, psp_irq_handler, psp->name, psp); + if (ret) { + dev_err(dev, "psp: unable to allocate an IRQ\n"); + goto e_err; + } + + sp_set_psp_master(sp); + + dev_dbg(dev, "initializing psp\n"); + ret = psp_init(psp); + if (ret) { + dev_err(dev, "failed to init psp\n"); + goto e_irq; + } + + /* Enable interrupt */ + dev_dbg(dev, "Enabling interrupts ...\n"); + iowrite32(7, psp->io_regs + PSP_P2CMSG_INTEN); + + dev_notice(dev, "psp enabled\n"); + + return 0; + +e_irq: + sp_free_psp_irq(psp->sp, psp); +e_err: + sp->psp_data = NULL; + + dev_notice(dev, "psp initialization failed\n"); + + return ret; +} + +void psp_dev_destroy(struct sp_device *sp) +{ + struct psp_device *psp = sp->psp_data; + + sev_dev_destroy(psp); + + sp_free_psp_irq(sp, psp); + + psp_del_device(psp); +} + +int psp_dev_resume(struct sp_device *sp) +{ + sev_dev_resume(sp->psp_data); + return 0; +} + +int psp_dev_suspend(struct sp_device *sp, pm_message_t state) +{ + sev_dev_suspend(sp->psp_data, state); + return 0; +} + +int psp_request_sev_irq(struct psp_device *psp, irq_handler_t handler, + void *data) +{ + psp->sev_irq_data = data; + psp->sev_irq_handler = handler; + + return 0; +} + +int psp_free_sev_irq(struct psp_device *psp, void *data) +{ + if (psp->sev_irq_handler) { + psp->sev_irq_data = NULL; + psp->sev_irq_handler = NULL; + } + + return 0; +} + +struct psp_device *psp_get_master_device(void) +{ + struct sp_device *sp = sp_get_psp_master_device(); + + return sp ? sp->psp_data : NULL; +} diff --git a/drivers/crypto/ccp/psp-dev.h b/drivers/crypto/ccp/psp-dev.h new file mode 100644 index 0000000..bbd3d96 --- /dev/null +++ b/drivers/crypto/ccp/psp-dev.h @@ -0,0 +1,102 @@ +/* + * AMD Platform Security Processor (PSP) interface driver + * + * Copyright (C) 2016 Advanced Micro Devices, Inc. + * + * Author: Brijesh Singh + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __PSP_DEV_H__ +#define __PSP_DEV_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "sp-dev.h" + +#define PSP_P2CMSG_INTEN 0x0110 +#define PSP_P2CMSG_INTSTS 0x0114 + +#define PSP_C2PMSG_ATTR_0 0x0118 +#define PSP_C2PMSG_ATTR_1 0x011c +#define PSP_C2PMSG_ATTR_2 0x0120 +#define PSP_C2PMSG_ATTR_3 0x0124 +#define PSP_P2CMSG_ATTR_0 0x0128 + +#define PSP_CMDRESP_CMD_SHIFT 16 +#define PSP_CMDRESP_IOC BIT(0) +#define PSP_CMDRESP_RESP BIT(31) +#define PSP_CMDRESP_ERR_MASK 0xffff + +#define MAX_PSP_NAME_LEN 16 + +struct psp_device { + struct list_head entry; + + struct psp_vdata *vdata; + char name[MAX_PSP_NAME_LEN]; + + struct device *dev; + struct sp_device *sp; + + void __iomem *io_regs; + + irq_handler_t sev_irq_handler; + void *sev_irq_data; + + void *sev_data; +}; + +void psp_add_device(struct psp_device *psp); +void psp_del_device(struct psp_device *psp); + +int psp_request_sev_irq(struct psp_device *psp, irq_handler_t handler, + void *data); +int psp_free_sev_irq(struct psp_device *psp, void *data); + +struct psp_device *psp_get_master_device(void); + +#ifdef CONFIG_AMD_SEV + +int sev_dev_init(struct psp_device *psp); +void sev_dev_destroy(struct psp_device *psp); +int sev_dev_resume(struct psp_device *psp); +int sev_dev_suspend(struct psp_device *psp, pm_message_t state); + +#else + +static inline int sev_dev_init(struct psp_device *psp) +{ + return -ENODEV; +} + +static inline void sev_dev_destroy(struct psp_device *psp) { } + +static inline int sev_dev_resume(struct psp_device *psp) +{ + return -ENODEV; +} + +static inline int sev_dev_suspend(struct psp_device *psp, pm_message_t state) +{ + return -ENODEV; +} + +#endif /* __AMD_SEV_H */ + +#endif /* __PSP_DEV_H */ + diff --git a/drivers/crypto/ccp/sp-dev.c b/drivers/crypto/ccp/sp-dev.c index e47fb8e..975a435 100644 --- a/drivers/crypto/ccp/sp-dev.c +++ b/drivers/crypto/ccp/sp-dev.c @@ -212,6 +212,8 @@ int sp_init(struct sp_device *sp) if (sp->dev_data->ccp_vdata) ccp_dev_init(sp); + if (sp->dev_data->psp_vdata) + psp_dev_init(sp); return 0; } @@ -220,6 +222,9 @@ void sp_destroy(struct sp_device *sp) if (sp->dev_data->ccp_vdata) ccp_dev_destroy(sp); + if (sp->dev_data->psp_vdata) + psp_dev_destroy(sp); + sp_del_device(sp); } @@ -233,6 +238,12 @@ int sp_suspend(struct sp_device *sp, pm_message_t state) return ret; } + if (sp->dev_data->psp_vdata) { + ret = psp_dev_suspend(sp, state); + if (ret) + return ret; + } + return 0; } @@ -246,6 +257,11 @@ int sp_resume(struct sp_device *sp) return ret; } + if (sp->dev_data->psp_vdata) { + ret = psp_dev_resume(sp); + if (ret) + return ret; + } return 0; } diff --git a/drivers/crypto/ccp/sp-dev.h b/drivers/crypto/ccp/sp-dev.h index 9a8a8f8..aeff7a0 100644 --- a/drivers/crypto/ccp/sp-dev.h +++ b/drivers/crypto/ccp/sp-dev.h @@ -40,12 +40,18 @@ struct ccp_vdata { const unsigned int offset; }; +struct psp_vdata { + const unsigned int version; + const struct psp_actions *perform; + const unsigned int offset; +}; + /* Structure to hold SP device data */ struct sp_dev_data { const unsigned int bar; const struct ccp_vdata *ccp_vdata; - const void *psp_vdata; + const struct psp_vdata *psp_vdata; }; struct sp_device { @@ -137,4 +143,30 @@ static inline int ccp_dev_resume(struct sp_device *sp) #endif /* CONFIG_CRYPTO_DEV_CCP */ +#ifdef CONFIG_CRYPTO_DEV_PSP + +int psp_dev_init(struct sp_device *sp); +void psp_dev_destroy(struct sp_device *sp); + +int psp_dev_suspend(struct sp_device *sp, pm_message_t state); +int psp_dev_resume(struct sp_device *sp); +#else /* !CONFIG_CRYPTO_DEV_CCP */ + +static inline int psp_dev_init(struct sp_device *sp) +{ + return 0; +} +static inline void psp_dev_destroy(struct sp_device *sp) { } + +static inline int psp_dev_suspend(struct sp_device *sp, pm_message_t state) +{ + return 0; +} +static inline int psp_dev_resume(struct sp_device *sp) +{ + return 0; +} + +#endif /* CONFIG_CRYPTO_DEV_CCP */ + #endif diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c index 0960e2d..4999662 100644 --- a/drivers/crypto/ccp/sp-pci.c +++ b/drivers/crypto/ccp/sp-pci.c @@ -271,6 +271,7 @@ static int sp_pci_resume(struct pci_dev *pdev) extern struct ccp_vdata ccpv3_pci; extern struct ccp_vdata ccpv5a; extern struct ccp_vdata ccpv5b; +extern struct psp_vdata psp_entry; static const struct sp_dev_data dev_data[] = { { @@ -284,6 +285,9 @@ static const struct sp_dev_data dev_data[] = { #ifdef CONFIG_CRYPTO_DEV_CCP .ccp_vdata = &ccpv5a, #endif +#ifdef CONFIG_CRYPTO_DEV_PSP + .psp_vdata = &psp_entry +#endif }, { .bar = 2,