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