unify {de,}mangle_poll(), get rid of kernel-side POLL...
[cris-mirror.git] / include / linux / psp-sev.h
blob93addfa3406199aa1b93f7ca44ffc3f522537c36
1 /*
2 * AMD Secure Encrypted Virtualization (SEV) driver interface
4 * Copyright (C) 2016-2017 Advanced Micro Devices, Inc.
6 * Author: Brijesh Singh <brijesh.singh@amd.com>
8 * SEV spec 0.14 is available at:
9 * http://support.amd.com/TechDocs/55766_SEV-KM API_Specification.pdf
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.
16 #ifndef __PSP_SEV_H__
17 #define __PSP_SEV_H__
19 #include <uapi/linux/psp-sev.h>
21 #ifdef CONFIG_X86
22 #include <linux/mem_encrypt.h>
24 #define __psp_pa(x) __sme_pa(x)
25 #else
26 #define __psp_pa(x) __pa(x)
27 #endif
29 #define SEV_FW_BLOB_MAX_SIZE 0x4000 /* 16KB */
31 /**
32 * SEV platform state
34 enum sev_state {
35 SEV_STATE_UNINIT = 0x0,
36 SEV_STATE_INIT = 0x1,
37 SEV_STATE_WORKING = 0x2,
39 SEV_STATE_MAX
42 /**
43 * SEV platform and guest management commands
45 enum sev_cmd {
46 /* platform commands */
47 SEV_CMD_INIT = 0x001,
48 SEV_CMD_SHUTDOWN = 0x002,
49 SEV_CMD_FACTORY_RESET = 0x003,
50 SEV_CMD_PLATFORM_STATUS = 0x004,
51 SEV_CMD_PEK_GEN = 0x005,
52 SEV_CMD_PEK_CSR = 0x006,
53 SEV_CMD_PEK_CERT_IMPORT = 0x007,
54 SEV_CMD_PDH_CERT_EXPORT = 0x008,
55 SEV_CMD_PDH_GEN = 0x009,
56 SEV_CMD_DF_FLUSH = 0x00A,
58 /* Guest commands */
59 SEV_CMD_DECOMMISSION = 0x020,
60 SEV_CMD_ACTIVATE = 0x021,
61 SEV_CMD_DEACTIVATE = 0x022,
62 SEV_CMD_GUEST_STATUS = 0x023,
64 /* Guest launch commands */
65 SEV_CMD_LAUNCH_START = 0x030,
66 SEV_CMD_LAUNCH_UPDATE_DATA = 0x031,
67 SEV_CMD_LAUNCH_UPDATE_VMSA = 0x032,
68 SEV_CMD_LAUNCH_MEASURE = 0x033,
69 SEV_CMD_LAUNCH_UPDATE_SECRET = 0x034,
70 SEV_CMD_LAUNCH_FINISH = 0x035,
72 /* Guest migration commands (outgoing) */
73 SEV_CMD_SEND_START = 0x040,
74 SEV_CMD_SEND_UPDATE_DATA = 0x041,
75 SEV_CMD_SEND_UPDATE_VMSA = 0x042,
76 SEV_CMD_SEND_FINISH = 0x043,
78 /* Guest migration commands (incoming) */
79 SEV_CMD_RECEIVE_START = 0x050,
80 SEV_CMD_RECEIVE_UPDATE_DATA = 0x051,
81 SEV_CMD_RECEIVE_UPDATE_VMSA = 0x052,
82 SEV_CMD_RECEIVE_FINISH = 0x053,
84 /* Guest debug commands */
85 SEV_CMD_DBG_DECRYPT = 0x060,
86 SEV_CMD_DBG_ENCRYPT = 0x061,
88 SEV_CMD_MAX,
91 /**
92 * struct sev_data_init - INIT command parameters
94 * @flags: processing flags
95 * @tmr_address: system physical address used for SEV-ES
96 * @tmr_len: len of tmr_address
98 struct sev_data_init {
99 u32 flags; /* In */
100 u32 reserved; /* In */
101 u64 tmr_address; /* In */
102 u32 tmr_len; /* In */
103 } __packed;
106 * struct sev_data_pek_csr - PEK_CSR command parameters
108 * @address: PEK certificate chain
109 * @len: len of certificate
111 struct sev_data_pek_csr {
112 u64 address; /* In */
113 u32 len; /* In/Out */
114 } __packed;
117 * struct sev_data_cert_import - PEK_CERT_IMPORT command parameters
119 * @pek_address: PEK certificate chain
120 * @pek_len: len of PEK certificate
121 * @oca_address: OCA certificate chain
122 * @oca_len: len of OCA certificate
124 struct sev_data_pek_cert_import {
125 u64 pek_cert_address; /* In */
126 u32 pek_cert_len; /* In */
127 u32 reserved; /* In */
128 u64 oca_cert_address; /* In */
129 u32 oca_cert_len; /* In */
130 } __packed;
133 * struct sev_data_pdh_cert_export - PDH_CERT_EXPORT command parameters
135 * @pdh_address: PDH certificate address
136 * @pdh_len: len of PDH certificate
137 * @cert_chain_address: PDH certificate chain
138 * @cert_chain_len: len of PDH certificate chain
140 struct sev_data_pdh_cert_export {
141 u64 pdh_cert_address; /* In */
142 u32 pdh_cert_len; /* In/Out */
143 u32 reserved; /* In */
144 u64 cert_chain_address; /* In */
145 u32 cert_chain_len; /* In/Out */
146 } __packed;
149 * struct sev_data_decommission - DECOMMISSION command parameters
151 * @handle: handle of the VM to decommission
153 struct sev_data_decommission {
154 u32 handle; /* In */
155 } __packed;
158 * struct sev_data_activate - ACTIVATE command parameters
160 * @handle: handle of the VM to activate
161 * @asid: asid assigned to the VM
163 struct sev_data_activate {
164 u32 handle; /* In */
165 u32 asid; /* In */
166 } __packed;
169 * struct sev_data_deactivate - DEACTIVATE command parameters
171 * @handle: handle of the VM to deactivate
173 struct sev_data_deactivate {
174 u32 handle; /* In */
175 } __packed;
178 * struct sev_data_guest_status - SEV GUEST_STATUS command parameters
180 * @handle: handle of the VM to retrieve status
181 * @policy: policy information for the VM
182 * @asid: current ASID of the VM
183 * @state: current state of the VM
185 struct sev_data_guest_status {
186 u32 handle; /* In */
187 u32 policy; /* Out */
188 u32 asid; /* Out */
189 u8 state; /* Out */
190 } __packed;
193 * struct sev_data_launch_start - LAUNCH_START command parameters
195 * @handle: handle assigned to the VM
196 * @policy: guest launch policy
197 * @dh_cert_address: physical address of DH certificate blob
198 * @dh_cert_len: len of DH certificate blob
199 * @session_address: physical address of session parameters
200 * @session_len: len of session parameters
202 struct sev_data_launch_start {
203 u32 handle; /* In/Out */
204 u32 policy; /* In */
205 u64 dh_cert_address; /* In */
206 u32 dh_cert_len; /* In */
207 u32 reserved; /* In */
208 u64 session_address; /* In */
209 u32 session_len; /* In */
210 } __packed;
213 * struct sev_data_launch_update_data - LAUNCH_UPDATE_DATA command parameter
215 * @handle: handle of the VM to update
216 * @len: len of memory to be encrypted
217 * @address: physical address of memory region to encrypt
219 struct sev_data_launch_update_data {
220 u32 handle; /* In */
221 u32 reserved;
222 u64 address; /* In */
223 u32 len; /* In */
224 } __packed;
227 * struct sev_data_launch_update_vmsa - LAUNCH_UPDATE_VMSA command
229 * @handle: handle of the VM
230 * @address: physical address of memory region to encrypt
231 * @len: len of memory region to encrypt
233 struct sev_data_launch_update_vmsa {
234 u32 handle; /* In */
235 u32 reserved;
236 u64 address; /* In */
237 u32 len; /* In */
238 } __packed;
241 * struct sev_data_launch_measure - LAUNCH_MEASURE command parameters
243 * @handle: handle of the VM to process
244 * @address: physical address containing the measurement blob
245 * @len: len of measurement blob
247 struct sev_data_launch_measure {
248 u32 handle; /* In */
249 u32 reserved;
250 u64 address; /* In */
251 u32 len; /* In/Out */
252 } __packed;
255 * struct sev_data_launch_secret - LAUNCH_SECRET command parameters
257 * @handle: handle of the VM to process
258 * @hdr_address: physical address containing the packet header
259 * @hdr_len: len of packet header
260 * @guest_address: system physical address of guest memory region
261 * @guest_len: len of guest_paddr
262 * @trans_address: physical address of transport memory buffer
263 * @trans_len: len of transport memory buffer
265 struct sev_data_launch_secret {
266 u32 handle; /* In */
267 u32 reserved1;
268 u64 hdr_address; /* In */
269 u32 hdr_len; /* In */
270 u32 reserved2;
271 u64 guest_address; /* In */
272 u32 guest_len; /* In */
273 u32 reserved3;
274 u64 trans_address; /* In */
275 u32 trans_len; /* In */
276 } __packed;
279 * struct sev_data_launch_finish - LAUNCH_FINISH command parameters
281 * @handle: handle of the VM to process
283 struct sev_data_launch_finish {
284 u32 handle; /* In */
285 } __packed;
288 * struct sev_data_send_start - SEND_START command parameters
290 * @handle: handle of the VM to process
291 * @policy: policy information for the VM
292 * @pdh_cert_address: physical address containing PDH certificate
293 * @pdh_cert_len: len of PDH certificate
294 * @plat_certs_address: physical address containing platform certificate
295 * @plat_certs_len: len of platform certificate
296 * @amd_certs_address: physical address containing AMD certificate
297 * @amd_certs_len: len of AMD certificate
298 * @session_address: physical address containing Session data
299 * @session_len: len of session data
301 struct sev_data_send_start {
302 u32 handle; /* In */
303 u32 policy; /* Out */
304 u64 pdh_cert_address; /* In */
305 u32 pdh_cert_len; /* In */
306 u32 reserved1;
307 u64 plat_cert_address; /* In */
308 u32 plat_cert_len; /* In */
309 u32 reserved2;
310 u64 amd_cert_address; /* In */
311 u32 amd_cert_len; /* In */
312 u32 reserved3;
313 u64 session_address; /* In */
314 u32 session_len; /* In/Out */
315 } __packed;
318 * struct sev_data_send_update - SEND_UPDATE_DATA command
320 * @handle: handle of the VM to process
321 * @hdr_address: physical address containing packet header
322 * @hdr_len: len of packet header
323 * @guest_address: physical address of guest memory region to send
324 * @guest_len: len of guest memory region to send
325 * @trans_address: physical address of host memory region
326 * @trans_len: len of host memory region
328 struct sev_data_send_update_data {
329 u32 handle; /* In */
330 u32 reserved1;
331 u64 hdr_address; /* In */
332 u32 hdr_len; /* In/Out */
333 u32 reserved2;
334 u64 guest_address; /* In */
335 u32 guest_len; /* In */
336 u32 reserved3;
337 u64 trans_address; /* In */
338 u32 trans_len; /* In */
339 } __packed;
342 * struct sev_data_send_update - SEND_UPDATE_VMSA command
344 * @handle: handle of the VM to process
345 * @hdr_address: physical address containing packet header
346 * @hdr_len: len of packet header
347 * @guest_address: physical address of guest memory region to send
348 * @guest_len: len of guest memory region to send
349 * @trans_address: physical address of host memory region
350 * @trans_len: len of host memory region
352 struct sev_data_send_update_vmsa {
353 u32 handle; /* In */
354 u64 hdr_address; /* In */
355 u32 hdr_len; /* In/Out */
356 u32 reserved2;
357 u64 guest_address; /* In */
358 u32 guest_len; /* In */
359 u32 reserved3;
360 u64 trans_address; /* In */
361 u32 trans_len; /* In */
362 } __packed;
365 * struct sev_data_send_finish - SEND_FINISH command parameters
367 * @handle: handle of the VM to process
369 struct sev_data_send_finish {
370 u32 handle; /* In */
371 } __packed;
374 * struct sev_data_receive_start - RECEIVE_START command parameters
376 * @handle: handle of the VM to perform receive operation
377 * @pdh_cert_address: system physical address containing PDH certificate blob
378 * @pdh_cert_len: len of PDH certificate blob
379 * @session_address: system physical address containing session blob
380 * @session_len: len of session blob
382 struct sev_data_receive_start {
383 u32 handle; /* In/Out */
384 u32 policy; /* In */
385 u64 pdh_cert_address; /* In */
386 u32 pdh_cert_len; /* In */
387 u32 reserved1;
388 u64 session_address; /* In */
389 u32 session_len; /* In */
390 } __packed;
393 * struct sev_data_receive_update_data - RECEIVE_UPDATE_DATA command parameters
395 * @handle: handle of the VM to update
396 * @hdr_address: physical address containing packet header blob
397 * @hdr_len: len of packet header
398 * @guest_address: system physical address of guest memory region
399 * @guest_len: len of guest memory region
400 * @trans_address: system physical address of transport buffer
401 * @trans_len: len of transport buffer
403 struct sev_data_receive_update_data {
404 u32 handle; /* In */
405 u32 reserved1;
406 u64 hdr_address; /* In */
407 u32 hdr_len; /* In */
408 u32 reserved2;
409 u64 guest_address; /* In */
410 u32 guest_len; /* In */
411 u32 reserved3;
412 u64 trans_address; /* In */
413 u32 trans_len; /* In */
414 } __packed;
417 * struct sev_data_receive_update_vmsa - RECEIVE_UPDATE_VMSA command parameters
419 * @handle: handle of the VM to update
420 * @hdr_address: physical address containing packet header blob
421 * @hdr_len: len of packet header
422 * @guest_address: system physical address of guest memory region
423 * @guest_len: len of guest memory region
424 * @trans_address: system physical address of transport buffer
425 * @trans_len: len of transport buffer
427 struct sev_data_receive_update_vmsa {
428 u32 handle; /* In */
429 u32 reserved1;
430 u64 hdr_address; /* In */
431 u32 hdr_len; /* In */
432 u32 reserved2;
433 u64 guest_address; /* In */
434 u32 guest_len; /* In */
435 u32 reserved3;
436 u64 trans_address; /* In */
437 u32 trans_len; /* In */
438 } __packed;
441 * struct sev_data_receive_finish - RECEIVE_FINISH command parameters
443 * @handle: handle of the VM to finish
445 struct sev_data_receive_finish {
446 u32 handle; /* In */
447 } __packed;
450 * struct sev_data_dbg - DBG_ENCRYPT/DBG_DECRYPT command parameters
452 * @handle: handle of the VM to perform debug operation
453 * @src_addr: source address of data to operate on
454 * @dst_addr: destination address of data to operate on
455 * @len: len of data to operate on
457 struct sev_data_dbg {
458 u32 handle; /* In */
459 u32 reserved;
460 u64 src_addr; /* In */
461 u64 dst_addr; /* In */
462 u32 len; /* In */
463 } __packed;
465 #ifdef CONFIG_CRYPTO_DEV_SP_PSP
468 * sev_platform_init - perform SEV INIT command
470 * @error: SEV command return code
472 * Returns:
473 * 0 if the SEV successfully processed the command
474 * -%ENODEV if the SEV device is not available
475 * -%ENOTSUPP if the SEV does not support SEV
476 * -%ETIMEDOUT if the SEV command timed out
477 * -%EIO if the SEV returned a non-zero return code
479 int sev_platform_init(int *error);
482 * sev_platform_status - perform SEV PLATFORM_STATUS command
484 * @status: sev_user_data_status structure to be processed
485 * @error: SEV command return code
487 * Returns:
488 * 0 if the SEV successfully processed the command
489 * -%ENODEV if the SEV device is not available
490 * -%ENOTSUPP if the SEV does not support SEV
491 * -%ETIMEDOUT if the SEV command timed out
492 * -%EIO if the SEV returned a non-zero return code
494 int sev_platform_status(struct sev_user_data_status *status, int *error);
497 * sev_issue_cmd_external_user - issue SEV command by other driver with a file
498 * handle.
500 * This function can be used by other drivers to issue a SEV command on
501 * behalf of userspace. The caller must pass a valid SEV file descriptor
502 * so that we know that it has access to SEV device.
504 * @filep - SEV device file pointer
505 * @cmd - command to issue
506 * @data - command buffer
507 * @error: SEV command return code
509 * Returns:
510 * 0 if the SEV successfully processed the command
511 * -%ENODEV if the SEV device is not available
512 * -%ENOTSUPP if the SEV does not support SEV
513 * -%ETIMEDOUT if the SEV command timed out
514 * -%EIO if the SEV returned a non-zero return code
515 * -%EINVAL if the SEV file descriptor is not valid
517 int sev_issue_cmd_external_user(struct file *filep, unsigned int id,
518 void *data, int *error);
521 * sev_guest_deactivate - perform SEV DEACTIVATE command
523 * @deactivate: sev_data_deactivate structure to be processed
524 * @sev_ret: sev command return code
526 * Returns:
527 * 0 if the sev successfully processed the command
528 * -%ENODEV if the sev device is not available
529 * -%ENOTSUPP if the sev does not support SEV
530 * -%ETIMEDOUT if the sev command timed out
531 * -%EIO if the sev returned a non-zero return code
533 int sev_guest_deactivate(struct sev_data_deactivate *data, int *error);
536 * sev_guest_activate - perform SEV ACTIVATE command
538 * @activate: sev_data_activate structure to be processed
539 * @sev_ret: sev command return code
541 * Returns:
542 * 0 if the sev successfully processed the command
543 * -%ENODEV if the sev device is not available
544 * -%ENOTSUPP if the sev does not support SEV
545 * -%ETIMEDOUT if the sev command timed out
546 * -%EIO if the sev returned a non-zero return code
548 int sev_guest_activate(struct sev_data_activate *data, int *error);
551 * sev_guest_df_flush - perform SEV DF_FLUSH command
553 * @sev_ret: sev command return code
555 * Returns:
556 * 0 if the sev successfully processed the command
557 * -%ENODEV if the sev device is not available
558 * -%ENOTSUPP if the sev does not support SEV
559 * -%ETIMEDOUT if the sev command timed out
560 * -%EIO if the sev returned a non-zero return code
562 int sev_guest_df_flush(int *error);
565 * sev_guest_decommission - perform SEV DECOMMISSION command
567 * @decommission: sev_data_decommission structure to be processed
568 * @sev_ret: sev command return code
570 * Returns:
571 * 0 if the sev successfully processed the command
572 * -%ENODEV if the sev device is not available
573 * -%ENOTSUPP if the sev does not support SEV
574 * -%ETIMEDOUT if the sev command timed out
575 * -%EIO if the sev returned a non-zero return code
577 int sev_guest_decommission(struct sev_data_decommission *data, int *error);
579 void *psp_copy_user_blob(u64 __user uaddr, u32 len);
581 #else /* !CONFIG_CRYPTO_DEV_SP_PSP */
583 static inline int
584 sev_platform_status(struct sev_user_data_status *status, int *error) { return -ENODEV; }
586 static inline int sev_platform_init(int *error) { return -ENODEV; }
588 static inline int
589 sev_guest_deactivate(struct sev_data_deactivate *data, int *error) { return -ENODEV; }
591 static inline int
592 sev_guest_decommission(struct sev_data_decommission *data, int *error) { return -ENODEV; }
594 static inline int
595 sev_guest_activate(struct sev_data_activate *data, int *error) { return -ENODEV; }
597 static inline int sev_guest_df_flush(int *error) { return -ENODEV; }
599 static inline int
600 sev_issue_cmd_external_user(struct file *filep, unsigned int id, void *data, int *error) { return -ENODEV; }
602 static inline void *psp_copy_user_blob(u64 __user uaddr, u32 len) { return ERR_PTR(-EINVAL); }
604 #endif /* CONFIG_CRYPTO_DEV_SP_PSP */
606 #endif /* __PSP_SEV_H__ */