numa.c 6.5 KB

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