hyperv: Implement additional driver functions

* Switch instance ID from string to raw attribute
* Implement device allocate/free GPADL functions
* Add definitions and functions for additional VMBus packet types

Change-Id: I01e9a30f567358fad520df95b1c14b7ea9671915
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10402
Reviewed-by: Jérôme Duval <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
John Davis
2026-03-05 18:14:42 +00:00
committed by Jérôme Duval
parent a3fe30c940
commit 4d75e43574
8 changed files with 184 additions and 44 deletions
+9 -3
View File
@@ -15,7 +15,7 @@
// Device attributes for the VMBus device
#define HYPERV_CHANNEL_ID_ITEM "hyperv/channel"
#define HYPERV_DEVICE_TYPE_ITEM "hyperv/type"
#define HYPERV_DEVICE_TYPE_ITEM "hyperv/type_string"
#define HYPERV_INSTANCE_ID_ITEM "hyperv/instance"
#define HYPERV_PRETTYNAME_VMBUS "Hyper-V Virtual Machine Bus"
@@ -53,10 +53,16 @@ typedef struct hyperv_device_interface {
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);
status_t (*write_packet)(hyperv_device cookie, uint16 type, const void* buffer,
uint32 length, bool responseRequired, uint64 transactionID);
status_t (*write_gpa_packet)(hyperv_device cookie, uint32 rangeCount,
const vmbus_gpa_range* rangesList, uint32 rangesLength, const void* buffer,
uint32 length, bool responseRequired, uint64 transactionID);
status_t (*allocate_gpadl)(hyperv_device cookie, uint32 length, void** _buffer,
uint32* _gpadl);
status_t (*free_gpadl)(hyperv_device cookie, uint32 gpadl);
} hyperv_device_interface;
+57 -6
View File
@@ -9,11 +9,14 @@
#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_PAGE_SIZE 4096
#define HV_PAGE_MASK (HV_PAGE_SIZE - 1)
#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_BYTES_TO_SPAN_PAGES(a, l) ((((l) - 1) >> HV_PAGE_SHIFT) \
+ (((((l) - 1) & HV_PAGE_MASK) + ((a) & HV_PAGE_MASK)) >> HV_PAGE_SHIFT) + 1);
#define HV_MS_TO_US(x) ((x) * 1000ULL)
#define HV_STATIC_ASSERT(cond, msg) static_assert(cond, msg)
@@ -56,6 +59,14 @@
#define VMBUS_TYPE_VSS "35fa2e29-ea23-4236-96ae-3a6ebacba440"
typedef struct {
uint32 data1;
uint16 data2;
uint16 data3;
uint8 data4[8];
} _PACKED vmbus_guid_t;
// VMBus packet types
enum {
VMBUS_PKTTYPE_INVALID = 0,
@@ -89,7 +100,47 @@ typedef struct {
uint16 total_length;
uint16 flags;
uint64 transaction_id;
} vmbus_pkt_header;
} _PACKED vmbus_pkt_header;
// VMBus transfer range
// Describes a buffer within an existing defined buffer
typedef struct {
uint32 length;
uint32 offset;
} _PACKED vmbus_transfer_range;
// VMBus transfer ranges packet header
typedef struct {
vmbus_pkt_header header;
uint16 transfer_pageset_id;
uint8 sender_owns_sets;
uint8 reserved;
uint32 range_count;
vmbus_transfer_range ranges[];
} _PACKED vmbus_pkt_transfer_header;
// VMBus GPA (Guest Physical Address) range
// Describes a buffer made up of one or more physical pages in the guest
typedef struct {
uint32 length;
uint32 offset;
uint64 page_nums[];
} _PACKED vmbus_gpa_range;
// VMBus GPA packet header
typedef struct {
vmbus_pkt_header header;
uint32 reserved;
uint32 range_count;
vmbus_gpa_range ranges[];
} _PACKED vmbus_pkt_gpa_header;
#endif // _HYPERV_SPEC_H_