tables.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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. void acpi_table_print(struct acpi_table_header *header, unsigned long phys_addr)
  70. {
  71. char *name = NULL;
  72. if (!header)
  73. return;
  74. /* Some table signatures aren't good table names */
  75. if (!strncmp((char *)&header->signature,
  76. acpi_table_signatures[ACPI_APIC],
  77. sizeof(header->signature))) {
  78. name = "MADT";
  79. } else if (!strncmp((char *)&header->signature,
  80. acpi_table_signatures[ACPI_FADT],
  81. sizeof(header->signature))) {
  82. name = "FADT";
  83. } else
  84. name = header->signature;
  85. printk(KERN_DEBUG PREFIX
  86. "%.4s (v%3.3d %6.6s %8.8s 0x%08x %.4s 0x%08x) @ 0x%p\n", name,
  87. header->revision, header->oem_id, header->oem_table_id,
  88. header->oem_revision, header->asl_compiler_id,
  89. header->asl_compiler_revision, (void *)phys_addr);
  90. }
  91. void acpi_table_print_madt_entry(acpi_table_entry_header * header)
  92. {
  93. if (!header)
  94. return;
  95. switch (header->type) {
  96. case ACPI_MADT_LAPIC:
  97. {
  98. struct acpi_table_lapic *p =
  99. (struct acpi_table_lapic *)header;
  100. printk(KERN_INFO PREFIX
  101. "LAPIC (acpi_id[0x%02x] lapic_id[0x%02x] %s)\n",
  102. p->acpi_id, p->id,
  103. p->flags.enabled ? "enabled" : "disabled");
  104. }
  105. break;
  106. case ACPI_MADT_IOAPIC:
  107. {
  108. struct acpi_table_ioapic *p =
  109. (struct acpi_table_ioapic *)header;
  110. printk(KERN_INFO PREFIX
  111. "IOAPIC (id[0x%02x] address[0x%08x] gsi_base[%d])\n",
  112. p->id, p->address, p->global_irq_base);
  113. }
  114. break;
  115. case ACPI_MADT_INT_SRC_OVR:
  116. {
  117. struct acpi_table_int_src_ovr *p =
  118. (struct acpi_table_int_src_ovr *)header;
  119. printk(KERN_INFO PREFIX
  120. "INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s %s)\n",
  121. p->bus, p->bus_irq, p->global_irq,
  122. mps_inti_flags_polarity[p->flags.polarity],
  123. mps_inti_flags_trigger[p->flags.trigger]);
  124. if (p->flags.reserved)
  125. printk(KERN_INFO PREFIX
  126. "INT_SRC_OVR unexpected reserved flags: 0x%x\n",
  127. p->flags.reserved);
  128. }
  129. break;
  130. case ACPI_MADT_NMI_SRC:
  131. {
  132. struct acpi_table_nmi_src *p =
  133. (struct acpi_table_nmi_src *)header;
  134. printk(KERN_INFO PREFIX
  135. "NMI_SRC (%s %s global_irq %d)\n",
  136. mps_inti_flags_polarity[p->flags.polarity],
  137. mps_inti_flags_trigger[p->flags.trigger],
  138. p->global_irq);
  139. }
  140. break;
  141. case ACPI_MADT_LAPIC_NMI:
  142. {
  143. struct acpi_table_lapic_nmi *p =
  144. (struct acpi_table_lapic_nmi *)header;
  145. printk(KERN_INFO PREFIX
  146. "LAPIC_NMI (acpi_id[0x%02x] %s %s lint[0x%x])\n",
  147. p->acpi_id,
  148. mps_inti_flags_polarity[p->flags.polarity],
  149. mps_inti_flags_trigger[p->flags.trigger],
  150. p->lint);
  151. }
  152. break;
  153. case ACPI_MADT_LAPIC_ADDR_OVR:
  154. {
  155. struct acpi_table_lapic_addr_ovr *p =
  156. (struct acpi_table_lapic_addr_ovr *)header;
  157. printk(KERN_INFO PREFIX
  158. "LAPIC_ADDR_OVR (address[%p])\n",
  159. (void *)(unsigned long)p->address);
  160. }
  161. break;
  162. case ACPI_MADT_IOSAPIC:
  163. {
  164. struct acpi_table_iosapic *p =
  165. (struct acpi_table_iosapic *)header;
  166. printk(KERN_INFO PREFIX
  167. "IOSAPIC (id[0x%x] address[%p] gsi_base[%d])\n",
  168. p->id, (void *)(unsigned long)p->address,
  169. p->global_irq_base);
  170. }
  171. break;
  172. case ACPI_MADT_LSAPIC:
  173. {
  174. struct acpi_table_lsapic *p =
  175. (struct acpi_table_lsapic *)header;
  176. printk(KERN_INFO PREFIX
  177. "LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] lsapic_eid[0x%02x] %s)\n",
  178. p->acpi_id, p->id, p->eid,
  179. p->flags.enabled ? "enabled" : "disabled");
  180. }
  181. break;
  182. case ACPI_MADT_PLAT_INT_SRC:
  183. {
  184. struct acpi_table_plat_int_src *p =
  185. (struct acpi_table_plat_int_src *)header;
  186. printk(KERN_INFO PREFIX
  187. "PLAT_INT_SRC (%s %s type[0x%x] id[0x%04x] eid[0x%x] iosapic_vector[0x%x] global_irq[0x%x]\n",
  188. mps_inti_flags_polarity[p->flags.polarity],
  189. mps_inti_flags_trigger[p->flags.trigger],
  190. p->type, p->id, p->eid, p->iosapic_vector,
  191. p->global_irq);
  192. }
  193. break;
  194. default:
  195. printk(KERN_WARNING PREFIX
  196. "Found unsupported MADT entry (type = 0x%x)\n",
  197. header->type);
  198. break;
  199. }
  200. }
  201. static int
  202. acpi_table_compute_checksum(void *table_pointer, unsigned long length)
  203. {
  204. u8 *p = (u8 *) table_pointer;
  205. unsigned long remains = length;
  206. unsigned long sum = 0;
  207. if (!p || !length)
  208. return -EINVAL;
  209. while (remains--)
  210. sum += *p++;
  211. return (sum & 0xFF);
  212. }
  213. /*
  214. * acpi_get_table_header_early()
  215. * for acpi_blacklisted(), acpi_table_get_sdt()
  216. */
  217. int __init
  218. acpi_get_table_header_early(enum acpi_table_id id,
  219. struct acpi_table_header **header)
  220. {
  221. unsigned int i;
  222. enum acpi_table_id temp_id;
  223. /* DSDT is different from the rest */
  224. if (id == ACPI_DSDT)
  225. temp_id = ACPI_FADT;
  226. else
  227. temp_id = id;
  228. /* Locate the table. */
  229. for (i = 0; i < sdt_count; i++) {
  230. if (sdt_entry[i].id != temp_id)
  231. continue;
  232. *header = (void *)
  233. __acpi_map_table(sdt_entry[i].pa, sdt_entry[i].size);
  234. if (!*header) {
  235. printk(KERN_WARNING PREFIX "Unable to map %s\n",
  236. acpi_table_signatures[temp_id]);
  237. return -ENODEV;
  238. }
  239. break;
  240. }
  241. if (!*header) {
  242. printk(KERN_WARNING PREFIX "%s not present\n",
  243. acpi_table_signatures[id]);
  244. return -ENODEV;
  245. }
  246. /* Map the DSDT header via the pointer in the FADT */
  247. if (id == ACPI_DSDT) {
  248. struct fadt_descriptor *fadt =
  249. (struct fadt_descriptor *)*header;
  250. if (fadt->revision == 3 && fadt->Xdsdt) {
  251. *header = (void *)__acpi_map_table(fadt->Xdsdt,
  252. sizeof(struct
  253. acpi_table_header));
  254. } else if (fadt->V1_dsdt) {
  255. *header = (void *)__acpi_map_table(fadt->V1_dsdt,
  256. sizeof(struct
  257. acpi_table_header));
  258. } else
  259. *header = NULL;
  260. if (!*header) {
  261. printk(KERN_WARNING PREFIX "Unable to map DSDT\n");
  262. return -ENODEV;
  263. }
  264. }
  265. return 0;
  266. }
  267. int __init
  268. acpi_table_parse_madt_family(enum acpi_table_id id,
  269. unsigned long madt_size,
  270. int entry_id,
  271. acpi_madt_entry_handler handler,
  272. unsigned int max_entries)
  273. {
  274. void *madt = NULL;
  275. acpi_table_entry_header *entry;
  276. unsigned int count = 0;
  277. unsigned long madt_end;
  278. unsigned int i;
  279. if (!handler)
  280. return -EINVAL;
  281. /* Locate the MADT (if exists). There should only be one. */
  282. for (i = 0; i < sdt_count; i++) {
  283. if (sdt_entry[i].id != id)
  284. continue;
  285. madt = (void *)
  286. __acpi_map_table(sdt_entry[i].pa, sdt_entry[i].size);
  287. if (!madt) {
  288. printk(KERN_WARNING PREFIX "Unable to map %s\n",
  289. acpi_table_signatures[id]);
  290. return -ENODEV;
  291. }
  292. break;
  293. }
  294. if (!madt) {
  295. printk(KERN_WARNING PREFIX "%s not present\n",
  296. acpi_table_signatures[id]);
  297. return -ENODEV;
  298. }
  299. madt_end = (unsigned long)madt + sdt_entry[i].size;
  300. /* Parse all entries looking for a match. */
  301. entry = (acpi_table_entry_header *)
  302. ((unsigned long)madt + madt_size);
  303. while (((unsigned long)entry) + sizeof(acpi_table_entry_header) <
  304. madt_end) {
  305. if (entry->type == entry_id
  306. && (!max_entries || count++ < max_entries))
  307. if (handler(entry, madt_end))
  308. return -EINVAL;
  309. entry = (acpi_table_entry_header *)
  310. ((unsigned long)entry + entry->length);
  311. }
  312. if (max_entries && count > max_entries) {
  313. printk(KERN_WARNING PREFIX "[%s:0x%02x] ignored %i entries of "
  314. "%i found\n", acpi_table_signatures[id], entry_id,
  315. count - max_entries, count);
  316. }
  317. return count;
  318. }
  319. int __init
  320. acpi_table_parse_madt(enum acpi_madt_entry_id id,
  321. acpi_madt_entry_handler handler, unsigned int max_entries)
  322. {
  323. return acpi_table_parse_madt_family(ACPI_APIC,
  324. sizeof(struct acpi_table_madt), id,
  325. handler, max_entries);
  326. }
  327. int __init acpi_table_parse(enum acpi_table_id id, acpi_table_handler handler)
  328. {
  329. int count = 0;
  330. unsigned int i = 0;
  331. if (!handler)
  332. return -EINVAL;
  333. for (i = 0; i < sdt_count; i++) {
  334. if (sdt_entry[i].id != id)
  335. continue;
  336. count++;
  337. if (count == 1)
  338. handler(sdt_entry[i].pa, sdt_entry[i].size);
  339. else
  340. printk(KERN_WARNING PREFIX
  341. "%d duplicate %s table ignored.\n", count,
  342. acpi_table_signatures[id]);
  343. }
  344. return count;
  345. }
  346. static int __init acpi_table_get_sdt(struct acpi_table_rsdp *rsdp)
  347. {
  348. struct acpi_table_header *header = NULL;
  349. unsigned int i, id = 0;
  350. if (!rsdp)
  351. return -EINVAL;
  352. /* First check XSDT (but only on ACPI 2.0-compatible systems) */
  353. if ((rsdp->revision >= 2) &&
  354. (((struct acpi20_table_rsdp *)rsdp)->xsdt_address)) {
  355. struct acpi_table_xsdt *mapped_xsdt = NULL;
  356. sdt_pa = ((struct acpi20_table_rsdp *)rsdp)->xsdt_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->entry[i];
  392. }
  393. /* Then check RSDT */
  394. else if (rsdp->rsdt_address) {
  395. struct acpi_table_rsdt *mapped_rsdt = NULL;
  396. sdt_pa = rsdp->rsdt_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->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,
  506. sizeof(struct acpi_table_rsdp));
  507. else
  508. result =
  509. acpi_table_compute_checksum(rsdp,
  510. ((struct acpi20_table_rsdp *)
  511. rsdp)->length);
  512. if (result) {
  513. printk(KERN_WARNING " >>> ERROR: Invalid checksum\n");
  514. return -ENODEV;
  515. }
  516. /* Locate and map the System Description table (RSDT/XSDT) */
  517. if (acpi_table_get_sdt(rsdp))
  518. return -ENODEV;
  519. return 0;
  520. }