tables.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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/sched.h>
  28. #include <linux/smp.h>
  29. #include <linux/string.h>
  30. #include <linux/types.h>
  31. #include <linux/irq.h>
  32. #include <linux/errno.h>
  33. #include <linux/acpi.h>
  34. #include <linux/bootmem.h>
  35. #define PREFIX "ACPI: "
  36. #define ACPI_MAX_TABLES 128
  37. static char *acpi_table_signatures[ACPI_TABLE_COUNT] = {
  38. [ACPI_TABLE_UNKNOWN] = "????",
  39. [ACPI_APIC] = "APIC",
  40. [ACPI_BOOT] = "BOOT",
  41. [ACPI_DBGP] = "DBGP",
  42. [ACPI_DSDT] = "DSDT",
  43. [ACPI_ECDT] = "ECDT",
  44. [ACPI_ETDT] = "ETDT",
  45. [ACPI_FADT] = "FACP",
  46. [ACPI_FACS] = "FACS",
  47. [ACPI_OEMX] = "OEM",
  48. [ACPI_PSDT] = "PSDT",
  49. [ACPI_SBST] = "SBST",
  50. [ACPI_SLIT] = "SLIT",
  51. [ACPI_SPCR] = "SPCR",
  52. [ACPI_SRAT] = "SRAT",
  53. [ACPI_SSDT] = "SSDT",
  54. [ACPI_SPMI] = "SPMI",
  55. [ACPI_HPET] = "HPET",
  56. [ACPI_MCFG] = "MCFG",
  57. };
  58. static char *mps_inti_flags_polarity[] = { "dfl", "high", "res", "low" };
  59. static char *mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" };
  60. /* System Description Table (RSDT/XSDT) */
  61. struct acpi_table_sdt {
  62. unsigned long pa;
  63. enum acpi_table_id id;
  64. unsigned long size;
  65. } __attribute__ ((packed));
  66. static unsigned long sdt_pa; /* Physical Address */
  67. static unsigned long sdt_count; /* Table count */
  68. static struct acpi_table_sdt sdt_entry[ACPI_MAX_TABLES] __initdata;
  69. static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES] __initdata;
  70. void acpi_table_print(struct acpi_table_header *header, unsigned long phys_addr)
  71. {
  72. char *name = NULL;
  73. if (!header)
  74. return;
  75. /* Some table signatures aren't good table names */
  76. if (!strncmp((char *)&header->signature,
  77. acpi_table_signatures[ACPI_APIC],
  78. sizeof(header->signature))) {
  79. name = "MADT";
  80. } else if (!strncmp((char *)&header->signature,
  81. acpi_table_signatures[ACPI_FADT],
  82. sizeof(header->signature))) {
  83. name = "FADT";
  84. } else
  85. name = header->signature;
  86. printk(KERN_DEBUG PREFIX
  87. "%.4s (v%3.3d %6.6s %8.8s 0x%08x %.4s 0x%08x) @ 0x%p\n", name,
  88. header->revision, header->oem_id, header->oem_table_id,
  89. header->oem_revision, header->asl_compiler_id,
  90. header->asl_compiler_revision, (void *)phys_addr);
  91. }
  92. void acpi_table_print_madt_entry(acpi_table_entry_header * header)
  93. {
  94. if (!header)
  95. return;
  96. switch (header->type) {
  97. case ACPI_MADT_LAPIC:
  98. {
  99. struct acpi_table_lapic *p =
  100. (struct acpi_table_lapic *)header;
  101. printk(KERN_INFO PREFIX
  102. "LAPIC (acpi_id[0x%02x] lapic_id[0x%02x] %s)\n",
  103. p->acpi_id, p->id,
  104. p->flags.enabled ? "enabled" : "disabled");
  105. }
  106. break;
  107. case ACPI_MADT_IOAPIC:
  108. {
  109. struct acpi_table_ioapic *p =
  110. (struct acpi_table_ioapic *)header;
  111. printk(KERN_INFO PREFIX
  112. "IOAPIC (id[0x%02x] address[0x%08x] gsi_base[%d])\n",
  113. p->id, p->address, p->global_irq_base);
  114. }
  115. break;
  116. case ACPI_MADT_INT_SRC_OVR:
  117. {
  118. struct acpi_table_int_src_ovr *p =
  119. (struct acpi_table_int_src_ovr *)header;
  120. printk(KERN_INFO PREFIX
  121. "INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s %s)\n",
  122. p->bus, p->bus_irq, p->global_irq,
  123. mps_inti_flags_polarity[p->flags.polarity],
  124. mps_inti_flags_trigger[p->flags.trigger]);
  125. if (p->flags.reserved)
  126. printk(KERN_INFO PREFIX
  127. "INT_SRC_OVR unexpected reserved flags: 0x%x\n",
  128. p->flags.reserved);
  129. }
  130. break;
  131. case ACPI_MADT_NMI_SRC:
  132. {
  133. struct acpi_table_nmi_src *p =
  134. (struct acpi_table_nmi_src *)header;
  135. printk(KERN_INFO PREFIX
  136. "NMI_SRC (%s %s global_irq %d)\n",
  137. mps_inti_flags_polarity[p->flags.polarity],
  138. mps_inti_flags_trigger[p->flags.trigger],
  139. p->global_irq);
  140. }
  141. break;
  142. case ACPI_MADT_LAPIC_NMI:
  143. {
  144. struct acpi_table_lapic_nmi *p =
  145. (struct acpi_table_lapic_nmi *)header;
  146. printk(KERN_INFO PREFIX
  147. "LAPIC_NMI (acpi_id[0x%02x] %s %s lint[0x%x])\n",
  148. p->acpi_id,
  149. mps_inti_flags_polarity[p->flags.polarity],
  150. mps_inti_flags_trigger[p->flags.trigger],
  151. p->lint);
  152. }
  153. break;
  154. case ACPI_MADT_LAPIC_ADDR_OVR:
  155. {
  156. struct acpi_table_lapic_addr_ovr *p =
  157. (struct acpi_table_lapic_addr_ovr *)header;
  158. printk(KERN_INFO PREFIX
  159. "LAPIC_ADDR_OVR (address[%p])\n",
  160. (void *)(unsigned long)p->address);
  161. }
  162. break;
  163. case ACPI_MADT_IOSAPIC:
  164. {
  165. struct acpi_table_iosapic *p =
  166. (struct acpi_table_iosapic *)header;
  167. printk(KERN_INFO PREFIX
  168. "IOSAPIC (id[0x%x] address[%p] gsi_base[%d])\n",
  169. p->id, (void *)(unsigned long)p->address,
  170. p->global_irq_base);
  171. }
  172. break;
  173. case ACPI_MADT_LSAPIC:
  174. {
  175. struct acpi_table_lsapic *p =
  176. (struct acpi_table_lsapic *)header;
  177. printk(KERN_INFO PREFIX
  178. "LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] lsapic_eid[0x%02x] %s)\n",
  179. p->acpi_id, p->id, p->eid,
  180. p->flags.enabled ? "enabled" : "disabled");
  181. }
  182. break;
  183. case ACPI_MADT_PLAT_INT_SRC:
  184. {
  185. struct acpi_table_plat_int_src *p =
  186. (struct acpi_table_plat_int_src *)header;
  187. printk(KERN_INFO PREFIX
  188. "PLAT_INT_SRC (%s %s type[0x%x] id[0x%04x] eid[0x%x] iosapic_vector[0x%x] global_irq[0x%x]\n",
  189. mps_inti_flags_polarity[p->flags.polarity],
  190. mps_inti_flags_trigger[p->flags.trigger],
  191. p->type, p->id, p->eid, p->iosapic_vector,
  192. p->global_irq);
  193. }
  194. break;
  195. default:
  196. printk(KERN_WARNING PREFIX
  197. "Found unsupported MADT entry (type = 0x%x)\n",
  198. header->type);
  199. break;
  200. }
  201. }
  202. static int
  203. acpi_table_compute_checksum(void *table_pointer, unsigned long length)
  204. {
  205. u8 *p = table_pointer;
  206. unsigned long remains = length;
  207. unsigned long sum = 0;
  208. if (!p || !length)
  209. return -EINVAL;
  210. while (remains--)
  211. sum += *p++;
  212. return (sum & 0xFF);
  213. }
  214. /*
  215. * acpi_get_table_header_early()
  216. * for acpi_blacklisted(), acpi_table_get_sdt()
  217. */
  218. int __init
  219. acpi_get_table_header_early(enum acpi_table_id id,
  220. struct acpi_table_header **header)
  221. {
  222. unsigned int i;
  223. enum acpi_table_id temp_id;
  224. /* DSDT is different from the rest */
  225. if (id == ACPI_DSDT)
  226. temp_id = ACPI_FADT;
  227. else
  228. temp_id = id;
  229. /* Locate the table. */
  230. for (i = 0; i < sdt_count; i++) {
  231. if (sdt_entry[i].id != temp_id)
  232. continue;
  233. *header = (void *)
  234. __acpi_map_table(sdt_entry[i].pa, sdt_entry[i].size);
  235. if (!*header) {
  236. printk(KERN_WARNING PREFIX "Unable to map %s\n",
  237. acpi_table_signatures[temp_id]);
  238. return -ENODEV;
  239. }
  240. break;
  241. }
  242. if (!*header) {
  243. printk(KERN_WARNING PREFIX "%s not present\n",
  244. acpi_table_signatures[id]);
  245. return -ENODEV;
  246. }
  247. /* Map the DSDT header via the pointer in the FADT */
  248. if (id == ACPI_DSDT) {
  249. struct fadt_descriptor *fadt =
  250. (struct fadt_descriptor *)*header;
  251. if (fadt->header.revision == 3 && fadt->Xdsdt) {
  252. *header = (void *)__acpi_map_table(fadt->Xdsdt,
  253. sizeof(struct
  254. acpi_table_header));
  255. } else if (fadt->dsdt) {
  256. *header = (void *)__acpi_map_table(fadt->dsdt,
  257. sizeof(struct
  258. acpi_table_header));
  259. } else
  260. *header = NULL;
  261. if (!*header) {
  262. printk(KERN_WARNING PREFIX "Unable to map DSDT\n");
  263. return -ENODEV;
  264. }
  265. }
  266. return 0;
  267. }
  268. int __init
  269. acpi_table_parse_madt_family(enum acpi_table_id id,
  270. unsigned long madt_size,
  271. int entry_id,
  272. acpi_madt_entry_handler handler,
  273. unsigned int max_entries)
  274. {
  275. void *madt = NULL;
  276. acpi_table_entry_header *entry;
  277. unsigned int count = 0;
  278. unsigned long madt_end;
  279. unsigned int i;
  280. if (!handler)
  281. return -EINVAL;
  282. /* Locate the MADT (if exists). There should only be one. */
  283. for (i = 0; i < sdt_count; i++) {
  284. if (sdt_entry[i].id != id)
  285. continue;
  286. madt = (void *)
  287. __acpi_map_table(sdt_entry[i].pa, sdt_entry[i].size);
  288. if (!madt) {
  289. printk(KERN_WARNING PREFIX "Unable to map %s\n",
  290. acpi_table_signatures[id]);
  291. return -ENODEV;
  292. }
  293. break;
  294. }
  295. if (!madt) {
  296. printk(KERN_WARNING PREFIX "%s not present\n",
  297. acpi_table_signatures[id]);
  298. return -ENODEV;
  299. }
  300. madt_end = (unsigned long)madt + sdt_entry[i].size;
  301. /* Parse all entries looking for a match. */
  302. entry = (acpi_table_entry_header *)
  303. ((unsigned long)madt + madt_size);
  304. while (((unsigned long)entry) + sizeof(acpi_table_entry_header) <
  305. madt_end) {
  306. if (entry->type == entry_id
  307. && (!max_entries || count++ < max_entries))
  308. if (handler(entry, madt_end))
  309. return -EINVAL;
  310. entry = (acpi_table_entry_header *)
  311. ((unsigned long)entry + entry->length);
  312. }
  313. if (max_entries && count > max_entries) {
  314. printk(KERN_WARNING PREFIX "[%s:0x%02x] ignored %i entries of "
  315. "%i found\n", acpi_table_signatures[id], entry_id,
  316. count - max_entries, count);
  317. }
  318. return count;
  319. }
  320. int __init
  321. acpi_table_parse_madt(enum acpi_madt_entry_id id,
  322. acpi_madt_entry_handler handler, unsigned int max_entries)
  323. {
  324. return acpi_table_parse_madt_family(ACPI_APIC,
  325. sizeof(struct acpi_table_madt), id,
  326. handler, max_entries);
  327. }
  328. int __init acpi_table_parse(enum acpi_table_id id, acpi_table_handler handler)
  329. {
  330. int count = 0;
  331. unsigned int i = 0;
  332. if (!handler)
  333. return -EINVAL;
  334. for (i = 0; i < sdt_count; i++) {
  335. if (sdt_entry[i].id != id)
  336. continue;
  337. count++;
  338. if (count == 1)
  339. handler(sdt_entry[i].pa, sdt_entry[i].size);
  340. else
  341. printk(KERN_WARNING PREFIX
  342. "%d duplicate %s table ignored.\n", count,
  343. acpi_table_signatures[id]);
  344. }
  345. return count;
  346. }
  347. static int __init acpi_table_get_sdt(struct acpi_table_rsdp *rsdp)
  348. {
  349. struct acpi_table_header *header = NULL;
  350. unsigned int i, id = 0;
  351. if (!rsdp)
  352. return -EINVAL;
  353. /* First check XSDT (but only on ACPI 2.0-compatible systems) */
  354. if ((rsdp->revision >= 2) && rsdp->xsdt_physical_address) {
  355. struct acpi_table_xsdt *mapped_xsdt = NULL;
  356. sdt_pa = rsdp->xsdt_physical_address;
  357. /* map in just the header */
  358. header = (struct acpi_table_header *)
  359. __acpi_map_table(sdt_pa, sizeof(struct acpi_table_header));
  360. if (!header) {
  361. printk(KERN_WARNING PREFIX
  362. "Unable to map XSDT header\n");
  363. return -ENODEV;
  364. }
  365. /* remap in the entire table before processing */
  366. mapped_xsdt = (struct acpi_table_xsdt *)
  367. __acpi_map_table(sdt_pa, header->length);
  368. if (!mapped_xsdt) {
  369. printk(KERN_WARNING PREFIX "Unable to map XSDT\n");
  370. return -ENODEV;
  371. }
  372. header = &mapped_xsdt->header;
  373. if (strncmp(header->signature, "XSDT", 4)) {
  374. printk(KERN_WARNING PREFIX
  375. "XSDT signature incorrect\n");
  376. return -ENODEV;
  377. }
  378. if (acpi_table_compute_checksum(header, header->length)) {
  379. printk(KERN_WARNING PREFIX "Invalid XSDT checksum\n");
  380. return -ENODEV;
  381. }
  382. sdt_count =
  383. (header->length - sizeof(struct acpi_table_header)) >> 3;
  384. if (sdt_count > ACPI_MAX_TABLES) {
  385. printk(KERN_WARNING PREFIX
  386. "Truncated %lu XSDT entries\n",
  387. (sdt_count - ACPI_MAX_TABLES));
  388. sdt_count = ACPI_MAX_TABLES;
  389. }
  390. for (i = 0; i < sdt_count; i++)
  391. sdt_entry[i].pa = (unsigned long)mapped_xsdt->table_offset_entry[i];
  392. }
  393. /* Then check RSDT */
  394. else if (rsdp->rsdt_physical_address) {
  395. struct acpi_table_rsdt *mapped_rsdt = NULL;
  396. sdt_pa = rsdp->rsdt_physical_address;
  397. /* map in just the header */
  398. header = (struct acpi_table_header *)
  399. __acpi_map_table(sdt_pa, sizeof(struct acpi_table_header));
  400. if (!header) {
  401. printk(KERN_WARNING PREFIX
  402. "Unable to map RSDT header\n");
  403. return -ENODEV;
  404. }
  405. /* remap in the entire table before processing */
  406. mapped_rsdt = (struct acpi_table_rsdt *)
  407. __acpi_map_table(sdt_pa, header->length);
  408. if (!mapped_rsdt) {
  409. printk(KERN_WARNING PREFIX "Unable to map RSDT\n");
  410. return -ENODEV;
  411. }
  412. header = &mapped_rsdt->header;
  413. if (strncmp(header->signature, "RSDT", 4)) {
  414. printk(KERN_WARNING PREFIX
  415. "RSDT signature incorrect\n");
  416. return -ENODEV;
  417. }
  418. if (acpi_table_compute_checksum(header, header->length)) {
  419. printk(KERN_WARNING PREFIX "Invalid RSDT checksum\n");
  420. return -ENODEV;
  421. }
  422. sdt_count =
  423. (header->length - sizeof(struct acpi_table_header)) >> 2;
  424. if (sdt_count > ACPI_MAX_TABLES) {
  425. printk(KERN_WARNING PREFIX
  426. "Truncated %lu RSDT entries\n",
  427. (sdt_count - ACPI_MAX_TABLES));
  428. sdt_count = ACPI_MAX_TABLES;
  429. }
  430. for (i = 0; i < sdt_count; i++)
  431. sdt_entry[i].pa = (unsigned long)mapped_rsdt->table_offset_entry[i];
  432. }
  433. else {
  434. printk(KERN_WARNING PREFIX
  435. "No System Description Table (RSDT/XSDT) specified in RSDP\n");
  436. return -ENODEV;
  437. }
  438. acpi_table_print(header, sdt_pa);
  439. for (i = 0; i < sdt_count; i++) {
  440. /* map in just the header */
  441. header = (struct acpi_table_header *)
  442. __acpi_map_table(sdt_entry[i].pa,
  443. sizeof(struct acpi_table_header));
  444. if (!header)
  445. continue;
  446. /* remap in the entire table before processing */
  447. header = (struct acpi_table_header *)
  448. __acpi_map_table(sdt_entry[i].pa, header->length);
  449. if (!header)
  450. continue;
  451. acpi_table_print(header, sdt_entry[i].pa);
  452. if (acpi_table_compute_checksum(header, header->length)) {
  453. printk(KERN_WARNING " >>> ERROR: Invalid checksum\n");
  454. continue;
  455. }
  456. sdt_entry[i].size = header->length;
  457. for (id = 0; id < ACPI_TABLE_COUNT; id++) {
  458. if (!strncmp((char *)&header->signature,
  459. acpi_table_signatures[id],
  460. sizeof(header->signature))) {
  461. sdt_entry[i].id = id;
  462. }
  463. }
  464. }
  465. /*
  466. * The DSDT is *not* in the RSDT (why not? no idea.) but we want
  467. * to print its info, because this is what people usually blacklist
  468. * against. Unfortunately, we don't know the phys_addr, so just
  469. * print 0. Maybe no one will notice.
  470. */
  471. if (!acpi_get_table_header_early(ACPI_DSDT, &header))
  472. acpi_table_print(header, 0);
  473. return 0;
  474. }
  475. /*
  476. * acpi_table_init()
  477. *
  478. * find RSDP, find and checksum SDT/XSDT.
  479. * checksum all tables, print SDT/XSDT
  480. *
  481. * result: sdt_entry[] is initialized
  482. */
  483. int __init acpi_table_init(void)
  484. {
  485. struct acpi_table_rsdp *rsdp = NULL;
  486. unsigned long rsdp_phys = 0;
  487. int result = 0;
  488. /* Locate and map the Root System Description Table (RSDP) */
  489. rsdp_phys = acpi_find_rsdp();
  490. if (!rsdp_phys) {
  491. printk(KERN_ERR PREFIX "Unable to locate RSDP\n");
  492. return -ENODEV;
  493. }
  494. rsdp = (struct acpi_table_rsdp *)__acpi_map_table(rsdp_phys,
  495. sizeof(struct acpi_table_rsdp));
  496. if (!rsdp) {
  497. printk(KERN_WARNING PREFIX "Unable to map RSDP\n");
  498. return -ENODEV;
  499. }
  500. printk(KERN_DEBUG PREFIX
  501. "RSDP (v%3.3d %6.6s ) @ 0x%p\n",
  502. rsdp->revision, rsdp->oem_id, (void *)rsdp_phys);
  503. if (rsdp->revision < 2)
  504. result =
  505. acpi_table_compute_checksum(rsdp, ACPI_RSDP_REV0_SIZE);
  506. else
  507. result =
  508. acpi_table_compute_checksum(rsdp, rsdp->length);
  509. if (result) {
  510. printk(KERN_WARNING " >>> ERROR: Invalid checksum\n");
  511. return -ENODEV;
  512. }
  513. /* Locate and map the System Description table (RSDT/XSDT) */
  514. if (acpi_table_get_sdt(rsdp))
  515. return -ENODEV;
  516. acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
  517. return 0;
  518. }