2 * ARM64 ACPI Parking Protocol implementation
4 * Authors: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
5 * Mark Salter <msalter@redhat.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <linux/acpi.h>
20 #include <linux/types.h>
22 #include <asm/cpu_ops.h>
24 struct cpu_mailbox_entry {
25 phys_addr_t mailbox_addr;
30 static struct cpu_mailbox_entry cpu_mailbox_entries[NR_CPUS];
32 void __init acpi_set_mailbox_entry(int cpu,
33 struct acpi_madt_generic_interrupt *p)
35 struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
37 cpu_entry->mailbox_addr = p->parked_address;
38 cpu_entry->version = p->parking_version;
39 cpu_entry->gic_cpu_id = p->cpu_interface_number;
42 bool acpi_parking_protocol_valid(int cpu)
44 struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
46 return cpu_entry->mailbox_addr && cpu_entry->version;
49 static int acpi_parking_protocol_cpu_init(unsigned int cpu)
51 pr_debug("%s: ACPI parked addr=%llx\n", __func__,
52 cpu_mailbox_entries[cpu].mailbox_addr);
57 static int acpi_parking_protocol_cpu_prepare(unsigned int cpu)
62 struct parking_protocol_mailbox {
68 static int acpi_parking_protocol_cpu_boot(unsigned int cpu)
70 struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
71 struct parking_protocol_mailbox __iomem *mailbox;
75 * Map mailbox memory with attribute device nGnRE (ie ioremap -
76 * this deviates from the parking protocol specifications since
77 * the mailboxes are required to be mapped nGnRnE; the attribute
78 * discrepancy is harmless insofar as the protocol specification
80 * If the mailbox is mistakenly allocated in the linear mapping
81 * by FW ioremap will fail since the mapping will be prevented
82 * by the kernel (it clashes with the linear mapping attributes
85 mailbox = ioremap(cpu_entry->mailbox_addr, sizeof(*mailbox));
89 cpu_id = readl_relaxed(&mailbox->cpu_id);
91 * Check if firmware has set-up the mailbox entry properly
92 * before kickstarting the respective cpu.
100 * We write the entry point and cpu id as LE regardless of the
101 * native endianness of the kernel. Therefore, any boot-loaders
102 * that read this address need to convert this address to the
103 * Boot-Loader's endianness before jumping.
105 writeq_relaxed(__pa(secondary_entry), &mailbox->entry_point);
106 writel_relaxed(cpu_entry->gic_cpu_id, &mailbox->cpu_id);
108 arch_send_wakeup_ipi_mask(cpumask_of(cpu));
115 static void acpi_parking_protocol_cpu_postboot(void)
117 int cpu = smp_processor_id();
118 struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
119 struct parking_protocol_mailbox __iomem *mailbox;
123 * Map mailbox memory with attribute device nGnRE (ie ioremap -
124 * this deviates from the parking protocol specifications since
125 * the mailboxes are required to be mapped nGnRnE; the attribute
126 * discrepancy is harmless insofar as the protocol specification
128 * If the mailbox is mistakenly allocated in the linear mapping
129 * by FW ioremap will fail since the mapping will be prevented
130 * by the kernel (it clashes with the linear mapping attributes
133 mailbox = ioremap(cpu_entry->mailbox_addr, sizeof(*mailbox));
137 entry_point = readl_relaxed(&mailbox->entry_point);
139 * Check if firmware has cleared the entry_point as expected
140 * by the protocol specification.
142 WARN_ON(entry_point);
147 const struct cpu_operations acpi_parking_protocol_ops = {
148 .name = "parking-protocol",
149 .cpu_init = acpi_parking_protocol_cpu_init,
150 .cpu_prepare = acpi_parking_protocol_cpu_prepare,
151 .cpu_boot = acpi_parking_protocol_cpu_boot,
152 .cpu_postboot = acpi_parking_protocol_cpu_postboot