tables.c 21 KB

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