acpi.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * ARM64 Specific Low-Level ACPI Boot Support
  3. *
  4. * Copyright (C) 2013-2014, Linaro Ltd.
  5. * Author: Al Stone <al.stone@linaro.org>
  6. * Author: Graeme Gregory <graeme.gregory@linaro.org>
  7. * Author: Hanjun Guo <hanjun.guo@linaro.org>
  8. * Author: Tomasz Nowicki <tomasz.nowicki@linaro.org>
  9. * Author: Naresh Bhat <naresh.bhat@linaro.org>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #define pr_fmt(fmt) "ACPI: " fmt
  16. #include <linux/acpi.h>
  17. #include <linux/bootmem.h>
  18. #include <linux/cpumask.h>
  19. #include <linux/efi-bgrt.h>
  20. #include <linux/init.h>
  21. #include <linux/irq.h>
  22. #include <linux/irqdomain.h>
  23. #include <linux/memblock.h>
  24. #include <linux/of_fdt.h>
  25. #include <linux/smp.h>
  26. #include <linux/serial_core.h>
  27. #include <asm/cputype.h>
  28. #include <asm/cpu_ops.h>
  29. #include <asm/smp_plat.h>
  30. #ifdef CONFIG_ACPI_APEI
  31. # include <linux/efi.h>
  32. # include <asm/pgtable.h>
  33. #endif
  34. int acpi_noirq = 1; /* skip ACPI IRQ initialization */
  35. int acpi_disabled = 1;
  36. EXPORT_SYMBOL(acpi_disabled);
  37. int acpi_pci_disabled = 1; /* skip ACPI PCI scan and IRQ initialization */
  38. EXPORT_SYMBOL(acpi_pci_disabled);
  39. static bool param_acpi_off __initdata;
  40. static bool param_acpi_on __initdata;
  41. static bool param_acpi_force __initdata;
  42. static int __init parse_acpi(char *arg)
  43. {
  44. if (!arg)
  45. return -EINVAL;
  46. /* "acpi=off" disables both ACPI table parsing and interpreter */
  47. if (strcmp(arg, "off") == 0)
  48. param_acpi_off = true;
  49. else if (strcmp(arg, "on") == 0) /* prefer ACPI over DT */
  50. param_acpi_on = true;
  51. else if (strcmp(arg, "force") == 0) /* force ACPI to be enabled */
  52. param_acpi_force = true;
  53. else
  54. return -EINVAL; /* Core will print when we return error */
  55. return 0;
  56. }
  57. early_param("acpi", parse_acpi);
  58. static int __init dt_scan_depth1_nodes(unsigned long node,
  59. const char *uname, int depth,
  60. void *data)
  61. {
  62. /*
  63. * Ignore anything not directly under the root node; we'll
  64. * catch its parent instead.
  65. */
  66. if (depth != 1)
  67. return 0;
  68. if (strcmp(uname, "chosen") == 0)
  69. return 0;
  70. if (strcmp(uname, "hypervisor") == 0 &&
  71. of_flat_dt_is_compatible(node, "xen,xen"))
  72. return 0;
  73. /*
  74. * This node at depth 1 is neither a chosen node nor a xen node,
  75. * which we do not expect.
  76. */
  77. return 1;
  78. }
  79. /*
  80. * __acpi_map_table() will be called before page_init(), so early_ioremap()
  81. * or early_memremap() should be called here to for ACPI table mapping.
  82. */
  83. void __init __iomem *__acpi_map_table(unsigned long phys, unsigned long size)
  84. {
  85. if (!size)
  86. return NULL;
  87. return early_memremap(phys, size);
  88. }
  89. void __init __acpi_unmap_table(void __iomem *map, unsigned long size)
  90. {
  91. if (!map || !size)
  92. return;
  93. early_memunmap(map, size);
  94. }
  95. bool __init acpi_psci_present(void)
  96. {
  97. return acpi_gbl_FADT.arm_boot_flags & ACPI_FADT_PSCI_COMPLIANT;
  98. }
  99. /* Whether HVC must be used instead of SMC as the PSCI conduit */
  100. bool acpi_psci_use_hvc(void)
  101. {
  102. return acpi_gbl_FADT.arm_boot_flags & ACPI_FADT_PSCI_USE_HVC;
  103. }
  104. /*
  105. * acpi_fadt_sanity_check() - Check FADT presence and carry out sanity
  106. * checks on it
  107. *
  108. * Return 0 on success, <0 on failure
  109. */
  110. static int __init acpi_fadt_sanity_check(void)
  111. {
  112. struct acpi_table_header *table;
  113. struct acpi_table_fadt *fadt;
  114. acpi_status status;
  115. int ret = 0;
  116. /*
  117. * FADT is required on arm64; retrieve it to check its presence
  118. * and carry out revision and ACPI HW reduced compliancy tests
  119. */
  120. status = acpi_get_table(ACPI_SIG_FADT, 0, &table);
  121. if (ACPI_FAILURE(status)) {
  122. const char *msg = acpi_format_exception(status);
  123. pr_err("Failed to get FADT table, %s\n", msg);
  124. return -ENODEV;
  125. }
  126. fadt = (struct acpi_table_fadt *)table;
  127. /*
  128. * Revision in table header is the FADT Major revision, and there
  129. * is a minor revision of FADT which was introduced by ACPI 5.1,
  130. * we only deal with ACPI 5.1 or newer revision to get GIC and SMP
  131. * boot protocol configuration data.
  132. */
  133. if (table->revision < 5 ||
  134. (table->revision == 5 && fadt->minor_revision < 1)) {
  135. pr_err("Unsupported FADT revision %d.%d, should be 5.1+\n",
  136. table->revision, fadt->minor_revision);
  137. ret = -EINVAL;
  138. goto out;
  139. }
  140. if (!(fadt->flags & ACPI_FADT_HW_REDUCED)) {
  141. pr_err("FADT not ACPI hardware reduced compliant\n");
  142. ret = -EINVAL;
  143. }
  144. out:
  145. /*
  146. * acpi_get_table() creates FADT table mapping that
  147. * should be released after parsing and before resuming boot
  148. */
  149. acpi_put_table(table);
  150. return ret;
  151. }
  152. /*
  153. * acpi_boot_table_init() called from setup_arch(), always.
  154. * 1. find RSDP and get its address, and then find XSDT
  155. * 2. extract all tables and checksums them all
  156. * 3. check ACPI FADT revision
  157. * 4. check ACPI FADT HW reduced flag
  158. *
  159. * We can parse ACPI boot-time tables such as MADT after
  160. * this function is called.
  161. *
  162. * On return ACPI is enabled if either:
  163. *
  164. * - ACPI tables are initialized and sanity checks passed
  165. * - acpi=force was passed in the command line and ACPI was not disabled
  166. * explicitly through acpi=off command line parameter
  167. *
  168. * ACPI is disabled on function return otherwise
  169. */
  170. void __init acpi_boot_table_init(void)
  171. {
  172. /*
  173. * Enable ACPI instead of device tree unless
  174. * - ACPI has been disabled explicitly (acpi=off), or
  175. * - the device tree is not empty (it has more than just a /chosen node,
  176. * and a /hypervisor node when running on Xen)
  177. * and ACPI has not been [force] enabled (acpi=on|force)
  178. */
  179. if (param_acpi_off ||
  180. (!param_acpi_on && !param_acpi_force &&
  181. of_scan_flat_dt(dt_scan_depth1_nodes, NULL)))
  182. goto done;
  183. /*
  184. * ACPI is disabled at this point. Enable it in order to parse
  185. * the ACPI tables and carry out sanity checks
  186. */
  187. enable_acpi();
  188. /*
  189. * If ACPI tables are initialized and FADT sanity checks passed,
  190. * leave ACPI enabled and carry on booting; otherwise disable ACPI
  191. * on initialization error.
  192. * If acpi=force was passed on the command line it forces ACPI
  193. * to be enabled even if its initialization failed.
  194. */
  195. if (acpi_table_init() || acpi_fadt_sanity_check()) {
  196. pr_err("Failed to init ACPI tables\n");
  197. if (!param_acpi_force)
  198. disable_acpi();
  199. }
  200. done:
  201. if (acpi_disabled) {
  202. if (earlycon_acpi_spcr_enable)
  203. early_init_dt_scan_chosen_stdout();
  204. } else {
  205. acpi_parse_spcr(earlycon_acpi_spcr_enable, true);
  206. if (IS_ENABLED(CONFIG_ACPI_BGRT))
  207. acpi_table_parse(ACPI_SIG_BGRT, acpi_parse_bgrt);
  208. }
  209. }
  210. #ifdef CONFIG_ACPI_APEI
  211. pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr)
  212. {
  213. /*
  214. * According to "Table 8 Map: EFI memory types to AArch64 memory
  215. * types" of UEFI 2.5 section 2.3.6.1, each EFI memory type is
  216. * mapped to a corresponding MAIR attribute encoding.
  217. * The EFI memory attribute advises all possible capabilities
  218. * of a memory region. We use the most efficient capability.
  219. */
  220. u64 attr;
  221. attr = efi_mem_attributes(addr);
  222. if (attr & EFI_MEMORY_WB)
  223. return PAGE_KERNEL;
  224. if (attr & EFI_MEMORY_WT)
  225. return __pgprot(PROT_NORMAL_WT);
  226. if (attr & EFI_MEMORY_WC)
  227. return __pgprot(PROT_NORMAL_NC);
  228. return __pgprot(PROT_DEVICE_nGnRnE);
  229. }
  230. #endif