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 = { 345ad01a984STom Lendacky .cmdresp_reg = 0x10580, 346ad01a984STom Lendacky .cmdbuff_addr_lo_reg = 0x105e0, 347ad01a984STom Lendacky .cmdbuff_addr_hi_reg = 0x105e4, 3486eb0cc72SRijo Thomas }; 3496eb0cc72SRijo Thomas 3506eb0cc72SRijo Thomas static const struct sev_vdata sevv2 = { 3516eb0cc72SRijo Thomas .cmdresp_reg = 0x10980, 3526eb0cc72SRijo Thomas .cmdbuff_addr_lo_reg = 0x109e0, 3536eb0cc72SRijo Thomas .cmdbuff_addr_hi_reg = 0x109e4, 3546eb0cc72SRijo Thomas }; 3556eb0cc72SRijo Thomas 35633960accSRijo Thomas static const struct tee_vdata teev1 = { 35733960accSRijo Thomas .cmdresp_reg = 0x10544, 35833960accSRijo Thomas .cmdbuff_addr_lo_reg = 0x10548, 35933960accSRijo Thomas .cmdbuff_addr_hi_reg = 0x1054c, 36033960accSRijo Thomas .ring_wptr_reg = 0x10550, 36133960accSRijo Thomas .ring_rptr_reg = 0x10554, 36233960accSRijo Thomas }; 36333960accSRijo Thomas 3646eb0cc72SRijo Thomas static const struct psp_vdata pspv1 = { 3656eb0cc72SRijo Thomas .sev = &sevv1, 366ad01a984STom Lendacky .feature_reg = 0x105fc, 367ad01a984STom Lendacky .inten_reg = 0x10610, 368ad01a984STom Lendacky .intsts_reg = 0x10614, 3692a6170dfSBrijesh Singh }; 370dcbc0c6eSTom Lendacky 371dcbc0c6eSTom Lendacky static const struct psp_vdata pspv2 = { 3726eb0cc72SRijo Thomas .sev = &sevv2, 373dcbc0c6eSTom Lendacky .feature_reg = 0x109fc, 374dcbc0c6eSTom Lendacky .inten_reg = 0x10690, 375dcbc0c6eSTom Lendacky .intsts_reg = 0x10694, 376dcbc0c6eSTom Lendacky }; 37733960accSRijo Thomas 37833960accSRijo Thomas static const struct psp_vdata pspv3 = { 37933960accSRijo Thomas .tee = &teev1, 38033960accSRijo Thomas .feature_reg = 0x109fc, 38133960accSRijo Thomas .inten_reg = 0x10690, 38233960accSRijo Thomas .intsts_reg = 0x10694, 38333960accSRijo Thomas }; 3842a6170dfSBrijesh Singh #endif 3852a6170dfSBrijesh Singh 386d0ebbc0cSBrijesh Singh static const struct sp_dev_vdata dev_vdata[] = { 387dcbc0c6eSTom Lendacky { /* 0 */ 388d0ebbc0cSBrijesh Singh .bar = 2, 389d0ebbc0cSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_CCP 390d0ebbc0cSBrijesh Singh .ccp_vdata = &ccpv3, 391d0ebbc0cSBrijesh Singh #endif 392d0ebbc0cSBrijesh Singh }, 393dcbc0c6eSTom Lendacky { /* 1 */ 394d0ebbc0cSBrijesh Singh .bar = 2, 395d0ebbc0cSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_CCP 396d0ebbc0cSBrijesh Singh .ccp_vdata = &ccpv5a, 397d0ebbc0cSBrijesh Singh #endif 3982a6170dfSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_PSP 399dcbc0c6eSTom Lendacky .psp_vdata = &pspv1, 4002a6170dfSBrijesh Singh #endif 401d0ebbc0cSBrijesh Singh }, 402dcbc0c6eSTom Lendacky { /* 2 */ 403d0ebbc0cSBrijesh Singh .bar = 2, 404d0ebbc0cSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_CCP 405d0ebbc0cSBrijesh Singh .ccp_vdata = &ccpv5b, 406d0ebbc0cSBrijesh Singh #endif 407d0ebbc0cSBrijesh Singh }, 408dcbc0c6eSTom Lendacky { /* 3 */ 409dcbc0c6eSTom Lendacky .bar = 2, 410dcbc0c6eSTom Lendacky #ifdef CONFIG_CRYPTO_DEV_SP_CCP 411dcbc0c6eSTom Lendacky .ccp_vdata = &ccpv5a, 412dcbc0c6eSTom Lendacky #endif 413dcbc0c6eSTom Lendacky #ifdef CONFIG_CRYPTO_DEV_SP_PSP 414dcbc0c6eSTom Lendacky .psp_vdata = &pspv2, 415dcbc0c6eSTom Lendacky #endif 416dcbc0c6eSTom Lendacky }, 41733960accSRijo Thomas { /* 4 */ 41833960accSRijo Thomas .bar = 2, 41933960accSRijo Thomas #ifdef CONFIG_CRYPTO_DEV_SP_CCP 42033960accSRijo Thomas .ccp_vdata = &ccpv5a, 42133960accSRijo Thomas #endif 42233960accSRijo Thomas #ifdef CONFIG_CRYPTO_DEV_SP_PSP 42333960accSRijo Thomas .psp_vdata = &pspv3, 42433960accSRijo Thomas #endif 42533960accSRijo Thomas }, 4263438de03SJohn Allen { /* 5 */ 4273438de03SJohn Allen .bar = 2, 4283438de03SJohn Allen #ifdef CONFIG_CRYPTO_DEV_SP_PSP 4293438de03SJohn Allen .psp_vdata = &pspv2, 4303438de03SJohn Allen #endif 4313438de03SJohn Allen }, 432*96ec8dfdSMario Limonciello { /* 6 */ 433*96ec8dfdSMario Limonciello .bar = 2, 434*96ec8dfdSMario Limonciello #ifdef CONFIG_CRYPTO_DEV_SP_PSP 435*96ec8dfdSMario Limonciello .psp_vdata = &pspv3, 436*96ec8dfdSMario Limonciello #endif 437*96ec8dfdSMario Limonciello }, 438d0ebbc0cSBrijesh Singh }; 439d0ebbc0cSBrijesh Singh static const struct pci_device_id sp_pci_table[] = { 440d0ebbc0cSBrijesh Singh { PCI_VDEVICE(AMD, 0x1537), (kernel_ulong_t)&dev_vdata[0] }, 441d0ebbc0cSBrijesh Singh { PCI_VDEVICE(AMD, 0x1456), (kernel_ulong_t)&dev_vdata[1] }, 442d0ebbc0cSBrijesh Singh { PCI_VDEVICE(AMD, 0x1468), (kernel_ulong_t)&dev_vdata[2] }, 443dcbc0c6eSTom Lendacky { PCI_VDEVICE(AMD, 0x1486), (kernel_ulong_t)&dev_vdata[3] }, 44433960accSRijo Thomas { PCI_VDEVICE(AMD, 0x15DF), (kernel_ulong_t)&dev_vdata[4] }, 445195ec383SDevaraj Rangasamy { PCI_VDEVICE(AMD, 0x1649), (kernel_ulong_t)&dev_vdata[4] }, 4463438de03SJohn Allen { PCI_VDEVICE(AMD, 0x14CA), (kernel_ulong_t)&dev_vdata[5] }, 447*96ec8dfdSMario Limonciello { PCI_VDEVICE(AMD, 0x15C7), (kernel_ulong_t)&dev_vdata[6] }, 448d0ebbc0cSBrijesh Singh /* Last entry must be zero */ 449d0ebbc0cSBrijesh Singh { 0, } 450d0ebbc0cSBrijesh Singh }; 451d0ebbc0cSBrijesh Singh MODULE_DEVICE_TABLE(pci, sp_pci_table); 452d0ebbc0cSBrijesh Singh 453f892a21fSVaibhav Gupta static SIMPLE_DEV_PM_OPS(sp_pci_pm_ops, sp_pci_suspend, sp_pci_resume); 454f892a21fSVaibhav Gupta 455d0ebbc0cSBrijesh Singh static struct pci_driver sp_pci_driver = { 456d0ebbc0cSBrijesh Singh .name = "ccp", 457d0ebbc0cSBrijesh Singh .id_table = sp_pci_table, 458d0ebbc0cSBrijesh Singh .probe = sp_pci_probe, 459d0ebbc0cSBrijesh Singh .remove = sp_pci_remove, 4605441a07aSBrijesh Singh .shutdown = sp_pci_shutdown, 461f892a21fSVaibhav Gupta .driver.pm = &sp_pci_pm_ops, 46250c4deccSMario Limonciello .dev_groups = psp_groups, 463d0ebbc0cSBrijesh Singh }; 464d0ebbc0cSBrijesh Singh 465d0ebbc0cSBrijesh Singh int sp_pci_init(void) 466d0ebbc0cSBrijesh Singh { 467d0ebbc0cSBrijesh Singh return pci_register_driver(&sp_pci_driver); 468d0ebbc0cSBrijesh Singh } 469d0ebbc0cSBrijesh Singh 470d0ebbc0cSBrijesh Singh void sp_pci_exit(void) 471d0ebbc0cSBrijesh Singh { 472d0ebbc0cSBrijesh Singh pci_unregister_driver(&sp_pci_driver); 473d0ebbc0cSBrijesh Singh } 474