virtio: support modern devices

fixes #17239 #17238

Change-Id: Ia5b6347110a60fab18852079b30dca6301010474
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6995
Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
Jérôme Duval
2023-10-15 13:02:41 +00:00
parent 518e9cb9f2
commit 6d42b430d1
19 changed files with 507 additions and 139 deletions
+13 -7
View File
@@ -26,13 +26,14 @@
#define VIRTIO_DEVICE_ID_VSOCK 19
#define VIRTIO_DEVICE_ID_CRYPTO 20
#define VIRTIO_FEATURE_TRANSPORT_MASK ((1 << 28) - 1)
#define VIRTIO_FEATURE_TRANSPORT_MASK ((1ULL << 28) - 1)
#define VIRTIO_FEATURE_NOTIFY_ON_EMPTY (1 << 24)
#define VIRTIO_FEATURE_ANY_LAYOUT (1 << 27)
#define VIRTIO_FEATURE_RING_INDIRECT_DESC (1 << 28)
#define VIRTIO_FEATURE_RING_EVENT_IDX (1 << 29)
#define VIRTIO_FEATURE_BAD_FEATURE (1 << 30)
#define VIRTIO_FEATURE_VERSION_1 (1ULL << 32)
#define VIRTIO_VIRTQUEUES_MAX_COUNT 8
@@ -40,6 +41,8 @@
#define VIRTIO_CONFIG_STATUS_ACK 0x01
#define VIRTIO_CONFIG_STATUS_DRIVER 0x02
#define VIRTIO_CONFIG_STATUS_DRIVER_OK 0x04
#define VIRTIO_CONFIG_STATUS_FEATURES_OK 0x08
#define VIRTIO_CONFIG_STATUS_DEVICE_NEEDS_RESET 0x40
#define VIRTIO_CONFIG_STATUS_FAILED 0x80
// attributes:
@@ -50,6 +53,8 @@
#define VIRTIO_DEVICE_TYPE_ITEM "virtio/type"
// alignment (uint16)
#define VIRTIO_VRING_ALIGNMENT_ITEM "virtio/vring_alignment"
// version (uint8)
#define VIRTIO_VERSION_ITEM "virtio/version"
// sim cookie, issued by virtio bus manager
typedef void* virtio_sim;
@@ -78,8 +83,8 @@ typedef struct {
driver_module_info info;
void (*set_sim)(void* cookie, virtio_sim sim);
status_t (*read_host_features)(void* cookie, uint32* features);
status_t (*write_guest_features)(void* cookie, uint32 features);
status_t (*read_host_features)(void* cookie, uint64* features);
status_t (*write_guest_features)(void* cookie, uint64 features);
uint8 (*get_status)(void* cookie);
void (*set_status)(void* cookie, uint8 status);
status_t (*read_device_config)(void* cookie, uint8 offset, void* buffer,
@@ -88,7 +93,8 @@ typedef struct {
const void* buffer, size_t bufferSize);
uint16 (*get_queue_ring_size)(void* cookie, uint16 queue);
status_t (*setup_queue)(void* cookie, uint16 queue, phys_addr_t phy);
status_t (*setup_queue)(void* cookie, uint16 queue, phys_addr_t phy, phys_addr_t phyAvail,
phys_addr_t phyUsed);
status_t (*setup_interrupt)(void* cookie, uint16 queueCount);
status_t (*free_interrupt)(void* cookie);
void (*notify_queue)(void* cookie, uint16 queue);
@@ -99,10 +105,10 @@ typedef struct {
typedef struct {
driver_module_info info;
status_t (*negotiate_features)(virtio_device cookie, uint32 supported,
uint32* negotiated, const char* (*get_feature_name)(uint32));
status_t (*negotiate_features)(virtio_device cookie, uint64 supported,
uint64* negotiated, const char* (*get_feature_name)(uint64));
status_t (*clear_feature)(virtio_device cookie, uint32 feature);
status_t (*clear_feature)(virtio_device cookie, uint64 feature);
status_t (*read_device_config)(virtio_device cookie, uint8 offset,
void* buffer, size_t bufferSize);