1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2d0ebbc0cSBrijesh Singh /* 3d0ebbc0cSBrijesh Singh * AMD Secure Processor device driver 4d0ebbc0cSBrijesh Singh * 533960accSRijo Thomas * Copyright (C) 2013,2019 Advanced Micro Devices, Inc. 6d0ebbc0cSBrijesh Singh * 7d0ebbc0cSBrijesh Singh * Author: Tom Lendacky <thomas.lendacky@amd.com> 8d0ebbc0cSBrijesh Singh * Author: Gary R Hook <gary.hook@amd.com> 9d0ebbc0cSBrijesh Singh */ 10d0ebbc0cSBrijesh Singh 11d0ebbc0cSBrijesh Singh #include <linux/module.h> 12d0ebbc0cSBrijesh Singh #include <linux/kernel.h> 13d0ebbc0cSBrijesh Singh #include <linux/device.h> 14d0ebbc0cSBrijesh Singh #include <linux/pci.h> 15d0ebbc0cSBrijesh Singh #include <linux/pci_ids.h> 16d0ebbc0cSBrijesh Singh #include <linux/dma-mapping.h> 17d0ebbc0cSBrijesh Singh #include <linux/kthread.h> 18d0ebbc0cSBrijesh Singh #include <linux/sched.h> 19d0ebbc0cSBrijesh Singh #include <linux/interrupt.h> 20d0ebbc0cSBrijesh Singh #include <linux/spinlock.h> 21d0ebbc0cSBrijesh Singh #include <linux/delay.h> 22d0ebbc0cSBrijesh Singh #include <linux/ccp.h> 23d0ebbc0cSBrijesh Singh 24d0ebbc0cSBrijesh Singh #include "ccp-dev.h" 25b93566f1SRijo Thomas #include "psp-dev.h" 26d0ebbc0cSBrijesh Singh 27d0ebbc0cSBrijesh Singh #define MSIX_VECTORS 2 28d0ebbc0cSBrijesh Singh 29d0ebbc0cSBrijesh Singh struct sp_pci { 30d0ebbc0cSBrijesh Singh int msix_count; 31d0ebbc0cSBrijesh Singh struct msix_entry msix_entry[MSIX_VECTORS]; 32d0ebbc0cSBrijesh Singh }; 332a6170dfSBrijesh Singh static struct sp_device *sp_dev_master; 34d0ebbc0cSBrijesh Singh 3550c4deccSMario Limonciello #define attribute_show(name, def) \ 3650c4deccSMario Limonciello static ssize_t name##_show(struct device *d, struct device_attribute *attr, \ 3750c4deccSMario Limonciello char *buf) \ 3850c4deccSMario Limonciello { \ 3950c4deccSMario Limonciello struct sp_device *sp = dev_get_drvdata(d); \ 4050c4deccSMario Limonciello struct psp_device *psp = sp->psp_data; \ 4150c4deccSMario Limonciello int bit = PSP_SECURITY_##def << PSP_CAPABILITY_PSP_SECURITY_OFFSET; \ 4250c4deccSMario Limonciello return sysfs_emit(buf, "%d\n", (psp->capability & bit) > 0); \ 4350c4deccSMario Limonciello } 4450c4deccSMario Limonciello 4550c4deccSMario Limonciello attribute_show(fused_part, FUSED_PART) 4650c4deccSMario Limonciello static DEVICE_ATTR_RO(fused_part); 4750c4deccSMario Limonciello attribute_show(debug_lock_on, DEBUG_LOCK_ON) 4850c4deccSMario Limonciello static DEVICE_ATTR_RO(debug_lock_on); 4950c4deccSMario Limonciello attribute_show(tsme_status, TSME_STATUS) 5050c4deccSMario Limonciello static DEVICE_ATTR_RO(tsme_status); 5150c4deccSMario Limonciello attribute_show(anti_rollback_status, ANTI_ROLLBACK_STATUS) 5250c4deccSMario Limonciello static DEVICE_ATTR_RO(anti_rollback_status); 5350c4deccSMario Limonciello attribute_show(rpmc_production_enabled, RPMC_PRODUCTION_ENABLED) 5450c4deccSMario Limonciello static DEVICE_ATTR_RO(rpmc_production_enabled); 5550c4deccSMario Limonciello attribute_show(rpmc_spirom_available, RPMC_SPIROM_AVAILABLE) 5650c4deccSMario Limonciello static DEVICE_ATTR_RO(rpmc_spirom_available); 5750c4deccSMario Limonciello attribute_show(hsp_tpm_available, HSP_TPM_AVAILABLE) 5850c4deccSMario Limonciello static DEVICE_ATTR_RO(hsp_tpm_available); 5950c4deccSMario Limonciello attribute_show(rom_armor_enforced, ROM_ARMOR_ENFORCED) 6050c4deccSMario Limonciello static DEVICE_ATTR_RO(rom_armor_enforced); 6150c4deccSMario Limonciello 6250c4deccSMario Limonciello static struct attribute *psp_attrs[] = { 6350c4deccSMario Limonciello &dev_attr_fused_part.attr, 6450c4deccSMario Limonciello &dev_attr_debug_lock_on.attr, 6550c4deccSMario Limonciello &dev_attr_tsme_status.attr, 6650c4deccSMario Limonciello &dev_attr_anti_rollback_status.attr, 6750c4deccSMario Limonciello &dev_attr_rpmc_production_enabled.attr, 6850c4deccSMario Limonciello &dev_attr_rpmc_spirom_available.attr, 6950c4deccSMario Limonciello &dev_attr_hsp_tpm_available.attr, 7050c4deccSMario Limonciello &dev_attr_rom_armor_enforced.attr, 7150c4deccSMario Limonciello NULL 7250c4deccSMario Limonciello }; 7350c4deccSMario Limonciello 7450c4deccSMario Limonciello static umode_t psp_security_is_visible(struct kobject *kobj, struct attribute *attr, int idx) 7550c4deccSMario Limonciello { 7650c4deccSMario Limonciello struct device *dev = kobj_to_dev(kobj); 7750c4deccSMario Limonciello struct sp_device *sp = dev_get_drvdata(dev); 7850c4deccSMario Limonciello struct psp_device *psp = sp->psp_data; 7950c4deccSMario Limonciello 8050c4deccSMario Limonciello if (psp && (psp->capability & PSP_CAPABILITY_PSP_SECURITY_REPORTING)) 8150c4deccSMario Limonciello return 0444; 8250c4deccSMario Limonciello 8350c4deccSMario Limonciello return 0; 8450c4deccSMario Limonciello } 8550c4deccSMario Limonciello 8650c4deccSMario Limonciello static struct attribute_group psp_attr_group = { 8750c4deccSMario Limonciello .attrs = psp_attrs, 8850c4deccSMario Limonciello .is_visible = psp_security_is_visible, 8950c4deccSMario Limonciello }; 9050c4deccSMario Limonciello 9150c4deccSMario Limonciello static const struct attribute_group *psp_groups[] = { 9250c4deccSMario Limonciello &psp_attr_group, 9350c4deccSMario Limonciello NULL, 9450c4deccSMario Limonciello }; 9550c4deccSMario Limonciello 96d0ebbc0cSBrijesh Singh static int sp_get_msix_irqs(struct sp_device *sp) 97d0ebbc0cSBrijesh Singh { 98d0ebbc0cSBrijesh Singh struct sp_pci *sp_pci = sp->dev_specific; 99d0ebbc0cSBrijesh Singh struct device *dev = sp->dev; 100d0ebbc0cSBrijesh Singh struct pci_dev *pdev = to_pci_dev(dev); 101d0ebbc0cSBrijesh Singh int v, ret; 102d0ebbc0cSBrijesh Singh 103d0ebbc0cSBrijesh Singh for (v = 0; v < ARRAY_SIZE(sp_pci->msix_entry); v++) 104d0ebbc0cSBrijesh Singh sp_pci->msix_entry[v].entry = v; 105d0ebbc0cSBrijesh Singh 106d0ebbc0cSBrijesh Singh ret = pci_enable_msix_range(pdev, sp_pci->msix_entry, 1, v); 107d0ebbc0cSBrijesh Singh if (ret < 0) 108d0ebbc0cSBrijesh Singh return ret; 109d0ebbc0cSBrijesh Singh 110d0ebbc0cSBrijesh Singh sp_pci->msix_count = ret; 111d0ebbc0cSBrijesh Singh sp->use_tasklet = true; 112d0ebbc0cSBrijesh Singh 113d0ebbc0cSBrijesh Singh sp->psp_irq = sp_pci->msix_entry[0].vector; 114d0ebbc0cSBrijesh Singh sp->ccp_irq = (sp_pci->msix_count > 1) ? sp_pci->msix_entry[1].vector 115d0ebbc0cSBrijesh Singh : sp_pci->msix_entry[0].vector; 116d0ebbc0cSBrijesh Singh return 0; 117d0ebbc0cSBrijesh Singh } 118d0ebbc0cSBrijesh Singh 119d0ebbc0cSBrijesh Singh static int sp_get_msi_irq(struct sp_device *sp) 120d0ebbc0cSBrijesh Singh { 121d0ebbc0cSBrijesh Singh struct device *dev = sp->dev; 122d0ebbc0cSBrijesh Singh struct pci_dev *pdev = to_pci_dev(dev); 123d0ebbc0cSBrijesh Singh int ret; 124d0ebbc0cSBrijesh Singh 125d0ebbc0cSBrijesh Singh ret = pci_enable_msi(pdev); 126d0ebbc0cSBrijesh Singh if (ret) 127d0ebbc0cSBrijesh Singh return ret; 128d0ebbc0cSBrijesh Singh 129d0ebbc0cSBrijesh Singh sp->ccp_irq = pdev->irq; 130d0ebbc0cSBrijesh Singh sp->psp_irq = pdev->irq; 131d0ebbc0cSBrijesh Singh 132d0ebbc0cSBrijesh Singh return 0; 133d0ebbc0cSBrijesh Singh } 134d0ebbc0cSBrijesh Singh 135d0ebbc0cSBrijesh Singh static int sp_get_irqs(struct sp_device *sp) 136d0ebbc0cSBrijesh Singh { 137d0ebbc0cSBrijesh Singh struct device *dev = sp->dev; 138d0ebbc0cSBrijesh Singh int ret; 139d0ebbc0cSBrijesh Singh 140d0ebbc0cSBrijesh Singh ret = sp_get_msix_irqs(sp); 141d0ebbc0cSBrijesh Singh if (!ret) 142d0ebbc0cSBrijesh Singh return 0; 143d0ebbc0cSBrijesh Singh 144d0ebbc0cSBrijesh Singh /* Couldn't get MSI-X vectors, try MSI */ 145d0ebbc0cSBrijesh Singh dev_notice(dev, "could not enable MSI-X (%d), trying MSI\n", ret); 146d0ebbc0cSBrijesh Singh ret = sp_get_msi_irq(sp); 147d0ebbc0cSBrijesh Singh if (!ret) 148d0ebbc0cSBrijesh Singh return 0; 149d0ebbc0cSBrijesh Singh 150d0ebbc0cSBrijesh Singh /* Couldn't get MSI interrupt */ 151d0ebbc0cSBrijesh Singh dev_notice(dev, "could not enable MSI (%d)\n", ret); 152d0ebbc0cSBrijesh Singh 153d0ebbc0cSBrijesh Singh return ret; 154d0ebbc0cSBrijesh Singh } 155d0ebbc0cSBrijesh Singh 156d0ebbc0cSBrijesh Singh static void sp_free_irqs(struct sp_device *sp) 157d0ebbc0cSBrijesh Singh { 158d0ebbc0cSBrijesh Singh struct sp_pci *sp_pci = sp->dev_specific; 159d0ebbc0cSBrijesh Singh struct device *dev = sp->dev; 160d0ebbc0cSBrijesh Singh struct pci_dev *pdev = to_pci_dev(dev); 161d0ebbc0cSBrijesh Singh 162d0ebbc0cSBrijesh Singh if (sp_pci->msix_count) 163d0ebbc0cSBrijesh Singh pci_disable_msix(pdev); 164d0ebbc0cSBrijesh Singh else if (sp->psp_irq) 165d0ebbc0cSBrijesh Singh pci_disable_msi(pdev); 166d0ebbc0cSBrijesh Singh 167d0ebbc0cSBrijesh Singh sp->ccp_irq = 0; 168d0ebbc0cSBrijesh Singh sp->psp_irq = 0; 169d0ebbc0cSBrijesh Singh } 170d0ebbc0cSBrijesh Singh 1712a6170dfSBrijesh Singh static bool sp_pci_is_master(struct sp_device *sp) 1722a6170dfSBrijesh Singh { 1732a6170dfSBrijesh Singh struct device *dev_cur, *dev_new; 1742a6170dfSBrijesh Singh struct pci_dev *pdev_cur, *pdev_new; 1752a6170dfSBrijesh Singh 1762a6170dfSBrijesh Singh dev_new = sp->dev; 1772a6170dfSBrijesh Singh dev_cur = sp_dev_master->dev; 1782a6170dfSBrijesh Singh 1792a6170dfSBrijesh Singh pdev_new = to_pci_dev(dev_new); 1802a6170dfSBrijesh Singh pdev_cur = to_pci_dev(dev_cur); 1812a6170dfSBrijesh Singh 1822a6170dfSBrijesh Singh if (pdev_new->bus->number < pdev_cur->bus->number) 1832a6170dfSBrijesh Singh return true; 1842a6170dfSBrijesh Singh 1852a6170dfSBrijesh Singh if (PCI_SLOT(pdev_new->devfn) < PCI_SLOT(pdev_cur->devfn)) 1862a6170dfSBrijesh Singh return true; 1872a6170dfSBrijesh Singh 1882a6170dfSBrijesh Singh if (PCI_FUNC(pdev_new->devfn) < PCI_FUNC(pdev_cur->devfn)) 1892a6170dfSBrijesh Singh return true; 1902a6170dfSBrijesh Singh 1912a6170dfSBrijesh Singh return false; 1922a6170dfSBrijesh Singh } 1932a6170dfSBrijesh Singh 1942a6170dfSBrijesh Singh static void psp_set_master(struct sp_device *sp) 1952a6170dfSBrijesh Singh { 1962a6170dfSBrijesh Singh if (!sp_dev_master) { 1972a6170dfSBrijesh Singh sp_dev_master = sp; 1982a6170dfSBrijesh Singh return; 1992a6170dfSBrijesh Singh } 2002a6170dfSBrijesh Singh 2012a6170dfSBrijesh Singh if (sp_pci_is_master(sp)) 2022a6170dfSBrijesh Singh sp_dev_master = sp; 2032a6170dfSBrijesh Singh } 2042a6170dfSBrijesh Singh 2052a6170dfSBrijesh Singh static struct sp_device *psp_get_master(void) 2062a6170dfSBrijesh Singh { 2072a6170dfSBrijesh Singh return sp_dev_master; 2082a6170dfSBrijesh Singh } 2092a6170dfSBrijesh Singh 21015f7a4c6SJohn Allen static void psp_clear_master(struct sp_device *sp) 21115f7a4c6SJohn Allen { 21215f7a4c6SJohn Allen if (sp == sp_dev_master) { 21315f7a4c6SJohn Allen sp_dev_master = NULL; 21415f7a4c6SJohn Allen dev_dbg(sp->dev, "Cleared sp_dev_master\n"); 21515f7a4c6SJohn Allen } 21615f7a4c6SJohn Allen } 21715f7a4c6SJohn Allen 218d0ebbc0cSBrijesh Singh static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) 219d0ebbc0cSBrijesh Singh { 220d0ebbc0cSBrijesh Singh struct sp_device *sp; 221d0ebbc0cSBrijesh Singh struct sp_pci *sp_pci; 222d0ebbc0cSBrijesh Singh struct device *dev = &pdev->dev; 223d0ebbc0cSBrijesh Singh void __iomem * const *iomap_table; 224d0ebbc0cSBrijesh Singh int bar_mask; 225d0ebbc0cSBrijesh Singh int ret; 226d0ebbc0cSBrijesh Singh 227d0ebbc0cSBrijesh Singh ret = -ENOMEM; 228d0ebbc0cSBrijesh Singh sp = sp_alloc_struct(dev); 229d0ebbc0cSBrijesh Singh if (!sp) 230d0ebbc0cSBrijesh Singh goto e_err; 231d0ebbc0cSBrijesh Singh 232d0ebbc0cSBrijesh Singh sp_pci = devm_kzalloc(dev, sizeof(*sp_pci), GFP_KERNEL); 233d0ebbc0cSBrijesh Singh if (!sp_pci) 234d0ebbc0cSBrijesh Singh goto e_err; 235d0ebbc0cSBrijesh Singh 236d0ebbc0cSBrijesh Singh sp->dev_specific = sp_pci; 237d0ebbc0cSBrijesh Singh sp->dev_vdata = (struct sp_dev_vdata *)id->driver_data; 238d0ebbc0cSBrijesh Singh if (!sp->dev_vdata) { 239d0ebbc0cSBrijesh Singh ret = -ENODEV; 240d0ebbc0cSBrijesh Singh dev_err(dev, "missing driver data\n"); 241d0ebbc0cSBrijesh Singh goto e_err; 242d0ebbc0cSBrijesh Singh } 243d0ebbc0cSBrijesh Singh 244d0ebbc0cSBrijesh Singh ret = pcim_enable_device(pdev); 245d0ebbc0cSBrijesh Singh if (ret) { 246d0ebbc0cSBrijesh Singh dev_err(dev, "pcim_enable_device failed (%d)\n", ret); 247d0ebbc0cSBrijesh Singh goto e_err; 248d0ebbc0cSBrijesh Singh } 249d0ebbc0cSBrijesh Singh 250d0ebbc0cSBrijesh Singh bar_mask = pci_select_bars(pdev, IORESOURCE_MEM); 251d0ebbc0cSBrijesh Singh ret = pcim_iomap_regions(pdev, bar_mask, "ccp"); 252d0ebbc0cSBrijesh Singh if (ret) { 253d0ebbc0cSBrijesh Singh dev_err(dev, "pcim_iomap_regions failed (%d)\n", ret); 254d0ebbc0cSBrijesh Singh goto e_err; 255d0ebbc0cSBrijesh Singh } 256d0ebbc0cSBrijesh Singh 257d0ebbc0cSBrijesh Singh iomap_table = pcim_iomap_table(pdev); 258d0ebbc0cSBrijesh Singh if (!iomap_table) { 259d0ebbc0cSBrijesh Singh dev_err(dev, "pcim_iomap_table failed\n"); 260d0ebbc0cSBrijesh Singh ret = -ENOMEM; 261d0ebbc0cSBrijesh Singh goto e_err; 262d0ebbc0cSBrijesh Singh } 263d0ebbc0cSBrijesh Singh 264d0ebbc0cSBrijesh Singh sp->io_map = iomap_table[sp->dev_vdata->bar]; 265d0ebbc0cSBrijesh Singh if (!sp->io_map) { 266d0ebbc0cSBrijesh Singh dev_err(dev, "ioremap failed\n"); 267d0ebbc0cSBrijesh Singh ret = -ENOMEM; 268d0ebbc0cSBrijesh Singh goto e_err; 269d0ebbc0cSBrijesh Singh } 270d0ebbc0cSBrijesh Singh 271d0ebbc0cSBrijesh Singh ret = sp_get_irqs(sp); 272d0ebbc0cSBrijesh Singh if (ret) 273d0ebbc0cSBrijesh Singh goto e_err; 274d0ebbc0cSBrijesh Singh 275d0ebbc0cSBrijesh Singh pci_set_master(pdev); 2762a6170dfSBrijesh Singh sp->set_psp_master_device = psp_set_master; 2772a6170dfSBrijesh Singh sp->get_psp_master_device = psp_get_master; 27815f7a4c6SJohn Allen sp->clear_psp_master_device = psp_clear_master; 279d0ebbc0cSBrijesh Singh 280d0ebbc0cSBrijesh Singh ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48)); 281d0ebbc0cSBrijesh Singh if (ret) { 282d0ebbc0cSBrijesh Singh ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); 283d0ebbc0cSBrijesh Singh if (ret) { 284d0ebbc0cSBrijesh Singh dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n", 285d0ebbc0cSBrijesh Singh ret); 286a6f8e68eSChristophe JAILLET goto free_irqs; 287d0ebbc0cSBrijesh Singh } 288d0ebbc0cSBrijesh Singh } 289d0ebbc0cSBrijesh Singh 290d0ebbc0cSBrijesh Singh dev_set_drvdata(dev, sp); 291d0ebbc0cSBrijesh Singh 292d0ebbc0cSBrijesh Singh ret = sp_init(sp); 293d0ebbc0cSBrijesh Singh if (ret) 294a6f8e68eSChristophe JAILLET goto free_irqs; 295d0ebbc0cSBrijesh Singh 296d0ebbc0cSBrijesh Singh return 0; 297d0ebbc0cSBrijesh Singh 298a6f8e68eSChristophe JAILLET free_irqs: 299a6f8e68eSChristophe JAILLET sp_free_irqs(sp); 300d0ebbc0cSBrijesh Singh e_err: 301d0ebbc0cSBrijesh Singh dev_notice(dev, "initialization failed\n"); 302d0ebbc0cSBrijesh Singh return ret; 303d0ebbc0cSBrijesh Singh } 304d0ebbc0cSBrijesh Singh 3055441a07aSBrijesh Singh static void sp_pci_shutdown(struct pci_dev *pdev) 3065441a07aSBrijesh Singh { 3075441a07aSBrijesh Singh struct device *dev = &pdev->dev; 3085441a07aSBrijesh Singh struct sp_device *sp = dev_get_drvdata(dev); 3095441a07aSBrijesh Singh 3105441a07aSBrijesh Singh if (!sp) 3115441a07aSBrijesh Singh return; 3125441a07aSBrijesh Singh 3135441a07aSBrijesh Singh sp_destroy(sp); 3145441a07aSBrijesh Singh } 3155441a07aSBrijesh Singh 316d0ebbc0cSBrijesh Singh static void sp_pci_remove(struct pci_dev *pdev) 317d0ebbc0cSBrijesh Singh { 318d0ebbc0cSBrijesh Singh struct device *dev = &pdev->dev; 319d0ebbc0cSBrijesh Singh struct sp_device *sp = dev_get_drvdata(dev); 320d0ebbc0cSBrijesh Singh 321d0ebbc0cSBrijesh Singh if (!sp) 322d0ebbc0cSBrijesh Singh return; 323d0ebbc0cSBrijesh Singh 324d0ebbc0cSBrijesh Singh sp_destroy(sp); 325d0ebbc0cSBrijesh Singh 326d0ebbc0cSBrijesh Singh sp_free_irqs(sp); 327d0ebbc0cSBrijesh Singh } 328d0ebbc0cSBrijesh Singh 329f892a21fSVaibhav Gupta static int __maybe_unused sp_pci_suspend(struct device *dev) 330d0ebbc0cSBrijesh Singh { 331d0ebbc0cSBrijesh Singh struct sp_device *sp = dev_get_drvdata(dev); 332d0ebbc0cSBrijesh Singh 333f892a21fSVaibhav Gupta return sp_suspend(sp); 334d0ebbc0cSBrijesh Singh } 335d0ebbc0cSBrijesh Singh 336f892a21fSVaibhav Gupta static int __maybe_unused sp_pci_resume(struct device *dev) 337d0ebbc0cSBrijesh Singh { 338d0ebbc0cSBrijesh Singh struct sp_device *sp = dev_get_drvdata(dev); 339d0ebbc0cSBrijesh Singh 340d0ebbc0cSBrijesh Singh return sp_resume(sp); 341d0ebbc0cSBrijesh Singh } 342d0ebbc0cSBrijesh Singh 3432a6170dfSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_PSP 3446eb0cc72SRijo Thomas static const struct sev_vdata sevv1 = { 345675c3919STom Lendacky .cmdresp_reg = 0x10580, /* C2PMSG_32 */ 346675c3919STom Lendacky .cmdbuff_addr_lo_reg = 0x105e0, /* C2PMSG_56 */ 347675c3919STom Lendacky .cmdbuff_addr_hi_reg = 0x105e4, /* C2PMSG_57 */ 3486eb0cc72SRijo Thomas }; 3496eb0cc72SRijo Thomas 3506eb0cc72SRijo Thomas static const struct sev_vdata sevv2 = { 351675c3919STom Lendacky .cmdresp_reg = 0x10980, /* C2PMSG_32 */ 352675c3919STom Lendacky .cmdbuff_addr_lo_reg = 0x109e0, /* C2PMSG_56 */ 353675c3919STom Lendacky .cmdbuff_addr_hi_reg = 0x109e4, /* C2PMSG_57 */ 3546eb0cc72SRijo Thomas }; 3556eb0cc72SRijo Thomas 35633960accSRijo Thomas static const struct tee_vdata teev1 = { 357675c3919STom Lendacky .cmdresp_reg = 0x10544, /* C2PMSG_17 */ 358675c3919STom Lendacky .cmdbuff_addr_lo_reg = 0x10548, /* C2PMSG_18 */ 359675c3919STom Lendacky .cmdbuff_addr_hi_reg = 0x1054c, /* C2PMSG_19 */ 360675c3919STom Lendacky .ring_wptr_reg = 0x10550, /* C2PMSG_20 */ 361675c3919STom Lendacky .ring_rptr_reg = 0x10554, /* C2PMSG_21 */ 36233960accSRijo Thomas }; 36333960accSRijo Thomas 364*4aa0931bSMario Limonciello static const struct tee_vdata teev2 = { 365*4aa0931bSMario Limonciello .cmdresp_reg = 0x10944, /* C2PMSG_17 */ 366*4aa0931bSMario Limonciello .cmdbuff_addr_lo_reg = 0x10948, /* C2PMSG_18 */ 367*4aa0931bSMario Limonciello .cmdbuff_addr_hi_reg = 0x1094c, /* C2PMSG_19 */ 368*4aa0931bSMario Limonciello .ring_wptr_reg = 0x10950, /* C2PMSG_20 */ 369*4aa0931bSMario Limonciello .ring_rptr_reg = 0x10954, /* C2PMSG_21 */ 370*4aa0931bSMario Limonciello }; 371*4aa0931bSMario Limonciello 37222351239SMario Limonciello static const struct platform_access_vdata pa_v1 = { 37322351239SMario Limonciello .cmdresp_reg = 0x10570, /* C2PMSG_28 */ 37422351239SMario Limonciello .cmdbuff_addr_lo_reg = 0x10574, /* C2PMSG_29 */ 37522351239SMario Limonciello .cmdbuff_addr_hi_reg = 0x10578, /* C2PMSG_30 */ 376d5812571SMario Limonciello .doorbell_button_reg = 0x10a24, /* C2PMSG_73 */ 377d5812571SMario Limonciello .doorbell_cmd_reg = 0x10a40, /* C2PMSG_80 */ 37822351239SMario Limonciello }; 37922351239SMario Limonciello 380*4aa0931bSMario Limonciello static const struct platform_access_vdata pa_v2 = { 381*4aa0931bSMario Limonciello .doorbell_button_reg = 0x10a24, /* C2PMSG_73 */ 382*4aa0931bSMario Limonciello .doorbell_cmd_reg = 0x10a40, /* C2PMSG_80 */ 383*4aa0931bSMario Limonciello }; 384*4aa0931bSMario Limonciello 3856eb0cc72SRijo Thomas static const struct psp_vdata pspv1 = { 3866eb0cc72SRijo Thomas .sev = &sevv1, 387675c3919STom Lendacky .feature_reg = 0x105fc, /* C2PMSG_63 */ 388675c3919STom Lendacky .inten_reg = 0x10610, /* P2CMSG_INTEN */ 389675c3919STom Lendacky .intsts_reg = 0x10614, /* P2CMSG_INTSTS */ 3902a6170dfSBrijesh Singh }; 391dcbc0c6eSTom Lendacky 392dcbc0c6eSTom Lendacky static const struct psp_vdata pspv2 = { 3936eb0cc72SRijo Thomas .sev = &sevv2, 394675c3919STom Lendacky .feature_reg = 0x109fc, /* C2PMSG_63 */ 395675c3919STom Lendacky .inten_reg = 0x10690, /* P2CMSG_INTEN */ 396675c3919STom Lendacky .intsts_reg = 0x10694, /* P2CMSG_INTSTS */ 397dcbc0c6eSTom Lendacky }; 39833960accSRijo Thomas 39933960accSRijo Thomas static const struct psp_vdata pspv3 = { 40033960accSRijo Thomas .tee = &teev1, 40122351239SMario Limonciello .platform_access = &pa_v1, 402675c3919STom Lendacky .feature_reg = 0x109fc, /* C2PMSG_63 */ 403675c3919STom Lendacky .inten_reg = 0x10690, /* P2CMSG_INTEN */ 404675c3919STom Lendacky .intsts_reg = 0x10694, /* P2CMSG_INTSTS */ 40533960accSRijo Thomas }; 40610da230aSMario Limonciello 40710da230aSMario Limonciello static const struct psp_vdata pspv4 = { 40810da230aSMario Limonciello .sev = &sevv2, 40910da230aSMario Limonciello .tee = &teev1, 410675c3919STom Lendacky .feature_reg = 0x109fc, /* C2PMSG_63 */ 411675c3919STom Lendacky .inten_reg = 0x10690, /* P2CMSG_INTEN */ 412675c3919STom Lendacky .intsts_reg = 0x10694, /* P2CMSG_INTSTS */ 41310da230aSMario Limonciello }; 41410da230aSMario Limonciello 415*4aa0931bSMario Limonciello static const struct psp_vdata pspv5 = { 416*4aa0931bSMario Limonciello .tee = &teev2, 417*4aa0931bSMario Limonciello .platform_access = &pa_v2, 418*4aa0931bSMario Limonciello .feature_reg = 0x109fc, /* C2PMSG_63 */ 419*4aa0931bSMario Limonciello .inten_reg = 0x10510, /* P2CMSG_INTEN */ 420*4aa0931bSMario Limonciello .intsts_reg = 0x10514, /* P2CMSG_INTSTS */ 421*4aa0931bSMario Limonciello }; 422*4aa0931bSMario Limonciello 4232a6170dfSBrijesh Singh #endif 4242a6170dfSBrijesh Singh 425d0ebbc0cSBrijesh Singh static const struct sp_dev_vdata dev_vdata[] = { 426dcbc0c6eSTom Lendacky { /* 0 */ 427d0ebbc0cSBrijesh Singh .bar = 2, 428d0ebbc0cSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_CCP 429d0ebbc0cSBrijesh Singh .ccp_vdata = &ccpv3, 430d0ebbc0cSBrijesh Singh #endif 431d0ebbc0cSBrijesh Singh }, 432dcbc0c6eSTom Lendacky { /* 1 */ 433d0ebbc0cSBrijesh Singh .bar = 2, 434d0ebbc0cSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_CCP 435d0ebbc0cSBrijesh Singh .ccp_vdata = &ccpv5a, 436d0ebbc0cSBrijesh Singh #endif 4372a6170dfSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_PSP 438dcbc0c6eSTom Lendacky .psp_vdata = &pspv1, 4392a6170dfSBrijesh Singh #endif 440d0ebbc0cSBrijesh Singh }, 441dcbc0c6eSTom Lendacky { /* 2 */ 442d0ebbc0cSBrijesh Singh .bar = 2, 443d0ebbc0cSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_CCP 444d0ebbc0cSBrijesh Singh .ccp_vdata = &ccpv5b, 445d0ebbc0cSBrijesh Singh #endif 446d0ebbc0cSBrijesh Singh }, 447dcbc0c6eSTom Lendacky { /* 3 */ 448dcbc0c6eSTom Lendacky .bar = 2, 449dcbc0c6eSTom Lendacky #ifdef CONFIG_CRYPTO_DEV_SP_CCP 450dcbc0c6eSTom Lendacky .ccp_vdata = &ccpv5a, 451dcbc0c6eSTom Lendacky #endif 452dcbc0c6eSTom Lendacky #ifdef CONFIG_CRYPTO_DEV_SP_PSP 453dcbc0c6eSTom Lendacky .psp_vdata = &pspv2, 454dcbc0c6eSTom Lendacky #endif 455dcbc0c6eSTom Lendacky }, 45633960accSRijo Thomas { /* 4 */ 45733960accSRijo Thomas .bar = 2, 45833960accSRijo Thomas #ifdef CONFIG_CRYPTO_DEV_SP_CCP 45933960accSRijo Thomas .ccp_vdata = &ccpv5a, 46033960accSRijo Thomas #endif 46133960accSRijo Thomas #ifdef CONFIG_CRYPTO_DEV_SP_PSP 46233960accSRijo Thomas .psp_vdata = &pspv3, 46333960accSRijo Thomas #endif 46433960accSRijo Thomas }, 4653438de03SJohn Allen { /* 5 */ 4663438de03SJohn Allen .bar = 2, 4673438de03SJohn Allen #ifdef CONFIG_CRYPTO_DEV_SP_PSP 46810da230aSMario Limonciello .psp_vdata = &pspv4, 4693438de03SJohn Allen #endif 4703438de03SJohn Allen }, 47196ec8dfdSMario Limonciello { /* 6 */ 47296ec8dfdSMario Limonciello .bar = 2, 47396ec8dfdSMario Limonciello #ifdef CONFIG_CRYPTO_DEV_SP_PSP 47496ec8dfdSMario Limonciello .psp_vdata = &pspv3, 47596ec8dfdSMario Limonciello #endif 47696ec8dfdSMario Limonciello }, 477*4aa0931bSMario Limonciello { /* 7 */ 478*4aa0931bSMario Limonciello .bar = 2, 479*4aa0931bSMario Limonciello #ifdef CONFIG_CRYPTO_DEV_SP_PSP 480*4aa0931bSMario Limonciello .psp_vdata = &pspv5, 481*4aa0931bSMario Limonciello #endif 482*4aa0931bSMario Limonciello }, 483d0ebbc0cSBrijesh Singh }; 484d0ebbc0cSBrijesh Singh static const struct pci_device_id sp_pci_table[] = { 485d0ebbc0cSBrijesh Singh { PCI_VDEVICE(AMD, 0x1537), (kernel_ulong_t)&dev_vdata[0] }, 486d0ebbc0cSBrijesh Singh { PCI_VDEVICE(AMD, 0x1456), (kernel_ulong_t)&dev_vdata[1] }, 487d0ebbc0cSBrijesh Singh { PCI_VDEVICE(AMD, 0x1468), (kernel_ulong_t)&dev_vdata[2] }, 488dcbc0c6eSTom Lendacky { PCI_VDEVICE(AMD, 0x1486), (kernel_ulong_t)&dev_vdata[3] }, 48933960accSRijo Thomas { PCI_VDEVICE(AMD, 0x15DF), (kernel_ulong_t)&dev_vdata[4] }, 4903438de03SJohn Allen { PCI_VDEVICE(AMD, 0x14CA), (kernel_ulong_t)&dev_vdata[5] }, 49196ec8dfdSMario Limonciello { PCI_VDEVICE(AMD, 0x15C7), (kernel_ulong_t)&dev_vdata[6] }, 492c79a3169SMario Limonciello { PCI_VDEVICE(AMD, 0x1649), (kernel_ulong_t)&dev_vdata[6] }, 493*4aa0931bSMario Limonciello { PCI_VDEVICE(AMD, 0x17E0), (kernel_ulong_t)&dev_vdata[7] }, 494d0ebbc0cSBrijesh Singh /* Last entry must be zero */ 495d0ebbc0cSBrijesh Singh { 0, } 496d0ebbc0cSBrijesh Singh }; 497d0ebbc0cSBrijesh Singh MODULE_DEVICE_TABLE(pci, sp_pci_table); 498d0ebbc0cSBrijesh Singh 499f892a21fSVaibhav Gupta static SIMPLE_DEV_PM_OPS(sp_pci_pm_ops, sp_pci_suspend, sp_pci_resume); 500f892a21fSVaibhav Gupta 501d0ebbc0cSBrijesh Singh static struct pci_driver sp_pci_driver = { 502d0ebbc0cSBrijesh Singh .name = "ccp", 503d0ebbc0cSBrijesh Singh .id_table = sp_pci_table, 504d0ebbc0cSBrijesh Singh .probe = sp_pci_probe, 505d0ebbc0cSBrijesh Singh .remove = sp_pci_remove, 5065441a07aSBrijesh Singh .shutdown = sp_pci_shutdown, 507f892a21fSVaibhav Gupta .driver.pm = &sp_pci_pm_ops, 50850c4deccSMario Limonciello .dev_groups = psp_groups, 509d0ebbc0cSBrijesh Singh }; 510d0ebbc0cSBrijesh Singh 511d0ebbc0cSBrijesh Singh int sp_pci_init(void) 512d0ebbc0cSBrijesh Singh { 513d0ebbc0cSBrijesh Singh return pci_register_driver(&sp_pci_driver); 514d0ebbc0cSBrijesh Singh } 515d0ebbc0cSBrijesh Singh 516d0ebbc0cSBrijesh Singh void sp_pci_exit(void) 517d0ebbc0cSBrijesh Singh { 518d0ebbc0cSBrijesh Singh pci_unregister_driver(&sp_pci_driver); 519d0ebbc0cSBrijesh Singh } 520