1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 #ifndef _ASM_X86_ACPI_H 3 #define _ASM_X86_ACPI_H 4 5 /* 6 * Copyright (C) 2001 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> 7 * Copyright (C) 2001 Patrick Mochel <mochel@osdl.org> 8 */ 9 #include <acpi/proc_cap_intel.h> 10 11 #include <asm/numa.h> 12 #include <asm/fixmap.h> 13 #include <asm/processor.h> 14 #include <asm/mmu.h> 15 #include <asm/mpspec.h> 16 #include <asm/x86_init.h> 17 #include <asm/cpufeature.h> 18 #include <asm/irq_vectors.h> 19 #include <asm/xen/hypervisor.h> 20 21 #include <xen/xen.h> 22 23 #ifdef CONFIG_ACPI_APEI 24 # include <asm/pgtable_types.h> 25 #endif 26 27 #ifdef CONFIG_ACPI 28 extern int acpi_lapic; 29 extern int acpi_ioapic; 30 extern int acpi_noirq; 31 extern int acpi_strict; 32 extern int acpi_disabled; 33 extern int acpi_pci_disabled; 34 extern int acpi_skip_timer_override; 35 extern int acpi_use_timer_override; 36 extern int acpi_fix_pin2_polarity; 37 extern int acpi_disable_cmcff; 38 extern bool acpi_int_src_ovr[NR_IRQS_LEGACY]; 39 40 extern u8 acpi_sci_flags; 41 extern u32 acpi_sci_override_gsi; 42 void acpi_pic_sci_set_trigger(unsigned int, u16); 43 44 struct device; 45 46 extern int (*__acpi_register_gsi)(struct device *dev, u32 gsi, 47 int trigger, int polarity); 48 extern void (*__acpi_unregister_gsi)(u32 gsi); 49 50 static inline void disable_acpi(void) 51 { 52 acpi_disabled = 1; 53 acpi_pci_disabled = 1; 54 acpi_noirq = 1; 55 } 56 57 extern int acpi_gsi_to_irq(u32 gsi, unsigned int *irq); 58 59 extern int acpi_blacklisted(void); 60 61 static inline void acpi_noirq_set(void) { acpi_noirq = 1; } 62 static inline void acpi_disable_pci(void) 63 { 64 acpi_pci_disabled = 1; 65 acpi_noirq_set(); 66 } 67 68 /* Low-level suspend routine. */ 69 extern int (*acpi_suspend_lowlevel)(void); 70 71 /* Physical address to resume after wakeup */ 72 unsigned long acpi_get_wakeup_address(void); 73 74 static inline bool acpi_skip_set_wakeup_address(void) 75 { 76 return cpu_feature_enabled(X86_FEATURE_XENPV); 77 } 78 79 #define acpi_skip_set_wakeup_address acpi_skip_set_wakeup_address 80 81 union acpi_subtable_headers; 82 83 int __init acpi_parse_mp_wake(union acpi_subtable_headers *header, 84 const unsigned long end); 85 86 void asm_acpi_mp_play_dead(u64 reset_vector, u64 pgd_pa); 87 88 /* 89 * Check if the CPU can handle C2 and deeper 90 */ 91 static inline unsigned int acpi_processor_cstate_check(unsigned int max_cstate) 92 { 93 /* 94 * Early models (<=5) of AMD Opterons are not supposed to go into 95 * C2 state. 96 * 97 * Steppings 0x0A and later are good 98 */ 99 if (boot_cpu_data.x86 == 0x0F && 100 boot_cpu_data.x86_vendor == X86_VENDOR_AMD && 101 boot_cpu_data.x86_model <= 0x05 && 102 boot_cpu_data.x86_stepping < 0x0A) 103 return 1; 104 else if (boot_cpu_has(X86_BUG_AMD_APIC_C1E)) 105 return 1; 106 else 107 return max_cstate; 108 } 109 110 static inline bool arch_has_acpi_pdc(void) 111 { 112 struct cpuinfo_x86 *c = &cpu_data(0); 113 return (c->x86_vendor == X86_VENDOR_INTEL || 114 c->x86_vendor == X86_VENDOR_CENTAUR); 115 } 116 117 static inline void arch_acpi_set_proc_cap_bits(u32 *cap) 118 { 119 struct cpuinfo_x86 *c = &cpu_data(0); 120 121 *cap |= ACPI_PROC_CAP_C_CAPABILITY_SMP; 122 123 /* Enable coordination with firmware's _TSD info */ 124 *cap |= ACPI_PROC_CAP_SMP_T_SWCOORD; 125 126 if (cpu_has(c, X86_FEATURE_EST)) 127 *cap |= ACPI_PROC_CAP_EST_CAPABILITY_SWSMP; 128 129 if (cpu_has(c, X86_FEATURE_ACPI)) 130 *cap |= ACPI_PROC_CAP_T_FFH; 131 132 if (cpu_has(c, X86_FEATURE_HWP)) 133 *cap |= ACPI_PROC_CAP_COLLAB_PROC_PERF; 134 135 /* 136 * If mwait/monitor is unsupported, C_C1_FFH and 137 * C2/C3_FFH will be disabled. 138 */ 139 if (!cpu_has(c, X86_FEATURE_MWAIT) || 140 boot_option_idle_override == IDLE_NOMWAIT) 141 *cap &= ~(ACPI_PROC_CAP_C_C1_FFH | ACPI_PROC_CAP_C_C2C3_FFH); 142 143 if (xen_initial_domain()) { 144 /* 145 * When Linux is running as Xen dom0, the hypervisor is the 146 * entity in charge of the processor power management, and so 147 * Xen needs to check the OS capabilities reported in the 148 * processor capabilities buffer matches what the hypervisor 149 * driver supports. 150 */ 151 xen_sanitize_proc_cap_bits(cap); 152 } 153 } 154 155 static inline bool acpi_has_cpu_in_madt(void) 156 { 157 return !!acpi_lapic; 158 } 159 160 #define ACPI_HAVE_ARCH_SET_ROOT_POINTER 161 static inline void acpi_arch_set_root_pointer(u64 addr) 162 { 163 x86_init.acpi.set_root_pointer(addr); 164 } 165 166 #define ACPI_HAVE_ARCH_GET_ROOT_POINTER 167 static inline u64 acpi_arch_get_root_pointer(void) 168 { 169 return x86_init.acpi.get_root_pointer(); 170 } 171 172 void acpi_generic_reduced_hw_init(void); 173 174 void x86_default_set_root_pointer(u64 addr); 175 u64 x86_default_get_root_pointer(void); 176 177 #ifdef CONFIG_XEN_PV 178 /* A Xen PV domain needs a special acpi_os_ioremap() handling. */ 179 extern void __iomem * (*acpi_os_ioremap)(acpi_physical_address phys, 180 acpi_size size); 181 void __iomem *x86_acpi_os_ioremap(acpi_physical_address phys, acpi_size size); 182 #define acpi_os_ioremap acpi_os_ioremap 183 #endif 184 185 #else /* !CONFIG_ACPI */ 186 187 #define acpi_lapic 0 188 #define acpi_ioapic 0 189 #define acpi_disable_cmcff 0 190 static inline void acpi_noirq_set(void) { } 191 static inline void acpi_disable_pci(void) { } 192 static inline void disable_acpi(void) { } 193 194 static inline void acpi_generic_reduced_hw_init(void) { } 195 196 static inline void x86_default_set_root_pointer(u64 addr) { } 197 198 static inline u64 x86_default_get_root_pointer(void) 199 { 200 return 0; 201 } 202 203 #endif /* !CONFIG_ACPI */ 204 205 #define ARCH_HAS_POWER_INIT 1 206 207 #ifdef CONFIG_ACPI_NUMA 208 extern int x86_acpi_numa_init(void); 209 #endif /* CONFIG_ACPI_NUMA */ 210 211 struct cper_ia_proc_ctx; 212 213 #ifdef CONFIG_ACPI_APEI 214 static inline pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr) 215 { 216 /* 217 * We currently have no way to look up the EFI memory map 218 * attributes for a region in a consistent way, because the 219 * memmap is discarded after efi_free_boot_services(). So if 220 * you call efi_mem_attributes() during boot and at runtime, 221 * you could theoretically see different attributes. 222 * 223 * We are yet to see any x86 platforms that require anything 224 * other than PAGE_KERNEL (some ARM64 platforms require the 225 * equivalent of PAGE_KERNEL_NOCACHE). Additionally, if SME 226 * is active, the ACPI information will not be encrypted, 227 * so return PAGE_KERNEL_NOENC until we know differently. 228 */ 229 return PAGE_KERNEL_NOENC; 230 } 231 232 int arch_apei_report_x86_error(struct cper_ia_proc_ctx *ctx_info, 233 u64 lapic_id); 234 #else 235 static inline int arch_apei_report_x86_error(struct cper_ia_proc_ctx *ctx_info, 236 u64 lapic_id) 237 { 238 return -EINVAL; 239 } 240 #endif 241 242 #define ACPI_TABLE_UPGRADE_MAX_PHYS (max_low_pfn_mapped << PAGE_SHIFT) 243 244 #endif /* _ASM_X86_ACPI_H */ 245