numa.c 4.7 KB

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