srat.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. /*
  40. * Callback for SLIT parsing. pxm_to_node() returns NUMA_NO_NODE for
  41. * I/O localities since SRAT does not list them. I/O localities are
  42. * not supported at this point.
  43. */
  44. void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
  45. {
  46. int i, j;
  47. for (i = 0; i < slit->locality_count; i++) {
  48. const int from_node = pxm_to_node(i);
  49. if (from_node == NUMA_NO_NODE)
  50. continue;
  51. for (j = 0; j < slit->locality_count; j++) {
  52. const int to_node = pxm_to_node(j);
  53. if (to_node == NUMA_NO_NODE)
  54. continue;
  55. numa_set_distance(from_node, to_node,
  56. slit->entry[slit->locality_count * i + j]);
  57. }
  58. }
  59. }
  60. /* Callback for Proximity Domain -> x2APIC mapping */
  61. void __init
  62. acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
  63. {
  64. int pxm, node;
  65. int apic_id;
  66. if (srat_disabled())
  67. return;
  68. if (pa->header.length < sizeof(struct acpi_srat_x2apic_cpu_affinity)) {
  69. bad_srat();
  70. return;
  71. }
  72. if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
  73. return;
  74. pxm = pa->proximity_domain;
  75. apic_id = pa->apic_id;
  76. if (!apic->apic_id_valid(apic_id)) {
  77. printk(KERN_INFO "SRAT: PXM %u -> X2APIC 0x%04x ignored\n",
  78. pxm, apic_id);
  79. return;
  80. }
  81. node = setup_node(pxm);
  82. if (node < 0) {
  83. printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
  84. bad_srat();
  85. return;
  86. }
  87. if (apic_id >= MAX_LOCAL_APIC) {
  88. printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
  89. return;
  90. }
  91. set_apicid_to_node(apic_id, node);
  92. node_set(node, numa_nodes_parsed);
  93. acpi_numa = 1;
  94. printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u\n",
  95. pxm, apic_id, node);
  96. }
  97. /* Callback for Proximity Domain -> LAPIC mapping */
  98. void __init
  99. acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
  100. {
  101. int pxm, node;
  102. int apic_id;
  103. if (srat_disabled())
  104. return;
  105. if (pa->header.length != sizeof(struct acpi_srat_cpu_affinity)) {
  106. bad_srat();
  107. return;
  108. }
  109. if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
  110. return;
  111. pxm = pa->proximity_domain_lo;
  112. if (acpi_srat_revision >= 2)
  113. pxm |= *((unsigned int*)pa->proximity_domain_hi) << 8;
  114. node = setup_node(pxm);
  115. if (node < 0) {
  116. printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
  117. bad_srat();
  118. return;
  119. }
  120. if (get_uv_system_type() >= UV_X2APIC)
  121. apic_id = (pa->apic_id << 8) | pa->local_sapic_eid;
  122. else
  123. apic_id = pa->apic_id;
  124. if (apic_id >= MAX_LOCAL_APIC) {
  125. printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
  126. return;
  127. }
  128. set_apicid_to_node(apic_id, node);
  129. node_set(node, numa_nodes_parsed);
  130. acpi_numa = 1;
  131. printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u\n",
  132. pxm, apic_id, node);
  133. }
  134. #ifdef CONFIG_MEMORY_HOTPLUG
  135. static inline int save_add_info(void) {return 1;}
  136. #else
  137. static inline int save_add_info(void) {return 0;}
  138. #endif
  139. /* Callback for parsing of the Proximity Domain <-> Memory Area mappings */
  140. int __init
  141. acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
  142. {
  143. u64 start, end;
  144. u32 hotpluggable;
  145. int node, pxm;
  146. if (srat_disabled())
  147. goto out_err;
  148. if (ma->header.length != sizeof(struct acpi_srat_mem_affinity))
  149. goto out_err_bad_srat;
  150. if ((ma->flags & ACPI_SRAT_MEM_ENABLED) == 0)
  151. goto out_err;
  152. hotpluggable = ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE;
  153. if (hotpluggable && !save_add_info())
  154. goto out_err;
  155. start = ma->base_address;
  156. end = start + ma->length;
  157. pxm = ma->proximity_domain;
  158. if (acpi_srat_revision <= 1)
  159. pxm &= 0xff;
  160. node = setup_node(pxm);
  161. if (node < 0) {
  162. printk(KERN_ERR "SRAT: Too many proximity domains.\n");
  163. goto out_err_bad_srat;
  164. }
  165. if (numa_add_memblk(node, start, end) < 0)
  166. goto out_err_bad_srat;
  167. node_set(node, numa_nodes_parsed);
  168. pr_info("SRAT: Node %u PXM %u [mem %#010Lx-%#010Lx]%s%s\n",
  169. node, pxm,
  170. (unsigned long long) start, (unsigned long long) end - 1,
  171. hotpluggable ? " hotplug" : "",
  172. ma->flags & ACPI_SRAT_MEM_NON_VOLATILE ? " non-volatile" : "");
  173. /* Mark hotplug range in memblock. */
  174. if (hotpluggable && memblock_mark_hotplug(start, ma->length))
  175. pr_warn("SRAT: Failed to mark hotplug range [mem %#010Lx-%#010Lx] in memblock\n",
  176. (unsigned long long)start, (unsigned long long)end - 1);
  177. return 0;
  178. out_err_bad_srat:
  179. bad_srat();
  180. out_err:
  181. return -1;
  182. }
  183. void __init acpi_numa_arch_fixup(void) {}
  184. int __init x86_acpi_numa_init(void)
  185. {
  186. int ret;
  187. ret = acpi_numa_init();
  188. if (ret < 0)
  189. return ret;
  190. return srat_disabled() ? -EINVAL : 0;
  191. }