mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 00:03:54 -06:00
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>
This commit is contained in:
parent
246fc0fb66
commit
a795fc08f2
4 changed files with 175 additions and 131 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue