psp-sev.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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_INVALID_PARAM,
  57. SEV_RET_RESOURCE_LIMIT,
  58. SEV_RET_SECURE_DATA_INVALID,
  59. SEV_RET_MAX,
  60. } sev_ret_code;
  61. /**
  62. * struct sev_user_data_status - PLATFORM_STATUS command parameters
  63. *
  64. * @major: major API version
  65. * @minor: minor API version
  66. * @state: platform state
  67. * @flags: platform config flags
  68. * @build: firmware build id for API version
  69. * @guest_count: number of active guests
  70. */
  71. struct sev_user_data_status {
  72. __u8 api_major; /* Out */
  73. __u8 api_minor; /* Out */
  74. __u8 state; /* Out */
  75. __u32 flags; /* Out */
  76. __u8 build; /* Out */
  77. __u32 guest_count; /* Out */
  78. } __attribute__((packed));
  79. /**
  80. * struct sev_user_data_pek_csr - PEK_CSR command parameters
  81. *
  82. * @address: PEK certificate chain
  83. * @length: length of certificate
  84. */
  85. struct sev_user_data_pek_csr {
  86. __u64 address; /* In */
  87. __u32 length; /* In/Out */
  88. } __attribute__((packed));
  89. /**
  90. * struct sev_user_data_cert_import - PEK_CERT_IMPORT command parameters
  91. *
  92. * @pek_address: PEK certificate chain
  93. * @pek_len: length of PEK certificate
  94. * @oca_address: OCA certificate chain
  95. * @oca_len: length of OCA certificate
  96. */
  97. struct sev_user_data_pek_cert_import {
  98. __u64 pek_cert_address; /* In */
  99. __u32 pek_cert_len; /* In */
  100. __u64 oca_cert_address; /* In */
  101. __u32 oca_cert_len; /* In */
  102. } __attribute__((packed));
  103. /**
  104. * struct sev_user_data_pdh_cert_export - PDH_CERT_EXPORT command parameters
  105. *
  106. * @pdh_address: PDH certificate address
  107. * @pdh_len: length of PDH certificate
  108. * @cert_chain_address: PDH certificate chain
  109. * @cert_chain_len: length of PDH certificate chain
  110. */
  111. struct sev_user_data_pdh_cert_export {
  112. __u64 pdh_cert_address; /* In */
  113. __u32 pdh_cert_len; /* In/Out */
  114. __u64 cert_chain_address; /* In */
  115. __u32 cert_chain_len; /* In/Out */
  116. } __attribute__((packed));
  117. /**
  118. * struct sev_user_data_get_id - GET_ID command parameters (deprecated)
  119. *
  120. * @socket1: Buffer to pass unique ID of first socket
  121. * @socket2: Buffer to pass unique ID of second socket
  122. */
  123. struct sev_user_data_get_id {
  124. __u8 socket1[64]; /* Out */
  125. __u8 socket2[64]; /* Out */
  126. } __attribute__((packed));
  127. /**
  128. * struct sev_user_data_get_id2 - GET_ID command parameters
  129. * @address: Buffer to store unique ID
  130. * @length: length of the unique ID
  131. */
  132. struct sev_user_data_get_id2 {
  133. __u64 address; /* In */
  134. __u32 length; /* In/Out */
  135. } __attribute__((packed));
  136. /**
  137. * struct sev_issue_cmd - SEV ioctl parameters
  138. *
  139. * @cmd: SEV commands to execute
  140. * @opaque: pointer to the command structure
  141. * @error: SEV FW return code on failure
  142. */
  143. struct sev_issue_cmd {
  144. __u32 cmd; /* In */
  145. __u64 data; /* In */
  146. __u32 error; /* Out */
  147. } __attribute__((packed));
  148. #define SEV_IOC_TYPE 'S'
  149. #define SEV_ISSUE_CMD _IOWR(SEV_IOC_TYPE, 0x0, struct sev_issue_cmd)
  150. #endif /* __PSP_USER_SEV_H */