1 /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
3 * Userspace interface for AMD Secure Encrypted Virtualization (SEV)
4 * platform management commands.
6 * Copyright (C) 2016-2017 Advanced Micro Devices, Inc.
8 * Author: Brijesh Singh <brijesh.singh@amd.com>
10 * SEV API specification is available at: https://developer.amd.com/sev/
13 #ifndef __PSP_SEV_USER_H__
14 #define __PSP_SEV_USER_H__
16 #include <linux/types.h>
19 * SEV platform commands
22 SEV_FACTORY_RESET
= 0,
29 SEV_GET_ID
, /* This command is deprecated, use SEV_GET_ID2 */
39 * SEV Firmware status code
43 * This error code is not in the SEV spec. Its purpose is to convey that
44 * there was an error that prevented the SEV firmware from being called.
45 * The SEV API error codes are 16 bits, so the -1 value will not overlap
46 * with possible values from the specification.
48 SEV_RET_NO_FW_CALL
= -1,
50 SEV_RET_INVALID_PLATFORM_STATE
,
51 SEV_RET_INVALID_GUEST_STATE
,
52 SEV_RET_INAVLID_CONFIG
,
54 SEV_RET_ALREADY_OWNED
,
55 SEV_RET_INVALID_CERTIFICATE
,
56 SEV_RET_POLICY_FAILURE
,
58 SEV_RET_INVALID_ADDRESS
,
59 SEV_RET_BAD_SIGNATURE
,
60 SEV_RET_BAD_MEASUREMENT
,
63 SEV_RET_WBINVD_REQUIRED
,
64 SEV_RET_DFFLUSH_REQUIRED
,
65 SEV_RET_INVALID_GUEST
,
66 SEV_RET_INVALID_COMMAND
,
68 SEV_RET_HWSEV_RET_PLATFORM
,
69 SEV_RET_HWSEV_RET_UNSAFE
,
71 SEV_RET_INVALID_PARAM
,
72 SEV_RET_RESOURCE_LIMIT
,
73 SEV_RET_SECURE_DATA_INVALID
,
74 SEV_RET_INVALID_KEY
= 0x27,
75 SEV_RET_INVALID_PAGE_SIZE
,
76 SEV_RET_INVALID_PAGE_STATE
,
77 SEV_RET_INVALID_MDATA_ENTRY
,
78 SEV_RET_INVALID_PAGE_OWNER
,
79 SEV_RET_INVALID_PAGE_AEAD_OFLOW
,
80 SEV_RET_RMP_INIT_REQUIRED
,
85 * struct sev_user_data_status - PLATFORM_STATUS command parameters
87 * @major: major API version
88 * @minor: minor API version
89 * @state: platform state
90 * @flags: platform config flags
91 * @build: firmware build id for API version
92 * @guest_count: number of active guests
94 struct sev_user_data_status
{
95 __u8 api_major
; /* Out */
96 __u8 api_minor
; /* Out */
98 __u32 flags
; /* Out */
100 __u32 guest_count
; /* Out */
101 } __attribute__((packed
));
103 #define SEV_STATUS_FLAGS_CONFIG_ES 0x0100
106 * struct sev_user_data_pek_csr - PEK_CSR command parameters
108 * @address: PEK certificate chain
109 * @length: length of certificate
111 struct sev_user_data_pek_csr
{
112 __u64 address
; /* In */
113 __u32 length
; /* In/Out */
114 } __attribute__((packed
));
117 * struct sev_user_data_cert_import - PEK_CERT_IMPORT command parameters
119 * @pek_address: PEK certificate chain
120 * @pek_len: length of PEK certificate
121 * @oca_address: OCA certificate chain
122 * @oca_len: length of OCA certificate
124 struct sev_user_data_pek_cert_import
{
125 __u64 pek_cert_address
; /* In */
126 __u32 pek_cert_len
; /* In */
127 __u64 oca_cert_address
; /* In */
128 __u32 oca_cert_len
; /* In */
129 } __attribute__((packed
));
132 * struct sev_user_data_pdh_cert_export - PDH_CERT_EXPORT command parameters
134 * @pdh_address: PDH certificate address
135 * @pdh_len: length of PDH certificate
136 * @cert_chain_address: PDH certificate chain
137 * @cert_chain_len: length of PDH certificate chain
139 struct sev_user_data_pdh_cert_export
{
140 __u64 pdh_cert_address
; /* In */
141 __u32 pdh_cert_len
; /* In/Out */
142 __u64 cert_chain_address
; /* In */
143 __u32 cert_chain_len
; /* In/Out */
144 } __attribute__((packed
));
147 * struct sev_user_data_get_id - GET_ID command parameters (deprecated)
149 * @socket1: Buffer to pass unique ID of first socket
150 * @socket2: Buffer to pass unique ID of second socket
152 struct sev_user_data_get_id
{
153 __u8 socket1
[64]; /* Out */
154 __u8 socket2
[64]; /* Out */
155 } __attribute__((packed
));
158 * struct sev_user_data_get_id2 - GET_ID command parameters
159 * @address: Buffer to store unique ID
160 * @length: length of the unique ID
162 struct sev_user_data_get_id2
{
163 __u64 address
; /* In */
164 __u32 length
; /* In/Out */
165 } __attribute__((packed
));
168 * struct sev_user_data_snp_status - SNP status
170 * @api_major: API major version
171 * @api_minor: API minor version
172 * @state: current platform state
173 * @is_rmp_initialized: whether RMP is initialized or not
175 * @build_id: firmware build id for the API version
176 * @mask_chip_id: whether chip id is present in attestation reports or not
177 * @mask_chip_key: whether attestation reports are signed or not
178 * @vlek_en: VLEK (Version Loaded Endorsement Key) hashstick is loaded
180 * @guest_count: the number of guest currently managed by the firmware
181 * @current_tcb_version: current TCB version
182 * @reported_tcb_version: reported TCB version
184 struct sev_user_data_snp_status
{
185 __u8 api_major
; /* Out */
186 __u8 api_minor
; /* Out */
187 __u8 state
; /* Out */
188 __u8 is_rmp_initialized
:1; /* Out */
190 __u32 build_id
; /* Out */
191 __u32 mask_chip_id
:1; /* Out */
192 __u32 mask_chip_key
:1; /* Out */
193 __u32 vlek_en
:1; /* Out */
195 __u32 guest_count
; /* Out */
196 __u64 current_tcb_version
; /* Out */
197 __u64 reported_tcb_version
; /* Out */
198 } __attribute__((packed
));
201 * struct sev_user_data_snp_config - system wide configuration value for SNP.
203 * @reported_tcb: the TCB version to report in the guest attestation report.
204 * @mask_chip_id: whether chip id is present in attestation reports or not
205 * @mask_chip_key: whether attestation reports are signed or not
209 struct sev_user_data_snp_config
{
210 __u64 reported_tcb
; /* In */
211 __u32 mask_chip_id
:1; /* In */
212 __u32 mask_chip_key
:1; /* In */
213 __u32 rsvd
:30; /* In */
215 } __attribute__((packed
));
218 * struct sev_issue_cmd - SEV ioctl parameters
220 * @cmd: SEV commands to execute
221 * @opaque: pointer to the command structure
222 * @error: SEV FW return code on failure
224 struct sev_issue_cmd
{
227 __u32 error
; /* Out */
228 } __attribute__((packed
));
230 #define SEV_IOC_TYPE 'S'
231 #define SEV_ISSUE_CMD _IOWR(SEV_IOC_TYPE, 0x0, struct sev_issue_cmd)
233 #endif /* __PSP_USER_SEV_H */