From: "Dr. David Alan Gilbert" <dgilb...@redhat.com> Define a new capability type 'VIRTIO_PCI_CAP_SHARED_MEMORY_CFG'. They allow defining shared memory regions with sizes and offsets of 2^32 and more. Multiple instances of the capability are allowed and distinguished by a device-specific 'id'. Use VIRTIO_GPU_SHM_ID_HOST_VISIBLE as id for virtio-gpu.
Signed-off-by: Dr. David Alan Gilbert <dgilb...@redhat.com> Signed-off-by: Antonio Caggiano <antonio.caggi...@collabora.com> (cherry picked from commit a5d628a3a3c5e60b98b15ffff197c36a77056115) --- hw/display/virtio-gpu-pci.c | 2 +- hw/display/virtio-vga.c | 2 +- hw/virtio/virtio-pci.c | 19 +++++++++++++++++++ hw/virtio/virtio-pci.h | 5 +++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/hw/display/virtio-gpu-pci.c b/hw/display/virtio-gpu-pci.c index 9808663d05..a79bd751b2 100644 --- a/hw/display/virtio-gpu-pci.c +++ b/hw/display/virtio-gpu-pci.c @@ -43,7 +43,7 @@ static void virtio_gpu_pci_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp) PCI_BASE_ADDRESS_MEM_PREFETCH | PCI_BASE_ADDRESS_MEM_TYPE_64, &g->hostmem); - virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, 0); + virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, VIRTIO_GPU_SHM_ID_HOST_VISIBLE); } qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus), errp); diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c index 61993dd3f2..ca841a0799 100644 --- a/hw/display/virtio-vga.c +++ b/hw/display/virtio-vga.c @@ -147,7 +147,7 @@ static void virtio_vga_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp) PCI_BASE_ADDRESS_MEM_PREFETCH | PCI_BASE_ADDRESS_MEM_TYPE_64, &g->hostmem); - virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, 0); + virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, VIRTIO_GPU_SHM_ID_HOST_VISIBLE); } if (!(vpci_dev->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ)) { diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 433060ac02..37a50b4658 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1149,6 +1149,25 @@ static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, return offset; } +int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy, + uint8_t bar, uint64_t offset, uint64_t length, + uint8_t id) +{ + struct virtio_pci_cap64 cap = { + .cap.cap_len = sizeof cap, + .cap.cfg_type = VIRTIO_PCI_CAP_SHARED_MEMORY_CFG, + }; + uint32_t mask32 = ~0; + + cap.cap.bar = bar; + cap.cap.length = cpu_to_le32(length & mask32); + cap.length_hi = cpu_to_le32((length >> 32) & mask32); + cap.cap.offset = cpu_to_le32(offset & mask32); + cap.offset_hi = cpu_to_le32((offset >> 32) & mask32); + cap.cap.id = id; + return virtio_pci_add_mem_cap(proxy, &cap.cap); +} + static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr, unsigned size) { diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index 2446dcd9ae..25c4b7a32d 100644 --- a/hw/virtio/virtio-pci.h +++ b/hw/virtio/virtio-pci.h @@ -252,4 +252,9 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t); */ unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues); +/* Add shared memory capability */ +int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy, + uint8_t bar, uint64_t offset, uint64_t length, + uint8_t id); + #endif -- 2.30.2