sp-dev.h 3.1 KB

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