1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * AMD Secure Processor driver
5 * Copyright (C) 2017-2019 Advanced Micro Devices, Inc.
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>
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 /* Structure to hold CCP device data */
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
;
43 const unsigned int cmdresp_reg
;
44 const unsigned int cmdbuff_addr_lo_reg
;
45 const unsigned int cmdbuff_addr_hi_reg
;
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
;
57 const struct sev_vdata
*sev
;
58 const struct tee_vdata
*tee
;
59 const unsigned int feature_reg
;
60 const unsigned int inten_reg
;
61 const unsigned int intsts_reg
;
64 /* Structure to hold SP device data */
66 const unsigned int bar
;
68 const struct ccp_vdata
*ccp_vdata
;
69 const struct psp_vdata
*psp_vdata
;
73 struct list_head entry
;
77 struct sp_dev_vdata
*dev_vdata
;
79 char name
[SP_MAX_NAME_LEN
];
81 /* Bus specific device information */
84 /* I/O area used for device communication. */
87 /* DMA caching attribute support */
90 /* get and set master device */
91 struct sp_device
*(*get_psp_master_device
)(void);
92 void (*set_psp_master_device
)(struct sp_device
*);
98 irq_handler_t ccp_irq_handler
;
101 unsigned int psp_irq
;
102 irq_handler_t psp_irq_handler
;
109 int sp_pci_init(void);
110 void sp_pci_exit(void);
112 int sp_platform_init(void);
113 void sp_platform_exit(void);
115 struct sp_device
*sp_alloc_struct(struct device
*dev
);
117 int sp_init(struct sp_device
*sp
);
118 void sp_destroy(struct sp_device
*sp
);
119 struct sp_device
*sp_get_master(void);
121 int sp_suspend(struct sp_device
*sp
, pm_message_t state
);
122 int sp_resume(struct sp_device
*sp
);
123 int sp_request_ccp_irq(struct sp_device
*sp
, irq_handler_t handler
,
124 const char *name
, void *data
);
125 void sp_free_ccp_irq(struct sp_device
*sp
, void *data
);
126 int sp_request_psp_irq(struct sp_device
*sp
, irq_handler_t handler
,
127 const char *name
, void *data
);
128 void sp_free_psp_irq(struct sp_device
*sp
, void *data
);
129 struct sp_device
*sp_get_psp_master_device(void);
131 #ifdef CONFIG_CRYPTO_DEV_SP_CCP
133 int ccp_dev_init(struct sp_device
*sp
);
134 void ccp_dev_destroy(struct sp_device
*sp
);
136 int ccp_dev_suspend(struct sp_device
*sp
, pm_message_t state
);
137 int ccp_dev_resume(struct sp_device
*sp
);
139 #else /* !CONFIG_CRYPTO_DEV_SP_CCP */
141 static inline int ccp_dev_init(struct sp_device
*sp
)
145 static inline void ccp_dev_destroy(struct sp_device
*sp
) { }
147 static inline int ccp_dev_suspend(struct sp_device
*sp
, pm_message_t state
)
151 static inline int ccp_dev_resume(struct sp_device
*sp
)
155 #endif /* CONFIG_CRYPTO_DEV_SP_CCP */
157 #ifdef CONFIG_CRYPTO_DEV_SP_PSP
159 int psp_dev_init(struct sp_device
*sp
);
160 void psp_pci_init(void);
161 void psp_dev_destroy(struct sp_device
*sp
);
162 void psp_pci_exit(void);
164 #else /* !CONFIG_CRYPTO_DEV_SP_PSP */
166 static inline int psp_dev_init(struct sp_device
*sp
) { return 0; }
167 static inline void psp_pci_init(void) { }
168 static inline void psp_dev_destroy(struct sp_device
*sp
) { }
169 static inline void psp_pci_exit(void) { }
171 #endif /* CONFIG_CRYPTO_DEV_SP_PSP */