numa.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. extern int __init acpi_table_parse_madt_family (enum acpi_table_id id, unsigned long madt_size, int entry_id, acpi_madt_entry_handler handler, unsigned int max_entries);
  38. void __init
  39. acpi_table_print_srat_entry (
  40. acpi_table_entry_header *header)
  41. {
  42. ACPI_FUNCTION_NAME ("acpi_table_print_srat_entry");
  43. if (!header)
  44. return;
  45. switch (header->type) {
  46. case ACPI_SRAT_PROCESSOR_AFFINITY:
  47. #ifdef ACPI_DEBUG_OUTPUT
  48. {
  49. struct acpi_table_processor_affinity *p =
  50. (struct acpi_table_processor_affinity*) header;
  51. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "SRAT Processor (id[0x%02x] eid[0x%02x]) in proximity domain %d %s\n",
  52. p->apic_id, p->lsapic_eid, p->proximity_domain,
  53. p->flags.enabled?"enabled":"disabled"));
  54. }
  55. #endif /* ACPI_DEBUG_OUTPUT */
  56. break;
  57. case ACPI_SRAT_MEMORY_AFFINITY:
  58. #ifdef ACPI_DEBUG_OUTPUT
  59. {
  60. struct acpi_table_memory_affinity *p =
  61. (struct acpi_table_memory_affinity*) header;
  62. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "SRAT Memory (0x%08x%08x length 0x%08x%08x type 0x%x) in proximity domain %d %s%s\n",
  63. p->base_addr_hi, p->base_addr_lo, p->length_hi, p->length_lo,
  64. p->memory_type, p->proximity_domain,
  65. p->flags.enabled ? "enabled" : "disabled",
  66. p->flags.hot_pluggable ? " hot-pluggable" : ""));
  67. }
  68. #endif /* ACPI_DEBUG_OUTPUT */
  69. break;
  70. default:
  71. printk(KERN_WARNING PREFIX "Found unsupported SRAT entry (type = 0x%x)\n",
  72. header->type);
  73. break;
  74. }
  75. }
  76. static int __init
  77. acpi_parse_slit (unsigned long phys_addr, unsigned long size)
  78. {
  79. struct acpi_table_slit *slit;
  80. u32 localities;
  81. if (!phys_addr || !size)
  82. return -EINVAL;
  83. slit = (struct acpi_table_slit *) __va(phys_addr);
  84. /* downcast just for %llu vs %lu for i386/ia64 */
  85. localities = (u32) slit->localities;
  86. acpi_numa_slit_init(slit);
  87. return 0;
  88. }
  89. static int __init
  90. acpi_parse_processor_affinity (
  91. acpi_table_entry_header *header,
  92. const unsigned long end)
  93. {
  94. struct acpi_table_processor_affinity *processor_affinity;
  95. processor_affinity = (struct acpi_table_processor_affinity*) header;
  96. if (!processor_affinity)
  97. return -EINVAL;
  98. acpi_table_print_srat_entry(header);
  99. /* let architecture-dependent part to do it */
  100. acpi_numa_processor_affinity_init(processor_affinity);
  101. return 0;
  102. }
  103. static int __init
  104. acpi_parse_memory_affinity (
  105. acpi_table_entry_header *header,
  106. const unsigned long end)
  107. {
  108. struct acpi_table_memory_affinity *memory_affinity;
  109. memory_affinity = (struct acpi_table_memory_affinity*) header;
  110. if (!memory_affinity)
  111. return -EINVAL;
  112. acpi_table_print_srat_entry(header);
  113. /* let architecture-dependent part to do it */
  114. acpi_numa_memory_affinity_init(memory_affinity);
  115. return 0;
  116. }
  117. static int __init
  118. acpi_parse_srat (unsigned long phys_addr, unsigned long size)
  119. {
  120. struct acpi_table_srat *srat;
  121. if (!phys_addr || !size)
  122. return -EINVAL;
  123. srat = (struct acpi_table_srat *) __va(phys_addr);
  124. return 0;
  125. }
  126. int __init
  127. acpi_table_parse_srat (
  128. enum acpi_srat_entry_id id,
  129. acpi_madt_entry_handler handler,
  130. unsigned int max_entries)
  131. {
  132. return acpi_table_parse_madt_family(ACPI_SRAT, sizeof(struct acpi_table_srat),
  133. id, handler, max_entries);
  134. }
  135. int __init
  136. acpi_numa_init(void)
  137. {
  138. int result;
  139. /* SRAT: Static Resource Affinity Table */
  140. result = acpi_table_parse(ACPI_SRAT, acpi_parse_srat);
  141. if (result > 0) {
  142. result = acpi_table_parse_srat(ACPI_SRAT_PROCESSOR_AFFINITY,
  143. acpi_parse_processor_affinity,
  144. NR_CPUS);
  145. result = acpi_table_parse_srat(ACPI_SRAT_MEMORY_AFFINITY,
  146. acpi_parse_memory_affinity,
  147. NR_NODE_MEMBLKS); // IA64 specific
  148. }
  149. /* SLIT: System Locality Information Table */
  150. result = acpi_table_parse(ACPI_SLIT, acpi_parse_slit);
  151. acpi_numa_arch_fixup();
  152. return 0;
  153. }
  154. int
  155. acpi_get_pxm(acpi_handle h)
  156. {
  157. unsigned long pxm;
  158. acpi_status status;
  159. acpi_handle handle;
  160. acpi_handle phandle = h;
  161. do {
  162. handle = phandle;
  163. status = acpi_evaluate_integer(handle, "_PXM", NULL, &pxm);
  164. if (ACPI_SUCCESS(status))
  165. return (int)pxm;
  166. status = acpi_get_parent(handle, &phandle);
  167. } while(ACPI_SUCCESS(status));
  168. return -1;
  169. }
  170. EXPORT_SYMBOL(acpi_get_pxm);