xref: /openbmc/linux/drivers/crypto/ccp/sp-dev.h (revision 20e2fc42)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * AMD Secure Processor driver
4  *
5  * Copyright (C) 2017-2018 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 psp_vdata {
43 	const unsigned int cmdresp_reg;
44 	const unsigned int cmdbuff_addr_lo_reg;
45 	const unsigned int cmdbuff_addr_hi_reg;
46 	const unsigned int feature_reg;
47 	const unsigned int inten_reg;
48 	const unsigned int intsts_reg;
49 };
50 
51 /* Structure to hold SP device data */
52 struct sp_dev_vdata {
53 	const unsigned int bar;
54 
55 	const struct ccp_vdata *ccp_vdata;
56 	const struct psp_vdata *psp_vdata;
57 };
58 
59 struct sp_device {
60 	struct list_head entry;
61 
62 	struct device *dev;
63 
64 	struct sp_dev_vdata *dev_vdata;
65 	unsigned int ord;
66 	char name[SP_MAX_NAME_LEN];
67 
68 	/* Bus specific device information */
69 	void *dev_specific;
70 
71 	/* I/O area used for device communication. */
72 	void __iomem *io_map;
73 
74 	/* DMA caching attribute support */
75 	unsigned int axcache;
76 
77 	/* get and set master device */
78 	struct sp_device*(*get_psp_master_device)(void);
79 	void (*set_psp_master_device)(struct sp_device *);
80 
81 	bool irq_registered;
82 	bool use_tasklet;
83 
84 	unsigned int ccp_irq;
85 	irq_handler_t ccp_irq_handler;
86 	void *ccp_irq_data;
87 
88 	unsigned int psp_irq;
89 	irq_handler_t psp_irq_handler;
90 	void *psp_irq_data;
91 
92 	void *ccp_data;
93 	void *psp_data;
94 };
95 
96 int sp_pci_init(void);
97 void sp_pci_exit(void);
98 
99 int sp_platform_init(void);
100 void sp_platform_exit(void);
101 
102 struct sp_device *sp_alloc_struct(struct device *dev);
103 
104 int sp_init(struct sp_device *sp);
105 void sp_destroy(struct sp_device *sp);
106 struct sp_device *sp_get_master(void);
107 
108 int sp_suspend(struct sp_device *sp, pm_message_t state);
109 int sp_resume(struct sp_device *sp);
110 int sp_request_ccp_irq(struct sp_device *sp, irq_handler_t handler,
111 		       const char *name, void *data);
112 void sp_free_ccp_irq(struct sp_device *sp, void *data);
113 int sp_request_psp_irq(struct sp_device *sp, irq_handler_t handler,
114 		       const char *name, void *data);
115 void sp_free_psp_irq(struct sp_device *sp, void *data);
116 struct sp_device *sp_get_psp_master_device(void);
117 
118 #ifdef CONFIG_CRYPTO_DEV_SP_CCP
119 
120 int ccp_dev_init(struct sp_device *sp);
121 void ccp_dev_destroy(struct sp_device *sp);
122 
123 int ccp_dev_suspend(struct sp_device *sp, pm_message_t state);
124 int ccp_dev_resume(struct sp_device *sp);
125 
126 #else	/* !CONFIG_CRYPTO_DEV_SP_CCP */
127 
128 static inline int ccp_dev_init(struct sp_device *sp)
129 {
130 	return 0;
131 }
132 static inline void ccp_dev_destroy(struct sp_device *sp) { }
133 
134 static inline int ccp_dev_suspend(struct sp_device *sp, pm_message_t state)
135 {
136 	return 0;
137 }
138 static inline int ccp_dev_resume(struct sp_device *sp)
139 {
140 	return 0;
141 }
142 #endif	/* CONFIG_CRYPTO_DEV_SP_CCP */
143 
144 #ifdef CONFIG_CRYPTO_DEV_SP_PSP
145 
146 int psp_dev_init(struct sp_device *sp);
147 void psp_pci_init(void);
148 void psp_dev_destroy(struct sp_device *sp);
149 void psp_pci_exit(void);
150 
151 #else /* !CONFIG_CRYPTO_DEV_SP_PSP */
152 
153 static inline int psp_dev_init(struct sp_device *sp) { return 0; }
154 static inline void psp_pci_init(void) { }
155 static inline void psp_dev_destroy(struct sp_device *sp) { }
156 static inline void psp_pci_exit(void) { }
157 
158 #endif /* CONFIG_CRYPTO_DEV_SP_PSP */
159 
160 #endif
161