sp-dev.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 <[email protected]>
  8. * Author: Gary R Hook <[email protected]>
  9. * Author: Brijesh Singh <[email protected]>
  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. /* Structure to hold CCP device data */
  27. struct ccp_device;
  28. struct ccp_vdata {
  29. const unsigned int version;
  30. const unsigned int dma_chan_attr;
  31. void (*setup)(struct ccp_device *);
  32. const struct ccp_actions *perform;
  33. const unsigned int offset;
  34. const unsigned int rsamax;
  35. };
  36. struct sev_vdata {
  37. const unsigned int cmdresp_reg;
  38. const unsigned int cmdbuff_addr_lo_reg;
  39. const unsigned int cmdbuff_addr_hi_reg;
  40. };
  41. struct tee_vdata {
  42. const unsigned int cmdresp_reg;
  43. const unsigned int cmdbuff_addr_lo_reg;
  44. const unsigned int cmdbuff_addr_hi_reg;
  45. const unsigned int ring_wptr_reg;
  46. const unsigned int ring_rptr_reg;
  47. };
  48. struct psp_vdata {
  49. const struct sev_vdata *sev;
  50. const struct tee_vdata *tee;
  51. const unsigned int feature_reg;
  52. const unsigned int inten_reg;
  53. const unsigned int intsts_reg;
  54. };
  55. /* Structure to hold SP device data */
  56. struct sp_dev_vdata {
  57. const unsigned int bar;
  58. const struct ccp_vdata *ccp_vdata;
  59. const struct psp_vdata *psp_vdata;
  60. };
  61. struct sp_device {
  62. struct list_head entry;
  63. struct device *dev;
  64. struct sp_dev_vdata *dev_vdata;
  65. unsigned int ord;
  66. char name[SP_MAX_NAME_LEN];
  67. /* Bus specific device information */
  68. void *dev_specific;
  69. /* I/O area used for device communication. */
  70. void __iomem *io_map;
  71. /* DMA caching attribute support */
  72. unsigned int axcache;
  73. /* get and set master device */
  74. struct sp_device*(*get_psp_master_device)(void);
  75. void (*set_psp_master_device)(struct sp_device *);
  76. void (*clear_psp_master_device)(struct sp_device *);
  77. bool irq_registered;
  78. bool use_tasklet;
  79. unsigned int ccp_irq;
  80. irq_handler_t ccp_irq_handler;
  81. void *ccp_irq_data;
  82. unsigned int psp_irq;
  83. irq_handler_t psp_irq_handler;
  84. void *psp_irq_data;
  85. void *ccp_data;
  86. void *psp_data;
  87. };
  88. int sp_pci_init(void);
  89. void sp_pci_exit(void);
  90. int sp_platform_init(void);
  91. void sp_platform_exit(void);
  92. struct sp_device *sp_alloc_struct(struct device *dev);
  93. int sp_init(struct sp_device *sp);
  94. void sp_destroy(struct sp_device *sp);
  95. struct sp_device *sp_get_master(void);
  96. int sp_suspend(struct sp_device *sp);
  97. int sp_resume(struct sp_device *sp);
  98. int sp_request_ccp_irq(struct sp_device *sp, irq_handler_t handler,
  99. const char *name, void *data);
  100. void sp_free_ccp_irq(struct sp_device *sp, void *data);
  101. int sp_request_psp_irq(struct sp_device *sp, irq_handler_t handler,
  102. const char *name, void *data);
  103. void sp_free_psp_irq(struct sp_device *sp, void *data);
  104. struct sp_device *sp_get_psp_master_device(void);
  105. #ifdef CONFIG_CRYPTO_DEV_SP_CCP
  106. int ccp_dev_init(struct sp_device *sp);
  107. void ccp_dev_destroy(struct sp_device *sp);
  108. void ccp_dev_suspend(struct sp_device *sp);
  109. void ccp_dev_resume(struct sp_device *sp);
  110. #else /* !CONFIG_CRYPTO_DEV_SP_CCP */
  111. static inline int ccp_dev_init(struct sp_device *sp)
  112. {
  113. return 0;
  114. }
  115. static inline void ccp_dev_destroy(struct sp_device *sp) { }
  116. static inline void ccp_dev_suspend(struct sp_device *sp) { }
  117. static inline void ccp_dev_resume(struct sp_device *sp) { }
  118. #endif /* CONFIG_CRYPTO_DEV_SP_CCP */
  119. #ifdef CONFIG_CRYPTO_DEV_SP_PSP
  120. int psp_dev_init(struct sp_device *sp);
  121. void psp_pci_init(void);
  122. void psp_dev_destroy(struct sp_device *sp);
  123. void psp_pci_exit(void);
  124. #else /* !CONFIG_CRYPTO_DEV_SP_PSP */
  125. static inline int psp_dev_init(struct sp_device *sp) { return 0; }
  126. static inline void psp_pci_init(void) { }
  127. static inline void psp_dev_destroy(struct sp_device *sp) { }
  128. static inline void psp_pci_exit(void) { }
  129. #endif /* CONFIG_CRYPTO_DEV_SP_PSP */
  130. #endif