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 13 #ifndef __PSP_SEV_USER_H__ 14 #define __PSP_SEV_USER_H__ 15 16 #include <linux/types.h> 17 18 /** 19 * SEV platform commands 20 */ 21 enum { 22 SEV_FACTORY_RESET = 0, 23 SEV_PLATFORM_STATUS, 24 SEV_PEK_GEN, 25 SEV_PEK_CSR, 26 SEV_PDH_GEN, 27 SEV_PDH_CERT_EXPORT, 28 SEV_PEK_CERT_IMPORT, 29 SEV_GET_ID, /* This command is deprecated, use SEV_GET_ID2 */ 30 SEV_GET_ID2, 31 SNP_PLATFORM_STATUS, 32 33 SEV_MAX, 34 }; 35 36 /** 37 * SEV Firmware status code 38 */ 39 typedef enum { 40 /* 41 * This error code is not in the SEV spec. Its purpose is to convey that 42 * there was an error that prevented the SEV firmware from being called. 43 * The SEV API error codes are 16 bits, so the -1 value will not overlap 44 * with possible values from the specification. 45 */ 46 SEV_RET_NO_FW_CALL = -1, 47 SEV_RET_SUCCESS = 0, 48 SEV_RET_INVALID_PLATFORM_STATE, 49 SEV_RET_INVALID_GUEST_STATE, 50 SEV_RET_INAVLID_CONFIG, 51 SEV_RET_INVALID_LEN, 52 SEV_RET_ALREADY_OWNED, 53 SEV_RET_INVALID_CERTIFICATE, 54 SEV_RET_POLICY_FAILURE, 55 SEV_RET_INACTIVE, 56 SEV_RET_INVALID_ADDRESS, 57 SEV_RET_BAD_SIGNATURE, 58 SEV_RET_BAD_MEASUREMENT, 59 SEV_RET_ASID_OWNED, 60 SEV_RET_INVALID_ASID, 61 SEV_RET_WBINVD_REQUIRED, 62 SEV_RET_DFFLUSH_REQUIRED, 63 SEV_RET_INVALID_GUEST, 64 SEV_RET_INVALID_COMMAND, 65 SEV_RET_ACTIVE, 66 SEV_RET_HWSEV_RET_PLATFORM, 67 SEV_RET_HWSEV_RET_UNSAFE, 68 SEV_RET_UNSUPPORTED, 69 SEV_RET_INVALID_PARAM, 70 SEV_RET_RESOURCE_LIMIT, 71 SEV_RET_SECURE_DATA_INVALID, 72 SEV_RET_INVALID_KEY = 0x27, 73 SEV_RET_INVALID_PAGE_SIZE, 74 SEV_RET_INVALID_PAGE_STATE, 75 SEV_RET_INVALID_MDATA_ENTRY, 76 SEV_RET_INVALID_PAGE_OWNER, 77 SEV_RET_INVALID_PAGE_AEAD_OFLOW, 78 SEV_RET_RMP_INIT_REQUIRED, 79 SEV_RET_MAX, 80 } sev_ret_code; 81 82 /** 83 * struct sev_user_data_status - PLATFORM_STATUS command parameters 84 * 85 * @major: major API version 86 * @minor: minor API version 87 * @state: platform state 88 * @flags: platform config flags 89 * @build: firmware build id for API version 90 * @guest_count: number of active guests 91 */ 92 struct sev_user_data_status { 93 __u8 api_major; /* Out */ 94 __u8 api_minor; /* Out */ 95 __u8 state; /* Out */ 96 __u32 flags; /* Out */ 97 __u8 build; /* Out */ 98 __u32 guest_count; /* Out */ 99 } __packed; 100 101 #define SEV_STATUS_FLAGS_CONFIG_ES 0x0100 102 103 /** 104 * struct sev_user_data_pek_csr - PEK_CSR command parameters 105 * 106 * @address: PEK certificate chain 107 * @length: length of certificate 108 */ 109 struct sev_user_data_pek_csr { 110 __u64 address; /* In */ 111 __u32 length; /* In/Out */ 112 } __packed; 113 114 /** 115 * struct sev_user_data_cert_import - PEK_CERT_IMPORT command parameters 116 * 117 * @pek_address: PEK certificate chain 118 * @pek_len: length of PEK certificate 119 * @oca_address: OCA certificate chain 120 * @oca_len: length of OCA certificate 121 */ 122 struct sev_user_data_pek_cert_import { 123 __u64 pek_cert_address; /* In */ 124 __u32 pek_cert_len; /* In */ 125 __u64 oca_cert_address; /* In */ 126 __u32 oca_cert_len; /* In */ 127 } __packed; 128 129 /** 130 * struct sev_user_data_pdh_cert_export - PDH_CERT_EXPORT command parameters 131 * 132 * @pdh_address: PDH certificate address 133 * @pdh_len: length of PDH certificate 134 * @cert_chain_address: PDH certificate chain 135 * @cert_chain_len: length of PDH certificate chain 136 */ 137 struct sev_user_data_pdh_cert_export { 138 __u64 pdh_cert_address; /* In */ 139 __u32 pdh_cert_len; /* In/Out */ 140 __u64 cert_chain_address; /* In */ 141 __u32 cert_chain_len; /* In/Out */ 142 } __packed; 143 144 /** 145 * struct sev_user_data_get_id - GET_ID command parameters (deprecated) 146 * 147 * @socket1: Buffer to pass unique ID of first socket 148 * @socket2: Buffer to pass unique ID of second socket 149 */ 150 struct sev_user_data_get_id { 151 __u8 socket1[64]; /* Out */ 152 __u8 socket2[64]; /* Out */ 153 } __packed; 154 155 /** 156 * struct sev_user_data_get_id2 - GET_ID command parameters 157 * @address: Buffer to store unique ID 158 * @length: length of the unique ID 159 */ 160 struct sev_user_data_get_id2 { 161 __u64 address; /* In */ 162 __u32 length; /* In/Out */ 163 } __packed; 164 165 /** 166 * struct sev_user_data_snp_status - SNP status 167 * 168 * @api_major: API major version 169 * @api_minor: API minor version 170 * @state: current platform state 171 * @is_rmp_initialized: whether RMP is initialized or not 172 * @rsvd: reserved 173 * @build_id: firmware build id for the API version 174 * @mask_chip_id: whether chip id is present in attestation reports or not 175 * @mask_chip_key: whether attestation reports are signed or not 176 * @vlek_en: VLEK (Version Loaded Endorsement Key) hashstick is loaded 177 * @rsvd1: reserved 178 * @guest_count: the number of guest currently managed by the firmware 179 * @current_tcb_version: current TCB version 180 * @reported_tcb_version: reported TCB version 181 */ 182 struct sev_user_data_snp_status { 183 __u8 api_major; /* Out */ 184 __u8 api_minor; /* Out */ 185 __u8 state; /* Out */ 186 __u8 is_rmp_initialized:1; /* Out */ 187 __u8 rsvd:7; 188 __u32 build_id; /* Out */ 189 __u32 mask_chip_id:1; /* Out */ 190 __u32 mask_chip_key:1; /* Out */ 191 __u32 vlek_en:1; /* Out */ 192 __u32 rsvd1:29; 193 __u32 guest_count; /* Out */ 194 __u64 current_tcb_version; /* Out */ 195 __u64 reported_tcb_version; /* Out */ 196 } __packed; 197 198 /** 199 * struct sev_user_data_snp_config - system wide configuration value for SNP. 200 * 201 * @reported_tcb: the TCB version to report in the guest attestation report. 202 * @mask_chip_id: whether chip id is present in attestation reports or not 203 * @mask_chip_key: whether attestation reports are signed or not 204 * @rsvd: reserved 205 * @rsvd1: reserved 206 */ 207 struct sev_user_data_snp_config { 208 __u64 reported_tcb ; /* In */ 209 __u32 mask_chip_id:1; /* In */ 210 __u32 mask_chip_key:1; /* In */ 211 __u32 rsvd:30; /* In */ 212 __u8 rsvd1[52]; 213 } __packed; 214 215 /** 216 * struct sev_issue_cmd - SEV ioctl parameters 217 * 218 * @cmd: SEV commands to execute 219 * @opaque: pointer to the command structure 220 * @error: SEV FW return code on failure 221 */ 222 struct sev_issue_cmd { 223 __u32 cmd; /* In */ 224 __u64 data; /* In */ 225 __u32 error; /* Out */ 226 } __packed; 227 228 #define SEV_IOC_TYPE 'S' 229 #define SEV_ISSUE_CMD _IOWR(SEV_IOC_TYPE, 0x0, struct sev_issue_cmd) 230 231 #endif /* __PSP_USER_SEV_H */ 232