1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * AMD Secure Processor driver
5 * Copyright (C) 2017-2019 Advanced Micro Devices, Inc.
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>
26 #define SP_MAX_NAME_LEN 32
28 #define CACHE_NONE 0x00
29 #define CACHE_WB_NO_ALLOC 0xb7
31 #define PLATFORM_FEATURE_DBC 0x1
33 #define PSP_FEATURE(psp, feat) (psp->vdata && psp->vdata->platform_features & PLATFORM_FEATURE_##feat)
35 /* Structure to hold CCP device data */
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;
47 const unsigned int cmdresp_reg;
48 const unsigned int cmdbuff_addr_lo_reg;
49 const unsigned int cmdbuff_addr_hi_reg;
53 const unsigned int cmdresp_reg;
54 const unsigned int cmdbuff_addr_lo_reg;
55 const unsigned int cmdbuff_addr_hi_reg;
56 const unsigned int ring_wptr_reg;
57 const unsigned int ring_rptr_reg;
58 const unsigned int info_reg;
61 struct platform_access_vdata {
62 const unsigned int cmdresp_reg;
63 const unsigned int cmdbuff_addr_lo_reg;
64 const unsigned int cmdbuff_addr_hi_reg;
65 const unsigned int doorbell_button_reg;
66 const unsigned int doorbell_cmd_reg;
71 const struct sev_vdata *sev;
72 const struct tee_vdata *tee;
73 const struct platform_access_vdata *platform_access;
74 const unsigned int feature_reg;
75 const unsigned int inten_reg;
76 const unsigned int intsts_reg;
77 const unsigned int bootloader_info_reg;
78 const unsigned int platform_features;
81 /* Structure to hold SP device data */
83 const unsigned int bar;
85 const struct ccp_vdata *ccp_vdata;
86 const struct psp_vdata *psp_vdata;
90 struct list_head entry;
94 struct sp_dev_vdata *dev_vdata;
96 char name[SP_MAX_NAME_LEN];
98 /* Bus specific device information */
101 /* I/O area used for device communication. */
102 void __iomem *io_map;
104 /* DMA caching attribute support */
105 unsigned int axcache;
107 /* get and set master device */
108 struct sp_device*(*get_psp_master_device)(void);
109 void (*set_psp_master_device)(struct sp_device *);
110 void (*clear_psp_master_device)(struct sp_device *);
115 unsigned int ccp_irq;
116 irq_handler_t ccp_irq_handler;
119 unsigned int psp_irq;
120 irq_handler_t psp_irq_handler;
127 int sp_pci_init(void);
128 void sp_pci_exit(void);
130 int sp_platform_init(void);
131 void sp_platform_exit(void);
133 struct sp_device *sp_alloc_struct(struct device *dev);
135 int sp_init(struct sp_device *sp);
136 void sp_destroy(struct sp_device *sp);
137 struct sp_device *sp_get_master(void);
139 int sp_suspend(struct sp_device *sp);
140 int sp_resume(struct sp_device *sp);
141 int sp_request_ccp_irq(struct sp_device *sp, irq_handler_t handler,
142 const char *name, void *data);
143 void sp_free_ccp_irq(struct sp_device *sp, void *data);
144 int sp_request_psp_irq(struct sp_device *sp, irq_handler_t handler,
145 const char *name, void *data);
146 void sp_free_psp_irq(struct sp_device *sp, void *data);
147 struct sp_device *sp_get_psp_master_device(void);
149 #ifdef CONFIG_CRYPTO_DEV_SP_CCP
151 int ccp_dev_init(struct sp_device *sp);
152 void ccp_dev_destroy(struct sp_device *sp);
154 void ccp_dev_suspend(struct sp_device *sp);
155 void ccp_dev_resume(struct sp_device *sp);
157 #else /* !CONFIG_CRYPTO_DEV_SP_CCP */
159 static inline int ccp_dev_init(struct sp_device *sp)
163 static inline void ccp_dev_destroy(struct sp_device *sp) { }
164 static inline void ccp_dev_suspend(struct sp_device *sp) { }
165 static inline void ccp_dev_resume(struct sp_device *sp) { }
166 #endif /* CONFIG_CRYPTO_DEV_SP_CCP */
168 #ifdef CONFIG_CRYPTO_DEV_SP_PSP
170 int psp_dev_init(struct sp_device *sp);
171 void psp_pci_init(void);
172 void psp_dev_destroy(struct sp_device *sp);
173 void psp_pci_exit(void);
175 #else /* !CONFIG_CRYPTO_DEV_SP_PSP */
177 static inline int psp_dev_init(struct sp_device *sp) { return 0; }
178 static inline void psp_pci_init(void) { }
179 static inline void psp_dev_destroy(struct sp_device *sp) { }
180 static inline void psp_pci_exit(void) { }
182 #endif /* CONFIG_CRYPTO_DEV_SP_PSP */