srat.c 5.2 KB

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