sev-dev-tio.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. #ifndef __PSP_SEV_TIO_H__
  3. #define __PSP_SEV_TIO_H__
  4. #include <linux/pci-tsm.h>
  5. #include <linux/pci-ide.h>
  6. #include <linux/tsm.h>
  7. #include <uapi/linux/psp-sev.h>
  8. struct sla_addr_t {
  9. union {
  10. u64 sla;
  11. struct {
  12. u64 page_type :1,
  13. page_size :1,
  14. reserved1 :10,
  15. pfn :40,
  16. reserved2 :12;
  17. };
  18. };
  19. } __packed;
  20. #define SEV_TIO_MAX_COMMAND_LENGTH 128
  21. /* SPDM control structure for DOE */
  22. struct tsm_spdm {
  23. unsigned long req_len;
  24. void *req;
  25. unsigned long rsp_len;
  26. void *rsp;
  27. };
  28. /* Describes TIO device */
  29. struct tsm_dsm_tio {
  30. u8 cert_slot;
  31. struct sla_addr_t dev_ctx;
  32. struct sla_addr_t req;
  33. struct sla_addr_t resp;
  34. struct sla_addr_t scratch;
  35. struct sla_addr_t output;
  36. size_t output_len;
  37. size_t scratch_len;
  38. struct tsm_spdm spdm;
  39. struct sla_buffer_hdr *reqbuf; /* vmap'ed @req for DOE */
  40. struct sla_buffer_hdr *respbuf; /* vmap'ed @resp for DOE */
  41. int cmd;
  42. int psp_ret;
  43. u8 cmd_data[SEV_TIO_MAX_COMMAND_LENGTH];
  44. void *data_pg; /* Data page for DEV_STATUS/TDI_STATUS/TDI_INFO/ASID_FENCE */
  45. #define TIO_IDE_MAX_TC 8
  46. struct pci_ide *ide[TIO_IDE_MAX_TC];
  47. };
  48. /* Describes TSM structure for PF0 pointed by pci_dev->tsm */
  49. struct tio_dsm {
  50. struct pci_tsm_pf0 tsm;
  51. struct tsm_dsm_tio data;
  52. struct sev_device *sev;
  53. };
  54. /* Data object IDs */
  55. #define SPDM_DOBJ_ID_NONE 0
  56. #define SPDM_DOBJ_ID_REQ 1
  57. #define SPDM_DOBJ_ID_RESP 2
  58. struct spdm_dobj_hdr {
  59. u32 id; /* Data object type identifier */
  60. u32 length; /* Length of the data object, INCLUDING THIS HEADER */
  61. struct { /* Version of the data object structure */
  62. u8 minor;
  63. u8 major;
  64. } version;
  65. } __packed;
  66. /**
  67. * struct sev_tio_status - TIO_STATUS command's info_paddr buffer
  68. *
  69. * @length: Length of this structure in bytes
  70. * @tio_en: Indicates that SNP_INIT_EX initialized the RMP for SEV-TIO
  71. * @tio_init_done: Indicates TIO_INIT has been invoked
  72. * @spdm_req_size_min: Minimum SPDM request buffer size in bytes
  73. * @spdm_req_size_max: Maximum SPDM request buffer size in bytes
  74. * @spdm_scratch_size_min: Minimum SPDM scratch buffer size in bytes
  75. * @spdm_scratch_size_max: Maximum SPDM scratch buffer size in bytes
  76. * @spdm_out_size_min: Minimum SPDM output buffer size in bytes
  77. * @spdm_out_size_max: Maximum for the SPDM output buffer size in bytes
  78. * @spdm_rsp_size_min: Minimum SPDM response buffer size in bytes
  79. * @spdm_rsp_size_max: Maximum SPDM response buffer size in bytes
  80. * @devctx_size: Size of a device context buffer in bytes
  81. * @tdictx_size: Size of a TDI context buffer in bytes
  82. * @tio_crypto_alg: TIO crypto algorithms supported
  83. */
  84. struct sev_tio_status {
  85. u32 length;
  86. u32 tio_en :1,
  87. tio_init_done :1,
  88. reserved :30;
  89. u32 spdm_req_size_min;
  90. u32 spdm_req_size_max;
  91. u32 spdm_scratch_size_min;
  92. u32 spdm_scratch_size_max;
  93. u32 spdm_out_size_min;
  94. u32 spdm_out_size_max;
  95. u32 spdm_rsp_size_min;
  96. u32 spdm_rsp_size_max;
  97. u32 devctx_size;
  98. u32 tdictx_size;
  99. u32 tio_crypto_alg;
  100. u8 reserved2[12];
  101. } __packed;
  102. int sev_tio_init_locked(void *tio_status_page);
  103. int sev_tio_continue(struct tsm_dsm_tio *dev_data);
  104. int sev_tio_dev_create(struct tsm_dsm_tio *dev_data, u16 device_id, u16 root_port_id,
  105. u8 segment_id);
  106. int sev_tio_dev_connect(struct tsm_dsm_tio *dev_data, u8 tc_mask, u8 ids[8], u8 cert_slot);
  107. int sev_tio_dev_disconnect(struct tsm_dsm_tio *dev_data, bool force);
  108. int sev_tio_dev_reclaim(struct tsm_dsm_tio *dev_data);
  109. #endif /* __PSP_SEV_TIO_H__ */