tables.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  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: size of the root table
  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. * The table_size is not the size of the complete ACPI table (the length
  209. * field in the header struct), but only the size of the root table; i.e.,
  210. * the offset from the very first byte of the complete ACPI table, to the
  211. * first byte of the very first subtable.
  212. *
  213. * On success returns sum of all matching entries for all proc handlers.
  214. * Otherwise, -ENODEV or -EINVAL is returned.
  215. */
  216. static int __init
  217. acpi_parse_entries_array(char *id, unsigned long table_size,
  218. struct acpi_table_header *table_header,
  219. struct acpi_subtable_proc *proc, int proc_num,
  220. unsigned int max_entries)
  221. {
  222. struct acpi_subtable_header *entry;
  223. unsigned long table_end;
  224. int count = 0;
  225. int errs = 0;
  226. int i;
  227. if (acpi_disabled)
  228. return -ENODEV;
  229. if (!id)
  230. return -EINVAL;
  231. if (!table_size)
  232. return -EINVAL;
  233. if (!table_header) {
  234. pr_warn("%4.4s not present\n", id);
  235. return -ENODEV;
  236. }
  237. table_end = (unsigned long)table_header + table_header->length;
  238. /* Parse all entries looking for a match. */
  239. entry = (struct acpi_subtable_header *)
  240. ((unsigned long)table_header + table_size);
  241. while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
  242. table_end) {
  243. if (max_entries && count >= max_entries)
  244. break;
  245. for (i = 0; i < proc_num; i++) {
  246. if (entry->type != proc[i].id)
  247. continue;
  248. if (!proc[i].handler ||
  249. (!errs && proc[i].handler(entry, table_end))) {
  250. errs++;
  251. continue;
  252. }
  253. proc[i].count++;
  254. break;
  255. }
  256. if (i != proc_num)
  257. count++;
  258. /*
  259. * If entry->length is 0, break from this loop to avoid
  260. * infinite loop.
  261. */
  262. if (entry->length == 0) {
  263. pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, proc->id);
  264. return -EINVAL;
  265. }
  266. entry = (struct acpi_subtable_header *)
  267. ((unsigned long)entry + entry->length);
  268. }
  269. if (max_entries && count > max_entries) {
  270. pr_warn("[%4.4s:0x%02x] found the maximum %i entries\n",
  271. id, proc->id, count);
  272. }
  273. return errs ? -EINVAL : count;
  274. }
  275. int __init
  276. acpi_table_parse_entries_array(char *id,
  277. unsigned long table_size,
  278. struct acpi_subtable_proc *proc, int proc_num,
  279. unsigned int max_entries)
  280. {
  281. struct acpi_table_header *table_header = NULL;
  282. int count;
  283. u32 instance = 0;
  284. if (acpi_disabled)
  285. return -ENODEV;
  286. if (!id)
  287. return -EINVAL;
  288. if (!strncmp(id, ACPI_SIG_MADT, 4))
  289. instance = acpi_apic_instance;
  290. acpi_get_table(id, instance, &table_header);
  291. if (!table_header) {
  292. pr_warn("%4.4s not present\n", id);
  293. return -ENODEV;
  294. }
  295. count = acpi_parse_entries_array(id, table_size, table_header,
  296. proc, proc_num, max_entries);
  297. acpi_put_table(table_header);
  298. return count;
  299. }
  300. int __init
  301. acpi_table_parse_entries(char *id,
  302. unsigned long table_size,
  303. int entry_id,
  304. acpi_tbl_entry_handler handler,
  305. unsigned int max_entries)
  306. {
  307. struct acpi_subtable_proc proc = {
  308. .id = entry_id,
  309. .handler = handler,
  310. };
  311. return acpi_table_parse_entries_array(id, table_size, &proc, 1,
  312. max_entries);
  313. }
  314. int __init
  315. acpi_table_parse_madt(enum acpi_madt_type id,
  316. acpi_tbl_entry_handler handler, unsigned int max_entries)
  317. {
  318. return acpi_table_parse_entries(ACPI_SIG_MADT,
  319. sizeof(struct acpi_table_madt), id,
  320. handler, max_entries);
  321. }
  322. /**
  323. * acpi_table_parse - find table with @id, run @handler on it
  324. * @id: table id to find
  325. * @handler: handler to run
  326. *
  327. * Scan the ACPI System Descriptor Table (STD) for a table matching @id,
  328. * run @handler on it.
  329. *
  330. * Return 0 if table found, -errno if not.
  331. */
  332. int __init acpi_table_parse(char *id, acpi_tbl_table_handler handler)
  333. {
  334. struct acpi_table_header *table = NULL;
  335. if (acpi_disabled)
  336. return -ENODEV;
  337. if (!id || !handler)
  338. return -EINVAL;
  339. if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
  340. acpi_get_table(id, acpi_apic_instance, &table);
  341. else
  342. acpi_get_table(id, 0, &table);
  343. if (table) {
  344. handler(table);
  345. acpi_put_table(table);
  346. return 0;
  347. } else
  348. return -ENODEV;
  349. }
  350. /*
  351. * The BIOS is supposed to supply a single APIC/MADT,
  352. * but some report two. Provide a knob to use either.
  353. * (don't you wish instance 0 and 1 were not the same?)
  354. */
  355. static void __init check_multiple_madt(void)
  356. {
  357. struct acpi_table_header *table = NULL;
  358. acpi_get_table(ACPI_SIG_MADT, 2, &table);
  359. if (table) {
  360. pr_warn("BIOS bug: multiple APIC/MADT found, using %d\n",
  361. acpi_apic_instance);
  362. pr_warn("If \"acpi_apic_instance=%d\" works better, "
  363. "notify linux-acpi@vger.kernel.org\n",
  364. acpi_apic_instance ? 0 : 2);
  365. acpi_put_table(table);
  366. } else
  367. acpi_apic_instance = 0;
  368. return;
  369. }
  370. static void acpi_table_taint(struct acpi_table_header *table)
  371. {
  372. pr_warn("Override [%4.4s-%8.8s], this is unsafe: tainting kernel\n",
  373. table->signature, table->oem_table_id);
  374. add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE);
  375. }
  376. #ifdef CONFIG_ACPI_TABLE_UPGRADE
  377. static u64 acpi_tables_addr;
  378. static int all_tables_size;
  379. /* Copied from acpica/tbutils.c:acpi_tb_checksum() */
  380. static u8 __init acpi_table_checksum(u8 *buffer, u32 length)
  381. {
  382. u8 sum = 0;
  383. u8 *end = buffer + length;
  384. while (buffer < end)
  385. sum = (u8) (sum + *(buffer++));
  386. return sum;
  387. }
  388. /* All but ACPI_SIG_RSDP and ACPI_SIG_FACS: */
  389. static const char * const table_sigs[] = {
  390. ACPI_SIG_BERT, ACPI_SIG_CPEP, ACPI_SIG_ECDT, ACPI_SIG_EINJ,
  391. ACPI_SIG_ERST, ACPI_SIG_HEST, ACPI_SIG_MADT, ACPI_SIG_MSCT,
  392. ACPI_SIG_SBST, ACPI_SIG_SLIT, ACPI_SIG_SRAT, ACPI_SIG_ASF,
  393. ACPI_SIG_BOOT, ACPI_SIG_DBGP, ACPI_SIG_DMAR, ACPI_SIG_HPET,
  394. ACPI_SIG_IBFT, ACPI_SIG_IVRS, ACPI_SIG_MCFG, ACPI_SIG_MCHI,
  395. ACPI_SIG_SLIC, ACPI_SIG_SPCR, ACPI_SIG_SPMI, ACPI_SIG_TCPA,
  396. ACPI_SIG_UEFI, ACPI_SIG_WAET, ACPI_SIG_WDAT, ACPI_SIG_WDDT,
  397. ACPI_SIG_WDRT, ACPI_SIG_DSDT, ACPI_SIG_FADT, ACPI_SIG_PSDT,
  398. ACPI_SIG_RSDT, ACPI_SIG_XSDT, ACPI_SIG_SSDT, ACPI_SIG_IORT,
  399. ACPI_SIG_NFIT, ACPI_SIG_HMAT, ACPI_SIG_PPTT, NULL };
  400. #define ACPI_HEADER_SIZE sizeof(struct acpi_table_header)
  401. #define NR_ACPI_INITRD_TABLES 64
  402. static struct cpio_data __initdata acpi_initrd_files[NR_ACPI_INITRD_TABLES];
  403. static DECLARE_BITMAP(acpi_initrd_installed, NR_ACPI_INITRD_TABLES);
  404. #define MAP_CHUNK_SIZE (NR_FIX_BTMAPS << PAGE_SHIFT)
  405. void __init acpi_table_upgrade(void)
  406. {
  407. void *data = (void *)initrd_start;
  408. size_t size = initrd_end - initrd_start;
  409. int sig, no, table_nr = 0, total_offset = 0;
  410. long offset = 0;
  411. struct acpi_table_header *table;
  412. char cpio_path[32] = "kernel/firmware/acpi/";
  413. struct cpio_data file;
  414. if (data == NULL || size == 0)
  415. return;
  416. for (no = 0; no < NR_ACPI_INITRD_TABLES; no++) {
  417. file = find_cpio_data(cpio_path, data, size, &offset);
  418. if (!file.data)
  419. break;
  420. data += offset;
  421. size -= offset;
  422. if (file.size < sizeof(struct acpi_table_header)) {
  423. pr_err("ACPI OVERRIDE: Table smaller than ACPI header [%s%s]\n",
  424. cpio_path, file.name);
  425. continue;
  426. }
  427. table = file.data;
  428. for (sig = 0; table_sigs[sig]; sig++)
  429. if (!memcmp(table->signature, table_sigs[sig], 4))
  430. break;
  431. if (!table_sigs[sig]) {
  432. pr_err("ACPI OVERRIDE: Unknown signature [%s%s]\n",
  433. cpio_path, file.name);
  434. continue;
  435. }
  436. if (file.size != table->length) {
  437. pr_err("ACPI OVERRIDE: File length does not match table length [%s%s]\n",
  438. cpio_path, file.name);
  439. continue;
  440. }
  441. if (acpi_table_checksum(file.data, table->length)) {
  442. pr_err("ACPI OVERRIDE: Bad table checksum [%s%s]\n",
  443. cpio_path, file.name);
  444. continue;
  445. }
  446. pr_info("%4.4s ACPI table found in initrd [%s%s][0x%x]\n",
  447. table->signature, cpio_path, file.name, table->length);
  448. all_tables_size += table->length;
  449. acpi_initrd_files[table_nr].data = file.data;
  450. acpi_initrd_files[table_nr].size = file.size;
  451. table_nr++;
  452. }
  453. if (table_nr == 0)
  454. return;
  455. acpi_tables_addr =
  456. memblock_find_in_range(0, ACPI_TABLE_UPGRADE_MAX_PHYS,
  457. all_tables_size, PAGE_SIZE);
  458. if (!acpi_tables_addr) {
  459. WARN_ON(1);
  460. return;
  461. }
  462. /*
  463. * Only calling e820_add_reserve does not work and the
  464. * tables are invalid (memory got used) later.
  465. * memblock_reserve works as expected and the tables won't get modified.
  466. * But it's not enough on X86 because ioremap will
  467. * complain later (used by acpi_os_map_memory) that the pages
  468. * that should get mapped are not marked "reserved".
  469. * Both memblock_reserve and e820__range_add (via arch_reserve_mem_area)
  470. * works fine.
  471. */
  472. memblock_reserve(acpi_tables_addr, all_tables_size);
  473. arch_reserve_mem_area(acpi_tables_addr, all_tables_size);
  474. /*
  475. * early_ioremap only can remap 256k one time. If we map all
  476. * tables one time, we will hit the limit. Need to map chunks
  477. * one by one during copying the same as that in relocate_initrd().
  478. */
  479. for (no = 0; no < table_nr; no++) {
  480. unsigned char *src_p = acpi_initrd_files[no].data;
  481. phys_addr_t size = acpi_initrd_files[no].size;
  482. phys_addr_t dest_addr = acpi_tables_addr + total_offset;
  483. phys_addr_t slop, clen;
  484. char *dest_p;
  485. total_offset += size;
  486. while (size) {
  487. slop = dest_addr & ~PAGE_MASK;
  488. clen = size;
  489. if (clen > MAP_CHUNK_SIZE - slop)
  490. clen = MAP_CHUNK_SIZE - slop;
  491. dest_p = early_memremap(dest_addr & PAGE_MASK,
  492. clen + slop);
  493. memcpy(dest_p + slop, src_p, clen);
  494. early_memunmap(dest_p, clen + slop);
  495. src_p += clen;
  496. dest_addr += clen;
  497. size -= clen;
  498. }
  499. }
  500. }
  501. static acpi_status
  502. acpi_table_initrd_override(struct acpi_table_header *existing_table,
  503. acpi_physical_address *address, u32 *length)
  504. {
  505. int table_offset = 0;
  506. int table_index = 0;
  507. struct acpi_table_header *table;
  508. u32 table_length;
  509. *length = 0;
  510. *address = 0;
  511. if (!acpi_tables_addr)
  512. return AE_OK;
  513. while (table_offset + ACPI_HEADER_SIZE <= all_tables_size) {
  514. table = acpi_os_map_memory(acpi_tables_addr + table_offset,
  515. ACPI_HEADER_SIZE);
  516. if (table_offset + table->length > all_tables_size) {
  517. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  518. WARN_ON(1);
  519. return AE_OK;
  520. }
  521. table_length = table->length;
  522. /* Only override tables matched */
  523. if (memcmp(existing_table->signature, table->signature, 4) ||
  524. memcmp(table->oem_id, existing_table->oem_id,
  525. ACPI_OEM_ID_SIZE) ||
  526. memcmp(table->oem_table_id, existing_table->oem_table_id,
  527. ACPI_OEM_TABLE_ID_SIZE)) {
  528. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  529. goto next_table;
  530. }
  531. /*
  532. * Mark the table to avoid being used in
  533. * acpi_table_initrd_scan() and check the revision.
  534. */
  535. if (test_and_set_bit(table_index, acpi_initrd_installed) ||
  536. existing_table->oem_revision >= table->oem_revision) {
  537. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  538. goto next_table;
  539. }
  540. *length = table_length;
  541. *address = acpi_tables_addr + table_offset;
  542. pr_info("Table Upgrade: override [%4.4s-%6.6s-%8.8s]\n",
  543. table->signature, table->oem_id,
  544. table->oem_table_id);
  545. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  546. break;
  547. next_table:
  548. table_offset += table_length;
  549. table_index++;
  550. }
  551. return AE_OK;
  552. }
  553. static void __init acpi_table_initrd_scan(void)
  554. {
  555. int table_offset = 0;
  556. int table_index = 0;
  557. u32 table_length;
  558. struct acpi_table_header *table;
  559. if (!acpi_tables_addr)
  560. return;
  561. while (table_offset + ACPI_HEADER_SIZE <= all_tables_size) {
  562. table = acpi_os_map_memory(acpi_tables_addr + table_offset,
  563. ACPI_HEADER_SIZE);
  564. if (table_offset + table->length > all_tables_size) {
  565. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  566. WARN_ON(1);
  567. return;
  568. }
  569. table_length = table->length;
  570. /* Skip RSDT/XSDT which should only be used for override */
  571. if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_RSDT) ||
  572. ACPI_COMPARE_NAME(table->signature, ACPI_SIG_XSDT)) {
  573. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  574. goto next_table;
  575. }
  576. /*
  577. * Mark the table to avoid being used in
  578. * acpi_table_initrd_override(). Though this is not possible
  579. * because override is disabled in acpi_install_table().
  580. */
  581. if (test_and_set_bit(table_index, acpi_initrd_installed)) {
  582. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  583. goto next_table;
  584. }
  585. pr_info("Table Upgrade: install [%4.4s-%6.6s-%8.8s]\n",
  586. table->signature, table->oem_id,
  587. table->oem_table_id);
  588. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  589. acpi_install_table(acpi_tables_addr + table_offset, TRUE);
  590. next_table:
  591. table_offset += table_length;
  592. table_index++;
  593. }
  594. }
  595. #else
  596. static acpi_status
  597. acpi_table_initrd_override(struct acpi_table_header *existing_table,
  598. acpi_physical_address *address,
  599. u32 *table_length)
  600. {
  601. *table_length = 0;
  602. *address = 0;
  603. return AE_OK;
  604. }
  605. static void __init acpi_table_initrd_scan(void)
  606. {
  607. }
  608. #endif /* CONFIG_ACPI_TABLE_UPGRADE */
  609. acpi_status
  610. acpi_os_physical_table_override(struct acpi_table_header *existing_table,
  611. acpi_physical_address *address,
  612. u32 *table_length)
  613. {
  614. return acpi_table_initrd_override(existing_table, address,
  615. table_length);
  616. }
  617. acpi_status
  618. acpi_os_table_override(struct acpi_table_header *existing_table,
  619. struct acpi_table_header **new_table)
  620. {
  621. if (!existing_table || !new_table)
  622. return AE_BAD_PARAMETER;
  623. *new_table = NULL;
  624. #ifdef CONFIG_ACPI_CUSTOM_DSDT
  625. if (strncmp(existing_table->signature, "DSDT", 4) == 0)
  626. *new_table = (struct acpi_table_header *)AmlCode;
  627. #endif
  628. if (*new_table != NULL)
  629. acpi_table_taint(existing_table);
  630. return AE_OK;
  631. }
  632. /*
  633. * acpi_locate_initial_tables()
  634. *
  635. * find RSDP, find and checksum SDT/XSDT.
  636. * checksum all tables, print SDT/XSDT
  637. *
  638. * result: sdt_entry[] is initialized
  639. */
  640. int __init acpi_locate_initial_tables(void)
  641. {
  642. acpi_status status;
  643. if (acpi_verify_table_checksum) {
  644. pr_info("Early table checksum verification enabled\n");
  645. acpi_gbl_enable_table_validation = TRUE;
  646. } else {
  647. pr_info("Early table checksum verification disabled\n");
  648. acpi_gbl_enable_table_validation = FALSE;
  649. }
  650. status = acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
  651. if (ACPI_FAILURE(status))
  652. return -EINVAL;
  653. return 0;
  654. }
  655. void __init acpi_reserve_initial_tables(void)
  656. {
  657. int i;
  658. for (i = 0; i < ACPI_MAX_TABLES; i++) {
  659. struct acpi_table_desc *table_desc = &initial_tables[i];
  660. u64 start = table_desc->address;
  661. u64 size = table_desc->length;
  662. if (!start || !size)
  663. break;
  664. pr_info("Reserving %4s table memory at [mem 0x%llx-0x%llx]\n",
  665. table_desc->signature.ascii, start, start + size - 1);
  666. memblock_reserve(start, size);
  667. }
  668. }
  669. void __init acpi_table_init_complete(void)
  670. {
  671. acpi_table_initrd_scan();
  672. check_multiple_madt();
  673. }
  674. int __init acpi_table_init(void)
  675. {
  676. int ret;
  677. ret = acpi_locate_initial_tables();
  678. if (ret)
  679. return ret;
  680. acpi_table_init_complete();
  681. return 0;
  682. }
  683. static int __init acpi_parse_apic_instance(char *str)
  684. {
  685. if (!str)
  686. return -EINVAL;
  687. if (kstrtoint(str, 0, &acpi_apic_instance))
  688. return -EINVAL;
  689. pr_notice("Shall use APIC/MADT table %d\n", acpi_apic_instance);
  690. return 0;
  691. }
  692. early_param("acpi_apic_instance", acpi_parse_apic_instance);
  693. static int __init acpi_force_table_verification_setup(char *s)
  694. {
  695. acpi_verify_table_checksum = true;
  696. return 0;
  697. }
  698. early_param("acpi_force_table_verification", acpi_force_table_verification_setup);
  699. static int __init acpi_force_32bit_fadt_addr(char *s)
  700. {
  701. pr_info("Forcing 32 Bit FADT addresses\n");
  702. acpi_gbl_use32_bit_fadt_addresses = TRUE;
  703. return 0;
  704. }
  705. early_param("acpi_force_32bit_fadt_addr", acpi_force_32bit_fadt_addr);