numaq_32.c 3.9 KB

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