sp-dev.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * AMD Secure Processor driver
  4. *
  5. * Copyright (C) 2017-2018 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. /* 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 psp_vdata {
  37. const unsigned int cmdresp_reg;
  38. const unsigned int cmdbuff_addr_lo_reg;
  39. const unsigned int cmdbuff_addr_hi_reg;
  40. const unsigned int feature_reg;
  41. const unsigned int inten_reg;
  42. const unsigned int intsts_reg;
  43. };
  44. /* Structure to hold SP device data */
  45. struct sp_dev_vdata {
  46. const unsigned int bar;
  47. const struct ccp_vdata *ccp_vdata;
  48. const struct psp_vdata *psp_vdata;
  49. };
  50. struct sp_device {
  51. struct list_head entry;
  52. struct device *dev;
  53. struct sp_dev_vdata *dev_vdata;
  54. unsigned int ord;
  55. char name[SP_MAX_NAME_LEN];
  56. /* Bus specific device information */
  57. void *dev_specific;
  58. /* I/O area used for device communication. */
  59. void __iomem *io_map;
  60. /* DMA caching attribute support */
  61. unsigned int axcache;
  62. /* get and set master device */
  63. struct sp_device*(*get_psp_master_device)(void);
  64. void (*set_psp_master_device)(struct sp_device *);
  65. bool irq_registered;
  66. bool use_tasklet;
  67. unsigned int ccp_irq;
  68. irq_handler_t ccp_irq_handler;
  69. void *ccp_irq_data;
  70. unsigned int psp_irq;
  71. irq_handler_t psp_irq_handler;
  72. void *psp_irq_data;
  73. void *ccp_data;
  74. void *psp_data;
  75. };
  76. int sp_pci_init(void);
  77. void sp_pci_exit(void);
  78. int sp_platform_init(void);
  79. void sp_platform_exit(void);
  80. struct sp_device *sp_alloc_struct(struct device *dev);
  81. int sp_init(struct sp_device *sp);
  82. void sp_destroy(struct sp_device *sp);
  83. struct sp_device *sp_get_master(void);
  84. int sp_suspend(struct sp_device *sp, pm_message_t state);
  85. int sp_resume(struct sp_device *sp);
  86. int sp_request_ccp_irq(struct sp_device *sp, irq_handler_t handler,
  87. const char *name, void *data);
  88. void sp_free_ccp_irq(struct sp_device *sp, void *data);
  89. int sp_request_psp_irq(struct sp_device *sp, irq_handler_t handler,
  90. const char *name, void *data);
  91. void sp_free_psp_irq(struct sp_device *sp, void *data);
  92. struct sp_device *sp_get_psp_master_device(void);
  93. #ifdef CONFIG_CRYPTO_DEV_SP_CCP
  94. int ccp_dev_init(struct sp_device *sp);
  95. void ccp_dev_destroy(struct sp_device *sp);
  96. int ccp_dev_suspend(struct sp_device *sp, pm_message_t state);
  97. int ccp_dev_resume(struct sp_device *sp);
  98. #else /* !CONFIG_CRYPTO_DEV_SP_CCP */
  99. static inline int ccp_dev_init(struct sp_device *sp)
  100. {
  101. return 0;
  102. }
  103. static inline void ccp_dev_destroy(struct sp_device *sp) { }
  104. static inline int ccp_dev_suspend(struct sp_device *sp, pm_message_t state)
  105. {
  106. return 0;
  107. }
  108. static inline int ccp_dev_resume(struct sp_device *sp)
  109. {
  110. return 0;
  111. }
  112. #endif /* CONFIG_CRYPTO_DEV_SP_CCP */
  113. #ifdef CONFIG_CRYPTO_DEV_SP_PSP
  114. int psp_dev_init(struct sp_device *sp);
  115. void psp_pci_init(void);
  116. void psp_dev_destroy(struct sp_device *sp);
  117. void psp_pci_exit(void);
  118. #else /* !CONFIG_CRYPTO_DEV_SP_PSP */
  119. static inline int psp_dev_init(struct sp_device *sp) { return 0; }
  120. static inline void psp_pci_init(void) { }
  121. static inline void psp_dev_destroy(struct sp_device *sp) { }
  122. static inline void psp_pci_exit(void) { }
  123. #endif /* CONFIG_CRYPTO_DEV_SP_PSP */
  124. #endif