2 * Low-Level PCI Support for PC
4 * (c) 1999--2000 Martin Mares <mj@ucw.cz>
6 Note: on x86-64 there is no PCI BIOS so there is no way to sort in the
7 same order as 32bit Linux. This could cause grief for dualbooting because
8 devices may wander. May want to use ACPI for sorting eventually.
12 #include <linux/sched.h>
13 #include <linux/pci.h>
14 #include <linux/init.h>
15 #include <linux/ioport.h>
17 #include <asm/segment.h>
20 #include <asm/cache.h>
24 unsigned int pci_probe
= PCI_PROBE_CONF1
| PCI_PROBE_CONF2
;
26 int pcibios_last_bus
= 0xff; /* XXX */
27 struct pci_bus
*pci_root_bus
= NULL
;
28 struct pci_ops
*pci_root_ops
= NULL
;
30 int (*pci_config_read
)(int seg
, int bus
, int dev
, int fn
, int reg
, int len
, u32
*value
) = NULL
;
31 int (*pci_config_write
)(int seg
, int bus
, int dev
, int fn
, int reg
, int len
, u32 value
) = NULL
;
34 * legacy, numa, and acpi all want to call pcibios_scan_root
35 * from their initcalls. This flag prevents that.
40 * This interrupt-safe spinlock protects all accesses to PCI
41 * configuration space.
43 spinlock_t pci_config_lock
= SPIN_LOCK_UNLOCKED
;
46 * Several buggy motherboards address only 16 devices and mirror
47 * them to next 16 IDs. We try to detect this `feature' on all
48 * primary buses (those containing host bridges as they are
49 * expected to be unique) and remove the ghost devices.
52 static void __devinit
pcibios_fixup_ghosts(struct pci_bus
*b
)
54 struct list_head
*ln
, *mn
;
55 struct pci_dev
*d
, *e
;
56 int mirror
= PCI_DEVFN(16,0);
57 int seen_host_bridge
= 0;
60 DBG("PCI: Scanning for ghost devices on bus %d\n", b
->number
);
61 for (ln
=b
->devices
.next
; ln
!= &b
->devices
; ln
=ln
->next
) {
63 if ((d
->class >> 8) == PCI_CLASS_BRIDGE_HOST
)
65 for (mn
=ln
->next
; mn
!= &b
->devices
; mn
=mn
->next
) {
67 if (e
->devfn
!= d
->devfn
+ mirror
||
68 e
->vendor
!= d
->vendor
||
69 e
->device
!= d
->device
||
72 for(i
=0; i
<PCI_NUM_RESOURCES
; i
++)
73 if (e
->resource
[i
].start
!= d
->resource
[i
].start
||
74 e
->resource
[i
].end
!= d
->resource
[i
].end
||
75 e
->resource
[i
].flags
!= d
->resource
[i
].flags
)
79 if (mn
== &b
->devices
)
82 if (!seen_host_bridge
)
84 printk(KERN_WARNING
"PCI: Ignoring ghost devices on bus %02x\n", b
->number
);
87 while (ln
->next
!= &b
->devices
) {
88 d
= pci_dev_b(ln
->next
);
89 if (d
->devfn
>= mirror
) {
90 list_del(&d
->global_list
);
91 list_del(&d
->bus_list
);
98 struct pbus_set_ranges_data
;
101 pcibios_fixup_pbus_ranges (struct pci_bus
*bus
, struct pbus_set_ranges_data
*ranges
)
106 * Called after each bus is probed, but before its children
110 void __devinit
pcibios_fixup_bus(struct pci_bus
*b
)
112 pcibios_fixup_ghosts(b
);
113 pci_read_bridge_bases(b
);
117 struct pci_bus
* __devinit
pcibios_scan_root(int busnum
)
119 struct list_head
*list
;
122 list_for_each(list
, &pci_root_buses
) {
123 bus
= pci_bus_b(list
);
124 if (bus
->number
== busnum
) {
125 /* Already scanned */
130 printk("PCI: Probing PCI hardware (bus %02x)\n", busnum
);
132 return pci_scan_bus(busnum
, pci_root_ops
, NULL
);
135 extern u8 pci_cache_line_size
;
137 static int __init
pcibios_init(void)
140 printk("PCI: System does not support PCI\n");
144 pci_cache_line_size
= boot_cpu_data
.x86_clflush_size
>> 2;
146 pcibios_resource_survey();
148 #ifdef CONFIG_GART_IOMMU
152 /* may eventually need to do ACPI sort here. */
156 subsys_initcall(pcibios_init
);
158 char * __devinit
pcibios_setup(char *str
)
160 if (!strcmp(str
, "off")) {
164 #ifdef CONFIG_PCI_DIRECT
165 else if (!strcmp(str
, "conf1")) {
166 pci_probe
= PCI_PROBE_CONF1
| PCI_NO_CHECKS
;
169 else if (!strcmp(str
, "conf2")) {
170 pci_probe
= PCI_PROBE_CONF2
| PCI_NO_CHECKS
;
174 #ifdef CONFIG_ACPI_PCI
175 else if (!strcmp(str
, "noacpi")) {
176 pci_probe
|= PCI_NO_ACPI_ROUTING
;
180 else if (!strcmp(str
, "rom")) {
181 pci_probe
|= PCI_ASSIGN_ROMS
;
183 } else if (!strcmp(str
, "assign-busses")) {
184 pci_probe
|= PCI_ASSIGN_ALL_BUSSES
;
186 } else if (!strcmp(str
, "usepirqmask")) {
187 pci_probe
|= PCI_USE_PIRQ_MASK
;
189 } else if (!strncmp(str
, "irqmask=", 8)) {
190 pcibios_irq_mask
= simple_strtol(str
+8, NULL
, 0);
192 } else if (!strncmp(str
, "lastbus=", 8)) {
193 pcibios_last_bus
= simple_strtol(str
+8, NULL
, 0);
199 unsigned int pcibios_assign_all_busses(void)
201 return (pci_probe
& PCI_ASSIGN_ALL_BUSSES
) ? 1 : 0;
204 int pcibios_enable_device(struct pci_dev
*dev
, int mask
)
208 if ((err
= pcibios_enable_resources(dev
, mask
)) < 0)
211 return pcibios_enable_irq(dev
);