seabios: enable virtio device mmio access and wait util virtio device reset done

This commit is contained in:
fangyi 2024-11-27 15:17:38 +08:00
parent aa16691f24
commit 5f745d0bc9
2 changed files with 92 additions and 1 deletions

View File

@ -0,0 +1,87 @@
From 0a179313fde1f71a8a7520c3d3149aa2dc4e66b2 Mon Sep 17 00:00:00 2001
From: fangyi <eric.fangyi@huawei.com>
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

View File

@ -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 <eric.fangyi@huawei.com> - 11:8.2.0-22
- seabios: enable virtio device mmio access and wait util virtio device reset done
* Thu Nov 7 2024 Jiabo Feng <fengjiabo1@huawei.com> - 11:8.2.0-21
- tests: bump QOS_PATH_MAX_ELEMENT_SIZE again
- softmmu/physmem: fix memory leak in dirty_memory_extend()