tables.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  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. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. *
  20. */
  21. /* Uncomment next line to get verbose printout */
  22. /* #define DEBUG */
  23. #define pr_fmt(fmt) "ACPI: " fmt
  24. #include <linux/init.h>
  25. #include <linux/kernel.h>
  26. #include <linux/smp.h>
  27. #include <linux/string.h>
  28. #include <linux/types.h>
  29. #include <linux/irq.h>
  30. #include <linux/errno.h>
  31. #include <linux/acpi.h>
  32. #include <linux/memblock.h>
  33. #include <linux/earlycpio.h>
  34. #include <linux/initrd.h>
  35. #include "internal.h"
  36. #ifdef CONFIG_ACPI_CUSTOM_DSDT
  37. #include CONFIG_ACPI_CUSTOM_DSDT_FILE
  38. #endif
  39. #define ACPI_MAX_TABLES 128
  40. static char *mps_inti_flags_polarity[] = { "dfl", "high", "res", "low" };
  41. static char *mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" };
  42. static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES] __initdata;
  43. static int acpi_apic_instance __initdata;
  44. /*
  45. * Disable table checksum verification for the early stage due to the size
  46. * limitation of the current x86 early mapping implementation.
  47. */
  48. static bool acpi_verify_table_checksum __initdata = false;
  49. void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
  50. {
  51. if (!header)
  52. return;
  53. switch (header->type) {
  54. case ACPI_MADT_TYPE_LOCAL_APIC:
  55. {
  56. struct acpi_madt_local_apic *p =
  57. (struct acpi_madt_local_apic *)header;
  58. pr_debug("LAPIC (acpi_id[0x%02x] lapic_id[0x%02x] %s)\n",
  59. p->processor_id, p->id,
  60. (p->lapic_flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
  61. }
  62. break;
  63. case ACPI_MADT_TYPE_LOCAL_X2APIC:
  64. {
  65. struct acpi_madt_local_x2apic *p =
  66. (struct acpi_madt_local_x2apic *)header;
  67. pr_debug("X2APIC (apic_id[0x%02x] uid[0x%02x] %s)\n",
  68. p->local_apic_id, p->uid,
  69. (p->lapic_flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
  70. }
  71. break;
  72. case ACPI_MADT_TYPE_IO_APIC:
  73. {
  74. struct acpi_madt_io_apic *p =
  75. (struct acpi_madt_io_apic *)header;
  76. pr_debug("IOAPIC (id[0x%02x] address[0x%08x] gsi_base[%d])\n",
  77. p->id, p->address, p->global_irq_base);
  78. }
  79. break;
  80. case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE:
  81. {
  82. struct acpi_madt_interrupt_override *p =
  83. (struct acpi_madt_interrupt_override *)header;
  84. pr_info("INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s %s)\n",
  85. p->bus, p->source_irq, p->global_irq,
  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. if (p->inti_flags &
  89. ~(ACPI_MADT_POLARITY_MASK | ACPI_MADT_TRIGGER_MASK))
  90. pr_info("INT_SRC_OVR unexpected reserved flags: 0x%x\n",
  91. p->inti_flags &
  92. ~(ACPI_MADT_POLARITY_MASK | ACPI_MADT_TRIGGER_MASK));
  93. }
  94. break;
  95. case ACPI_MADT_TYPE_NMI_SOURCE:
  96. {
  97. struct acpi_madt_nmi_source *p =
  98. (struct acpi_madt_nmi_source *)header;
  99. pr_info("NMI_SRC (%s %s global_irq %d)\n",
  100. mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
  101. mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
  102. p->global_irq);
  103. }
  104. break;
  105. case ACPI_MADT_TYPE_LOCAL_APIC_NMI:
  106. {
  107. struct acpi_madt_local_apic_nmi *p =
  108. (struct acpi_madt_local_apic_nmi *)header;
  109. pr_info("LAPIC_NMI (acpi_id[0x%02x] %s %s lint[0x%x])\n",
  110. p->processor_id,
  111. mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK ],
  112. mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
  113. p->lint);
  114. }
  115. break;
  116. case ACPI_MADT_TYPE_LOCAL_X2APIC_NMI:
  117. {
  118. u16 polarity, trigger;
  119. struct acpi_madt_local_x2apic_nmi *p =
  120. (struct acpi_madt_local_x2apic_nmi *)header;
  121. polarity = p->inti_flags & ACPI_MADT_POLARITY_MASK;
  122. trigger = (p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
  123. pr_info("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. pr_info("LAPIC_ADDR_OVR (address[%p])\n",
  135. (void *)(unsigned long)p->address);
  136. }
  137. break;
  138. case ACPI_MADT_TYPE_IO_SAPIC:
  139. {
  140. struct acpi_madt_io_sapic *p =
  141. (struct acpi_madt_io_sapic *)header;
  142. pr_debug("IOSAPIC (id[0x%x] address[%p] gsi_base[%d])\n",
  143. p->id, (void *)(unsigned long)p->address,
  144. p->global_irq_base);
  145. }
  146. break;
  147. case ACPI_MADT_TYPE_LOCAL_SAPIC:
  148. {
  149. struct acpi_madt_local_sapic *p =
  150. (struct acpi_madt_local_sapic *)header;
  151. pr_debug("LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] lsapic_eid[0x%02x] %s)\n",
  152. p->processor_id, p->id, p->eid,
  153. (p->lapic_flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
  154. }
  155. break;
  156. case ACPI_MADT_TYPE_INTERRUPT_SOURCE:
  157. {
  158. struct acpi_madt_interrupt_source *p =
  159. (struct acpi_madt_interrupt_source *)header;
  160. pr_info("PLAT_INT_SRC (%s %s type[0x%x] id[0x%04x] eid[0x%x] iosapic_vector[0x%x] global_irq[0x%x]\n",
  161. mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
  162. mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
  163. p->type, p->id, p->eid, p->io_sapic_vector,
  164. p->global_irq);
  165. }
  166. break;
  167. case ACPI_MADT_TYPE_GENERIC_INTERRUPT:
  168. {
  169. struct acpi_madt_generic_interrupt *p =
  170. (struct acpi_madt_generic_interrupt *)header;
  171. pr_debug("GICC (acpi_id[0x%04x] address[%llx] MPIDR[0x%llx] %s)\n",
  172. p->uid, p->base_address,
  173. p->arm_mpidr,
  174. (p->flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
  175. }
  176. break;
  177. case ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR:
  178. {
  179. struct acpi_madt_generic_distributor *p =
  180. (struct acpi_madt_generic_distributor *)header;
  181. pr_debug("GIC Distributor (gic_id[0x%04x] address[%llx] gsi_base[%d])\n",
  182. p->gic_id, p->base_address,
  183. p->global_irq_base);
  184. }
  185. break;
  186. default:
  187. pr_warn("Found unsupported MADT entry (type = 0x%x)\n",
  188. header->type);
  189. break;
  190. }
  191. }
  192. /**
  193. * acpi_parse_entries_array - for each proc_num find a suitable subtable
  194. *
  195. * @id: table id (for debugging purposes)
  196. * @table_size: size of the root table
  197. * @table_header: where does the table start?
  198. * @proc: array of acpi_subtable_proc struct containing entry id
  199. * and associated handler with it
  200. * @proc_num: how big proc is?
  201. * @max_entries: how many entries can we process?
  202. *
  203. * For each proc_num find a subtable with proc->id and run proc->handler
  204. * on it. Assumption is that there's only single handler for particular
  205. * entry id.
  206. *
  207. * The table_size is not the size of the complete ACPI table (the length
  208. * field in the header struct), but only the size of the root table; i.e.,
  209. * the offset from the very first byte of the complete ACPI table, to the
  210. * first byte of the very first subtable.
  211. *
  212. * On success returns sum of all matching entries for all proc handlers.
  213. * Otherwise, -ENODEV or -EINVAL is returned.
  214. */
  215. static int __init
  216. acpi_parse_entries_array(char *id, unsigned long table_size,
  217. struct acpi_table_header *table_header,
  218. struct acpi_subtable_proc *proc, int proc_num,
  219. unsigned int max_entries)
  220. {
  221. struct acpi_subtable_header *entry;
  222. unsigned long table_end;
  223. int count = 0;
  224. int errs = 0;
  225. int i;
  226. if (acpi_disabled)
  227. return -ENODEV;
  228. if (!id)
  229. return -EINVAL;
  230. if (!table_size)
  231. return -EINVAL;
  232. if (!table_header) {
  233. pr_warn("%4.4s not present\n", id);
  234. return -ENODEV;
  235. }
  236. table_end = (unsigned long)table_header + table_header->length;
  237. /* Parse all entries looking for a match. */
  238. entry = (struct acpi_subtable_header *)
  239. ((unsigned long)table_header + table_size);
  240. while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
  241. table_end) {
  242. if (max_entries && count >= max_entries)
  243. break;
  244. for (i = 0; i < proc_num; i++) {
  245. if (entry->type != proc[i].id)
  246. continue;
  247. if (!proc[i].handler ||
  248. (!errs && proc[i].handler(entry, table_end))) {
  249. errs++;
  250. continue;
  251. }
  252. proc[i].count++;
  253. break;
  254. }
  255. if (i != proc_num)
  256. count++;
  257. /*
  258. * If entry->length is 0, break from this loop to avoid
  259. * infinite loop.
  260. */
  261. if (entry->length == 0) {
  262. pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, proc->id);
  263. return -EINVAL;
  264. }
  265. entry = (struct acpi_subtable_header *)
  266. ((unsigned long)entry + entry->length);
  267. }
  268. if (max_entries && count > max_entries) {
  269. pr_warn("[%4.4s:0x%02x] found the maximum %i entries\n",
  270. id, proc->id, count);
  271. }
  272. return errs ? -EINVAL : count;
  273. }
  274. int __init
  275. acpi_table_parse_entries_array(char *id,
  276. unsigned long table_size,
  277. struct acpi_subtable_proc *proc, int proc_num,
  278. unsigned int max_entries)
  279. {
  280. struct acpi_table_header *table_header = NULL;
  281. int count;
  282. u32 instance = 0;
  283. if (acpi_disabled)
  284. return -ENODEV;
  285. if (!id)
  286. return -EINVAL;
  287. if (!strncmp(id, ACPI_SIG_MADT, 4))
  288. instance = acpi_apic_instance;
  289. acpi_get_table(id, instance, &table_header);
  290. if (!table_header) {
  291. pr_warn("%4.4s not present\n", id);
  292. return -ENODEV;
  293. }
  294. count = acpi_parse_entries_array(id, table_size, table_header,
  295. proc, proc_num, max_entries);
  296. acpi_put_table(table_header);
  297. return count;
  298. }
  299. int __init
  300. acpi_table_parse_entries(char *id,
  301. unsigned long table_size,
  302. int entry_id,
  303. acpi_tbl_entry_handler handler,
  304. unsigned int max_entries)
  305. {
  306. struct acpi_subtable_proc proc = {
  307. .id = entry_id,
  308. .handler = handler,
  309. };
  310. return acpi_table_parse_entries_array(id, table_size, &proc, 1,
  311. max_entries);
  312. }
  313. int __init
  314. acpi_table_parse_madt(enum acpi_madt_type id,
  315. acpi_tbl_entry_handler handler, unsigned int max_entries)
  316. {
  317. return acpi_table_parse_entries(ACPI_SIG_MADT,
  318. sizeof(struct acpi_table_madt), id,
  319. handler, max_entries);
  320. }
  321. /**
  322. * acpi_table_parse - find table with @id, run @handler on it
  323. * @id: table id to find
  324. * @handler: handler to run
  325. *
  326. * Scan the ACPI System Descriptor Table (STD) for a table matching @id,
  327. * run @handler on it.
  328. *
  329. * Return 0 if table found, -errno if not.
  330. */
  331. int __init acpi_table_parse(char *id, acpi_tbl_table_handler handler)
  332. {
  333. struct acpi_table_header *table = NULL;
  334. if (acpi_disabled)
  335. return -ENODEV;
  336. if (!id || !handler)
  337. return -EINVAL;
  338. if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
  339. acpi_get_table(id, acpi_apic_instance, &table);
  340. else
  341. acpi_get_table(id, 0, &table);
  342. if (table) {
  343. handler(table);
  344. acpi_put_table(table);
  345. return 0;
  346. } else
  347. return -ENODEV;
  348. }
  349. /*
  350. * The BIOS is supposed to supply a single APIC/MADT,
  351. * but some report two. Provide a knob to use either.
  352. * (don't you wish instance 0 and 1 were not the same?)
  353. */
  354. static void __init check_multiple_madt(void)
  355. {
  356. struct acpi_table_header *table = NULL;
  357. acpi_get_table(ACPI_SIG_MADT, 2, &table);
  358. if (table) {
  359. pr_warn("BIOS bug: multiple APIC/MADT found, using %d\n",
  360. acpi_apic_instance);
  361. pr_warn("If \"acpi_apic_instance=%d\" works better, "
  362. "notify linux-acpi@vger.kernel.org\n",
  363. acpi_apic_instance ? 0 : 2);
  364. acpi_put_table(table);
  365. } else
  366. acpi_apic_instance = 0;
  367. return;
  368. }
  369. static void acpi_table_taint(struct acpi_table_header *table)
  370. {
  371. pr_warn("Override [%4.4s-%8.8s], this is unsafe: tainting kernel\n",
  372. table->signature, table->oem_table_id);
  373. add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE);
  374. }
  375. #ifdef CONFIG_ACPI_TABLE_UPGRADE
  376. static u64 acpi_tables_addr;
  377. static int all_tables_size;
  378. /* Copied from acpica/tbutils.c:acpi_tb_checksum() */
  379. static u8 __init acpi_table_checksum(u8 *buffer, u32 length)
  380. {
  381. u8 sum = 0;
  382. u8 *end = buffer + length;
  383. while (buffer < end)
  384. sum = (u8) (sum + *(buffer++));
  385. return sum;
  386. }
  387. /* All but ACPI_SIG_RSDP and ACPI_SIG_FACS: */
  388. static const char * const table_sigs[] = {
  389. ACPI_SIG_BERT, ACPI_SIG_CPEP, ACPI_SIG_ECDT, ACPI_SIG_EINJ,
  390. ACPI_SIG_ERST, ACPI_SIG_HEST, ACPI_SIG_MADT, ACPI_SIG_MSCT,
  391. ACPI_SIG_SBST, ACPI_SIG_SLIT, ACPI_SIG_SRAT, ACPI_SIG_ASF,
  392. ACPI_SIG_BOOT, ACPI_SIG_DBGP, ACPI_SIG_DMAR, ACPI_SIG_HPET,
  393. ACPI_SIG_IBFT, ACPI_SIG_IVRS, ACPI_SIG_MCFG, ACPI_SIG_MCHI,
  394. ACPI_SIG_SLIC, ACPI_SIG_SPCR, ACPI_SIG_SPMI, ACPI_SIG_TCPA,
  395. ACPI_SIG_UEFI, ACPI_SIG_WAET, ACPI_SIG_WDAT, ACPI_SIG_WDDT,
  396. ACPI_SIG_WDRT, ACPI_SIG_DSDT, ACPI_SIG_FADT, ACPI_SIG_PSDT,
  397. ACPI_SIG_RSDT, ACPI_SIG_XSDT, ACPI_SIG_SSDT, ACPI_SIG_IORT,
  398. ACPI_SIG_NFIT, ACPI_SIG_HMAT, ACPI_SIG_PPTT, NULL };
  399. #define ACPI_HEADER_SIZE sizeof(struct acpi_table_header)
  400. #define NR_ACPI_INITRD_TABLES 64
  401. static struct cpio_data __initdata acpi_initrd_files[NR_ACPI_INITRD_TABLES];
  402. static DECLARE_BITMAP(acpi_initrd_installed, NR_ACPI_INITRD_TABLES);
  403. #define MAP_CHUNK_SIZE (NR_FIX_BTMAPS << PAGE_SHIFT)
  404. void __init acpi_table_upgrade(void)
  405. {
  406. void *data = (void *)initrd_start;
  407. size_t size = initrd_end - initrd_start;
  408. int sig, no, table_nr = 0, total_offset = 0;
  409. long offset = 0;
  410. struct acpi_table_header *table;
  411. char cpio_path[32] = "kernel/firmware/acpi/";
  412. struct cpio_data file;
  413. if (data == NULL || size == 0)
  414. return;
  415. for (no = 0; no < NR_ACPI_INITRD_TABLES; no++) {
  416. file = find_cpio_data(cpio_path, data, size, &offset);
  417. if (!file.data)
  418. break;
  419. data += offset;
  420. size -= offset;
  421. if (file.size < sizeof(struct acpi_table_header)) {
  422. pr_err("ACPI OVERRIDE: Table smaller than ACPI header [%s%s]\n",
  423. cpio_path, file.name);
  424. continue;
  425. }
  426. table = file.data;
  427. for (sig = 0; table_sigs[sig]; sig++)
  428. if (!memcmp(table->signature, table_sigs[sig], 4))
  429. break;
  430. if (!table_sigs[sig]) {
  431. pr_err("ACPI OVERRIDE: Unknown signature [%s%s]\n",
  432. cpio_path, file.name);
  433. continue;
  434. }
  435. if (file.size != table->length) {
  436. pr_err("ACPI OVERRIDE: File length does not match table length [%s%s]\n",
  437. cpio_path, file.name);
  438. continue;
  439. }
  440. if (acpi_table_checksum(file.data, table->length)) {
  441. pr_err("ACPI OVERRIDE: Bad table checksum [%s%s]\n",
  442. cpio_path, file.name);
  443. continue;
  444. }
  445. pr_info("%4.4s ACPI table found in initrd [%s%s][0x%x]\n",
  446. table->signature, cpio_path, file.name, table->length);
  447. all_tables_size += table->length;
  448. acpi_initrd_files[table_nr].data = file.data;
  449. acpi_initrd_files[table_nr].size = file.size;
  450. table_nr++;
  451. }
  452. if (table_nr == 0)
  453. return;
  454. acpi_tables_addr =
  455. memblock_find_in_range(0, ACPI_TABLE_UPGRADE_MAX_PHYS,
  456. all_tables_size, PAGE_SIZE);
  457. if (!acpi_tables_addr) {
  458. WARN_ON(1);
  459. return;
  460. }
  461. /*
  462. * Only calling e820_add_reserve does not work and the
  463. * tables are invalid (memory got used) later.
  464. * memblock_reserve works as expected and the tables won't get modified.
  465. * But it's not enough on X86 because ioremap will
  466. * complain later (used by acpi_os_map_memory) that the pages
  467. * that should get mapped are not marked "reserved".
  468. * Both memblock_reserve and e820__range_add (via arch_reserve_mem_area)
  469. * works fine.
  470. */
  471. memblock_reserve(acpi_tables_addr, all_tables_size);
  472. arch_reserve_mem_area(acpi_tables_addr, all_tables_size);
  473. /*
  474. * early_ioremap only can remap 256k one time. If we map all
  475. * tables one time, we will hit the limit. Need to map chunks
  476. * one by one during copying the same as that in relocate_initrd().
  477. */
  478. for (no = 0; no < table_nr; no++) {
  479. unsigned char *src_p = acpi_initrd_files[no].data;
  480. phys_addr_t size = acpi_initrd_files[no].size;
  481. phys_addr_t dest_addr = acpi_tables_addr + total_offset;
  482. phys_addr_t slop, clen;
  483. char *dest_p;
  484. total_offset += size;
  485. while (size) {
  486. slop = dest_addr & ~PAGE_MASK;
  487. clen = size;
  488. if (clen > MAP_CHUNK_SIZE - slop)
  489. clen = MAP_CHUNK_SIZE - slop;
  490. dest_p = early_memremap(dest_addr & PAGE_MASK,
  491. clen + slop);
  492. memcpy(dest_p + slop, src_p, clen);
  493. early_memunmap(dest_p, clen + slop);
  494. src_p += clen;
  495. dest_addr += clen;
  496. size -= clen;
  497. }
  498. }
  499. }
  500. static acpi_status
  501. acpi_table_initrd_override(struct acpi_table_header *existing_table,
  502. acpi_physical_address *address, u32 *length)
  503. {
  504. int table_offset = 0;
  505. int table_index = 0;
  506. struct acpi_table_header *table;
  507. u32 table_length;
  508. *length = 0;
  509. *address = 0;
  510. if (!acpi_tables_addr)
  511. return AE_OK;
  512. while (table_offset + ACPI_HEADER_SIZE <= all_tables_size) {
  513. table = acpi_os_map_memory(acpi_tables_addr + table_offset,
  514. ACPI_HEADER_SIZE);
  515. if (table_offset + table->length > all_tables_size) {
  516. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  517. WARN_ON(1);
  518. return AE_OK;
  519. }
  520. table_length = table->length;
  521. /* Only override tables matched */
  522. if (memcmp(existing_table->signature, table->signature, 4) ||
  523. memcmp(table->oem_id, existing_table->oem_id,
  524. ACPI_OEM_ID_SIZE) ||
  525. memcmp(table->oem_table_id, existing_table->oem_table_id,
  526. ACPI_OEM_TABLE_ID_SIZE)) {
  527. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  528. goto next_table;
  529. }
  530. /*
  531. * Mark the table to avoid being used in
  532. * acpi_table_initrd_scan() and check the revision.
  533. */
  534. if (test_and_set_bit(table_index, acpi_initrd_installed) ||
  535. existing_table->oem_revision >= table->oem_revision) {
  536. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  537. goto next_table;
  538. }
  539. *length = table_length;
  540. *address = acpi_tables_addr + table_offset;
  541. pr_info("Table Upgrade: override [%4.4s-%6.6s-%8.8s]\n",
  542. table->signature, table->oem_id,
  543. table->oem_table_id);
  544. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  545. break;
  546. next_table:
  547. table_offset += table_length;
  548. table_index++;
  549. }
  550. return AE_OK;
  551. }
  552. static void __init acpi_table_initrd_scan(void)
  553. {
  554. int table_offset = 0;
  555. int table_index = 0;
  556. u32 table_length;
  557. struct acpi_table_header *table;
  558. if (!acpi_tables_addr)
  559. return;
  560. while (table_offset + ACPI_HEADER_SIZE <= all_tables_size) {
  561. table = acpi_os_map_memory(acpi_tables_addr + table_offset,
  562. ACPI_HEADER_SIZE);
  563. if (table_offset + table->length > all_tables_size) {
  564. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  565. WARN_ON(1);
  566. return;
  567. }
  568. table_length = table->length;
  569. /* Skip RSDT/XSDT which should only be used for override */
  570. if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_RSDT) ||
  571. ACPI_COMPARE_NAME(table->signature, ACPI_SIG_XSDT)) {
  572. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  573. goto next_table;
  574. }
  575. /*
  576. * Mark the table to avoid being used in
  577. * acpi_table_initrd_override(). Though this is not possible
  578. * because override is disabled in acpi_install_table().
  579. */
  580. if (test_and_set_bit(table_index, acpi_initrd_installed)) {
  581. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  582. goto next_table;
  583. }
  584. pr_info("Table Upgrade: install [%4.4s-%6.6s-%8.8s]\n",
  585. table->signature, table->oem_id,
  586. table->oem_table_id);
  587. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  588. acpi_install_table(acpi_tables_addr + table_offset, TRUE);
  589. next_table:
  590. table_offset += table_length;
  591. table_index++;
  592. }
  593. }
  594. #else
  595. static acpi_status
  596. acpi_table_initrd_override(struct acpi_table_header *existing_table,
  597. acpi_physical_address *address,
  598. u32 *table_length)
  599. {
  600. *table_length = 0;
  601. *address = 0;
  602. return AE_OK;
  603. }
  604. static void __init acpi_table_initrd_scan(void)
  605. {
  606. }
  607. #endif /* CONFIG_ACPI_TABLE_UPGRADE */
  608. acpi_status
  609. acpi_os_physical_table_override(struct acpi_table_header *existing_table,
  610. acpi_physical_address *address,
  611. u32 *table_length)
  612. {
  613. return acpi_table_initrd_override(existing_table, address,
  614. table_length);
  615. }
  616. acpi_status
  617. acpi_os_table_override(struct acpi_table_header *existing_table,
  618. struct acpi_table_header **new_table)
  619. {
  620. if (!existing_table || !new_table)
  621. return AE_BAD_PARAMETER;
  622. *new_table = NULL;
  623. #ifdef CONFIG_ACPI_CUSTOM_DSDT
  624. if (strncmp(existing_table->signature, "DSDT", 4) == 0)
  625. *new_table = (struct acpi_table_header *)AmlCode;
  626. #endif
  627. if (*new_table != NULL)
  628. acpi_table_taint(existing_table);
  629. return AE_OK;
  630. }
  631. /*
  632. * acpi_table_init()
  633. *
  634. * find RSDP, find and checksum SDT/XSDT.
  635. * checksum all tables, print SDT/XSDT
  636. *
  637. * result: sdt_entry[] is initialized
  638. */
  639. int __init acpi_table_init(void)
  640. {
  641. acpi_status status;
  642. if (acpi_verify_table_checksum) {
  643. pr_info("Early table checksum verification enabled\n");
  644. acpi_gbl_enable_table_validation = TRUE;
  645. } else {
  646. pr_info("Early table checksum verification disabled\n");
  647. acpi_gbl_enable_table_validation = FALSE;
  648. }
  649. status = acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
  650. if (ACPI_FAILURE(status))
  651. return -EINVAL;
  652. acpi_table_initrd_scan();
  653. check_multiple_madt();
  654. return 0;
  655. }
  656. static int __init acpi_parse_apic_instance(char *str)
  657. {
  658. if (!str)
  659. return -EINVAL;
  660. if (kstrtoint(str, 0, &acpi_apic_instance))
  661. return -EINVAL;
  662. pr_notice("Shall use APIC/MADT table %d\n", acpi_apic_instance);
  663. return 0;
  664. }
  665. early_param("acpi_apic_instance", acpi_parse_apic_instance);
  666. static int __init acpi_force_table_verification_setup(char *s)
  667. {
  668. acpi_verify_table_checksum = true;
  669. return 0;
  670. }
  671. early_param("acpi_force_table_verification", acpi_force_table_verification_setup);
  672. static int __init acpi_force_32bit_fadt_addr(char *s)
  673. {
  674. pr_info("Forcing 32 Bit FADT addresses\n");
  675. acpi_gbl_use32_bit_fadt_addresses = TRUE;
  676. return 0;
  677. }
  678. early_param("acpi_force_32bit_fadt_addr", acpi_force_32bit_fadt_addr);