xref: /qemu/linux-headers/linux/psp-sev.h (revision 6078a0b6)
1 /*
2  * Userspace interface for AMD Secure Encrypted Virtualization (SEV)
3  * platform management commands.
4  *
5  * Copyright (C) 2016-2017 Advanced Micro Devices, Inc.
6  *
7  * Author: Brijesh Singh <brijesh.singh@amd.com>
8  *
9  * SEV API specification is available at: https://developer.amd.com/sev/
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License version 2 as
13  * published by the Free Software Foundation.
14  */
15 
16 #ifndef __PSP_SEV_USER_H__
17 #define __PSP_SEV_USER_H__
18 
19 #include <linux/types.h>
20 
21 /**
22  * SEV platform commands
23  */
24 enum {
25 	SEV_FACTORY_RESET = 0,
26 	SEV_PLATFORM_STATUS,
27 	SEV_PEK_GEN,
28 	SEV_PEK_CSR,
29 	SEV_PDH_GEN,
30 	SEV_PDH_CERT_EXPORT,
31 	SEV_PEK_CERT_IMPORT,
32 	SEV_GET_ID,	/* This command is deprecated, use SEV_GET_ID2 */
33 	SEV_GET_ID2,
34 
35 	SEV_MAX,
36 };
37 
38 /**
39  * SEV Firmware status code
40  */
41 typedef 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_MAX,
65 } sev_ret_code;
66 
67 /**
68  * struct sev_user_data_status - PLATFORM_STATUS command parameters
69  *
70  * @major: major API version
71  * @minor: minor API version
72  * @state: platform state
73  * @flags: platform config flags
74  * @build: firmware build id for API version
75  * @guest_count: number of active guests
76  */
77 struct sev_user_data_status {
78 	__u8 api_major;				/* Out */
79 	__u8 api_minor;				/* Out */
80 	__u8 state;				/* Out */
81 	__u32 flags;				/* Out */
82 	__u8 build;				/* Out */
83 	__u32 guest_count;			/* Out */
84 } __attribute__((packed));
85 
86 /**
87  * struct sev_user_data_pek_csr - PEK_CSR command parameters
88  *
89  * @address: PEK certificate chain
90  * @length: length of certificate
91  */
92 struct sev_user_data_pek_csr {
93 	__u64 address;				/* In */
94 	__u32 length;				/* In/Out */
95 } __attribute__((packed));
96 
97 /**
98  * struct sev_user_data_cert_import - PEK_CERT_IMPORT command parameters
99  *
100  * @pek_address: PEK certificate chain
101  * @pek_len: length of PEK certificate
102  * @oca_address: OCA certificate chain
103  * @oca_len: length of OCA certificate
104  */
105 struct sev_user_data_pek_cert_import {
106 	__u64 pek_cert_address;			/* In */
107 	__u32 pek_cert_len;			/* In */
108 	__u64 oca_cert_address;			/* In */
109 	__u32 oca_cert_len;			/* In */
110 } __attribute__((packed));
111 
112 /**
113  * struct sev_user_data_pdh_cert_export - PDH_CERT_EXPORT command parameters
114  *
115  * @pdh_address: PDH certificate address
116  * @pdh_len: length of PDH certificate
117  * @cert_chain_address: PDH certificate chain
118  * @cert_chain_len: length of PDH certificate chain
119  */
120 struct sev_user_data_pdh_cert_export {
121 	__u64 pdh_cert_address;			/* In */
122 	__u32 pdh_cert_len;			/* In/Out */
123 	__u64 cert_chain_address;		/* In */
124 	__u32 cert_chain_len;			/* In/Out */
125 } __attribute__((packed));
126 
127 /**
128  * struct sev_user_data_get_id - GET_ID command parameters (deprecated)
129  *
130  * @socket1: Buffer to pass unique ID of first socket
131  * @socket2: Buffer to pass unique ID of second socket
132  */
133 struct sev_user_data_get_id {
134 	__u8 socket1[64];			/* Out */
135 	__u8 socket2[64];			/* Out */
136 } __attribute__((packed));
137 
138 /**
139  * struct sev_user_data_get_id2 - GET_ID command parameters
140  * @address: Buffer to store unique ID
141  * @length: length of the unique ID
142  */
143 struct sev_user_data_get_id2 {
144 	__u64 address;				/* In */
145 	__u32 length;				/* In/Out */
146 } __attribute__((packed));
147 
148 /**
149  * struct sev_issue_cmd - SEV ioctl parameters
150  *
151  * @cmd: SEV commands to execute
152  * @opaque: pointer to the command structure
153  * @error: SEV FW return code on failure
154  */
155 struct sev_issue_cmd {
156 	__u32 cmd;				/* In */
157 	__u64 data;				/* In */
158 	__u32 error;				/* Out */
159 } __attribute__((packed));
160 
161 #define SEV_IOC_TYPE		'S'
162 #define SEV_ISSUE_CMD	_IOWR(SEV_IOC_TYPE, 0x0, struct sev_issue_cmd)
163 
164 #endif /* __PSP_USER_SEV_H */
165