srat.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. apic_id = pa->apic_id;
  64. if (!apic->apic_id_valid(apic_id)) {
  65. printk(KERN_INFO "SRAT: PXM %u -> X2APIC 0x%04x ignored\n",
  66. pxm, apic_id);
  67. return;
  68. }
  69. node = setup_node(pxm);
  70. if (node < 0) {
  71. printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
  72. bad_srat();
  73. return;
  74. }
  75. if (apic_id >= MAX_LOCAL_APIC) {
  76. printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
  77. return;
  78. }
  79. set_apicid_to_node(apic_id, node);
  80. node_set(node, numa_nodes_parsed);
  81. acpi_numa = 1;
  82. printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u\n",
  83. pxm, apic_id, node);
  84. }
  85. /* Callback for Proximity Domain -> LAPIC mapping */
  86. void __init
  87. acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
  88. {
  89. int pxm, node;
  90. int apic_id;
  91. if (srat_disabled())
  92. return;
  93. if (pa->header.length != sizeof(struct acpi_srat_cpu_affinity)) {
  94. bad_srat();
  95. return;
  96. }
  97. if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
  98. return;
  99. pxm = pa->proximity_domain_lo;
  100. if (acpi_srat_revision >= 2)
  101. pxm |= *((unsigned int*)pa->proximity_domain_hi) << 8;
  102. node = setup_node(pxm);
  103. if (node < 0) {
  104. printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
  105. bad_srat();
  106. return;
  107. }
  108. if (get_uv_system_type() >= UV_X2APIC)
  109. apic_id = (pa->apic_id << 8) | pa->local_sapic_eid;
  110. else
  111. apic_id = pa->apic_id;
  112. if (apic_id >= MAX_LOCAL_APIC) {
  113. printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
  114. return;
  115. }
  116. set_apicid_to_node(apic_id, node);
  117. node_set(node, numa_nodes_parsed);
  118. acpi_numa = 1;
  119. printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u\n",
  120. pxm, apic_id, node);
  121. }
  122. #ifdef CONFIG_MEMORY_HOTPLUG
  123. static inline int save_add_info(void) {return 1;}
  124. #else
  125. static inline int save_add_info(void) {return 0;}
  126. #endif
  127. /* Callback for parsing of the Proximity Domain <-> Memory Area mappings */
  128. void __init
  129. acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
  130. {
  131. u64 start, end;
  132. int node, pxm;
  133. if (srat_disabled())
  134. return;
  135. if (ma->header.length != sizeof(struct acpi_srat_mem_affinity)) {
  136. bad_srat();
  137. return;
  138. }
  139. if ((ma->flags & ACPI_SRAT_MEM_ENABLED) == 0)
  140. return;
  141. if ((ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) && !save_add_info())
  142. return;
  143. start = ma->base_address;
  144. end = start + ma->length;
  145. pxm = ma->proximity_domain;
  146. if (acpi_srat_revision <= 1)
  147. pxm &= 0xff;
  148. node = setup_node(pxm);
  149. if (node < 0) {
  150. printk(KERN_ERR "SRAT: Too many proximity domains.\n");
  151. bad_srat();
  152. return;
  153. }
  154. if (numa_add_memblk(node, start, end) < 0) {
  155. bad_srat();
  156. return;
  157. }
  158. printk(KERN_INFO "SRAT: Node %u PXM %u %Lx-%Lx\n", node, pxm,
  159. start, end);
  160. }
  161. void __init acpi_numa_arch_fixup(void) {}
  162. int __init x86_acpi_numa_init(void)
  163. {
  164. int ret;
  165. ret = acpi_numa_init();
  166. if (ret < 0)
  167. return ret;
  168. return srat_disabled() ? -EINVAL : 0;
  169. }