xref: /openbmc/linux/drivers/crypto/ccp/sp-pci.c (revision 675c39196ce3b47307dfc339dade6e6946ee1e1b)
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 = {
345*675c3919STom Lendacky 	.cmdresp_reg		= 0x10580,	/* C2PMSG_32 */
346*675c3919STom Lendacky 	.cmdbuff_addr_lo_reg	= 0x105e0,	/* C2PMSG_56 */
347*675c3919STom Lendacky 	.cmdbuff_addr_hi_reg	= 0x105e4,	/* C2PMSG_57 */
3486eb0cc72SRijo Thomas };
3496eb0cc72SRijo Thomas 
3506eb0cc72SRijo Thomas static const struct sev_vdata sevv2 = {
351*675c3919STom Lendacky 	.cmdresp_reg		= 0x10980,	/* C2PMSG_32 */
352*675c3919STom Lendacky 	.cmdbuff_addr_lo_reg	= 0x109e0,	/* C2PMSG_56 */
353*675c3919STom Lendacky 	.cmdbuff_addr_hi_reg	= 0x109e4,	/* C2PMSG_57 */
3546eb0cc72SRijo Thomas };
3556eb0cc72SRijo Thomas 
35633960accSRijo Thomas static const struct tee_vdata teev1 = {
357*675c3919STom Lendacky 	.cmdresp_reg		= 0x10544,	/* C2PMSG_17 */
358*675c3919STom Lendacky 	.cmdbuff_addr_lo_reg	= 0x10548,	/* C2PMSG_18 */
359*675c3919STom Lendacky 	.cmdbuff_addr_hi_reg	= 0x1054c,	/* C2PMSG_19 */
360*675c3919STom Lendacky 	.ring_wptr_reg          = 0x10550,	/* C2PMSG_20 */
361*675c3919STom Lendacky 	.ring_rptr_reg          = 0x10554,	/* C2PMSG_21 */
36233960accSRijo Thomas };
36333960accSRijo Thomas 
3646eb0cc72SRijo Thomas static const struct psp_vdata pspv1 = {
3656eb0cc72SRijo Thomas 	.sev			= &sevv1,
366*675c3919STom Lendacky 	.feature_reg		= 0x105fc,	/* C2PMSG_63 */
367*675c3919STom Lendacky 	.inten_reg		= 0x10610,	/* P2CMSG_INTEN */
368*675c3919STom Lendacky 	.intsts_reg		= 0x10614,	/* P2CMSG_INTSTS */
3692a6170dfSBrijesh Singh };
370dcbc0c6eSTom Lendacky 
371dcbc0c6eSTom Lendacky static const struct psp_vdata pspv2 = {
3726eb0cc72SRijo Thomas 	.sev			= &sevv2,
373*675c3919STom Lendacky 	.feature_reg		= 0x109fc,	/* C2PMSG_63 */
374*675c3919STom Lendacky 	.inten_reg		= 0x10690,	/* P2CMSG_INTEN */
375*675c3919STom Lendacky 	.intsts_reg		= 0x10694,	/* P2CMSG_INTSTS */
376dcbc0c6eSTom Lendacky };
37733960accSRijo Thomas 
37833960accSRijo Thomas static const struct psp_vdata pspv3 = {
37933960accSRijo Thomas 	.tee			= &teev1,
380*675c3919STom Lendacky 	.feature_reg		= 0x109fc,	/* C2PMSG_63 */
381*675c3919STom Lendacky 	.inten_reg		= 0x10690,	/* P2CMSG_INTEN */
382*675c3919STom Lendacky 	.intsts_reg		= 0x10694,	/* P2CMSG_INTSTS */
38333960accSRijo Thomas };
38410da230aSMario Limonciello 
38510da230aSMario Limonciello static const struct psp_vdata pspv4 = {
38610da230aSMario Limonciello 	.sev			= &sevv2,
38710da230aSMario Limonciello 	.tee			= &teev1,
388*675c3919STom Lendacky 	.feature_reg		= 0x109fc,	/* C2PMSG_63 */
389*675c3919STom Lendacky 	.inten_reg		= 0x10690,	/* P2CMSG_INTEN */
390*675c3919STom Lendacky 	.intsts_reg		= 0x10694,	/* P2CMSG_INTSTS */
39110da230aSMario Limonciello };
39210da230aSMario Limonciello 
3932a6170dfSBrijesh Singh #endif
3942a6170dfSBrijesh Singh 
395d0ebbc0cSBrijesh Singh static const struct sp_dev_vdata dev_vdata[] = {
396dcbc0c6eSTom Lendacky 	{	/* 0 */
397d0ebbc0cSBrijesh Singh 		.bar = 2,
398d0ebbc0cSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_CCP
399d0ebbc0cSBrijesh Singh 		.ccp_vdata = &ccpv3,
400d0ebbc0cSBrijesh Singh #endif
401d0ebbc0cSBrijesh Singh 	},
402dcbc0c6eSTom Lendacky 	{	/* 1 */
403d0ebbc0cSBrijesh Singh 		.bar = 2,
404d0ebbc0cSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_CCP
405d0ebbc0cSBrijesh Singh 		.ccp_vdata = &ccpv5a,
406d0ebbc0cSBrijesh Singh #endif
4072a6170dfSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_PSP
408dcbc0c6eSTom Lendacky 		.psp_vdata = &pspv1,
4092a6170dfSBrijesh Singh #endif
410d0ebbc0cSBrijesh Singh 	},
411dcbc0c6eSTom Lendacky 	{	/* 2 */
412d0ebbc0cSBrijesh Singh 		.bar = 2,
413d0ebbc0cSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_CCP
414d0ebbc0cSBrijesh Singh 		.ccp_vdata = &ccpv5b,
415d0ebbc0cSBrijesh Singh #endif
416d0ebbc0cSBrijesh Singh 	},
417dcbc0c6eSTom Lendacky 	{	/* 3 */
418dcbc0c6eSTom Lendacky 		.bar = 2,
419dcbc0c6eSTom Lendacky #ifdef CONFIG_CRYPTO_DEV_SP_CCP
420dcbc0c6eSTom Lendacky 		.ccp_vdata = &ccpv5a,
421dcbc0c6eSTom Lendacky #endif
422dcbc0c6eSTom Lendacky #ifdef CONFIG_CRYPTO_DEV_SP_PSP
423dcbc0c6eSTom Lendacky 		.psp_vdata = &pspv2,
424dcbc0c6eSTom Lendacky #endif
425dcbc0c6eSTom Lendacky 	},
42633960accSRijo Thomas 	{	/* 4 */
42733960accSRijo Thomas 		.bar = 2,
42833960accSRijo Thomas #ifdef CONFIG_CRYPTO_DEV_SP_CCP
42933960accSRijo Thomas 		.ccp_vdata = &ccpv5a,
43033960accSRijo Thomas #endif
43133960accSRijo Thomas #ifdef CONFIG_CRYPTO_DEV_SP_PSP
43233960accSRijo Thomas 		.psp_vdata = &pspv3,
43333960accSRijo Thomas #endif
43433960accSRijo Thomas 	},
4353438de03SJohn Allen 	{	/* 5 */
4363438de03SJohn Allen 		.bar = 2,
4373438de03SJohn Allen #ifdef CONFIG_CRYPTO_DEV_SP_PSP
43810da230aSMario Limonciello 		.psp_vdata = &pspv4,
4393438de03SJohn Allen #endif
4403438de03SJohn Allen 	},
44196ec8dfdSMario Limonciello 	{	/* 6 */
44296ec8dfdSMario Limonciello 		.bar = 2,
44396ec8dfdSMario Limonciello #ifdef CONFIG_CRYPTO_DEV_SP_PSP
44496ec8dfdSMario Limonciello 		.psp_vdata = &pspv3,
44596ec8dfdSMario Limonciello #endif
44696ec8dfdSMario Limonciello 	},
447d0ebbc0cSBrijesh Singh };
448d0ebbc0cSBrijesh Singh static const struct pci_device_id sp_pci_table[] = {
449d0ebbc0cSBrijesh Singh 	{ PCI_VDEVICE(AMD, 0x1537), (kernel_ulong_t)&dev_vdata[0] },
450d0ebbc0cSBrijesh Singh 	{ PCI_VDEVICE(AMD, 0x1456), (kernel_ulong_t)&dev_vdata[1] },
451d0ebbc0cSBrijesh Singh 	{ PCI_VDEVICE(AMD, 0x1468), (kernel_ulong_t)&dev_vdata[2] },
452dcbc0c6eSTom Lendacky 	{ PCI_VDEVICE(AMD, 0x1486), (kernel_ulong_t)&dev_vdata[3] },
45333960accSRijo Thomas 	{ PCI_VDEVICE(AMD, 0x15DF), (kernel_ulong_t)&dev_vdata[4] },
454195ec383SDevaraj Rangasamy 	{ PCI_VDEVICE(AMD, 0x1649), (kernel_ulong_t)&dev_vdata[4] },
4553438de03SJohn Allen 	{ PCI_VDEVICE(AMD, 0x14CA), (kernel_ulong_t)&dev_vdata[5] },
45696ec8dfdSMario Limonciello 	{ PCI_VDEVICE(AMD, 0x15C7), (kernel_ulong_t)&dev_vdata[6] },
457d0ebbc0cSBrijesh Singh 	/* Last entry must be zero */
458d0ebbc0cSBrijesh Singh 	{ 0, }
459d0ebbc0cSBrijesh Singh };
460d0ebbc0cSBrijesh Singh MODULE_DEVICE_TABLE(pci, sp_pci_table);
461d0ebbc0cSBrijesh Singh 
462f892a21fSVaibhav Gupta static SIMPLE_DEV_PM_OPS(sp_pci_pm_ops, sp_pci_suspend, sp_pci_resume);
463f892a21fSVaibhav Gupta 
464d0ebbc0cSBrijesh Singh static struct pci_driver sp_pci_driver = {
465d0ebbc0cSBrijesh Singh 	.name = "ccp",
466d0ebbc0cSBrijesh Singh 	.id_table = sp_pci_table,
467d0ebbc0cSBrijesh Singh 	.probe = sp_pci_probe,
468d0ebbc0cSBrijesh Singh 	.remove = sp_pci_remove,
4695441a07aSBrijesh Singh 	.shutdown = sp_pci_shutdown,
470f892a21fSVaibhav Gupta 	.driver.pm = &sp_pci_pm_ops,
47150c4deccSMario Limonciello 	.dev_groups = psp_groups,
472d0ebbc0cSBrijesh Singh };
473d0ebbc0cSBrijesh Singh 
474d0ebbc0cSBrijesh Singh int sp_pci_init(void)
475d0ebbc0cSBrijesh Singh {
476d0ebbc0cSBrijesh Singh 	return pci_register_driver(&sp_pci_driver);
477d0ebbc0cSBrijesh Singh }
478d0ebbc0cSBrijesh Singh 
479d0ebbc0cSBrijesh Singh void sp_pci_exit(void)
480d0ebbc0cSBrijesh Singh {
481d0ebbc0cSBrijesh Singh 	pci_unregister_driver(&sp_pci_driver);
482d0ebbc0cSBrijesh Singh }
483