numa.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * numa.c - Low-level PCI access for NUMA-Q machines
  3. */
  4. #include <linux/pci.h>
  5. #include <linux/init.h>
  6. #include <linux/nodemask.h>
  7. #include "pci.h"
  8. #define BUS2QUAD(global) (mp_bus_id_to_node[global])
  9. #define BUS2LOCAL(global) (mp_bus_id_to_local[global])
  10. #define QUADLOCAL2BUS(quad,local) (quad_local_to_mp_bus_id[quad][local])
  11. #define PCI_CONF1_MQ_ADDRESS(bus, devfn, reg) \
  12. (0x80000000 | (BUS2LOCAL(bus) << 16) | (devfn << 8) | (reg & ~3))
  13. static int pci_conf1_mq_read(unsigned int seg, unsigned int bus,
  14. unsigned int devfn, int reg, int len, u32 *value)
  15. {
  16. unsigned long flags;
  17. if (!value || (bus >= MAX_MP_BUSSES) || (devfn > 255) || (reg > 255))
  18. return -EINVAL;
  19. spin_lock_irqsave(&pci_config_lock, flags);
  20. outl_quad(PCI_CONF1_MQ_ADDRESS(bus, devfn, reg), 0xCF8, BUS2QUAD(bus));
  21. switch (len) {
  22. case 1:
  23. *value = inb_quad(0xCFC + (reg & 3), BUS2QUAD(bus));
  24. break;
  25. case 2:
  26. *value = inw_quad(0xCFC + (reg & 2), BUS2QUAD(bus));
  27. break;
  28. case 4:
  29. *value = inl_quad(0xCFC, BUS2QUAD(bus));
  30. break;
  31. }
  32. spin_unlock_irqrestore(&pci_config_lock, flags);
  33. return 0;
  34. }
  35. static int pci_conf1_mq_write(unsigned int seg, unsigned int bus,
  36. unsigned int devfn, int reg, int len, u32 value)
  37. {
  38. unsigned long flags;
  39. if ((bus >= MAX_MP_BUSSES) || (devfn > 255) || (reg > 255))
  40. return -EINVAL;
  41. spin_lock_irqsave(&pci_config_lock, flags);
  42. outl_quad(PCI_CONF1_MQ_ADDRESS(bus, devfn, reg), 0xCF8, BUS2QUAD(bus));
  43. switch (len) {
  44. case 1:
  45. outb_quad((u8)value, 0xCFC + (reg & 3), BUS2QUAD(bus));
  46. break;
  47. case 2:
  48. outw_quad((u16)value, 0xCFC + (reg & 2), BUS2QUAD(bus));
  49. break;
  50. case 4:
  51. outl_quad((u32)value, 0xCFC, BUS2QUAD(bus));
  52. break;
  53. }
  54. spin_unlock_irqrestore(&pci_config_lock, flags);
  55. return 0;
  56. }
  57. #undef PCI_CONF1_MQ_ADDRESS
  58. static struct pci_raw_ops pci_direct_conf1_mq = {
  59. .read = pci_conf1_mq_read,
  60. .write = pci_conf1_mq_write
  61. };
  62. static void __devinit pci_fixup_i450nx(struct pci_dev *d)
  63. {
  64. /*
  65. * i450NX -- Find and scan all secondary buses on all PXB's.
  66. */
  67. int pxb, reg;
  68. u8 busno, suba, subb;
  69. int quad = BUS2QUAD(d->bus->number);
  70. printk("PCI: Searching for i450NX host bridges on %s\n", pci_name(d));
  71. reg = 0xd0;
  72. for(pxb=0; pxb<2; pxb++) {
  73. pci_read_config_byte(d, reg++, &busno);
  74. pci_read_config_byte(d, reg++, &suba);
  75. pci_read_config_byte(d, reg++, &subb);
  76. DBG("i450NX PXB %d: %02x/%02x/%02x\n", pxb, busno, suba, subb);
  77. if (busno)
  78. pci_scan_bus(QUADLOCAL2BUS(quad,busno), &pci_root_ops, NULL); /* Bus A */
  79. if (suba < subb)
  80. pci_scan_bus(QUADLOCAL2BUS(quad,suba+1), &pci_root_ops, NULL); /* Bus B */
  81. }
  82. pcibios_last_bus = -1;
  83. }
  84. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82451NX, pci_fixup_i450nx);
  85. static int __init pci_numa_init(void)
  86. {
  87. int quad;
  88. raw_pci_ops = &pci_direct_conf1_mq;
  89. if (pcibios_scanned++)
  90. return 0;
  91. pci_root_bus = pcibios_scan_root(0);
  92. if (pci_root_bus)
  93. pci_bus_add_devices(pci_root_bus);
  94. if (num_online_nodes() > 1)
  95. for_each_online_node(quad) {
  96. if (quad == 0)
  97. continue;
  98. printk("Scanning PCI bus %d for quad %d\n",
  99. QUADLOCAL2BUS(quad,0), quad);
  100. pci_scan_bus(QUADLOCAL2BUS(quad,0),
  101. &pci_root_ops, NULL);
  102. }
  103. return 0;
  104. }
  105. subsys_initcall(pci_numa_init);