xref: /linux/arch/arm64/include/asm/acpi.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
237655163SAl Stone /*
337655163SAl Stone  *  Copyright (C) 2013-2014, Linaro Ltd.
437655163SAl Stone  *	Author: Al Stone <al.stone@linaro.org>
537655163SAl Stone  *	Author: Graeme Gregory <graeme.gregory@linaro.org>
637655163SAl Stone  *	Author: Hanjun Guo <hanjun.guo@linaro.org>
737655163SAl Stone  */
837655163SAl Stone 
937655163SAl Stone #ifndef _ASM_ACPI_H
1037655163SAl Stone #define _ASM_ACPI_H
1137655163SAl Stone 
124785aa80SOza Pawandeep #include <linux/cpuidle.h>
1309ffcb0dSAKASHI Takahiro #include <linux/efi.h>
14e7cd1903SAKASHI Takahiro #include <linux/memblock.h>
15bff60792SMark Rutland #include <linux/psci.h>
16a194c33fSNick Desaulniers #include <linux/stddef.h>
17d60fc389STomasz Nowicki 
18020295b4SHanjun Guo #include <asm/cputype.h>
1909ffcb0dSAKASHI Takahiro #include <asm/io.h>
20d44f1b8dSJames Morse #include <asm/ptrace.h>
21020295b4SHanjun Guo #include <asm/smp_plat.h>
229f9a35a7STomasz Nowicki #include <asm/tlbflush.h>
23652261a7SMark Salter 
24b6cfb277SAl Stone /* Macros for consistency checks of the GICC subtable of MADT */
259eb1c92bSJeremy Linton 
269eb1c92bSJeremy Linton /*
279eb1c92bSJeremy Linton  * MADT GICC minimum length refers to the MADT GICC structure table length as
289eb1c92bSJeremy Linton  * defined in the earliest ACPI version supported on arm64, ie ACPI 5.1.
299eb1c92bSJeremy Linton  *
309eb1c92bSJeremy Linton  * The efficiency_class member was added to the
319eb1c92bSJeremy Linton  * struct acpi_madt_generic_interrupt to represent the MADT GICC structure
329eb1c92bSJeremy Linton  * "Processor Power Efficiency Class" field, added in ACPI 6.0 whose offset
339eb1c92bSJeremy Linton  * is therefore used to delimit the MADT GICC structure minimum length
349eb1c92bSJeremy Linton  * appropriately.
359eb1c92bSJeremy Linton  */
36a194c33fSNick Desaulniers #define ACPI_MADT_GICC_MIN_LENGTH   offsetof(  \
379eb1c92bSJeremy Linton 	struct acpi_madt_generic_interrupt, efficiency_class)
38b6cfb277SAl Stone 
39b6cfb277SAl Stone #define BAD_MADT_GICC_ENTRY(entry, end)					\
409eb1c92bSJeremy Linton 	(!(entry) || (entry)->header.length < ACPI_MADT_GICC_MIN_LENGTH || \
419eb1c92bSJeremy Linton 	(unsigned long)(entry) + (entry)->header.length > (end))
42b6cfb277SAl Stone 
43a194c33fSNick Desaulniers #define ACPI_MADT_GICC_SPE  (offsetof(struct acpi_madt_generic_interrupt, \
44d24a0c70SJeremy Linton 	spe_interrupt) + sizeof(u16))
45d24a0c70SJeremy Linton 
461aa3d027SAnshuman Khandual #define ACPI_MADT_GICC_TRBE  (offsetof(struct acpi_madt_generic_interrupt, \
471aa3d027SAnshuman Khandual 	trbe_interrupt) + sizeof(u16))
484785aa80SOza Pawandeep /*
494785aa80SOza Pawandeep  * Arm® Functional Fixed Hardware Specification Version 1.2.
504785aa80SOza Pawandeep  * Table 2: Arm Architecture context loss flags
514785aa80SOza Pawandeep  */
524785aa80SOza Pawandeep #define CPUIDLE_CORE_CTXT		BIT(0) /* Core context Lost */
534785aa80SOza Pawandeep 
arch_get_idle_state_flags(u32 arch_flags)544785aa80SOza Pawandeep static inline unsigned int arch_get_idle_state_flags(u32 arch_flags)
554785aa80SOza Pawandeep {
564785aa80SOza Pawandeep 	if (arch_flags & CPUIDLE_CORE_CTXT)
574785aa80SOza Pawandeep 		return CPUIDLE_FLAG_TIMER_STOP;
584785aa80SOza Pawandeep 
594785aa80SOza Pawandeep 	return 0;
604785aa80SOza Pawandeep }
614785aa80SOza Pawandeep #define arch_get_idle_state_flags arch_get_idle_state_flags
624785aa80SOza Pawandeep 
634785aa80SOza Pawandeep #define CPUIDLE_TRACE_CTXT		BIT(1) /* Trace context loss */
644785aa80SOza Pawandeep #define CPUIDLE_GICR_CTXT		BIT(2) /* GICR */
654785aa80SOza Pawandeep #define CPUIDLE_GICD_CTXT		BIT(3) /* GICD */
661aa3d027SAnshuman Khandual 
6737655163SAl Stone /* Basic configuration for ACPI */
6837655163SAl Stone #ifdef	CONFIG_ACPI
6909ffcb0dSAKASHI Takahiro pgprot_t __acpi_get_mem_attribute(phys_addr_t addr);
7009ffcb0dSAKASHI Takahiro 
718d3523fbSLv Zheng /* ACPI table mapping after acpi_permanent_mmap is set */
721583052dSArd Biesheuvel void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size);
73652261a7SMark Salter #define acpi_os_ioremap acpi_os_ioremap
74652261a7SMark Salter 
75020295b4SHanjun Guo typedef u64 phys_cpuid_t;
76020295b4SHanjun Guo #define PHYS_CPUID_INVALID INVALID_HWID
77020295b4SHanjun Guo 
7837655163SAl Stone #define acpi_strict 1	/* No out-of-spec workarounds on ARM64 */
7937655163SAl Stone extern int acpi_disabled;
8037655163SAl Stone extern int acpi_noirq;
8137655163SAl Stone extern int acpi_pci_disabled;
8237655163SAl Stone 
disable_acpi(void)8337655163SAl Stone static inline void disable_acpi(void)
8437655163SAl Stone {
8537655163SAl Stone 	acpi_disabled = 1;
8637655163SAl Stone 	acpi_pci_disabled = 1;
8737655163SAl Stone 	acpi_noirq = 1;
8837655163SAl Stone }
8937655163SAl Stone 
enable_acpi(void)90b10d79f7SAl Stone static inline void enable_acpi(void)
91b10d79f7SAl Stone {
92b10d79f7SAl Stone 	acpi_disabled = 0;
93b10d79f7SAl Stone 	acpi_pci_disabled = 0;
94b10d79f7SAl Stone 	acpi_noirq = 0;
95b10d79f7SAl Stone }
96b10d79f7SAl Stone 
9737655163SAl Stone /*
98020295b4SHanjun Guo  * The ACPI processor driver for ACPI core code needs this macro
99020295b4SHanjun Guo  * to find out this cpu was already mapped (mapping from CPU hardware
100020295b4SHanjun Guo  * ID to CPU logical ID) or not.
101020295b4SHanjun Guo  */
102020295b4SHanjun Guo #define cpu_physical_id(cpu) cpu_logical_map(cpu)
103020295b4SHanjun Guo 
104020295b4SHanjun Guo /*
10537655163SAl Stone  * It's used from ACPI core in kdump to boot UP system with SMP kernel,
10637655163SAl Stone  * with this check the ACPI core will not override the CPU index
10737655163SAl Stone  * obtained from GICC with 0 and not print some error message as well.
10837655163SAl Stone  * Since MADT must provide at least one GICC structure for GIC
10937655163SAl Stone  * initialization, CPU will be always available in MADT on ARM64.
11037655163SAl Stone  */
acpi_has_cpu_in_madt(void)11137655163SAl Stone static inline bool acpi_has_cpu_in_madt(void)
11237655163SAl Stone {
11337655163SAl Stone 	return true;
11437655163SAl Stone }
11537655163SAl Stone 
116e0013aedSMark Rutland struct acpi_madt_generic_interrupt *acpi_cpu_get_madt_gicc(int cpu);
get_acpi_id_for_cpu(unsigned int cpu)11730d87bfaSJeremy Linton static inline u32 get_acpi_id_for_cpu(unsigned int cpu)
11830d87bfaSJeremy Linton {
11930d87bfaSJeremy Linton 	return	acpi_cpu_get_madt_gicc(cpu)->uid;
12030d87bfaSJeremy Linton }
121e0013aedSMark Rutland 
get_cpu_for_acpi_id(u32 uid)1228d34b6f1SJames Morse static inline int get_cpu_for_acpi_id(u32 uid)
1238d34b6f1SJames Morse {
1248d34b6f1SJames Morse 	int cpu;
1258d34b6f1SJames Morse 
1268d34b6f1SJames Morse 	for (cpu = 0; cpu < nr_cpu_ids; cpu++)
127*24884442SJonathan Cameron 		if (acpi_cpu_get_madt_gicc(cpu) &&
128*24884442SJonathan Cameron 		    uid == get_acpi_id_for_cpu(cpu))
1298d34b6f1SJames Morse 			return cpu;
1308d34b6f1SJames Morse 
1318d34b6f1SJames Morse 	return -EINVAL;
1328d34b6f1SJames Morse }
1338d34b6f1SJames Morse 
arch_fix_phys_package_id(int num,u32 slot)13437655163SAl Stone static inline void arch_fix_phys_package_id(int num, u32 slot) { }
135fccb9a81SHanjun Guo void __init acpi_init_cpus(void);
136d44f1b8dSJames Morse int apei_claim_sea(struct pt_regs *regs);
1377c59a3dfSGraeme Gregory #else
acpi_init_cpus(void)138fccb9a81SHanjun Guo static inline void acpi_init_cpus(void) { }
apei_claim_sea(struct pt_regs * regs)139d44f1b8dSJames Morse static inline int apei_claim_sea(struct pt_regs *regs) { return -ENOENT; }
14037655163SAl Stone #endif /* CONFIG_ACPI */
14137655163SAl Stone 
1425e89c55eSLorenzo Pieralisi #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
1435e89c55eSLorenzo Pieralisi bool acpi_parking_protocol_valid(int cpu);
1445e89c55eSLorenzo Pieralisi void __init
1455e89c55eSLorenzo Pieralisi acpi_set_mailbox_entry(int cpu, struct acpi_madt_generic_interrupt *processor);
1465e89c55eSLorenzo Pieralisi #else
acpi_parking_protocol_valid(int cpu)1475e89c55eSLorenzo Pieralisi static inline bool acpi_parking_protocol_valid(int cpu) { return false; }
1485e89c55eSLorenzo Pieralisi static inline void
acpi_set_mailbox_entry(int cpu,struct acpi_madt_generic_interrupt * processor)1495e89c55eSLorenzo Pieralisi acpi_set_mailbox_entry(int cpu, struct acpi_madt_generic_interrupt *processor)
1505e89c55eSLorenzo Pieralisi {}
1515e89c55eSLorenzo Pieralisi #endif
1525e89c55eSLorenzo Pieralisi 
acpi_get_enable_method(int cpu)1530f078336SLorenzo Pieralisi static inline const char *acpi_get_enable_method(int cpu)
1540f078336SLorenzo Pieralisi {
1555e89c55eSLorenzo Pieralisi 	if (acpi_psci_present())
1565e89c55eSLorenzo Pieralisi 		return "psci";
1575e89c55eSLorenzo Pieralisi 
1585e89c55eSLorenzo Pieralisi 	if (acpi_parking_protocol_valid(cpu))
1595e89c55eSLorenzo Pieralisi 		return "parking-protocol";
1605e89c55eSLorenzo Pieralisi 
1615e89c55eSLorenzo Pieralisi 	return NULL;
1620f078336SLorenzo Pieralisi }
16389e44b51SJonathan (Zhixiong) Zhang 
16489e44b51SJonathan (Zhixiong) Zhang #ifdef	CONFIG_ACPI_APEI
1659f9a35a7STomasz Nowicki /*
1669f9a35a7STomasz Nowicki  * acpi_disable_cmcff is used in drivers/acpi/apei/hest.c for disabling
1679f9a35a7STomasz Nowicki  * IA-32 Architecture Corrected Machine Check (CMC) Firmware-First mode
1689f9a35a7STomasz Nowicki  * with a kernel command line parameter "acpi=nocmcoff". But we don't
1699f9a35a7STomasz Nowicki  * have this IA-32 specific feature on ARM64, this definition is only
1709f9a35a7STomasz Nowicki  * for compatibility.
1719f9a35a7STomasz Nowicki  */
1729f9a35a7STomasz Nowicki #define acpi_disable_cmcff 1
arch_apei_get_mem_attribute(phys_addr_t addr)17309ffcb0dSAKASHI Takahiro static inline pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr)
17409ffcb0dSAKASHI Takahiro {
17509ffcb0dSAKASHI Takahiro 	return __acpi_get_mem_attribute(addr);
17609ffcb0dSAKASHI Takahiro }
1779f9a35a7STomasz Nowicki #endif /* CONFIG_ACPI_APEI */
17889e44b51SJonathan (Zhixiong) Zhang 
179d8b47fcaSHanjun Guo #ifdef CONFIG_ACPI_NUMA
180d8b47fcaSHanjun Guo int arm64_acpi_numa_init(void);
181e1896249SLorenzo Pieralisi int acpi_numa_get_nid(unsigned int cpu);
182e1896249SLorenzo Pieralisi void acpi_map_cpus_to_nodes(void);
183d8b47fcaSHanjun Guo #else
arm64_acpi_numa_init(void)184d8b47fcaSHanjun Guo static inline int arm64_acpi_numa_init(void) { return -ENOSYS; }
acpi_numa_get_nid(unsigned int cpu)185e1896249SLorenzo Pieralisi static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
acpi_map_cpus_to_nodes(void)186e1896249SLorenzo Pieralisi static inline void acpi_map_cpus_to_nodes(void) { }
187d8b47fcaSHanjun Guo #endif /* CONFIG_ACPI_NUMA */
188d8b47fcaSHanjun Guo 
18938b04a74SJon Masters #define ACPI_TABLE_UPGRADE_MAX_PHYS MEMBLOCK_ALLOC_ACCESSIBLE
19038b04a74SJon Masters 
19137655163SAl Stone #endif /*_ASM_ACPI_H*/
192