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