numa.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * acpi_numa.c - ACPI NUMA support
  3. *
  4. * Copyright (C) 2002 Takayoshi Kochi <t-kochi@bq.jp.nec.com>
  5. *
  6. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. *
  24. */
  25. #include <linux/module.h>
  26. #include <linux/init.h>
  27. #include <linux/kernel.h>
  28. #include <linux/types.h>
  29. #include <linux/errno.h>
  30. #include <linux/acpi.h>
  31. #include <acpi/acpi_bus.h>
  32. #include <acpi/acmacros.h>
  33. #define ACPI_NUMA 0x80000000
  34. #define _COMPONENT ACPI_NUMA
  35. ACPI_MODULE_NAME("numa");
  36. static nodemask_t nodes_found_map = NODE_MASK_NONE;
  37. #define PXM_INVAL -1
  38. #define NID_INVAL -1
  39. /* maps to convert between proximity domain and logical node ID */
  40. static int pxm_to_node_map[MAX_PXM_DOMAINS]
  41. = { [0 ... MAX_PXM_DOMAINS - 1] = NID_INVAL };
  42. static int node_to_pxm_map[MAX_NUMNODES]
  43. = { [0 ... MAX_NUMNODES - 1] = PXM_INVAL };
  44. int pxm_to_node(int pxm)
  45. {
  46. if (pxm < 0)
  47. return NID_INVAL;
  48. return pxm_to_node_map[pxm];
  49. }
  50. int node_to_pxm(int node)
  51. {
  52. if (node < 0)
  53. return PXM_INVAL;
  54. return node_to_pxm_map[node];
  55. }
  56. int __cpuinit acpi_map_pxm_to_node(int pxm)
  57. {
  58. int node = pxm_to_node_map[pxm];
  59. if (node < 0){
  60. if (nodes_weight(nodes_found_map) >= MAX_NUMNODES)
  61. return NID_INVAL;
  62. node = first_unset_node(nodes_found_map);
  63. pxm_to_node_map[pxm] = node;
  64. node_to_pxm_map[node] = pxm;
  65. node_set(node, nodes_found_map);
  66. }
  67. return node;
  68. }
  69. void __cpuinit acpi_unmap_pxm_to_node(int node)
  70. {
  71. int pxm = node_to_pxm_map[node];
  72. pxm_to_node_map[pxm] = NID_INVAL;
  73. node_to_pxm_map[node] = PXM_INVAL;
  74. node_clear(node, nodes_found_map);
  75. }
  76. void __init acpi_table_print_srat_entry(struct acpi_subtable_header * header)
  77. {
  78. ACPI_FUNCTION_NAME("acpi_table_print_srat_entry");
  79. if (!header)
  80. return;
  81. switch (header->type) {
  82. case ACPI_SRAT_TYPE_CPU_AFFINITY:
  83. #ifdef ACPI_DEBUG_OUTPUT
  84. {
  85. struct acpi_srat_cpu_affinity *p =
  86. (struct acpi_srat_cpu_affinity *)header;
  87. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  88. "SRAT Processor (id[0x%02x] eid[0x%02x]) in proximity domain %d %s\n",
  89. p->apic_id, p->local_sapic_eid,
  90. p->proximity_domain_lo,
  91. (p->flags & ACPI_SRAT_CPU_ENABLED)?
  92. "enabled" : "disabled"));
  93. }
  94. #endif /* ACPI_DEBUG_OUTPUT */
  95. break;
  96. case ACPI_SRAT_TYPE_MEMORY_AFFINITY:
  97. #ifdef ACPI_DEBUG_OUTPUT
  98. {
  99. struct acpi_srat_mem_affinity *p =
  100. (struct acpi_srat_mem_affinity *)header;
  101. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  102. "SRAT Memory (0x%lx length 0x%lx type 0x%x) in proximity domain %d %s%s\n",
  103. (unsigned long)p->base_address,
  104. (unsigned long)p->length,
  105. p->memory_type, p->proximity_domain,
  106. (p->flags & ACPI_SRAT_MEM_ENABLED)?
  107. "enabled" : "disabled",
  108. (p->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)?
  109. " hot-pluggable" : ""));
  110. }
  111. #endif /* ACPI_DEBUG_OUTPUT */
  112. break;
  113. default:
  114. printk(KERN_WARNING PREFIX
  115. "Found unsupported SRAT entry (type = 0x%x)\n",
  116. header->type);
  117. break;
  118. }
  119. }
  120. static int __init acpi_parse_slit(struct acpi_table_header *table)
  121. {
  122. struct acpi_table_slit *slit;
  123. u32 localities;
  124. if (!table)
  125. return -EINVAL;
  126. slit = (struct acpi_table_slit *)table;
  127. /* downcast just for %llu vs %lu for i386/ia64 */
  128. localities = (u32) slit->locality_count;
  129. acpi_numa_slit_init(slit);
  130. return 0;
  131. }
  132. static int __init
  133. acpi_parse_processor_affinity(struct acpi_subtable_header * header,
  134. const unsigned long end)
  135. {
  136. struct acpi_srat_cpu_affinity *processor_affinity;
  137. processor_affinity = (struct acpi_srat_cpu_affinity *)header;
  138. if (!processor_affinity)
  139. return -EINVAL;
  140. acpi_table_print_srat_entry(header);
  141. /* let architecture-dependent part to do it */
  142. acpi_numa_processor_affinity_init(processor_affinity);
  143. return 0;
  144. }
  145. static int __init
  146. acpi_parse_memory_affinity(struct acpi_subtable_header * header,
  147. const unsigned long end)
  148. {
  149. struct acpi_srat_mem_affinity *memory_affinity;
  150. memory_affinity = (struct acpi_srat_mem_affinity *)header;
  151. if (!memory_affinity)
  152. return -EINVAL;
  153. acpi_table_print_srat_entry(header);
  154. /* let architecture-dependent part to do it */
  155. acpi_numa_memory_affinity_init(memory_affinity);
  156. return 0;
  157. }
  158. static int __init acpi_parse_srat(struct acpi_table_header *table)
  159. {
  160. struct acpi_table_srat *srat;
  161. if (!table)
  162. return -EINVAL;
  163. srat = (struct acpi_table_srat *)table;
  164. return 0;
  165. }
  166. int __init
  167. acpi_table_parse_srat(enum acpi_srat_type id,
  168. acpi_table_entry_handler handler, unsigned int max_entries)
  169. {
  170. return acpi_table_parse_entries(ACPI_SIG_SRAT,
  171. sizeof(struct acpi_table_srat), id,
  172. handler, max_entries);
  173. }
  174. int __init acpi_numa_init(void)
  175. {
  176. int result;
  177. /* SRAT: Static Resource Affinity Table */
  178. if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) {
  179. result = acpi_table_parse_srat(ACPI_SRAT_TYPE_CPU_AFFINITY,
  180. acpi_parse_processor_affinity,
  181. NR_CPUS);
  182. result = acpi_table_parse_srat(ACPI_SRAT_TYPE_MEMORY_AFFINITY, acpi_parse_memory_affinity, NR_NODE_MEMBLKS); // IA64 specific
  183. }
  184. /* SLIT: System Locality Information Table */
  185. acpi_table_parse(ACPI_SIG_SLIT, acpi_parse_slit);
  186. acpi_numa_arch_fixup();
  187. return 0;
  188. }
  189. int acpi_get_pxm(acpi_handle h)
  190. {
  191. unsigned long pxm;
  192. acpi_status status;
  193. acpi_handle handle;
  194. acpi_handle phandle = h;
  195. do {
  196. handle = phandle;
  197. status = acpi_evaluate_integer(handle, "_PXM", NULL, &pxm);
  198. if (ACPI_SUCCESS(status))
  199. return pxm;
  200. status = acpi_get_parent(handle, &phandle);
  201. } while (ACPI_SUCCESS(status));
  202. return -1;
  203. }
  204. EXPORT_SYMBOL(acpi_get_pxm);
  205. int acpi_get_node(acpi_handle *handle)
  206. {
  207. int pxm, node = -1;
  208. pxm = acpi_get_pxm(handle);
  209. if (pxm >= 0)
  210. node = acpi_map_pxm_to_node(pxm);
  211. return node;
  212. }
  213. EXPORT_SYMBOL(acpi_get_node);