tables.c 21 KB

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