numa.c 6.6 KB

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