srat.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * ACPI 3.0 based NUMA setup
  3. * Copyright 2004 Andi Kleen, SuSE Labs.
  4. *
  5. * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs.
  6. *
  7. * Called from acpi_numa_init while reading the SRAT and SLIT tables.
  8. * Assumes all memory regions belonging to a single proximity domain
  9. * are in one chunk. Holes between them will be included in the node.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/acpi.h>
  13. #include <linux/mmzone.h>
  14. #include <linux/bitmap.h>
  15. #include <linux/module.h>
  16. #include <linux/topology.h>
  17. #include <linux/bootmem.h>
  18. #include <linux/memblock.h>
  19. #include <linux/mm.h>
  20. #include <asm/proto.h>
  21. #include <asm/numa.h>
  22. #include <asm/e820.h>
  23. #include <asm/apic.h>
  24. #include <asm/uv/uv.h>
  25. int acpi_numa __initdata;
  26. static __init int setup_node(int pxm)
  27. {
  28. return acpi_map_pxm_to_node(pxm);
  29. }
  30. static __init void bad_srat(void)
  31. {
  32. printk(KERN_ERR "SRAT: SRAT not used.\n");
  33. acpi_numa = -1;
  34. }
  35. static __init inline int srat_disabled(void)
  36. {
  37. return acpi_numa < 0;
  38. }
  39. /* Callback for SLIT parsing */
  40. void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
  41. {
  42. int i, j;
  43. for (i = 0; i < slit->locality_count; i++)
  44. for (j = 0; j < slit->locality_count; j++)
  45. numa_set_distance(pxm_to_node(i), pxm_to_node(j),
  46. slit->entry[slit->locality_count * i + j]);
  47. }
  48. /* Callback for Proximity Domain -> x2APIC mapping */
  49. void __init
  50. acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
  51. {
  52. int pxm, node;
  53. int apic_id;
  54. if (srat_disabled())
  55. return;
  56. if (pa->header.length < sizeof(struct acpi_srat_x2apic_cpu_affinity)) {
  57. bad_srat();
  58. return;
  59. }
  60. if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
  61. return;
  62. pxm = pa->proximity_domain;
  63. node = setup_node(pxm);
  64. if (node < 0) {
  65. printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
  66. bad_srat();
  67. return;
  68. }
  69. apic_id = pa->apic_id;
  70. if (apic_id >= MAX_LOCAL_APIC) {
  71. printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
  72. return;
  73. }
  74. set_apicid_to_node(apic_id, node);
  75. node_set(node, numa_nodes_parsed);
  76. acpi_numa = 1;
  77. printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u\n",
  78. pxm, apic_id, node);
  79. }
  80. /* Callback for Proximity Domain -> LAPIC mapping */
  81. void __init
  82. acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
  83. {
  84. int pxm, node;
  85. int apic_id;
  86. if (srat_disabled())
  87. return;
  88. if (pa->header.length != sizeof(struct acpi_srat_cpu_affinity)) {
  89. bad_srat();
  90. return;
  91. }
  92. if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
  93. return;
  94. pxm = pa->proximity_domain_lo;
  95. node = setup_node(pxm);
  96. if (node < 0) {
  97. printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
  98. bad_srat();
  99. return;
  100. }
  101. if (get_uv_system_type() >= UV_X2APIC)
  102. apic_id = (pa->apic_id << 8) | pa->local_sapic_eid;
  103. else
  104. apic_id = pa->apic_id;
  105. if (apic_id >= MAX_LOCAL_APIC) {
  106. printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
  107. return;
  108. }
  109. set_apicid_to_node(apic_id, node);
  110. node_set(node, numa_nodes_parsed);
  111. acpi_numa = 1;
  112. printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u\n",
  113. pxm, apic_id, node);
  114. }
  115. #ifdef CONFIG_MEMORY_HOTPLUG
  116. static inline int save_add_info(void) {return 1;}
  117. #else
  118. static inline int save_add_info(void) {return 0;}
  119. #endif
  120. /* Callback for parsing of the Proximity Domain <-> Memory Area mappings */
  121. void __init
  122. acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
  123. {
  124. u64 start, end;
  125. int node, pxm;
  126. if (srat_disabled())
  127. return;
  128. if (ma->header.length != sizeof(struct acpi_srat_mem_affinity)) {
  129. bad_srat();
  130. return;
  131. }
  132. if ((ma->flags & ACPI_SRAT_MEM_ENABLED) == 0)
  133. return;
  134. if ((ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) && !save_add_info())
  135. return;
  136. start = ma->base_address;
  137. end = start + ma->length;
  138. pxm = ma->proximity_domain;
  139. node = setup_node(pxm);
  140. if (node < 0) {
  141. printk(KERN_ERR "SRAT: Too many proximity domains.\n");
  142. bad_srat();
  143. return;
  144. }
  145. if (numa_add_memblk(node, start, end) < 0) {
  146. bad_srat();
  147. return;
  148. }
  149. printk(KERN_INFO "SRAT: Node %u PXM %u %Lx-%Lx\n", node, pxm,
  150. start, end);
  151. }
  152. void __init acpi_numa_arch_fixup(void) {}
  153. int __init x86_acpi_numa_init(void)
  154. {
  155. int ret;
  156. ret = acpi_numa_init();
  157. if (ret < 0)
  158. return ret;
  159. return srat_disabled() ? -EINVAL : 0;
  160. }