Implement initial Hyper-V support on x86 platforms
Haiku currently does not have any form of Hyper-V guest support, and this change begins work toward #16664. This change implements initial VMBus bus/device structure and functions. Change-Id: I2d081f55e99da479d9bc5084f1815ade6cc77fe2 Reviewed-on: https://review.haiku-os.org/c/haiku/+/10333 Tested-by: Commit checker robot <[email protected]> Reviewed-by: Jérôme Duval <[email protected]> Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2026 John Davis. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _HYPERV_H_
|
||||
#define _HYPERV_H_
|
||||
|
||||
|
||||
#include <device_manager.h>
|
||||
#include <KernelExport.h>
|
||||
|
||||
#include <hyperv_spec.h>
|
||||
|
||||
#define HYPERV_BUS_NAME "hyperv"
|
||||
|
||||
// Device attributes for the VMBus device
|
||||
#define HYPERV_CHANNEL_ID_ITEM "hyperv/channel"
|
||||
#define HYPERV_DEVICE_TYPE_ITEM "hyperv/type"
|
||||
#define HYPERV_INSTANCE_ID_ITEM "hyperv/instance"
|
||||
|
||||
#define HYPERV_PRETTYNAME_VMBUS "Hyper-V Virtual Machine Bus"
|
||||
#define HYPERV_PRETTYNAME_VMBUS_DEVICE_FMT "Hyper-V Channel %u"
|
||||
#define HYPERV_PRETTYNAME_AVMA "Hyper-V Automatic Virtual Machine Activation"
|
||||
#define HYPERV_PRETTYNAME_BALLOON "Hyper-V Dynamic Memory"
|
||||
#define HYPERV_PRETTYNAME_DISPLAY "Hyper-V Display"
|
||||
#define HYPERV_PRETTYNAME_FIBRECHANNEL "Hyper-V Fibre Channel"
|
||||
#define HYPERV_PRETTYNAME_FILECOPY "Hyper-V File Copy"
|
||||
#define HYPERV_PRETTYNAME_HEARTBEAT "Hyper-V Heartbeat"
|
||||
#define HYPERV_PRETTYNAME_IDE "Hyper-V IDE Accelerator"
|
||||
#define HYPERV_PRETTYNAME_INPUT "Hyper-V Input"
|
||||
#define HYPERV_PRETTYNAME_KEYBOARD "Hyper-V Keyboard"
|
||||
#define HYPERV_PRETTYNAME_KVP "Hyper-V Data Exchange"
|
||||
#define HYPERV_PRETTYNAME_NETWORK "Hyper-V Network Adapter"
|
||||
#define HYPERV_PRETTYNAME_PCI "Hyper-V PCI Bridge"
|
||||
#define HYPERV_PRETTYNAME_RDCONTROL "Hyper-V Remote Desktop Control"
|
||||
#define HYPERV_PRETTYNAME_RDMA "Hyper-V RDMA"
|
||||
#define HYPERV_PRETTYNAME_RDVIRT "Hyper-V Remote Desktop Virtualization"
|
||||
#define HYPERV_PRETTYNAME_SCSI "Hyper-V SCSI Adapter"
|
||||
#define HYPERV_PRETTYNAME_SHUTDOWN "Hyper-V Guest Shutdown"
|
||||
#define HYPERV_PRETTYNAME_TIMESYNC "Hyper-V Time Synchronization"
|
||||
#define HYPERV_PRETTYNAME_VSS "Hyper-V Volume Shadow Copy"
|
||||
|
||||
|
||||
typedef void* hyperv_device;
|
||||
typedef void (*hyperv_device_callback)(void* data);
|
||||
|
||||
|
||||
// Interface between the VMBus device driver, and the VMBus device bus manager
|
||||
typedef struct hyperv_device_interface {
|
||||
driver_module_info info;
|
||||
|
||||
uint32 (*get_bus_version)(hyperv_device cookie);
|
||||
status_t (*open)(hyperv_device cookie, uint32 txLength, uint32 rxLength,
|
||||
hyperv_device_callback callback, void* callbackData);
|
||||
void (*close)(hyperv_device cookie);
|
||||
status_t (*write_packet)(hyperv_device cookie, uint16 type, void* buffer,
|
||||
uint32 length, bool responseRequired, uint64 transactionID);
|
||||
status_t (*read_packet)(hyperv_device cookie, vmbus_pkt_header* _header,
|
||||
uint32* _headerLength, void* _buffer, uint32* _length);
|
||||
} hyperv_device_interface;
|
||||
|
||||
|
||||
#endif // _HYPERV_H_
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright 2026 John Davis. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _HYPERV_SPEC_H_
|
||||
#define _HYPERV_SPEC_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
#define HV_PAGE_SIZE 4096
|
||||
#define HV_PAGE_SHIFT 12
|
||||
#define HV_PAGE_ALIGN(x) (((x) + (HV_PAGE_SIZE - 1)) & ~(HV_PAGE_SIZE - 1))
|
||||
#define HV_BYTES_TO_PAGES(x) (HV_PAGE_ALIGN(x) >> HV_PAGE_SHIFT)
|
||||
#define HV_MS_TO_US(x) ((x) * 1000ULL)
|
||||
|
||||
#define HV_STATIC_ASSERT(cond, msg) static_assert(cond, msg)
|
||||
|
||||
|
||||
#define MAKE_VMBUS_VERSION(maj, min) ((((maj) << 16) & 0xFFFF0000) | ((min) & 0x0000FFFF))
|
||||
#define GET_VMBUS_VERSION_MAJOR(ver) (((ver) >> 16) & 0xFFFF)
|
||||
#define GET_VMBUS_VERSION_MINOR(ver) ((ver) & 0xFFFF)
|
||||
|
||||
#define VMBUS_VERSION_WS2008 MAKE_VMBUS_VERSION(0, 13)
|
||||
#define VMBUS_VERSION_WS2008R2 MAKE_VMBUS_VERSION(1, 1)
|
||||
#define VMBUS_VERSION_WIN8_WS2012 MAKE_VMBUS_VERSION(2, 4)
|
||||
#define VMBUS_VERSION_WIN81_WS2012R2 MAKE_VMBUS_VERSION(3, 0)
|
||||
#define VMBUS_VERSION_WIN10_RS1_WS2016 MAKE_VMBUS_VERSION(4, 0)
|
||||
#define VMBUS_VERSION_WIN10_RS3 MAKE_VMBUS_VERSION(4, 1)
|
||||
#define VMBUS_VERSION_WIN10_V5 MAKE_VMBUS_VERSION(5, 0)
|
||||
#define VMBUS_VERSION_WIN10_RS4 MAKE_VMBUS_VERSION(5, 1)
|
||||
#define VMBUS_VERSION_WIN10_RS5_WS2019 MAKE_VMBUS_VERSION(5, 2)
|
||||
#define VMBUS_VERSION_WS2022 MAKE_VMBUS_VERSION(5, 3)
|
||||
|
||||
|
||||
// VMBus device types
|
||||
#define VMBUS_TYPE_AVMA "3375baf4-9e15-4b30-b765-67acb10d607b"
|
||||
#define VMBUS_TYPE_BALLOON "525074dc-8985-46e2-8057-a307dc18a502"
|
||||
#define VMBUS_TYPE_DISPLAY "da0a7802-e377-4aac-8e77-0558eb1073f8"
|
||||
#define VMBUS_TYPE_FIBRECHANNEL "2f9bcc4a-0069-4af3-b76b-6fd0be528cda"
|
||||
#define VMBUS_TYPE_FILECOPY "34d14be3-dee4-41c8-9ae7-6b174977c192"
|
||||
#define VMBUS_TYPE_HEARTBEAT "57164f39-9115-4e78-ab55-382f3bd5422d"
|
||||
#define VMBUS_TYPE_IDE "32412632-86cb-44a2-9b5c-50d1417354f5"
|
||||
#define VMBUS_TYPE_INPUT "cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a"
|
||||
#define VMBUS_TYPE_KEYBOARD "f912ad6d-2b17-48ea-bd65-f927a61c7684"
|
||||
#define VMBUS_TYPE_KVP "a9a0f4e7-5a45-4d96-b827-8a841e8c03e6"
|
||||
#define VMBUS_TYPE_NETWORK "f8615163-df3e-46c5-913f-f2d2f965ed0e"
|
||||
#define VMBUS_TYPE_PCI "44c4f61d-4444-4400-9d52-802e27ede19f"
|
||||
#define VMBUS_TYPE_RDCONTROL "f8e65716-3cb3-4a06-9a60-1889c5cccab5"
|
||||
#define VMBUS_TYPE_RDMA "8c2eaf3d-32a7-4b09-ab99-bd1f1c86b501"
|
||||
#define VMBUS_TYPE_RDVIRT "276aacf4-ac15-426c-98dd-7521ad3f01fe"
|
||||
#define VMBUS_TYPE_SCSI "ba6163d9-04a1-4d29-b605-72e2ffb1dc7f"
|
||||
#define VMBUS_TYPE_SHUTDOWN "0e0b6031-5213-4934-818b-38d90ced39db"
|
||||
#define VMBUS_TYPE_TIMESYNC "9527e630-d0ae-497b-adce-e80ab0175caf"
|
||||
#define VMBUS_TYPE_VSS "35fa2e29-ea23-4236-96ae-3a6ebacba440"
|
||||
|
||||
|
||||
// VMBus packet types
|
||||
enum {
|
||||
VMBUS_PKTTYPE_INVALID = 0,
|
||||
VMBUS_PKTTYPE_SYNCH = 1,
|
||||
VMBUS_PKTTYPE_ADD_TRANSFER_PAGESET = 2,
|
||||
VMBUS_PKTTYPE_REMOVE_TRANSFER_PAGESET = 3,
|
||||
VMBUS_PKTTYPE_CREATE_GPADL = 4,
|
||||
VMBUS_PKTTYPE_FREE_GPADL = 5,
|
||||
VMBUS_PKTTYPE_DATA_INBAND = 6,
|
||||
VMBUS_PKTTYPE_DATA_USING_TRANSFER_PAGES = 7,
|
||||
VMBUS_PKTTYPE_DATA_USING_GPADL = 8,
|
||||
VMBUS_PKTTYPE_DATA_USING_GPA_DIRECT = 9,
|
||||
VMBUS_PKTTYPE_CANCEL_REQUEST = 10,
|
||||
VMBUS_PKTTYPE_COMPLETION = 11,
|
||||
VMBUS_PKTTYPE_DATA_USING_ADDT_PKT = 12,
|
||||
VMBUS_PKTTYPE_ADDT_DATA = 13,
|
||||
VMBUS_PKTTYPE_MAX
|
||||
};
|
||||
|
||||
|
||||
#define VMBUS_PKT_FLAGS_RESPONSE_REQUIRED (1 << 0)
|
||||
|
||||
#define VMBUS_PKT_SIZE_SHIFT 3
|
||||
#define VMBUS_PKT_ALIGN(x) (((x) + (sizeof(uint64) - 1)) &~ (sizeof(uint64) - 1))
|
||||
|
||||
|
||||
// VMBus packet header
|
||||
typedef struct {
|
||||
uint16 type;
|
||||
uint16 header_length;
|
||||
uint16 total_length;
|
||||
uint16 flags;
|
||||
uint64 transaction_id;
|
||||
} vmbus_pkt_header;
|
||||
|
||||
|
||||
#endif // _HYPERV_SPEC_H_
|
||||
Reference in New Issue
Block a user