psp-sev.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
  2. /*
  3. * Userspace interface for AMD Secure Encrypted Virtualization (SEV)
  4. * platform management commands.
  5. *
  6. * Copyright (C) 2016-2017 Advanced Micro Devices, Inc.
  7. *
  8. * Author: Brijesh Singh <brijesh.singh@amd.com>
  9. *
  10. * SEV API specification is available at: https://developer.amd.com/sev/
  11. */
  12. #ifndef __PSP_SEV_USER_H__
  13. #define __PSP_SEV_USER_H__
  14. #include <linux/types.h>
  15. /**
  16. * SEV platform commands
  17. */
  18. enum {
  19. SEV_FACTORY_RESET = 0,
  20. SEV_PLATFORM_STATUS,
  21. SEV_PEK_GEN,
  22. SEV_PEK_CSR,
  23. SEV_PDH_GEN,
  24. SEV_PDH_CERT_EXPORT,
  25. SEV_PEK_CERT_IMPORT,
  26. SEV_GET_ID, /* This command is deprecated, use SEV_GET_ID2 */
  27. SEV_GET_ID2,
  28. SEV_MAX,
  29. };
  30. /**
  31. * SEV Firmware status code
  32. */
  33. typedef enum {
  34. SEV_RET_SUCCESS = 0,
  35. SEV_RET_INVALID_PLATFORM_STATE,
  36. SEV_RET_INVALID_GUEST_STATE,
  37. SEV_RET_INAVLID_CONFIG,
  38. SEV_RET_INVALID_LEN,
  39. SEV_RET_ALREADY_OWNED,
  40. SEV_RET_INVALID_CERTIFICATE,
  41. SEV_RET_POLICY_FAILURE,
  42. SEV_RET_INACTIVE,
  43. SEV_RET_INVALID_ADDRESS,
  44. SEV_RET_BAD_SIGNATURE,
  45. SEV_RET_BAD_MEASUREMENT,
  46. SEV_RET_ASID_OWNED,
  47. SEV_RET_INVALID_ASID,
  48. SEV_RET_WBINVD_REQUIRED,
  49. SEV_RET_DFFLUSH_REQUIRED,
  50. SEV_RET_INVALID_GUEST,
  51. SEV_RET_INVALID_COMMAND,
  52. SEV_RET_ACTIVE,
  53. SEV_RET_HWSEV_RET_PLATFORM,
  54. SEV_RET_HWSEV_RET_UNSAFE,
  55. SEV_RET_UNSUPPORTED,
  56. SEV_RET_MAX,
  57. } sev_ret_code;
  58. /**
  59. * struct sev_user_data_status - PLATFORM_STATUS command parameters
  60. *
  61. * @major: major API version
  62. * @minor: minor API version
  63. * @state: platform state
  64. * @flags: platform config flags
  65. * @build: firmware build id for API version
  66. * @guest_count: number of active guests
  67. */
  68. struct sev_user_data_status {
  69. __u8 api_major; /* Out */
  70. __u8 api_minor; /* Out */
  71. __u8 state; /* Out */
  72. __u32 flags; /* Out */
  73. __u8 build; /* Out */
  74. __u32 guest_count; /* Out */
  75. } __attribute__((packed));
  76. /**
  77. * struct sev_user_data_pek_csr - PEK_CSR command parameters
  78. *
  79. * @address: PEK certificate chain
  80. * @length: length of certificate
  81. */
  82. struct sev_user_data_pek_csr {
  83. __u64 address; /* In */
  84. __u32 length; /* In/Out */
  85. } __attribute__((packed));
  86. /**
  87. * struct sev_user_data_cert_import - PEK_CERT_IMPORT command parameters
  88. *
  89. * @pek_address: PEK certificate chain
  90. * @pek_len: length of PEK certificate
  91. * @oca_address: OCA certificate chain
  92. * @oca_len: length of OCA certificate
  93. */
  94. struct sev_user_data_pek_cert_import {
  95. __u64 pek_cert_address; /* In */
  96. __u32 pek_cert_len; /* In */
  97. __u64 oca_cert_address; /* In */
  98. __u32 oca_cert_len; /* In */
  99. } __attribute__((packed));
  100. /**
  101. * struct sev_user_data_pdh_cert_export - PDH_CERT_EXPORT command parameters
  102. *
  103. * @pdh_address: PDH certificate address
  104. * @pdh_len: length of PDH certificate
  105. * @cert_chain_address: PDH certificate chain
  106. * @cert_chain_len: length of PDH certificate chain
  107. */
  108. struct sev_user_data_pdh_cert_export {
  109. __u64 pdh_cert_address; /* In */
  110. __u32 pdh_cert_len; /* In/Out */
  111. __u64 cert_chain_address; /* In */
  112. __u32 cert_chain_len; /* In/Out */
  113. } __attribute__((packed));
  114. /**
  115. * struct sev_user_data_get_id - GET_ID command parameters (deprecated)
  116. *
  117. * @socket1: Buffer to pass unique ID of first socket
  118. * @socket2: Buffer to pass unique ID of second socket
  119. */
  120. struct sev_user_data_get_id {
  121. __u8 socket1[64]; /* Out */
  122. __u8 socket2[64]; /* Out */
  123. } __attribute__((packed));
  124. /**
  125. * struct sev_user_data_get_id2 - GET_ID command parameters
  126. * @address: Buffer to store unique ID
  127. * @length: length of the unique ID
  128. */
  129. struct sev_user_data_get_id2 {
  130. __u64 address; /* In */
  131. __u32 length; /* In/Out */
  132. } __attribute__((packed));
  133. /**
  134. * struct sev_issue_cmd - SEV ioctl parameters
  135. *
  136. * @cmd: SEV commands to execute
  137. * @opaque: pointer to the command structure
  138. * @error: SEV FW return code on failure
  139. */
  140. struct sev_issue_cmd {
  141. __u32 cmd; /* In */
  142. __u64 data; /* In */
  143. __u32 error; /* Out */
  144. } __attribute__((packed));
  145. #define SEV_IOC_TYPE 'S'
  146. #define SEV_ISSUE_CMD _IOWR(SEV_IOC_TYPE, 0x0, struct sev_issue_cmd)
  147. #endif /* __PSP_USER_SEV_H */