1 // SPDX-License-Identifier: GPL-2.0-only
3 * ARM64 ACPI Parking Protocol implementation
5 * Authors: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
6 * Mark Salter <msalter@redhat.com>
8 #include <linux/acpi.h>
10 #include <linux/types.h>
12 #include <asm/cpu_ops.h>
14 struct parking_protocol_mailbox
{
20 struct cpu_mailbox_entry
{
21 struct parking_protocol_mailbox __iomem
*mailbox
;
22 phys_addr_t mailbox_addr
;
27 static struct cpu_mailbox_entry cpu_mailbox_entries
[NR_CPUS
];
29 void __init
acpi_set_mailbox_entry(int cpu
,
30 struct acpi_madt_generic_interrupt
*p
)
32 struct cpu_mailbox_entry
*cpu_entry
= &cpu_mailbox_entries
[cpu
];
34 cpu_entry
->mailbox_addr
= p
->parked_address
;
35 cpu_entry
->version
= p
->parking_version
;
36 cpu_entry
->gic_cpu_id
= p
->cpu_interface_number
;
39 bool acpi_parking_protocol_valid(int cpu
)
41 struct cpu_mailbox_entry
*cpu_entry
= &cpu_mailbox_entries
[cpu
];
43 return cpu_entry
->mailbox_addr
&& cpu_entry
->version
;
46 static int acpi_parking_protocol_cpu_init(unsigned int cpu
)
48 pr_debug("%s: ACPI parked addr=%llx\n", __func__
,
49 cpu_mailbox_entries
[cpu
].mailbox_addr
);
54 static int acpi_parking_protocol_cpu_prepare(unsigned int cpu
)
59 static int acpi_parking_protocol_cpu_boot(unsigned int cpu
)
61 struct cpu_mailbox_entry
*cpu_entry
= &cpu_mailbox_entries
[cpu
];
62 struct parking_protocol_mailbox __iomem
*mailbox
;
66 * Map mailbox memory with attribute device nGnRE (ie ioremap -
67 * this deviates from the parking protocol specifications since
68 * the mailboxes are required to be mapped nGnRnE; the attribute
69 * discrepancy is harmless insofar as the protocol specification
71 * If the mailbox is mistakenly allocated in the linear mapping
72 * by FW ioremap will fail since the mapping will be prevented
73 * by the kernel (it clashes with the linear mapping attributes
76 mailbox
= ioremap(cpu_entry
->mailbox_addr
, sizeof(*mailbox
));
80 cpu_id
= readl_relaxed(&mailbox
->cpu_id
);
82 * Check if firmware has set-up the mailbox entry properly
83 * before kickstarting the respective cpu.
91 * stash the mailbox address mapping to use it for further FW
92 * checks in the postboot method
94 cpu_entry
->mailbox
= mailbox
;
97 * We write the entry point and cpu id as LE regardless of the
98 * native endianness of the kernel. Therefore, any boot-loaders
99 * that read this address need to convert this address to the
100 * Boot-Loader's endianness before jumping.
102 writeq_relaxed(__pa_symbol(secondary_entry
), &mailbox
->entry_point
);
103 writel_relaxed(cpu_entry
->gic_cpu_id
, &mailbox
->cpu_id
);
105 arch_send_wakeup_ipi_mask(cpumask_of(cpu
));
110 static void acpi_parking_protocol_cpu_postboot(void)
112 int cpu
= smp_processor_id();
113 struct cpu_mailbox_entry
*cpu_entry
= &cpu_mailbox_entries
[cpu
];
114 struct parking_protocol_mailbox __iomem
*mailbox
= cpu_entry
->mailbox
;
117 entry_point
= readq_relaxed(&mailbox
->entry_point
);
119 * Check if firmware has cleared the entry_point as expected
120 * by the protocol specification.
122 WARN_ON(entry_point
);
125 const 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_postboot