diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2016-10-18 17:02:49 +1100 |
---|---|---|
committer | David Gibson <david@gibson.dropbear.id.au> | 2016-10-28 09:38:27 +1100 |
commit | a795fc08f2636013fe097e51bdac62d089ac505a (patch) | |
tree | 42d6e2e8ed55611a33149a1529968690b024e6a7 /tests/libqos/pci-pc.c | |
parent | 246fc0fb66cbf861b0e76320626b059e2d49ea12 (diff) |
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-pc.c')
-rw-r--r-- | tests/libqos/pci-pc.c | 107 |
1 files changed, 50 insertions, 57 deletions
diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c index 9600ed6e41..51dff8a7fa 100644 --- a/tests/libqos/pci-pc.c +++ b/tests/libqos/pci-pc.c @@ -36,79 +36,64 @@ typedef struct QPCIBusPC uint16_t pci_iohole_alloc; } QPCIBusPC; -static uint8_t qpci_pc_io_readb(QPCIBus *bus, void *addr) +static uint8_t qpci_pc_pio_readb(QPCIBus *bus, uint32_t addr) { - uintptr_t port = (uintptr_t)addr; - uint8_t value; - - if (port < 0x10000) { - value = inb(port); - } else { - value = readb(port); - } - - return value; + return inb(addr); } -static uint16_t qpci_pc_io_readw(QPCIBus *bus, void *addr) +static uint8_t qpci_pc_mmio_readb(QPCIBus *bus, uint32_t addr) { - uintptr_t port = (uintptr_t)addr; - uint16_t value; - - if (port < 0x10000) { - value = inw(port); - } else { - value = readw(port); - } + return readb(addr); +} - return value; +static void qpci_pc_pio_writeb(QPCIBus *bus, uint32_t addr, uint8_t val) +{ + outb(addr, val); } -static uint32_t qpci_pc_io_readl(QPCIBus *bus, void *addr) +static void qpci_pc_mmio_writeb(QPCIBus *bus, uint32_t addr, uint8_t val) { - uintptr_t port = (uintptr_t)addr; - uint32_t value; + writeb(addr, val); +} - if (port < 0x10000) { - value = inl(port); - } else { - value = readl(port); - } +static uint16_t qpci_pc_pio_readw(QPCIBus *bus, uint32_t addr) +{ + return inw(addr); +} - return value; +static uint16_t qpci_pc_mmio_readw(QPCIBus *bus, uint32_t addr) +{ + return readw(addr); } -static void qpci_pc_io_writeb(QPCIBus *bus, void *addr, uint8_t value) +static void qpci_pc_pio_writew(QPCIBus *bus, uint32_t addr, uint16_t val) { - uintptr_t port = (uintptr_t)addr; + outw(addr, val); +} - if (port < 0x10000) { - outb(port, value); - } else { - writeb(port, value); - } +static void qpci_pc_mmio_writew(QPCIBus *bus, uint32_t addr, uint16_t val) +{ + writew(addr, val); } -static void qpci_pc_io_writew(QPCIBus *bus, void *addr, uint16_t value) +static uint32_t qpci_pc_pio_readl(QPCIBus *bus, uint32_t addr) { - uintptr_t port = (uintptr_t)addr; + return inl(addr); +} - if (port < 0x10000) { - outw(port, value); - } else { - writew(port, value); - } +static uint32_t qpci_pc_mmio_readl(QPCIBus *bus, uint32_t addr) +{ + return readl(addr); } -static void qpci_pc_io_writel(QPCIBus *bus, void *addr, uint32_t value) +static void qpci_pc_pio_writel(QPCIBus *bus, uint32_t addr, uint32_t val) { - uintptr_t port = (uintptr_t)addr; + outl(addr, val); +} - if (port < 0x10000) { - outl(port, value); - } else { - writel(port, value); - } +static void qpci_pc_mmio_writel(QPCIBus *bus, uint32_t addr, uint32_t val) +{ + writel(addr, val); } static uint8_t qpci_pc_config_readb(QPCIBus *bus, int devfn, uint8_t offset) @@ -218,13 +203,21 @@ QPCIBus *qpci_init_pc(QGuestAllocator *alloc) ret = g_malloc(sizeof(*ret)); - ret->bus.io_readb = qpci_pc_io_readb; - ret->bus.io_readw = qpci_pc_io_readw; - ret->bus.io_readl = qpci_pc_io_readl; + ret->bus.pio_readb = qpci_pc_pio_readb; + ret->bus.pio_readw = qpci_pc_pio_readw; + ret->bus.pio_readl = qpci_pc_pio_readl; + + ret->bus.pio_writeb = qpci_pc_pio_writeb; + ret->bus.pio_writew = qpci_pc_pio_writew; + ret->bus.pio_writel = qpci_pc_pio_writel; + + ret->bus.mmio_readb = qpci_pc_mmio_readb; + ret->bus.mmio_readw = qpci_pc_mmio_readw; + ret->bus.mmio_readl = qpci_pc_mmio_readl; - ret->bus.io_writeb = qpci_pc_io_writeb; - ret->bus.io_writew = qpci_pc_io_writew; - ret->bus.io_writel = qpci_pc_io_writel; + ret->bus.mmio_writeb = qpci_pc_mmio_writeb; + ret->bus.mmio_writew = qpci_pc_mmio_writew; + ret->bus.mmio_writel = qpci_pc_mmio_writel; ret->bus.config_readb = qpci_pc_config_readb; ret->bus.config_readw = qpci_pc_config_readw; |