Brijesh Singh | 720419f | 2017-07-06 09:59:14 -0500 | [diff] [blame^] | 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 | }; |
| 44 | /* Structure to hold SP device data */ |
| 45 | struct sp_dev_vdata { |
| 46 | const unsigned int bar; |
| 47 | |
| 48 | const struct ccp_vdata *ccp_vdata; |
| 49 | void *psp_vdata; |
| 50 | }; |
| 51 | |
| 52 | struct sp_device { |
| 53 | struct list_head entry; |
| 54 | |
| 55 | struct device *dev; |
| 56 | |
| 57 | struct sp_dev_vdata *dev_vdata; |
| 58 | unsigned int ord; |
| 59 | char name[SP_MAX_NAME_LEN]; |
| 60 | |
| 61 | /* Bus specific device information */ |
| 62 | void *dev_specific; |
| 63 | |
| 64 | /* I/O area used for device communication. */ |
| 65 | void __iomem *io_map; |
| 66 | |
| 67 | /* DMA caching attribute support */ |
| 68 | unsigned int axcache; |
| 69 | |
| 70 | bool irq_registered; |
| 71 | |
| 72 | int (*get_irq)(struct ccp_device *ccp); |
| 73 | void (*free_irq)(struct ccp_device *ccp); |
| 74 | |
| 75 | void *ccp_data; |
| 76 | void *psp_data; |
| 77 | }; |
| 78 | |
| 79 | int sp_pci_init(void); |
| 80 | void sp_pci_exit(void); |
| 81 | |
| 82 | int sp_platform_init(void); |
| 83 | void sp_platform_exit(void); |
| 84 | |
| 85 | struct sp_device *sp_alloc_struct(struct device *dev); |
| 86 | |
| 87 | int sp_init(struct sp_device *sp); |
| 88 | void sp_destroy(struct sp_device *sp); |
| 89 | struct sp_device *sp_get_master(void); |
| 90 | |
| 91 | int sp_suspend(struct sp_device *sp, pm_message_t state); |
| 92 | int sp_resume(struct sp_device *sp); |
| 93 | |
| 94 | #ifdef CONFIG_CRYPTO_DEV_SP_CCP |
| 95 | |
| 96 | int ccp_dev_init(struct sp_device *sp); |
| 97 | void ccp_dev_destroy(struct sp_device *sp); |
| 98 | |
| 99 | int ccp_dev_suspend(struct sp_device *sp, pm_message_t state); |
| 100 | int ccp_dev_resume(struct sp_device *sp); |
| 101 | |
| 102 | #else /* !CONFIG_CRYPTO_DEV_SP_CCP */ |
| 103 | |
| 104 | static inline int ccp_dev_init(struct sp_device *sp) |
| 105 | { |
| 106 | return 0; |
| 107 | } |
| 108 | static inline void ccp_dev_destroy(struct sp_device *sp) { } |
| 109 | |
| 110 | static inline int ccp_dev_suspend(struct sp_device *sp, pm_message_t state) |
| 111 | { |
| 112 | return 0; |
| 113 | } |
| 114 | static inline int ccp_dev_resume(struct sp_device *sp) |
| 115 | { |
| 116 | return 0; |
| 117 | } |
| 118 | #endif /* CONFIG_CRYPTO_DEV_SP_CCP */ |
| 119 | |
| 120 | #endif |