| 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
| 3 | #ifndef QEMU_I386_TDX_H |
| 4 | #define QEMU_I386_TDX_H |
| 5 | |
| 6 | #ifndef CONFIG_USER_ONLY |
| 7 | #include CONFIG_DEVICES /* CONFIG_TDX */ |
| 8 | #endif |
| 9 | |
| 10 | #include "confidential-guest.h" |
| 11 | #include "cpu.h" |
| 12 | #include "hw/i386/tdvf.h" |
| 13 | |
| 14 | #include "tdx-quote-generator.h" |
| 15 | |
| 16 | #define TYPE_TDX_GUEST "tdx-guest" |
| 17 | #define TDX_GUEST(obj) OBJECT_CHECK(TdxGuest, (obj), TYPE_TDX_GUEST) |
| 18 | |
| 19 | typedef struct TdxGuestClass { |
| 20 | X86ConfidentialGuestClass parent_class; |
| 21 | } TdxGuestClass; |
| 22 | |
| 23 | /* TDX requires bus frequency 25MHz */ |
| 24 | #define TDX_APIC_BUS_CYCLES_NS 40 |
| 25 | |
| 26 | #define TDVMCALL_GET_TD_VM_CALL_INFO 0x10000 |
| 27 | #define TDVMCALL_GET_QUOTE 0x10002 |
| 28 | #define TDVMCALL_SETUP_EVENT_NOTIFY_INTERRUPT 0x10004 |
| 29 | |
| 30 | #define TDG_VP_VMCALL_SUCCESS 0x0000000000000000ULL |
| 31 | #define TDG_VP_VMCALL_RETRY 0x0000000000000001ULL |
| 32 | #define TDG_VP_VMCALL_INVALID_OPERAND 0x8000000000000000ULL |
| 33 | #define TDG_VP_VMCALL_GPA_INUSE 0x8000000000000001ULL |
| 34 | #define TDG_VP_VMCALL_ALIGN_ERROR 0x8000000000000002ULL |
| 35 | |
| 36 | #define TDG_VP_VMCALL_SUBFUNC_SET_EVENT_NOTIFY_INTERRUPT BIT_ULL(1) |
| 37 | |
| 38 | enum TdxRamType { |
| 39 | TDX_RAM_UNACCEPTED, |
| 40 | TDX_RAM_ADDED, |
| 41 | }; |
| 42 | |
| 43 | typedef struct TdxRamEntry { |
| 44 | uint64_t address; |
| 45 | uint64_t length; |
| 46 | enum TdxRamType type; |
| 47 | } TdxRamEntry; |
| 48 | |
| 49 | typedef struct TdxGuest { |
| 50 | X86ConfidentialGuest parent_obj; |
| 51 | |
| 52 | QemuMutex lock; |
| 53 | |
| 54 | bool initialized; |
| 55 | uint64_t attributes; /* TD attributes */ |
| 56 | uint64_t xfam; |
| 57 | char *mrconfigid; /* base64 encoded sha384 digest */ |
| 58 | char *mrowner; /* base64 encoded sha384 digest */ |
| 59 | char *mrownerconfig; /* base64 encoded sha384 digest */ |
| 60 | |
| 61 | MemoryRegion *tdvf_mr; |
| 62 | TdxFirmware tdvf; |
| 63 | |
| 64 | uint32_t nr_ram_entries; |
| 65 | TdxRamEntry *ram_entries; |
| 66 | |
| 67 | /* GetQuote */ |
| 68 | SocketAddress *qg_sock_addr; |
| 69 | int num; |
| 70 | |
| 71 | uint32_t event_notify_vector; |
| 72 | uint32_t event_notify_apicid; |
| 73 | ResettableState reset_state; |
| 74 | } TdxGuest; |
| 75 | |
| 76 | #ifdef CONFIG_TDX |
| 77 | bool is_tdx_vm(void); |
| 78 | #else |
| 79 | #define is_tdx_vm() 0 |
| 80 | #endif /* CONFIG_TDX */ |
| 81 | |
| 82 | int tdx_pre_create_vcpu(CPUState *cpu, Error **errp); |
| 83 | void tdx_set_tdvf_region(MemoryRegion *tdvf_mr); |
| 84 | int tdx_parse_tdvf(void *flash_ptr, int size); |
| 85 | int tdx_handle_report_fatal_error(X86CPU *cpu, struct kvm_run *run); |
| 86 | void tdx_handle_get_quote(X86CPU *cpu, struct kvm_run *run); |
| 87 | void tdx_handle_get_tdvmcall_info(X86CPU *cpu, struct kvm_run *run); |
| 88 | void tdx_handle_setup_event_notify_interrupt(X86CPU *cpu, struct kvm_run *run); |
| 89 | |
| 90 | #endif /* QEMU_I386_TDX_H */ |