srat.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. if (acpi_srat_revision >= 2)
  96. pxm |= *((unsigned int*)pa->proximity_domain_hi) << 8;
  97. node = setup_node(pxm);
  98. if (node < 0) {
  99. printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
  100. bad_srat();
  101. return;
  102. }
  103. if (get_uv_system_type() >= UV_X2APIC)
  104. apic_id = (pa->apic_id << 8) | pa->local_sapic_eid;
  105. else
  106. apic_id = pa->apic_id;
  107. if (apic_id >= MAX_LOCAL_APIC) {
  108. printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
  109. return;
  110. }
  111. set_apicid_to_node(apic_id, node);
  112. node_set(node, numa_nodes_parsed);
  113. acpi_numa = 1;
  114. printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u\n",
  115. pxm, apic_id, node);
  116. }
  117. #ifdef CONFIG_MEMORY_HOTPLUG
  118. static inline int save_add_info(void) {return 1;}
  119. #else
  120. static inline int save_add_info(void) {return 0;}
  121. #endif
  122. /* Callback for parsing of the Proximity Domain <-> Memory Area mappings */
  123. void __init
  124. acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
  125. {
  126. u64 start, end;
  127. int node, pxm;
  128. if (srat_disabled())
  129. return;
  130. if (ma->header.length != sizeof(struct acpi_srat_mem_affinity)) {
  131. bad_srat();
  132. return;
  133. }
  134. if ((ma->flags & ACPI_SRAT_MEM_ENABLED) == 0)
  135. return;
  136. if ((ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) && !save_add_info())
  137. return;
  138. start = ma->base_address;
  139. end = start + ma->length;
  140. pxm = ma->proximity_domain;
  141. if (acpi_srat_revision <= 1)
  142. pxm &= 0xff;
  143. node = setup_node(pxm);
  144. if (node < 0) {
  145. printk(KERN_ERR "SRAT: Too many proximity domains.\n");
  146. bad_srat();
  147. return;
  148. }
  149. if (numa_add_memblk(node, start, end) < 0) {
  150. bad_srat();
  151. return;
  152. }
  153. printk(KERN_INFO "SRAT: Node %u PXM %u %Lx-%Lx\n", node, pxm,
  154. start, end);
  155. }
  156. void __init acpi_numa_arch_fixup(void) {}
  157. int __init x86_acpi_numa_init(void)
  158. {
  159. int ret;
  160. ret = acpi_numa_init();
  161. if (ret < 0)
  162. return ret;
  163. return srat_disabled() ? -EINVAL : 0;
  164. }