qemu/tests/libqos/pci.h
<<
>>
Prefs
   1/*
   2 * libqos PCI bindings
   3 *
   4 * Copyright IBM, Corp. 2012-2013
   5 *
   6 * Authors:
   7 *  Anthony Liguori   <aliguori@us.ibm.com>
   8 *
   9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
  10 * See the COPYING file in the top-level directory.
  11 */
  12
  13#ifndef LIBQOS_PCI_H
  14#define LIBQOS_PCI_H
  15
  16#include <stdint.h>
  17#include "libqtest.h"
  18
  19#define QPCI_DEVFN(dev, fn) (((dev) << 3) | (fn))
  20
  21typedef struct QPCIDevice QPCIDevice;
  22typedef struct QPCIBus QPCIBus;
  23
  24struct QPCIBus
  25{
  26    uint8_t (*io_readb)(QPCIBus *bus, void *addr);
  27    uint16_t (*io_readw)(QPCIBus *bus, void *addr);
  28    uint32_t (*io_readl)(QPCIBus *bus, void *addr);
  29
  30    void (*io_writeb)(QPCIBus *bus, void *addr, uint8_t value);
  31    void (*io_writew)(QPCIBus *bus, void *addr, uint16_t value);
  32    void (*io_writel)(QPCIBus *bus, void *addr, uint32_t value);
  33
  34    uint8_t (*config_readb)(QPCIBus *bus, int devfn, uint8_t offset);
  35    uint16_t (*config_readw)(QPCIBus *bus, int devfn, uint8_t offset);
  36    uint32_t (*config_readl)(QPCIBus *bus, int devfn, uint8_t offset);
  37
  38    void (*config_writeb)(QPCIBus *bus, int devfn,
  39                          uint8_t offset, uint8_t value);
  40    void (*config_writew)(QPCIBus *bus, int devfn,
  41                          uint8_t offset, uint16_t value);
  42    void (*config_writel)(QPCIBus *bus, int devfn,
  43                          uint8_t offset, uint32_t value);
  44
  45    void *(*iomap)(QPCIBus *bus, QPCIDevice *dev, int barno, uint64_t *sizeptr);
  46    void (*iounmap)(QPCIBus *bus, void *data);
  47};
  48
  49struct QPCIDevice
  50{
  51    QPCIBus *bus;
  52    int devfn;
  53    bool msix_enabled;
  54    void *msix_table;
  55    void *msix_pba;
  56};
  57
  58void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id,
  59                         void (*func)(QPCIDevice *dev, int devfn, void *data),
  60                         void *data);
  61QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn);
  62
  63void qpci_device_enable(QPCIDevice *dev);
  64uint8_t qpci_find_capability(QPCIDevice *dev, uint8_t id);
  65void qpci_msix_enable(QPCIDevice *dev);
  66void qpci_msix_disable(QPCIDevice *dev);
  67bool qpci_msix_pending(QPCIDevice *dev, uint16_t entry);
  68bool qpci_msix_masked(QPCIDevice *dev, uint16_t entry);
  69uint16_t qpci_msix_table_size(QPCIDevice *dev);
  70
  71uint8_t qpci_config_readb(QPCIDevice *dev, uint8_t offset);
  72uint16_t qpci_config_readw(QPCIDevice *dev, uint8_t offset);
  73uint32_t qpci_config_readl(QPCIDevice *dev, uint8_t offset);
  74
  75void qpci_config_writeb(QPCIDevice *dev, uint8_t offset, uint8_t value);
  76void qpci_config_writew(QPCIDevice *dev, uint8_t offset, uint16_t value);
  77void qpci_config_writel(QPCIDevice *dev, uint8_t offset, uint32_t value);
  78
  79uint8_t qpci_io_readb(QPCIDevice *dev, void *data);
  80uint16_t qpci_io_readw(QPCIDevice *dev, void *data);
  81uint32_t qpci_io_readl(QPCIDevice *dev, void *data);
  82
  83void qpci_io_writeb(QPCIDevice *dev, void *data, uint8_t value);
  84void qpci_io_writew(QPCIDevice *dev, void *data, uint16_t value);
  85void qpci_io_writel(QPCIDevice *dev, void *data, uint32_t value);
  86
  87void *qpci_iomap(QPCIDevice *dev, int barno, uint64_t *sizeptr);
  88void qpci_iounmap(QPCIDevice *dev, void *data);
  89
  90void qpci_plug_device_test(const char *driver, const char *id,
  91                           uint8_t slot, const char *opts);
  92void qpci_unplug_acpi_device_test(const char *id, uint8_t slot);
  93#endif
  94