numaq_32.c 4.0 KB

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