19102c968SPaolo Bonzini #ifndef WHP_INTERNAL_H 29102c968SPaolo Bonzini #define WHP_INTERNAL_H 39102c968SPaolo Bonzini 49102c968SPaolo Bonzini #include <windows.h> 59102c968SPaolo Bonzini #include <WinHvPlatform.h> 69102c968SPaolo Bonzini #include <WinHvEmulation.h> 79102c968SPaolo Bonzini 8*84f4ef17SPaolo Bonzini struct whpx_state { 9*84f4ef17SPaolo Bonzini uint64_t mem_quota; 10*84f4ef17SPaolo Bonzini WHV_PARTITION_HANDLE partition; 11*84f4ef17SPaolo Bonzini bool kernel_irqchip_allowed; 12*84f4ef17SPaolo Bonzini bool kernel_irqchip_required; 13*84f4ef17SPaolo Bonzini bool apic_in_platform; 14*84f4ef17SPaolo Bonzini }; 15*84f4ef17SPaolo Bonzini 16*84f4ef17SPaolo Bonzini struct whpx_lapic_state { 17*84f4ef17SPaolo Bonzini struct { 18*84f4ef17SPaolo Bonzini uint32_t data; 19*84f4ef17SPaolo Bonzini uint32_t padding[3]; 20*84f4ef17SPaolo Bonzini } fields[256]; 21*84f4ef17SPaolo Bonzini }; 22*84f4ef17SPaolo Bonzini 23*84f4ef17SPaolo Bonzini extern struct whpx_state whpx_global; 24*84f4ef17SPaolo Bonzini void whpx_apic_get(DeviceState *s); 25*84f4ef17SPaolo Bonzini 269102c968SPaolo Bonzini #define WHV_E_UNKNOWN_CAPABILITY 0x80370300L 279102c968SPaolo Bonzini 289102c968SPaolo Bonzini #define LIST_WINHVPLATFORM_FUNCTIONS(X) \ 299102c968SPaolo Bonzini X(HRESULT, WHvGetCapability, (WHV_CAPABILITY_CODE CapabilityCode, VOID* CapabilityBuffer, UINT32 CapabilityBufferSizeInBytes, UINT32* WrittenSizeInBytes)) \ 309102c968SPaolo Bonzini X(HRESULT, WHvCreatePartition, (WHV_PARTITION_HANDLE* Partition)) \ 319102c968SPaolo Bonzini X(HRESULT, WHvSetupPartition, (WHV_PARTITION_HANDLE Partition)) \ 329102c968SPaolo Bonzini X(HRESULT, WHvDeletePartition, (WHV_PARTITION_HANDLE Partition)) \ 339102c968SPaolo Bonzini X(HRESULT, WHvGetPartitionProperty, (WHV_PARTITION_HANDLE Partition, WHV_PARTITION_PROPERTY_CODE PropertyCode, VOID* PropertyBuffer, UINT32 PropertyBufferSizeInBytes, UINT32* WrittenSizeInBytes)) \ 349102c968SPaolo Bonzini X(HRESULT, WHvSetPartitionProperty, (WHV_PARTITION_HANDLE Partition, WHV_PARTITION_PROPERTY_CODE PropertyCode, const VOID* PropertyBuffer, UINT32 PropertyBufferSizeInBytes)) \ 359102c968SPaolo Bonzini X(HRESULT, WHvMapGpaRange, (WHV_PARTITION_HANDLE Partition, VOID* SourceAddress, WHV_GUEST_PHYSICAL_ADDRESS GuestAddress, UINT64 SizeInBytes, WHV_MAP_GPA_RANGE_FLAGS Flags)) \ 369102c968SPaolo Bonzini X(HRESULT, WHvUnmapGpaRange, (WHV_PARTITION_HANDLE Partition, WHV_GUEST_PHYSICAL_ADDRESS GuestAddress, UINT64 SizeInBytes)) \ 379102c968SPaolo Bonzini X(HRESULT, WHvTranslateGva, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, WHV_GUEST_VIRTUAL_ADDRESS Gva, WHV_TRANSLATE_GVA_FLAGS TranslateFlags, WHV_TRANSLATE_GVA_RESULT* TranslationResult, WHV_GUEST_PHYSICAL_ADDRESS* Gpa)) \ 389102c968SPaolo Bonzini X(HRESULT, WHvCreateVirtualProcessor, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, UINT32 Flags)) \ 399102c968SPaolo Bonzini X(HRESULT, WHvDeleteVirtualProcessor, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex)) \ 409102c968SPaolo Bonzini X(HRESULT, WHvRunVirtualProcessor, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, VOID* ExitContext, UINT32 ExitContextSizeInBytes)) \ 419102c968SPaolo Bonzini X(HRESULT, WHvCancelRunVirtualProcessor, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, UINT32 Flags)) \ 429102c968SPaolo Bonzini X(HRESULT, WHvGetVirtualProcessorRegisters, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, const WHV_REGISTER_NAME* RegisterNames, UINT32 RegisterCount, WHV_REGISTER_VALUE* RegisterValues)) \ 439102c968SPaolo Bonzini X(HRESULT, WHvSetVirtualProcessorRegisters, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, const WHV_REGISTER_NAME* RegisterNames, UINT32 RegisterCount, const WHV_REGISTER_VALUE* RegisterValues)) \ 449102c968SPaolo Bonzini 459102c968SPaolo Bonzini /* 469102c968SPaolo Bonzini * These are supplemental functions that may not be present 479102c968SPaolo Bonzini * on all versions and are not critical for basic functionality. 489102c968SPaolo Bonzini */ 499102c968SPaolo Bonzini #define LIST_WINHVPLATFORM_FUNCTIONS_SUPPLEMENTAL(X) \ 509102c968SPaolo Bonzini X(HRESULT, WHvSuspendPartitionTime, (WHV_PARTITION_HANDLE Partition)) \ 519102c968SPaolo Bonzini X(HRESULT, WHvRequestInterrupt, (WHV_PARTITION_HANDLE Partition, \ 529102c968SPaolo Bonzini WHV_INTERRUPT_CONTROL* Interrupt, UINT32 InterruptControlSize)) \ 539102c968SPaolo Bonzini X(HRESULT, WHvGetVirtualProcessorInterruptControllerState2, \ 549102c968SPaolo Bonzini (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, PVOID State, \ 559102c968SPaolo Bonzini UINT32 StateSize, UINT32* WrittenSize)) \ 569102c968SPaolo Bonzini X(HRESULT, WHvSetVirtualProcessorInterruptControllerState2, \ 579102c968SPaolo Bonzini (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, PVOID State, \ 589102c968SPaolo Bonzini UINT32 StateSize)) \ 599102c968SPaolo Bonzini 609102c968SPaolo Bonzini #define LIST_WINHVEMULATION_FUNCTIONS(X) \ 619102c968SPaolo Bonzini X(HRESULT, WHvEmulatorCreateEmulator, (const WHV_EMULATOR_CALLBACKS* Callbacks, WHV_EMULATOR_HANDLE* Emulator)) \ 629102c968SPaolo Bonzini X(HRESULT, WHvEmulatorDestroyEmulator, (WHV_EMULATOR_HANDLE Emulator)) \ 639102c968SPaolo Bonzini X(HRESULT, WHvEmulatorTryIoEmulation, (WHV_EMULATOR_HANDLE Emulator, VOID* Context, const WHV_VP_EXIT_CONTEXT* VpContext, const WHV_X64_IO_PORT_ACCESS_CONTEXT* IoInstructionContext, WHV_EMULATOR_STATUS* EmulatorReturnStatus)) \ 649102c968SPaolo Bonzini X(HRESULT, WHvEmulatorTryMmioEmulation, (WHV_EMULATOR_HANDLE Emulator, VOID* Context, const WHV_VP_EXIT_CONTEXT* VpContext, const WHV_MEMORY_ACCESS_CONTEXT* MmioInstructionContext, WHV_EMULATOR_STATUS* EmulatorReturnStatus)) \ 659102c968SPaolo Bonzini 669102c968SPaolo Bonzini #define WHP_DEFINE_TYPE(return_type, function_name, signature) \ 679102c968SPaolo Bonzini typedef return_type (WINAPI *function_name ## _t) signature; 689102c968SPaolo Bonzini 699102c968SPaolo Bonzini #define WHP_DECLARE_MEMBER(return_type, function_name, signature) \ 709102c968SPaolo Bonzini function_name ## _t function_name; 719102c968SPaolo Bonzini 729102c968SPaolo Bonzini /* Define function typedef */ 739102c968SPaolo Bonzini LIST_WINHVPLATFORM_FUNCTIONS(WHP_DEFINE_TYPE) 749102c968SPaolo Bonzini LIST_WINHVEMULATION_FUNCTIONS(WHP_DEFINE_TYPE) 759102c968SPaolo Bonzini LIST_WINHVPLATFORM_FUNCTIONS_SUPPLEMENTAL(WHP_DEFINE_TYPE) 769102c968SPaolo Bonzini 779102c968SPaolo Bonzini struct WHPDispatch { 789102c968SPaolo Bonzini LIST_WINHVPLATFORM_FUNCTIONS(WHP_DECLARE_MEMBER) 799102c968SPaolo Bonzini LIST_WINHVEMULATION_FUNCTIONS(WHP_DECLARE_MEMBER) 809102c968SPaolo Bonzini LIST_WINHVPLATFORM_FUNCTIONS_SUPPLEMENTAL(WHP_DECLARE_MEMBER) 819102c968SPaolo Bonzini }; 829102c968SPaolo Bonzini 839102c968SPaolo Bonzini extern struct WHPDispatch whp_dispatch; 849102c968SPaolo Bonzini 859102c968SPaolo Bonzini bool init_whp_dispatch(void); 869102c968SPaolo Bonzini 879102c968SPaolo Bonzini typedef enum WHPFunctionList { 889102c968SPaolo Bonzini WINHV_PLATFORM_FNS_DEFAULT, 899102c968SPaolo Bonzini WINHV_EMULATION_FNS_DEFAULT, 909102c968SPaolo Bonzini WINHV_PLATFORM_FNS_SUPPLEMENTAL 919102c968SPaolo Bonzini } WHPFunctionList; 929102c968SPaolo Bonzini 939102c968SPaolo Bonzini #endif /* WHP_INTERNAL_H */ 94