xref: /qemu/target/i386/sev.h (revision 63cda19446c5307cc05b965c203742a583fc5abf)
1 /*
2  * QEMU Secure Encrypted Virutualization (SEV) support
3  *
4  * Copyright: Advanced Micro Devices, 2016-2018
5  *
6  * Authors:
7  *  Brijesh Singh <brijesh.singh@amd.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or later.
10  * See the COPYING file in the top-level directory.
11  *
12  */
13 
14 #ifndef I386_SEV_H
15 #define I386_SEV_H
16 
17 #ifndef CONFIG_USER_ONLY
18 #include CONFIG_DEVICES /* CONFIG_SEV */
19 #endif
20 
21 #if !defined(CONFIG_SEV) || defined(CONFIG_USER_ONLY)
22 #define sev_enabled() 0
23 #define sev_es_enabled() 0
24 #define sev_snp_enabled() 0
25 #else
26 bool sev_enabled(void);
27 bool sev_es_enabled(void);
28 bool sev_snp_enabled(void);
29 #endif
30 
31 #if !defined(CONFIG_USER_ONLY)
32 
33 #define TYPE_SEV_COMMON "sev-common"
34 #define TYPE_SEV_GUEST "sev-guest"
35 #define TYPE_SEV_SNP_GUEST "sev-snp-guest"
36 
37 #define SEV_POLICY_NODBG        0x1
38 #define SEV_POLICY_NOKS         0x2
39 #define SEV_POLICY_ES           0x4
40 #define SEV_POLICY_NOSEND       0x8
41 #define SEV_POLICY_DOMAIN       0x10
42 #define SEV_POLICY_SEV          0x20
43 
44 #define SEV_SNP_POLICY_SMT      0x10000
45 #define SEV_SNP_POLICY_DBG      0x80000
46 
47 typedef struct SevKernelLoaderContext {
48     char *setup_data;
49     size_t setup_size;
50     char *kernel_data;
51     size_t kernel_size;
52     char *initrd_data;
53     size_t initrd_size;
54     char *cmdline_data;
55     size_t cmdline_size;
56 } SevKernelLoaderContext;
57 
58 bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **errp);
59 
60 int sev_encrypt_flash(hwaddr gpa, uint8_t *ptr, uint64_t len, Error **errp);
61 int sev_inject_launch_secret(const char *hdr, const char *secret,
62                              uint64_t gpa, Error **errp);
63 
64 int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size);
65 void sev_es_set_reset_vector(CPUState *cpu);
66 
67 void pc_system_parse_sev_metadata(uint8_t *flash_ptr, size_t flash_size);
68 
69 #endif /* !CONFIG_USER_ONLY */
70 
71 uint32_t sev_get_cbit_position(void);
72 uint32_t sev_get_reduced_phys_bits(void);
73 
74 #endif
75