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