sp-dev.h 3.9 KB

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