numaq_32.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. if (!value || (bus >= MAX_MP_BUSSES) || (devfn > 255) || (reg > 255))
  30. return -EINVAL;
  31. raw_spin_lock_irqsave(&pci_config_lock, flags);
  32. write_cf8(bus, devfn, reg);
  33. switch (len) {
  34. case 1:
  35. if (xquad_portio)
  36. *value = readb(adr + (reg & 3));
  37. else
  38. *value = inb(0xCFC + (reg & 3));
  39. break;
  40. case 2:
  41. if (xquad_portio)
  42. *value = readw(adr + (reg & 2));
  43. else
  44. *value = inw(0xCFC + (reg & 2));
  45. break;
  46. case 4:
  47. if (xquad_portio)
  48. *value = readl(adr);
  49. else
  50. *value = inl(0xCFC);
  51. break;
  52. }
  53. raw_spin_unlock_irqrestore(&pci_config_lock, flags);
  54. return 0;
  55. }
  56. static int pci_conf1_mq_write(unsigned int seg, unsigned int bus,
  57. unsigned int devfn, int reg, int len, u32 value)
  58. {
  59. unsigned long flags;
  60. void *adr __iomem = XQUAD_PORT_ADDR(0xcfc, BUS2QUAD(bus));
  61. if ((bus >= MAX_MP_BUSSES) || (devfn > 255) || (reg > 255))
  62. return -EINVAL;
  63. raw_spin_lock_irqsave(&pci_config_lock, flags);
  64. write_cf8(bus, devfn, reg);
  65. switch (len) {
  66. case 1:
  67. if (xquad_portio)
  68. writeb(value, adr + (reg & 3));
  69. else
  70. outb((u8)value, 0xCFC + (reg & 3));
  71. break;
  72. case 2:
  73. if (xquad_portio)
  74. writew(value, adr + (reg & 2));
  75. else
  76. outw((u16)value, 0xCFC + (reg & 2));
  77. break;
  78. case 4:
  79. if (xquad_portio)
  80. writel(value, adr + reg);
  81. else
  82. outl((u32)value, 0xCFC);
  83. break;
  84. }
  85. raw_spin_unlock_irqrestore(&pci_config_lock, flags);
  86. return 0;
  87. }
  88. #undef PCI_CONF1_MQ_ADDRESS
  89. static struct pci_raw_ops pci_direct_conf1_mq = {
  90. .read = pci_conf1_mq_read,
  91. .write = pci_conf1_mq_write
  92. };
  93. static void __devinit pci_fixup_i450nx(struct pci_dev *d)
  94. {
  95. /*
  96. * i450NX -- Find and scan all secondary buses on all PXB's.
  97. */
  98. int pxb, reg;
  99. u8 busno, suba, subb;
  100. int quad = BUS2QUAD(d->bus->number);
  101. dev_info(&d->dev, "searching for i450NX host bridges\n");
  102. reg = 0xd0;
  103. for(pxb=0; pxb<2; pxb++) {
  104. pci_read_config_byte(d, reg++, &busno);
  105. pci_read_config_byte(d, reg++, &suba);
  106. pci_read_config_byte(d, reg++, &subb);
  107. dev_dbg(&d->dev, "i450NX PXB %d: %02x/%02x/%02x\n",
  108. pxb, busno, suba, subb);
  109. if (busno) {
  110. /* Bus A */
  111. pci_scan_bus_with_sysdata(QUADLOCAL2BUS(quad, busno));
  112. }
  113. if (suba < subb) {
  114. /* Bus B */
  115. pci_scan_bus_with_sysdata(QUADLOCAL2BUS(quad, suba+1));
  116. }
  117. }
  118. pcibios_last_bus = -1;
  119. }
  120. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82451NX, pci_fixup_i450nx);
  121. int __init pci_numaq_init(void)
  122. {
  123. int quad;
  124. raw_pci_ops = &pci_direct_conf1_mq;
  125. pci_root_bus = pcibios_scan_root(0);
  126. if (pci_root_bus)
  127. pci_bus_add_devices(pci_root_bus);
  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. }