common.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. /*
  2. * Low-Level PCI Support for PC
  3. *
  4. * (c) 1999--2000 Martin Mares <mj@ucw.cz>
  5. */
  6. #include <linux/sched.h>
  7. #include <linux/pci.h>
  8. #include <linux/pci-acpi.h>
  9. #include <linux/ioport.h>
  10. #include <linux/init.h>
  11. #include <linux/dmi.h>
  12. #include <linux/slab.h>
  13. #include <asm-generic/pci-bridge.h>
  14. #include <asm/acpi.h>
  15. #include <asm/segment.h>
  16. #include <asm/io.h>
  17. #include <asm/smp.h>
  18. #include <asm/pci_x86.h>
  19. #include <asm/setup.h>
  20. unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 |
  21. PCI_PROBE_MMCONF;
  22. unsigned int pci_early_dump_regs;
  23. static int pci_bf_sort;
  24. static int smbios_type_b1_flag;
  25. int pci_routeirq;
  26. int noioapicquirk;
  27. #ifdef CONFIG_X86_REROUTE_FOR_BROKEN_BOOT_IRQS
  28. int noioapicreroute = 0;
  29. #else
  30. int noioapicreroute = 1;
  31. #endif
  32. int pcibios_last_bus = -1;
  33. unsigned long pirq_table_addr;
  34. const struct pci_raw_ops *__read_mostly raw_pci_ops;
  35. const struct pci_raw_ops *__read_mostly raw_pci_ext_ops;
  36. int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
  37. int reg, int len, u32 *val)
  38. {
  39. if (domain == 0 && reg < 256 && raw_pci_ops)
  40. return raw_pci_ops->read(domain, bus, devfn, reg, len, val);
  41. if (raw_pci_ext_ops)
  42. return raw_pci_ext_ops->read(domain, bus, devfn, reg, len, val);
  43. return -EINVAL;
  44. }
  45. int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
  46. int reg, int len, u32 val)
  47. {
  48. if (domain == 0 && reg < 256 && raw_pci_ops)
  49. return raw_pci_ops->write(domain, bus, devfn, reg, len, val);
  50. if (raw_pci_ext_ops)
  51. return raw_pci_ext_ops->write(domain, bus, devfn, reg, len, val);
  52. return -EINVAL;
  53. }
  54. static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
  55. {
  56. return raw_pci_read(pci_domain_nr(bus), bus->number,
  57. devfn, where, size, value);
  58. }
  59. static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
  60. {
  61. return raw_pci_write(pci_domain_nr(bus), bus->number,
  62. devfn, where, size, value);
  63. }
  64. struct pci_ops pci_root_ops = {
  65. .read = pci_read,
  66. .write = pci_write,
  67. };
  68. /*
  69. * This interrupt-safe spinlock protects all accesses to PCI
  70. * configuration space.
  71. */
  72. DEFINE_RAW_SPINLOCK(pci_config_lock);
  73. static int can_skip_ioresource_align(const struct dmi_system_id *d)
  74. {
  75. pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
  76. printk(KERN_INFO "PCI: %s detected, can skip ISA alignment\n", d->ident);
  77. return 0;
  78. }
  79. static const struct dmi_system_id can_skip_pciprobe_dmi_table[] = {
  80. /*
  81. * Systems where PCI IO resource ISA alignment can be skipped
  82. * when the ISA enable bit in the bridge control is not set
  83. */
  84. {
  85. .callback = can_skip_ioresource_align,
  86. .ident = "IBM System x3800",
  87. .matches = {
  88. DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
  89. DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
  90. },
  91. },
  92. {
  93. .callback = can_skip_ioresource_align,
  94. .ident = "IBM System x3850",
  95. .matches = {
  96. DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
  97. DMI_MATCH(DMI_PRODUCT_NAME, "x3850"),
  98. },
  99. },
  100. {
  101. .callback = can_skip_ioresource_align,
  102. .ident = "IBM System x3950",
  103. .matches = {
  104. DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
  105. DMI_MATCH(DMI_PRODUCT_NAME, "x3950"),
  106. },
  107. },
  108. {}
  109. };
  110. void __init dmi_check_skip_isa_align(void)
  111. {
  112. dmi_check_system(can_skip_pciprobe_dmi_table);
  113. }
  114. static void pcibios_fixup_device_resources(struct pci_dev *dev)
  115. {
  116. struct resource *rom_r = &dev->resource[PCI_ROM_RESOURCE];
  117. struct resource *bar_r;
  118. int bar;
  119. if (pci_probe & PCI_NOASSIGN_BARS) {
  120. /*
  121. * If the BIOS did not assign the BAR, zero out the
  122. * resource so the kernel doesn't attmept to assign
  123. * it later on in pci_assign_unassigned_resources
  124. */
  125. for (bar = 0; bar <= PCI_STD_RESOURCE_END; bar++) {
  126. bar_r = &dev->resource[bar];
  127. if (bar_r->start == 0 && bar_r->end != 0) {
  128. bar_r->flags = 0;
  129. bar_r->end = 0;
  130. }
  131. }
  132. }
  133. if (pci_probe & PCI_NOASSIGN_ROMS) {
  134. if (rom_r->parent)
  135. return;
  136. if (rom_r->start) {
  137. /* we deal with BIOS assigned ROM later */
  138. return;
  139. }
  140. rom_r->start = rom_r->end = rom_r->flags = 0;
  141. }
  142. }
  143. /*
  144. * Called after each bus is probed, but before its children
  145. * are examined.
  146. */
  147. void pcibios_fixup_bus(struct pci_bus *b)
  148. {
  149. struct pci_dev *dev;
  150. pci_read_bridge_bases(b);
  151. list_for_each_entry(dev, &b->devices, bus_list)
  152. pcibios_fixup_device_resources(dev);
  153. }
  154. void pcibios_add_bus(struct pci_bus *bus)
  155. {
  156. acpi_pci_add_bus(bus);
  157. }
  158. void pcibios_remove_bus(struct pci_bus *bus)
  159. {
  160. acpi_pci_remove_bus(bus);
  161. }
  162. /*
  163. * Only use DMI information to set this if nothing was passed
  164. * on the kernel command line (which was parsed earlier).
  165. */
  166. static int set_bf_sort(const struct dmi_system_id *d)
  167. {
  168. if (pci_bf_sort == pci_bf_sort_default) {
  169. pci_bf_sort = pci_dmi_bf;
  170. printk(KERN_INFO "PCI: %s detected, enabling pci=bfsort.\n", d->ident);
  171. }
  172. return 0;
  173. }
  174. static void read_dmi_type_b1(const struct dmi_header *dm,
  175. void *private_data)
  176. {
  177. u8 *d = (u8 *)dm + 4;
  178. if (dm->type != 0xB1)
  179. return;
  180. switch (((*(u32 *)d) >> 9) & 0x03) {
  181. case 0x00:
  182. printk(KERN_INFO "dmi type 0xB1 record - unknown flag\n");
  183. break;
  184. case 0x01: /* set pci=bfsort */
  185. smbios_type_b1_flag = 1;
  186. break;
  187. case 0x02: /* do not set pci=bfsort */
  188. smbios_type_b1_flag = 2;
  189. break;
  190. default:
  191. break;
  192. }
  193. }
  194. static int find_sort_method(const struct dmi_system_id *d)
  195. {
  196. dmi_walk(read_dmi_type_b1, NULL);
  197. if (smbios_type_b1_flag == 1) {
  198. set_bf_sort(d);
  199. return 0;
  200. }
  201. return -1;
  202. }
  203. /*
  204. * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
  205. */
  206. #ifdef __i386__
  207. static int assign_all_busses(const struct dmi_system_id *d)
  208. {
  209. pci_probe |= PCI_ASSIGN_ALL_BUSSES;
  210. printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
  211. " (pci=assign-busses)\n", d->ident);
  212. return 0;
  213. }
  214. #endif
  215. static int set_scan_all(const struct dmi_system_id *d)
  216. {
  217. printk(KERN_INFO "PCI: %s detected, enabling pci=pcie_scan_all\n",
  218. d->ident);
  219. pci_add_flags(PCI_SCAN_ALL_PCIE_DEVS);
  220. return 0;
  221. }
  222. static const struct dmi_system_id pciprobe_dmi_table[] = {
  223. #ifdef __i386__
  224. /*
  225. * Laptops which need pci=assign-busses to see Cardbus cards
  226. */
  227. {
  228. .callback = assign_all_busses,
  229. .ident = "Samsung X20 Laptop",
  230. .matches = {
  231. DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
  232. DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
  233. },
  234. },
  235. #endif /* __i386__ */
  236. {
  237. .callback = set_bf_sort,
  238. .ident = "Dell PowerEdge 1950",
  239. .matches = {
  240. DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
  241. DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1950"),
  242. },
  243. },
  244. {
  245. .callback = set_bf_sort,
  246. .ident = "Dell PowerEdge 1955",
  247. .matches = {
  248. DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
  249. DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1955"),
  250. },
  251. },
  252. {
  253. .callback = set_bf_sort,
  254. .ident = "Dell PowerEdge 2900",
  255. .matches = {
  256. DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
  257. DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2900"),
  258. },
  259. },
  260. {
  261. .callback = set_bf_sort,
  262. .ident = "Dell PowerEdge 2950",
  263. .matches = {
  264. DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
  265. DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2950"),
  266. },
  267. },
  268. {
  269. .callback = set_bf_sort,
  270. .ident = "Dell PowerEdge R900",
  271. .matches = {
  272. DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
  273. DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R900"),
  274. },
  275. },
  276. {
  277. .callback = find_sort_method,
  278. .ident = "Dell System",
  279. .matches = {
  280. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
  281. },
  282. },
  283. {
  284. .callback = set_bf_sort,
  285. .ident = "HP ProLiant BL20p G3",
  286. .matches = {
  287. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  288. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G3"),
  289. },
  290. },
  291. {
  292. .callback = set_bf_sort,
  293. .ident = "HP ProLiant BL20p G4",
  294. .matches = {
  295. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  296. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G4"),
  297. },
  298. },
  299. {
  300. .callback = set_bf_sort,
  301. .ident = "HP ProLiant BL30p G1",
  302. .matches = {
  303. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  304. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL30p G1"),
  305. },
  306. },
  307. {
  308. .callback = set_bf_sort,
  309. .ident = "HP ProLiant BL25p G1",
  310. .matches = {
  311. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  312. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL25p G1"),
  313. },
  314. },
  315. {
  316. .callback = set_bf_sort,
  317. .ident = "HP ProLiant BL35p G1",
  318. .matches = {
  319. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  320. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL35p G1"),
  321. },
  322. },
  323. {
  324. .callback = set_bf_sort,
  325. .ident = "HP ProLiant BL45p G1",
  326. .matches = {
  327. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  328. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G1"),
  329. },
  330. },
  331. {
  332. .callback = set_bf_sort,
  333. .ident = "HP ProLiant BL45p G2",
  334. .matches = {
  335. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  336. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G2"),
  337. },
  338. },
  339. {
  340. .callback = set_bf_sort,
  341. .ident = "HP ProLiant BL460c G1",
  342. .matches = {
  343. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  344. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL460c G1"),
  345. },
  346. },
  347. {
  348. .callback = set_bf_sort,
  349. .ident = "HP ProLiant BL465c G1",
  350. .matches = {
  351. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  352. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL465c G1"),
  353. },
  354. },
  355. {
  356. .callback = set_bf_sort,
  357. .ident = "HP ProLiant BL480c G1",
  358. .matches = {
  359. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  360. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL480c G1"),
  361. },
  362. },
  363. {
  364. .callback = set_bf_sort,
  365. .ident = "HP ProLiant BL685c G1",
  366. .matches = {
  367. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  368. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL685c G1"),
  369. },
  370. },
  371. {
  372. .callback = set_bf_sort,
  373. .ident = "HP ProLiant DL360",
  374. .matches = {
  375. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  376. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL360"),
  377. },
  378. },
  379. {
  380. .callback = set_bf_sort,
  381. .ident = "HP ProLiant DL380",
  382. .matches = {
  383. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  384. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL380"),
  385. },
  386. },
  387. #ifdef __i386__
  388. {
  389. .callback = assign_all_busses,
  390. .ident = "Compaq EVO N800c",
  391. .matches = {
  392. DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
  393. DMI_MATCH(DMI_PRODUCT_NAME, "EVO N800c"),
  394. },
  395. },
  396. #endif
  397. {
  398. .callback = set_bf_sort,
  399. .ident = "HP ProLiant DL385 G2",
  400. .matches = {
  401. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  402. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL385 G2"),
  403. },
  404. },
  405. {
  406. .callback = set_bf_sort,
  407. .ident = "HP ProLiant DL585 G2",
  408. .matches = {
  409. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  410. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
  411. },
  412. },
  413. {
  414. .callback = set_scan_all,
  415. .ident = "Stratus/NEC ftServer",
  416. .matches = {
  417. DMI_MATCH(DMI_SYS_VENDOR, "Stratus"),
  418. DMI_MATCH(DMI_PRODUCT_NAME, "ftServer"),
  419. },
  420. },
  421. {}
  422. };
  423. void __init dmi_check_pciprobe(void)
  424. {
  425. dmi_check_system(pciprobe_dmi_table);
  426. }
  427. struct pci_bus *pcibios_scan_root(int busnum)
  428. {
  429. struct pci_bus *bus = NULL;
  430. while ((bus = pci_find_next_bus(bus)) != NULL) {
  431. if (bus->number == busnum) {
  432. /* Already scanned */
  433. return bus;
  434. }
  435. }
  436. return pci_scan_bus_on_node(busnum, &pci_root_ops,
  437. get_mp_bus_to_node(busnum));
  438. }
  439. void __init pcibios_set_cache_line_size(void)
  440. {
  441. struct cpuinfo_x86 *c = &boot_cpu_data;
  442. /*
  443. * Set PCI cacheline size to that of the CPU if the CPU has reported it.
  444. * (For older CPUs that don't support cpuid, we se it to 32 bytes
  445. * It's also good for 386/486s (which actually have 16)
  446. * as quite a few PCI devices do not support smaller values.
  447. */
  448. if (c->x86_clflush_size > 0) {
  449. pci_dfl_cache_line_size = c->x86_clflush_size >> 2;
  450. printk(KERN_DEBUG "PCI: pci_cache_line_size set to %d bytes\n",
  451. pci_dfl_cache_line_size << 2);
  452. } else {
  453. pci_dfl_cache_line_size = 32 >> 2;
  454. printk(KERN_DEBUG "PCI: Unknown cacheline size. Setting to 32 bytes\n");
  455. }
  456. }
  457. int __init pcibios_init(void)
  458. {
  459. if (!raw_pci_ops) {
  460. printk(KERN_WARNING "PCI: System does not support PCI\n");
  461. return 0;
  462. }
  463. pcibios_set_cache_line_size();
  464. pcibios_resource_survey();
  465. if (pci_bf_sort >= pci_force_bf)
  466. pci_sort_breadthfirst();
  467. return 0;
  468. }
  469. char * __init pcibios_setup(char *str)
  470. {
  471. if (!strcmp(str, "off")) {
  472. pci_probe = 0;
  473. return NULL;
  474. } else if (!strcmp(str, "bfsort")) {
  475. pci_bf_sort = pci_force_bf;
  476. return NULL;
  477. } else if (!strcmp(str, "nobfsort")) {
  478. pci_bf_sort = pci_force_nobf;
  479. return NULL;
  480. }
  481. #ifdef CONFIG_PCI_BIOS
  482. else if (!strcmp(str, "bios")) {
  483. pci_probe = PCI_PROBE_BIOS;
  484. return NULL;
  485. } else if (!strcmp(str, "nobios")) {
  486. pci_probe &= ~PCI_PROBE_BIOS;
  487. return NULL;
  488. } else if (!strcmp(str, "biosirq")) {
  489. pci_probe |= PCI_BIOS_IRQ_SCAN;
  490. return NULL;
  491. } else if (!strncmp(str, "pirqaddr=", 9)) {
  492. pirq_table_addr = simple_strtoul(str+9, NULL, 0);
  493. return NULL;
  494. }
  495. #endif
  496. #ifdef CONFIG_PCI_DIRECT
  497. else if (!strcmp(str, "conf1")) {
  498. pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
  499. return NULL;
  500. }
  501. else if (!strcmp(str, "conf2")) {
  502. pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
  503. return NULL;
  504. }
  505. #endif
  506. #ifdef CONFIG_PCI_MMCONFIG
  507. else if (!strcmp(str, "nommconf")) {
  508. pci_probe &= ~PCI_PROBE_MMCONF;
  509. return NULL;
  510. }
  511. else if (!strcmp(str, "check_enable_amd_mmconf")) {
  512. pci_probe |= PCI_CHECK_ENABLE_AMD_MMCONF;
  513. return NULL;
  514. }
  515. #endif
  516. else if (!strcmp(str, "noacpi")) {
  517. acpi_noirq_set();
  518. return NULL;
  519. }
  520. else if (!strcmp(str, "noearly")) {
  521. pci_probe |= PCI_PROBE_NOEARLY;
  522. return NULL;
  523. }
  524. #ifndef CONFIG_X86_VISWS
  525. else if (!strcmp(str, "usepirqmask")) {
  526. pci_probe |= PCI_USE_PIRQ_MASK;
  527. return NULL;
  528. } else if (!strncmp(str, "irqmask=", 8)) {
  529. pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
  530. return NULL;
  531. } else if (!strncmp(str, "lastbus=", 8)) {
  532. pcibios_last_bus = simple_strtol(str+8, NULL, 0);
  533. return NULL;
  534. }
  535. #endif
  536. else if (!strcmp(str, "rom")) {
  537. pci_probe |= PCI_ASSIGN_ROMS;
  538. return NULL;
  539. } else if (!strcmp(str, "norom")) {
  540. pci_probe |= PCI_NOASSIGN_ROMS;
  541. return NULL;
  542. } else if (!strcmp(str, "nobar")) {
  543. pci_probe |= PCI_NOASSIGN_BARS;
  544. return NULL;
  545. } else if (!strcmp(str, "assign-busses")) {
  546. pci_probe |= PCI_ASSIGN_ALL_BUSSES;
  547. return NULL;
  548. } else if (!strcmp(str, "use_crs")) {
  549. pci_probe |= PCI_USE__CRS;
  550. return NULL;
  551. } else if (!strcmp(str, "nocrs")) {
  552. pci_probe |= PCI_ROOT_NO_CRS;
  553. return NULL;
  554. } else if (!strcmp(str, "earlydump")) {
  555. pci_early_dump_regs = 1;
  556. return NULL;
  557. } else if (!strcmp(str, "routeirq")) {
  558. pci_routeirq = 1;
  559. return NULL;
  560. } else if (!strcmp(str, "skip_isa_align")) {
  561. pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
  562. return NULL;
  563. } else if (!strcmp(str, "noioapicquirk")) {
  564. noioapicquirk = 1;
  565. return NULL;
  566. } else if (!strcmp(str, "ioapicreroute")) {
  567. if (noioapicreroute != -1)
  568. noioapicreroute = 0;
  569. return NULL;
  570. } else if (!strcmp(str, "noioapicreroute")) {
  571. if (noioapicreroute != -1)
  572. noioapicreroute = 1;
  573. return NULL;
  574. }
  575. return str;
  576. }
  577. unsigned int pcibios_assign_all_busses(void)
  578. {
  579. return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
  580. }
  581. int pcibios_add_device(struct pci_dev *dev)
  582. {
  583. struct setup_data *data;
  584. struct pci_setup_rom *rom;
  585. u64 pa_data;
  586. pa_data = boot_params.hdr.setup_data;
  587. while (pa_data) {
  588. data = phys_to_virt(pa_data);
  589. if (data->type == SETUP_PCI) {
  590. rom = (struct pci_setup_rom *)data;
  591. if ((pci_domain_nr(dev->bus) == rom->segment) &&
  592. (dev->bus->number == rom->bus) &&
  593. (PCI_SLOT(dev->devfn) == rom->device) &&
  594. (PCI_FUNC(dev->devfn) == rom->function) &&
  595. (dev->vendor == rom->vendor) &&
  596. (dev->device == rom->devid)) {
  597. dev->rom = pa_data +
  598. offsetof(struct pci_setup_rom, romdata);
  599. dev->romlen = rom->pcilen;
  600. }
  601. }
  602. pa_data = data->next;
  603. }
  604. return 0;
  605. }
  606. int pcibios_enable_device(struct pci_dev *dev, int mask)
  607. {
  608. int err;
  609. if ((err = pci_enable_resources(dev, mask)) < 0)
  610. return err;
  611. if (!pci_dev_msi_enabled(dev))
  612. return pcibios_enable_irq(dev);
  613. return 0;
  614. }
  615. void pcibios_disable_device (struct pci_dev *dev)
  616. {
  617. if (!pci_dev_msi_enabled(dev) && pcibios_disable_irq)
  618. pcibios_disable_irq(dev);
  619. }
  620. int pci_ext_cfg_avail(void)
  621. {
  622. if (raw_pci_ext_ops)
  623. return 1;
  624. else
  625. return 0;
  626. }
  627. struct pci_bus *pci_scan_bus_on_node(int busno, struct pci_ops *ops, int node)
  628. {
  629. LIST_HEAD(resources);
  630. struct pci_bus *bus = NULL;
  631. struct pci_sysdata *sd;
  632. /*
  633. * Allocate per-root-bus (not per bus) arch-specific data.
  634. * TODO: leak; this memory is never freed.
  635. * It's arguable whether it's worth the trouble to care.
  636. */
  637. sd = kzalloc(sizeof(*sd), GFP_KERNEL);
  638. if (!sd) {
  639. printk(KERN_ERR "PCI: OOM, skipping PCI bus %02x\n", busno);
  640. return NULL;
  641. }
  642. sd->node = node;
  643. x86_pci_root_bus_resources(busno, &resources);
  644. printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busno);
  645. bus = pci_scan_root_bus(NULL, busno, ops, sd, &resources);
  646. if (!bus) {
  647. pci_free_resource_list(&resources);
  648. kfree(sd);
  649. }
  650. return bus;
  651. }
  652. struct pci_bus *pci_scan_bus_with_sysdata(int busno)
  653. {
  654. return pci_scan_bus_on_node(busno, &pci_root_ops, -1);
  655. }
  656. /*
  657. * NUMA info for PCI busses
  658. *
  659. * Early arch code is responsible for filling in reasonable values here.
  660. * A node id of "-1" means "use current node". In other words, if a bus
  661. * has a -1 node id, it's not tightly coupled to any particular chunk
  662. * of memory (as is the case on some Nehalem systems).
  663. */
  664. #ifdef CONFIG_NUMA
  665. #define BUS_NR 256
  666. #ifdef CONFIG_X86_64
  667. static int mp_bus_to_node[BUS_NR] = {
  668. [0 ... BUS_NR - 1] = -1
  669. };
  670. void set_mp_bus_to_node(int busnum, int node)
  671. {
  672. if (busnum >= 0 && busnum < BUS_NR)
  673. mp_bus_to_node[busnum] = node;
  674. }
  675. int get_mp_bus_to_node(int busnum)
  676. {
  677. int node = -1;
  678. if (busnum < 0 || busnum > (BUS_NR - 1))
  679. return node;
  680. node = mp_bus_to_node[busnum];
  681. /*
  682. * let numa_node_id to decide it later in dma_alloc_pages
  683. * if there is no ram on that node
  684. */
  685. if (node != -1 && !node_online(node))
  686. node = -1;
  687. return node;
  688. }
  689. #else /* CONFIG_X86_32 */
  690. static int mp_bus_to_node[BUS_NR] = {
  691. [0 ... BUS_NR - 1] = -1
  692. };
  693. void set_mp_bus_to_node(int busnum, int node)
  694. {
  695. if (busnum >= 0 && busnum < BUS_NR)
  696. mp_bus_to_node[busnum] = (unsigned char) node;
  697. }
  698. int get_mp_bus_to_node(int busnum)
  699. {
  700. int node;
  701. if (busnum < 0 || busnum > (BUS_NR - 1))
  702. return 0;
  703. node = mp_bus_to_node[busnum];
  704. return node;
  705. }
  706. #endif /* CONFIG_X86_32 */
  707. #endif /* CONFIG_NUMA */