numa.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. /* maps to convert between proximity domain and logical node ID */
  38. static int __cpuinitdata pxm_to_node_map[MAX_PXM_DOMAINS]
  39. = { [0 ... MAX_PXM_DOMAINS - 1] = NID_INVAL };
  40. static int __cpuinitdata node_to_pxm_map[MAX_NUMNODES]
  41. = { [0 ... MAX_NUMNODES - 1] = PXM_INVAL };
  42. int pxm_to_node(int pxm)
  43. {
  44. if (pxm < 0)
  45. return NID_INVAL;
  46. return pxm_to_node_map[pxm];
  47. }
  48. int node_to_pxm(int node)
  49. {
  50. if (node < 0)
  51. return PXM_INVAL;
  52. return node_to_pxm_map[node];
  53. }
  54. void __acpi_map_pxm_to_node(int pxm, int node)
  55. {
  56. pxm_to_node_map[pxm] = node;
  57. node_to_pxm_map[node] = pxm;
  58. }
  59. int acpi_map_pxm_to_node(int pxm)
  60. {
  61. int node = pxm_to_node_map[pxm];
  62. if (node < 0){
  63. if (nodes_weight(nodes_found_map) >= MAX_NUMNODES)
  64. return NID_INVAL;
  65. node = first_unset_node(nodes_found_map);
  66. __acpi_map_pxm_to_node(pxm, node);
  67. node_set(node, nodes_found_map);
  68. }
  69. return node;
  70. }
  71. void __cpuinit acpi_unmap_pxm_to_node(int node)
  72. {
  73. int pxm = node_to_pxm_map[node];
  74. pxm_to_node_map[pxm] = NID_INVAL;
  75. node_to_pxm_map[node] = PXM_INVAL;
  76. node_clear(node, nodes_found_map);
  77. }
  78. static void __init
  79. acpi_table_print_srat_entry(struct acpi_subtable_header *header)
  80. {
  81. ACPI_FUNCTION_NAME("acpi_table_print_srat_entry");
  82. if (!header)
  83. return;
  84. switch (header->type) {
  85. case ACPI_SRAT_TYPE_CPU_AFFINITY:
  86. #ifdef ACPI_DEBUG_OUTPUT
  87. {
  88. struct acpi_srat_cpu_affinity *p =
  89. (struct acpi_srat_cpu_affinity *)header;
  90. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  91. "SRAT Processor (id[0x%02x] eid[0x%02x]) in proximity domain %d %s\n",
  92. p->apic_id, p->local_sapic_eid,
  93. p->proximity_domain_lo,
  94. (p->flags & ACPI_SRAT_CPU_ENABLED)?
  95. "enabled" : "disabled"));
  96. }
  97. #endif /* ACPI_DEBUG_OUTPUT */
  98. break;
  99. case ACPI_SRAT_TYPE_MEMORY_AFFINITY:
  100. #ifdef ACPI_DEBUG_OUTPUT
  101. {
  102. struct acpi_srat_mem_affinity *p =
  103. (struct acpi_srat_mem_affinity *)header;
  104. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  105. "SRAT Memory (0x%lx length 0x%lx type 0x%x) in proximity domain %d %s%s\n",
  106. (unsigned long)p->base_address,
  107. (unsigned long)p->length,
  108. p->memory_type, p->proximity_domain,
  109. (p->flags & ACPI_SRAT_MEM_ENABLED)?
  110. "enabled" : "disabled",
  111. (p->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)?
  112. " hot-pluggable" : ""));
  113. }
  114. #endif /* ACPI_DEBUG_OUTPUT */
  115. break;
  116. default:
  117. printk(KERN_WARNING PREFIX
  118. "Found unsupported SRAT entry (type = 0x%x)\n",
  119. header->type);
  120. break;
  121. }
  122. }
  123. static int __init acpi_parse_slit(struct acpi_table_header *table)
  124. {
  125. struct acpi_table_slit *slit;
  126. u32 localities;
  127. if (!table)
  128. return -EINVAL;
  129. slit = (struct acpi_table_slit *)table;
  130. /* downcast just for %llu vs %lu for i386/ia64 */
  131. localities = (u32) slit->locality_count;
  132. acpi_numa_slit_init(slit);
  133. return 0;
  134. }
  135. static int __init
  136. acpi_parse_processor_affinity(struct acpi_subtable_header * header,
  137. const unsigned long end)
  138. {
  139. struct acpi_srat_cpu_affinity *processor_affinity;
  140. processor_affinity = (struct acpi_srat_cpu_affinity *)header;
  141. if (!processor_affinity)
  142. return -EINVAL;
  143. acpi_table_print_srat_entry(header);
  144. /* let architecture-dependent part to do it */
  145. acpi_numa_processor_affinity_init(processor_affinity);
  146. return 0;
  147. }
  148. static int __init
  149. acpi_parse_memory_affinity(struct acpi_subtable_header * header,
  150. const unsigned long end)
  151. {
  152. struct acpi_srat_mem_affinity *memory_affinity;
  153. memory_affinity = (struct acpi_srat_mem_affinity *)header;
  154. if (!memory_affinity)
  155. return -EINVAL;
  156. acpi_table_print_srat_entry(header);
  157. /* let architecture-dependent part to do it */
  158. acpi_numa_memory_affinity_init(memory_affinity);
  159. return 0;
  160. }
  161. static int __init acpi_parse_srat(struct acpi_table_header *table)
  162. {
  163. struct acpi_table_srat *srat;
  164. if (!table)
  165. return -EINVAL;
  166. srat = (struct acpi_table_srat *)table;
  167. return 0;
  168. }
  169. static int __init
  170. acpi_table_parse_srat(enum acpi_srat_type id,
  171. acpi_table_entry_handler handler, unsigned int max_entries)
  172. {
  173. return acpi_table_parse_entries(ACPI_SIG_SRAT,
  174. sizeof(struct acpi_table_srat), id,
  175. handler, max_entries);
  176. }
  177. int __init acpi_numa_init(void)
  178. {
  179. /* SRAT: Static Resource Affinity Table */
  180. if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) {
  181. acpi_table_parse_srat(ACPI_SRAT_TYPE_CPU_AFFINITY,
  182. acpi_parse_processor_affinity, NR_CPUS);
  183. acpi_table_parse_srat(ACPI_SRAT_TYPE_MEMORY_AFFINITY,
  184. acpi_parse_memory_affinity,
  185. NR_NODE_MEMBLKS);
  186. }
  187. /* SLIT: System Locality Information Table */
  188. acpi_table_parse(ACPI_SIG_SLIT, acpi_parse_slit);
  189. acpi_numa_arch_fixup();
  190. return 0;
  191. }
  192. int acpi_get_pxm(acpi_handle h)
  193. {
  194. unsigned long pxm;
  195. acpi_status status;
  196. acpi_handle handle;
  197. acpi_handle phandle = h;
  198. do {
  199. handle = phandle;
  200. status = acpi_evaluate_integer(handle, "_PXM", NULL, &pxm);
  201. if (ACPI_SUCCESS(status))
  202. return pxm;
  203. status = acpi_get_parent(handle, &phandle);
  204. } while (ACPI_SUCCESS(status));
  205. return -1;
  206. }
  207. EXPORT_SYMBOL(acpi_get_pxm);
  208. int acpi_get_node(acpi_handle *handle)
  209. {
  210. int pxm, node = -1;
  211. pxm = acpi_get_pxm(handle);
  212. if (pxm >= 0)
  213. node = acpi_map_pxm_to_node(pxm);
  214. return node;
  215. }
  216. EXPORT_SYMBOL(acpi_get_node);