1 // SPDX-License-Identifier: GPL-2.0-only
3 * Spin Table SMP initialisation
5 * Copyright (C) 2013 ARM Ltd.
8 #include <linux/delay.h>
9 #include <linux/init.h>
11 #include <linux/smp.h>
12 #include <linux/types.h>
15 #include <asm/cacheflush.h>
16 #include <asm/cpu_ops.h>
17 #include <asm/cputype.h>
19 #include <asm/smp_plat.h>
21 extern void secondary_holding_pen(void);
22 volatile unsigned long __section(".mmuoff.data.read")
23 secondary_holding_pen_release
= INVALID_HWID
;
25 static phys_addr_t cpu_release_addr
[NR_CPUS
];
28 * Write secondary_holding_pen_release in a way that is guaranteed to be
29 * visible to all observers, irrespective of whether they're taking part
30 * in coherency or not. This is necessary for the hotplug code to work
33 static void write_pen_release(u64 val
)
35 void *start
= (void *)&secondary_holding_pen_release
;
36 unsigned long size
= sizeof(secondary_holding_pen_release
);
38 secondary_holding_pen_release
= val
;
39 dcache_clean_inval_poc((unsigned long)start
, (unsigned long)start
+ size
);
43 static int smp_spin_table_cpu_init(unsigned int cpu
)
45 struct device_node
*dn
;
48 dn
= of_get_cpu_node(cpu
, NULL
);
53 * Determine the address from which the CPU is polling.
55 ret
= of_property_read_u64(dn
, "cpu-release-addr",
56 &cpu_release_addr
[cpu
]);
58 pr_err("CPU %d: missing or invalid cpu-release-addr property\n",
66 static int smp_spin_table_cpu_prepare(unsigned int cpu
)
68 __le64 __iomem
*release_addr
;
69 phys_addr_t pa_holding_pen
= __pa_symbol(secondary_holding_pen
);
71 if (!cpu_release_addr
[cpu
])
75 * The cpu-release-addr may or may not be inside the linear mapping.
76 * As ioremap_cache will either give us a new mapping or reuse the
77 * existing linear mapping, we can use it to cover both cases. In
78 * either case the memory will be MT_NORMAL.
80 release_addr
= ioremap_cache(cpu_release_addr
[cpu
],
81 sizeof(*release_addr
));
86 * We write the release address as LE regardless of the native
87 * endianness of the kernel. Therefore, any boot-loaders that
88 * read this address need to convert this address to the
89 * boot-loader's endianness before jumping. This is mandated by
92 writeq_relaxed(pa_holding_pen
, release_addr
);
93 dcache_clean_inval_poc((__force
unsigned long)release_addr
,
94 (__force
unsigned long)release_addr
+
95 sizeof(*release_addr
));
98 * Send an event to wake up the secondary CPU.
102 iounmap(release_addr
);
107 static int smp_spin_table_cpu_boot(unsigned int cpu
)
110 * Update the pen release flag.
112 write_pen_release(cpu_logical_map(cpu
));
115 * Send an event, causing the secondaries to read pen_release.
122 const struct cpu_operations smp_spin_table_ops
= {
123 .name
= "spin-table",
124 .cpu_init
= smp_spin_table_cpu_init
,
125 .cpu_prepare
= smp_spin_table_cpu_prepare
,
126 .cpu_boot
= smp_spin_table_cpu_boot
,