blob: 5b0790025db3e64131fdd2e95ade8a789df3899b [file] [log] [blame]
Brijesh Singh720419f2017-07-06 09:59:14 -05001/*
2 * AMD Secure Processor driver
3 *
Hook, Garyfa5cd1c2018-12-18 15:48:29 +00004 * Copyright (C) 2017-2018 Advanced Micro Devices, Inc.
Brijesh Singh720419f2017-07-06 09:59:14 -05005 *
6 * Author: Tom Lendacky <thomas.lendacky@amd.com>
7 * Author: Gary R Hook <gary.hook@amd.com>
8 * Author: Brijesh Singh <brijesh.singh@amd.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#ifndef __SP_DEV_H__
16#define __SP_DEV_H__
17
18#include <linux/device.h>
19#include <linux/pci.h>
20#include <linux/spinlock.h>
21#include <linux/mutex.h>
22#include <linux/list.h>
23#include <linux/wait.h>
24#include <linux/dmapool.h>
25#include <linux/hw_random.h>
26#include <linux/bitops.h>
27#include <linux/interrupt.h>
28#include <linux/irqreturn.h>
29
30#define SP_MAX_NAME_LEN 32
31
32#define CACHE_NONE 0x00
33#define CACHE_WB_NO_ALLOC 0xb7
34
35/* Structure to hold CCP device data */
36struct ccp_device;
37struct ccp_vdata {
38 const unsigned int version;
39 const unsigned int dma_chan_attr;
40 void (*setup)(struct ccp_device *);
41 const struct ccp_actions *perform;
42 const unsigned int offset;
Gary R Hooke28c1902017-07-17 15:16:42 -050043 const unsigned int rsamax;
Brijesh Singh720419f2017-07-06 09:59:14 -050044};
Brijesh Singh2a6170d2017-12-04 10:57:28 -060045
46struct psp_vdata {
Tom Lendackyad01a982018-07-03 12:12:03 -050047 const unsigned int cmdresp_reg;
48 const unsigned int cmdbuff_addr_lo_reg;
49 const unsigned int cmdbuff_addr_hi_reg;
50 const unsigned int feature_reg;
51 const unsigned int inten_reg;
52 const unsigned int intsts_reg;
Brijesh Singh2a6170d2017-12-04 10:57:28 -060053};
54
Brijesh Singh720419f2017-07-06 09:59:14 -050055/* Structure to hold SP device data */
56struct sp_dev_vdata {
57 const unsigned int bar;
58
59 const struct ccp_vdata *ccp_vdata;
Brijesh Singh2a6170d2017-12-04 10:57:28 -060060 const struct psp_vdata *psp_vdata;
Brijesh Singh720419f2017-07-06 09:59:14 -050061};
62
63struct sp_device {
64 struct list_head entry;
65
66 struct device *dev;
67
68 struct sp_dev_vdata *dev_vdata;
69 unsigned int ord;
70 char name[SP_MAX_NAME_LEN];
71
72 /* Bus specific device information */
73 void *dev_specific;
74
75 /* I/O area used for device communication. */
76 void __iomem *io_map;
77
78 /* DMA caching attribute support */
79 unsigned int axcache;
80
Brijesh Singh2a6170d2017-12-04 10:57:28 -060081 /* get and set master device */
82 struct sp_device*(*get_psp_master_device)(void);
83 void (*set_psp_master_device)(struct sp_device *);
84
Brijesh Singh720419f2017-07-06 09:59:14 -050085 bool irq_registered;
Brijesh Singhf4d18d62017-07-06 09:59:15 -050086 bool use_tasklet;
Brijesh Singh720419f2017-07-06 09:59:14 -050087
Brijesh Singhf4d18d62017-07-06 09:59:15 -050088 unsigned int ccp_irq;
89 irq_handler_t ccp_irq_handler;
90 void *ccp_irq_data;
91
92 unsigned int psp_irq;
93 irq_handler_t psp_irq_handler;
94 void *psp_irq_data;
Brijesh Singh720419f2017-07-06 09:59:14 -050095
96 void *ccp_data;
97 void *psp_data;
98};
99
100int sp_pci_init(void);
101void sp_pci_exit(void);
102
103int sp_platform_init(void);
104void sp_platform_exit(void);
105
106struct sp_device *sp_alloc_struct(struct device *dev);
107
108int sp_init(struct sp_device *sp);
109void sp_destroy(struct sp_device *sp);
110struct sp_device *sp_get_master(void);
111
112int sp_suspend(struct sp_device *sp, pm_message_t state);
113int sp_resume(struct sp_device *sp);
Brijesh Singhf4d18d62017-07-06 09:59:15 -0500114int sp_request_ccp_irq(struct sp_device *sp, irq_handler_t handler,
115 const char *name, void *data);
116void sp_free_ccp_irq(struct sp_device *sp, void *data);
117int sp_request_psp_irq(struct sp_device *sp, irq_handler_t handler,
118 const char *name, void *data);
119void sp_free_psp_irq(struct sp_device *sp, void *data);
Brijesh Singh2a6170d2017-12-04 10:57:28 -0600120struct sp_device *sp_get_psp_master_device(void);
Brijesh Singh720419f2017-07-06 09:59:14 -0500121
122#ifdef CONFIG_CRYPTO_DEV_SP_CCP
123
124int ccp_dev_init(struct sp_device *sp);
125void ccp_dev_destroy(struct sp_device *sp);
126
127int ccp_dev_suspend(struct sp_device *sp, pm_message_t state);
128int ccp_dev_resume(struct sp_device *sp);
129
130#else /* !CONFIG_CRYPTO_DEV_SP_CCP */
131
132static inline int ccp_dev_init(struct sp_device *sp)
133{
134 return 0;
135}
136static inline void ccp_dev_destroy(struct sp_device *sp) { }
137
138static inline int ccp_dev_suspend(struct sp_device *sp, pm_message_t state)
139{
140 return 0;
141}
142static inline int ccp_dev_resume(struct sp_device *sp)
143{
144 return 0;
145}
146#endif /* CONFIG_CRYPTO_DEV_SP_CCP */
147
Brijesh Singh2a6170d2017-12-04 10:57:28 -0600148#ifdef CONFIG_CRYPTO_DEV_SP_PSP
149
150int psp_dev_init(struct sp_device *sp);
Brijesh Singh200664d2017-12-04 10:57:28 -0600151void psp_pci_init(void);
Brijesh Singh2a6170d2017-12-04 10:57:28 -0600152void psp_dev_destroy(struct sp_device *sp);
Brijesh Singh200664d2017-12-04 10:57:28 -0600153void psp_pci_exit(void);
Brijesh Singh2a6170d2017-12-04 10:57:28 -0600154
155#else /* !CONFIG_CRYPTO_DEV_SP_PSP */
156
157static inline int psp_dev_init(struct sp_device *sp) { return 0; }
Brijesh Singh200664d2017-12-04 10:57:28 -0600158static inline void psp_pci_init(void) { }
Brijesh Singh2a6170d2017-12-04 10:57:28 -0600159static inline void psp_dev_destroy(struct sp_device *sp) { }
Brijesh Singh200664d2017-12-04 10:57:28 -0600160static inline void psp_pci_exit(void) { }
Brijesh Singh2a6170d2017-12-04 10:57:28 -0600161
162#endif /* CONFIG_CRYPTO_DEV_SP_PSP */
163
Brijesh Singh720419f2017-07-06 09:59:14 -0500164#endif