18 #include <linux/kernel.h>
20 #include <linux/pci.h>
22 #include <asm/pci-bridge.h>
58 # define DBG(x...) printk(x)
63 static int pciauto_upper_iospc;
64 static int pciauto_upper_memspc;
66 static struct pci_dev pciauto_dev;
67 static struct pci_bus pciauto_bus;
76 pciauto_setup_bars(
struct pci_dev *
dev,
int bar_limit)
88 pci_write_config_dword(dev, bar, 0xffffffff);
89 pci_read_config_dword(dev, bar, &bar_size);
99 upper_limit = &pciauto_upper_iospc;
100 DBG(
"PCI Autoconfig: BAR %d, I/O, ", bar_nr);
109 upper_limit = &pciauto_upper_memspc;
110 DBG(
"PCI Autoconfig: BAR %d, Mem, ", bar_nr);
114 *upper_limit = (*upper_limit + bar_size) & bar_size;
117 pci_write_config_dword(dev, bar, *upper_limit);
126 pci_write_config_dword(dev, (bar+=4), 0x00000000);
128 DBG(
"size=0x%x, address=0x%x\n", ~bar_size + 1, *upper_limit);
144 if (pin == 0 || pin > 4)
147 if (pci_ctrl->map_irq)
148 irq = pci_ctrl->map_irq(dev,
PCI_SLOT(devfn), pin);
153 DBG(
"PCI Autoconfig: Interrupt %d, pin %d\n", irq, pin);
160 pciauto_prescan_setup_bridge(
struct pci_dev *dev,
int current_bus,
161 int sub_bus,
int *iosave,
int *memsave)
169 pciauto_upper_memspc &= ~(0x100000 - 1);
170 *memsave = pciauto_upper_memspc;
173 pciauto_upper_iospc &= ~(0x1000 - 1);
174 *iosave = pciauto_upper_iospc;
178 ((pciauto_upper_memspc - 1) & 0xfff00000) >> 16);
180 ((pciauto_upper_iospc - 1) & 0x0000f000) >> 8);
182 ((pciauto_upper_iospc - 1) & 0xffff0000) >> 16);
186 pciauto_postscan_setup_bridge(
struct pci_dev *dev,
int current_bus,
int sub_bus,
187 int *iosave,
int *memsave)
198 pciauto_upper_memspc &= ~(0x100000 - 1);
199 if (*memsave == pciauto_upper_memspc)
200 pciauto_upper_memspc -= 0x00100000;
202 pci_write_config_word(dev,
PCI_MEMORY_BASE, pciauto_upper_memspc >> 16);
206 ((pciauto_upper_memspc - 1) & 0xfff00000) >> 16);
208 pciauto_upper_memspc -= 0x100000;
211 pciauto_upper_memspc >> 16);
214 pciauto_upper_iospc &= ~(0x1000 - 1);
215 if (*iosave == pciauto_upper_iospc)
216 pciauto_upper_iospc -= 0x1000;
219 (pciauto_upper_iospc & 0x0000f000) >> 8);
221 pciauto_upper_iospc >> 16);
239 int sub_bus, pci_devfn, pci_class,
cmdstat, found_multi=0;
241 unsigned char header_type;
242 struct pci_dev *dev = &pciauto_dev;
244 pciauto_dev.bus = &pciauto_bus;
245 pciauto_dev.sysdata = pci_ctrl;
246 pciauto_bus.ops = pci_ctrl->
ops;
255 pciauto_upper_iospc = pci_ctrl->io_resource.end + 1;
259 sub_bus = current_bus;
261 for (pci_devfn = 0; pci_devfn < 0xff; pci_devfn++)
264 if ((current_bus == pci_ctrl->
first_busno) && (pci_devfn == 0))
267 if (
PCI_FUNC(pci_devfn) && !found_multi)
270 pciauto_bus.number = current_bus;
271 pciauto_dev.devfn = pci_devfn;
278 found_multi = header_type & 0x80;
281 if (vid == 0xffff || vid == 0x0000) {
292 DBG(
"PCI Autoconfig: Found P2P bridge, device %d\n",
298 pciauto_prescan_setup_bridge(dev, current_bus, sub_bus,
301 pciauto_postscan_setup_bridge(dev, current_bus, sub_bus,
303 pciauto_bus.number = current_bus;
315 unsigned char prg_iface;
318 if (!(prg_iface & PCIAUTO_IDE_MODE_MASK)) {
319 DBG(
"PCI Autoconfig: Skipping legacy mode "
340 DBG(
"PCI Autoconfig: Found Bus %d, Device %d, Function %d\n",
344 pciauto_setup_irq(pci_ctrl, dev, pci_devfn);