xref: /openbmc/qemu/subprojects/libvduse/linux-headers/linux/psp-sev.h (revision ee057a9f2976e1fb2f58e07e86b410f38bf04ac6)
1f363d039SEric Auger /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
29d8ad114SBrijesh Singh /*
39d8ad114SBrijesh Singh  * Userspace interface for AMD Secure Encrypted Virtualization (SEV)
49d8ad114SBrijesh Singh  * platform management commands.
59d8ad114SBrijesh Singh  *
69d8ad114SBrijesh Singh  * Copyright (C) 2016-2017 Advanced Micro Devices, Inc.
79d8ad114SBrijesh Singh  *
89d8ad114SBrijesh Singh  * Author: Brijesh Singh <brijesh.singh@amd.com>
99d8ad114SBrijesh Singh  *
10d9cb4336SCornelia Huck  * SEV API specification is available at: https://developer.amd.com/sev/
119d8ad114SBrijesh Singh  */
129d8ad114SBrijesh Singh 
139d8ad114SBrijesh Singh #ifndef __PSP_SEV_USER_H__
149d8ad114SBrijesh Singh #define __PSP_SEV_USER_H__
159d8ad114SBrijesh Singh 
169d8ad114SBrijesh Singh #include <linux/types.h>
179d8ad114SBrijesh Singh 
189d8ad114SBrijesh Singh /**
199d8ad114SBrijesh Singh  * SEV platform commands
209d8ad114SBrijesh Singh  */
219d8ad114SBrijesh Singh enum {
229d8ad114SBrijesh Singh 	SEV_FACTORY_RESET = 0,
239d8ad114SBrijesh Singh 	SEV_PLATFORM_STATUS,
249d8ad114SBrijesh Singh 	SEV_PEK_GEN,
259d8ad114SBrijesh Singh 	SEV_PEK_CSR,
269d8ad114SBrijesh Singh 	SEV_PDH_GEN,
279d8ad114SBrijesh Singh 	SEV_PDH_CERT_EXPORT,
289d8ad114SBrijesh Singh 	SEV_PEK_CERT_IMPORT,
29d9cb4336SCornelia Huck 	SEV_GET_ID,	/* This command is deprecated, use SEV_GET_ID2 */
30d9cb4336SCornelia Huck 	SEV_GET_ID2,
31ab0c7fb2SPaolo Bonzini 	SNP_PLATFORM_STATUS,
32ab0c7fb2SPaolo Bonzini 	SNP_COMMIT,
33ab0c7fb2SPaolo Bonzini 	SNP_SET_CONFIG,
34*0d2eeef7SBibo Mao 	SNP_VLEK_LOAD,
359d8ad114SBrijesh Singh 
369d8ad114SBrijesh Singh 	SEV_MAX,
379d8ad114SBrijesh Singh };
389d8ad114SBrijesh Singh 
399d8ad114SBrijesh Singh /**
409d8ad114SBrijesh Singh  * SEV Firmware status code
419d8ad114SBrijesh Singh  */
429d8ad114SBrijesh Singh typedef enum {
43d0bf492fSCédric Le Goater 	/*
44d0bf492fSCédric Le Goater 	 * This error code is not in the SEV spec. Its purpose is to convey that
45d0bf492fSCédric Le Goater 	 * there was an error that prevented the SEV firmware from being called.
46d0bf492fSCédric Le Goater 	 * The SEV API error codes are 16 bits, so the -1 value will not overlap
47d0bf492fSCédric Le Goater 	 * with possible values from the specification.
48d0bf492fSCédric Le Goater 	 */
49d0bf492fSCédric Le Goater 	SEV_RET_NO_FW_CALL = -1,
509d8ad114SBrijesh Singh 	SEV_RET_SUCCESS = 0,
519d8ad114SBrijesh Singh 	SEV_RET_INVALID_PLATFORM_STATE,
529d8ad114SBrijesh Singh 	SEV_RET_INVALID_GUEST_STATE,
539d8ad114SBrijesh Singh 	SEV_RET_INAVLID_CONFIG,
54*0d2eeef7SBibo Mao 	SEV_RET_INVALID_CONFIG = SEV_RET_INAVLID_CONFIG,
559d8ad114SBrijesh Singh 	SEV_RET_INVALID_LEN,
569d8ad114SBrijesh Singh 	SEV_RET_ALREADY_OWNED,
579d8ad114SBrijesh Singh 	SEV_RET_INVALID_CERTIFICATE,
589d8ad114SBrijesh Singh 	SEV_RET_POLICY_FAILURE,
599d8ad114SBrijesh Singh 	SEV_RET_INACTIVE,
609d8ad114SBrijesh Singh 	SEV_RET_INVALID_ADDRESS,
619d8ad114SBrijesh Singh 	SEV_RET_BAD_SIGNATURE,
629d8ad114SBrijesh Singh 	SEV_RET_BAD_MEASUREMENT,
639d8ad114SBrijesh Singh 	SEV_RET_ASID_OWNED,
649d8ad114SBrijesh Singh 	SEV_RET_INVALID_ASID,
659d8ad114SBrijesh Singh 	SEV_RET_WBINVD_REQUIRED,
669d8ad114SBrijesh Singh 	SEV_RET_DFFLUSH_REQUIRED,
679d8ad114SBrijesh Singh 	SEV_RET_INVALID_GUEST,
689d8ad114SBrijesh Singh 	SEV_RET_INVALID_COMMAND,
699d8ad114SBrijesh Singh 	SEV_RET_ACTIVE,
709d8ad114SBrijesh Singh 	SEV_RET_HWSEV_RET_PLATFORM,
719d8ad114SBrijesh Singh 	SEV_RET_HWSEV_RET_UNSAFE,
729d8ad114SBrijesh Singh 	SEV_RET_UNSUPPORTED,
732a886794SGreg Kurz 	SEV_RET_INVALID_PARAM,
742a886794SGreg Kurz 	SEV_RET_RESOURCE_LIMIT,
752a886794SGreg Kurz 	SEV_RET_SECURE_DATA_INVALID,
76efb91426SDaniel Henrique Barboza 	SEV_RET_INVALID_KEY = 0x27,
77ab0c7fb2SPaolo Bonzini 	SEV_RET_INVALID_PAGE_SIZE,
78ab0c7fb2SPaolo Bonzini 	SEV_RET_INVALID_PAGE_STATE,
79ab0c7fb2SPaolo Bonzini 	SEV_RET_INVALID_MDATA_ENTRY,
80ab0c7fb2SPaolo Bonzini 	SEV_RET_INVALID_PAGE_OWNER,
81ab0c7fb2SPaolo Bonzini 	SEV_RET_INVALID_PAGE_AEAD_OFLOW,
82ab0c7fb2SPaolo Bonzini 	SEV_RET_RMP_INIT_REQUIRED,
839d8ad114SBrijesh Singh 	SEV_RET_MAX,
849d8ad114SBrijesh Singh } sev_ret_code;
859d8ad114SBrijesh Singh 
869d8ad114SBrijesh Singh /**
879d8ad114SBrijesh Singh  * struct sev_user_data_status - PLATFORM_STATUS command parameters
889d8ad114SBrijesh Singh  *
899d8ad114SBrijesh Singh  * @major: major API version
909d8ad114SBrijesh Singh  * @minor: minor API version
919d8ad114SBrijesh Singh  * @state: platform state
929d8ad114SBrijesh Singh  * @flags: platform config flags
939d8ad114SBrijesh Singh  * @build: firmware build id for API version
949d8ad114SBrijesh Singh  * @guest_count: number of active guests
959d8ad114SBrijesh Singh  */
969d8ad114SBrijesh Singh struct sev_user_data_status {
979d8ad114SBrijesh Singh 	__u8 api_major;				/* Out */
989d8ad114SBrijesh Singh 	__u8 api_minor;				/* Out */
999d8ad114SBrijesh Singh 	__u8 state;				/* Out */
1009d8ad114SBrijesh Singh 	__u32 flags;				/* Out */
1019d8ad114SBrijesh Singh 	__u8 build;				/* Out */
1029d8ad114SBrijesh Singh 	__u32 guest_count;			/* Out */
1039d8ad114SBrijesh Singh } __attribute__((packed));
1049d8ad114SBrijesh Singh 
105f76b348eSCornelia Huck #define SEV_STATUS_FLAGS_CONFIG_ES	0x0100
106f76b348eSCornelia Huck 
1079d8ad114SBrijesh Singh /**
1089d8ad114SBrijesh Singh  * struct sev_user_data_pek_csr - PEK_CSR command parameters
1099d8ad114SBrijesh Singh  *
1109d8ad114SBrijesh Singh  * @address: PEK certificate chain
1119d8ad114SBrijesh Singh  * @length: length of certificate
1129d8ad114SBrijesh Singh  */
1139d8ad114SBrijesh Singh struct sev_user_data_pek_csr {
1149d8ad114SBrijesh Singh 	__u64 address;				/* In */
1159d8ad114SBrijesh Singh 	__u32 length;				/* In/Out */
1169d8ad114SBrijesh Singh } __attribute__((packed));
1179d8ad114SBrijesh Singh 
1189d8ad114SBrijesh Singh /**
1199d8ad114SBrijesh Singh  * struct sev_user_data_cert_import - PEK_CERT_IMPORT command parameters
1209d8ad114SBrijesh Singh  *
1219d8ad114SBrijesh Singh  * @pek_address: PEK certificate chain
1229d8ad114SBrijesh Singh  * @pek_len: length of PEK certificate
1239d8ad114SBrijesh Singh  * @oca_address: OCA certificate chain
1249d8ad114SBrijesh Singh  * @oca_len: length of OCA certificate
1259d8ad114SBrijesh Singh  */
1269d8ad114SBrijesh Singh struct sev_user_data_pek_cert_import {
1279d8ad114SBrijesh Singh 	__u64 pek_cert_address;			/* In */
1289d8ad114SBrijesh Singh 	__u32 pek_cert_len;			/* In */
1299d8ad114SBrijesh Singh 	__u64 oca_cert_address;			/* In */
1309d8ad114SBrijesh Singh 	__u32 oca_cert_len;			/* In */
1319d8ad114SBrijesh Singh } __attribute__((packed));
1329d8ad114SBrijesh Singh 
1339d8ad114SBrijesh Singh /**
1349d8ad114SBrijesh Singh  * struct sev_user_data_pdh_cert_export - PDH_CERT_EXPORT command parameters
1359d8ad114SBrijesh Singh  *
1369d8ad114SBrijesh Singh  * @pdh_address: PDH certificate address
1379d8ad114SBrijesh Singh  * @pdh_len: length of PDH certificate
1389d8ad114SBrijesh Singh  * @cert_chain_address: PDH certificate chain
1399d8ad114SBrijesh Singh  * @cert_chain_len: length of PDH certificate chain
1409d8ad114SBrijesh Singh  */
1419d8ad114SBrijesh Singh struct sev_user_data_pdh_cert_export {
1429d8ad114SBrijesh Singh 	__u64 pdh_cert_address;			/* In */
1439d8ad114SBrijesh Singh 	__u32 pdh_cert_len;			/* In/Out */
1449d8ad114SBrijesh Singh 	__u64 cert_chain_address;		/* In */
1459d8ad114SBrijesh Singh 	__u32 cert_chain_len;			/* In/Out */
1469d8ad114SBrijesh Singh } __attribute__((packed));
1479d8ad114SBrijesh Singh 
1489d8ad114SBrijesh Singh /**
149d9cb4336SCornelia Huck  * struct sev_user_data_get_id - GET_ID command parameters (deprecated)
15077d361b1SEric Auger  *
15177d361b1SEric Auger  * @socket1: Buffer to pass unique ID of first socket
15277d361b1SEric Auger  * @socket2: Buffer to pass unique ID of second socket
15377d361b1SEric Auger  */
15477d361b1SEric Auger struct sev_user_data_get_id {
15577d361b1SEric Auger 	__u8 socket1[64];			/* Out */
15677d361b1SEric Auger 	__u8 socket2[64];			/* Out */
15777d361b1SEric Auger } __attribute__((packed));
15877d361b1SEric Auger 
15977d361b1SEric Auger /**
160d9cb4336SCornelia Huck  * struct sev_user_data_get_id2 - GET_ID command parameters
161d9cb4336SCornelia Huck  * @address: Buffer to store unique ID
162d9cb4336SCornelia Huck  * @length: length of the unique ID
163d9cb4336SCornelia Huck  */
164d9cb4336SCornelia Huck struct sev_user_data_get_id2 {
165d9cb4336SCornelia Huck 	__u64 address;				/* In */
166d9cb4336SCornelia Huck 	__u32 length;				/* In/Out */
167d9cb4336SCornelia Huck } __attribute__((packed));
168d9cb4336SCornelia Huck 
169d9cb4336SCornelia Huck /**
170ab0c7fb2SPaolo Bonzini  * struct sev_user_data_snp_status - SNP status
171ab0c7fb2SPaolo Bonzini  *
172ab0c7fb2SPaolo Bonzini  * @api_major: API major version
173ab0c7fb2SPaolo Bonzini  * @api_minor: API minor version
174ab0c7fb2SPaolo Bonzini  * @state: current platform state
175ab0c7fb2SPaolo Bonzini  * @is_rmp_initialized: whether RMP is initialized or not
176ab0c7fb2SPaolo Bonzini  * @rsvd: reserved
177ab0c7fb2SPaolo Bonzini  * @build_id: firmware build id for the API version
178ab0c7fb2SPaolo Bonzini  * @mask_chip_id: whether chip id is present in attestation reports or not
179ab0c7fb2SPaolo Bonzini  * @mask_chip_key: whether attestation reports are signed or not
180ab0c7fb2SPaolo Bonzini  * @vlek_en: VLEK (Version Loaded Endorsement Key) hashstick is loaded
181ab0c7fb2SPaolo Bonzini  * @rsvd1: reserved
182ab0c7fb2SPaolo Bonzini  * @guest_count: the number of guest currently managed by the firmware
183ab0c7fb2SPaolo Bonzini  * @current_tcb_version: current TCB version
184ab0c7fb2SPaolo Bonzini  * @reported_tcb_version: reported TCB version
185ab0c7fb2SPaolo Bonzini  */
186ab0c7fb2SPaolo Bonzini struct sev_user_data_snp_status {
187ab0c7fb2SPaolo Bonzini 	__u8 api_major;			/* Out */
188ab0c7fb2SPaolo Bonzini 	__u8 api_minor;			/* Out */
189ab0c7fb2SPaolo Bonzini 	__u8 state;			/* Out */
190ab0c7fb2SPaolo Bonzini 	__u8 is_rmp_initialized:1;	/* Out */
191ab0c7fb2SPaolo Bonzini 	__u8 rsvd:7;
192ab0c7fb2SPaolo Bonzini 	__u32 build_id;			/* Out */
193ab0c7fb2SPaolo Bonzini 	__u32 mask_chip_id:1;		/* Out */
194ab0c7fb2SPaolo Bonzini 	__u32 mask_chip_key:1;		/* Out */
195ab0c7fb2SPaolo Bonzini 	__u32 vlek_en:1;		/* Out */
196ab0c7fb2SPaolo Bonzini 	__u32 rsvd1:29;
197ab0c7fb2SPaolo Bonzini 	__u32 guest_count;		/* Out */
198ab0c7fb2SPaolo Bonzini 	__u64 current_tcb_version;	/* Out */
199ab0c7fb2SPaolo Bonzini 	__u64 reported_tcb_version;	/* Out */
200ab0c7fb2SPaolo Bonzini } __attribute__((packed));
201ab0c7fb2SPaolo Bonzini 
202ab0c7fb2SPaolo Bonzini /**
203ab0c7fb2SPaolo Bonzini  * struct sev_user_data_snp_config - system wide configuration value for SNP.
204ab0c7fb2SPaolo Bonzini  *
205ab0c7fb2SPaolo Bonzini  * @reported_tcb: the TCB version to report in the guest attestation report.
206ab0c7fb2SPaolo Bonzini  * @mask_chip_id: whether chip id is present in attestation reports or not
207ab0c7fb2SPaolo Bonzini  * @mask_chip_key: whether attestation reports are signed or not
208ab0c7fb2SPaolo Bonzini  * @rsvd: reserved
209ab0c7fb2SPaolo Bonzini  * @rsvd1: reserved
210ab0c7fb2SPaolo Bonzini  */
211ab0c7fb2SPaolo Bonzini struct sev_user_data_snp_config {
212ab0c7fb2SPaolo Bonzini 	__u64 reported_tcb  ;   /* In */
213ab0c7fb2SPaolo Bonzini 	__u32 mask_chip_id:1;   /* In */
214ab0c7fb2SPaolo Bonzini 	__u32 mask_chip_key:1;  /* In */
215ab0c7fb2SPaolo Bonzini 	__u32 rsvd:30;          /* In */
216ab0c7fb2SPaolo Bonzini 	__u8 rsvd1[52];
217ab0c7fb2SPaolo Bonzini } __attribute__((packed));
218ab0c7fb2SPaolo Bonzini 
219ab0c7fb2SPaolo Bonzini /**
220*0d2eeef7SBibo Mao  * struct sev_data_snp_vlek_load - SNP_VLEK_LOAD structure
221*0d2eeef7SBibo Mao  *
222*0d2eeef7SBibo Mao  * @len: length of the command buffer read by the PSP
223*0d2eeef7SBibo Mao  * @vlek_wrapped_version: version of wrapped VLEK hashstick (Must be 0h)
224*0d2eeef7SBibo Mao  * @rsvd: reserved
225*0d2eeef7SBibo Mao  * @vlek_wrapped_address: address of a wrapped VLEK hashstick
226*0d2eeef7SBibo Mao  *                        (struct sev_user_data_snp_wrapped_vlek_hashstick)
227*0d2eeef7SBibo Mao  */
228*0d2eeef7SBibo Mao struct sev_user_data_snp_vlek_load {
229*0d2eeef7SBibo Mao 	__u32 len;				/* In */
230*0d2eeef7SBibo Mao 	__u8 vlek_wrapped_version;		/* In */
231*0d2eeef7SBibo Mao 	__u8 rsvd[3];				/* In */
232*0d2eeef7SBibo Mao 	__u64 vlek_wrapped_address;		/* In */
233*0d2eeef7SBibo Mao } __attribute__((packed));
234*0d2eeef7SBibo Mao 
235*0d2eeef7SBibo Mao /**
236*0d2eeef7SBibo Mao  * struct sev_user_data_snp_vlek_wrapped_vlek_hashstick - Wrapped VLEK data
237*0d2eeef7SBibo Mao  *
238*0d2eeef7SBibo Mao  * @data: Opaque data provided by AMD KDS (as described in SEV-SNP Firmware ABI
239*0d2eeef7SBibo Mao  *        1.54, SNP_VLEK_LOAD)
240*0d2eeef7SBibo Mao  */
241*0d2eeef7SBibo Mao struct sev_user_data_snp_wrapped_vlek_hashstick {
242*0d2eeef7SBibo Mao 	__u8 data[432];				/* In */
243*0d2eeef7SBibo Mao } __attribute__((packed));
244*0d2eeef7SBibo Mao 
245*0d2eeef7SBibo Mao /**
2469d8ad114SBrijesh Singh  * struct sev_issue_cmd - SEV ioctl parameters
2479d8ad114SBrijesh Singh  *
2489d8ad114SBrijesh Singh  * @cmd: SEV commands to execute
2499d8ad114SBrijesh Singh  * @opaque: pointer to the command structure
2509d8ad114SBrijesh Singh  * @error: SEV FW return code on failure
2519d8ad114SBrijesh Singh  */
2529d8ad114SBrijesh Singh struct sev_issue_cmd {
2539d8ad114SBrijesh Singh 	__u32 cmd;				/* In */
2549d8ad114SBrijesh Singh 	__u64 data;				/* In */
2559d8ad114SBrijesh Singh 	__u32 error;				/* Out */
2569d8ad114SBrijesh Singh } __attribute__((packed));
2579d8ad114SBrijesh Singh 
2589d8ad114SBrijesh Singh #define SEV_IOC_TYPE		'S'
2599d8ad114SBrijesh Singh #define SEV_ISSUE_CMD	_IOWR(SEV_IOC_TYPE, 0x0, struct sev_issue_cmd)
2609d8ad114SBrijesh Singh 
2619d8ad114SBrijesh Singh #endif /* __PSP_USER_SEV_H */
262