tables.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. * acpi_tables.c - ACPI Boot-Time Table Parsing
  3. *
  4. * Copyright (C) 2001 Paul Diefenbaugh <paul.s.diefenbaugh@intel.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/init.h>
  26. #include <linux/kernel.h>
  27. #include <linux/smp.h>
  28. #include <linux/string.h>
  29. #include <linux/types.h>
  30. #include <linux/irq.h>
  31. #include <linux/errno.h>
  32. #include <linux/acpi.h>
  33. #include <linux/bootmem.h>
  34. #define PREFIX "ACPI: "
  35. #define ACPI_MAX_TABLES 128
  36. static char *mps_inti_flags_polarity[] = { "dfl", "high", "res", "low" };
  37. static char *mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" };
  38. static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES] __initdata;
  39. static int acpi_apic_instance __initdata;
  40. void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
  41. {
  42. if (!header)
  43. return;
  44. switch (header->type) {
  45. case ACPI_MADT_TYPE_LOCAL_APIC:
  46. {
  47. struct acpi_madt_local_apic *p =
  48. (struct acpi_madt_local_apic *)header;
  49. printk(KERN_INFO PREFIX
  50. "LAPIC (acpi_id[0x%02x] lapic_id[0x%02x] %s)\n",
  51. p->processor_id, p->id,
  52. (p->lapic_flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
  53. }
  54. break;
  55. case ACPI_MADT_TYPE_IO_APIC:
  56. {
  57. struct acpi_madt_io_apic *p =
  58. (struct acpi_madt_io_apic *)header;
  59. printk(KERN_INFO PREFIX
  60. "IOAPIC (id[0x%02x] address[0x%08x] gsi_base[%d])\n",
  61. p->id, p->address, p->global_irq_base);
  62. }
  63. break;
  64. case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE:
  65. {
  66. struct acpi_madt_interrupt_override *p =
  67. (struct acpi_madt_interrupt_override *)header;
  68. printk(KERN_INFO PREFIX
  69. "INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s %s)\n",
  70. p->bus, p->source_irq, p->global_irq,
  71. mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
  72. mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2]);
  73. if (p->inti_flags &
  74. ~(ACPI_MADT_POLARITY_MASK | ACPI_MADT_TRIGGER_MASK))
  75. printk(KERN_INFO PREFIX
  76. "INT_SRC_OVR unexpected reserved flags: 0x%x\n",
  77. p->inti_flags &
  78. ~(ACPI_MADT_POLARITY_MASK | ACPI_MADT_TRIGGER_MASK));
  79. }
  80. break;
  81. case ACPI_MADT_TYPE_NMI_SOURCE:
  82. {
  83. struct acpi_madt_nmi_source *p =
  84. (struct acpi_madt_nmi_source *)header;
  85. printk(KERN_INFO PREFIX
  86. "NMI_SRC (%s %s global_irq %d)\n",
  87. mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
  88. mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
  89. p->global_irq);
  90. }
  91. break;
  92. case ACPI_MADT_TYPE_LOCAL_APIC_NMI:
  93. {
  94. struct acpi_madt_local_apic_nmi *p =
  95. (struct acpi_madt_local_apic_nmi *)header;
  96. printk(KERN_INFO PREFIX
  97. "LAPIC_NMI (acpi_id[0x%02x] %s %s lint[0x%x])\n",
  98. p->processor_id,
  99. mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK ],
  100. mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
  101. p->lint);
  102. }
  103. break;
  104. case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE:
  105. {
  106. struct acpi_madt_local_apic_override *p =
  107. (struct acpi_madt_local_apic_override *)header;
  108. printk(KERN_INFO PREFIX
  109. "LAPIC_ADDR_OVR (address[%p])\n",
  110. (void *)(unsigned long)p->address);
  111. }
  112. break;
  113. case ACPI_MADT_TYPE_IO_SAPIC:
  114. {
  115. struct acpi_madt_io_sapic *p =
  116. (struct acpi_madt_io_sapic *)header;
  117. printk(KERN_INFO PREFIX
  118. "IOSAPIC (id[0x%x] address[%p] gsi_base[%d])\n",
  119. p->id, (void *)(unsigned long)p->address,
  120. p->global_irq_base);
  121. }
  122. break;
  123. case ACPI_MADT_TYPE_LOCAL_SAPIC:
  124. {
  125. struct acpi_madt_local_sapic *p =
  126. (struct acpi_madt_local_sapic *)header;
  127. printk(KERN_INFO PREFIX
  128. "LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] lsapic_eid[0x%02x] %s)\n",
  129. p->processor_id, p->id, p->eid,
  130. (p->lapic_flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
  131. }
  132. break;
  133. case ACPI_MADT_TYPE_INTERRUPT_SOURCE:
  134. {
  135. struct acpi_madt_interrupt_source *p =
  136. (struct acpi_madt_interrupt_source *)header;
  137. printk(KERN_INFO PREFIX
  138. "PLAT_INT_SRC (%s %s type[0x%x] id[0x%04x] eid[0x%x] iosapic_vector[0x%x] global_irq[0x%x]\n",
  139. mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
  140. mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
  141. p->type, p->id, p->eid, p->io_sapic_vector,
  142. p->global_irq);
  143. }
  144. break;
  145. default:
  146. printk(KERN_WARNING PREFIX
  147. "Found unsupported MADT entry (type = 0x%x)\n",
  148. header->type);
  149. break;
  150. }
  151. }
  152. int __init
  153. acpi_table_parse_entries(char *id,
  154. unsigned long table_size,
  155. int entry_id,
  156. acpi_table_entry_handler handler,
  157. unsigned int max_entries)
  158. {
  159. struct acpi_table_header *table_header = NULL;
  160. struct acpi_subtable_header *entry;
  161. unsigned int count = 0;
  162. unsigned long table_end;
  163. if (!handler)
  164. return -EINVAL;
  165. if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
  166. acpi_get_table(id, acpi_apic_instance, &table_header);
  167. else
  168. acpi_get_table(id, 0, &table_header);
  169. if (!table_header) {
  170. printk(KERN_WARNING PREFIX "%4.4s not present\n", id);
  171. return -ENODEV;
  172. }
  173. table_end = (unsigned long)table_header + table_header->length;
  174. /* Parse all entries looking for a match. */
  175. entry = (struct acpi_subtable_header *)
  176. ((unsigned long)table_header + table_size);
  177. while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
  178. table_end) {
  179. if (entry->type == entry_id
  180. && (!max_entries || count++ < max_entries))
  181. if (handler(entry, table_end))
  182. return -EINVAL;
  183. entry = (struct acpi_subtable_header *)
  184. ((unsigned long)entry + entry->length);
  185. }
  186. if (max_entries && count > max_entries) {
  187. printk(KERN_WARNING PREFIX "[%4.4s:0x%02x] ignored %i entries of "
  188. "%i found\n", id, entry_id, count - max_entries, count);
  189. }
  190. return count;
  191. }
  192. int __init
  193. acpi_table_parse_madt(enum acpi_madt_type id,
  194. acpi_table_entry_handler handler, unsigned int max_entries)
  195. {
  196. return acpi_table_parse_entries(ACPI_SIG_MADT,
  197. sizeof(struct acpi_table_madt), id,
  198. handler, max_entries);
  199. }
  200. /**
  201. * acpi_table_parse - find table with @id, run @handler on it
  202. *
  203. * @id: table id to find
  204. * @handler: handler to run
  205. *
  206. * Scan the ACPI System Descriptor Table (STD) for a table matching @id,
  207. * run @handler on it. Return 0 if table found, return on if not.
  208. */
  209. int __init acpi_table_parse(char *id, acpi_table_handler handler)
  210. {
  211. struct acpi_table_header *table = NULL;
  212. if (!handler)
  213. return -EINVAL;
  214. if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
  215. acpi_get_table(id, acpi_apic_instance, &table);
  216. else
  217. acpi_get_table(id, 0, &table);
  218. if (table) {
  219. handler(table);
  220. return 0;
  221. } else
  222. return 1;
  223. }
  224. /*
  225. * The BIOS is supposed to supply a single APIC/MADT,
  226. * but some report two. Provide a knob to use either.
  227. * (don't you wish instance 0 and 1 were not the same?)
  228. */
  229. static void __init check_multiple_madt(void)
  230. {
  231. struct acpi_table_header *table = NULL;
  232. acpi_get_table(ACPI_SIG_MADT, 2, &table);
  233. if (table) {
  234. printk(KERN_WARNING PREFIX
  235. "BIOS bug: multiple APIC/MADT found,"
  236. " using %d\n", acpi_apic_instance);
  237. printk(KERN_WARNING PREFIX
  238. "If \"acpi_apic_instance=%d\" works better, "
  239. "notify linux-acpi@vger.kernel.org\n",
  240. acpi_apic_instance ? 0 : 2);
  241. } else
  242. acpi_apic_instance = 0;
  243. return;
  244. }
  245. /*
  246. * acpi_table_init()
  247. *
  248. * find RSDP, find and checksum SDT/XSDT.
  249. * checksum all tables, print SDT/XSDT
  250. *
  251. * result: sdt_entry[] is initialized
  252. */
  253. int __init acpi_table_init(void)
  254. {
  255. acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
  256. check_multiple_madt();
  257. return 0;
  258. }
  259. static int __init acpi_parse_apic_instance(char *str)
  260. {
  261. acpi_apic_instance = simple_strtoul(str, NULL, 0);
  262. printk(KERN_NOTICE PREFIX "Shall use APIC/MADT table %d\n",
  263. acpi_apic_instance);
  264. return 0;
  265. }
  266. early_param("acpi_apic_instance", acpi_parse_apic_instance);