sp-dev.h 3.8 KB

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