From d9f5b7195e3d777803f06fd6c693cad0bbb5933d Mon Sep 17 00:00:00 2001 From: fangyi Date: Wed, 27 Nov 2024 15:17:38 +0800 Subject: [PATCH] seabios: enable virtio device mmio access and wait util virtio device reset done (cherry picked from commit 5f745d0bc9257ce5715e48a73e2d5321ad86c0ff) --- ...vice-mmio-access-and-wait-util-virti.patch | 87 +++++++++++++++++++ qemu.spec | 6 +- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 enable-virtio-device-mmio-access-and-wait-util-virti.patch diff --git a/enable-virtio-device-mmio-access-and-wait-util-virti.patch b/enable-virtio-device-mmio-access-and-wait-util-virti.patch new file mode 100644 index 0000000..5c3057f --- /dev/null +++ b/enable-virtio-device-mmio-access-and-wait-util-virti.patch @@ -0,0 +1,87 @@ +From 0a179313fde1f71a8a7520c3d3149aa2dc4e66b2 Mon Sep 17 00:00:00 2001 +From: fangyi +Date: Sat, 26 Oct 2024 15:32:02 +0800 +Subject: [PATCH] enable virtio device mmio access and wait util virtio device + reset done + +--- + roms/seabios/src/hw/blockcmd.h | 2 +- + roms/seabiossrc/hw/virtio-pci.c | 32 +++++++++++++++++++++++++++----- + 2 files changed, 28 insertions(+), 6 deletions(-) + +diff --git a/roms/seabios/src/hw/blockcmd.h b/roms/seabios/src/hw/blockcmd.h +index f18543ed..1063e6ab 100644 +--- a/roms/seabios/src/hw/blockcmd.h ++++ b/roms/seabios/src/hw/blockcmd.h +@@ -30,7 +30,7 @@ struct cdb_read_capacity { + struct cdbres_read_capacity { + u32 sectors; + u32 blksize; +-} PACKED; ++} __attribute__((aligned(4))); + + #define CDB_CMD_TEST_UNIT_READY 0x00 + #define CDB_CMD_INQUIRY 0x12 +diff --git a/roms/seabios/src/hw/virtio-pci.c b/roms/seabios/src/hw/virtio-pci.c +index 89a4f505..5d7b8428 100644 +--- a/roms/seabios/src/hw/virtio-pci.c ++++ b/roms/seabios/src/hw/virtio-pci.c +@@ -15,6 +15,7 @@ + * See the COPYING file in the top-level directory. + */ + ++#include "util.h" // msleep + #include "config.h" // CONFIG_DEBUG_LEVEL + #include "malloc.h" // free + #include "output.h" // dprintf +@@ -271,6 +272,10 @@ void vp_reset(struct vp_device *vp) + vp_read(&vp->common, virtio_mmio_cfg, irq_status); + } else if (vp->use_modern) { + vp_write(&vp->common, virtio_pci_common_cfg, device_status, 0); ++ dprintf(1, "vp start reset\n"); ++ while (vp_get_status(vp) != 0) ++ msleep(2); ++ dprintf(1, "vp reset finished\n"); + vp_read(&vp->isr, virtio_pci_isr, isr); + } else { + vp_write(&vp->legacy, virtio_pci_legacy, status, 0); +@@ -535,14 +540,31 @@ void vp_init_simple(struct vp_device *vp, struct pci_device *pci) + } else { + dprintf(1, "pci dev %pP using legacy (0.9.5) virtio mode\n", pci); + vp->legacy.bar = 0; +- vp->legacy.ioaddr = pci_enable_iobar(pci, PCI_BASE_ADDRESS_0); +- if (!vp->legacy.ioaddr) +- return; +- vp->legacy.mode = VP_ACCESS_IO; ++ ++ /* ++ * Extend the legacy virtio interface to support MMIO bar which ++ * is required by SR-IOV. ++ */ ++ addr = pci_config_readl(pci->bdf, PCI_BASE_ADDRESS_0); ++ if (addr & PCI_BASE_ADDRESS_SPACE_IO) { ++ dprintf(1, "legacy virtio: I/O BAR used\n"); ++ vp->legacy.ioaddr = pci_enable_iobar(pci, PCI_BASE_ADDRESS_0); ++ if (!vp->legacy.ioaddr) ++ return; ++ vp->legacy.mode = VP_ACCESS_IO; ++ } else { ++ dprintf(1, "legacy virtio: MMIO BAR used\n"); ++ vp->legacy.memaddr = pci_enable_membar(pci, PCI_BASE_ADDRESS_0); ++ if (!vp->legacy.memaddr) ++ return; ++ vp->legacy.mode = VP_ACCESS_MMIO; ++ } + } + +- vp_reset(vp); + pci_enable_busmaster(pci); ++ dprintf(1, "pci dev %pP start reset\n", pci); ++ vp_reset(vp); ++ dprintf(1, "pci dev %pP finish reset\n", pci); + vp_set_status(vp, VIRTIO_CONFIG_S_ACKNOWLEDGE | + VIRTIO_CONFIG_S_DRIVER ); + } +-- +2.43.0 + diff --git a/qemu.spec b/qemu.spec index 242a404..cb13b69 100644 --- a/qemu.spec +++ b/qemu.spec @@ -3,7 +3,7 @@ Name: qemu Version: 8.2.0 -Release: 21 +Release: 22 Epoch: 11 Summary: QEMU is a generic and open source machine emulator and virtualizer License: GPLv2 and BSD and MIT and CC-BY-SA-4.0 @@ -382,6 +382,7 @@ Patch0365: hw-audio-virtio-sound-fix-heap-buffer-overflow.patch Patch0366: crypto-run-qcrypto_pbkdf2_count_iters-in-a-new-threa.patch Patch0367: softmmu-physmem-fix-memory-leak-in-dirty_memory_exte.patch Patch0368: tests-bump-QOS_PATH_MAX_ELEMENT_SIZE-again.patch +Patch0369: enable-virtio-device-mmio-access-and-wait-util-virti.patch BuildRequires: flex BuildRequires: gcc @@ -979,6 +980,9 @@ getent passwd qemu >/dev/null || \ %endif %changelog +* Wed Nov 27 2024 fangyi - 11:8.2.0-22 +- seabios: enable virtio device mmio access and wait util virtio device reset done + * Thu Nov 7 2024 Jiabo Feng - 11:8.2.0-21 - tests: bump QOS_PATH_MAX_ELEMENT_SIZE again - softmmu/physmem: fix memory leak in dirty_memory_extend() -- Gitee