xref: /kvm-unit-tests/lib/x86/amd_sev.h (revision 1399f7f7f1c3170b2337c08beb615ae875636405)
1 /*
2  * AMD SEV support in kvm-unit-tests
3  *
4  * Copyright (c) 2021, Google Inc
5  *
6  * Authors:
7  *   Zixuan Wang <zixuanwang@google.com>
8  *
9  * SPDX-License-Identifier: LGPL-2.0-or-later
10  */
11 
12 #ifndef _X86_AMD_SEV_H_
13 #define _X86_AMD_SEV_H_
14 
15 #ifdef CONFIG_EFI
16 
17 #include "libcflat.h"
18 #include "desc.h"
19 #include "asm/page.h"
20 #include "efi.h"
21 
22 /*
23  * AMD Programmer's Manual Volume 3
24  *   - Section "Function 8000_0000h - Maximum Extended Function Number and Vendor String"
25  *   - Section "Function 8000_001Fh - Encrypted Memory Capabilities"
26  */
27 #define CPUID_FN_LARGEST_EXT_FUNC_NUM 0x80000000
28 #define CPUID_FN_ENCRYPT_MEM_CAPAB    0x8000001f
29 #define SEV_SUPPORT_MASK              0b10
30 
31 /*
32  * AMD Programmer's Manual Volume 2
33  *   - Section "SEV_STATUS MSR"
34  */
35 #define MSR_SEV_STATUS      0xc0010131
36 #define SEV_ENABLED_MASK    0b1
37 #define SEV_ES_ENABLED_MASK 0b10
38 
39 bool amd_sev_enabled(void);
40 efi_status_t setup_amd_sev(void);
41 
42 /*
43  * AMD Programmer's Manual Volume 2
44  *   - Section "#VC Exception"
45  */
46 #define SEV_ES_VC_HANDLER_VECTOR 29
47 
48 /*
49  * AMD Programmer's Manual Volume 2
50  *   - Section "GHCB"
51  */
52 #define SEV_ES_GHCB_MSR_INDEX 0xc0010130
53 
54 bool amd_sev_es_enabled(void);
55 efi_status_t setup_amd_sev_es(void);
56 void setup_ghcb_pte(pgd_t *page_table);
57 
58 unsigned long long get_amd_sev_c_bit_mask(void);
59 unsigned long long get_amd_sev_addr_upperbound(void);
60 
61 #endif /* CONFIG_EFI */
62 
63 #endif /* _X86_AMD_SEV_H_ */
64