virtio-1.0: cleanups and preparations for virtio-vga
cover virtio-1.0: cleanups and preparations for virtio-vga
Hi,
Here is a series of patches for virtio-pci, with some cleanups and preparations for virtio-vga.
Patches 1-6 clean up the modern (virtio-1.0) memory region initialization a bit. They are preparations for the other patches, but IMHO are also a useful cleanup on their own.
Patches 7+8 changes initialization so virtio-vga has a chance to arrange things as it pleases.
Patches 1-8 should apply fine on top of mst's virtio-1.0 branch, and I'm looking for reviews of them.
Patch 9 is the showcase for patches 7+8. It has more dependencies though, if you wanna play with that I'd suggest to fetch
https://www.kraxel.org/cgit/qemu/log/?h=rebase/vga-wip
cheers,
Gerd
Gerd Hoffmann (9):
virtio: add struct VirtIOPCIRegion for virtio-1 regions
virtio: add virtio_pci_modern_regions_init()
virtio: add virtio_pci_modern_region_map()
virtio: move virtio_pci_add_mem_cap call to
virtio_pci_modern_region_map
virtio: move cap type to VirtIOPCIRegion
virtio: drop identical virtio_pci_cap
virtio: move bar assignments to VirtIOPCIProxy
virtio: init from virtio_pci_device_plugged to virtio_pci_realize
virtio-vga: make compatible with stdvga
hw/display/vga-pci.c | 8 +- hw/display/vga_int.h | 6 ++ hw/display/virtio-vga.c | 20 ++++- hw/virtio/virtio-pci.c | 228 ++++++++++++++++++++++++------------------------ hw/virtio/virtio-pci.h | 17 +++- 5 files changed, 157 insertions(+), 122 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/9 virtio: add struct VirtIOPCIRegion for virtio-1 regions
For now just place the MemoryRegion there,
following patches will add more.
--- hw/virtio/virtio-pci.c | 18 ++++++++++-------- hw/virtio/virtio-pci.h | 12 ++++++++---- 2 files changed, 18 insertions(+), 12 deletions(-)
hw/virtio/virtio-pci.c +10 -8
@@ -1307,28 +1307,30 @@ static void virtio_pci_device_plugged(DeviceState *d)memory_region_init (&proxy->modern_bar,OBJECT (proxy),"virtio-pci" ,2 *QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *VIRTIO_PCI_QUEUE_MAX ); -memory_region_init_io (&proxy->common,OBJECT (proxy), +memory_region_init_io (&proxy->common.mr,OBJECT (proxy), &common_ops, proxy,"virtio-pci-common" ,0x1000 ); -memory_region_add_subregion (&proxy->modern_bar,0 , &proxy->common); -memory_region_init_io (&proxy->isr,OBJECT (proxy), +memory_region_add_subregion (&proxy->modern_bar,0 , &proxy->common.mr); +memory_region_init_io (&proxy->isr.mr,OBJECT (proxy), &isr_ops, proxy,"virtio-pci-isr" ,0x1000 ); -memory_region_add_subregion (&proxy->modern_bar,0x1000 , &proxy->isr); -memory_region_init_io (&proxy->device,OBJECT (proxy), +memory_region_add_subregion (&proxy->modern_bar,0x1000 , &proxy->isr.mr); +memory_region_init_io (&proxy->device.mr,OBJECT (proxy), &device_ops,virtio_bus_get_device (&proxy->bus),"virtio-pci-device" ,0x1000 ); -memory_region_add_subregion (&proxy->modern_bar,0x2000 , &proxy->device); -memory_region_init_io (&proxy->notify,OBJECT (proxy), +memory_region_add_subregion (&proxy->modern_bar,0x2000 , + &proxy->device.mr); +memory_region_init_io (&proxy->notify.mr,OBJECT (proxy), ¬ify_ops,virtio_bus_get_device (&proxy->bus),"virtio-pci-notify" ,QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *VIRTIO_PCI_QUEUE_MAX ); -memory_region_add_subregion (&proxy->modern_bar,0x3000 , &proxy->notify); +memory_region_add_subregion (&proxy->modern_bar,0x3000 , + &proxy->notify.mr); pci_register_bar(&proxy->pci_dev, modern_mem_bar, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_PREFETCH |
hw/virtio/virtio-pci.h +8 -4
@@ -93,13 +93,17 @@ typedef struct VirtioPCIClass {void (*realize)(VirtIOPCIProxy *vpci_dev,Error **errp); } VirtioPCIClass; +typedef struct VirtIOPCIRegion { +MemoryRegion mr; +}VirtIOPCIRegion ; +struct VirtIOPCIProxy {PCIDevice pci_dev;MemoryRegion bar; -MemoryRegion common; -MemoryRegion isr; -MemoryRegion device; -MemoryRegion notify; +VirtIOPCIRegion common; +VirtIOPCIRegion isr; +VirtIOPCIRegion device; +VirtIOPCIRegion notify;MemoryRegion modern_bar;uint32_t flags;uint32_t class_code;
Signature · 1 line
1.8.3.1
PATCH 2/9 virtio: add virtio_pci_modern_regions_init()
In reply to Gerd HoffmannAdd init function for the modern pci regions,
move over the init code.
--- hw/virtio/virtio-pci.c | 117 +++++++++++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 58 deletions(-)
hw/virtio/virtio-pci.c +59 -58
@@ -1177,6 +1177,64 @@ static void virtio_pci_device_write(void *opaque, hwaddr addr, } } +static void virtio_pci_modern_regions_init (VirtIOPCIProxy *proxy) +{ +static const MemoryRegionOps common_ops = { + .read = virtio_pci_common_read, + .write = virtio_pci_common_write, + .impl = { + .min_access_size =1 , + .max_access_size =4 , + }, + .endianness =DEVICE_LITTLE_ENDIAN , + }; +static const MemoryRegionOps isr_ops = { + .read = virtio_pci_isr_read, + .write = virtio_pci_isr_write, + .impl = { + .min_access_size =1 , + .max_access_size =4 , + }, + .endianness =DEVICE_LITTLE_ENDIAN , + }; +static const MemoryRegionOps device_ops = { + .read = virtio_pci_device_read, + .write = virtio_pci_device_write, + .impl = { + .min_access_size =1 , + .max_access_size =4 , + }, + .endianness =DEVICE_LITTLE_ENDIAN , + }; +static const MemoryRegionOps notify_ops = { + .read = virtio_pci_notify_read, + .write = virtio_pci_notify_write, + .impl = { + .min_access_size =1 , + .max_access_size =4 , + }, + .endianness =DEVICE_LITTLE_ENDIAN , + }; + +memory_region_init_io (&proxy->common.mr,OBJECT (proxy), + &common_ops, + proxy, +"virtio-pci-common" ,0x1000 ); +memory_region_init_io (&proxy->isr.mr,OBJECT (proxy), + &isr_ops, + proxy, +"virtio-pci-isr" ,0x1000 ); +memory_region_init_io (&proxy->device.mr,OBJECT (proxy), + &device_ops, +virtio_bus_get_device (&proxy->bus), +"virtio-pci-device" ,0x1000 ); +memory_region_init_io (&proxy->notify.mr,OBJECT (proxy), + ¬ify_ops, +virtio_bus_get_device (&proxy->bus), +"virtio-pci-notify" , +QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * +VIRTIO_PCI_QUEUE_MAX ); +}/* This is called by virtio-bus just after the device is plugged. */ static void virtio_pci_device_plugged (DeviceState *d)
@@ -1257,46 +1315,6 @@ static void virtio_pci_device_plugged(DeviceState *d) .notify_off_multiplier = cpu_to_le32(QEMU_VIRTIO_PCI_QUEUE_MEM_MULT), }; -static const MemoryRegionOps common_ops = { - .read = virtio_pci_common_read, - .write = virtio_pci_common_write, - .impl = { - .min_access_size =1 , - .max_access_size =4 , - }, - .endianness =DEVICE_LITTLE_ENDIAN , - }; - -static const MemoryRegionOps isr_ops = { - .read = virtio_pci_isr_read, - .write = virtio_pci_isr_write, - .impl = { - .min_access_size =1 , - .max_access_size =4 , - }, - .endianness =DEVICE_LITTLE_ENDIAN , - }; - -static const MemoryRegionOps device_ops = { - .read = virtio_pci_device_read, - .write = virtio_pci_device_write, - .impl = { - .min_access_size =1 , - .max_access_size =4 , - }, - .endianness =DEVICE_LITTLE_ENDIAN , - }; - -static const MemoryRegionOps notify_ops = { - .read = virtio_pci_notify_read, - .write = virtio_pci_notify_write, - .impl = { - .min_access_size =1 , - .max_access_size =4 , - }, - .endianness =DEVICE_LITTLE_ENDIAN , - }; -/* TODO: add io access for speed */ virtio_pci_add_mem_cap (proxy, &common);virtio_pci_add_mem_cap (proxy, &isr);
@@ -1307,28 +1325,11 @@ static void virtio_pci_device_plugged(DeviceState *d)memory_region_init (&proxy->modern_bar,OBJECT (proxy),"virtio-pci" ,2 *QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *VIRTIO_PCI_QUEUE_MAX ); -memory_region_init_io (&proxy->common.mr,OBJECT (proxy), - &common_ops, - proxy, -"virtio-pci-common" ,0x1000 ); +virtio_pci_modern_regions_init (proxy);memory_region_add_subregion (&proxy->modern_bar,0 , &proxy->common.mr); -memory_region_init_io (&proxy->isr.mr,OBJECT (proxy), - &isr_ops, - proxy, -"virtio-pci-isr" ,0x1000 );memory_region_add_subregion (&proxy->modern_bar,0x1000 , &proxy->isr.mr); -memory_region_init_io (&proxy->device.mr,OBJECT (proxy), - &device_ops, -virtio_bus_get_device (&proxy->bus), -"virtio-pci-device" ,0x1000 );memory_region_add_subregion (&proxy->modern_bar,0x2000 , &proxy->device.mr); -memory_region_init_io (&proxy->notify.mr,OBJECT (proxy), - ¬ify_ops, -virtio_bus_get_device (&proxy->bus), -"virtio-pci-notify" , -QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * -VIRTIO_PCI_QUEUE_MAX );memory_region_add_subregion (&proxy->modern_bar,0x3000 , &proxy->notify.mr); pci_register_bar(&proxy->pci_dev, modern_mem_bar,
Signature · 1 line
1.8.3.1
PATCH 3/9 virtio: add virtio_pci_modern_region_map()
In reply to Gerd HoffmannAdd funxction to map modern virtio regions.
Add offset to VirtIOPCIRegion.
--- hw/virtio/virtio-pci.c | 25 +++++++++++++++++++------ hw/virtio/virtio-pci.h | 2 ++ 2 files changed, 21 insertions(+), 6 deletions(-)
hw/virtio/virtio-pci.c +19 -6
@@ -1220,20 +1220,35 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy) &common_ops, proxy, "virtio-pci-common", 0x1000); + proxy->common.offset =0x0 ; +memory_region_init_io (&proxy->isr.mr,OBJECT (proxy), &isr_ops, proxy,"virtio-pci-isr" ,0x1000 ); + proxy->isr.offset =0x1000 ; +memory_region_init_io (&proxy->device.mr,OBJECT (proxy), &device_ops,virtio_bus_get_device (&proxy->bus),"virtio-pci-device" ,0x1000 ); + proxy->device.offset =0x2000 ; +memory_region_init_io (&proxy->notify.mr,OBJECT (proxy), ¬ify_ops,virtio_bus_get_device (&proxy->bus),"virtio-pci-notify" ,QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *VIRTIO_PCI_QUEUE_MAX ); + proxy->notify.offset =0x3000 ; +} + +static void virtio_pci_modern_region_map (VirtIOPCIProxy *proxy, +VirtIOPCIRegion *region) +{ +memory_region_add_subregion (&proxy->modern_bar, + region->offset, + ®ion->mr); }/* This is called by virtio-bus just after the device is plugged. */
@@ -1326,12 +1341,10 @@ static void virtio_pci_device_plugged(DeviceState *d)2 *QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * VIRTIO_PCI_QUEUE_MAX);virtio_pci_modern_regions_init (proxy); -memory_region_add_subregion (&proxy->modern_bar,0 , &proxy->common.mr); -memory_region_add_subregion (&proxy->modern_bar,0x1000 , &proxy->isr.mr); -memory_region_add_subregion (&proxy->modern_bar,0x2000 , - &proxy->device.mr); -memory_region_add_subregion (&proxy->modern_bar,0x3000 , - &proxy->notify.mr); +virtio_pci_modern_region_map (proxy, &proxy->common); +virtio_pci_modern_region_map (proxy, &proxy->isr); +virtio_pci_modern_region_map (proxy, &proxy->device); +virtio_pci_modern_region_map (proxy, &proxy->notify); pci_register_bar(&proxy->pci_dev, modern_mem_bar, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_PREFETCH |
hw/virtio/virtio-pci.h +2 -0
@@ -95,6 +95,8 @@ typedef struct VirtioPCIClass {typedef struct VirtIOPCIRegion {MemoryRegion mr; +uint32_t offset; +uint32_t type; }VirtIOPCIRegion ;struct VirtIOPCIProxy {
Signature · 1 line
1.8.3.1
PATCH 4/9 virtio: move virtio_pci_add_mem_cap call to virtio_pci_modern_region_map
In reply to Gerd HoffmannAlso fill offset and length automatically,
from VirtIOPCIRegion->offset and region size.
--- hw/virtio/virtio-pci.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-)
hw/virtio/virtio-pci.c +10 -18
@@ -1244,11 +1244,16 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy) }static void virtio_pci_modern_region_map (VirtIOPCIProxy *proxy, -VirtIOPCIRegion *region) +VirtIOPCIRegion *region, +struct virtio_pci_cap *cap) {memory_region_add_subregion (&proxy->modern_bar, region->offset, ®ion->mr); + + cap->offset =cpu_to_le32 (region->offset); + cap->length =cpu_to_le32 (memory_region_size (®ion->mr)); +virtio_pci_add_mem_cap (proxy, cap); }/* This is called by virtio-bus just after the device is plugged. */
@@ -1303,48 +1308,35 @@ static void virtio_pci_device_plugged(DeviceState *d) .cfg_type = VIRTIO_PCI_CAP_COMMON_CFG, .cap_len = sizeof common, .bar = modern_mem_bar, - .offset = cpu_to_le32(0x0), - .length = cpu_to_le32(0x1000), };struct virtio_pci_cap isr = { .cfg_type =VIRTIO_PCI_CAP_ISR_CFG , .cap_len =sizeof isr, .bar = modern_mem_bar, - .offset =cpu_to_le32 (0x1000 ), - .length =cpu_to_le32 (0x1000 ), };struct virtio_pci_cap device = { .cfg_type =VIRTIO_PCI_CAP_DEVICE_CFG , .cap_len =sizeof device, .bar = modern_mem_bar, - .offset =cpu_to_le32 (0x2000 ), - .length =cpu_to_le32 (0x1000 ), };struct virtio_pci_notify_cap notify = { .cap.cfg_type =VIRTIO_PCI_CAP_NOTIFY_CFG , .cap.cap_len =sizeof notify, .cap.bar = modern_mem_bar, - .cap.offset =cpu_to_le32 (0x3000 ), - .cap.length =cpu_to_le32 (QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * -VIRTIO_PCI_QUEUE_MAX ), .notify_off_multiplier =cpu_to_le32 (QEMU_VIRTIO_PCI_QUEUE_MEM_MULT ), };/* TODO: add io access for speed */ -virtio_pci_add_mem_cap (proxy, &common); -virtio_pci_add_mem_cap (proxy, &isr); -virtio_pci_add_mem_cap (proxy, &device); -virtio_pci_add_mem_cap (proxy, ¬ify.cap);virtio_add_feature (&proxy->host_features,VIRTIO_F_VERSION_1 );memory_region_init (&proxy->modern_bar,OBJECT (proxy),"virtio-pci" ,2 *QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *VIRTIO_PCI_QUEUE_MAX );virtio_pci_modern_regions_init (proxy); -virtio_pci_modern_region_map (proxy, &proxy->common); -virtio_pci_modern_region_map (proxy, &proxy->isr); -virtio_pci_modern_region_map (proxy, &proxy->device); -virtio_pci_modern_region_map (proxy, &proxy->notify); +virtio_pci_modern_region_map (proxy, &proxy->common, &common); +virtio_pci_modern_region_map (proxy, &proxy->isr, &isr); +virtio_pci_modern_region_map (proxy, &proxy->device, &device); +virtio_pci_modern_region_map (proxy, &proxy->notify, ¬ify.cap); pci_register_bar(&proxy->pci_dev, modern_mem_bar, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_PREFETCH |
Signature · 1 line
1.8.3.1
PATCH 5/9 virtio: move cap type to VirtIOPCIRegion
In reply to Gerd Hoffmann--- hw/virtio/virtio-pci.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
hw/virtio/virtio-pci.c +5 -4
@@ -1221,18 +1221,21 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy) proxy, "virtio-pci-common", 0x1000); proxy->common.offset =0x0 ; + proxy->common.type =VIRTIO_PCI_CAP_COMMON_CFG ;memory_region_init_io (&proxy->isr.mr,OBJECT (proxy), &isr_ops, proxy,"virtio-pci-isr" ,0x1000 ); proxy->isr.offset =0x1000 ; + proxy->isr.type =VIRTIO_PCI_CAP_ISR_CFG ;memory_region_init_io (&proxy->device.mr,OBJECT (proxy), &device_ops,virtio_bus_get_device (&proxy->bus),"virtio-pci-device" ,0x1000 ); proxy->device.offset =0x2000 ; + proxy->device.type =VIRTIO_PCI_CAP_DEVICE_CFG ; memory_region_init_io(&proxy->notify.mr, OBJECT(proxy), ¬ify_ops,
@@ -1241,6 +1244,7 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy)QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * VIRTIO_PCI_QUEUE_MAX); proxy->notify.offset =0x3000 ; + proxy->notify.type =VIRTIO_PCI_CAP_NOTIFY_CFG ; } static void virtio_pci_modern_region_map(VirtIOPCIProxy *proxy,
@@ -1251,6 +1255,7 @@ static void virtio_pci_modern_region_map(VirtIOPCIProxy *proxy, region->offset, ®ion->mr); + cap->cfg_type = region->type; cap->offset =cpu_to_le32 (region->offset); cap->length =cpu_to_le32 (memory_region_size (®ion->mr));virtio_pci_add_mem_cap (proxy, cap);
@@ -1305,22 +1310,18 @@ static void virtio_pci_device_plugged(DeviceState *d)if (modern) {struct virtio_pci_cap common = { - .cfg_type =VIRTIO_PCI_CAP_COMMON_CFG , .cap_len =sizeof common, .bar = modern_mem_bar, };struct virtio_pci_cap isr = { - .cfg_type =VIRTIO_PCI_CAP_ISR_CFG , .cap_len =sizeof isr, .bar = modern_mem_bar, };struct virtio_pci_cap device = { - .cfg_type =VIRTIO_PCI_CAP_DEVICE_CFG , .cap_len =sizeof device, .bar = modern_mem_bar, };struct virtio_pci_notify_cap notify = { - .cap.cfg_type =VIRTIO_PCI_CAP_NOTIFY_CFG , .cap.cap_len =sizeof notify, .cap.bar = modern_mem_bar, .notify_off_multiplier =cpu_to_le32 (QEMU_VIRTIO_PCI_QUEUE_MEM_MULT ),
Signature · 1 line
1.8.3.1
PATCH 6/9 virtio: drop identical virtio_pci_cap
In reply to Gerd HoffmannNow the three struct virtio_pci_caps are identical, lets drop two of them ;)
--- hw/virtio/virtio-pci.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
hw/virtio/virtio-pci.c +5 -13
@@ -1309,16 +1309,8 @@ static void virtio_pci_device_plugged(DeviceState *d)if (modern) { -struct virtio_pci_cap common = { - .cap_len =sizeof common, - .bar = modern_mem_bar, - }; -struct virtio_pci_cap isr = { - .cap_len =sizeof isr, - .bar = modern_mem_bar, - }; -struct virtio_pci_cap device = { - .cap_len =sizeof device, +struct virtio_pci_cap cap = { + .cap_len =sizeof cap, .bar = modern_mem_bar, };struct virtio_pci_notify_cap notify = {
@@ -1334,9 +1326,9 @@ static void virtio_pci_device_plugged(DeviceState *d)2 *QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * VIRTIO_PCI_QUEUE_MAX);virtio_pci_modern_regions_init (proxy); -virtio_pci_modern_region_map (proxy, &proxy->common, &common); -virtio_pci_modern_region_map (proxy, &proxy->isr, &isr); -virtio_pci_modern_region_map (proxy, &proxy->device, &device); +virtio_pci_modern_region_map (proxy, &proxy->common, &cap); +virtio_pci_modern_region_map (proxy, &proxy->isr, &cap); +virtio_pci_modern_region_map (proxy, &proxy->device, &cap);virtio_pci_modern_region_map (proxy, &proxy->notify, ¬ify.cap); pci_register_bar(&proxy->pci_dev, modern_mem_bar, PCI_BASE_ADDRESS_SPACE_MEMORY |
Signature · 1 line
1.8.3.1
PATCH 7/9 virtio: move bar assignments to VirtIOPCIProxy
In reply to Gerd HoffmannAdd variables for the pci bars, in preparation
to make this configurable.
--- hw/virtio/virtio-pci.c | 16 ++++++++-------- hw/virtio/virtio-pci.h | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-)
hw/virtio/virtio-pci.c +8 -8
@@ -1256,6 +1256,7 @@ static void virtio_pci_modern_region_map(VirtIOPCIProxy *proxy, ®ion->mr); cap->cfg_type = region->type; + cap->bar = proxy->modern_mem_bar; cap->offset =cpu_to_le32 (region->offset); cap->length =cpu_to_le32 (memory_region_size (®ion->mr));virtio_pci_add_mem_cap (proxy, cap);
@@ -1283,9 +1284,9 @@ static void virtio_pci_device_plugged(DeviceState *d)* virtio-vga places the vga framebuffer there. * */ -uint32_t legacy_io_bar =0 ; -uint32_t msix_bar =1 ; -uint32_t modern_mem_bar =4 ; + proxy->legacy_io_bar =0 ; + proxy->msix_bar =1 ; + proxy->modern_mem_bar =4 ; config = proxy->pci_dev.config;if (proxy->class_code) {
@@ -1311,11 +1312,9 @@ static void virtio_pci_device_plugged(DeviceState *d)if (modern) {struct virtio_pci_cap cap = { .cap_len =sizeof cap, - .bar = modern_mem_bar, };struct virtio_pci_notify_cap notify = { .cap.cap_len =sizeof notify, - .cap.bar = modern_mem_bar, .notify_off_multiplier =cpu_to_le32 (QEMU_VIRTIO_PCI_QUEUE_MEM_MULT ), };
@@ -1330,7 +1329,7 @@ static void virtio_pci_device_plugged(DeviceState *d)virtio_pci_modern_region_map (proxy, &proxy->isr, &cap);virtio_pci_modern_region_map (proxy, &proxy->device, &cap);virtio_pci_modern_region_map (proxy, &proxy->notify, ¬ify.cap); - pci_register_bar(&proxy->pci_dev, modern_mem_bar, + pci_register_bar(&proxy->pci_dev, proxy->modern_mem_bar, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_PREFETCH | PCI_BASE_ADDRESS_MEM_TYPE_64,
@@ -1338,7 +1337,8 @@ static void virtio_pci_device_plugged(DeviceState *d) }if (proxy->nvectors && -msix_init_exclusive_bar (&proxy->pci_dev, proxy->nvectors, msix_bar)) { +msix_init_exclusive_bar (&proxy->pci_dev, proxy->nvectors, + proxy->msix_bar)) {error_report ("unable to init msix vectors to %" PRIu32, proxy->nvectors); proxy->nvectors =0 ;
@@ -1357,7 +1357,7 @@ static void virtio_pci_device_plugged(DeviceState *d) &virtio_pci_config_ops, proxy, "virtio-pci", size); -pci_register_bar (&proxy->pci_dev, legacy_io_bar, +pci_register_bar (&proxy->pci_dev, proxy->legacy_io_bar,PCI_BASE_ADDRESS_SPACE_IO , &proxy->bar); }
hw/virtio/virtio-pci.h +3 -0
@@ -107,6 +107,9 @@ struct VirtIOPCIProxy {VirtIOPCIRegion device;VirtIOPCIRegion notify;MemoryRegion modern_bar; +uint32_t legacy_io_bar; +uint32_t msix_bar; +uint32_t modern_mem_bar;uint32_t flags;uint32_t class_code;uint32_t nvectors;
Signature · 1 line
1.8.3.1
PATCH 8/9 virtio: init from virtio_pci_device_plugged to virtio_pci_realize
In reply to Gerd HoffmannThis allows virtio-pci subclasses to change things before the plugged callback applies them.
--- hw/virtio/virtio-pci.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-)
hw/virtio/virtio-pci.c +21 -20
@@ -1272,22 +1272,6 @@ static void virtio_pci_device_plugged(DeviceState *d)uint8_t *config;uint32_t size; -/* -* virtio pci bar layout -* -* region 0 -- virtio legacy io bar -* region 1 -- msi-x bar -* region 2+3 -- not used by virtio-pci -* region 4+5 -- virtio modern memory (64bit) bar -* -* Regions 2+3 can be used by VirtIOPCIProxy subclasses. -* virtio-vga places the vga framebuffer there. -* -*/ - proxy->legacy_io_bar =0 ; - proxy->msix_bar =1 ; - proxy->modern_mem_bar =4 ; - config = proxy->pci_dev.config;if (proxy->class_code) {pci_config_set_class (config, proxy->class_code);
@@ -1321,10 +1305,6 @@ static void virtio_pci_device_plugged(DeviceState *d)/* TODO: add io access for speed */ virtio_add_feature (&proxy->host_features,VIRTIO_F_VERSION_1 ); -memory_region_init (&proxy->modern_bar,OBJECT (proxy),"virtio-pci" , -2 *QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * -VIRTIO_PCI_QUEUE_MAX ); -virtio_pci_modern_regions_init (proxy);virtio_pci_modern_region_map (proxy, &proxy->common, &cap);virtio_pci_modern_region_map (proxy, &proxy->isr, &cap);virtio_pci_modern_region_map (proxy, &proxy->device, &cap);
@@ -1383,6 +1363,27 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)VirtIOPCIProxy *dev =VIRTIO_PCI (pci_dev);VirtioPCIClass *k =VIRTIO_PCI_GET_CLASS (pci_dev); +/* +* virtio pci bar layout +* +* region 0 -- virtio legacy io bar +* region 1 -- msi-x bar +* region 2+3 -- not used by virtio-pci +* region 4+5 -- virtio modern memory (64bit) bar +* +* Regions 2+3 can be used by VirtIOPCIProxy subclasses. +* virtio-vga places the vga framebuffer there. +* +*/ + dev->legacy_io_bar =0 ; + dev->msix_bar =1 ; + dev->modern_mem_bar =4 ; + +memory_region_init (&dev->modern_bar,OBJECT (dev),"virtio-pci" , +2 *QEMU_VIRTIO_PCI_QUEUE_MEM_MULT * +VIRTIO_PCI_QUEUE_MAX ); +virtio_pci_modern_regions_init (dev); +virtio_pci_bus_new (&dev->bus,sizeof (dev->bus), dev);if (k->realize) { k->realize (dev, errp);
Signature · 1 line
1.8.3.1
PATCH 9/9 virtio-vga: make compatible with stdvga
In reply to Gerd HoffmannArrange things in a way that virtio-vga is both a virtio-1.0 device (acting like virtio-gpu-pci in virtio mode) and fully compatible with stdvga (in vga mode, i.e. when virtio is not enabled).
PCI bar #0 is identical for both stdvga and virtio-vga. PCI bar #1 is msi-x for virtio-vga and unused for stdvga, PCI bar #2 is the mmio area, looks like this for virtio-vga:
00000000fe800000-00000000fe87ffff (prio 1, RW): virtio-pci
00000000fe800400-00000000fe80041f (prio 0, RW): vga ioports remapped
00000000fe800500-00000000fe800515 (prio 0, RW): bochs dispi interface
00000000fe800600-00000000fe800607 (prio 0, RW): qemu extended regs
00000000fe83d000-00000000fe83dfff (prio 0, RW): virtio-pci-common
00000000fe83e000-00000000fe83efff (prio 0, RW): virtio-pci-isr
00000000fe83f000-00000000fe83ffff (prio 0, RW): virtio-pci-device
00000000fe840000-00000000fe87ffff (prio 0, RW): virtio-pci-notifyPCI bar #2 for stdvga looks this way:
00000000febf0000-00000000febf0fff (prio 1, RW): vga.mmio
00000000febf0400-00000000febf041f (prio 0, RW): vga ioports remapped
00000000febf0500-00000000febf0515 (prio 0, RW): bochs dispi interface
00000000febf0600-00000000febf0607 (prio 0, RW): qemu extended regsi.e. it is smaller, lacks the virtio subregions, and seabios picks a different place because of the size difference. But otherwise the mmio bar is identical.
--- hw/display/vga-pci.c | 8 ++++---- hw/display/vga_int.h | 6 ++++++ hw/display/virtio-vga.c | 20 +++++++++++++++++++- 3 files changed, 29 insertions(+), 5 deletions(-)
hw/display/vga-pci.c +4 -4
@@ -201,10 +201,10 @@ static const MemoryRegionOps pci_vga_qext_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; -static void pci_std_vga_mmio_region_init (VGACommonState *s, -MemoryRegion *parent, -MemoryRegion *subs, -bool qext) +void pci_std_vga_mmio_region_init (VGACommonState *s, +MemoryRegion *parent, +MemoryRegion *subs, +bool qext) {memory_region_init_io (&subs[0 ],NULL , &pci_vga_ioport_ops, s,"vga ioports remapped" ,PCI_VGA_IOPORT_SIZE );
hw/display/vga_int.h +6 -0
@@ -221,4 +221,10 @@ extern const uint8_t gr_mask[16];extern const MemoryRegionOps vga_mem_ops; +/* vga-pci.c */ +void pci_std_vga_mmio_region_init (VGACommonState *s, +MemoryRegion *parent, +MemoryRegion *subs, +bool qext); +#endif
hw/display/virtio-vga.c +19 -1
@@ -15,6 +15,7 @@ typedef struct VirtIOVGA {VirtIOPCIProxy parent_obj;VirtIOGPU vdev;VGACommonState vga; +MemoryRegion vga_mrs[3 ];uint32_t dummy; } VirtIOVGA;
@@ -78,15 +79,28 @@ static void virtio_vga_realize(VirtIOPCIProxy *vpci_dev, Error **errp)VirtIOVGA *vvga =VIRTIO_VGA (vpci_dev);VirtIOGPU *g = &vvga->vdev;VGACommonState *vga = &vvga->vga; +uint32_t offset;/* init vga compat bits */ vga->vram_size_mb =8 ;vga_common_init (vga,OBJECT (vpci_dev), false);vga_init (vga,OBJECT (vpci_dev),pci_address_space (&vpci_dev->pci_dev),pci_address_space_io (&vpci_dev->pci_dev), true); -pci_register_bar (&vpci_dev->pci_dev,2 , +pci_register_bar (&vpci_dev->pci_dev,0 ,PCI_BASE_ADDRESS_MEM_PREFETCH , &vga->vram); +/* configure virtio bar and regions */ + vpci_dev->modern_mem_bar =2 ; + offset =memory_region_size (&vpci_dev->modern_bar); + offset -=memory_region_size (&vpci_dev->notify.mr); + vpci_dev->notify.offset = offset; + offset -=memory_region_size (&vpci_dev->device.mr); + vpci_dev->device.offset = offset; + offset -=memory_region_size (&vpci_dev->isr.mr); + vpci_dev->isr.offset = offset; + offset -=memory_region_size (&vpci_dev->common.mr); + vpci_dev->common.offset = offset; +/* init virtio bits */ qdev_set_parent_bus (DEVICE (g),BUS (&vpci_dev->bus));/* force virtio-1.0 */
@@ -94,6 +108,10 @@ static void virtio_vga_realize(VirtIOPCIProxy *vpci_dev, Error **errp) vpci_dev->flags |=VIRTIO_PCI_FLAG_DISABLE_LEGACY ;object_property_set_bool (OBJECT (g), true,"realized" , errp); +/* add stdvga mmio regions */ +pci_std_vga_mmio_region_init (vga, &vpci_dev->modern_bar, + vvga->vga_mrs, true); + vga->con = g->scanout[0 ].con;graphic_console_set_hwops (vga->con, &virtio_vga_ops, vvga); }
Signature · 1 line
1.8.3.1
Quoted 12 lines · Gerd Hoffmann
Hi,
Here is a series of patches for virtio-pci, with some cleanups and preparations for virtio-vga.
Patches 1-6 clean up the modern (virtio-1.0) memory region initialization a bit. They are preparations for the other patches, but IMHO are also a useful cleanup on their own.
Patches 7+8 changes initialization so virtio-vga has a chance to arrange things as it pleases.
Quoted 6 lines
Patches 1-8 should apply fine on top of mst's virtio-1.0 branch, and I'm looking for reviews of them.
Patch 9 is the showcase for patches 7+8. It has more dependencies though, if you wanna play with that I'd suggest to fetch
https://www.kraxel.org/cgit/qemu/log/?h=rebase/vga-wip
Ping? mst, had you a chance to look at this?
What are your virtio-1.0 merge plans for qemu, now that the 2.4 tree is open for development? I'd love to see a quick merge so I can proceed with bits having dependencies on virtio-1.0.
thanks,
Gerd
Quoted 13 lines · Gerd Hoffmann
Quoted 12 lines · Gerd Hoffmann
Hi,
Here is a series of patches for virtio-pci, with some cleanups and preparations for virtio-vga.
Patches 1-6 clean up the modern (virtio-1.0) memory region initialization a bit. They are preparations for the other patches, but IMHO are also a useful cleanup on their own.
Patches 7+8 changes initialization so virtio-vga has a chance to arrange things as it pleases.
Quoted 8 lines
Quoted 6 lines
Patches 1-8 should apply fine on top of mst's virtio-1.0 branch, and I'm looking for reviews of them.
Patch 9 is the showcase for patches 7+8. It has more dependencies though, if you wanna play with that I'd suggest to fetch
https://www.kraxel.org/cgit/qemu/log/?h=rebase/vga-wipPing? mst, had you a chance to look at this?
I'll merge this on the virtio 1 branch shortly.
Quoted 6 lines
What are your virtio-1.0 merge plans for qemu, now that the 2.4 tree is open for development? I'd love to see a quick merge so I can proceed with bits having dependencies on virtio-1.0.
thanks,
Gerd
That branch still needs some work.
I hope to have things in mergeable state end of may. In particular
- the way we have structured breaks migration and makes supporting it properly tricky, so I'm refactoring some code.
- virtio 1 spec forbids devices from accessing memory until DRIVER_OK is set, but we also need to support legacy guests which trigger ready state by kicking some ring.
Do you need some bits from master on that branch?
I could rebase it if it's helpful.
Signature · 1 line
MST
Quoted 10 lines · On Mon, 27 Apr 2015 12:15:16 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
That branch still needs some work.
I hope to have things in mergeable state end of may. In particular
- the way we have structured breaks migration and makes supporting it properly tricky, so I'm refactoring some code.
- virtio 1 spec forbids devices from accessing memory untilDRIVER_OKis set, but we also need to support legacy guests which trigger ready state by kicking some ring.
Quoted 2 lines
Do you need some bits from master on that branch?
I could rebase it if it's helpful.
I'd find it helpful if you could rebase it - I think there was some stuff still sitting somewhere in one of my branches that I wanted to follow up on.
Quoted 13 lines · Cornelia Huck
Quoted 10 lines · On Mon, 27 Apr 2015 12:15:16 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
That branch still needs some work.
I hope to have things in mergeable state end of may. In particular
- the way we have structured breaks migration and makes supporting it properly tricky, so I'm refactoring some code.
- virtio 1 spec forbids devices from accessing memory untilDRIVER_OKis set, but we also need to support legacy guests which trigger ready state by kicking some ring.
Quoted 6 lines
Quoted 2 lines
Do you need some bits from master on that branch?
I could rebase it if it's helpful.I'd find it helpful if you could rebase it - I think there was some stuff still sitting somewhere in one of my branches that I wanted to follow up on.
OK, will do hopefully tomorrow.
Signature · 1 line
MST
Hi,
Quoted 2 lines
Do you need some bits from master on that branch?
I could rebase it if it's helpful.
I have already rebased it:
https://www.kraxel.org/cgit/qemu/log/?h=rebase/virtio-wip
FYI: the virtio-gpu bits and virtio patches for virtio-vga are here:
https://www.kraxel.org/cgit/qemu/log/?h=rebase/vga-wip
cheers,
Gerd