1d7445676SArnd Bergmann // SPDX-License-Identifier: GPL-2.0-only
2d7445676SArnd Bergmann /*
3d7445676SArnd Bergmann * Copyright (C) 2002 ARM Ltd.
4d7445676SArnd Bergmann * All Rights Reserved
5d7445676SArnd Bergmann */
6d7445676SArnd Bergmann #include <linux/init.h>
7d7445676SArnd Bergmann #include <linux/errno.h>
8d7445676SArnd Bergmann #include <linux/smp.h>
9d7445676SArnd Bergmann #include <linux/io.h>
10d7445676SArnd Bergmann #include <linux/of_address.h>
11d7445676SArnd Bergmann #include <linux/vexpress.h>
12d7445676SArnd Bergmann
13d7445676SArnd Bergmann #include <asm/mcpm.h>
14d7445676SArnd Bergmann #include <asm/smp_scu.h>
15d7445676SArnd Bergmann #include <asm/mach/map.h>
16d7445676SArnd Bergmann
17d7445676SArnd Bergmann #include "platsmp.h"
18d7445676SArnd Bergmann #include "vexpress.h"
19d7445676SArnd Bergmann
vexpress_smp_init_ops(void)20d7445676SArnd Bergmann bool __init vexpress_smp_init_ops(void)
21d7445676SArnd Bergmann {
22d7445676SArnd Bergmann #ifdef CONFIG_MCPM
23d7445676SArnd Bergmann int cpu;
24d7445676SArnd Bergmann struct device_node *cpu_node, *cci_node;
25d7445676SArnd Bergmann
26d7445676SArnd Bergmann /*
27d7445676SArnd Bergmann * The best way to detect a multi-cluster configuration
28d7445676SArnd Bergmann * is to detect if the kernel can take over CCI ports
29d7445676SArnd Bergmann * control. Loop over possible CPUs and check if CCI
30d7445676SArnd Bergmann * port control is available.
31d7445676SArnd Bergmann * Override the default vexpress_smp_ops if so.
32d7445676SArnd Bergmann */
33d7445676SArnd Bergmann for_each_possible_cpu(cpu) {
34d7445676SArnd Bergmann bool available;
35d7445676SArnd Bergmann
36d7445676SArnd Bergmann cpu_node = of_get_cpu_node(cpu, NULL);
37d7445676SArnd Bergmann if (WARN(!cpu_node, "Missing cpu device node!"))
38d7445676SArnd Bergmann return false;
39d7445676SArnd Bergmann
40d7445676SArnd Bergmann cci_node = of_parse_phandle(cpu_node, "cci-control-port", 0);
41d7445676SArnd Bergmann available = cci_node && of_device_is_available(cci_node);
42d7445676SArnd Bergmann of_node_put(cci_node);
43d7445676SArnd Bergmann of_node_put(cpu_node);
44d7445676SArnd Bergmann
45d7445676SArnd Bergmann if (!available)
46d7445676SArnd Bergmann return false;
47d7445676SArnd Bergmann }
48d7445676SArnd Bergmann
49d7445676SArnd Bergmann mcpm_smp_set_ops();
50d7445676SArnd Bergmann return true;
51d7445676SArnd Bergmann #else
52d7445676SArnd Bergmann return false;
53d7445676SArnd Bergmann #endif
54d7445676SArnd Bergmann }
55d7445676SArnd Bergmann
56d7445676SArnd Bergmann static const struct of_device_id vexpress_smp_dt_scu_match[] __initconst = {
57d7445676SArnd Bergmann { .compatible = "arm,cortex-a5-scu", },
58d7445676SArnd Bergmann { .compatible = "arm,cortex-a9-scu", },
59d7445676SArnd Bergmann {}
60d7445676SArnd Bergmann };
61d7445676SArnd Bergmann
vexpress_smp_dt_prepare_cpus(unsigned int max_cpus)62d7445676SArnd Bergmann static void __init vexpress_smp_dt_prepare_cpus(unsigned int max_cpus)
63d7445676SArnd Bergmann {
64d7445676SArnd Bergmann struct device_node *scu = of_find_matching_node(NULL,
65d7445676SArnd Bergmann vexpress_smp_dt_scu_match);
66d7445676SArnd Bergmann
67d7445676SArnd Bergmann if (scu)
68d7445676SArnd Bergmann scu_enable(of_iomap(scu, 0));
69d7445676SArnd Bergmann
70d7445676SArnd Bergmann /*
71d7445676SArnd Bergmann * Write the address of secondary startup into the
72d7445676SArnd Bergmann * system-wide flags register. The boot monitor waits
73d7445676SArnd Bergmann * until it receives a soft interrupt, and then the
74d7445676SArnd Bergmann * secondary CPU branches to this address.
75d7445676SArnd Bergmann */
76d7445676SArnd Bergmann vexpress_flags_set(__pa_symbol(versatile_secondary_startup));
77d7445676SArnd Bergmann }
78d7445676SArnd Bergmann
79d7445676SArnd Bergmann #ifdef CONFIG_HOTPLUG_CPU
vexpress_cpu_die(unsigned int cpu)80d7445676SArnd Bergmann static void vexpress_cpu_die(unsigned int cpu)
81d7445676SArnd Bergmann {
82d7445676SArnd Bergmann versatile_immitation_cpu_die(cpu, 0x40);
83d7445676SArnd Bergmann }
84d7445676SArnd Bergmann #endif
85d7445676SArnd Bergmann
86d7445676SArnd Bergmann const struct smp_operations vexpress_smp_dt_ops __initconst = {
87d7445676SArnd Bergmann .smp_prepare_cpus = vexpress_smp_dt_prepare_cpus,
88d7445676SArnd Bergmann .smp_secondary_init = versatile_secondary_init,
89d7445676SArnd Bergmann .smp_boot_secondary = versatile_boot_secondary,
90d7445676SArnd Bergmann #ifdef CONFIG_HOTPLUG_CPU
91d7445676SArnd Bergmann .cpu_die = vexpress_cpu_die,
92d7445676SArnd Bergmann #endif
93d7445676SArnd Bergmann };
94