Linux 6.9-rc6
[sfrench/cifs-2.6.git] / arch / x86 / include / asm / acpi.h
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 static inline void acpi_noirq_set(void) { acpi_noirq = 1; }
60 static inline void acpi_disable_pci(void)
61 {
62         acpi_pci_disabled = 1;
63         acpi_noirq_set();
64 }
65
66 /* Low-level suspend routine. */
67 extern int (*acpi_suspend_lowlevel)(void);
68
69 /* Physical address to resume after wakeup */
70 unsigned long acpi_get_wakeup_address(void);
71
72 static inline bool acpi_skip_set_wakeup_address(void)
73 {
74         return cpu_feature_enabled(X86_FEATURE_XENPV);
75 }
76
77 #define acpi_skip_set_wakeup_address acpi_skip_set_wakeup_address
78
79 /*
80  * Check if the CPU can handle C2 and deeper
81  */
82 static inline unsigned int acpi_processor_cstate_check(unsigned int max_cstate)
83 {
84         /*
85          * Early models (<=5) of AMD Opterons are not supposed to go into
86          * C2 state.
87          *
88          * Steppings 0x0A and later are good
89          */
90         if (boot_cpu_data.x86 == 0x0F &&
91             boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
92             boot_cpu_data.x86_model <= 0x05 &&
93             boot_cpu_data.x86_stepping < 0x0A)
94                 return 1;
95         else if (boot_cpu_has(X86_BUG_AMD_APIC_C1E))
96                 return 1;
97         else
98                 return max_cstate;
99 }
100
101 static inline bool arch_has_acpi_pdc(void)
102 {
103         struct cpuinfo_x86 *c = &cpu_data(0);
104         return (c->x86_vendor == X86_VENDOR_INTEL ||
105                 c->x86_vendor == X86_VENDOR_CENTAUR);
106 }
107
108 static inline void arch_acpi_set_proc_cap_bits(u32 *cap)
109 {
110         struct cpuinfo_x86 *c = &cpu_data(0);
111
112         *cap |= ACPI_PROC_CAP_C_CAPABILITY_SMP;
113
114         /* Enable coordination with firmware's _TSD info */
115         *cap |= ACPI_PROC_CAP_SMP_T_SWCOORD;
116
117         if (cpu_has(c, X86_FEATURE_EST))
118                 *cap |= ACPI_PROC_CAP_EST_CAPABILITY_SWSMP;
119
120         if (cpu_has(c, X86_FEATURE_ACPI))
121                 *cap |= ACPI_PROC_CAP_T_FFH;
122
123         if (cpu_has(c, X86_FEATURE_HWP))
124                 *cap |= ACPI_PROC_CAP_COLLAB_PROC_PERF;
125
126         /*
127          * If mwait/monitor is unsupported, C_C1_FFH and
128          * C2/C3_FFH will be disabled.
129          */
130         if (!cpu_has(c, X86_FEATURE_MWAIT) ||
131             boot_option_idle_override == IDLE_NOMWAIT)
132                 *cap &= ~(ACPI_PROC_CAP_C_C1_FFH | ACPI_PROC_CAP_C_C2C3_FFH);
133
134         if (xen_initial_domain()) {
135                 /*
136                  * When Linux is running as Xen dom0, the hypervisor is the
137                  * entity in charge of the processor power management, and so
138                  * Xen needs to check the OS capabilities reported in the
139                  * processor capabilities buffer matches what the hypervisor
140                  * driver supports.
141                  */
142                 xen_sanitize_proc_cap_bits(cap);
143         }
144 }
145
146 static inline bool acpi_has_cpu_in_madt(void)
147 {
148         return !!acpi_lapic;
149 }
150
151 #define ACPI_HAVE_ARCH_SET_ROOT_POINTER
152 static inline void acpi_arch_set_root_pointer(u64 addr)
153 {
154         x86_init.acpi.set_root_pointer(addr);
155 }
156
157 #define ACPI_HAVE_ARCH_GET_ROOT_POINTER
158 static inline u64 acpi_arch_get_root_pointer(void)
159 {
160         return x86_init.acpi.get_root_pointer();
161 }
162
163 void acpi_generic_reduced_hw_init(void);
164
165 void x86_default_set_root_pointer(u64 addr);
166 u64 x86_default_get_root_pointer(void);
167
168 #else /* !CONFIG_ACPI */
169
170 #define acpi_lapic 0
171 #define acpi_ioapic 0
172 #define acpi_disable_cmcff 0
173 static inline void acpi_noirq_set(void) { }
174 static inline void acpi_disable_pci(void) { }
175 static inline void disable_acpi(void) { }
176
177 static inline void acpi_generic_reduced_hw_init(void) { }
178
179 static inline void x86_default_set_root_pointer(u64 addr) { }
180
181 static inline u64 x86_default_get_root_pointer(void)
182 {
183         return 0;
184 }
185
186 #endif /* !CONFIG_ACPI */
187
188 #define ARCH_HAS_POWER_INIT     1
189
190 #ifdef CONFIG_ACPI_NUMA
191 extern int x86_acpi_numa_init(void);
192 #endif /* CONFIG_ACPI_NUMA */
193
194 struct cper_ia_proc_ctx;
195
196 #ifdef CONFIG_ACPI_APEI
197 static inline pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr)
198 {
199         /*
200          * We currently have no way to look up the EFI memory map
201          * attributes for a region in a consistent way, because the
202          * memmap is discarded after efi_free_boot_services(). So if
203          * you call efi_mem_attributes() during boot and at runtime,
204          * you could theoretically see different attributes.
205          *
206          * We are yet to see any x86 platforms that require anything
207          * other than PAGE_KERNEL (some ARM64 platforms require the
208          * equivalent of PAGE_KERNEL_NOCACHE). Additionally, if SME
209          * is active, the ACPI information will not be encrypted,
210          * so return PAGE_KERNEL_NOENC until we know differently.
211          */
212         return PAGE_KERNEL_NOENC;
213 }
214
215 int arch_apei_report_x86_error(struct cper_ia_proc_ctx *ctx_info,
216                                u64 lapic_id);
217 #else
218 static inline int arch_apei_report_x86_error(struct cper_ia_proc_ctx *ctx_info,
219                                              u64 lapic_id)
220 {
221         return -EINVAL;
222 }
223 #endif
224
225 #define ACPI_TABLE_UPGRADE_MAX_PHYS (max_low_pfn_mapped << PAGE_SHIFT)
226
227 #endif /* _ASM_X86_ACPI_H */