Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * ARM64 ACPI Parking Protocol implementation
0004  *
0005  * Authors: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
0006  *      Mark Salter <msalter@redhat.com>
0007  */
0008 #include <linux/acpi.h>
0009 #include <linux/mm.h>
0010 #include <linux/types.h>
0011 
0012 #include <asm/cpu_ops.h>
0013 
0014 struct parking_protocol_mailbox {
0015     __le32 cpu_id;
0016     __le32 reserved;
0017     __le64 entry_point;
0018 };
0019 
0020 struct cpu_mailbox_entry {
0021     struct parking_protocol_mailbox __iomem *mailbox;
0022     phys_addr_t mailbox_addr;
0023     u8 version;
0024     u8 gic_cpu_id;
0025 };
0026 
0027 static struct cpu_mailbox_entry cpu_mailbox_entries[NR_CPUS];
0028 
0029 void __init acpi_set_mailbox_entry(int cpu,
0030                    struct acpi_madt_generic_interrupt *p)
0031 {
0032     struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
0033 
0034     cpu_entry->mailbox_addr = p->parked_address;
0035     cpu_entry->version = p->parking_version;
0036     cpu_entry->gic_cpu_id = p->cpu_interface_number;
0037 }
0038 
0039 bool acpi_parking_protocol_valid(int cpu)
0040 {
0041     struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
0042 
0043     return cpu_entry->mailbox_addr && cpu_entry->version;
0044 }
0045 
0046 static int acpi_parking_protocol_cpu_init(unsigned int cpu)
0047 {
0048     pr_debug("%s: ACPI parked addr=%llx\n", __func__,
0049           cpu_mailbox_entries[cpu].mailbox_addr);
0050 
0051     return 0;
0052 }
0053 
0054 static int acpi_parking_protocol_cpu_prepare(unsigned int cpu)
0055 {
0056     return 0;
0057 }
0058 
0059 static int acpi_parking_protocol_cpu_boot(unsigned int cpu)
0060 {
0061     struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
0062     struct parking_protocol_mailbox __iomem *mailbox;
0063     u32 cpu_id;
0064 
0065     /*
0066      * Map mailbox memory with attribute device nGnRE (ie ioremap -
0067      * this deviates from the parking protocol specifications since
0068      * the mailboxes are required to be mapped nGnRnE; the attribute
0069      * discrepancy is harmless insofar as the protocol specification
0070      * is concerned).
0071      * If the mailbox is mistakenly allocated in the linear mapping
0072      * by FW ioremap will fail since the mapping will be prevented
0073      * by the kernel (it clashes with the linear mapping attributes
0074      * specifications).
0075      */
0076     mailbox = ioremap(cpu_entry->mailbox_addr, sizeof(*mailbox));
0077     if (!mailbox)
0078         return -EIO;
0079 
0080     cpu_id = readl_relaxed(&mailbox->cpu_id);
0081     /*
0082      * Check if firmware has set-up the mailbox entry properly
0083      * before kickstarting the respective cpu.
0084      */
0085     if (cpu_id != ~0U) {
0086         iounmap(mailbox);
0087         return -ENXIO;
0088     }
0089 
0090     /*
0091      * stash the mailbox address mapping to use it for further FW
0092      * checks in the postboot method
0093      */
0094     cpu_entry->mailbox = mailbox;
0095 
0096     /*
0097      * We write the entry point and cpu id as LE regardless of the
0098      * native endianness of the kernel. Therefore, any boot-loaders
0099      * that read this address need to convert this address to the
0100      * Boot-Loader's endianness before jumping.
0101      */
0102     writeq_relaxed(__pa_symbol(function_nocfi(secondary_entry)),
0103                &mailbox->entry_point);
0104     writel_relaxed(cpu_entry->gic_cpu_id, &mailbox->cpu_id);
0105 
0106     arch_send_wakeup_ipi_mask(cpumask_of(cpu));
0107 
0108     return 0;
0109 }
0110 
0111 static void acpi_parking_protocol_cpu_postboot(void)
0112 {
0113     int cpu = smp_processor_id();
0114     struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
0115     struct parking_protocol_mailbox __iomem *mailbox = cpu_entry->mailbox;
0116     u64 entry_point;
0117 
0118     entry_point = readq_relaxed(&mailbox->entry_point);
0119     /*
0120      * Check if firmware has cleared the entry_point as expected
0121      * by the protocol specification.
0122      */
0123     WARN_ON(entry_point);
0124 }
0125 
0126 const struct cpu_operations acpi_parking_protocol_ops = {
0127     .name       = "parking-protocol",
0128     .cpu_init   = acpi_parking_protocol_cpu_init,
0129     .cpu_prepare    = acpi_parking_protocol_cpu_prepare,
0130     .cpu_boot   = acpi_parking_protocol_cpu_boot,
0131     .cpu_postboot   = acpi_parking_protocol_cpu_postboot
0132 };