numa.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 <mach_apic.h>
  8. #include "pci.h"
  9. #define XQUAD_PORTIO_BASE 0xfe400000
  10. #define XQUAD_PORTIO_QUAD 0x40000 /* 256k per quad. */
  11. #define BUS2QUAD(global) (mp_bus_id_to_node[global])
  12. #define BUS2LOCAL(global) (mp_bus_id_to_local[global])
  13. int quad_local_to_mp_bus_id [NR_CPUS/4][4];
  14. #define QUADLOCAL2BUS(quad,local) (quad_local_to_mp_bus_id[quad][local])
  15. extern void *xquad_portio; /* Where the IO area was mapped */
  16. #define XQUAD_PORT_ADDR(port, quad) (xquad_portio + (XQUAD_PORTIO_QUAD*quad) + port)
  17. #define PCI_CONF1_MQ_ADDRESS(bus, devfn, reg) \
  18. (0x80000000 | (BUS2LOCAL(bus) << 16) | (devfn << 8) | (reg & ~3))
  19. static void write_cf8(unsigned bus, unsigned devfn, unsigned reg)
  20. {
  21. unsigned val = PCI_CONF1_MQ_ADDRESS(bus, devfn, reg);
  22. if (xquad_portio)
  23. writel(val, XQUAD_PORT_ADDR(0xcf8, BUS2QUAD(bus)));
  24. else
  25. outl(val, 0xCF8);
  26. }
  27. static int pci_conf1_mq_read(unsigned int seg, unsigned int bus,
  28. unsigned int devfn, int reg, int len, u32 *value)
  29. {
  30. unsigned long flags;
  31. void *adr __iomem = XQUAD_PORT_ADDR(0xcfc, BUS2QUAD(bus));
  32. if (!value || (bus >= MAX_MP_BUSSES) || (devfn > 255) || (reg > 255))
  33. return -EINVAL;
  34. spin_lock_irqsave(&pci_config_lock, flags);
  35. write_cf8(bus, devfn, reg);
  36. switch (len) {
  37. case 1:
  38. if (xquad_portio)
  39. *value = readb(adr + (reg & 3));
  40. else
  41. *value = inb(0xCFC + (reg & 3));
  42. break;
  43. case 2:
  44. if (xquad_portio)
  45. *value = readw(adr + (reg & 2));
  46. else
  47. *value = inw(0xCFC + (reg & 2));
  48. break;
  49. case 4:
  50. if (xquad_portio)
  51. *value = readl(adr);
  52. else
  53. *value = inl(0xCFC);
  54. break;
  55. }
  56. spin_unlock_irqrestore(&pci_config_lock, flags);
  57. return 0;
  58. }
  59. static int pci_conf1_mq_write(unsigned int seg, unsigned int bus,
  60. unsigned int devfn, int reg, int len, u32 value)
  61. {
  62. unsigned long flags;
  63. void *adr __iomem = XQUAD_PORT_ADDR(0xcfc, BUS2QUAD(bus));
  64. if ((bus >= MAX_MP_BUSSES) || (devfn > 255) || (reg > 255))
  65. return -EINVAL;
  66. spin_lock_irqsave(&pci_config_lock, flags);
  67. write_cf8(bus, devfn, reg);
  68. switch (len) {
  69. case 1:
  70. if (xquad_portio)
  71. writeb(value, adr + (reg & 3));
  72. else
  73. outb((u8)value, 0xCFC + (reg & 3));
  74. break;
  75. case 2:
  76. if (xquad_portio)
  77. writew(value, adr + (reg & 2));
  78. else
  79. outw((u16)value, 0xCFC + (reg & 2));
  80. break;
  81. case 4:
  82. if (xquad_portio)
  83. writel(value, adr + reg);
  84. else
  85. outl((u32)value, 0xCFC);
  86. break;
  87. }
  88. spin_unlock_irqrestore(&pci_config_lock, flags);
  89. return 0;
  90. }
  91. #undef PCI_CONF1_MQ_ADDRESS
  92. static struct pci_raw_ops pci_direct_conf1_mq = {
  93. .read = pci_conf1_mq_read,
  94. .write = pci_conf1_mq_write
  95. };
  96. static void __devinit pci_fixup_i450nx(struct pci_dev *d)
  97. {
  98. /*
  99. * i450NX -- Find and scan all secondary buses on all PXB's.
  100. */
  101. int pxb, reg;
  102. u8 busno, suba, subb;
  103. int quad = BUS2QUAD(d->bus->number);
  104. printk("PCI: Searching for i450NX host bridges on %s\n", pci_name(d));
  105. reg = 0xd0;
  106. for(pxb=0; pxb<2; pxb++) {
  107. pci_read_config_byte(d, reg++, &busno);
  108. pci_read_config_byte(d, reg++, &suba);
  109. pci_read_config_byte(d, reg++, &subb);
  110. DBG("i450NX PXB %d: %02x/%02x/%02x\n", pxb, busno, suba, subb);
  111. if (busno) {
  112. /* Bus A */
  113. pci_scan_bus_with_sysdata(QUADLOCAL2BUS(quad, busno));
  114. }
  115. if (suba < subb) {
  116. /* Bus B */
  117. pci_scan_bus_with_sysdata(QUADLOCAL2BUS(quad, suba+1));
  118. }
  119. }
  120. pcibios_last_bus = -1;
  121. }
  122. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82451NX, pci_fixup_i450nx);
  123. static int __init pci_numa_init(void)
  124. {
  125. int quad;
  126. raw_pci_ops = &pci_direct_conf1_mq;
  127. if (pcibios_scanned++)
  128. return 0;
  129. pci_root_bus = pcibios_scan_root(0);
  130. if (pci_root_bus)
  131. pci_bus_add_devices(pci_root_bus);
  132. if (num_online_nodes() > 1)
  133. for_each_online_node(quad) {
  134. if (quad == 0)
  135. continue;
  136. printk("Scanning PCI bus %d for quad %d\n",
  137. QUADLOCAL2BUS(quad,0), quad);
  138. pci_scan_bus_with_sysdata(QUADLOCAL2BUS(quad, 0));
  139. }
  140. return 0;
  141. }
  142. subsys_initcall(pci_numa_init);