18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Userspace interface for AMD Secure Encrypted Virtualization (SEV) 48c2ecf20Sopenharmony_ci * platform management commands. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (C) 2016-2017 Advanced Micro Devices, Inc. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Author: Brijesh Singh <brijesh.singh@amd.com> 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * SEV API specification is available at: https://developer.amd.com/sev/ 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#ifndef __PSP_SEV_USER_H__ 148c2ecf20Sopenharmony_ci#define __PSP_SEV_USER_H__ 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#include <linux/types.h> 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci/** 198c2ecf20Sopenharmony_ci * SEV platform commands 208c2ecf20Sopenharmony_ci */ 218c2ecf20Sopenharmony_cienum { 228c2ecf20Sopenharmony_ci SEV_FACTORY_RESET = 0, 238c2ecf20Sopenharmony_ci SEV_PLATFORM_STATUS, 248c2ecf20Sopenharmony_ci SEV_PEK_GEN, 258c2ecf20Sopenharmony_ci SEV_PEK_CSR, 268c2ecf20Sopenharmony_ci SEV_PDH_GEN, 278c2ecf20Sopenharmony_ci SEV_PDH_CERT_EXPORT, 288c2ecf20Sopenharmony_ci SEV_PEK_CERT_IMPORT, 298c2ecf20Sopenharmony_ci SEV_GET_ID, /* This command is deprecated, use SEV_GET_ID2 */ 308c2ecf20Sopenharmony_ci SEV_GET_ID2, 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci SEV_MAX, 338c2ecf20Sopenharmony_ci}; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/** 368c2ecf20Sopenharmony_ci * SEV Firmware status code 378c2ecf20Sopenharmony_ci */ 388c2ecf20Sopenharmony_citypedef enum { 398c2ecf20Sopenharmony_ci SEV_RET_SUCCESS = 0, 408c2ecf20Sopenharmony_ci SEV_RET_INVALID_PLATFORM_STATE, 418c2ecf20Sopenharmony_ci SEV_RET_INVALID_GUEST_STATE, 428c2ecf20Sopenharmony_ci SEV_RET_INAVLID_CONFIG, 438c2ecf20Sopenharmony_ci SEV_RET_INVALID_LEN, 448c2ecf20Sopenharmony_ci SEV_RET_ALREADY_OWNED, 458c2ecf20Sopenharmony_ci SEV_RET_INVALID_CERTIFICATE, 468c2ecf20Sopenharmony_ci SEV_RET_POLICY_FAILURE, 478c2ecf20Sopenharmony_ci SEV_RET_INACTIVE, 488c2ecf20Sopenharmony_ci SEV_RET_INVALID_ADDRESS, 498c2ecf20Sopenharmony_ci SEV_RET_BAD_SIGNATURE, 508c2ecf20Sopenharmony_ci SEV_RET_BAD_MEASUREMENT, 518c2ecf20Sopenharmony_ci SEV_RET_ASID_OWNED, 528c2ecf20Sopenharmony_ci SEV_RET_INVALID_ASID, 538c2ecf20Sopenharmony_ci SEV_RET_WBINVD_REQUIRED, 548c2ecf20Sopenharmony_ci SEV_RET_DFFLUSH_REQUIRED, 558c2ecf20Sopenharmony_ci SEV_RET_INVALID_GUEST, 568c2ecf20Sopenharmony_ci SEV_RET_INVALID_COMMAND, 578c2ecf20Sopenharmony_ci SEV_RET_ACTIVE, 588c2ecf20Sopenharmony_ci SEV_RET_HWSEV_RET_PLATFORM, 598c2ecf20Sopenharmony_ci SEV_RET_HWSEV_RET_UNSAFE, 608c2ecf20Sopenharmony_ci SEV_RET_UNSUPPORTED, 618c2ecf20Sopenharmony_ci SEV_RET_INVALID_PARAM, 628c2ecf20Sopenharmony_ci SEV_RET_RESOURCE_LIMIT, 638c2ecf20Sopenharmony_ci SEV_RET_SECURE_DATA_INVALID, 648c2ecf20Sopenharmony_ci SEV_RET_MAX, 658c2ecf20Sopenharmony_ci} sev_ret_code; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci/** 688c2ecf20Sopenharmony_ci * struct sev_user_data_status - PLATFORM_STATUS command parameters 698c2ecf20Sopenharmony_ci * 708c2ecf20Sopenharmony_ci * @major: major API version 718c2ecf20Sopenharmony_ci * @minor: minor API version 728c2ecf20Sopenharmony_ci * @state: platform state 738c2ecf20Sopenharmony_ci * @flags: platform config flags 748c2ecf20Sopenharmony_ci * @build: firmware build id for API version 758c2ecf20Sopenharmony_ci * @guest_count: number of active guests 768c2ecf20Sopenharmony_ci */ 778c2ecf20Sopenharmony_cistruct sev_user_data_status { 788c2ecf20Sopenharmony_ci __u8 api_major; /* Out */ 798c2ecf20Sopenharmony_ci __u8 api_minor; /* Out */ 808c2ecf20Sopenharmony_ci __u8 state; /* Out */ 818c2ecf20Sopenharmony_ci __u32 flags; /* Out */ 828c2ecf20Sopenharmony_ci __u8 build; /* Out */ 838c2ecf20Sopenharmony_ci __u32 guest_count; /* Out */ 848c2ecf20Sopenharmony_ci} __packed; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci#define SEV_STATUS_FLAGS_CONFIG_ES 0x0100 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/** 898c2ecf20Sopenharmony_ci * struct sev_user_data_pek_csr - PEK_CSR command parameters 908c2ecf20Sopenharmony_ci * 918c2ecf20Sopenharmony_ci * @address: PEK certificate chain 928c2ecf20Sopenharmony_ci * @length: length of certificate 938c2ecf20Sopenharmony_ci */ 948c2ecf20Sopenharmony_cistruct sev_user_data_pek_csr { 958c2ecf20Sopenharmony_ci __u64 address; /* In */ 968c2ecf20Sopenharmony_ci __u32 length; /* In/Out */ 978c2ecf20Sopenharmony_ci} __packed; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/** 1008c2ecf20Sopenharmony_ci * struct sev_user_data_cert_import - PEK_CERT_IMPORT command parameters 1018c2ecf20Sopenharmony_ci * 1028c2ecf20Sopenharmony_ci * @pek_address: PEK certificate chain 1038c2ecf20Sopenharmony_ci * @pek_len: length of PEK certificate 1048c2ecf20Sopenharmony_ci * @oca_address: OCA certificate chain 1058c2ecf20Sopenharmony_ci * @oca_len: length of OCA certificate 1068c2ecf20Sopenharmony_ci */ 1078c2ecf20Sopenharmony_cistruct sev_user_data_pek_cert_import { 1088c2ecf20Sopenharmony_ci __u64 pek_cert_address; /* In */ 1098c2ecf20Sopenharmony_ci __u32 pek_cert_len; /* In */ 1108c2ecf20Sopenharmony_ci __u64 oca_cert_address; /* In */ 1118c2ecf20Sopenharmony_ci __u32 oca_cert_len; /* In */ 1128c2ecf20Sopenharmony_ci} __packed; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci/** 1158c2ecf20Sopenharmony_ci * struct sev_user_data_pdh_cert_export - PDH_CERT_EXPORT command parameters 1168c2ecf20Sopenharmony_ci * 1178c2ecf20Sopenharmony_ci * @pdh_address: PDH certificate address 1188c2ecf20Sopenharmony_ci * @pdh_len: length of PDH certificate 1198c2ecf20Sopenharmony_ci * @cert_chain_address: PDH certificate chain 1208c2ecf20Sopenharmony_ci * @cert_chain_len: length of PDH certificate chain 1218c2ecf20Sopenharmony_ci */ 1228c2ecf20Sopenharmony_cistruct sev_user_data_pdh_cert_export { 1238c2ecf20Sopenharmony_ci __u64 pdh_cert_address; /* In */ 1248c2ecf20Sopenharmony_ci __u32 pdh_cert_len; /* In/Out */ 1258c2ecf20Sopenharmony_ci __u64 cert_chain_address; /* In */ 1268c2ecf20Sopenharmony_ci __u32 cert_chain_len; /* In/Out */ 1278c2ecf20Sopenharmony_ci} __packed; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci/** 1308c2ecf20Sopenharmony_ci * struct sev_user_data_get_id - GET_ID command parameters (deprecated) 1318c2ecf20Sopenharmony_ci * 1328c2ecf20Sopenharmony_ci * @socket1: Buffer to pass unique ID of first socket 1338c2ecf20Sopenharmony_ci * @socket2: Buffer to pass unique ID of second socket 1348c2ecf20Sopenharmony_ci */ 1358c2ecf20Sopenharmony_cistruct sev_user_data_get_id { 1368c2ecf20Sopenharmony_ci __u8 socket1[64]; /* Out */ 1378c2ecf20Sopenharmony_ci __u8 socket2[64]; /* Out */ 1388c2ecf20Sopenharmony_ci} __packed; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci/** 1418c2ecf20Sopenharmony_ci * struct sev_user_data_get_id2 - GET_ID command parameters 1428c2ecf20Sopenharmony_ci * @address: Buffer to store unique ID 1438c2ecf20Sopenharmony_ci * @length: length of the unique ID 1448c2ecf20Sopenharmony_ci */ 1458c2ecf20Sopenharmony_cistruct sev_user_data_get_id2 { 1468c2ecf20Sopenharmony_ci __u64 address; /* In */ 1478c2ecf20Sopenharmony_ci __u32 length; /* In/Out */ 1488c2ecf20Sopenharmony_ci} __packed; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci/** 1518c2ecf20Sopenharmony_ci * struct sev_issue_cmd - SEV ioctl parameters 1528c2ecf20Sopenharmony_ci * 1538c2ecf20Sopenharmony_ci * @cmd: SEV commands to execute 1548c2ecf20Sopenharmony_ci * @opaque: pointer to the command structure 1558c2ecf20Sopenharmony_ci * @error: SEV FW return code on failure 1568c2ecf20Sopenharmony_ci */ 1578c2ecf20Sopenharmony_cistruct sev_issue_cmd { 1588c2ecf20Sopenharmony_ci __u32 cmd; /* In */ 1598c2ecf20Sopenharmony_ci __u64 data; /* In */ 1608c2ecf20Sopenharmony_ci __u32 error; /* Out */ 1618c2ecf20Sopenharmony_ci} __packed; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci#define SEV_IOC_TYPE 'S' 1648c2ecf20Sopenharmony_ci#define SEV_ISSUE_CMD _IOWR(SEV_IOC_TYPE, 0x0, struct sev_issue_cmd) 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci#endif /* __PSP_USER_SEV_H */ 167