cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

psp-sev.h (5796B)


      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 */
     21enum {
     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_SET_EXT_CONFIG,
     33	SNP_GET_EXT_CONFIG,
     34
     35	SEV_MAX,
     36};
     37
     38/**
     39 * SEV Firmware status code
     40 */
     41typedef enum {
     42	SEV_RET_SUCCESS = 0,
     43	SEV_RET_INVALID_PLATFORM_STATE,
     44	SEV_RET_INVALID_GUEST_STATE,
     45	SEV_RET_INAVLID_CONFIG,
     46	SEV_RET_INVALID_LEN,
     47	SEV_RET_ALREADY_OWNED,
     48	SEV_RET_INVALID_CERTIFICATE,
     49	SEV_RET_POLICY_FAILURE,
     50	SEV_RET_INACTIVE,
     51	SEV_RET_INVALID_ADDRESS,
     52	SEV_RET_BAD_SIGNATURE,
     53	SEV_RET_BAD_MEASUREMENT,
     54	SEV_RET_ASID_OWNED,
     55	SEV_RET_INVALID_ASID,
     56	SEV_RET_WBINVD_REQUIRED,
     57	SEV_RET_DFFLUSH_REQUIRED,
     58	SEV_RET_INVALID_GUEST,
     59	SEV_RET_INVALID_COMMAND,
     60	SEV_RET_ACTIVE,
     61	SEV_RET_HWSEV_RET_PLATFORM,
     62	SEV_RET_HWSEV_RET_UNSAFE,
     63	SEV_RET_UNSUPPORTED,
     64	SEV_RET_INVALID_PARAM,
     65	SEV_RET_RESOURCE_LIMIT,
     66	SEV_RET_SECURE_DATA_INVALID,
     67	SEV_RET_INVALID_PAGE_SIZE,
     68	SEV_RET_INVALID_PAGE_STATE,
     69	SEV_RET_INVALID_MDATA_ENTRY,
     70	SEV_RET_INVALID_PAGE_OWNER,
     71	SEV_RET_INVALID_PAGE_AEAD_OFLOW,
     72	SEV_RET_RMP_INIT_REQUIRED,
     73
     74	SEV_RET_MAX,
     75} sev_ret_code;
     76
     77/**
     78 * struct sev_user_data_status - PLATFORM_STATUS command parameters
     79 *
     80 * @major: major API version
     81 * @minor: minor API version
     82 * @state: platform state
     83 * @flags: platform config flags
     84 * @build: firmware build id for API version
     85 * @guest_count: number of active guests
     86 */
     87struct sev_user_data_status {
     88	__u8 api_major;				/* Out */
     89	__u8 api_minor;				/* Out */
     90	__u8 state;				/* Out */
     91	__u32 flags;				/* Out */
     92	__u8 build;				/* Out */
     93	__u32 guest_count;			/* Out */
     94} __packed;
     95
     96#define SEV_STATUS_FLAGS_CONFIG_ES	0x0100
     97
     98/**
     99 * struct sev_user_data_pek_csr - PEK_CSR command parameters
    100 *
    101 * @address: PEK certificate chain
    102 * @length: length of certificate
    103 */
    104struct sev_user_data_pek_csr {
    105	__u64 address;				/* In */
    106	__u32 length;				/* In/Out */
    107} __packed;
    108
    109/**
    110 * struct sev_user_data_cert_import - PEK_CERT_IMPORT command parameters
    111 *
    112 * @pek_address: PEK certificate chain
    113 * @pek_len: length of PEK certificate
    114 * @oca_address: OCA certificate chain
    115 * @oca_len: length of OCA certificate
    116 */
    117struct sev_user_data_pek_cert_import {
    118	__u64 pek_cert_address;			/* In */
    119	__u32 pek_cert_len;			/* In */
    120	__u64 oca_cert_address;			/* In */
    121	__u32 oca_cert_len;			/* In */
    122} __packed;
    123
    124/**
    125 * struct sev_user_data_pdh_cert_export - PDH_CERT_EXPORT command parameters
    126 *
    127 * @pdh_address: PDH certificate address
    128 * @pdh_len: length of PDH certificate
    129 * @cert_chain_address: PDH certificate chain
    130 * @cert_chain_len: length of PDH certificate chain
    131 */
    132struct sev_user_data_pdh_cert_export {
    133	__u64 pdh_cert_address;			/* In */
    134	__u32 pdh_cert_len;			/* In/Out */
    135	__u64 cert_chain_address;		/* In */
    136	__u32 cert_chain_len;			/* In/Out */
    137} __packed;
    138
    139/**
    140 * struct sev_user_data_get_id - GET_ID command parameters (deprecated)
    141 *
    142 * @socket1: Buffer to pass unique ID of first socket
    143 * @socket2: Buffer to pass unique ID of second socket
    144 */
    145struct sev_user_data_get_id {
    146	__u8 socket1[64];			/* Out */
    147	__u8 socket2[64];			/* Out */
    148} __packed;
    149
    150/**
    151 * struct sev_user_data_get_id2 - GET_ID command parameters
    152 * @address: Buffer to store unique ID
    153 * @length: length of the unique ID
    154 */
    155struct sev_user_data_get_id2 {
    156	__u64 address;				/* In */
    157	__u32 length;				/* In/Out */
    158} __packed;
    159
    160/**
    161 * struct sev_user_data_snp_status - SNP status
    162 *
    163 * @major: API major version
    164 * @minor: API minor version
    165 * @state: current platform state
    166 * @build: firmware build id for the API version
    167 * @guest_count: the number of guest currently managed by the firmware
    168 * @tcb_version: current TCB version
    169 */
    170struct sev_user_data_snp_status {
    171	__u8 api_major;		/* Out */
    172	__u8 api_minor;		/* Out */
    173	__u8 state;		/* Out */
    174	__u8 rsvd;
    175	__u32 build_id;		/* Out */
    176	__u32 rsvd1;
    177	__u32 guest_count;	/* Out */
    178	__u64 tcb_version;	/* Out */
    179	__u64 rsvd2;
    180} __packed;
    181
    182/*
    183 * struct sev_user_data_snp_config - system wide configuration value for SNP.
    184 *
    185 * @reported_tcb: The TCB version to report in the guest attestation report.
    186 * @mask_chip_id: Indicates that the CHID_ID field in the attestation report
    187 * will always be zero.
    188 */
    189struct sev_user_data_snp_config {
    190	__u64 reported_tcb;     /* In */
    191	__u32 mask_chip_id;     /* In */
    192	__u8 rsvd[52];
    193} __packed;
    194
    195/**
    196 * struct sev_data_snp_ext_config - system wide configuration value for SNP.
    197 *
    198 * @config_address: address of the struct sev_user_data_snp_config or 0 when
    199 *		reported_tcb does not need to be updated.
    200 * @certs_address: address of extended guest request certificate chain or
    201 *              0 when previous certificate should be removed on SNP_SET_EXT_CONFIG.
    202 * @certs_len: length of the certs
    203 */
    204struct sev_user_data_ext_snp_config {
    205	__u64 config_address;		/* In */
    206	__u64 certs_address;		/* In */
    207	__u32 certs_len;		/* In */
    208};
    209
    210/**
    211 * struct sev_issue_cmd - SEV ioctl parameters
    212 *
    213 * @cmd: SEV commands to execute
    214 * @opaque: pointer to the command structure
    215 * @error: SEV FW return code on failure
    216 */
    217struct sev_issue_cmd {
    218	__u32 cmd;				/* In */
    219	__u64 data;				/* In */
    220	__u32 error;				/* Out */
    221} __packed;
    222
    223#define SEV_IOC_TYPE		'S'
    224#define SEV_ISSUE_CMD	_IOWR(SEV_IOC_TYPE, 0x0, struct sev_issue_cmd)
    225
    226#endif /* __PSP_USER_SEV_H */