git: 89c085b8993d - main - Only use byte register access in legacy virtio pci
Andrew Turner
andrew at FreeBSD.org
Wed Aug 11 10:21:50 UTC 2021
The branch main has been updated by andrew:
URL: https://cgit.FreeBSD.org/src/commit/?id=89c085b8993d7d1e7b137f99fa6df94c37c3a68a
commit 89c085b8993d7d1e7b137f99fa6df94c37c3a68a
Author: Andrew Turner <andrew at FreeBSD.org>
AuthorDate: 2021-08-05 14:36:07 +0000
Commit: Andrew Turner <andrew at FreeBSD.org>
CommitDate: 2021-08-11 10:18:54 +0000
Only use byte register access in legacy virtio pci
Some simulators don't implement arbitrary sized memory access to the
virtio PCI registers. Follow Linux and use single byte accesses to read
and write to these registers.
Reviewed by: bryanv, emaste (previous version)
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D31424
---
sys/dev/virtio/pci/virtio_pci_legacy.c | 32 ++++++++------------------------
1 file changed, 8 insertions(+), 24 deletions(-)
diff --git a/sys/dev/virtio/pci/virtio_pci_legacy.c b/sys/dev/virtio/pci/virtio_pci_legacy.c
index 0524529d064b..a0d962058a84 100644
--- a/sys/dev/virtio/pci/virtio_pci_legacy.c
+++ b/sys/dev/virtio/pci/virtio_pci_legacy.c
@@ -506,22 +506,14 @@ vtpci_legacy_read_dev_config(device_t dev, bus_size_t offset,
struct vtpci_legacy_softc *sc;
bus_size_t off;
uint8_t *d;
- int size;
+ int i;
sc = device_get_softc(dev);
off = VIRTIO_PCI_LEGACY_CONFIG(sc) + offset;
- for (d = dst; length > 0; d += size, off += size, length -= size) {
- if (length >= 4) {
- size = 4;
- *(uint32_t *)d = vtpci_legacy_read_config_4(sc, off);
- } else if (length >= 2) {
- size = 2;
- *(uint16_t *)d = vtpci_legacy_read_config_2(sc, off);
- } else {
- size = 1;
- *d = vtpci_legacy_read_config_1(sc, off);
- }
+ d = dst;
+ for (i = 0; i < length; i++) {
+ d[i] = vtpci_legacy_read_config_1(sc, off + i);
}
}
@@ -532,22 +524,14 @@ vtpci_legacy_write_dev_config(device_t dev, bus_size_t offset,
struct vtpci_legacy_softc *sc;
bus_size_t off;
uint8_t *s;
- int size;
+ int i;
sc = device_get_softc(dev);
off = VIRTIO_PCI_LEGACY_CONFIG(sc) + offset;
- for (s = src; length > 0; s += size, off += size, length -= size) {
- if (length >= 4) {
- size = 4;
- vtpci_legacy_write_config_4(sc, off, *(uint32_t *)s);
- } else if (length >= 2) {
- size = 2;
- vtpci_legacy_write_config_2(sc, off, *(uint16_t *)s);
- } else {
- size = 1;
- vtpci_legacy_write_config_1(sc, off, *s);
- }
+ s = src;
+ for (i = 0; i < length; i++) {
+ vtpci_legacy_write_config_1(sc, off + i, s[i]);
}
}
More information about the dev-commits-src-main
mailing list