1*433d6423SLionel Sambuc #ifndef _DDEKIT_PCI_H 2*433d6423SLionel Sambuc #define _DDEKIT_PCI_H 3*433d6423SLionel Sambuc #include <ddekit/ddekit.h> 4*433d6423SLionel Sambuc 5*433d6423SLionel Sambuc #include <ddekit/types.h> 6*433d6423SLionel Sambuc 7*433d6423SLionel Sambuc /** \defgroup DDEKit_pci */ 8*433d6423SLionel Sambuc 9*433d6423SLionel Sambuc /** Our version of PCI_ANY_ID */ 10*433d6423SLionel Sambuc #define DDEKIT_PCI_ANY_ID (~0) 11*433d6423SLionel Sambuc 12*433d6423SLionel Sambuc /** Copy of L4IO_PCIDEV_RES */ 13*433d6423SLionel Sambuc #define DDEKIT_PCIDEV_RES 12 14*433d6423SLionel Sambuc 15*433d6423SLionel Sambuc struct ddekit_pci_dev; 16*433d6423SLionel Sambuc 17*433d6423SLionel Sambuc /** PCI resource descriptor. Copied from generic_io. 18*433d6423SLionel Sambuc * 19*433d6423SLionel Sambuc * XXX! 20*433d6423SLionel Sambuc */ 21*433d6423SLionel Sambuc typedef struct ddekit_pci_resource { 22*433d6423SLionel Sambuc unsigned long start; 23*433d6423SLionel Sambuc unsigned long end; 24*433d6423SLionel Sambuc unsigned long flags; 25*433d6423SLionel Sambuc } ddekit_pci_res_t; 26*433d6423SLionel Sambuc 27*433d6423SLionel Sambuc void ddekit_pci_init(void); 28*433d6423SLionel Sambuc 29*433d6423SLionel Sambuc int ddekit_pci_get_device(int nr, int *bus, int *slot, int *func); 30*433d6423SLionel Sambuc 31*433d6423SLionel Sambuc int ddekit_pci_read(int bus, int slot, int func, int pos, int len, 32*433d6423SLionel Sambuc ddekit_uint32_t *val); 33*433d6423SLionel Sambuc int ddekit_pci_write(int bus, int slot, int func, int pos, int len, 34*433d6423SLionel Sambuc ddekit_uint32_t val); 35*433d6423SLionel Sambuc 36*433d6423SLionel Sambuc /** Read byte from PCI config space. 37*433d6423SLionel Sambuc * 38*433d6423SLionel Sambuc * \ingroup DDEKit_pci 39*433d6423SLionel Sambuc * 40*433d6423SLionel Sambuc * \param bus bus ID 41*433d6423SLionel Sambuc * \param slot slot # 42*433d6423SLionel Sambuc * \param func function # 43*433d6423SLionel Sambuc * \param pos offset in config space 44*433d6423SLionel Sambuc * \retval val read value 45*433d6423SLionel Sambuc * 46*433d6423SLionel Sambuc * \return 0 success 47*433d6423SLionel Sambuc */ 48*433d6423SLionel Sambuc int ddekit_pci_readb(int bus, int slot, int func, int pos, 49*433d6423SLionel Sambuc ddekit_uint8_t *val); 50*433d6423SLionel Sambuc 51*433d6423SLionel Sambuc /** Read word from PCI config space. 52*433d6423SLionel Sambuc * 53*433d6423SLionel Sambuc * \ingroup DDEKit_pci 54*433d6423SLionel Sambuc * 55*433d6423SLionel Sambuc * \param bus bus ID 56*433d6423SLionel Sambuc * \param slot slot # 57*433d6423SLionel Sambuc * \param func function # 58*433d6423SLionel Sambuc * \param pos offset in config space 59*433d6423SLionel Sambuc * \retval val read value 60*433d6423SLionel Sambuc * 61*433d6423SLionel Sambuc * \return 0 success 62*433d6423SLionel Sambuc */ 63*433d6423SLionel Sambuc int ddekit_pci_readw(int bus, int slot, int func, int pos, 64*433d6423SLionel Sambuc ddekit_uint16_t *val); 65*433d6423SLionel Sambuc 66*433d6423SLionel Sambuc /** Read dword from PCI config space. 67*433d6423SLionel Sambuc * 68*433d6423SLionel Sambuc * \ingroup DDEKit_pci 69*433d6423SLionel Sambuc * 70*433d6423SLionel Sambuc * \param bus bus ID 71*433d6423SLionel Sambuc * \param slot slot # 72*433d6423SLionel Sambuc * \param func function # 73*433d6423SLionel Sambuc * \param pos offset in config space 74*433d6423SLionel Sambuc * \retval val read value 75*433d6423SLionel Sambuc * 76*433d6423SLionel Sambuc * \return 0 success 77*433d6423SLionel Sambuc */ 78*433d6423SLionel Sambuc int ddekit_pci_readl(int bus, int slot, int func, int pos, 79*433d6423SLionel Sambuc ddekit_uint32_t *val); 80*433d6423SLionel Sambuc 81*433d6423SLionel Sambuc /** Write byte to PCI config space. 82*433d6423SLionel Sambuc * 83*433d6423SLionel Sambuc * \ingroup DDEKit_pci 84*433d6423SLionel Sambuc * 85*433d6423SLionel Sambuc * \param bus bus ID 86*433d6423SLionel Sambuc * \param slot slot # 87*433d6423SLionel Sambuc * \param func function # 88*433d6423SLionel Sambuc * \param pos offset in config space 89*433d6423SLionel Sambuc * \retval val value to write 90*433d6423SLionel Sambuc * 91*433d6423SLionel Sambuc * \return 0 success 92*433d6423SLionel Sambuc */ 93*433d6423SLionel Sambuc int ddekit_pci_writeb(int bus, int slot, int func, int pos, 94*433d6423SLionel Sambuc ddekit_uint8_t val); 95*433d6423SLionel Sambuc 96*433d6423SLionel Sambuc /** Write word to PCI config space. 97*433d6423SLionel Sambuc * 98*433d6423SLionel Sambuc * \ingroup DDEKit_pci 99*433d6423SLionel Sambuc * 100*433d6423SLionel Sambuc * \param bus bus ID 101*433d6423SLionel Sambuc * \param slot slot # 102*433d6423SLionel Sambuc * \param func function # 103*433d6423SLionel Sambuc * \param pos offset in config space 104*433d6423SLionel Sambuc * \retval val value to write 105*433d6423SLionel Sambuc * 106*433d6423SLionel Sambuc * \return 0 success 107*433d6423SLionel Sambuc */ 108*433d6423SLionel Sambuc int ddekit_pci_writew(int bus, int slot, int func, int pos, 109*433d6423SLionel Sambuc ddekit_uint16_t val); 110*433d6423SLionel Sambuc 111*433d6423SLionel Sambuc /** Write word to PCI config space. 112*433d6423SLionel Sambuc * 113*433d6423SLionel Sambuc * \ingroup DDEKit_pci 114*433d6423SLionel Sambuc * 115*433d6423SLionel Sambuc * \param bus bus ID 116*433d6423SLionel Sambuc * \param slot slot # 117*433d6423SLionel Sambuc * \param func function # 118*433d6423SLionel Sambuc * \param pos offset in config space 119*433d6423SLionel Sambuc * \retval val value to write 120*433d6423SLionel Sambuc * 121*433d6423SLionel Sambuc * \return 0 success 122*433d6423SLionel Sambuc */ 123*433d6423SLionel Sambuc int ddekit_pci_writel(int bus, int slot, int func, int pos, 124*433d6423SLionel Sambuc ddekit_uint32_t val); 125*433d6423SLionel Sambuc 126*433d6423SLionel Sambuc /** Find a PCI device. 127*433d6423SLionel Sambuc * 128*433d6423SLionel Sambuc * \ingroup DDEKit_pci 129*433d6423SLionel Sambuc * 130*433d6423SLionel Sambuc * \param bus pointer to bus number or \ref DDEKIT_PCI_ANY_ID 131*433d6423SLionel Sambuc * \param slot pointer to slot number (devfn >> DEVFN_SLOTSHIFT) or \ref DDEKIT_PCI_ANY_ID 132*433d6423SLionel Sambuc * \param func pointer to func number (devfc & DEVFN_FUNCMASK) or \ref DDEKIT_PCI_ANY_ID 133*433d6423SLionel Sambuc * \param start search device list only behind this device (excluding it!), NULL 134*433d6423SLionel Sambuc * searches whole device list 135*433d6423SLionel Sambuc * 136*433d6423SLionel Sambuc * \retval bus bus number 137*433d6423SLionel Sambuc * \retval slot slot number 138*433d6423SLionel Sambuc * \retval func function number 139*433d6423SLionel Sambuc * 140*433d6423SLionel Sambuc * \return device a valid PCI device 141*433d6423SLionel Sambuc * \return NULL if no device found 142*433d6423SLionel Sambuc */ 143*433d6423SLionel Sambuc struct ddekit_pci_dev * ddekit_pci_find_device(int *bus, int *slot, int 144*433d6423SLionel Sambuc *func, struct ddekit_pci_dev *start); 145*433d6423SLionel Sambuc 146*433d6423SLionel Sambuc /** Enable PCI device 147*433d6423SLionel Sambuc * \ingroup DDEKit_pci 148*433d6423SLionel Sambuc */ 149*433d6423SLionel Sambuc int ddekit_pci_enable_device(struct ddekit_pci_dev *dev); 150*433d6423SLionel Sambuc 151*433d6423SLionel Sambuc /** Disable PCI device 152*433d6423SLionel Sambuc * \ingroup DDEKit_pci 153*433d6423SLionel Sambuc */ 154*433d6423SLionel Sambuc int ddekit_pci_disable_device(struct ddekit_pci_dev *dev); 155*433d6423SLionel Sambuc 156*433d6423SLionel Sambuc /** Enable bus-mastering for device. 157*433d6423SLionel Sambuc * \ingroup DDEKit_pci 158*433d6423SLionel Sambuc */ 159*433d6423SLionel Sambuc void ddekit_pci_set_master(struct ddekit_pci_dev *dev); 160*433d6423SLionel Sambuc 161*433d6423SLionel Sambuc /** Get device vendor ID. 162*433d6423SLionel Sambuc * \ingroup DDEKit_pci 163*433d6423SLionel Sambuc */ 164*433d6423SLionel Sambuc unsigned short ddekit_pci_get_vendor(struct ddekit_pci_dev *dev); 165*433d6423SLionel Sambuc 166*433d6423SLionel Sambuc /** Get device ID. 167*433d6423SLionel Sambuc * \ingroup DDEKit_pci 168*433d6423SLionel Sambuc */ 169*433d6423SLionel Sambuc unsigned short ddekit_pci_get_device_id(struct ddekit_pci_dev *dev); 170*433d6423SLionel Sambuc 171*433d6423SLionel Sambuc /** Get device subvendor ID. 172*433d6423SLionel Sambuc * \ingroup DDEKit_pci 173*433d6423SLionel Sambuc */ 174*433d6423SLionel Sambuc unsigned short ddekit_pci_get_sub_vendor(struct ddekit_pci_dev *dev); 175*433d6423SLionel Sambuc 176*433d6423SLionel Sambuc /** Get subdevice ID. 177*433d6423SLionel Sambuc * \ingroup DDEKit_pci 178*433d6423SLionel Sambuc */ 179*433d6423SLionel Sambuc unsigned short ddekit_pci_get_sub_device(struct ddekit_pci_dev *dev); 180*433d6423SLionel Sambuc 181*433d6423SLionel Sambuc /** Get device class ID. 182*433d6423SLionel Sambuc * \ingroup DDEKit_pci 183*433d6423SLionel Sambuc */ 184*433d6423SLionel Sambuc unsigned ddekit_pci_get_dev_class(struct ddekit_pci_dev *dev); 185*433d6423SLionel Sambuc 186*433d6423SLionel Sambuc /** Get device's IRQ number. 187*433d6423SLionel Sambuc * \ingroup DDEKit_pci 188*433d6423SLionel Sambuc */ 189*433d6423SLionel Sambuc unsigned long ddekit_pci_get_irq(struct ddekit_pci_dev *dev); 190*433d6423SLionel Sambuc 191*433d6423SLionel Sambuc /** Get device name. 192*433d6423SLionel Sambuc * \ingroup DDEKit_pci 193*433d6423SLionel Sambuc */ 194*433d6423SLionel Sambuc char *ddekit_pci_get_name(struct ddekit_pci_dev *dev); 195*433d6423SLionel Sambuc 196*433d6423SLionel Sambuc /** Get device's slot name. 197*433d6423SLionel Sambuc * \ingroup DDEKit_pci 198*433d6423SLionel Sambuc */ 199*433d6423SLionel Sambuc char *ddekit_pci_get_slot_name(struct ddekit_pci_dev *dev); 200*433d6423SLionel Sambuc 201*433d6423SLionel Sambuc /** Get one of the device's resources. 202*433d6423SLionel Sambuc * \ingroup DDEKit_pci 203*433d6423SLionel Sambuc */ 204*433d6423SLionel Sambuc ddekit_pci_res_t *ddekit_pci_get_resource(struct ddekit_pci_dev *dev, 205*433d6423SLionel Sambuc unsigned int idx); 206*433d6423SLionel Sambuc 207*433d6423SLionel Sambuc int ddekit_pci_irq_enable(int bus, int slot, int func, int pin, int 208*433d6423SLionel Sambuc *irq); 209*433d6423SLionel Sambuc 210*433d6423SLionel Sambuc #endif 211