tables.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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_LOCAL_X2APIC:
  56. {
  57. struct acpi_madt_local_x2apic *p =
  58. (struct acpi_madt_local_x2apic *)header;
  59. printk(KERN_INFO PREFIX
  60. "X2APIC (apic_id[0x%02x] uid[0x%02x] %s)\n",
  61. p->local_apic_id, p->uid,
  62. (p->lapic_flags & ACPI_MADT_ENABLED) ?
  63. "enabled" : "disabled");
  64. }
  65. break;
  66. case ACPI_MADT_TYPE_IO_APIC:
  67. {
  68. struct acpi_madt_io_apic *p =
  69. (struct acpi_madt_io_apic *)header;
  70. printk(KERN_INFO PREFIX
  71. "IOAPIC (id[0x%02x] address[0x%08x] gsi_base[%d])\n",
  72. p->id, p->address, p->global_irq_base);
  73. }
  74. break;
  75. case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE:
  76. {
  77. struct acpi_madt_interrupt_override *p =
  78. (struct acpi_madt_interrupt_override *)header;
  79. printk(KERN_INFO PREFIX
  80. "INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s %s)\n",
  81. p->bus, p->source_irq, p->global_irq,
  82. mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
  83. mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2]);
  84. if (p->inti_flags &
  85. ~(ACPI_MADT_POLARITY_MASK | ACPI_MADT_TRIGGER_MASK))
  86. printk(KERN_INFO PREFIX
  87. "INT_SRC_OVR unexpected reserved flags: 0x%x\n",
  88. p->inti_flags &
  89. ~(ACPI_MADT_POLARITY_MASK | ACPI_MADT_TRIGGER_MASK));
  90. }
  91. break;
  92. case ACPI_MADT_TYPE_NMI_SOURCE:
  93. {
  94. struct acpi_madt_nmi_source *p =
  95. (struct acpi_madt_nmi_source *)header;
  96. printk(KERN_INFO PREFIX
  97. "NMI_SRC (%s %s global_irq %d)\n",
  98. mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
  99. mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
  100. p->global_irq);
  101. }
  102. break;
  103. case ACPI_MADT_TYPE_LOCAL_APIC_NMI:
  104. {
  105. struct acpi_madt_local_apic_nmi *p =
  106. (struct acpi_madt_local_apic_nmi *)header;
  107. printk(KERN_INFO PREFIX
  108. "LAPIC_NMI (acpi_id[0x%02x] %s %s lint[0x%x])\n",
  109. p->processor_id,
  110. mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK ],
  111. mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
  112. p->lint);
  113. }
  114. break;
  115. case ACPI_MADT_TYPE_LOCAL_X2APIC_NMI:
  116. {
  117. u16 polarity, trigger;
  118. struct acpi_madt_local_x2apic_nmi *p =
  119. (struct acpi_madt_local_x2apic_nmi *)header;
  120. polarity = p->inti_flags & ACPI_MADT_POLARITY_MASK;
  121. trigger = (p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
  122. printk(KERN_INFO PREFIX
  123. "X2APIC_NMI (uid[0x%02x] %s %s lint[0x%x])\n",
  124. p->uid,
  125. mps_inti_flags_polarity[polarity],
  126. mps_inti_flags_trigger[trigger],
  127. p->lint);
  128. }
  129. break;
  130. case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE:
  131. {
  132. struct acpi_madt_local_apic_override *p =
  133. (struct acpi_madt_local_apic_override *)header;
  134. printk(KERN_INFO PREFIX
  135. "LAPIC_ADDR_OVR (address[%p])\n",
  136. (void *)(unsigned long)p->address);
  137. }
  138. break;
  139. case ACPI_MADT_TYPE_IO_SAPIC:
  140. {
  141. struct acpi_madt_io_sapic *p =
  142. (struct acpi_madt_io_sapic *)header;
  143. printk(KERN_INFO PREFIX
  144. "IOSAPIC (id[0x%x] address[%p] gsi_base[%d])\n",
  145. p->id, (void *)(unsigned long)p->address,
  146. p->global_irq_base);
  147. }
  148. break;
  149. case ACPI_MADT_TYPE_LOCAL_SAPIC:
  150. {
  151. struct acpi_madt_local_sapic *p =
  152. (struct acpi_madt_local_sapic *)header;
  153. printk(KERN_INFO PREFIX
  154. "LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] lsapic_eid[0x%02x] %s)\n",
  155. p->processor_id, p->id, p->eid,
  156. (p->lapic_flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
  157. }
  158. break;
  159. case ACPI_MADT_TYPE_INTERRUPT_SOURCE:
  160. {
  161. struct acpi_madt_interrupt_source *p =
  162. (struct acpi_madt_interrupt_source *)header;
  163. printk(KERN_INFO PREFIX
  164. "PLAT_INT_SRC (%s %s type[0x%x] id[0x%04x] eid[0x%x] iosapic_vector[0x%x] global_irq[0x%x]\n",
  165. mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
  166. mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
  167. p->type, p->id, p->eid, p->io_sapic_vector,
  168. p->global_irq);
  169. }
  170. break;
  171. default:
  172. printk(KERN_WARNING PREFIX
  173. "Found unsupported MADT entry (type = 0x%x)\n",
  174. header->type);
  175. break;
  176. }
  177. }
  178. int __init
  179. acpi_table_parse_entries(char *id,
  180. unsigned long table_size,
  181. int entry_id,
  182. acpi_table_entry_handler handler,
  183. unsigned int max_entries)
  184. {
  185. struct acpi_table_header *table_header = NULL;
  186. struct acpi_subtable_header *entry;
  187. unsigned int count = 0;
  188. unsigned long table_end;
  189. acpi_size tbl_size;
  190. if (acpi_disabled)
  191. return -ENODEV;
  192. if (!handler)
  193. return -EINVAL;
  194. if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
  195. acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size);
  196. else
  197. acpi_get_table_with_size(id, 0, &table_header, &tbl_size);
  198. if (!table_header) {
  199. printk(KERN_WARNING PREFIX "%4.4s not present\n", id);
  200. return -ENODEV;
  201. }
  202. table_end = (unsigned long)table_header + table_header->length;
  203. /* Parse all entries looking for a match. */
  204. entry = (struct acpi_subtable_header *)
  205. ((unsigned long)table_header + table_size);
  206. while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
  207. table_end) {
  208. if (entry->type == entry_id
  209. && (!max_entries || count++ < max_entries))
  210. if (handler(entry, table_end)) {
  211. early_acpi_os_unmap_memory((char *)table_header, tbl_size);
  212. return -EINVAL;
  213. }
  214. entry = (struct acpi_subtable_header *)
  215. ((unsigned long)entry + entry->length);
  216. }
  217. if (max_entries && count > max_entries) {
  218. printk(KERN_WARNING PREFIX "[%4.4s:0x%02x] ignored %i entries of "
  219. "%i found\n", id, entry_id, count - max_entries, count);
  220. }
  221. early_acpi_os_unmap_memory((char *)table_header, tbl_size);
  222. return count;
  223. }
  224. int __init
  225. acpi_table_parse_madt(enum acpi_madt_type id,
  226. acpi_table_entry_handler handler, unsigned int max_entries)
  227. {
  228. return acpi_table_parse_entries(ACPI_SIG_MADT,
  229. sizeof(struct acpi_table_madt), id,
  230. handler, max_entries);
  231. }
  232. /**
  233. * acpi_table_parse - find table with @id, run @handler on it
  234. *
  235. * @id: table id to find
  236. * @handler: handler to run
  237. *
  238. * Scan the ACPI System Descriptor Table (STD) for a table matching @id,
  239. * run @handler on it. Return 0 if table found, return on if not.
  240. */
  241. int __init acpi_table_parse(char *id, acpi_table_handler handler)
  242. {
  243. struct acpi_table_header *table = NULL;
  244. acpi_size tbl_size;
  245. if (acpi_disabled)
  246. return -ENODEV;
  247. if (!handler)
  248. return -EINVAL;
  249. if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
  250. acpi_get_table_with_size(id, acpi_apic_instance, &table, &tbl_size);
  251. else
  252. acpi_get_table_with_size(id, 0, &table, &tbl_size);
  253. if (table) {
  254. handler(table);
  255. early_acpi_os_unmap_memory(table, tbl_size);
  256. return 0;
  257. } else
  258. return 1;
  259. }
  260. /*
  261. * The BIOS is supposed to supply a single APIC/MADT,
  262. * but some report two. Provide a knob to use either.
  263. * (don't you wish instance 0 and 1 were not the same?)
  264. */
  265. static void __init check_multiple_madt(void)
  266. {
  267. struct acpi_table_header *table = NULL;
  268. acpi_size tbl_size;
  269. acpi_get_table_with_size(ACPI_SIG_MADT, 2, &table, &tbl_size);
  270. if (table) {
  271. printk(KERN_WARNING PREFIX
  272. "BIOS bug: multiple APIC/MADT found,"
  273. " using %d\n", acpi_apic_instance);
  274. printk(KERN_WARNING PREFIX
  275. "If \"acpi_apic_instance=%d\" works better, "
  276. "notify linux-acpi@vger.kernel.org\n",
  277. acpi_apic_instance ? 0 : 2);
  278. early_acpi_os_unmap_memory(table, tbl_size);
  279. } else
  280. acpi_apic_instance = 0;
  281. return;
  282. }
  283. /*
  284. * acpi_table_init()
  285. *
  286. * find RSDP, find and checksum SDT/XSDT.
  287. * checksum all tables, print SDT/XSDT
  288. *
  289. * result: sdt_entry[] is initialized
  290. */
  291. int __init acpi_table_init(void)
  292. {
  293. acpi_status status;
  294. status = acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
  295. if (ACPI_FAILURE(status))
  296. return 1;
  297. check_multiple_madt();
  298. return 0;
  299. }
  300. static int __init acpi_parse_apic_instance(char *str)
  301. {
  302. if (!str)
  303. return -EINVAL;
  304. acpi_apic_instance = simple_strtoul(str, NULL, 0);
  305. printk(KERN_NOTICE PREFIX "Shall use APIC/MADT table %d\n",
  306. acpi_apic_instance);
  307. return 0;
  308. }
  309. early_param("acpi_apic_instance", acpi_parse_apic_instance);