numaq_32.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. #include <asm/numaq.h>
  11. #define BUS2QUAD(global) (mp_bus_id_to_node[global])
  12. #define BUS2LOCAL(global) (mp_bus_id_to_local[global])
  13. #define QUADLOCAL2BUS(quad,local) (quad_local_to_mp_bus_id[quad][local])
  14. #define PCI_CONF1_MQ_ADDRESS(bus, devfn, reg) \
  15. (0x80000000 | (BUS2LOCAL(bus) << 16) | (devfn << 8) | (reg & ~3))
  16. static void write_cf8(unsigned bus, unsigned devfn, unsigned reg)
  17. {
  18. unsigned val = PCI_CONF1_MQ_ADDRESS(bus, devfn, reg);
  19. if (xquad_portio)
  20. writel(val, XQUAD_PORT_ADDR(0xcf8, BUS2QUAD(bus)));
  21. else
  22. outl(val, 0xCF8);
  23. }
  24. static int pci_conf1_mq_read(unsigned int seg, unsigned int bus,
  25. unsigned int devfn, int reg, int len, u32 *value)
  26. {
  27. unsigned long flags;
  28. void *adr __iomem = XQUAD_PORT_ADDR(0xcfc, BUS2QUAD(bus));
  29. WARN_ON(seg);
  30. if (!value || (bus >= MAX_MP_BUSSES) || (devfn > 255) || (reg > 255))
  31. return -EINVAL;
  32. raw_spin_lock_irqsave(&pci_config_lock, flags);
  33. write_cf8(bus, devfn, reg);
  34. switch (len) {
  35. case 1:
  36. if (xquad_portio)
  37. *value = readb(adr + (reg & 3));
  38. else
  39. *value = inb(0xCFC + (reg & 3));
  40. break;
  41. case 2:
  42. if (xquad_portio)
  43. *value = readw(adr + (reg & 2));
  44. else
  45. *value = inw(0xCFC + (reg & 2));
  46. break;
  47. case 4:
  48. if (xquad_portio)
  49. *value = readl(adr);
  50. else
  51. *value = inl(0xCFC);
  52. break;
  53. }
  54. raw_spin_unlock_irqrestore(&pci_config_lock, flags);
  55. return 0;
  56. }
  57. static int pci_conf1_mq_write(unsigned int seg, unsigned int bus,
  58. unsigned int devfn, int reg, int len, u32 value)
  59. {
  60. unsigned long flags;
  61. void *adr __iomem = XQUAD_PORT_ADDR(0xcfc, BUS2QUAD(bus));
  62. WARN_ON(seg);
  63. if ((bus >= MAX_MP_BUSSES) || (devfn > 255) || (reg > 255))
  64. return -EINVAL;
  65. raw_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. raw_spin_unlock_irqrestore(&pci_config_lock, flags);
  88. return 0;
  89. }
  90. #undef PCI_CONF1_MQ_ADDRESS
  91. static const 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. raw_pci_ops = &pci_direct_conf1_mq;
  127. pci_root_bus = pcibios_scan_root(0);
  128. if (num_online_nodes() > 1)
  129. for_each_online_node(quad) {
  130. if (quad == 0)
  131. continue;
  132. printk("Scanning PCI bus %d for quad %d\n",
  133. QUADLOCAL2BUS(quad,0), quad);
  134. pci_scan_bus_with_sysdata(QUADLOCAL2BUS(quad, 0));
  135. }
  136. return 0;
  137. }