acpi.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2013-2014, Linaro Ltd.
  4. * Author: Al Stone <al.stone@linaro.org>
  5. * Author: Graeme Gregory <graeme.gregory@linaro.org>
  6. * Author: Hanjun Guo <hanjun.guo@linaro.org>
  7. */
  8. #ifndef _ASM_ACPI_H
  9. #define _ASM_ACPI_H
  10. #include <linux/cpuidle.h>
  11. #include <linux/efi.h>
  12. #include <linux/memblock.h>
  13. #include <linux/psci.h>
  14. #include <linux/stddef.h>
  15. #include <asm/cputype.h>
  16. #include <asm/io.h>
  17. #include <asm/ptrace.h>
  18. #include <asm/smp_plat.h>
  19. #include <asm/tlbflush.h>
  20. /* Macros for consistency checks of the GICC subtable of MADT */
  21. /*
  22. * MADT GICC minimum length refers to the MADT GICC structure table length as
  23. * defined in the earliest ACPI version supported on arm64, ie ACPI 5.1.
  24. *
  25. * The efficiency_class member was added to the
  26. * struct acpi_madt_generic_interrupt to represent the MADT GICC structure
  27. * "Processor Power Efficiency Class" field, added in ACPI 6.0 whose offset
  28. * is therefore used to delimit the MADT GICC structure minimum length
  29. * appropriately.
  30. */
  31. #define ACPI_MADT_GICC_MIN_LENGTH offsetof( \
  32. struct acpi_madt_generic_interrupt, efficiency_class)
  33. #define BAD_MADT_GICC_ENTRY(entry, end) \
  34. (!(entry) || (entry)->header.length < ACPI_MADT_GICC_MIN_LENGTH || \
  35. (unsigned long)(entry) + (entry)->header.length > (end))
  36. #define ACPI_MADT_GICC_SPE (offsetof(struct acpi_madt_generic_interrupt, \
  37. spe_interrupt) + sizeof(u16))
  38. #define ACPI_MADT_GICC_TRBE (offsetof(struct acpi_madt_generic_interrupt, \
  39. trbe_interrupt) + sizeof(u16))
  40. /*
  41. * Arm® Functional Fixed Hardware Specification Version 1.2.
  42. * Table 2: Arm Architecture context loss flags
  43. */
  44. #define CPUIDLE_CORE_CTXT BIT(0) /* Core context Lost */
  45. static inline unsigned int arch_get_idle_state_flags(u32 arch_flags)
  46. {
  47. if (arch_flags & CPUIDLE_CORE_CTXT)
  48. return CPUIDLE_FLAG_TIMER_STOP;
  49. return 0;
  50. }
  51. #define arch_get_idle_state_flags arch_get_idle_state_flags
  52. #define CPUIDLE_TRACE_CTXT BIT(1) /* Trace context loss */
  53. #define CPUIDLE_GICR_CTXT BIT(2) /* GICR */
  54. #define CPUIDLE_GICD_CTXT BIT(3) /* GICD */
  55. /* Basic configuration for ACPI */
  56. #ifdef CONFIG_ACPI
  57. pgprot_t __acpi_get_mem_attribute(phys_addr_t addr);
  58. /* ACPI table mapping after acpi_permanent_mmap is set */
  59. void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size);
  60. #define acpi_os_ioremap acpi_os_ioremap
  61. typedef u64 phys_cpuid_t;
  62. #define PHYS_CPUID_INVALID INVALID_HWID
  63. #define acpi_strict 1 /* No out-of-spec workarounds on ARM64 */
  64. extern int acpi_disabled;
  65. extern int acpi_noirq;
  66. extern int acpi_pci_disabled;
  67. static inline void disable_acpi(void)
  68. {
  69. acpi_disabled = 1;
  70. acpi_pci_disabled = 1;
  71. acpi_noirq = 1;
  72. }
  73. static inline void enable_acpi(void)
  74. {
  75. acpi_disabled = 0;
  76. acpi_pci_disabled = 0;
  77. acpi_noirq = 0;
  78. }
  79. /*
  80. * The ACPI processor driver for ACPI core code needs this macro
  81. * to find out this cpu was already mapped (mapping from CPU hardware
  82. * ID to CPU logical ID) or not.
  83. */
  84. #define cpu_physical_id(cpu) cpu_logical_map(cpu)
  85. /*
  86. * It's used from ACPI core in kdump to boot UP system with SMP kernel,
  87. * with this check the ACPI core will not override the CPU index
  88. * obtained from GICC with 0 and not print some error message as well.
  89. * Since MADT must provide at least one GICC structure for GIC
  90. * initialization, CPU will be always available in MADT on ARM64.
  91. */
  92. static inline bool acpi_has_cpu_in_madt(void)
  93. {
  94. return true;
  95. }
  96. struct acpi_madt_generic_interrupt *acpi_cpu_get_madt_gicc(int cpu);
  97. static inline u32 get_acpi_id_for_cpu(unsigned int cpu)
  98. {
  99. return acpi_cpu_get_madt_gicc(cpu)->uid;
  100. }
  101. static inline int get_cpu_for_acpi_id(u32 uid)
  102. {
  103. int cpu;
  104. for (cpu = 0; cpu < nr_cpu_ids; cpu++)
  105. if (acpi_cpu_get_madt_gicc(cpu) &&
  106. uid == get_acpi_id_for_cpu(cpu))
  107. return cpu;
  108. return -EINVAL;
  109. }
  110. static inline void arch_fix_phys_package_id(int num, u32 slot) { }
  111. void __init acpi_init_cpus(void);
  112. int apei_claim_sea(struct pt_regs *regs);
  113. #else
  114. static inline void acpi_init_cpus(void) { }
  115. static inline int apei_claim_sea(struct pt_regs *regs) { return -ENOENT; }
  116. #endif /* CONFIG_ACPI */
  117. #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
  118. bool acpi_parking_protocol_valid(int cpu);
  119. void __init
  120. acpi_set_mailbox_entry(int cpu, struct acpi_madt_generic_interrupt *processor);
  121. #else
  122. static inline bool acpi_parking_protocol_valid(int cpu) { return false; }
  123. static inline void
  124. acpi_set_mailbox_entry(int cpu, struct acpi_madt_generic_interrupt *processor)
  125. {}
  126. #endif
  127. static __always_inline const char *acpi_get_enable_method(int cpu)
  128. {
  129. if (acpi_psci_present())
  130. return "psci";
  131. if (acpi_parking_protocol_valid(cpu))
  132. return "parking-protocol";
  133. return NULL;
  134. }
  135. #ifdef CONFIG_ACPI_APEI
  136. /*
  137. * acpi_disable_cmcff is used in drivers/acpi/apei/hest.c for disabling
  138. * IA-32 Architecture Corrected Machine Check (CMC) Firmware-First mode
  139. * with a kernel command line parameter "acpi=nocmcoff". But we don't
  140. * have this IA-32 specific feature on ARM64, this definition is only
  141. * for compatibility.
  142. */
  143. #define acpi_disable_cmcff 1
  144. static inline pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr)
  145. {
  146. return __acpi_get_mem_attribute(addr);
  147. }
  148. #endif /* CONFIG_ACPI_APEI */
  149. #ifdef CONFIG_ACPI_NUMA
  150. int arm64_acpi_numa_init(void);
  151. int acpi_numa_get_nid(unsigned int cpu);
  152. void acpi_map_cpus_to_nodes(void);
  153. #else
  154. static inline int arm64_acpi_numa_init(void) { return -ENOSYS; }
  155. static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
  156. static inline void acpi_map_cpus_to_nodes(void) { }
  157. #endif /* CONFIG_ACPI_NUMA */
  158. #define ACPI_TABLE_UPGRADE_MAX_PHYS MEMBLOCK_ALLOC_ACCESSIBLE
  159. #endif /*_ASM_ACPI_H*/