6 #define LIBPCI_CHECK_VERSION(major,minor,micro) \
7 ((((major) << 16) | ((minor) << 8) | (micro)) <= PCI_LIB_VERSION)
9 #define LIBPCI_CHECK_VERSION(major,minor,micro) \
10 ( (LIBPCI_MAJOR_VERSION > (major)) || \
11 (LIBPCI_MAJOR_VERSION == (major) && LIBPCI_MINOR_VERSION > (minor)) || \
12 (LIBPCI_MAJOR_VERSION == (major) && LIBPCI_MINOR_VERSION == (minor)) && \
13 LIBPCI_MICRO_VERSION >= (micro) )
16 #define PCITAG struct pci_filter *
20 struct pci_access *pacc;
23 struct pci_filter ltag;
34 for (dev = pacc->devices; dev; dev = dev->next) {
35 pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES);
46 PCITAG findPci(unsigned short bx)
50 int bus = (bx >> 8) & 0xFF;
51 int slot = (bx >> 3) & 0x1F;
58 #if LIBPCI_CHECK_VERSION(2,1,99)
59 if (pci_get_dev(pacc, 0, bus, slot, func))
61 if (pci_get_dev(pacc, bus, slot, func))
68 u32 pciSlotBX(PCITAG tag)
70 return (tag->bus << 8) | (tag->slot << 3) | (tag->func);
73 u8 pciReadByte(PCITAG tag, u32 idx)
76 #if LIBPCI_CHECK_VERSION(2,1,99)
77 if ((d = pci_get_dev(pacc, 0, tag->bus, tag->slot, tag->func)))
79 if ((d = pci_get_dev(pacc, tag->bus, tag->slot, tag->func)))
81 return pci_read_byte(d, idx);
83 printf("PCI: device not found while read byte (%x:%x.%x)\n",
84 tag->bus, tag->slot, tag->func);
89 u16 pciReadWord(PCITAG tag, u32 idx)
92 #if LIBPCI_CHECK_VERSION(2,1,99)
93 if ((d = pci_get_dev(pacc, 0, tag->bus, tag->slot, tag->func)))
95 if ((d = pci_get_dev(pacc, tag->bus, tag->slot, tag->func)))
97 return pci_read_word(d, idx);
99 printf("PCI: device not found while read word (%x:%x.%x)\n",
100 tag->bus, tag->slot, tag->func);
105 u32 pciReadLong(PCITAG tag, u32 idx)
108 #if LIBPCI_CHECK_VERSION(2,1,99)
109 if ((d = pci_get_dev(pacc, 0, tag->bus, tag->slot, tag->func)))
111 if ((d = pci_get_dev(pacc, tag->bus, tag->slot, tag->func)))
113 return pci_read_long(d, idx);
115 printf("PCI: device not found while read long (%x:%x.%x)\n",
116 tag->bus, tag->slot, tag->func);
122 void pciWriteLong(PCITAG tag, u32 idx, u32 data)
125 #if LIBPCI_CHECK_VERSION(2,1,99)
126 if ((d = pci_get_dev(pacc, 0, tag->bus, tag->slot, tag->func)))
128 if ((d = pci_get_dev(pacc, tag->bus, tag->slot, tag->func)))
130 pci_write_long(d, idx, data);
133 printf("PCI: device not found while write long (%x:%x.%x)\n",
134 tag->bus, tag->slot, tag->func);
138 void pciWriteWord(PCITAG tag, u32 idx, u16 data)
141 #if LIBPCI_CHECK_VERSION(2,1,99)
142 if ((d = pci_get_dev(pacc, 0, tag->bus, tag->slot, tag->func)))
144 if ((d = pci_get_dev(pacc, tag->bus, tag->slot, tag->func)))
146 pci_write_word(d, idx, data);
149 printf("PCI: device not found while write word (%x:%x.%x)\n",
150 tag->bus, tag->slot, tag->func);
155 void pciWriteByte(PCITAG tag, u32 idx, u8 data)
158 #if LIBPCI_CHECK_VERSION(2,1,99)
159 if ((d = pci_get_dev(pacc, 0, tag->bus, tag->slot, tag->func)))
161 if ((d = pci_get_dev(pacc, tag->bus, tag->slot, tag->func)))
163 pci_write_long(d, idx, data);
166 printf("PCI: device not found while write long (%x:%x.%x)\n",
167 tag->bus, tag->slot, tag->func);