legacy.c 1.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4
/*
 * legacy.c - traditional, old school PCI bus probing
 */
#include <linux/init.h>
5
#include <linux/export.h>
L
Linus Torvalds 已提交
6
#include <linux/pci.h>
7
#include <asm/pci_x86.h>
L
Linus Torvalds 已提交
8 9 10 11 12

/*
 * Discover remaining PCI buses in case there are peer host bridges.
 * We use the number of last PCI bus provided by the PCI BIOS.
 */
13
static void pcibios_fixup_peer_bridges(void)
L
Linus Torvalds 已提交
14
{
15
	int n;
L
Linus Torvalds 已提交
16

17
	if (pcibios_last_bus <= 0 || pcibios_last_bus > 0xff)
L
Linus Torvalds 已提交
18 19 20
		return;
	DBG("PCI: Peer bridge fixup\n");

21 22
	for (n=0; n <= pcibios_last_bus; n++)
		pcibios_scan_specific_bus(n);
L
Linus Torvalds 已提交
23 24
}

25
int __init pci_legacy_init(void)
L
Linus Torvalds 已提交
26
{
27 28
	if (!raw_pci_ops)
		return 1;
L
Linus Torvalds 已提交
29

30
	pr_info("PCI: Probing PCI hardware\n");
31
	pcibios_scan_root(0);
L
Linus Torvalds 已提交
32 33
	return 0;
}
34

35
void pcibios_scan_specific_bus(int busn)
36 37 38 39 40 41 42 43 44 45 46
{
	int devfn;
	u32 l;

	if (pci_find_bus(0, busn))
		return;

	for (devfn = 0; devfn < 256; devfn += 8) {
		if (!raw_pci_read(0, busn, devfn, PCI_VENDOR_ID, 2, &l) &&
		    l != 0x0000 && l != 0xffff) {
			DBG("Found device at %02x:%02x [%04x]\n", busn, devfn, l);
47
			pr_info("PCI: Discovered peer bus %02x\n", busn);
48
			pcibios_scan_root(busn);
49 50 51 52
			return;
		}
	}
}
53
EXPORT_SYMBOL_GPL(pcibios_scan_specific_bus);
L
Linus Torvalds 已提交
54

55
static int __init pci_subsys_init(void)
56
{
57 58 59 60
	/*
	 * The init function returns an non zero value when
	 * pci_legacy_init should be invoked.
	 */
61 62 63 64 65 66
	if (x86_init.pci.init()) {
		if (pci_legacy_init()) {
			pr_info("PCI: System does not support PCI\n");
			return -ENODEV;
		}
	}
67

68
	pcibios_fixup_peer_bridges();
69
	x86_init.pci.init_irq();
70
	pcibios_init();
71 72

	return 0;
73 74
}
subsys_initcall(pci_subsys_init);