2 * AMD Secure Processor driver
4 * Copyright (C) 2017 Advanced Micro Devices, Inc.
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>
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.
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>
30 #define SP_MAX_NAME_LEN 32
32 #define CACHE_NONE 0x00
33 #define CACHE_WB_NO_ALLOC 0xb7
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
;
50 const unsigned int feature_reg
;
51 const unsigned int inten_reg
;
52 const unsigned int intsts_reg
;
55 /* Structure to hold SP device data */
57 const unsigned int bar
;
59 const struct ccp_vdata
*ccp_vdata
;
60 const struct psp_vdata
*psp_vdata
;
64 struct list_head entry
;
68 struct sp_dev_vdata
*dev_vdata
;
70 char name
[SP_MAX_NAME_LEN
];
72 /* Bus specific device information */
75 /* I/O area used for device communication. */
78 /* DMA caching attribute support */
81 /* get and set master device */
82 struct sp_device
*(*get_psp_master_device
)(void);
83 void (*set_psp_master_device
)(struct sp_device
*);
89 irq_handler_t ccp_irq_handler
;
93 irq_handler_t psp_irq_handler
;
100 int sp_pci_init(void);
101 void sp_pci_exit(void);
103 int sp_platform_init(void);
104 void sp_platform_exit(void);
106 struct sp_device
*sp_alloc_struct(struct device
*dev
);
108 int sp_init(struct sp_device
*sp
);
109 void sp_destroy(struct sp_device
*sp
);
110 struct sp_device
*sp_get_master(void);
112 int sp_suspend(struct sp_device
*sp
, pm_message_t state
);
113 int sp_resume(struct sp_device
*sp
);
114 int sp_request_ccp_irq(struct sp_device
*sp
, irq_handler_t handler
,
115 const char *name
, void *data
);
116 void sp_free_ccp_irq(struct sp_device
*sp
, void *data
);
117 int sp_request_psp_irq(struct sp_device
*sp
, irq_handler_t handler
,
118 const char *name
, void *data
);
119 void sp_free_psp_irq(struct sp_device
*sp
, void *data
);
120 struct sp_device
*sp_get_psp_master_device(void);
122 #ifdef CONFIG_CRYPTO_DEV_SP_CCP
124 int ccp_dev_init(struct sp_device
*sp
);
125 void ccp_dev_destroy(struct sp_device
*sp
);
127 int ccp_dev_suspend(struct sp_device
*sp
, pm_message_t state
);
128 int ccp_dev_resume(struct sp_device
*sp
);
130 #else /* !CONFIG_CRYPTO_DEV_SP_CCP */
132 static inline int ccp_dev_init(struct sp_device
*sp
)
136 static inline void ccp_dev_destroy(struct sp_device
*sp
) { }
138 static inline int ccp_dev_suspend(struct sp_device
*sp
, pm_message_t state
)
142 static inline int ccp_dev_resume(struct sp_device
*sp
)
146 #endif /* CONFIG_CRYPTO_DEV_SP_CCP */
148 #ifdef CONFIG_CRYPTO_DEV_SP_PSP
150 int psp_dev_init(struct sp_device
*sp
);
151 void psp_pci_init(void);
152 void psp_dev_destroy(struct sp_device
*sp
);
153 void psp_pci_exit(void);
155 #else /* !CONFIG_CRYPTO_DEV_SP_PSP */
157 static inline int psp_dev_init(struct sp_device
*sp
) { return 0; }
158 static inline void psp_pci_init(void) { }
159 static inline void psp_dev_destroy(struct sp_device
*sp
) { }
160 static inline void psp_pci_exit(void) { }
162 #endif /* CONFIG_CRYPTO_DEV_SP_PSP */