Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Low-Level PCI Support for PC |
| 3 | * |
| 4 | * (c) 1999--2000 Martin Mares <mj@ucw.cz> |
| 5 | */ |
| 6 | |
| 7 | #include <linux/sched.h> |
| 8 | #include <linux/pci.h> |
| 9 | #include <linux/ioport.h> |
| 10 | #include <linux/init.h> |
Bernhard Kaindl | 8c4b2cf | 2006-02-18 01:36:55 -0800 | [diff] [blame] | 11 | #include <linux/dmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
| 13 | #include <asm/acpi.h> |
| 14 | #include <asm/segment.h> |
| 15 | #include <asm/io.h> |
| 16 | #include <asm/smp.h> |
| 17 | |
| 18 | #include "pci.h" |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 | |
| 21 | PCI_PROBE_MMCONF; |
| 22 | |
Yinghai Lu | e3f2bae | 2008-05-22 14:35:11 -0700 | [diff] [blame] | 23 | unsigned int pci_early_dump_regs; |
Adrian Bunk | 2b290da | 2006-11-16 13:16:23 +0100 | [diff] [blame] | 24 | static int pci_bf_sort; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | int pci_routeirq; |
Stefan Assmann | a9322f6 | 2008-06-11 16:35:14 +0200 | [diff] [blame] | 26 | int noioapicquirk; |
Stefan Assmann | 41b9eb2 | 2008-07-15 13:48:55 +0200 | [diff] [blame^] | 27 | #ifdef CONFIG_X86_REROUTE_FOR_BROKEN_BOOT_IRQS |
| 28 | int noioapicreroute = 0; |
| 29 | #else |
Stefan Assmann | 9197979 | 2008-06-11 16:35:15 +0200 | [diff] [blame] | 30 | int noioapicreroute = 1; |
Stefan Assmann | 41b9eb2 | 2008-07-15 13:48:55 +0200 | [diff] [blame^] | 31 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | int pcibios_last_bus = -1; |
jayalk@intworks.biz | 120bb42 | 2005-03-21 20:20:42 -0800 | [diff] [blame] | 33 | unsigned long pirq_table_addr; |
| 34 | struct pci_bus *pci_root_bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | struct pci_raw_ops *raw_pci_ops; |
Matthew Wilcox | b6ce068 | 2008-02-10 09:45:28 -0500 | [diff] [blame] | 36 | struct pci_raw_ops *raw_pci_ext_ops; |
| 37 | |
| 38 | int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn, |
| 39 | int reg, int len, u32 *val) |
| 40 | { |
Matthew Wilcox | beef312 | 2008-07-11 15:21:17 -0600 | [diff] [blame] | 41 | if (domain == 0 && reg < 256 && raw_pci_ops) |
Matthew Wilcox | b6ce068 | 2008-02-10 09:45:28 -0500 | [diff] [blame] | 42 | return raw_pci_ops->read(domain, bus, devfn, reg, len, val); |
| 43 | if (raw_pci_ext_ops) |
| 44 | return raw_pci_ext_ops->read(domain, bus, devfn, reg, len, val); |
| 45 | return -EINVAL; |
| 46 | } |
| 47 | |
| 48 | int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn, |
| 49 | int reg, int len, u32 val) |
| 50 | { |
Matthew Wilcox | beef312 | 2008-07-11 15:21:17 -0600 | [diff] [blame] | 51 | if (domain == 0 && reg < 256 && raw_pci_ops) |
Matthew Wilcox | b6ce068 | 2008-02-10 09:45:28 -0500 | [diff] [blame] | 52 | return raw_pci_ops->write(domain, bus, devfn, reg, len, val); |
| 53 | if (raw_pci_ext_ops) |
| 54 | return raw_pci_ext_ops->write(domain, bus, devfn, reg, len, val); |
| 55 | return -EINVAL; |
| 56 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value) |
| 59 | { |
Matthew Wilcox | b6ce068 | 2008-02-10 09:45:28 -0500 | [diff] [blame] | 60 | return raw_pci_read(pci_domain_nr(bus), bus->number, |
Jeff Garzik | a79e419 | 2007-10-11 16:58:30 -0400 | [diff] [blame] | 61 | devfn, where, size, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value) |
| 65 | { |
Matthew Wilcox | b6ce068 | 2008-02-10 09:45:28 -0500 | [diff] [blame] | 66 | return raw_pci_write(pci_domain_nr(bus), bus->number, |
Jeff Garzik | a79e419 | 2007-10-11 16:58:30 -0400 | [diff] [blame] | 67 | devfn, where, size, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | struct pci_ops pci_root_ops = { |
| 71 | .read = pci_read, |
| 72 | .write = pci_write, |
| 73 | }; |
| 74 | |
| 75 | /* |
| 76 | * legacy, numa, and acpi all want to call pcibios_scan_root |
| 77 | * from their initcalls. This flag prevents that. |
| 78 | */ |
| 79 | int pcibios_scanned; |
| 80 | |
| 81 | /* |
| 82 | * This interrupt-safe spinlock protects all accesses to PCI |
| 83 | * configuration space. |
| 84 | */ |
| 85 | DEFINE_SPINLOCK(pci_config_lock); |
| 86 | |
Yinghai Lu | 13a6ddb | 2008-03-27 01:31:18 -0700 | [diff] [blame] | 87 | static int __devinit can_skip_ioresource_align(const struct dmi_system_id *d) |
| 88 | { |
| 89 | pci_probe |= PCI_CAN_SKIP_ISA_ALIGN; |
| 90 | printk(KERN_INFO "PCI: %s detected, can skip ISA alignment\n", d->ident); |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static struct dmi_system_id can_skip_pciprobe_dmi_table[] __devinitdata = { |
| 95 | /* |
| 96 | * Systems where PCI IO resource ISA alignment can be skipped |
| 97 | * when the ISA enable bit in the bridge control is not set |
| 98 | */ |
| 99 | { |
| 100 | .callback = can_skip_ioresource_align, |
| 101 | .ident = "IBM System x3800", |
| 102 | .matches = { |
| 103 | DMI_MATCH(DMI_SYS_VENDOR, "IBM"), |
| 104 | DMI_MATCH(DMI_PRODUCT_NAME, "x3800"), |
| 105 | }, |
| 106 | }, |
| 107 | { |
| 108 | .callback = can_skip_ioresource_align, |
| 109 | .ident = "IBM System x3850", |
| 110 | .matches = { |
| 111 | DMI_MATCH(DMI_SYS_VENDOR, "IBM"), |
| 112 | DMI_MATCH(DMI_PRODUCT_NAME, "x3850"), |
| 113 | }, |
| 114 | }, |
| 115 | { |
| 116 | .callback = can_skip_ioresource_align, |
| 117 | .ident = "IBM System x3950", |
| 118 | .matches = { |
| 119 | DMI_MATCH(DMI_SYS_VENDOR, "IBM"), |
| 120 | DMI_MATCH(DMI_PRODUCT_NAME, "x3950"), |
| 121 | }, |
| 122 | }, |
| 123 | {} |
| 124 | }; |
| 125 | |
| 126 | void __init dmi_check_skip_isa_align(void) |
| 127 | { |
| 128 | dmi_check_system(can_skip_pciprobe_dmi_table); |
| 129 | } |
| 130 | |
Gary Hade | bb71ad8 | 2008-05-12 13:57:46 -0700 | [diff] [blame] | 131 | static void __devinit pcibios_fixup_device_resources(struct pci_dev *dev) |
| 132 | { |
| 133 | struct resource *rom_r = &dev->resource[PCI_ROM_RESOURCE]; |
| 134 | |
| 135 | if (pci_probe & PCI_NOASSIGN_ROMS) { |
| 136 | if (rom_r->parent) |
| 137 | return; |
| 138 | if (rom_r->start) { |
| 139 | /* we deal with BIOS assigned ROM later */ |
| 140 | return; |
| 141 | } |
| 142 | rom_r->start = rom_r->end = rom_r->flags = 0; |
| 143 | } |
| 144 | } |
| 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | /* |
| 147 | * Called after each bus is probed, but before its children |
| 148 | * are examined. |
| 149 | */ |
| 150 | |
| 151 | void __devinit pcibios_fixup_bus(struct pci_bus *b) |
| 152 | { |
Gary Hade | bb71ad8 | 2008-05-12 13:57:46 -0700 | [diff] [blame] | 153 | struct pci_dev *dev; |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | pci_read_bridge_bases(b); |
Gary Hade | bb71ad8 | 2008-05-12 13:57:46 -0700 | [diff] [blame] | 156 | list_for_each_entry(dev, &b->devices, bus_list) |
| 157 | pcibios_fixup_device_resources(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Bernhard Kaindl | 8c4b2cf | 2006-02-18 01:36:55 -0800 | [diff] [blame] | 160 | /* |
Matt Domsch | 6b4b78f | 2006-09-29 15:23:23 -0500 | [diff] [blame] | 161 | * Only use DMI information to set this if nothing was passed |
| 162 | * on the kernel command line (which was parsed earlier). |
| 163 | */ |
| 164 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 165 | static int __devinit set_bf_sort(const struct dmi_system_id *d) |
Matt Domsch | 6b4b78f | 2006-09-29 15:23:23 -0500 | [diff] [blame] | 166 | { |
| 167 | if (pci_bf_sort == pci_bf_sort_default) { |
| 168 | pci_bf_sort = pci_dmi_bf; |
| 169 | printk(KERN_INFO "PCI: %s detected, enabling pci=bfsort.\n", d->ident); |
| 170 | } |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | /* |
Bernhard Kaindl | 8c4b2cf | 2006-02-18 01:36:55 -0800 | [diff] [blame] | 175 | * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus) |
| 176 | */ |
| 177 | #ifdef __i386__ |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 178 | static int __devinit assign_all_busses(const struct dmi_system_id *d) |
Bernhard Kaindl | 8c4b2cf | 2006-02-18 01:36:55 -0800 | [diff] [blame] | 179 | { |
| 180 | pci_probe |= PCI_ASSIGN_ALL_BUSSES; |
| 181 | printk(KERN_INFO "%s detected: enabling PCI bus# renumbering" |
| 182 | " (pci=assign-busses)\n", d->ident); |
| 183 | return 0; |
| 184 | } |
| 185 | #endif |
| 186 | |
Matt Domsch | 6b4b78f | 2006-09-29 15:23:23 -0500 | [diff] [blame] | 187 | static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = { |
| 188 | #ifdef __i386__ |
Bernhard Kaindl | 8c4b2cf | 2006-02-18 01:36:55 -0800 | [diff] [blame] | 189 | /* |
| 190 | * Laptops which need pci=assign-busses to see Cardbus cards |
| 191 | */ |
Bernhard Kaindl | 8c4b2cf | 2006-02-18 01:36:55 -0800 | [diff] [blame] | 192 | { |
| 193 | .callback = assign_all_busses, |
| 194 | .ident = "Samsung X20 Laptop", |
| 195 | .matches = { |
| 196 | DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"), |
| 197 | DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"), |
| 198 | }, |
| 199 | }, |
| 200 | #endif /* __i386__ */ |
Matt Domsch | 6b4b78f | 2006-09-29 15:23:23 -0500 | [diff] [blame] | 201 | { |
| 202 | .callback = set_bf_sort, |
| 203 | .ident = "Dell PowerEdge 1950", |
| 204 | .matches = { |
| 205 | DMI_MATCH(DMI_SYS_VENDOR, "Dell"), |
| 206 | DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1950"), |
| 207 | }, |
| 208 | }, |
| 209 | { |
| 210 | .callback = set_bf_sort, |
| 211 | .ident = "Dell PowerEdge 1955", |
| 212 | .matches = { |
| 213 | DMI_MATCH(DMI_SYS_VENDOR, "Dell"), |
| 214 | DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1955"), |
| 215 | }, |
| 216 | }, |
| 217 | { |
| 218 | .callback = set_bf_sort, |
| 219 | .ident = "Dell PowerEdge 2900", |
| 220 | .matches = { |
| 221 | DMI_MATCH(DMI_SYS_VENDOR, "Dell"), |
| 222 | DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2900"), |
| 223 | }, |
| 224 | }, |
| 225 | { |
| 226 | .callback = set_bf_sort, |
| 227 | .ident = "Dell PowerEdge 2950", |
| 228 | .matches = { |
| 229 | DMI_MATCH(DMI_SYS_VENDOR, "Dell"), |
| 230 | DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2950"), |
| 231 | }, |
| 232 | }, |
Andy Gospodarek | f52383d | 2007-02-05 16:36:10 -0800 | [diff] [blame] | 233 | { |
| 234 | .callback = set_bf_sort, |
Matt Domsch | f7a9dae | 2007-03-23 23:58:07 -0500 | [diff] [blame] | 235 | .ident = "Dell PowerEdge R900", |
| 236 | .matches = { |
| 237 | DMI_MATCH(DMI_SYS_VENDOR, "Dell"), |
| 238 | DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R900"), |
| 239 | }, |
| 240 | }, |
| 241 | { |
| 242 | .callback = set_bf_sort, |
Andy Gospodarek | f52383d | 2007-02-05 16:36:10 -0800 | [diff] [blame] | 243 | .ident = "HP ProLiant BL20p G3", |
| 244 | .matches = { |
| 245 | DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
| 246 | DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G3"), |
| 247 | }, |
| 248 | }, |
| 249 | { |
| 250 | .callback = set_bf_sort, |
| 251 | .ident = "HP ProLiant BL20p G4", |
| 252 | .matches = { |
| 253 | DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
| 254 | DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G4"), |
| 255 | }, |
| 256 | }, |
| 257 | { |
| 258 | .callback = set_bf_sort, |
| 259 | .ident = "HP ProLiant BL30p G1", |
| 260 | .matches = { |
| 261 | DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
| 262 | DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL30p G1"), |
| 263 | }, |
| 264 | }, |
| 265 | { |
| 266 | .callback = set_bf_sort, |
| 267 | .ident = "HP ProLiant BL25p G1", |
| 268 | .matches = { |
| 269 | DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
| 270 | DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL25p G1"), |
| 271 | }, |
| 272 | }, |
| 273 | { |
| 274 | .callback = set_bf_sort, |
| 275 | .ident = "HP ProLiant BL35p G1", |
| 276 | .matches = { |
| 277 | DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
| 278 | DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL35p G1"), |
| 279 | }, |
| 280 | }, |
| 281 | { |
| 282 | .callback = set_bf_sort, |
| 283 | .ident = "HP ProLiant BL45p G1", |
| 284 | .matches = { |
| 285 | DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
| 286 | DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G1"), |
| 287 | }, |
| 288 | }, |
| 289 | { |
| 290 | .callback = set_bf_sort, |
| 291 | .ident = "HP ProLiant BL45p G2", |
| 292 | .matches = { |
| 293 | DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
| 294 | DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G2"), |
| 295 | }, |
| 296 | }, |
| 297 | { |
| 298 | .callback = set_bf_sort, |
| 299 | .ident = "HP ProLiant BL460c G1", |
| 300 | .matches = { |
| 301 | DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
| 302 | DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL460c G1"), |
| 303 | }, |
| 304 | }, |
| 305 | { |
| 306 | .callback = set_bf_sort, |
| 307 | .ident = "HP ProLiant BL465c G1", |
| 308 | .matches = { |
| 309 | DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
| 310 | DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL465c G1"), |
| 311 | }, |
| 312 | }, |
| 313 | { |
| 314 | .callback = set_bf_sort, |
| 315 | .ident = "HP ProLiant BL480c G1", |
| 316 | .matches = { |
| 317 | DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
| 318 | DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL480c G1"), |
| 319 | }, |
| 320 | }, |
| 321 | { |
| 322 | .callback = set_bf_sort, |
| 323 | .ident = "HP ProLiant BL685c G1", |
| 324 | .matches = { |
| 325 | DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
| 326 | DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL685c G1"), |
| 327 | }, |
| 328 | }, |
Michal Schmidt | 8f8ae1a | 2007-10-17 18:04:35 +0200 | [diff] [blame] | 329 | { |
| 330 | .callback = set_bf_sort, |
Tony Camuso | 8d64c78 | 2008-05-15 14:40:14 -0400 | [diff] [blame] | 331 | .ident = "HP ProLiant DL360", |
Michal Schmidt | 8f8ae1a | 2007-10-17 18:04:35 +0200 | [diff] [blame] | 332 | .matches = { |
| 333 | DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
Tony Camuso | 8d64c78 | 2008-05-15 14:40:14 -0400 | [diff] [blame] | 334 | DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL360"), |
Michal Schmidt | 8f8ae1a | 2007-10-17 18:04:35 +0200 | [diff] [blame] | 335 | }, |
| 336 | }, |
| 337 | { |
| 338 | .callback = set_bf_sort, |
Tony Camuso | 8d64c78 | 2008-05-15 14:40:14 -0400 | [diff] [blame] | 339 | .ident = "HP ProLiant DL380", |
Michal Schmidt | 8f8ae1a | 2007-10-17 18:04:35 +0200 | [diff] [blame] | 340 | .matches = { |
| 341 | DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
Tony Camuso | 8d64c78 | 2008-05-15 14:40:14 -0400 | [diff] [blame] | 342 | DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL380"), |
Michal Schmidt | 8f8ae1a | 2007-10-17 18:04:35 +0200 | [diff] [blame] | 343 | }, |
| 344 | }, |
Juha Laiho | 5b1ea82 | 2007-09-13 21:21:34 +0300 | [diff] [blame] | 345 | #ifdef __i386__ |
| 346 | { |
| 347 | .callback = assign_all_busses, |
| 348 | .ident = "Compaq EVO N800c", |
| 349 | .matches = { |
| 350 | DMI_MATCH(DMI_SYS_VENDOR, "Compaq"), |
| 351 | DMI_MATCH(DMI_PRODUCT_NAME, "EVO N800c"), |
| 352 | }, |
| 353 | }, |
| 354 | #endif |
Michal Schmidt | c82bc5a | 2007-11-26 20:42:19 +0100 | [diff] [blame] | 355 | { |
| 356 | .callback = set_bf_sort, |
Jesse Barnes | 739db07 | 2008-07-07 09:55:26 -0700 | [diff] [blame] | 357 | .ident = "HP ProLiant DL385 G2", |
Michal Schmidt | c82bc5a | 2007-11-26 20:42:19 +0100 | [diff] [blame] | 358 | .matches = { |
| 359 | DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
Jesse Barnes | 739db07 | 2008-07-07 09:55:26 -0700 | [diff] [blame] | 360 | DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL385 G2"), |
Michal Schmidt | c82bc5a | 2007-11-26 20:42:19 +0100 | [diff] [blame] | 361 | }, |
| 362 | }, |
| 363 | { |
| 364 | .callback = set_bf_sort, |
Jesse Barnes | 739db07 | 2008-07-07 09:55:26 -0700 | [diff] [blame] | 365 | .ident = "HP ProLiant DL585 G2", |
Michal Schmidt | c82bc5a | 2007-11-26 20:42:19 +0100 | [diff] [blame] | 366 | .matches = { |
| 367 | DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
Jesse Barnes | 739db07 | 2008-07-07 09:55:26 -0700 | [diff] [blame] | 368 | DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"), |
Michal Schmidt | c82bc5a | 2007-11-26 20:42:19 +0100 | [diff] [blame] | 369 | }, |
| 370 | }, |
Bernhard Kaindl | 8c4b2cf | 2006-02-18 01:36:55 -0800 | [diff] [blame] | 371 | {} |
| 372 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Yinghai Lu | 0df18ff | 2008-04-14 15:40:37 -0700 | [diff] [blame] | 374 | void __init dmi_check_pciprobe(void) |
| 375 | { |
| 376 | dmi_check_system(pciprobe_dmi_table); |
| 377 | } |
| 378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | struct pci_bus * __devinit pcibios_scan_root(int busnum) |
| 380 | { |
| 381 | struct pci_bus *bus = NULL; |
Muli Ben-Yehuda | 08f1c19 | 2007-07-22 00:23:39 +0300 | [diff] [blame] | 382 | struct pci_sysdata *sd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
| 384 | while ((bus = pci_find_next_bus(bus)) != NULL) { |
| 385 | if (bus->number == busnum) { |
| 386 | /* Already scanned */ |
| 387 | return bus; |
| 388 | } |
| 389 | } |
| 390 | |
Muli Ben-Yehuda | 08f1c19 | 2007-07-22 00:23:39 +0300 | [diff] [blame] | 391 | /* Allocate per-root-bus (not per bus) arch-specific data. |
| 392 | * TODO: leak; this memory is never freed. |
| 393 | * It's arguable whether it's worth the trouble to care. |
| 394 | */ |
| 395 | sd = kzalloc(sizeof(*sd), GFP_KERNEL); |
| 396 | if (!sd) { |
| 397 | printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum); |
| 398 | return NULL; |
| 399 | } |
| 400 | |
Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 401 | sd->node = get_mp_bus_to_node(busnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 403 | printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum); |
| 404 | bus = pci_scan_bus_parented(NULL, busnum, &pci_root_ops, sd); |
| 405 | if (!bus) |
| 406 | kfree(sd); |
| 407 | |
| 408 | return bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | extern u8 pci_cache_line_size; |
| 412 | |
Robert Richter | 8dd779b | 2008-07-02 22:50:29 +0200 | [diff] [blame] | 413 | int __init pcibios_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | { |
| 415 | struct cpuinfo_x86 *c = &boot_cpu_data; |
| 416 | |
| 417 | if (!raw_pci_ops) { |
Daniel Marjamäkia | dcb8907 | 2005-11-23 15:44:49 -0800 | [diff] [blame] | 418 | printk(KERN_WARNING "PCI: System does not support PCI\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | /* |
| 423 | * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8 |
| 424 | * and P4. It's also good for 386/486s (which actually have 16) |
| 425 | * as quite a few PCI devices do not support smaller values. |
| 426 | */ |
| 427 | pci_cache_line_size = 32 >> 2; |
| 428 | if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD) |
| 429 | pci_cache_line_size = 64 >> 2; /* K7 & K8 */ |
| 430 | else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL) |
| 431 | pci_cache_line_size = 128 >> 2; /* P4 */ |
| 432 | |
| 433 | pcibios_resource_survey(); |
| 434 | |
Matt Domsch | 6b4b78f | 2006-09-29 15:23:23 -0500 | [diff] [blame] | 435 | if (pci_bf_sort >= pci_force_bf) |
| 436 | pci_sort_breadthfirst(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | return 0; |
| 438 | } |
| 439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | char * __devinit pcibios_setup(char *str) |
| 441 | { |
| 442 | if (!strcmp(str, "off")) { |
| 443 | pci_probe = 0; |
| 444 | return NULL; |
Matt Domsch | 6b4b78f | 2006-09-29 15:23:23 -0500 | [diff] [blame] | 445 | } else if (!strcmp(str, "bfsort")) { |
| 446 | pci_bf_sort = pci_force_bf; |
| 447 | return NULL; |
| 448 | } else if (!strcmp(str, "nobfsort")) { |
| 449 | pci_bf_sort = pci_force_nobf; |
| 450 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | } |
| 452 | #ifdef CONFIG_PCI_BIOS |
| 453 | else if (!strcmp(str, "bios")) { |
| 454 | pci_probe = PCI_PROBE_BIOS; |
| 455 | return NULL; |
| 456 | } else if (!strcmp(str, "nobios")) { |
| 457 | pci_probe &= ~PCI_PROBE_BIOS; |
| 458 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } else if (!strcmp(str, "biosirq")) { |
| 460 | pci_probe |= PCI_BIOS_IRQ_SCAN; |
| 461 | return NULL; |
jayalk@intworks.biz | 120bb42 | 2005-03-21 20:20:42 -0800 | [diff] [blame] | 462 | } else if (!strncmp(str, "pirqaddr=", 9)) { |
| 463 | pirq_table_addr = simple_strtoul(str+9, NULL, 0); |
| 464 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | } |
| 466 | #endif |
| 467 | #ifdef CONFIG_PCI_DIRECT |
| 468 | else if (!strcmp(str, "conf1")) { |
| 469 | pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS; |
| 470 | return NULL; |
| 471 | } |
| 472 | else if (!strcmp(str, "conf2")) { |
| 473 | pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS; |
| 474 | return NULL; |
| 475 | } |
| 476 | #endif |
| 477 | #ifdef CONFIG_PCI_MMCONFIG |
| 478 | else if (!strcmp(str, "nommconf")) { |
| 479 | pci_probe &= ~PCI_PROBE_MMCONF; |
| 480 | return NULL; |
| 481 | } |
Yinghai Lu | 5f0b297 | 2008-04-14 16:08:25 -0700 | [diff] [blame] | 482 | else if (!strcmp(str, "check_enable_amd_mmconf")) { |
| 483 | pci_probe |= PCI_CHECK_ENABLE_AMD_MMCONF; |
| 484 | return NULL; |
| 485 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | #endif |
| 487 | else if (!strcmp(str, "noacpi")) { |
| 488 | acpi_noirq_set(); |
| 489 | return NULL; |
| 490 | } |
Andi Kleen | 0637a70 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 491 | else if (!strcmp(str, "noearly")) { |
| 492 | pci_probe |= PCI_PROBE_NOEARLY; |
| 493 | return NULL; |
| 494 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | #ifndef CONFIG_X86_VISWS |
| 496 | else if (!strcmp(str, "usepirqmask")) { |
| 497 | pci_probe |= PCI_USE_PIRQ_MASK; |
| 498 | return NULL; |
| 499 | } else if (!strncmp(str, "irqmask=", 8)) { |
| 500 | pcibios_irq_mask = simple_strtol(str+8, NULL, 0); |
| 501 | return NULL; |
| 502 | } else if (!strncmp(str, "lastbus=", 8)) { |
| 503 | pcibios_last_bus = simple_strtol(str+8, NULL, 0); |
| 504 | return NULL; |
| 505 | } |
| 506 | #endif |
| 507 | else if (!strcmp(str, "rom")) { |
| 508 | pci_probe |= PCI_ASSIGN_ROMS; |
| 509 | return NULL; |
Gary Hade | bb71ad8 | 2008-05-12 13:57:46 -0700 | [diff] [blame] | 510 | } else if (!strcmp(str, "norom")) { |
| 511 | pci_probe |= PCI_NOASSIGN_ROMS; |
| 512 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } else if (!strcmp(str, "assign-busses")) { |
| 514 | pci_probe |= PCI_ASSIGN_ALL_BUSSES; |
| 515 | return NULL; |
Gary Hade | 62f420f | 2007-10-03 15:56:51 -0700 | [diff] [blame] | 516 | } else if (!strcmp(str, "use_crs")) { |
| 517 | pci_probe |= PCI_USE__CRS; |
| 518 | return NULL; |
Yinghai Lu | e3f2bae | 2008-05-22 14:35:11 -0700 | [diff] [blame] | 519 | } else if (!strcmp(str, "earlydump")) { |
| 520 | pci_early_dump_regs = 1; |
| 521 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | } else if (!strcmp(str, "routeirq")) { |
| 523 | pci_routeirq = 1; |
| 524 | return NULL; |
Yinghai Lu | 13a6ddb | 2008-03-27 01:31:18 -0700 | [diff] [blame] | 525 | } else if (!strcmp(str, "skip_isa_align")) { |
| 526 | pci_probe |= PCI_CAN_SKIP_ISA_ALIGN; |
| 527 | return NULL; |
Stefan Assmann | a9322f6 | 2008-06-11 16:35:14 +0200 | [diff] [blame] | 528 | } else if (!strcmp(str, "noioapicquirk")) { |
| 529 | noioapicquirk = 1; |
| 530 | return NULL; |
Stefan Assmann | 9197979 | 2008-06-11 16:35:15 +0200 | [diff] [blame] | 531 | } else if (!strcmp(str, "ioapicreroute")) { |
| 532 | if (noioapicreroute != -1) |
| 533 | noioapicreroute = 0; |
| 534 | return NULL; |
Stefan Assmann | 41b9eb2 | 2008-07-15 13:48:55 +0200 | [diff] [blame^] | 535 | } else if (!strcmp(str, "noioapicreroute")) { |
| 536 | if (noioapicreroute != -1) |
| 537 | noioapicreroute = 1; |
| 538 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | } |
| 540 | return str; |
| 541 | } |
| 542 | |
| 543 | unsigned int pcibios_assign_all_busses(void) |
| 544 | { |
| 545 | return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0; |
| 546 | } |
| 547 | |
| 548 | int pcibios_enable_device(struct pci_dev *dev, int mask) |
| 549 | { |
| 550 | int err; |
| 551 | |
Bjorn Helgaas | b81d988 | 2008-03-04 11:57:01 -0700 | [diff] [blame] | 552 | if ((err = pci_enable_resources(dev, mask)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | return err; |
| 554 | |
Eric W. Biederman | bba6f6f | 2007-03-28 15:36:09 +0200 | [diff] [blame] | 555 | if (!dev->msi_enabled) |
| 556 | return pcibios_enable_irq(dev); |
| 557 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 559 | |
| 560 | void pcibios_disable_device (struct pci_dev *dev) |
| 561 | { |
Eric W. Biederman | bba6f6f | 2007-03-28 15:36:09 +0200 | [diff] [blame] | 562 | if (!dev->msi_enabled && pcibios_disable_irq) |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 563 | pcibios_disable_irq(dev); |
| 564 | } |
Muli Ben-Yehuda | 73c59af | 2007-08-10 13:01:19 -0700 | [diff] [blame] | 565 | |
Sam Ravnborg | 98db6f1 | 2008-04-29 22:38:48 +0200 | [diff] [blame] | 566 | struct pci_bus * __devinit pci_scan_bus_on_node(int busno, struct pci_ops *ops, int node) |
Muli Ben-Yehuda | 73c59af | 2007-08-10 13:01:19 -0700 | [diff] [blame] | 567 | { |
| 568 | struct pci_bus *bus = NULL; |
| 569 | struct pci_sysdata *sd; |
| 570 | |
| 571 | /* |
| 572 | * Allocate per-root-bus (not per bus) arch-specific data. |
| 573 | * TODO: leak; this memory is never freed. |
| 574 | * It's arguable whether it's worth the trouble to care. |
| 575 | */ |
| 576 | sd = kzalloc(sizeof(*sd), GFP_KERNEL); |
| 577 | if (!sd) { |
| 578 | printk(KERN_ERR "PCI: OOM, skipping PCI bus %02x\n", busno); |
| 579 | return NULL; |
| 580 | } |
Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 581 | sd->node = node; |
| 582 | bus = pci_scan_bus(busno, ops, sd); |
Muli Ben-Yehuda | 73c59af | 2007-08-10 13:01:19 -0700 | [diff] [blame] | 583 | if (!bus) |
| 584 | kfree(sd); |
| 585 | |
| 586 | return bus; |
| 587 | } |
Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 588 | |
Sam Ravnborg | 98db6f1 | 2008-04-29 22:38:48 +0200 | [diff] [blame] | 589 | struct pci_bus * __devinit pci_scan_bus_with_sysdata(int busno) |
Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 590 | { |
| 591 | return pci_scan_bus_on_node(busno, &pci_root_ops, -1); |
| 592 | } |