mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 15:53:54 -06:00
libqos: Give qvirtio_config_read*() consistent semantics
The 'addr' parameter to qvirtio_config_read*() doesn't have a consistent meaning: when using the virtio-pci versions, it's a full PCI space address, but for virtio-mmio, it's an offset from the device's base mmio address. This means that the callers need to do different things to calculate the addresses in the two cases, which rather defeats the purpose of function pointer backends. All the current users of these functions are using them to retrieve variables from the device specific portion of the virtio config space. So, this patch alters the semantics to always be an offset into that device specific config area. 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
a37eb9fccd
commit
246fc0fb66
5 changed files with 36 additions and 59 deletions
|
@ -62,10 +62,13 @@ static void qvirtio_pci_assign_device(QVirtioDevice *d, void *data)
|
|||
*vpcidev = (QVirtioPCIDevice *)d;
|
||||
}
|
||||
|
||||
static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, uint64_t addr)
|
||||
#define CONFIG_BASE(dev) \
|
||||
((dev)->addr + VIRTIO_PCI_CONFIG_OFF((dev)->pdev->msix_enabled))
|
||||
|
||||
static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, uint64_t off)
|
||||
{
|
||||
QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
|
||||
return qpci_io_readb(dev->pdev, (void *)(uintptr_t)addr);
|
||||
return qpci_io_readb(dev->pdev, CONFIG_BASE(dev) + off);
|
||||
}
|
||||
|
||||
/* PCI is always read in little-endian order
|
||||
|
@ -76,31 +79,31 @@ static uint8_t qvirtio_pci_config_readb(QVirtioDevice *d, uint64_t addr)
|
|||
* case will be managed inside qvirtio_is_big_endian()
|
||||
*/
|
||||
|
||||
static uint16_t qvirtio_pci_config_readw(QVirtioDevice *d, uint64_t addr)
|
||||
static uint16_t qvirtio_pci_config_readw(QVirtioDevice *d, uint64_t off)
|
||||
{
|
||||
QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
|
||||
uint16_t value;
|
||||
|
||||
value = qpci_io_readw(dev->pdev, (void *)(uintptr_t)addr);
|
||||
value = qpci_io_readw(dev->pdev, CONFIG_BASE(dev) + off);
|
||||
if (qvirtio_is_big_endian(d)) {
|
||||
value = bswap16(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
static uint32_t qvirtio_pci_config_readl(QVirtioDevice *d, uint64_t addr)
|
||||
static uint32_t qvirtio_pci_config_readl(QVirtioDevice *d, uint64_t off)
|
||||
{
|
||||
QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
|
||||
uint32_t value;
|
||||
|
||||
value = qpci_io_readl(dev->pdev, (void *)(uintptr_t)addr);
|
||||
value = qpci_io_readl(dev->pdev, CONFIG_BASE(dev) + off);
|
||||
if (qvirtio_is_big_endian(d)) {
|
||||
value = bswap32(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, uint64_t addr)
|
||||
static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, uint64_t off)
|
||||
{
|
||||
QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
|
||||
int i;
|
||||
|
@ -108,13 +111,13 @@ static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, uint64_t addr)
|
|||
|
||||
if (qvirtio_is_big_endian(d)) {
|
||||
for (i = 0; i < 8; ++i) {
|
||||
u64 |= (uint64_t)qpci_io_readb(dev->pdev,
|
||||
(void *)(uintptr_t)addr + i) << (7 - i) * 8;
|
||||
u64 |= (uint64_t)qpci_io_readb(dev->pdev, CONFIG_BASE(dev)
|
||||
+ off + i) << (7 - i) * 8;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < 8; ++i) {
|
||||
u64 |= (uint64_t)qpci_io_readb(dev->pdev,
|
||||
(void *)(uintptr_t)addr + i) << i * 8;
|
||||
u64 |= (uint64_t)qpci_io_readb(dev->pdev, CONFIG_BASE(dev)
|
||||
+ off + i) << i * 8;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue