11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
21965aae3SH. Peter Anvin #ifndef _ASM_X86_ACPI_H
31965aae3SH. Peter Anvin #define _ASM_X86_ACPI_H
4bb898558SAl Viro
5bb898558SAl Viro /*
6bb898558SAl Viro * Copyright (C) 2001 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7bb898558SAl Viro * Copyright (C) 2001 Patrick Mochel <mochel@osdl.org>
8bb898558SAl Viro */
9c9e6c5e6SMichal Wilczynski #include <acpi/proc_cap_intel.h>
10bb898558SAl Viro
11bb898558SAl Viro #include <asm/numa.h>
12bee7f9c8SYinghai Lu #include <asm/fixmap.h>
13bb898558SAl Viro #include <asm/processor.h>
14bb898558SAl Viro #include <asm/mmu.h>
15bb898558SAl Viro #include <asm/mpspec.h>
16038bac2bSJuergen Gross #include <asm/x86_init.h>
17fe0ba8c2SJuergen Gross #include <asm/cpufeature.h>
18c6a1fd91SHans de Goede #include <asm/irq_vectors.h>
19bfa993b3SRoger Pau Monne #include <asm/xen/hypervisor.h>
20bfa993b3SRoger Pau Monne
21bfa993b3SRoger Pau Monne #include <xen/xen.h>
22bb898558SAl Viro
23b40227fbSJonathan (Zhixiong) Zhang #ifdef CONFIG_ACPI_APEI
24b40227fbSJonathan (Zhixiong) Zhang # include <asm/pgtable_types.h>
25b40227fbSJonathan (Zhixiong) Zhang #endif
26b40227fbSJonathan (Zhixiong) Zhang
27bb898558SAl Viro #ifdef CONFIG_ACPI
28bb898558SAl Viro extern int acpi_lapic;
29bb898558SAl Viro extern int acpi_ioapic;
30bb898558SAl Viro extern int acpi_noirq;
31bb898558SAl Viro extern int acpi_strict;
32bb898558SAl Viro extern int acpi_disabled;
33bb898558SAl Viro extern int acpi_pci_disabled;
34bb898558SAl Viro extern int acpi_skip_timer_override;
35bb898558SAl Viro extern int acpi_use_timer_override;
367f74f8f2SAndreas Herrmann extern int acpi_fix_pin2_polarity;
379ad95879SNaveen N. Rao extern int acpi_disable_cmcff;
38c6a1fd91SHans de Goede extern bool acpi_int_src_ovr[NR_IRQS_LEGACY];
39bb898558SAl Viro
40bb898558SAl Viro extern u8 acpi_sci_flags;
414565c4f6SAndy Shevchenko extern u32 acpi_sci_override_gsi;
42bb898558SAl Viro void acpi_pic_sci_set_trigger(unsigned int, u16);
43bb898558SAl Viro
4499da1ffeSIngo Molnar struct device;
4599da1ffeSIngo Molnar
4690f6881eSJeremy Fitzhardinge extern int (*__acpi_register_gsi)(struct device *dev, u32 gsi,
4790f6881eSJeremy Fitzhardinge int trigger, int polarity);
488abb850aSJiang Liu extern void (*__acpi_unregister_gsi)(u32 gsi);
4990f6881eSJeremy Fitzhardinge
disable_acpi(void)50bb898558SAl Viro static inline void disable_acpi(void)
51bb898558SAl Viro {
52bb898558SAl Viro acpi_disabled = 1;
53bb898558SAl Viro acpi_pci_disabled = 1;
54bb898558SAl Viro acpi_noirq = 1;
55bb898558SAl Viro }
56bb898558SAl Viro
57bb898558SAl Viro extern int acpi_gsi_to_irq(u32 gsi, unsigned int *irq);
58bb898558SAl Viro
59dfac21b1SKuppuswamy Sathyanarayanan extern int acpi_blacklisted(void);
60dfac21b1SKuppuswamy Sathyanarayanan
acpi_noirq_set(void)61bb898558SAl Viro static inline void acpi_noirq_set(void) { acpi_noirq = 1; }
acpi_disable_pci(void)62bb898558SAl Viro static inline void acpi_disable_pci(void)
63bb898558SAl Viro {
64bb898558SAl Viro acpi_pci_disabled = 1;
65bb898558SAl Viro acpi_noirq_set();
66bb898558SAl Viro }
67bb898558SAl Viro
68f1a2003eSRafael J. Wysocki /* Low-level suspend routine. */
69d6a77eadSKonrad Rzeszutek Wilk extern int (*acpi_suspend_lowlevel)(void);
70bb898558SAl Viro
71319b6ffcSH. Peter Anvin /* Physical address to resume after wakeup */
7296078642SSean Christopherson unsigned long acpi_get_wakeup_address(void);
73bb898558SAl Viro
acpi_skip_set_wakeup_address(void)74fe0ba8c2SJuergen Gross static inline bool acpi_skip_set_wakeup_address(void)
75fe0ba8c2SJuergen Gross {
76fe0ba8c2SJuergen Gross return cpu_feature_enabled(X86_FEATURE_XENPV);
77fe0ba8c2SJuergen Gross }
78fe0ba8c2SJuergen Gross
79fe0ba8c2SJuergen Gross #define acpi_skip_set_wakeup_address acpi_skip_set_wakeup_address
80fe0ba8c2SJuergen Gross
812b5e22afSKirill A. Shutemov union acpi_subtable_headers;
822b5e22afSKirill A. Shutemov
832b5e22afSKirill A. Shutemov int __init acpi_parse_mp_wake(union acpi_subtable_headers *header,
842b5e22afSKirill A. Shutemov const unsigned long end);
852b5e22afSKirill A. Shutemov
861ceebe2eSKirill A. Shutemov void asm_acpi_mp_play_dead(u64 reset_vector, u64 pgd_pa);
871ceebe2eSKirill A. Shutemov
88bb898558SAl Viro /*
89bb898558SAl Viro * Check if the CPU can handle C2 and deeper
90bb898558SAl Viro */
acpi_processor_cstate_check(unsigned int max_cstate)91bb898558SAl Viro static inline unsigned int acpi_processor_cstate_check(unsigned int max_cstate)
92bb898558SAl Viro {
93bb898558SAl Viro /*
94bb898558SAl Viro * Early models (<=5) of AMD Opterons are not supposed to go into
95bb898558SAl Viro * C2 state.
96bb898558SAl Viro *
97bb898558SAl Viro * Steppings 0x0A and later are good
98bb898558SAl Viro */
99bb898558SAl Viro if (boot_cpu_data.x86 == 0x0F &&
100bb898558SAl Viro boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
101bb898558SAl Viro boot_cpu_data.x86_model <= 0x05 &&
102b399151cSJia Zhang boot_cpu_data.x86_stepping < 0x0A)
103bb898558SAl Viro return 1;
10407c94a38SBorislav Petkov else if (boot_cpu_has(X86_BUG_AMD_APIC_C1E))
105bb898558SAl Viro return 1;
106bb898558SAl Viro else
107bb898558SAl Viro return max_cstate;
108bb898558SAl Viro }
109bb898558SAl Viro
arch_has_acpi_pdc(void)1101d9cb470SAlex Chiang static inline bool arch_has_acpi_pdc(void)
1111d9cb470SAlex Chiang {
1121d9cb470SAlex Chiang struct cpuinfo_x86 *c = &cpu_data(0);
1131d9cb470SAlex Chiang return (c->x86_vendor == X86_VENDOR_INTEL ||
1141d9cb470SAlex Chiang c->x86_vendor == X86_VENDOR_CENTAUR);
1151d9cb470SAlex Chiang }
1161d9cb470SAlex Chiang
arch_acpi_set_proc_cap_bits(u32 * cap)117c5e4d05dSMichal Wilczynski static inline void arch_acpi_set_proc_cap_bits(u32 *cap)
1186c5807d7SAlex Chiang {
1196c5807d7SAlex Chiang struct cpuinfo_x86 *c = &cpu_data(0);
1206c5807d7SAlex Chiang
121c9e6c5e6SMichal Wilczynski *cap |= ACPI_PROC_CAP_C_CAPABILITY_SMP;
1226c5807d7SAlex Chiang
123b9e8d016SMichal Wilczynski /* Enable coordination with firmware's _TSD info */
124b9e8d016SMichal Wilczynski *cap |= ACPI_PROC_CAP_SMP_T_SWCOORD;
1256c5807d7SAlex Chiang
1266c5807d7SAlex Chiang if (cpu_has(c, X86_FEATURE_EST))
127c9e6c5e6SMichal Wilczynski *cap |= ACPI_PROC_CAP_EST_CAPABILITY_SWSMP;
1286c5807d7SAlex Chiang
1296c5807d7SAlex Chiang if (cpu_has(c, X86_FEATURE_ACPI))
130c9e6c5e6SMichal Wilczynski *cap |= ACPI_PROC_CAP_T_FFH;
1316c5807d7SAlex Chiang
1325ba30be7SMichal Wilczynski if (cpu_has(c, X86_FEATURE_HWP))
1335ba30be7SMichal Wilczynski *cap |= ACPI_PROC_CAP_COLLAB_PROC_PERF;
1346c5807d7SAlex Chiang
1356c5807d7SAlex Chiang /*
1364f37ab5eSMichal Wilczynski * If mwait/monitor is unsupported, C_C1_FFH and
1374f37ab5eSMichal Wilczynski * C2/C3_FFH will be disabled.
1386c5807d7SAlex Chiang */
1394f37ab5eSMichal Wilczynski if (!cpu_has(c, X86_FEATURE_MWAIT) ||
1404f37ab5eSMichal Wilczynski boot_option_idle_override == IDLE_NOMWAIT)
1414f37ab5eSMichal Wilczynski *cap &= ~(ACPI_PROC_CAP_C_C1_FFH | ACPI_PROC_CAP_C_C2C3_FFH);
142bfa993b3SRoger Pau Monne
143bfa993b3SRoger Pau Monne if (xen_initial_domain()) {
144bfa993b3SRoger Pau Monne /*
145bfa993b3SRoger Pau Monne * When Linux is running as Xen dom0, the hypervisor is the
146bfa993b3SRoger Pau Monne * entity in charge of the processor power management, and so
147bfa993b3SRoger Pau Monne * Xen needs to check the OS capabilities reported in the
148bfa993b3SRoger Pau Monne * processor capabilities buffer matches what the hypervisor
149bfa993b3SRoger Pau Monne * driver supports.
150bfa993b3SRoger Pau Monne */
151bfa993b3SRoger Pau Monne xen_sanitize_proc_cap_bits(cap);
152bfa993b3SRoger Pau Monne }
1536c5807d7SAlex Chiang }
1546c5807d7SAlex Chiang
acpi_has_cpu_in_madt(void)155b50154d5SGraeme Gregory static inline bool acpi_has_cpu_in_madt(void)
156b50154d5SGraeme Gregory {
157b50154d5SGraeme Gregory return !!acpi_lapic;
158b50154d5SGraeme Gregory }
159b50154d5SGraeme Gregory
16041fa1ee9SJosh Boyer #define ACPI_HAVE_ARCH_SET_ROOT_POINTER
acpi_arch_set_root_pointer(u64 addr)16141fa1ee9SJosh Boyer static inline void acpi_arch_set_root_pointer(u64 addr)
16241fa1ee9SJosh Boyer {
16341fa1ee9SJosh Boyer x86_init.acpi.set_root_pointer(addr);
16441fa1ee9SJosh Boyer }
16541fa1ee9SJosh Boyer
166038bac2bSJuergen Gross #define ACPI_HAVE_ARCH_GET_ROOT_POINTER
acpi_arch_get_root_pointer(void)167038bac2bSJuergen Gross static inline u64 acpi_arch_get_root_pointer(void)
168038bac2bSJuergen Gross {
169038bac2bSJuergen Gross return x86_init.acpi.get_root_pointer();
170038bac2bSJuergen Gross }
171038bac2bSJuergen Gross
17250beba07SAndy Shevchenko void acpi_generic_reduced_hw_init(void);
17350beba07SAndy Shevchenko
17441fa1ee9SJosh Boyer void x86_default_set_root_pointer(u64 addr);
175e7b66d16SJuergen Gross u64 x86_default_get_root_pointer(void);
176e7b66d16SJuergen Gross
177*9221222cSJuergen Gross #ifdef CONFIG_XEN_PV
178*9221222cSJuergen Gross /* A Xen PV domain needs a special acpi_os_ioremap() handling. */
179*9221222cSJuergen Gross extern void __iomem * (*acpi_os_ioremap)(acpi_physical_address phys,
180*9221222cSJuergen Gross acpi_size size);
181*9221222cSJuergen Gross void __iomem *x86_acpi_os_ioremap(acpi_physical_address phys, acpi_size size);
182*9221222cSJuergen Gross #define acpi_os_ioremap acpi_os_ioremap
183*9221222cSJuergen Gross #endif
184*9221222cSJuergen Gross
185bb898558SAl Viro #else /* !CONFIG_ACPI */
186bb898558SAl Viro
187bb898558SAl Viro #define acpi_lapic 0
188bb898558SAl Viro #define acpi_ioapic 0
1899ad95879SNaveen N. Rao #define acpi_disable_cmcff 0
acpi_noirq_set(void)190bb898558SAl Viro static inline void acpi_noirq_set(void) { }
acpi_disable_pci(void)191bb898558SAl Viro static inline void acpi_disable_pci(void) { }
disable_acpi(void)192bb898558SAl Viro static inline void disable_acpi(void) { }
193bb898558SAl Viro
acpi_generic_reduced_hw_init(void)19450beba07SAndy Shevchenko static inline void acpi_generic_reduced_hw_init(void) { }
19550beba07SAndy Shevchenko
x86_default_set_root_pointer(u64 addr)19641fa1ee9SJosh Boyer static inline void x86_default_set_root_pointer(u64 addr) { }
19741fa1ee9SJosh Boyer
x86_default_get_root_pointer(void)198e7b66d16SJuergen Gross static inline u64 x86_default_get_root_pointer(void)
199e7b66d16SJuergen Gross {
200e7b66d16SJuergen Gross return 0;
201e7b66d16SJuergen Gross }
202e7b66d16SJuergen Gross
203bb898558SAl Viro #endif /* !CONFIG_ACPI */
204bb898558SAl Viro
205bb898558SAl Viro #define ARCH_HAS_POWER_INIT 1
206bb898558SAl Viro
207bb898558SAl Viro #ifdef CONFIG_ACPI_NUMA
208a9aec56aSTejun Heo extern int x86_acpi_numa_init(void);
2094e76f4e6SDavid Rientjes #endif /* CONFIG_ACPI_NUMA */
210bb898558SAl Viro
2114a24d80bSSmita Koralahalli struct cper_ia_proc_ctx;
2124a24d80bSSmita Koralahalli
213b40227fbSJonathan (Zhixiong) Zhang #ifdef CONFIG_ACPI_APEI
arch_apei_get_mem_attribute(phys_addr_t addr)214b40227fbSJonathan (Zhixiong) Zhang static inline pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr)
215b40227fbSJonathan (Zhixiong) Zhang {
216b40227fbSJonathan (Zhixiong) Zhang /*
217b40227fbSJonathan (Zhixiong) Zhang * We currently have no way to look up the EFI memory map
218b40227fbSJonathan (Zhixiong) Zhang * attributes for a region in a consistent way, because the
219b40227fbSJonathan (Zhixiong) Zhang * memmap is discarded after efi_free_boot_services(). So if
220b40227fbSJonathan (Zhixiong) Zhang * you call efi_mem_attributes() during boot and at runtime,
221b40227fbSJonathan (Zhixiong) Zhang * you could theoretically see different attributes.
222b40227fbSJonathan (Zhixiong) Zhang *
22357bd1905STom Lendacky * We are yet to see any x86 platforms that require anything
22457bd1905STom Lendacky * other than PAGE_KERNEL (some ARM64 platforms require the
22557bd1905STom Lendacky * equivalent of PAGE_KERNEL_NOCACHE). Additionally, if SME
22657bd1905STom Lendacky * is active, the ACPI information will not be encrypted,
22757bd1905STom Lendacky * so return PAGE_KERNEL_NOENC until we know differently.
228b40227fbSJonathan (Zhixiong) Zhang */
22957bd1905STom Lendacky return PAGE_KERNEL_NOENC;
230b40227fbSJonathan (Zhixiong) Zhang }
2314a24d80bSSmita Koralahalli
2324a24d80bSSmita Koralahalli int arch_apei_report_x86_error(struct cper_ia_proc_ctx *ctx_info,
2334a24d80bSSmita Koralahalli u64 lapic_id);
2344a24d80bSSmita Koralahalli #else
arch_apei_report_x86_error(struct cper_ia_proc_ctx * ctx_info,u64 lapic_id)2354a24d80bSSmita Koralahalli static inline int arch_apei_report_x86_error(struct cper_ia_proc_ctx *ctx_info,
2364a24d80bSSmita Koralahalli u64 lapic_id)
2374a24d80bSSmita Koralahalli {
2384a24d80bSSmita Koralahalli return -EINVAL;
2394a24d80bSSmita Koralahalli }
240b40227fbSJonathan (Zhixiong) Zhang #endif
241b40227fbSJonathan (Zhixiong) Zhang
24284b06ca3SAleksey Makarov #define ACPI_TABLE_UPGRADE_MAX_PHYS (max_low_pfn_mapped << PAGE_SHIFT)
24384b06ca3SAleksey Makarov
2441965aae3SH. Peter Anvin #endif /* _ASM_X86_ACPI_H */
245