Linux Audio

Check our new training course

Loading...
v6.2
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * AMD Secure Processor device driver
  4 *
  5 * Copyright (C) 2013,2019 Advanced Micro Devices, Inc.
  6 *
  7 * Author: Tom Lendacky <thomas.lendacky@amd.com>
  8 * Author: Gary R Hook <gary.hook@amd.com>
 
 
 
 
  9 */
 10
 11#include <linux/module.h>
 12#include <linux/kernel.h>
 13#include <linux/device.h>
 14#include <linux/pci.h>
 15#include <linux/pci_ids.h>
 16#include <linux/dma-mapping.h>
 17#include <linux/kthread.h>
 18#include <linux/sched.h>
 19#include <linux/interrupt.h>
 20#include <linux/spinlock.h>
 21#include <linux/delay.h>
 22#include <linux/ccp.h>
 23
 24#include "ccp-dev.h"
 25#include "psp-dev.h"
 26
 27#define MSIX_VECTORS			2
 28
 29struct sp_pci {
 30	int msix_count;
 31	struct msix_entry msix_entry[MSIX_VECTORS];
 32};
 33static struct sp_device *sp_dev_master;
 34
 35#define attribute_show(name, def)						\
 36static ssize_t name##_show(struct device *d, struct device_attribute *attr,	\
 37			   char *buf)						\
 38{										\
 39	struct sp_device *sp = dev_get_drvdata(d);				\
 40	struct psp_device *psp = sp->psp_data;					\
 41	int bit = PSP_SECURITY_##def << PSP_CAPABILITY_PSP_SECURITY_OFFSET;	\
 42	return sysfs_emit(buf, "%d\n", (psp->capability & bit) > 0);		\
 43}
 44
 45attribute_show(fused_part, FUSED_PART)
 46static DEVICE_ATTR_RO(fused_part);
 47attribute_show(debug_lock_on, DEBUG_LOCK_ON)
 48static DEVICE_ATTR_RO(debug_lock_on);
 49attribute_show(tsme_status, TSME_STATUS)
 50static DEVICE_ATTR_RO(tsme_status);
 51attribute_show(anti_rollback_status, ANTI_ROLLBACK_STATUS)
 52static DEVICE_ATTR_RO(anti_rollback_status);
 53attribute_show(rpmc_production_enabled, RPMC_PRODUCTION_ENABLED)
 54static DEVICE_ATTR_RO(rpmc_production_enabled);
 55attribute_show(rpmc_spirom_available, RPMC_SPIROM_AVAILABLE)
 56static DEVICE_ATTR_RO(rpmc_spirom_available);
 57attribute_show(hsp_tpm_available, HSP_TPM_AVAILABLE)
 58static DEVICE_ATTR_RO(hsp_tpm_available);
 59attribute_show(rom_armor_enforced, ROM_ARMOR_ENFORCED)
 60static DEVICE_ATTR_RO(rom_armor_enforced);
 61
 62static struct attribute *psp_attrs[] = {
 63	&dev_attr_fused_part.attr,
 64	&dev_attr_debug_lock_on.attr,
 65	&dev_attr_tsme_status.attr,
 66	&dev_attr_anti_rollback_status.attr,
 67	&dev_attr_rpmc_production_enabled.attr,
 68	&dev_attr_rpmc_spirom_available.attr,
 69	&dev_attr_hsp_tpm_available.attr,
 70	&dev_attr_rom_armor_enforced.attr,
 71	NULL
 72};
 73
 74static umode_t psp_security_is_visible(struct kobject *kobj, struct attribute *attr, int idx)
 75{
 76	struct device *dev = kobj_to_dev(kobj);
 77	struct sp_device *sp = dev_get_drvdata(dev);
 78	struct psp_device *psp = sp->psp_data;
 79
 80	if (psp && (psp->capability & PSP_CAPABILITY_PSP_SECURITY_REPORTING))
 81		return 0444;
 82
 83	return 0;
 84}
 85
 86static struct attribute_group psp_attr_group = {
 87	.attrs = psp_attrs,
 88	.is_visible = psp_security_is_visible,
 89};
 90
 91static const struct attribute_group *psp_groups[] = {
 92	&psp_attr_group,
 93	NULL,
 94};
 95
 96static int sp_get_msix_irqs(struct sp_device *sp)
 97{
 98	struct sp_pci *sp_pci = sp->dev_specific;
 99	struct device *dev = sp->dev;
100	struct pci_dev *pdev = to_pci_dev(dev);
101	int v, ret;
102
103	for (v = 0; v < ARRAY_SIZE(sp_pci->msix_entry); v++)
104		sp_pci->msix_entry[v].entry = v;
105
106	ret = pci_enable_msix_range(pdev, sp_pci->msix_entry, 1, v);
107	if (ret < 0)
108		return ret;
109
110	sp_pci->msix_count = ret;
111	sp->use_tasklet = true;
112
113	sp->psp_irq = sp_pci->msix_entry[0].vector;
114	sp->ccp_irq = (sp_pci->msix_count > 1) ? sp_pci->msix_entry[1].vector
115					       : sp_pci->msix_entry[0].vector;
116	return 0;
117}
118
119static int sp_get_msi_irq(struct sp_device *sp)
120{
121	struct device *dev = sp->dev;
122	struct pci_dev *pdev = to_pci_dev(dev);
123	int ret;
124
125	ret = pci_enable_msi(pdev);
126	if (ret)
127		return ret;
128
129	sp->ccp_irq = pdev->irq;
130	sp->psp_irq = pdev->irq;
131
132	return 0;
133}
134
135static int sp_get_irqs(struct sp_device *sp)
136{
137	struct device *dev = sp->dev;
138	int ret;
139
140	ret = sp_get_msix_irqs(sp);
141	if (!ret)
142		return 0;
143
144	/* Couldn't get MSI-X vectors, try MSI */
145	dev_notice(dev, "could not enable MSI-X (%d), trying MSI\n", ret);
146	ret = sp_get_msi_irq(sp);
147	if (!ret)
148		return 0;
149
150	/* Couldn't get MSI interrupt */
151	dev_notice(dev, "could not enable MSI (%d)\n", ret);
152
153	return ret;
154}
155
156static void sp_free_irqs(struct sp_device *sp)
157{
158	struct sp_pci *sp_pci = sp->dev_specific;
159	struct device *dev = sp->dev;
160	struct pci_dev *pdev = to_pci_dev(dev);
161
162	if (sp_pci->msix_count)
163		pci_disable_msix(pdev);
164	else if (sp->psp_irq)
165		pci_disable_msi(pdev);
166
167	sp->ccp_irq = 0;
168	sp->psp_irq = 0;
169}
170
171static bool sp_pci_is_master(struct sp_device *sp)
172{
173	struct device *dev_cur, *dev_new;
174	struct pci_dev *pdev_cur, *pdev_new;
175
176	dev_new = sp->dev;
177	dev_cur = sp_dev_master->dev;
178
179	pdev_new = to_pci_dev(dev_new);
180	pdev_cur = to_pci_dev(dev_cur);
181
182	if (pdev_new->bus->number < pdev_cur->bus->number)
183		return true;
184
185	if (PCI_SLOT(pdev_new->devfn) < PCI_SLOT(pdev_cur->devfn))
186		return true;
187
188	if (PCI_FUNC(pdev_new->devfn) < PCI_FUNC(pdev_cur->devfn))
189		return true;
190
191	return false;
192}
193
194static void psp_set_master(struct sp_device *sp)
195{
196	if (!sp_dev_master) {
197		sp_dev_master = sp;
198		return;
199	}
200
201	if (sp_pci_is_master(sp))
202		sp_dev_master = sp;
203}
204
205static struct sp_device *psp_get_master(void)
206{
207	return sp_dev_master;
208}
209
210static void psp_clear_master(struct sp_device *sp)
211{
212	if (sp == sp_dev_master) {
213		sp_dev_master = NULL;
214		dev_dbg(sp->dev, "Cleared sp_dev_master\n");
215	}
216}
217
218static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
219{
220	struct sp_device *sp;
221	struct sp_pci *sp_pci;
222	struct device *dev = &pdev->dev;
223	void __iomem * const *iomap_table;
224	int bar_mask;
225	int ret;
226
227	ret = -ENOMEM;
228	sp = sp_alloc_struct(dev);
229	if (!sp)
230		goto e_err;
231
232	sp_pci = devm_kzalloc(dev, sizeof(*sp_pci), GFP_KERNEL);
233	if (!sp_pci)
234		goto e_err;
235
236	sp->dev_specific = sp_pci;
237	sp->dev_vdata = (struct sp_dev_vdata *)id->driver_data;
238	if (!sp->dev_vdata) {
239		ret = -ENODEV;
240		dev_err(dev, "missing driver data\n");
241		goto e_err;
242	}
243
244	ret = pcim_enable_device(pdev);
245	if (ret) {
246		dev_err(dev, "pcim_enable_device failed (%d)\n", ret);
247		goto e_err;
248	}
249
250	bar_mask = pci_select_bars(pdev, IORESOURCE_MEM);
251	ret = pcim_iomap_regions(pdev, bar_mask, "ccp");
252	if (ret) {
253		dev_err(dev, "pcim_iomap_regions failed (%d)\n", ret);
254		goto e_err;
255	}
256
257	iomap_table = pcim_iomap_table(pdev);
258	if (!iomap_table) {
259		dev_err(dev, "pcim_iomap_table failed\n");
260		ret = -ENOMEM;
261		goto e_err;
262	}
263
264	sp->io_map = iomap_table[sp->dev_vdata->bar];
265	if (!sp->io_map) {
266		dev_err(dev, "ioremap failed\n");
267		ret = -ENOMEM;
268		goto e_err;
269	}
270
271	ret = sp_get_irqs(sp);
272	if (ret)
273		goto e_err;
274
275	pci_set_master(pdev);
276	sp->set_psp_master_device = psp_set_master;
277	sp->get_psp_master_device = psp_get_master;
278	sp->clear_psp_master_device = psp_clear_master;
279
280	ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48));
281	if (ret) {
282		ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
283		if (ret) {
284			dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n",
285				ret);
286			goto free_irqs;
287		}
288	}
289
290	dev_set_drvdata(dev, sp);
291
292	ret = sp_init(sp);
293	if (ret)
294		goto free_irqs;
 
 
295
296	return 0;
297
298free_irqs:
299	sp_free_irqs(sp);
300e_err:
301	dev_notice(dev, "initialization failed\n");
302	return ret;
303}
304
305static void sp_pci_shutdown(struct pci_dev *pdev)
306{
307	struct device *dev = &pdev->dev;
308	struct sp_device *sp = dev_get_drvdata(dev);
309
310	if (!sp)
311		return;
312
313	sp_destroy(sp);
314}
315
316static void sp_pci_remove(struct pci_dev *pdev)
317{
318	struct device *dev = &pdev->dev;
319	struct sp_device *sp = dev_get_drvdata(dev);
320
321	if (!sp)
322		return;
323
324	sp_destroy(sp);
325
326	sp_free_irqs(sp);
 
 
327}
328
329static int __maybe_unused sp_pci_suspend(struct device *dev)
 
330{
 
331	struct sp_device *sp = dev_get_drvdata(dev);
332
333	return sp_suspend(sp);
334}
335
336static int __maybe_unused sp_pci_resume(struct device *dev)
337{
 
338	struct sp_device *sp = dev_get_drvdata(dev);
339
340	return sp_resume(sp);
341}
 
342
343#ifdef CONFIG_CRYPTO_DEV_SP_PSP
344static const struct sev_vdata sevv1 = {
345	.cmdresp_reg		= 0x10580,
346	.cmdbuff_addr_lo_reg	= 0x105e0,
347	.cmdbuff_addr_hi_reg	= 0x105e4,
348};
349
350static const struct sev_vdata sevv2 = {
351	.cmdresp_reg		= 0x10980,
352	.cmdbuff_addr_lo_reg	= 0x109e0,
353	.cmdbuff_addr_hi_reg	= 0x109e4,
354};
355
356static const struct tee_vdata teev1 = {
357	.cmdresp_reg		= 0x10544,
358	.cmdbuff_addr_lo_reg	= 0x10548,
359	.cmdbuff_addr_hi_reg	= 0x1054c,
360	.ring_wptr_reg          = 0x10550,
361	.ring_rptr_reg          = 0x10554,
362};
363
364static const struct psp_vdata pspv1 = {
365	.sev			= &sevv1,
366	.feature_reg		= 0x105fc,
367	.inten_reg		= 0x10610,
368	.intsts_reg		= 0x10614,
369};
370
371static const struct psp_vdata pspv2 = {
372	.sev			= &sevv2,
373	.feature_reg		= 0x109fc,
374	.inten_reg		= 0x10690,
375	.intsts_reg		= 0x10694,
376};
377
378static const struct psp_vdata pspv3 = {
379	.tee			= &teev1,
380	.feature_reg		= 0x109fc,
381	.inten_reg		= 0x10690,
382	.intsts_reg		= 0x10694,
383};
384
385static const struct psp_vdata pspv4 = {
386	.sev			= &sevv2,
387	.tee			= &teev1,
388	.feature_reg		= 0x109fc,
389	.inten_reg		= 0x10690,
390	.intsts_reg		= 0x10694,
391};
392
393#endif
394
395static const struct sp_dev_vdata dev_vdata[] = {
396	{	/* 0 */
397		.bar = 2,
398#ifdef CONFIG_CRYPTO_DEV_SP_CCP
399		.ccp_vdata = &ccpv3,
400#endif
401	},
402	{	/* 1 */
403		.bar = 2,
404#ifdef CONFIG_CRYPTO_DEV_SP_CCP
405		.ccp_vdata = &ccpv5a,
406#endif
407#ifdef CONFIG_CRYPTO_DEV_SP_PSP
408		.psp_vdata = &pspv1,
409#endif
410	},
411	{	/* 2 */
412		.bar = 2,
413#ifdef CONFIG_CRYPTO_DEV_SP_CCP
414		.ccp_vdata = &ccpv5b,
415#endif
416	},
417	{	/* 3 */
418		.bar = 2,
419#ifdef CONFIG_CRYPTO_DEV_SP_CCP
420		.ccp_vdata = &ccpv5a,
421#endif
422#ifdef CONFIG_CRYPTO_DEV_SP_PSP
423		.psp_vdata = &pspv2,
424#endif
425	},
426	{	/* 4 */
427		.bar = 2,
428#ifdef CONFIG_CRYPTO_DEV_SP_CCP
429		.ccp_vdata = &ccpv5a,
430#endif
431#ifdef CONFIG_CRYPTO_DEV_SP_PSP
432		.psp_vdata = &pspv3,
433#endif
434	},
435	{	/* 5 */
436		.bar = 2,
437#ifdef CONFIG_CRYPTO_DEV_SP_PSP
438		.psp_vdata = &pspv4,
439#endif
440	},
441	{	/* 6 */
442		.bar = 2,
443#ifdef CONFIG_CRYPTO_DEV_SP_PSP
444		.psp_vdata = &pspv3,
445#endif
446	},
447};
448static const struct pci_device_id sp_pci_table[] = {
449	{ PCI_VDEVICE(AMD, 0x1537), (kernel_ulong_t)&dev_vdata[0] },
450	{ PCI_VDEVICE(AMD, 0x1456), (kernel_ulong_t)&dev_vdata[1] },
451	{ PCI_VDEVICE(AMD, 0x1468), (kernel_ulong_t)&dev_vdata[2] },
452	{ PCI_VDEVICE(AMD, 0x1486), (kernel_ulong_t)&dev_vdata[3] },
453	{ PCI_VDEVICE(AMD, 0x15DF), (kernel_ulong_t)&dev_vdata[4] },
454	{ PCI_VDEVICE(AMD, 0x1649), (kernel_ulong_t)&dev_vdata[4] },
455	{ PCI_VDEVICE(AMD, 0x14CA), (kernel_ulong_t)&dev_vdata[5] },
456	{ PCI_VDEVICE(AMD, 0x15C7), (kernel_ulong_t)&dev_vdata[6] },
457	/* Last entry must be zero */
458	{ 0, }
459};
460MODULE_DEVICE_TABLE(pci, sp_pci_table);
461
462static SIMPLE_DEV_PM_OPS(sp_pci_pm_ops, sp_pci_suspend, sp_pci_resume);
463
464static struct pci_driver sp_pci_driver = {
465	.name = "ccp",
466	.id_table = sp_pci_table,
467	.probe = sp_pci_probe,
468	.remove = sp_pci_remove,
469	.shutdown = sp_pci_shutdown,
470	.driver.pm = &sp_pci_pm_ops,
471	.dev_groups = psp_groups,
 
472};
473
474int sp_pci_init(void)
475{
476	return pci_register_driver(&sp_pci_driver);
477}
478
479void sp_pci_exit(void)
480{
481	pci_unregister_driver(&sp_pci_driver);
482}
v4.17
 
  1/*
  2 * AMD Secure Processor device driver
  3 *
  4 * Copyright (C) 2013,2016 Advanced Micro Devices, Inc.
  5 *
  6 * Author: Tom Lendacky <thomas.lendacky@amd.com>
  7 * Author: Gary R Hook <gary.hook@amd.com>
  8 *
  9 * This program is free software; you can redistribute it and/or modify
 10 * it under the terms of the GNU General Public License version 2 as
 11 * published by the Free Software Foundation.
 12 */
 13
 14#include <linux/module.h>
 15#include <linux/kernel.h>
 16#include <linux/device.h>
 17#include <linux/pci.h>
 18#include <linux/pci_ids.h>
 19#include <linux/dma-mapping.h>
 20#include <linux/kthread.h>
 21#include <linux/sched.h>
 22#include <linux/interrupt.h>
 23#include <linux/spinlock.h>
 24#include <linux/delay.h>
 25#include <linux/ccp.h>
 26
 27#include "ccp-dev.h"
 28#include "psp-dev.h"
 29
 30#define MSIX_VECTORS			2
 31
 32struct sp_pci {
 33	int msix_count;
 34	struct msix_entry msix_entry[MSIX_VECTORS];
 35};
 36static struct sp_device *sp_dev_master;
 37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 38static int sp_get_msix_irqs(struct sp_device *sp)
 39{
 40	struct sp_pci *sp_pci = sp->dev_specific;
 41	struct device *dev = sp->dev;
 42	struct pci_dev *pdev = to_pci_dev(dev);
 43	int v, ret;
 44
 45	for (v = 0; v < ARRAY_SIZE(sp_pci->msix_entry); v++)
 46		sp_pci->msix_entry[v].entry = v;
 47
 48	ret = pci_enable_msix_range(pdev, sp_pci->msix_entry, 1, v);
 49	if (ret < 0)
 50		return ret;
 51
 52	sp_pci->msix_count = ret;
 53	sp->use_tasklet = true;
 54
 55	sp->psp_irq = sp_pci->msix_entry[0].vector;
 56	sp->ccp_irq = (sp_pci->msix_count > 1) ? sp_pci->msix_entry[1].vector
 57					       : sp_pci->msix_entry[0].vector;
 58	return 0;
 59}
 60
 61static int sp_get_msi_irq(struct sp_device *sp)
 62{
 63	struct device *dev = sp->dev;
 64	struct pci_dev *pdev = to_pci_dev(dev);
 65	int ret;
 66
 67	ret = pci_enable_msi(pdev);
 68	if (ret)
 69		return ret;
 70
 71	sp->ccp_irq = pdev->irq;
 72	sp->psp_irq = pdev->irq;
 73
 74	return 0;
 75}
 76
 77static int sp_get_irqs(struct sp_device *sp)
 78{
 79	struct device *dev = sp->dev;
 80	int ret;
 81
 82	ret = sp_get_msix_irqs(sp);
 83	if (!ret)
 84		return 0;
 85
 86	/* Couldn't get MSI-X vectors, try MSI */
 87	dev_notice(dev, "could not enable MSI-X (%d), trying MSI\n", ret);
 88	ret = sp_get_msi_irq(sp);
 89	if (!ret)
 90		return 0;
 91
 92	/* Couldn't get MSI interrupt */
 93	dev_notice(dev, "could not enable MSI (%d)\n", ret);
 94
 95	return ret;
 96}
 97
 98static void sp_free_irqs(struct sp_device *sp)
 99{
100	struct sp_pci *sp_pci = sp->dev_specific;
101	struct device *dev = sp->dev;
102	struct pci_dev *pdev = to_pci_dev(dev);
103
104	if (sp_pci->msix_count)
105		pci_disable_msix(pdev);
106	else if (sp->psp_irq)
107		pci_disable_msi(pdev);
108
109	sp->ccp_irq = 0;
110	sp->psp_irq = 0;
111}
112
113static bool sp_pci_is_master(struct sp_device *sp)
114{
115	struct device *dev_cur, *dev_new;
116	struct pci_dev *pdev_cur, *pdev_new;
117
118	dev_new = sp->dev;
119	dev_cur = sp_dev_master->dev;
120
121	pdev_new = to_pci_dev(dev_new);
122	pdev_cur = to_pci_dev(dev_cur);
123
124	if (pdev_new->bus->number < pdev_cur->bus->number)
125		return true;
126
127	if (PCI_SLOT(pdev_new->devfn) < PCI_SLOT(pdev_cur->devfn))
128		return true;
129
130	if (PCI_FUNC(pdev_new->devfn) < PCI_FUNC(pdev_cur->devfn))
131		return true;
132
133	return false;
134}
135
136static void psp_set_master(struct sp_device *sp)
137{
138	if (!sp_dev_master) {
139		sp_dev_master = sp;
140		return;
141	}
142
143	if (sp_pci_is_master(sp))
144		sp_dev_master = sp;
145}
146
147static struct sp_device *psp_get_master(void)
148{
149	return sp_dev_master;
150}
151
 
 
 
 
 
 
 
 
152static int sp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
153{
154	struct sp_device *sp;
155	struct sp_pci *sp_pci;
156	struct device *dev = &pdev->dev;
157	void __iomem * const *iomap_table;
158	int bar_mask;
159	int ret;
160
161	ret = -ENOMEM;
162	sp = sp_alloc_struct(dev);
163	if (!sp)
164		goto e_err;
165
166	sp_pci = devm_kzalloc(dev, sizeof(*sp_pci), GFP_KERNEL);
167	if (!sp_pci)
168		goto e_err;
169
170	sp->dev_specific = sp_pci;
171	sp->dev_vdata = (struct sp_dev_vdata *)id->driver_data;
172	if (!sp->dev_vdata) {
173		ret = -ENODEV;
174		dev_err(dev, "missing driver data\n");
175		goto e_err;
176	}
177
178	ret = pcim_enable_device(pdev);
179	if (ret) {
180		dev_err(dev, "pcim_enable_device failed (%d)\n", ret);
181		goto e_err;
182	}
183
184	bar_mask = pci_select_bars(pdev, IORESOURCE_MEM);
185	ret = pcim_iomap_regions(pdev, bar_mask, "ccp");
186	if (ret) {
187		dev_err(dev, "pcim_iomap_regions failed (%d)\n", ret);
188		goto e_err;
189	}
190
191	iomap_table = pcim_iomap_table(pdev);
192	if (!iomap_table) {
193		dev_err(dev, "pcim_iomap_table failed\n");
194		ret = -ENOMEM;
195		goto e_err;
196	}
197
198	sp->io_map = iomap_table[sp->dev_vdata->bar];
199	if (!sp->io_map) {
200		dev_err(dev, "ioremap failed\n");
201		ret = -ENOMEM;
202		goto e_err;
203	}
204
205	ret = sp_get_irqs(sp);
206	if (ret)
207		goto e_err;
208
209	pci_set_master(pdev);
210	sp->set_psp_master_device = psp_set_master;
211	sp->get_psp_master_device = psp_get_master;
 
212
213	ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48));
214	if (ret) {
215		ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
216		if (ret) {
217			dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n",
218				ret);
219			goto e_err;
220		}
221	}
222
223	dev_set_drvdata(dev, sp);
224
225	ret = sp_init(sp);
226	if (ret)
227		goto e_err;
228
229	dev_notice(dev, "enabled\n");
230
231	return 0;
232
 
 
233e_err:
234	dev_notice(dev, "initialization failed\n");
235	return ret;
236}
237
 
 
 
 
 
 
 
 
 
 
 
238static void sp_pci_remove(struct pci_dev *pdev)
239{
240	struct device *dev = &pdev->dev;
241	struct sp_device *sp = dev_get_drvdata(dev);
242
243	if (!sp)
244		return;
245
246	sp_destroy(sp);
247
248	sp_free_irqs(sp);
249
250	dev_notice(dev, "disabled\n");
251}
252
253#ifdef CONFIG_PM
254static int sp_pci_suspend(struct pci_dev *pdev, pm_message_t state)
255{
256	struct device *dev = &pdev->dev;
257	struct sp_device *sp = dev_get_drvdata(dev);
258
259	return sp_suspend(sp, state);
260}
261
262static int sp_pci_resume(struct pci_dev *pdev)
263{
264	struct device *dev = &pdev->dev;
265	struct sp_device *sp = dev_get_drvdata(dev);
266
267	return sp_resume(sp);
268}
269#endif
270
271#ifdef CONFIG_CRYPTO_DEV_SP_PSP
272static const struct psp_vdata psp_entry = {
273	.offset = 0x10500,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274};
 
 
 
 
 
 
 
 
 
275#endif
276
277static const struct sp_dev_vdata dev_vdata[] = {
278	{
279		.bar = 2,
280#ifdef CONFIG_CRYPTO_DEV_SP_CCP
281		.ccp_vdata = &ccpv3,
282#endif
283	},
284	{
285		.bar = 2,
286#ifdef CONFIG_CRYPTO_DEV_SP_CCP
287		.ccp_vdata = &ccpv5a,
288#endif
289#ifdef CONFIG_CRYPTO_DEV_SP_PSP
290		.psp_vdata = &psp_entry
291#endif
292	},
293	{
294		.bar = 2,
295#ifdef CONFIG_CRYPTO_DEV_SP_CCP
296		.ccp_vdata = &ccpv5b,
297#endif
298	},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299};
300static const struct pci_device_id sp_pci_table[] = {
301	{ PCI_VDEVICE(AMD, 0x1537), (kernel_ulong_t)&dev_vdata[0] },
302	{ PCI_VDEVICE(AMD, 0x1456), (kernel_ulong_t)&dev_vdata[1] },
303	{ PCI_VDEVICE(AMD, 0x1468), (kernel_ulong_t)&dev_vdata[2] },
 
 
 
 
 
304	/* Last entry must be zero */
305	{ 0, }
306};
307MODULE_DEVICE_TABLE(pci, sp_pci_table);
308
 
 
309static struct pci_driver sp_pci_driver = {
310	.name = "ccp",
311	.id_table = sp_pci_table,
312	.probe = sp_pci_probe,
313	.remove = sp_pci_remove,
314#ifdef CONFIG_PM
315	.suspend = sp_pci_suspend,
316	.resume = sp_pci_resume,
317#endif
318};
319
320int sp_pci_init(void)
321{
322	return pci_register_driver(&sp_pci_driver);
323}
324
325void sp_pci_exit(void)
326{
327	pci_unregister_driver(&sp_pci_driver);
328}