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