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