common.c 15 KB

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