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