diff options
author | David Gibson | 2016-10-18 08:02:49 +0200 |
---|---|---|
committer | David Gibson | 2016-10-28 00:38:27 +0200 |
commit | a795fc08f2636013fe097e51bdac62d089ac505a (patch) | |
tree | 42d6e2e8ed55611a33149a1529968690b024e6a7 /tests/libqos/pci.c | |
parent | libqos: Give qvirtio_config_read*() consistent semantics (diff) | |
download | qemu-a795fc08f2636013fe097e51bdac62d089ac505a.tar.gz qemu-a795fc08f2636013fe097e51bdac62d089ac505a.tar.xz qemu-a795fc08f2636013fe097e51bdac62d089ac505a.zip |
libqos: Handle PCI IO de-multiplexing in common code
The PCI IO space (aka PIO, aka legacy IO) and PCI memory space (aka MMIO)
are distinct address spaces by the PCI spec (although parts of one might be
aliased to parts of the other in some cases).
However, qpci_io_read*() and qpci_io_write*() can perform accesses to
either space depending on parameter. That's convenient for test case
drivers, since there are a fair few devices which can be controlled via
either a PIO or MMIO BAR but with an otherwise identical driver.
This is implemented by having addresses below 64kiB treated as PIO, and
those above treated as MMIO. This works because low addresses in memory
space are generally reserved for DMA rather than MMIO.
At the moment, this demultiplexing must be handled by each PCI backend
(pc and spapr, so far). There's no real reason for this - the current
encoding is likely to work for all platforms, and even if it doesn't we
can still use a more complex common encoding since the value returned from
iomap are semi-opaque.
This patch moves the demultiplexing into the common part of the libqos PCI
code, with the backends having simpler, separate accessors for PIO and
MMIO space. This also means we have a way of explicitly accessing either
space if it's necessary for some special case.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Diffstat (limited to 'tests/libqos/pci.c')
-rw-r--r-- | tests/libqos/pci.c | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c index c3f3382b7c..55b01df37b 100644 --- a/tests/libqos/pci.c +++ b/tests/libqos/pci.c @@ -224,33 +224,68 @@ void qpci_config_writel(QPCIDevice *dev, uint8_t offset, uint32_t value) uint8_t qpci_io_readb(QPCIDevice *dev, void *data) { - return dev->bus->io_readb(dev->bus, data); + uintptr_t addr = (uintptr_t)data; + + if (addr < QPCI_PIO_LIMIT) { + return dev->bus->pio_readb(dev->bus, addr); + } else { + return dev->bus->mmio_readb(dev->bus, addr); + } } uint16_t qpci_io_readw(QPCIDevice *dev, void *data) { - return dev->bus->io_readw(dev->bus, data); + uintptr_t addr = (uintptr_t)data; + + if (addr < QPCI_PIO_LIMIT) { + return dev->bus->pio_readw(dev->bus, addr); + } else { + return dev->bus->mmio_readw(dev->bus, addr); + } } uint32_t qpci_io_readl(QPCIDevice *dev, void *data) { - return dev->bus->io_readl(dev->bus, data); -} + uintptr_t addr = (uintptr_t)data; + if (addr < QPCI_PIO_LIMIT) { + return dev->bus->pio_readl(dev->bus, addr); + } else { + return dev->bus->mmio_readl(dev->bus, addr); + } +} void qpci_io_writeb(QPCIDevice *dev, void *data, uint8_t value) { - dev->bus->io_writeb(dev->bus, data, value); + uintptr_t addr = (uintptr_t)data; + + if (addr < QPCI_PIO_LIMIT) { + dev->bus->pio_writeb(dev->bus, addr, value); + } else { + dev->bus->mmio_writeb(dev->bus, addr, value); + } } void qpci_io_writew(QPCIDevice *dev, void *data, uint16_t value) { - dev->bus->io_writew(dev->bus, data, value); + uintptr_t addr = (uintptr_t)data; + + if (addr < QPCI_PIO_LIMIT) { + dev->bus->pio_writew(dev->bus, addr, value); + } else { + dev->bus->mmio_writew(dev->bus, addr, value); + } } void qpci_io_writel(QPCIDevice *dev, void *data, uint32_t value) { - dev->bus->io_writel(dev->bus, data, value); + uintptr_t addr = (uintptr_t)data; + + if (addr < QPCI_PIO_LIMIT) { + dev->bus->pio_writel(dev->bus, addr, value); + } else { + dev->bus->mmio_writel(dev->bus, addr, value); + } } void *qpci_iomap(QPCIDevice *dev, int barno, uint64_t *sizeptr) |