GNU Linux-libre 4.14.290-gnu1
[releases.git] / arch / arm / mach-axxia / platsmp.c
1 /*
2  * linux/arch/arm/mach-axxia/platsmp.c
3  *
4  * Copyright (C) 2012 LSI Corporation
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/init.h>
12 #include <linux/io.h>
13 #include <linux/smp.h>
14 #include <linux/of.h>
15 #include <linux/of_address.h>
16 #include <asm/cacheflush.h>
17
18 /* Syscon register offsets for releasing cores from reset */
19 #define SC_CRIT_WRITE_KEY       0x1000
20 #define SC_RST_CPU_HOLD         0x1010
21
22 /*
23  * Write the kernel entry point for secondary CPUs to the specified address
24  */
25 static void write_release_addr(u32 release_phys)
26 {
27         u32 *virt = (u32 *) phys_to_virt(release_phys);
28         writel_relaxed(__pa_symbol(secondary_startup), virt);
29         /* Make sure this store is visible to other CPUs */
30         smp_wmb();
31         __cpuc_flush_dcache_area(virt, sizeof(u32));
32 }
33
34 static int axxia_boot_secondary(unsigned int cpu, struct task_struct *idle)
35 {
36         struct device_node *syscon_np;
37         void __iomem *syscon;
38         u32 tmp;
39
40         syscon_np = of_find_compatible_node(NULL, NULL, "lsi,axxia-syscon");
41         if (!syscon_np)
42                 return -ENOENT;
43
44         syscon = of_iomap(syscon_np, 0);
45         of_node_put(syscon_np);
46         if (!syscon)
47                 return -ENOMEM;
48
49         tmp = readl(syscon + SC_RST_CPU_HOLD);
50         writel(0xab, syscon + SC_CRIT_WRITE_KEY);
51         tmp &= ~(1 << cpu);
52         writel(tmp, syscon + SC_RST_CPU_HOLD);
53
54         return 0;
55 }
56
57 static void __init axxia_smp_prepare_cpus(unsigned int max_cpus)
58 {
59         int cpu_count = 0;
60         int cpu;
61
62         /*
63          * Initialise the present map, which describes the set of CPUs actually
64          * populated at the present time.
65          */
66         for_each_possible_cpu(cpu) {
67                 struct device_node *np;
68                 u32 release_phys;
69
70                 np = of_get_cpu_node(cpu, NULL);
71                 if (!np)
72                         continue;
73                 if (of_property_read_u32(np, "cpu-release-addr", &release_phys))
74                         continue;
75
76                 if (cpu_count < max_cpus) {
77                         set_cpu_present(cpu, true);
78                         cpu_count++;
79                 }
80
81                 if (release_phys != 0)
82                         write_release_addr(release_phys);
83         }
84 }
85
86 static const struct smp_operations axxia_smp_ops __initconst = {
87         .smp_prepare_cpus       = axxia_smp_prepare_cpus,
88         .smp_boot_secondary     = axxia_boot_secondary,
89 };
90 CPU_METHOD_OF_DECLARE(axxia_smp, "lsi,syscon-release", &axxia_smp_ops);