152581c71SMarkus Armbruster #ifndef TARGET_I386_WHPX_INTERNAL_H 252581c71SMarkus Armbruster #define TARGET_I386_WHPX_INTERNAL_H 39102c968SPaolo Bonzini 49102c968SPaolo Bonzini #include <windows.h> 5*641b8417SPhilippe Mathieu-Daudé #include <winhvplatform.h> 6*641b8417SPhilippe Mathieu-Daudé #include <winhvemulation.h> 79102c968SPaolo Bonzini 8d7482ffeSIvan Shcherbakov typedef enum WhpxBreakpointState { 9d7482ffeSIvan Shcherbakov WHPX_BP_CLEARED = 0, 10d7482ffeSIvan Shcherbakov WHPX_BP_SET_PENDING, 11d7482ffeSIvan Shcherbakov WHPX_BP_SET, 12d7482ffeSIvan Shcherbakov WHPX_BP_CLEAR_PENDING, 13d7482ffeSIvan Shcherbakov } WhpxBreakpointState; 14d7482ffeSIvan Shcherbakov 15d7482ffeSIvan Shcherbakov struct whpx_breakpoint { 16d7482ffeSIvan Shcherbakov vaddr address; 17d7482ffeSIvan Shcherbakov WhpxBreakpointState state; 18d7482ffeSIvan Shcherbakov uint8_t original_instruction; 19d7482ffeSIvan Shcherbakov }; 20d7482ffeSIvan Shcherbakov 21d7482ffeSIvan Shcherbakov struct whpx_breakpoint_collection { 22d7482ffeSIvan Shcherbakov int allocated, used; 23d7482ffeSIvan Shcherbakov struct whpx_breakpoint data[0]; 24d7482ffeSIvan Shcherbakov }; 25d7482ffeSIvan Shcherbakov 26d7482ffeSIvan Shcherbakov struct whpx_breakpoints { 27d7482ffeSIvan Shcherbakov int original_address_count; 28d7482ffeSIvan Shcherbakov vaddr *original_addresses; 29d7482ffeSIvan Shcherbakov 30d7482ffeSIvan Shcherbakov struct whpx_breakpoint_collection *breakpoints; 31d7482ffeSIvan Shcherbakov }; 32d7482ffeSIvan Shcherbakov 3384f4ef17SPaolo Bonzini struct whpx_state { 3484f4ef17SPaolo Bonzini uint64_t mem_quota; 3584f4ef17SPaolo Bonzini WHV_PARTITION_HANDLE partition; 36d7482ffeSIvan Shcherbakov uint64_t exception_exit_bitmap; 37d7482ffeSIvan Shcherbakov int32_t running_cpus; 38d7482ffeSIvan Shcherbakov struct whpx_breakpoints breakpoints; 39d7482ffeSIvan Shcherbakov bool step_pending; 40d7482ffeSIvan Shcherbakov 4184f4ef17SPaolo Bonzini bool kernel_irqchip_allowed; 4284f4ef17SPaolo Bonzini bool kernel_irqchip_required; 4384f4ef17SPaolo Bonzini bool apic_in_platform; 4484f4ef17SPaolo Bonzini }; 4584f4ef17SPaolo Bonzini 4684f4ef17SPaolo Bonzini extern struct whpx_state whpx_global; 4784f4ef17SPaolo Bonzini void whpx_apic_get(DeviceState *s); 4884f4ef17SPaolo Bonzini 499102c968SPaolo Bonzini #define WHV_E_UNKNOWN_CAPABILITY 0x80370300L 509102c968SPaolo Bonzini 51b6b3da99SSunil Muthuswamy /* This should eventually come from the Windows SDK */ 52b6b3da99SSunil Muthuswamy #define WHV_E_UNKNOWN_PROPERTY 0x80370302 53b6b3da99SSunil Muthuswamy 549102c968SPaolo Bonzini #define LIST_WINHVPLATFORM_FUNCTIONS(X) \ 559102c968SPaolo Bonzini X(HRESULT, WHvGetCapability, (WHV_CAPABILITY_CODE CapabilityCode, VOID* CapabilityBuffer, UINT32 CapabilityBufferSizeInBytes, UINT32* WrittenSizeInBytes)) \ 569102c968SPaolo Bonzini X(HRESULT, WHvCreatePartition, (WHV_PARTITION_HANDLE* Partition)) \ 579102c968SPaolo Bonzini X(HRESULT, WHvSetupPartition, (WHV_PARTITION_HANDLE Partition)) \ 589102c968SPaolo Bonzini X(HRESULT, WHvDeletePartition, (WHV_PARTITION_HANDLE Partition)) \ 599102c968SPaolo Bonzini X(HRESULT, WHvGetPartitionProperty, (WHV_PARTITION_HANDLE Partition, WHV_PARTITION_PROPERTY_CODE PropertyCode, VOID* PropertyBuffer, UINT32 PropertyBufferSizeInBytes, UINT32* WrittenSizeInBytes)) \ 609102c968SPaolo Bonzini X(HRESULT, WHvSetPartitionProperty, (WHV_PARTITION_HANDLE Partition, WHV_PARTITION_PROPERTY_CODE PropertyCode, const VOID* PropertyBuffer, UINT32 PropertyBufferSizeInBytes)) \ 619102c968SPaolo Bonzini X(HRESULT, WHvMapGpaRange, (WHV_PARTITION_HANDLE Partition, VOID* SourceAddress, WHV_GUEST_PHYSICAL_ADDRESS GuestAddress, UINT64 SizeInBytes, WHV_MAP_GPA_RANGE_FLAGS Flags)) \ 629102c968SPaolo Bonzini X(HRESULT, WHvUnmapGpaRange, (WHV_PARTITION_HANDLE Partition, WHV_GUEST_PHYSICAL_ADDRESS GuestAddress, UINT64 SizeInBytes)) \ 639102c968SPaolo 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)) \ 649102c968SPaolo Bonzini X(HRESULT, WHvCreateVirtualProcessor, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, UINT32 Flags)) \ 659102c968SPaolo Bonzini X(HRESULT, WHvDeleteVirtualProcessor, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex)) \ 669102c968SPaolo Bonzini X(HRESULT, WHvRunVirtualProcessor, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, VOID* ExitContext, UINT32 ExitContextSizeInBytes)) \ 679102c968SPaolo Bonzini X(HRESULT, WHvCancelRunVirtualProcessor, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, UINT32 Flags)) \ 689102c968SPaolo Bonzini X(HRESULT, WHvGetVirtualProcessorRegisters, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, const WHV_REGISTER_NAME* RegisterNames, UINT32 RegisterCount, WHV_REGISTER_VALUE* RegisterValues)) \ 699102c968SPaolo Bonzini X(HRESULT, WHvSetVirtualProcessorRegisters, (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, const WHV_REGISTER_NAME* RegisterNames, UINT32 RegisterCount, const WHV_REGISTER_VALUE* RegisterValues)) \ 709102c968SPaolo Bonzini 719102c968SPaolo Bonzini /* 729102c968SPaolo Bonzini * These are supplemental functions that may not be present 739102c968SPaolo Bonzini * on all versions and are not critical for basic functionality. 749102c968SPaolo Bonzini */ 759102c968SPaolo Bonzini #define LIST_WINHVPLATFORM_FUNCTIONS_SUPPLEMENTAL(X) \ 769102c968SPaolo Bonzini X(HRESULT, WHvSuspendPartitionTime, (WHV_PARTITION_HANDLE Partition)) \ 779102c968SPaolo Bonzini X(HRESULT, WHvRequestInterrupt, (WHV_PARTITION_HANDLE Partition, \ 789102c968SPaolo Bonzini WHV_INTERRUPT_CONTROL* Interrupt, UINT32 InterruptControlSize)) \ 799102c968SPaolo Bonzini X(HRESULT, WHvGetVirtualProcessorInterruptControllerState2, \ 809102c968SPaolo Bonzini (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, PVOID State, \ 819102c968SPaolo Bonzini UINT32 StateSize, UINT32* WrittenSize)) \ 829102c968SPaolo Bonzini X(HRESULT, WHvSetVirtualProcessorInterruptControllerState2, \ 839102c968SPaolo Bonzini (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, PVOID State, \ 849102c968SPaolo Bonzini UINT32 StateSize)) \ 859102c968SPaolo Bonzini 869102c968SPaolo Bonzini #define LIST_WINHVEMULATION_FUNCTIONS(X) \ 879102c968SPaolo Bonzini X(HRESULT, WHvEmulatorCreateEmulator, (const WHV_EMULATOR_CALLBACKS* Callbacks, WHV_EMULATOR_HANDLE* Emulator)) \ 889102c968SPaolo Bonzini X(HRESULT, WHvEmulatorDestroyEmulator, (WHV_EMULATOR_HANDLE Emulator)) \ 899102c968SPaolo 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)) \ 909102c968SPaolo 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)) \ 919102c968SPaolo Bonzini 929102c968SPaolo Bonzini #define WHP_DEFINE_TYPE(return_type, function_name, signature) \ 939102c968SPaolo Bonzini typedef return_type (WINAPI *function_name ## _t) signature; 949102c968SPaolo Bonzini 959102c968SPaolo Bonzini #define WHP_DECLARE_MEMBER(return_type, function_name, signature) \ 969102c968SPaolo Bonzini function_name ## _t function_name; 979102c968SPaolo Bonzini 989102c968SPaolo Bonzini /* Define function typedef */ 999102c968SPaolo Bonzini LIST_WINHVPLATFORM_FUNCTIONS(WHP_DEFINE_TYPE) 1009102c968SPaolo Bonzini LIST_WINHVEMULATION_FUNCTIONS(WHP_DEFINE_TYPE) 1019102c968SPaolo Bonzini LIST_WINHVPLATFORM_FUNCTIONS_SUPPLEMENTAL(WHP_DEFINE_TYPE) 1029102c968SPaolo Bonzini 1039102c968SPaolo Bonzini struct WHPDispatch { 1049102c968SPaolo Bonzini LIST_WINHVPLATFORM_FUNCTIONS(WHP_DECLARE_MEMBER) 1059102c968SPaolo Bonzini LIST_WINHVEMULATION_FUNCTIONS(WHP_DECLARE_MEMBER) 1069102c968SPaolo Bonzini LIST_WINHVPLATFORM_FUNCTIONS_SUPPLEMENTAL(WHP_DECLARE_MEMBER) 1079102c968SPaolo Bonzini }; 1089102c968SPaolo Bonzini 1099102c968SPaolo Bonzini extern struct WHPDispatch whp_dispatch; 1109102c968SPaolo Bonzini 1119102c968SPaolo Bonzini bool init_whp_dispatch(void); 1129102c968SPaolo Bonzini 1139102c968SPaolo Bonzini typedef enum WHPFunctionList { 1149102c968SPaolo Bonzini WINHV_PLATFORM_FNS_DEFAULT, 1159102c968SPaolo Bonzini WINHV_EMULATION_FNS_DEFAULT, 1169102c968SPaolo Bonzini WINHV_PLATFORM_FNS_SUPPLEMENTAL 1179102c968SPaolo Bonzini } WHPFunctionList; 1189102c968SPaolo Bonzini 11952581c71SMarkus Armbruster #endif /* TARGET_I386_WHPX_INTERNAL_H */ 120