acpi.c 6.7 KB

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