xref: /openbmc/linux/drivers/crypto/ccp/sp-dev.h (revision 12109610)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * AMD Secure Processor driver
4  *
5  * Copyright (C) 2017-2019 Advanced Micro Devices, Inc.
6  *
7  * Author: Tom Lendacky <thomas.lendacky@amd.com>
8  * Author: Gary R Hook <gary.hook@amd.com>
9  * Author: Brijesh Singh <brijesh.singh@amd.com>
10  */
11 
12 #ifndef __SP_DEV_H__
13 #define __SP_DEV_H__
14 
15 #include <linux/device.h>
16 #include <linux/spinlock.h>
17 #include <linux/mutex.h>
18 #include <linux/list.h>
19 #include <linux/wait.h>
20 #include <linux/dmapool.h>
21 #include <linux/hw_random.h>
22 #include <linux/bitops.h>
23 #include <linux/interrupt.h>
24 #include <linux/irqreturn.h>
25 
26 #define SP_MAX_NAME_LEN		32
27 
28 #define CACHE_NONE			0x00
29 #define CACHE_WB_NO_ALLOC		0xb7
30 
31 /* Structure to hold CCP device data */
32 struct ccp_device;
33 struct ccp_vdata {
34 	const unsigned int version;
35 	const unsigned int dma_chan_attr;
36 	void (*setup)(struct ccp_device *);
37 	const struct ccp_actions *perform;
38 	const unsigned int offset;
39 	const unsigned int rsamax;
40 };
41 
42 struct sev_vdata {
43 	const unsigned int cmdresp_reg;
44 	const unsigned int cmdbuff_addr_lo_reg;
45 	const unsigned int cmdbuff_addr_hi_reg;
46 };
47 
48 struct tee_vdata {
49 	const unsigned int cmdresp_reg;
50 	const unsigned int cmdbuff_addr_lo_reg;
51 	const unsigned int cmdbuff_addr_hi_reg;
52 	const unsigned int ring_wptr_reg;
53 	const unsigned int ring_rptr_reg;
54 };
55 
56 struct platform_access_vdata {
57 	const unsigned int cmdresp_reg;
58 	const unsigned int cmdbuff_addr_lo_reg;
59 	const unsigned int cmdbuff_addr_hi_reg;
60 	const unsigned int doorbell_button_reg;
61 	const unsigned int doorbell_cmd_reg;
62 
63 };
64 
65 struct psp_vdata {
66 	const struct sev_vdata *sev;
67 	const struct tee_vdata *tee;
68 	const struct platform_access_vdata *platform_access;
69 	const unsigned int feature_reg;
70 	const unsigned int inten_reg;
71 	const unsigned int intsts_reg;
72 };
73 
74 /* Structure to hold SP device data */
75 struct sp_dev_vdata {
76 	const unsigned int bar;
77 
78 	const struct ccp_vdata *ccp_vdata;
79 	const struct psp_vdata *psp_vdata;
80 };
81 
82 struct sp_device {
83 	struct list_head entry;
84 
85 	struct device *dev;
86 
87 	struct sp_dev_vdata *dev_vdata;
88 	unsigned int ord;
89 	char name[SP_MAX_NAME_LEN];
90 
91 	/* Bus specific device information */
92 	void *dev_specific;
93 
94 	/* I/O area used for device communication. */
95 	void __iomem *io_map;
96 
97 	/* DMA caching attribute support */
98 	unsigned int axcache;
99 
100 	/* get and set master device */
101 	struct sp_device*(*get_psp_master_device)(void);
102 	void (*set_psp_master_device)(struct sp_device *);
103 	void (*clear_psp_master_device)(struct sp_device *);
104 
105 	bool irq_registered;
106 	bool use_tasklet;
107 
108 	unsigned int ccp_irq;
109 	irq_handler_t ccp_irq_handler;
110 	void *ccp_irq_data;
111 
112 	unsigned int psp_irq;
113 	irq_handler_t psp_irq_handler;
114 	void *psp_irq_data;
115 
116 	void *ccp_data;
117 	void *psp_data;
118 };
119 
120 int sp_pci_init(void);
121 void sp_pci_exit(void);
122 
123 int sp_platform_init(void);
124 void sp_platform_exit(void);
125 
126 struct sp_device *sp_alloc_struct(struct device *dev);
127 
128 int sp_init(struct sp_device *sp);
129 void sp_destroy(struct sp_device *sp);
130 struct sp_device *sp_get_master(void);
131 
132 int sp_suspend(struct sp_device *sp);
133 int sp_resume(struct sp_device *sp);
134 int sp_request_ccp_irq(struct sp_device *sp, irq_handler_t handler,
135 		       const char *name, void *data);
136 void sp_free_ccp_irq(struct sp_device *sp, void *data);
137 int sp_request_psp_irq(struct sp_device *sp, irq_handler_t handler,
138 		       const char *name, void *data);
139 void sp_free_psp_irq(struct sp_device *sp, void *data);
140 struct sp_device *sp_get_psp_master_device(void);
141 
142 #ifdef CONFIG_CRYPTO_DEV_SP_CCP
143 
144 int ccp_dev_init(struct sp_device *sp);
145 void ccp_dev_destroy(struct sp_device *sp);
146 
147 void ccp_dev_suspend(struct sp_device *sp);
148 void ccp_dev_resume(struct sp_device *sp);
149 
150 #else	/* !CONFIG_CRYPTO_DEV_SP_CCP */
151 
152 static inline int ccp_dev_init(struct sp_device *sp)
153 {
154 	return 0;
155 }
156 static inline void ccp_dev_destroy(struct sp_device *sp) { }
157 static inline void ccp_dev_suspend(struct sp_device *sp) { }
158 static inline void ccp_dev_resume(struct sp_device *sp) { }
159 #endif	/* CONFIG_CRYPTO_DEV_SP_CCP */
160 
161 #ifdef CONFIG_CRYPTO_DEV_SP_PSP
162 
163 int psp_dev_init(struct sp_device *sp);
164 void psp_pci_init(void);
165 void psp_dev_destroy(struct sp_device *sp);
166 void psp_pci_exit(void);
167 
168 #else /* !CONFIG_CRYPTO_DEV_SP_PSP */
169 
170 static inline int psp_dev_init(struct sp_device *sp) { return 0; }
171 static inline void psp_pci_init(void) { }
172 static inline void psp_dev_destroy(struct sp_device *sp) { }
173 static inline void psp_pci_exit(void) { }
174 
175 #endif /* CONFIG_CRYPTO_DEV_SP_PSP */
176 
177 #endif
178