2013-04-16 18:45:16 +04:00
|
|
|
/*
|
|
|
|
* libqos PCI bindings
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2012-2013
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LIBQOS_PCI_H
|
|
|
|
#define LIBQOS_PCI_H
|
|
|
|
|
2014-09-01 14:07:59 +04:00
|
|
|
#include "libqtest.h"
|
2013-04-16 18:45:16 +04:00
|
|
|
|
2016-10-18 09:02:49 +03:00
|
|
|
#define QPCI_PIO_LIMIT 0x10000
|
|
|
|
|
2013-04-16 18:45:16 +04:00
|
|
|
#define QPCI_DEVFN(dev, fn) (((dev) << 3) | (fn))
|
|
|
|
|
|
|
|
typedef struct QPCIDevice QPCIDevice;
|
|
|
|
typedef struct QPCIBus QPCIBus;
|
|
|
|
|
2016-10-19 06:06:51 +03:00
|
|
|
struct QPCIBus {
|
2016-10-18 09:02:49 +03:00
|
|
|
uint8_t (*pio_readb)(QPCIBus *bus, uint32_t addr);
|
|
|
|
uint16_t (*pio_readw)(QPCIBus *bus, uint32_t addr);
|
|
|
|
uint32_t (*pio_readl)(QPCIBus *bus, uint32_t addr);
|
|
|
|
|
|
|
|
uint8_t (*mmio_readb)(QPCIBus *bus, uint32_t addr);
|
|
|
|
uint16_t (*mmio_readw)(QPCIBus *bus, uint32_t addr);
|
|
|
|
uint32_t (*mmio_readl)(QPCIBus *bus, uint32_t addr);
|
|
|
|
|
|
|
|
void (*pio_writeb)(QPCIBus *bus, uint32_t addr, uint8_t value);
|
|
|
|
void (*pio_writew)(QPCIBus *bus, uint32_t addr, uint16_t value);
|
|
|
|
void (*pio_writel)(QPCIBus *bus, uint32_t addr, uint32_t value);
|
2013-04-16 18:45:16 +04:00
|
|
|
|
2016-10-18 09:02:49 +03:00
|
|
|
void (*mmio_writeb)(QPCIBus *bus, uint32_t addr, uint8_t value);
|
|
|
|
void (*mmio_writew)(QPCIBus *bus, uint32_t addr, uint16_t value);
|
|
|
|
void (*mmio_writel)(QPCIBus *bus, uint32_t addr, uint32_t value);
|
2013-04-16 18:45:16 +04:00
|
|
|
|
|
|
|
uint8_t (*config_readb)(QPCIBus *bus, int devfn, uint8_t offset);
|
|
|
|
uint16_t (*config_readw)(QPCIBus *bus, int devfn, uint8_t offset);
|
|
|
|
uint32_t (*config_readl)(QPCIBus *bus, int devfn, uint8_t offset);
|
|
|
|
|
|
|
|
void (*config_writeb)(QPCIBus *bus, int devfn,
|
|
|
|
uint8_t offset, uint8_t value);
|
|
|
|
void (*config_writew)(QPCIBus *bus, int devfn,
|
|
|
|
uint8_t offset, uint16_t value);
|
|
|
|
void (*config_writel)(QPCIBus *bus, int devfn,
|
|
|
|
uint8_t offset, uint32_t value);
|
|
|
|
|
2016-10-19 06:06:51 +03:00
|
|
|
uint16_t pio_alloc_ptr;
|
|
|
|
uint64_t mmio_alloc_ptr, mmio_limit;
|
2013-04-16 18:45:16 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct QPCIDevice
|
|
|
|
{
|
|
|
|
QPCIBus *bus;
|
|
|
|
int devfn;
|
2014-09-01 14:07:59 +04:00
|
|
|
bool msix_enabled;
|
|
|
|
void *msix_table;
|
|
|
|
void *msix_pba;
|
2013-04-16 18:45:16 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id,
|
|
|
|
void (*func)(QPCIDevice *dev, int devfn, void *data),
|
|
|
|
void *data);
|
|
|
|
QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn);
|
|
|
|
|
|
|
|
void qpci_device_enable(QPCIDevice *dev);
|
2014-09-01 14:07:59 +04:00
|
|
|
uint8_t qpci_find_capability(QPCIDevice *dev, uint8_t id);
|
|
|
|
void qpci_msix_enable(QPCIDevice *dev);
|
|
|
|
void qpci_msix_disable(QPCIDevice *dev);
|
|
|
|
bool qpci_msix_pending(QPCIDevice *dev, uint16_t entry);
|
|
|
|
bool qpci_msix_masked(QPCIDevice *dev, uint16_t entry);
|
|
|
|
uint16_t qpci_msix_table_size(QPCIDevice *dev);
|
2013-04-16 18:45:16 +04:00
|
|
|
|
|
|
|
uint8_t qpci_config_readb(QPCIDevice *dev, uint8_t offset);
|
|
|
|
uint16_t qpci_config_readw(QPCIDevice *dev, uint8_t offset);
|
|
|
|
uint32_t qpci_config_readl(QPCIDevice *dev, uint8_t offset);
|
|
|
|
|
|
|
|
void qpci_config_writeb(QPCIDevice *dev, uint8_t offset, uint8_t value);
|
|
|
|
void qpci_config_writew(QPCIDevice *dev, uint8_t offset, uint16_t value);
|
|
|
|
void qpci_config_writel(QPCIDevice *dev, uint8_t offset, uint32_t value);
|
|
|
|
|
|
|
|
uint8_t qpci_io_readb(QPCIDevice *dev, void *data);
|
|
|
|
uint16_t qpci_io_readw(QPCIDevice *dev, void *data);
|
|
|
|
uint32_t qpci_io_readl(QPCIDevice *dev, void *data);
|
|
|
|
|
|
|
|
void qpci_io_writeb(QPCIDevice *dev, void *data, uint8_t value);
|
|
|
|
void qpci_io_writew(QPCIDevice *dev, void *data, uint16_t value);
|
|
|
|
void qpci_io_writel(QPCIDevice *dev, void *data, uint32_t value);
|
|
|
|
|
2014-08-05 01:11:24 +04:00
|
|
|
void *qpci_iomap(QPCIDevice *dev, int barno, uint64_t *sizeptr);
|
2013-04-16 18:45:16 +04:00
|
|
|
void qpci_iounmap(QPCIDevice *dev, void *data);
|
libqos: Better handling of PCI legacy IO
The usual model for PCI IO with libqos is to use qpci_iomap() to map a
specific BAR for a PCI device, then perform IOs within that BAR using
qpci_io_{read,write}*().
However, certain devices also have legacy PCI IO. In this case, instead of
(or as well as) being accessed via PCI BARs, the device can be accessed
via certain well-known, fixed addresses in PCI IO space.
Two existing tests use legacy PCI IO, and take different flawed approaches
to it:
* tco-test manually constructs a tco_io_base value instead of calling
qpci_iomap(), which assumes internal knowledge of the structure of
the value it shouldn't have
* ide-test uses direct in*() and out*() calls instead of using
qpci_io_*() accessors, meaning it's not portable to non-x86 machine
types.
This patch implements a new qpci_iomap_legacy() interface which gets a
handle in the same format as qpci_iomap() but refers to a region in
the legacy PIO space. For a device which has the same registers
available both in a BAR and in legacy space (quite common), this
allows the same test code to test both options with just a different
iomap() at the beginning.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
2016-10-19 09:43:42 +03:00
|
|
|
void *qpci_legacy_iomap(QPCIDevice *dev, uint16_t addr);
|
2013-04-16 18:45:16 +04:00
|
|
|
|
2014-09-26 13:28:08 +04:00
|
|
|
void qpci_plug_device_test(const char *driver, const char *id,
|
|
|
|
uint8_t slot, const char *opts);
|
|
|
|
void qpci_unplug_acpi_device_test(const char *id, uint8_t slot);
|
2013-04-16 18:45:16 +04:00
|
|
|
#endif
|