From 6213c65bc462db243d5f08c4150cd428dafd6ccb Mon Sep 17 00:00:00 2001 From: Vitalii Chulak Date: Mon, 18 Nov 2024 12:39:34 +0200 Subject: [PATCH] VirtIO apply clang-format Signed-off-by: Vitalii Chulak --- VirtIO/VirtIO.h | 48 +++----- VirtIO/VirtIOPCICommon.c | 71 ++++------- VirtIO/VirtIOPCILegacy.c | 44 +++---- VirtIO/VirtIOPCIModern.c | 155 ++++++++++-------------- VirtIO/VirtIORing-Packed.c | 147 +++++++++++----------- VirtIO/VirtIORing.c | 105 +++++++--------- VirtIO/WDF/Callbacks.c | 20 +-- VirtIO/WDF/Dma.c | 96 ++++++--------- VirtIO/WDF/MemPortIO.c | 14 +-- VirtIO/WDF/PCI.c | 109 +++++++---------- VirtIO/WDF/VirtIOWdf.c | 73 ++++------- VirtIO/WDF/VirtIOWdf.h | 110 +++++++---------- VirtIO/WDF/private.h | 44 +++---- VirtIO/kdebugprint.h | 10 +- VirtIO/linux/types.h | 16 +-- VirtIO/linux/virtio_config.h | 31 +++-- VirtIO/osdep.h | 7 +- VirtIO/virtio_pci.h | 145 ++++++++++------------ VirtIO/virtio_pci_common.h | 26 ++-- VirtIO/virtio_ring.h | 6 +- VirtIO/windows/virtio_ring_allocation.h | 22 ++-- 21 files changed, 548 insertions(+), 751 deletions(-) mode change 100755 => 100644 VirtIO/VirtIOPCICommon.c diff --git a/VirtIO/VirtIO.h b/VirtIO/VirtIO.h index 030e918d7..6d2ccce96 100644 --- a/VirtIO/VirtIO.h +++ b/VirtIO/VirtIO.h @@ -10,43 +10,38 @@ struct VirtIOBufferDescriptor { ULONG length; }; -typedef int (*proc_virtqueue_add_buf)( - struct virtqueue *vq, - struct scatterlist sg[], - unsigned int out_num, - unsigned int in_num, - void *opaque, - void *va_indirect, - ULONGLONG phys_indirect); +typedef int (*proc_virtqueue_add_buf)(struct virtqueue *vq, struct scatterlist sg[], + unsigned int out_num, unsigned int in_num, void *opaque, + void *va_indirect, ULONGLONG phys_indirect); -typedef bool(*proc_virtqueue_kick_prepare)(struct virtqueue *vq); +typedef bool (*proc_virtqueue_kick_prepare)(struct virtqueue *vq); -typedef void(*proc_virtqueue_kick_always)(struct virtqueue *vq); +typedef void (*proc_virtqueue_kick_always)(struct virtqueue *vq); -typedef void * (*proc_virtqueue_get_buf)(struct virtqueue *vq, unsigned int *len); +typedef void *(*proc_virtqueue_get_buf)(struct virtqueue *vq, unsigned int *len); -typedef void(*proc_virtqueue_disable_cb)(struct virtqueue *vq); +typedef void (*proc_virtqueue_disable_cb)(struct virtqueue *vq); -typedef bool(*proc_virtqueue_enable_cb)(struct virtqueue *vq); +typedef bool (*proc_virtqueue_enable_cb)(struct virtqueue *vq); -typedef bool(*proc_virtqueue_enable_cb_delayed)(struct virtqueue *vq); +typedef bool (*proc_virtqueue_enable_cb_delayed)(struct virtqueue *vq); -typedef void * (*proc_virtqueue_detach_unused_buf)(struct virtqueue *vq); +typedef void *(*proc_virtqueue_detach_unused_buf)(struct virtqueue *vq); -typedef BOOLEAN(*proc_virtqueue_is_interrupt_enabled)(struct virtqueue *vq); +typedef BOOLEAN (*proc_virtqueue_is_interrupt_enabled)(struct virtqueue *vq); -typedef BOOLEAN(*proc_virtqueue_has_buf)(struct virtqueue *vq); +typedef BOOLEAN (*proc_virtqueue_has_buf)(struct virtqueue *vq); -typedef void(*proc_virtqueue_shutdown)(struct virtqueue *vq); +typedef void (*proc_virtqueue_shutdown)(struct virtqueue *vq); /* Represents one virtqueue; only data pointed to by the vring structure is exposed to the host */ struct virtqueue { VirtIODevice *vdev; unsigned int index; void (*notification_cb)(struct virtqueue *vq); - void *notification_addr; - void *avail_va; - void *used_va; + void *notification_addr; + void *avail_va; + void *used_va; proc_virtqueue_add_buf add_buf; proc_virtqueue_kick_prepare kick_prepare; proc_virtqueue_kick_always kick_always; @@ -60,14 +55,9 @@ struct virtqueue { proc_virtqueue_shutdown shutdown; }; -static inline int virtqueue_add_buf( - struct virtqueue *vq, - struct scatterlist sg[], - unsigned int out_num, - unsigned int in_num, - void *opaque, - void *va_indirect, - ULONGLONG phys_indirect) +static inline int virtqueue_add_buf(struct virtqueue *vq, struct scatterlist sg[], + unsigned int out_num, unsigned int in_num, void *opaque, + void *va_indirect, ULONGLONG phys_indirect) { return vq->add_buf(vq, sg, out_num, in_num, opaque, va_indirect, phys_indirect); } diff --git a/VirtIO/VirtIOPCICommon.c b/VirtIO/VirtIOPCICommon.c old mode 100755 new mode 100644 index 9648685b9..cb26872e8 --- a/VirtIO/VirtIOPCICommon.c +++ b/VirtIO/VirtIOPCICommon.c @@ -41,10 +41,8 @@ #include "virtio_pci_common.h" -NTSTATUS virtio_device_initialize(VirtIODevice *vdev, - const VirtIOSystemOps *pSystemOps, - PVOID DeviceContext, - bool msix_used) +NTSTATUS virtio_device_initialize(VirtIODevice *vdev, const VirtIOSystemOps *pSystemOps, + PVOID DeviceContext, bool msix_used) { NTSTATUS status; @@ -76,8 +74,7 @@ NTSTATUS virtio_device_initialize(VirtIODevice *vdev, void virtio_device_shutdown(VirtIODevice *vdev) { - if (vdev->info && - vdev->info != vdev->inline_info) { + if (vdev->info && vdev->info != vdev->inline_info) { mem_free_nonpaged_block(vdev, vdev->info); vdev->info = NULL; } @@ -143,29 +140,26 @@ NTSTATUS virtio_set_features(VirtIODevice *vdev, u64 features) } /* Read @count fields, @bytes each. */ -static void virtio_cread_many(VirtIODevice *vdev, - unsigned int offset, - void *buf, size_t count, size_t bytes) +static void virtio_cread_many(VirtIODevice *vdev, unsigned int offset, void *buf, size_t count, + size_t bytes) { - u32 old, gen = vdev->device->get_config_generation ? - vdev->device->get_config_generation(vdev) : 0; + u32 old, + gen = vdev->device->get_config_generation ? vdev->device->get_config_generation(vdev) : 0; size_t i; do { old = gen; for (i = 0; i < count; i++) { - vdev->device->get_config(vdev, (unsigned)(offset + bytes * i), - (char *)buf + i * bytes, (unsigned)bytes); + vdev->device->get_config(vdev, (unsigned)(offset + bytes * i), (char *)buf + i * bytes, + (unsigned)bytes); } - gen = vdev->device->get_config_generation ? - vdev->device->get_config_generation(vdev) : 0; + gen = vdev->device->get_config_generation ? vdev->device->get_config_generation(vdev) : 0; } while (gen != old); } -void virtio_get_config(VirtIODevice *vdev, unsigned offset, - void *buf, unsigned len) +void virtio_get_config(VirtIODevice *vdev, unsigned offset, void *buf, unsigned len) { switch (len) { case 1: @@ -183,19 +177,17 @@ void virtio_get_config(VirtIODevice *vdev, unsigned offset, } /* Write @count fields, @bytes each. */ -static void virtio_cwrite_many(VirtIODevice *vdev, - unsigned int offset, - void *buf, size_t count, size_t bytes) +static void virtio_cwrite_many(VirtIODevice *vdev, unsigned int offset, void *buf, size_t count, + size_t bytes) { size_t i; for (i = 0; i < count; i++) { - vdev->device->set_config(vdev, (unsigned)(offset + bytes * i), - (char *)buf + i * bytes, (unsigned)bytes); + vdev->device->set_config(vdev, (unsigned)(offset + bytes * i), (char *)buf + i * bytes, + (unsigned)bytes); } } -void virtio_set_config(VirtIODevice *vdev, unsigned offset, - void *buf, unsigned len) +void virtio_set_config(VirtIODevice *vdev, unsigned offset, void *buf, unsigned len) { switch (len) { case 1: @@ -212,10 +204,8 @@ void virtio_set_config(VirtIODevice *vdev, unsigned offset, } } -NTSTATUS virtio_query_queue_allocation(VirtIODevice *vdev, - unsigned index, - unsigned short *pNumEntries, - unsigned long *pRingSize, +NTSTATUS virtio_query_queue_allocation(VirtIODevice *vdev, unsigned index, + unsigned short *pNumEntries, unsigned long *pRingSize, unsigned long *pHeapSize) { return vdev->device->query_queue_alloc(vdev, index, pNumEntries, pRingSize, pHeapSize); @@ -239,8 +229,7 @@ NTSTATUS virtio_reserve_queue_memory(VirtIODevice *vdev, unsigned nvqs) return STATUS_SUCCESS; } -static NTSTATUS vp_setup_vq(struct virtqueue **queue, - VirtIODevice *vdev, unsigned index, +static NTSTATUS vp_setup_vq(struct virtqueue **queue, VirtIODevice *vdev, unsigned index, u16 msix_vec) { VirtIOQueueInfo *info = &vdev->info[index]; @@ -253,20 +242,13 @@ static NTSTATUS vp_setup_vq(struct virtqueue **queue, return status; } -NTSTATUS virtio_find_queue(VirtIODevice *vdev, unsigned index, - struct virtqueue **vq) +NTSTATUS virtio_find_queue(VirtIODevice *vdev, unsigned index, struct virtqueue **vq) { u16 msix_vec = vdev_get_msix_vector(vdev, index); - return vp_setup_vq( - vq, - vdev, - index, - msix_vec); + return vp_setup_vq(vq, vdev, index, msix_vec); } -NTSTATUS virtio_find_queues(VirtIODevice *vdev, - unsigned nvqs, - struct virtqueue *vqs[]) +NTSTATUS virtio_find_queues(VirtIODevice *vdev, unsigned nvqs, struct virtqueue *vqs[]) { unsigned i; NTSTATUS status; @@ -292,11 +274,7 @@ NTSTATUS virtio_find_queues(VirtIODevice *vdev, /* set up queue interrupts */ for (i = 0; i < nvqs; i++) { msix_vec = vdev_get_msix_vector(vdev, i); - status = vp_setup_vq( - &vqs[i], - vdev, - i, - msix_vec); + status = vp_setup_vq(&vqs[i], vdev, i, msix_vec); if (!NT_SUCCESS(status)) { goto error_find; } @@ -322,8 +300,9 @@ void virtio_delete_queues(VirtIODevice *vdev) struct virtqueue *vq; unsigned i; - if (vdev->info == NULL) + if (vdev->info == NULL) { return; + } for (i = 0; i < vdev->maxQueues; i++) { vq = vdev->info[i].vq; diff --git a/VirtIO/VirtIOPCILegacy.c b/VirtIO/VirtIOPCILegacy.c index f4ddb423a..22b75070d 100644 --- a/VirtIO/VirtIOPCILegacy.c +++ b/VirtIO/VirtIOPCILegacy.c @@ -51,20 +51,20 @@ void vio_legacy_dump_registers(VirtIODevice *vdev) { DPrintf(5, ("%s\n", __FUNCTION__)); - DPrintf(0, "[VIRTIO_PCI_HOST_FEATURES] = %x\n", ioread32(vdev, vdev->addr + VIRTIO_PCI_HOST_FEATURES)); - DPrintf(0, "[VIRTIO_PCI_GUEST_FEATURES] = %x\n", ioread32(vdev, vdev->addr + VIRTIO_PCI_GUEST_FEATURES)); + DPrintf(0, "[VIRTIO_PCI_HOST_FEATURES] = %x\n", + ioread32(vdev, vdev->addr + VIRTIO_PCI_HOST_FEATURES)); + DPrintf(0, "[VIRTIO_PCI_GUEST_FEATURES] = %x\n", + ioread32(vdev, vdev->addr + VIRTIO_PCI_GUEST_FEATURES)); DPrintf(0, "[VIRTIO_PCI_QUEUE_PFN] = %x\n", ioread32(vdev, vdev->addr + VIRTIO_PCI_QUEUE_PFN)); DPrintf(0, "[VIRTIO_PCI_QUEUE_NUM] = %x\n", ioread32(vdev, vdev->addr + VIRTIO_PCI_QUEUE_NUM)); DPrintf(0, "[VIRTIO_PCI_QUEUE_SEL] = %x\n", ioread32(vdev, vdev->addr + VIRTIO_PCI_QUEUE_SEL)); - DPrintf(0, "[VIRTIO_PCI_QUEUE_NOTIFY] = %x\n", ioread32(vdev, vdev->addr + VIRTIO_PCI_QUEUE_NOTIFY)); + DPrintf(0, "[VIRTIO_PCI_QUEUE_NOTIFY] = %x\n", + ioread32(vdev, vdev->addr + VIRTIO_PCI_QUEUE_NOTIFY)); DPrintf(0, "[VIRTIO_PCI_STATUS] = %x\n", ioread32(vdev, vdev->addr + VIRTIO_PCI_STATUS)); DPrintf(0, "[VIRTIO_PCI_ISR] = %x\n", ioread32(vdev, vdev->addr + VIRTIO_PCI_ISR)); } -static void vio_legacy_get_config(VirtIODevice * vdev, - unsigned offset, - void *buf, - unsigned len) +static void vio_legacy_get_config(VirtIODevice *vdev, unsigned offset, void *buf, unsigned len) { ULONG_PTR ioaddr = vdev->addr + VIRTIO_PCI_CONFIG(vdev->msix_used) + offset; u8 *ptr = buf; @@ -77,9 +77,7 @@ static void vio_legacy_get_config(VirtIODevice * vdev, } } -static void vio_legacy_set_config(VirtIODevice *vdev, - unsigned offset, - const void *buf, +static void vio_legacy_set_config(VirtIODevice *vdev, unsigned offset, const void *buf, unsigned len) { ULONG_PTR ioaddr = vdev->addr + VIRTIO_PCI_CONFIG(vdev->msix_used) + offset; @@ -146,10 +144,8 @@ static u16 vio_legacy_set_queue_vector(struct virtqueue *vq, u16 vector) return ioread16(vdev, vdev->addr + VIRTIO_MSI_QUEUE_VECTOR); } -static NTSTATUS vio_legacy_query_vq_alloc(VirtIODevice *vdev, - unsigned index, - unsigned short *pNumEntries, - unsigned long *pRingSize, +static NTSTATUS vio_legacy_query_vq_alloc(VirtIODevice *vdev, unsigned index, + unsigned short *pNumEntries, unsigned long *pRingSize, unsigned long *pHeapSize) { unsigned long ring_size, data_size; @@ -174,11 +170,8 @@ static NTSTATUS vio_legacy_query_vq_alloc(VirtIODevice *vdev, return STATUS_SUCCESS; } -static NTSTATUS vio_legacy_setup_vq(struct virtqueue **queue, - VirtIODevice *vdev, - VirtIOQueueInfo *info, - unsigned index, - u16 msix_vec) +static NTSTATUS vio_legacy_setup_vq(struct virtqueue **queue, VirtIODevice *vdev, + VirtIOQueueInfo *info, unsigned index, u16 msix_vec) { struct virtqueue *vq; unsigned long ring_size, heap_size; @@ -196,13 +189,13 @@ static NTSTATUS vio_legacy_setup_vq(struct virtqueue **queue, } /* activate the queue */ - iowrite32(vdev, (u32)(mem_get_physical_address(vdev, info->queue) >> VIRTIO_PCI_QUEUE_ADDR_SHIFT), - vdev->addr + VIRTIO_PCI_QUEUE_PFN); + iowrite32(vdev, + (u32)(mem_get_physical_address(vdev, info->queue) >> VIRTIO_PCI_QUEUE_ADDR_SHIFT), + vdev->addr + VIRTIO_PCI_QUEUE_PFN); /* create the vring */ - vq = vring_new_virtqueue_split(index, info->num, - VIRTIO_PCI_VRING_ALIGN, vdev, - info->queue, vp_notify, + vq = vring_new_virtqueue_split( + index, info->num, VIRTIO_PCI_VRING_ALIGN, vdev, info->queue, vp_notify, (u8 *)info->queue + ROUND_TO_PAGES(vring_size(info->num, VIRTIO_PCI_VRING_ALIGN, false))); if (!vq) { status = STATUS_INSUFFICIENT_RESOURCES; @@ -237,8 +230,7 @@ static void vio_legacy_del_vq(VirtIOQueueInfo *info) iowrite16(vdev, (u16)vq->index, vdev->addr + VIRTIO_PCI_QUEUE_SEL); if (vdev->msix_used) { - iowrite16(vdev, VIRTIO_MSI_NO_VECTOR, - vdev->addr + VIRTIO_MSI_QUEUE_VECTOR); + iowrite16(vdev, VIRTIO_MSI_NO_VECTOR, vdev->addr + VIRTIO_MSI_QUEUE_VECTOR); /* Flush the write out to device */ ioread8(vdev, vdev->addr + VIRTIO_PCI_ISR); } diff --git a/VirtIO/VirtIOPCIModern.c b/VirtIO/VirtIOPCIModern.c index 85ae75f39..307e96815 100644 --- a/VirtIO/VirtIOPCIModern.c +++ b/VirtIO/VirtIOPCIModern.c @@ -46,9 +46,8 @@ #include "VirtIOPCIModern.tmh" #endif -static void *vio_modern_map_capability(VirtIODevice *vdev, int cap_offset, - size_t minlen, u32 alignment, - u32 start, u32 size, size_t *len) +static void *vio_modern_map_capability(VirtIODevice *vdev, int cap_offset, size_t minlen, + u32 alignment, u32 start, u32 size, size_t *len) { u8 bar; u32 bar_offset, bar_length; @@ -59,7 +58,8 @@ static void *vio_modern_map_capability(VirtIODevice *vdev, int cap_offset, pci_read_config_dword(vdev, cap_offset + offsetof(struct virtio_pci_cap, length), &bar_length); if (start + minlen > bar_length) { - DPrintf(0, "bar %i cap is not large enough to map %zu bytes at offset %u\n", bar, minlen, start); + DPrintf(0, "bar %i cap is not large enough to map %zu bytes at offset %u\n", bar, minlen, + start); return NULL; } @@ -80,7 +80,8 @@ static void *vio_modern_map_capability(VirtIODevice *vdev, int cap_offset, } if (bar_offset + minlen > pci_get_resource_len(vdev, bar)) { - DPrintf(0, "bar %i is not large enough to map %zu bytes at offset %u\n", bar, minlen, bar_offset); + DPrintf(0, "bar %i is not large enough to map %zu bytes at offset %u\n", bar, minlen, + bar_offset); return NULL; } @@ -91,20 +92,18 @@ static void *vio_modern_map_capability(VirtIODevice *vdev, int cap_offset, return addr; } -static void *vio_modern_map_simple_capability(VirtIODevice *vdev, int cap_offset, size_t length, u32 alignment) +static void *vio_modern_map_simple_capability(VirtIODevice *vdev, int cap_offset, size_t length, + u32 alignment) { - return vio_modern_map_capability( - vdev, - cap_offset, - length, // minlen - alignment, - 0, // offset - (u32)length, // size is equal to minlen - NULL); // not interested in the full length + return vio_modern_map_capability(vdev, cap_offset, + length, // minlen + alignment, + 0, // offset + (u32)length, // size is equal to minlen + NULL); // not interested in the full length } -static void vio_modern_get_config(VirtIODevice *vdev, unsigned offset, - void *buf, unsigned len) +static void vio_modern_get_config(VirtIODevice *vdev, unsigned offset, void *buf, unsigned len) { if (!vdev->config) { ASSERT(!"Device has no config to read"); @@ -130,8 +129,8 @@ static void vio_modern_get_config(VirtIODevice *vdev, unsigned offset, } } -static void vio_modern_set_config(VirtIODevice *vdev, unsigned offset, - const void *buf, unsigned len) +static void vio_modern_set_config(VirtIODevice *vdev, unsigned offset, const void *buf, + unsigned len) { if (!vdev->config) { ASSERT(!"Device has no config to write"); @@ -248,10 +247,8 @@ static size_t vring_pci_size(u16 num, bool packed) return (size_t)ROUND_TO_PAGES(vring_size(num, SMP_CACHE_BYTES, packed)); } -static NTSTATUS vio_modern_query_vq_alloc(VirtIODevice *vdev, - unsigned index, - unsigned short *pNumEntries, - unsigned long *pRingSize, +static NTSTATUS vio_modern_query_vq_alloc(VirtIODevice *vdev, unsigned index, + unsigned short *pNumEntries, unsigned long *pRingSize, unsigned long *pHeapSize) { volatile struct virtio_pci_common_cfg *cfg = vdev->common; @@ -285,11 +282,8 @@ static NTSTATUS vio_modern_query_vq_alloc(VirtIODevice *vdev, return STATUS_SUCCESS; } -static NTSTATUS vio_modern_setup_vq(struct virtqueue **queue, - VirtIODevice *vdev, - VirtIOQueueInfo *info, - unsigned index, - u16 msix_vec) +static NTSTATUS vio_modern_setup_vq(struct virtqueue **queue, VirtIODevice *vdev, + VirtIOQueueInfo *info, unsigned index, u16 msix_vec) { volatile struct virtio_pci_common_cfg *cfg = vdev->common; struct virtqueue *vq; @@ -308,7 +302,8 @@ static NTSTATUS vio_modern_setup_vq(struct virtqueue **queue, off = ioread16(vdev, &cfg->queue_notify_off); /* try to allocate contiguous pages, scale down on failure */ - while (!(info->queue = mem_alloc_contiguous_pages(vdev, vring_pci_size(info->num, vdev->packed_ring)))) { + while (!(info->queue = + mem_alloc_contiguous_pages(vdev, vring_pci_size(info->num, vdev->packed_ring)))) { if (info->num > 0) { info->num /= 2; } else { @@ -323,13 +318,11 @@ static NTSTATUS vio_modern_setup_vq(struct virtqueue **queue, /* create the vring */ if (vdev->packed_ring) { - vq = vring_new_virtqueue_packed(index, info->num, - SMP_CACHE_BYTES, vdev, - info->queue, vp_notify, vq_addr); + vq = vring_new_virtqueue_packed(index, info->num, SMP_CACHE_BYTES, vdev, info->queue, + vp_notify, vq_addr); } else { - vq = vring_new_virtqueue_split(index, info->num, - SMP_CACHE_BYTES, vdev, - info->queue, vp_notify, vq_addr); + vq = vring_new_virtqueue_split(index, info->num, SMP_CACHE_BYTES, vdev, info->queue, + vp_notify, vq_addr); } if (!vq) { @@ -339,33 +332,27 @@ static NTSTATUS vio_modern_setup_vq(struct virtqueue **queue, /* activate the queue */ iowrite16(vdev, info->num, &cfg->queue_size); - iowrite64_twopart(vdev, mem_get_physical_address(vdev, info->queue), - &cfg->queue_desc_lo, &cfg->queue_desc_hi); - iowrite64_twopart(vdev, mem_get_physical_address(vdev, vq->avail_va), - &cfg->queue_avail_lo, &cfg->queue_avail_hi); - iowrite64_twopart(vdev, mem_get_physical_address(vdev, vq->used_va), - &cfg->queue_used_lo, &cfg->queue_used_hi); + iowrite64_twopart(vdev, mem_get_physical_address(vdev, info->queue), &cfg->queue_desc_lo, + &cfg->queue_desc_hi); + iowrite64_twopart(vdev, mem_get_physical_address(vdev, vq->avail_va), &cfg->queue_avail_lo, + &cfg->queue_avail_hi); + iowrite64_twopart(vdev, mem_get_physical_address(vdev, vq->used_va), &cfg->queue_used_lo, + &cfg->queue_used_hi); if (vdev->notify_base) { /* offset should not wrap */ - if ((u64)off * vdev->notify_offset_multiplier + 2 - > vdev->notify_len) { + if ((u64)off * vdev->notify_offset_multiplier + 2 > vdev->notify_len) { DPrintf(0, - "%p: bad notification offset %u (x %u) " - "for queue %u > %zd", - vdev, - off, vdev->notify_offset_multiplier, - index, vdev->notify_len); + "%p: bad notification offset %u (x %u) " + "for queue %u > %zd", + vdev, off, vdev->notify_offset_multiplier, index, vdev->notify_len); status = STATUS_INVALID_PARAMETER; goto err_map_notify; } - vq->notification_addr = (void *)(vdev->notify_base + - off * vdev->notify_offset_multiplier); + vq->notification_addr = (void *)(vdev->notify_base + off * vdev->notify_offset_multiplier); } else { - vq->notification_addr = vio_modern_map_capability(vdev, - vdev->notify_map_cap, 2, 2, - off * vdev->notify_offset_multiplier, 2, - NULL); + vq->notification_addr = vio_modern_map_capability( + vdev, vdev->notify_map_cap, 2, 2, off * vdev->notify_offset_multiplier, 2, NULL); } if (!vq->notification_addr) { @@ -442,8 +429,8 @@ static u8 find_next_pci_vendor_capability(VirtIODevice *vdev, u8 offset) while (iterations-- && offset >= 0x40) { offset &= ~3; - if (pci_read_config_byte(vdev, offset + offsetof(PCI_CAPABILITIES_HEADER, - CapabilityID), &id) != 0) { + if (pci_read_config_byte(vdev, offset + offsetof(PCI_CAPABILITIES_HEADER, CapabilityID), + &id) != 0) { break; } if (id == 0xFF) { @@ -452,8 +439,8 @@ static u8 find_next_pci_vendor_capability(VirtIODevice *vdev, u8 offset) if (id == PCI_CAPABILITY_ID_VENDOR_SPECIFIC) { return offset; } - if (pci_read_config_byte(vdev, offset + offsetof(PCI_CAPABILITIES_HEADER, - Next), &offset) != 0) { + if (pci_read_config_byte(vdev, offset + offsetof(PCI_CAPABILITIES_HEADER, Next), &offset) != + 0) { break; } } @@ -502,13 +489,13 @@ static void find_pci_vendor_capabilities(VirtIODevice *vdev, int *Offsets, size_ pci_read_config_byte(vdev, offset + offsetof(struct virtio_pci_cap, cfg_type), &cfg_type); pci_read_config_byte(vdev, offset + offsetof(struct virtio_pci_cap, bar), &bar); - if (bar < PCI_TYPE0_ADDRESSES && - cfg_type < nOffsets && + if (bar < PCI_TYPE0_ADDRESSES && cfg_type < nOffsets && pci_get_resource_len(vdev, bar) > 0) { Offsets[cfg_type] = offset; } - offset = find_next_pci_vendor_capability(vdev, offset + offsetof(PCI_CAPABILITIES_HEADER, Next)); + offset = + find_next_pci_vendor_capability(vdev, offset + offsetof(PCI_CAPABILITIES_HEADER, Next)); } } @@ -531,53 +518,47 @@ NTSTATUS vio_modern_initialize(VirtIODevice *vdev) /* Check isr and notify caps, if not found fail */ if (!capabilities[VIRTIO_PCI_CAP_ISR_CFG] || !capabilities[VIRTIO_PCI_CAP_NOTIFY_CFG]) { - DPrintf(0, "%s(%p): missing capabilities %i/%i/%i\n", - __FUNCTION__, vdev, - capabilities[VIRTIO_PCI_CAP_COMMON_CFG], - capabilities[VIRTIO_PCI_CAP_ISR_CFG], - capabilities[VIRTIO_PCI_CAP_NOTIFY_CFG]); + DPrintf(0, "%s(%p): missing capabilities %i/%i/%i\n", __FUNCTION__, vdev, + capabilities[VIRTIO_PCI_CAP_COMMON_CFG], capabilities[VIRTIO_PCI_CAP_ISR_CFG], + capabilities[VIRTIO_PCI_CAP_NOTIFY_CFG]); return STATUS_INVALID_PARAMETER; } /* Map bars according to the capabilities */ - vdev->common = vio_modern_map_simple_capability(vdev, - capabilities[VIRTIO_PCI_CAP_COMMON_CFG], - sizeof(struct virtio_pci_common_cfg), 4); + vdev->common = vio_modern_map_simple_capability(vdev, capabilities[VIRTIO_PCI_CAP_COMMON_CFG], + sizeof(struct virtio_pci_common_cfg), 4); if (!vdev->common) { return STATUS_INVALID_PARAMETER; } - vdev->isr = vio_modern_map_simple_capability(vdev, - capabilities[VIRTIO_PCI_CAP_ISR_CFG], - sizeof(u8), 1); + vdev->isr = + vio_modern_map_simple_capability(vdev, capabilities[VIRTIO_PCI_CAP_ISR_CFG], sizeof(u8), 1); if (!vdev->isr) { return STATUS_INVALID_PARAMETER; } /* Read notify_off_multiplier from config space. */ pci_read_config_dword(vdev, - capabilities[VIRTIO_PCI_CAP_NOTIFY_CFG] + offsetof(struct virtio_pci_notify_cap, - notify_off_multiplier), - &vdev->notify_offset_multiplier); + capabilities[VIRTIO_PCI_CAP_NOTIFY_CFG] + + offsetof(struct virtio_pci_notify_cap, notify_off_multiplier), + &vdev->notify_offset_multiplier); /* Read notify length and offset from config space. */ pci_read_config_dword(vdev, - capabilities[VIRTIO_PCI_CAP_NOTIFY_CFG] + offsetof(struct virtio_pci_notify_cap, - cap.length), - ¬ify_length); + capabilities[VIRTIO_PCI_CAP_NOTIFY_CFG] + + offsetof(struct virtio_pci_notify_cap, cap.length), + ¬ify_length); pci_read_config_dword(vdev, - capabilities[VIRTIO_PCI_CAP_NOTIFY_CFG] + offsetof(struct virtio_pci_notify_cap, - cap.offset), - ¬ify_offset); + capabilities[VIRTIO_PCI_CAP_NOTIFY_CFG] + + offsetof(struct virtio_pci_notify_cap, cap.offset), + ¬ify_offset); /* Map the notify capability if it's small enough. * Otherwise, map each VQ individually later. */ if (notify_length + (notify_offset % PAGE_SIZE) <= PAGE_SIZE) { - vdev->notify_base = vio_modern_map_capability(vdev, - capabilities[VIRTIO_PCI_CAP_NOTIFY_CFG], 2, 2, - 0, notify_length, - &vdev->notify_len); + vdev->notify_base = vio_modern_map_capability(vdev, capabilities[VIRTIO_PCI_CAP_NOTIFY_CFG], + 2, 2, 0, notify_length, &vdev->notify_len); if (!vdev->notify_base) { return STATUS_INVALID_PARAMETER; } @@ -587,10 +568,8 @@ NTSTATUS vio_modern_initialize(VirtIODevice *vdev) /* Map the device config capability, the PAGE_SIZE size is a guess */ if (capabilities[VIRTIO_PCI_CAP_DEVICE_CFG]) { - vdev->config = vio_modern_map_capability(vdev, - capabilities[VIRTIO_PCI_CAP_DEVICE_CFG], 0, 4, - 0, PAGE_SIZE, - &vdev->config_len); + vdev->config = vio_modern_map_capability(vdev, capabilities[VIRTIO_PCI_CAP_DEVICE_CFG], 0, + 4, 0, PAGE_SIZE, &vdev->config_len); if (!vdev->config) { return STATUS_INVALID_PARAMETER; } diff --git a/VirtIO/VirtIORing-Packed.c b/VirtIO/VirtIORing-Packed.c index 17ffe1f89..824ad95d9 100644 --- a/VirtIO/VirtIORing-Packed.c +++ b/VirtIO/VirtIORing-Packed.c @@ -59,39 +59,46 @@ struct vring_packed_desc { #include -#define BUG_ON(condition) { if (condition) { KeBugCheck(0xE0E1E2E3); }} -#define BAD_RING(vq, fmt, ...) DPrintf(0, "%s: queue %d: " fmt, __FUNCTION__, vq->vq.index, __VA_ARGS__); BUG_ON(true) +#define BUG_ON(condition) \ + { \ + if (condition) { \ + KeBugCheck(0xE0E1E2E3); \ + } \ + } +#define BAD_RING(vq, fmt, ...) \ + DPrintf(0, "%s: queue %d: " fmt, __FUNCTION__, vq->vq.index, __VA_ARGS__); \ + BUG_ON(true) /* This marks a buffer as continuing via the next field. */ -#define VRING_DESC_F_NEXT 1 +#define VRING_DESC_F_NEXT 1 /* This marks a buffer as write-only (otherwise read-only). */ -#define VRING_DESC_F_WRITE 2 +#define VRING_DESC_F_WRITE 2 /* This means the buffer contains a list of buffer descriptors. */ -#define VRING_DESC_F_INDIRECT 4 +#define VRING_DESC_F_INDIRECT 4 /* * Mark a descriptor as available or used in packed ring. * Notice: they are defined as shifts instead of shifted values. */ -#define VRING_PACKED_DESC_F_AVAIL 7 -#define VRING_PACKED_DESC_F_USED 15 +#define VRING_PACKED_DESC_F_AVAIL 7 +#define VRING_PACKED_DESC_F_USED 15 /* Enable events in packed ring. */ -#define VRING_PACKED_EVENT_FLAG_ENABLE 0x0 +#define VRING_PACKED_EVENT_FLAG_ENABLE 0x0 /* Disable events in packed ring. */ -#define VRING_PACKED_EVENT_FLAG_DISABLE 0x1 +#define VRING_PACKED_EVENT_FLAG_DISABLE 0x1 /* * Enable events for a specific descriptor in packed ring. * (as specified by Descriptor Ring Change Event Offset/Wrap Counter). * Only valid if VIRTIO_RING_F_EVENT_IDX has been negotiated. */ -#define VRING_PACKED_EVENT_FLAG_DESC 0x2 - /* +#define VRING_PACKED_EVENT_FLAG_DESC 0x2 +/* * Wrap counter bit shift in event suppression structure * of packed ring. */ -#define VRING_PACKED_EVENT_F_WRAP_CTR 15 +#define VRING_PACKED_EVENT_F_WRAP_CTR 15 /* The following is used with USED_EVENT_IDX and AVAIL_EVENT_IDX */ /* Assuming a given event_idx value from the other side, if @@ -109,10 +116,10 @@ static inline bool vring_need_event(__u16 event_idx, __u16 new_idx, __u16 old) } struct vring_desc_state_packed { - void *data; /* Data for callback. */ - u16 num; /* Descriptor list length. */ - u16 next; /* The next desc state in a list. */ - u16 last; /* The last desc state in a list. */ + void *data; /* Data for callback. */ + u16 num; /* Descriptor list length. */ + u16 next; /* The next desc state in a list. */ + u16 last; /* The last desc state in a list. */ }; struct virtqueue_packed { @@ -127,8 +134,7 @@ struct virtqueue_packed { u16 last_used_idx; /* Avail used flags. */ u16 avail_used_flags; - struct - { + struct { /* Driver ring wrap counter. */ bool avail_wrap_counter; /* Device ring wrap counter. */ @@ -168,14 +174,14 @@ unsigned long vring_size_packed(unsigned int num, unsigned long align) return res; } -static int virtqueue_add_buf_packed( - struct virtqueue *_vq, /* the queue */ - struct scatterlist sg[], /* sg array of length out + in */ - unsigned int out, /* number of driver->device buffer descriptors in sg */ - unsigned int in, /* number of device->driver buffer descriptors in sg */ - void *opaque, /* later returned from virtqueue_get_buf */ - void *va_indirect, /* VA of the indirect page or NULL */ - ULONGLONG phys_indirect) /* PA of the indirect page or 0 */ +static int +virtqueue_add_buf_packed(struct virtqueue *_vq, /* the queue */ + struct scatterlist sg[], /* sg array of length out + in */ + unsigned int out, /* number of driver->device buffer descriptors in sg */ + unsigned int in, /* number of device->driver buffer descriptors in sg */ + void *opaque, /* later returned from virtqueue_get_buf */ + void *va_indirect, /* VA of the indirect page or NULL */ + ULONGLONG phys_indirect) /* PA of the indirect page or 0 */ { struct virtqueue_packed *vq = packedvq(_vq); unsigned int descs_used; @@ -208,9 +214,7 @@ static int virtqueue_add_buf_packed( if (head >= vq->packed.vring.num) { head = 0; vq->packed.avail_wrap_counter ^= 1; - vq->avail_used_flags ^= - 1 << VRING_PACKED_DESC_F_AVAIL | - 1 << VRING_PACKED_DESC_F_USED; + vq->avail_used_flags ^= 1 << VRING_PACKED_DESC_F_AVAIL | 1 << VRING_PACKED_DESC_F_USED; } vq->packed.next_avail_idx = head; /* We're using some buffers from the free list. */ @@ -245,8 +249,7 @@ static int virtqueue_add_buf_packed( desc[i].id = id; if (n == 0) { head_flags = flags; - } - else { + } else { desc[i].flags = flags; } @@ -256,13 +259,13 @@ static int virtqueue_add_buf_packed( if (++i >= vq->packed.vring.num) { i = 0; vq->avail_used_flags ^= - 1 << VRING_PACKED_DESC_F_AVAIL | - 1 << VRING_PACKED_DESC_F_USED; + 1 << VRING_PACKED_DESC_F_AVAIL | 1 << VRING_PACKED_DESC_F_USED; } } - if (i < head) + if (i < head) { vq->packed.avail_wrap_counter ^= 1; + } /* We're using some buffers from the free list. */ vq->num_free -= descs_used; @@ -310,8 +313,9 @@ static void *virtqueue_detach_unused_buf_packed(struct virtqueue *_vq) void *buf; for (i = 0; i < vq->packed.vring.num; i++) { - if (!vq->packed.desc_state[i].data) + if (!vq->packed.desc_state[i].data) { continue; + } /* detach_buf clears data, so grab it now. */ buf = vq->packed.desc_state[i].data; detach_buf_packed(vq, i); @@ -333,8 +337,8 @@ static void virtqueue_disable_cb_packed(struct virtqueue *_vq) } } -static inline bool is_used_desc_packed(const struct virtqueue_packed *vq, - u16 idx, bool used_wrap_counter) +static inline bool is_used_desc_packed(const struct virtqueue_packed *vq, u16 idx, + bool used_wrap_counter) { bool avail, used; u16 flags; @@ -356,7 +360,6 @@ static inline bool virtqueue_poll_packed(struct virtqueue_packed *vq, u16 off_wr used_idx = off_wrap & ~(1 << VRING_PACKED_EVENT_F_WRAP_CTR); return is_used_desc_packed(vq, used_idx, wrap_counter); - } static inline unsigned virtqueue_enable_cb_prepare_packed(struct virtqueue_packed *vq) @@ -369,9 +372,7 @@ static inline unsigned virtqueue_enable_cb_prepare_packed(struct virtqueue_packe if (event_suppression_enabled) { vq->packed.vring.driver->off_wrap = - vq->last_used_idx | - (vq->packed.used_wrap_counter << - VRING_PACKED_EVENT_F_WRAP_CTR); + vq->last_used_idx | (vq->packed.used_wrap_counter << VRING_PACKED_EVENT_F_WRAP_CTR); /* * We need to update event offset and event wrap * counter first before updating event flags. @@ -380,14 +381,12 @@ static inline unsigned virtqueue_enable_cb_prepare_packed(struct virtqueue_packe } if (vq->packed.event_flags_shadow == VRING_PACKED_EVENT_FLAG_DISABLE) { - vq->packed.event_flags_shadow = event_suppression_enabled ? - VRING_PACKED_EVENT_FLAG_DESC : - VRING_PACKED_EVENT_FLAG_ENABLE; + vq->packed.event_flags_shadow = event_suppression_enabled ? VRING_PACKED_EVENT_FLAG_DESC : + VRING_PACKED_EVENT_FLAG_ENABLE; vq->packed.vring.driver->flags = vq->packed.event_flags_shadow; } - return vq->last_used_idx | ((u16)vq->packed.used_wrap_counter << - VRING_PACKED_EVENT_F_WRAP_CTR); + return vq->last_used_idx | ((u16)vq->packed.used_wrap_counter << VRING_PACKED_EVENT_F_WRAP_CTR); } static bool virtqueue_enable_cb_packed(struct virtqueue *_vq) @@ -421,8 +420,8 @@ static bool virtqueue_enable_cb_delayed_packed(struct virtqueue *_vq) wrap_counter ^= 1; } - vq->packed.vring.driver->off_wrap = used_idx | - (wrap_counter << VRING_PACKED_EVENT_F_WRAP_CTR); + vq->packed.vring.driver->off_wrap = + used_idx | (wrap_counter << VRING_PACKED_EVENT_F_WRAP_CTR); /* * We need to update event offset and event wrap @@ -432,9 +431,8 @@ static bool virtqueue_enable_cb_delayed_packed(struct virtqueue *_vq) } if (vq->packed.event_flags_shadow == VRING_PACKED_EVENT_FLAG_DISABLE) { - vq->packed.event_flags_shadow = event_suppression_enabled ? - VRING_PACKED_EVENT_FLAG_DESC : - VRING_PACKED_EVENT_FLAG_ENABLE; + vq->packed.event_flags_shadow = event_suppression_enabled ? VRING_PACKED_EVENT_FLAG_DESC : + VRING_PACKED_EVENT_FLAG_ENABLE; vq->packed.vring.driver->flags = vq->packed.event_flags_shadow; } @@ -444,9 +442,7 @@ static bool virtqueue_enable_cb_delayed_packed(struct virtqueue *_vq) */ KeMemoryBarrier(); - if (is_used_desc_packed(vq, - vq->last_used_idx, - vq->packed.used_wrap_counter)) { + if (is_used_desc_packed(vq, vq->last_used_idx, vq->packed.used_wrap_counter)) { return false; } @@ -467,25 +463,18 @@ static void virtqueue_shutdown_packed(struct virtqueue *_vq) unsigned int vring_align = _vq->vdev->addr ? PAGE_SIZE : SMP_CACHE_BYTES; RtlZeroMemory(pages, vring_size_packed(num, vring_align)); - vring_new_virtqueue_packed( - _vq->index, - num, - vring_align, - _vq->vdev, - pages, - _vq->notification_cb, - _vq); + vring_new_virtqueue_packed(_vq->index, num, vring_align, _vq->vdev, pages, _vq->notification_cb, + _vq); } static inline bool more_used_packed(const struct virtqueue_packed *vq) { - return is_used_desc_packed(vq, vq->last_used_idx, - vq->packed.used_wrap_counter); + return is_used_desc_packed(vq, vq->last_used_idx, vq->packed.used_wrap_counter); } -static void *virtqueue_get_buf_packed( - struct virtqueue *_vq, /* the queue */ - unsigned int *len) /* number of bytes returned by the device */ +static void * +virtqueue_get_buf_packed(struct virtqueue *_vq, /* the queue */ + unsigned int *len) /* number of bytes returned by the device */ { struct virtqueue_packed *vq = packedvq(_vq); u16 last_used, id; @@ -528,9 +517,8 @@ static void *virtqueue_get_buf_packed( * the read in the next get_buf call. */ if (vq->packed.event_flags_shadow == VRING_PACKED_EVENT_FLAG_DESC) { - vq->packed.vring.driver->off_wrap = vq->last_used_idx | - ((u16)vq->packed.used_wrap_counter << - VRING_PACKED_EVENT_F_WRAP_CTR); + vq->packed.vring.driver->off_wrap = vq->last_used_idx | ((u16)vq->packed.used_wrap_counter + << VRING_PACKED_EVENT_F_WRAP_CTR); KeMemoryBarrier(); } @@ -578,8 +566,9 @@ static bool virtqueue_kick_prepare_packed(struct virtqueue *_vq) wrap_counter = off_wrap >> VRING_PACKED_EVENT_F_WRAP_CTR; event_idx = off_wrap & ~(1 << VRING_PACKED_EVENT_F_WRAP_CTR); - if (wrap_counter != vq->packed.avail_wrap_counter) + if (wrap_counter != vq->packed.avail_wrap_counter) { event_idx -= (u16)vq->packed.vring.num; + } needs_kick = vring_need_event(event_idx, new, old); out: @@ -595,14 +584,14 @@ static void virtqueue_kick_always_packed(struct virtqueue *_vq) } /* Initializes a new virtqueue using already allocated memory */ -struct virtqueue *vring_new_virtqueue_packed( - unsigned int index, /* virtqueue index */ - unsigned int num, /* virtqueue size (always a power of 2) */ - unsigned int vring_align, /* vring alignment requirement */ - VirtIODevice *vdev, /* the virtio device owning the queue */ - void *pages, /* vring memory */ - void(*notify)(struct virtqueue *), /* notification callback */ - void *control) /* virtqueue memory */ +struct virtqueue * +vring_new_virtqueue_packed(unsigned int index, /* virtqueue index */ + unsigned int num, /* virtqueue size (always a power of 2) */ + unsigned int vring_align, /* vring alignment requirement */ + VirtIODevice *vdev, /* the virtio device owning the queue */ + void *pages, /* vring memory */ + void (*notify)(struct virtqueue *), /* notification callback */ + void *control) /* virtqueue memory */ { struct virtqueue_packed *vq = packedvq(control); unsigned int i; diff --git a/VirtIO/VirtIORing.c b/VirtIO/VirtIORing.c index 1053d494b..d29469a08 100644 --- a/VirtIO/VirtIORing.c +++ b/VirtIO/VirtIORing.c @@ -36,26 +36,26 @@ #include "virtio_ring.h" #include "windows\virtio_ring_allocation.h" -#define DESC_INDEX(num, i) ((i) & ((num) - 1)) +#define DESC_INDEX(num, i) ((i) & ((num) - 1)) - /* This marks a buffer as continuing via the next field. */ -#define VIRTQ_DESC_F_NEXT 1 +/* This marks a buffer as continuing via the next field. */ +#define VIRTQ_DESC_F_NEXT 1 /* This marks a buffer as write-only (otherwise read-only). */ -#define VIRTQ_DESC_F_WRITE 2 +#define VIRTQ_DESC_F_WRITE 2 /* This means the buffer contains a list of buffer descriptors. */ -#define VIRTQ_DESC_F_INDIRECT 4 +#define VIRTQ_DESC_F_INDIRECT 4 /* The Host uses this in used->flags to advise the Guest: don't kick me when * you add a buffer. It's unreliable, so it's simply an optimization. Guest * will still kick if it's out of buffers. */ -#define VIRTQ_USED_F_NO_NOTIFY 1 +#define VIRTQ_USED_F_NO_NOTIFY 1 /* The Guest uses this in avail->flags to advise the Host: don't interrupt me * when you consume a buffer. It's unreliable, so it's simply an * optimization. */ -#define VIRTQ_AVAIL_F_NO_INTERRUPT 1 +#define VIRTQ_AVAIL_F_NO_INTERRUPT 1 -#pragma warning (push) -#pragma warning (disable:4200) +#pragma warning(push) +#pragma warning(disable : 4200) #include @@ -97,8 +97,8 @@ struct vring_used { * When using pre-virtio 1.0 layout, these fall out naturally. */ #define VRING_AVAIL_ALIGN_SIZE 2 -#define VRING_USED_ALIGN_SIZE 4 -#define VRING_DESC_ALIGN_SIZE 16 +#define VRING_USED_ALIGN_SIZE 4 +#define VRING_DESC_ALIGN_SIZE 16 /* The standard layout for the ring is a continuous chunk of memory which looks * like this. We assume num is a power of 2. @@ -137,26 +137,26 @@ struct vring { struct vring_used *used; }; -#define vring_used_event(vr) ((vr)->avail->ring[(vr)->num]) +#define vring_used_event(vr) ((vr)->avail->ring[(vr)->num]) #define vring_avail_event(vr) (*(__virtio16 *)&(vr)->used->ring[(vr)->num]) -static inline void vring_init(struct vring *vr, unsigned int num, void *p, - unsigned long align) +static inline void vring_init(struct vring *vr, unsigned int num, void *p, unsigned long align) { vr->num = num; vr->desc = (struct vring_desc *)p; vr->avail = (struct vring_avail *)((__u8 *)p + num * sizeof(struct vring_desc)); - vr->used = (struct vring_used *)(((ULONG_PTR)&vr->avail->ring[num] + sizeof(__virtio16) - + align - 1) & ~((ULONG_PTR)align - 1)); + vr->used = + (struct vring_used *)(((ULONG_PTR)&vr->avail->ring[num] + sizeof(__virtio16) + align - 1) & + ~((ULONG_PTR)align - 1)); } static inline unsigned vring_size_split(unsigned int num, unsigned long align) { -#pragma warning (push) -#pragma warning (disable:4319) - return ((sizeof(struct vring_desc) * num + sizeof(__virtio16) * (3 + num) - + align - 1) & ~(align - 1)) - + sizeof(__virtio16) * 3 + sizeof(struct vring_used_elem) * num; +#pragma warning(push) +#pragma warning(disable : 4319) + return ((sizeof(struct vring_desc) * num + sizeof(__virtio16) * (3 + num) + align - 1) & + ~(align - 1)) + + sizeof(__virtio16) * 3 + sizeof(struct vring_used_elem) * num; #pragma warning(pop) } @@ -190,9 +190,9 @@ struct virtqueue_split { #define splitvq(vq) ((struct virtqueue_split *)vq) -#pragma warning (pop) +#pragma warning(pop) - /* Returns the index of the first unused descriptor */ +/* Returns the index of the first unused descriptor */ static inline u16 get_unused_desc(struct virtqueue_split *vq) { u16 idx = vq->first_unused; @@ -222,14 +222,14 @@ static inline void put_unused_desc_chain(struct virtqueue_split *vq, u16 idx) } /* Adds a buffer to a virtqueue, returns 0 on success, negative number on error */ -static int virtqueue_add_buf_split( - struct virtqueue *_vq, /* the queue */ - struct scatterlist sg[], /* sg array of length out + in */ - unsigned int out, /* number of driver->device buffer descriptors in sg */ - unsigned int in, /* number of device->driver buffer descriptors in sg */ - void *opaque, /* later returned from virtqueue_get_buf */ - void *va_indirect, /* VA of the indirect page or NULL */ - ULONGLONG phys_indirect) /* PA of the indirect page or 0 */ +static int +virtqueue_add_buf_split(struct virtqueue *_vq, /* the queue */ + struct scatterlist sg[], /* sg array of length out + in */ + unsigned int out, /* number of driver->device buffer descriptors in sg */ + unsigned int in, /* number of device->driver buffer descriptors in sg */ + void *opaque, /* later returned from virtqueue_get_buf */ + void *va_indirect, /* VA of the indirect page or NULL */ + ULONGLONG phys_indirect) /* PA of the indirect page or 0 */ { struct virtqueue_split *vq = splitvq(_vq); struct vring *vring = &vq->vring; @@ -300,9 +300,8 @@ static int virtqueue_add_buf_split( } /* Gets the opaque pointer associated with a returned buffer, or NULL if no buffer is available */ -static void *virtqueue_get_buf_split( - struct virtqueue *_vq, /* the queue */ - unsigned int *len) /* number of bytes returned by the device */ +static void *virtqueue_get_buf_split(struct virtqueue *_vq, /* the queue */ + unsigned int *len) /* number of bytes returned by the device */ { struct virtqueue_split *vq = splitvq(_vq); void *opaque; @@ -378,8 +377,7 @@ static bool virtqueue_enable_cb_split(struct virtqueue *_vq) struct virtqueue_split *vq = splitvq(_vq); if (!virtqueue_is_interrupt_enabled(_vq)) { vq->master_vring_avail.flags &= ~VIRTQ_AVAIL_F_NO_INTERRUPT; - if (!_vq->vdev->event_suppression_enabled) - { + if (!_vq->vdev->event_suppression_enabled) { vq->vring.avail->flags = vq->master_vring_avail.flags; } } @@ -398,8 +396,7 @@ static bool virtqueue_enable_cb_delayed_split(struct virtqueue *_vq) if (!virtqueue_is_interrupt_enabled(_vq)) { vq->master_vring_avail.flags &= ~VIRTQ_AVAIL_F_NO_INTERRUPT; - if (!_vq->vdev->event_suppression_enabled) - { + if (!_vq->vdev->event_suppression_enabled) { vq->vring.avail->flags = vq->master_vring_avail.flags; } } @@ -417,8 +414,7 @@ static void virtqueue_disable_cb_split(struct virtqueue *_vq) struct virtqueue_split *vq = splitvq(_vq); if (virtqueue_is_interrupt_enabled(_vq)) { vq->master_vring_avail.flags |= VIRTQ_AVAIL_F_NO_INTERRUPT; - if (!_vq->vdev->event_suppression_enabled) - { + if (!_vq->vdev->event_suppression_enabled) { vq->vring.avail->flags = vq->master_vring_avail.flags; } } @@ -440,14 +436,8 @@ static void virtqueue_shutdown_split(struct virtqueue *_vq) unsigned int vring_align = _vq->vdev->addr ? PAGE_SIZE : SMP_CACHE_BYTES; RtlZeroMemory(pages, vring_size_split(num, vring_align)); - (void)vring_new_virtqueue_split( - _vq->index, - vq->vring.num, - vring_align, - _vq->vdev, - pages, - _vq->notification_cb, - vq); + (void)vring_new_virtqueue_split(_vq->index, vq->vring.num, vring_align, _vq->vdev, pages, + _vq->notification_cb, vq); } /* Gets the opaque pointer associated with a not-yet-returned buffer, or NULL if no buffer is available @@ -483,14 +473,14 @@ unsigned int vring_control_block_size(u16 qsize, bool packed) } /* Initializes a new virtqueue using already allocated memory */ -struct virtqueue *vring_new_virtqueue_split( - unsigned int index, /* virtqueue index */ - unsigned int num, /* virtqueue size (always a power of 2) */ - unsigned int vring_align, /* vring alignment requirement */ - VirtIODevice *vdev, /* the virtio device owning the queue */ - void *pages, /* vring memory */ - void(*notify)(struct virtqueue *), /* notification callback */ - void *control) /* virtqueue memory */ +struct virtqueue * +vring_new_virtqueue_split(unsigned int index, /* virtqueue index */ + unsigned int num, /* virtqueue size (always a power of 2) */ + unsigned int vring_align, /* vring alignment requirement */ + VirtIODevice *vdev, /* the virtio device owning the queue */ + void *pages, /* vring memory */ + void (*notify)(struct virtqueue *), /* notification callback */ + void *control) /* virtqueue memory */ { struct virtqueue_split *vq = splitvq(control); u16 i; @@ -538,8 +528,7 @@ void vring_transport_features( unsigned int i; for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++) { - if (i != VIRTIO_RING_F_INDIRECT_DESC && - i != VIRTIO_RING_F_EVENT_IDX && + if (i != VIRTIO_RING_F_INDIRECT_DESC && i != VIRTIO_RING_F_EVENT_IDX && i != VIRTIO_F_VERSION_1) { virtio_feature_disable(*features, i); } diff --git a/VirtIO/WDF/Callbacks.c b/VirtIO/WDF/Callbacks.c index 4d253ab75..d789e3926 100644 --- a/VirtIO/WDF/Callbacks.c +++ b/VirtIO/WDF/Callbacks.c @@ -65,10 +65,7 @@ static void *mem_alloc_nonpaged_block(void *context, size_t size) { PVIRTIO_WDF_DRIVER pWdfDriver = (PVIRTIO_WDF_DRIVER)context; - PVOID addr = ExAllocatePoolUninitialized( - NonPagedPool, - size, - pWdfDriver->MemoryTag); + PVOID addr = ExAllocatePoolUninitialized(NonPagedPool, size, pWdfDriver->MemoryTag); if (addr) { RtlZeroMemory(addr, size); } @@ -79,9 +76,7 @@ static void mem_free_nonpaged_block(void *context, void *addr) { PVIRTIO_WDF_DRIVER pWdfDriver = (PVIRTIO_WDF_DRIVER)context; - ExFreePoolWithTag( - addr, - pWdfDriver->MemoryTag); + ExFreePoolWithTag(addr, pWdfDriver->MemoryTag); } static int pci_read_config_byte(void *context, int where, u8 *bVal) @@ -103,7 +98,7 @@ static PVIRTIO_WDF_BAR find_bar(void *context, int bar) { PVIRTIO_WDF_DRIVER pWdfDriver = (PVIRTIO_WDF_DRIVER)context; PSINGLE_LIST_ENTRY iter = &pWdfDriver->PCIBars; - + while (iter->Next != NULL) { PVIRTIO_WDF_BAR pBar = CONTAINING_RECORD(iter->Next, VIRTIO_WDF_BAR, ListEntry); if (pBar->iBar == bar) { @@ -127,10 +122,8 @@ static void *pci_map_address_range(void *context, int bar, size_t offset, size_t if (pBar->pBase == NULL) { ASSERT(!pBar->bPortSpace); #if defined(NTDDI_WINTHRESHOLD) && (NTDDI_VERSION >= NTDDI_WINTHRESHOLD) - pBar->pBase = MmMapIoSpaceEx( - pBar->BasePA, - pBar->uLength, - PAGE_READWRITE | PAGE_NOCACHE); + pBar->pBase = + MmMapIoSpaceEx(pBar->BasePA, pBar->uLength, PAGE_READWRITE | PAGE_NOCACHE); #else pBar->pBase = MmMapIoSpace(pBar->BasePA, pBar->uLength, MmNonCached); #endif @@ -152,8 +145,7 @@ static u16 vdev_get_msix_vector(void *context, int queue) if (pWdfDriver->pQueueParams != NULL) { vector = PCIGetMSIInterruptVector(pWdfDriver->pQueueParams[queue].Interrupt); } - } - else { + } else { /* on-device-config-change interrupt */ vector = PCIGetMSIInterruptVector(pWdfDriver->ConfigInterrupt); } diff --git a/VirtIO/WDF/Dma.c b/VirtIO/WDF/Dma.c index 025420007..5b0234345 100644 --- a/VirtIO/WDF/Dma.c +++ b/VirtIO/WDF/Dma.c @@ -35,7 +35,7 @@ #include "private.h" static EVT_WDF_OBJECT_CONTEXT_DESTROY OnDmaTransactionDestroy; -static EVT_WDF_PROGRAM_DMA OnDmaTransactionProgramDma; +static EVT_WDF_PROGRAM_DMA OnDmaTransactionProgramDma; static void *AllocateCommonBuffer(PVIRTIO_WDF_DRIVER pWdfDriver, size_t size, ULONG groupTag) { @@ -70,11 +70,8 @@ static void *AllocateCommonBuffer(PVIRTIO_WDF_DRIVER pWdfDriver, size_t size, UL WdfSpinLockRelease(pWdfDriver->DmaSpinlock); RtlZeroMemory(context->pVirtualAddress, size); - DPrintf(1, "%s done %p@%I64x(tag %08X), size 0x%x\n", __FUNCTION__, - context->pVirtualAddress, - context->PhysicalAddress.QuadPart, - context->groupTag, - (ULONG)size); + DPrintf(1, "%s done %p@%I64x(tag %08X), size 0x%x\n", __FUNCTION__, context->pVirtualAddress, + context->PhysicalAddress.QuadPart, context->groupTag, (ULONG)size); return context->pVirtualAddress; } @@ -84,12 +81,8 @@ void *VirtIOWdfDeviceAllocDmaMemory(VirtIODevice *vdev, size_t size, ULONG group return AllocateCommonBuffer(vdev->DeviceContext, size, groupTag); } -static BOOLEAN FindCommonBuffer( - PVIRTIO_WDF_DRIVER pWdfDriver, - void *p, - PHYSICAL_ADDRESS *ppa, - size_t *pOffset, - BOOLEAN bRemoval) +static BOOLEAN FindCommonBuffer(PVIRTIO_WDF_DRIVER pWdfDriver, void *p, PHYSICAL_ADDRESS *ppa, + size_t *pOffset, BOOLEAN bRemoval) { BOOLEAN b = FALSE; ULONG_PTR va = (ULONG_PTR)p; @@ -123,18 +116,15 @@ static BOOLEAN FindCommonBuffer( WdfSpinLockRelease(pWdfDriver->DmaSpinlock); if (!b) { DPrintf(0, "%s(%s) FAILED!\n", __FUNCTION__, bRemoval ? "Remove" : "Locate"); - } - else if (bRemoval) { + } else if (bRemoval) { if (KeGetCurrentIrql() == PASSIVE_LEVEL) { - WdfSpinLockAcquire(pWdfDriver->DmaSpinlock); WdfCollectionRemove(pWdfDriver->MemoryBlockCollection, obj); WdfSpinLockRelease(pWdfDriver->DmaSpinlock); WdfObjectDelete(obj); DPrintf(1, "%s %p freed (%d common buffers)\n", __FUNCTION__, va, n - 1); - } - else { + } else { DPrintf(0, "%s %p marked for deletion\n", __FUNCTION__, va); } } @@ -164,10 +154,7 @@ void VirtIOWdfDeviceFreeDmaMemory(VirtIODevice *vdev, void *va) FindCommonBuffer(vdev->DeviceContext, va, &pa, &offset, TRUE); } -static BOOLEAN FindCommonBufferByTag( - PVIRTIO_WDF_DRIVER pWdfDriver, - ULONG tag -) +static BOOLEAN FindCommonBufferByTag(PVIRTIO_WDF_DRIVER pWdfDriver, ULONG tag) { BOOLEAN b = FALSE; ULONG i, n; @@ -189,7 +176,7 @@ static BOOLEAN FindCommonBufferByTag( WdfSpinLockRelease(pWdfDriver->DmaSpinlock); if (b) { DPrintf(1, "%s %p (tag %08X) freed (%d common buffers)\n", __FUNCTION__, - context->pVirtualAddress, tag, n - 1); + context->pVirtualAddress, tag, n - 1); WdfSpinLockAcquire(pWdfDriver->DmaSpinlock); WdfCollectionRemove(pWdfDriver->MemoryBlockCollection, obj); WdfSpinLockRelease(pWdfDriver->DmaSpinlock); @@ -212,7 +199,8 @@ void VirtIOWdfDeviceFreeDmaMemoryByTag(VirtIODevice *vdev, ULONG groupTag) DPrintf(0, "%s was not initialized\n", __FUNCTION__); return; } - while (FindCommonBufferByTag(vdev->DeviceContext, groupTag)); + while (FindCommonBufferByTag(vdev->DeviceContext, groupTag)) + ; } static void FreeSlicedBlock(PVIRTIO_DMA_MEMORY_SLICED p) @@ -242,8 +230,7 @@ static void FreeSlice(PVIRTIO_DMA_MEMORY_SLICED p, PVOID va) return; } if (offset % p->slice) { - DPrintf(0, "%s: offset %d is wrong for slice %d\n", __FUNCTION__, - (ULONG)offset, p->slice); + DPrintf(0, "%s: offset %d is wrong for slice %d\n", __FUNCTION__, (ULONG)offset, p->slice); return; } ULONG index = (ULONG)(offset / p->slice); @@ -254,14 +241,14 @@ static void FreeSlice(PVIRTIO_DMA_MEMORY_SLICED p, PVOID va) RtlClearBit(&p->bitmap, index); } -PVIRTIO_DMA_MEMORY_SLICED VirtIOWdfDeviceAllocDmaMemorySliced( - VirtIODevice *vdev, - size_t blockSize, - ULONG sliceSize) +PVIRTIO_DMA_MEMORY_SLICED VirtIOWdfDeviceAllocDmaMemorySliced(VirtIODevice *vdev, size_t blockSize, + ULONG sliceSize) { PVIRTIO_WDF_DRIVER pWdfDriver = vdev->DeviceContext; - size_t allocSize = sizeof(VIRTIO_DMA_MEMORY_SLICED) + (blockSize / sliceSize) / 8 + sizeof(ULONG); - PVIRTIO_DMA_MEMORY_SLICED p = ExAllocatePoolUninitialized(NonPagedPool, allocSize, pWdfDriver->MemoryTag); + size_t allocSize = + sizeof(VIRTIO_DMA_MEMORY_SLICED) + (blockSize / sliceSize) / 8 + sizeof(ULONG); + PVIRTIO_DMA_MEMORY_SLICED p = + ExAllocatePoolUninitialized(NonPagedPool, allocSize, pWdfDriver->MemoryTag); if (!p) { return NULL; } @@ -278,7 +265,7 @@ PVIRTIO_DMA_MEMORY_SLICED VirtIOWdfDeviceAllocDmaMemorySliced( RtlInitializeBitMap(&p->bitmap, p->bitmap_buffer, (ULONG)blockSize / sliceSize); p->return_slice = FreeSlice; p->get_slice = AllocateSlice; - p->destroy = FreeSlicedBlock; + p->destroy = FreeSlicedBlock; return p; } @@ -306,31 +293,24 @@ static FORCEINLINE void DerefTransaction(PVIRTIO_WDF_DMA_TRANSACTION_CONTEXT ctx } } -BOOLEAN OnDmaTransactionProgramDma( - WDFDMATRANSACTION Transaction, - WDFDEVICE Device, - WDFCONTEXT Context, - WDF_DMA_DIRECTION Direction, - PSCATTER_GATHER_LIST SgList -) +BOOLEAN OnDmaTransactionProgramDma(WDFDMATRANSACTION Transaction, WDFDEVICE Device, + WDFCONTEXT Context, WDF_DMA_DIRECTION Direction, + PSCATTER_GATHER_LIST SgList) { PVIRTIO_WDF_DMA_TRANSACTION_CONTEXT ctx = GetDmaTransactionContext(Transaction); RefTransaction(ctx); ctx->parameters.transaction = Transaction; ctx->parameters.sgList = SgList; - DPrintf(1, "-->%s %p %d frags\n", __FUNCTION__, - Transaction, - SgList->NumberOfElements); + DPrintf(1, "-->%s %p %d frags\n", __FUNCTION__, Transaction, SgList->NumberOfElements); BOOLEAN bFailed = !ctx->callback(&ctx->parameters); DPrintf(1, "<--%s %s\n", __FUNCTION__, bFailed ? "Failed" : "OK"); DerefTransaction(ctx); return TRUE; } -static BOOLEAN VirtIOWdfDeviceDmaAsync(VirtIODevice *vdev, - PVIRTIO_DMA_TRANSACTION_PARAMS params, - VirtIOWdfDmaTransactionCallback callback, - WDF_DMA_DIRECTION Direction) +static BOOLEAN VirtIOWdfDeviceDmaAsync(VirtIODevice *vdev, PVIRTIO_DMA_TRANSACTION_PARAMS params, + VirtIOWdfDmaTransactionCallback callback, + WDF_DMA_DIRECTION Direction) { PVIRTIO_WDF_DRIVER pWdfDriver = vdev->DeviceContext; WDFDMATRANSACTION tr; @@ -350,10 +330,11 @@ static BOOLEAN VirtIOWdfDeviceDmaAsync(VirtIODevice *vdev, ctx->refCount = 1; ctx->direction = Direction; if (params->req) { - status = WdfDmaTransactionInitializeUsingRequest( - tr, params->req, OnDmaTransactionProgramDma, Direction); + status = WdfDmaTransactionInitializeUsingRequest(tr, params->req, + OnDmaTransactionProgramDma, Direction); } else { - ctx->buffer = ExAllocatePoolUninitialized(NonPagedPool, ctx->parameters.size, ctx->parameters.allocationTag); + ctx->buffer = ExAllocatePoolUninitialized(NonPagedPool, ctx->parameters.size, + ctx->parameters.allocationTag); if (ctx->buffer) { if (Direction == WdfDmaDirectionWriteToDevice) { RtlCopyMemory(ctx->buffer, params->buffer, params->size); @@ -361,9 +342,8 @@ static BOOLEAN VirtIOWdfDeviceDmaAsync(VirtIODevice *vdev, ctx->mdl = IoAllocateMdl(ctx->buffer, params->size, FALSE, FALSE, NULL); if (ctx->mdl) { MmBuildMdlForNonPagedPool(ctx->mdl); - status = WdfDmaTransactionInitialize( - tr, OnDmaTransactionProgramDma, Direction, - ctx->mdl, ctx->buffer, params->size); + status = WdfDmaTransactionInitialize(tr, OnDmaTransactionProgramDma, Direction, + ctx->mdl, ctx->buffer, params->size); } else { status = STATUS_INSUFFICIENT_RESOURCES; } @@ -388,16 +368,14 @@ static BOOLEAN VirtIOWdfDeviceDmaAsync(VirtIODevice *vdev, return TRUE; } -BOOLEAN VirtIOWdfDeviceDmaTxAsync(VirtIODevice* vdev, - PVIRTIO_DMA_TRANSACTION_PARAMS params, - VirtIOWdfDmaTransactionCallback callback) +BOOLEAN VirtIOWdfDeviceDmaTxAsync(VirtIODevice *vdev, PVIRTIO_DMA_TRANSACTION_PARAMS params, + VirtIOWdfDmaTransactionCallback callback) { return VirtIOWdfDeviceDmaAsync(vdev, params, callback, WdfDmaDirectionWriteToDevice); } -BOOLEAN VirtIOWdfDeviceDmaRxAsync(VirtIODevice* vdev, - PVIRTIO_DMA_TRANSACTION_PARAMS params, - VirtIOWdfDmaTransactionCallback callback) +BOOLEAN VirtIOWdfDeviceDmaRxAsync(VirtIODevice *vdev, PVIRTIO_DMA_TRANSACTION_PARAMS params, + VirtIOWdfDmaTransactionCallback callback) { return VirtIOWdfDeviceDmaAsync(vdev, params, callback, WdfDmaDirectionReadFromDevice); } @@ -412,7 +390,7 @@ void VirtIOWdfDeviceDmaTxComplete(VirtIODevice *vdev, WDFDMATRANSACTION transact DerefTransaction(ctx); } -void VirtIOWdfDeviceDmaRxComplete(VirtIODevice* vdev, WDFDMATRANSACTION transaction, ULONG length) +void VirtIOWdfDeviceDmaRxComplete(VirtIODevice *vdev, WDFDMATRANSACTION transaction, ULONG length) { PVIRTIO_WDF_DRIVER pWdfDriver = vdev->DeviceContext; PVIRTIO_WDF_DMA_TRANSACTION_CONTEXT ctx = GetDmaTransactionContext(transaction); diff --git a/VirtIO/WDF/MemPortIO.c b/VirtIO/WDF/MemPortIO.c index 8c2f91ae6..3cc6d7c45 100644 --- a/VirtIO/WDF/MemPortIO.c +++ b/VirtIO/WDF/MemPortIO.c @@ -41,15 +41,13 @@ /* READ_REGISTER_* and WRITE_REGISTER_* take volatile ptr in newer DDKs */ #define _VOLATILE volatile -#define READ_PORT_OR_REGISTER(address, width) \ - (address & ~PORT_MASK) ? \ - READ_REGISTER_##width((_VOLATILE width *)address) : \ - READ_PORT_##width((width *)address) +#define READ_PORT_OR_REGISTER(address, width) \ + (address & ~PORT_MASK) ? READ_REGISTER_##width((_VOLATILE width *)address) : \ + READ_PORT_##width((width *)address) -#define WRITE_PORT_OR_REGISTER(address, width, value) \ - (address & ~PORT_MASK) ? \ - WRITE_REGISTER_##width((_VOLATILE width *)address, value) : \ - WRITE_PORT_##width((width *)address, value) +#define WRITE_PORT_OR_REGISTER(address, width, value) \ + (address & ~PORT_MASK) ? WRITE_REGISTER_##width((_VOLATILE width *)address, value) : \ + WRITE_PORT_##width((width *)address, value) u8 ReadVirtIODeviceByte(ULONG_PTR ulRegister) { diff --git a/VirtIO/WDF/PCI.c b/VirtIO/WDF/PCI.c index bd7320c50..43c1d591a 100644 --- a/VirtIO/WDF/PCI.c +++ b/VirtIO/WDF/PCI.c @@ -33,8 +33,7 @@ #include "VirtIOWdf.h" #include "private.h" -NTSTATUS PCIAllocBars(WDFCMRESLIST ResourcesTranslated, - PVIRTIO_WDF_DRIVER pWdfDriver) +NTSTATUS PCIAllocBars(WDFCMRESLIST ResourcesTranslated, PVIRTIO_WDF_DRIVER pWdfDriver) { PCM_PARTIAL_RESOURCE_DESCRIPTOR pResDescriptor; ULONG nInterrupts = 0, nMSIInterrupts = 0; @@ -44,59 +43,53 @@ NTSTATUS PCIAllocBars(WDFCMRESLIST ResourcesTranslated, PCI_COMMON_HEADER PCIHeader = { 0 }; /* read the PCI config header */ - if (pWdfDriver->PCIBus.GetBusData( - pWdfDriver->PCIBus.Context, - PCI_WHICHSPACE_CONFIG, - &PCIHeader, - 0, - sizeof(PCIHeader)) != sizeof(PCIHeader)) { + if (pWdfDriver->PCIBus.GetBusData(pWdfDriver->PCIBus.Context, PCI_WHICHSPACE_CONFIG, &PCIHeader, + 0, sizeof(PCIHeader)) != sizeof(PCIHeader)) { return STATUS_DEVICE_CONFIGURATION_ERROR; } - + for (i = 0; i < nListSize; i++) { pResDescriptor = WdfCmResourceListGetDescriptor(ResourcesTranslated, i); if (pResDescriptor) { switch (pResDescriptor->Type) { - case CmResourceTypePort: - case CmResourceTypeMemory: - pBar = (PVIRTIO_WDF_BAR)ExAllocatePoolUninitialized( - NonPagedPool, - sizeof(VIRTIO_WDF_BAR), - pWdfDriver->MemoryTag); - if (pBar == NULL) { - /* undo what we've done so far */ - PCIFreeBars(pWdfDriver); - return STATUS_INSUFFICIENT_RESOURCES; - } - - /* unfortunately WDF doesn't tell us BAR indices */ - pBar->iBar = virtio_get_bar_index(&PCIHeader, pResDescriptor->u.Memory.Start); - if (pBar->iBar < 0) { - /* undo what we've done so far */ - PCIFreeBars(pWdfDriver); - return STATUS_NOT_FOUND; - } - - pBar->bPortSpace = !!(pResDescriptor->Flags & CM_RESOURCE_PORT_IO); - pBar->BasePA = pResDescriptor->u.Memory.Start; - pBar->uLength = pResDescriptor->u.Memory.Length; - - if (pBar->bPortSpace) { - pBar->pBase = (PVOID)(ULONG_PTR)pBar->BasePA.QuadPart; - } else { - /* memory regions are mapped into the virtual memory space on demand */ - pBar->pBase = NULL; - } - PushEntryList(&pWdfDriver->PCIBars, &pBar->ListEntry); - break; - - case CmResourceTypeInterrupt: - nInterrupts++; - if (pResDescriptor->Flags & - (CM_RESOURCE_INTERRUPT_LATCHED | CM_RESOURCE_INTERRUPT_MESSAGE)) { - nMSIInterrupts++; - } - break; + case CmResourceTypePort: + case CmResourceTypeMemory: + pBar = (PVIRTIO_WDF_BAR)ExAllocatePoolUninitialized( + NonPagedPool, sizeof(VIRTIO_WDF_BAR), pWdfDriver->MemoryTag); + if (pBar == NULL) { + /* undo what we've done so far */ + PCIFreeBars(pWdfDriver); + return STATUS_INSUFFICIENT_RESOURCES; + } + + /* unfortunately WDF doesn't tell us BAR indices */ + pBar->iBar = virtio_get_bar_index(&PCIHeader, pResDescriptor->u.Memory.Start); + if (pBar->iBar < 0) { + /* undo what we've done so far */ + PCIFreeBars(pWdfDriver); + return STATUS_NOT_FOUND; + } + + pBar->bPortSpace = !!(pResDescriptor->Flags & CM_RESOURCE_PORT_IO); + pBar->BasePA = pResDescriptor->u.Memory.Start; + pBar->uLength = pResDescriptor->u.Memory.Length; + + if (pBar->bPortSpace) { + pBar->pBase = (PVOID)(ULONG_PTR)pBar->BasePA.QuadPart; + } else { + /* memory regions are mapped into the virtual memory space on demand */ + pBar->pBase = NULL; + } + PushEntryList(&pWdfDriver->PCIBars, &pBar->ListEntry); + break; + + case CmResourceTypeInterrupt: + nInterrupts++; + if (pResDescriptor->Flags & + (CM_RESOURCE_INTERRUPT_LATCHED | CM_RESOURCE_INTERRUPT_MESSAGE)) { + nMSIInterrupts++; + } + break; } } } @@ -121,19 +114,12 @@ void PCIFreeBars(PVIRTIO_WDF_DRIVER pWdfDriver) } } -int PCIReadConfig(PVIRTIO_WDF_DRIVER pWdfDriver, - int where, - void *buffer, - size_t length) +int PCIReadConfig(PVIRTIO_WDF_DRIVER pWdfDriver, int where, void *buffer, size_t length) { ULONG read; - read = pWdfDriver->PCIBus.GetBusData( - pWdfDriver->PCIBus.Context, - PCI_WHICHSPACE_CONFIG, - buffer, - where, - (ULONG)length); + read = pWdfDriver->PCIBus.GetBusData(pWdfDriver->PCIBus.Context, PCI_WHICHSPACE_CONFIG, buffer, + where, (ULONG)length); return (read == length ? 0 : -1); } @@ -147,10 +133,7 @@ NTSTATUS PCIRegisterInterrupt(WDFINTERRUPT Interrupt) status = STATUS_SUCCESS; } else { WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, VIRTIO_WDF_INTERRUPT_CONTEXT); - status = WdfObjectAllocateContext( - Interrupt, - &attributes, - &context); + status = WdfObjectAllocateContext(Interrupt, &attributes, &context); if (status == STATUS_OBJECT_NAME_EXISTS) { /* this is fine, we want to reuse the pre-existing context */ status = STATUS_SUCCESS; diff --git a/VirtIO/WDF/VirtIOWdf.c b/VirtIO/WDF/VirtIOWdf.c index 320f2d22e..cc2f16a7c 100644 --- a/VirtIO/WDF/VirtIOWdf.c +++ b/VirtIO/WDF/VirtIOWdf.c @@ -37,27 +37,21 @@ extern VirtIOSystemOps VirtIOWdfSystemOps; -NTSTATUS VirtIOWdfInitialize(PVIRTIO_WDF_DRIVER pWdfDriver, - WDFDEVICE Device, - WDFCMRESLIST ResourcesTranslated, - WDFINTERRUPT ConfigInterrupt, +NTSTATUS VirtIOWdfInitialize(PVIRTIO_WDF_DRIVER pWdfDriver, WDFDEVICE Device, + WDFCMRESLIST ResourcesTranslated, WDFINTERRUPT ConfigInterrupt, ULONG MemoryTag) { NTSTATUS status = STATUS_SUCCESS; WDF_DMA_ENABLER_CONFIG dmaEnablerConfig; - WDF_OBJECT_ATTRIBUTES attributes; + WDF_OBJECT_ATTRIBUTES attributes; RtlZeroMemory(pWdfDriver, sizeof(*pWdfDriver)); pWdfDriver->MemoryTag = MemoryTag; /* get the PCI bus interface */ - status = WdfFdoQueryForInterface( - Device, - &GUID_BUS_INTERFACE_STANDARD, - (PINTERFACE)&pWdfDriver->PCIBus, - sizeof(pWdfDriver->PCIBus), - 1 /* version */, - NULL); + status = WdfFdoQueryForInterface(Device, &GUID_BUS_INTERFACE_STANDARD, + (PINTERFACE)&pWdfDriver->PCIBus, sizeof(pWdfDriver->PCIBus), + 1 /* version */, NULL); if (!NT_SUCCESS(status)) { return status; } @@ -77,11 +71,12 @@ NTSTATUS VirtIOWdfInitialize(PVIRTIO_WDF_DRIVER pWdfDriver, /* set max transfer size to 256M, should be enough for any purpose */ /* number of SG fragments is unlimited */ WDF_DMA_ENABLER_CONFIG_INIT(&dmaEnablerConfig, WdfDmaProfileScatterGather64Duplex, 0xFFFFFFF); - status = WdfDmaEnablerCreate(Device, &dmaEnablerConfig, WDF_NO_OBJECT_ATTRIBUTES, &pWdfDriver->DmaEnabler); + status = WdfDmaEnablerCreate(Device, &dmaEnablerConfig, WDF_NO_OBJECT_ATTRIBUTES, + &pWdfDriver->DmaEnabler); if (NT_SUCCESS(status)) { WDF_OBJECT_ATTRIBUTES_INIT(&attributes); DPrintf(0, "%s DMA enabler ready (alignment %d), pWdfDriver %p\n", __FUNCTION__, - WdfDeviceGetAlignmentRequirement(Device) + 1, pWdfDriver); + WdfDeviceGetAlignmentRequirement(Device) + 1, pWdfDriver); attributes.ParentObject = Device; status = WdfCollectionCreate(&attributes, &pWdfDriver->MemoryBlockCollection); } @@ -95,11 +90,8 @@ NTSTATUS VirtIOWdfInitialize(PVIRTIO_WDF_DRIVER pWdfDriver, } /* initialize the underlying VirtIODevice */ - status = virtio_device_initialize( - &pWdfDriver->VIODevice, - &VirtIOWdfSystemOps, - pWdfDriver, - pWdfDriver->nMSIInterrupts > 0); + status = virtio_device_initialize(&pWdfDriver->VIODevice, &VirtIOWdfSystemOps, pWdfDriver, + pWdfDriver->nMSIInterrupts > 0); if (!NT_SUCCESS(status)) { PCIFreeBars(pWdfDriver); } @@ -114,8 +106,7 @@ ULONGLONG VirtIOWdfGetDeviceFeatures(PVIRTIO_WDF_DRIVER pWdfDriver) return virtio_get_features(&pWdfDriver->VIODevice); } -NTSTATUS VirtIOWdfSetDriverFeatures(PVIRTIO_WDF_DRIVER pWdfDriver, - ULONGLONG uPrivateFeaturesOn, +NTSTATUS VirtIOWdfSetDriverFeatures(PVIRTIO_WDF_DRIVER pWdfDriver, ULONGLONG uPrivateFeaturesOn, ULONGLONG uFeaturesOff) { ULONGLONG uFeatures = 0, uDeviceFeatures = VirtIOWdfGetDeviceFeatures(pWdfDriver); @@ -135,8 +126,8 @@ NTSTATUS VirtIOWdfSetDriverFeatures(PVIRTIO_WDF_DRIVER pWdfDriver, } if ((uDeviceFeatures & uPrivateFeaturesOn) != uPrivateFeaturesOn) { - DPrintf(0, "%s(%s) FAILED features %I64X != %I64X\n", __FUNCTION__, - drvTag, uPrivateFeaturesOn, (uDeviceFeatures & uPrivateFeaturesOn)); + DPrintf(0, "%s(%s) FAILED features %I64X != %I64X\n", __FUNCTION__, drvTag, + uPrivateFeaturesOn, (uDeviceFeatures & uPrivateFeaturesOn)); return STATUS_INVALID_PARAMETER; } @@ -183,10 +174,8 @@ static NTSTATUS VirtIOWdfFinalizeFeatures(PVIRTIO_WDF_DRIVER pWdfDriver) return status; } -NTSTATUS VirtIOWdfInitQueues(PVIRTIO_WDF_DRIVER pWdfDriver, - ULONG nQueues, - struct virtqueue **pQueues, - PVIRTIO_WDF_QUEUE_PARAM pQueueParams) +NTSTATUS VirtIOWdfInitQueues(PVIRTIO_WDF_DRIVER pWdfDriver, ULONG nQueues, + struct virtqueue **pQueues, PVIRTIO_WDF_QUEUE_PARAM pQueueParams) { NTSTATUS status; ULONG i; @@ -207,17 +196,13 @@ NTSTATUS VirtIOWdfInitQueues(PVIRTIO_WDF_DRIVER pWdfDriver, /* find and initialize queues */ pWdfDriver->pQueueParams = pQueueParams; - status = virtio_find_queues( - &pWdfDriver->VIODevice, - nQueues, - pQueues); + status = virtio_find_queues(&pWdfDriver->VIODevice, nQueues, pQueues); pWdfDriver->pQueueParams = NULL; return status; } -NTSTATUS VirtIOWdfInitQueuesCB(PVIRTIO_WDF_DRIVER pWdfDriver, - ULONG nQueues, +NTSTATUS VirtIOWdfInitQueuesCB(PVIRTIO_WDF_DRIVER pWdfDriver, ULONG nQueues, VirtIOWdfGetQueueParamCallback pQueueParamFunc, VirtIOWdfSetQueueCallback pSetQueueFunc) { @@ -309,28 +294,14 @@ NTSTATUS VirtIOWdfDestroyQueues(PVIRTIO_WDF_DRIVER pWdfDriver) return STATUS_SUCCESS; } -void VirtIOWdfDeviceGet(PVIRTIO_WDF_DRIVER pWdfDriver, - ULONG offset, - PVOID buf, - ULONG len) +void VirtIOWdfDeviceGet(PVIRTIO_WDF_DRIVER pWdfDriver, ULONG offset, PVOID buf, ULONG len) { - virtio_get_config( - &pWdfDriver->VIODevice, - offset, - buf, - len); + virtio_get_config(&pWdfDriver->VIODevice, offset, buf, len); } -void VirtIOWdfDeviceSet(PVIRTIO_WDF_DRIVER pWdfDriver, - ULONG offset, - CONST PVOID buf, - ULONG len) +void VirtIOWdfDeviceSet(PVIRTIO_WDF_DRIVER pWdfDriver, ULONG offset, CONST PVOID buf, ULONG len) { - virtio_set_config( - &pWdfDriver->VIODevice, - offset, - buf, - len); + virtio_set_config(&pWdfDriver->VIODevice, offset, buf, len); } UCHAR VirtIOWdfGetISRStatus(PVIRTIO_WDF_DRIVER pWdfDriver) diff --git a/VirtIO/WDF/VirtIOWdf.h b/VirtIO/WDF/VirtIOWdf.h index b4355faef..d3d1bfd7e 100644 --- a/VirtIO/WDF/VirtIOWdf.h +++ b/VirtIO/WDF/VirtIOWdf.h @@ -37,49 +37,44 @@ /* Configures a virtqueue, see VirtIOWdfInitQueues. */ typedef struct virtio_wdf_queue_param { /* interrupt associated with the queue */ - WDFINTERRUPT Interrupt; -} VIRTIO_WDF_QUEUE_PARAM , *PVIRTIO_WDF_QUEUE_PARAM; + WDFINTERRUPT Interrupt; +} VIRTIO_WDF_QUEUE_PARAM, *PVIRTIO_WDF_QUEUE_PARAM; /* Data associated with a WDF virtio driver, usually declared as * a field in the driver's context structure and treated opaque. */ typedef struct virtio_wdf_driver { - VirtIODevice VIODevice; + VirtIODevice VIODevice; - ULONG MemoryTag; - ULONGLONG uFeatures; + ULONG MemoryTag; + ULONGLONG uFeatures; - BUS_INTERFACE_STANDARD PCIBus; - SINGLE_LIST_ENTRY PCIBars; + BUS_INTERFACE_STANDARD PCIBus; + SINGLE_LIST_ENTRY PCIBars; - ULONG nInterrupts; - ULONG nMSIInterrupts; + ULONG nInterrupts; + ULONG nMSIInterrupts; - WDFINTERRUPT ConfigInterrupt; + WDFINTERRUPT ConfigInterrupt; PVIRTIO_WDF_QUEUE_PARAM pQueueParams; - WDFDMAENABLER DmaEnabler; - WDFCOLLECTION MemoryBlockCollection; - WDFSPINLOCK DmaSpinlock; + WDFDMAENABLER DmaEnabler; + WDFCOLLECTION MemoryBlockCollection; + WDFSPINLOCK DmaSpinlock; - } VIRTIO_WDF_DRIVER, *PVIRTIO_WDF_DRIVER; /* Queue discovery callbacks used by VirtIOWdfInitQueuesCB. */ -typedef void (*VirtIOWdfGetQueueParamCallback)(PVIRTIO_WDF_DRIVER pWdfDriver, - ULONG uQueueIndex, +typedef void (*VirtIOWdfGetQueueParamCallback)(PVIRTIO_WDF_DRIVER pWdfDriver, ULONG uQueueIndex, PVIRTIO_WDF_QUEUE_PARAM pQueueParam); -typedef void (*VirtIOWdfSetQueueCallback)(PVIRTIO_WDF_DRIVER pWdfDriver, - ULONG uQueueIndex, +typedef void (*VirtIOWdfSetQueueCallback)(PVIRTIO_WDF_DRIVER pWdfDriver, ULONG uQueueIndex, struct virtqueue *pQueue); /* Initializes the VIRTIO_WDF_DRIVER context, called from driver's * EvtDevicePrepareHardware callback. */ -NTSTATUS VirtIOWdfInitialize(PVIRTIO_WDF_DRIVER pWdfDriver, - WDFDEVICE Device, - WDFCMRESLIST ResourcesTranslated, - WDFINTERRUPT ConfigInterrupt, +NTSTATUS VirtIOWdfInitialize(PVIRTIO_WDF_DRIVER pWdfDriver, WDFDEVICE Device, + WDFCMRESLIST ResourcesTranslated, WDFINTERRUPT ConfigInterrupt, ULONG MemoryTag); /* Device/driver feature negotiation routines. These can be called from @@ -94,8 +89,7 @@ NTSTATUS VirtIOWdfInitialize(PVIRTIO_WDF_DRIVER pWdfDriver, * call to VirtIOWdfInitQueues or VirtIOWdfInitQueuesCB */ ULONGLONG VirtIOWdfGetDeviceFeatures(PVIRTIO_WDF_DRIVER pWdfDriver); -NTSTATUS VirtIOWdfSetDriverFeatures(PVIRTIO_WDF_DRIVER pWdfDriver, - ULONGLONG uPrivateFeaturesOn, +NTSTATUS VirtIOWdfSetDriverFeatures(PVIRTIO_WDF_DRIVER pWdfDriver, ULONGLONG uPrivateFeaturesOn, ULONGLONG uFeaturesOff); /* Queue discovery entry points. Must be called after each device reset as @@ -104,12 +98,9 @@ NTSTATUS VirtIOWdfSetDriverFeatures(PVIRTIO_WDF_DRIVER pWdfDriver, * The regular version uses caller-allocated arrays for the same. They are * functionally equivalent. */ -NTSTATUS VirtIOWdfInitQueues(PVIRTIO_WDF_DRIVER pWdfDriver, - ULONG nQueues, - struct virtqueue **pQueues, - PVIRTIO_WDF_QUEUE_PARAM pQueueParams); -NTSTATUS VirtIOWdfInitQueuesCB(PVIRTIO_WDF_DRIVER pWdfDriver, - ULONG nQueues, +NTSTATUS VirtIOWdfInitQueues(PVIRTIO_WDF_DRIVER pWdfDriver, ULONG nQueues, + struct virtqueue **pQueues, PVIRTIO_WDF_QUEUE_PARAM pQueueParams); +NTSTATUS VirtIOWdfInitQueuesCB(PVIRTIO_WDF_DRIVER pWdfDriver, ULONG nQueues, VirtIOWdfGetQueueParamCallback pQueueParamFunc, VirtIOWdfSetQueueCallback pSetQueueFunc); @@ -141,14 +132,8 @@ UCHAR VirtIOWdfGetISRStatus(PVIRTIO_WDF_DRIVER pWdfDriver); * config change is desired, a valid WDFINTERRUPT should be passed to * VirtIOWdfInitialize. */ -void VirtIOWdfDeviceGet(PVIRTIO_WDF_DRIVER pWdfDriver, - ULONG offset, - PVOID buf, - ULONG len); -void VirtIOWdfDeviceSet(PVIRTIO_WDF_DRIVER pWdfDriver, - ULONG offset, - CONST PVOID buf, - ULONG len); +void VirtIOWdfDeviceGet(PVIRTIO_WDF_DRIVER pWdfDriver, ULONG offset, PVOID buf, ULONG len); +void VirtIOWdfDeviceSet(PVIRTIO_WDF_DRIVER pWdfDriver, ULONG offset, CONST PVOID buf, ULONG len); /* DMA memory allocations */ @@ -164,14 +149,13 @@ void VirtIOWdfDeviceFreeDmaMemory(VirtIODevice *vdev, void *va); /* PASSIVE, suitable for D0 exit */ void VirtIOWdfDeviceFreeDmaMemoryByTag(VirtIODevice *vdev, ULONG groupTag); -typedef struct virtio_dma_transaction_params -{ +typedef struct virtio_dma_transaction_params { /* IN */ PVOID param1; /* scratch field to be used by the callback */ PVOID param2; - WDFREQUEST req; /* NULL or Write request */ - PVOID buffer; /* NULL or buffer with data to be sent */ - ULONG size; /* amount of data to be copied from buffer */ + WDFREQUEST req; /* NULL or Write request */ + PVOID buffer; /* NULL or buffer with data to be sent */ + ULONG size; /* amount of data to be copied from buffer */ ULONG allocationTag; /* used for reallocation */ /* callback */ WDFDMATRANSACTION transaction; @@ -195,30 +179,28 @@ typedef BOOLEAN (*VirtIOWdfDmaTransactionCallback)(PVIRTIO_DMA_TRANSACTION_PARAM * with cancelled request which SG is enqueued in TX virtq * IRQL: <= DISPATCH, callback is called on DISPATCH */ -BOOLEAN VirtIOWdfDeviceDmaTxAsync(VirtIODevice *vdev, - PVIRTIO_DMA_TRANSACTION_PARAMS params, - VirtIOWdfDmaTransactionCallback); -BOOLEAN VirtIOWdfDeviceDmaRxAsync(VirtIODevice* vdev, - PVIRTIO_DMA_TRANSACTION_PARAMS params, - VirtIOWdfDmaTransactionCallback); +BOOLEAN VirtIOWdfDeviceDmaTxAsync(VirtIODevice *vdev, PVIRTIO_DMA_TRANSACTION_PARAMS params, + VirtIOWdfDmaTransactionCallback); +BOOLEAN VirtIOWdfDeviceDmaRxAsync(VirtIODevice *vdev, PVIRTIO_DMA_TRANSACTION_PARAMS params, + VirtIOWdfDmaTransactionCallback); /* <= DISPATCH transaction = VIRTIO_DMA_TRANSACTION_PARAMS.transaction */ void VirtIOWdfDeviceDmaTxComplete(VirtIODevice *vdev, WDFDMATRANSACTION transaction); /* <= DISPATCH transaction = VIRTIO_DMA_TRANSACTION_PARAMS.transaction */ -void VirtIOWdfDeviceDmaRxComplete(VirtIODevice* vdev, WDFDMATRANSACTION transaction, ULONG length); +void VirtIOWdfDeviceDmaRxComplete(VirtIODevice *vdev, WDFDMATRANSACTION transaction, ULONG length); -typedef struct virtio_dma_memory_sliced -{ - PVOID (*get_slice)(struct virtio_dma_memory_sliced *, PHYSICAL_ADDRESS *ppa); - void (*return_slice)(struct virtio_dma_memory_sliced *, PVOID va); - void (*destroy)(struct virtio_dma_memory_sliced *); +typedef struct virtio_dma_memory_sliced { + PVOID (*get_slice)(struct virtio_dma_memory_sliced *, PHYSICAL_ADDRESS *ppa); + void (*return_slice)(struct virtio_dma_memory_sliced *, PVOID va); + void (*destroy)(struct virtio_dma_memory_sliced *); /* private area */ - PHYSICAL_ADDRESS pa; - PVIRTIO_WDF_DRIVER drv; - PVOID va; - RTL_BITMAP bitmap; - ULONG slice; - ULONG bitmap_buffer[1]; -}VIRTIO_DMA_MEMORY_SLICED, *PVIRTIO_DMA_MEMORY_SLICED; - -PVIRTIO_DMA_MEMORY_SLICED VirtIOWdfDeviceAllocDmaMemorySliced(VirtIODevice *vdev, size_t blockSize, ULONG sliceSize); + PHYSICAL_ADDRESS pa; + PVIRTIO_WDF_DRIVER drv; + PVOID va; + RTL_BITMAP bitmap; + ULONG slice; + ULONG bitmap_buffer[1]; +} VIRTIO_DMA_MEMORY_SLICED, *PVIRTIO_DMA_MEMORY_SLICED; + +PVIRTIO_DMA_MEMORY_SLICED VirtIOWdfDeviceAllocDmaMemorySliced(VirtIODevice *vdev, size_t blockSize, + ULONG sliceSize); diff --git a/VirtIO/WDF/private.h b/VirtIO/WDF/private.h index 764b4cb87..1a6c14cbf 100644 --- a/VirtIO/WDF/private.h +++ b/VirtIO/WDF/private.h @@ -38,11 +38,11 @@ typedef struct virtio_wdf_bar { SINGLE_LIST_ENTRY ListEntry; - int iBar; - PHYSICAL_ADDRESS BasePA; - ULONG uLength; - PVOID pBase; - bool bPortSpace; + int iBar; + PHYSICAL_ADDRESS BasePA; + ULONG uLength; + PVOID pBase; + bool bPortSpace; } VIRTIO_WDF_BAR, *PVIRTIO_WDF_BAR; typedef struct virtio_wdf_interrupt_context { @@ -52,44 +52,40 @@ typedef struct virtio_wdf_interrupt_context { * report the right MSI message number to the virtio device when * re-initializing it and it may stop working. */ - USHORT uMessageNumber; - bool bMessageNumberSet; + USHORT uMessageNumber; + bool bMessageNumberSet; } VIRTIO_WDF_INTERRUPT_CONTEXT, *PVIRTIO_WDF_INTERRUPT_CONTEXT; WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(VIRTIO_WDF_INTERRUPT_CONTEXT, GetInterruptContext) -NTSTATUS PCIAllocBars(WDFCMRESLIST ResourcesTranslated, - PVIRTIO_WDF_DRIVER pWdfDriver); +NTSTATUS PCIAllocBars(WDFCMRESLIST ResourcesTranslated, PVIRTIO_WDF_DRIVER pWdfDriver); void PCIFreeBars(PVIRTIO_WDF_DRIVER pWdfDriver); -int PCIReadConfig(PVIRTIO_WDF_DRIVER pWdfDriver, - int where, - void *buffer, - size_t length); +int PCIReadConfig(PVIRTIO_WDF_DRIVER pWdfDriver, int where, void *buffer, size_t length); NTSTATUS PCIRegisterInterrupt(WDFINTERRUPT Interrupt); u16 PCIGetMSIInterruptVector(WDFINTERRUPT Interrupt); typedef struct virtio_wdf_memory_block_context { - PVOID pVirtualAddress; - PHYSICAL_ADDRESS PhysicalAddress; - WDFCOMMONBUFFER WdfBuffer; - size_t Length; - ULONG groupTag; - BOOLEAN bToBeDeleted; + PVOID pVirtualAddress; + PHYSICAL_ADDRESS PhysicalAddress; + WDFCOMMONBUFFER WdfBuffer; + size_t Length; + ULONG groupTag; + BOOLEAN bToBeDeleted; } VIRTIO_WDF_MEMORY_BLOCK_CONTEXT, *PVIRTIO_WDF_MEMORY_BLOCK_CONTEXT; WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(VIRTIO_WDF_MEMORY_BLOCK_CONTEXT, GetMemoryBlockContext) typedef struct virtio_wdf_dma_transaction_context { - VIRTIO_DMA_TRANSACTION_PARAMS parameters; + VIRTIO_DMA_TRANSACTION_PARAMS parameters; VirtIOWdfDmaTransactionCallback callback; - PMDL mdl; - PVOID buffer; - LONG refCount; - WDF_DMA_DIRECTION direction; + PMDL mdl; + PVOID buffer; + LONG refCount; + WDF_DMA_DIRECTION direction; } VIRTIO_WDF_DMA_TRANSACTION_CONTEXT, *PVIRTIO_WDF_DMA_TRANSACTION_CONTEXT; WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(VIRTIO_WDF_DMA_TRANSACTION_CONTEXT, GetDmaTransactionContext) diff --git a/VirtIO/kdebugprint.h b/VirtIO/kdebugprint.h index 35d2b1aa2..b05e4eac4 100644 --- a/VirtIO/kdebugprint.h +++ b/VirtIO/kdebugprint.h @@ -5,7 +5,11 @@ extern int bDebugPrint; typedef void (*tDebugPrintFunc)(const char *format, ...); extern tDebugPrintFunc VirtioDebugPrintProc; -#define DPrintf(Level, MSG, ...) if ((!bDebugPrint) || Level > virtioDebugLevel) {} else VirtioDebugPrintProc(MSG, __VA_ARGS__) +#define DPrintf(Level, MSG, ...) \ + if ((!bDebugPrint) || Level > virtioDebugLevel) { \ + } else \ + VirtioDebugPrintProc(MSG, __VA_ARGS__) -#define DEBUG_ENTRY(level) DPrintf(level, "[%s]=>\n", __FUNCTION__) -#define DEBUG_EXIT_STATUS(level, status) DPrintf((status == NDIS_STATUS_SUCCESS ? level : 0), "[%s]<=0x%X\n", __FUNCTION__, (status)) +#define DEBUG_ENTRY(level) DPrintf(level, "[%s]=>\n", __FUNCTION__) +#define DEBUG_EXIT_STATUS(level, status) \ + DPrintf((status == NDIS_STATUS_SUCCESS ? level : 0), "[%s]<=0x%X\n", __FUNCTION__, (status)) diff --git a/VirtIO/linux/types.h b/VirtIO/linux/types.h index 3eb050005..64130878c 100644 --- a/VirtIO/linux/types.h +++ b/VirtIO/linux/types.h @@ -4,16 +4,16 @@ #define __bitwise__ #define __attribute__(x) -#define u8 unsigned char -#define u16 unsigned short -#define u32 unsigned long -#define u64 ULONGLONG +#define u8 unsigned char +#define u16 unsigned short +#define u32 unsigned long +#define u64 ULONGLONG -#define __u8 unsigned char -#define __u16 unsigned short +#define __u8 unsigned char +#define __u16 unsigned short #define __le16 unsigned short -#define __u32 unsigned long +#define __u32 unsigned long #define __le32 unsigned long -#define __u64 ULONGLONG +#define __u64 ULONGLONG #endif /* _LINUX_TYPES_H */ diff --git a/VirtIO/linux/virtio_config.h b/VirtIO/linux/virtio_config.h index e7a89e88d..88c0b6711 100644 --- a/VirtIO/linux/virtio_config.h +++ b/VirtIO/linux/virtio_config.h @@ -32,48 +32,47 @@ /* Status byte for guest to report progress, and synchronize features. */ /* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */ -#define VIRTIO_CONFIG_S_ACKNOWLEDGE 1 +#define VIRTIO_CONFIG_S_ACKNOWLEDGE 1 /* We have found a driver for the device. */ -#define VIRTIO_CONFIG_S_DRIVER 2 +#define VIRTIO_CONFIG_S_DRIVER 2 /* Driver has used its parts of the config, and is happy */ -#define VIRTIO_CONFIG_S_DRIVER_OK 4 +#define VIRTIO_CONFIG_S_DRIVER_OK 4 /* Driver has finished configuring features */ -#define VIRTIO_CONFIG_S_FEATURES_OK 8 +#define VIRTIO_CONFIG_S_FEATURES_OK 8 /* Device entered invalid state, driver SHOULD reset it */ -#define VIRTIO_CONFIG_S_NEEDS_RESET 0x40 +#define VIRTIO_CONFIG_S_NEEDS_RESET 0x40 /* We've given up on this device. */ -#define VIRTIO_CONFIG_S_FAILED 0x80 +#define VIRTIO_CONFIG_S_FAILED 0x80 /* virtio library features bits */ - /* Some virtio feature bits (currently bits 28 through 31) are reserved for the * transport being used (eg. virtio_ring), the rest are per-device feature * bits. */ -#define VIRTIO_TRANSPORT_F_START 28 -#define VIRTIO_TRANSPORT_F_END 32 +#define VIRTIO_TRANSPORT_F_START 28 +#define VIRTIO_TRANSPORT_F_END 32 /* Do we get callbacks when the ring is completely used, even if we've * suppressed them? */ -#define VIRTIO_F_NOTIFY_ON_EMPTY 24 +#define VIRTIO_F_NOTIFY_ON_EMPTY 24 /* Can the device handle any descriptor layout? */ -#define VIRTIO_F_ANY_LAYOUT 27 +#define VIRTIO_F_ANY_LAYOUT 27 /* v1.0 compliant. */ -#define VIRTIO_F_VERSION_1 32 +#define VIRTIO_F_VERSION_1 32 -#define VIRTIO_F_ACCESS_PLATFORM 33 +#define VIRTIO_F_ACCESS_PLATFORM 33 /* This feature indicates support for the packed virtqueue layout. */ -#define VIRTIO_F_RING_PACKED 34 +#define VIRTIO_F_RING_PACKED 34 /* * This feature indicates that memory accesses by the driver and the * device are ordered in a way described by the platform. */ -#define VIRTIO_F_ORDER_PLATFORM 36 +#define VIRTIO_F_ORDER_PLATFORM 36 // if this number is not equal to desc size, queue creation fails -#define SIZE_OF_SINGLE_INDIRECT_DESC 16 +#define SIZE_OF_SINGLE_INDIRECT_DESC 16 #endif /* _UAPI_LINUX_VIRTIO_CONFIG_H */ diff --git a/VirtIO/osdep.h b/VirtIO/osdep.h index 95bad27b6..aa1929e21 100644 --- a/VirtIO/osdep.h +++ b/VirtIO/osdep.h @@ -20,14 +20,15 @@ #define ENOSPC 28 #endif +#define inline __forceinline + #if !defined(__cplusplus) && !defined(bool) // Important note: in MSFT C++ bool length is 1 bytes // C++ does not define length of bool // inconsistent definition of 'bool' may create compatibility problems -#define bool u8 +#define bool u8 #define false FALSE -#define true TRUE +#define true TRUE #endif -#define inline __forceinline #define SMP_CACHE_BYTES 64 diff --git a/VirtIO/virtio_pci.h b/VirtIO/virtio_pci.h index 92599545d..3fa53a7ba 100644 --- a/VirtIO/virtio_pci.h +++ b/VirtIO/virtio_pci.h @@ -45,118 +45,117 @@ #ifndef VIRTIO_PCI_NO_LEGACY /* A 32-bit r/o bitmask of the features supported by the host */ -#define VIRTIO_PCI_HOST_FEATURES 0 +#define VIRTIO_PCI_HOST_FEATURES 0 /* A 32-bit r/w bitmask of features activated by the guest */ -#define VIRTIO_PCI_GUEST_FEATURES 4 +#define VIRTIO_PCI_GUEST_FEATURES 4 /* A 32-bit r/w PFN for the currently selected queue */ -#define VIRTIO_PCI_QUEUE_PFN 8 +#define VIRTIO_PCI_QUEUE_PFN 8 /* A 16-bit r/o queue size for the currently selected queue */ -#define VIRTIO_PCI_QUEUE_NUM 12 +#define VIRTIO_PCI_QUEUE_NUM 12 /* A 16-bit r/w queue selector */ -#define VIRTIO_PCI_QUEUE_SEL 14 +#define VIRTIO_PCI_QUEUE_SEL 14 /* A 16-bit r/w queue notifier */ -#define VIRTIO_PCI_QUEUE_NOTIFY 16 +#define VIRTIO_PCI_QUEUE_NOTIFY 16 /* An 8-bit device status register. */ -#define VIRTIO_PCI_STATUS 18 +#define VIRTIO_PCI_STATUS 18 /* An 8-bit r/o interrupt status register. Reading the value will return the * current contents of the ISR and will also clear it. This is effectively * a read-and-acknowledge. */ -#define VIRTIO_PCI_ISR 19 +#define VIRTIO_PCI_ISR 19 /* MSI-X registers: only enabled if MSI-X is enabled. */ /* A 16-bit vector for configuration changes. */ -#define VIRTIO_MSI_CONFIG_VECTOR 20 +#define VIRTIO_MSI_CONFIG_VECTOR 20 /* A 16-bit vector for selected queue notifications. */ -#define VIRTIO_MSI_QUEUE_VECTOR 22 +#define VIRTIO_MSI_QUEUE_VECTOR 22 /* The remaining space is defined by each driver as the per-driver * configuration space */ #define VIRTIO_PCI_CONFIG_OFF(msix_enabled) ((msix_enabled) ? 24 : 20) /* Deprecated: please use VIRTIO_PCI_CONFIG_OFF instead */ -#define VIRTIO_PCI_CONFIG(msix_enabled) VIRTIO_PCI_CONFIG_OFF(msix_enabled) +#define VIRTIO_PCI_CONFIG(msix_enabled) VIRTIO_PCI_CONFIG_OFF(msix_enabled) /* How many bits to shift physical queue address written to QUEUE_PFN. * 12 is historical, and due to x86 page size. */ -#define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12 +#define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12 /* The alignment to use between consumer and producer parts of vring. * x86 pagesize again. */ -#define VIRTIO_PCI_VRING_ALIGN 4096 +#define VIRTIO_PCI_VRING_ALIGN 4096 #endif /* VIRTIO_PCI_NO_LEGACY */ /* The bit of the ISR which indicates a device configuration change. */ -#define VIRTIO_PCI_ISR_CONFIG 0x2 +#define VIRTIO_PCI_ISR_CONFIG 0x2 /* Vector value used to disable MSI for queue */ -#define VIRTIO_MSI_NO_VECTOR 0xffff +#define VIRTIO_MSI_NO_VECTOR 0xffff /* IDs for different capabilities. Must all exist. */ /* Common configuration */ -#define VIRTIO_PCI_CAP_COMMON_CFG 1 +#define VIRTIO_PCI_CAP_COMMON_CFG 1 /* Notifications */ -#define VIRTIO_PCI_CAP_NOTIFY_CFG 2 +#define VIRTIO_PCI_CAP_NOTIFY_CFG 2 /* ISR access */ -#define VIRTIO_PCI_CAP_ISR_CFG 3 +#define VIRTIO_PCI_CAP_ISR_CFG 3 /* Device specific configuration */ -#define VIRTIO_PCI_CAP_DEVICE_CFG 4 +#define VIRTIO_PCI_CAP_DEVICE_CFG 4 /* PCI configuration access */ -#define VIRTIO_PCI_CAP_PCI_CFG 5 +#define VIRTIO_PCI_CAP_PCI_CFG 5 /* This is the PCI capability header: */ struct virtio_pci_cap { - __u8 cap_vndr; /* Generic PCI field: PCI_CAPABILITY_ID_VENDOR_SPECIFIC */ - __u8 cap_next; /* Generic PCI field: next ptr. */ - __u8 cap_len; /* Generic PCI field: capability length */ - __u8 cfg_type; /* Identifies the structure. */ - __u8 bar; /* Where to find it. */ - __u8 padding[3]; /* Pad to full dword. */ - __le32 offset; /* Offset within bar. */ - __le32 length; /* Length of the structure, in bytes. */ + __u8 cap_vndr; /* Generic PCI field: PCI_CAPABILITY_ID_VENDOR_SPECIFIC */ + __u8 cap_next; /* Generic PCI field: next ptr. */ + __u8 cap_len; /* Generic PCI field: capability length */ + __u8 cfg_type; /* Identifies the structure. */ + __u8 bar; /* Where to find it. */ + __u8 padding[3]; /* Pad to full dword. */ + __le32 offset; /* Offset within bar. */ + __le32 length; /* Length of the structure, in bytes. */ }; struct virtio_pci_notify_cap { struct virtio_pci_cap cap; - __le32 notify_off_multiplier; /* Multiplier for queue_notify_off. */ + __le32 notify_off_multiplier; /* Multiplier for queue_notify_off. */ }; /* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */ struct virtio_pci_common_cfg { /* About the whole device. */ - __le32 device_feature_select; /* read-write */ - __le32 device_feature; /* read-only */ - __le32 guest_feature_select; /* read-write */ - __le32 guest_feature; /* read-write */ - __le16 msix_config; /* read-write */ - __le16 num_queues; /* read-only */ - __u8 device_status; /* read-write */ - __u8 config_generation; /* read-only */ + __le32 device_feature_select; /* read-write */ + __le32 device_feature; /* read-only */ + __le32 guest_feature_select; /* read-write */ + __le32 guest_feature; /* read-write */ + __le16 msix_config; /* read-write */ + __le16 num_queues; /* read-only */ + __u8 device_status; /* read-write */ + __u8 config_generation; /* read-only */ /* About a specific virtqueue. */ - __le16 queue_select; /* read-write */ - __le16 queue_size; /* read-write, power of 2. */ - __le16 queue_msix_vector; /* read-write */ - __le16 queue_enable; /* read-write */ - __le16 queue_notify_off; /* read-only */ - __le32 queue_desc_lo; /* read-write */ - __le32 queue_desc_hi; /* read-write */ - __le32 queue_avail_lo; /* read-write */ - __le32 queue_avail_hi; /* read-write */ - __le32 queue_used_lo; /* read-write */ - __le32 queue_used_hi; /* read-write */ + __le16 queue_select; /* read-write */ + __le16 queue_size; /* read-write, power of 2. */ + __le16 queue_msix_vector; /* read-write */ + __le16 queue_enable; /* read-write */ + __le16 queue_notify_off; /* read-only */ + __le32 queue_desc_lo; /* read-write */ + __le32 queue_desc_hi; /* read-write */ + __le32 queue_avail_lo; /* read-write */ + __le32 queue_avail_hi; /* read-write */ + __le32 queue_used_lo; /* read-write */ + __le32 queue_used_hi; /* read-write */ }; #define MAX_QUEUES_PER_DEVICE_DEFAULT 8 -typedef struct virtio_queue_info -{ +typedef struct virtio_queue_info { /* the actual virtqueue */ struct virtqueue *vq; /* the number of entries in the queue */ @@ -198,8 +197,7 @@ typedef struct virtio_system_ops { struct virtio_device; typedef struct virtio_device VirtIODevice; -struct virtio_device_ops -{ +struct virtio_device_ops { // read/write device config and read config generation counter void (*get_config)(VirtIODevice *vdev, unsigned offset, void *buf, unsigned len); void (*set_config)(VirtIODevice *vdev, unsigned offset, const void *buf, unsigned len); @@ -219,22 +217,20 @@ struct virtio_device_ops u16 (*set_queue_vector)(struct virtqueue *vq, u16 vector); // query virtual queue size and memory requirements - NTSTATUS (*query_queue_alloc)(VirtIODevice *vdev, - unsigned index, unsigned short *pNumEntries, - unsigned long *pRingSize, - unsigned long *pHeapSize); + NTSTATUS(*query_queue_alloc) + (VirtIODevice *vdev, unsigned index, unsigned short *pNumEntries, unsigned long *pRingSize, + unsigned long *pHeapSize); // allocate and initialize a queue - NTSTATUS (*setup_queue)(struct virtqueue **queue, - VirtIODevice *vdev, VirtIOQueueInfo *info, - unsigned idx, u16 msix_vec); + NTSTATUS(*setup_queue) + (struct virtqueue **queue, VirtIODevice *vdev, VirtIOQueueInfo *info, unsigned idx, + u16 msix_vec); // tear down and deallocate a queue void (*delete_queue)(VirtIOQueueInfo *info); }; -struct virtio_device -{ +struct virtio_device { // the I/O port BAR of the PCI device (legacy virtio devices only) ULONG_PTR addr; @@ -284,10 +280,8 @@ struct virtio_device * its fields must be non-NULL. msix_used is true if and only if the device is * configured with MSI support. */ -NTSTATUS virtio_device_initialize(VirtIODevice *vdev, - const VirtIOSystemOps *pSystemOps, - void *DeviceContext, - bool msix_used); +NTSTATUS virtio_device_initialize(VirtIODevice *vdev, const VirtIOSystemOps *pSystemOps, + void *DeviceContext, bool msix_used); void virtio_device_shutdown(VirtIODevice *vdev); /* Driver API: device status manipulation @@ -308,9 +302,9 @@ void virtio_device_ready(VirtIODevice *vdev); * the device as returned from virtio_get_features. virtio_set_features sets the * VIRTIO_CONFIG_S_FEATURES_OK status bit if it is supported by the device. */ -#define virtio_is_feature_enabled(FeaturesList, Feature) (!!((FeaturesList) & (1ULL << (Feature)))) -#define virtio_feature_enable(FeaturesList, Feature) ((FeaturesList) |= (1ULL << (Feature))) -#define virtio_feature_disable(FeaturesList, Feature) ((FeaturesList) &= ~(1ULL << (Feature))) +#define virtio_is_feature_enabled(FeaturesList, Feature) (!!((FeaturesList) & (1ULL << (Feature)))) +#define virtio_feature_enable(FeaturesList, Feature) ((FeaturesList) |= (1ULL << (Feature))) +#define virtio_feature_disable(FeaturesList, Feature) ((FeaturesList) &= ~(1ULL << (Feature))) u64 virtio_get_features(VirtIODevice *dev); NTSTATUS virtio_set_features(VirtIODevice *vdev, u64 features); @@ -321,10 +315,8 @@ NTSTATUS virtio_set_features(VirtIODevice *vdev, u64 features); * length 8 is broken down to two 4 bytes accesses, and any other length is read or * written byte by byte. */ -void virtio_get_config(VirtIODevice *vdev, unsigned offset, - void *buf, unsigned len); -void virtio_set_config(VirtIODevice *vdev, unsigned offset, - void *buf, unsigned len); +void virtio_get_config(VirtIODevice *vdev, unsigned offset, void *buf, unsigned len); +void virtio_set_config(VirtIODevice *vdev, unsigned offset, void *buf, unsigned len); /* Driver API: virtqueue setup * virtio_reserve_queue_memory makes VirtioLib reserve memory for its virtqueue @@ -336,16 +328,13 @@ void virtio_set_config(VirtIODevice *vdev, unsigned offset, * Drivers should treat the returned struct virtqueue pointers as opaque handles. */ NTSTATUS virtio_query_queue_allocation(VirtIODevice *vdev, unsigned index, - unsigned short *pNumEntries, - unsigned long *pRingSize, + unsigned short *pNumEntries, unsigned long *pRingSize, unsigned long *pHeapSize); NTSTATUS virtio_reserve_queue_memory(VirtIODevice *vdev, unsigned nvqs); -NTSTATUS virtio_find_queue(VirtIODevice *vdev, unsigned index, - struct virtqueue **vq); -NTSTATUS virtio_find_queues(VirtIODevice *vdev, unsigned nvqs, - struct virtqueue *vqs[]); +NTSTATUS virtio_find_queue(VirtIODevice *vdev, unsigned index, struct virtqueue **vq); +NTSTATUS virtio_find_queues(VirtIODevice *vdev, unsigned nvqs, struct virtqueue *vqs[]); /* Driver API: virtqueue shutdown * The device must be reset and re-initialized to re-setup queues after they have diff --git a/VirtIO/virtio_pci_common.h b/VirtIO/virtio_pci_common.h index 064997cf6..5a4d52b97 100644 --- a/VirtIO/virtio_pci_common.h +++ b/VirtIO/virtio_pci_common.h @@ -35,19 +35,13 @@ * SUCH DAMAGE. */ -#define ioread8(vdev, addr) \ - vdev->system->vdev_read_byte((ULONG_PTR)(addr)) -#define ioread16(vdev, addr) \ - vdev->system->vdev_read_word((ULONG_PTR)(addr)) -#define ioread32(vdev, addr) \ - vdev->system->vdev_read_dword((ULONG_PTR)(addr)) -#define iowrite8(vdev, val, addr) \ - vdev->system->vdev_write_byte((ULONG_PTR)(addr), val) -#define iowrite16(vdev, val, addr) \ - vdev->system->vdev_write_word((ULONG_PTR)(addr), val) -#define iowrite32(vdev, val, addr) \ - vdev->system->vdev_write_dword((ULONG_PTR)(addr), val) -#define iowrite64_twopart(vdev, val, lo_addr, hi_addr) \ +#define ioread8(vdev, addr) vdev->system->vdev_read_byte((ULONG_PTR)(addr)) +#define ioread16(vdev, addr) vdev->system->vdev_read_word((ULONG_PTR)(addr)) +#define ioread32(vdev, addr) vdev->system->vdev_read_dword((ULONG_PTR)(addr)) +#define iowrite8(vdev, val, addr) vdev->system->vdev_write_byte((ULONG_PTR)(addr), val) +#define iowrite16(vdev, val, addr) vdev->system->vdev_write_word((ULONG_PTR)(addr), val) +#define iowrite32(vdev, val, addr) vdev->system->vdev_write_dword((ULONG_PTR)(addr), val) +#define iowrite64_twopart(vdev, val, lo_addr, hi_addr) \ vdev->system->vdev_write_dword((ULONG_PTR)(lo_addr), (u32)(val)); \ vdev->system->vdev_write_dword((ULONG_PTR)(hi_addr), (val) >> 32) @@ -69,15 +63,13 @@ #define pci_read_config_dword(vdev, where, dwVal) \ vdev->system->pci_read_config_dword(vdev->DeviceContext, where, dwVal) -#define pci_get_resource_len(vdev, bar) \ - vdev->system->pci_get_resource_len(vdev->DeviceContext, bar) +#define pci_get_resource_len(vdev, bar) vdev->system->pci_get_resource_len(vdev->DeviceContext, bar) #define pci_map_address_range(vdev, bar, offset, maxlen) \ vdev->system->pci_map_address_range(vdev->DeviceContext, bar, offset, maxlen) #define vdev_get_msix_vector(vdev, queue) \ vdev->system->vdev_get_msix_vector(vdev->DeviceContext, queue) -#define vdev_sleep(vdev, msecs) \ - vdev->system->vdev_sleep(vdev->DeviceContext, msecs) +#define vdev_sleep(vdev, msecs) vdev->system->vdev_sleep(vdev->DeviceContext, msecs) /* the notify function used when creating a virt queue */ bool vp_notify(struct virtqueue *vq); diff --git a/VirtIO/virtio_ring.h b/VirtIO/virtio_ring.h index 21ca5524f..3c8cee4ba 100644 --- a/VirtIO/virtio_ring.h +++ b/VirtIO/virtio_ring.h @@ -36,15 +36,15 @@ #include "linux/virtio_types.h" /* We support indirect buffer descriptors */ -#define VIRTIO_RING_F_INDIRECT_DESC 28 +#define VIRTIO_RING_F_INDIRECT_DESC 28 /* The Guest publishes the used index for which it expects an interrupt * at the end of the avail ring. Host should ignore the avail->flags field. */ /* The Host publishes the avail index for which it expects a kick * at the end of the used ring. Guest should ignore the used->flags field. */ -#define VIRTIO_RING_F_EVENT_IDX 29 +#define VIRTIO_RING_F_EVENT_IDX 29 -#define VQ_ADD_BUFFER_SUCCESS 0 +#define VQ_ADD_BUFFER_SUCCESS 0 void vring_transport_features(VirtIODevice *vdev, u64 *features); unsigned long vring_size(unsigned int num, unsigned long align, bool packed); diff --git a/VirtIO/windows/virtio_ring_allocation.h b/VirtIO/windows/virtio_ring_allocation.h index 39fe1e7b6..2826281a5 100644 --- a/VirtIO/windows/virtio_ring_allocation.h +++ b/VirtIO/windows/virtio_ring_allocation.h @@ -1,21 +1,15 @@ #ifndef _VIRTIO_RING_ALLOCATION_H #define _VIRTIO_RING_ALLOCATION_H -struct virtqueue *vring_new_virtqueue_split(unsigned int index, - unsigned int num, - unsigned int vring_align, - VirtIODevice *vdev, - void *pages, - void (*notify)(struct virtqueue *), - void *control); +struct virtqueue *vring_new_virtqueue_split(unsigned int index, unsigned int num, + unsigned int vring_align, VirtIODevice *vdev, + void *pages, void (*notify)(struct virtqueue *), + void *control); -struct virtqueue *vring_new_virtqueue_packed(unsigned int index, - unsigned int num, - unsigned int vring_align, - VirtIODevice *vdev, - void *pages, - void (*notify)(struct virtqueue *), - void *control); +struct virtqueue *vring_new_virtqueue_packed(unsigned int index, unsigned int num, + unsigned int vring_align, VirtIODevice *vdev, + void *pages, void (*notify)(struct virtqueue *), + void *control); unsigned int vring_control_block_size(u16 qsize, bool packed); unsigned int vring_control_block_size_packed(u16 qsize);