blob: ada0bc480a1b26e01ecb7e903149ce03d8e7e269 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Al Stone37655162015-03-24 14:02:37 +00002/*
3 * Copyright (C) 2013-2014, Linaro Ltd.
4 * Author: Al Stone <al.stone@linaro.org>
5 * Author: Graeme Gregory <graeme.gregory@linaro.org>
6 * Author: Hanjun Guo <hanjun.guo@linaro.org>
Al Stone37655162015-03-24 14:02:37 +00007 */
8
9#ifndef _ASM_ACPI_H
10#define _ASM_ACPI_H
11
AKASHI Takahiro09ffcb0d2018-07-23 10:57:32 +090012#include <linux/efi.h>
AKASHI Takahiroe7cd1902016-08-22 15:55:24 +090013#include <linux/memblock.h>
Mark Rutlandbff60792015-07-31 15:46:16 +010014#include <linux/psci.h>
Tomasz Nowickid60fc382015-03-24 14:02:49 +000015
Hanjun Guo020295b2015-03-24 14:02:47 +000016#include <asm/cputype.h>
AKASHI Takahiro09ffcb0d2018-07-23 10:57:32 +090017#include <asm/io.h>
James Morsed44f1b82019-01-29 18:48:50 +000018#include <asm/ptrace.h>
Hanjun Guo020295b2015-03-24 14:02:47 +000019#include <asm/smp_plat.h>
Tomasz Nowicki9f9a35a2016-12-01 21:51:12 +080020#include <asm/tlbflush.h>
Mark Salter652261a2015-03-24 14:02:38 +000021
Al Stoneb6cfb272015-07-06 17:16:47 -060022/* Macros for consistency checks of the GICC subtable of MADT */
Jeremy Linton9eb1c922018-11-27 17:59:12 +000023
24/*
25 * MADT GICC minimum length refers to the MADT GICC structure table length as
26 * defined in the earliest ACPI version supported on arm64, ie ACPI 5.1.
27 *
28 * The efficiency_class member was added to the
29 * struct acpi_madt_generic_interrupt to represent the MADT GICC structure
30 * "Processor Power Efficiency Class" field, added in ACPI 6.0 whose offset
31 * is therefore used to delimit the MADT GICC structure minimum length
32 * appropriately.
33 */
34#define ACPI_MADT_GICC_MIN_LENGTH ACPI_OFFSET( \
35 struct acpi_madt_generic_interrupt, efficiency_class)
Al Stoneb6cfb272015-07-06 17:16:47 -060036
Lorenzo Pieralisicb7cf772017-05-26 17:40:02 +010037#define BAD_MADT_GICC_ENTRY(entry, end) \
Jeremy Linton9eb1c922018-11-27 17:59:12 +000038 (!(entry) || (entry)->header.length < ACPI_MADT_GICC_MIN_LENGTH || \
39 (unsigned long)(entry) + (entry)->header.length > (end))
Al Stoneb6cfb272015-07-06 17:16:47 -060040
Al Stone37655162015-03-24 14:02:37 +000041/* Basic configuration for ACPI */
42#ifdef CONFIG_ACPI
AKASHI Takahiro09ffcb0d2018-07-23 10:57:32 +090043pgprot_t __acpi_get_mem_attribute(phys_addr_t addr);
44
Lv Zheng8d3523f2016-12-14 15:04:46 +080045/* ACPI table mapping after acpi_permanent_mmap is set */
Mark Salter652261a2015-03-24 14:02:38 +000046static inline void __iomem *acpi_os_ioremap(acpi_physical_address phys,
47 acpi_size size)
48{
AKASHI Takahiro09ffcb0d2018-07-23 10:57:32 +090049 /* For normal memory we already have a cacheable mapping. */
50 if (memblock_is_map_memory(phys))
51 return (void __iomem *)__phys_to_virt(phys);
Mark Salter652261a2015-03-24 14:02:38 +000052
AKASHI Takahiro09ffcb0d2018-07-23 10:57:32 +090053 /*
54 * We should still honor the memory's attribute here because
55 * crash dump kernel possibly excludes some ACPI (reclaim)
56 * regions from memblock list.
57 */
58 return __ioremap(phys, size, __acpi_get_mem_attribute(phys));
Mark Salter652261a2015-03-24 14:02:38 +000059}
60#define acpi_os_ioremap acpi_os_ioremap
61
Hanjun Guo020295b2015-03-24 14:02:47 +000062typedef u64 phys_cpuid_t;
63#define PHYS_CPUID_INVALID INVALID_HWID
64
Al Stone37655162015-03-24 14:02:37 +000065#define acpi_strict 1 /* No out-of-spec workarounds on ARM64 */
66extern int acpi_disabled;
67extern int acpi_noirq;
68extern int acpi_pci_disabled;
69
70static inline void disable_acpi(void)
71{
72 acpi_disabled = 1;
73 acpi_pci_disabled = 1;
74 acpi_noirq = 1;
75}
76
Al Stoneb10d79f2015-03-24 14:02:41 +000077static inline void enable_acpi(void)
78{
79 acpi_disabled = 0;
80 acpi_pci_disabled = 0;
81 acpi_noirq = 0;
82}
83
Al Stone37655162015-03-24 14:02:37 +000084/*
Hanjun Guo020295b2015-03-24 14:02:47 +000085 * The ACPI processor driver for ACPI core code needs this macro
86 * to find out this cpu was already mapped (mapping from CPU hardware
87 * ID to CPU logical ID) or not.
88 */
89#define cpu_physical_id(cpu) cpu_logical_map(cpu)
90
91/*
Al Stone37655162015-03-24 14:02:37 +000092 * It's used from ACPI core in kdump to boot UP system with SMP kernel,
93 * with this check the ACPI core will not override the CPU index
94 * obtained from GICC with 0 and not print some error message as well.
95 * Since MADT must provide at least one GICC structure for GIC
96 * initialization, CPU will be always available in MADT on ARM64.
97 */
98static inline bool acpi_has_cpu_in_madt(void)
99{
100 return true;
101}
102
Mark Rutlande0013ae2017-04-11 09:39:54 +0100103struct acpi_madt_generic_interrupt *acpi_cpu_get_madt_gicc(int cpu);
Jeremy Linton30d87bf2018-05-11 18:57:59 -0500104static inline u32 get_acpi_id_for_cpu(unsigned int cpu)
105{
106 return acpi_cpu_get_madt_gicc(cpu)->uid;
107}
Mark Rutlande0013ae2017-04-11 09:39:54 +0100108
Al Stone37655162015-03-24 14:02:37 +0000109static inline void arch_fix_phys_package_id(int num, u32 slot) { }
Hanjun Guofccb9a82015-03-24 22:02:45 +0800110void __init acpi_init_cpus(void);
James Morsed44f1b82019-01-29 18:48:50 +0000111int apei_claim_sea(struct pt_regs *regs);
Graeme Gregory7c59a3d2015-03-24 14:02:43 +0000112#else
Hanjun Guofccb9a82015-03-24 22:02:45 +0800113static inline void acpi_init_cpus(void) { }
James Morsed44f1b82019-01-29 18:48:50 +0000114static inline int apei_claim_sea(struct pt_regs *regs) { return -ENOENT; }
Al Stone37655162015-03-24 14:02:37 +0000115#endif /* CONFIG_ACPI */
116
Lorenzo Pieralisi5e89c552016-01-26 11:10:38 +0000117#ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
118bool acpi_parking_protocol_valid(int cpu);
119void __init
120acpi_set_mailbox_entry(int cpu, struct acpi_madt_generic_interrupt *processor);
121#else
122static inline bool acpi_parking_protocol_valid(int cpu) { return false; }
123static inline void
124acpi_set_mailbox_entry(int cpu, struct acpi_madt_generic_interrupt *processor)
125{}
126#endif
127
Lorenzo Pieralisi0f078332015-05-13 14:12:47 +0100128static inline const char *acpi_get_enable_method(int cpu)
129{
Lorenzo Pieralisi5e89c552016-01-26 11:10:38 +0000130 if (acpi_psci_present())
131 return "psci";
132
133 if (acpi_parking_protocol_valid(cpu))
134 return "parking-protocol";
135
136 return NULL;
Lorenzo Pieralisi0f078332015-05-13 14:12:47 +0100137}
Jonathan (Zhixiong) Zhang89e44b52015-09-04 14:11:41 +0100138
139#ifdef CONFIG_ACPI_APEI
Tomasz Nowicki9f9a35a2016-12-01 21:51:12 +0800140/*
141 * acpi_disable_cmcff is used in drivers/acpi/apei/hest.c for disabling
142 * IA-32 Architecture Corrected Machine Check (CMC) Firmware-First mode
143 * with a kernel command line parameter "acpi=nocmcoff". But we don't
144 * have this IA-32 specific feature on ARM64, this definition is only
145 * for compatibility.
146 */
147#define acpi_disable_cmcff 1
AKASHI Takahiro09ffcb0d2018-07-23 10:57:32 +0900148static inline pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr)
149{
150 return __acpi_get_mem_attribute(addr);
151}
Tomasz Nowicki9f9a35a2016-12-01 21:51:12 +0800152#endif /* CONFIG_ACPI_APEI */
Jonathan (Zhixiong) Zhang89e44b52015-09-04 14:11:41 +0100153
Hanjun Guod8b47fc2016-05-24 15:35:44 -0700154#ifdef CONFIG_ACPI_NUMA
155int arm64_acpi_numa_init(void);
Lorenzo Pieralisie1896242018-06-25 14:05:52 +0100156int acpi_numa_get_nid(unsigned int cpu);
157void acpi_map_cpus_to_nodes(void);
Hanjun Guod8b47fc2016-05-24 15:35:44 -0700158#else
159static inline int arm64_acpi_numa_init(void) { return -ENOSYS; }
Lorenzo Pieralisie1896242018-06-25 14:05:52 +0100160static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
161static inline void acpi_map_cpus_to_nodes(void) { }
Hanjun Guod8b47fc2016-05-24 15:35:44 -0700162#endif /* CONFIG_ACPI_NUMA */
163
Jon Masters38b04a72016-06-20 13:56:13 +0300164#define ACPI_TABLE_UPGRADE_MAX_PHYS MEMBLOCK_ALLOC_ACCESSIBLE
165
Al Stone37655162015-03-24 14:02:37 +0000166#endif /*_ASM_ACPI_H*/