acpi.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. int acpi_noirq = 1; /* skip ACPI IRQ initialization */
  29. int acpi_disabled = 1;
  30. EXPORT_SYMBOL(acpi_disabled);
  31. int acpi_pci_disabled = 1; /* skip ACPI PCI scan and IRQ initialization */
  32. EXPORT_SYMBOL(acpi_pci_disabled);
  33. static bool param_acpi_off __initdata;
  34. static bool param_acpi_force __initdata;
  35. static int __init parse_acpi(char *arg)
  36. {
  37. if (!arg)
  38. return -EINVAL;
  39. /* "acpi=off" disables both ACPI table parsing and interpreter */
  40. if (strcmp(arg, "off") == 0)
  41. param_acpi_off = true;
  42. else if (strcmp(arg, "force") == 0) /* force ACPI to be enabled */
  43. param_acpi_force = true;
  44. else
  45. return -EINVAL; /* Core will print when we return error */
  46. return 0;
  47. }
  48. early_param("acpi", parse_acpi);
  49. static int __init dt_scan_depth1_nodes(unsigned long node,
  50. const char *uname, int depth,
  51. void *data)
  52. {
  53. /*
  54. * Return 1 as soon as we encounter a node at depth 1 that is
  55. * not the /chosen node.
  56. */
  57. if (depth == 1 && (strcmp(uname, "chosen") != 0))
  58. return 1;
  59. return 0;
  60. }
  61. /*
  62. * __acpi_map_table() will be called before page_init(), so early_ioremap()
  63. * or early_memremap() should be called here to for ACPI table mapping.
  64. */
  65. char *__init __acpi_map_table(unsigned long phys, unsigned long size)
  66. {
  67. if (!size)
  68. return NULL;
  69. return early_memremap(phys, size);
  70. }
  71. void __init __acpi_unmap_table(char *map, unsigned long size)
  72. {
  73. if (!map || !size)
  74. return;
  75. early_memunmap(map, size);
  76. }
  77. bool __init acpi_psci_present(void)
  78. {
  79. return acpi_gbl_FADT.arm_boot_flags & ACPI_FADT_PSCI_COMPLIANT;
  80. }
  81. /* Whether HVC must be used instead of SMC as the PSCI conduit */
  82. bool __init acpi_psci_use_hvc(void)
  83. {
  84. return acpi_gbl_FADT.arm_boot_flags & ACPI_FADT_PSCI_USE_HVC;
  85. }
  86. /*
  87. * acpi_fadt_sanity_check() - Check FADT presence and carry out sanity
  88. * checks on it
  89. *
  90. * Return 0 on success, <0 on failure
  91. */
  92. static int __init acpi_fadt_sanity_check(void)
  93. {
  94. struct acpi_table_header *table;
  95. struct acpi_table_fadt *fadt;
  96. acpi_status status;
  97. acpi_size tbl_size;
  98. int ret = 0;
  99. /*
  100. * FADT is required on arm64; retrieve it to check its presence
  101. * and carry out revision and ACPI HW reduced compliancy tests
  102. */
  103. status = acpi_get_table_with_size(ACPI_SIG_FADT, 0, &table, &tbl_size);
  104. if (ACPI_FAILURE(status)) {
  105. const char *msg = acpi_format_exception(status);
  106. pr_err("Failed to get FADT table, %s\n", msg);
  107. return -ENODEV;
  108. }
  109. fadt = (struct acpi_table_fadt *)table;
  110. /*
  111. * Revision in table header is the FADT Major revision, and there
  112. * is a minor revision of FADT which was introduced by ACPI 5.1,
  113. * we only deal with ACPI 5.1 or newer revision to get GIC and SMP
  114. * boot protocol configuration data.
  115. */
  116. if (table->revision < 5 ||
  117. (table->revision == 5 && fadt->minor_revision < 1)) {
  118. pr_err("Unsupported FADT revision %d.%d, should be 5.1+\n",
  119. table->revision, fadt->minor_revision);
  120. ret = -EINVAL;
  121. goto out;
  122. }
  123. if (!(fadt->flags & ACPI_FADT_HW_REDUCED)) {
  124. pr_err("FADT not ACPI hardware reduced compliant\n");
  125. ret = -EINVAL;
  126. }
  127. out:
  128. /*
  129. * acpi_get_table_with_size() creates FADT table mapping that
  130. * should be released after parsing and before resuming boot
  131. */
  132. early_acpi_os_unmap_memory(table, tbl_size);
  133. return ret;
  134. }
  135. /*
  136. * acpi_boot_table_init() called from setup_arch(), always.
  137. * 1. find RSDP and get its address, and then find XSDT
  138. * 2. extract all tables and checksums them all
  139. * 3. check ACPI FADT revision
  140. * 4. check ACPI FADT HW reduced flag
  141. *
  142. * We can parse ACPI boot-time tables such as MADT after
  143. * this function is called.
  144. *
  145. * On return ACPI is enabled if either:
  146. *
  147. * - ACPI tables are initialized and sanity checks passed
  148. * - acpi=force was passed in the command line and ACPI was not disabled
  149. * explicitly through acpi=off command line parameter
  150. *
  151. * ACPI is disabled on function return otherwise
  152. */
  153. void __init acpi_boot_table_init(void)
  154. {
  155. /*
  156. * Enable ACPI instead of device tree unless
  157. * - ACPI has been disabled explicitly (acpi=off), or
  158. * - the device tree is not empty (it has more than just a /chosen node)
  159. * and ACPI has not been force enabled (acpi=force)
  160. */
  161. if (param_acpi_off ||
  162. (!param_acpi_force && of_scan_flat_dt(dt_scan_depth1_nodes, NULL)))
  163. return;
  164. /*
  165. * ACPI is disabled at this point. Enable it in order to parse
  166. * the ACPI tables and carry out sanity checks
  167. */
  168. enable_acpi();
  169. /*
  170. * If ACPI tables are initialized and FADT sanity checks passed,
  171. * leave ACPI enabled and carry on booting; otherwise disable ACPI
  172. * on initialization error.
  173. * If acpi=force was passed on the command line it forces ACPI
  174. * to be enabled even if its initialization failed.
  175. */
  176. if (acpi_table_init() || acpi_fadt_sanity_check()) {
  177. pr_err("Failed to init ACPI tables\n");
  178. if (!param_acpi_force)
  179. disable_acpi();
  180. }
  181. }
  182. void __init acpi_gic_init(void)
  183. {
  184. struct acpi_table_header *table;
  185. acpi_status status;
  186. acpi_size tbl_size;
  187. int err;
  188. if (acpi_disabled)
  189. return;
  190. status = acpi_get_table_with_size(ACPI_SIG_MADT, 0, &table, &tbl_size);
  191. if (ACPI_FAILURE(status)) {
  192. const char *msg = acpi_format_exception(status);
  193. pr_err("Failed to get MADT table, %s\n", msg);
  194. return;
  195. }
  196. err = gic_v2_acpi_init(table);
  197. if (err)
  198. pr_err("Failed to initialize GIC IRQ controller");
  199. early_acpi_os_unmap_memory((char *)table, tbl_size);
  200. }