xref: /linux/include/uapi/linux/psp-sev.h (revision 1260ed77798502de9c98020040d2995008de10cc)
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 	SNP_COMMIT,
33 	SNP_SET_CONFIG,
34 	SNP_VLEK_LOAD,
35 
36 	SEV_MAX,
37 };
38 
39 /**
40  * SEV Firmware status code
41  */
42 typedef enum {
43 	/*
44 	 * This error code is not in the SEV spec. Its purpose is to convey that
45 	 * there was an error that prevented the SEV firmware from being called.
46 	 * The SEV API error codes are 16 bits, so the -1 value will not overlap
47 	 * with possible values from the specification.
48 	 */
49 	SEV_RET_NO_FW_CALL = -1,
50 	SEV_RET_SUCCESS = 0,
51 	SEV_RET_INVALID_PLATFORM_STATE,
52 	SEV_RET_INVALID_GUEST_STATE,
53 	SEV_RET_INAVLID_CONFIG,
54 	SEV_RET_INVALID_CONFIG = SEV_RET_INAVLID_CONFIG,
55 	SEV_RET_INVALID_LEN,
56 	SEV_RET_ALREADY_OWNED,
57 	SEV_RET_INVALID_CERTIFICATE,
58 	SEV_RET_POLICY_FAILURE,
59 	SEV_RET_INACTIVE,
60 	SEV_RET_INVALID_ADDRESS,
61 	SEV_RET_BAD_SIGNATURE,
62 	SEV_RET_BAD_MEASUREMENT,
63 	SEV_RET_ASID_OWNED,
64 	SEV_RET_INVALID_ASID,
65 	SEV_RET_WBINVD_REQUIRED,
66 	SEV_RET_DFFLUSH_REQUIRED,
67 	SEV_RET_INVALID_GUEST,
68 	SEV_RET_INVALID_COMMAND,
69 	SEV_RET_ACTIVE,
70 	SEV_RET_HWSEV_RET_PLATFORM,
71 	SEV_RET_HWSEV_RET_UNSAFE,
72 	SEV_RET_UNSUPPORTED,
73 	SEV_RET_INVALID_PARAM,
74 	SEV_RET_RESOURCE_LIMIT,
75 	SEV_RET_SECURE_DATA_INVALID,
76 	SEV_RET_INVALID_PAGE_SIZE          = 0x0019,
77 	SEV_RET_INVALID_PAGE_STATE         = 0x001A,
78 	SEV_RET_INVALID_MDATA_ENTRY        = 0x001B,
79 	SEV_RET_INVALID_PAGE_OWNER         = 0x001C,
80 	SEV_RET_AEAD_OFLOW                 = 0x001D,
81 	SEV_RET_EXIT_RING_BUFFER           = 0x001F,
82 	SEV_RET_RMP_INIT_REQUIRED          = 0x0020,
83 	SEV_RET_BAD_SVN                    = 0x0021,
84 	SEV_RET_BAD_VERSION                = 0x0022,
85 	SEV_RET_SHUTDOWN_REQUIRED          = 0x0023,
86 	SEV_RET_UPDATE_FAILED              = 0x0024,
87 	SEV_RET_RESTORE_REQUIRED           = 0x0025,
88 	SEV_RET_RMP_INITIALIZATION_FAILED  = 0x0026,
89 	SEV_RET_INVALID_KEY                = 0x0027,
90 	SEV_RET_MAX,
91 } sev_ret_code;
92 
93 /**
94  * struct sev_user_data_status - PLATFORM_STATUS command parameters
95  *
96  * @major: major API version
97  * @minor: minor API version
98  * @state: platform state
99  * @flags: platform config flags
100  * @build: firmware build id for API version
101  * @guest_count: number of active guests
102  */
103 struct sev_user_data_status {
104 	__u8 api_major;				/* Out */
105 	__u8 api_minor;				/* Out */
106 	__u8 state;				/* Out */
107 	__u32 flags;				/* Out */
108 	__u8 build;				/* Out */
109 	__u32 guest_count;			/* Out */
110 } __packed;
111 
112 #define SEV_STATUS_FLAGS_CONFIG_ES	0x0100
113 
114 /**
115  * struct sev_user_data_pek_csr - PEK_CSR command parameters
116  *
117  * @address: PEK certificate chain
118  * @length: length of certificate
119  */
120 struct sev_user_data_pek_csr {
121 	__u64 address;				/* In */
122 	__u32 length;				/* In/Out */
123 } __packed;
124 
125 /**
126  * struct sev_user_data_cert_import - PEK_CERT_IMPORT command parameters
127  *
128  * @pek_address: PEK certificate chain
129  * @pek_len: length of PEK certificate
130  * @oca_address: OCA certificate chain
131  * @oca_len: length of OCA certificate
132  */
133 struct sev_user_data_pek_cert_import {
134 	__u64 pek_cert_address;			/* In */
135 	__u32 pek_cert_len;			/* In */
136 	__u64 oca_cert_address;			/* In */
137 	__u32 oca_cert_len;			/* In */
138 } __packed;
139 
140 /**
141  * struct sev_user_data_pdh_cert_export - PDH_CERT_EXPORT command parameters
142  *
143  * @pdh_address: PDH certificate address
144  * @pdh_len: length of PDH certificate
145  * @cert_chain_address: PDH certificate chain
146  * @cert_chain_len: length of PDH certificate chain
147  */
148 struct sev_user_data_pdh_cert_export {
149 	__u64 pdh_cert_address;			/* In */
150 	__u32 pdh_cert_len;			/* In/Out */
151 	__u64 cert_chain_address;		/* In */
152 	__u32 cert_chain_len;			/* In/Out */
153 } __packed;
154 
155 /**
156  * struct sev_user_data_get_id - GET_ID command parameters (deprecated)
157  *
158  * @socket1: Buffer to pass unique ID of first socket
159  * @socket2: Buffer to pass unique ID of second socket
160  */
161 struct sev_user_data_get_id {
162 	__u8 socket1[64];			/* Out */
163 	__u8 socket2[64];			/* Out */
164 } __packed;
165 
166 /**
167  * struct sev_user_data_get_id2 - GET_ID command parameters
168  * @address: Buffer to store unique ID
169  * @length: length of the unique ID
170  */
171 struct sev_user_data_get_id2 {
172 	__u64 address;				/* In */
173 	__u32 length;				/* In/Out */
174 } __packed;
175 
176 /**
177  * struct sev_user_data_snp_status - SNP status
178  *
179  * @api_major: API major version
180  * @api_minor: API minor version
181  * @state: current platform state
182  * @is_rmp_initialized: whether RMP is initialized or not
183  * @rsvd: reserved
184  * @build_id: firmware build id for the API version
185  * @mask_chip_id: whether chip id is present in attestation reports or not
186  * @mask_chip_key: whether attestation reports are signed or not
187  * @vlek_en: VLEK (Version Loaded Endorsement Key) hashstick is loaded
188  * @rsvd1: reserved
189  * @guest_count: the number of guest currently managed by the firmware
190  * @current_tcb_version: current TCB version
191  * @reported_tcb_version: reported TCB version
192  */
193 struct sev_user_data_snp_status {
194 	__u8 api_major;			/* Out */
195 	__u8 api_minor;			/* Out */
196 	__u8 state;			/* Out */
197 	__u8 is_rmp_initialized:1;	/* Out */
198 	__u8 rsvd:7;
199 	__u32 build_id;			/* Out */
200 	__u32 mask_chip_id:1;		/* Out */
201 	__u32 mask_chip_key:1;		/* Out */
202 	__u32 vlek_en:1;		/* Out */
203 	__u32 rsvd1:29;
204 	__u32 guest_count;		/* Out */
205 	__u64 current_tcb_version;	/* Out */
206 	__u64 reported_tcb_version;	/* Out */
207 } __packed;
208 
209 /**
210  * struct sev_user_data_snp_config - system wide configuration value for SNP.
211  *
212  * @reported_tcb: the TCB version to report in the guest attestation report.
213  * @mask_chip_id: whether chip id is present in attestation reports or not
214  * @mask_chip_key: whether attestation reports are signed or not
215  * @rsvd: reserved
216  * @rsvd1: reserved
217  */
218 struct sev_user_data_snp_config {
219 	__u64 reported_tcb  ;   /* In */
220 	__u32 mask_chip_id:1;   /* In */
221 	__u32 mask_chip_key:1;  /* In */
222 	__u32 rsvd:30;          /* In */
223 	__u8 rsvd1[52];
224 } __packed;
225 
226 /**
227  * struct sev_data_snp_vlek_load - SNP_VLEK_LOAD structure
228  *
229  * @len: length of the command buffer read by the PSP
230  * @vlek_wrapped_version: version of wrapped VLEK hashstick (Must be 0h)
231  * @rsvd: reserved
232  * @vlek_wrapped_address: address of a wrapped VLEK hashstick
233  *                        (struct sev_user_data_snp_wrapped_vlek_hashstick)
234  */
235 struct sev_user_data_snp_vlek_load {
236 	__u32 len;				/* In */
237 	__u8 vlek_wrapped_version;		/* In */
238 	__u8 rsvd[3];				/* In */
239 	__u64 vlek_wrapped_address;		/* In */
240 } __packed;
241 
242 /**
243  * struct sev_user_data_snp_vlek_wrapped_vlek_hashstick - Wrapped VLEK data
244  *
245  * @data: Opaque data provided by AMD KDS (as described in SEV-SNP Firmware ABI
246  *        1.54, SNP_VLEK_LOAD)
247  */
248 struct sev_user_data_snp_wrapped_vlek_hashstick {
249 	__u8 data[432];				/* In */
250 } __packed;
251 
252 /**
253  * struct sev_issue_cmd - SEV ioctl parameters
254  *
255  * @cmd: SEV commands to execute
256  * @opaque: pointer to the command structure
257  * @error: SEV FW return code on failure
258  */
259 struct sev_issue_cmd {
260 	__u32 cmd;				/* In */
261 	__u64 data;				/* In */
262 	__u32 error;				/* Out */
263 } __packed;
264 
265 #define SEV_IOC_TYPE		'S'
266 #define SEV_ISSUE_CMD	_IOWR(SEV_IOC_TYPE, 0x0, struct sev_issue_cmd)
267 
268 #endif /* __PSP_USER_SEV_H */
269