xref: /openbmc/linux/drivers/crypto/ccp/sp-pci.c (revision 3438de03e98ad305129bdd033cb63e46debd67f4)
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 
35d0ebbc0cSBrijesh Singh static int sp_get_msix_irqs(struct sp_device *sp)
36d0ebbc0cSBrijesh Singh {
37d0ebbc0cSBrijesh Singh 	struct sp_pci *sp_pci = sp->dev_specific;
38d0ebbc0cSBrijesh Singh 	struct device *dev = sp->dev;
39d0ebbc0cSBrijesh Singh 	struct pci_dev *pdev = to_pci_dev(dev);
40d0ebbc0cSBrijesh Singh 	int v, ret;
41d0ebbc0cSBrijesh Singh 
42d0ebbc0cSBrijesh Singh 	for (v = 0; v < ARRAY_SIZE(sp_pci->msix_entry); v++)
43d0ebbc0cSBrijesh Singh 		sp_pci->msix_entry[v].entry = v;
44d0ebbc0cSBrijesh Singh 
45d0ebbc0cSBrijesh Singh 	ret = pci_enable_msix_range(pdev, sp_pci->msix_entry, 1, v);
46d0ebbc0cSBrijesh Singh 	if (ret < 0)
47d0ebbc0cSBrijesh Singh 		return ret;
48d0ebbc0cSBrijesh Singh 
49d0ebbc0cSBrijesh Singh 	sp_pci->msix_count = ret;
50d0ebbc0cSBrijesh Singh 	sp->use_tasklet = true;
51d0ebbc0cSBrijesh Singh 
52d0ebbc0cSBrijesh Singh 	sp->psp_irq = sp_pci->msix_entry[0].vector;
53d0ebbc0cSBrijesh Singh 	sp->ccp_irq = (sp_pci->msix_count > 1) ? sp_pci->msix_entry[1].vector
54d0ebbc0cSBrijesh Singh 					       : sp_pci->msix_entry[0].vector;
55d0ebbc0cSBrijesh Singh 	return 0;
56d0ebbc0cSBrijesh Singh }
57d0ebbc0cSBrijesh Singh 
58d0ebbc0cSBrijesh Singh static int sp_get_msi_irq(struct sp_device *sp)
59d0ebbc0cSBrijesh Singh {
60d0ebbc0cSBrijesh Singh 	struct device *dev = sp->dev;
61d0ebbc0cSBrijesh Singh 	struct pci_dev *pdev = to_pci_dev(dev);
62d0ebbc0cSBrijesh Singh 	int ret;
63d0ebbc0cSBrijesh Singh 
64d0ebbc0cSBrijesh Singh 	ret = pci_enable_msi(pdev);
65d0ebbc0cSBrijesh Singh 	if (ret)
66d0ebbc0cSBrijesh Singh 		return ret;
67d0ebbc0cSBrijesh Singh 
68d0ebbc0cSBrijesh Singh 	sp->ccp_irq = pdev->irq;
69d0ebbc0cSBrijesh Singh 	sp->psp_irq = pdev->irq;
70d0ebbc0cSBrijesh Singh 
71d0ebbc0cSBrijesh Singh 	return 0;
72d0ebbc0cSBrijesh Singh }
73d0ebbc0cSBrijesh Singh 
74d0ebbc0cSBrijesh Singh static int sp_get_irqs(struct sp_device *sp)
75d0ebbc0cSBrijesh Singh {
76d0ebbc0cSBrijesh Singh 	struct device *dev = sp->dev;
77d0ebbc0cSBrijesh Singh 	int ret;
78d0ebbc0cSBrijesh Singh 
79d0ebbc0cSBrijesh Singh 	ret = sp_get_msix_irqs(sp);
80d0ebbc0cSBrijesh Singh 	if (!ret)
81d0ebbc0cSBrijesh Singh 		return 0;
82d0ebbc0cSBrijesh Singh 
83d0ebbc0cSBrijesh Singh 	/* Couldn't get MSI-X vectors, try MSI */
84d0ebbc0cSBrijesh Singh 	dev_notice(dev, "could not enable MSI-X (%d), trying MSI\n", ret);
85d0ebbc0cSBrijesh Singh 	ret = sp_get_msi_irq(sp);
86d0ebbc0cSBrijesh Singh 	if (!ret)
87d0ebbc0cSBrijesh Singh 		return 0;
88d0ebbc0cSBrijesh Singh 
89d0ebbc0cSBrijesh Singh 	/* Couldn't get MSI interrupt */
90d0ebbc0cSBrijesh Singh 	dev_notice(dev, "could not enable MSI (%d)\n", ret);
91d0ebbc0cSBrijesh Singh 
92d0ebbc0cSBrijesh Singh 	return ret;
93d0ebbc0cSBrijesh Singh }
94d0ebbc0cSBrijesh Singh 
95d0ebbc0cSBrijesh Singh static void sp_free_irqs(struct sp_device *sp)
96d0ebbc0cSBrijesh Singh {
97d0ebbc0cSBrijesh Singh 	struct sp_pci *sp_pci = sp->dev_specific;
98d0ebbc0cSBrijesh Singh 	struct device *dev = sp->dev;
99d0ebbc0cSBrijesh Singh 	struct pci_dev *pdev = to_pci_dev(dev);
100d0ebbc0cSBrijesh Singh 
101d0ebbc0cSBrijesh Singh 	if (sp_pci->msix_count)
102d0ebbc0cSBrijesh Singh 		pci_disable_msix(pdev);
103d0ebbc0cSBrijesh Singh 	else if (sp->psp_irq)
104d0ebbc0cSBrijesh Singh 		pci_disable_msi(pdev);
105d0ebbc0cSBrijesh Singh 
106d0ebbc0cSBrijesh Singh 	sp->ccp_irq = 0;
107d0ebbc0cSBrijesh Singh 	sp->psp_irq = 0;
108d0ebbc0cSBrijesh Singh }
109d0ebbc0cSBrijesh Singh 
1102a6170dfSBrijesh Singh static bool sp_pci_is_master(struct sp_device *sp)
1112a6170dfSBrijesh Singh {
1122a6170dfSBrijesh Singh 	struct device *dev_cur, *dev_new;
1132a6170dfSBrijesh Singh 	struct pci_dev *pdev_cur, *pdev_new;
1142a6170dfSBrijesh Singh 
1152a6170dfSBrijesh Singh 	dev_new = sp->dev;
1162a6170dfSBrijesh Singh 	dev_cur = sp_dev_master->dev;
1172a6170dfSBrijesh Singh 
1182a6170dfSBrijesh Singh 	pdev_new = to_pci_dev(dev_new);
1192a6170dfSBrijesh Singh 	pdev_cur = to_pci_dev(dev_cur);
1202a6170dfSBrijesh Singh 
1212a6170dfSBrijesh Singh 	if (pdev_new->bus->number < pdev_cur->bus->number)
1222a6170dfSBrijesh Singh 		return true;
1232a6170dfSBrijesh Singh 
1242a6170dfSBrijesh Singh 	if (PCI_SLOT(pdev_new->devfn) < PCI_SLOT(pdev_cur->devfn))
1252a6170dfSBrijesh Singh 		return true;
1262a6170dfSBrijesh Singh 
1272a6170dfSBrijesh Singh 	if (PCI_FUNC(pdev_new->devfn) < PCI_FUNC(pdev_cur->devfn))
1282a6170dfSBrijesh Singh 		return true;
1292a6170dfSBrijesh Singh 
1302a6170dfSBrijesh Singh 	return false;
1312a6170dfSBrijesh Singh }
1322a6170dfSBrijesh Singh 
1332a6170dfSBrijesh Singh static void psp_set_master(struct sp_device *sp)
1342a6170dfSBrijesh Singh {
1352a6170dfSBrijesh Singh 	if (!sp_dev_master) {
1362a6170dfSBrijesh Singh 		sp_dev_master = sp;
1372a6170dfSBrijesh Singh 		return;
1382a6170dfSBrijesh Singh 	}
1392a6170dfSBrijesh Singh 
1402a6170dfSBrijesh Singh 	if (sp_pci_is_master(sp))
1412a6170dfSBrijesh Singh 		sp_dev_master = sp;
1422a6170dfSBrijesh Singh }
1432a6170dfSBrijesh Singh 
1442a6170dfSBrijesh Singh static struct sp_device *psp_get_master(void)
1452a6170dfSBrijesh Singh {
1462a6170dfSBrijesh Singh 	return sp_dev_master;
1472a6170dfSBrijesh Singh }
1482a6170dfSBrijesh Singh 
14915f7a4c6SJohn Allen static void psp_clear_master(struct sp_device *sp)
15015f7a4c6SJohn Allen {
15115f7a4c6SJohn Allen 	if (sp == sp_dev_master) {
15215f7a4c6SJohn Allen 		sp_dev_master = NULL;
15315f7a4c6SJohn Allen 		dev_dbg(sp->dev, "Cleared sp_dev_master\n");
15415f7a4c6SJohn Allen 	}
15515f7a4c6SJohn Allen }
15615f7a4c6SJohn Allen 
157d0ebbc0cSBrijesh Singh static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
158d0ebbc0cSBrijesh Singh {
159d0ebbc0cSBrijesh Singh 	struct sp_device *sp;
160d0ebbc0cSBrijesh Singh 	struct sp_pci *sp_pci;
161d0ebbc0cSBrijesh Singh 	struct device *dev = &pdev->dev;
162d0ebbc0cSBrijesh Singh 	void __iomem * const *iomap_table;
163d0ebbc0cSBrijesh Singh 	int bar_mask;
164d0ebbc0cSBrijesh Singh 	int ret;
165d0ebbc0cSBrijesh Singh 
166d0ebbc0cSBrijesh Singh 	ret = -ENOMEM;
167d0ebbc0cSBrijesh Singh 	sp = sp_alloc_struct(dev);
168d0ebbc0cSBrijesh Singh 	if (!sp)
169d0ebbc0cSBrijesh Singh 		goto e_err;
170d0ebbc0cSBrijesh Singh 
171d0ebbc0cSBrijesh Singh 	sp_pci = devm_kzalloc(dev, sizeof(*sp_pci), GFP_KERNEL);
172d0ebbc0cSBrijesh Singh 	if (!sp_pci)
173d0ebbc0cSBrijesh Singh 		goto e_err;
174d0ebbc0cSBrijesh Singh 
175d0ebbc0cSBrijesh Singh 	sp->dev_specific = sp_pci;
176d0ebbc0cSBrijesh Singh 	sp->dev_vdata = (struct sp_dev_vdata *)id->driver_data;
177d0ebbc0cSBrijesh Singh 	if (!sp->dev_vdata) {
178d0ebbc0cSBrijesh Singh 		ret = -ENODEV;
179d0ebbc0cSBrijesh Singh 		dev_err(dev, "missing driver data\n");
180d0ebbc0cSBrijesh Singh 		goto e_err;
181d0ebbc0cSBrijesh Singh 	}
182d0ebbc0cSBrijesh Singh 
183d0ebbc0cSBrijesh Singh 	ret = pcim_enable_device(pdev);
184d0ebbc0cSBrijesh Singh 	if (ret) {
185d0ebbc0cSBrijesh Singh 		dev_err(dev, "pcim_enable_device failed (%d)\n", ret);
186d0ebbc0cSBrijesh Singh 		goto e_err;
187d0ebbc0cSBrijesh Singh 	}
188d0ebbc0cSBrijesh Singh 
189d0ebbc0cSBrijesh Singh 	bar_mask = pci_select_bars(pdev, IORESOURCE_MEM);
190d0ebbc0cSBrijesh Singh 	ret = pcim_iomap_regions(pdev, bar_mask, "ccp");
191d0ebbc0cSBrijesh Singh 	if (ret) {
192d0ebbc0cSBrijesh Singh 		dev_err(dev, "pcim_iomap_regions failed (%d)\n", ret);
193d0ebbc0cSBrijesh Singh 		goto e_err;
194d0ebbc0cSBrijesh Singh 	}
195d0ebbc0cSBrijesh Singh 
196d0ebbc0cSBrijesh Singh 	iomap_table = pcim_iomap_table(pdev);
197d0ebbc0cSBrijesh Singh 	if (!iomap_table) {
198d0ebbc0cSBrijesh Singh 		dev_err(dev, "pcim_iomap_table failed\n");
199d0ebbc0cSBrijesh Singh 		ret = -ENOMEM;
200d0ebbc0cSBrijesh Singh 		goto e_err;
201d0ebbc0cSBrijesh Singh 	}
202d0ebbc0cSBrijesh Singh 
203d0ebbc0cSBrijesh Singh 	sp->io_map = iomap_table[sp->dev_vdata->bar];
204d0ebbc0cSBrijesh Singh 	if (!sp->io_map) {
205d0ebbc0cSBrijesh Singh 		dev_err(dev, "ioremap failed\n");
206d0ebbc0cSBrijesh Singh 		ret = -ENOMEM;
207d0ebbc0cSBrijesh Singh 		goto e_err;
208d0ebbc0cSBrijesh Singh 	}
209d0ebbc0cSBrijesh Singh 
210d0ebbc0cSBrijesh Singh 	ret = sp_get_irqs(sp);
211d0ebbc0cSBrijesh Singh 	if (ret)
212d0ebbc0cSBrijesh Singh 		goto e_err;
213d0ebbc0cSBrijesh Singh 
214d0ebbc0cSBrijesh Singh 	pci_set_master(pdev);
2152a6170dfSBrijesh Singh 	sp->set_psp_master_device = psp_set_master;
2162a6170dfSBrijesh Singh 	sp->get_psp_master_device = psp_get_master;
21715f7a4c6SJohn Allen 	sp->clear_psp_master_device = psp_clear_master;
218d0ebbc0cSBrijesh Singh 
219d0ebbc0cSBrijesh Singh 	ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48));
220d0ebbc0cSBrijesh Singh 	if (ret) {
221d0ebbc0cSBrijesh Singh 		ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
222d0ebbc0cSBrijesh Singh 		if (ret) {
223d0ebbc0cSBrijesh Singh 			dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n",
224d0ebbc0cSBrijesh Singh 				ret);
225a6f8e68eSChristophe JAILLET 			goto free_irqs;
226d0ebbc0cSBrijesh Singh 		}
227d0ebbc0cSBrijesh Singh 	}
228d0ebbc0cSBrijesh Singh 
229d0ebbc0cSBrijesh Singh 	dev_set_drvdata(dev, sp);
230d0ebbc0cSBrijesh Singh 
231d0ebbc0cSBrijesh Singh 	ret = sp_init(sp);
232d0ebbc0cSBrijesh Singh 	if (ret)
233a6f8e68eSChristophe JAILLET 		goto free_irqs;
234d0ebbc0cSBrijesh Singh 
235d0ebbc0cSBrijesh Singh 	return 0;
236d0ebbc0cSBrijesh Singh 
237a6f8e68eSChristophe JAILLET free_irqs:
238a6f8e68eSChristophe JAILLET 	sp_free_irqs(sp);
239d0ebbc0cSBrijesh Singh e_err:
240d0ebbc0cSBrijesh Singh 	dev_notice(dev, "initialization failed\n");
241d0ebbc0cSBrijesh Singh 	return ret;
242d0ebbc0cSBrijesh Singh }
243d0ebbc0cSBrijesh Singh 
2445441a07aSBrijesh Singh static void sp_pci_shutdown(struct pci_dev *pdev)
2455441a07aSBrijesh Singh {
2465441a07aSBrijesh Singh 	struct device *dev = &pdev->dev;
2475441a07aSBrijesh Singh 	struct sp_device *sp = dev_get_drvdata(dev);
2485441a07aSBrijesh Singh 
2495441a07aSBrijesh Singh 	if (!sp)
2505441a07aSBrijesh Singh 		return;
2515441a07aSBrijesh Singh 
2525441a07aSBrijesh Singh 	sp_destroy(sp);
2535441a07aSBrijesh Singh }
2545441a07aSBrijesh Singh 
255d0ebbc0cSBrijesh Singh static void sp_pci_remove(struct pci_dev *pdev)
256d0ebbc0cSBrijesh Singh {
257d0ebbc0cSBrijesh Singh 	struct device *dev = &pdev->dev;
258d0ebbc0cSBrijesh Singh 	struct sp_device *sp = dev_get_drvdata(dev);
259d0ebbc0cSBrijesh Singh 
260d0ebbc0cSBrijesh Singh 	if (!sp)
261d0ebbc0cSBrijesh Singh 		return;
262d0ebbc0cSBrijesh Singh 
263d0ebbc0cSBrijesh Singh 	sp_destroy(sp);
264d0ebbc0cSBrijesh Singh 
265d0ebbc0cSBrijesh Singh 	sp_free_irqs(sp);
266d0ebbc0cSBrijesh Singh }
267d0ebbc0cSBrijesh Singh 
268f892a21fSVaibhav Gupta static int __maybe_unused sp_pci_suspend(struct device *dev)
269d0ebbc0cSBrijesh Singh {
270d0ebbc0cSBrijesh Singh 	struct sp_device *sp = dev_get_drvdata(dev);
271d0ebbc0cSBrijesh Singh 
272f892a21fSVaibhav Gupta 	return sp_suspend(sp);
273d0ebbc0cSBrijesh Singh }
274d0ebbc0cSBrijesh Singh 
275f892a21fSVaibhav Gupta static int __maybe_unused sp_pci_resume(struct device *dev)
276d0ebbc0cSBrijesh Singh {
277d0ebbc0cSBrijesh Singh 	struct sp_device *sp = dev_get_drvdata(dev);
278d0ebbc0cSBrijesh Singh 
279d0ebbc0cSBrijesh Singh 	return sp_resume(sp);
280d0ebbc0cSBrijesh Singh }
281d0ebbc0cSBrijesh Singh 
2822a6170dfSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_PSP
2836eb0cc72SRijo Thomas static const struct sev_vdata sevv1 = {
284ad01a984STom Lendacky 	.cmdresp_reg		= 0x10580,
285ad01a984STom Lendacky 	.cmdbuff_addr_lo_reg	= 0x105e0,
286ad01a984STom Lendacky 	.cmdbuff_addr_hi_reg	= 0x105e4,
2876eb0cc72SRijo Thomas };
2886eb0cc72SRijo Thomas 
2896eb0cc72SRijo Thomas static const struct sev_vdata sevv2 = {
2906eb0cc72SRijo Thomas 	.cmdresp_reg		= 0x10980,
2916eb0cc72SRijo Thomas 	.cmdbuff_addr_lo_reg	= 0x109e0,
2926eb0cc72SRijo Thomas 	.cmdbuff_addr_hi_reg	= 0x109e4,
2936eb0cc72SRijo Thomas };
2946eb0cc72SRijo Thomas 
29533960accSRijo Thomas static const struct tee_vdata teev1 = {
29633960accSRijo Thomas 	.cmdresp_reg		= 0x10544,
29733960accSRijo Thomas 	.cmdbuff_addr_lo_reg	= 0x10548,
29833960accSRijo Thomas 	.cmdbuff_addr_hi_reg	= 0x1054c,
29933960accSRijo Thomas 	.ring_wptr_reg          = 0x10550,
30033960accSRijo Thomas 	.ring_rptr_reg          = 0x10554,
30133960accSRijo Thomas };
30233960accSRijo Thomas 
3036eb0cc72SRijo Thomas static const struct psp_vdata pspv1 = {
3046eb0cc72SRijo Thomas 	.sev			= &sevv1,
305ad01a984STom Lendacky 	.feature_reg		= 0x105fc,
306ad01a984STom Lendacky 	.inten_reg		= 0x10610,
307ad01a984STom Lendacky 	.intsts_reg		= 0x10614,
3082a6170dfSBrijesh Singh };
309dcbc0c6eSTom Lendacky 
310dcbc0c6eSTom Lendacky static const struct psp_vdata pspv2 = {
3116eb0cc72SRijo Thomas 	.sev			= &sevv2,
312dcbc0c6eSTom Lendacky 	.feature_reg		= 0x109fc,
313dcbc0c6eSTom Lendacky 	.inten_reg		= 0x10690,
314dcbc0c6eSTom Lendacky 	.intsts_reg		= 0x10694,
315dcbc0c6eSTom Lendacky };
31633960accSRijo Thomas 
31733960accSRijo Thomas static const struct psp_vdata pspv3 = {
31833960accSRijo Thomas 	.tee			= &teev1,
31933960accSRijo Thomas 	.feature_reg		= 0x109fc,
32033960accSRijo Thomas 	.inten_reg		= 0x10690,
32133960accSRijo Thomas 	.intsts_reg		= 0x10694,
32233960accSRijo Thomas };
3232a6170dfSBrijesh Singh #endif
3242a6170dfSBrijesh Singh 
325d0ebbc0cSBrijesh Singh static const struct sp_dev_vdata dev_vdata[] = {
326dcbc0c6eSTom Lendacky 	{	/* 0 */
327d0ebbc0cSBrijesh Singh 		.bar = 2,
328d0ebbc0cSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_CCP
329d0ebbc0cSBrijesh Singh 		.ccp_vdata = &ccpv3,
330d0ebbc0cSBrijesh Singh #endif
331d0ebbc0cSBrijesh Singh 	},
332dcbc0c6eSTom Lendacky 	{	/* 1 */
333d0ebbc0cSBrijesh Singh 		.bar = 2,
334d0ebbc0cSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_CCP
335d0ebbc0cSBrijesh Singh 		.ccp_vdata = &ccpv5a,
336d0ebbc0cSBrijesh Singh #endif
3372a6170dfSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_PSP
338dcbc0c6eSTom Lendacky 		.psp_vdata = &pspv1,
3392a6170dfSBrijesh Singh #endif
340d0ebbc0cSBrijesh Singh 	},
341dcbc0c6eSTom Lendacky 	{	/* 2 */
342d0ebbc0cSBrijesh Singh 		.bar = 2,
343d0ebbc0cSBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_CCP
344d0ebbc0cSBrijesh Singh 		.ccp_vdata = &ccpv5b,
345d0ebbc0cSBrijesh Singh #endif
346d0ebbc0cSBrijesh Singh 	},
347dcbc0c6eSTom Lendacky 	{	/* 3 */
348dcbc0c6eSTom Lendacky 		.bar = 2,
349dcbc0c6eSTom Lendacky #ifdef CONFIG_CRYPTO_DEV_SP_CCP
350dcbc0c6eSTom Lendacky 		.ccp_vdata = &ccpv5a,
351dcbc0c6eSTom Lendacky #endif
352dcbc0c6eSTom Lendacky #ifdef CONFIG_CRYPTO_DEV_SP_PSP
353dcbc0c6eSTom Lendacky 		.psp_vdata = &pspv2,
354dcbc0c6eSTom Lendacky #endif
355dcbc0c6eSTom Lendacky 	},
35633960accSRijo Thomas 	{	/* 4 */
35733960accSRijo Thomas 		.bar = 2,
35833960accSRijo Thomas #ifdef CONFIG_CRYPTO_DEV_SP_CCP
35933960accSRijo Thomas 		.ccp_vdata = &ccpv5a,
36033960accSRijo Thomas #endif
36133960accSRijo Thomas #ifdef CONFIG_CRYPTO_DEV_SP_PSP
36233960accSRijo Thomas 		.psp_vdata = &pspv3,
36333960accSRijo Thomas #endif
36433960accSRijo Thomas 	},
365*3438de03SJohn Allen 	{	/* 5 */
366*3438de03SJohn Allen 		.bar = 2,
367*3438de03SJohn Allen #ifdef CONFIG_CRYPTO_DEV_SP_PSP
368*3438de03SJohn Allen 		.psp_vdata = &pspv2,
369*3438de03SJohn Allen #endif
370*3438de03SJohn Allen 	},
371d0ebbc0cSBrijesh Singh };
372d0ebbc0cSBrijesh Singh static const struct pci_device_id sp_pci_table[] = {
373d0ebbc0cSBrijesh Singh 	{ PCI_VDEVICE(AMD, 0x1537), (kernel_ulong_t)&dev_vdata[0] },
374d0ebbc0cSBrijesh Singh 	{ PCI_VDEVICE(AMD, 0x1456), (kernel_ulong_t)&dev_vdata[1] },
375d0ebbc0cSBrijesh Singh 	{ PCI_VDEVICE(AMD, 0x1468), (kernel_ulong_t)&dev_vdata[2] },
376dcbc0c6eSTom Lendacky 	{ PCI_VDEVICE(AMD, 0x1486), (kernel_ulong_t)&dev_vdata[3] },
37733960accSRijo Thomas 	{ PCI_VDEVICE(AMD, 0x15DF), (kernel_ulong_t)&dev_vdata[4] },
378195ec383SDevaraj Rangasamy 	{ PCI_VDEVICE(AMD, 0x1649), (kernel_ulong_t)&dev_vdata[4] },
379*3438de03SJohn Allen 	{ PCI_VDEVICE(AMD, 0x14CA), (kernel_ulong_t)&dev_vdata[5] },
380d0ebbc0cSBrijesh Singh 	/* Last entry must be zero */
381d0ebbc0cSBrijesh Singh 	{ 0, }
382d0ebbc0cSBrijesh Singh };
383d0ebbc0cSBrijesh Singh MODULE_DEVICE_TABLE(pci, sp_pci_table);
384d0ebbc0cSBrijesh Singh 
385f892a21fSVaibhav Gupta static SIMPLE_DEV_PM_OPS(sp_pci_pm_ops, sp_pci_suspend, sp_pci_resume);
386f892a21fSVaibhav Gupta 
387d0ebbc0cSBrijesh Singh static struct pci_driver sp_pci_driver = {
388d0ebbc0cSBrijesh Singh 	.name = "ccp",
389d0ebbc0cSBrijesh Singh 	.id_table = sp_pci_table,
390d0ebbc0cSBrijesh Singh 	.probe = sp_pci_probe,
391d0ebbc0cSBrijesh Singh 	.remove = sp_pci_remove,
3925441a07aSBrijesh Singh 	.shutdown = sp_pci_shutdown,
393f892a21fSVaibhav Gupta 	.driver.pm = &sp_pci_pm_ops,
394d0ebbc0cSBrijesh Singh };
395d0ebbc0cSBrijesh Singh 
396d0ebbc0cSBrijesh Singh int sp_pci_init(void)
397d0ebbc0cSBrijesh Singh {
398d0ebbc0cSBrijesh Singh 	return pci_register_driver(&sp_pci_driver);
399d0ebbc0cSBrijesh Singh }
400d0ebbc0cSBrijesh Singh 
401d0ebbc0cSBrijesh Singh void sp_pci_exit(void)
402d0ebbc0cSBrijesh Singh {
403d0ebbc0cSBrijesh Singh 	pci_unregister_driver(&sp_pci_driver);
404d0ebbc0cSBrijesh Singh }
405