xref: /openbmc/linux/include/linux/psp-sev.h (revision ae7d45fb)
1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2592d5e74SBrijesh Singh /*
3592d5e74SBrijesh Singh  * AMD Secure Encrypted Virtualization (SEV) driver interface
4592d5e74SBrijesh Singh  *
5592d5e74SBrijesh Singh  * Copyright (C) 2016-2017 Advanced Micro Devices, Inc.
6592d5e74SBrijesh Singh  *
7592d5e74SBrijesh Singh  * Author: Brijesh Singh <brijesh.singh@amd.com>
8592d5e74SBrijesh Singh  *
9d6112ea0SSingh, Brijesh  * SEV API spec is available at https://developer.amd.com/sev
10592d5e74SBrijesh Singh  */
11592d5e74SBrijesh Singh 
12592d5e74SBrijesh Singh #ifndef __PSP_SEV_H__
13592d5e74SBrijesh Singh #define __PSP_SEV_H__
14592d5e74SBrijesh Singh 
15592d5e74SBrijesh Singh #include <uapi/linux/psp-sev.h>
16592d5e74SBrijesh Singh 
17592d5e74SBrijesh Singh #define SEV_FW_BLOB_MAX_SIZE	0x4000	/* 16KB */
18592d5e74SBrijesh Singh 
19592d5e74SBrijesh Singh /**
20592d5e74SBrijesh Singh  * SEV platform state
21592d5e74SBrijesh Singh  */
22592d5e74SBrijesh Singh enum sev_state {
23592d5e74SBrijesh Singh 	SEV_STATE_UNINIT		= 0x0,
24592d5e74SBrijesh Singh 	SEV_STATE_INIT			= 0x1,
25592d5e74SBrijesh Singh 	SEV_STATE_WORKING		= 0x2,
26592d5e74SBrijesh Singh 
27592d5e74SBrijesh Singh 	SEV_STATE_MAX
28592d5e74SBrijesh Singh };
29592d5e74SBrijesh Singh 
30592d5e74SBrijesh Singh /**
31592d5e74SBrijesh Singh  * SEV platform and guest management commands
32592d5e74SBrijesh Singh  */
33592d5e74SBrijesh Singh enum sev_cmd {
34592d5e74SBrijesh Singh 	/* platform commands */
35592d5e74SBrijesh Singh 	SEV_CMD_INIT			= 0x001,
36592d5e74SBrijesh Singh 	SEV_CMD_SHUTDOWN		= 0x002,
37592d5e74SBrijesh Singh 	SEV_CMD_FACTORY_RESET		= 0x003,
38592d5e74SBrijesh Singh 	SEV_CMD_PLATFORM_STATUS		= 0x004,
39592d5e74SBrijesh Singh 	SEV_CMD_PEK_GEN			= 0x005,
40592d5e74SBrijesh Singh 	SEV_CMD_PEK_CSR			= 0x006,
41592d5e74SBrijesh Singh 	SEV_CMD_PEK_CERT_IMPORT		= 0x007,
42592d5e74SBrijesh Singh 	SEV_CMD_PDH_CERT_EXPORT		= 0x008,
43592d5e74SBrijesh Singh 	SEV_CMD_PDH_GEN			= 0x009,
44592d5e74SBrijesh Singh 	SEV_CMD_DF_FLUSH		= 0x00A,
45edd303ffSJanakarajan Natarajan 	SEV_CMD_DOWNLOAD_FIRMWARE	= 0x00B,
460b3a830bSJanakarajan Natarajan 	SEV_CMD_GET_ID			= 0x00C,
47*3d725965SDavid Rientjes 	SEV_CMD_INIT_EX                 = 0x00D,
48592d5e74SBrijesh Singh 
49592d5e74SBrijesh Singh 	/* Guest commands */
50592d5e74SBrijesh Singh 	SEV_CMD_DECOMMISSION		= 0x020,
51592d5e74SBrijesh Singh 	SEV_CMD_ACTIVATE		= 0x021,
52592d5e74SBrijesh Singh 	SEV_CMD_DEACTIVATE		= 0x022,
53592d5e74SBrijesh Singh 	SEV_CMD_GUEST_STATUS		= 0x023,
54592d5e74SBrijesh Singh 
55592d5e74SBrijesh Singh 	/* Guest launch commands */
56592d5e74SBrijesh Singh 	SEV_CMD_LAUNCH_START		= 0x030,
57592d5e74SBrijesh Singh 	SEV_CMD_LAUNCH_UPDATE_DATA	= 0x031,
58592d5e74SBrijesh Singh 	SEV_CMD_LAUNCH_UPDATE_VMSA	= 0x032,
59592d5e74SBrijesh Singh 	SEV_CMD_LAUNCH_MEASURE		= 0x033,
60592d5e74SBrijesh Singh 	SEV_CMD_LAUNCH_UPDATE_SECRET	= 0x034,
61592d5e74SBrijesh Singh 	SEV_CMD_LAUNCH_FINISH		= 0x035,
622c07ded0SBrijesh Singh 	SEV_CMD_ATTESTATION_REPORT	= 0x036,
63592d5e74SBrijesh Singh 
64592d5e74SBrijesh Singh 	/* Guest migration commands (outgoing) */
65592d5e74SBrijesh Singh 	SEV_CMD_SEND_START		= 0x040,
66592d5e74SBrijesh Singh 	SEV_CMD_SEND_UPDATE_DATA	= 0x041,
67592d5e74SBrijesh Singh 	SEV_CMD_SEND_UPDATE_VMSA	= 0x042,
68592d5e74SBrijesh Singh 	SEV_CMD_SEND_FINISH		= 0x043,
695569e2e7SSteve Rutherford 	SEV_CMD_SEND_CANCEL		= 0x044,
70592d5e74SBrijesh Singh 
71592d5e74SBrijesh Singh 	/* Guest migration commands (incoming) */
72592d5e74SBrijesh Singh 	SEV_CMD_RECEIVE_START		= 0x050,
73592d5e74SBrijesh Singh 	SEV_CMD_RECEIVE_UPDATE_DATA	= 0x051,
74592d5e74SBrijesh Singh 	SEV_CMD_RECEIVE_UPDATE_VMSA	= 0x052,
75592d5e74SBrijesh Singh 	SEV_CMD_RECEIVE_FINISH		= 0x053,
76592d5e74SBrijesh Singh 
77592d5e74SBrijesh Singh 	/* Guest debug commands */
78592d5e74SBrijesh Singh 	SEV_CMD_DBG_DECRYPT		= 0x060,
79592d5e74SBrijesh Singh 	SEV_CMD_DBG_ENCRYPT		= 0x061,
80592d5e74SBrijesh Singh 
81592d5e74SBrijesh Singh 	SEV_CMD_MAX,
82592d5e74SBrijesh Singh };
83592d5e74SBrijesh Singh 
84592d5e74SBrijesh Singh /**
85592d5e74SBrijesh Singh  * struct sev_data_init - INIT command parameters
86592d5e74SBrijesh Singh  *
87592d5e74SBrijesh Singh  * @flags: processing flags
88592d5e74SBrijesh Singh  * @tmr_address: system physical address used for SEV-ES
89592d5e74SBrijesh Singh  * @tmr_len: len of tmr_address
90592d5e74SBrijesh Singh  */
91592d5e74SBrijesh Singh struct sev_data_init {
92592d5e74SBrijesh Singh 	u32 flags;			/* In */
93592d5e74SBrijesh Singh 	u32 reserved;			/* In */
94592d5e74SBrijesh Singh 	u64 tmr_address;		/* In */
95592d5e74SBrijesh Singh 	u32 tmr_len;			/* In */
96592d5e74SBrijesh Singh } __packed;
97592d5e74SBrijesh Singh 
98*3d725965SDavid Rientjes /**
99*3d725965SDavid Rientjes  * struct sev_data_init_ex - INIT_EX command parameters
100*3d725965SDavid Rientjes  *
101*3d725965SDavid Rientjes  * @length: len of the command buffer read by the PSP
102*3d725965SDavid Rientjes  * @flags: processing flags
103*3d725965SDavid Rientjes  * @tmr_address: system physical address used for SEV-ES
104*3d725965SDavid Rientjes  * @tmr_len: len of tmr_address
105*3d725965SDavid Rientjes  * @nv_address: system physical address used for PSP NV storage
106*3d725965SDavid Rientjes  * @nv_len: len of nv_address
107*3d725965SDavid Rientjes  */
108*3d725965SDavid Rientjes struct sev_data_init_ex {
109*3d725965SDavid Rientjes 	u32 length;                     /* In */
110*3d725965SDavid Rientjes 	u32 flags;                      /* In */
111*3d725965SDavid Rientjes 	u64 tmr_address;                /* In */
112*3d725965SDavid Rientjes 	u32 tmr_len;                    /* In */
113*3d725965SDavid Rientjes 	u32 reserved;                   /* In */
114*3d725965SDavid Rientjes 	u64 nv_address;                 /* In/Out */
115*3d725965SDavid Rientjes 	u32 nv_len;                     /* In */
116*3d725965SDavid Rientjes } __packed;
117*3d725965SDavid Rientjes 
11897f9ac3dSTom Lendacky #define SEV_INIT_FLAGS_SEV_ES	0x01
11997f9ac3dSTom Lendacky 
120592d5e74SBrijesh Singh /**
121592d5e74SBrijesh Singh  * struct sev_data_pek_csr - PEK_CSR command parameters
122592d5e74SBrijesh Singh  *
123592d5e74SBrijesh Singh  * @address: PEK certificate chain
124592d5e74SBrijesh Singh  * @len: len of certificate
125592d5e74SBrijesh Singh  */
126592d5e74SBrijesh Singh struct sev_data_pek_csr {
127592d5e74SBrijesh Singh 	u64 address;				/* In */
128592d5e74SBrijesh Singh 	u32 len;				/* In/Out */
129592d5e74SBrijesh Singh } __packed;
130592d5e74SBrijesh Singh 
131592d5e74SBrijesh Singh /**
132592d5e74SBrijesh Singh  * struct sev_data_cert_import - PEK_CERT_IMPORT command parameters
133592d5e74SBrijesh Singh  *
134592d5e74SBrijesh Singh  * @pek_address: PEK certificate chain
135592d5e74SBrijesh Singh  * @pek_len: len of PEK certificate
136592d5e74SBrijesh Singh  * @oca_address: OCA certificate chain
137592d5e74SBrijesh Singh  * @oca_len: len of OCA certificate
138592d5e74SBrijesh Singh  */
139592d5e74SBrijesh Singh struct sev_data_pek_cert_import {
140592d5e74SBrijesh Singh 	u64 pek_cert_address;			/* In */
141592d5e74SBrijesh Singh 	u32 pek_cert_len;			/* In */
142592d5e74SBrijesh Singh 	u32 reserved;				/* In */
143592d5e74SBrijesh Singh 	u64 oca_cert_address;			/* In */
144592d5e74SBrijesh Singh 	u32 oca_cert_len;			/* In */
145592d5e74SBrijesh Singh } __packed;
146592d5e74SBrijesh Singh 
147592d5e74SBrijesh Singh /**
148edd303ffSJanakarajan Natarajan  * struct sev_data_download_firmware - DOWNLOAD_FIRMWARE command parameters
149edd303ffSJanakarajan Natarajan  *
150edd303ffSJanakarajan Natarajan  * @address: physical address of firmware image
151edd303ffSJanakarajan Natarajan  * @len: len of the firmware image
152edd303ffSJanakarajan Natarajan  */
153edd303ffSJanakarajan Natarajan struct sev_data_download_firmware {
154edd303ffSJanakarajan Natarajan 	u64 address;				/* In */
155edd303ffSJanakarajan Natarajan 	u32 len;				/* In */
156edd303ffSJanakarajan Natarajan } __packed;
157edd303ffSJanakarajan Natarajan 
158edd303ffSJanakarajan Natarajan /**
1590b3a830bSJanakarajan Natarajan  * struct sev_data_get_id - GET_ID command parameters
1600b3a830bSJanakarajan Natarajan  *
1610b3a830bSJanakarajan Natarajan  * @address: physical address of region to place unique CPU ID(s)
1620b3a830bSJanakarajan Natarajan  * @len: len of the region
1630b3a830bSJanakarajan Natarajan  */
1640b3a830bSJanakarajan Natarajan struct sev_data_get_id {
1650b3a830bSJanakarajan Natarajan 	u64 address;				/* In */
1660b3a830bSJanakarajan Natarajan 	u32 len;				/* In/Out */
1670b3a830bSJanakarajan Natarajan } __packed;
1680b3a830bSJanakarajan Natarajan /**
169592d5e74SBrijesh Singh  * struct sev_data_pdh_cert_export - PDH_CERT_EXPORT command parameters
170592d5e74SBrijesh Singh  *
171592d5e74SBrijesh Singh  * @pdh_address: PDH certificate address
172592d5e74SBrijesh Singh  * @pdh_len: len of PDH certificate
173592d5e74SBrijesh Singh  * @cert_chain_address: PDH certificate chain
174592d5e74SBrijesh Singh  * @cert_chain_len: len of PDH certificate chain
175592d5e74SBrijesh Singh  */
176592d5e74SBrijesh Singh struct sev_data_pdh_cert_export {
177592d5e74SBrijesh Singh 	u64 pdh_cert_address;			/* In */
178592d5e74SBrijesh Singh 	u32 pdh_cert_len;			/* In/Out */
179592d5e74SBrijesh Singh 	u32 reserved;				/* In */
180592d5e74SBrijesh Singh 	u64 cert_chain_address;			/* In */
181592d5e74SBrijesh Singh 	u32 cert_chain_len;			/* In/Out */
182592d5e74SBrijesh Singh } __packed;
183592d5e74SBrijesh Singh 
184592d5e74SBrijesh Singh /**
185592d5e74SBrijesh Singh  * struct sev_data_decommission - DECOMMISSION command parameters
186592d5e74SBrijesh Singh  *
187592d5e74SBrijesh Singh  * @handle: handle of the VM to decommission
188592d5e74SBrijesh Singh  */
189592d5e74SBrijesh Singh struct sev_data_decommission {
190592d5e74SBrijesh Singh 	u32 handle;				/* In */
191592d5e74SBrijesh Singh } __packed;
192592d5e74SBrijesh Singh 
193592d5e74SBrijesh Singh /**
194592d5e74SBrijesh Singh  * struct sev_data_activate - ACTIVATE command parameters
195592d5e74SBrijesh Singh  *
196592d5e74SBrijesh Singh  * @handle: handle of the VM to activate
197592d5e74SBrijesh Singh  * @asid: asid assigned to the VM
198592d5e74SBrijesh Singh  */
199592d5e74SBrijesh Singh struct sev_data_activate {
200592d5e74SBrijesh Singh 	u32 handle;				/* In */
201592d5e74SBrijesh Singh 	u32 asid;				/* In */
202592d5e74SBrijesh Singh } __packed;
203592d5e74SBrijesh Singh 
204592d5e74SBrijesh Singh /**
205592d5e74SBrijesh Singh  * struct sev_data_deactivate - DEACTIVATE command parameters
206592d5e74SBrijesh Singh  *
207592d5e74SBrijesh Singh  * @handle: handle of the VM to deactivate
208592d5e74SBrijesh Singh  */
209592d5e74SBrijesh Singh struct sev_data_deactivate {
210592d5e74SBrijesh Singh 	u32 handle;				/* In */
211592d5e74SBrijesh Singh } __packed;
212592d5e74SBrijesh Singh 
213592d5e74SBrijesh Singh /**
214592d5e74SBrijesh Singh  * struct sev_data_guest_status - SEV GUEST_STATUS command parameters
215592d5e74SBrijesh Singh  *
216592d5e74SBrijesh Singh  * @handle: handle of the VM to retrieve status
217592d5e74SBrijesh Singh  * @policy: policy information for the VM
218592d5e74SBrijesh Singh  * @asid: current ASID of the VM
219592d5e74SBrijesh Singh  * @state: current state of the VM
220592d5e74SBrijesh Singh  */
221592d5e74SBrijesh Singh struct sev_data_guest_status {
222592d5e74SBrijesh Singh 	u32 handle;				/* In */
223592d5e74SBrijesh Singh 	u32 policy;				/* Out */
224592d5e74SBrijesh Singh 	u32 asid;				/* Out */
225592d5e74SBrijesh Singh 	u8 state;				/* Out */
226592d5e74SBrijesh Singh } __packed;
227592d5e74SBrijesh Singh 
228592d5e74SBrijesh Singh /**
229592d5e74SBrijesh Singh  * struct sev_data_launch_start - LAUNCH_START command parameters
230592d5e74SBrijesh Singh  *
231592d5e74SBrijesh Singh  * @handle: handle assigned to the VM
232592d5e74SBrijesh Singh  * @policy: guest launch policy
233592d5e74SBrijesh Singh  * @dh_cert_address: physical address of DH certificate blob
234592d5e74SBrijesh Singh  * @dh_cert_len: len of DH certificate blob
235592d5e74SBrijesh Singh  * @session_address: physical address of session parameters
236592d5e74SBrijesh Singh  * @session_len: len of session parameters
237592d5e74SBrijesh Singh  */
238592d5e74SBrijesh Singh struct sev_data_launch_start {
239592d5e74SBrijesh Singh 	u32 handle;				/* In/Out */
240592d5e74SBrijesh Singh 	u32 policy;				/* In */
241592d5e74SBrijesh Singh 	u64 dh_cert_address;			/* In */
242592d5e74SBrijesh Singh 	u32 dh_cert_len;			/* In */
243592d5e74SBrijesh Singh 	u32 reserved;				/* In */
244592d5e74SBrijesh Singh 	u64 session_address;			/* In */
245592d5e74SBrijesh Singh 	u32 session_len;			/* In */
246592d5e74SBrijesh Singh } __packed;
247592d5e74SBrijesh Singh 
248592d5e74SBrijesh Singh /**
249592d5e74SBrijesh Singh  * struct sev_data_launch_update_data - LAUNCH_UPDATE_DATA command parameter
250592d5e74SBrijesh Singh  *
251592d5e74SBrijesh Singh  * @handle: handle of the VM to update
252592d5e74SBrijesh Singh  * @len: len of memory to be encrypted
253592d5e74SBrijesh Singh  * @address: physical address of memory region to encrypt
254592d5e74SBrijesh Singh  */
255592d5e74SBrijesh Singh struct sev_data_launch_update_data {
256592d5e74SBrijesh Singh 	u32 handle;				/* In */
257592d5e74SBrijesh Singh 	u32 reserved;
258592d5e74SBrijesh Singh 	u64 address;				/* In */
259592d5e74SBrijesh Singh 	u32 len;				/* In */
260592d5e74SBrijesh Singh } __packed;
261592d5e74SBrijesh Singh 
262592d5e74SBrijesh Singh /**
263592d5e74SBrijesh Singh  * struct sev_data_launch_update_vmsa - LAUNCH_UPDATE_VMSA command
264592d5e74SBrijesh Singh  *
265592d5e74SBrijesh Singh  * @handle: handle of the VM
266592d5e74SBrijesh Singh  * @address: physical address of memory region to encrypt
267592d5e74SBrijesh Singh  * @len: len of memory region to encrypt
268592d5e74SBrijesh Singh  */
269592d5e74SBrijesh Singh struct sev_data_launch_update_vmsa {
270592d5e74SBrijesh Singh 	u32 handle;				/* In */
271592d5e74SBrijesh Singh 	u32 reserved;
272592d5e74SBrijesh Singh 	u64 address;				/* In */
273592d5e74SBrijesh Singh 	u32 len;				/* In */
274592d5e74SBrijesh Singh } __packed;
275592d5e74SBrijesh Singh 
276592d5e74SBrijesh Singh /**
277592d5e74SBrijesh Singh  * struct sev_data_launch_measure - LAUNCH_MEASURE command parameters
278592d5e74SBrijesh Singh  *
279592d5e74SBrijesh Singh  * @handle: handle of the VM to process
280592d5e74SBrijesh Singh  * @address: physical address containing the measurement blob
281592d5e74SBrijesh Singh  * @len: len of measurement blob
282592d5e74SBrijesh Singh  */
283592d5e74SBrijesh Singh struct sev_data_launch_measure {
284592d5e74SBrijesh Singh 	u32 handle;				/* In */
285592d5e74SBrijesh Singh 	u32 reserved;
286592d5e74SBrijesh Singh 	u64 address;				/* In */
287592d5e74SBrijesh Singh 	u32 len;				/* In/Out */
288592d5e74SBrijesh Singh } __packed;
289592d5e74SBrijesh Singh 
290592d5e74SBrijesh Singh /**
291592d5e74SBrijesh Singh  * struct sev_data_launch_secret - LAUNCH_SECRET command parameters
292592d5e74SBrijesh Singh  *
293592d5e74SBrijesh Singh  * @handle: handle of the VM to process
294592d5e74SBrijesh Singh  * @hdr_address: physical address containing the packet header
295592d5e74SBrijesh Singh  * @hdr_len: len of packet header
296592d5e74SBrijesh Singh  * @guest_address: system physical address of guest memory region
297592d5e74SBrijesh Singh  * @guest_len: len of guest_paddr
298592d5e74SBrijesh Singh  * @trans_address: physical address of transport memory buffer
299592d5e74SBrijesh Singh  * @trans_len: len of transport memory buffer
300592d5e74SBrijesh Singh  */
301592d5e74SBrijesh Singh struct sev_data_launch_secret {
302592d5e74SBrijesh Singh 	u32 handle;				/* In */
303592d5e74SBrijesh Singh 	u32 reserved1;
304592d5e74SBrijesh Singh 	u64 hdr_address;			/* In */
305592d5e74SBrijesh Singh 	u32 hdr_len;				/* In */
306592d5e74SBrijesh Singh 	u32 reserved2;
307592d5e74SBrijesh Singh 	u64 guest_address;			/* In */
308592d5e74SBrijesh Singh 	u32 guest_len;				/* In */
309592d5e74SBrijesh Singh 	u32 reserved3;
310592d5e74SBrijesh Singh 	u64 trans_address;			/* In */
311592d5e74SBrijesh Singh 	u32 trans_len;				/* In */
312592d5e74SBrijesh Singh } __packed;
313592d5e74SBrijesh Singh 
314592d5e74SBrijesh Singh /**
315592d5e74SBrijesh Singh  * struct sev_data_launch_finish - LAUNCH_FINISH command parameters
316592d5e74SBrijesh Singh  *
317592d5e74SBrijesh Singh  * @handle: handle of the VM to process
318592d5e74SBrijesh Singh  */
319592d5e74SBrijesh Singh struct sev_data_launch_finish {
320592d5e74SBrijesh Singh 	u32 handle;				/* In */
321592d5e74SBrijesh Singh } __packed;
322592d5e74SBrijesh Singh 
323592d5e74SBrijesh Singh /**
324592d5e74SBrijesh Singh  * struct sev_data_send_start - SEND_START command parameters
325592d5e74SBrijesh Singh  *
326592d5e74SBrijesh Singh  * @handle: handle of the VM to process
327592d5e74SBrijesh Singh  * @policy: policy information for the VM
328592d5e74SBrijesh Singh  * @pdh_cert_address: physical address containing PDH certificate
329592d5e74SBrijesh Singh  * @pdh_cert_len: len of PDH certificate
330592d5e74SBrijesh Singh  * @plat_certs_address: physical address containing platform certificate
331592d5e74SBrijesh Singh  * @plat_certs_len: len of platform certificate
332592d5e74SBrijesh Singh  * @amd_certs_address: physical address containing AMD certificate
333592d5e74SBrijesh Singh  * @amd_certs_len: len of AMD certificate
334592d5e74SBrijesh Singh  * @session_address: physical address containing Session data
335592d5e74SBrijesh Singh  * @session_len: len of session data
336592d5e74SBrijesh Singh  */
337592d5e74SBrijesh Singh struct sev_data_send_start {
338592d5e74SBrijesh Singh 	u32 handle;				/* In */
339592d5e74SBrijesh Singh 	u32 policy;				/* Out */
340592d5e74SBrijesh Singh 	u64 pdh_cert_address;			/* In */
341592d5e74SBrijesh Singh 	u32 pdh_cert_len;			/* In */
342592d5e74SBrijesh Singh 	u32 reserved1;
3434cfdd47dSBrijesh Singh 	u64 plat_certs_address;			/* In */
3444cfdd47dSBrijesh Singh 	u32 plat_certs_len;			/* In */
345592d5e74SBrijesh Singh 	u32 reserved2;
3464cfdd47dSBrijesh Singh 	u64 amd_certs_address;			/* In */
3474cfdd47dSBrijesh Singh 	u32 amd_certs_len;			/* In */
348592d5e74SBrijesh Singh 	u32 reserved3;
349592d5e74SBrijesh Singh 	u64 session_address;			/* In */
350592d5e74SBrijesh Singh 	u32 session_len;			/* In/Out */
351592d5e74SBrijesh Singh } __packed;
352592d5e74SBrijesh Singh 
353592d5e74SBrijesh Singh /**
354592d5e74SBrijesh Singh  * struct sev_data_send_update - SEND_UPDATE_DATA command
355592d5e74SBrijesh Singh  *
356592d5e74SBrijesh Singh  * @handle: handle of the VM to process
357592d5e74SBrijesh Singh  * @hdr_address: physical address containing packet header
358592d5e74SBrijesh Singh  * @hdr_len: len of packet header
359592d5e74SBrijesh Singh  * @guest_address: physical address of guest memory region to send
360592d5e74SBrijesh Singh  * @guest_len: len of guest memory region to send
361592d5e74SBrijesh Singh  * @trans_address: physical address of host memory region
362592d5e74SBrijesh Singh  * @trans_len: len of host memory region
363592d5e74SBrijesh Singh  */
364592d5e74SBrijesh Singh struct sev_data_send_update_data {
365592d5e74SBrijesh Singh 	u32 handle;				/* In */
366592d5e74SBrijesh Singh 	u32 reserved1;
367592d5e74SBrijesh Singh 	u64 hdr_address;			/* In */
368592d5e74SBrijesh Singh 	u32 hdr_len;				/* In/Out */
369592d5e74SBrijesh Singh 	u32 reserved2;
370592d5e74SBrijesh Singh 	u64 guest_address;			/* In */
371592d5e74SBrijesh Singh 	u32 guest_len;				/* In */
372592d5e74SBrijesh Singh 	u32 reserved3;
373592d5e74SBrijesh Singh 	u64 trans_address;			/* In */
374592d5e74SBrijesh Singh 	u32 trans_len;				/* In */
375592d5e74SBrijesh Singh } __packed;
376592d5e74SBrijesh Singh 
377592d5e74SBrijesh Singh /**
378592d5e74SBrijesh Singh  * struct sev_data_send_update - SEND_UPDATE_VMSA command
379592d5e74SBrijesh Singh  *
380592d5e74SBrijesh Singh  * @handle: handle of the VM to process
381592d5e74SBrijesh Singh  * @hdr_address: physical address containing packet header
382592d5e74SBrijesh Singh  * @hdr_len: len of packet header
383592d5e74SBrijesh Singh  * @guest_address: physical address of guest memory region to send
384592d5e74SBrijesh Singh  * @guest_len: len of guest memory region to send
385592d5e74SBrijesh Singh  * @trans_address: physical address of host memory region
386592d5e74SBrijesh Singh  * @trans_len: len of host memory region
387592d5e74SBrijesh Singh  */
388592d5e74SBrijesh Singh struct sev_data_send_update_vmsa {
389592d5e74SBrijesh Singh 	u32 handle;				/* In */
390592d5e74SBrijesh Singh 	u64 hdr_address;			/* In */
391592d5e74SBrijesh Singh 	u32 hdr_len;				/* In/Out */
392592d5e74SBrijesh Singh 	u32 reserved2;
393592d5e74SBrijesh Singh 	u64 guest_address;			/* In */
394592d5e74SBrijesh Singh 	u32 guest_len;				/* In */
395592d5e74SBrijesh Singh 	u32 reserved3;
396592d5e74SBrijesh Singh 	u64 trans_address;			/* In */
397592d5e74SBrijesh Singh 	u32 trans_len;				/* In */
398592d5e74SBrijesh Singh } __packed;
399592d5e74SBrijesh Singh 
400592d5e74SBrijesh Singh /**
401592d5e74SBrijesh Singh  * struct sev_data_send_finish - SEND_FINISH command parameters
402592d5e74SBrijesh Singh  *
403592d5e74SBrijesh Singh  * @handle: handle of the VM to process
404592d5e74SBrijesh Singh  */
405592d5e74SBrijesh Singh struct sev_data_send_finish {
406592d5e74SBrijesh Singh 	u32 handle;				/* In */
407592d5e74SBrijesh Singh } __packed;
408592d5e74SBrijesh Singh 
409592d5e74SBrijesh Singh /**
4105569e2e7SSteve Rutherford  * struct sev_data_send_cancel - SEND_CANCEL command parameters
4115569e2e7SSteve Rutherford  *
4125569e2e7SSteve Rutherford  * @handle: handle of the VM to process
4135569e2e7SSteve Rutherford  */
4145569e2e7SSteve Rutherford struct sev_data_send_cancel {
4155569e2e7SSteve Rutherford 	u32 handle;				/* In */
4165569e2e7SSteve Rutherford } __packed;
4175569e2e7SSteve Rutherford 
4185569e2e7SSteve Rutherford /**
419592d5e74SBrijesh Singh  * struct sev_data_receive_start - RECEIVE_START command parameters
420592d5e74SBrijesh Singh  *
421592d5e74SBrijesh Singh  * @handle: handle of the VM to perform receive operation
422592d5e74SBrijesh Singh  * @pdh_cert_address: system physical address containing PDH certificate blob
423592d5e74SBrijesh Singh  * @pdh_cert_len: len of PDH certificate blob
424592d5e74SBrijesh Singh  * @session_address: system physical address containing session blob
425592d5e74SBrijesh Singh  * @session_len: len of session blob
426592d5e74SBrijesh Singh  */
427592d5e74SBrijesh Singh struct sev_data_receive_start {
428592d5e74SBrijesh Singh 	u32 handle;				/* In/Out */
429592d5e74SBrijesh Singh 	u32 policy;				/* In */
430592d5e74SBrijesh Singh 	u64 pdh_cert_address;			/* In */
431592d5e74SBrijesh Singh 	u32 pdh_cert_len;			/* In */
432592d5e74SBrijesh Singh 	u32 reserved1;
433592d5e74SBrijesh Singh 	u64 session_address;			/* In */
434592d5e74SBrijesh Singh 	u32 session_len;			/* In */
435592d5e74SBrijesh Singh } __packed;
436592d5e74SBrijesh Singh 
437592d5e74SBrijesh Singh /**
438592d5e74SBrijesh Singh  * struct sev_data_receive_update_data - RECEIVE_UPDATE_DATA command parameters
439592d5e74SBrijesh Singh  *
440592d5e74SBrijesh Singh  * @handle: handle of the VM to update
441592d5e74SBrijesh Singh  * @hdr_address: physical address containing packet header blob
442592d5e74SBrijesh Singh  * @hdr_len: len of packet header
443592d5e74SBrijesh Singh  * @guest_address: system physical address of guest memory region
444592d5e74SBrijesh Singh  * @guest_len: len of guest memory region
445592d5e74SBrijesh Singh  * @trans_address: system physical address of transport buffer
446592d5e74SBrijesh Singh  * @trans_len: len of transport buffer
447592d5e74SBrijesh Singh  */
448592d5e74SBrijesh Singh struct sev_data_receive_update_data {
449592d5e74SBrijesh Singh 	u32 handle;				/* In */
450592d5e74SBrijesh Singh 	u32 reserved1;
451592d5e74SBrijesh Singh 	u64 hdr_address;			/* In */
452592d5e74SBrijesh Singh 	u32 hdr_len;				/* In */
453592d5e74SBrijesh Singh 	u32 reserved2;
454592d5e74SBrijesh Singh 	u64 guest_address;			/* In */
455592d5e74SBrijesh Singh 	u32 guest_len;				/* In */
456592d5e74SBrijesh Singh 	u32 reserved3;
457592d5e74SBrijesh Singh 	u64 trans_address;			/* In */
458592d5e74SBrijesh Singh 	u32 trans_len;				/* In */
459592d5e74SBrijesh Singh } __packed;
460592d5e74SBrijesh Singh 
461592d5e74SBrijesh Singh /**
462592d5e74SBrijesh Singh  * struct sev_data_receive_update_vmsa - RECEIVE_UPDATE_VMSA command parameters
463592d5e74SBrijesh Singh  *
464592d5e74SBrijesh Singh  * @handle: handle of the VM to update
465592d5e74SBrijesh Singh  * @hdr_address: physical address containing packet header blob
466592d5e74SBrijesh Singh  * @hdr_len: len of packet header
467592d5e74SBrijesh Singh  * @guest_address: system physical address of guest memory region
468592d5e74SBrijesh Singh  * @guest_len: len of guest memory region
469592d5e74SBrijesh Singh  * @trans_address: system physical address of transport buffer
470592d5e74SBrijesh Singh  * @trans_len: len of transport buffer
471592d5e74SBrijesh Singh  */
472592d5e74SBrijesh Singh struct sev_data_receive_update_vmsa {
473592d5e74SBrijesh Singh 	u32 handle;				/* In */
474592d5e74SBrijesh Singh 	u32 reserved1;
475592d5e74SBrijesh Singh 	u64 hdr_address;			/* In */
476592d5e74SBrijesh Singh 	u32 hdr_len;				/* In */
477592d5e74SBrijesh Singh 	u32 reserved2;
478592d5e74SBrijesh Singh 	u64 guest_address;			/* In */
479592d5e74SBrijesh Singh 	u32 guest_len;				/* In */
480592d5e74SBrijesh Singh 	u32 reserved3;
481592d5e74SBrijesh Singh 	u64 trans_address;			/* In */
482592d5e74SBrijesh Singh 	u32 trans_len;				/* In */
483592d5e74SBrijesh Singh } __packed;
484592d5e74SBrijesh Singh 
485592d5e74SBrijesh Singh /**
486592d5e74SBrijesh Singh  * struct sev_data_receive_finish - RECEIVE_FINISH command parameters
487592d5e74SBrijesh Singh  *
488592d5e74SBrijesh Singh  * @handle: handle of the VM to finish
489592d5e74SBrijesh Singh  */
490592d5e74SBrijesh Singh struct sev_data_receive_finish {
491592d5e74SBrijesh Singh 	u32 handle;				/* In */
492592d5e74SBrijesh Singh } __packed;
493592d5e74SBrijesh Singh 
494592d5e74SBrijesh Singh /**
495592d5e74SBrijesh Singh  * struct sev_data_dbg - DBG_ENCRYPT/DBG_DECRYPT command parameters
496592d5e74SBrijesh Singh  *
497592d5e74SBrijesh Singh  * @handle: handle of the VM to perform debug operation
498592d5e74SBrijesh Singh  * @src_addr: source address of data to operate on
499592d5e74SBrijesh Singh  * @dst_addr: destination address of data to operate on
500592d5e74SBrijesh Singh  * @len: len of data to operate on
501592d5e74SBrijesh Singh  */
502592d5e74SBrijesh Singh struct sev_data_dbg {
503592d5e74SBrijesh Singh 	u32 handle;				/* In */
504592d5e74SBrijesh Singh 	u32 reserved;
505592d5e74SBrijesh Singh 	u64 src_addr;				/* In */
506592d5e74SBrijesh Singh 	u64 dst_addr;				/* In */
507592d5e74SBrijesh Singh 	u32 len;				/* In */
508592d5e74SBrijesh Singh } __packed;
509592d5e74SBrijesh Singh 
5102c07ded0SBrijesh Singh /**
5112c07ded0SBrijesh Singh  * struct sev_data_attestation_report - SEV_ATTESTATION_REPORT command parameters
5122c07ded0SBrijesh Singh  *
5132c07ded0SBrijesh Singh  * @handle: handle of the VM
5142c07ded0SBrijesh Singh  * @mnonce: a random nonce that will be included in the report.
5152c07ded0SBrijesh Singh  * @address: physical address where the report will be copied.
5162c07ded0SBrijesh Singh  * @len: length of the physical buffer.
5172c07ded0SBrijesh Singh  */
5182c07ded0SBrijesh Singh struct sev_data_attestation_report {
5192c07ded0SBrijesh Singh 	u32 handle;				/* In */
5202c07ded0SBrijesh Singh 	u32 reserved;
5212c07ded0SBrijesh Singh 	u64 address;				/* In */
5222c07ded0SBrijesh Singh 	u8 mnonce[16];				/* In */
5232c07ded0SBrijesh Singh 	u32 len;				/* In/Out */
5242c07ded0SBrijesh Singh } __packed;
5252c07ded0SBrijesh Singh 
526200664d5SBrijesh Singh #ifdef CONFIG_CRYPTO_DEV_SP_PSP
527200664d5SBrijesh Singh 
528200664d5SBrijesh Singh /**
529200664d5SBrijesh Singh  * sev_platform_init - perform SEV INIT command
530200664d5SBrijesh Singh  *
531200664d5SBrijesh Singh  * @error: SEV command return code
532200664d5SBrijesh Singh  *
533200664d5SBrijesh Singh  * Returns:
534200664d5SBrijesh Singh  * 0 if the SEV successfully processed the command
535200664d5SBrijesh Singh  * -%ENODEV    if the SEV device is not available
536200664d5SBrijesh Singh  * -%ENOTSUPP  if the SEV does not support SEV
537200664d5SBrijesh Singh  * -%ETIMEDOUT if the SEV command timed out
538200664d5SBrijesh Singh  * -%EIO       if the SEV returned a non-zero return code
539200664d5SBrijesh Singh  */
540200664d5SBrijesh Singh int sev_platform_init(int *error);
541200664d5SBrijesh Singh 
542200664d5SBrijesh Singh /**
543200664d5SBrijesh Singh  * sev_platform_status - perform SEV PLATFORM_STATUS command
544200664d5SBrijesh Singh  *
545200664d5SBrijesh Singh  * @status: sev_user_data_status structure to be processed
546200664d5SBrijesh Singh  * @error: SEV command return code
547200664d5SBrijesh Singh  *
548200664d5SBrijesh Singh  * Returns:
549200664d5SBrijesh Singh  * 0 if the SEV successfully processed the command
550200664d5SBrijesh Singh  * -%ENODEV    if the SEV device is not available
551200664d5SBrijesh Singh  * -%ENOTSUPP  if the SEV does not support SEV
552200664d5SBrijesh Singh  * -%ETIMEDOUT if the SEV command timed out
553200664d5SBrijesh Singh  * -%EIO       if the SEV returned a non-zero return code
554200664d5SBrijesh Singh  */
555200664d5SBrijesh Singh int sev_platform_status(struct sev_user_data_status *status, int *error);
556200664d5SBrijesh Singh 
557200664d5SBrijesh Singh /**
558200664d5SBrijesh Singh  * sev_issue_cmd_external_user - issue SEV command by other driver with a file
559200664d5SBrijesh Singh  * handle.
560200664d5SBrijesh Singh  *
561200664d5SBrijesh Singh  * This function can be used by other drivers to issue a SEV command on
562200664d5SBrijesh Singh  * behalf of userspace. The caller must pass a valid SEV file descriptor
563200664d5SBrijesh Singh  * so that we know that it has access to SEV device.
564200664d5SBrijesh Singh  *
565200664d5SBrijesh Singh  * @filep - SEV device file pointer
566200664d5SBrijesh Singh  * @cmd - command to issue
567200664d5SBrijesh Singh  * @data - command buffer
568200664d5SBrijesh Singh  * @error: SEV command return code
569200664d5SBrijesh Singh  *
570200664d5SBrijesh Singh  * Returns:
571200664d5SBrijesh Singh  * 0 if the SEV successfully processed the command
572200664d5SBrijesh Singh  * -%ENODEV    if the SEV device is not available
573200664d5SBrijesh Singh  * -%ENOTSUPP  if the SEV does not support SEV
574200664d5SBrijesh Singh  * -%ETIMEDOUT if the SEV command timed out
575200664d5SBrijesh Singh  * -%EIO       if the SEV returned a non-zero return code
576200664d5SBrijesh Singh  * -%EINVAL    if the SEV file descriptor is not valid
577200664d5SBrijesh Singh  */
578200664d5SBrijesh Singh int sev_issue_cmd_external_user(struct file *filep, unsigned int id,
579200664d5SBrijesh Singh 				void *data, int *error);
580200664d5SBrijesh Singh 
581200664d5SBrijesh Singh /**
582200664d5SBrijesh Singh  * sev_guest_deactivate - perform SEV DEACTIVATE command
583200664d5SBrijesh Singh  *
584200664d5SBrijesh Singh  * @deactivate: sev_data_deactivate structure to be processed
585200664d5SBrijesh Singh  * @sev_ret: sev command return code
586200664d5SBrijesh Singh  *
587200664d5SBrijesh Singh  * Returns:
588200664d5SBrijesh Singh  * 0 if the sev successfully processed the command
589200664d5SBrijesh Singh  * -%ENODEV    if the sev device is not available
590200664d5SBrijesh Singh  * -%ENOTSUPP  if the sev does not support SEV
591200664d5SBrijesh Singh  * -%ETIMEDOUT if the sev command timed out
592200664d5SBrijesh Singh  * -%EIO       if the sev returned a non-zero return code
593200664d5SBrijesh Singh  */
594200664d5SBrijesh Singh int sev_guest_deactivate(struct sev_data_deactivate *data, int *error);
595200664d5SBrijesh Singh 
596200664d5SBrijesh Singh /**
597200664d5SBrijesh Singh  * sev_guest_activate - perform SEV ACTIVATE command
598200664d5SBrijesh Singh  *
599200664d5SBrijesh Singh  * @activate: sev_data_activate structure to be processed
600200664d5SBrijesh Singh  * @sev_ret: sev command return code
601200664d5SBrijesh Singh  *
602200664d5SBrijesh Singh  * Returns:
603200664d5SBrijesh Singh  * 0 if the sev successfully processed the command
604200664d5SBrijesh Singh  * -%ENODEV    if the sev device is not available
605200664d5SBrijesh Singh  * -%ENOTSUPP  if the sev does not support SEV
606200664d5SBrijesh Singh  * -%ETIMEDOUT if the sev command timed out
607200664d5SBrijesh Singh  * -%EIO       if the sev returned a non-zero return code
608200664d5SBrijesh Singh  */
609200664d5SBrijesh Singh int sev_guest_activate(struct sev_data_activate *data, int *error);
610200664d5SBrijesh Singh 
611200664d5SBrijesh Singh /**
612200664d5SBrijesh Singh  * sev_guest_df_flush - perform SEV DF_FLUSH command
613200664d5SBrijesh Singh  *
614200664d5SBrijesh Singh  * @sev_ret: sev command return code
615200664d5SBrijesh Singh  *
616200664d5SBrijesh Singh  * Returns:
617200664d5SBrijesh Singh  * 0 if the sev successfully processed the command
618200664d5SBrijesh Singh  * -%ENODEV    if the sev device is not available
619200664d5SBrijesh Singh  * -%ENOTSUPP  if the sev does not support SEV
620200664d5SBrijesh Singh  * -%ETIMEDOUT if the sev command timed out
621200664d5SBrijesh Singh  * -%EIO       if the sev returned a non-zero return code
622200664d5SBrijesh Singh  */
623200664d5SBrijesh Singh int sev_guest_df_flush(int *error);
624200664d5SBrijesh Singh 
625200664d5SBrijesh Singh /**
626200664d5SBrijesh Singh  * sev_guest_decommission - perform SEV DECOMMISSION command
627200664d5SBrijesh Singh  *
628200664d5SBrijesh Singh  * @decommission: sev_data_decommission structure to be processed
629200664d5SBrijesh Singh  * @sev_ret: sev command return code
630200664d5SBrijesh Singh  *
631200664d5SBrijesh Singh  * Returns:
632200664d5SBrijesh Singh  * 0 if the sev successfully processed the command
633200664d5SBrijesh Singh  * -%ENODEV    if the sev device is not available
634200664d5SBrijesh Singh  * -%ENOTSUPP  if the sev does not support SEV
635200664d5SBrijesh Singh  * -%ETIMEDOUT if the sev command timed out
636200664d5SBrijesh Singh  * -%EIO       if the sev returned a non-zero return code
637200664d5SBrijesh Singh  */
638200664d5SBrijesh Singh int sev_guest_decommission(struct sev_data_decommission *data, int *error);
639200664d5SBrijesh Singh 
640376bd28dSHerbert Xu void *psp_copy_user_blob(u64 uaddr, u32 len);
6417360e4b1SBrijesh Singh 
642200664d5SBrijesh Singh #else	/* !CONFIG_CRYPTO_DEV_SP_PSP */
643200664d5SBrijesh Singh 
644200664d5SBrijesh Singh static inline int
sev_platform_status(struct sev_user_data_status * status,int * error)645200664d5SBrijesh Singh sev_platform_status(struct sev_user_data_status *status, int *error) { return -ENODEV; }
646200664d5SBrijesh Singh 
sev_platform_init(int * error)647200664d5SBrijesh Singh static inline int sev_platform_init(int *error) { return -ENODEV; }
648200664d5SBrijesh Singh 
649200664d5SBrijesh Singh static inline int
sev_guest_deactivate(struct sev_data_deactivate * data,int * error)650200664d5SBrijesh Singh sev_guest_deactivate(struct sev_data_deactivate *data, int *error) { return -ENODEV; }
651200664d5SBrijesh Singh 
652200664d5SBrijesh Singh static inline int
sev_guest_decommission(struct sev_data_decommission * data,int * error)653200664d5SBrijesh Singh sev_guest_decommission(struct sev_data_decommission *data, int *error) { return -ENODEV; }
654200664d5SBrijesh Singh 
655200664d5SBrijesh Singh static inline int
sev_guest_activate(struct sev_data_activate * data,int * error)656200664d5SBrijesh Singh sev_guest_activate(struct sev_data_activate *data, int *error) { return -ENODEV; }
657200664d5SBrijesh Singh 
sev_guest_df_flush(int * error)658200664d5SBrijesh Singh static inline int sev_guest_df_flush(int *error) { return -ENODEV; }
659200664d5SBrijesh Singh 
660200664d5SBrijesh Singh static inline int
sev_issue_cmd_external_user(struct file * filep,unsigned int id,void * data,int * error)661200664d5SBrijesh Singh sev_issue_cmd_external_user(struct file *filep, unsigned int id, void *data, int *error) { return -ENODEV; }
662200664d5SBrijesh Singh 
psp_copy_user_blob(u64 __user uaddr,u32 len)6637360e4b1SBrijesh Singh static inline void *psp_copy_user_blob(u64 __user uaddr, u32 len) { return ERR_PTR(-EINVAL); }
6647360e4b1SBrijesh Singh 
665200664d5SBrijesh Singh #endif	/* CONFIG_CRYPTO_DEV_SP_PSP */
666200664d5SBrijesh Singh 
667592d5e74SBrijesh Singh #endif	/* __PSP_SEV_H__ */
668