numa.c 5.4 KB

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