Path: blob/master/arch/arm64/kernel/acpi_parking_protocol.c
26442 views
// SPDX-License-Identifier: GPL-2.0-only1/*2* ARM64 ACPI Parking Protocol implementation3*4* Authors: Lorenzo Pieralisi <[email protected]>5* Mark Salter <[email protected]>6*/7#include <linux/acpi.h>8#include <linux/mm.h>9#include <linux/types.h>1011#include <asm/cpu_ops.h>1213struct parking_protocol_mailbox {14__le32 cpu_id;15__le32 reserved;16__le64 entry_point;17};1819struct cpu_mailbox_entry {20struct parking_protocol_mailbox __iomem *mailbox;21phys_addr_t mailbox_addr;22u8 version;23u8 gic_cpu_id;24};2526static struct cpu_mailbox_entry cpu_mailbox_entries[NR_CPUS];2728void __init acpi_set_mailbox_entry(int cpu,29struct acpi_madt_generic_interrupt *p)30{31struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];3233cpu_entry->mailbox_addr = p->parked_address;34cpu_entry->version = p->parking_version;35cpu_entry->gic_cpu_id = p->cpu_interface_number;36}3738bool acpi_parking_protocol_valid(int cpu)39{40struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];4142return cpu_entry->mailbox_addr && cpu_entry->version;43}4445static int acpi_parking_protocol_cpu_init(unsigned int cpu)46{47pr_debug("%s: ACPI parked addr=%llx\n", __func__,48cpu_mailbox_entries[cpu].mailbox_addr);4950return 0;51}5253static int acpi_parking_protocol_cpu_prepare(unsigned int cpu)54{55return 0;56}5758static int acpi_parking_protocol_cpu_boot(unsigned int cpu)59{60struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];61struct parking_protocol_mailbox __iomem *mailbox;62u32 cpu_id;6364/*65* Map mailbox memory with attribute device nGnRE (ie ioremap -66* this deviates from the parking protocol specifications since67* the mailboxes are required to be mapped nGnRnE; the attribute68* discrepancy is harmless insofar as the protocol specification69* is concerned).70* If the mailbox is mistakenly allocated in the linear mapping71* by FW ioremap will fail since the mapping will be prevented72* by the kernel (it clashes with the linear mapping attributes73* specifications).74*/75mailbox = ioremap(cpu_entry->mailbox_addr, sizeof(*mailbox));76if (!mailbox)77return -EIO;7879cpu_id = readl_relaxed(&mailbox->cpu_id);80/*81* Check if firmware has set-up the mailbox entry properly82* before kickstarting the respective cpu.83*/84if (cpu_id != ~0U) {85iounmap(mailbox);86return -ENXIO;87}8889/*90* stash the mailbox address mapping to use it for further FW91* checks in the postboot method92*/93cpu_entry->mailbox = mailbox;9495/*96* We write the entry point and cpu id as LE regardless of the97* native endianness of the kernel. Therefore, any boot-loaders98* that read this address need to convert this address to the99* Boot-Loader's endianness before jumping.100*/101writeq_relaxed(__pa_symbol(secondary_entry),102&mailbox->entry_point);103writel_relaxed(cpu_entry->gic_cpu_id, &mailbox->cpu_id);104105arch_send_wakeup_ipi(cpu);106107return 0;108}109110static void acpi_parking_protocol_cpu_postboot(void)111{112int cpu = smp_processor_id();113struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];114struct parking_protocol_mailbox __iomem *mailbox = cpu_entry->mailbox;115u64 entry_point;116117entry_point = readq_relaxed(&mailbox->entry_point);118/*119* Check if firmware has cleared the entry_point as expected120* by the protocol specification.121*/122WARN_ON(entry_point);123}124125const struct cpu_operations acpi_parking_protocol_ops = {126.name = "parking-protocol",127.cpu_init = acpi_parking_protocol_cpu_init,128.cpu_prepare = acpi_parking_protocol_cpu_prepare,129.cpu_boot = acpi_parking_protocol_cpu_boot,130.cpu_postboot = acpi_parking_protocol_cpu_postboot131};132133134