xref: /linux/arch/arm64/include/asm/acpi.h (revision 9eb1c92b47c73249465d388eaa394fe436a3b489)
137655163SAl Stone /*
237655163SAl Stone  *  Copyright (C) 2013-2014, Linaro Ltd.
337655163SAl Stone  *	Author: Al Stone <al.stone@linaro.org>
437655163SAl Stone  *	Author: Graeme Gregory <graeme.gregory@linaro.org>
537655163SAl Stone  *	Author: Hanjun Guo <hanjun.guo@linaro.org>
637655163SAl Stone  *
737655163SAl Stone  *  This program is free software; you can redistribute it and/or modify
837655163SAl Stone  *  it under the terms of the GNU General Public License version 2 as
937655163SAl Stone  *  published by the Free Software Foundation;
1037655163SAl Stone  */
1137655163SAl Stone 
1237655163SAl Stone #ifndef _ASM_ACPI_H
1337655163SAl Stone #define _ASM_ACPI_H
1437655163SAl Stone 
1509ffcb0dSAKASHI Takahiro #include <linux/efi.h>
16e7cd1903SAKASHI Takahiro #include <linux/memblock.h>
17bff60792SMark Rutland #include <linux/psci.h>
18d60fc389STomasz Nowicki 
19020295b4SHanjun Guo #include <asm/cputype.h>
2009ffcb0dSAKASHI Takahiro #include <asm/io.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 */
25*9eb1c92bSJeremy Linton 
26*9eb1c92bSJeremy Linton /*
27*9eb1c92bSJeremy Linton  * MADT GICC minimum length refers to the MADT GICC structure table length as
28*9eb1c92bSJeremy Linton  * defined in the earliest ACPI version supported on arm64, ie ACPI 5.1.
29*9eb1c92bSJeremy Linton  *
30*9eb1c92bSJeremy Linton  * The efficiency_class member was added to the
31*9eb1c92bSJeremy Linton  * struct acpi_madt_generic_interrupt to represent the MADT GICC structure
32*9eb1c92bSJeremy Linton  * "Processor Power Efficiency Class" field, added in ACPI 6.0 whose offset
33*9eb1c92bSJeremy Linton  * is therefore used to delimit the MADT GICC structure minimum length
34*9eb1c92bSJeremy Linton  * appropriately.
35*9eb1c92bSJeremy Linton  */
36*9eb1c92bSJeremy Linton #define ACPI_MADT_GICC_MIN_LENGTH   ACPI_OFFSET(  \
37*9eb1c92bSJeremy Linton 	struct acpi_madt_generic_interrupt, efficiency_class)
38b6cfb277SAl Stone 
39b6cfb277SAl Stone #define BAD_MADT_GICC_ENTRY(entry, end)					\
40*9eb1c92bSJeremy Linton 	(!(entry) || (entry)->header.length < ACPI_MADT_GICC_MIN_LENGTH || \
41*9eb1c92bSJeremy Linton 	(unsigned long)(entry) + (entry)->header.length > (end))
42b6cfb277SAl Stone 
4337655163SAl Stone /* Basic configuration for ACPI */
4437655163SAl Stone #ifdef	CONFIG_ACPI
4509ffcb0dSAKASHI Takahiro pgprot_t __acpi_get_mem_attribute(phys_addr_t addr);
4609ffcb0dSAKASHI Takahiro 
478d3523fbSLv Zheng /* ACPI table mapping after acpi_permanent_mmap is set */
48652261a7SMark Salter static inline void __iomem *acpi_os_ioremap(acpi_physical_address phys,
49652261a7SMark Salter 					    acpi_size size)
50652261a7SMark Salter {
5109ffcb0dSAKASHI Takahiro 	/* For normal memory we already have a cacheable mapping. */
5209ffcb0dSAKASHI Takahiro 	if (memblock_is_map_memory(phys))
5309ffcb0dSAKASHI Takahiro 		return (void __iomem *)__phys_to_virt(phys);
54652261a7SMark Salter 
5509ffcb0dSAKASHI Takahiro 	/*
5609ffcb0dSAKASHI Takahiro 	 * We should still honor the memory's attribute here because
5709ffcb0dSAKASHI Takahiro 	 * crash dump kernel possibly excludes some ACPI (reclaim)
5809ffcb0dSAKASHI Takahiro 	 * regions from memblock list.
5909ffcb0dSAKASHI Takahiro 	 */
6009ffcb0dSAKASHI Takahiro 	return __ioremap(phys, size, __acpi_get_mem_attribute(phys));
61652261a7SMark Salter }
62652261a7SMark Salter #define acpi_os_ioremap acpi_os_ioremap
63652261a7SMark Salter 
64020295b4SHanjun Guo typedef u64 phys_cpuid_t;
65020295b4SHanjun Guo #define PHYS_CPUID_INVALID INVALID_HWID
66020295b4SHanjun Guo 
6737655163SAl Stone #define acpi_strict 1	/* No out-of-spec workarounds on ARM64 */
6837655163SAl Stone extern int acpi_disabled;
6937655163SAl Stone extern int acpi_noirq;
7037655163SAl Stone extern int acpi_pci_disabled;
7137655163SAl Stone 
7237655163SAl Stone static inline void disable_acpi(void)
7337655163SAl Stone {
7437655163SAl Stone 	acpi_disabled = 1;
7537655163SAl Stone 	acpi_pci_disabled = 1;
7637655163SAl Stone 	acpi_noirq = 1;
7737655163SAl Stone }
7837655163SAl Stone 
79b10d79f7SAl Stone static inline void enable_acpi(void)
80b10d79f7SAl Stone {
81b10d79f7SAl Stone 	acpi_disabled = 0;
82b10d79f7SAl Stone 	acpi_pci_disabled = 0;
83b10d79f7SAl Stone 	acpi_noirq = 0;
84b10d79f7SAl Stone }
85b10d79f7SAl Stone 
8637655163SAl Stone /*
87020295b4SHanjun Guo  * The ACPI processor driver for ACPI core code needs this macro
88020295b4SHanjun Guo  * to find out this cpu was already mapped (mapping from CPU hardware
89020295b4SHanjun Guo  * ID to CPU logical ID) or not.
90020295b4SHanjun Guo  */
91020295b4SHanjun Guo #define cpu_physical_id(cpu) cpu_logical_map(cpu)
92020295b4SHanjun Guo 
93020295b4SHanjun Guo /*
9437655163SAl Stone  * It's used from ACPI core in kdump to boot UP system with SMP kernel,
9537655163SAl Stone  * with this check the ACPI core will not override the CPU index
9637655163SAl Stone  * obtained from GICC with 0 and not print some error message as well.
9737655163SAl Stone  * Since MADT must provide at least one GICC structure for GIC
9837655163SAl Stone  * initialization, CPU will be always available in MADT on ARM64.
9937655163SAl Stone  */
10037655163SAl Stone static inline bool acpi_has_cpu_in_madt(void)
10137655163SAl Stone {
10237655163SAl Stone 	return true;
10337655163SAl Stone }
10437655163SAl Stone 
105e0013aedSMark Rutland struct acpi_madt_generic_interrupt *acpi_cpu_get_madt_gicc(int cpu);
10630d87bfaSJeremy Linton static inline u32 get_acpi_id_for_cpu(unsigned int cpu)
10730d87bfaSJeremy Linton {
10830d87bfaSJeremy Linton 	return	acpi_cpu_get_madt_gicc(cpu)->uid;
10930d87bfaSJeremy Linton }
110e0013aedSMark Rutland 
11137655163SAl Stone static inline void arch_fix_phys_package_id(int num, u32 slot) { }
112fccb9a81SHanjun Guo void __init acpi_init_cpus(void);
11337655163SAl Stone 
1147c59a3dfSGraeme Gregory #else
115fccb9a81SHanjun Guo static inline void acpi_init_cpus(void) { }
11637655163SAl Stone #endif /* CONFIG_ACPI */
11737655163SAl Stone 
1185e89c55eSLorenzo Pieralisi #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
1195e89c55eSLorenzo Pieralisi bool acpi_parking_protocol_valid(int cpu);
1205e89c55eSLorenzo Pieralisi void __init
1215e89c55eSLorenzo Pieralisi acpi_set_mailbox_entry(int cpu, struct acpi_madt_generic_interrupt *processor);
1225e89c55eSLorenzo Pieralisi #else
1235e89c55eSLorenzo Pieralisi static inline bool acpi_parking_protocol_valid(int cpu) { return false; }
1245e89c55eSLorenzo Pieralisi static inline void
1255e89c55eSLorenzo Pieralisi acpi_set_mailbox_entry(int cpu, struct acpi_madt_generic_interrupt *processor)
1265e89c55eSLorenzo Pieralisi {}
1275e89c55eSLorenzo Pieralisi #endif
1285e89c55eSLorenzo Pieralisi 
1290f078336SLorenzo Pieralisi static inline const char *acpi_get_enable_method(int cpu)
1300f078336SLorenzo Pieralisi {
1315e89c55eSLorenzo Pieralisi 	if (acpi_psci_present())
1325e89c55eSLorenzo Pieralisi 		return "psci";
1335e89c55eSLorenzo Pieralisi 
1345e89c55eSLorenzo Pieralisi 	if (acpi_parking_protocol_valid(cpu))
1355e89c55eSLorenzo Pieralisi 		return "parking-protocol";
1365e89c55eSLorenzo Pieralisi 
1375e89c55eSLorenzo Pieralisi 	return NULL;
1380f078336SLorenzo Pieralisi }
13989e44b51SJonathan (Zhixiong) Zhang 
14089e44b51SJonathan (Zhixiong) Zhang #ifdef	CONFIG_ACPI_APEI
1419f9a35a7STomasz Nowicki /*
1429f9a35a7STomasz Nowicki  * acpi_disable_cmcff is used in drivers/acpi/apei/hest.c for disabling
1439f9a35a7STomasz Nowicki  * IA-32 Architecture Corrected Machine Check (CMC) Firmware-First mode
1449f9a35a7STomasz Nowicki  * with a kernel command line parameter "acpi=nocmcoff". But we don't
1459f9a35a7STomasz Nowicki  * have this IA-32 specific feature on ARM64, this definition is only
1469f9a35a7STomasz Nowicki  * for compatibility.
1479f9a35a7STomasz Nowicki  */
1489f9a35a7STomasz Nowicki #define acpi_disable_cmcff 1
14909ffcb0dSAKASHI Takahiro static inline pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr)
15009ffcb0dSAKASHI Takahiro {
15109ffcb0dSAKASHI Takahiro 	return __acpi_get_mem_attribute(addr);
15209ffcb0dSAKASHI Takahiro }
1539f9a35a7STomasz Nowicki #endif /* CONFIG_ACPI_APEI */
15489e44b51SJonathan (Zhixiong) Zhang 
155d8b47fcaSHanjun Guo #ifdef CONFIG_ACPI_NUMA
156d8b47fcaSHanjun Guo int arm64_acpi_numa_init(void);
157e1896249SLorenzo Pieralisi int acpi_numa_get_nid(unsigned int cpu);
158e1896249SLorenzo Pieralisi void acpi_map_cpus_to_nodes(void);
159d8b47fcaSHanjun Guo #else
160d8b47fcaSHanjun Guo static inline int arm64_acpi_numa_init(void) { return -ENOSYS; }
161e1896249SLorenzo Pieralisi static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
162e1896249SLorenzo Pieralisi static inline void acpi_map_cpus_to_nodes(void) { }
163d8b47fcaSHanjun Guo #endif /* CONFIG_ACPI_NUMA */
164d8b47fcaSHanjun Guo 
16538b04a74SJon Masters #define ACPI_TABLE_UPGRADE_MAX_PHYS MEMBLOCK_ALLOC_ACCESSIBLE
16638b04a74SJon Masters 
16737655163SAl Stone #endif /*_ASM_ACPI_H*/
168