tables.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. void acpi_table_print_madt_entry(struct acpi_subtable_header * header)
  40. {
  41. if (!header)
  42. return;
  43. switch (header->type) {
  44. case ACPI_MADT_TYPE_LOCAL_APIC:
  45. {
  46. struct acpi_madt_local_apic *p =
  47. (struct acpi_madt_local_apic *)header;
  48. printk(KERN_INFO PREFIX
  49. "LAPIC (acpi_id[0x%02x] lapic_id[0x%02x] %s)\n",
  50. p->processor_id, p->id,
  51. (p->lapic_flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
  52. }
  53. break;
  54. case ACPI_MADT_TYPE_IO_APIC:
  55. {
  56. struct acpi_madt_io_apic *p =
  57. (struct acpi_madt_io_apic *)header;
  58. printk(KERN_INFO PREFIX
  59. "IOAPIC (id[0x%02x] address[0x%08x] gsi_base[%d])\n",
  60. p->id, p->address, p->global_irq_base);
  61. }
  62. break;
  63. case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE:
  64. {
  65. struct acpi_madt_interrupt_override *p =
  66. (struct acpi_madt_interrupt_override *)header;
  67. printk(KERN_INFO PREFIX
  68. "INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s %s)\n",
  69. p->bus, p->source_irq, p->global_irq,
  70. mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
  71. mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2]);
  72. if (p->inti_flags &
  73. ~(ACPI_MADT_POLARITY_MASK | ACPI_MADT_TRIGGER_MASK))
  74. printk(KERN_INFO PREFIX
  75. "INT_SRC_OVR unexpected reserved flags: 0x%x\n",
  76. p->inti_flags &
  77. ~(ACPI_MADT_POLARITY_MASK | ACPI_MADT_TRIGGER_MASK));
  78. }
  79. break;
  80. case ACPI_MADT_TYPE_NMI_SOURCE:
  81. {
  82. struct acpi_madt_nmi_source *p =
  83. (struct acpi_madt_nmi_source *)header;
  84. printk(KERN_INFO PREFIX
  85. "NMI_SRC (%s %s global_irq %d)\n",
  86. mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
  87. mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
  88. p->global_irq);
  89. }
  90. break;
  91. case ACPI_MADT_TYPE_LOCAL_APIC_NMI:
  92. {
  93. struct acpi_madt_local_apic_nmi *p =
  94. (struct acpi_madt_local_apic_nmi *)header;
  95. printk(KERN_INFO PREFIX
  96. "LAPIC_NMI (acpi_id[0x%02x] %s %s lint[0x%x])\n",
  97. p->processor_id,
  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->lint);
  101. }
  102. break;
  103. case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE:
  104. {
  105. struct acpi_madt_local_apic_override *p =
  106. (struct acpi_madt_local_apic_override *)header;
  107. printk(KERN_INFO PREFIX
  108. "LAPIC_ADDR_OVR (address[%p])\n",
  109. (void *)(unsigned long)p->address);
  110. }
  111. break;
  112. case ACPI_MADT_TYPE_IO_SAPIC:
  113. {
  114. struct acpi_madt_io_sapic *p =
  115. (struct acpi_madt_io_sapic *)header;
  116. printk(KERN_INFO PREFIX
  117. "IOSAPIC (id[0x%x] address[%p] gsi_base[%d])\n",
  118. p->id, (void *)(unsigned long)p->address,
  119. p->global_irq_base);
  120. }
  121. break;
  122. case ACPI_MADT_TYPE_LOCAL_SAPIC:
  123. {
  124. struct acpi_madt_local_sapic *p =
  125. (struct acpi_madt_local_sapic *)header;
  126. printk(KERN_INFO PREFIX
  127. "LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] lsapic_eid[0x%02x] %s)\n",
  128. p->processor_id, p->id, p->eid,
  129. (p->lapic_flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
  130. }
  131. break;
  132. case ACPI_MADT_TYPE_INTERRUPT_SOURCE:
  133. {
  134. struct acpi_madt_interrupt_source *p =
  135. (struct acpi_madt_interrupt_source *)header;
  136. printk(KERN_INFO PREFIX
  137. "PLAT_INT_SRC (%s %s type[0x%x] id[0x%04x] eid[0x%x] iosapic_vector[0x%x] global_irq[0x%x]\n",
  138. mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
  139. mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
  140. p->type, p->id, p->eid, p->io_sapic_vector,
  141. p->global_irq);
  142. }
  143. break;
  144. default:
  145. printk(KERN_WARNING PREFIX
  146. "Found unsupported MADT entry (type = 0x%x)\n",
  147. header->type);
  148. break;
  149. }
  150. }
  151. int __init
  152. acpi_table_parse_entries(char *id,
  153. unsigned long table_size,
  154. int entry_id,
  155. acpi_table_entry_handler handler,
  156. unsigned int max_entries)
  157. {
  158. struct acpi_table_header *table_header = NULL;
  159. struct acpi_subtable_header *entry;
  160. unsigned int count = 0;
  161. unsigned long table_end;
  162. if (!handler)
  163. return -EINVAL;
  164. /* Locate the table (if exists). There should only be one. */
  165. acpi_get_table(id, 0, &table_header);
  166. if (!table_header) {
  167. printk(KERN_WARNING PREFIX "%4.4s not present\n", id);
  168. return -ENODEV;
  169. }
  170. table_end = (unsigned long)table_header + table_header->length;
  171. /* Parse all entries looking for a match. */
  172. entry = (struct acpi_subtable_header *)
  173. ((unsigned long)table_header + table_size);
  174. while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
  175. table_end) {
  176. if (entry->type == entry_id
  177. && (!max_entries || count++ < max_entries))
  178. if (handler(entry, table_end))
  179. return -EINVAL;
  180. entry = (struct acpi_subtable_header *)
  181. ((unsigned long)entry + entry->length);
  182. }
  183. if (max_entries && count > max_entries) {
  184. printk(KERN_WARNING PREFIX "[%4.4s:0x%02x] ignored %i entries of "
  185. "%i found\n", id, entry_id, count - max_entries, count);
  186. }
  187. return count;
  188. }
  189. int __init
  190. acpi_table_parse_madt(enum acpi_madt_type id,
  191. acpi_table_entry_handler handler, unsigned int max_entries)
  192. {
  193. return acpi_table_parse_entries(ACPI_SIG_MADT,
  194. sizeof(struct acpi_table_madt), id,
  195. handler, max_entries);
  196. }
  197. /**
  198. * acpi_table_parse - find table with @id, run @handler on it
  199. *
  200. * @id: table id to find
  201. * @handler: handler to run
  202. *
  203. * Scan the ACPI System Descriptor Table (STD) for a table matching @id,
  204. * run @handler on it. Return 0 if table found, return on if not.
  205. */
  206. int __init acpi_table_parse(char *id, acpi_table_handler handler)
  207. {
  208. struct acpi_table_header *table = NULL;
  209. if (!handler)
  210. return -EINVAL;
  211. acpi_get_table(id, 0, &table);
  212. if (table) {
  213. handler(table);
  214. return 0;
  215. } else
  216. return 1;
  217. }
  218. /*
  219. * acpi_table_init()
  220. *
  221. * find RSDP, find and checksum SDT/XSDT.
  222. * checksum all tables, print SDT/XSDT
  223. *
  224. * result: sdt_entry[] is initialized
  225. */
  226. int __init acpi_table_init(void)
  227. {
  228. acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
  229. return 0;
  230. }