common.c 16 KB

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