xref: /openbmc/linux/arch/x86/include/asm/acpi.h (revision 41fa1ee9)
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  */
9bb898558SAl Viro #include <acpi/pdc_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>
16319b6ffcSH. Peter Anvin #include <asm/realmode.h>
17038bac2bSJuergen Gross #include <asm/x86_init.h>
18bb898558SAl Viro 
19b40227fbSJonathan (Zhixiong) Zhang #ifdef CONFIG_ACPI_APEI
20b40227fbSJonathan (Zhixiong) Zhang # include <asm/pgtable_types.h>
21b40227fbSJonathan (Zhixiong) Zhang #endif
22b40227fbSJonathan (Zhixiong) Zhang 
23bb898558SAl Viro #ifdef CONFIG_ACPI
24bb898558SAl Viro extern int acpi_lapic;
25bb898558SAl Viro extern int acpi_ioapic;
26bb898558SAl Viro extern int acpi_noirq;
27bb898558SAl Viro extern int acpi_strict;
28bb898558SAl Viro extern int acpi_disabled;
29bb898558SAl Viro extern int acpi_pci_disabled;
30bb898558SAl Viro extern int acpi_skip_timer_override;
31bb898558SAl Viro extern int acpi_use_timer_override;
327f74f8f2SAndreas Herrmann extern int acpi_fix_pin2_polarity;
339ad95879SNaveen N. Rao extern int acpi_disable_cmcff;
34bb898558SAl Viro 
35bb898558SAl Viro extern u8 acpi_sci_flags;
364565c4f6SAndy Shevchenko extern u32 acpi_sci_override_gsi;
37bb898558SAl Viro void acpi_pic_sci_set_trigger(unsigned int, u16);
38bb898558SAl Viro 
3999da1ffeSIngo Molnar struct device;
4099da1ffeSIngo Molnar 
4190f6881eSJeremy Fitzhardinge extern int (*__acpi_register_gsi)(struct device *dev, u32 gsi,
4290f6881eSJeremy Fitzhardinge 				  int trigger, int polarity);
438abb850aSJiang Liu extern void (*__acpi_unregister_gsi)(u32 gsi);
4490f6881eSJeremy Fitzhardinge 
45bb898558SAl Viro static inline void disable_acpi(void)
46bb898558SAl Viro {
47bb898558SAl Viro 	acpi_disabled = 1;
48bb898558SAl Viro 	acpi_pci_disabled = 1;
49bb898558SAl Viro 	acpi_noirq = 1;
50bb898558SAl Viro }
51bb898558SAl Viro 
52bb898558SAl Viro extern int acpi_gsi_to_irq(u32 gsi, unsigned int *irq);
53bb898558SAl Viro 
54bb898558SAl Viro static inline void acpi_noirq_set(void) { acpi_noirq = 1; }
55bb898558SAl Viro static inline void acpi_disable_pci(void)
56bb898558SAl Viro {
57bb898558SAl Viro 	acpi_pci_disabled = 1;
58bb898558SAl Viro 	acpi_noirq_set();
59bb898558SAl Viro }
60bb898558SAl Viro 
61f1a2003eSRafael J. Wysocki /* Low-level suspend routine. */
62d6a77eadSKonrad Rzeszutek Wilk extern int (*acpi_suspend_lowlevel)(void);
63bb898558SAl Viro 
64319b6ffcSH. Peter Anvin /* Physical address to resume after wakeup */
65319b6ffcSH. Peter Anvin #define acpi_wakeup_address ((unsigned long)(real_mode_header->wakeup_start))
66bb898558SAl Viro 
67bb898558SAl Viro /*
68bb898558SAl Viro  * Check if the CPU can handle C2 and deeper
69bb898558SAl Viro  */
70bb898558SAl Viro static inline unsigned int acpi_processor_cstate_check(unsigned int max_cstate)
71bb898558SAl Viro {
72bb898558SAl Viro 	/*
73bb898558SAl Viro 	 * Early models (<=5) of AMD Opterons are not supposed to go into
74bb898558SAl Viro 	 * C2 state.
75bb898558SAl Viro 	 *
76bb898558SAl Viro 	 * Steppings 0x0A and later are good
77bb898558SAl Viro 	 */
78bb898558SAl Viro 	if (boot_cpu_data.x86 == 0x0F &&
79bb898558SAl Viro 	    boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
80bb898558SAl Viro 	    boot_cpu_data.x86_model <= 0x05 &&
81b399151cSJia Zhang 	    boot_cpu_data.x86_stepping < 0x0A)
82bb898558SAl Viro 		return 1;
8307c94a38SBorislav Petkov 	else if (boot_cpu_has(X86_BUG_AMD_APIC_C1E))
84bb898558SAl Viro 		return 1;
85bb898558SAl Viro 	else
86bb898558SAl Viro 		return max_cstate;
87bb898558SAl Viro }
88bb898558SAl Viro 
891d9cb470SAlex Chiang static inline bool arch_has_acpi_pdc(void)
901d9cb470SAlex Chiang {
911d9cb470SAlex Chiang 	struct cpuinfo_x86 *c = &cpu_data(0);
921d9cb470SAlex Chiang 	return (c->x86_vendor == X86_VENDOR_INTEL ||
931d9cb470SAlex Chiang 		c->x86_vendor == X86_VENDOR_CENTAUR);
941d9cb470SAlex Chiang }
951d9cb470SAlex Chiang 
966c5807d7SAlex Chiang static inline void arch_acpi_set_pdc_bits(u32 *buf)
976c5807d7SAlex Chiang {
986c5807d7SAlex Chiang 	struct cpuinfo_x86 *c = &cpu_data(0);
996c5807d7SAlex Chiang 
1006c5807d7SAlex Chiang 	buf[2] |= ACPI_PDC_C_CAPABILITY_SMP;
1016c5807d7SAlex Chiang 
1026c5807d7SAlex Chiang 	if (cpu_has(c, X86_FEATURE_EST))
1036c5807d7SAlex Chiang 		buf[2] |= ACPI_PDC_EST_CAPABILITY_SWSMP;
1046c5807d7SAlex Chiang 
1056c5807d7SAlex Chiang 	if (cpu_has(c, X86_FEATURE_ACPI))
1066c5807d7SAlex Chiang 		buf[2] |= ACPI_PDC_T_FFH;
1076c5807d7SAlex Chiang 
1086c5807d7SAlex Chiang 	/*
1096c5807d7SAlex Chiang 	 * If mwait/monitor is unsupported, C2/C3_FFH will be disabled
1106c5807d7SAlex Chiang 	 */
1116c5807d7SAlex Chiang 	if (!cpu_has(c, X86_FEATURE_MWAIT))
1126c5807d7SAlex Chiang 		buf[2] &= ~(ACPI_PDC_C_C2C3_FFH);
1136c5807d7SAlex Chiang }
1146c5807d7SAlex Chiang 
115b50154d5SGraeme Gregory static inline bool acpi_has_cpu_in_madt(void)
116b50154d5SGraeme Gregory {
117b50154d5SGraeme Gregory 	return !!acpi_lapic;
118b50154d5SGraeme Gregory }
119b50154d5SGraeme Gregory 
12041fa1ee9SJosh Boyer #define ACPI_HAVE_ARCH_SET_ROOT_POINTER
12141fa1ee9SJosh Boyer static inline void acpi_arch_set_root_pointer(u64 addr)
12241fa1ee9SJosh Boyer {
12341fa1ee9SJosh Boyer 	x86_init.acpi.set_root_pointer(addr);
12441fa1ee9SJosh Boyer }
12541fa1ee9SJosh Boyer 
126038bac2bSJuergen Gross #define ACPI_HAVE_ARCH_GET_ROOT_POINTER
127038bac2bSJuergen Gross static inline u64 acpi_arch_get_root_pointer(void)
128038bac2bSJuergen Gross {
129038bac2bSJuergen Gross 	return x86_init.acpi.get_root_pointer();
130038bac2bSJuergen Gross }
131038bac2bSJuergen Gross 
13250beba07SAndy Shevchenko void acpi_generic_reduced_hw_init(void);
13350beba07SAndy Shevchenko 
13441fa1ee9SJosh Boyer void x86_default_set_root_pointer(u64 addr);
135e7b66d16SJuergen Gross u64 x86_default_get_root_pointer(void);
136e7b66d16SJuergen Gross 
137bb898558SAl Viro #else /* !CONFIG_ACPI */
138bb898558SAl Viro 
139bb898558SAl Viro #define acpi_lapic 0
140bb898558SAl Viro #define acpi_ioapic 0
1419ad95879SNaveen N. Rao #define acpi_disable_cmcff 0
142bb898558SAl Viro static inline void acpi_noirq_set(void) { }
143bb898558SAl Viro static inline void acpi_disable_pci(void) { }
144bb898558SAl Viro static inline void disable_acpi(void) { }
145bb898558SAl Viro 
14650beba07SAndy Shevchenko static inline void acpi_generic_reduced_hw_init(void) { }
14750beba07SAndy Shevchenko 
14841fa1ee9SJosh Boyer static inline void x86_default_set_root_pointer(u64 addr) { }
14941fa1ee9SJosh Boyer 
150e7b66d16SJuergen Gross static inline u64 x86_default_get_root_pointer(void)
151e7b66d16SJuergen Gross {
152e7b66d16SJuergen Gross 	return 0;
153e7b66d16SJuergen Gross }
154e7b66d16SJuergen Gross 
155bb898558SAl Viro #endif /* !CONFIG_ACPI */
156bb898558SAl Viro 
157bb898558SAl Viro #define ARCH_HAS_POWER_INIT	1
158bb898558SAl Viro 
159bb898558SAl Viro #ifdef CONFIG_ACPI_NUMA
160a9aec56aSTejun Heo extern int x86_acpi_numa_init(void);
1614e76f4e6SDavid Rientjes #endif /* CONFIG_ACPI_NUMA */
162bb898558SAl Viro 
16367535736SAndy Lutomirski #define acpi_unlazy_tlb(x)	leave_mm(x)
16467535736SAndy Lutomirski 
165b40227fbSJonathan (Zhixiong) Zhang #ifdef CONFIG_ACPI_APEI
166b40227fbSJonathan (Zhixiong) Zhang static inline pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr)
167b40227fbSJonathan (Zhixiong) Zhang {
168b40227fbSJonathan (Zhixiong) Zhang 	/*
169b40227fbSJonathan (Zhixiong) Zhang 	 * We currently have no way to look up the EFI memory map
170b40227fbSJonathan (Zhixiong) Zhang 	 * attributes for a region in a consistent way, because the
171b40227fbSJonathan (Zhixiong) Zhang 	 * memmap is discarded after efi_free_boot_services(). So if
172b40227fbSJonathan (Zhixiong) Zhang 	 * you call efi_mem_attributes() during boot and at runtime,
173b40227fbSJonathan (Zhixiong) Zhang 	 * you could theoretically see different attributes.
174b40227fbSJonathan (Zhixiong) Zhang 	 *
17557bd1905STom Lendacky 	 * We are yet to see any x86 platforms that require anything
17657bd1905STom Lendacky 	 * other than PAGE_KERNEL (some ARM64 platforms require the
17757bd1905STom Lendacky 	 * equivalent of PAGE_KERNEL_NOCACHE). Additionally, if SME
17857bd1905STom Lendacky 	 * is active, the ACPI information will not be encrypted,
17957bd1905STom Lendacky 	 * so return PAGE_KERNEL_NOENC until we know differently.
180b40227fbSJonathan (Zhixiong) Zhang 	 */
18157bd1905STom Lendacky 	return PAGE_KERNEL_NOENC;
182b40227fbSJonathan (Zhixiong) Zhang }
183b40227fbSJonathan (Zhixiong) Zhang #endif
184b40227fbSJonathan (Zhixiong) Zhang 
18584b06ca3SAleksey Makarov #define ACPI_TABLE_UPGRADE_MAX_PHYS (max_low_pfn_mapped << PAGE_SHIFT)
18684b06ca3SAleksey Makarov 
1871965aae3SH. Peter Anvin #endif /* _ASM_X86_ACPI_H */
188