18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_ACPI_H
38c2ecf20Sopenharmony_ci#define _ASM_X86_ACPI_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci *  Copyright (C) 2001 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
78c2ecf20Sopenharmony_ci *  Copyright (C) 2001 Patrick Mochel <mochel@osdl.org>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#include <acpi/pdc_intel.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <asm/numa.h>
128c2ecf20Sopenharmony_ci#include <asm/fixmap.h>
138c2ecf20Sopenharmony_ci#include <asm/processor.h>
148c2ecf20Sopenharmony_ci#include <asm/mmu.h>
158c2ecf20Sopenharmony_ci#include <asm/mpspec.h>
168c2ecf20Sopenharmony_ci#include <asm/x86_init.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI_APEI
198c2ecf20Sopenharmony_ci# include <asm/pgtable_types.h>
208c2ecf20Sopenharmony_ci#endif
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI
238c2ecf20Sopenharmony_ciextern int acpi_lapic;
248c2ecf20Sopenharmony_ciextern int acpi_ioapic;
258c2ecf20Sopenharmony_ciextern int acpi_noirq;
268c2ecf20Sopenharmony_ciextern int acpi_strict;
278c2ecf20Sopenharmony_ciextern int acpi_disabled;
288c2ecf20Sopenharmony_ciextern int acpi_pci_disabled;
298c2ecf20Sopenharmony_ciextern int acpi_skip_timer_override;
308c2ecf20Sopenharmony_ciextern int acpi_use_timer_override;
318c2ecf20Sopenharmony_ciextern int acpi_fix_pin2_polarity;
328c2ecf20Sopenharmony_ciextern int acpi_disable_cmcff;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciextern u8 acpi_sci_flags;
358c2ecf20Sopenharmony_ciextern u32 acpi_sci_override_gsi;
368c2ecf20Sopenharmony_civoid acpi_pic_sci_set_trigger(unsigned int, u16);
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistruct device;
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ciextern int (*__acpi_register_gsi)(struct device *dev, u32 gsi,
418c2ecf20Sopenharmony_ci				  int trigger, int polarity);
428c2ecf20Sopenharmony_ciextern void (*__acpi_unregister_gsi)(u32 gsi);
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic inline void disable_acpi(void)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci	acpi_disabled = 1;
478c2ecf20Sopenharmony_ci	acpi_pci_disabled = 1;
488c2ecf20Sopenharmony_ci	acpi_noirq = 1;
498c2ecf20Sopenharmony_ci}
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ciextern int acpi_gsi_to_irq(u32 gsi, unsigned int *irq);
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistatic inline void acpi_noirq_set(void) { acpi_noirq = 1; }
548c2ecf20Sopenharmony_cistatic inline void acpi_disable_pci(void)
558c2ecf20Sopenharmony_ci{
568c2ecf20Sopenharmony_ci	acpi_pci_disabled = 1;
578c2ecf20Sopenharmony_ci	acpi_noirq_set();
588c2ecf20Sopenharmony_ci}
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/* Low-level suspend routine. */
618c2ecf20Sopenharmony_ciextern int (*acpi_suspend_lowlevel)(void);
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/* Physical address to resume after wakeup */
648c2ecf20Sopenharmony_ciunsigned long acpi_get_wakeup_address(void);
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci/*
678c2ecf20Sopenharmony_ci * Check if the CPU can handle C2 and deeper
688c2ecf20Sopenharmony_ci */
698c2ecf20Sopenharmony_cistatic inline unsigned int acpi_processor_cstate_check(unsigned int max_cstate)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	/*
728c2ecf20Sopenharmony_ci	 * Early models (<=5) of AMD Opterons are not supposed to go into
738c2ecf20Sopenharmony_ci	 * C2 state.
748c2ecf20Sopenharmony_ci	 *
758c2ecf20Sopenharmony_ci	 * Steppings 0x0A and later are good
768c2ecf20Sopenharmony_ci	 */
778c2ecf20Sopenharmony_ci	if (boot_cpu_data.x86 == 0x0F &&
788c2ecf20Sopenharmony_ci	    boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
798c2ecf20Sopenharmony_ci	    boot_cpu_data.x86_model <= 0x05 &&
808c2ecf20Sopenharmony_ci	    boot_cpu_data.x86_stepping < 0x0A)
818c2ecf20Sopenharmony_ci		return 1;
828c2ecf20Sopenharmony_ci	else if (boot_cpu_has(X86_BUG_AMD_APIC_C1E))
838c2ecf20Sopenharmony_ci		return 1;
848c2ecf20Sopenharmony_ci	else
858c2ecf20Sopenharmony_ci		return max_cstate;
868c2ecf20Sopenharmony_ci}
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistatic inline bool arch_has_acpi_pdc(void)
898c2ecf20Sopenharmony_ci{
908c2ecf20Sopenharmony_ci	struct cpuinfo_x86 *c = &cpu_data(0);
918c2ecf20Sopenharmony_ci	return (c->x86_vendor == X86_VENDOR_INTEL ||
928c2ecf20Sopenharmony_ci		c->x86_vendor == X86_VENDOR_CENTAUR);
938c2ecf20Sopenharmony_ci}
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_cistatic inline void arch_acpi_set_pdc_bits(u32 *buf)
968c2ecf20Sopenharmony_ci{
978c2ecf20Sopenharmony_ci	struct cpuinfo_x86 *c = &cpu_data(0);
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	buf[2] |= ACPI_PDC_C_CAPABILITY_SMP;
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	if (cpu_has(c, X86_FEATURE_EST))
1028c2ecf20Sopenharmony_ci		buf[2] |= ACPI_PDC_EST_CAPABILITY_SWSMP;
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	if (cpu_has(c, X86_FEATURE_ACPI))
1058c2ecf20Sopenharmony_ci		buf[2] |= ACPI_PDC_T_FFH;
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	/*
1088c2ecf20Sopenharmony_ci	 * If mwait/monitor is unsupported, C2/C3_FFH will be disabled
1098c2ecf20Sopenharmony_ci	 */
1108c2ecf20Sopenharmony_ci	if (!cpu_has(c, X86_FEATURE_MWAIT))
1118c2ecf20Sopenharmony_ci		buf[2] &= ~(ACPI_PDC_C_C2C3_FFH);
1128c2ecf20Sopenharmony_ci}
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistatic inline bool acpi_has_cpu_in_madt(void)
1158c2ecf20Sopenharmony_ci{
1168c2ecf20Sopenharmony_ci	return !!acpi_lapic;
1178c2ecf20Sopenharmony_ci}
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci#define ACPI_HAVE_ARCH_SET_ROOT_POINTER
1208c2ecf20Sopenharmony_cistatic inline void acpi_arch_set_root_pointer(u64 addr)
1218c2ecf20Sopenharmony_ci{
1228c2ecf20Sopenharmony_ci	x86_init.acpi.set_root_pointer(addr);
1238c2ecf20Sopenharmony_ci}
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci#define ACPI_HAVE_ARCH_GET_ROOT_POINTER
1268c2ecf20Sopenharmony_cistatic inline u64 acpi_arch_get_root_pointer(void)
1278c2ecf20Sopenharmony_ci{
1288c2ecf20Sopenharmony_ci	return x86_init.acpi.get_root_pointer();
1298c2ecf20Sopenharmony_ci}
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_civoid acpi_generic_reduced_hw_init(void);
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_civoid x86_default_set_root_pointer(u64 addr);
1348c2ecf20Sopenharmony_ciu64 x86_default_get_root_pointer(void);
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci#else /* !CONFIG_ACPI */
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci#define acpi_lapic 0
1398c2ecf20Sopenharmony_ci#define acpi_ioapic 0
1408c2ecf20Sopenharmony_ci#define acpi_disable_cmcff 0
1418c2ecf20Sopenharmony_cistatic inline void acpi_noirq_set(void) { }
1428c2ecf20Sopenharmony_cistatic inline void acpi_disable_pci(void) { }
1438c2ecf20Sopenharmony_cistatic inline void disable_acpi(void) { }
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistatic inline void acpi_generic_reduced_hw_init(void) { }
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_cistatic inline void x86_default_set_root_pointer(u64 addr) { }
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_cistatic inline u64 x86_default_get_root_pointer(void)
1508c2ecf20Sopenharmony_ci{
1518c2ecf20Sopenharmony_ci	return 0;
1528c2ecf20Sopenharmony_ci}
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci#endif /* !CONFIG_ACPI */
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci#define ARCH_HAS_POWER_INIT	1
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI_NUMA
1598c2ecf20Sopenharmony_ciextern int x86_acpi_numa_init(void);
1608c2ecf20Sopenharmony_ci#endif /* CONFIG_ACPI_NUMA */
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI_APEI
1638c2ecf20Sopenharmony_cistatic inline pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr)
1648c2ecf20Sopenharmony_ci{
1658c2ecf20Sopenharmony_ci	/*
1668c2ecf20Sopenharmony_ci	 * We currently have no way to look up the EFI memory map
1678c2ecf20Sopenharmony_ci	 * attributes for a region in a consistent way, because the
1688c2ecf20Sopenharmony_ci	 * memmap is discarded after efi_free_boot_services(). So if
1698c2ecf20Sopenharmony_ci	 * you call efi_mem_attributes() during boot and at runtime,
1708c2ecf20Sopenharmony_ci	 * you could theoretically see different attributes.
1718c2ecf20Sopenharmony_ci	 *
1728c2ecf20Sopenharmony_ci	 * We are yet to see any x86 platforms that require anything
1738c2ecf20Sopenharmony_ci	 * other than PAGE_KERNEL (some ARM64 platforms require the
1748c2ecf20Sopenharmony_ci	 * equivalent of PAGE_KERNEL_NOCACHE). Additionally, if SME
1758c2ecf20Sopenharmony_ci	 * is active, the ACPI information will not be encrypted,
1768c2ecf20Sopenharmony_ci	 * so return PAGE_KERNEL_NOENC until we know differently.
1778c2ecf20Sopenharmony_ci	 */
1788c2ecf20Sopenharmony_ci	return PAGE_KERNEL_NOENC;
1798c2ecf20Sopenharmony_ci}
1808c2ecf20Sopenharmony_ci#endif
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci#define ACPI_TABLE_UPGRADE_MAX_PHYS (max_low_pfn_mapped << PAGE_SHIFT)
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci#endif /* _ASM_X86_ACPI_H */
185