psp-sev.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. /*
  35. * This error code is not in the SEV spec. Its purpose is to convey that
  36. * there was an error that prevented the SEV firmware from being called.
  37. * The SEV API error codes are 16 bits, so the -1 value will not overlap
  38. * with possible values from the specification.
  39. */
  40. SEV_RET_NO_FW_CALL = -1,
  41. SEV_RET_SUCCESS = 0,
  42. SEV_RET_INVALID_PLATFORM_STATE,
  43. SEV_RET_INVALID_GUEST_STATE,
  44. SEV_RET_INAVLID_CONFIG,
  45. SEV_RET_INVALID_LEN,
  46. SEV_RET_ALREADY_OWNED,
  47. SEV_RET_INVALID_CERTIFICATE,
  48. SEV_RET_POLICY_FAILURE,
  49. SEV_RET_INACTIVE,
  50. SEV_RET_INVALID_ADDRESS,
  51. SEV_RET_BAD_SIGNATURE,
  52. SEV_RET_BAD_MEASUREMENT,
  53. SEV_RET_ASID_OWNED,
  54. SEV_RET_INVALID_ASID,
  55. SEV_RET_WBINVD_REQUIRED,
  56. SEV_RET_DFFLUSH_REQUIRED,
  57. SEV_RET_INVALID_GUEST,
  58. SEV_RET_INVALID_COMMAND,
  59. SEV_RET_ACTIVE,
  60. SEV_RET_HWSEV_RET_PLATFORM,
  61. SEV_RET_HWSEV_RET_UNSAFE,
  62. SEV_RET_UNSUPPORTED,
  63. SEV_RET_INVALID_PARAM,
  64. SEV_RET_RESOURCE_LIMIT,
  65. SEV_RET_SECURE_DATA_INVALID,
  66. SEV_RET_MAX,
  67. } sev_ret_code;
  68. /**
  69. * struct sev_user_data_status - PLATFORM_STATUS command parameters
  70. *
  71. * @major: major API version
  72. * @minor: minor API version
  73. * @state: platform state
  74. * @flags: platform config flags
  75. * @build: firmware build id for API version
  76. * @guest_count: number of active guests
  77. */
  78. struct sev_user_data_status {
  79. __u8 api_major; /* Out */
  80. __u8 api_minor; /* Out */
  81. __u8 state; /* Out */
  82. __u32 flags; /* Out */
  83. __u8 build; /* Out */
  84. __u32 guest_count; /* Out */
  85. } __attribute__((packed));
  86. #define SEV_STATUS_FLAGS_CONFIG_ES 0x0100
  87. /**
  88. * struct sev_user_data_pek_csr - PEK_CSR command parameters
  89. *
  90. * @address: PEK certificate chain
  91. * @length: length of certificate
  92. */
  93. struct sev_user_data_pek_csr {
  94. __u64 address; /* In */
  95. __u32 length; /* In/Out */
  96. } __attribute__((packed));
  97. /**
  98. * struct sev_user_data_cert_import - PEK_CERT_IMPORT command parameters
  99. *
  100. * @pek_address: PEK certificate chain
  101. * @pek_len: length of PEK certificate
  102. * @oca_address: OCA certificate chain
  103. * @oca_len: length of OCA certificate
  104. */
  105. struct sev_user_data_pek_cert_import {
  106. __u64 pek_cert_address; /* In */
  107. __u32 pek_cert_len; /* In */
  108. __u64 oca_cert_address; /* In */
  109. __u32 oca_cert_len; /* In */
  110. } __attribute__((packed));
  111. /**
  112. * struct sev_user_data_pdh_cert_export - PDH_CERT_EXPORT command parameters
  113. *
  114. * @pdh_address: PDH certificate address
  115. * @pdh_len: length of PDH certificate
  116. * @cert_chain_address: PDH certificate chain
  117. * @cert_chain_len: length of PDH certificate chain
  118. */
  119. struct sev_user_data_pdh_cert_export {
  120. __u64 pdh_cert_address; /* In */
  121. __u32 pdh_cert_len; /* In/Out */
  122. __u64 cert_chain_address; /* In */
  123. __u32 cert_chain_len; /* In/Out */
  124. } __attribute__((packed));
  125. /**
  126. * struct sev_user_data_get_id - GET_ID command parameters (deprecated)
  127. *
  128. * @socket1: Buffer to pass unique ID of first socket
  129. * @socket2: Buffer to pass unique ID of second socket
  130. */
  131. struct sev_user_data_get_id {
  132. __u8 socket1[64]; /* Out */
  133. __u8 socket2[64]; /* Out */
  134. } __attribute__((packed));
  135. /**
  136. * struct sev_user_data_get_id2 - GET_ID command parameters
  137. * @address: Buffer to store unique ID
  138. * @length: length of the unique ID
  139. */
  140. struct sev_user_data_get_id2 {
  141. __u64 address; /* In */
  142. __u32 length; /* In/Out */
  143. } __attribute__((packed));
  144. /**
  145. * struct sev_issue_cmd - SEV ioctl parameters
  146. *
  147. * @cmd: SEV commands to execute
  148. * @opaque: pointer to the command structure
  149. * @error: SEV FW return code on failure
  150. */
  151. struct sev_issue_cmd {
  152. __u32 cmd; /* In */
  153. __u64 data; /* In */
  154. __u32 error; /* Out */
  155. } __attribute__((packed));
  156. #define SEV_IOC_TYPE 'S'
  157. #define SEV_ISSUE_CMD _IOWR(SEV_IOC_TYPE, 0x0, struct sev_issue_cmd)
  158. #endif /* __PSP_USER_SEV_H */