tables.c 21 KB

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