sp-dev.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * AMD Secure Processor driver
  4. *
  5. * Copyright (C) 2017-2019 Advanced Micro Devices, Inc.
  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>
  10. */
  11. #ifndef __SP_DEV_H__
  12. #define __SP_DEV_H__
  13. #include <linux/device.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/mutex.h>
  16. #include <linux/list.h>
  17. #include <linux/wait.h>
  18. #include <linux/dmapool.h>
  19. #include <linux/hw_random.h>
  20. #include <linux/bitops.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/irqreturn.h>
  23. #define SP_MAX_NAME_LEN 32
  24. #define CACHE_NONE 0x00
  25. #define CACHE_WB_NO_ALLOC 0xb7
  26. #define PLATFORM_FEATURE_DBC 0x1
  27. #define PLATFORM_FEATURE_HSTI 0x2
  28. #define PSP_FEATURE(psp, feat) (psp->vdata && psp->vdata->platform_features & PLATFORM_FEATURE_##feat)
  29. /* Structure to hold CCP device data */
  30. struct ccp_device;
  31. struct ccp_vdata {
  32. const unsigned int version;
  33. const unsigned int dma_chan_attr;
  34. void (*setup)(struct ccp_device *);
  35. const struct ccp_actions *perform;
  36. const unsigned int offset;
  37. const unsigned int rsamax;
  38. };
  39. struct sev_vdata {
  40. const unsigned int cmdresp_reg;
  41. const unsigned int cmdbuff_addr_lo_reg;
  42. const unsigned int cmdbuff_addr_hi_reg;
  43. };
  44. struct tee_vdata {
  45. const unsigned int cmdresp_reg;
  46. const unsigned int cmdbuff_addr_lo_reg;
  47. const unsigned int cmdbuff_addr_hi_reg;
  48. const unsigned int ring_wptr_reg;
  49. const unsigned int ring_rptr_reg;
  50. const unsigned int info_reg;
  51. };
  52. struct platform_access_vdata {
  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 doorbell_button_reg;
  57. const unsigned int doorbell_cmd_reg;
  58. };
  59. struct psp_vdata {
  60. const struct sev_vdata *sev;
  61. const struct tee_vdata *tee;
  62. const struct platform_access_vdata *platform_access;
  63. const unsigned int cmdresp_reg;
  64. const unsigned int cmdbuff_addr_lo_reg;
  65. const unsigned int cmdbuff_addr_hi_reg;
  66. const unsigned int feature_reg;
  67. const unsigned int inten_reg;
  68. const unsigned int intsts_reg;
  69. const unsigned int bootloader_info_reg;
  70. const unsigned int platform_features;
  71. };
  72. /* Structure to hold SP device data */
  73. struct sp_dev_vdata {
  74. const unsigned int bar;
  75. const struct ccp_vdata *ccp_vdata;
  76. const struct psp_vdata *psp_vdata;
  77. };
  78. struct sp_device {
  79. struct list_head entry;
  80. struct device *dev;
  81. const struct sp_dev_vdata *dev_vdata;
  82. unsigned int ord;
  83. char name[SP_MAX_NAME_LEN];
  84. /* Bus specific device information */
  85. void *dev_specific;
  86. /* I/O area used for device communication. */
  87. void __iomem *io_map;
  88. /* DMA caching attribute support */
  89. unsigned int axcache;
  90. /* get and set master device */
  91. struct sp_device*(*get_psp_master_device)(void);
  92. void (*set_psp_master_device)(struct sp_device *);
  93. void (*clear_psp_master_device)(struct sp_device *);
  94. bool irq_registered;
  95. bool use_tasklet;
  96. unsigned int ccp_irq;
  97. irq_handler_t ccp_irq_handler;
  98. void *ccp_irq_data;
  99. unsigned int psp_irq;
  100. irq_handler_t psp_irq_handler;
  101. void *psp_irq_data;
  102. void *ccp_data;
  103. void *psp_data;
  104. };
  105. int sp_pci_init(void);
  106. void sp_pci_exit(void);
  107. int sp_platform_init(void);
  108. void sp_platform_exit(void);
  109. struct sp_device *sp_alloc_struct(struct device *dev);
  110. int sp_init(struct sp_device *sp);
  111. void sp_destroy(struct sp_device *sp);
  112. int sp_suspend(struct sp_device *sp);
  113. int sp_resume(struct sp_device *sp);
  114. int sp_restore(struct sp_device *sp);
  115. int sp_request_ccp_irq(struct sp_device *sp, irq_handler_t handler,
  116. const char *name, void *data);
  117. void sp_free_ccp_irq(struct sp_device *sp, void *data);
  118. int sp_request_psp_irq(struct sp_device *sp, irq_handler_t handler,
  119. const char *name, void *data);
  120. void sp_free_psp_irq(struct sp_device *sp, void *data);
  121. struct sp_device *sp_get_psp_master_device(void);
  122. #ifdef CONFIG_CRYPTO_DEV_SP_CCP
  123. int ccp_dev_init(struct sp_device *sp);
  124. void ccp_dev_destroy(struct sp_device *sp);
  125. void ccp_dev_suspend(struct sp_device *sp);
  126. void ccp_dev_resume(struct sp_device *sp);
  127. #else /* !CONFIG_CRYPTO_DEV_SP_CCP */
  128. static inline int ccp_dev_init(struct sp_device *sp)
  129. {
  130. return 0;
  131. }
  132. static inline void ccp_dev_destroy(struct sp_device *sp) { }
  133. static inline void ccp_dev_suspend(struct sp_device *sp) { }
  134. static inline void ccp_dev_resume(struct sp_device *sp) { }
  135. #endif /* CONFIG_CRYPTO_DEV_SP_CCP */
  136. #ifdef CONFIG_CRYPTO_DEV_SP_PSP
  137. int psp_dev_init(struct sp_device *sp);
  138. void psp_pci_init(void);
  139. void psp_dev_destroy(struct sp_device *sp);
  140. void psp_pci_exit(void);
  141. int psp_restore(struct sp_device *sp);
  142. #else /* !CONFIG_CRYPTO_DEV_SP_PSP */
  143. static inline int psp_dev_init(struct sp_device *sp) { return 0; }
  144. static inline void psp_pci_init(void) { }
  145. static inline void psp_dev_destroy(struct sp_device *sp) { }
  146. static inline void psp_pci_exit(void) { }
  147. static inline int psp_restore(struct sp_device *sp) { return 0; }
  148. #endif /* CONFIG_CRYPTO_DEV_SP_PSP */
  149. #endif