1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/acpi.h>
20#include <linux/mm.h>
21#include <linux/types.h>
22
23#include <asm/cpu_ops.h>
24
25struct parking_protocol_mailbox {
26 __le32 cpu_id;
27 __le32 reserved;
28 __le64 entry_point;
29};
30
31struct cpu_mailbox_entry {
32 struct parking_protocol_mailbox __iomem *mailbox;
33 phys_addr_t mailbox_addr;
34 u8 version;
35 u8 gic_cpu_id;
36};
37
38static struct cpu_mailbox_entry cpu_mailbox_entries[NR_CPUS];
39
40void __init acpi_set_mailbox_entry(int cpu,
41 struct acpi_madt_generic_interrupt *p)
42{
43 struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
44
45 cpu_entry->mailbox_addr = p->parked_address;
46 cpu_entry->version = p->parking_version;
47 cpu_entry->gic_cpu_id = p->cpu_interface_number;
48}
49
50bool acpi_parking_protocol_valid(int cpu)
51{
52 struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
53
54 return cpu_entry->mailbox_addr && cpu_entry->version;
55}
56
57static int acpi_parking_protocol_cpu_init(unsigned int cpu)
58{
59 pr_debug("%s: ACPI parked addr=%llx\n", __func__,
60 cpu_mailbox_entries[cpu].mailbox_addr);
61
62 return 0;
63}
64
65static int acpi_parking_protocol_cpu_prepare(unsigned int cpu)
66{
67 return 0;
68}
69
70static int acpi_parking_protocol_cpu_boot(unsigned int cpu)
71{
72 struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
73 struct parking_protocol_mailbox __iomem *mailbox;
74 u32 cpu_id;
75
76
77
78
79
80
81
82
83
84
85
86
87 mailbox = ioremap(cpu_entry->mailbox_addr, sizeof(*mailbox));
88 if (!mailbox)
89 return -EIO;
90
91 cpu_id = readl_relaxed(&mailbox->cpu_id);
92
93
94
95
96 if (cpu_id != ~0U) {
97 iounmap(mailbox);
98 return -ENXIO;
99 }
100
101
102
103
104
105 cpu_entry->mailbox = mailbox;
106
107
108
109
110
111
112
113 writeq_relaxed(__pa_symbol(secondary_entry), &mailbox->entry_point);
114 writel_relaxed(cpu_entry->gic_cpu_id, &mailbox->cpu_id);
115
116 arch_send_wakeup_ipi_mask(cpumask_of(cpu));
117
118 return 0;
119}
120
121static void acpi_parking_protocol_cpu_postboot(void)
122{
123 int cpu = smp_processor_id();
124 struct cpu_mailbox_entry *cpu_entry = &cpu_mailbox_entries[cpu];
125 struct parking_protocol_mailbox __iomem *mailbox = cpu_entry->mailbox;
126 u64 entry_point;
127
128 entry_point = readq_relaxed(&mailbox->entry_point);
129
130
131
132
133 WARN_ON(entry_point);
134}
135
136const struct cpu_operations acpi_parking_protocol_ops = {
137 .name = "parking-protocol",
138 .cpu_init = acpi_parking_protocol_cpu_init,
139 .cpu_prepare = acpi_parking_protocol_cpu_prepare,
140 .cpu_boot = acpi_parking_protocol_cpu_boot,
141 .cpu_postboot = acpi_parking_protocol_cpu_postboot
142};
143