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