k8-bus_64.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #include <linux/init.h>
  2. #include <linux/pci.h>
  3. #include <asm/pci-direct.h>
  4. #include <asm/mpspec.h>
  5. #include <linux/cpumask.h>
  6. #include <linux/topology.h>
  7. /*
  8. * This discovers the pcibus <-> node mapping on AMD K8.
  9. *
  10. * RED-PEN need to call this again on PCI hotplug
  11. * RED-PEN empty cpus get reported wrong
  12. */
  13. #define NODE_ID(dword) ((dword>>4) & 0x07)
  14. #define LDT_BUS_NUMBER_REGISTER_0 0xE0
  15. #define LDT_BUS_NUMBER_REGISTER_1 0xE4
  16. #define LDT_BUS_NUMBER_REGISTER_2 0xE8
  17. #define LDT_BUS_NUMBER_REGISTER_3 0xEC
  18. #define NR_LDT_BUS_NUMBER_REGISTERS 4
  19. #define SECONDARY_LDT_BUS_NUMBER(dword) ((dword >> 16) & 0xFF)
  20. #define SUBORDINATE_LDT_BUS_NUMBER(dword) ((dword >> 24) & 0xFF)
  21. #define PCI_DEVICE_ID_K8HTCONFIG 0x1100
  22. #define PCI_DEVICE_ID_K8_10H_HTCONFIG 0x1200
  23. #define PCI_DEVICE_ID_K8_11H_HTCONFIG 0x1300
  24. #ifdef CONFIG_NUMA
  25. #define BUS_NR 256
  26. static int mp_bus_to_node[BUS_NR];
  27. void set_mp_bus_to_node(int busnum, int node)
  28. {
  29. if (busnum >= 0 && busnum < BUS_NR)
  30. mp_bus_to_node[busnum] = node;
  31. }
  32. int get_mp_bus_to_node(int busnum)
  33. {
  34. int node = -1;
  35. if (busnum < 0 || busnum > (BUS_NR - 1))
  36. return node;
  37. node = mp_bus_to_node[busnum];
  38. /*
  39. * let numa_node_id to decide it later in dma_alloc_pages
  40. * if there is no ram on that node
  41. */
  42. if (node != -1 && !node_online(node))
  43. node = -1;
  44. return node;
  45. }
  46. #endif
  47. /**
  48. * early_fill_mp_bus_to_node()
  49. * called before pcibios_scan_root and pci_scan_bus
  50. * fills the mp_bus_to_cpumask array based according to the LDT Bus Number
  51. * Registers found in the K8 northbridge
  52. */
  53. __init static int
  54. early_fill_mp_bus_to_node(void)
  55. {
  56. #ifdef CONFIG_NUMA
  57. int i, j;
  58. unsigned slot;
  59. u32 ldtbus;
  60. u32 id;
  61. int node;
  62. u16 deviceid;
  63. u16 vendorid;
  64. int min_bus;
  65. int max_bus;
  66. static int lbnr[NR_LDT_BUS_NUMBER_REGISTERS] = {
  67. LDT_BUS_NUMBER_REGISTER_0,
  68. LDT_BUS_NUMBER_REGISTER_1,
  69. LDT_BUS_NUMBER_REGISTER_2,
  70. LDT_BUS_NUMBER_REGISTER_3
  71. };
  72. for (i = 0; i < BUS_NR; i++)
  73. mp_bus_to_node[i] = -1;
  74. if (!early_pci_allowed())
  75. return -1;
  76. slot = 0x18;
  77. id = read_pci_config(0, slot, 0, PCI_VENDOR_ID);
  78. vendorid = id & 0xffff;
  79. if (vendorid != PCI_VENDOR_ID_AMD)
  80. goto out;
  81. deviceid = (id>>16) & 0xffff;
  82. if ((deviceid != PCI_DEVICE_ID_K8HTCONFIG) &&
  83. (deviceid != PCI_DEVICE_ID_K8_10H_HTCONFIG) &&
  84. (deviceid != PCI_DEVICE_ID_K8_11H_HTCONFIG))
  85. goto out;
  86. for (i = 0; i < NR_LDT_BUS_NUMBER_REGISTERS; i++) {
  87. ldtbus = read_pci_config(0, slot, 1, lbnr[i]);
  88. /* Check if that register is enabled for bus range */
  89. if ((ldtbus & 7) != 3)
  90. continue;
  91. min_bus = SECONDARY_LDT_BUS_NUMBER(ldtbus);
  92. max_bus = SUBORDINATE_LDT_BUS_NUMBER(ldtbus);
  93. node = NODE_ID(ldtbus);
  94. for (j = min_bus; j <= max_bus; j++)
  95. mp_bus_to_node[j] = (unsigned char) node;
  96. }
  97. out:
  98. for (i = 0; i < BUS_NR; i++) {
  99. node = mp_bus_to_node[i];
  100. if (node >= 0)
  101. printk(KERN_DEBUG "bus: %02x to node: %02x\n", i, node);
  102. }
  103. #endif
  104. return 0;
  105. }
  106. postcore_initcall(early_fill_mp_bus_to_node);